Files

144 lines
6.8 KiB
Lua

-- OctoTextSize: addon-local factory; Blizzard CreateFrame is unchanged.
local CreateFrame = OctoTextSize and OctoTextSize.WrapFactory(CreateFrame) or CreateFrame
-- Octo Battlegrounds: Octo's minimap queue menu (FrameXML Minimap.lua BuildTWBGQueueMenu)
-- on the native menu system. Each entry sends TW_BGQueue "<name>"; the server
-- (Tortoise ChatHandler TW_BGQueue) answers with the ordinary battleground list, which
-- the gateway presents natively. Rated arena uses TW_ARENA, which this client does not
-- carry, so only Skirmish ("Arena") is offered under Arena.
local PREFIX = "TW_BGQueue"
local L = {
title = BATTLEFIELDS or "Battlegrounds",
arena = ARENA or "Arena",
skirmish = ARENA_QUEUE_SKIRMISH or "Skirmish",
}
local ENTRIES = {
-- list = BattlemasterList ID the gateway gives the server's battleground list
-- (native/battleground_queue.hpp fields: map 30 -> 1, 489 -> 2, 529 -> 3).
{ key = "Warsong", name = "Warsong Gulch", level = 0, list = 2 },
{ key = "Arathi", name = "Arathi Basin", level = 0, list = 3 },
{ key = "ThornGorge", name = "Thorn Gorge", level = 30 },
{ key = "Alterac", name = "Alterac Valley", level = 51, list = 1 },
}
local function send(payload)
if not C_ChatInfo or type(C_ChatInfo.SendAddonMessage) ~= "function" then return false end
local result = C_ChatInfo.SendAddonMessage(PREFIX, payload, "WHISPER", UnitName("player"))
return result == 0 or result == true
end
local pendingName, pendingList
local function queued()
local result = {}
local count = (type(GetMaxBattlefieldID) == "function" and GetMaxBattlefieldID()) or MAX_BATTLEFIELD_QUEUES or 3
for i = 1, count do
local status, name = GetBattlefieldStatus(i)
if (status == "queued" or status == "confirm" or status == "active") and name then result[name] = true end
end
return result
end
local button = CreateFrame("Button", "OctoBattlegroundsMinimapButton", Minimap)
button:SetSize(31, 31)
button:SetFrameStrata("MEDIUM")
button:SetFrameLevel(Minimap:GetFrameLevel() + 8)
button:SetPoint("TOPLEFT", Minimap, "TOPLEFT", -2, -40)
button:RegisterForClicks("LeftButtonUp", "RightButtonUp")
local icon = button:CreateTexture(nil, "BACKGROUND")
icon:SetSize(20, 20)
icon:SetPoint("TOPLEFT", 7, -5)
local border = button:CreateTexture(nil, "OVERLAY")
border:SetSize(53, 53)
border:SetPoint("TOPLEFT")
border:SetTexture("Interface\\Minimap\\MiniMap-TrackingBorder")
button:SetHighlightTexture("Interface\\Minimap\\UI-Minimap-ZoomButton-Highlight")
local function updateIcon()
local faction = UnitFactionGroup("player")
icon:SetTexture("Interface\\TargetingFrame\\UI-PVP-" .. ((faction == "Alliance" or faction == "Horde") and faction or "FFA"))
icon:SetTexCoord(0.05, 0.6, 0.05, 0.6)
end
button:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_LEFT")
GameTooltip:SetText(L.title, 1, 1, 1)
GameTooltip:Show()
end)
button:SetScript("OnLeave", GameTooltip_Hide)
button:SetScript("OnClick", function(self)
if not MenuUtil or type(MenuUtil.CreateContextMenu) ~= "function" then return end
local inQueue = queued()
local level = UnitLevel("player") or 0
MenuUtil.CreateContextMenu(self, function(_, root)
root:CreateTitle(L.title)
local arena = root:CreateButton(L.arena)
local skirmish = arena:CreateButton(L.skirmish, function() pendingName, pendingList = L.arena .. " - " .. L.skirmish, nil; send("Arena") end)
if inQueue[L.arena] then skirmish:SetEnabled(false) end
for _, entry in ipairs(ENTRIES) do
if level >= entry.level then
local item = root:CreateCheckbox(entry.name,
function() return inQueue[entry.name] == true end,
function() pendingName, pendingList = entry.name, entry.list; send(entry.key) end)
if inQueue[entry.name] then item:SetEnabled(false) end
end
end
end)
end)
-- The server answers TW_BGQueue with its ordinary battleground list, which the client raises
-- as BATTLEFIELDS_SHOW(isArena, battleMasterListID). Camelot loads no stock listener for it,
-- so this prompt is the explicit step that queues: C_PvP.JoinBattlefield is restricted to
-- Blizzard UI code, so Join goes through the gateway's OctoBG control. Picking a menu entry alone never queues.
local prompt = CreateFrame("Frame", nil, UIParent, "ButtonFrameTemplate")
prompt:SetSize(280, 120)
prompt:SetPoint("TOP", UIParent, "TOP", 0, -160)
prompt:SetFrameStrata("DIALOG")
prompt:SetToplevel(true)
prompt:EnableMouse(true)
prompt:Hide()
if ButtonFrameTemplate_HidePortrait then ButtonFrameTemplate_HidePortrait(prompt) end
if prompt.SetTitle then prompt:SetTitle(L.title) end
local promptText = prompt:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
promptText:SetPoint("TOP", prompt, "TOP", 0, -40)
promptText:SetWidth(250)
local join = CreateFrame("Button", nil, prompt, "UIPanelButtonTemplate")
join:SetSize(120, 22)
join:SetPoint("BOTTOMRIGHT", prompt, "BOTTOM", -4, 8)
join:SetText(BATTLEFIELD_JOIN or "Join Battle")
local cancel = CreateFrame("Button", nil, prompt, "UIPanelButtonTemplate")
cancel:SetSize(120, 22)
cancel:SetPoint("BOTTOMLEFT", prompt, "BOTTOM", 4, 8)
cancel:SetText(CANCEL or "Cancel")
cancel:SetScript("OnClick", function() prompt:Hide() end)
join:SetScript("OnClick", function()
local id = prompt.listId
prompt:Hide()
if IsInGroup and IsInGroup() and not UnitIsGroupLeader("player") then
UIErrorsFrame:AddMessage(ERR_NOT_LEADER or "You are not the party leader.", 1, 0.1, 0.1)
return
end
-- C_PvP.JoinBattlefield is restricted to Blizzard UI code on 70334 (live: "blocked from an
-- action only available to the Blizzard UI"). The gateway's OctoBG control sends the client's
-- own join request (native 0x3e002b -> Turtle CMSG_BATTLEFIELD_JOIN) for this list ID.
if id and id >= 1 and id <= 9 and C_ChatInfo and C_ChatInfo.SendAddonMessage then
C_ChatInfo.SendAddonMessage("OctoBG", "J " .. id, "WHISPER", UnitName("player"))
end
end)
local events = CreateFrame("Frame")
events:RegisterEvent("PLAYER_ENTERING_WORLD")
events:RegisterEvent("BATTLEFIELDS_SHOW")
events:RegisterEvent("BATTLEFIELDS_CLOSED")
-- The server answers TW_BGQueue with a list addressed to the player itself; the gateway sends it
-- as a queue-anywhere list, which 70334 raises as PVPQUEUE_ANYWHERE_SHOW (no payload; live LOCAL probe).
events:RegisterEvent("PVPQUEUE_ANYWHERE_SHOW")
events:SetScript("OnEvent", function(_, event, isArena, listId)
if event == "PLAYER_ENTERING_WORLD" then updateIcon(); return end
if event == "BATTLEFIELDS_CLOSED" then prompt:Hide(); return end
if event == "PVPQUEUE_ANYWHERE_SHOW" then isArena, listId = false, pendingList end
if not listId then return end
prompt.listId = listId
promptText:SetText(pendingName or (isArena and L.arena) or L.title)
pendingName, pendingList = nil, nil
prompt:Show()
end)