/trunk
-- ShowTablet line 3: possible source of bugs (glitch) when trying to solve: block/self -> incorrect setpoint |
local BUTTON_HEIGHT, ICON_SIZE, GAP, TEXT_OFFSET, TIMEOUT = |
15, 13, 10, 5, .05 |
local f = CreateFrame( "Frame", "AraBrokerGuildFriends" ) |
local t = CreateFrame"Frame" |
--local dropdown, dropdown_init = CreateFrame( "Frame", "AraBrokerGuildFriendsDDFrame", nil, "UIDropDownMenuTemplate" ) |
local extraFrame = CreateFrame"Frame" |
local dropdown, dropdown_init = CreateFrame( "Frame", "AraBrokerGuildFriendsDDFrame", nil, "UIDropDownMenuTemplate" ) |
local block, isGuild, leaving |
local L = setmetatable( {}, { __index = function(t,k) return k end } ) -- GetLocale() |
local format, strfind, GetGuildRosterInfo, GetFriendInfo, RAID_CLASS_COLORS, CLASS_BUTTONS = |
format, strfind, GetGuildRosterInfo, GetFriendInfo, RAID_CLASS_COLORS, CLASS_BUTTONS |
---------------------------------[[ ]]-------------------------------- |
local mejoin = format( ERR_GUILD_JOIN_S, UnitName"player" ) |
local friendOnline, friendOffline = gsub(ERR_FRIEND_ONLINE_SS,"\124Hplayer:%%s\124h%[%%s%]\124h",""), gsub(ERR_FRIEND_OFFLINE_S,"%%s","") |
function f:CHAT_MSG_SYSTEM( event, msg ) |
if msg == mejoin or strfind( msg, friendOnline ) or strfind( msg, friendOffline ) then t.updateFriends = true end |
if msg == mejoin then self.updateGuild = true return end |
if strfind( msg, friendOnline ) or strfind( msg, friendOffline ) then self.updateFriends, self.updateGuild = true, true end |
end |
local guildEntries, friendEntries = {}, {} |
local friendEntries = {} |
function f:FRIENDLIST_UPDATE() |
for k,v in next,friendEntries do del(v) friendEntries[k]=nil end |
friendEntries[1] = new( nil, "Name", "", "Lv", "Zone", "Notes" ) |
end |
online = online + 1 |
friendEntries[online+1] = new( name, status ~= "" and format("%s %s", tostring(status), tostring(name)) or name, class:gsub(" ",""):upper(), level, zone or "Unknown", note and format("[%s]",note) or "-" ) |
friendEntries[online+1] = new( name, status and format("%s %s", tostring(status), tostring(name)) or name, class:gsub(" ",""):upper(), level, zone or "Unknown", note and format("[%s]",note) or "-" ) |
end |
end |
f.FriendsBlock.text = total > 0 and format("%d/%d", online, total) or "No friends." |
f.FriendsBlock.text = total > 0 and format("%d/%d", online, total) or L["No friends."] |
if( not isGuild and block )then f:FriendsOnEnter(block) end |
end |
function f:GUILD_ROSTER_UPDATE() |
f.GuildOnEnter( block, not( isGuild and block ) ) |
local numOnline = 0 |
for i=1, GetNumGuildMembers() do |
if( select( 9, GetGuildRosterInfo(i) ) )then numOnline = numOnline + 1 end |
end |
f.GuildBlock.text = IsInGuild() and format( "%s - %d/%d", GetGuildInfo"player", numOnline, GetNumGuildMembers(true) ) or L["No Guild"] |
if( isGuild and block )then f:GuildOnEnter(block) end |
end |
function f:PLAYER_GUILD_UPDATE(event, unit) |
end |
local function Menu_OnUpdate( frame, elapsed ) |
f.timer = f.timer + elapsed |
if( f.timer <= TIMEOUT )then return end |
f:SetScript( "OnUpdate", nil ) |
extraFrame.timer = extraFrame.timer + elapsed |
if( extraFrame.timer <= TIMEOUT )then return end |
extraFrame:SetScript( "OnUpdate", nil ) |
f:Hide() |
block = nil |
return f:Hide() |
end |
local highlight = f:CreateTexture(nil,"ARTWORK") |
local function Menu_OnEnter(b) |
leaving = false |
f:SetScript("OnUpdate",nil) |
if( b.index )then |
extraFrame:SetScript( "OnUpdate", nil ) |
if(b.index)then |
highlight:SetAllPoints(b) |
if( b.index > 1)then highlight:SetAlpha(1) end |
end |
local function Menu_OnLeave(b) |
leaving = true |
f.timer = 0 |
f:SetScript("OnUpdate", Menu_OnUpdate) |
extraFrame.timer = 0 |
extraFrame:SetScript( "OnUpdate", Menu_OnUpdate ) |
highlight:ClearAllPoints() |
if( b.index and b.index > 1 )then highlight:SetAlpha(0) end |
if(b.index and b.index > 1)then highlight:SetAlpha(0) end |
end |
local font, _, flags = GameFontNormal:GetFont() |
local function CreateFS( index, parent, justify, anchor ) |
local fs = parent:CreateFontString( nil, "OVERLAY" ) |
local font, _, flags = GameFontNormal:GetFont() |
fs:SetFont( font, 12, flags ) |
fs:SetJustifyH( justify ) |
fs:SetTextColor( 1, index == 1 and .8 or 1, 0 ) |
local buttons = setmetatable( { }, { __index = function( table, key ) |
local button = CreateFrame( "Button", nil, f ) |
table[key] = button |
rawset( table, key, button ) |
button.index = key |
button:RegisterForClicks"AnyUp" |
button:SetHeight( BUTTON_HEIGHT ) |
button:SetScript( "OnEnter", Menu_OnEnter ) |
button:SetScript( "OnLeave", Menu_OnLeave ) |
button.fontName = CreateFS( key, button, "LEFT" ) |
button.fontName = CreateFS( key, button, "LEFT" ) |
if( key == 0 )then |
button.fontName:SetJustifyV"TOP" |
else |
button.icon:SetTexture"Interface\\Glues\\CharacterCreate\\UI-CharacterCreate-Classes" |
local offset, left, right, bottom, top = 0.025, unpack( CLASS_BUTTONS[class] ) |
button.icon:SetTexCoord( left+offset, right-offset, bottom+offset, top-offset ) |
-- button.icon:SetTexCoord( unpack( CLASS_BUTTONS[class] ) ) |
local color = RAID_CLASS_COLORS[class] |
button.fontName:SetTextColor( color.r, color.g, color.b ) |
color = GetDifficultyColor(level) |
end |
------------------------------[[ data feed ]]---------------------------- |
local function EditMOTD() |
f:Hide() |
GuildMOTDEditButton:Click() |
SortGuildRoster( cols[ prevDist < 0 and dist or #colspace ] ) |
elseif( IsAltKeyDown() )then |
InviteUnit( self.unit ) |
elseif( IsControlKeyDown() )then |
if( not isGuild )then |
FriendsFrame.NotesID = self.index - 1 |
StaticPopup_Show( "SET_FRIENDNOTE", self.unit ) |
elseif( CanEditPublicNote() )then |
SetGuildRosterSelection( guildEntries[self.index][8] ) |
StaticPopup_Show("SET_GUILDPLAYERNOTE") |
end |
elseif( not isGuild and IsControlKeyDown() )then |
FriendsFrame.NotesID = self.index - 1 |
StaticPopup_Show( "SET_FRIENDNOTE", self.unit ) |
else |
SetItemRef("player:"..self.unit, format( "|Hplayer:%s|h[%s]|h", self.unit, self.unit ), "LeftButton") |
end |
if( InCombatLockdown() )then return end |
if( isGuild and not IsInGuild() or #entries == 0 )then |
GameTooltip:SetOwner(self) |
GameTooltip:AddLine( isGuild and ERR_GUILD_PLAYER_NOT_IN_GUILD or "No friends online." ) |
GameTooltip:AddLine( isGuild and ERR_GUILD_PLAYER_NOT_IN_GUILD or L["No friends online."] ) |
return GameTooltip:Show() |
end |
Menu_OnEnter(self) |
return ShowTablet( self, false, friendEntries, OnGuildmateClick ) |
end |
function f:GuildOnEnter(dontShow) |
if( not dontShow and InCombatLockdown() )then return end |
local guildEntries = {} |
function f:GuildOnEnter() |
if( InCombatLockdown() )then return 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) |
guildEntries[1] = new( nil, "Name", "", "Lv", "Zone", "Notes", "Rank" ) |
end |
local notes = note ~= "" and (offnote ~= "" and |
format( "[%s] - \124cffff9944[%s]\124r", note, offnote ) or |
format( "[%s] - [%s]", note, offnote ) or |
format( "[%s]", note )) or (offnote ~= "" and |
format( "\124cffff9944[%s]\124r", offnote ) or "-") |
guildEntries[#guildEntries+1] = new( name, status == "" and name or format( "%s %s", status, name ), class, level, zone, notes, rank, i ) |
format( "[%s]", offnote ) or "-") |
guildEntries[#guildEntries+1] = new( name, status == "" and name or format( "%s %s", status, name ), class, level, zone, notes, rank ) |
end |
end |
local g = f.GuildBlock |
if( not IsInGuild() )then |
g.text, g.value, g.label = "No Guild", nil, nil |
else -- buttonbin/fortress --> "label: value" or "label: text" or "value" or "text" |
g.label = " "..GetGuildInfo"player" |
g.value = format( " %d/%d", #guildEntries-1, GetNumGuildMembers(true) ) |
g.text = format( "%s -%s", g.label, g.value ) |
end |
-- f.GuildBlock.text = IsInGuild() and format( "%s - %d/%d", GetGuildInfo"player", numOnline, GetNumGuildMembers(true) ) or "No Guild" |
return not dontShow and ShowTablet( self, true, guildEntries, OnGuildmateClick ) |
return ShowTablet( self, true, guildEntries, OnGuildmateClick ) |
end |
local orgShowFriends = ShowFriends |
ShowFriends = function(...) |
t.friendsTimer, t.updateFriends = 0, false |
f.friendsTimer, f.updateFriends = 0, false |
return orgShowFriends(...) |
end |
local orgGuildRoster = GuildRoster |
GuildRoster = function(...) |
t.guildTimer = 0 |
f.guildTimer, f.updateGuild = 0, false |
return orgGuildRoster(...) |
end |
local function OnUpdate( self, elapsed ) |
t.guildTimer, t.friendsTimer = t.guildTimer + elapsed, t.friendsTimer + elapsed |
if( t.guildTimer > 15 )then |
if IsInGuild() then GuildRoster() else t.guildTimer = 0 end |
self.guildTimer, self.friendsTimer = self.guildTimer + elapsed, self.friendsTimer + elapsed |
if( self.updateGuild and self.guildTimer > 15 or self.guildTimer > 300 )then |
self.guildTimer, self.updateGuild = 0, false |
if IsInGuild() then GuildRoster() end |
end |
if( t.updateFriends and t.friendsTimer > 15 or t.friendsTimer > 300 )then |
if( self.updateFriends and self.friendsTimer > 15 or self.friendsTimer > 300 )then |
ShowFriends() |
end |
end |
-------------------------------[[ events ]]------------------------------ |
f.PLAYER_LOGIN = function( self, event ) |
horde = UnitFactionGroup"player" == "Horde" |
SortGuildRoster"class" -- name, rank, note, online, zone, level, class |
SortGuildRoster"class" -- "name", "rank", "note", "online", "zone", "level", "class" |
self:SetBackdrop( { bgFile="Interface\\Buttons\\WHITE8X8", edgeFile="Interface\\Tooltips\\UI-Tooltip-Border", |
tile=true, tileSize=12, edgeSize=12, insets = { left=2, right=2, top=2, bottom=2 } } ) |
self:SetBackdropColor( 0, 0, 0, .75 ) |
self:SetScale( UIParent:GetScale() ) |
self:SetFrameStrata"TOOLTIP" |
self:SetFrameStrata"DIALOG" |
self:SetClampedToScreen(true) |
self:EnableMouse( true ) |
self:Show() -- possible fix for menu width bug |
self:Show() -- possible fix for menu width bug (or TODO: put in PLAYER_ENTERING_WORLD) |
t.guildTimer, t.friendsTimer = 0, 0 |
t:SetScript( "OnUpdate", OnUpdate ) |
self.guildTimer, self.friendsTimer = 0, 0 |
self:SetScript( "OnUpdate", OnUpdate ) |
self:SetScript( "OnEnter", Menu_OnEnter ) |
self:SetScript( "OnLeave", Menu_OnLeave ) |
## Interface: 30000 |
## Title: |cFFFFB366Ara|r - Guild & Friends |
## Version: r3 |
## Version: r2 |
## Notes: A Data Broker plugin that provides guildmates & friends informations and interactions. |
## Dependencies: |
## OptionalDeps: |
## SavedVariables: |
## SavedVariablesPerCharacter: |
## LoadManagers: AddonLoader |
## X-LoadOn-Always: delayed |
## _LoadManagers: AddonLoader |
## _X-LoadOn-Always: delayed |
libs\LibStub.lua |
libs\CallbackHandler-1.0.lua |