annotate CrossRealmAssist.lua @ 13:1f68e8154947

New alpha build
author ShadowTheAge
date Thu, 12 Mar 2015 22:51:35 +0300
parents 0deef890ec99
children c97b3a4e5feb
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 addon = CrossRealmAssist;
ShadowTheAge@0 3 local wholib = LibStub:GetLibrary('LibWho-2.0'):Library()
ShadowTheAge@12 4 local ScrollingTable = LibStub("ScrollingTable");
ShadowTheAge@13 5 local ldb = LibStub("LibDataBroker-1.1")
ShadowTheAge@13 6 local minimapIcon = LibStub("LibDBIcon-1.0")
ShadowTheAge@13 7 local db
ShadowTheAge@0 8
ShadowTheAge@13 9 local homeRealm, realmSep, gui, btRefresh, btSettings, btQuick, btManual, lbRealm, lbStatus, playerName, lfgui, lfgTabSelected, lfgTable, lbThrottle, curLfgGroup, sheduledScan, wasInGroup, inInstance
ShadowTheAge@13 10 local settingsMenu
ShadowTheAge@13 11 local hintShown
ShadowTheAge@0 12
ShadowTheAge@12 13 local tabs = {}
ShadowTheAge@11 14 local curRealmStat
ShadowTheAge@0 15 local scanstate=0
ShadowTheAge@0 16 local recentRealms={}
ShadowTheAge@12 17 local recentgroups={}
ShadowTheAge@13 18 local autoScanGroups={}
ShadowTheAge@0 19 local active=false
ShadowTheAge@0 20
ShadowTheAge@0 21 local lfgGroups={
ShadowTheAge@0 22 6, -- Custom
ShadowTheAge@0 23 10, -- Ashran
ShadowTheAge@0 24 1, -- Quests
ShadowTheAge@13 25 3, -- Raids
ShadowTheAge@13 26 8 -- BGs
ShadowTheAge@0 27 }
ShadowTheAge@0 28
ShadowTheAge@12 29 local StatusTable = {
ShadowTheAge@12 30 ["invited"]="Invited",
ShadowTheAge@12 31 ["declined"]="Declined",
ShadowTheAge@12 32 ["timedout"]="Timed out",
ShadowTheAge@12 33 ["applied"]="Applied",
ShadowTheAge@12 34 ["cancelled"]="Join cancelled",
ShadowTheAge@12 35 ["inviteaccepted"]="Joined",
ShadowTheAge@13 36 ["_init"]="Join request",
ShadowTheAge@13 37 ["_skip"]="Skipped"
ShadowTheAge@12 38 }
ShadowTheAge@13 39 local DefaultWidgetPos = {x=0, y=200, to="CENTER"}
ShadowTheAge@13 40 local SettingsDefaults={
ShadowTheAge@13 41 global={
ShadowTheAge@13 42 minimap = {},
ShadowTheAge@13 43 widgetPos=DefaultWidgetPos,
ShadowTheAge@13 44 quickJoinHint = true,
ShadowTheAge@13 45 quickJoin={[6]=1,[10]=1}
ShadowTheAge@13 46 }
ShadowTheAge@13 47 }
ShadowTheAge@12 48
ShadowTheAge@12 49
ShadowTheAge@12 50 -- Utils functions
ShadowTheAge@12 51
ShadowTheAge@12 52 local function PlayerName(fullname)
ShadowTheAge@12 53 fullname = fullname or "???-???"
ShadowTheAge@12 54 local name, realm = strsplit(realmSep, fullname)
ShadowTheAge@12 55 realm = realm or homeRealm;
ShadowTheAge@12 56 return name, realm;
ShadowTheAge@12 57 end
ShadowTheAge@12 58
ShadowTheAge@12 59 local function canJoinGroup()
ShadowTheAge@12 60 return (not IsInGroup()) or (UnitIsGroupLeader('player') and not IsInRaid())
ShadowTheAge@12 61 end
ShadowTheAge@12 62
ShadowTheAge@12 63 local function sortByWeight(a,b)
ShadowTheAge@12 64 return b.weight < a.weight
ShadowTheAge@12 65 end
ShadowTheAge@12 66
ShadowTheAge@12 67
ShadowTheAge@12 68 -- UI functions
ShadowTheAge@12 69
ShadowTheAge@12 70 local function createIcon(owner, icon, id)
ShadowTheAge@12 71 local image = owner:CreateTexture(nil, "BACKGROUND")
ShadowTheAge@12 72 image:SetWidth(16)
ShadowTheAge@12 73 image:SetHeight(16)
ShadowTheAge@12 74 image:SetTexture(icon)
ShadowTheAge@12 75 image:SetPoint("TOPLEFT",owner,"TOPLEFT",id*16,0)
ShadowTheAge@12 76 return image
ShadowTheAge@12 77 end
ShadowTheAge@0 78
ShadowTheAge@11 79 local function setupWidget(widget, parameters, x, y)
ShadowTheAge@11 80 if parameters then
ShadowTheAge@11 81 for key,value in pairs(parameters) do widget[key](widget,value) end
ShadowTheAge@11 82 end
ShadowTheAge@11 83 if y then
ShadowTheAge@11 84 widget:SetPoint("TOPLEFT",widget:GetParent(),"TOPLEFT",x,-y)
ShadowTheAge@11 85 end
ShadowTheAge@11 86 return widget
ShadowTheAge@11 87 end
ShadowTheAge@11 88
ShadowTheAge@11 89 local function ShowTooltip(widget)
ShadowTheAge@11 90 GameTooltip:SetOwner(widget, widget.TooltipAnchor)
ShadowTheAge@11 91 GameTooltip:ClearLines()
ShadowTheAge@11 92 widget:TooltipFactory()
ShadowTheAge@11 93 GameTooltip:Show()
ShadowTheAge@11 94 end
ShadowTheAge@11 95
ShadowTheAge@11 96 local function HideTooltip(widget)
ShadowTheAge@11 97 GameTooltip:Hide()
ShadowTheAge@11 98 end
ShadowTheAge@11 99
ShadowTheAge@11 100 local function setupTooltip(widget, anchor, factory)
ShadowTheAge@11 101 widget.TooltipAnchor = anchor;
ShadowTheAge@11 102 widget.TooltipFactory = factory;
ShadowTheAge@11 103 widget:SetScript("OnEnter", ShowTooltip)
ShadowTheAge@11 104 widget:SetScript("OnLeave", HideTooltip)
ShadowTheAge@11 105 end
ShadowTheAge@11 106
ShadowTheAge@13 107 local function TabClick(tab)
ShadowTheAge@13 108 if tab == lfgTabSelected then return end
ShadowTheAge@13 109 addon.LfgScan(tab.searchID)
ShadowTheAge@13 110 end
ShadowTheAge@13 111
ShadowTheAge@13 112 local function changeTab(tab)
ShadowTheAge@12 113 PanelTemplates_DeselectTab(lfgTabSelected)
ShadowTheAge@12 114 lfgTabSelected = tab
ShadowTheAge@12 115 PanelTemplates_SelectTab(lfgTabSelected)
ShadowTheAge@12 116 end
ShadowTheAge@0 117
ShadowTheAge@12 118 local function realmToolip()
ShadowTheAge@12 119 if not curRealmStat then return end
ShadowTheAge@12 120 local players = curRealmStat.players;
ShadowTheAge@12 121 local threshold = curRealmStat.threshold
ShadowTheAge@12 122 GameTooltip:AddLine("Players in zone: "..players)
ShadowTheAge@12 123 if not curRealmStat.complete then
ShadowTheAge@12 124 GameTooltip:AppendText("+")
ShadowTheAge@12 125 end
ShadowTheAge@12 126 for i=1,curRealmStat.realms do
ShadowTheAge@12 127 local data = curRealmStat[i]
ShadowTheAge@12 128 local percent = math.ceil(100 * data.count / players - 0.5) .. "%";
ShadowTheAge@12 129 if data.count >= threshold then
ShadowTheAge@12 130 GameTooltip:AddDoubleLine(data.realm, percent, 0,1,0,0,1,0)
ShadowTheAge@12 131 else
ShadowTheAge@12 132 GameTooltip:AddDoubleLine(data.realm, percent, 0.5,0.5,0.5,0.5,0.5,0.5)
ShadowTheAge@12 133 end
ShadowTheAge@12 134 end
ShadowTheAge@0 135 end
ShadowTheAge@0 136
ShadowTheAge@13 137 local function ClearRealmHistory()
ShadowTheAge@13 138 recentRealms = {}
ShadowTheAge@13 139 addon:updateCurrentRealm()
ShadowTheAge@13 140 if lfgTable then lfgTable:Refresh() end
ShadowTheAge@13 141 end
ShadowTheAge@13 142
ShadowTheAge@12 143
ShadowTheAge@12 144
ShadowTheAge@12 145
ShadowTheAge@12 146
ShadowTheAge@12 147
ShadowTheAge@12 148
ShadowTheAge@12 149 -- LFG list data providers, filters and tooltips
ShadowTheAge@12 150
ShadowTheAge@12 151 local lfgScanInProgress=false
ShadowTheAge@12 152 local hasLfgListChanges=false
ShadowTheAge@12 153
ShadowTheAge@12 154 local function addTooltipLineIcon(predicat, text, icon, r, g, b, wrap)
ShadowTheAge@12 155 if predicat then
ShadowTheAge@12 156 GameTooltip:AddLine(text, r, g, b, wrap)
ShadowTheAge@12 157 if icon then GameTooltip:AddTexture(icon) end
ShadowTheAge@12 158 end
ShadowTheAge@12 159 end
ShadowTheAge@12 160
ShadowTheAge@12 161 local function WeightLfgItem(id, forAutoJoin)
ShadowTheAge@12 162 local _, action, caption, desc, voice, ilvl, time, bnetfr, charfr, guild, delisted, fullname, pcount, autoinv = C_LFGList.GetSearchResultInfo(id)
ShadowTheAge@12 163 if delisted then return 0 end
ShadowTheAge@12 164 local name,realm = PlayerName(fullname);
ShadowTheAge@12 165 if forAutoJoin then
ShadowTheAge@12 166 if not autoinv or pcount >= 35 or pcount <= 5 or recentgroups[fullname] then return 0 end
ShadowTheAge@12 167 end
ShadowTheAge@12 168
ShadowTheAge@12 169 local autoinvWeight = autoinv and 5 or 2
ShadowTheAge@12 170
ShadowTheAge@12 171 local visCoef = 1
ShadowTheAge@12 172 if recentgroups[fullname] then
ShadowTheAge@12 173 local ago = GetTime() - recentgroups[fullname].time;
ShadowTheAge@12 174 visCoef = math.min(1,ago/600)
ShadowTheAge@12 175 end
ShadowTheAge@12 176
ShadowTheAge@12 177 local leaderRealm = 3 -- recently visited realms
ShadowTheAge@13 178 local realmVis = recentRealms[realm]
ShadowTheAge@13 179 local leaderRealm = 3;
ShadowTheAge@13 180 if realmVis then
ShadowTheAge@13 181 local ago = GetTime() - realmVis
ShadowTheAge@13 182 leaderRealm = 1 + 2*math.min(1,ago/600);
ShadowTheAge@13 183 end
ShadowTheAge@12 184
ShadowTheAge@12 185 local countWeight = 4 -- count weight
ShadowTheAge@12 186 if pcount >= 39 or pcount <= 1 then countWeight = 1
ShadowTheAge@12 187 elseif pcount >= 35 or pcount <= 4 then countWeight = 2
ShadowTheAge@12 188 elseif pcount >= 30 or pcount <= 10 then countWeight = 3
ShadowTheAge@12 189 else countWeight = 4 end
ShadowTheAge@12 190
ShadowTheAge@12 191 local ageWeight = 2
ShadowTheAge@12 192 if time > 1200 then ageWeight = 4
ShadowTheAge@12 193 elseif time > 300 then ageWeight = 3 end
ShadowTheAge@12 194
ShadowTheAge@12 195 return leaderRealm * countWeight * visCoef * autoinvWeight * ageWeight;
ShadowTheAge@12 196 end
ShadowTheAge@12 197
ShadowTheAge@13 198 local function AddLfgGroupInfo(id, short)
ShadowTheAge@13 199 local _, action, caption, desc, voice, ilvl, time, bnetfr, charfr, guild, delisted, fullname, pcount, autoinv = C_LFGList.GetSearchResultInfo(id)
ShadowTheAge@12 200 local friends = bnetfr+charfr+guild
ShadowTheAge@12 201 GameTooltip:ClearLines()
ShadowTheAge@12 202 GameTooltip:AddLine(caption,1,1,1)
ShadowTheAge@12 203 addTooltipLineIcon(desc ~= "", desc, nil, 0.5, 0.5, 0.5, true)
ShadowTheAge@12 204 local name, realm = PlayerName(fullname)
ShadowTheAge@13 205 GameTooltip:AddDoubleLine("Players:",pcount)
ShadowTheAge@12 206 GameTooltip:AddDoubleLine("Leader:",name)
ShadowTheAge@12 207 GameTooltip:AddDoubleLine("Leader realm:",realm)
ShadowTheAge@13 208 if recentRealms[realm] then
ShadowTheAge@13 209 local ago = GetTime() - recentRealms[realm]
ShadowTheAge@13 210 GameTooltip:AddDoubleLine("Realm visited",SecondsToTime(ago, false, false, 1, false).." ago",1,0.5,0,1,0.5,0)
ShadowTheAge@13 211 else
ShadowTheAge@13 212 GameTooltip:AddDoubleLine(" ","Realm not visited!",0,0,0,0,1,0)
ShadowTheAge@13 213 end
ShadowTheAge@13 214 if not short then
ShadowTheAge@13 215 addTooltipLineIcon(ilvl > 0, "Min. ilvl: "..ilvl, READY_CHECK_WAITING_TEXTURE, 1, 1, 0)
ShadowTheAge@13 216 addTooltipLineIcon(voice ~= "", "Voice: "..voice, READY_CHECK_WAITING_TEXTURE, 1, 1, 0)
ShadowTheAge@13 217 addTooltipLineIcon(friends > 0, "Friends: "..friends, READY_CHECK_WAITING_TEXTURE, 1, 1, 0)
ShadowTheAge@13 218 addTooltipLineIcon(autoinv, "Autoinvite!", READY_CHECK_READY_TEXTURE, 0, 1, 0)
ShadowTheAge@13 219 local visitinfo = recentgroups[fullname]
ShadowTheAge@13 220 if visitinfo then
ShadowTheAge@13 221 local ago = GetTime() - visitinfo.time;
ShadowTheAge@13 222 GameTooltip:AddDoubleLine(StatusTable[visitinfo.status] or visitinfo.status,SecondsToTime(ago, false, false, 1, false).." ago",1,0,0,1,0,0)
ShadowTheAge@13 223 GameTooltip:AddTexture(READY_CHECK_NOT_READY_TEXTURE)
ShadowTheAge@13 224 end
ShadowTheAge@12 225 end
ShadowTheAge@12 226 GameTooltip:Show()
ShadowTheAge@12 227 end
ShadowTheAge@12 228
ShadowTheAge@13 229 local function ShowLfgInfo(rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...)
ShadowTheAge@13 230 if not realrow then return end
ShadowTheAge@13 231 local rowdata = scrollingTable:GetRow(realrow);
ShadowTheAge@13 232 GameTooltip:SetOwner(rowFrame, "ANCHOR_BOTTOMLEFT",-10,25)
ShadowTheAge@13 233 AddLfgGroupInfo(rowdata.id);
ShadowTheAge@13 234 end
ShadowTheAge@13 235
ShadowTheAge@12 236 local function updateTableData(rowFrame, cellFrame, data, cols, row, realrow, column, fShow, table, ...)
ShadowTheAge@12 237 if fShow then
ShadowTheAge@12 238 local rowdata = table:GetRow(realrow);
ShadowTheAge@12 239 local icons = cellFrame.icons
ShadowTheAge@12 240 local _, action, caption, desc, voice, ilvl, time, bnetfr, charfr, guild, delisted, fullname, pcount, autoinv = C_LFGList.GetSearchResultInfo(rowdata.id)
ShadowTheAge@12 241 if not icons then
ShadowTheAge@12 242 local miscdata = createIcon(cellFrame,READY_CHECK_WAITING_TEXTURE,0)
ShadowTheAge@12 243 local autoinv = createIcon(cellFrame,READY_CHECK_READY_TEXTURE, 1)
ShadowTheAge@12 244 local visited = createIcon(cellFrame,READY_CHECK_NOT_READY_TEXTURE, 2)
ShadowTheAge@12 245 icons = {misc=miscdata, autoinv=autoinv, visited=visited}
ShadowTheAge@12 246 cellFrame.icons = icons
ShadowTheAge@12 247 end
ShadowTheAge@12 248 icons.misc:SetShown(voice ~= "" or bnetfr > 0 or charfr > 0 or guild > 0 or ilvl > 0)
ShadowTheAge@12 249 icons.autoinv:SetShown(autoinv)
ShadowTheAge@12 250 icons.visited:SetShown(recentgroups[fullname])
ShadowTheAge@12 251 if GameTooltip:GetOwner() == rowFrame then ShowLfgInfo(rowFrame, cellFrame, data, cols, row, realrow, column, table) end
ShadowTheAge@12 252 end
ShadowTheAge@12 253 end
ShadowTheAge@12 254
ShadowTheAge@12 255 local function updateGroupName(id)
ShadowTheAge@12 256 return select(3, C_LFGList.GetSearchResultInfo(id))
ShadowTheAge@12 257 end
ShadowTheAge@12 258
ShadowTheAge@12 259 local function updateGroupCount(id)
ShadowTheAge@12 260 return select(13, C_LFGList.GetSearchResultInfo(id))
ShadowTheAge@12 261 end
ShadowTheAge@12 262
ShadowTheAge@12 263 local function updateGroupRealm(id)
ShadowTheAge@12 264 local name = select(12, C_LFGList.GetSearchResultInfo(id))
ShadowTheAge@12 265 local pname, realm = PlayerName(name);
ShadowTheAge@12 266 return realm
ShadowTheAge@12 267 end
ShadowTheAge@12 268
ShadowTheAge@13 269 local COLOR_YELLOW = {r=1,g=1,b=0,a=1}
ShadowTheAge@13 270 local COLOR_GREEN = {r=0,g=1,b=0,a=1}
ShadowTheAge@13 271 local function updateRealmColor(id)
ShadowTheAge@13 272 local name = select(12, C_LFGList.GetSearchResultInfo(id))
ShadowTheAge@13 273 local pname, realm = PlayerName(name);
ShadowTheAge@13 274 return recentRealms[realm] and COLOR_YELLOW or COLOR_GREEN;
ShadowTheAge@13 275 end
ShadowTheAge@13 276
ShadowTheAge@12 277 local function filterTable(self, row)
ShadowTheAge@12 278 local delisted = select(11, C_LFGList.GetSearchResultInfo(row.id))
ShadowTheAge@12 279 return not delisted;
ShadowTheAge@12 280 end
ShadowTheAge@12 281
ShadowTheAge@12 282 function addon:UpdateResponseData(event, result)
ShadowTheAge@13 283 if not lfgTable then return end
ShadowTheAge@12 284 if select(11, C_LFGList.GetSearchResultInfo(result)) then
ShadowTheAge@12 285 lfgTable:SetFilter(filterTable)
ShadowTheAge@12 286 end
ShadowTheAge@12 287 hasLfgListChanges = true
ShadowTheAge@12 288 end
ShadowTheAge@12 289
ShadowTheAge@12 290 local function refreshLFGList()
ShadowTheAge@12 291 if lfgScanInProgress or not lfgTable then return end
ShadowTheAge@12 292 local count, list = C_LFGList.GetSearchResults()
ShadowTheAge@12 293 local tableData = {}
ShadowTheAge@12 294 for i = 1,count do
ShadowTheAge@12 295 local rid = list[i];
ShadowTheAge@12 296 if not rid then break end
ShadowTheAge@12 297 local data = list[i];
ShadowTheAge@12 298 local cols = {}
ShadowTheAge@12 299 local row = {rid}
ShadowTheAge@12 300 cols[1] = {value=updateGroupName,args=row}
ShadowTheAge@12 301 cols[2] = {value=updateGroupCount,args=row}
ShadowTheAge@13 302 cols[3] = {value=updateGroupRealm,args=row,color=updateRealmColor,colorargs=row}
ShadowTheAge@12 303 cols[4] = {}
ShadowTheAge@12 304 table.insert(tableData, {cols=cols,id=rid,weight=WeightLfgItem(rid)})
ShadowTheAge@12 305 end
ShadowTheAge@12 306 table.sort(tableData, sortByWeight);
ShadowTheAge@12 307 lfgTable:SetData(tableData)
ShadowTheAge@12 308 end
ShadowTheAge@12 309
ShadowTheAge@13 310 local function JoinGroup(rid)
ShadowTheAge@13 311 local tank, heal, dd = C_LFGList.GetAvailableRoles()
ShadowTheAge@13 312 addon:SetGroupJoinStatus(rid, "_init")
ShadowTheAge@13 313 C_LFGList.ApplyToGroup(rid, "", tank, heal, dd)
ShadowTheAge@13 314 end
ShadowTheAge@13 315
ShadowTheAge@13 316 local function TableCellClick(rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...)
ShadowTheAge@12 317 if not realrow or not canJoinGroup() then return end
ShadowTheAge@12 318 local rowdata = scrollingTable:GetRow(realrow);
ShadowTheAge@13 319 JoinGroup(rowdata.id)
ShadowTheAge@12 320 end
ShadowTheAge@12 321
ShadowTheAge@12 322
ShadowTheAge@12 323
ShadowTheAge@12 324
ShadowTheAge@12 325
ShadowTheAge@12 326
ShadowTheAge@12 327 -- Addon functions and gui constructors
ShadowTheAge@12 328
ShadowTheAge@13 329 function addon.ShowMmTooltip(tooltip)
ShadowTheAge@13 330 tooltip:AddLine("Cross Realm Assist",1,1,1)
ShadowTheAge@13 331 tooltip:Show()
ShadowTheAge@13 332 end
ShadowTheAge@13 333
ShadowTheAge@13 334 --[[function addon.MmClick(self, button)
ShadowTheAge@13 335 if button == "RightButton" then
ShadowTheAge@13 336 addon.ShowSettings(self)
ShadowTheAge@13 337 else
ShadowTheAge@13 338 addon:Activate()
ShadowTheAge@13 339 end
ShadowTheAge@13 340 end]]
ShadowTheAge@13 341
ShadowTheAge@13 342 function addon:OnInitialize()
ShadowTheAge@13 343 db = LibStub("AceDB-3.0"):New("CrossRealmAssistDB", SettingsDefaults)
ShadowTheAge@13 344 local minimapData = ldb:NewDataObject("CrossRealmAssistMinimapIcon",{
ShadowTheAge@13 345 type = "data source",
ShadowTheAge@13 346 text = "Cross Realm Assist",
ShadowTheAge@13 347 icon = "Interface/Icons/INV_Misc_GroupNeedMore",
ShadowTheAge@13 348 OnClick = addon.Activate,
ShadowTheAge@13 349 OnTooltipShow = addon.ShowMmTooltip
ShadowTheAge@13 350 })
ShadowTheAge@13 351 minimapIcon:Register("CrossRealmAssistMinimapIcon", minimapData, db.global.minimap)
ShadowTheAge@13 352 end
ShadowTheAge@13 353
ShadowTheAge@0 354 function addon:OnEnable()
ShadowTheAge@0 355 realmSep = _G.REALM_SEPARATORS
ShadowTheAge@11 356 playerName = UnitName("player")
ShadowTheAge@0 357 homeRealm = GetRealmName()
ShadowTheAge@0 358 addon:RegisterChatCommand("cra", "Activate")
ShadowTheAge@0 359 addon:RegisterChatCommand("crossrealmassist", "Activate")
ShadowTheAge@11 360
ShadowTheAge@11 361 addon:ScheduleTimer("Activate", 0.5)
ShadowTheAge@0 362 end
ShadowTheAge@0 363
ShadowTheAge@0 364 function addon:OnDisable()
ShadowTheAge@0 365 addon:Deactivate()
ShadowTheAge@0 366 end
ShadowTheAge@0 367
ShadowTheAge@0 368 function addon:Activate()
ShadowTheAge@0 369 if active then return end
ShadowTheAge@0 370 active=true
ShadowTheAge@0 371 wasInGroup = IsInGroup()
ShadowTheAge@11 372 if not gui then addon:CreateUI() end
ShadowTheAge@11 373 addon:updateCurrentRealm();
ShadowTheAge@13 374 addon:RefreshZoneAndClearHistory();
ShadowTheAge@11 375 gui:Show()
ShadowTheAge@13 376 addon:RegisterEvent("ZONE_CHANGED_NEW_AREA", "RefreshZoneAndClearHistory")
ShadowTheAge@13 377 addon:RegisterEvent("SCENARIO_UPDATE", "RefreshZoneAndClearHistory")
ShadowTheAge@12 378 addon:RegisterEvent("LFG_LIST_SEARCH_RESULTS_RECEIVED", "LfgResponseData")
ShadowTheAge@12 379 addon:RegisterEvent("LFG_LIST_SEARCH_RESULT_UPDATED", "UpdateResponseData")
ShadowTheAge@12 380 addon:RegisterEvent("LFG_LIST_SEARCH_FAILED", "LfgScanFailed")
ShadowTheAge@12 381 addon:RegisterEvent("GROUP_ROSTER_UPDATE", "updatePartyInfo")
ShadowTheAge@12 382 addon:RegisterEvent("LFG_LIST_APPLICATION_STATUS_UPDATED", "updateAppStatus")
ShadowTheAge@13 383 addon.LfgScan(addon.GetNextAutoScanCategory() or 1)
ShadowTheAge@0 384 end
ShadowTheAge@0 385
ShadowTheAge@0 386 function addon:Deactivate()
ShadowTheAge@0 387 if not active then return end
ShadowTheAge@0 388 active = false
ShadowTheAge@12 389 gui:Hide()
ShadowTheAge@12 390 if lfgui then lfgui:Hide() end
ShadowTheAge@0 391 scanstate = 0
ShadowTheAge@0 392 lfgScanInProgress = false
ShadowTheAge@0 393 addon:UnregisterEvent("ZONE_CHANGED_NEW_AREA")
ShadowTheAge@0 394 addon:UnregisterEvent("PLAYER_REGEN_ENABLED")
ShadowTheAge@0 395 addon:UnregisterEvent("LFG_LIST_SEARCH_RESULTS_RECEIVED")
ShadowTheAge@12 396 addon:UnregisterEvent("LFG_LIST_SEARCH_RESULT_UPDATED")
ShadowTheAge@0 397 addon:UnregisterEvent("LFG_LIST_SEARCH_FAILED")
ShadowTheAge@0 398 addon:UnregisterEvent("GROUP_ROSTER_UPDATE")
ShadowTheAge@0 399 addon:UnregisterEvent("LFG_LIST_APPLICATION_STATUS_UPDATED")
ShadowTheAge@0 400 end
ShadowTheAge@0 401
ShadowTheAge@11 402 function addon:SetStatus(status)
ShadowTheAge@11 403 if status then
ShadowTheAge@11 404 lbStatus:SetText(status)
ShadowTheAge@11 405 else
ShadowTheAge@13 406 lbStatus:SetText("")
ShadowTheAge@11 407 end
ShadowTheAge@11 408 end
ShadowTheAge@11 409
ShadowTheAge@13 410 local function stopMovingWidget()
ShadowTheAge@13 411 gui:StopMovingOrSizing()
ShadowTheAge@13 412 local point,_,_,x,y = gui:GetPoint(1);
ShadowTheAge@13 413 db.global.widgetPos = {x=x,y=y,to=point}
ShadowTheAge@13 414 end
ShadowTheAge@13 415
ShadowTheAge@0 416 function addon:CreateUI()
ShadowTheAge@12 417 gui = setupWidget(CreateFrame("Frame","CrossRealmAssistMainUI",nil,"InsetFrameTemplate3"), {SetFrameStrata="LOW",SetWidth=208,SetHeight=60,EnableMouse=true,SetMovable=true})
ShadowTheAge@11 418 local title = setupWidget(CreateFrame("Frame",nil,gui), {SetWidth=190,SetHeight=18,EnableMouse=true,RegisterForDrag="LeftButton"}, 0, 6);
ShadowTheAge@11 419 title:SetScript("OnDragStart", function() gui:StartMoving() end)
ShadowTheAge@13 420 title:SetScript("OnDragStop", stopMovingWidget)
ShadowTheAge@11 421 gui:SetScript("OnHide", addon.Deactivate)
ShadowTheAge@12 422 setupTooltip(title, "ANCHOR_TOP", realmToolip)
ShadowTheAge@11 423
ShadowTheAge@11 424 lbRealm = setupWidget(gui:CreateFontString(nil,"BACKGROUND", "GameFontNormal"), {SetWidth=200,SetHeight=18}, 0, 6)
ShadowTheAge@11 425 lbStatus = setupWidget(gui:CreateFontString(nil,"BACKGROUND", "GameFontHighlightSmallLeft"), {SetWidth=200,SetHeight=10}, 6, 23)
ShadowTheAge@11 426
ShadowTheAge@12 427 btQuick = setupWidget(CreateFrame("Button",nil,gui,"UIMenuButtonStretchTemplate"),{SetWidth=90,SetHeight=20,SetText="Quick join"},4,36)
ShadowTheAge@13 428 btQuick:RegisterForClicks("RightButtonUp","LeftButtonUp")
ShadowTheAge@12 429 btQuick:SetScript("OnClick",addon.DoAutoAction)
ShadowTheAge@13 430 setupTooltip(btQuick, "ANCHOR_BOTTOM", addon.actionTooltip)
ShadowTheAge@12 431 btManual = setupWidget(CreateFrame("Button",nil,gui,"UIMenuButtonStretchTemplate"),{SetWidth=90,SetHeight=20,SetText="Manual join"},94,36)
ShadowTheAge@12 432 btManual:SetScript("OnClick",addon.ShowManualLfg)
ShadowTheAge@11 433 setupWidget(CreateFrame("Button",nil,gui,"UIPanelCloseButton"),{EnableMouse=true,SetWidth=20,SetHeight=20},188,0)
ShadowTheAge@11 434
ShadowTheAge@13 435 btRefresh = setupWidget(CreateFrame("Button",nil,gui,"UIPanelSquareButton"),{SetWidth=20,SetHeight=20},184,16)
ShadowTheAge@11 436 btRefresh.icon:SetTexture("Interface/BUTTONS/UI-RefreshButton")
ShadowTheAge@11 437 btRefresh.icon:SetTexCoord(0,1,0,1);
ShadowTheAge@11 438 btRefresh:SetScript("OnClick",addon.RefreshZone)
ShadowTheAge@11 439
ShadowTheAge@13 440 btSettings = setupWidget(CreateFrame("Button",nil,gui,"UIPanelSquareButton"),{SetWidth=20,SetHeight=20},184,36)
ShadowTheAge@13 441 btSettings.icon:SetTexture("Interface/Worldmap/Gear_64Grey")
ShadowTheAge@13 442 btSettings.icon:SetTexCoord(0.1,0.9,0.1,0.9);
ShadowTheAge@13 443 btSettings:SetScript("OnClick",addon.ShowSettings)
ShadowTheAge@13 444
ShadowTheAge@13 445 local savedPos = db.global.widgetPos
ShadowTheAge@13 446 gui:SetPoint(savedPos.to,savedPos.x,savedPos.y)
ShadowTheAge@12 447 addon:UpdateAutoButtonStatus()
ShadowTheAge@12 448 end
ShadowTheAge@11 449
ShadowTheAge@12 450 function addon:ShowManualLfg()
ShadowTheAge@12 451 if not lfgui then addon:CreateLFGUI() end
ShadowTheAge@12 452 lfgui:Show()
ShadowTheAge@12 453 end
ShadowTheAge@0 454
ShadowTheAge@12 455 function addon.lfgUpdate()
ShadowTheAge@12 456 if hasLfgListChanges then
ShadowTheAge@12 457 lfgTable:Refresh()
ShadowTheAge@12 458 hasLfgListChanges = false
ShadowTheAge@12 459 end
ShadowTheAge@12 460 end
ShadowTheAge@0 461
ShadowTheAge@12 462 function addon:CreateLFGUI()
ShadowTheAge@12 463 lfgui = setupWidget(CreateFrame("Frame","CrossRealmAssistJoinUI",nil,"UIPanelDialogTemplate"), {SetFrameStrata="DIALOG",SetWidth=405,SetHeight=300,EnableMouse=true,SetMovable=true})
ShadowTheAge@12 464 lfgui.title:SetText("Click to join group")
ShadowTheAge@12 465 lfgui:SetScript("OnUpdate",addon.lfgUpdate)
ShadowTheAge@12 466 local titlereg = lfgui:CreateTitleRegion()
ShadowTheAge@12 467 titlereg:SetAllPoints(lfgui.title)
ShadowTheAge@12 468 addon:CreateTabs()
ShadowTheAge@0 469
ShadowTheAge@12 470 lfgTable = ScrollingTable:CreateST({
ShadowTheAge@12 471 {name="Title",width=160},
ShadowTheAge@12 472 {name="#",width=30,align="CENTER"},
ShadowTheAge@12 473 {name="Realm",width=120,align="RIGHT"},
ShadowTheAge@12 474 {name="",width=50,DoCellUpdate=updateTableData}
ShadowTheAge@12 475 },15,16,nil,lfgui);
ShadowTheAge@0 476
ShadowTheAge@13 477 lfgTable:RegisterEvents({OnEnter=ShowLfgInfo,OnLeave=HideTooltip,OnClick=TableCellClick})
ShadowTheAge@0 478
ShadowTheAge@12 479 setupWidget(lfgTable.frame, nil, 10, 45);
ShadowTheAge@12 480 lfgTable.frame:SetBackdrop(nil)
ShadowTheAge@12 481 lfgui:SetPoint("CENTER",0,0)
ShadowTheAge@12 482 refreshLFGList()
ShadowTheAge@0 483
ShadowTheAge@12 484 lbThrottle = setupWidget(lfgui:CreateFontString(nil,"BACKGROUND", "GameFontHighlightSmall"), {SetWidth=300}, 50, 100)
ShadowTheAge@12 485 lbThrottle:Hide();
ShadowTheAge@0 486
ShadowTheAge@12 487 local btRefresh = setupWidget(CreateFrame("Button",nil,lfgui,"UIPanelSquareButton"),{SetWidth=22,SetHeight=22},379,27)
ShadowTheAge@12 488 btRefresh.icon:SetTexture("Interface/BUTTONS/UI-RefreshButton")
ShadowTheAge@12 489 btRefresh.icon:SetTexCoord(0,1,0,1);
ShadowTheAge@12 490 btRefresh:SetScript("OnClick",addon.refreshLfgCurrent)
ShadowTheAge@12 491 end
ShadowTheAge@0 492
ShadowTheAge@12 493 function addon:CreateTabs()
ShadowTheAge@12 494 local prevTab
ShadowTheAge@12 495 for i=1,#lfgGroups do
ShadowTheAge@12 496 local tab = CreateFrame("Button","$parentTab"..i,lfgui,"CharacterFrameTabButtonTemplate")
ShadowTheAge@12 497 tab:SetText((C_LFGList.GetCategoryInfo(lfgGroups[i])));
ShadowTheAge@13 498 tab.searchID = i;
ShadowTheAge@12 499 tab:SetID(i);
ShadowTheAge@12 500 PanelTemplates_TabResize(tab, 0)
ShadowTheAge@12 501 if i == 1 then
ShadowTheAge@12 502 tab:SetPoint("TOPLEFT", lfgui, "BOTTOMLEFT", 10, 7)
ShadowTheAge@12 503 lfgTabSelected = tab
ShadowTheAge@13 504 else
ShadowTheAge@13 505 tab:SetPoint("TOPLEFT", prevTab, "TOPRIGHT",-15,0)
ShadowTheAge@13 506 end
ShadowTheAge@13 507 if curLfgGroup == i then
ShadowTheAge@12 508 PanelTemplates_SelectTab(tab)
ShadowTheAge@12 509 else
ShadowTheAge@12 510 PanelTemplates_DeselectTab(tab)
ShadowTheAge@12 511 end
ShadowTheAge@13 512 tab:SetScript("OnClick", TabClick)
ShadowTheAge@12 513 tabs[i] = tab
ShadowTheAge@12 514 prevTab = tab
ShadowTheAge@12 515 end
ShadowTheAge@0 516 end
ShadowTheAge@0 517
ShadowTheAge@0 518 -- LFG scanning routine
ShadowTheAge@0 519
ShadowTheAge@12 520 function addon.refreshLfgCurrent()
ShadowTheAge@12 521 addon.LfgScan(curLfgGroup)
ShadowTheAge@0 522 end
ShadowTheAge@0 523
ShadowTheAge@13 524 function addon.GetNextAutoScanCategory()
ShadowTheAge@13 525 for i=1,#lfgGroups do
ShadowTheAge@13 526 if not autoScanGroups[i] and db.global.quickJoin[lfgGroups[i]] and i ~= curLfgGroup then return i end
ShadowTheAge@13 527 end
ShadowTheAge@13 528 return nil
ShadowTheAge@13 529 end
ShadowTheAge@13 530
ShadowTheAge@12 531 function addon.LfgScan(group)
ShadowTheAge@13 532 if lfgTable then
ShadowTheAge@13 533 lfgTable:SetData({})
ShadowTheAge@13 534 changeTab(tabs[group])
ShadowTheAge@13 535 end
ShadowTheAge@0 536 lfgScanInProgress = true
ShadowTheAge@12 537 curLfgGroup = group
ShadowTheAge@13 538 C_LFGList.Search(lfgGroups[curLfgGroup],"")
ShadowTheAge@0 539 end
ShadowTheAge@0 540
ShadowTheAge@0 541 function addon:LfgScanFailed(event, reason)
ShadowTheAge@0 542 if reason == "throttled" then
ShadowTheAge@12 543 addon:ScheduleTimer(addon.LfgScan, 2, curLfgGroup)
ShadowTheAge@0 544 end
ShadowTheAge@13 545 if lbThrottle then
ShadowTheAge@13 546 if reason == "throttled" then
ShadowTheAge@13 547 lbThrottle:SetText("LFG scan is delayed (throttled).\nThis page will update automatically...")
ShadowTheAge@13 548 else
ShadowTheAge@13 549 lbThrottle:SetText("Scan failed ("..reason..")")
ShadowTheAge@13 550 end
ShadowTheAge@13 551 lbThrottle:Show()
ShadowTheAge@13 552 end
ShadowTheAge@0 553 end
ShadowTheAge@0 554
ShadowTheAge@0 555 function addon:LfgResponseData()
ShadowTheAge@0 556 lfgScanInProgress = false;
ShadowTheAge@13 557 addon:UpdateAutoButtonStatus()
ShadowTheAge@12 558 if lbThrottle then lbThrottle:Hide() end
ShadowTheAge@12 559 refreshLFGList()
ShadowTheAge@0 560 end
ShadowTheAge@0 561
ShadowTheAge@0 562 function addon:updateAppStatus(event, id, status, oldstatus)
ShadowTheAge@0 563 if status == "invited" then
ShadowTheAge@0 564 LFGListInviteDialog_Accept(LFGListInviteDialog)
ShadowTheAge@0 565 end
ShadowTheAge@12 566 addon:UpdateAutoButtonStatus()
ShadowTheAge@12 567 addon:SetGroupJoinStatus(id, status)
ShadowTheAge@12 568 end
ShadowTheAge@12 569
ShadowTheAge@12 570 function addon:SetGroupJoinStatus(id, status)
ShadowTheAge@12 571 local name = select(12, C_LFGList.GetSearchResultInfo(id))
ShadowTheAge@13 572 if name then
ShadowTheAge@13 573 recentgroups[name] = {status=status, time=GetTime()}
ShadowTheAge@13 574 end
ShadowTheAge@13 575 end
ShadowTheAge@13 576
ShadowTheAge@13 577 function addon:RealmVisited(realm, head)
ShadowTheAge@13 578 recentRealms[realm] = GetTime()
ShadowTheAge@12 579 end
ShadowTheAge@12 580
ShadowTheAge@12 581 function addon:updatePartyInfo()
ShadowTheAge@12 582 local realms = {}
ShadowTheAge@12 583 local inGroup = IsInGroup()
ShadowTheAge@12 584 if inGroup then
ShadowTheAge@12 585 if IsInRaid() then
ShadowTheAge@12 586 for i=1, MAX_RAID_MEMBERS do
ShadowTheAge@12 587 addon:AddUnitIdStat("raid"..i, realms)
ShadowTheAge@12 588 end
ShadowTheAge@12 589 else
ShadowTheAge@12 590 for i=1, MAX_PARTY_MEMBERS do
ShadowTheAge@12 591 addon:AddUnitIdStat("party"..i, realms)
ShadowTheAge@12 592 end
ShadowTheAge@12 593 end
ShadowTheAge@12 594 end
ShadowTheAge@12 595 if inGroup ~= wasInGroup then
ShadowTheAge@13 596 addon:RefreshZone(true)
ShadowTheAge@12 597 wasInGroup = inGroup
ShadowTheAge@12 598 addon:UpdateAutoButtonStatus()
ShadowTheAge@12 599 end
ShadowTheAge@12 600 end
ShadowTheAge@12 601
ShadowTheAge@12 602
ShadowTheAge@12 603
ShadowTheAge@0 604
ShadowTheAge@0 605 -- Zone scanning routine
ShadowTheAge@0 606
ShadowTheAge@0 607 function addon:LeaveCombat()
ShadowTheAge@0 608 addon:UnregisterEvent("PLAYER_REGEN_ENABLED")
ShadowTheAge@0 609 scanstate = 0
ShadowTheAge@0 610 addon:ScanRealm();
ShadowTheAge@0 611 end
ShadowTheAge@0 612
ShadowTheAge@13 613 function addon:RefreshZoneAndClearHistory()
ShadowTheAge@13 614 ClearRealmHistory()
ShadowTheAge@11 615 addon:RefreshZone(true)
ShadowTheAge@11 616 end
ShadowTheAge@11 617
ShadowTheAge@11 618 function addon:RefreshZone(shedule)
ShadowTheAge@11 619 local inst, instType = IsInInstance()
ShadowTheAge@12 620 inInstance = (inst or instType ~= "none")
ShadowTheAge@12 621 if inInstance then
ShadowTheAge@11 622 lbRealm:SetText("Instanced zone")
ShadowTheAge@11 623 curRealmStat = nil
ShadowTheAge@12 624 inInstance = true
ShadowTheAge@11 625 else
ShadowTheAge@12 626 inInstance = false;
ShadowTheAge@11 627 if scanstate == 0 then
ShadowTheAge@11 628 addon:ScanRealm()
ShadowTheAge@11 629 elseif shedule == true and scanstate == 2 then
ShadowTheAge@11 630 addon:SetStatus("Rescan sheduled...")
ShadowTheAge@11 631 scanstate = 3
ShadowTheAge@11 632 end
ShadowTheAge@11 633 end
ShadowTheAge@12 634 addon:UpdateAutoButtonStatus()
ShadowTheAge@11 635 end
ShadowTheAge@11 636
ShadowTheAge@0 637 function addon:ScanRealm()
ShadowTheAge@0 638 if scanstate > 0 then return end
ShadowTheAge@0 639 if InCombatLockdown() then
ShadowTheAge@0 640 addon:RegisterEvent("PLAYER_REGEN_ENABLED","LeaveCombat")
ShadowTheAge@0 641 scanstate = 1
ShadowTheAge@11 642 addon:SetStatus("Scan sheduled after combat...");
ShadowTheAge@0 643 return
ShadowTheAge@0 644 end
ShadowTheAge@0 645 scanstate = 2
ShadowTheAge@11 646 addon:SetStatus("Scanning current realm...");
ShadowTheAge@0 647 local searchString = _G.WHO_TAG_ZONE .. '"' .. GetZoneText() .. '"';
ShadowTheAge@0 648 wholib:Who(searchString, {callback = "ScanResult", handler=addon})
ShadowTheAge@0 649 end
ShadowTheAge@0 650
ShadowTheAge@0 651 function addon:ScanResult(query, results, complete)
ShadowTheAge@0 652 local realms = {}
ShadowTheAge@0 653 for _, player in ipairs(results) do
ShadowTheAge@0 654 addon:AddRealmStat(player.Name, realms);
ShadowTheAge@0 655 end
ShadowTheAge@0 656 curRealmStat = addon:GetRealmStat(realms);
ShadowTheAge@11 657 curRealmStat.complete = complete
ShadowTheAge@0 658 addon:updateCurrentRealm();
ShadowTheAge@0 659 local rescan = scanstate == 3
ShadowTheAge@0 660 scanstate = 0;
ShadowTheAge@0 661 if rescan then addon:ScanRealm() end
ShadowTheAge@0 662 end
ShadowTheAge@0 663
ShadowTheAge@0 664 function addon:AddRealmStat(name, realms)
ShadowTheAge@11 665 if (name == playerName) then return end
ShadowTheAge@11 666 local _, realm = strsplit(realmSep, name)
ShadowTheAge@0 667 realm = realm or homeRealm
ShadowTheAge@0 668 realms[realm] = (realms[realm] or 0) + 1
ShadowTheAge@0 669 end
ShadowTheAge@0 670
ShadowTheAge@0 671 function addon:AddUnitIdStat(unitid, realms)
ShadowTheAge@0 672 local name, realm = UnitName(unitid);
ShadowTheAge@0 673 if not name then return end
ShadowTheAge@0 674 if realm == "" then realm = homeRealm end
ShadowTheAge@0 675 realm = realm or homeRealm
ShadowTheAge@0 676 realms[realm] = (realms[realm] or 0) + 1
ShadowTheAge@0 677 end
ShadowTheAge@0 678
ShadowTheAge@0 679 function addon:GetRealmStat(realms)
ShadowTheAge@0 680 local rcount = 0;
ShadowTheAge@0 681 local stat = {};
ShadowTheAge@0 682 local pcount = 0;
ShadowTheAge@0 683 for realm,count in pairs(realms) do
ShadowTheAge@0 684 table.insert(stat,{realm=realm,count=count})
ShadowTheAge@0 685 rcount = rcount + 1;
ShadowTheAge@0 686 pcount = pcount + count;
ShadowTheAge@0 687 end
ShadowTheAge@0 688 if rcount > 1 then
ShadowTheAge@0 689 table.sort(stat, function(a,b) return a.count > b.count end)
ShadowTheAge@0 690 stat.max = stat[1].count
ShadowTheAge@0 691 else stat.max = 0 end
ShadowTheAge@0 692 stat.players = pcount;
ShadowTheAge@0 693 stat.realms = rcount;
ShadowTheAge@0 694 return stat;
ShadowTheAge@0 695 end
ShadowTheAge@0 696
ShadowTheAge@0 697 function addon:updateCurrentRealm()
ShadowTheAge@11 698 addon:SetStatus();
ShadowTheAge@11 699 if not curRealmStat or curRealmStat.realms < 1 then
ShadowTheAge@11 700 lbRealm:SetText("Unknown realm (No players)")
ShadowTheAge@11 701 return;
ShadowTheAge@0 702 end
ShadowTheAge@11 703
ShadowTheAge@11 704 local bestRealm = curRealmStat[1]
ShadowTheAge@13 705 addon:RealmVisited(bestRealm.realm, true)
ShadowTheAge@12 706 local prevThreshold = math.min(bestRealm.count/3,10)
ShadowTheAge@11 707 local mixCount = 0
ShadowTheAge@11 708 for i=2,curRealmStat.realms do
ShadowTheAge@0 709 local data = curRealmStat[i]
ShadowTheAge@11 710 if data.count >= prevThreshold then
ShadowTheAge@11 711 mixCount = mixCount + 1
ShadowTheAge@13 712 addon:RealmVisited(data.realm)
ShadowTheAge@12 713 prevThreshold = math.min(data.count/3,10)
ShadowTheAge@0 714 end
ShadowTheAge@0 715 end
ShadowTheAge@11 716 curRealmStat.threshold = prevThreshold
ShadowTheAge@11 717
ShadowTheAge@11 718 if (mixCount > 0) then
ShadowTheAge@11 719 lbRealm:SetText("Mixed "..bestRealm.realm.." +"..mixCount)
ShadowTheAge@11 720 else
ShadowTheAge@11 721 lbRealm:SetText(bestRealm.realm)
ShadowTheAge@0 722 end
ShadowTheAge@0 723 end
ShadowTheAge@0 724
ShadowTheAge@12 725
ShadowTheAge@12 726
ShadowTheAge@12 727
ShadowTheAge@12 728
ShadowTheAge@12 729
ShadowTheAge@12 730 -- Auto action button
ShadowTheAge@12 731
ShadowTheAge@13 732 local action
ShadowTheAge@12 733
ShadowTheAge@13 734 local LeaveGroup = {
ShadowTheAge@13 735 func = LeaveParty;
ShadowTheAge@13 736 tooltip = "Leave current joined group",
ShadowTheAge@13 737 text = "Leave group"
ShadowTheAge@13 738 }
ShadowTheAge@13 739
ShadowTheAge@13 740 local CancelJoin = {
ShadowTheAge@13 741 func = function()
ShadowTheAge@13 742 local apps = C_LFGList.GetApplications();
ShadowTheAge@13 743 if apps[1] then
ShadowTheAge@13 744 C_LFGList.CancelApplication(apps[1])
ShadowTheAge@13 745 end
ShadowTheAge@13 746 end,
ShadowTheAge@13 747 tooltip = "Cancel your current join application",
ShadowTheAge@13 748 text = "Cancel join"
ShadowTheAge@13 749 }
ShadowTheAge@13 750
ShadowTheAge@13 751 local QuickJoin = {
ShadowTheAge@13 752 func = function(self, button)
ShadowTheAge@13 753 if button == "RightButton" then
ShadowTheAge@13 754 addon:SetGroupJoinStatus(self.groupToJoin, "_skip")
ShadowTheAge@13 755 else
ShadowTheAge@13 756 local delisted = select(11, C_LFGList.GetSearchResultInfo(self.groupToJoin))
ShadowTheAge@13 757 if delisted == false then
ShadowTheAge@13 758 JoinGroup(self.groupToJoin)
ShadowTheAge@13 759 else
ShadowTheAge@13 760 addon:SetStatus("Group just delisted")
ShadowTheAge@13 761 end
ShadowTheAge@13 762 end
ShadowTheAge@13 763 end,
ShadowTheAge@13 764 findGroup = function()
ShadowTheAge@13 765 local count, list = C_LFGList.GetSearchResults()
ShadowTheAge@13 766 local best
ShadowTheAge@13 767 local bestvalue = 0
ShadowTheAge@13 768 for i = 1,count do
ShadowTheAge@13 769 local rid = list[i];
ShadowTheAge@13 770 if not rid then break end
ShadowTheAge@13 771 local value = WeightLfgItem(rid, true);
ShadowTheAge@13 772 if value > bestvalue then
ShadowTheAge@13 773 best = rid
ShadowTheAge@13 774 bestvalue = value
ShadowTheAge@13 775 end
ShadowTheAge@13 776 end
ShadowTheAge@13 777 return best
ShadowTheAge@13 778 end,
ShadowTheAge@13 779 tooltip = function(self)
ShadowTheAge@13 780 AddLfgGroupInfo(self.groupToJoin, true)
ShadowTheAge@13 781 GameTooltip:AddLine(" ")
ShadowTheAge@13 782 GameTooltip:AddDoubleLine("Click to join","Right click to skip",0,1,0,1,0.5,0)
ShadowTheAge@13 783 end,
ShadowTheAge@13 784 text = "Quick join"
ShadowTheAge@13 785 }
ShadowTheAge@13 786
ShadowTheAge@13 787 local ScanNext = {
ShadowTheAge@13 788 func = function(self)
ShadowTheAge@13 789 autoScanGroups[curLfgGroup] = 1
ShadowTheAge@13 790 addon.LfgScan(self.category)
ShadowTheAge@13 791 end,
ShadowTheAge@13 792 tooltip = function(self)
ShadowTheAge@13 793 GameTooltip:AddLine("Scan "..(C_LFGList.GetCategoryInfo(lfgGroups[self.category])))
ShadowTheAge@13 794 end,
ShadowTheAge@13 795 text = "Scan more"
ShadowTheAge@13 796 }
ShadowTheAge@13 797
ShadowTheAge@13 798 local NeedReset = {
ShadowTheAge@13 799 func = function()
ShadowTheAge@13 800 wipe(autoScanGroups);
ShadowTheAge@13 801 local categoryToScan = addon.GetNextAutoScanCategory()
ShadowTheAge@13 802 if categoryToScan then
ShadowTheAge@13 803 addon.LfgScan(categoryToScan)
ShadowTheAge@13 804 end
ShadowTheAge@13 805 end,
ShadowTheAge@13 806 tooltip = "Scan again",
ShadowTheAge@13 807 text = "Restart scan"
ShadowTheAge@13 808 }
ShadowTheAge@13 809
ShadowTheAge@13 810 local Wait = {
ShadowTheAge@13 811 tooltip = "Scan in progress",
ShadowTheAge@13 812 text = "Wait..."
ShadowTheAge@13 813 }
ShadowTheAge@13 814
ShadowTheAge@13 815 local ShowQuickHint = {
ShadowTheAge@13 816 tooltip = "Quick Join",
ShadowTheAge@13 817 text = "Quick Join",
ShadowTheAge@13 818 func = function()
ShadowTheAge@13 819 StaticPopupDialogs["CROSS_REALM_ASSIST"] = {
ShadowTheAge@13 820 text = "Quick Join button will automatically join you to a random group with autoinvite and medium number of players. You never join same group twice, you need to clear join history to do so. This message can be disabled in options.",
ShadowTheAge@13 821 button1 = OKAY,
ShadowTheAge@13 822 hideOnEscape = true,
ShadowTheAge@13 823 preferredIndex = 3,
ShadowTheAge@13 824 }
ShadowTheAge@13 825 StaticPopup_Show("CROSS_REALM_ASSIST")
ShadowTheAge@13 826 hintShown = true;
ShadowTheAge@13 827 end
ShadowTheAge@13 828 }
ShadowTheAge@13 829
ShadowTheAge@13 830 function addon.DoAutoAction(widget, button)
ShadowTheAge@13 831 addon:SetStatus()
ShadowTheAge@13 832 if action and action.func then
ShadowTheAge@13 833 action:func(button)
ShadowTheAge@13 834 end
ShadowTheAge@13 835 addon:UpdateAutoButtonStatus()
ShadowTheAge@13 836 end
ShadowTheAge@13 837
ShadowTheAge@13 838 function addon.actionTooltip()
ShadowTheAge@13 839 local tooltip = action.tooltip
ShadowTheAge@13 840 if type(tooltip) == 'function' then
ShadowTheAge@13 841 tooltip(action)
ShadowTheAge@13 842 else
ShadowTheAge@13 843 GameTooltip:AddLine(tooltip)
ShadowTheAge@11 844 end
ShadowTheAge@11 845 end
ShadowTheAge@11 846
ShadowTheAge@13 847 function addon:UpdateAutoButtonStatus()
ShadowTheAge@13 848 if not btQuick then return end
ShadowTheAge@13 849 btQuick:Enable()
ShadowTheAge@13 850 if not hintShown and db.global.quickJoinHint then
ShadowTheAge@13 851 action = ShowQuickHint;
ShadowTheAge@13 852 elseif IsInGroup() then
ShadowTheAge@13 853 action = LeaveGroup;
ShadowTheAge@13 854 elseif C_LFGList.GetNumApplications() > 0 then
ShadowTheAge@13 855 action = CancelJoin;
ShadowTheAge@13 856 elseif lfgScanInProgress then
ShadowTheAge@13 857 action = Wait
ShadowTheAge@13 858 else
ShadowTheAge@13 859 local group = QuickJoin.findGroup();
ShadowTheAge@13 860 if group then
ShadowTheAge@13 861 action = QuickJoin;
ShadowTheAge@13 862 QuickJoin.groupToJoin = group
ShadowTheAge@13 863 else
ShadowTheAge@13 864 local categoryToScan = addon.GetNextAutoScanCategory()
ShadowTheAge@13 865 if (categoryToScan) then
ShadowTheAge@13 866 action = ScanNext;
ShadowTheAge@13 867 ScanNext.category = categoryToScan
ShadowTheAge@13 868 else
ShadowTheAge@13 869 action = NeedReset;
ShadowTheAge@13 870 end
ShadowTheAge@13 871 end
ShadowTheAge@13 872 end
ShadowTheAge@13 873 btQuick:SetText(action.text)
ShadowTheAge@13 874 if GameTooltip:GetOwner() == btQuick then
ShadowTheAge@13 875 ShowTooltip(btQuick)
ShadowTheAge@0 876 end
ShadowTheAge@0 877 end
ShadowTheAge@0 878
ShadowTheAge@12 879
ShadowTheAge@13 880
ShadowTheAge@13 881
ShadowTheAge@13 882
ShadowTheAge@13 883
ShadowTheAge@13 884 -- Settings
ShadowTheAge@13 885
ShadowTheAge@13 886 local function toggleMinimapIcon(btn, arg1, arg2, checked)
ShadowTheAge@13 887 local hidden = not checked;
ShadowTheAge@13 888 db.global.minimap.hide = hidden;
ShadowTheAge@13 889 if hidden then
ShadowTheAge@13 890 DEFAULT_CHAT_FRAME:AddMessage("|cffff0000Type |cffffffff/cra |cffff0000in chat to open Cross Realm Assist without minimap button");
ShadowTheAge@13 891 minimapIcon:Hide("CrossRealmAssistMinimapIcon")
ShadowTheAge@13 892 else
ShadowTheAge@13 893 minimapIcon:Show("CrossRealmAssistMinimapIcon")
ShadowTheAge@13 894 end
ShadowTheAge@0 895 end
ShadowTheAge@0 896
ShadowTheAge@13 897 local function toggleQuickJoinHint(btn, arg1, arg2, checked)
ShadowTheAge@13 898 db.global.quickJoinHint = checked
ShadowTheAge@0 899 end
ShadowTheAge@0 900
ShadowTheAge@13 901 local function toggleQuickJoin(btn, arg1, arg2, checked)
ShadowTheAge@13 902 db.global.quickJoin[arg1] = checked
ShadowTheAge@13 903 end
ShadowTheAge@13 904
ShadowTheAge@13 905 local function ClearJoinHistory()
ShadowTheAge@13 906 recentgroups = {}
ShadowTheAge@13 907 addon:UpdateAutoButtonStatus()
ShadowTheAge@13 908 if lfgTable then lfgTable:Refresh() end
ShadowTheAge@13 909 end
ShadowTheAge@13 910
ShadowTheAge@13 911 --[[local function resetPos()
ShadowTheAge@13 912 db.global.widgetPos = DefaultWidgetPos
ShadowTheAge@13 913 if gui then
ShadowTheAge@13 914 gui:ClearAllPoints()
ShadowTheAge@13 915 gui:SetPoint(DefaultWidgetPos.to,DefaultWidgetPos.x,DefaultWidgetPos.y)
ShadowTheAge@0 916 end
ShadowTheAge@13 917 end]]
ShadowTheAge@13 918
ShadowTheAge@13 919 local function initMenu(self, level)
ShadowTheAge@13 920 if not level then return end
ShadowTheAge@13 921 if level == 1 then
ShadowTheAge@13 922 UIDropDownMenu_AddButton({text="Clear realm history",notCheckable=1,func=ClearRealmHistory}, level)
ShadowTheAge@13 923 UIDropDownMenu_AddButton({text="Clear join history",notCheckable=1,func=ClearJoinHistory}, level)
ShadowTheAge@13 924 UIDropDownMenu_AddButton({disabled=1,notCheckable=1}, level)
ShadowTheAge@13 925 UIDropDownMenu_AddButton({isTitle=1,text="Settings",notCheckable=1}, level)
ShadowTheAge@13 926 UIDropDownMenu_AddButton({text="Show Minimap Button",checked=not db.global.minimap.hide, func=toggleMinimapIcon,keepShownOnClick=true,isNotRadio=true}, level)
ShadowTheAge@13 927 UIDropDownMenu_AddButton({text="Show Quick Join Hint",checked=db.global.quickJoinHint, func=toggleQuickJoinHint,keepShownOnClick=true,isNotRadio=true}, level)
ShadowTheAge@13 928 UIDropDownMenu_AddButton({text="Quick join categories",notCheckable=1,hasArrow=1,value="qjc",keepShownOnClick=true}, level)
ShadowTheAge@13 929 elseif level == 2 then
ShadowTheAge@13 930 if UIDROPDOWNMENU_MENU_VALUE == "qjc" then
ShadowTheAge@13 931 for i=1,#lfgGroups do
ShadowTheAge@13 932 local groupId = lfgGroups[i]
ShadowTheAge@13 933 UIDropDownMenu_AddButton({text=(C_LFGList.GetCategoryInfo(groupId)),checked=db.global.quickJoin[groupId],arg1=groupId,func=toggleQuickJoin,keepShownOnClick=true,isNotRadio=true}, level)
ShadowTheAge@13 934 end
ShadowTheAge@13 935 end
ShadowTheAge@13 936 end
ShadowTheAge@13 937 end
ShadowTheAge@13 938
ShadowTheAge@13 939 function addon.ShowSettings(frame)
ShadowTheAge@13 940 if not settingsMenu then
ShadowTheAge@13 941 settingsMenu = CreateFrame("Frame", "CrossRealmAssistMenu")
ShadowTheAge@13 942 settingsMenu.displayMode = "MENU"
ShadowTheAge@13 943 settingsMenu.initialize = initMenu
ShadowTheAge@13 944 end
ShadowTheAge@13 945 ToggleDropDownMenu(1, nil, settingsMenu, frame, 10, 0)
ShadowTheAge@12 946 end