ShadowTheAge@0: CrossRealmAssist = LibStub("AceAddon-3.0"):NewAddon("CrossRealmAssist", "AceEvent-3.0", "AceConsole-3.0", "AceTimer-3.0") ShadowTheAge@0: local addon = CrossRealmAssist; ShadowTheAge@0: local wholib = LibStub:GetLibrary('LibWho-2.0'):Library() ShadowTheAge@12: local ScrollingTable = LibStub("ScrollingTable"); ShadowTheAge@13: local ldb = LibStub("LibDataBroker-1.1") ShadowTheAge@13: local minimapIcon = LibStub("LibDBIcon-1.0") ShadowTheAge@13: local db ShadowTheAge@0: ShadowTheAge@13: local homeRealm, realmSep, gui, btRefresh, btSettings, btQuick, btManual, lbRealm, lbStatus, playerName, lfgui, lfgTabSelected, lfgTable, lbThrottle, curLfgGroup, sheduledScan, wasInGroup, inInstance ShadowTheAge@13: local settingsMenu ShadowTheAge@13: local hintShown ShadowTheAge@0: ShadowTheAge@12: local tabs = {} ShadowTheAge@17: local curRealmStat, curPartyStat ShadowTheAge@0: local scanstate=0 ShadowTheAge@0: local recentRealms={} ShadowTheAge@12: local recentgroups={} ShadowTheAge@13: local autoScanGroups={} ShadowTheAge@0: local active=false ShadowTheAge@0: ShadowTheAge@0: local lfgGroups={ ShadowTheAge@0: 6, -- Custom ShadowTheAge@0: 10, -- Ashran ShadowTheAge@0: 1, -- Quests ShadowTheAge@13: 3, -- Raids ShadowTheAge@13: 8 -- BGs ShadowTheAge@0: } ShadowTheAge@0: ShadowTheAge@12: local StatusTable = { ShadowTheAge@12: ["invited"]="Invited", ShadowTheAge@12: ["declined"]="Declined", ShadowTheAge@12: ["timedout"]="Timed out", ShadowTheAge@12: ["applied"]="Applied", ShadowTheAge@12: ["cancelled"]="Join cancelled", ShadowTheAge@12: ["inviteaccepted"]="Joined", ShadowTheAge@13: ["_init"]="Join request", ShadowTheAge@13: ["_skip"]="Skipped" ShadowTheAge@12: } ShadowTheAge@13: local DefaultWidgetPos = {x=0, y=200, to="CENTER"} ShadowTheAge@13: local SettingsDefaults={ ShadowTheAge@13: global={ ShadowTheAge@13: minimap = {}, ShadowTheAge@13: widgetPos=DefaultWidgetPos, ShadowTheAge@13: quickJoinHint = true, ShadowTheAge@13: quickJoin={[6]=1,[10]=1} ShadowTheAge@13: } ShadowTheAge@13: } ShadowTheAge@12: ShadowTheAge@12: ShadowTheAge@12: -- Utils functions ShadowTheAge@12: ShadowTheAge@12: local function PlayerName(fullname) ShadowTheAge@12: fullname = fullname or "???-???" ShadowTheAge@12: local name, realm = strsplit(realmSep, fullname) ShadowTheAge@12: realm = realm or homeRealm; ShadowTheAge@12: return name, realm; ShadowTheAge@12: end ShadowTheAge@12: ShadowTheAge@12: local function canJoinGroup() ShadowTheAge@12: return (not IsInGroup()) or (UnitIsGroupLeader('player') and not IsInRaid()) ShadowTheAge@12: end ShadowTheAge@12: ShadowTheAge@12: local function sortByWeight(a,b) ShadowTheAge@12: return b.weight < a.weight ShadowTheAge@12: end ShadowTheAge@12: ShadowTheAge@12: ShadowTheAge@12: -- UI functions ShadowTheAge@12: ShadowTheAge@12: local function createIcon(owner, icon, id) ShadowTheAge@12: local image = owner:CreateTexture(nil, "BACKGROUND") ShadowTheAge@12: image:SetWidth(16) ShadowTheAge@12: image:SetHeight(16) ShadowTheAge@12: image:SetTexture(icon) ShadowTheAge@12: image:SetPoint("TOPLEFT",owner,"TOPLEFT",id*16,0) ShadowTheAge@12: return image ShadowTheAge@12: end ShadowTheAge@0: ShadowTheAge@11: local function setupWidget(widget, parameters, x, y) ShadowTheAge@11: if parameters then ShadowTheAge@11: for key,value in pairs(parameters) do widget[key](widget,value) end ShadowTheAge@11: end ShadowTheAge@11: if y then ShadowTheAge@11: widget:SetPoint("TOPLEFT",widget:GetParent(),"TOPLEFT",x,-y) ShadowTheAge@11: end ShadowTheAge@11: return widget ShadowTheAge@11: end ShadowTheAge@11: ShadowTheAge@11: local function ShowTooltip(widget) ShadowTheAge@11: GameTooltip:SetOwner(widget, widget.TooltipAnchor) ShadowTheAge@11: GameTooltip:ClearLines() ShadowTheAge@11: widget:TooltipFactory() ShadowTheAge@11: GameTooltip:Show() ShadowTheAge@11: end ShadowTheAge@11: ShadowTheAge@11: local function HideTooltip(widget) ShadowTheAge@11: GameTooltip:Hide() ShadowTheAge@11: end ShadowTheAge@11: ShadowTheAge@11: local function setupTooltip(widget, anchor, factory) ShadowTheAge@11: widget.TooltipAnchor = anchor; ShadowTheAge@11: widget.TooltipFactory = factory; ShadowTheAge@11: widget:SetScript("OnEnter", ShowTooltip) ShadowTheAge@11: widget:SetScript("OnLeave", HideTooltip) ShadowTheAge@11: end ShadowTheAge@11: ShadowTheAge@13: local function TabClick(tab) ShadowTheAge@13: if tab == lfgTabSelected then return end ShadowTheAge@13: addon.LfgScan(tab.searchID) ShadowTheAge@13: end ShadowTheAge@13: ShadowTheAge@13: local function changeTab(tab) ShadowTheAge@12: PanelTemplates_DeselectTab(lfgTabSelected) ShadowTheAge@12: lfgTabSelected = tab ShadowTheAge@12: PanelTemplates_SelectTab(lfgTabSelected) ShadowTheAge@12: end ShadowTheAge@0: ShadowTheAge@12: local function realmToolip() ShadowTheAge@12: if not curRealmStat then return end ShadowTheAge@12: local players = curRealmStat.players; ShadowTheAge@12: local threshold = curRealmStat.threshold ShadowTheAge@12: GameTooltip:AddLine("Players in zone: "..players) ShadowTheAge@12: if not curRealmStat.complete then ShadowTheAge@12: GameTooltip:AppendText("+") ShadowTheAge@12: end ShadowTheAge@12: for i=1,curRealmStat.realms do ShadowTheAge@12: local data = curRealmStat[i] ShadowTheAge@12: local percent = math.ceil(100 * data.count / players - 0.5) .. "%"; ShadowTheAge@12: if data.count >= threshold then ShadowTheAge@12: GameTooltip:AddDoubleLine(data.realm, percent, 0,1,0,0,1,0) ShadowTheAge@12: else ShadowTheAge@12: GameTooltip:AddDoubleLine(data.realm, percent, 0.5,0.5,0.5,0.5,0.5,0.5) ShadowTheAge@12: end ShadowTheAge@12: end ShadowTheAge@0: end ShadowTheAge@0: ShadowTheAge@13: local function ClearRealmHistory() ShadowTheAge@13: recentRealms = {} ShadowTheAge@13: addon:updateCurrentRealm() ShadowTheAge@13: if lfgTable then lfgTable:Refresh() end ShadowTheAge@13: end ShadowTheAge@13: ShadowTheAge@12: ShadowTheAge@12: ShadowTheAge@12: ShadowTheAge@12: ShadowTheAge@12: ShadowTheAge@12: ShadowTheAge@12: -- LFG list data providers, filters and tooltips ShadowTheAge@12: ShadowTheAge@12: local lfgScanInProgress=false ShadowTheAge@12: local hasLfgListChanges=false ShadowTheAge@12: ShadowTheAge@12: local function addTooltipLineIcon(predicat, text, icon, r, g, b, wrap) ShadowTheAge@12: if predicat then ShadowTheAge@12: GameTooltip:AddLine(text, r, g, b, wrap) ShadowTheAge@12: if icon then GameTooltip:AddTexture(icon) end ShadowTheAge@12: end ShadowTheAge@12: end ShadowTheAge@12: ShadowTheAge@12: local function WeightLfgItem(id, forAutoJoin) ShadowTheAge@12: local _, action, caption, desc, voice, ilvl, time, bnetfr, charfr, guild, delisted, fullname, pcount, autoinv = C_LFGList.GetSearchResultInfo(id) ShadowTheAge@12: if delisted then return 0 end ShadowTheAge@12: local name,realm = PlayerName(fullname); ShadowTheAge@12: if forAutoJoin then ShadowTheAge@12: if not autoinv or pcount >= 35 or pcount <= 5 or recentgroups[fullname] then return 0 end ShadowTheAge@12: end ShadowTheAge@12: ShadowTheAge@12: local autoinvWeight = autoinv and 5 or 2 ShadowTheAge@12: ShadowTheAge@12: local visCoef = 1 ShadowTheAge@12: if recentgroups[fullname] then ShadowTheAge@12: local ago = GetTime() - recentgroups[fullname].time; ShadowTheAge@12: visCoef = math.min(1,ago/600) ShadowTheAge@12: end ShadowTheAge@12: ShadowTheAge@12: local leaderRealm = 3 -- recently visited realms ShadowTheAge@13: local realmVis = recentRealms[realm] ShadowTheAge@13: local leaderRealm = 3; ShadowTheAge@13: if realmVis then ShadowTheAge@13: local ago = GetTime() - realmVis ShadowTheAge@13: leaderRealm = 1 + 2*math.min(1,ago/600); ShadowTheAge@13: end ShadowTheAge@12: ShadowTheAge@12: local countWeight = 4 -- count weight ShadowTheAge@12: if pcount >= 39 or pcount <= 1 then countWeight = 1 ShadowTheAge@12: elseif pcount >= 35 or pcount <= 4 then countWeight = 2 ShadowTheAge@12: elseif pcount >= 30 or pcount <= 10 then countWeight = 3 ShadowTheAge@12: else countWeight = 4 end ShadowTheAge@12: ShadowTheAge@12: local ageWeight = 2 ShadowTheAge@12: if time > 1200 then ageWeight = 4 ShadowTheAge@12: elseif time > 300 then ageWeight = 3 end ShadowTheAge@12: ShadowTheAge@12: return leaderRealm * countWeight * visCoef * autoinvWeight * ageWeight; ShadowTheAge@12: end ShadowTheAge@12: ShadowTheAge@13: local function AddLfgGroupInfo(id, short) ShadowTheAge@13: local _, action, caption, desc, voice, ilvl, time, bnetfr, charfr, guild, delisted, fullname, pcount, autoinv = C_LFGList.GetSearchResultInfo(id) ShadowTheAge@12: local friends = bnetfr+charfr+guild ShadowTheAge@12: GameTooltip:ClearLines() ShadowTheAge@12: GameTooltip:AddLine(caption,1,1,1) ShadowTheAge@12: addTooltipLineIcon(desc ~= "", desc, nil, 0.5, 0.5, 0.5, true) ShadowTheAge@12: local name, realm = PlayerName(fullname) ShadowTheAge@13: GameTooltip:AddDoubleLine("Players:",pcount) ShadowTheAge@12: GameTooltip:AddDoubleLine("Leader:",name) ShadowTheAge@12: GameTooltip:AddDoubleLine("Leader realm:",realm) ShadowTheAge@13: if recentRealms[realm] then ShadowTheAge@13: local ago = GetTime() - recentRealms[realm] ShadowTheAge@13: GameTooltip:AddDoubleLine("Realm visited",SecondsToTime(ago, false, false, 1, false).." ago",1,0.5,0,1,0.5,0) ShadowTheAge@13: else ShadowTheAge@13: GameTooltip:AddDoubleLine(" ","Realm not visited!",0,0,0,0,1,0) ShadowTheAge@13: end ShadowTheAge@13: if not short then ShadowTheAge@13: addTooltipLineIcon(ilvl > 0, "Min. ilvl: "..ilvl, READY_CHECK_WAITING_TEXTURE, 1, 1, 0) ShadowTheAge@13: addTooltipLineIcon(voice ~= "", "Voice: "..voice, READY_CHECK_WAITING_TEXTURE, 1, 1, 0) ShadowTheAge@13: addTooltipLineIcon(friends > 0, "Friends: "..friends, READY_CHECK_WAITING_TEXTURE, 1, 1, 0) ShadowTheAge@13: addTooltipLineIcon(autoinv, "Autoinvite!", READY_CHECK_READY_TEXTURE, 0, 1, 0) ShadowTheAge@13: local visitinfo = recentgroups[fullname] ShadowTheAge@13: if visitinfo then ShadowTheAge@13: local ago = GetTime() - visitinfo.time; ShadowTheAge@13: GameTooltip:AddDoubleLine(StatusTable[visitinfo.status] or visitinfo.status,SecondsToTime(ago, false, false, 1, false).." ago",1,0,0,1,0,0) ShadowTheAge@13: GameTooltip:AddTexture(READY_CHECK_NOT_READY_TEXTURE) ShadowTheAge@13: end ShadowTheAge@12: end ShadowTheAge@12: GameTooltip:Show() ShadowTheAge@12: end ShadowTheAge@12: ShadowTheAge@13: local function ShowLfgInfo(rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...) ShadowTheAge@13: if not realrow then return end ShadowTheAge@13: local rowdata = scrollingTable:GetRow(realrow); ShadowTheAge@13: GameTooltip:SetOwner(rowFrame, "ANCHOR_BOTTOMLEFT",-10,25) ShadowTheAge@13: AddLfgGroupInfo(rowdata.id); ShadowTheAge@13: end ShadowTheAge@13: ShadowTheAge@12: local function updateTableData(rowFrame, cellFrame, data, cols, row, realrow, column, fShow, table, ...) ShadowTheAge@12: if fShow then ShadowTheAge@12: local rowdata = table:GetRow(realrow); ShadowTheAge@12: local icons = cellFrame.icons ShadowTheAge@12: local _, action, caption, desc, voice, ilvl, time, bnetfr, charfr, guild, delisted, fullname, pcount, autoinv = C_LFGList.GetSearchResultInfo(rowdata.id) ShadowTheAge@12: if not icons then ShadowTheAge@12: local miscdata = createIcon(cellFrame,READY_CHECK_WAITING_TEXTURE,0) ShadowTheAge@12: local autoinv = createIcon(cellFrame,READY_CHECK_READY_TEXTURE, 1) ShadowTheAge@12: local visited = createIcon(cellFrame,READY_CHECK_NOT_READY_TEXTURE, 2) ShadowTheAge@12: icons = {misc=miscdata, autoinv=autoinv, visited=visited} ShadowTheAge@12: cellFrame.icons = icons ShadowTheAge@12: end ShadowTheAge@12: icons.misc:SetShown(voice ~= "" or bnetfr > 0 or charfr > 0 or guild > 0 or ilvl > 0) ShadowTheAge@12: icons.autoinv:SetShown(autoinv) ShadowTheAge@12: icons.visited:SetShown(recentgroups[fullname]) ShadowTheAge@12: if GameTooltip:GetOwner() == rowFrame then ShowLfgInfo(rowFrame, cellFrame, data, cols, row, realrow, column, table) end ShadowTheAge@12: end ShadowTheAge@12: end ShadowTheAge@12: ShadowTheAge@12: local function updateGroupName(id) ShadowTheAge@12: return select(3, C_LFGList.GetSearchResultInfo(id)) ShadowTheAge@12: end ShadowTheAge@12: ShadowTheAge@12: local function updateGroupCount(id) ShadowTheAge@12: return select(13, C_LFGList.GetSearchResultInfo(id)) ShadowTheAge@12: end ShadowTheAge@12: ShadowTheAge@12: local function updateGroupRealm(id) ShadowTheAge@12: local name = select(12, C_LFGList.GetSearchResultInfo(id)) ShadowTheAge@12: local pname, realm = PlayerName(name); ShadowTheAge@12: return realm ShadowTheAge@12: end ShadowTheAge@12: ShadowTheAge@13: local COLOR_YELLOW = {r=1,g=1,b=0,a=1} ShadowTheAge@13: local COLOR_GREEN = {r=0,g=1,b=0,a=1} ShadowTheAge@13: local function updateRealmColor(id) ShadowTheAge@13: local name = select(12, C_LFGList.GetSearchResultInfo(id)) ShadowTheAge@13: local pname, realm = PlayerName(name); ShadowTheAge@13: return recentRealms[realm] and COLOR_YELLOW or COLOR_GREEN; ShadowTheAge@13: end ShadowTheAge@13: ShadowTheAge@12: local function filterTable(self, row) ShadowTheAge@12: local delisted = select(11, C_LFGList.GetSearchResultInfo(row.id)) ShadowTheAge@12: return not delisted; ShadowTheAge@12: end ShadowTheAge@12: ShadowTheAge@12: function addon:UpdateResponseData(event, result) ShadowTheAge@13: if not lfgTable then return end ShadowTheAge@12: if select(11, C_LFGList.GetSearchResultInfo(result)) then ShadowTheAge@12: lfgTable:SetFilter(filterTable) ShadowTheAge@12: end ShadowTheAge@12: hasLfgListChanges = true ShadowTheAge@12: end ShadowTheAge@12: ShadowTheAge@12: local function refreshLFGList() ShadowTheAge@12: if lfgScanInProgress or not lfgTable then return end ShadowTheAge@12: local count, list = C_LFGList.GetSearchResults() ShadowTheAge@12: local tableData = {} ShadowTheAge@12: for i = 1,count do ShadowTheAge@12: local rid = list[i]; ShadowTheAge@12: if not rid then break end ShadowTheAge@12: local data = list[i]; ShadowTheAge@12: local cols = {} ShadowTheAge@12: local row = {rid} ShadowTheAge@12: cols[1] = {value=updateGroupName,args=row} ShadowTheAge@12: cols[2] = {value=updateGroupCount,args=row} ShadowTheAge@13: cols[3] = {value=updateGroupRealm,args=row,color=updateRealmColor,colorargs=row} ShadowTheAge@12: cols[4] = {} ShadowTheAge@12: table.insert(tableData, {cols=cols,id=rid,weight=WeightLfgItem(rid)}) ShadowTheAge@12: end ShadowTheAge@12: table.sort(tableData, sortByWeight); ShadowTheAge@12: lfgTable:SetData(tableData) ShadowTheAge@12: end ShadowTheAge@12: ShadowTheAge@13: local function JoinGroup(rid) ShadowTheAge@13: local tank, heal, dd = C_LFGList.GetAvailableRoles() ShadowTheAge@13: addon:SetGroupJoinStatus(rid, "_init") ShadowTheAge@13: C_LFGList.ApplyToGroup(rid, "", tank, heal, dd) ShadowTheAge@13: end ShadowTheAge@13: ShadowTheAge@13: local function TableCellClick(rowFrame, cellFrame, data, cols, row, realrow, column, scrollingTable, ...) ShadowTheAge@12: if not realrow or not canJoinGroup() then return end ShadowTheAge@12: local rowdata = scrollingTable:GetRow(realrow); ShadowTheAge@13: JoinGroup(rowdata.id) ShadowTheAge@12: end ShadowTheAge@12: ShadowTheAge@12: ShadowTheAge@12: ShadowTheAge@12: ShadowTheAge@12: ShadowTheAge@12: ShadowTheAge@12: -- Addon functions and gui constructors ShadowTheAge@12: ShadowTheAge@13: function addon.ShowMmTooltip(tooltip) ShadowTheAge@13: tooltip:AddLine("Cross Realm Assist",1,1,1) ShadowTheAge@13: tooltip:Show() ShadowTheAge@13: end ShadowTheAge@13: ShadowTheAge@13: --[[function addon.MmClick(self, button) ShadowTheAge@13: if button == "RightButton" then ShadowTheAge@13: addon.ShowSettings(self) ShadowTheAge@13: else ShadowTheAge@13: addon:Activate() ShadowTheAge@13: end ShadowTheAge@13: end]] ShadowTheAge@13: ShadowTheAge@13: function addon:OnInitialize() ShadowTheAge@13: db = LibStub("AceDB-3.0"):New("CrossRealmAssistDB", SettingsDefaults) ShadowTheAge@13: local minimapData = ldb:NewDataObject("CrossRealmAssistMinimapIcon",{ ShadowTheAge@13: type = "data source", ShadowTheAge@13: text = "Cross Realm Assist", ShadowTheAge@13: icon = "Interface/Icons/INV_Misc_GroupNeedMore", ShadowTheAge@13: OnClick = addon.Activate, ShadowTheAge@13: OnTooltipShow = addon.ShowMmTooltip ShadowTheAge@13: }) ShadowTheAge@13: minimapIcon:Register("CrossRealmAssistMinimapIcon", minimapData, db.global.minimap) ShadowTheAge@13: end ShadowTheAge@13: ShadowTheAge@0: function addon:OnEnable() ShadowTheAge@0: realmSep = _G.REALM_SEPARATORS ShadowTheAge@11: playerName = UnitName("player") ShadowTheAge@0: homeRealm = GetRealmName() ShadowTheAge@0: addon:RegisterChatCommand("cra", "Activate") ShadowTheAge@0: addon:RegisterChatCommand("crossrealmassist", "Activate") ShadowTheAge@0: end ShadowTheAge@0: ShadowTheAge@0: function addon:OnDisable() ShadowTheAge@0: addon:Deactivate() ShadowTheAge@0: end ShadowTheAge@0: ShadowTheAge@0: function addon:Activate() ShadowTheAge@0: if active then return end ShadowTheAge@0: active=true ShadowTheAge@0: wasInGroup = IsInGroup() ShadowTheAge@11: if not gui then addon:CreateUI() end ShadowTheAge@11: addon:updateCurrentRealm(); ShadowTheAge@13: addon:RefreshZoneAndClearHistory(); ShadowTheAge@11: gui:Show() ShadowTheAge@13: addon:RegisterEvent("ZONE_CHANGED_NEW_AREA", "RefreshZoneAndClearHistory") ShadowTheAge@13: addon:RegisterEvent("SCENARIO_UPDATE", "RefreshZoneAndClearHistory") ShadowTheAge@12: addon:RegisterEvent("LFG_LIST_SEARCH_RESULTS_RECEIVED", "LfgResponseData") ShadowTheAge@12: addon:RegisterEvent("LFG_LIST_SEARCH_RESULT_UPDATED", "UpdateResponseData") ShadowTheAge@12: addon:RegisterEvent("LFG_LIST_SEARCH_FAILED", "LfgScanFailed") ShadowTheAge@12: addon:RegisterEvent("GROUP_ROSTER_UPDATE", "updatePartyInfo") ShadowTheAge@12: addon:RegisterEvent("LFG_LIST_APPLICATION_STATUS_UPDATED", "updateAppStatus") ShadowTheAge@13: addon.LfgScan(addon.GetNextAutoScanCategory() or 1) ShadowTheAge@0: end ShadowTheAge@0: ShadowTheAge@0: function addon:Deactivate() ShadowTheAge@0: if not active then return end ShadowTheAge@0: active = false ShadowTheAge@12: gui:Hide() ShadowTheAge@12: if lfgui then lfgui:Hide() end ShadowTheAge@0: scanstate = 0 ShadowTheAge@0: lfgScanInProgress = false ShadowTheAge@0: addon:UnregisterEvent("ZONE_CHANGED_NEW_AREA") ShadowTheAge@17: addon:UnregisterEvent("SCENARIO_UPDATE") ShadowTheAge@0: addon:UnregisterEvent("PLAYER_REGEN_ENABLED") ShadowTheAge@0: addon:UnregisterEvent("LFG_LIST_SEARCH_RESULTS_RECEIVED") ShadowTheAge@12: addon:UnregisterEvent("LFG_LIST_SEARCH_RESULT_UPDATED") ShadowTheAge@0: addon:UnregisterEvent("LFG_LIST_SEARCH_FAILED") ShadowTheAge@0: addon:UnregisterEvent("GROUP_ROSTER_UPDATE") ShadowTheAge@0: addon:UnregisterEvent("LFG_LIST_APPLICATION_STATUS_UPDATED") ShadowTheAge@0: end ShadowTheAge@0: ShadowTheAge@11: function addon:SetStatus(status) ShadowTheAge@11: if status then ShadowTheAge@11: lbStatus:SetText(status) ShadowTheAge@11: else ShadowTheAge@13: lbStatus:SetText("") ShadowTheAge@11: end ShadowTheAge@11: end ShadowTheAge@11: ShadowTheAge@13: local function stopMovingWidget() ShadowTheAge@13: gui:StopMovingOrSizing() ShadowTheAge@13: local point,_,_,x,y = gui:GetPoint(1); ShadowTheAge@13: db.global.widgetPos = {x=x,y=y,to=point} ShadowTheAge@13: end ShadowTheAge@13: ShadowTheAge@0: function addon:CreateUI() ShadowTheAge@12: gui = setupWidget(CreateFrame("Frame","CrossRealmAssistMainUI",nil,"InsetFrameTemplate3"), {SetFrameStrata="LOW",SetWidth=208,SetHeight=60,EnableMouse=true,SetMovable=true}) ShadowTheAge@11: local title = setupWidget(CreateFrame("Frame",nil,gui), {SetWidth=190,SetHeight=18,EnableMouse=true,RegisterForDrag="LeftButton"}, 0, 6); ShadowTheAge@11: title:SetScript("OnDragStart", function() gui:StartMoving() end) ShadowTheAge@13: title:SetScript("OnDragStop", stopMovingWidget) ShadowTheAge@11: gui:SetScript("OnHide", addon.Deactivate) ShadowTheAge@12: setupTooltip(title, "ANCHOR_TOP", realmToolip) ShadowTheAge@11: ShadowTheAge@11: lbRealm = setupWidget(gui:CreateFontString(nil,"BACKGROUND", "GameFontNormal"), {SetWidth=200,SetHeight=18}, 0, 6) ShadowTheAge@11: lbStatus = setupWidget(gui:CreateFontString(nil,"BACKGROUND", "GameFontHighlightSmallLeft"), {SetWidth=200,SetHeight=10}, 6, 23) ShadowTheAge@11: ShadowTheAge@12: btQuick = setupWidget(CreateFrame("Button",nil,gui,"UIMenuButtonStretchTemplate"),{SetWidth=90,SetHeight=20,SetText="Quick join"},4,36) ShadowTheAge@13: btQuick:RegisterForClicks("RightButtonUp","LeftButtonUp") ShadowTheAge@12: btQuick:SetScript("OnClick",addon.DoAutoAction) ShadowTheAge@13: setupTooltip(btQuick, "ANCHOR_BOTTOM", addon.actionTooltip) ShadowTheAge@12: btManual = setupWidget(CreateFrame("Button",nil,gui,"UIMenuButtonStretchTemplate"),{SetWidth=90,SetHeight=20,SetText="Manual join"},94,36) ShadowTheAge@12: btManual:SetScript("OnClick",addon.ShowManualLfg) ShadowTheAge@11: setupWidget(CreateFrame("Button",nil,gui,"UIPanelCloseButton"),{EnableMouse=true,SetWidth=20,SetHeight=20},188,0) ShadowTheAge@11: ShadowTheAge@13: btRefresh = setupWidget(CreateFrame("Button",nil,gui,"UIPanelSquareButton"),{SetWidth=20,SetHeight=20},184,16) ShadowTheAge@11: btRefresh.icon:SetTexture("Interface/BUTTONS/UI-RefreshButton") ShadowTheAge@11: btRefresh.icon:SetTexCoord(0,1,0,1); ShadowTheAge@11: btRefresh:SetScript("OnClick",addon.RefreshZone) ShadowTheAge@11: ShadowTheAge@13: btSettings = setupWidget(CreateFrame("Button",nil,gui,"UIPanelSquareButton"),{SetWidth=20,SetHeight=20},184,36) ShadowTheAge@13: btSettings.icon:SetTexture("Interface/Worldmap/Gear_64Grey") ShadowTheAge@13: btSettings.icon:SetTexCoord(0.1,0.9,0.1,0.9); ShadowTheAge@13: btSettings:SetScript("OnClick",addon.ShowSettings) ShadowTheAge@13: ShadowTheAge@13: local savedPos = db.global.widgetPos ShadowTheAge@13: gui:SetPoint(savedPos.to,savedPos.x,savedPos.y) ShadowTheAge@12: addon:UpdateAutoButtonStatus() ShadowTheAge@12: end ShadowTheAge@11: ShadowTheAge@12: function addon:ShowManualLfg() ShadowTheAge@12: if not lfgui then addon:CreateLFGUI() end ShadowTheAge@12: lfgui:Show() ShadowTheAge@12: end ShadowTheAge@0: ShadowTheAge@12: function addon.lfgUpdate() ShadowTheAge@12: if hasLfgListChanges then ShadowTheAge@12: lfgTable:Refresh() ShadowTheAge@12: hasLfgListChanges = false ShadowTheAge@12: end ShadowTheAge@12: end ShadowTheAge@0: ShadowTheAge@12: function addon:CreateLFGUI() ShadowTheAge@12: lfgui = setupWidget(CreateFrame("Frame","CrossRealmAssistJoinUI",nil,"UIPanelDialogTemplate"), {SetFrameStrata="DIALOG",SetWidth=405,SetHeight=300,EnableMouse=true,SetMovable=true}) ShadowTheAge@12: lfgui.title:SetText("Click to join group") ShadowTheAge@12: lfgui:SetScript("OnUpdate",addon.lfgUpdate) ShadowTheAge@12: local titlereg = lfgui:CreateTitleRegion() ShadowTheAge@12: titlereg:SetAllPoints(lfgui.title) ShadowTheAge@12: addon:CreateTabs() ShadowTheAge@0: ShadowTheAge@12: lfgTable = ScrollingTable:CreateST({ ShadowTheAge@12: {name="Title",width=160}, ShadowTheAge@12: {name="#",width=30,align="CENTER"}, ShadowTheAge@12: {name="Realm",width=120,align="RIGHT"}, ShadowTheAge@12: {name="",width=50,DoCellUpdate=updateTableData} ShadowTheAge@12: },15,16,nil,lfgui); ShadowTheAge@0: ShadowTheAge@13: lfgTable:RegisterEvents({OnEnter=ShowLfgInfo,OnLeave=HideTooltip,OnClick=TableCellClick}) ShadowTheAge@0: ShadowTheAge@12: setupWidget(lfgTable.frame, nil, 10, 45); ShadowTheAge@12: lfgTable.frame:SetBackdrop(nil) ShadowTheAge@12: lfgui:SetPoint("CENTER",0,0) ShadowTheAge@12: refreshLFGList() ShadowTheAge@0: ShadowTheAge@12: lbThrottle = setupWidget(lfgui:CreateFontString(nil,"BACKGROUND", "GameFontHighlightSmall"), {SetWidth=300}, 50, 100) ShadowTheAge@12: lbThrottle:Hide(); ShadowTheAge@0: ShadowTheAge@12: local btRefresh = setupWidget(CreateFrame("Button",nil,lfgui,"UIPanelSquareButton"),{SetWidth=22,SetHeight=22},379,27) ShadowTheAge@12: btRefresh.icon:SetTexture("Interface/BUTTONS/UI-RefreshButton") ShadowTheAge@12: btRefresh.icon:SetTexCoord(0,1,0,1); ShadowTheAge@12: btRefresh:SetScript("OnClick",addon.refreshLfgCurrent) ShadowTheAge@12: end ShadowTheAge@0: ShadowTheAge@12: function addon:CreateTabs() ShadowTheAge@12: local prevTab ShadowTheAge@12: for i=1,#lfgGroups do ShadowTheAge@12: local tab = CreateFrame("Button","$parentTab"..i,lfgui,"CharacterFrameTabButtonTemplate") ShadowTheAge@12: tab:SetText((C_LFGList.GetCategoryInfo(lfgGroups[i]))); ShadowTheAge@13: tab.searchID = i; ShadowTheAge@12: tab:SetID(i); ShadowTheAge@12: PanelTemplates_TabResize(tab, 0) ShadowTheAge@12: if i == 1 then ShadowTheAge@12: tab:SetPoint("TOPLEFT", lfgui, "BOTTOMLEFT", 10, 7) ShadowTheAge@12: lfgTabSelected = tab ShadowTheAge@13: else ShadowTheAge@13: tab:SetPoint("TOPLEFT", prevTab, "TOPRIGHT",-15,0) ShadowTheAge@13: end ShadowTheAge@13: if curLfgGroup == i then ShadowTheAge@12: PanelTemplates_SelectTab(tab) ShadowTheAge@12: else ShadowTheAge@12: PanelTemplates_DeselectTab(tab) ShadowTheAge@12: end ShadowTheAge@13: tab:SetScript("OnClick", TabClick) ShadowTheAge@12: tabs[i] = tab ShadowTheAge@12: prevTab = tab ShadowTheAge@12: end ShadowTheAge@0: end ShadowTheAge@0: ShadowTheAge@0: -- LFG scanning routine ShadowTheAge@0: ShadowTheAge@12: function addon.refreshLfgCurrent() ShadowTheAge@12: addon.LfgScan(curLfgGroup) ShadowTheAge@0: end ShadowTheAge@0: ShadowTheAge@13: function addon.GetNextAutoScanCategory() ShadowTheAge@13: for i=1,#lfgGroups do ShadowTheAge@13: if not autoScanGroups[i] and db.global.quickJoin[lfgGroups[i]] and i ~= curLfgGroup then return i end ShadowTheAge@13: end ShadowTheAge@13: return nil ShadowTheAge@13: end ShadowTheAge@13: ShadowTheAge@12: function addon.LfgScan(group) ShadowTheAge@13: if lfgTable then ShadowTheAge@13: lfgTable:SetData({}) ShadowTheAge@13: changeTab(tabs[group]) ShadowTheAge@13: end ShadowTheAge@0: lfgScanInProgress = true ShadowTheAge@12: curLfgGroup = group ShadowTheAge@13: C_LFGList.Search(lfgGroups[curLfgGroup],"") ShadowTheAge@0: end ShadowTheAge@0: ShadowTheAge@0: function addon:LfgScanFailed(event, reason) ShadowTheAge@0: if reason == "throttled" then ShadowTheAge@12: addon:ScheduleTimer(addon.LfgScan, 2, curLfgGroup) ShadowTheAge@0: end ShadowTheAge@13: if lbThrottle then ShadowTheAge@13: if reason == "throttled" then ShadowTheAge@13: lbThrottle:SetText("LFG scan is delayed (throttled).\nThis page will update automatically...") ShadowTheAge@13: else ShadowTheAge@13: lbThrottle:SetText("Scan failed ("..reason..")") ShadowTheAge@13: end ShadowTheAge@13: lbThrottle:Show() ShadowTheAge@13: end ShadowTheAge@0: end ShadowTheAge@0: ShadowTheAge@0: function addon:LfgResponseData() ShadowTheAge@0: lfgScanInProgress = false; ShadowTheAge@13: addon:UpdateAutoButtonStatus() ShadowTheAge@12: if lbThrottle then lbThrottle:Hide() end ShadowTheAge@12: refreshLFGList() ShadowTheAge@0: end ShadowTheAge@0: ShadowTheAge@0: function addon:updateAppStatus(event, id, status, oldstatus) ShadowTheAge@0: if status == "invited" then ShadowTheAge@0: LFGListInviteDialog_Accept(LFGListInviteDialog) ShadowTheAge@0: end ShadowTheAge@12: addon:UpdateAutoButtonStatus() ShadowTheAge@12: addon:SetGroupJoinStatus(id, status) ShadowTheAge@12: end ShadowTheAge@12: ShadowTheAge@12: function addon:SetGroupJoinStatus(id, status) ShadowTheAge@12: local name = select(12, C_LFGList.GetSearchResultInfo(id)) ShadowTheAge@13: if name then ShadowTheAge@13: recentgroups[name] = {status=status, time=GetTime()} ShadowTheAge@13: end ShadowTheAge@13: end ShadowTheAge@13: ShadowTheAge@13: function addon:RealmVisited(realm, head) ShadowTheAge@13: recentRealms[realm] = GetTime() ShadowTheAge@12: end ShadowTheAge@12: ShadowTheAge@12: function addon:updatePartyInfo() ShadowTheAge@17: curPartyStat = {} ShadowTheAge@12: local inGroup = IsInGroup() ShadowTheAge@12: if inGroup then ShadowTheAge@12: if IsInRaid() then ShadowTheAge@12: for i=1, MAX_RAID_MEMBERS do ShadowTheAge@17: addon:AddUnitIdStat("raid"..i, curPartyStat) ShadowTheAge@12: end ShadowTheAge@12: else ShadowTheAge@12: for i=1, MAX_PARTY_MEMBERS do ShadowTheAge@17: addon:AddUnitIdStat("party"..i, curPartyStat) ShadowTheAge@12: end ShadowTheAge@12: end ShadowTheAge@12: end ShadowTheAge@12: if inGroup ~= wasInGroup then ShadowTheAge@13: addon:RefreshZone(true) ShadowTheAge@12: wasInGroup = inGroup ShadowTheAge@12: addon:UpdateAutoButtonStatus() ShadowTheAge@12: end ShadowTheAge@12: end ShadowTheAge@12: ShadowTheAge@12: ShadowTheAge@12: ShadowTheAge@0: ShadowTheAge@0: -- Zone scanning routine ShadowTheAge@0: ShadowTheAge@0: function addon:LeaveCombat() ShadowTheAge@0: addon:UnregisterEvent("PLAYER_REGEN_ENABLED") ShadowTheAge@0: scanstate = 0 ShadowTheAge@0: addon:ScanRealm(); ShadowTheAge@0: end ShadowTheAge@0: ShadowTheAge@13: function addon:RefreshZoneAndClearHistory() ShadowTheAge@13: ClearRealmHistory() ShadowTheAge@11: addon:RefreshZone(true) ShadowTheAge@11: end ShadowTheAge@11: ShadowTheAge@11: function addon:RefreshZone(shedule) ShadowTheAge@11: local inst, instType = IsInInstance() ShadowTheAge@12: inInstance = (inst or instType ~= "none") ShadowTheAge@12: if inInstance then ShadowTheAge@11: lbRealm:SetText("Instanced zone") ShadowTheAge@11: curRealmStat = nil ShadowTheAge@12: inInstance = true ShadowTheAge@11: else ShadowTheAge@12: inInstance = false; ShadowTheAge@11: if scanstate == 0 then ShadowTheAge@11: addon:ScanRealm() ShadowTheAge@11: elseif shedule == true and scanstate == 2 then ShadowTheAge@11: addon:SetStatus("Rescan sheduled...") ShadowTheAge@11: scanstate = 3 ShadowTheAge@11: end ShadowTheAge@11: end ShadowTheAge@12: addon:UpdateAutoButtonStatus() ShadowTheAge@11: end ShadowTheAge@11: ShadowTheAge@0: function addon:ScanRealm() ShadowTheAge@0: if scanstate > 0 then return end ShadowTheAge@0: if InCombatLockdown() then ShadowTheAge@0: addon:RegisterEvent("PLAYER_REGEN_ENABLED","LeaveCombat") ShadowTheAge@0: scanstate = 1 ShadowTheAge@11: addon:SetStatus("Scan sheduled after combat..."); ShadowTheAge@0: return ShadowTheAge@0: end ShadowTheAge@0: scanstate = 2 ShadowTheAge@11: addon:SetStatus("Scanning current realm..."); ShadowTheAge@0: local searchString = _G.WHO_TAG_ZONE .. '"' .. GetZoneText() .. '"'; ShadowTheAge@0: wholib:Who(searchString, {callback = "ScanResult", handler=addon}) ShadowTheAge@0: end ShadowTheAge@0: ShadowTheAge@0: function addon:ScanResult(query, results, complete) ShadowTheAge@0: local realms = {} ShadowTheAge@0: for _, player in ipairs(results) do ShadowTheAge@0: addon:AddRealmStat(player.Name, realms); ShadowTheAge@0: end ShadowTheAge@0: curRealmStat = addon:GetRealmStat(realms); ShadowTheAge@11: curRealmStat.complete = complete ShadowTheAge@0: addon:updateCurrentRealm(); ShadowTheAge@0: local rescan = scanstate == 3 ShadowTheAge@0: scanstate = 0; ShadowTheAge@0: if rescan then addon:ScanRealm() end ShadowTheAge@0: end ShadowTheAge@0: ShadowTheAge@0: function addon:AddRealmStat(name, realms) ShadowTheAge@11: if (name == playerName) then return end ShadowTheAge@11: local _, realm = strsplit(realmSep, name) ShadowTheAge@0: realm = realm or homeRealm ShadowTheAge@0: realms[realm] = (realms[realm] or 0) + 1 ShadowTheAge@0: end ShadowTheAge@0: ShadowTheAge@0: function addon:AddUnitIdStat(unitid, realms) ShadowTheAge@0: local name, realm = UnitName(unitid); ShadowTheAge@0: if not name then return end ShadowTheAge@0: if realm == "" then realm = homeRealm end ShadowTheAge@0: realm = realm or homeRealm ShadowTheAge@0: realms[realm] = (realms[realm] or 0) + 1 ShadowTheAge@0: end ShadowTheAge@0: ShadowTheAge@0: function addon:GetRealmStat(realms) ShadowTheAge@0: local rcount = 0; ShadowTheAge@0: local stat = {}; ShadowTheAge@0: local pcount = 0; ShadowTheAge@19: if realms then ShadowTheAge@19: for realm,count in pairs(realms) do ShadowTheAge@19: table.insert(stat,{realm=realm,count=count}) ShadowTheAge@19: rcount = rcount + 1; ShadowTheAge@19: pcount = pcount + count; ShadowTheAge@19: end ShadowTheAge@0: end ShadowTheAge@0: if rcount > 1 then ShadowTheAge@0: table.sort(stat, function(a,b) return a.count > b.count end) ShadowTheAge@0: stat.max = stat[1].count ShadowTheAge@0: else stat.max = 0 end ShadowTheAge@0: stat.players = pcount; ShadowTheAge@0: stat.realms = rcount; ShadowTheAge@0: return stat; ShadowTheAge@0: end ShadowTheAge@0: ShadowTheAge@0: function addon:updateCurrentRealm() ShadowTheAge@11: addon:SetStatus(); ShadowTheAge@11: if not curRealmStat or curRealmStat.realms < 1 then ShadowTheAge@11: lbRealm:SetText("Unknown realm (No players)") ShadowTheAge@11: return; ShadowTheAge@0: end ShadowTheAge@11: ShadowTheAge@11: local bestRealm = curRealmStat[1] ShadowTheAge@13: addon:RealmVisited(bestRealm.realm, true) ShadowTheAge@12: local prevThreshold = math.min(bestRealm.count/3,10) ShadowTheAge@11: local mixCount = 0 ShadowTheAge@11: for i=2,curRealmStat.realms do ShadowTheAge@0: local data = curRealmStat[i] ShadowTheAge@11: if data.count >= prevThreshold then ShadowTheAge@11: mixCount = mixCount + 1 ShadowTheAge@13: addon:RealmVisited(data.realm) ShadowTheAge@12: prevThreshold = math.min(data.count/3,10) ShadowTheAge@0: end ShadowTheAge@0: end ShadowTheAge@11: curRealmStat.threshold = prevThreshold ShadowTheAge@11: ShadowTheAge@11: if (mixCount > 0) then ShadowTheAge@11: lbRealm:SetText("Mixed "..bestRealm.realm.." +"..mixCount) ShadowTheAge@11: else ShadowTheAge@11: lbRealm:SetText(bestRealm.realm) ShadowTheAge@0: end ShadowTheAge@0: end ShadowTheAge@0: ShadowTheAge@12: ShadowTheAge@12: ShadowTheAge@12: ShadowTheAge@12: ShadowTheAge@12: ShadowTheAge@12: -- Auto action button ShadowTheAge@12: ShadowTheAge@13: local action ShadowTheAge@12: ShadowTheAge@13: local LeaveGroup = { ShadowTheAge@13: func = LeaveParty; ShadowTheAge@17: tooltip = function(self) ShadowTheAge@17: local partyStat = addon:GetRealmStat(curPartyStat) ShadowTheAge@17: GameTooltip:AddLine("Players in party "..partyStat.players) ShadowTheAge@17: local max = partyStat.max; ShadowTheAge@17: for i=1,#partyStat do ShadowTheAge@17: local data = partyStat[i] ShadowTheAge@17: local percent = math.ceil(100 * data.count / partyStat.players - 0.5) .. "%"; ShadowTheAge@17: local pmax = data.count/max; ShadowTheAge@17: local green = 0.5 + pmax * 0.5; ShadowTheAge@17: local gray = 0.5 * (1-pmax) ShadowTheAge@17: GameTooltip:AddDoubleLine(data.realm, percent, gray,green,gray,gray,green,gray) ShadowTheAge@17: end ShadowTheAge@17: GameTooltip:AddLine("Click to leave party",1,0.5,0) ShadowTheAge@17: end, ShadowTheAge@13: text = "Leave group" ShadowTheAge@13: } ShadowTheAge@13: ShadowTheAge@13: local CancelJoin = { ShadowTheAge@13: func = function() ShadowTheAge@13: local apps = C_LFGList.GetApplications(); ShadowTheAge@13: if apps[1] then ShadowTheAge@13: C_LFGList.CancelApplication(apps[1]) ShadowTheAge@13: end ShadowTheAge@13: end, ShadowTheAge@13: tooltip = "Cancel your current join application", ShadowTheAge@13: text = "Cancel join" ShadowTheAge@13: } ShadowTheAge@13: ShadowTheAge@13: local QuickJoin = { ShadowTheAge@13: func = function(self, button) ShadowTheAge@13: if button == "RightButton" then ShadowTheAge@13: addon:SetGroupJoinStatus(self.groupToJoin, "_skip") ShadowTheAge@13: else ShadowTheAge@13: local delisted = select(11, C_LFGList.GetSearchResultInfo(self.groupToJoin)) ShadowTheAge@13: if delisted == false then ShadowTheAge@13: JoinGroup(self.groupToJoin) ShadowTheAge@13: else ShadowTheAge@13: addon:SetStatus("Group just delisted") ShadowTheAge@13: end ShadowTheAge@13: end ShadowTheAge@13: end, ShadowTheAge@13: findGroup = function() ShadowTheAge@13: local count, list = C_LFGList.GetSearchResults() ShadowTheAge@13: local best ShadowTheAge@13: local bestvalue = 0 ShadowTheAge@13: for i = 1,count do ShadowTheAge@13: local rid = list[i]; ShadowTheAge@13: if not rid then break end ShadowTheAge@13: local value = WeightLfgItem(rid, true); ShadowTheAge@13: if value > bestvalue then ShadowTheAge@13: best = rid ShadowTheAge@13: bestvalue = value ShadowTheAge@13: end ShadowTheAge@13: end ShadowTheAge@13: return best ShadowTheAge@13: end, ShadowTheAge@13: tooltip = function(self) ShadowTheAge@13: AddLfgGroupInfo(self.groupToJoin, true) ShadowTheAge@13: GameTooltip:AddLine(" ") ShadowTheAge@13: GameTooltip:AddDoubleLine("Click to join","Right click to skip",0,1,0,1,0.5,0) ShadowTheAge@13: end, ShadowTheAge@13: text = "Quick join" ShadowTheAge@13: } ShadowTheAge@13: ShadowTheAge@13: local ScanNext = { ShadowTheAge@13: func = function(self) ShadowTheAge@13: autoScanGroups[curLfgGroup] = 1 ShadowTheAge@13: addon.LfgScan(self.category) ShadowTheAge@13: end, ShadowTheAge@13: tooltip = function(self) ShadowTheAge@13: GameTooltip:AddLine("Scan "..(C_LFGList.GetCategoryInfo(lfgGroups[self.category]))) ShadowTheAge@13: end, ShadowTheAge@13: text = "Scan more" ShadowTheAge@13: } ShadowTheAge@13: ShadowTheAge@13: local NeedReset = { ShadowTheAge@13: func = function() ShadowTheAge@13: wipe(autoScanGroups); ShadowTheAge@13: local categoryToScan = addon.GetNextAutoScanCategory() ShadowTheAge@13: if categoryToScan then ShadowTheAge@13: addon.LfgScan(categoryToScan) ShadowTheAge@13: end ShadowTheAge@13: end, ShadowTheAge@13: tooltip = "Scan again", ShadowTheAge@13: text = "Restart scan" ShadowTheAge@13: } ShadowTheAge@13: ShadowTheAge@13: local Wait = { ShadowTheAge@13: tooltip = "Scan in progress", ShadowTheAge@13: text = "Wait..." ShadowTheAge@13: } ShadowTheAge@13: ShadowTheAge@13: local ShowQuickHint = { ShadowTheAge@13: tooltip = "Quick Join", ShadowTheAge@13: text = "Quick Join", ShadowTheAge@13: func = function() ShadowTheAge@13: StaticPopupDialogs["CROSS_REALM_ASSIST"] = { ShadowTheAge@13: text = "Quick Join button will automatically join you to a random group with autoinvite and medium number of players. You never join same group twice, you need to clear join history to do so. This message can be disabled in options.", ShadowTheAge@13: button1 = OKAY, ShadowTheAge@13: hideOnEscape = true, ShadowTheAge@13: preferredIndex = 3, ShadowTheAge@13: } ShadowTheAge@13: StaticPopup_Show("CROSS_REALM_ASSIST") ShadowTheAge@13: hintShown = true; ShadowTheAge@13: end ShadowTheAge@13: } ShadowTheAge@13: ShadowTheAge@13: function addon.DoAutoAction(widget, button) ShadowTheAge@13: addon:SetStatus() ShadowTheAge@13: if action and action.func then ShadowTheAge@13: action:func(button) ShadowTheAge@13: end ShadowTheAge@13: addon:UpdateAutoButtonStatus() ShadowTheAge@13: end ShadowTheAge@13: ShadowTheAge@13: function addon.actionTooltip() ShadowTheAge@13: local tooltip = action.tooltip ShadowTheAge@13: if type(tooltip) == 'function' then ShadowTheAge@13: tooltip(action) ShadowTheAge@13: else ShadowTheAge@13: GameTooltip:AddLine(tooltip) ShadowTheAge@11: end ShadowTheAge@11: end ShadowTheAge@11: ShadowTheAge@13: function addon:UpdateAutoButtonStatus() ShadowTheAge@13: if not btQuick then return end ShadowTheAge@13: btQuick:Enable() ShadowTheAge@19: if IsInGroup() then ShadowTheAge@13: action = LeaveGroup; ShadowTheAge@13: elseif C_LFGList.GetNumApplications() > 0 then ShadowTheAge@13: action = CancelJoin; ShadowTheAge@13: elseif lfgScanInProgress then ShadowTheAge@13: action = Wait ShadowTheAge@19: elseif not hintShown and db.global.quickJoinHint then ShadowTheAge@19: action = ShowQuickHint; ShadowTheAge@13: else ShadowTheAge@13: local group = QuickJoin.findGroup(); ShadowTheAge@13: if group then ShadowTheAge@13: action = QuickJoin; ShadowTheAge@13: QuickJoin.groupToJoin = group ShadowTheAge@13: else ShadowTheAge@13: local categoryToScan = addon.GetNextAutoScanCategory() ShadowTheAge@13: if (categoryToScan) then ShadowTheAge@13: action = ScanNext; ShadowTheAge@13: ScanNext.category = categoryToScan ShadowTheAge@13: else ShadowTheAge@13: action = NeedReset; ShadowTheAge@13: end ShadowTheAge@13: end ShadowTheAge@13: end ShadowTheAge@13: btQuick:SetText(action.text) ShadowTheAge@13: if GameTooltip:GetOwner() == btQuick then ShadowTheAge@13: ShowTooltip(btQuick) ShadowTheAge@0: end ShadowTheAge@0: end ShadowTheAge@0: ShadowTheAge@12: ShadowTheAge@13: ShadowTheAge@13: ShadowTheAge@13: ShadowTheAge@13: ShadowTheAge@13: -- Settings ShadowTheAge@13: ShadowTheAge@13: local function toggleMinimapIcon(btn, arg1, arg2, checked) ShadowTheAge@13: local hidden = not checked; ShadowTheAge@13: db.global.minimap.hide = hidden; ShadowTheAge@13: if hidden then ShadowTheAge@13: DEFAULT_CHAT_FRAME:AddMessage("|cffff0000Type |cffffffff/cra |cffff0000in chat to open Cross Realm Assist without minimap button"); ShadowTheAge@13: minimapIcon:Hide("CrossRealmAssistMinimapIcon") ShadowTheAge@13: else ShadowTheAge@13: minimapIcon:Show("CrossRealmAssistMinimapIcon") ShadowTheAge@13: end ShadowTheAge@0: end ShadowTheAge@0: ShadowTheAge@13: local function toggleQuickJoinHint(btn, arg1, arg2, checked) ShadowTheAge@13: db.global.quickJoinHint = checked ShadowTheAge@0: end ShadowTheAge@0: ShadowTheAge@13: local function toggleQuickJoin(btn, arg1, arg2, checked) ShadowTheAge@13: db.global.quickJoin[arg1] = checked ShadowTheAge@13: end ShadowTheAge@13: ShadowTheAge@13: local function ClearJoinHistory() ShadowTheAge@13: recentgroups = {} ShadowTheAge@13: addon:UpdateAutoButtonStatus() ShadowTheAge@13: if lfgTable then lfgTable:Refresh() end ShadowTheAge@13: end ShadowTheAge@13: ShadowTheAge@13: --[[local function resetPos() ShadowTheAge@13: db.global.widgetPos = DefaultWidgetPos ShadowTheAge@13: if gui then ShadowTheAge@13: gui:ClearAllPoints() ShadowTheAge@13: gui:SetPoint(DefaultWidgetPos.to,DefaultWidgetPos.x,DefaultWidgetPos.y) ShadowTheAge@0: end ShadowTheAge@13: end]] ShadowTheAge@13: ShadowTheAge@13: local function initMenu(self, level) ShadowTheAge@13: if not level then return end ShadowTheAge@13: if level == 1 then ShadowTheAge@13: UIDropDownMenu_AddButton({text="Clear realm history",notCheckable=1,func=ClearRealmHistory}, level) ShadowTheAge@13: UIDropDownMenu_AddButton({text="Clear join history",notCheckable=1,func=ClearJoinHistory}, level) ShadowTheAge@13: UIDropDownMenu_AddButton({disabled=1,notCheckable=1}, level) ShadowTheAge@13: UIDropDownMenu_AddButton({isTitle=1,text="Settings",notCheckable=1}, level) ShadowTheAge@13: UIDropDownMenu_AddButton({text="Show Minimap Button",checked=not db.global.minimap.hide, func=toggleMinimapIcon,keepShownOnClick=true,isNotRadio=true}, level) ShadowTheAge@13: UIDropDownMenu_AddButton({text="Show Quick Join Hint",checked=db.global.quickJoinHint, func=toggleQuickJoinHint,keepShownOnClick=true,isNotRadio=true}, level) ShadowTheAge@13: UIDropDownMenu_AddButton({text="Quick join categories",notCheckable=1,hasArrow=1,value="qjc",keepShownOnClick=true}, level) ShadowTheAge@13: elseif level == 2 then ShadowTheAge@13: if UIDROPDOWNMENU_MENU_VALUE == "qjc" then ShadowTheAge@13: for i=1,#lfgGroups do ShadowTheAge@13: local groupId = lfgGroups[i] ShadowTheAge@13: UIDropDownMenu_AddButton({text=(C_LFGList.GetCategoryInfo(groupId)),checked=db.global.quickJoin[groupId],arg1=groupId,func=toggleQuickJoin,keepShownOnClick=true,isNotRadio=true}, level) ShadowTheAge@13: end ShadowTheAge@13: end ShadowTheAge@13: end ShadowTheAge@13: end ShadowTheAge@13: ShadowTheAge@13: function addon.ShowSettings(frame) ShadowTheAge@13: if not settingsMenu then ShadowTheAge@13: settingsMenu = CreateFrame("Frame", "CrossRealmAssistMenu") ShadowTheAge@13: settingsMenu.displayMode = "MENU" ShadowTheAge@13: settingsMenu.initialize = initMenu ShadowTheAge@13: end ShadowTheAge@13: ToggleDropDownMenu(1, nil, settingsMenu, frame, 10, 0) ShadowTheAge@12: end