Skip to content

Commit

Permalink
set button macrotext on creation
Browse files Browse the repository at this point in the history
  • Loading branch information
jordonwow committed Jun 8, 2021
1 parent fcd4fd4 commit ab3e459
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 70 deletions.
32 changes: 9 additions & 23 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,13 @@ exclude_files = {
".luacheckrc",
}
ignore = {
"11./SLASH_.*", -- Setting an undefined (Slash handler) global variable
"11./BINDING_.*", -- Setting an undefined (Keybinding header) global variable
"113/LE_.*", -- Accessing an undefined (Lua ENUM type) global variable
"113/NUM_LE_.*", -- Accessing an undefined (Lua ENUM type) global variable
"211", -- Unused local variable
"211/L", -- Unused local variable "CL"
"211/CL", -- Unused local variable "CL"
"212", -- Unused argument
"213", -- Unused loop variable
-- "231", -- Set but never accessed
"311", -- Value assigned to a local variable is unused
"314", -- Value of a field in a table literal is unused
"42.", -- Shadowing a local variable, an argument, a loop variable.
"43.", -- Shadowing an upvalue, an upvalue argument, an upvalue loop variable.
"542", -- An empty if branch
"11./SLASH_.*",
"211",
"212",
"213",
"311",
"431",
"432",
}

