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@11: local homeRealm, realmSep, gui, btRefresh, btQuick, btManual, lbRealm, lbStatus, playerName ShadowTheAge@0: ShadowTheAge@11: local curRealmStat 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@11: local wasInInstance ShadowTheAge@0: local lfgScanInProgress=false ShadowTheAge@0: ShadowTheAge@11: local function setupWidget(widget, parameters, x, y) ShadowTheAge@11: if parameters then ShadowTheAge@11: for key,value in pairs(parameters) do widget[key](widget,value) end ShadowTheAge@11: end ShadowTheAge@11: if y then ShadowTheAge@11: widget:SetPoint("TOPLEFT",widget:GetParent(),"TOPLEFT",x,-y) ShadowTheAge@11: end ShadowTheAge@11: return widget ShadowTheAge@11: end ShadowTheAge@11: ShadowTheAge@11: local function ShowTooltip(widget) ShadowTheAge@11: GameTooltip:SetOwner(widget, widget.TooltipAnchor) ShadowTheAge@11: GameTooltip:ClearLines() ShadowTheAge@11: widget:TooltipFactory() ShadowTheAge@11: GameTooltip:Show() ShadowTheAge@11: end ShadowTheAge@11: ShadowTheAge@11: local function HideTooltip(widget) ShadowTheAge@11: GameTooltip:Hide() ShadowTheAge@11: end ShadowTheAge@11: ShadowTheAge@11: local function setupTooltip(widget, anchor, factory) ShadowTheAge@11: widget.TooltipAnchor = anchor; ShadowTheAge@11: widget.TooltipFactory = factory; ShadowTheAge@11: widget:SetScript("OnEnter", ShowTooltip) ShadowTheAge@11: widget:SetScript("OnLeave", HideTooltip) ShadowTheAge@11: end ShadowTheAge@11: 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@11: playerName = UnitName("player") ShadowTheAge@0: homeRealm = GetRealmName() ShadowTheAge@0: addon:RegisterChatCommand("cra", "Activate") ShadowTheAge@0: addon:RegisterChatCommand("crossrealmassist", "Activate") ShadowTheAge@11: ShadowTheAge@11: addon:ScheduleTimer("Activate", 0.5) 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@11: if not gui then addon:CreateUI() end ShadowTheAge@11: addon:updateCurrentRealm(); ShadowTheAge@11: addon:ForceRefreshZone(); ShadowTheAge@11: gui:Show() ShadowTheAge@11: addon:RegisterEvent("ZONE_CHANGED_NEW_AREA", "ForceRefreshZone") ShadowTheAge@11: addon:RegisterEvent("SCENARIO_UPDATE", "ForceRefreshZone") ShadowTheAge@11: --addon:RegisterEvent("LFG_LIST_SEARCH_RESULTS_RECEIVED", "LfgResponseData") ShadowTheAge@11: --addon:RegisterEvent("LFG_LIST_SEARCH_FAILED", "LfgScanFailed") ShadowTheAge@11: --addon:RegisterEvent("GROUP_ROSTER_UPDATE", "updatePartyInfo") ShadowTheAge@11: --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: 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@11: function addon:SetStatus(status) ShadowTheAge@11: if status then ShadowTheAge@11: lbStatus:SetText(status) ShadowTheAge@11: else ShadowTheAge@11: lbStatus:SetText("") -- TODO ShadowTheAge@11: end ShadowTheAge@11: end ShadowTheAge@11: ShadowTheAge@0: function addon:CreateUI() ShadowTheAge@11: gui = setupWidget(CreateFrame("Frame",nil,nil,"InsetFrameTemplate3"), {SetFrameStrata="DIALOG",SetWidth=208,SetHeight=60,EnableMouse=true,SetMovable=true}) ShadowTheAge@11: local title = setupWidget(CreateFrame("Frame",nil,gui), {SetWidth=190,SetHeight=18,EnableMouse=true,RegisterForDrag="LeftButton"}, 0, 6); ShadowTheAge@11: title:SetScript("OnDragStart", function() gui:StartMoving() end) ShadowTheAge@11: title:SetScript("OnDragStop", function() gui:StopMovingOrSizing() end) ShadowTheAge@11: gui:SetScript("OnHide", addon.Deactivate) ShadowTheAge@11: setupTooltip(title, "ANCHOR_TOP", addon.realmToolip) ShadowTheAge@11: ShadowTheAge@11: lbRealm = setupWidget(gui:CreateFontString(nil,"BACKGROUND", "GameFontNormal"), {SetWidth=200,SetHeight=18}, 0, 6) ShadowTheAge@11: lbStatus = setupWidget(gui:CreateFontString(nil,"BACKGROUND", "GameFontHighlightSmallLeft"), {SetWidth=200,SetHeight=10}, 6, 23) ShadowTheAge@11: ShadowTheAge@11: btQuick = setupWidget(CreateFrame("Button",nil,gui,"UIMenuButtonStretchTemplate"),{EnableMouse=true,SetWidth=90,SetHeight=20,SetText="Quick join"},4,36) ShadowTheAge@11: btManual = setupWidget(CreateFrame("Button",nil,gui,"UIMenuButtonStretchTemplate"),{EnableMouse=true,SetWidth=90,SetHeight=20,SetText="Manual join"},94,36) ShadowTheAge@11: setupWidget(CreateFrame("Button",nil,gui,"UIPanelCloseButton"),{EnableMouse=true,SetWidth=20,SetHeight=20},188,0) ShadowTheAge@11: ShadowTheAge@11: btRefresh = setupWidget(CreateFrame("Button",nil,gui,"UIPanelSquareButton"),{EnableMouse=true,SetWidth=20,SetHeight=20},184,36) ShadowTheAge@11: btRefresh.icon:SetTexture("Interface/BUTTONS/UI-RefreshButton") ShadowTheAge@11: btRefresh.icon:SetTexCoord(0,1,0,1); ShadowTheAge@11: btRefresh:SetScript("OnClick",addon.RefreshZone) ShadowTheAge@11: ShadowTheAge@11: gui:SetPoint("CENTER",0,0) ShadowTheAge@11: ShadowTheAge@11: --[[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@11: addon:updateRecentRealms()]] ShadowTheAge@0: end ShadowTheAge@0: ShadowTheAge@0: -- LFG scanning routine ShadowTheAge@0: ShadowTheAge@11: --[[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@11: 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@11: function addon:ForceRefreshZone() ShadowTheAge@11: addon:RefreshZone(true) ShadowTheAge@11: end ShadowTheAge@11: ShadowTheAge@11: function addon:RefreshZone(shedule) ShadowTheAge@11: local inst, instType = IsInInstance() ShadowTheAge@11: if (inst or instType ~= "none") then ShadowTheAge@11: lbRealm:SetText("Instanced zone") ShadowTheAge@11: curRealmStat = nil ShadowTheAge@11: btQuick:Disable() ShadowTheAge@11: else ShadowTheAge@11: btQuick:Enable() ShadowTheAge@11: if scanstate == 0 then ShadowTheAge@11: addon:ScanRealm() ShadowTheAge@11: elseif shedule == true and scanstate == 2 then ShadowTheAge@11: addon:SetStatus("Rescan sheduled...") ShadowTheAge@11: scanstate = 3 ShadowTheAge@11: end ShadowTheAge@11: end ShadowTheAge@11: end ShadowTheAge@11: 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@11: addon:SetStatus("Scan sheduled after combat..."); ShadowTheAge@0: return ShadowTheAge@0: end ShadowTheAge@0: scanstate = 2 ShadowTheAge@11: addon:SetStatus("Scanning current realm..."); 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@11: curRealmStat.complete = complete 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@11: if (name == playerName) then return end ShadowTheAge@11: local _, realm = strsplit(realmSep, name) 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@11: addon:SetStatus(); ShadowTheAge@11: if not curRealmStat or curRealmStat.realms < 1 then ShadowTheAge@11: lbRealm:SetText("Unknown realm (No players)") ShadowTheAge@11: return; ShadowTheAge@0: end ShadowTheAge@11: ShadowTheAge@11: local bestRealm = curRealmStat[1] ShadowTheAge@11: local prevThreshold = math.min(bestRealm.count/3,5) ShadowTheAge@11: local mixCount = 0 ShadowTheAge@11: for i=2,curRealmStat.realms do ShadowTheAge@0: local data = curRealmStat[i] ShadowTheAge@11: if data.count >= prevThreshold then ShadowTheAge@11: mixCount = mixCount + 1 ShadowTheAge@11: prevThreshold = math.min(data.count/3,5) ShadowTheAge@0: end ShadowTheAge@0: end ShadowTheAge@11: curRealmStat.threshold = prevThreshold ShadowTheAge@11: ShadowTheAge@11: if (mixCount > 0) then ShadowTheAge@11: lbRealm:SetText("Mixed "..bestRealm.realm.." +"..mixCount) ShadowTheAge@11: else ShadowTheAge@11: lbRealm:SetText(bestRealm.realm) ShadowTheAge@0: end ShadowTheAge@0: end ShadowTheAge@0: ShadowTheAge@11: function addon:realmToolip() ShadowTheAge@11: if not curRealmStat then return end ShadowTheAge@11: local players = curRealmStat.players; ShadowTheAge@11: local threshold = curRealmStat.threshold ShadowTheAge@11: GameTooltip:AddLine("Players in zone: "..players) ShadowTheAge@11: if not curRealmStat.complete then ShadowTheAge@11: GameTooltip:AppendText("+") ShadowTheAge@11: end ShadowTheAge@11: for i=1,curRealmStat.realms do ShadowTheAge@11: local data = curRealmStat[i] ShadowTheAge@11: local percent = math.ceil(100 * data.count / players - 0.5) .. "%"; ShadowTheAge@11: if data.count >= threshold then ShadowTheAge@11: GameTooltip:AddDoubleLine(data.realm, percent, 0,1,0,0,1,0) ShadowTheAge@11: else ShadowTheAge@11: GameTooltip:AddDoubleLine(data.realm, percent, 0.5,0.5,0.5,0.5,0.5,0.5) ShadowTheAge@11: end ShadowTheAge@11: end ShadowTheAge@11: end ShadowTheAge@11: ShadowTheAge@11: --[[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: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@11: end]]