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