annotate CrossRealmAssist.lua @ 36:8288dff494ec beta-0.76

Oops, critical fix :)
author ShadowTheAge
date Mon, 26 Oct 2015 01:18:15 +0300
parents f39b5803b4c1
children 616d67ff7543
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@32 4 local realmInfo = LibStub:GetLibrary('LibRealmInfo')
ShadowTheAge@12 5 local ScrollingTable = LibStub("ScrollingTable");
ShadowTheAge@13 6 local ldb = LibStub("LibDataBroker-1.1")
ShadowTheAge@13 7 local minimapIcon = LibStub("LibDBIcon-1.0")
ShadowTheAge@13 8 local db
ShadowTheAge@0 9
ShadowTheAge@13 10 local homeRealm, realmSep, gui, btRefresh, btSettings, btQuick, btManual, lbRealm, lbStatus, playerName, lfgui, lfgTabSelected, lfgTable, lbThrottle, curLfgGroup, sheduledScan, wasInGroup, inInstance
ShadowTheAge@13 11 local settingsMenu
ShadowTheAge@13 12 local hintShown
ShadowTheAge@32 13 local btFilterCount, cbHideNoAutoinv, edFilterText
ShadowTheAge@0 14
ShadowTheAge@12 15 local tabs = {}
ShadowTheAge@27 16 local curRealmStat
ShadowTheAge@0 17 local scanstate=0
ShadowTheAge@0 18 local recentRealms={}
ShadowTheAge@12 19 local recentgroups={}
ShadowTheAge@13 20 local autoScanGroups={}
ShadowTheAge@0 21 local active=false
ShadowTheAge@21 22 local allLanguageTable={}
ShadowTheAge@32 23 local extraColumns
ShadowTheAge@32 24 local tableTemplate
ShadowTheAge@32 25 local filterString
ShadowTheAge@32 26 local filterByCountId=1
ShadowTheAge@0 27
ShadowTheAge@32 28 addon.lfgGroups={
ShadowTheAge@0 29 6, -- Custom
ShadowTheAge@0 30 10, -- Ashran
ShadowTheAge@0 31 1, -- Quests
ShadowTheAge@13 32 3, -- Raids
ShadowTheAge@13 33 8 -- BGs
ShadowTheAge@0 34 }
ShadowTheAge@0 35
ShadowTheAge@12 36 local StatusTable = {
ShadowTheAge@12 37 ["invited"]="Invited",
ShadowTheAge@12 38 ["declined"]="Declined",
ShadowTheAge@12 39 ["timedout"]="Timed out",
ShadowTheAge@12 40 ["applied"]="Applied",
ShadowTheAge@12 41 ["cancelled"]="Join cancelled",
ShadowTheAge@12 42 ["inviteaccepted"]="Joined",
ShadowTheAge@13 43 ["_init"]="Join request",
ShadowTheAge@13 44 ["_skip"]="Skipped"
ShadowTheAge@12 45 }
ShadowTheAge@13 46 local DefaultWidgetPos = {x=0, y=200, to="CENTER"}
ShadowTheAge@13 47 local SettingsDefaults={
ShadowTheAge@13 48 global={
ShadowTheAge@13 49 minimap = {},
ShadowTheAge@13 50 widgetPos=DefaultWidgetPos,
ShadowTheAge@13 51 quickJoinHint = true,
ShadowTheAge@27 52 quickJoin={[6]=1},
ShadowTheAge@27 53 allLanguages = true,
ShadowTheAge@32 54 stoplist = {"no hop","nohop","no realm","kick"},
ShadowTheAge@32 55 priorityList = {"realm hop","realmhop","garrison"},
ShadowTheAge@32 56 lfgPanelScale = 1.0, uiScale = 1.0, listItemCount=15,
ShadowTheAge@32 57 extraColumns = {}
ShadowTheAge@13 58 }
ShadowTheAge@13 59 }
ShadowTheAge@32 60 local filterByCountList = {
ShadowTheAge@32 61 {text="Any number of players",min=1,max=40},
ShadowTheAge@32 62 {text="Groups (1-5)",min=1,max=5},
ShadowTheAge@32 63 {text="Raids (6-40)",min=6,max=40},
ShadowTheAge@32 64 {text="Non-full groups (1-4)",min=1,max=4},
ShadowTheAge@32 65 {text="Non-full raids (6-35)",min=6,max=35}
ShadowTheAge@32 66 }
ShadowTheAge@12 67
ShadowTheAge@12 68
ShadowTheAge@12 69 -- Utils functions
ShadowTheAge@12 70
ShadowTheAge@32 71
ShadowTheAge@32 72 local function searchInList(name, list)
ShadowTheAge@32 73 if list and name then
ShadowTheAge@32 74 local lname = string.lower(name);
ShadowTheAge@32 75 for i=1, #list do
ShadowTheAge@32 76 if string.find(lname, list[i], 1, true) then return true end
ShadowTheAge@32 77 end
ShadowTheAge@32 78 end
ShadowTheAge@32 79 return false;
ShadowTheAge@32 80 end
ShadowTheAge@32 81
ShadowTheAge@12 82 local function PlayerName(fullname)
ShadowTheAge@12 83 fullname = fullname or "???-???"
ShadowTheAge@12 84 local name, realm = strsplit(realmSep, fullname)
ShadowTheAge@12 85 realm = realm or homeRealm;
ShadowTheAge@12 86 return name, realm;
ShadowTheAge@12 87 end
ShadowTheAge@12 88
ShadowTheAge@12 89 local function canJoinGroup()
ShadowTheAge@12 90 return (not IsInGroup()) or (UnitIsGroupLeader('player') and not IsInRaid())
ShadowTheAge@12 91 end
ShadowTheAge@12 92
ShadowTheAge@32 93 local function sortByTypeAndName(a,b)
ShadowTheAge@32 94 if a.type == b.type then
ShadowTheAge@32 95 return a.name < b.name
ShadowTheAge@32 96 else
ShadowTheAge@32 97 return a.type < b.type;
ShadowTheAge@32 98 end
ShadowTheAge@12 99 end
ShadowTheAge@12 100
ShadowTheAge@12 101
ShadowTheAge@12 102 -- UI functions
ShadowTheAge@12 103
ShadowTheAge@12 104 local function createIcon(owner, icon, id)
ShadowTheAge@12 105 local image = owner:CreateTexture(nil, "BACKGROUND")
ShadowTheAge@12 106 image:SetWidth(16)
ShadowTheAge@12 107 image:SetHeight(16)
ShadowTheAge@12 108 image:SetTexture(icon)
ShadowTheAge@12 109 image:SetPoint("TOPLEFT",owner,"TOPLEFT",id*16,0)
ShadowTheAge@12 110 return image
ShadowTheAge@12 111 end
ShadowTheAge@0 112
ShadowTheAge@11 113 local function setupWidget(widget, parameters, x, y)
ShadowTheAge@11 114 if parameters then
ShadowTheAge@11 115 for key,value in pairs(parameters) do widget[key](widget,value) end
ShadowTheAge@11 116 end
ShadowTheAge@11 117 if y then
ShadowTheAge@11 118 widget:SetPoint("TOPLEFT",widget:GetParent(),"TOPLEFT",x,-y)
ShadowTheAge@11 119 end
ShadowTheAge@11 120 return widget
ShadowTheAge@11 121 end
ShadowTheAge@11 122
ShadowTheAge@11 123 local function ShowTooltip(widget)
ShadowTheAge@11 124 GameTooltip:SetOwner(widget, widget.TooltipAnchor)
ShadowTheAge@11 125 GameTooltip:ClearLines()
ShadowTheAge@11 126 widget:TooltipFactory()
ShadowTheAge@11 127 GameTooltip:Show()
ShadowTheAge@11 128 end
ShadowTheAge@11 129
ShadowTheAge@11 130 local function HideTooltip(widget)
ShadowTheAge@11 131 GameTooltip:Hide()
ShadowTheAge@11 132 end
ShadowTheAge@11 133
ShadowTheAge@11 134 local function setupTooltip(widget, anchor, factory)
ShadowTheAge@11 135 widget.TooltipAnchor = anchor;
ShadowTheAge@11 136 widget.TooltipFactory = factory;
ShadowTheAge@11 137 widget:SetScript("OnEnter", ShowTooltip)
ShadowTheAge@11 138 widget:SetScript("OnLeave", HideTooltip)
ShadowTheAge@11 139 end
ShadowTheAge@11 140
ShadowTheAge@13 141 local function TabClick(tab)
ShadowTheAge@13 142 if tab == lfgTabSelected then return end
ShadowTheAge@13 143 addon.LfgScan(tab.searchID)
ShadowTheAge@13 144 end
ShadowTheAge@13 145
ShadowTheAge@13 146 local function changeTab(tab)
ShadowTheAge@12 147 PanelTemplates_DeselectTab(lfgTabSelected)
ShadowTheAge@12 148 lfgTabSelected = tab
ShadowTheAge@12 149 PanelTemplates_SelectTab(lfgTabSelected)
ShadowTheAge@12 150 end
ShadowTheAge@0 151
ShadowTheAge@12 152 local function realmToolip()
ShadowTheAge@12 153 if not curRealmStat then return end
ShadowTheAge@12 154 local players = curRealmStat.players;
ShadowTheAge@12 155 local threshold = curRealmStat.threshold
ShadowTheAge@12 156 GameTooltip:AddLine("Players in zone: "..players)
ShadowTheAge@12 157 if not curRealmStat.complete then
ShadowTheAge@12 158 GameTooltip:AppendText("+")
ShadowTheAge@12 159 end
ShadowTheAge@12 160 for i=1,curRealmStat.realms do
ShadowTheAge@12 161 local data = curRealmStat[i]
ShadowTheAge@12 162 local percent = math.ceil(100 * data.count / players - 0.5) .. "%";
ShadowTheAge@12 163 if data.count >= threshold then
ShadowTheAge@12 164 GameTooltip:AddDoubleLine(data.realm, percent, 0,1,0,0,1,0)
ShadowTheAge@12 165 else
ShadowTheAge@12 166 GameTooltip:AddDoubleLine(data.realm, percent, 0.5,0.5,0.5,0.5,0.5,0.5)
ShadowTheAge@12 167 end
ShadowTheAge@12 168 end
ShadowTheAge@0 169 end
ShadowTheAge@0 170
ShadowTheAge@13 171 local function ClearRealmHistory()
ShadowTheAge@13 172 recentRealms = {}
ShadowTheAge@13 173 addon:updateCurrentRealm()
ShadowTheAge@13 174 if lfgTable then lfgTable:Refresh() end
ShadowTheAge@13 175 end
ShadowTheAge@13 176
ShadowTheAge@12 177
ShadowTheAge@12 178
ShadowTheAge@12 179
ShadowTheAge@12 180
ShadowTheAge@12 181
ShadowTheAge@12 182
ShadowTheAge@12 183 -- LFG list data providers, filters and tooltips
ShadowTheAge@12 184
ShadowTheAge@12 185 local lfgScanInProgress=false
ShadowTheAge@12 186 local hasLfgListChanges=false
ShadowTheAge@12 187
ShadowTheAge@12 188 local function addTooltipLineIcon(predicat, text, icon, r, g, b, wrap)
ShadowTheAge@12 189 if predicat then
ShadowTheAge@12 190 GameTooltip:AddLine(text, r, g, b, wrap)
ShadowTheAge@12 191 if icon then GameTooltip:AddTexture(icon) end
ShadowTheAge@12 192 end
ShadowTheAge@12 193 end
ShadowTheAge@12 194
ShadowTheAge@32 195 local function getJoinedAgo(name)
ShadowTheAge@32 196 if recentgroups[name] then
ShadowTheAge@32 197 return GetTime() - recentgroups[name].time
ShadowTheAge@32 198 end
ShadowTheAge@32 199 end
ShadowTheAge@32 200
ShadowTheAge@12 201 local function WeightLfgItem(id, forAutoJoin)
ShadowTheAge@12 202 local _, action, caption, desc, voice, ilvl, time, bnetfr, charfr, guild, delisted, fullname, pcount, autoinv = C_LFGList.GetSearchResultInfo(id)
ShadowTheAge@12 203 if delisted then return 0 end
ShadowTheAge@12 204 local name,realm = PlayerName(fullname);
ShadowTheAge@32 205 local ldesc = caption .. "|" .. desc;
ShadowTheAge@32 206 if searchInList(ldesc, db.global.stoplist) then return 0 end
ShadowTheAge@32 207 local isHopGroup = searchInList(ldesc, db.global.priorityList);
ShadowTheAge@12 208 if forAutoJoin then
ShadowTheAge@27 209 if not autoinv or recentgroups[fullname] or (not isHopGroup and (pcount >= 35 or pcount <= 5)) then return 0 end
ShadowTheAge@12 210 end
ShadowTheAge@12 211
ShadowTheAge@12 212 local autoinvWeight = autoinv and 5 or 2
ShadowTheAge@29 213 local hopCoef = isHopGroup and 3 or 1
ShadowTheAge@12 214
ShadowTheAge@12 215 local visCoef = 1
ShadowTheAge@12 216 if recentgroups[fullname] then
ShadowTheAge@32 217 local ago = getJoinedAgo(fullname)
ShadowTheAge@12 218 visCoef = math.min(1,ago/600)
ShadowTheAge@12 219 end
ShadowTheAge@12 220
ShadowTheAge@12 221 local leaderRealm = 3 -- recently visited realms
ShadowTheAge@13 222 local realmVis = recentRealms[realm]
ShadowTheAge@13 223 local leaderRealm = 3;
ShadowTheAge@13 224 if realmVis then
ShadowTheAge@13 225 local ago = GetTime() - realmVis
ShadowTheAge@13 226 leaderRealm = 1 + 2*math.min(1,ago/600);
ShadowTheAge@13 227 end
ShadowTheAge@12 228
ShadowTheAge@12 229 local countWeight = 4 -- count weight
ShadowTheAge@29 230 if not isHopGroup then
ShadowTheAge@29 231 if pcount >= 39 or pcount <= 1 then countWeight = 1
ShadowTheAge@29 232 elseif pcount >= 35 or pcount <= 5 then countWeight = 2
ShadowTheAge@29 233 elseif pcount >= 30 or pcount <= 10 then countWeight = 3 end
ShadowTheAge@27 234 end
ShadowTheAge@12 235
ShadowTheAge@12 236 local ageWeight = 2
ShadowTheAge@12 237 if time > 1200 then ageWeight = 4
ShadowTheAge@12 238 elseif time > 300 then ageWeight = 3 end
ShadowTheAge@12 239
ShadowTheAge@27 240 return leaderRealm * countWeight * visCoef * autoinvWeight * ageWeight * hopCoef;
ShadowTheAge@12 241 end
ShadowTheAge@12 242
ShadowTheAge@13 243 local function AddLfgGroupInfo(id, short)
ShadowTheAge@13 244 local _, action, caption, desc, voice, ilvl, time, bnetfr, charfr, guild, delisted, fullname, pcount, autoinv = C_LFGList.GetSearchResultInfo(id)
ShadowTheAge@12 245 local friends = bnetfr+charfr+guild
ShadowTheAge@12 246 GameTooltip:ClearLines()
ShadowTheAge@12 247 GameTooltip:AddLine(caption,1,1,1)
ShadowTheAge@12 248 addTooltipLineIcon(desc ~= "", desc, nil, 0.5, 0.5, 0.5, true)
ShadowTheAge@12 249 local name, realm = PlayerName(fullname)
ShadowTheAge@13 250 GameTooltip:AddDoubleLine("Players:",pcount)
ShadowTheAge@12 251 GameTooltip:AddDoubleLine("Leader:",name)
ShadowTheAge@12 252 GameTooltip:AddDoubleLine("Leader realm:",realm)
ShadowTheAge@13 253 if recentRealms[realm] then
ShadowTheAge@13 254 local ago = GetTime() - recentRealms[realm]
ShadowTheAge@13 255 GameTooltip:AddDoubleLine("Realm visited",SecondsToTime(ago, false, false, 1, false).." ago",1,0.5,0,1,0.5,0)
ShadowTheAge@13 256 else
ShadowTheAge@13 257 GameTooltip:AddDoubleLine(" ","Realm not visited!",0,0,0,0,1,0)
ShadowTheAge@13 258 end
ShadowTheAge@13 259 if not short then
ShadowTheAge@13 260 addTooltipLineIcon(ilvl > 0, "Min. ilvl: "..ilvl, READY_CHECK_WAITING_TEXTURE, 1, 1, 0)
ShadowTheAge@13 261 addTooltipLineIcon(voice ~= "", "Voice: "..voice, READY_CHECK_WAITING_TEXTURE, 1, 1, 0)
ShadowTheAge@13 262 addTooltipLineIcon(friends > 0, "Friends: "..friends, READY_CHECK_WAITING_TEXTURE, 1, 1, 0)
ShadowTheAge@32 263 addTooltipLineIcon(autoinv, "Autoaccept!", READY_CHECK_READY_TEXTURE, 0, 1, 0)
ShadowTheAge@13 264 local visitinfo = recentgroups[fullname]
ShadowTheAge@13 265 if visitinfo then
ShadowTheAge@13 266 local ago = GetTime() - visitinfo.time;
ShadowTheAge@13 267 GameTooltip:AddDoubleLine(StatusTable[visitinfo.status] or visitinfo.status,SecondsToTime(ago, false, false, 1, false).." ago",1,0,0,1,0,0)
ShadowTheAge@13 268 GameTooltip:AddTexture(READY_CHECK_NOT_READY_TEXTURE)
ShadowTheAge@13 269 end
ShadowTheAge@12 270 end
ShadowTheAge@12 271 GameTooltip:Show()
ShadowTheAge@12 272 end
ShadowTheAge@12 273
ShadowTheAge@13 274 local function ShowLfgInfo(rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...)
ShadowTheAge@13 275 if not realrow then return end
ShadowTheAge@13 276 local rowdata = scrollingTable:GetRow(realrow);
ShadowTheAge@13 277 GameTooltip:SetOwner(rowFrame, "ANCHOR_BOTTOMLEFT",-10,25)
ShadowTheAge@13 278 AddLfgGroupInfo(rowdata.id);
ShadowTheAge@13 279 end
ShadowTheAge@13 280
ShadowTheAge@12 281 local function updateTableData(rowFrame, cellFrame, data, cols, row, realrow, column, fShow, table, ...)
ShadowTheAge@12 282 if fShow then
ShadowTheAge@12 283 local rowdata = table:GetRow(realrow);
ShadowTheAge@12 284 local icons = cellFrame.icons
ShadowTheAge@12 285 local _, action, caption, desc, voice, ilvl, time, bnetfr, charfr, guild, delisted, fullname, pcount, autoinv = C_LFGList.GetSearchResultInfo(rowdata.id)
ShadowTheAge@12 286 if not icons then
ShadowTheAge@12 287 local miscdata = createIcon(cellFrame,READY_CHECK_WAITING_TEXTURE,0)
ShadowTheAge@12 288 local autoinv = createIcon(cellFrame,READY_CHECK_READY_TEXTURE, 1)
ShadowTheAge@12 289 local visited = createIcon(cellFrame,READY_CHECK_NOT_READY_TEXTURE, 2)
ShadowTheAge@12 290 icons = {misc=miscdata, autoinv=autoinv, visited=visited}
ShadowTheAge@12 291 cellFrame.icons = icons
ShadowTheAge@12 292 end
ShadowTheAge@12 293 icons.misc:SetShown(voice ~= "" or bnetfr > 0 or charfr > 0 or guild > 0 or ilvl > 0)
ShadowTheAge@12 294 icons.autoinv:SetShown(autoinv)
ShadowTheAge@12 295 icons.visited:SetShown(recentgroups[fullname])
ShadowTheAge@12 296 if GameTooltip:GetOwner() == rowFrame then ShowLfgInfo(rowFrame, cellFrame, data, cols, row, realrow, column, table) end
ShadowTheAge@12 297 end
ShadowTheAge@12 298 end
ShadowTheAge@12 299
ShadowTheAge@12 300 local function updateGroupName(id)
ShadowTheAge@12 301 return select(3, C_LFGList.GetSearchResultInfo(id))
ShadowTheAge@12 302 end
ShadowTheAge@12 303
ShadowTheAge@32 304 local function updateRealmType(id)
ShadowTheAge@32 305 local name = select(12, C_LFGList.GetSearchResultInfo(id))
ShadowTheAge@32 306 local pname, realm = PlayerName(name);
ShadowTheAge@32 307 return select(4, realmInfo:GetRealmInfo(realm)) or "???"
ShadowTheAge@32 308 end
ShadowTheAge@32 309
ShadowTheAge@32 310 local function updateGroupAge(id)
ShadowTheAge@32 311 local age = select(7, C_LFGList.GetSearchResultInfo(id))
ShadowTheAge@32 312 return SecondsToTime(age, false, false, 1, false)
ShadowTheAge@32 313 end
ShadowTheAge@32 314
ShadowTheAge@32 315 local function sortBase(col, value)
ShadowTheAge@32 316 local column = lfgTable.cols[col];
ShadowTheAge@32 317 local direction = column.sort or column.defaultsort or "asc"
ShadowTheAge@32 318 if direction == "asc" then
ShadowTheAge@32 319 return value
ShadowTheAge@32 320 else
ShadowTheAge@32 321 return not value;
ShadowTheAge@32 322 end
ShadowTheAge@32 323 end
ShadowTheAge@32 324
ShadowTheAge@32 325
ShadowTheAge@32 326 local function sortByAge(self, rowa, rowb, sortbycol)
ShadowTheAge@32 327 if rowa == nil or rowb == nil then return false end; -- wtf ScrollingTable???
ShadowTheAge@32 328 local row1 = lfgTable:GetRow(rowa);
ShadowTheAge@32 329 local row2 = lfgTable:GetRow(rowb);
ShadowTheAge@32 330 local age1 = select(7, C_LFGList.GetSearchResultInfo(row1.id));
ShadowTheAge@32 331 local age2 = select(7, C_LFGList.GetSearchResultInfo(row2.id));
ShadowTheAge@32 332 return sortBase(sortbycol, age1<age2);
ShadowTheAge@32 333 end
ShadowTheAge@32 334
ShadowTheAge@32 335 local function updateJoinAge(id)
ShadowTheAge@32 336 local name = select(12, C_LFGList.GetSearchResultInfo(id))
ShadowTheAge@32 337 local ago = getJoinedAgo(name);
ShadowTheAge@32 338 if ago then
ShadowTheAge@32 339 return SecondsToTime(ago, false, false, 1, false)
ShadowTheAge@32 340 else
ShadowTheAge@32 341 return ""
ShadowTheAge@32 342 end
ShadowTheAge@32 343 end
ShadowTheAge@32 344
ShadowTheAge@32 345 local function sortByJoinAge(self, rowa, rowb, sortbycol)
ShadowTheAge@32 346 if rowa == nil or rowb == nil then return false end; -- wtf ScrollingTable???
ShadowTheAge@32 347 local row1 = lfgTable:GetRow(rowa);
ShadowTheAge@32 348 local row2 = lfgTable:GetRow(rowb);
ShadowTheAge@32 349 local joinAge1 = getJoinedAgo(select(12, C_LFGList.GetSearchResultInfo(row1.id))) or 1e10;
ShadowTheAge@32 350 local joinAge2 = getJoinedAgo(select(12, C_LFGList.GetSearchResultInfo(row2.id))) or 1e10;
ShadowTheAge@32 351 return sortBase(sortbycol, joinAge1<joinAge2);
ShadowTheAge@32 352 end
ShadowTheAge@32 353
ShadowTheAge@32 354 local function sortByScore(self, rowa, rowb, sortbycol)
ShadowTheAge@32 355 if rowa == nil or rowb == nil then return false end; -- wtf ScrollingTable???
ShadowTheAge@32 356 local row1 = lfgTable:GetRow(rowa);
ShadowTheAge@32 357 local row2 = lfgTable:GetRow(rowb);
ShadowTheAge@32 358 return row1.weight > row2.weight;
ShadowTheAge@32 359 end
ShadowTheAge@32 360
ShadowTheAge@12 361 local function updateGroupCount(id)
ShadowTheAge@12 362 return select(13, C_LFGList.GetSearchResultInfo(id))
ShadowTheAge@12 363 end
ShadowTheAge@12 364
ShadowTheAge@12 365 local function updateGroupRealm(id)
ShadowTheAge@12 366 local name = select(12, C_LFGList.GetSearchResultInfo(id))
ShadowTheAge@12 367 local pname, realm = PlayerName(name);
ShadowTheAge@32 368 return realm;
ShadowTheAge@12 369 end
ShadowTheAge@12 370
ShadowTheAge@13 371 local COLOR_YELLOW = {r=1,g=1,b=0,a=1}
ShadowTheAge@32 372 local COLOR_WHITE = {r=1,g=1,b=1,a=1}
ShadowTheAge@13 373 local COLOR_GREEN = {r=0,g=1,b=0,a=1}
ShadowTheAge@32 374 local COLOR_RED = {r=1,g=0,b=0,a=1}
ShadowTheAge@32 375 local COLOR_GREY = {r=0.5,g=0.5,b=0.5,a=1}
ShadowTheAge@13 376 local function updateRealmColor(id)
ShadowTheAge@13 377 local name = select(12, C_LFGList.GetSearchResultInfo(id))
ShadowTheAge@13 378 local pname, realm = PlayerName(name);
ShadowTheAge@13 379 return recentRealms[realm] and COLOR_YELLOW or COLOR_GREEN;
ShadowTheAge@13 380 end
ShadowTheAge@13 381
ShadowTheAge@32 382 local function updateNameColor(id)
ShadowTheAge@32 383 local name = select(3, C_LFGList.GetSearchResultInfo(id))
ShadowTheAge@32 384 if searchInList(name, db.global.highlightList) then return COLOR_GREEN end;
ShadowTheAge@32 385 if searchInList(name, db.global.stoplist) then return COLOR_GREY end;
ShadowTheAge@32 386 if searchInList(name, db.global.priorityList) then return COLOR_YELLOW end;
ShadowTheAge@32 387 return COLOR_WHITE;
ShadowTheAge@32 388 end
ShadowTheAge@32 389
ShadowTheAge@12 390 local function filterTable(self, row)
ShadowTheAge@32 391 local _, _, caption, desc, _, _, _, _, _, _, delisted, _, pcount, autoinv = C_LFGList.GetSearchResultInfo(row.id)
ShadowTheAge@25 392 if delisted then return false end;
ShadowTheAge@32 393 if filterByCountId > 1 then
ShadowTheAge@32 394 local fobj = filterByCountList[filterByCountId];
ShadowTheAge@32 395 if pcount < fobj.min or pcount > fobj.max then return false end;
ShadowTheAge@32 396 end
ShadowTheAge@25 397 if not autoinv and cbHideNoAutoinv:GetChecked() then return false end;
ShadowTheAge@32 398 if filterString then
ShadowTheAge@32 399 caption = string.lower(caption);
ShadowTheAge@32 400 desc = string.lower(desc);
ShadowTheAge@32 401 if not (string.find(caption, filterString, 1, true) or string.find(desc, filterString, 1, true))then return false end
ShadowTheAge@32 402 end
ShadowTheAge@25 403 return true;
ShadowTheAge@12 404 end
ShadowTheAge@12 405
ShadowTheAge@12 406 function addon:UpdateResponseData(event, result)
ShadowTheAge@13 407 if not lfgTable then return end
ShadowTheAge@12 408 if select(11, C_LFGList.GetSearchResultInfo(result)) then
ShadowTheAge@12 409 lfgTable:SetFilter(filterTable)
ShadowTheAge@12 410 end
ShadowTheAge@12 411 hasLfgListChanges = true
ShadowTheAge@12 412 end
ShadowTheAge@12 413
ShadowTheAge@12 414 local function refreshLFGList()
ShadowTheAge@12 415 if lfgScanInProgress or not lfgTable then return end
ShadowTheAge@12 416 local count, list = C_LFGList.GetSearchResults()
ShadowTheAge@12 417 local tableData = {}
ShadowTheAge@32 418 local extraColumnId = 4;
ShadowTheAge@32 419
ShadowTheAge@12 420 for i = 1,count do
ShadowTheAge@12 421 local rid = list[i];
ShadowTheAge@12 422 if not rid then break end
ShadowTheAge@12 423 local data = list[i];
ShadowTheAge@12 424 local cols = {}
ShadowTheAge@12 425 local row = {rid}
ShadowTheAge@32 426 for i=1, #tableTemplate do
ShadowTheAge@32 427 local item = tableTemplate[i];
ShadowTheAge@32 428 local cell = {value=item.value, args=row }
ShadowTheAge@32 429 if item.color then
ShadowTheAge@32 430 cell.color = item.color;
ShadowTheAge@32 431 cell.colorargs = row;
ShadowTheAge@32 432 end
ShadowTheAge@32 433 cols[i] = cell
ShadowTheAge@32 434 end
ShadowTheAge@12 435 table.insert(tableData, {cols=cols,id=rid,weight=WeightLfgItem(rid)})
ShadowTheAge@12 436 end
ShadowTheAge@12 437 lfgTable:SetData(tableData)
ShadowTheAge@21 438 if #tableData == 0 then
ShadowTheAge@21 439 lbThrottle:SetText("No groups found")
ShadowTheAge@21 440 end
ShadowTheAge@12 441 end
ShadowTheAge@12 442
ShadowTheAge@13 443 local function JoinGroup(rid)
ShadowTheAge@13 444 local tank, heal, dd = C_LFGList.GetAvailableRoles()
ShadowTheAge@25 445 local noHealTank = not db.global.applyAsDD;
ShadowTheAge@13 446 addon:SetGroupJoinStatus(rid, "_init")
ShadowTheAge@25 447 C_LFGList.ApplyToGroup(rid, "", tank and noHealTank, heal and noHealTank, dd)
ShadowTheAge@13 448 end
ShadowTheAge@13 449
ShadowTheAge@13 450 local function TableCellClick(rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...)
ShadowTheAge@32 451 if not realrow then return end
ShadowTheAge@12 452 local rowdata = scrollingTable:GetRow(realrow);
ShadowTheAge@32 453 if canJoinGroup() then
ShadowTheAge@32 454 JoinGroup(rowdata.id)
ShadowTheAge@32 455 else
ShadowTheAge@32 456 LeaveParty()
ShadowTheAge@32 457 end
ShadowTheAge@12 458 end
ShadowTheAge@12 459
ShadowTheAge@12 460
ShadowTheAge@12 461
ShadowTheAge@12 462
ShadowTheAge@12 463
ShadowTheAge@12 464
ShadowTheAge@12 465 -- Addon functions and gui constructors
ShadowTheAge@12 466
ShadowTheAge@13 467 function addon.ShowMmTooltip(tooltip)
ShadowTheAge@13 468 tooltip:AddLine("Cross Realm Assist",1,1,1)
ShadowTheAge@13 469 tooltip:Show()
ShadowTheAge@13 470 end
ShadowTheAge@13 471
ShadowTheAge@13 472 function addon:OnInitialize()
ShadowTheAge@13 473 db = LibStub("AceDB-3.0"):New("CrossRealmAssistDB", SettingsDefaults)
ShadowTheAge@32 474 addon.db = db;
ShadowTheAge@13 475 local minimapData = ldb:NewDataObject("CrossRealmAssistMinimapIcon",{
ShadowTheAge@13 476 type = "data source",
ShadowTheAge@13 477 text = "Cross Realm Assist",
ShadowTheAge@13 478 icon = "Interface/Icons/INV_Misc_GroupNeedMore",
ShadowTheAge@13 479 OnClick = addon.Activate,
ShadowTheAge@13 480 OnTooltipShow = addon.ShowMmTooltip
ShadowTheAge@13 481 })
ShadowTheAge@13 482 minimapIcon:Register("CrossRealmAssistMinimapIcon", minimapData, db.global.minimap)
ShadowTheAge@13 483 end
ShadowTheAge@13 484
ShadowTheAge@0 485 function addon:OnEnable()
ShadowTheAge@0 486 realmSep = _G.REALM_SEPARATORS
ShadowTheAge@11 487 playerName = UnitName("player")
ShadowTheAge@0 488 homeRealm = GetRealmName()
ShadowTheAge@0 489 addon:RegisterChatCommand("cra", "Activate")
ShadowTheAge@0 490 addon:RegisterChatCommand("crossrealmassist", "Activate")
ShadowTheAge@29 491 if db.global.autoCreateHopGroup then
ShadowTheAge@29 492 addon:RegisterEvent("PLAYER_FLAGS_CHANGED", "PlayerFlagsUpdate")
ShadowTheAge@29 493 end
ShadowTheAge@0 494 end
ShadowTheAge@0 495
ShadowTheAge@0 496 function addon:OnDisable()
ShadowTheAge@0 497 addon:Deactivate()
ShadowTheAge@0 498 end
ShadowTheAge@0 499
ShadowTheAge@0 500 function addon:Activate()
ShadowTheAge@0 501 if active then return end
ShadowTheAge@0 502 active=true
ShadowTheAge@0 503 wasInGroup = IsInGroup()
ShadowTheAge@11 504 if not gui then addon:CreateUI() end
ShadowTheAge@11 505 addon:updateCurrentRealm();
ShadowTheAge@13 506 addon:RefreshZoneAndClearHistory();
ShadowTheAge@11 507 gui:Show()
ShadowTheAge@13 508 addon:RegisterEvent("ZONE_CHANGED_NEW_AREA", "RefreshZoneAndClearHistory")
ShadowTheAge@13 509 addon:RegisterEvent("SCENARIO_UPDATE", "RefreshZoneAndClearHistory")
ShadowTheAge@12 510 addon:RegisterEvent("LFG_LIST_SEARCH_RESULTS_RECEIVED", "LfgResponseData")
ShadowTheAge@12 511 addon:RegisterEvent("LFG_LIST_SEARCH_RESULT_UPDATED", "UpdateResponseData")
ShadowTheAge@12 512 addon:RegisterEvent("LFG_LIST_SEARCH_FAILED", "LfgScanFailed")
ShadowTheAge@12 513 addon:RegisterEvent("GROUP_ROSTER_UPDATE", "updatePartyInfo")
ShadowTheAge@12 514 addon:RegisterEvent("LFG_LIST_APPLICATION_STATUS_UPDATED", "updateAppStatus")
ShadowTheAge@13 515 addon.LfgScan(addon.GetNextAutoScanCategory() or 1)
ShadowTheAge@0 516 end
ShadowTheAge@0 517
ShadowTheAge@0 518 function addon:Deactivate()
ShadowTheAge@0 519 if not active then return end
ShadowTheAge@0 520 active = false
ShadowTheAge@12 521 gui:Hide()
ShadowTheAge@12 522 if lfgui then lfgui:Hide() end
ShadowTheAge@0 523 scanstate = 0
ShadowTheAge@0 524 lfgScanInProgress = false
ShadowTheAge@0 525 addon:UnregisterEvent("ZONE_CHANGED_NEW_AREA")
ShadowTheAge@17 526 addon:UnregisterEvent("SCENARIO_UPDATE")
ShadowTheAge@0 527 addon:UnregisterEvent("PLAYER_REGEN_ENABLED")
ShadowTheAge@0 528 addon:UnregisterEvent("LFG_LIST_SEARCH_RESULTS_RECEIVED")
ShadowTheAge@12 529 addon:UnregisterEvent("LFG_LIST_SEARCH_RESULT_UPDATED")
ShadowTheAge@0 530 addon:UnregisterEvent("LFG_LIST_SEARCH_FAILED")
ShadowTheAge@0 531 addon:UnregisterEvent("GROUP_ROSTER_UPDATE")
ShadowTheAge@0 532 addon:UnregisterEvent("LFG_LIST_APPLICATION_STATUS_UPDATED")
ShadowTheAge@0 533 end
ShadowTheAge@0 534
ShadowTheAge@11 535 function addon:SetStatus(status)
ShadowTheAge@11 536 if status then
ShadowTheAge@11 537 lbStatus:SetText(status)
ShadowTheAge@11 538 else
ShadowTheAge@13 539 lbStatus:SetText("")
ShadowTheAge@11 540 end
ShadowTheAge@11 541 end
ShadowTheAge@11 542
ShadowTheAge@13 543 local function stopMovingWidget()
ShadowTheAge@13 544 gui:StopMovingOrSizing()
ShadowTheAge@13 545 local point,_,_,x,y = gui:GetPoint(1);
ShadowTheAge@13 546 db.global.widgetPos = {x=x,y=y,to=point}
ShadowTheAge@13 547 end
ShadowTheAge@13 548
ShadowTheAge@0 549 function addon:CreateUI()
ShadowTheAge@32 550 local scale = db.global.uiScale or 1.0;
ShadowTheAge@32 551 gui = setupWidget(CreateFrame("Frame","CrossRealmAssistMainUI",nil,"InsetFrameTemplate3"), {SetFrameStrata="LOW",SetWidth=208,SetHeight=60,EnableMouse=true,SetMovable=true,SetClampedToScreen=true,SetScale=scale})
ShadowTheAge@11 552 local title = setupWidget(CreateFrame("Frame",nil,gui), {SetWidth=190,SetHeight=18,EnableMouse=true,RegisterForDrag="LeftButton"}, 0, 6);
ShadowTheAge@11 553 title:SetScript("OnDragStart", function() gui:StartMoving() end)
ShadowTheAge@13 554 title:SetScript("OnDragStop", stopMovingWidget)
ShadowTheAge@11 555 gui:SetScript("OnHide", addon.Deactivate)
ShadowTheAge@12 556 setupTooltip(title, "ANCHOR_TOP", realmToolip)
ShadowTheAge@11 557
ShadowTheAge@11 558 lbRealm = setupWidget(gui:CreateFontString(nil,"BACKGROUND", "GameFontNormal"), {SetWidth=200,SetHeight=18}, 0, 6)
ShadowTheAge@11 559 lbStatus = setupWidget(gui:CreateFontString(nil,"BACKGROUND", "GameFontHighlightSmallLeft"), {SetWidth=200,SetHeight=10}, 6, 23)
ShadowTheAge@11 560
ShadowTheAge@12 561 btQuick = setupWidget(CreateFrame("Button",nil,gui,"UIMenuButtonStretchTemplate"),{SetWidth=90,SetHeight=20,SetText="Quick join"},4,36)
ShadowTheAge@13 562 btQuick:RegisterForClicks("RightButtonUp","LeftButtonUp")
ShadowTheAge@12 563 btQuick:SetScript("OnClick",addon.DoAutoAction)
ShadowTheAge@13 564 setupTooltip(btQuick, "ANCHOR_BOTTOM", addon.actionTooltip)
ShadowTheAge@12 565 btManual = setupWidget(CreateFrame("Button",nil,gui,"UIMenuButtonStretchTemplate"),{SetWidth=90,SetHeight=20,SetText="Manual join"},94,36)
ShadowTheAge@12 566 btManual:SetScript("OnClick",addon.ShowManualLfg)
ShadowTheAge@11 567 setupWidget(CreateFrame("Button",nil,gui,"UIPanelCloseButton"),{EnableMouse=true,SetWidth=20,SetHeight=20},188,0)
ShadowTheAge@11 568
ShadowTheAge@13 569 btRefresh = setupWidget(CreateFrame("Button",nil,gui,"UIPanelSquareButton"),{SetWidth=20,SetHeight=20},184,16)
ShadowTheAge@11 570 btRefresh.icon:SetTexture("Interface/BUTTONS/UI-RefreshButton")
ShadowTheAge@11 571 btRefresh.icon:SetTexCoord(0,1,0,1);
ShadowTheAge@11 572 btRefresh:SetScript("OnClick",addon.RefreshZone)
ShadowTheAge@11 573
ShadowTheAge@13 574 btSettings = setupWidget(CreateFrame("Button",nil,gui,"UIPanelSquareButton"),{SetWidth=20,SetHeight=20},184,36)
ShadowTheAge@13 575 btSettings.icon:SetTexture("Interface/Worldmap/Gear_64Grey")
ShadowTheAge@13 576 btSettings.icon:SetTexCoord(0.1,0.9,0.1,0.9);
ShadowTheAge@13 577 btSettings:SetScript("OnClick",addon.ShowSettings)
ShadowTheAge@13 578
ShadowTheAge@13 579 local savedPos = db.global.widgetPos
ShadowTheAge@13 580 gui:SetPoint(savedPos.to,savedPos.x,savedPos.y)
ShadowTheAge@12 581 addon:UpdateAutoButtonStatus()
ShadowTheAge@21 582
ShadowTheAge@21 583 local languages = C_LFGList.GetAvailableLanguageSearchFilter()
ShadowTheAge@21 584 for i=1,#languages do
ShadowTheAge@21 585 allLanguageTable[languages[i]] = true;
ShadowTheAge@21 586 end
ShadowTheAge@12 587 end
ShadowTheAge@11 588
ShadowTheAge@12 589 function addon:ShowManualLfg()
ShadowTheAge@12 590 if not lfgui then addon:CreateLFGUI() end
ShadowTheAge@12 591 lfgui:Show()
ShadowTheAge@12 592 end
ShadowTheAge@0 593
ShadowTheAge@12 594 function addon.lfgUpdate()
ShadowTheAge@12 595 if hasLfgListChanges then
ShadowTheAge@12 596 lfgTable:Refresh()
ShadowTheAge@12 597 hasLfgListChanges = false
ShadowTheAge@12 598 end
ShadowTheAge@12 599 end
ShadowTheAge@0 600
ShadowTheAge@25 601 function addon.refreshList()
ShadowTheAge@25 602 lfgTable:SetFilter(filterTable)
ShadowTheAge@25 603 end
ShadowTheAge@25 604
ShadowTheAge@32 605 local function updateFilter(self)
ShadowTheAge@32 606 SearchBoxTemplate_OnTextChanged(self)
ShadowTheAge@32 607 filterString = string.lower(edFilterText:GetText());
ShadowTheAge@32 608 if filterString == "" then filterString = nil end;
ShadowTheAge@32 609 addon.refreshList()
ShadowTheAge@32 610 end
ShadowTheAge@32 611
ShadowTheAge@32 612 local function updateFilterByCount(btn, arg1, arg2, checked)
ShadowTheAge@32 613 filterByCountId = arg1;
ShadowTheAge@32 614 local filterObj = filterByCountList[arg1];
ShadowTheAge@32 615 UIDropDownMenu_SetText(btFilterCount, "Count: "..filterObj.min.."-"..filterObj.max);
ShadowTheAge@32 616 addon.refreshList()
ShadowTheAge@32 617 end
ShadowTheAge@32 618
ShadowTheAge@32 619 local function numberFilter(self, level, menuList)
ShadowTheAge@32 620 for i=1,#filterByCountList do
ShadowTheAge@32 621 UIDropDownMenu_AddButton({text=filterByCountList[i].text, arg1=i,checked=(i==filterByCountId), func=updateFilterByCount}, level)
ShadowTheAge@32 622 end
ShadowTheAge@32 623 end
ShadowTheAge@32 624
ShadowTheAge@12 625 function addon:CreateLFGUI()
ShadowTheAge@32 626 local scale = db.global.lfgPanelScale or 1.0;
ShadowTheAge@32 627 local itemCount = db.global.listItemCount;
ShadowTheAge@32 628 local shift = itemCount * 16;
ShadowTheAge@32 629
ShadowTheAge@32 630 tableTemplate = {
ShadowTheAge@32 631 {name="Title",width=160, value = updateGroupName, color = updateNameColor},
ShadowTheAge@32 632 {name="#",width=30,align="CENTER",value = updateGroupCount},
ShadowTheAge@32 633 {name="Realm",width=120,align="RIGHT",value = updateGroupRealm, color = updateRealmColor}
ShadowTheAge@32 634 }
ShadowTheAge@32 635
ShadowTheAge@32 636 extraColumns = db.global.extraColumns;
ShadowTheAge@32 637 if extraColumns.rtype then table.insert(tableTemplate, {name="Type",width=40,align="CENTER", value = updateRealmType}) end;
ShadowTheAge@32 638 if extraColumns.groupAge then table.insert(tableTemplate, {name="Age",width=45,align="CENTER",comparesort=sortByAge, value = updateGroupAge}) end;
ShadowTheAge@32 639 if extraColumns.joinTime then table.insert(tableTemplate, {name="Joined",width=45,align="CENTER",comparesort=sortByJoinAge, value = updateJoinAge}) end;
ShadowTheAge@32 640 table.insert(tableTemplate, {name="Misc",width=50,DoCellUpdate=updateTableData,comparesort=sortByScore,align="RIGHT",sort="asc"})
ShadowTheAge@32 641
ShadowTheAge@32 642 local tableWidth = 0;
ShadowTheAge@32 643 for i=1,#tableTemplate do
ShadowTheAge@32 644 tableWidth = tableWidth + tableTemplate[i].width;
ShadowTheAge@32 645 end
ShadowTheAge@32 646
ShadowTheAge@32 647
ShadowTheAge@33 648 lfgui = setupWidget(CreateFrame("Frame","CrossRealmAssistJoinUI",nil,"UIPanelDialogTemplate"), {SetFrameStrata="HIGH",SetWidth=tableWidth+45,SetHeight=shift+95,EnableMouse=true,SetMovable=true,SetScale=scale})
ShadowTheAge@12 649 lfgui.title:SetText("Click to join group")
ShadowTheAge@12 650 lfgui:SetScript("OnUpdate",addon.lfgUpdate)
ShadowTheAge@12 651 local titlereg = lfgui:CreateTitleRegion()
ShadowTheAge@12 652 titlereg:SetAllPoints(lfgui.title)
ShadowTheAge@12 653 addon:CreateTabs()
ShadowTheAge@0 654
ShadowTheAge@32 655 lfgTable = ScrollingTable:CreateST(tableTemplate,itemCount,16,nil,lfgui);
ShadowTheAge@0 656
ShadowTheAge@13 657 lfgTable:RegisterEvents({OnEnter=ShowLfgInfo,OnLeave=HideTooltip,OnClick=TableCellClick})
ShadowTheAge@0 658
ShadowTheAge@12 659 setupWidget(lfgTable.frame, nil, 10, 45);
ShadowTheAge@12 660 lfgTable.frame:SetBackdrop(nil)
ShadowTheAge@12 661 lfgui:SetPoint("CENTER",0,0)
ShadowTheAge@12 662 refreshLFGList()
ShadowTheAge@0 663
ShadowTheAge@32 664 lbThrottle = setupWidget(lfgui:CreateFontString(nil,"BACKGROUND", "GameFontHighlightSmall"), {SetWidth=tableWidth}, 0, 100)
ShadowTheAge@12 665 lbThrottle:Hide();
ShadowTheAge@0 666
ShadowTheAge@32 667 local btRefresh = setupWidget(CreateFrame("Button",nil,lfgui,"UIPanelSquareButton"),{SetWidth=22,SetHeight=22},tableWidth+19,27)
ShadowTheAge@12 668 btRefresh.icon:SetTexture("Interface/BUTTONS/UI-RefreshButton")
ShadowTheAge@12 669 btRefresh.icon:SetTexCoord(0,1,0,1);
ShadowTheAge@12 670 btRefresh:SetScript("OnClick",addon.refreshLfgCurrent)
ShadowTheAge@25 671
ShadowTheAge@32 672 setupWidget(CreateFrame("Frame",nil,lfgui,"HorizontalBarTemplate"),{SetWidth=tableWidth+32,SetHeight=2}, 8, shift+54)
ShadowTheAge@32 673 local text = setupWidget(lfgui:CreateFontString(nil,"BACKGROUND", "GameFontHighlightSmall"), {SetText="Filters:"}, 20, shift+68)
ShadowTheAge@25 674
ShadowTheAge@32 675 btFilterCount = CreateFrame("FRAME", "CrossRealmAssistCountFilter", lfgui, "UIDropDownMenuTemplate")
ShadowTheAge@32 676 UIDropDownMenu_SetWidth(btFilterCount, 90)
ShadowTheAge@32 677 UIDropDownMenu_SetText(btFilterCount, "By count")
ShadowTheAge@32 678 UIDropDownMenu_Initialize(btFilterCount, numberFilter)
ShadowTheAge@32 679 btFilterCount:SetPoint("TOPLEFT",text,"TOPRIGHT",-10,10)
ShadowTheAge@32 680
ShadowTheAge@32 681 cbHideNoAutoinv = setupWidget(CreateFrame("CheckButton",nil,lfgui,"UICheckButtonTemplate"),{SetWidth=22,SetHeight=22})
ShadowTheAge@32 682 cbHideNoAutoinv:SetPoint("TOPLEFT",btFilterCount,"TOPRIGHT",-10,-3)
ShadowTheAge@32 683 cbHideNoAutoinv:SetScript("OnClick",addon.refreshList)
ShadowTheAge@32 684 text = setupWidget(lfgui:CreateFontString(nil,"BACKGROUND", "GameFontHighlightSmall"), {SetText="Autoaccept only"})
ShadowTheAge@32 685 text:SetPoint("TOPLEFT",cbHideNoAutoinv,"TOPRIGHT",0,-7)
ShadowTheAge@32 686
ShadowTheAge@32 687 edFilterText = setupWidget(CreateFrame("EditBox",nil,lfgui,"SearchBoxTemplate"),{SetHeight=22})
ShadowTheAge@32 688 edFilterText:SetPoint("TOPLEFT",text,"TOPRIGHT",10,7)
ShadowTheAge@32 689 edFilterText:SetPoint("TOPRIGHT",lfgui,"BOTTOMRIGHT",-10,0)
ShadowTheAge@32 690 edFilterText:SetScript("OnTextChanged",updateFilter)
ShadowTheAge@12 691 end
ShadowTheAge@0 692
ShadowTheAge@12 693 function addon:CreateTabs()
ShadowTheAge@12 694 local prevTab
ShadowTheAge@32 695 for i=1,#addon.lfgGroups do
ShadowTheAge@12 696 local tab = CreateFrame("Button","$parentTab"..i,lfgui,"CharacterFrameTabButtonTemplate")
ShadowTheAge@32 697 tab:SetText((C_LFGList.GetCategoryInfo(addon.lfgGroups[i])));
ShadowTheAge@13 698 tab.searchID = i;
ShadowTheAge@12 699 tab:SetID(i);
ShadowTheAge@12 700 PanelTemplates_TabResize(tab, 0)
ShadowTheAge@12 701 if i == 1 then
ShadowTheAge@12 702 tab:SetPoint("TOPLEFT", lfgui, "BOTTOMLEFT", 10, 7)
ShadowTheAge@12 703 lfgTabSelected = tab
ShadowTheAge@13 704 else
ShadowTheAge@13 705 tab:SetPoint("TOPLEFT", prevTab, "TOPRIGHT",-15,0)
ShadowTheAge@13 706 end
ShadowTheAge@13 707 if curLfgGroup == i then
ShadowTheAge@12 708 PanelTemplates_SelectTab(tab)
ShadowTheAge@12 709 else
ShadowTheAge@12 710 PanelTemplates_DeselectTab(tab)
ShadowTheAge@12 711 end
ShadowTheAge@13 712 tab:SetScript("OnClick", TabClick)
ShadowTheAge@12 713 tabs[i] = tab
ShadowTheAge@12 714 prevTab = tab
ShadowTheAge@12 715 end
ShadowTheAge@0 716 end
ShadowTheAge@0 717
ShadowTheAge@0 718 -- LFG scanning routine
ShadowTheAge@0 719
ShadowTheAge@12 720 function addon.refreshLfgCurrent()
ShadowTheAge@12 721 addon.LfgScan(curLfgGroup)
ShadowTheAge@0 722 end
ShadowTheAge@0 723
ShadowTheAge@13 724 function addon.GetNextAutoScanCategory()
ShadowTheAge@32 725 for i=1,#addon.lfgGroups do
ShadowTheAge@32 726 if not autoScanGroups[i] and db.global.quickJoin[addon.lfgGroups[i]] and i ~= curLfgGroup then return i end
ShadowTheAge@13 727 end
ShadowTheAge@13 728 return nil
ShadowTheAge@13 729 end
ShadowTheAge@13 730
ShadowTheAge@12 731 function addon.LfgScan(group)
ShadowTheAge@13 732 if lfgTable then
ShadowTheAge@13 733 lfgTable:SetData({})
ShadowTheAge@13 734 changeTab(tabs[group])
ShadowTheAge@13 735 end
ShadowTheAge@0 736 lfgScanInProgress = true
ShadowTheAge@12 737 curLfgGroup = group
ShadowTheAge@21 738 local languages = db.global.allLanguages and allLanguageTable or C_LFGList.GetLanguageSearchFilter();
ShadowTheAge@32 739 C_LFGList.Search(addon.lfgGroups[curLfgGroup],"",nil,nil,languages)
ShadowTheAge@0 740 end
ShadowTheAge@0 741
ShadowTheAge@0 742 function addon:LfgScanFailed(event, reason)
ShadowTheAge@21 743 reason = reason or "Unknown reason";
ShadowTheAge@0 744 if reason == "throttled" then
ShadowTheAge@12 745 addon:ScheduleTimer(addon.LfgScan, 2, curLfgGroup)
ShadowTheAge@0 746 end
ShadowTheAge@13 747 if lbThrottle then
ShadowTheAge@13 748 if reason == "throttled" then
ShadowTheAge@13 749 lbThrottle:SetText("LFG scan is delayed (throttled).\nThis page will update automatically...")
ShadowTheAge@13 750 else
ShadowTheAge@13 751 lbThrottle:SetText("Scan failed ("..reason..")")
ShadowTheAge@13 752 end
ShadowTheAge@13 753 lbThrottle:Show()
ShadowTheAge@13 754 end
ShadowTheAge@0 755 end
ShadowTheAge@0 756
ShadowTheAge@0 757 function addon:LfgResponseData()
ShadowTheAge@0 758 lfgScanInProgress = false;
ShadowTheAge@13 759 addon:UpdateAutoButtonStatus()
ShadowTheAge@12 760 if lbThrottle then lbThrottle:Hide() end
ShadowTheAge@12 761 refreshLFGList()
ShadowTheAge@0 762 end
ShadowTheAge@0 763
ShadowTheAge@0 764 function addon:updateAppStatus(event, id, status, oldstatus)
ShadowTheAge@0 765 if status == "invited" then
ShadowTheAge@0 766 LFGListInviteDialog_Accept(LFGListInviteDialog)
ShadowTheAge@0 767 end
ShadowTheAge@12 768 addon:UpdateAutoButtonStatus()
ShadowTheAge@12 769 addon:SetGroupJoinStatus(id, status)
ShadowTheAge@12 770 end
ShadowTheAge@12 771
ShadowTheAge@12 772 function addon:SetGroupJoinStatus(id, status)
ShadowTheAge@12 773 local name = select(12, C_LFGList.GetSearchResultInfo(id))
ShadowTheAge@13 774 if name then
ShadowTheAge@13 775 recentgroups[name] = {status=status, time=GetTime()}
ShadowTheAge@13 776 end
ShadowTheAge@13 777 end
ShadowTheAge@13 778
ShadowTheAge@13 779 function addon:RealmVisited(realm, head)
ShadowTheAge@13 780 recentRealms[realm] = GetTime()
ShadowTheAge@12 781 end
ShadowTheAge@12 782
ShadowTheAge@12 783 function addon:updatePartyInfo()
ShadowTheAge@27 784 if IsInGroup() ~= wasInGroup then
ShadowTheAge@13 785 addon:RefreshZone(true)
ShadowTheAge@27 786 wasInGroup = IsInGroup()
ShadowTheAge@12 787 addon:UpdateAutoButtonStatus()
ShadowTheAge@12 788 end
ShadowTheAge@12 789 end
ShadowTheAge@12 790
ShadowTheAge@12 791
ShadowTheAge@12 792
ShadowTheAge@0 793
ShadowTheAge@0 794 -- Zone scanning routine
ShadowTheAge@0 795
ShadowTheAge@0 796 function addon:LeaveCombat()
ShadowTheAge@0 797 addon:UnregisterEvent("PLAYER_REGEN_ENABLED")
ShadowTheAge@0 798 scanstate = 0
ShadowTheAge@0 799 addon:ScanRealm();
ShadowTheAge@0 800 end
ShadowTheAge@0 801
ShadowTheAge@13 802 function addon:RefreshZoneAndClearHistory()
ShadowTheAge@13 803 ClearRealmHistory()
ShadowTheAge@11 804 addon:RefreshZone(true)
ShadowTheAge@11 805 end
ShadowTheAge@11 806
ShadowTheAge@11 807 function addon:RefreshZone(shedule)
ShadowTheAge@11 808 local inst, instType = IsInInstance()
ShadowTheAge@12 809 inInstance = (inst or instType ~= "none")
ShadowTheAge@12 810 if inInstance then
ShadowTheAge@11 811 lbRealm:SetText("Instanced zone")
ShadowTheAge@11 812 curRealmStat = nil
ShadowTheAge@12 813 inInstance = true
ShadowTheAge@11 814 else
ShadowTheAge@12 815 inInstance = false;
ShadowTheAge@11 816 if scanstate == 0 then
ShadowTheAge@11 817 addon:ScanRealm()
ShadowTheAge@11 818 elseif shedule == true and scanstate == 2 then
ShadowTheAge@27 819 addon:SetStatus("Rescan scheduled...")
ShadowTheAge@11 820 scanstate = 3
ShadowTheAge@11 821 end
ShadowTheAge@11 822 end
ShadowTheAge@12 823 addon:UpdateAutoButtonStatus()
ShadowTheAge@11 824 end
ShadowTheAge@11 825
ShadowTheAge@0 826 function addon:ScanRealm()
ShadowTheAge@0 827 if scanstate > 0 then return end
ShadowTheAge@0 828 if InCombatLockdown() then
ShadowTheAge@0 829 addon:RegisterEvent("PLAYER_REGEN_ENABLED","LeaveCombat")
ShadowTheAge@0 830 scanstate = 1
ShadowTheAge@27 831 addon:SetStatus("Scan scheduled after combat...");
ShadowTheAge@0 832 return
ShadowTheAge@0 833 end
ShadowTheAge@0 834 scanstate = 2
ShadowTheAge@11 835 addon:SetStatus("Scanning current realm...");
ShadowTheAge@0 836 local searchString = _G.WHO_TAG_ZONE .. '"' .. GetZoneText() .. '"';
ShadowTheAge@0 837 wholib:Who(searchString, {callback = "ScanResult", handler=addon})
ShadowTheAge@0 838 end
ShadowTheAge@0 839
ShadowTheAge@0 840 function addon:ScanResult(query, results, complete)
ShadowTheAge@0 841 local realms = {}
ShadowTheAge@0 842 for _, player in ipairs(results) do
ShadowTheAge@0 843 addon:AddRealmStat(player.Name, realms);
ShadowTheAge@0 844 end
ShadowTheAge@0 845 curRealmStat = addon:GetRealmStat(realms);
ShadowTheAge@11 846 curRealmStat.complete = complete
ShadowTheAge@0 847 addon:updateCurrentRealm();
ShadowTheAge@0 848 local rescan = scanstate == 3
ShadowTheAge@0 849 scanstate = 0;
ShadowTheAge@0 850 if rescan then addon:ScanRealm() end
ShadowTheAge@0 851 end
ShadowTheAge@0 852
ShadowTheAge@0 853 function addon:AddRealmStat(name, realms)
ShadowTheAge@11 854 if (name == playerName) then return end
ShadowTheAge@11 855 local _, realm = strsplit(realmSep, name)
ShadowTheAge@0 856 realm = realm or homeRealm
ShadowTheAge@0 857 realms[realm] = (realms[realm] or 0) + 1
ShadowTheAge@0 858 end
ShadowTheAge@0 859
ShadowTheAge@0 860 function addon:AddUnitIdStat(unitid, realms)
ShadowTheAge@0 861 local name, realm = UnitName(unitid);
ShadowTheAge@0 862 if not name then return end
ShadowTheAge@0 863 if realm == "" then realm = homeRealm end
ShadowTheAge@0 864 realm = realm or homeRealm
ShadowTheAge@0 865 realms[realm] = (realms[realm] or 0) + 1
ShadowTheAge@0 866 end
ShadowTheAge@0 867
ShadowTheAge@0 868 function addon:GetRealmStat(realms)
ShadowTheAge@0 869 local rcount = 0;
ShadowTheAge@0 870 local stat = {};
ShadowTheAge@0 871 local pcount = 0;
ShadowTheAge@19 872 if realms then
ShadowTheAge@19 873 for realm,count in pairs(realms) do
ShadowTheAge@19 874 table.insert(stat,{realm=realm,count=count})
ShadowTheAge@19 875 rcount = rcount + 1;
ShadowTheAge@19 876 pcount = pcount + count;
ShadowTheAge@19 877 end
ShadowTheAge@0 878 end
ShadowTheAge@0 879 if rcount > 1 then
ShadowTheAge@0 880 table.sort(stat, function(a,b) return a.count > b.count end)
ShadowTheAge@0 881 stat.max = stat[1].count
ShadowTheAge@0 882 else stat.max = 0 end
ShadowTheAge@0 883 stat.players = pcount;
ShadowTheAge@0 884 stat.realms = rcount;
ShadowTheAge@0 885 return stat;
ShadowTheAge@0 886 end
ShadowTheAge@0 887
ShadowTheAge@0 888 function addon:updateCurrentRealm()
ShadowTheAge@11 889 addon:SetStatus();
ShadowTheAge@11 890 if not curRealmStat or curRealmStat.realms < 1 then
ShadowTheAge@11 891 lbRealm:SetText("Unknown realm (No players)")
ShadowTheAge@11 892 return;
ShadowTheAge@0 893 end
ShadowTheAge@11 894
ShadowTheAge@11 895 local bestRealm = curRealmStat[1]
ShadowTheAge@13 896 addon:RealmVisited(bestRealm.realm, true)
ShadowTheAge@12 897 local prevThreshold = math.min(bestRealm.count/3,10)
ShadowTheAge@11 898 local mixCount = 0
ShadowTheAge@11 899 for i=2,curRealmStat.realms do
ShadowTheAge@0 900 local data = curRealmStat[i]
ShadowTheAge@11 901 if data.count >= prevThreshold then
ShadowTheAge@11 902 mixCount = mixCount + 1
ShadowTheAge@13 903 addon:RealmVisited(data.realm)
ShadowTheAge@12 904 prevThreshold = math.min(data.count/3,10)
ShadowTheAge@0 905 end
ShadowTheAge@0 906 end
ShadowTheAge@11 907 curRealmStat.threshold = prevThreshold
ShadowTheAge@11 908
ShadowTheAge@11 909 if (mixCount > 0) then
ShadowTheAge@11 910 lbRealm:SetText("Mixed "..bestRealm.realm.." +"..mixCount)
ShadowTheAge@11 911 else
ShadowTheAge@11 912 lbRealm:SetText(bestRealm.realm)
ShadowTheAge@0 913 end
ShadowTheAge@0 914 end
ShadowTheAge@0 915
ShadowTheAge@12 916
ShadowTheAge@12 917
ShadowTheAge@12 918
ShadowTheAge@12 919
ShadowTheAge@12 920
ShadowTheAge@12 921 -- Auto action button
ShadowTheAge@12 922
ShadowTheAge@13 923 local action
ShadowTheAge@12 924
ShadowTheAge@27 925 local function getPartyStat()
ShadowTheAge@29 926 local curPartyStat = {}
ShadowTheAge@27 927 if IsInGroup() then
ShadowTheAge@27 928 if IsInRaid() then
ShadowTheAge@27 929 for i=1, MAX_RAID_MEMBERS do
ShadowTheAge@27 930 addon:AddUnitIdStat("raid"..i, curPartyStat)
ShadowTheAge@27 931 end
ShadowTheAge@27 932 else
ShadowTheAge@27 933 for i=1, MAX_PARTY_MEMBERS do
ShadowTheAge@27 934 addon:AddUnitIdStat("party"..i, curPartyStat)
ShadowTheAge@27 935 end
ShadowTheAge@27 936 end
ShadowTheAge@27 937 end
ShadowTheAge@29 938 return curPartyStat
ShadowTheAge@27 939 end
ShadowTheAge@27 940
ShadowTheAge@13 941 local LeaveGroup = {
ShadowTheAge@13 942 func = LeaveParty;
ShadowTheAge@17 943 tooltip = function(self)
ShadowTheAge@27 944 local partyStat = addon:GetRealmStat(getPartyStat())
ShadowTheAge@17 945 GameTooltip:AddLine("Players in party "..partyStat.players)
ShadowTheAge@17 946 local max = partyStat.max;
ShadowTheAge@17 947 for i=1,#partyStat do
ShadowTheAge@17 948 local data = partyStat[i]
ShadowTheAge@17 949 local percent = math.ceil(100 * data.count / partyStat.players - 0.5) .. "%";
ShadowTheAge@17 950 local pmax = data.count/max;
ShadowTheAge@17 951 local green = 0.5 + pmax * 0.5;
ShadowTheAge@17 952 local gray = 0.5 * (1-pmax)
ShadowTheAge@17 953 GameTooltip:AddDoubleLine(data.realm, percent, gray,green,gray,gray,green,gray)
ShadowTheAge@17 954 end
ShadowTheAge@17 955 GameTooltip:AddLine("Click to leave party",1,0.5,0)
ShadowTheAge@17 956 end,
ShadowTheAge@13 957 text = "Leave group"
ShadowTheAge@13 958 }
ShadowTheAge@13 959
ShadowTheAge@13 960 local CancelJoin = {
ShadowTheAge@13 961 func = function()
ShadowTheAge@13 962 local apps = C_LFGList.GetApplications();
ShadowTheAge@13 963 if apps[1] then
ShadowTheAge@13 964 C_LFGList.CancelApplication(apps[1])
ShadowTheAge@13 965 end
ShadowTheAge@13 966 end,
ShadowTheAge@13 967 tooltip = "Cancel your current join application",
ShadowTheAge@13 968 text = "Cancel join"
ShadowTheAge@13 969 }
ShadowTheAge@13 970
ShadowTheAge@13 971 local QuickJoin = {
ShadowTheAge@13 972 func = function(self, button)
ShadowTheAge@13 973 if button == "RightButton" then
ShadowTheAge@13 974 addon:SetGroupJoinStatus(self.groupToJoin, "_skip")
ShadowTheAge@13 975 else
ShadowTheAge@13 976 local delisted = select(11, C_LFGList.GetSearchResultInfo(self.groupToJoin))
ShadowTheAge@13 977 if delisted == false then
ShadowTheAge@13 978 JoinGroup(self.groupToJoin)
ShadowTheAge@13 979 else
ShadowTheAge@13 980 addon:SetStatus("Group just delisted")
ShadowTheAge@13 981 end
ShadowTheAge@13 982 end
ShadowTheAge@13 983 end,
ShadowTheAge@13 984 findGroup = function()
ShadowTheAge@13 985 local count, list = C_LFGList.GetSearchResults()
ShadowTheAge@13 986 local best
ShadowTheAge@13 987 local bestvalue = 0
ShadowTheAge@13 988 for i = 1,count do
ShadowTheAge@13 989 local rid = list[i];
ShadowTheAge@13 990 if not rid then break end
ShadowTheAge@13 991 local value = WeightLfgItem(rid, true);
ShadowTheAge@13 992 if value > bestvalue then
ShadowTheAge@13 993 best = rid
ShadowTheAge@13 994 bestvalue = value
ShadowTheAge@13 995 end
ShadowTheAge@13 996 end
ShadowTheAge@13 997 return best
ShadowTheAge@13 998 end,
ShadowTheAge@13 999 tooltip = function(self)
ShadowTheAge@13 1000 AddLfgGroupInfo(self.groupToJoin, true)
ShadowTheAge@13 1001 GameTooltip:AddLine(" ")
ShadowTheAge@13 1002 GameTooltip:AddDoubleLine("Click to join","Right click to skip",0,1,0,1,0.5,0)
ShadowTheAge@13 1003 end,
ShadowTheAge@13 1004 text = "Quick join"
ShadowTheAge@13 1005 }
ShadowTheAge@13 1006
ShadowTheAge@13 1007 local ScanNext = {
ShadowTheAge@13 1008 func = function(self)
ShadowTheAge@13 1009 autoScanGroups[curLfgGroup] = 1
ShadowTheAge@13 1010 addon.LfgScan(self.category)
ShadowTheAge@13 1011 end,
ShadowTheAge@13 1012 tooltip = function(self)
ShadowTheAge@32 1013 GameTooltip:AddLine("Scan "..(C_LFGList.GetCategoryInfo(addon.lfgGroups[self.category])))
ShadowTheAge@13 1014 end,
ShadowTheAge@13 1015 text = "Scan more"
ShadowTheAge@13 1016 }
ShadowTheAge@13 1017
ShadowTheAge@13 1018 local NeedReset = {
ShadowTheAge@13 1019 func = function()
ShadowTheAge@13 1020 wipe(autoScanGroups);
ShadowTheAge@13 1021 local categoryToScan = addon.GetNextAutoScanCategory()
ShadowTheAge@13 1022 if categoryToScan then
ShadowTheAge@13 1023 addon.LfgScan(categoryToScan)
ShadowTheAge@13 1024 end
ShadowTheAge@13 1025 end,
ShadowTheAge@13 1026 tooltip = "Scan again",
ShadowTheAge@13 1027 text = "Restart scan"
ShadowTheAge@13 1028 }
ShadowTheAge@13 1029
ShadowTheAge@13 1030 local Wait = {
ShadowTheAge@13 1031 tooltip = "Scan in progress",
ShadowTheAge@13 1032 text = "Wait..."
ShadowTheAge@13 1033 }
ShadowTheAge@13 1034
ShadowTheAge@13 1035 local ShowQuickHint = {
ShadowTheAge@13 1036 tooltip = "Quick Join",
ShadowTheAge@13 1037 text = "Quick Join",
ShadowTheAge@13 1038 func = function()
ShadowTheAge@13 1039 StaticPopupDialogs["CROSS_REALM_ASSIST"] = {
ShadowTheAge@32 1040 text = "Quick Join button will automatically join you to a random group with autoaccept 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 1041 button1 = OKAY,
ShadowTheAge@13 1042 hideOnEscape = true,
ShadowTheAge@13 1043 preferredIndex = 3,
ShadowTheAge@13 1044 }
ShadowTheAge@13 1045 StaticPopup_Show("CROSS_REALM_ASSIST")
ShadowTheAge@13 1046 hintShown = true;
ShadowTheAge@13 1047 end
ShadowTheAge@13 1048 }
ShadowTheAge@13 1049
ShadowTheAge@13 1050 function addon.DoAutoAction(widget, button)
ShadowTheAge@13 1051 addon:SetStatus()
ShadowTheAge@13 1052 if action and action.func then
ShadowTheAge@13 1053 action:func(button)
ShadowTheAge@13 1054 end
ShadowTheAge@13 1055 addon:UpdateAutoButtonStatus()
ShadowTheAge@13 1056 end
ShadowTheAge@13 1057
ShadowTheAge@13 1058 function addon.actionTooltip()
ShadowTheAge@13 1059 local tooltip = action.tooltip
ShadowTheAge@13 1060 if type(tooltip) == 'function' then
ShadowTheAge@13 1061 tooltip(action)
ShadowTheAge@13 1062 else
ShadowTheAge@13 1063 GameTooltip:AddLine(tooltip)
ShadowTheAge@11 1064 end
ShadowTheAge@11 1065 end
ShadowTheAge@11 1066
ShadowTheAge@13 1067 function addon:UpdateAutoButtonStatus()
ShadowTheAge@13 1068 if not btQuick then return end
ShadowTheAge@13 1069 btQuick:Enable()
ShadowTheAge@19 1070 if IsInGroup() then
ShadowTheAge@13 1071 action = LeaveGroup;
ShadowTheAge@13 1072 elseif C_LFGList.GetNumApplications() > 0 then
ShadowTheAge@13 1073 action = CancelJoin;
ShadowTheAge@13 1074 elseif lfgScanInProgress then
ShadowTheAge@13 1075 action = Wait
ShadowTheAge@19 1076 elseif not hintShown and db.global.quickJoinHint then
ShadowTheAge@19 1077 action = ShowQuickHint;
ShadowTheAge@13 1078 else
ShadowTheAge@13 1079 local group = QuickJoin.findGroup();
ShadowTheAge@13 1080 if group then
ShadowTheAge@13 1081 action = QuickJoin;
ShadowTheAge@13 1082 QuickJoin.groupToJoin = group
ShadowTheAge@13 1083 else
ShadowTheAge@13 1084 local categoryToScan = addon.GetNextAutoScanCategory()
ShadowTheAge@13 1085 if (categoryToScan) then
ShadowTheAge@13 1086 action = ScanNext;
ShadowTheAge@13 1087 ScanNext.category = categoryToScan
ShadowTheAge@13 1088 else
ShadowTheAge@13 1089 action = NeedReset;
ShadowTheAge@13 1090 end
ShadowTheAge@13 1091 end
ShadowTheAge@13 1092 end
ShadowTheAge@13 1093 btQuick:SetText(action.text)
ShadowTheAge@13 1094 if GameTooltip:GetOwner() == btQuick then
ShadowTheAge@13 1095 ShowTooltip(btQuick)
ShadowTheAge@0 1096 end
ShadowTheAge@0 1097 end
ShadowTheAge@0 1098
ShadowTheAge@12 1099
ShadowTheAge@13 1100
ShadowTheAge@13 1101
ShadowTheAge@27 1102 -- Realm hop group
ShadowTheAge@13 1103
ShadowTheAge@27 1104 local function CreateHopGroup()
ShadowTheAge@29 1105 if canJoinGroup() then
ShadowTheAge@29 1106 C_LFGList.CreateListing(16,"Realm hopping - "..homeRealm,0,"","",true)
ShadowTheAge@29 1107 addon:ScheduleTimer(ConvertToRaid, 5)
ShadowTheAge@29 1108 end
ShadowTheAge@27 1109 end
ShadowTheAge@27 1110
ShadowTheAge@27 1111 function addon:PlayerFlagsUpdate(event, target)
ShadowTheAge@29 1112 if target == "player" and UnitIsAFK("player") and C_Garrison.IsOnGarrisonMap() and db.global.autoCreateHopGroup then
ShadowTheAge@29 1113 CreateHopGroup()
ShadowTheAge@29 1114 end
ShadowTheAge@27 1115 end
ShadowTheAge@13 1116
ShadowTheAge@13 1117 -- Settings
ShadowTheAge@13 1118
ShadowTheAge@32 1119 function addon.toggleMinimapIcon(hidden)
ShadowTheAge@13 1120 if hidden then
ShadowTheAge@13 1121 DEFAULT_CHAT_FRAME:AddMessage("|cffff0000Type |cffffffff/cra |cffff0000in chat to open Cross Realm Assist without minimap button");
ShadowTheAge@13 1122 minimapIcon:Hide("CrossRealmAssistMinimapIcon")
ShadowTheAge@13 1123 else
ShadowTheAge@13 1124 minimapIcon:Show("CrossRealmAssistMinimapIcon")
ShadowTheAge@13 1125 end
ShadowTheAge@0 1126 end
ShadowTheAge@0 1127
ShadowTheAge@32 1128 function addon.updateLfgScale(scale)
ShadowTheAge@32 1129 if lfgui then lfgui:SetScale(scale) end;
ShadowTheAge@32 1130 end
ShadowTheAge@32 1131
ShadowTheAge@32 1132 function addon.updateUIScale(scale)
ShadowTheAge@32 1133 if gui then gui:SetScale(scale) end;
ShadowTheAge@32 1134 end
ShadowTheAge@32 1135
ShadowTheAge@13 1136 local function toggleQuickJoinHint(btn, arg1, arg2, checked)
ShadowTheAge@13 1137 db.global.quickJoinHint = checked
ShadowTheAge@0 1138 end
ShadowTheAge@0 1139
ShadowTheAge@13 1140 local function toggleQuickJoin(btn, arg1, arg2, checked)
ShadowTheAge@13 1141 db.global.quickJoin[arg1] = checked
ShadowTheAge@13 1142 end
ShadowTheAge@13 1143
ShadowTheAge@21 1144 local function toggleAllLanguages(btn, arg1, arg2, checked)
ShadowTheAge@21 1145 db.global.allLanguages = checked
ShadowTheAge@21 1146 end
ShadowTheAge@21 1147
ShadowTheAge@25 1148 local function toggleApplyAsDD(btn, arg1, arg2, checked)
ShadowTheAge@25 1149 db.global.applyAsDD = checked
ShadowTheAge@25 1150 end
ShadowTheAge@25 1151
ShadowTheAge@27 1152 local function toggleCreateHopGroup(btn, arg1, arg2, checked)
ShadowTheAge@27 1153 db.global.autoCreateHopGroup = checked
ShadowTheAge@29 1154 if checked then addon:RegisterEvent("PLAYER_FLAGS_CHANGED", "PlayerFlagsUpdate") end
ShadowTheAge@27 1155 end
ShadowTheAge@27 1156
ShadowTheAge@32 1157 local function joinFriendGroup(btn, rid)
ShadowTheAge@32 1158 JoinGroup(rid);
ShadowTheAge@32 1159 end
ShadowTheAge@32 1160
ShadowTheAge@13 1161 local function ClearJoinHistory()
ShadowTheAge@13 1162 recentgroups = {}
ShadowTheAge@13 1163 addon:UpdateAutoButtonStatus()
ShadowTheAge@13 1164 if lfgTable then lfgTable:Refresh() end
ShadowTheAge@13 1165 end
ShadowTheAge@13 1166
ShadowTheAge@27 1167 local function QuickJoinStoplist()
ShadowTheAge@27 1168 StaticPopupDialogs["CROSS_REALM_ASSIST_STOPLIST"] = {
ShadowTheAge@29 1169 OnShow = function (self, data)
ShadowTheAge@29 1170 self.editBox:SetText(table.concat(db.global.stoplist or {}, ","))
ShadowTheAge@29 1171 end,
ShadowTheAge@29 1172 OnAccept=function(self)
ShadowTheAge@29 1173 local text = self.editBox:GetText();
ShadowTheAge@29 1174 local stoplist = {}
ShadowTheAge@29 1175 for item in string.gmatch(text, "[^, ][^,]*") do
ShadowTheAge@29 1176 table.insert(stoplist,string.lower(item))
ShadowTheAge@29 1177 end
ShadowTheAge@29 1178 db.global.stoplist = stoplist
ShadowTheAge@29 1179 end,
ShadowTheAge@29 1180 button1 = OKAY,
ShadowTheAge@29 1181 button2 = CANCEL,
ShadowTheAge@29 1182 editBoxWidth = 350,
ShadowTheAge@29 1183 hasEditBox=true,
ShadowTheAge@29 1184 text = "Ignore groups containing following words:\nSeparated by comma",
ShadowTheAge@29 1185 preferredIndex = 3
ShadowTheAge@29 1186 }
ShadowTheAge@29 1187 StaticPopup_Show("CROSS_REALM_ASSIST_STOPLIST")
ShadowTheAge@27 1188 end
ShadowTheAge@13 1189
ShadowTheAge@13 1190 local function initMenu(self, level)
ShadowTheAge@13 1191 if not level then return end
ShadowTheAge@13 1192 if level == 1 then
ShadowTheAge@32 1193 UIDropDownMenu_AddButton({text="Clear join history",notCheckable=1,func=ClearJoinHistory}, level)
ShadowTheAge@13 1194 UIDropDownMenu_AddButton({text="Clear realm history",notCheckable=1,func=ClearRealmHistory}, level)
ShadowTheAge@32 1195 UIDropDownMenu_AddButton({disabled=1,notCheckable=1}, level)
ShadowTheAge@29 1196
ShadowTheAge@32 1197 UIDropDownMenu_AddButton({text="Cross Realm Assist Toolbox",notCheckable=1,func=CreateHopGroup,isTitle=1}, level)
ShadowTheAge@32 1198 UIDropDownMenu_AddButton({text="Show Quick Join Hint",checked=db.global.quickJoinHint, func=toggleQuickJoinHint,keepShownOnClick=true,isNotRadio=true}, level)
ShadowTheAge@32 1199 if canJoinGroup() then
ShadowTheAge@29 1200 UIDropDownMenu_AddButton({text="Create a group for realm hoppers",notCheckable=1,func=CreateHopGroup}, level)
ShadowTheAge@32 1201 UIDropDownMenu_AddButton({text="Join to a friend",notCheckable=1,hasArrow=1,value="jtf",keepShownOnClick=true}, level)
ShadowTheAge@29 1202 end
ShadowTheAge@29 1203
ShadowTheAge@29 1204 UIDropDownMenu_AddButton({disabled=1,notCheckable=1}, level)
ShadowTheAge@32 1205 UIDropDownMenu_AddButton({text="Settings...",notCheckable=1,func=addon.showSettings}, level)
ShadowTheAge@13 1206 elseif level == 2 then
ShadowTheAge@32 1207 if UIDROPDOWNMENU_MENU_VALUE == "jtf" then
ShadowTheAge@32 1208 local count, list = C_LFGList.GetSearchResults()
ShadowTheAge@32 1209 local friends = {}
ShadowTheAge@32 1210 for i = 1,count do
ShadowTheAge@32 1211 local rid = list[i];
ShadowTheAge@32 1212 if not rid then break end
ShadowTheAge@32 1213 local bnf, chf, gf = C_LFGList.GetSearchResultFriends(rid)
ShadowTheAge@32 1214 for j=1,#bnf do table.insert(friends,{name="|cFF00B1F0"..bnf[j],type=0,id=rid}) end
ShadowTheAge@32 1215 for j=1,#chf do table.insert(friends,{name="|cFFFF80FF"..chf[j],type=1,id=rid}) end
ShadowTheAge@32 1216 for j=1,#gf do table.insert(friends,{name="|cFF40FF40"..gf[j],type=2,id=rid}) end
ShadowTheAge@32 1217 end
ShadowTheAge@32 1218 if #friends==0 then
ShadowTheAge@32 1219 UIDropDownMenu_AddButton({text="No friends found (click to refresh)",notCheckable=1,func=addon.refreshLfgCurrent}, level)
ShadowTheAge@32 1220 else
ShadowTheAge@32 1221 UIDropDownMenu_AddButton({text="Refresh",notCheckable=1,func=addon.refreshLfgCurrent}, level)
ShadowTheAge@32 1222 table.sort(friends, sortByTypeAndName);
ShadowTheAge@32 1223 for i=1,#friends do
ShadowTheAge@32 1224 UIDropDownMenu_AddButton({text=friends[i].name,notCheckable=1,func=joinFriendGroup,arg1=friends[i].id}, level)
ShadowTheAge@32 1225 end
ShadowTheAge@32 1226 end
ShadowTheAge@32 1227 end
ShadowTheAge@29 1228 end
ShadowTheAge@13 1229 end
ShadowTheAge@13 1230
ShadowTheAge@13 1231 function addon.ShowSettings(frame)
ShadowTheAge@13 1232 if not settingsMenu then
ShadowTheAge@13 1233 settingsMenu = CreateFrame("Frame", "CrossRealmAssistMenu")
ShadowTheAge@13 1234 settingsMenu.displayMode = "MENU"
ShadowTheAge@13 1235 settingsMenu.initialize = initMenu
ShadowTheAge@13 1236 end
ShadowTheAge@13 1237 ToggleDropDownMenu(1, nil, settingsMenu, frame, 10, 0)
ShadowTheAge@12 1238 end