Mercurial > wow > crossrealmassist
changeset 11:421508c17712
Started implementing new interface
| author | ShadowTheAge |
|---|---|
| date | Tue, 10 Mar 2015 00:16:23 +0300 |
| parents | d1f39eeb8169 |
| children | 0deef890ec99 |
| files | CrossRealmAssist.lua |
| diffstat | 1 files changed, 142 insertions(+), 100 deletions(-) [+] |
line wrap: on
line diff
--- a/CrossRealmAssist.lua Wed Mar 04 23:00:59 2015 +0300 +++ b/CrossRealmAssist.lua Tue Mar 10 00:16:23 2015 +0300 @@ -3,8 +3,9 @@ local addon = CrossRealmAssist; local wholib = LibStub:GetLibrary('LibWho-2.0'):Library() -local hgroup, lfgContainer, currealm, partyrealm, recrealm, curRealmStat, homeRealm, realmSep, gui, leavebtn +local homeRealm, realmSep, gui, btRefresh, btQuick, btManual, lbRealm, lbStatus, playerName +local curRealmStat local scanstate=0 local recentRealms={} local active=false @@ -21,8 +22,37 @@ local curLfgGroup local sheduledScan local wasInGroup +local wasInInstance local lfgScanInProgress=false +local function setupWidget(widget, parameters, x, y) + if parameters then + for key,value in pairs(parameters) do widget[key](widget,value) end + end + if y then + widget:SetPoint("TOPLEFT",widget:GetParent(),"TOPLEFT",x,-y) + end + return widget +end + +local function ShowTooltip(widget) + GameTooltip:SetOwner(widget, widget.TooltipAnchor) + GameTooltip:ClearLines() + widget:TooltipFactory() + GameTooltip:Show() +end + +local function HideTooltip(widget) + GameTooltip:Hide() +end + +local function setupTooltip(widget, anchor, factory) + widget.TooltipAnchor = anchor; + widget.TooltipFactory = factory; + widget:SetScript("OnEnter", ShowTooltip) + widget:SetScript("OnLeave", HideTooltip) +end + function addon:OnInitialize() end @@ -35,9 +65,12 @@ table.insert(lfgTabs,{value=cat,text=(C_LFGList.GetCategoryInfo(cat))}) end realmSep = _G.REALM_SEPARATORS + playerName = UnitName("player") homeRealm = GetRealmName() addon:RegisterChatCommand("cra", "Activate") addon:RegisterChatCommand("crossrealmassist", "Activate") + + addon:ScheduleTimer("Activate", 0.5) end function addon:OnDisable() @@ -48,13 +81,16 @@ if active then return end active=true wasInGroup = IsInGroup() - addon:CreateUI() - addon:ScanRealm() - addon:RegisterEvent("ZONE_CHANGED_NEW_AREA", "SheduleScan") - addon:RegisterEvent("LFG_LIST_SEARCH_RESULTS_RECEIVED", "LfgResponseData") - addon:RegisterEvent("LFG_LIST_SEARCH_FAILED", "LfgScanFailed") - addon:RegisterEvent("GROUP_ROSTER_UPDATE", "updatePartyInfo") - addon:RegisterEvent("LFG_LIST_APPLICATION_STATUS_UPDATED", "updateAppStatus") + if not gui then addon:CreateUI() end + addon:updateCurrentRealm(); + addon:ForceRefreshZone(); + gui:Show() + addon:RegisterEvent("ZONE_CHANGED_NEW_AREA", "ForceRefreshZone") + addon:RegisterEvent("SCENARIO_UPDATE", "ForceRefreshZone") + --addon:RegisterEvent("LFG_LIST_SEARCH_RESULTS_RECEIVED", "LfgResponseData") + --addon:RegisterEvent("LFG_LIST_SEARCH_FAILED", "LfgScanFailed") + --addon:RegisterEvent("GROUP_ROSTER_UPDATE", "updatePartyInfo") + --addon:RegisterEvent("LFG_LIST_APPLICATION_STATUS_UPDATED", "updateAppStatus") end function addon:Deactivate() @@ -62,8 +98,6 @@ active = false scanstate = 0 lfgScanInProgress = false - gui:Release(); - gui, lfgContainer, hgroup, currealm, partyrealm, recrealm, leavebtn = nil,nil,nil,nil,nil,nil,nil addon:UnregisterEvent("ZONE_CHANGED_NEW_AREA") addon:UnregisterEvent("PLAYER_REGEN_ENABLED") addon:UnregisterEvent("LFG_LIST_SEARCH_RESULTS_RECEIVED") @@ -72,8 +106,37 @@ addon:UnregisterEvent("LFG_LIST_APPLICATION_STATUS_UPDATED") end +function addon:SetStatus(status) + if status then + lbStatus:SetText(status) + else + lbStatus:SetText("") -- TODO + end +end + function addon:CreateUI() - gui = addon:AddUI(nil,"Window",{SetTitle="Cross Realm Assist",EnableResize=false,SetLayout="Flow"},true,{OnClose=addon.Deactivate}) + gui = setupWidget(CreateFrame("Frame",nil,nil,"InsetFrameTemplate3"), {SetFrameStrata="DIALOG",SetWidth=208,SetHeight=60,EnableMouse=true,SetMovable=true}) + local title = setupWidget(CreateFrame("Frame",nil,gui), {SetWidth=190,SetHeight=18,EnableMouse=true,RegisterForDrag="LeftButton"}, 0, 6); + title:SetScript("OnDragStart", function() gui:StartMoving() end) + title:SetScript("OnDragStop", function() gui:StopMovingOrSizing() end) + gui:SetScript("OnHide", addon.Deactivate) + setupTooltip(title, "ANCHOR_TOP", addon.realmToolip) + + lbRealm = setupWidget(gui:CreateFontString(nil,"BACKGROUND", "GameFontNormal"), {SetWidth=200,SetHeight=18}, 0, 6) + lbStatus = setupWidget(gui:CreateFontString(nil,"BACKGROUND", "GameFontHighlightSmallLeft"), {SetWidth=200,SetHeight=10}, 6, 23) + + btQuick = setupWidget(CreateFrame("Button",nil,gui,"UIMenuButtonStretchTemplate"),{EnableMouse=true,SetWidth=90,SetHeight=20,SetText="Quick join"},4,36) + btManual = setupWidget(CreateFrame("Button",nil,gui,"UIMenuButtonStretchTemplate"),{EnableMouse=true,SetWidth=90,SetHeight=20,SetText="Manual join"},94,36) + setupWidget(CreateFrame("Button",nil,gui,"UIPanelCloseButton"),{EnableMouse=true,SetWidth=20,SetHeight=20},188,0) + + btRefresh = setupWidget(CreateFrame("Button",nil,gui,"UIPanelSquareButton"),{EnableMouse=true,SetWidth=20,SetHeight=20},184,36) + btRefresh.icon:SetTexture("Interface/BUTTONS/UI-RefreshButton") + btRefresh.icon:SetTexCoord(0,1,0,1); + btRefresh:SetScript("OnClick",addon.RefreshZone) + + gui:SetPoint("CENTER",0,0) + + --[[gui = addon:AddUI(nil,"Window",{SetTitle="Cross Realm Assist",EnableResize=false,SetLayout="Flow"},true,{OnClose=addon.Deactivate}) local tabgroup = addon:AddUI(gui,"TabGroup",{SetFullHeight=true,SetTabs=lfgTabs,SetLayout="Fill"},true,{OnGroupSelected=addon.LfgScan}) tabgroup:SelectTab(lfgGroups[1]) @@ -103,12 +166,12 @@ if curRealmStat then addon:updateCurrentRealm() end addon:updatePartyInfo() - addon:updateRecentRealms() + addon:updateRecentRealms()]] end -- LFG scanning routine -function addon.refreshLfgCurrent() +--[[function addon.refreshLfgCurrent() addon.LfgScan(nil,nil,curLfgGroup) end @@ -243,7 +306,7 @@ if status == "invited" then LFGListInviteDialog_Accept(LFGListInviteDialog) end -end +end]] -- Zone scanning routine @@ -253,16 +316,37 @@ addon:ScanRealm(); end +function addon:ForceRefreshZone() + addon:RefreshZone(true) +end + +function addon:RefreshZone(shedule) + local inst, instType = IsInInstance() + if (inst or instType ~= "none") then + lbRealm:SetText("Instanced zone") + curRealmStat = nil + btQuick:Disable() + else + btQuick:Enable() + if scanstate == 0 then + addon:ScanRealm() + elseif shedule == true and scanstate == 2 then + addon:SetStatus("Rescan sheduled...") + scanstate = 3 + end + end +end + function addon:ScanRealm() if scanstate > 0 then return end if InCombatLockdown() then addon:RegisterEvent("PLAYER_REGEN_ENABLED","LeaveCombat") scanstate = 1 - addon:AddLabel(currealm, "Scan sheduled after combat...", 3); + addon:SetStatus("Scan sheduled after combat..."); return end scanstate = 2 - addon:AddLabel(currealm, "Scanning...", 3); + addon:SetStatus("Scanning current realm..."); local searchString = _G.WHO_TAG_ZONE .. '"' .. GetZoneText() .. '"'; wholib:Who(searchString, {callback = "ScanResult", handler=addon}) end @@ -273,6 +357,7 @@ addon:AddRealmStat(player.Name, realms); end curRealmStat = addon:GetRealmStat(realms); + curRealmStat.complete = complete addon:updateCurrentRealm(); local rescan = scanstate == 3 scanstate = 0; @@ -280,7 +365,8 @@ end function addon:AddRealmStat(name, realms) - local _, realm = strsplit(realmSep, name) -- TODO exclude self + if (name == playerName) then return end + local _, realm = strsplit(realmSep, name) realm = realm or homeRealm realms[realm] = (realms[realm] or 0) + 1 end @@ -312,33 +398,51 @@ end function addon:updateCurrentRealm() - if not currealm then return end - currealm:ReleaseChildren() - if curRealmStat.players < 5 then - addon:AddLabel(currealm, "Not enough players", 0); + addon:SetStatus(); + if not curRealmStat or curRealmStat.realms < 1 then + lbRealm:SetText("Unknown realm (No players)") + return; end - local sureplayers = curRealmStat.players/2 - local maybeplayers = math.max(curRealmStat.max/4, 3) - local recentRealmUpdated = false - for i=1,curRealmStat.realms do + + local bestRealm = curRealmStat[1] + local prevThreshold = math.min(bestRealm.count/3,5) + local mixCount = 0 + for i=2,curRealmStat.realms do local data = curRealmStat[i] - if data.count >= maybeplayers then - local realm = data.realm - local rvalue = (data.count >= sureplayers) and 4 or 2 - if (rvalue > (recentRealms[realm] or 0)) then - recentRealmUpdated = true - recentRealms[realm] = rvalue - end + if data.count >= prevThreshold then + mixCount = mixCount + 1 + prevThreshold = math.min(data.count/3,5) end end - addon:addLabels(currealm, curRealmStat, sureplayers, maybeplayers, 3, "Realm unknown"); - if recentRealmUpdated then - addon:UpdateCurrentLfgInfo() - addon:updateRecentRealms() + curRealmStat.threshold = prevThreshold + + if (mixCount > 0) then + lbRealm:SetText("Mixed "..bestRealm.realm.." +"..mixCount) + else + lbRealm:SetText(bestRealm.realm) end end -function addon:addLabels(container, stats, epict, whitet, grayt, emptytext) +function addon:realmToolip() + if not curRealmStat then return end + local players = curRealmStat.players; + local threshold = curRealmStat.threshold + GameTooltip:AddLine("Players in zone: "..players) + if not curRealmStat.complete then + GameTooltip:AppendText("+") + end + for i=1,curRealmStat.realms do + local data = curRealmStat[i] + local percent = math.ceil(100 * data.count / players - 0.5) .. "%"; + if data.count >= threshold then + GameTooltip:AddDoubleLine(data.realm, percent, 0,1,0,0,1,0) + else + GameTooltip:AddDoubleLine(data.realm, percent, 0.5,0.5,0.5,0.5,0.5,0.5) + end + end +end + +--[[function addon:addLabels(container, stats, epict, whitet, grayt, emptytext) if stats.realms == 0 then addon:AddLabel(container, emptytext) else @@ -382,14 +486,6 @@ addon:updateRecentRealms() end -function addon:SheduleScan() - if scanstate == 0 then - addon:ScanRealm() - elseif scanstate == 2 then - scanstate = 3 - end -end - function addon:updatePartyInfo() if not partyrealm then return end partyrealm:ReleaseChildren() @@ -414,59 +510,4 @@ end local partyStat = addon:GetRealmStat(realms); addon:addLabels(partyrealm, partyStat, partyStat.players/2, 2, 0, "Not in party"); -end - --- Utils functions - -function addon:AddUI(owner, type, parameters, manual, callbacks) - local ui = AceGUI:Create(type) - if parameters then - for key,value in pairs(parameters) do ui[key](ui,value) end - end - if callbacks then - for key,value in pairs(callbacks) do ui:SetCallback(key,value) end - end - if not manual then ui:SetFullWidth(true) end - if owner then owner:AddChild(ui) end - return ui -end - -function addon:AddLabel(owner, text, color, icon) - local label = AceGUI:Create("Label") - label:SetText(text) - label:SetFullWidth(true) - if color ~= nil then - local r,g,b = GetItemQualityColor(color); - label:SetColor(r,g,b) - end - owner:AddChild(label) - return label -end - -function addon:AddIcon(owner, image, size, visible, tooltip) - if visible ~= false then - local icon = addon:AddUI(owner,"Icon",{SetWidth=size,SetHeight=size},true) - icon:SetImage(image) - icon:SetImageSize(size,size) - if tooltip then - icon:SetUserData('tooltip',tooltip) - icon:SetCallback("OnEnter",addon.ShowTooltip) - icon:SetCallback("OnLeave",addon.HideTooltip) - end - else -- add placeholder - addon:AddUI(owner,"Label",{SetWidth=size,SetHeight=size},true) - end -end - -function addon.ShowTooltip(widget) - GameTooltip:SetOwner(widget.frame, "ANCHOR_TOP") - local tooltip = widget:GetUserData('tooltip') - for i=1,#tooltip do - GameTooltip:AddLine(tooltip[i], 1, 1, 1) - end - GameTooltip:Show() -end - -function addon.HideTooltip(widget) - GameTooltip:Hide() -end \ No newline at end of file +end]] \ No newline at end of file
