annotate CrossRealmAssist.lua @ 0:9fa8442dd547

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