globals = {
Expand All @@ -35,17 +27,11 @@ globals = {
"MiniMapBattlefieldDropDown",
"PLAYER",
"PVPReadyDialog",
"SafeQueue_FindPopup",
"SafeQueue_Hide",
"SafeQueue_OnShow",
"SafeQueue_OnUpdate",
"SafeQueue_PostClick",
"SafeQueue_PreClick",
"SafeQueue_Show",
"SafeQueue_UpdateTimer",
"SafeQueuePopup",
"SecondsToTime",
"StaticPopup_Hide",
"StaticPopup_Visible",
"TOOLTIP_UPDATE_TIME",
"UnitInBattleground",
"WOW_PROJECT_ID",
"WOW_PROJECT_MAINLINE",
Expand Down
77 changes: 36 additions & 41 deletions SafeQueue.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ local PLAYER = PLAYER
local PVPReadyDialog = PVPReadyDialog
local SecondsToTime = SecondsToTime
local StaticPopup_Visible = StaticPopup_Visible
local TOOLTIP_UPDATE_TIME = TOOLTIP_UPDATE_TIME
local UnitInBattleground = UnitInBattleground
local hooksecurefunc = hooksecurefunc

local SafeQueue = CreateFrame("Frame", "SafeQueue")
SafeQueue:SetScript("OnEvent", function(self, event, ...) self[event](self, ...) end)
SafeQueue:RegisterEvent("UPDATE_BATTLEFIELD_STATUS")
SafeQueue.timer = TOOLTIP_UPDATE_TIME

local EXPIRES_FORMAT = (WOW_PROJECT_ID == WOW_PROJECT_MAINLINE and "Expires in " or "SafeQueue expires in ") ..
"|cf%s%s|r"
Expand All @@ -45,10 +47,14 @@ local function GetTimerText(battlefieldId)
end

if WOW_PROJECT_ID == WOW_PROJECT_MAINLINE then
SafeQueue:SetScript("OnUpdate", function()
if PVPReadyDialog:IsShown() and PVPReadyDialog.activeIndex then
SafeQueue:SetScript("OnUpdate", function(self, elapsed)
if (not PVPReadyDialog:IsShown()) or (not PVPReadyDialog.activeIndex) then return end
local timer = self.timer
timer = timer - elapsed
if timer <= 0 then
PVPReadyDialog.label:SetText(GetTimerText(PVPReadyDialog.activeIndex))
end
self.timer = timer
end)

hooksecurefunc("PVPReadyDialog_Display", function(self)
Expand All @@ -68,71 +74,60 @@ else
SafeQueue.popup = SafeQueuePopup
SafeQueue:RegisterEvent("PLAYER_REGEN_ENABLED")

function SafeQueue_OnShow(self)
self.text:SetText(GetTimerText(self.battlefieldId))
self.SubText:SetText(self.battleground)
local color = COLORS[self.battleground]
if color then self.SubText:SetTextColor(color.r, color.g, color.b) end
end

function SafeQueue:Create(battlefieldId)
if SafeQueue:FindPopup(battlefieldId) then return end
local status, battleground = GetBattlefieldStatus(battlefieldId)
if status ~= "confirm" then return end
if InCombatLockdown() then
self.createPopup = battlefieldId
return
end
self.createPopup = nil
if StaticPopup_Visible("CONFIRM_BATTLEFIELD_ENTRY") then
StaticPopup_Hide("CONFIRM_BATTLEFIELD_ENTRY")
end
self.createPopup = nil
self.popup.hidePopup = nil
self.popup.battleground = battleground
self.popup.battlefieldId = battlefieldId
self.popup.text:SetText(GetTimerText(battlefieldId))
self.popup.SubText:SetText(battleground)
local color = COLORS[battleground]
if color then self.popup.SubText:SetTextColor(color.r, color.g, color.b) end
self.popup.EnterButton:SetAttribute("macrotext", "/click MiniMapBattlefieldFrame RightButton\n" ..
"/click DropDownList1Button" .. ((battlefieldId * 3) - 1))
self.popup:Show()
end

function SafeQueue:FindPopup(battlefieldId)
if self.popup:IsVisible() and self.popup.battlefieldId == battlefieldId then
return self.popup
end
end

function SafeQueue:PLAYER_REGEN_ENABLED()
if self.popup.hidePopup then self.popup:Hide() end
if self.createPopup then self:Create(self.createPopup) end
end

function SafeQueue_OnUpdate(self, elapsed)
if (not self:IsVisible()) then return end
SafeQueue:SetScript("OnUpdate", function(self, elapsed)
local popup = self.popup
if (not popup:IsVisible()) then return end
local timer = self.timer
timer = timer - elapsed
if timer <= 0 then
if (not self.battlefieldId) or GetBattlefieldStatus(self.battlefieldId) ~= "confirm" then
self:Hide()
if (not popup.battlefieldId) or GetBattlefieldStatus(popup.battlefieldId) ~= "confirm" then
popup:Hide()
return
end
self.text:SetText(GetTimerText(self.battlefieldId))
popup.text:SetText(GetTimerText(popup.battlefieldId))
end
self.timer = timer
end

local function GetButtonNameById(id)
local n
if WOW_PROJECT_ID == WOW_PROJECT_MAINLINE then
n = id * 2
else
n = (id * 3) - 1
end
return "DropDownList1Button" .. n
end

function SafeQueue_PreClick(self)
if InCombatLockdown() then return end
self:SetAttribute("macrotext", "")
if UnitInBattleground(PLAYER) then return end
local id = self:GetParent().battlefieldId
if (not id) then return end
local button = "DropDownList1Button" .. GetButtonNameById(id)
self:SetAttribute("macrotext", "/click MiniMapBattlefieldFrame RightButton\n/click " .. GetButtonNameById(id))
end
end)

hooksecurefunc("StaticPopup_Show", function(name)
if name == "CONFIRM_BATTLEFIELD_ENTRY" and (not InCombatLockdown()) then
StaticPopup_Hide(name)
end
hooksecurefunc("StaticPopup_Show", function(name, _, _, i)
if name ~= "CONFIRM_BATTLEFIELD_ENTRY" then return end
if InCombatLockdown() and (not SafeQueue:FindPopup(i)) then return end
StaticPopup_Hide(name)
end)
end

Expand All @@ -144,7 +139,7 @@ end

function SafeQueue:UPDATE_BATTLEFIELD_STATUS()
for i = 1, GetMaxBattlefieldID() do
local popup = SafeQueue_FindPopup and SafeQueue_FindPopup(i)
local popup = SafeQueue.FindPopup and SafeQueue:FindPopup(i)
local status = GetBattlefieldStatus(i)
if status == "confirm" then
if self.queues[i] then
Expand Down
2 changes: 1 addition & 1 deletion SafeQueue.toc
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
## X-Wago-ID: 0mKOq1Nx
## X-WoWI-ID: 19494

SafeQueue.lua
SafeQueue.xml
SafeQueue.lua
11 changes: 6 additions & 5 deletions SafeQueue.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
</Size>
<Scripts>
<OnLoad>
if WOW_PROJECT_ID == WOW_PROJECT_MAINLINE then return end
self.timer = TOOLTIP_UPDATE_TIME
local BACKDROP_DIALOG_32_32 = BACKDROP_DIALOG_32_32 or {
bgFile = [[Interface\DialogFrame\UI-DialogBox-Background]],
edgeFile = [[Interface\DialogFrame\UI-DialogBox-Border]],
Expand All @@ -18,13 +16,15 @@
}
if BackdropTemplateMixin then Mixin(self, BackdropTemplateMixin) end
self:SetBackdrop(BACKDROP_DIALOG_32_32)
self:SetScript("OnUpdate", SafeQueue_OnUpdate)
self:SetScript("OnShow", SafeQueue_OnShow)
self.EnterButton:SetScript("PreClick", SafeQueue_PreClick)
</OnLoad>
<OnHide>
if InCombatLockdown() then
self.hidePopup = true
return
end
self.battleground = nil
self.battlefieldId = nil
self.EnterButton:SetAttribute("macrotext", "")
</OnHide>
</Scripts>
<Layers>
Expand Down Expand Up @@ -78,3 +78,4 @@
<Anchor point="TOP" x="0" y="-135"/>
</Anchors>
</Frame>
</Ui>

0 comments on commit ab3e459

Please sign in to comment.