diff --git a/api/options-zbuttons.lua b/api/options-zbuttons.lua index e7cbad6..7d2a048 100644 --- a/api/options-zbuttons.lua +++ b/api/options-zbuttons.lua @@ -303,6 +303,13 @@ local function MTH_ZB_EnsureButtonOptionDefaults(buttonName) saved["showammoname"] = saved["showammoname"] and true or false end + if buttonName == "zButtonTrap" then + if saved["cooldown"] == nil then + saved["cooldown"] = true + end + saved["cooldown"] = saved["cooldown"] and true or false + end + return saved end @@ -557,6 +564,18 @@ local function MTH_SetupButtonOptions(containerName, buttonName, displayName, ma buttonObj.tooltip = saved["tooltip"] and true or false end + if buttonName == "zButtonTrap" then + childrenBox:Checkbox(containerName.."ShowCooldown", MTH_ZB_L("ZB_LABEL_SHOW_TRAP_COOLDOWN", "Show cooldown"), { + checked = saved["cooldown"] and true or false, + onClick = function() + if not this then return end + local checked = this:GetChecked() == 1 + if not (ZHunterMod_Saved and ZHunterMod_Saved[buttonName]) then return end + ZHunterMod_Saved[buttonName]["cooldown"] = checked + end, + }) + end + if buttonName == "zButtonAmmo" then childrenBox:Checkbox(containerName.."ShowAmmoName", MTH_ZB_L("ZB_LABEL_SHOW_AMMO_NAME", "Show ammo name"), { checked = saved["showammoname"], diff --git a/modules/zhunter/zButtonTrap.lua b/modules/zhunter/zButtonTrap.lua index e8c897e..6fef282 100644 --- a/modules/zhunter/zButtonTrap.lua +++ b/modules/zhunter/zButtonTrap.lua @@ -19,6 +19,7 @@ if not root["zButtonTrap"] then root["zButtonTrap"]["children"] = {} root["zButtonTrap"]["children"]["size"] = 36 root["zButtonTrap"]["children"]["hideonclick"] = 1 + root["zButtonTrap"]["cooldown"] = true end ZHunterMod_Trap_Spells = { @@ -55,6 +56,9 @@ local function zButtonTrap_EnsureConfig() if saved["tooltip"] == nil then saved["tooltip"] = 1 end + if saved["cooldown"] == nil then + saved["cooldown"] = true + end if not saved["parent"] then saved["parent"] = {} end @@ -100,6 +104,81 @@ local function zButtonTrap_ApplyRuntimeSettings() zButtonTrap.fadetimer = saved["children"] and tonumber(saved["children"]["fadetimer"]) or 0 end +-- ---- Trap arming-cooldown display (shared trap re-arm, ~15s) --------------- +local MTH_ZH_TrapCD_Frame = nil +local MTH_ZH_TrapCD_Elapsed = 0 + +local function zButtonTrap_EnsureCooldownText(button) + if not button then return nil end + if button._mthCooldownText then return button._mthCooldownText end + local fs = button:CreateFontString(nil, "OVERLAY") + fs:SetFont("Fonts\\FRIZQT__.TTF", 14, "THICKOUTLINE") + fs:SetTextColor(1, 0.92, 0.3, 1) + fs:SetPoint("CENTER", button, "CENTER", 0, 0) + button._mthCooldownText = fs + return fs +end + +local function zButtonTrap_ClearCooldown(button) + if not button then return end + if button._mthCooldownText then button._mthCooldownText:SetText("") end + if button.cooldown and button._mthCdActive then + CooldownFrame_SetTimer(button.cooldown, 0, 0, 0) + button._mthCdActive = nil + button._mthCdStart = nil + button._mthCdDur = nil + end +end + +local function zButtonTrap_UpdateCooldownFor(button) + if not (button and button.id) then + zButtonTrap_ClearCooldown(button) + return + end + local start, duration, enable = GetSpellCooldown(button.id, "spell") + -- Skip the ~1.5s global cooldown; only show the real trap re-arm timer. + if enable == 1 and duration and duration > 1.5 and start and start > 0 then + local remaining = start + duration - GetTime() + if remaining > 0 then + if button.cooldown and (button._mthCdStart ~= start or button._mthCdDur ~= duration) then + CooldownFrame_SetTimer(button.cooldown, start, duration, 1) + button._mthCdStart = start + button._mthCdDur = duration + button._mthCdActive = 1 + end + local fs = zButtonTrap_EnsureCooldownText(button) + if fs then fs:SetText(tostring(math.ceil(remaining))) end + return + end + end + zButtonTrap_ClearCooldown(button) +end + +local function zButtonTrap_CooldownOnUpdate() + MTH_ZH_TrapCD_Elapsed = MTH_ZH_TrapCD_Elapsed + (arg1 or 0) + if MTH_ZH_TrapCD_Elapsed < 0.1 then return end + MTH_ZH_TrapCD_Elapsed = 0 + if not zButtonTrap then return end + local saved = zButtonTrap_GetSaved() + if not saved["cooldown"] then + zButtonTrap_ClearCooldown(zButtonTrap) + for i = 1, (zButtonTrap.count or 0) do + zButtonTrap_ClearCooldown(getglobal("zButtonTrap"..i)) + end + return + end + zButtonTrap_UpdateCooldownFor(zButtonTrap) + for i = 1, (zButtonTrap.count or 0) do + zButtonTrap_UpdateCooldownFor(getglobal("zButtonTrap"..i)) + end +end + +local function zButtonTrap_EnsureCooldownDriver() + if MTH_ZH_TrapCD_Frame then return end + MTH_ZH_TrapCD_Frame = CreateFrame("Frame", "MTH_ZH_TrapCooldownDriver") + MTH_ZH_TrapCD_Frame:SetScript("OnUpdate", zButtonTrap_CooldownOnUpdate) +end + function zButtonTrap_OnLoad() this:RegisterEvent("VARIABLES_LOADED") @@ -148,6 +227,7 @@ function zButtonTrap_CreateButtons() end zButtonTrap.found = ZSpellButton_SetButtons(zButtonTrap, info) zButtonTrap_ApplyRuntimeSettings() + zButtonTrap_EnsureCooldownDriver() end function zButtonTrap_SetupSizeAndPosition()