annotate CrossRealmAssist/CrossRealmAssist.lua @ 1:3f83977570fb

Project file layout
author ShadowTheAge
date Wed, 04 Mar 2015 21:54:21 +0300
parents
children
rev   line source
ShadowTheAge@1 1 CrossRealmAssist = LibStub("AceAddon-3.0"):NewAddon("CrossRealmAssist", "AceEvent-3.0", "AceConsole-3.0", "AceTimer-3.0")
ShadowTheAge@1 2 local AceGUI = LibStub("AceGUI-3.0")
ShadowTheAge@1 3 local addon = CrossRealmAssist;
ShadowTheAge@1 4 local wholib = LibStub:GetLibrary('LibWho-2.0'):Library()
ShadowTheAge@1 5
ShadowTheAge@1 6 local hgroup, lfgContainer, currealm, partyrealm, recrealm, curRealmStat, homeRealm, realmSep, gui, leavebtn
ShadowTheAge@1 7
ShadowTheAge@1 8 local scanstate=0
ShadowTheAge@1 9 local recentRealms={}
ShadowTheAge@1 10 local active=false
ShadowTheAge@1 11
ShadowTheAge@1 12 local lfgGroups={
ShadowTheAge@1 13 6, -- Custom
ShadowTheAge@1 14 10, -- Ashran
ShadowTheAge@1 15 1, -- Quests
ShadowTheAge@1 16 3, -- Raids
ShadowTheAge@1 17 8 -- BGs
ShadowTheAge@1 18 }
ShadowTheAge@1 19
ShadowTheAge@1 20 local lfgTabs
ShadowTheAge@1 21 local curLfgGroup
ShadowTheAge@1 22 local sheduledScan
ShadowTheAge@1 23 local wasInGroup
ShadowTheAge@1 24 local lfgScanInProgress=false
ShadowTheAge@1 25
ShadowTheAge@1 26 function addon:OnInitialize()
ShadowTheAge@1 27
ShadowTheAge@1 28 end
ShadowTheAge@1 29
ShadowTheAge@1 30 function addon:OnEnable()
ShadowTheAge@1 31 local tabCount = table.getn(lfgGroups)
ShadowTheAge@1 32 lfgTabs = {}
ShadowTheAge@1 33 for i=1,tabCount do
ShadowTheAge@1 34 local cat = lfgGroups[i]
ShadowTheAge@1 35 table.insert(lfgTabs,{value=cat,text=(C_LFGList.GetCategoryInfo(cat))})
ShadowTheAge@1 36 end
ShadowTheAge@1 37 realmSep = _G.REALM_SEPARATORS
ShadowTheAge@1 38 homeRealm = GetRealmName()
ShadowTheAge@1 39 addon:RegisterChatCommand("cra", "Activate")
ShadowTheAge@1 40 addon:RegisterChatCommand("crossrealmassist", "Activate")
ShadowTheAge@1 41 end
ShadowTheAge@1 42
ShadowTheAge@1 43 function addon:OnDisable()
ShadowTheAge@1 44 addon:Deactivate()
ShadowTheAge@1 45 end
ShadowTheAge@1 46
ShadowTheAge@1 47 function addon:Activate()
ShadowTheAge@1 48 if active then return end
ShadowTheAge@1 49 active=true
ShadowTheAge@1 50 wasInGroup = IsInGroup()
ShadowTheAge@1 51 addon:CreateUI()
ShadowTheAge@1 52 addon:ScanRealm()
ShadowTheAge@1 53 addon:RegisterEvent("ZONE_CHANGED_NEW_AREA", "SheduleScan")
ShadowTheAge@1 54 addon:RegisterEvent("LFG_LIST_SEARCH_RESULTS_RECEIVED", "LfgResponseData")
ShadowTheAge@1 55 addon:RegisterEvent("LFG_LIST_SEARCH_FAILED", "LfgScanFailed")
ShadowTheAge@1 56 addon:RegisterEvent("GROUP_ROSTER_UPDATE", "updatePartyInfo")
ShadowTheAge@1 57 addon:RegisterEvent("LFG_LIST_APPLICATION_STATUS_UPDATED", "updateAppStatus")
ShadowTheAge@1 58 end
ShadowTheAge@1 59
ShadowTheAge@1 60 function addon:Deactivate()
ShadowTheAge@1 61 if not active then return end
ShadowTheAge@1 62 active = false
ShadowTheAge@1 63 scanstate = 0
ShadowTheAge@1 64 lfgScanInProgress = false
ShadowTheAge@1 65 gui:Release();
ShadowTheAge@1 66 gui, lfgContainer, hgroup, currealm, partyrealm, recrealm, leavebtn = nil,nil,nil,nil,nil,nil,nil
ShadowTheAge@1 67 addon:UnregisterEvent("ZONE_CHANGED_NEW_AREA")
ShadowTheAge@1 68 addon:UnregisterEvent("PLAYER_REGEN_ENABLED")
ShadowTheAge@1 69 addon:UnregisterEvent("LFG_LIST_SEARCH_RESULTS_RECEIVED")
ShadowTheAge@1 70 addon:UnregisterEvent("LFG_LIST_SEARCH_FAILED")
ShadowTheAge@1 71 addon:UnregisterEvent("GROUP_ROSTER_UPDATE")
ShadowTheAge@1 72 addon:UnregisterEvent("LFG_LIST_APPLICATION_STATUS_UPDATED")
ShadowTheAge@1 73 end
ShadowTheAge@1 74
ShadowTheAge@1 75 function addon:CreateUI()
ShadowTheAge@1 76 gui = addon:AddUI(nil,"Window",{SetTitle="Cross Realm Assist",EnableResize=false,SetLayout="Flow"},true,{OnClose=addon.Deactivate})
ShadowTheAge@1 77
ShadowTheAge@1 78 local tabgroup = addon:AddUI(gui,"TabGroup",{SetFullHeight=true,SetTabs=lfgTabs,SetLayout="Fill"},true,{OnGroupSelected=addon.LfgScan})
ShadowTheAge@1 79 tabgroup:SelectTab(lfgGroups[1])
ShadowTheAge@1 80 lfgContainer = addon:AddUI(tabgroup,"ScrollFrame")
ShadowTheAge@1 81
ShadowTheAge@1 82 local hgroupc = addon:AddUI(gui,"InlineGroup",{SetLayout="Fill",SetFullHeight=true,SetTitle="Realm info"},true)
ShadowTheAge@1 83 hgroup = addon:AddUI(hgroupc,"ScrollFrame")
ShadowTheAge@1 84
ShadowTheAge@1 85 addon:AddUI(hgroup,"Heading",{SetText="Current realm"})
ShadowTheAge@1 86 currealm = addon:AddUI(hgroup,"SimpleGroup");
ShadowTheAge@1 87 addon:AddUI(hgroup,"Button",{SetText="Refresh",SetRelativeWidth=0.5,SetHeight=20},true,{OnClick=addon.ScanRealm})
ShadowTheAge@1 88
ShadowTheAge@1 89 addon:AddUI(hgroup,"Heading",{SetText="Party statistics"})
ShadowTheAge@1 90 partyrealm = addon:AddUI(hgroup,"SimpleGroup");
ShadowTheAge@1 91 leavebtn = addon:AddUI(hgroup,"Button",{SetText="Leave",SetRelativeWidth=0.5,SetHeight=20,SetDisabled=not IsInGroup()},true,{OnClick=LeaveParty})
ShadowTheAge@1 92
ShadowTheAge@1 93 addon:AddUI(hgroup,"Heading",{SetText="Recent realms"})
ShadowTheAge@1 94 recrealm = addon:AddUI(hgroup,"SimpleGroup");
ShadowTheAge@1 95 addon:AddUI(hgroup,"Button",{SetText="Clear",SetRelativeWidth=0.5,SetHeight=20},true,{OnClick=addon.ClearRecentRealms})
ShadowTheAge@1 96
ShadowTheAge@1 97 gui:DoLayout()
ShadowTheAge@1 98 gui:PauseLayout()
ShadowTheAge@1 99
ShadowTheAge@1 100 tabgroup:SetPoint("BOTTOMRIGHT", gui.content, "BOTTOMRIGHT", -200, 0)
ShadowTheAge@1 101 hgroupc:SetPoint("TOPLEFT", gui.content, "TOPRIGHT", -200, 0)
ShadowTheAge@1 102 hgroupc:SetPoint("BOTTOMRIGHT", gui.content, "BOTTOMRIGHT")
ShadowTheAge@1 103
ShadowTheAge@1 104 if curRealmStat then addon:updateCurrentRealm() end
ShadowTheAge@1 105 addon:updatePartyInfo()
ShadowTheAge@1 106 addon:updateRecentRealms()
ShadowTheAge@1 107 end
ShadowTheAge@1 108
ShadowTheAge@1 109 -- LFG scanning routine
ShadowTheAge@1 110
ShadowTheAge@1 111 function addon.refreshLfgCurrent()
ShadowTheAge@1 112 addon.LfgScan(nil,nil,curLfgGroup)
ShadowTheAge@1 113 end
ShadowTheAge@1 114
ShadowTheAge@1 115 function addon.LfgScan(widget, callback, tab)
ShadowTheAge@1 116 if not tab then return end
ShadowTheAge@1 117 lfgScanInProgress = true
ShadowTheAge@1 118 if lfgContainer then lfgContainer:ReleaseChildren() end
ShadowTheAge@1 119 curLfgGroup = tab
ShadowTheAge@1 120 C_LFGList.Search(curLfgGroup,"")
ShadowTheAge@1 121 end
ShadowTheAge@1 122
ShadowTheAge@1 123 function addon:LfgScanFailed(event, reason)
ShadowTheAge@1 124 print("scan failed "..reason)
ShadowTheAge@1 125 if reason == "throttled" then
ShadowTheAge@1 126 addon:ScheduleTimer(addon.LfgScan, 2, nil, nil, curLfgGroup)
ShadowTheAge@1 127 end
ShadowTheAge@1 128 end
ShadowTheAge@1 129
ShadowTheAge@1 130 local function WeightLfgItem(item)
ShadowTheAge@1 131 local leaderRealm = 3
ShadowTheAge@1 132 if (item.realm ~= "???") then leaderRealm = (5 - (recentRealms[item.realm] or 0)) end
ShadowTheAge@1 133 local weight =
ShadowTheAge@1 134 (item.autoinv and 5 or 2) *
ShadowTheAge@1 135 ((item.friends > 0) and 2 or 3) *
ShadowTheAge@1 136 ((item.ilvl > 0) and 2 or 3) *
ShadowTheAge@1 137 ((item.voice ~= "") and 2 or 4)
ShadowTheAge@1 138 local count = item.pcount;
ShadowTheAge@1 139 local countWeight
ShadowTheAge@1 140 if count >= 39 or count <= 1 then countWeight = 1
ShadowTheAge@1 141 elseif count >= 35 or count <= 4 then countWeight = 2
ShadowTheAge@1 142 elseif count >= 30 or count <= 10 then countWeight = 3
ShadowTheAge@1 143 else countWeight = 4 end
ShadowTheAge@1 144 return weight * leaderRealm * countWeight;
ShadowTheAge@1 145 end
ShadowTheAge@1 146
ShadowTheAge@1 147 function addon:LfgResponseData()
ShadowTheAge@1 148 lfgScanInProgress = false;
ShadowTheAge@1 149 addon:UpdateCurrentLfgInfo()
ShadowTheAge@1 150 end
ShadowTheAge@1 151
ShadowTheAge@1 152 function addon:UpdateCurrentLfgInfo(repeated)
ShadowTheAge@1 153 if lfgScanInProgress then return end
ShadowTheAge@1 154 local count, list = C_LFGList.GetSearchResults()
ShadowTheAge@1 155 local lfgList = {}
ShadowTheAge@1 156 local lfgEntries = 0
ShadowTheAge@1 157 local hasUnknowns = false
ShadowTheAge@1 158 for i = 1,count do
ShadowTheAge@1 159 local rid = list[i];
ShadowTheAge@1 160 if not rid then break end
ShadowTheAge@1 161 local _, action, caption, desc, voice, ilvl, time, bnetfr, charfr, guild, delisted, fullname, pcount, autoinv = C_LFGList.GetSearchResultInfo(rid)
ShadowTheAge@1 162 if not fullname then
ShadowTheAge@1 163 fullname = "???-???"
ShadowTheAge@1 164 hasUnknowns = true
ShadowTheAge@1 165 end
ShadowTheAge@1 166 if not delisted then
ShadowTheAge@1 167 local pname, realm = strsplit(realmSep, fullname)
ShadowTheAge@1 168 realm = realm or homeRealm
ShadowTheAge@1 169 local item = {
ShadowTheAge@1 170 rid=rid,
ShadowTheAge@1 171 action=action,
ShadowTheAge@1 172 caption=caption,
ShadowTheAge@1 173 desc=desc,
ShadowTheAge@1 174 ilvl=ilvl,
ShadowTheAge@1 175 voice=voice,
ShadowTheAge@1 176 time=time,
ShadowTheAge@1 177 friends=bnetfr+charfr+guild,
ShadowTheAge@1 178 name=pname,
ShadowTheAge@1 179 realm = realm,
ShadowTheAge@1 180 pcount=pcount,
ShadowTheAge@1 181 autoinv=autoinv
ShadowTheAge@1 182 }
ShadowTheAge@1 183 item.weight = WeightLfgItem(item)
ShadowTheAge@1 184 table.insert(lfgList, item)
ShadowTheAge@1 185 lfgEntries = lfgEntries + 1
ShadowTheAge@1 186 end
ShadowTheAge@1 187 end
ShadowTheAge@1 188 addon:refreshLFGList(lfgList, lfgEntries);
ShadowTheAge@1 189 if hasUnknowns and repeated ~= true then addon:ScheduleTimer("UpdateCurrentLfgInfo", 1, true) end
ShadowTheAge@1 190 end
ShadowTheAge@1 191
ShadowTheAge@1 192 function addon:refreshLFGList(list, count)
ShadowTheAge@1 193 if not lfgContainer then return end
ShadowTheAge@1 194 lfgContainer:PauseLayout()
ShadowTheAge@1 195 lfgContainer:ReleaseChildren()
ShadowTheAge@1 196 table.sort(list, addon.SortLfgItems)
ShadowTheAge@1 197
ShadowTheAge@1 198 local canJoin = addon.canJoinGroup()
ShadowTheAge@1 199
ShadowTheAge@1 200 for i=1,count do
ShadowTheAge@1 201 local data = list[i];
ShadowTheAge@1 202 local renderer = addon:AddUI(lfgContainer,"SimpleGroup",{SetLayout="Flow",SetHeight=20,SetAutoAdjustHeight=false});
ShadowTheAge@1 203
ShadowTheAge@1 204 addon:AddUI(renderer,"Label",{SetText=data.caption,SetRelativeWidth=0.4},true)
ShadowTheAge@1 205 addon:AddUI(renderer,"Label",{SetText=data.pcount,SetRelativeWidth=0.05},true)
ShadowTheAge@1 206 local realm = addon:AddUI(renderer,"Label",{SetText=data.realm,SetRelativeWidth=0.25},true)
ShadowTheAge@1 207 if recentRealms[data.realm] then
ShadowTheAge@1 208 local r,g,b = GetItemQualityColor(recentRealms[data.realm]);
ShadowTheAge@1 209 realm:SetColor(r,g,b)
ShadowTheAge@1 210 end
ShadowTheAge@1 211
ShadowTheAge@1 212 local tooltip = {}
ShadowTheAge@1 213 if data.voice ~= "" then table.insert(tooltip,"Voice: "..data.voice) end
ShadowTheAge@1 214 if data.friends > 0 then table.insert(tooltip,"Friends: "..data.friends) end
ShadowTheAge@1 215 if data.ilvl > 0 then table.insert(tooltip,"Min. Ilvl: "..data.ilvl) end
ShadowTheAge@1 216 addon:AddIcon(renderer, "Interface/GossipFrame/ActiveQuestIcon", 16, tooltip[1] ~= nil, tooltip)
ShadowTheAge@1 217 addon:AddIcon(renderer, READY_CHECK_READY_TEXTURE, 16, data.autoinv, {"Auto invite!"})
ShadowTheAge@1 218 local btn = addon:AddUI(renderer,"Button",{SetText="Join",SetRelativeWidth=0.2,SetHeight=20,SetDisabled=not canJoin},true,{OnClick=addon.joinGroup})
ShadowTheAge@1 219 btn:SetUserData('rid',data.rid)
ShadowTheAge@1 220 end
ShadowTheAge@1 221 addon:AddUI(lfgContainer,"Button",{SetText="Refresh",SetWidth=100,SetHeight=20},true,{OnClick=addon.refreshLfgCurrent})
ShadowTheAge@1 222
ShadowTheAge@1 223 lfgContainer:ResumeLayout()
ShadowTheAge@1 224 lfgContainer:DoLayout()
ShadowTheAge@1 225 end
ShadowTheAge@1 226
ShadowTheAge@1 227 function addon.SortLfgItems(a,b)
ShadowTheAge@1 228 return a.weight > b.weight
ShadowTheAge@1 229 end
ShadowTheAge@1 230
ShadowTheAge@1 231 function addon.canJoinGroup()
ShadowTheAge@1 232 return (not IsInGroup()) or (UnitIsGroupLeader('player') and not IsInRaid())
ShadowTheAge@1 233 end
ShadowTheAge@1 234
ShadowTheAge@1 235 function addon.joinGroup(widget)
ShadowTheAge@1 236 if not addon.canJoinGroup() then return end
ShadowTheAge@1 237 local rid = widget:GetUserData('rid');
ShadowTheAge@1 238 widget:SetDisabled(true)
ShadowTheAge@1 239 C_LFGList.ApplyToGroup(rid, "", C_LFGList.GetAvailableRoles())
ShadowTheAge@1 240 end
ShadowTheAge@1 241
ShadowTheAge@1 242 function addon:updateAppStatus(event, id, status, oldstatus)
ShadowTheAge@1 243 if status == "invited" then
ShadowTheAge@1 244 LFGListInviteDialog_Accept(LFGListInviteDialog)
ShadowTheAge@1 245 end
ShadowTheAge@1 246 end
ShadowTheAge@1 247
ShadowTheAge@1 248 -- Zone scanning routine
ShadowTheAge@1 249
ShadowTheAge@1 250 function addon:LeaveCombat()
ShadowTheAge@1 251 addon:UnregisterEvent("PLAYER_REGEN_ENABLED")
ShadowTheAge@1 252 scanstate = 0
ShadowTheAge@1 253 addon:ScanRealm();
ShadowTheAge@1 254 end
ShadowTheAge@1 255
ShadowTheAge@1 256 function addon:ScanRealm()
ShadowTheAge@1 257 if scanstate > 0 then return end
ShadowTheAge@1 258 if InCombatLockdown() then
ShadowTheAge@1 259 addon:RegisterEvent("PLAYER_REGEN_ENABLED","LeaveCombat")
ShadowTheAge@1 260 scanstate = 1
ShadowTheAge@1 261 addon:AddLabel(currealm, "Scan sheduled after combat...", 3);
ShadowTheAge@1 262 return
ShadowTheAge@1 263 end
ShadowTheAge@1 264 scanstate = 2
ShadowTheAge@1 265 addon:AddLabel(currealm, "Scanning...", 3);
ShadowTheAge@1 266 local searchString = _G.WHO_TAG_ZONE .. '"' .. GetZoneText() .. '"';
ShadowTheAge@1 267 wholib:Who(searchString, {callback = "ScanResult", handler=addon})
ShadowTheAge@1 268 end
ShadowTheAge@1 269
ShadowTheAge@1 270 function addon:ScanResult(query, results, complete)
ShadowTheAge@1 271 local realms = {}
ShadowTheAge@1 272 for _, player in ipairs(results) do
ShadowTheAge@1 273 addon:AddRealmStat(player.Name, realms);
ShadowTheAge@1 274 end
ShadowTheAge@1 275 curRealmStat = addon:GetRealmStat(realms);
ShadowTheAge@1 276 addon:updateCurrentRealm();
ShadowTheAge@1 277 local rescan = scanstate == 3
ShadowTheAge@1 278 scanstate = 0;
ShadowTheAge@1 279 if rescan then addon:ScanRealm() end
ShadowTheAge@1 280 end
ShadowTheAge@1 281
ShadowTheAge@1 282 function addon:AddRealmStat(name, realms)
ShadowTheAge@1 283 local _, realm = strsplit(realmSep, name) -- TODO exclude self
ShadowTheAge@1 284 realm = realm or homeRealm
ShadowTheAge@1 285 realms[realm] = (realms[realm] or 0) + 1
ShadowTheAge@1 286 end
ShadowTheAge@1 287
ShadowTheAge@1 288 function addon:AddUnitIdStat(unitid, realms)
ShadowTheAge@1 289 local name, realm = UnitName(unitid);
ShadowTheAge@1 290 if not name then return end
ShadowTheAge@1 291 if realm == "" then realm = homeRealm end
ShadowTheAge@1 292 realm = realm or homeRealm
ShadowTheAge@1 293 realms[realm] = (realms[realm] or 0) + 1
ShadowTheAge@1 294 end
ShadowTheAge@1 295
ShadowTheAge@1 296 function addon:GetRealmStat(realms)
ShadowTheAge@1 297 local rcount = 0;
ShadowTheAge@1 298 local stat = {};
ShadowTheAge@1 299 local pcount = 0;
ShadowTheAge@1 300 for realm,count in pairs(realms) do
ShadowTheAge@1 301 table.insert(stat,{realm=realm,count=count})
ShadowTheAge@1 302 rcount = rcount + 1;
ShadowTheAge@1 303 pcount = pcount + count;
ShadowTheAge@1 304 end
ShadowTheAge@1 305 if rcount > 1 then
ShadowTheAge@1 306 table.sort(stat, function(a,b) return a.count > b.count end)
ShadowTheAge@1 307 stat.max = stat[1].count
ShadowTheAge@1 308 else stat.max = 0 end
ShadowTheAge@1 309 stat.players = pcount;
ShadowTheAge@1 310 stat.realms = rcount;
ShadowTheAge@1 311 return stat;
ShadowTheAge@1 312 end
ShadowTheAge@1 313
ShadowTheAge@1 314 function addon:updateCurrentRealm()
ShadowTheAge@1 315 if not currealm then return end
ShadowTheAge@1 316 currealm:ReleaseChildren()
ShadowTheAge@1 317 if curRealmStat.players < 5 then
ShadowTheAge@1 318 addon:AddLabel(currealm, "Not enough players", 0);
ShadowTheAge@1 319 end
ShadowTheAge@1 320 local sureplayers = curRealmStat.players/2
ShadowTheAge@1 321 local maybeplayers = math.max(curRealmStat.max/4, 3)
ShadowTheAge@1 322 local recentRealmUpdated = false
ShadowTheAge@1 323 for i=1,curRealmStat.realms do
ShadowTheAge@1 324 local data = curRealmStat[i]
ShadowTheAge@1 325 if data.count >= maybeplayers then
ShadowTheAge@1 326 local realm = data.realm
ShadowTheAge@1 327 local rvalue = (data.count >= sureplayers) and 4 or 2
ShadowTheAge@1 328 if (rvalue > (recentRealms[realm] or 0)) then
ShadowTheAge@1 329 recentRealmUpdated = true
ShadowTheAge@1 330 recentRealms[realm] = rvalue
ShadowTheAge@1 331 end
ShadowTheAge@1 332 end
ShadowTheAge@1 333 end
ShadowTheAge@1 334 addon:addLabels(currealm, curRealmStat, sureplayers, maybeplayers, 3, "Realm unknown");
ShadowTheAge@1 335 if recentRealmUpdated then
ShadowTheAge@1 336 addon:UpdateCurrentLfgInfo()
ShadowTheAge@1 337 addon:updateRecentRealms()
ShadowTheAge@1 338 end
ShadowTheAge@1 339 end
ShadowTheAge@1 340
ShadowTheAge@1 341 function addon:addLabels(container, stats, epict, whitet, grayt, emptytext)
ShadowTheAge@1 342 if stats.realms == 0 then
ShadowTheAge@1 343 addon:AddLabel(container, emptytext)
ShadowTheAge@1 344 else
ShadowTheAge@1 345 local players = stats.players
ShadowTheAge@1 346 local pleft = players;
ShadowTheAge@1 347 for i=1,stats.realms do
ShadowTheAge@1 348 local data = stats[i]
ShadowTheAge@1 349 local count = data.count;
ShadowTheAge@1 350 local percent = math.ceil(100 * count / players - 0.5)
ShadowTheAge@1 351 local label = data.realm .. " (" .. percent .. "%)";
ShadowTheAge@1 352 local color
ShadowTheAge@1 353 if count < grayt then break
ShadowTheAge@1 354 elseif count < whitet then color = 1
ShadowTheAge@1 355 elseif count < epict then color = 2
ShadowTheAge@1 356 else color = 4 end
ShadowTheAge@1 357 pleft = pleft - count
ShadowTheAge@1 358 addon:AddLabel(container, label, color);
ShadowTheAge@1 359 end
ShadowTheAge@1 360 if pleft > 0 then
ShadowTheAge@1 361 addon:AddLabel(container, "Other" .. " (" .. math.ceil(100 * pleft / players - 0.5) .. "%)", 0);
ShadowTheAge@1 362 end
ShadowTheAge@1 363 end
ShadowTheAge@1 364 end
ShadowTheAge@1 365
ShadowTheAge@1 366 function addon:updateRecentRealms()
ShadowTheAge@1 367 if not recrealm then return end
ShadowTheAge@1 368 recrealm:ReleaseChildren()
ShadowTheAge@1 369 local nothing = true;
ShadowTheAge@1 370 for realm,color in pairs(recentRealms) do
ShadowTheAge@1 371 addon:AddLabel(recrealm, realm,color);
ShadowTheAge@1 372 nothing = false;
ShadowTheAge@1 373 end
ShadowTheAge@1 374 if nothing then
ShadowTheAge@1 375 addon:AddLabel(recrealm, "No recent realms");
ShadowTheAge@1 376 end
ShadowTheAge@1 377 end
ShadowTheAge@1 378
ShadowTheAge@1 379 function addon:ClearRecentRealms()
ShadowTheAge@1 380 recentRealms = {}
ShadowTheAge@1 381 addon:UpdateCurrentLfgInfo()
ShadowTheAge@1 382 addon:updateRecentRealms()
ShadowTheAge@1 383 end
ShadowTheAge@1 384
ShadowTheAge@1 385 function addon:SheduleScan()
ShadowTheAge@1 386 if scanstate == 0 then
ShadowTheAge@1 387 addon:ScanRealm()
ShadowTheAge@1 388 elseif scanstate == 2 then
ShadowTheAge@1 389 scanstate = 3
ShadowTheAge@1 390 end
ShadowTheAge@1 391 end
ShadowTheAge@1 392
ShadowTheAge@1 393 function addon:updatePartyInfo()
ShadowTheAge@1 394 if not partyrealm then return end
ShadowTheAge@1 395 partyrealm:ReleaseChildren()
ShadowTheAge@1 396 local realms = {}
ShadowTheAge@1 397 local inGroup = IsInGroup()
ShadowTheAge@1 398 if IsInGroup() then
ShadowTheAge@1 399 if IsInRaid() then
ShadowTheAge@1 400 for i=1, MAX_RAID_MEMBERS do
ShadowTheAge@1 401 addon:AddUnitIdStat("raid"..i, realms)
ShadowTheAge@1 402 end
ShadowTheAge@1 403 else
ShadowTheAge@1 404 for i=1, MAX_PARTY_MEMBERS do
ShadowTheAge@1 405 addon:AddUnitIdStat("party"..i, realms)
ShadowTheAge@1 406 end
ShadowTheAge@1 407 end
ShadowTheAge@1 408 end
ShadowTheAge@1 409 if inGroup ~= wasInGroup then
ShadowTheAge@1 410 addon:SheduleScan()
ShadowTheAge@1 411 wasInGroup = inGroup
ShadowTheAge@1 412 addon:UpdateCurrentLfgInfo()
ShadowTheAge@1 413 leavebtn:SetDisabled(not inGroup)
ShadowTheAge@1 414 end
ShadowTheAge@1 415 local partyStat = addon:GetRealmStat(realms);
ShadowTheAge@1 416 addon:addLabels(partyrealm, partyStat, partyStat.players/2, 2, 0, "Not in party");
ShadowTheAge@1 417 end
ShadowTheAge@1 418
ShadowTheAge@1 419 -- Utils functions
ShadowTheAge@1 420
ShadowTheAge@1 421 function addon:AddUI(owner, type, parameters, manual, callbacks)
ShadowTheAge@1 422 local ui = AceGUI:Create(type)
ShadowTheAge@1 423 if parameters then
ShadowTheAge@1 424 for key,value in pairs(parameters) do ui[key](ui,value) end
ShadowTheAge@1 425 end
ShadowTheAge@1 426 if callbacks then
ShadowTheAge@1 427 for key,value in pairs(callbacks) do ui:SetCallback(key,value) end
ShadowTheAge@1 428 end
ShadowTheAge@1 429 if not manual then ui:SetFullWidth(true) end
ShadowTheAge@1 430 if owner then owner:AddChild(ui) end
ShadowTheAge@1 431 return ui
ShadowTheAge@1 432 end
ShadowTheAge@1 433
ShadowTheAge@1 434 function addon:AddLabel(owner, text, color, icon)
ShadowTheAge@1 435 local label = AceGUI:Create("Label")
ShadowTheAge@1 436 label:SetText(text)
ShadowTheAge@1 437 label:SetFullWidth(true)
ShadowTheAge@1 438 if color ~= nil then
ShadowTheAge@1 439 local r,g,b = GetItemQualityColor(color);
ShadowTheAge@1 440 label:SetColor(r,g,b)
ShadowTheAge@1 441 end
ShadowTheAge@1 442 owner:AddChild(label)
ShadowTheAge@1 443 return label
ShadowTheAge@1 444 end
ShadowTheAge@1 445
ShadowTheAge@1 446 function addon:AddIcon(owner, image, size, visible, tooltip)
ShadowTheAge@1 447 if visible ~= false then
ShadowTheAge@1 448 local icon = addon:AddUI(owner,"Icon",{SetWidth=size,SetHeight=size},true)
ShadowTheAge@1 449 icon:SetImage(image)
ShadowTheAge@1 450 icon:SetImageSize(size,size)
ShadowTheAge@1 451 if tooltip then
ShadowTheAge@1 452 icon:SetUserData('tooltip',tooltip)
ShadowTheAge@1 453 icon:SetCallback("OnEnter",addon.ShowTooltip)
ShadowTheAge@1 454 icon:SetCallback("OnLeave",addon.HideTooltip)
ShadowTheAge@1 455 end
ShadowTheAge@1 456 else -- add placeholder
ShadowTheAge@1 457 addon:AddUI(owner,"Label",{SetWidth=size,SetHeight=size},true)
ShadowTheAge@1 458 end
ShadowTheAge@1 459 end
ShadowTheAge@1 460
ShadowTheAge@1 461 function addon.ShowTooltip(widget)
ShadowTheAge@1 462 GameTooltip:SetOwner(widget.frame, "ANCHOR_TOP")
ShadowTheAge@1 463 local tooltip = widget:GetUserData('tooltip')
ShadowTheAge@1 464 for i=1,#tooltip do
ShadowTheAge@1 465 GameTooltip:AddLine(tooltip[i], 1, 1, 1)
ShadowTheAge@1 466 end
ShadowTheAge@1 467 GameTooltip:Show()
ShadowTheAge@1 468 end
ShadowTheAge@1 469
ShadowTheAge@1 470 function addon.HideTooltip(widget)
ShadowTheAge@1 471 GameTooltip:Hide()
ShadowTheAge@1 472 end