ShadowTheAge@1: CrossRealmAssist = LibStub("AceAddon-3.0"):NewAddon("CrossRealmAssist", "AceEvent-3.0", "AceConsole-3.0", "AceTimer-3.0") ShadowTheAge@1: local AceGUI = LibStub("AceGUI-3.0") ShadowTheAge@1: local addon = CrossRealmAssist; ShadowTheAge@1: local wholib = LibStub:GetLibrary('LibWho-2.0'):Library() ShadowTheAge@1: ShadowTheAge@1: local hgroup, lfgContainer, currealm, partyrealm, recrealm, curRealmStat, homeRealm, realmSep, gui, leavebtn ShadowTheAge@1: ShadowTheAge@1: local scanstate=0 ShadowTheAge@1: local recentRealms={} ShadowTheAge@1: local active=false ShadowTheAge@1: ShadowTheAge@1: local lfgGroups={ ShadowTheAge@1: 6, -- Custom ShadowTheAge@1: 10, -- Ashran ShadowTheAge@1: 1, -- Quests ShadowTheAge@1: 3, -- Raids ShadowTheAge@1: 8 -- BGs ShadowTheAge@1: } ShadowTheAge@1: ShadowTheAge@1: local lfgTabs ShadowTheAge@1: local curLfgGroup ShadowTheAge@1: local sheduledScan ShadowTheAge@1: local wasInGroup ShadowTheAge@1: local lfgScanInProgress=false ShadowTheAge@1: ShadowTheAge@1: function addon:OnInitialize() ShadowTheAge@1: ShadowTheAge@1: end ShadowTheAge@1: ShadowTheAge@1: function addon:OnEnable() ShadowTheAge@1: local tabCount = table.getn(lfgGroups) ShadowTheAge@1: lfgTabs = {} ShadowTheAge@1: for i=1,tabCount do ShadowTheAge@1: local cat = lfgGroups[i] ShadowTheAge@1: table.insert(lfgTabs,{value=cat,text=(C_LFGList.GetCategoryInfo(cat))}) ShadowTheAge@1: end ShadowTheAge@1: realmSep = _G.REALM_SEPARATORS ShadowTheAge@1: homeRealm = GetRealmName() ShadowTheAge@1: addon:RegisterChatCommand("cra", "Activate") ShadowTheAge@1: addon:RegisterChatCommand("crossrealmassist", "Activate") ShadowTheAge@1: end ShadowTheAge@1: ShadowTheAge@1: function addon:OnDisable() ShadowTheAge@1: addon:Deactivate() ShadowTheAge@1: end ShadowTheAge@1: ShadowTheAge@1: function addon:Activate() ShadowTheAge@1: if active then return end ShadowTheAge@1: active=true ShadowTheAge@1: wasInGroup = IsInGroup() ShadowTheAge@1: addon:CreateUI() ShadowTheAge@1: addon:ScanRealm() ShadowTheAge@1: addon:RegisterEvent("ZONE_CHANGED_NEW_AREA", "SheduleScan") ShadowTheAge@1: addon:RegisterEvent("LFG_LIST_SEARCH_RESULTS_RECEIVED", "LfgResponseData") ShadowTheAge@1: addon:RegisterEvent("LFG_LIST_SEARCH_FAILED", "LfgScanFailed") ShadowTheAge@1: addon:RegisterEvent("GROUP_ROSTER_UPDATE", "updatePartyInfo") ShadowTheAge@1: addon:RegisterEvent("LFG_LIST_APPLICATION_STATUS_UPDATED", "updateAppStatus") ShadowTheAge@1: end ShadowTheAge@1: ShadowTheAge@1: function addon:Deactivate() ShadowTheAge@1: if not active then return end ShadowTheAge@1: active = false ShadowTheAge@1: scanstate = 0 ShadowTheAge@1: lfgScanInProgress = false ShadowTheAge@1: gui:Release(); ShadowTheAge@1: gui, lfgContainer, hgroup, currealm, partyrealm, recrealm, leavebtn = nil,nil,nil,nil,nil,nil,nil ShadowTheAge@1: addon:UnregisterEvent("ZONE_CHANGED_NEW_AREA") ShadowTheAge@1: addon:UnregisterEvent("PLAYER_REGEN_ENABLED") ShadowTheAge@1: addon:UnregisterEvent("LFG_LIST_SEARCH_RESULTS_RECEIVED") ShadowTheAge@1: addon:UnregisterEvent("LFG_LIST_SEARCH_FAILED") ShadowTheAge@1: addon:UnregisterEvent("GROUP_ROSTER_UPDATE") ShadowTheAge@1: addon:UnregisterEvent("LFG_LIST_APPLICATION_STATUS_UPDATED") ShadowTheAge@1: end ShadowTheAge@1: ShadowTheAge@1: function addon:CreateUI() ShadowTheAge@1: gui = addon:AddUI(nil,"Window",{SetTitle="Cross Realm Assist",EnableResize=false,SetLayout="Flow"},true,{OnClose=addon.Deactivate}) ShadowTheAge@1: ShadowTheAge@1: local tabgroup = addon:AddUI(gui,"TabGroup",{SetFullHeight=true,SetTabs=lfgTabs,SetLayout="Fill"},true,{OnGroupSelected=addon.LfgScan}) ShadowTheAge@1: tabgroup:SelectTab(lfgGroups[1]) ShadowTheAge@1: lfgContainer = addon:AddUI(tabgroup,"ScrollFrame") ShadowTheAge@1: ShadowTheAge@1: local hgroupc = addon:AddUI(gui,"InlineGroup",{SetLayout="Fill",SetFullHeight=true,SetTitle="Realm info"},true) ShadowTheAge@1: hgroup = addon:AddUI(hgroupc,"ScrollFrame") ShadowTheAge@1: ShadowTheAge@1: addon:AddUI(hgroup,"Heading",{SetText="Current realm"}) ShadowTheAge@1: currealm = addon:AddUI(hgroup,"SimpleGroup"); ShadowTheAge@1: addon:AddUI(hgroup,"Button",{SetText="Refresh",SetRelativeWidth=0.5,SetHeight=20},true,{OnClick=addon.ScanRealm}) ShadowTheAge@1: ShadowTheAge@1: addon:AddUI(hgroup,"Heading",{SetText="Party statistics"}) ShadowTheAge@1: partyrealm = addon:AddUI(hgroup,"SimpleGroup"); ShadowTheAge@1: leavebtn = addon:AddUI(hgroup,"Button",{SetText="Leave",SetRelativeWidth=0.5,SetHeight=20,SetDisabled=not IsInGroup()},true,{OnClick=LeaveParty}) ShadowTheAge@1: ShadowTheAge@1: addon:AddUI(hgroup,"Heading",{SetText="Recent realms"}) ShadowTheAge@1: recrealm = addon:AddUI(hgroup,"SimpleGroup"); ShadowTheAge@1: addon:AddUI(hgroup,"Button",{SetText="Clear",SetRelativeWidth=0.5,SetHeight=20},true,{OnClick=addon.ClearRecentRealms}) ShadowTheAge@1: ShadowTheAge@1: gui:DoLayout() ShadowTheAge@1: gui:PauseLayout() ShadowTheAge@1: ShadowTheAge@1: tabgroup:SetPoint("BOTTOMRIGHT", gui.content, "BOTTOMRIGHT", -200, 0) ShadowTheAge@1: hgroupc:SetPoint("TOPLEFT", gui.content, "TOPRIGHT", -200, 0) ShadowTheAge@1: hgroupc:SetPoint("BOTTOMRIGHT", gui.content, "BOTTOMRIGHT") ShadowTheAge@1: ShadowTheAge@1: if curRealmStat then addon:updateCurrentRealm() end ShadowTheAge@1: addon:updatePartyInfo() ShadowTheAge@1: addon:updateRecentRealms() ShadowTheAge@1: end ShadowTheAge@1: ShadowTheAge@1: -- LFG scanning routine ShadowTheAge@1: ShadowTheAge@1: function addon.refreshLfgCurrent() ShadowTheAge@1: addon.LfgScan(nil,nil,curLfgGroup) ShadowTheAge@1: end ShadowTheAge@1: ShadowTheAge@1: function addon.LfgScan(widget, callback, tab) ShadowTheAge@1: if not tab then return end ShadowTheAge@1: lfgScanInProgress = true ShadowTheAge@1: if lfgContainer then lfgContainer:ReleaseChildren() end ShadowTheAge@1: curLfgGroup = tab ShadowTheAge@1: C_LFGList.Search(curLfgGroup,"") ShadowTheAge@1: end ShadowTheAge@1: ShadowTheAge@1: function addon:LfgScanFailed(event, reason) ShadowTheAge@1: print("scan failed "..reason) ShadowTheAge@1: if reason == "throttled" then ShadowTheAge@1: addon:ScheduleTimer(addon.LfgScan, 2, nil, nil, curLfgGroup) ShadowTheAge@1: end ShadowTheAge@1: end ShadowTheAge@1: ShadowTheAge@1: local function WeightLfgItem(item) ShadowTheAge@1: local leaderRealm = 3 ShadowTheAge@1: if (item.realm ~= "???") then leaderRealm = (5 - (recentRealms[item.realm] or 0)) end ShadowTheAge@1: local weight = ShadowTheAge@1: (item.autoinv and 5 or 2) * ShadowTheAge@1: ((item.friends > 0) and 2 or 3) * ShadowTheAge@1: ((item.ilvl > 0) and 2 or 3) * ShadowTheAge@1: ((item.voice ~= "") and 2 or 4) ShadowTheAge@1: local count = item.pcount; ShadowTheAge@1: local countWeight ShadowTheAge@1: if count >= 39 or count <= 1 then countWeight = 1 ShadowTheAge@1: elseif count >= 35 or count <= 4 then countWeight = 2 ShadowTheAge@1: elseif count >= 30 or count <= 10 then countWeight = 3 ShadowTheAge@1: else countWeight = 4 end ShadowTheAge@1: return weight * leaderRealm * countWeight; ShadowTheAge@1: end ShadowTheAge@1: ShadowTheAge@1: function addon:LfgResponseData() ShadowTheAge@1: lfgScanInProgress = false; ShadowTheAge@1: addon:UpdateCurrentLfgInfo() ShadowTheAge@1: end ShadowTheAge@1: ShadowTheAge@1: function addon:UpdateCurrentLfgInfo(repeated) ShadowTheAge@1: if lfgScanInProgress then return end ShadowTheAge@1: local count, list = C_LFGList.GetSearchResults() ShadowTheAge@1: local lfgList = {} ShadowTheAge@1: local lfgEntries = 0 ShadowTheAge@1: local hasUnknowns = false ShadowTheAge@1: for i = 1,count do ShadowTheAge@1: local rid = list[i]; ShadowTheAge@1: if not rid then break end ShadowTheAge@1: local _, action, caption, desc, voice, ilvl, time, bnetfr, charfr, guild, delisted, fullname, pcount, autoinv = C_LFGList.GetSearchResultInfo(rid) ShadowTheAge@1: if not fullname then ShadowTheAge@1: fullname = "???-???" ShadowTheAge@1: hasUnknowns = true ShadowTheAge@1: end ShadowTheAge@1: if not delisted then ShadowTheAge@1: local pname, realm = strsplit(realmSep, fullname) ShadowTheAge@1: realm = realm or homeRealm ShadowTheAge@1: local item = { ShadowTheAge@1: rid=rid, ShadowTheAge@1: action=action, ShadowTheAge@1: caption=caption, ShadowTheAge@1: desc=desc, ShadowTheAge@1: ilvl=ilvl, ShadowTheAge@1: voice=voice, ShadowTheAge@1: time=time, ShadowTheAge@1: friends=bnetfr+charfr+guild, ShadowTheAge@1: name=pname, ShadowTheAge@1: realm = realm, ShadowTheAge@1: pcount=pcount, ShadowTheAge@1: autoinv=autoinv ShadowTheAge@1: } ShadowTheAge@1: item.weight = WeightLfgItem(item) ShadowTheAge@1: table.insert(lfgList, item) ShadowTheAge@1: lfgEntries = lfgEntries + 1 ShadowTheAge@1: end ShadowTheAge@1: end ShadowTheAge@1: addon:refreshLFGList(lfgList, lfgEntries); ShadowTheAge@1: if hasUnknowns and repeated ~= true then addon:ScheduleTimer("UpdateCurrentLfgInfo", 1, true) end ShadowTheAge@1: end ShadowTheAge@1: ShadowTheAge@1: function addon:refreshLFGList(list, count) ShadowTheAge@1: if not lfgContainer then return end ShadowTheAge@1: lfgContainer:PauseLayout() ShadowTheAge@1: lfgContainer:ReleaseChildren() ShadowTheAge@1: table.sort(list, addon.SortLfgItems) ShadowTheAge@1: ShadowTheAge@1: local canJoin = addon.canJoinGroup() ShadowTheAge@1: ShadowTheAge@1: for i=1,count do ShadowTheAge@1: local data = list[i]; ShadowTheAge@1: local renderer = addon:AddUI(lfgContainer,"SimpleGroup",{SetLayout="Flow",SetHeight=20,SetAutoAdjustHeight=false}); ShadowTheAge@1: ShadowTheAge@1: addon:AddUI(renderer,"Label",{SetText=data.caption,SetRelativeWidth=0.4},true) ShadowTheAge@1: addon:AddUI(renderer,"Label",{SetText=data.pcount,SetRelativeWidth=0.05},true) ShadowTheAge@1: local realm = addon:AddUI(renderer,"Label",{SetText=data.realm,SetRelativeWidth=0.25},true) ShadowTheAge@1: if recentRealms[data.realm] then ShadowTheAge@1: local r,g,b = GetItemQualityColor(recentRealms[data.realm]); ShadowTheAge@1: realm:SetColor(r,g,b) ShadowTheAge@1: end ShadowTheAge@1: ShadowTheAge@1: local tooltip = {} ShadowTheAge@1: if data.voice ~= "" then table.insert(tooltip,"Voice: "..data.voice) end ShadowTheAge@1: if data.friends > 0 then table.insert(tooltip,"Friends: "..data.friends) end ShadowTheAge@1: if data.ilvl > 0 then table.insert(tooltip,"Min. Ilvl: "..data.ilvl) end ShadowTheAge@1: addon:AddIcon(renderer, "Interface/GossipFrame/ActiveQuestIcon", 16, tooltip[1] ~= nil, tooltip) ShadowTheAge@1: addon:AddIcon(renderer, READY_CHECK_READY_TEXTURE, 16, data.autoinv, {"Auto invite!"}) ShadowTheAge@1: local btn = addon:AddUI(renderer,"Button",{SetText="Join",SetRelativeWidth=0.2,SetHeight=20,SetDisabled=not canJoin},true,{OnClick=addon.joinGroup}) ShadowTheAge@1: btn:SetUserData('rid',data.rid) ShadowTheAge@1: end ShadowTheAge@1: addon:AddUI(lfgContainer,"Button",{SetText="Refresh",SetWidth=100,SetHeight=20},true,{OnClick=addon.refreshLfgCurrent}) ShadowTheAge@1: ShadowTheAge@1: lfgContainer:ResumeLayout() ShadowTheAge@1: lfgContainer:DoLayout() ShadowTheAge@1: end ShadowTheAge@1: ShadowTheAge@1: function addon.SortLfgItems(a,b) ShadowTheAge@1: return a.weight > b.weight ShadowTheAge@1: end ShadowTheAge@1: ShadowTheAge@1: function addon.canJoinGroup() ShadowTheAge@1: return (not IsInGroup()) or (UnitIsGroupLeader('player') and not IsInRaid()) ShadowTheAge@1: end ShadowTheAge@1: ShadowTheAge@1: function addon.joinGroup(widget) ShadowTheAge@1: if not addon.canJoinGroup() then return end ShadowTheAge@1: local rid = widget:GetUserData('rid'); ShadowTheAge@1: widget:SetDisabled(true) ShadowTheAge@1: C_LFGList.ApplyToGroup(rid, "", C_LFGList.GetAvailableRoles()) ShadowTheAge@1: end ShadowTheAge@1: ShadowTheAge@1: function addon:updateAppStatus(event, id, status, oldstatus) ShadowTheAge@1: if status == "invited" then ShadowTheAge@1: LFGListInviteDialog_Accept(LFGListInviteDialog) ShadowTheAge@1: end ShadowTheAge@1: end ShadowTheAge@1: ShadowTheAge@1: -- Zone scanning routine ShadowTheAge@1: ShadowTheAge@1: function addon:LeaveCombat() ShadowTheAge@1: addon:UnregisterEvent("PLAYER_REGEN_ENABLED") ShadowTheAge@1: scanstate = 0 ShadowTheAge@1: addon:ScanRealm(); ShadowTheAge@1: end ShadowTheAge@1: ShadowTheAge@1: function addon:ScanRealm() ShadowTheAge@1: if scanstate > 0 then return end ShadowTheAge@1: if InCombatLockdown() then ShadowTheAge@1: addon:RegisterEvent("PLAYER_REGEN_ENABLED","LeaveCombat") ShadowTheAge@1: scanstate = 1 ShadowTheAge@1: addon:AddLabel(currealm, "Scan sheduled after combat...", 3); ShadowTheAge@1: return ShadowTheAge@1: end ShadowTheAge@1: scanstate = 2 ShadowTheAge@1: addon:AddLabel(currealm, "Scanning...", 3); ShadowTheAge@1: local searchString = _G.WHO_TAG_ZONE .. '"' .. GetZoneText() .. '"'; ShadowTheAge@1: wholib:Who(searchString, {callback = "ScanResult", handler=addon}) ShadowTheAge@1: end ShadowTheAge@1: ShadowTheAge@1: function addon:ScanResult(query, results, complete) ShadowTheAge@1: local realms = {} ShadowTheAge@1: for _, player in ipairs(results) do ShadowTheAge@1: addon:AddRealmStat(player.Name, realms); ShadowTheAge@1: end ShadowTheAge@1: curRealmStat = addon:GetRealmStat(realms); ShadowTheAge@1: addon:updateCurrentRealm(); ShadowTheAge@1: local rescan = scanstate == 3 ShadowTheAge@1: scanstate = 0; ShadowTheAge@1: if rescan then addon:ScanRealm() end ShadowTheAge@1: end ShadowTheAge@1: ShadowTheAge@1: function addon:AddRealmStat(name, realms) ShadowTheAge@1: local _, realm = strsplit(realmSep, name) -- TODO exclude self ShadowTheAge@1: realm = realm or homeRealm ShadowTheAge@1: realms[realm] = (realms[realm] or 0) + 1 ShadowTheAge@1: end ShadowTheAge@1: ShadowTheAge@1: function addon:AddUnitIdStat(unitid, realms) ShadowTheAge@1: local name, realm = UnitName(unitid); ShadowTheAge@1: if not name then return end ShadowTheAge@1: if realm == "" then realm = homeRealm end ShadowTheAge@1: realm = realm or homeRealm ShadowTheAge@1: realms[realm] = (realms[realm] or 0) + 1 ShadowTheAge@1: end ShadowTheAge@1: ShadowTheAge@1: function addon:GetRealmStat(realms) ShadowTheAge@1: local rcount = 0; ShadowTheAge@1: local stat = {}; ShadowTheAge@1: local pcount = 0; ShadowTheAge@1: for realm,count in pairs(realms) do ShadowTheAge@1: table.insert(stat,{realm=realm,count=count}) ShadowTheAge@1: rcount = rcount + 1; ShadowTheAge@1: pcount = pcount + count; ShadowTheAge@1: end ShadowTheAge@1: if rcount > 1 then ShadowTheAge@1: table.sort(stat, function(a,b) return a.count > b.count end) ShadowTheAge@1: stat.max = stat[1].count ShadowTheAge@1: else stat.max = 0 end ShadowTheAge@1: stat.players = pcount; ShadowTheAge@1: stat.realms = rcount; ShadowTheAge@1: return stat; ShadowTheAge@1: end ShadowTheAge@1: ShadowTheAge@1: function addon:updateCurrentRealm() ShadowTheAge@1: if not currealm then return end ShadowTheAge@1: currealm:ReleaseChildren() ShadowTheAge@1: if curRealmStat.players < 5 then ShadowTheAge@1: addon:AddLabel(currealm, "Not enough players", 0); ShadowTheAge@1: end ShadowTheAge@1: local sureplayers = curRealmStat.players/2 ShadowTheAge@1: local maybeplayers = math.max(curRealmStat.max/4, 3) ShadowTheAge@1: local recentRealmUpdated = false ShadowTheAge@1: for i=1,curRealmStat.realms do ShadowTheAge@1: local data = curRealmStat[i] ShadowTheAge@1: if data.count >= maybeplayers then ShadowTheAge@1: local realm = data.realm ShadowTheAge@1: local rvalue = (data.count >= sureplayers) and 4 or 2 ShadowTheAge@1: if (rvalue > (recentRealms[realm] or 0)) then ShadowTheAge@1: recentRealmUpdated = true ShadowTheAge@1: recentRealms[realm] = rvalue ShadowTheAge@1: end ShadowTheAge@1: end ShadowTheAge@1: end ShadowTheAge@1: addon:addLabels(currealm, curRealmStat, sureplayers, maybeplayers, 3, "Realm unknown"); ShadowTheAge@1: if recentRealmUpdated then ShadowTheAge@1: addon:UpdateCurrentLfgInfo() ShadowTheAge@1: addon:updateRecentRealms() ShadowTheAge@1: end ShadowTheAge@1: end ShadowTheAge@1: ShadowTheAge@1: function addon:addLabels(container, stats, epict, whitet, grayt, emptytext) ShadowTheAge@1: if stats.realms == 0 then ShadowTheAge@1: addon:AddLabel(container, emptytext) ShadowTheAge@1: else ShadowTheAge@1: local players = stats.players ShadowTheAge@1: local pleft = players; ShadowTheAge@1: for i=1,stats.realms do ShadowTheAge@1: local data = stats[i] ShadowTheAge@1: local count = data.count; ShadowTheAge@1: local percent = math.ceil(100 * count / players - 0.5) ShadowTheAge@1: local label = data.realm .. " (" .. percent .. "%)"; ShadowTheAge@1: local color ShadowTheAge@1: if count < grayt then break ShadowTheAge@1: elseif count < whitet then color = 1 ShadowTheAge@1: elseif count < epict then color = 2 ShadowTheAge@1: else color = 4 end ShadowTheAge@1: pleft = pleft - count ShadowTheAge@1: addon:AddLabel(container, label, color); ShadowTheAge@1: end ShadowTheAge@1: if pleft > 0 then ShadowTheAge@1: addon:AddLabel(container, "Other" .. " (" .. math.ceil(100 * pleft / players - 0.5) .. "%)", 0); ShadowTheAge@1: end ShadowTheAge@1: end ShadowTheAge@1: end ShadowTheAge@1: ShadowTheAge@1: function addon:updateRecentRealms() ShadowTheAge@1: if not recrealm then return end ShadowTheAge@1: recrealm:ReleaseChildren() ShadowTheAge@1: local nothing = true; ShadowTheAge@1: for realm,color in pairs(recentRealms) do ShadowTheAge@1: addon:AddLabel(recrealm, realm,color); ShadowTheAge@1: nothing = false; ShadowTheAge@1: end ShadowTheAge@1: if nothing then ShadowTheAge@1: addon:AddLabel(recrealm, "No recent realms"); ShadowTheAge@1: end ShadowTheAge@1: end ShadowTheAge@1: ShadowTheAge@1: function addon:ClearRecentRealms() ShadowTheAge@1: recentRealms = {} ShadowTheAge@1: addon:UpdateCurrentLfgInfo() ShadowTheAge@1: addon:updateRecentRealms() ShadowTheAge@1: end ShadowTheAge@1: ShadowTheAge@1: function addon:SheduleScan() ShadowTheAge@1: if scanstate == 0 then ShadowTheAge@1: addon:ScanRealm() ShadowTheAge@1: elseif scanstate == 2 then ShadowTheAge@1: scanstate = 3 ShadowTheAge@1: end ShadowTheAge@1: end ShadowTheAge@1: ShadowTheAge@1: function addon:updatePartyInfo() ShadowTheAge@1: if not partyrealm then return end ShadowTheAge@1: partyrealm:ReleaseChildren() ShadowTheAge@1: local realms = {} ShadowTheAge@1: local inGroup = IsInGroup() ShadowTheAge@1: if IsInGroup() then ShadowTheAge@1: if IsInRaid() then ShadowTheAge@1: for i=1, MAX_RAID_MEMBERS do ShadowTheAge@1: addon:AddUnitIdStat("raid"..i, realms) ShadowTheAge@1: end ShadowTheAge@1: else ShadowTheAge@1: for i=1, MAX_PARTY_MEMBERS do ShadowTheAge@1: addon:AddUnitIdStat("party"..i, realms) ShadowTheAge@1: end ShadowTheAge@1: end ShadowTheAge@1: end ShadowTheAge@1: if inGroup ~= wasInGroup then ShadowTheAge@1: addon:SheduleScan() ShadowTheAge@1: wasInGroup = inGroup ShadowTheAge@1: addon:UpdateCurrentLfgInfo() ShadowTheAge@1: leavebtn:SetDisabled(not inGroup) ShadowTheAge@1: end ShadowTheAge@1: local partyStat = addon:GetRealmStat(realms); ShadowTheAge@1: addon:addLabels(partyrealm, partyStat, partyStat.players/2, 2, 0, "Not in party"); ShadowTheAge@1: end ShadowTheAge@1: ShadowTheAge@1: -- Utils functions ShadowTheAge@1: ShadowTheAge@1: function addon:AddUI(owner, type, parameters, manual, callbacks) ShadowTheAge@1: local ui = AceGUI:Create(type) ShadowTheAge@1: if parameters then ShadowTheAge@1: for key,value in pairs(parameters) do ui[key](ui,value) end ShadowTheAge@1: end ShadowTheAge@1: if callbacks then ShadowTheAge@1: for key,value in pairs(callbacks) do ui:SetCallback(key,value) end ShadowTheAge@1: end ShadowTheAge@1: if not manual then ui:SetFullWidth(true) end ShadowTheAge@1: if owner then owner:AddChild(ui) end ShadowTheAge@1: return ui ShadowTheAge@1: end ShadowTheAge@1: ShadowTheAge@1: function addon:AddLabel(owner, text, color, icon) ShadowTheAge@1: local label = AceGUI:Create("Label") ShadowTheAge@1: label:SetText(text) ShadowTheAge@1: label:SetFullWidth(true) ShadowTheAge@1: if color ~= nil then ShadowTheAge@1: local r,g,b = GetItemQualityColor(color); ShadowTheAge@1: label:SetColor(r,g,b) ShadowTheAge@1: end ShadowTheAge@1: owner:AddChild(label) ShadowTheAge@1: return label ShadowTheAge@1: end ShadowTheAge@1: ShadowTheAge@1: function addon:AddIcon(owner, image, size, visible, tooltip) ShadowTheAge@1: if visible ~= false then ShadowTheAge@1: local icon = addon:AddUI(owner,"Icon",{SetWidth=size,SetHeight=size},true) ShadowTheAge@1: icon:SetImage(image) ShadowTheAge@1: icon:SetImageSize(size,size) ShadowTheAge@1: if tooltip then ShadowTheAge@1: icon:SetUserData('tooltip',tooltip) ShadowTheAge@1: icon:SetCallback("OnEnter",addon.ShowTooltip) ShadowTheAge@1: icon:SetCallback("OnLeave",addon.HideTooltip) ShadowTheAge@1: end ShadowTheAge@1: else -- add placeholder ShadowTheAge@1: addon:AddUI(owner,"Label",{SetWidth=size,SetHeight=size},true) ShadowTheAge@1: end ShadowTheAge@1: end ShadowTheAge@1: ShadowTheAge@1: function addon.ShowTooltip(widget) ShadowTheAge@1: GameTooltip:SetOwner(widget.frame, "ANCHOR_TOP") ShadowTheAge@1: local tooltip = widget:GetUserData('tooltip') ShadowTheAge@1: for i=1,#tooltip do ShadowTheAge@1: GameTooltip:AddLine(tooltip[i], 1, 1, 1) ShadowTheAge@1: end ShadowTheAge@1: GameTooltip:Show() ShadowTheAge@1: end ShadowTheAge@1: ShadowTheAge@1: function addon.HideTooltip(widget) ShadowTheAge@1: GameTooltip:Hide() ShadowTheAge@1: end