/
-- TODO: scroll large guild members |
local BUTTON_HEIGHT, ICON_SIZE, GAP, TEXT_OFFSET = |
15, 13, 10, 5 |
local BUTTON_HEIGHT, ICON_SIZE, GAP, TEXT_OFFSET, MAX_ENTRIES = |
15, 13, 10, 5, 45 |
local f = CreateFrame( "Frame", "AraBrokerGuildFriends", UIParent ) |
local t = CreateFrame"Frame" |
local dontShow, block, horde, config, isGuild, tip, tipShown = true |
local defaultConfig = { showGuildNotes = true, showGuildName = true, sortType = "class", sortDESC = false, fontSize=12 } |
local guildEntries, friendEntries, buttons, motd = {}, {} |
local guildEntries, friendEntries, motd, slider, nbEntries = {}, {} |
local sliderValue, hasSlider, ShowTablet = 0 |
local RAID_CLASS_COLORS = CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS |
local format, strfind, strupper, GetGuildRosterInfo, GetFriendInfo, CLASS_BUTTONS, GetDifficultyColor = |
tip:Hide() |
tipShown = false |
if b.index and b.index > 1 then highlight:SetAlpha(0) end |
if not MouseIsOver(f) then block = nil f:Hide() end |
if not MouseIsOver(f) then |
sliderValue = 0 |
block = nil |
f:Hide() |
end |
end |
local function CreateFS( index, parent, justify, anchor ) |
return fs |
end |
buttons = setmetatable( { }, { __index = function( table, key ) |
local function EditMOTD() |
f:Hide() |
block = nil |
GuildMOTDEditButton:Click() |
end |
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 |
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 |
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 |
config.sortDESC = not config.sortDESC |
else |
config.sortType, config.sortDESC = colpos, false |
end |
SortGuildRoster( colpos ) |
elseif button == "MiddleButton" and not isGuild then |
RemoveFriend( self.unit ) |
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 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 |
else |
SetItemRef("player:"..self.unit, "|Hplayer:"..self.unit.."|h["..self.unit.."]|h", "LeftButton") |
end |
end |
local function Scroll(self, delta) |
if slider then slider:SetValue( sliderValue - delta * (IsModifierKeyDown() and 10 or 3) ) end |
end |
local buttons = setmetatable( { }, { __index = function( table, key ) |
local button = CreateFrame( "Button", nil, f ) |
table[key] = button |
button.index = key |
button:RegisterForClicks"AnyUp" |
button:SetScript( "OnEnter", Menu_OnEnter ) |
button:SetScript( "OnLeave", Menu_OnLeave ) |
button:EnableMouseWheel(true) |
button:SetScript( "OnMouseWheel", Scroll) |
button.fontName = CreateFS( key, button, "LEFT" ) |
if key == 0 then |
motd = button |
motd:SetPoint( "TOPLEFT", f, "TOPLEFT", GAP, -GAP ) |
else |
button:SetHeight( BUTTON_HEIGHT ) |
button:SetPoint( "TOPLEFT", buttons[key-1], "BOTTOMLEFT" ) |
-- button:SetPoint( "TOPLEFT", table[key-1], "BOTTOMLEFT" ) |
button.icon = button:CreateTexture() |
button.icon:SetWidth( ICON_SIZE ) button.icon:SetHeight( ICON_SIZE ) |
button.icon:SetPoint( "LEFT", button, "LEFT" ) |
local function SetButtonData( index, name, class, level, zone, notes, rank, inGroup, isGrouped ) |
local button = buttons[index] |
button:Show() |
-- if index > nbEntries then button:Hide() else button:Show() end |
button.fontName:SetText( name or "" ) |
if class then |
if index > 1 then |
return button, button.fontName:GetStringWidth() |
end |
local function EditMOTD() |
f:Hide() |
block = nil |
GuildMOTDEditButton:Click() |
end |
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 |
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 |
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 |
config.sortDESC = not config.sortDESC |
else |
config.sortType, config.sortDESC = colpos, false |
end |
SortGuildRoster( colpos ) |
elseif button == "MiddleButton" and not isGuild then |
RemoveFriend( self.unit ) |
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 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 |
else |
SetItemRef("player:"..self.unit, "|Hplayer:"..self.unit.."|h["..self.unit.."]|h", "LeftButton") |
end |
end |
local function ShowTablet( self, _isGuild, entries ) |
ShowTablet = function( self, _isGuild ) |
f:Show() |
isGuild = _isGuild |
block = block or self |
local entries = isGuild and guildEntries or friendEntries |
local hasEntries = #entries > 0 |
hasSlider = #entries > MAX_ENTRIES |
if not hasEntries then |
entries[1] = new( nil, isGuild and ERR_GUILD_PLAYER_NOT_IN_GUILD or "No friends online.", "" ) |
elseif hasSlider then |
if not slider then |
slider = CreateFrame("Slider", nil, f) |
slider:SetWidth(16) |
slider:SetHeight(BUTTON_HEIGHT*MAX_ENTRIES-1) -- 21 entries |
slider:SetThumbTexture("Interface\\Buttons\\UI-SliderBar-Button-Horizontal") |
slider:SetBackdrop( { |
bgFile = "Interface\\Buttons\\UI-SliderBar-Background", |
edgeFile = "Interface\\Buttons\\UI-SliderBar-Border", |
edgeSize = 8, tile = true, tileSize = 8, |
insets = {left = 3, right = 3, top = 6, bottom = 6} |
} ) |
slider:SetValueStep(1) |
slider:SetScript( "OnLeave", Menu_OnLeave ) |
slider:SetValue(1) |
slider:SetScript( "OnValueChanged", function(self, value) |
if hasSlider then sliderValue = value end |
if block then ShowTablet(block, isGuild) end |
end ) |
end |
slider:SetMinMaxValues( 0, #entries - MAX_ENTRIES ) |
slider:SetValue(sliderValue) |
slider:Show() |
elseif slider then |
slider:Hide() |
end |
nbEntries = math.min( MAX_ENTRIES, #entries ) |
local nameC, levelC, zoneC, notesC, rankC = 0, 0, 0, 0, 0 |
local nameW, levelW, zoneW, notesW, rankW |
local hideNotes = isGuild and not config.showGuildNotes |
local extraHeight = 0 |
local extraHeight, button = 0 |
local isGrouped = GetNumRaidMembers()>0 and UnitInRaid or GetNumPartyMembers()>0 and UnitInParty or nil |
for i, entry in ipairs(entries) do |
for i = 1, #entries do |
local entry = entries[i] |
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]) ) |
button.unit = entry[1] |
button:SetScript( "OnClick", OnGuildmateClick ) |
SetButtonData( 0, "|cffffffffMOTD:|r "..GetGuildRosterMOTD() ) |
if CanEditMOTD() then motd:SetScript( "OnClick", EditMOTD ) end |
motd.fontName:SetWidth( maxWidth ) |
extraHeight = motd.fontName:GetHeight() + BUTTON_HEIGHT |
motd:SetWidth( maxWidth ) |
motd:SetHeight( motd.fontName:GetHeight() + BUTTON_HEIGHT ) |
extraHeight = motd:GetHeight() + BUTTON_HEIGHT |
motd:SetHeight( extraHeight ) |
motd:Show() |
buttons[1]:SetPoint( "TOPLEFT", motd, "BOTTOMLEFT" ) |
else |
buttons[0]:Hide() |
buttons[1]:SetPoint( "TOPLEFT", f, "TOPLEFT", GAP, -GAP ) |
end |
local btn = buttons[1] |
for i=2, #buttons do buttons[i]:Hide() end |
for i=2, nbEntries do |
button = buttons[sliderValue+i] |
button:SetPoint("TOPLEFT", btn, "TOPLEFT", 0, BUTTON_HEIGHT*(1-i)) |
button:Show() |
end |
for i=1, #entries do |
button = buttons[i] |
button:SetWidth( maxWidth ) |
end |
colspace[2], colspace[3], colspace[4], colspace[5], colspace[6] = nameC, levelC, zoneC, notesC, rankC |
f:SetWidth( maxWidth + GAP*2 ) |
f:SetHeight( BUTTON_HEIGHT * ( #entries + (isGuild and hasEntries and -1 or 0) ) + extraHeight + GAP*2 ) |
if slider then slider:SetPoint("TOPRIGHT", buttons[2], "TOPRIGHT", 19 + TEXT_OFFSET, BUTTON_HEIGHT*.5) end |
f:SetWidth( maxWidth + GAP*2 + (hasSlider and 16 + TEXT_OFFSET*2 or 0) ) |
f:SetHeight( BUTTON_HEIGHT * nbEntries + extraHeight + GAP*2 ) |
Menu_OnEnter(self) |
block = block or self |
Menu_OnEnter(block) |
local showBelow = select( 2, block:GetCenter() ) > ( UIParent:GetHeight() / 2 ) |
f:ClearAllPoints() |
f:SetPoint( showBelow and "TOP" or "BOTTOM", block, showBelow and "BOTTOM" or "TOP" ) |
for i=#entries+1, #buttons do buttons[i]:Hide() end |
if not (tipShown or config.hideHints) then ShowBlockHints() end |
end |
function f:FriendsOnEnter() |
if InCombatLockdown() then f:Show() return Menu_OnEnter(f) end |
return ShowTablet( self, false, friendEntries ) |
return ShowTablet( self, false ) |
end |
function f:GuildOnEnter() |
end |
end |
f.GuildBlock.text = IsInGuild() and format(config.hideGuildTotal and" %s%d"or" %s%d/%d", config.showGuildName and GetGuildInfo"player" and GetGuildInfo"player"..": " or "", #guildEntries-1, GetNumGuildMembers(true) ) or "No Guild" |
if dontShow then dontShow = false else return ShowTablet(self, true, guildEntries) end |
if dontShow then dontShow = false else return ShowTablet(self, true) end |
end |
f.GuildBlock.text = format( " %s%d/%d", config.showGuildName and GetGuildInfo"player"..": " or "", #guildEntries-1, GetNumGuildMembers(true) ) |
elseif IsControlKeyDown() then |
config.hideHints = not config.hideHints |
ShowTablet( block, isGuild, isGuild and guildEntries or friendEntries ) |
ShowTablet( block, isGuild ) |
else ToggleFriendsFrame(3) end |
elseif button == "RightButton" and IsShiftKeyDown() then |
config.hideGuildTotal = not config.hideGuildTotal |
f:GuildOnEnter() |
elseif not InCombatLockdown() then |
config.showGuildNotes = not config.showGuildNotes |
ShowTablet( block, true, guildEntries ) |
ShowTablet( block, true ) |
end |
end, |
} ) |
OnClick = function(self, btn) |
if IsControlKeyDown() then |
config.hideHints = not config.hideHints |
ShowTablet( block, isGuild, isGuild and guildEntries or friendEntries ) |
ShowTablet( block, isGuild ) |
elseif IsShiftKeyDown() then |
config.hideTotalFriends = not config.hideTotalFriends |
f:FRIENDLIST_UPDATE() |
## Interface: 30200 |
## Title: |cFFFFB366Ara|r - Broker - Guild & Friends |
## Version: r19 |
## Version: r20 |
## Author: Ara |
## Notes: A Data Broker plugin that provides guildmates & friends informations and interactions. |
## SavedVariables: AraBrokerGuildFriendsDB |