annotate CrossRealmAssist.lua @ 40:d12ccf325b4b v0.8

LibST highlight fix and version number inc
author ShadowTheAge
date Wed, 20 Jul 2016 21:49:36 +0300
parents 616d67ff7543
children 2152dcaa9265
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@38 202 local _, action, caption, desc, voice, ilvl, unk1, 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@38 244 local _, action, caption, desc, voice, ilvl, unk1, 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@38 285 local _, action, caption, desc, voice, ilvl, unk1, 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@38 305 local name = select(13, 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@38 311 local age = select(8, 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@38 330 local age1 = select(8, C_LFGList.GetSearchResultInfo(row1.id));
ShadowTheAge@38 331 local age2 = select(8, 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@38 336 local name = select(13, 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@38 349 local joinAge1 = getJoinedAgo(select(13, C_LFGList.GetSearchResultInfo(row1.id))) or 1e10;
ShadowTheAge@38 350 local joinAge2 = getJoinedAgo(select(13, 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@38 362 return select(14, C_LFGList.GetSearchResultInfo(id))
ShadowTheAge@12 363 end
ShadowTheAge@12 364
ShadowTheAge@12 365 local function updateGroupRealm(id)
ShadowTheAge@38 366 local name = select(13, 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@38 377 local name = select(13, 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@38 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@38 408 if select(12, 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@40 625 local function setHighlightColorMy(self, frame, color)
ShadowTheAge@40 626 if not frame.highlight then
ShadowTheAge@40 627 frame.highlight = frame:CreateTexture(nil, "OVERLAY");
ShadowTheAge@40 628 frame.highlight:SetAllPoints(frame);
ShadowTheAge@40 629 end
ShadowTheAge@40 630 frame.highlight:SetColorTexture(color.r, color.g, color.b, color.a);
ShadowTheAge@40 631 end
ShadowTheAge@40 632
ShadowTheAge@12 633 function addon:CreateLFGUI()
ShadowTheAge@32 634 local scale = db.global.lfgPanelScale or 1.0;
ShadowTheAge@32 635 local itemCount = db.global.listItemCount;
ShadowTheAge@32 636 local shift = itemCount * 16;
ShadowTheAge@32 637
ShadowTheAge@32 638 tableTemplate = {
ShadowTheAge@32 639 {name="Title",width=160, value = updateGroupName, color = updateNameColor},
ShadowTheAge@32 640 {name="#",width=30,align="CENTER",value = updateGroupCount},
ShadowTheAge@32 641 {name="Realm",width=120,align="RIGHT",value = updateGroupRealm, color = updateRealmColor}
ShadowTheAge@32 642 }
ShadowTheAge@32 643
ShadowTheAge@32 644 extraColumns = db.global.extraColumns;
ShadowTheAge@32 645 if extraColumns.rtype then table.insert(tableTemplate, {name="Type",width=40,align="CENTER", value = updateRealmType}) end;
ShadowTheAge@32 646 if extraColumns.groupAge then table.insert(tableTemplate, {name="Age",width=45,align="CENTER",comparesort=sortByAge, value = updateGroupAge}) end;
ShadowTheAge@32 647 if extraColumns.joinTime then table.insert(tableTemplate, {name="Joined",width=45,align="CENTER",comparesort=sortByJoinAge, value = updateJoinAge}) end;
ShadowTheAge@32 648 table.insert(tableTemplate, {name="Misc",width=50,DoCellUpdate=updateTableData,comparesort=sortByScore,align="RIGHT",sort="asc"})
ShadowTheAge@32 649
ShadowTheAge@32 650 local tableWidth = 0;
ShadowTheAge@32 651 for i=1,#tableTemplate do
ShadowTheAge@32 652 tableWidth = tableWidth + tableTemplate[i].width;
ShadowTheAge@32 653 end
ShadowTheAge@32 654
ShadowTheAge@32 655
ShadowTheAge@33 656 lfgui = setupWidget(CreateFrame("Frame","CrossRealmAssistJoinUI",nil,"UIPanelDialogTemplate"), {SetFrameStrata="HIGH",SetWidth=tableWidth+45,SetHeight=shift+95,EnableMouse=true,SetMovable=true,SetScale=scale})
ShadowTheAge@12 657 lfgui.title:SetText("Click to join group")
ShadowTheAge@12 658 lfgui:SetScript("OnUpdate",addon.lfgUpdate)
ShadowTheAge@12 659 local titlereg = lfgui:CreateTitleRegion()
ShadowTheAge@12 660 titlereg:SetAllPoints(lfgui.title)
ShadowTheAge@12 661 addon:CreateTabs()
ShadowTheAge@0 662
ShadowTheAge@32 663 lfgTable = ScrollingTable:CreateST(tableTemplate,itemCount,16,nil,lfgui);
ShadowTheAge@40 664 lfgTable.SetHighLightColor = setHighlightColorMy; -- work around API changes in 7.0 (SetTexture -> SetColorTexture)
ShadowTheAge@0 665
ShadowTheAge@13 666 lfgTable:RegisterEvents({OnEnter=ShowLfgInfo,OnLeave=HideTooltip,OnClick=TableCellClick})
ShadowTheAge@0 667
ShadowTheAge@12 668 setupWidget(lfgTable.frame, nil, 10, 45);
ShadowTheAge@12 669 lfgTable.frame:SetBackdrop(nil)
ShadowTheAge@12 670 lfgui:SetPoint("CENTER",0,0)
ShadowTheAge@12 671 refreshLFGList()
ShadowTheAge@0 672
ShadowTheAge@32 673 lbThrottle = setupWidget(lfgui:CreateFontString(nil,"BACKGROUND", "GameFontHighlightSmall"), {SetWidth=tableWidth}, 0, 100)
ShadowTheAge@12 674 lbThrottle:Hide();
ShadowTheAge@0 675
ShadowTheAge@32 676 local btRefresh = setupWidget(CreateFrame("Button",nil,lfgui,"UIPanelSquareButton"),{SetWidth=22,SetHeight=22},tableWidth+19,27)
ShadowTheAge@12 677 btRefresh.icon:SetTexture("Interface/BUTTONS/UI-RefreshButton")
ShadowTheAge@12 678 btRefresh.icon:SetTexCoord(0,1,0,1);
ShadowTheAge@12 679 btRefresh:SetScript("OnClick",addon.refreshLfgCurrent)
ShadowTheAge@25 680
ShadowTheAge@32 681 setupWidget(CreateFrame("Frame",nil,lfgui,"HorizontalBarTemplate"),{SetWidth=tableWidth+32,SetHeight=2}, 8, shift+54)
ShadowTheAge@32 682 local text = setupWidget(lfgui:CreateFontString(nil,"BACKGROUND", "GameFontHighlightSmall"), {SetText="Filters:"}, 20, shift+68)
ShadowTheAge@25 683
ShadowTheAge@32 684 btFilterCount = CreateFrame("FRAME", "CrossRealmAssistCountFilter", lfgui, "UIDropDownMenuTemplate")
ShadowTheAge@32 685 UIDropDownMenu_SetWidth(btFilterCount, 90)
ShadowTheAge@32 686 UIDropDownMenu_SetText(btFilterCount, "By count")
ShadowTheAge@32 687 UIDropDownMenu_Initialize(btFilterCount, numberFilter)
ShadowTheAge@32 688 btFilterCount:SetPoint("TOPLEFT",text,"TOPRIGHT",-10,10)
ShadowTheAge@32 689
ShadowTheAge@32 690 cbHideNoAutoinv = setupWidget(CreateFrame("CheckButton",nil,lfgui,"UICheckButtonTemplate"),{SetWidth=22,SetHeight=22})
ShadowTheAge@32 691 cbHideNoAutoinv:SetPoint("TOPLEFT",btFilterCount,"TOPRIGHT",-10,-3)
ShadowTheAge@32 692 cbHideNoAutoinv:SetScript("OnClick",addon.refreshList)
ShadowTheAge@32 693 text = setupWidget(lfgui:CreateFontString(nil,"BACKGROUND", "GameFontHighlightSmall"), {SetText="Autoaccept only"})
ShadowTheAge@32 694 text:SetPoint("TOPLEFT",cbHideNoAutoinv,"TOPRIGHT",0,-7)
ShadowTheAge@32 695
ShadowTheAge@32 696 edFilterText = setupWidget(CreateFrame("EditBox",nil,lfgui,"SearchBoxTemplate"),{SetHeight=22})
ShadowTheAge@32 697 edFilterText:SetPoint("TOPLEFT",text,"TOPRIGHT",10,7)
ShadowTheAge@32 698 edFilterText:SetPoint("TOPRIGHT",lfgui,"BOTTOMRIGHT",-10,0)
ShadowTheAge@32 699 edFilterText:SetScript("OnTextChanged",updateFilter)
ShadowTheAge@12 700 end
ShadowTheAge@0 701
ShadowTheAge@12 702 function addon:CreateTabs()
ShadowTheAge@12 703 local prevTab
ShadowTheAge@32 704 for i=1,#addon.lfgGroups do
ShadowTheAge@12 705 local tab = CreateFrame("Button","$parentTab"..i,lfgui,"CharacterFrameTabButtonTemplate")
ShadowTheAge@32 706 tab:SetText((C_LFGList.GetCategoryInfo(addon.lfgGroups[i])));
ShadowTheAge@13 707 tab.searchID = i;
ShadowTheAge@12 708 tab:SetID(i);
ShadowTheAge@12 709 PanelTemplates_TabResize(tab, 0)
ShadowTheAge@12 710 if i == 1 then
ShadowTheAge@12 711 tab:SetPoint("TOPLEFT", lfgui, "BOTTOMLEFT", 10, 7)
ShadowTheAge@12 712 lfgTabSelected = tab
ShadowTheAge@13 713 else
ShadowTheAge@13 714 tab:SetPoint("TOPLEFT", prevTab, "TOPRIGHT",-15,0)
ShadowTheAge@13 715 end
ShadowTheAge@13 716 if curLfgGroup == i then
ShadowTheAge@12 717 PanelTemplates_SelectTab(tab)
ShadowTheAge@12 718 else
ShadowTheAge@12 719 PanelTemplates_DeselectTab(tab)
ShadowTheAge@12 720 end
ShadowTheAge@13 721 tab:SetScript("OnClick", TabClick)
ShadowTheAge@12 722 tabs[i] = tab
ShadowTheAge@12 723 prevTab = tab
ShadowTheAge@12 724 end
ShadowTheAge@0 725 end
ShadowTheAge@0 726
ShadowTheAge@0 727 -- LFG scanning routine
ShadowTheAge@0 728
ShadowTheAge@12 729 function addon.refreshLfgCurrent()
ShadowTheAge@12 730 addon.LfgScan(curLfgGroup)
ShadowTheAge@0 731 end
ShadowTheAge@0 732
ShadowTheAge@13 733 function addon.GetNextAutoScanCategory()
ShadowTheAge@32 734 for i=1,#addon.lfgGroups do
ShadowTheAge@32 735 if not autoScanGroups[i] and db.global.quickJoin[addon.lfgGroups[i]] and i ~= curLfgGroup then return i end
ShadowTheAge@13 736 end
ShadowTheAge@13 737 return nil
ShadowTheAge@13 738 end
ShadowTheAge@13 739
ShadowTheAge@12 740 function addon.LfgScan(group)
ShadowTheAge@13 741 if lfgTable then
ShadowTheAge@13 742 lfgTable:SetData({})
ShadowTheAge@13 743 changeTab(tabs[group])
ShadowTheAge@13 744 end
ShadowTheAge@0 745 lfgScanInProgress = true
ShadowTheAge@12 746 curLfgGroup = group
ShadowTheAge@21 747 local languages = db.global.allLanguages and allLanguageTable or C_LFGList.GetLanguageSearchFilter();
ShadowTheAge@32 748 C_LFGList.Search(addon.lfgGroups[curLfgGroup],"",nil,nil,languages)
ShadowTheAge@0 749 end
ShadowTheAge@0 750
ShadowTheAge@0 751 function addon:LfgScanFailed(event, reason)
ShadowTheAge@21 752 reason = reason or "Unknown reason";
ShadowTheAge@0 753 if reason == "throttled" then
ShadowTheAge@12 754 addon:ScheduleTimer(addon.LfgScan, 2, curLfgGroup)
ShadowTheAge@0 755 end
ShadowTheAge@13 756 if lbThrottle then
ShadowTheAge@13 757 if reason == "throttled" then
ShadowTheAge@13 758 lbThrottle:SetText("LFG scan is delayed (throttled).\nThis page will update automatically...")
ShadowTheAge@13 759 else
ShadowTheAge@13 760 lbThrottle:SetText("Scan failed ("..reason..")")
ShadowTheAge@13 761 end
ShadowTheAge@13 762 lbThrottle:Show()
ShadowTheAge@13 763 end
ShadowTheAge@0 764 end
ShadowTheAge@0 765
ShadowTheAge@0 766 function addon:LfgResponseData()
ShadowTheAge@0 767 lfgScanInProgress = false;
ShadowTheAge@13 768 addon:UpdateAutoButtonStatus()
ShadowTheAge@12 769 if lbThrottle then lbThrottle:Hide() end
ShadowTheAge@12 770 refreshLFGList()
ShadowTheAge@0 771 end
ShadowTheAge@0 772
ShadowTheAge@0 773 function addon:updateAppStatus(event, id, status, oldstatus)
ShadowTheAge@0 774 if status == "invited" then
ShadowTheAge@0 775 LFGListInviteDialog_Accept(LFGListInviteDialog)
ShadowTheAge@0 776 end
ShadowTheAge@12 777 addon:UpdateAutoButtonStatus()
ShadowTheAge@12 778 addon:SetGroupJoinStatus(id, status)
ShadowTheAge@12 779 end
ShadowTheAge@12 780
ShadowTheAge@12 781 function addon:SetGroupJoinStatus(id, status)
ShadowTheAge@38 782 local name = select(13, C_LFGList.GetSearchResultInfo(id))
ShadowTheAge@13 783 if name then
ShadowTheAge@13 784 recentgroups[name] = {status=status, time=GetTime()}
ShadowTheAge@13 785 end
ShadowTheAge@13 786 end
ShadowTheAge@13 787
ShadowTheAge@13 788 function addon:RealmVisited(realm, head)
ShadowTheAge@13 789 recentRealms[realm] = GetTime()
ShadowTheAge@12 790 end
ShadowTheAge@12 791
ShadowTheAge@12 792 function addon:updatePartyInfo()
ShadowTheAge@27 793 if IsInGroup() ~= wasInGroup then
ShadowTheAge@13 794 addon:RefreshZone(true)
ShadowTheAge@27 795 wasInGroup = IsInGroup()
ShadowTheAge@12 796 addon:UpdateAutoButtonStatus()
ShadowTheAge@12 797 end
ShadowTheAge@12 798 end
ShadowTheAge@12 799
ShadowTheAge@12 800
ShadowTheAge@12 801
ShadowTheAge@0 802
ShadowTheAge@0 803 -- Zone scanning routine
ShadowTheAge@0 804
ShadowTheAge@0 805 function addon:LeaveCombat()
ShadowTheAge@0 806 addon:UnregisterEvent("PLAYER_REGEN_ENABLED")
ShadowTheAge@0 807 scanstate = 0
ShadowTheAge@0 808 addon:ScanRealm();
ShadowTheAge@0 809 end
ShadowTheAge@0 810
ShadowTheAge@13 811 function addon:RefreshZoneAndClearHistory()
ShadowTheAge@13 812 ClearRealmHistory()
ShadowTheAge@11 813 addon:RefreshZone(true)
ShadowTheAge@11 814 end
ShadowTheAge@11 815
ShadowTheAge@11 816 function addon:RefreshZone(shedule)
ShadowTheAge@11 817 local inst, instType = IsInInstance()
ShadowTheAge@12 818 inInstance = (inst or instType ~= "none")
ShadowTheAge@12 819 if inInstance then
ShadowTheAge@11 820 lbRealm:SetText("Instanced zone")
ShadowTheAge@11 821 curRealmStat = nil
ShadowTheAge@12 822 inInstance = true
ShadowTheAge@11 823 else
ShadowTheAge@12 824 inInstance = false;
ShadowTheAge@11 825 if scanstate == 0 then
ShadowTheAge@11 826 addon:ScanRealm()
ShadowTheAge@11 827 elseif shedule == true and scanstate == 2 then
ShadowTheAge@27 828 addon:SetStatus("Rescan scheduled...")
ShadowTheAge@11 829 scanstate = 3
ShadowTheAge@11 830 end
ShadowTheAge@11 831 end
ShadowTheAge@12 832 addon:UpdateAutoButtonStatus()
ShadowTheAge@11 833 end
ShadowTheAge@11 834
ShadowTheAge@0 835 function addon:ScanRealm()
ShadowTheAge@0 836 if scanstate > 0 then return end
ShadowTheAge@0 837 if InCombatLockdown() then
ShadowTheAge@0 838 addon:RegisterEvent("PLAYER_REGEN_ENABLED","LeaveCombat")
ShadowTheAge@0 839 scanstate = 1
ShadowTheAge@27 840 addon:SetStatus("Scan scheduled after combat...");
ShadowTheAge@0 841 return
ShadowTheAge@0 842 end
ShadowTheAge@0 843 scanstate = 2
ShadowTheAge@11 844 addon:SetStatus("Scanning current realm...");
ShadowTheAge@0 845 local searchString = _G.WHO_TAG_ZONE .. '"' .. GetZoneText() .. '"';
ShadowTheAge@0 846 wholib:Who(searchString, {callback = "ScanResult", handler=addon})
ShadowTheAge@0 847 end
ShadowTheAge@0 848
ShadowTheAge@0 849 function addon:ScanResult(query, results, complete)
ShadowTheAge@0 850 local realms = {}
ShadowTheAge@0 851 for _, player in ipairs(results) do
ShadowTheAge@0 852 addon:AddRealmStat(player.Name, realms);
ShadowTheAge@0 853 end
ShadowTheAge@0 854 curRealmStat = addon:GetRealmStat(realms);
ShadowTheAge@11 855 curRealmStat.complete = complete
ShadowTheAge@0 856 addon:updateCurrentRealm();
ShadowTheAge@0 857 local rescan = scanstate == 3
ShadowTheAge@0 858 scanstate = 0;
ShadowTheAge@0 859 if rescan then addon:ScanRealm() end
ShadowTheAge@0 860 end
ShadowTheAge@0 861
ShadowTheAge@0 862 function addon:AddRealmStat(name, realms)
ShadowTheAge@11 863 if (name == playerName) then return end
ShadowTheAge@11 864 local _, realm = strsplit(realmSep, name)
ShadowTheAge@0 865 realm = realm or homeRealm
ShadowTheAge@0 866 realms[realm] = (realms[realm] or 0) + 1
ShadowTheAge@0 867 end
ShadowTheAge@0 868
ShadowTheAge@0 869 function addon:AddUnitIdStat(unitid, realms)
ShadowTheAge@0 870 local name, realm = UnitName(unitid);
ShadowTheAge@0 871 if not name then return end
ShadowTheAge@0 872 if realm == "" then realm = homeRealm end
ShadowTheAge@0 873 realm = realm or homeRealm
ShadowTheAge@0 874 realms[realm] = (realms[realm] or 0) + 1
ShadowTheAge@0 875 end
ShadowTheAge@0 876
ShadowTheAge@0 877 function addon:GetRealmStat(realms)
ShadowTheAge@0 878 local rcount = 0;
ShadowTheAge@0 879 local stat = {};
ShadowTheAge@0 880 local pcount = 0;
ShadowTheAge@19 881 if realms then
ShadowTheAge@19 882 for realm,count in pairs(realms) do
ShadowTheAge@19 883 table.insert(stat,{realm=realm,count=count})
ShadowTheAge@19 884 rcount = rcount + 1;
ShadowTheAge@19 885 pcount = pcount + count;
ShadowTheAge@19 886 end
ShadowTheAge@0 887 end
ShadowTheAge@0 888 if rcount > 1 then
ShadowTheAge@0 889 table.sort(stat, function(a,b) return a.count > b.count end)
ShadowTheAge@0 890 stat.max = stat[1].count
ShadowTheAge@0 891 else stat.max = 0 end
ShadowTheAge@0 892 stat.players = pcount;
ShadowTheAge@0 893 stat.realms = rcount;
ShadowTheAge@0 894 return stat;
ShadowTheAge@0 895 end
ShadowTheAge@0 896
ShadowTheAge@0 897 function addon:updateCurrentRealm()
ShadowTheAge@11 898 addon:SetStatus();
ShadowTheAge@11 899 if not curRealmStat or curRealmStat.realms < 1 then
ShadowTheAge@11 900 lbRealm:SetText("Unknown realm (No players)")
ShadowTheAge@11 901 return;
ShadowTheAge@0 902 end
ShadowTheAge@11 903
ShadowTheAge@11 904 local bestRealm = curRealmStat[1]
ShadowTheAge@13 905 addon:RealmVisited(bestRealm.realm, true)
ShadowTheAge@12 906 local prevThreshold = math.min(bestRealm.count/3,10)
ShadowTheAge@11 907 local mixCount = 0
ShadowTheAge@11 908 for i=2,curRealmStat.realms do
ShadowTheAge@0 909 local data = curRealmStat[i]
ShadowTheAge@11 910 if data.count >= prevThreshold then
ShadowTheAge@11 911 mixCount = mixCount + 1
ShadowTheAge@13 912 addon:RealmVisited(data.realm)
ShadowTheAge@12 913 prevThreshold = math.min(data.count/3,10)
ShadowTheAge@0 914 end
ShadowTheAge@0 915 end
ShadowTheAge@11 916 curRealmStat.threshold = prevThreshold
ShadowTheAge@11 917
ShadowTheAge@11 918 if (mixCount > 0) then
ShadowTheAge@11 919 lbRealm:SetText("Mixed "..bestRealm.realm.." +"..mixCount)
ShadowTheAge@11 920 else
ShadowTheAge@11 921 lbRealm:SetText(bestRealm.realm)
ShadowTheAge@0 922 end
ShadowTheAge@0 923 end
ShadowTheAge@0 924
ShadowTheAge@12 925
ShadowTheAge@12 926
ShadowTheAge@12 927
ShadowTheAge@12 928
ShadowTheAge@12 929
ShadowTheAge@12 930 -- Auto action button
ShadowTheAge@12 931
ShadowTheAge@13 932 local action
ShadowTheAge@12 933
ShadowTheAge@27 934 local function getPartyStat()
ShadowTheAge@29 935 local curPartyStat = {}
ShadowTheAge@27 936 if IsInGroup() then
ShadowTheAge@27 937 if IsInRaid() then
ShadowTheAge@27 938 for i=1, MAX_RAID_MEMBERS do
ShadowTheAge@27 939 addon:AddUnitIdStat("raid"..i, curPartyStat)
ShadowTheAge@27 940 end
ShadowTheAge@27 941 else
ShadowTheAge@27 942 for i=1, MAX_PARTY_MEMBERS do
ShadowTheAge@27 943 addon:AddUnitIdStat("party"..i, curPartyStat)
ShadowTheAge@27 944 end
ShadowTheAge@27 945 end
ShadowTheAge@27 946 end
ShadowTheAge@29 947 return curPartyStat
ShadowTheAge@27 948 end
ShadowTheAge@27 949
ShadowTheAge@13 950 local LeaveGroup = {
ShadowTheAge@13 951 func = LeaveParty;
ShadowTheAge@17 952 tooltip = function(self)
ShadowTheAge@27 953 local partyStat = addon:GetRealmStat(getPartyStat())
ShadowTheAge@17 954 GameTooltip:AddLine("Players in party "..partyStat.players)
ShadowTheAge@17 955 local max = partyStat.max;
ShadowTheAge@17 956 for i=1,#partyStat do
ShadowTheAge@17 957 local data = partyStat[i]
ShadowTheAge@17 958 local percent = math.ceil(100 * data.count / partyStat.players - 0.5) .. "%";
ShadowTheAge@17 959 local pmax = data.count/max;
ShadowTheAge@17 960 local green = 0.5 + pmax * 0.5;
ShadowTheAge@17 961 local gray = 0.5 * (1-pmax)
ShadowTheAge@17 962 GameTooltip:AddDoubleLine(data.realm, percent, gray,green,gray,gray,green,gray)
ShadowTheAge@17 963 end
ShadowTheAge@17 964 GameTooltip:AddLine("Click to leave party",1,0.5,0)
ShadowTheAge@17 965 end,
ShadowTheAge@13 966 text = "Leave group"
ShadowTheAge@13 967 }
ShadowTheAge@13 968
ShadowTheAge@13 969 local CancelJoin = {
ShadowTheAge@13 970 func = function()
ShadowTheAge@13 971 local apps = C_LFGList.GetApplications();
ShadowTheAge@13 972 if apps[1] then
ShadowTheAge@13 973 C_LFGList.CancelApplication(apps[1])
ShadowTheAge@13 974 end
ShadowTheAge@13 975 end,
ShadowTheAge@13 976 tooltip = "Cancel your current join application",
ShadowTheAge@13 977 text = "Cancel join"
ShadowTheAge@13 978 }
ShadowTheAge@13 979
ShadowTheAge@13 980 local QuickJoin = {
ShadowTheAge@13 981 func = function(self, button)
ShadowTheAge@13 982 if button == "RightButton" then
ShadowTheAge@13 983 addon:SetGroupJoinStatus(self.groupToJoin, "_skip")
ShadowTheAge@13 984 else
ShadowTheAge@38 985 local delisted = select(12, C_LFGList.GetSearchResultInfo(self.groupToJoin))
ShadowTheAge@13 986 if delisted == false then
ShadowTheAge@13 987 JoinGroup(self.groupToJoin)
ShadowTheAge@13 988 else
ShadowTheAge@13 989 addon:SetStatus("Group just delisted")
ShadowTheAge@13 990 end
ShadowTheAge@13 991 end
ShadowTheAge@13 992 end,
ShadowTheAge@13 993 findGroup = function()
ShadowTheAge@13 994 local count, list = C_LFGList.GetSearchResults()
ShadowTheAge@13 995 local best
ShadowTheAge@13 996 local bestvalue = 0
ShadowTheAge@13 997 for i = 1,count do
ShadowTheAge@13 998 local rid = list[i];
ShadowTheAge@13 999 if not rid then break end
ShadowTheAge@13 1000 local value = WeightLfgItem(rid, true);
ShadowTheAge@13 1001 if value > bestvalue then
ShadowTheAge@13 1002 best = rid
ShadowTheAge@13 1003 bestvalue = value
ShadowTheAge@13 1004 end
ShadowTheAge@13 1005 end
ShadowTheAge@13 1006 return best
ShadowTheAge@13 1007 end,
ShadowTheAge@13 1008 tooltip = function(self)
ShadowTheAge@13 1009 AddLfgGroupInfo(self.groupToJoin, true)
ShadowTheAge@13 1010 GameTooltip:AddLine(" ")
ShadowTheAge@13 1011 GameTooltip:AddDoubleLine("Click to join","Right click to skip",0,1,0,1,0.5,0)
ShadowTheAge@13 1012 end,
ShadowTheAge@13 1013 text = "Quick join"
ShadowTheAge@13 1014 }
ShadowTheAge@13 1015
ShadowTheAge@13 1016 local ScanNext = {
ShadowTheAge@13 1017 func = function(self)
ShadowTheAge@13 1018 autoScanGroups[curLfgGroup] = 1
ShadowTheAge@13 1019 addon.LfgScan(self.category)
ShadowTheAge@13 1020 end,
ShadowTheAge@13 1021 tooltip = function(self)
ShadowTheAge@32 1022 GameTooltip:AddLine("Scan "..(C_LFGList.GetCategoryInfo(addon.lfgGroups[self.category])))
ShadowTheAge@13 1023 end,
ShadowTheAge@13 1024 text = "Scan more"
ShadowTheAge@13 1025 }
ShadowTheAge@13 1026
ShadowTheAge@13 1027 local NeedReset = {
ShadowTheAge@13 1028 func = function()
ShadowTheAge@13 1029 wipe(autoScanGroups);
ShadowTheAge@38 1030 curLfgGroup = 0;
ShadowTheAge@13 1031 local categoryToScan = addon.GetNextAutoScanCategory()
ShadowTheAge@13 1032 if categoryToScan then
ShadowTheAge@13 1033 addon.LfgScan(categoryToScan)
ShadowTheAge@13 1034 end
ShadowTheAge@13 1035 end,
ShadowTheAge@13 1036 tooltip = "Scan again",
ShadowTheAge@13 1037 text = "Restart scan"
ShadowTheAge@13 1038 }
ShadowTheAge@13 1039
ShadowTheAge@13 1040 local Wait = {
ShadowTheAge@13 1041 tooltip = "Scan in progress",
ShadowTheAge@13 1042 text = "Wait..."
ShadowTheAge@13 1043 }
ShadowTheAge@13 1044
ShadowTheAge@13 1045 local ShowQuickHint = {
ShadowTheAge@13 1046 tooltip = "Quick Join",
ShadowTheAge@13 1047 text = "Quick Join",
ShadowTheAge@13 1048 func = function()
ShadowTheAge@13 1049 StaticPopupDialogs["CROSS_REALM_ASSIST"] = {
ShadowTheAge@32 1050 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 1051 button1 = OKAY,
ShadowTheAge@13 1052 hideOnEscape = true,
ShadowTheAge@13 1053 preferredIndex = 3,
ShadowTheAge@13 1054 }
ShadowTheAge@13 1055 StaticPopup_Show("CROSS_REALM_ASSIST")
ShadowTheAge@13 1056 hintShown = true;
ShadowTheAge@13 1057 end
ShadowTheAge@13 1058 }
ShadowTheAge@13 1059
ShadowTheAge@13 1060 function addon.DoAutoAction(widget, button)
ShadowTheAge@13 1061 addon:SetStatus()
ShadowTheAge@13 1062 if action and action.func then
ShadowTheAge@13 1063 action:func(button)
ShadowTheAge@13 1064 end
ShadowTheAge@13 1065 addon:UpdateAutoButtonStatus()
ShadowTheAge@13 1066 end
ShadowTheAge@13 1067
ShadowTheAge@13 1068 function addon.actionTooltip()
ShadowTheAge@13 1069 local tooltip = action.tooltip
ShadowTheAge@13 1070 if type(tooltip) == 'function' then
ShadowTheAge@13 1071 tooltip(action)
ShadowTheAge@13 1072 else
ShadowTheAge@13 1073 GameTooltip:AddLine(tooltip)
ShadowTheAge@11 1074 end
ShadowTheAge@11 1075 end
ShadowTheAge@11 1076
ShadowTheAge@13 1077 function addon:UpdateAutoButtonStatus()
ShadowTheAge@13 1078 if not btQuick then return end
ShadowTheAge@13 1079 btQuick:Enable()
ShadowTheAge@19 1080 if IsInGroup() then
ShadowTheAge@13 1081 action = LeaveGroup;
ShadowTheAge@13 1082 elseif C_LFGList.GetNumApplications() > 0 then
ShadowTheAge@13 1083 action = CancelJoin;
ShadowTheAge@13 1084 elseif lfgScanInProgress then
ShadowTheAge@13 1085 action = Wait
ShadowTheAge@19 1086 elseif not hintShown and db.global.quickJoinHint then
ShadowTheAge@19 1087 action = ShowQuickHint;
ShadowTheAge@13 1088 else
ShadowTheAge@13 1089 local group = QuickJoin.findGroup();
ShadowTheAge@13 1090 if group then
ShadowTheAge@13 1091 action = QuickJoin;
ShadowTheAge@13 1092 QuickJoin.groupToJoin = group
ShadowTheAge@13 1093 else
ShadowTheAge@13 1094 local categoryToScan = addon.GetNextAutoScanCategory()
ShadowTheAge@13 1095 if (categoryToScan) then
ShadowTheAge@13 1096 action = ScanNext;
ShadowTheAge@13 1097 ScanNext.category = categoryToScan
ShadowTheAge@13 1098 else
ShadowTheAge@13 1099 action = NeedReset;
ShadowTheAge@13 1100 end
ShadowTheAge@13 1101 end
ShadowTheAge@13 1102 end
ShadowTheAge@13 1103 btQuick:SetText(action.text)
ShadowTheAge@13 1104 if GameTooltip:GetOwner() == btQuick then
ShadowTheAge@13 1105 ShowTooltip(btQuick)
ShadowTheAge@0 1106 end
ShadowTheAge@0 1107 end
ShadowTheAge@0 1108
ShadowTheAge@12 1109
ShadowTheAge@13 1110
ShadowTheAge@13 1111
ShadowTheAge@27 1112 -- Realm hop group
ShadowTheAge@13 1113
ShadowTheAge@27 1114 local function CreateHopGroup()
ShadowTheAge@29 1115 if canJoinGroup() then
ShadowTheAge@29 1116 C_LFGList.CreateListing(16,"Realm hopping - "..homeRealm,0,"","",true)
ShadowTheAge@29 1117 addon:ScheduleTimer(ConvertToRaid, 5)
ShadowTheAge@29 1118 end
ShadowTheAge@27 1119 end
ShadowTheAge@27 1120
ShadowTheAge@27 1121 function addon:PlayerFlagsUpdate(event, target)
ShadowTheAge@29 1122 if target == "player" and UnitIsAFK("player") and C_Garrison.IsOnGarrisonMap() and db.global.autoCreateHopGroup then
ShadowTheAge@29 1123 CreateHopGroup()
ShadowTheAge@29 1124 end
ShadowTheAge@27 1125 end
ShadowTheAge@13 1126
ShadowTheAge@13 1127 -- Settings
ShadowTheAge@13 1128
ShadowTheAge@32 1129 function addon.toggleMinimapIcon(hidden)
ShadowTheAge@13 1130 if hidden then
ShadowTheAge@13 1131 DEFAULT_CHAT_FRAME:AddMessage("|cffff0000Type |cffffffff/cra |cffff0000in chat to open Cross Realm Assist without minimap button");
ShadowTheAge@13 1132 minimapIcon:Hide("CrossRealmAssistMinimapIcon")
ShadowTheAge@13 1133 else
ShadowTheAge@13 1134 minimapIcon:Show("CrossRealmAssistMinimapIcon")
ShadowTheAge@13 1135 end
ShadowTheAge@0 1136 end
ShadowTheAge@0 1137
ShadowTheAge@32 1138 function addon.updateLfgScale(scale)
ShadowTheAge@32 1139 if lfgui then lfgui:SetScale(scale) end;
ShadowTheAge@32 1140 end
ShadowTheAge@32 1141
ShadowTheAge@32 1142 function addon.updateUIScale(scale)
ShadowTheAge@32 1143 if gui then gui:SetScale(scale) end;
ShadowTheAge@32 1144 end
ShadowTheAge@32 1145
ShadowTheAge@13 1146 local function toggleQuickJoinHint(btn, arg1, arg2, checked)
ShadowTheAge@13 1147 db.global.quickJoinHint = checked
ShadowTheAge@0 1148 end
ShadowTheAge@0 1149
ShadowTheAge@13 1150 local function toggleQuickJoin(btn, arg1, arg2, checked)
ShadowTheAge@13 1151 db.global.quickJoin[arg1] = checked
ShadowTheAge@13 1152 end
ShadowTheAge@13 1153
ShadowTheAge@21 1154 local function toggleAllLanguages(btn, arg1, arg2, checked)
ShadowTheAge@21 1155 db.global.allLanguages = checked
ShadowTheAge@21 1156 end
ShadowTheAge@21 1157
ShadowTheAge@25 1158 local function toggleApplyAsDD(btn, arg1, arg2, checked)
ShadowTheAge@25 1159 db.global.applyAsDD = checked
ShadowTheAge@25 1160 end
ShadowTheAge@25 1161
ShadowTheAge@27 1162 local function toggleCreateHopGroup(btn, arg1, arg2, checked)
ShadowTheAge@27 1163 db.global.autoCreateHopGroup = checked
ShadowTheAge@29 1164 if checked then addon:RegisterEvent("PLAYER_FLAGS_CHANGED", "PlayerFlagsUpdate") end
ShadowTheAge@27 1165 end
ShadowTheAge@27 1166
ShadowTheAge@32 1167 local function joinFriendGroup(btn, rid)
ShadowTheAge@32 1168 JoinGroup(rid);
ShadowTheAge@32 1169 end
ShadowTheAge@32 1170
ShadowTheAge@13 1171 local function ClearJoinHistory()
ShadowTheAge@13 1172 recentgroups = {}
ShadowTheAge@13 1173 addon:UpdateAutoButtonStatus()
ShadowTheAge@13 1174 if lfgTable then lfgTable:Refresh() end
ShadowTheAge@13 1175 end
ShadowTheAge@13 1176
ShadowTheAge@27 1177 local function QuickJoinStoplist()
ShadowTheAge@27 1178 StaticPopupDialogs["CROSS_REALM_ASSIST_STOPLIST"] = {
ShadowTheAge@29 1179 OnShow = function (self, data)
ShadowTheAge@29 1180 self.editBox:SetText(table.concat(db.global.stoplist or {}, ","))
ShadowTheAge@29 1181 end,
ShadowTheAge@29 1182 OnAccept=function(self)
ShadowTheAge@29 1183 local text = self.editBox:GetText();
ShadowTheAge@29 1184 local stoplist = {}
ShadowTheAge@29 1185 for item in string.gmatch(text, "[^, ][^,]*") do
ShadowTheAge@29 1186 table.insert(stoplist,string.lower(item))
ShadowTheAge@29 1187 end
ShadowTheAge@29 1188 db.global.stoplist = stoplist
ShadowTheAge@29 1189 end,
ShadowTheAge@29 1190 button1 = OKAY,
ShadowTheAge@29 1191 button2 = CANCEL,
ShadowTheAge@29 1192 editBoxWidth = 350,
ShadowTheAge@29 1193 hasEditBox=true,
ShadowTheAge@29 1194 text = "Ignore groups containing following words:\nSeparated by comma",
ShadowTheAge@29 1195 preferredIndex = 3
ShadowTheAge@29 1196 }
ShadowTheAge@29 1197 StaticPopup_Show("CROSS_REALM_ASSIST_STOPLIST")
ShadowTheAge@27 1198 end
ShadowTheAge@13 1199
ShadowTheAge@13 1200 local function initMenu(self, level)
ShadowTheAge@13 1201 if not level then return end
ShadowTheAge@13 1202 if level == 1 then
ShadowTheAge@32 1203 UIDropDownMenu_AddButton({text="Clear join history",notCheckable=1,func=ClearJoinHistory}, level)
ShadowTheAge@13 1204 UIDropDownMenu_AddButton({text="Clear realm history",notCheckable=1,func=ClearRealmHistory}, level)
ShadowTheAge@32 1205 UIDropDownMenu_AddButton({disabled=1,notCheckable=1}, level)
ShadowTheAge@29 1206
ShadowTheAge@32 1207 UIDropDownMenu_AddButton({text="Cross Realm Assist Toolbox",notCheckable=1,func=CreateHopGroup,isTitle=1}, level)
ShadowTheAge@32 1208 UIDropDownMenu_AddButton({text="Show Quick Join Hint",checked=db.global.quickJoinHint, func=toggleQuickJoinHint,keepShownOnClick=true,isNotRadio=true}, level)
ShadowTheAge@32 1209 if canJoinGroup() then
ShadowTheAge@29 1210 UIDropDownMenu_AddButton({text="Create a group for realm hoppers",notCheckable=1,func=CreateHopGroup}, level)
ShadowTheAge@32 1211 UIDropDownMenu_AddButton({text="Join to a friend",notCheckable=1,hasArrow=1,value="jtf",keepShownOnClick=true}, level)
ShadowTheAge@29 1212 end
ShadowTheAge@29 1213
ShadowTheAge@29 1214 UIDropDownMenu_AddButton({disabled=1,notCheckable=1}, level)
ShadowTheAge@32 1215 UIDropDownMenu_AddButton({text="Settings...",notCheckable=1,func=addon.showSettings}, level)
ShadowTheAge@13 1216 elseif level == 2 then
ShadowTheAge@32 1217 if UIDROPDOWNMENU_MENU_VALUE == "jtf" then
ShadowTheAge@32 1218 local count, list = C_LFGList.GetSearchResults()
ShadowTheAge@32 1219 local friends = {}
ShadowTheAge@32 1220 for i = 1,count do
ShadowTheAge@32 1221 local rid = list[i];
ShadowTheAge@32 1222 if not rid then break end
ShadowTheAge@32 1223 local bnf, chf, gf = C_LFGList.GetSearchResultFriends(rid)
ShadowTheAge@32 1224 for j=1,#bnf do table.insert(friends,{name="|cFF00B1F0"..bnf[j],type=0,id=rid}) end
ShadowTheAge@32 1225 for j=1,#chf do table.insert(friends,{name="|cFFFF80FF"..chf[j],type=1,id=rid}) end
ShadowTheAge@32 1226 for j=1,#gf do table.insert(friends,{name="|cFF40FF40"..gf[j],type=2,id=rid}) end
ShadowTheAge@32 1227 end
ShadowTheAge@32 1228 if #friends==0 then
ShadowTheAge@32 1229 UIDropDownMenu_AddButton({text="No friends found (click to refresh)",notCheckable=1,func=addon.refreshLfgCurrent}, level)
ShadowTheAge@32 1230 else
ShadowTheAge@32 1231 UIDropDownMenu_AddButton({text="Refresh",notCheckable=1,func=addon.refreshLfgCurrent}, level)
ShadowTheAge@32 1232 table.sort(friends, sortByTypeAndName);
ShadowTheAge@32 1233 for i=1,#friends do
ShadowTheAge@32 1234 UIDropDownMenu_AddButton({text=friends[i].name,notCheckable=1,func=joinFriendGroup,arg1=friends[i].id}, level)
ShadowTheAge@32 1235 end
ShadowTheAge@32 1236 end
ShadowTheAge@32 1237 end
ShadowTheAge@29 1238 end
ShadowTheAge@13 1239 end
ShadowTheAge@13 1240
ShadowTheAge@13 1241 function addon.ShowSettings(frame)
ShadowTheAge@13 1242 if not settingsMenu then
ShadowTheAge@13 1243 settingsMenu = CreateFrame("Frame", "CrossRealmAssistMenu")
ShadowTheAge@13 1244 settingsMenu.displayMode = "MENU"
ShadowTheAge@13 1245 settingsMenu.initialize = initMenu
ShadowTheAge@13 1246 end
ShadowTheAge@13 1247 ToggleDropDownMenu(1, nil, settingsMenu, frame, 10, 0)
ShadowTheAge@12 1248 end