/trunk
-- TODO: |
-- scroll large guild members |
local BUTTON_HEIGHT, ICON_SIZE, GAP, TEXT_OFFSET = |
15, 13, 10, 5 |
local dontShow, block, horde, config, isGuild = true |
local defaultConfig = { showGuildNotes = true, showGuildName = true, sortType = "class", sortDESC = false, fontSize=12 } |
local guildEntries, friendEntries = {}, {} |
local scrollIndex |
local format, strfind, strupper, GetGuildRosterInfo, GetFriendInfo, RAID_CLASS_COLORS, CLASS_BUTTONS = |
format, strfind, strupper, GetGuildRosterInfo, GetFriendInfo, RAID_CLASS_COLORS, CLASS_BUTTONS |
local total, online = GetNumFriends(), 0 |
for i = 1, total do |
local name, level, class, zone, connected, status, note = GetFriendInfo(i) |
if( connected )then |
if( online == 0 )then |
if connected then |
if online == 0 then |
friendEntries[1] = new( nil, "Name", "", "Lv", "Zone", "Notes" ) |
end |
online = online + 1 |
end |
end |
f.FriendsBlock.text = format(" %d/%d", online, total) |
if( not isGuild and block )then f:FriendsOnEnter(block) end |
if not isGuild and block then f:FriendsOnEnter(block) end |
end |
function f:GUILD_ROSTER_UPDATE() |
dontShow = not( isGuild and block ) |
f.GuildOnEnter( block ) |
dontShow = not(isGuild and block) |
f.GuildOnEnter(block) |
end |
function f:PLAYER_GUILD_UPDATE(event, unit) |
if( unit and unit ~= "player" )then return end |
if unit and unit ~= "player" then return end |
return IsInGuild() and GuildRoster() |
end |
local hordeZones = "Orgrimmar,Undercity,Thunder Bluff,Silvermoon City,Durotar,Tirisfal Glades,The Barrens,Silverpine Forest,Mulgore,The Sepulcher,Eversong Woods,Ghostlands," |
local allianceZones = "Ironforge,Stormwind City,Darnassus,Azuremyst Isle,Bloodmyst Isle,Darkshore,Dun Morogh,Loch Modan,Wetlands,Elwynn Forest,Redridge Mountains,Westfall,Teldrassil,Duskwood,Darshire,Thelsamar,Deeprun Tram,The Exodar,Auberdine,Menethil Harbor,Theramore Isle" |
local function GetZoneColor(zone) |
if( strfind( hordeZones , zone.."," ) )then if( horde )then return 0,1,0 else return 1,0,0 end end |
if( strfind( allianceZones, zone.."," ) )then if( horde )then return 1,0,0 else return 0,1,0 end end |
if strfind( hordeZones , zone.."," ) then if horde then return 0,1,0 else return 1,0,0 end end |
if strfind( allianceZones, zone.."," ) then if horde then return 1,0,0 else return 0,1,0 end end |
return 1,1,0 |
end |
highlight:SetAlpha(0) |
local function Menu_OnEnter(b) |
if( b.index )then |
if b.index then |
highlight:SetAllPoints(b) |
if( b.index > 1)then highlight:SetAlpha(1) end |
if b.index > 1 then highlight:SetAlpha(1) end |
end |
end |
local function Menu_OnLeave(b) |
highlight:ClearAllPoints() |
if( b.index and b.index > 1 )then highlight:SetAlpha(0) end |
if( not MouseIsOver(f) )then block = nil f:Hide() end |
if b.index and b.index > 1 then highlight:SetAlpha(0) end |
if not MouseIsOver(f) then block = nil f:Hide() end |
end |
local function CreateFS( index, parent, justify, anchor ) |
local fs = parent:CreateFontString( nil, "OVERLAY", "SystemFont_Shadow_Med1" ) |
fs:SetJustifyH( justify ) |
fs:SetTextColor( 1, index == 1 and .8 or 1, 0 ) |
if( anchor )then fs:SetPoint( "LEFT", anchor, "RIGHT", GAP, 0 ) end |
if anchor then fs:SetPoint( "LEFT", anchor, "RIGHT", GAP, 0 ) end |
return fs |
end |
button:SetScript( "OnEnter", Menu_OnEnter ) |
button:SetScript( "OnLeave", Menu_OnLeave ) |
button.fontName = CreateFS( key, button, "LEFT" ) |
if( key == 0 )then |
if key == 0 then |
button.fontName:SetJustifyV"TOP" |
else |
button.icon = button:CreateTexture() |
local button = buttons[index] |
button:Show() |
button.fontName:SetText( name or "" ) |
if( class )then |
if( index > 1 )then |
if class then |
if index > 1 then |
class = isGuild and class or L[class] |
local color = RAID_CLASS_COLORS[class] |
if( color )then |
if color then |
button.fontName:SetTextColor( color.r, color.g, color.b ) |
if( inGroup )then |
if inGroup then |
button.icon:SetTexture(isGrouped and "Interface\\Buttons\\UI-CheckBox-Check" or "") |
button.icon:SetTexCoord(.15,.85,.15,.85) |
else |
local cols, colspace = { "class", "name", "level", "zone", "note", "rank" }, { ICON_SIZE } |
local function OnGuildmateClick( self, button ) |
if( not( self and self.unit ) )then return end |
if( isGuild and button ~= "LeftButton" and not IsModifierKeyDown() )then -- sort columns |
if not( self and self.unit ) then return end |
if isGuild and button ~= "LeftButton" and not IsModifierKeyDown() then -- sort columns |
local prevDist = GetCursorPosition() / self:GetEffectiveScale() - self:GetLeft() |
local colpos, dist = colspace[1] - prevDist |
for i=2, #colspace do |
colpos = colpos + colspace[i] + (i==2 and TEXT_OFFSET or GAP) |
dist = abs( colpos - colspace[i]*.5 ) |
if( dist > prevDist )then dist, prevDist = i-1, -1 break else prevDist = dist end |
if dist > prevDist then dist, prevDist = i-1, -1 break else prevDist = dist end |
end |
colpos = prevDist < 0 and dist or #colspace |
colpos = not config.showGuildNotes and colpos == 5 and "rank" or cols[colpos] |
if( config.sortType == colpos )then |
if config.sortType == colpos then |
config.sortDESC = not config.sortDESC |
else |
config.sortType, config.sortDESC = colpos, false |
end |
SortGuildRoster( colpos ) |
elseif( IsAltKeyDown() )then |
elseif IsAltKeyDown() then |
InviteUnit( self.unit ) |
elseif( IsControlKeyDown() )then |
if( not isGuild )then |
elseif IsControlKeyDown() then |
if not isGuild then |
FriendsFrame.NotesID = self.index - 1 |
StaticPopup_Show( "SET_FRIENDNOTE", self.unit ) |
elseif( button == "LeftButton" and CanEditPublicNote() or button ~= "LeftButton" and CanEditOfficerNote() )then |
elseif button == "LeftButton" and CanEditPublicNote() or button ~= "LeftButton" and CanEditOfficerNote() then |
SetGuildRosterSelection( guildEntries[self.index][8] ) |
StaticPopup_Show( button == "LeftButton" and "SET_GUILDPLAYERNOTE" or "SET_GUILDOFFICERNOTE" ) |
end |
isGuild = _isGuild |
block = block or self |
local hasEntries = #entries > 0 |
if( not hasEntries )then |
if not hasEntries then |
entries[1] = new( nil, isGuild and ERR_GUILD_PLAYER_NOT_IN_GUILD or "No friends online.", "" ) |
end |
local hideNotes = isGuild and not config.showGuildNotes |
local extraHeight, motd = 0 |
if( isGuild and hasEntries )then |
if isGuild and hasEntries then |
motd, extraHeight = SetButtonData( 0, "|cffffffffMOTD:|r "..GetGuildRosterMOTD() ) |
if( CanEditMOTD() )then motd:SetScript( "OnClick", EditMOTD ) end |
if CanEditMOTD() then motd:SetScript( "OnClick", EditMOTD ) end |
motd.fontName:ClearAllPoints() |
end |
button, nameW, levelW, zoneW, notesW, rankW = SetButtonData( i, entry[2], entry[3], entry[4], entry[5], entry[6], entry[7], isGrouped, isGrouped and entry[1] and isGrouped(entry[1]), isGrouped ) --MOD |
button.unit = entry[1] |
button:SetScript( "OnClick", OnGuildmateClick ) |
if( nameW > nameC )then nameC = nameW end |
if( levelW and levelW>0 )then |
if( levelW > levelC )then levelC = levelW end |
if( zoneW > zoneC )then zoneC = zoneW end |
if( notesW > notesC )then notesC = notesW end |
if( rankW > rankC )then rankC = rankW end |
if( hideNotes )then button.fontNotes:Hide() else button.fontNotes:Show() end |
if nameW > nameC then nameC = nameW end |
if levelW and levelW>0 then |
if levelW > levelC then levelC = levelW end |
if zoneW > zoneC then zoneC = zoneW end |
if notesW > notesC then notesC = notesW end |
if rankW > rankC then rankC = rankW end |
if hideNotes then button.fontNotes:Hide() else button.fontNotes:Show() end |
button.fontRank:SetPoint( "LEFT", hideNotes and button.fontZone or button.fontNotes, "RIGHT", GAP, 0 ) |
end |
end |
if( hideNotes )then notesC = -GAP end |
if hideNotes then notesC = -GAP end |
local maxWidth = ICON_SIZE + TEXT_OFFSET + nameC + levelC + zoneC + notesC + rankC + GAP * (isGuild and 4 or 3) |
extraHeight = ceil( extraHeight / maxWidth ) |
if( isGuild and hasEntries )then |
if isGuild and hasEntries then |
motd = buttons[0] |
motd:SetWidth( maxWidth ) |
motd:SetPoint( "TOPLEFT", f, "TOPLEFT", GAP, -GAP ) |
motd:SetHeight( (extraHeight+1) * BUTTON_HEIGHT ) |
motd.fontName:SetAllPoints(motd) |
buttons[1]:SetPoint( "TOPLEFT", motd, "BOTTOMLEFT" ) |
elseif( rawget( buttons, 0 ) )then |
elseif rawget( buttons, 0 ) then |
buttons[0]:Hide() |
end |
for i=1, #entries do |
button = buttons[i] |
button:SetWidth( maxWidth ) |
if( not isGuild or i>1 or not hasEntries )then button:SetPoint( "TOPLEFT", f, "TOPLEFT", GAP, (1-i-extraHeight-offsetEntries) * BUTTON_HEIGHT - GAP ) end |
if not isGuild or i>1 or not hasEntries then button:SetPoint( "TOPLEFT", f, "TOPLEFT", GAP, (1-i-extraHeight-offsetEntries) * BUTTON_HEIGHT - GAP ) end |
button.fontName:SetWidth(nameC) |
button.fontLevel:SetWidth(levelC) |
button.fontZone:SetWidth(zoneC) |
function f:FriendsOnEnter() |
if( InCombatLockdown() )then f:Show() return Menu_OnEnter(f) end |
if InCombatLockdown() then f:Show() return Menu_OnEnter(f) end |
return ShowTablet( self, false, friendEntries ) |
end |
function f:GuildOnEnter() |
if( not dontShow and InCombatLockdown() )then f:Show() return Menu_OnEnter(f) end |
if not dontShow and InCombatLockdown() then f:Show() return Menu_OnEnter(f) end |
for k, v in next, guildEntries do del(v) guildEntries[k]=nil end |
for i=1, GetNumGuildMembers(true) do |
local name, rank, _, level, _, zone, note, offnote, connected, status, class = GetGuildRosterInfo(i) |
if( connected )then |
if( #guildEntries == 0 )then |
if connected then |
if #guildEntries == 0 then |
guildEntries[1] = new( nil, "Name", "", "Lv", "Zone", "Notes", "Rank" ) |
end |
local notes = note ~= "" and (offnote ~= "" and |
end |
local function OnBlockClick(self, button) |
if( button == "LeftButton" )then |
if( IsShiftKeyDown() and IsInGuild() )then |
if button == "LeftButton" then |
if IsShiftKeyDown() and IsInGuild() then |
config.showGuildName = not config.showGuildName |
f.GuildBlock.text = format( " %s%d/%d", config.showGuildName and GetGuildInfo"player"..": " or "", #guildEntries-1, GetNumGuildMembers(true) ) |
else ToggleFriendsFrame(3) end |
elseif( not InCombatLockdown() )then |
elseif not InCombatLockdown() then |
config.showGuildNotes = not config.showGuildNotes |
ShowTablet( block, true, guildEntries ) |
end |
return orgGuildRoster(...) |
end |
local orgShowFriends = ShowFriends |
ShowFriends = function(...) |
t.friendTimer = 0 |
return orgShowFriends(...) |
end |
local function OnUpdate( self, elapsed ) |
t.guildTimer = t.guildTimer + elapsed |
if( t.guildTimer > 15 )then |
if t.guildTimer > 15 then |
if IsInGuild() then GuildRoster() else t.guildTimer = 0 end |
end |
t.friendTimer = t.friendTimer + elapsed |
if t.friendTimer > 15 then ShowFriends() end |
end |
function f:ADDON_LOADED( event, addon ) |
if( addon ~= "Ara_Broker_Guild_Friends" )then return else self:UnregisterEvent(event) end |
if addon ~= "Ara_Broker_Guild_Friends" then return else self:UnregisterEvent(event) end |
AraBrokerGuildFriendsDB = AraBrokerGuildFriendsDB or defaultConfig |
config = AraBrokerGuildFriendsDB |
for k, v in next, defaultConfig do if config[k]==nil then config[k]=v end end |
if( config.reloading )then config.reloading = nil else SortGuildRoster(config.sortType) if( config.sortDESC )then SortGuildRoster(config.sortType) end end |
if config.reloading then config.reloading = nil else SortGuildRoster(config.sortType) if config.sortDESC then SortGuildRoster(config.sortType) end end |
horde = UnitFactionGroup"player" == "Horde" |
if( _G.Skinner )then |
if _G.Skinner then |
_G.Skinner:applySkin(self) |
else |
f:SetBackdrop( { bgFile="Interface\\Buttons\\WHITE8X8", edgeFile="Interface\\Tooltips\\UI-Tooltip-Border", |
f:RegisterEvent"FRIENDLIST_UPDATE" |
f:RegisterEvent"CHAT_MSG_SYSTEM" |
ShowFriends() |
if( IsInGuild() )then GuildRoster() else t.guildTimer = 0 end |
ShowFriends() t.friendTimer = 0 |
if IsInGuild() then GuildRoster() else t.guildTimer = 0 end |
f:GuildOnEnter() |
f.ADDON_LOADED = nil |
end |
## Interface: 30000 |
## Title: |cFFFFB366Ara|r - Broker - Guild & Friends |
## Version: r14 |
## Version: r15 |
## Author: Ara |
## Notes: A Data Broker plugin that provides guildmates & friends informations and interactions. |
## SavedVariables: AraBrokerGuildFriendsDB |