annotate CrossRealmAssist.lua @ 32:7b7b3ca996fd

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