Unify all option panels through MTH_Layout engine

Add reusable MTH_Layout box/column layout engine (api/options-layout.lua) and route every option panel through it (shell, general, zButtons per-button config, zBar, chronometer, auto buy, profiles, credits, etc.) for consistent, auto-sizing layout. Restore realm gate. README note.
This commit is contained in:
DuvelCorp
2026-09-10 23:59:37 +02:00
parent adb21c336c
commit ccf9d8b0b6
16 changed files with 1770 additions and 1861 deletions
+138 -250
View File
@@ -15,16 +15,7 @@ local function MTH_EA_OPT_GetCfg()
return MTH_SavedVariables.modules["expammo"] or {}
end
local MTH_EA_OPT_built = false
local MTH_EA_OPT_STATE = { bindStatus = nil, bindButton = nil, captureFrame = nil }
-- ── Layout constants ──────────────────────────────────────────
-- Two equal columns separated by a gutter. Values are offsets from the
-- container TOPLEFT corner (positive X right, negative Y down).
local OPT_L = 20 -- left column X
local OPT_R = 300 -- right column X
local OPT_CW = 255 -- column width (used for text wrapping and sliders)
local function MTH_EA_OPT_GetBindText()
if not GetBindingKey then return "Unbound" end
local k1, k2 = GetBindingKey("EXPAMMO ACTION")
@@ -119,271 +110,168 @@ local function MTH_EA_OPT_StartCapture()
if bb then bb:SetText("Press key...") end
end
-- Helper: checkbox anchored to a given X column
local function MTH_EA_OPT_CB(container, name, label, yOff, xOff, isChecked, onClick)
local cb = MTH_CreateCheckbox(container, name, label, yOff, xOff or OPT_L)
if cb then
cb:SetChecked(isChecked and 1 or 0)
cb:SetScript("OnClick", function()
local v = this:GetChecked()
onClick(v == 1 or v == true)
end)
end
return cb
end
-- Helper: section header label
local function MTH_EA_OPT_Header(container, text, yOff, xOff)
local fs = container:CreateFontString(nil, "ARTWORK", "GameFontNormal")
fs:SetPoint("TOPLEFT", container, "TOPLEFT", xOff or OPT_L, yOff)
fs:SetText("|cffff9900" .. text .. "|r")
return fs
end
-- Helper: small descriptive text
local function MTH_EA_OPT_Tip(container, text, yOff, xOff, r, g, b)
local fs = container:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
fs:SetPoint("TOPLEFT", container, "TOPLEFT", xOff or OPT_L, yOff)
fs:SetWidth(OPT_CW)
fs:SetJustifyH("LEFT")
fs:SetTextColor(r or 0.6, g or 0.6, b or 0.6)
fs:SetText(text)
return fs
end
-- Enable or disable a list of widgets (supports Frames/Buttons and FontStrings)
local function MTH_EA_OPT_SetGroupEnabled(widgets, enabled)
for _, w in ipairs(widgets) do
if w then
if w.Enable and w.Disable then
-- Frame / Button / CheckButton
if enabled then w:Enable() else w:Disable() end
end
-- Dim all (including FontStrings and frames) via alpha
if w.SetAlpha then
w:SetAlpha(enabled and 1.0 or 0.35)
end
end
end
end
local function MTH_EA_OPT_BuildUI(container)
if MTH_EA_OPT_built then return end
MTH_EA_OPT_built = true
local cfg = MTH_EA_OPT_GetCfg()
local showHint = cfg.showHint ~= false
---------------------------------------------------------------------------
-- Title
---------------------------------------------------------------------------
local title = container:CreateFontString(nil, "ARTWORK", "GameFontHighlightLarge")
title:SetPoint("TOPLEFT", container, "TOPLEFT", OPT_L, -16)
title:SetText("MM Widget — Experimental Ammunition Tracker")
local panel = MTH_Layout.Panel(container)
panel:Title("MM Widget — Experimental Ammunition Tracker")
---------------------------------------------------------------------------
-- LEFT COLUMN
---------------------------------------------------------------------------
-- ── Module ──────────────────────────────────────────────
MTH_EA_OPT_Header(container, "Module", -46)
-- Right-column gating: dim the box frames and disable their interactive
-- controls when the "Show action hint cell" checkbox is off.
local rightBoxes = {}
local rightControls = {}
local function setRightEnabled(enabled)
local i
for i = 1, table.getn(rightBoxes) do
local f = rightBoxes[i]
if f and f.SetAlpha then f:SetAlpha(enabled and 1.0 or 0.35) end
end
for i = 1, table.getn(rightControls) do
local c = rightControls[i]
if c and c.Enable and c.Disable then
if enabled then c:Enable() else c:Disable() end
end
end
end
-- ===== LEFT: Module =====
local moduleBox = panel:Box("left", "MTH_ExpAmmoModuleBox", "Module")
local moduleEnabled = true
if MTH and MTH.IsModuleEnabled then
moduleEnabled = MTH:IsModuleEnabled("expammo", true) and true or false
end
MTH_EA_OPT_CB(container, "MTH_ExpAmmoModuleCB",
"Enable MM Widget module",
-66, OPT_L, moduleEnabled,
function(v)
moduleBox:Checkbox("MTH_ExpAmmoModuleCB", "Enable MM Widget module", {
checked = moduleEnabled,
onClick = function()
local v = this:GetChecked() == 1
if MTH and MTH.SetModuleEnabled then MTH:SetModuleEnabled("expammo", v) end
if MTH_ExpAmmo then MTH_ExpAmmo.SetEnabled(v) end
end)
end,
})
-- ── Tracker Visibility ───────────────────────────────────
MTH_EA_OPT_Header(container, "Tracker Visibility", -100)
MTH_EA_OPT_CB(container, "MTH_ExpAmmoShowLnLCB",
"Show Lock and Load cell (top)",
-120, OPT_L, cfg.showLnL ~= false,
function(v) if MTH_ExpAmmo then MTH_ExpAmmo.SetShowLnL(v) end end)
-- "Show action hint cell" also gates the right column
local rightGroup = {} -- filled below; toggled when this CB changes
local showHintCB = MTH_EA_OPT_CB(container, "MTH_ExpAmmoShowHintCB",
"Show action hint cell (bottom)",
-144, OPT_L, showHint,
function(v)
-- ===== LEFT: Tracker Visibility =====
local visBox = panel:Box("left", "MTH_ExpAmmoVisBox", "Tracker Visibility")
visBox:Checkbox("MTH_ExpAmmoShowLnLCB", "Show Lock and Load cell (top)", {
checked = cfg.showLnL ~= false,
onClick = function() if MTH_ExpAmmo then MTH_ExpAmmo.SetShowLnL(this:GetChecked() == 1) end end,
})
visBox:Checkbox("MTH_ExpAmmoShowHintCB", "Show action hint cell (bottom)", {
checked = showHint,
onClick = function()
local v = this:GetChecked() == 1
if MTH_ExpAmmo then MTH_ExpAmmo.SetShowHint(v) end
MTH_EA_OPT_SetGroupEnabled(rightGroup, v)
end)
setRightEnabled(v)
end,
})
visBox:Checkbox("MTH_ExpAmmoHideOOCCB", "Hide widget when out of combat", {
checked = cfg.hideOOC == true,
onClick = function() if MTH_ExpAmmo then MTH_ExpAmmo.SetHideOOC(this:GetChecked() == 1) end end,
})
MTH_EA_OPT_CB(container, "MTH_ExpAmmoHideOOCCB",
"Hide widget when out of combat",
-168, OPT_L, cfg.hideOOC == true,
function(v) if MTH_ExpAmmo then MTH_ExpAmmo.SetHideOOC(v) end end)
-- ===== LEFT: Appearance =====
local appBox = panel:Box("left", "MTH_ExpAmmoAppBox", "Appearance")
appBox:Slider("MTH_ExpAmmoCellSizeSlider", {
label = "Cell Size (px)", min = 20, max = 80, step = 4,
value = math.max(20, math.min(80, cfg.cellSize or 40)),
onChange = function(val) if MTH_ExpAmmo then MTH_ExpAmmo.SetCellSize(val) end end,
})
appBox:Slider("MTH_ExpAmmoCellGapSlider", {
label = "Cell Spacing (px)", min = 0, max = 20, step = 1,
value = math.max(0, math.min(20, cfg.cellGap or 2)),
onChange = function(val) if MTH_ExpAmmo then MTH_ExpAmmo.SetCellGap(val) end end,
})
appBox:Checkbox("MTH_ExpAmmoBigCDCB", "Large cooldown numbers (centered in cell)", {
checked = cfg.bigCD == true,
onClick = function() if MTH_ExpAmmo then MTH_ExpAmmo.SetBigCD(this:GetChecked() == 1) end end,
})
-- ── Appearance ───────────────────────────────────────────
MTH_EA_OPT_Header(container, "Appearance", -202)
local sizeSlider = MTH_CreateSlider(container, "MTH_ExpAmmoCellSizeSlider",
"Cell Size (px)", 20, 80, 4, -222)
if sizeSlider then
sizeSlider:ClearAllPoints()
sizeSlider:SetPoint("TOPLEFT", container, "TOPLEFT", OPT_L + 5, -222)
sizeSlider:SetWidth(OPT_CW - 10)
sizeSlider:SetValue(math.max(20, math.min(80, cfg.cellSize or 40)))
sizeSlider.onChange = function(val)
if MTH_ExpAmmo then MTH_ExpAmmo.SetCellSize(val) end
end
end
local gapSlider = MTH_CreateSlider(container, "MTH_ExpAmmoCellGapSlider",
"Cell Spacing (px)", 0, 20, 1, -286)
if gapSlider then
gapSlider:ClearAllPoints()
gapSlider:SetPoint("TOPLEFT", container, "TOPLEFT", OPT_L + 5, -286)
gapSlider:SetWidth(OPT_CW - 10)
gapSlider:SetValue(math.max(0, math.min(20, cfg.cellGap or 2)))
gapSlider.onChange = function(val)
if MTH_ExpAmmo then MTH_ExpAmmo.SetCellGap(val) end
end
end
MTH_EA_OPT_CB(container, "MTH_ExpAmmoBigCDCB",
"Large cooldown numbers (centered in cell)",
-350, OPT_L, cfg.bigCD == true,
function(v) if MTH_ExpAmmo then MTH_ExpAmmo.SetBigCD(v) end end)
-- ── Position ─────────────────────────────────────────────
MTH_EA_OPT_Header(container, "Position", -390)
local anchorButton = MTH_CreateActionButton(container, "MTH_ExpAmmoToggleAnchor",
"Toggle Anchor", OPT_L, -410, 130, 22, function()
if MTH_ExpAmmo then MTH_ExpAmmo.ToggleAnchor() end
end)
if anchorButton then anchorButton:Show() end
MTH_EA_OPT_Tip(container,
-- ===== LEFT: Position =====
local posBox = panel:Box("left", "MTH_ExpAmmoPosBox", "Position")
posBox:Button("MTH_ExpAmmoToggleAnchor", "Toggle Anchor", {
width = 130,
onClick = function() if MTH_ExpAmmo then MTH_ExpAmmo.ToggleAnchor() end end,
})
posBox:Note("MTH_ExpAmmoPosNote",
"Shows 4 drag handles around the widget (top / bottom / left / right). Drag any one to reposition it.",
-436, OPT_L)
{ color = MTH_Layout.Theme.colText, lines = 3 })
---------------------------------------------------------------------------
-- RIGHT COLUMN — Action Hint Cell (keybind + casting)
-- All widgets here are greyed out when the bottom cell is hidden.
---------------------------------------------------------------------------
-- Vertical divider line
local divider = container:CreateTexture(nil, "BACKGROUND")
divider:SetTexture(0.3, 0.3, 0.3, 0.6)
divider:SetPoint("TOPLEFT", container, "TOPLEFT", OPT_R - 10, -46)
divider:SetPoint("BOTTOMLEFT", container, "TOPLEFT", OPT_R - 10, -530)
divider:SetWidth(1)
-- Column title
local rTitle = container:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
rTitle:SetPoint("TOPLEFT", container, "TOPLEFT", OPT_R, -46)
rTitle:SetText("|cffff9900" .. "Action Hint Cell" .. "|r")
table.insert(rightGroup, rTitle)
local rSubtitle = MTH_EA_OPT_Tip(container,
"Options below apply to the bottom cell only.\n Disable \"Show action hint cell\" to hide the cell and these controls.",
-64, OPT_R, 1.00, 1.00, 1.00)
if rSubtitle then rSubtitle:SetWidth(290) end
table.insert(rightGroup, rSubtitle)
local rNamPowerTip = MTH_EA_OPT_Tip(container,
-- ===== RIGHT: Smart Action Cell (helper + keybind + casting) =====
-- One feature = one box. The intro notes explain the bottom cell, and the
-- Keybind / Casting controls that drive it live underneath as sub-sections.
local cellBox = panel:Box("right", "MTH_ExpAmmoCellBox", "Smart Action Cell")
table.insert(rightBoxes, cellBox:Frame())
cellBox:Text("MTH_ExpAmmoHintSub",
"Options below apply to the bottom cell only. Disable \"Show action hint cell\" to hide the cell and these controls.",
{ color = { 1, 1, 1 }, lines = 3 })
cellBox:Note("MTH_ExpAmmoHintNam",
"Notes:\n - You need NAMPOWER for this to work reliably.\n - Aimed/Steady/Multi/Arcane Shots SHOULD BE on your action bars.",
-100, OPT_R, 0.35, 0.65, 1.00)
if rNamPowerTip then rNamPowerTip:SetWidth(290) end
table.insert(rightGroup, rNamPowerTip)
{ lines = 3 })
-- ── Keybind ──────────────────────────────────────────────
table.insert(rightGroup, MTH_EA_OPT_Header(container, "Keybind", -182, OPT_R))
-- Keybind sub-section
cellBox:Gap(4)
cellBox:Text("MTH_ExpAmmoKeyHead", "Keybind",
{ font = MTH_Layout.Theme.fontBoxTitle, color = MTH_Layout.Theme.colPanelTitle })
cellBox:Note("MTH_ExpAmmoBindTip",
"One key to rule them all.\n Aimed Shot when ready, Steady Shot while Aimed is on cooldown, consume-spell (Multi / Serpent / Arcane) when proc is up.",
{ lines = 4 })
MTH_EA_OPT_STATE.bindStatus = cellBox:Text("MTH_ExpAmmoBindStatus",
"Key: " .. MTH_EA_OPT_GetBindText())
local keyButtons = cellBox:Buttons({
{ name = "MTH_ExpAmmoBindButton", label = "Set Key", width = 90,
onClick = function()
if MTH_EA_OPT_STATE.captureFrame and MTH_EA_OPT_STATE.captureFrame:IsShown() then
MTH_EA_OPT_StopCapture()
else
MTH_EA_OPT_StartCapture()
end
end },
{ name = "MTH_ExpAmmoBindClear", label = "Clear", width = 70,
onClick = function() MTH_EA_OPT_SaveBinding(nil) end },
})
MTH_EA_OPT_STATE.bindButton = keyButtons[1]
table.insert(rightControls, keyButtons[1])
table.insert(rightControls, keyButtons[2])
local bindTip = MTH_EA_OPT_Tip(container,
"One key to rule them all.\n Aimed Shot when ready, Steady Shot while Aimed is on cooldown,\n consume-spell (Multi / Serpent / Arcane) when proc is up.",
-200, OPT_R, 0.65, 0.65, 0.65)
if bindTip then bindTip:SetWidth(290) end
table.insert(rightGroup, bindTip)
-- Casting sub-section
cellBox:Gap(4)
cellBox:Text("MTH_ExpAmmoCastHead", "Casting",
{ font = MTH_Layout.Theme.fontBoxTitle, color = MTH_Layout.Theme.colPanelTitle })
local quiverCB = cellBox:Checkbox("MTH_ExpAmmoQuiverNoClipCB", "Use Quiver no-clip casting", {
checked = cfg.useQuiverNoClip == true,
onClick = function() if MTH_ExpAmmo then MTH_ExpAmmo.SetUseQuiverNoClip(this:GetChecked() == 1) end end,
})
table.insert(rightControls, quiverCB)
cellBox:Note("MTH_ExpAmmoQuiverTip",
"Requires the Quiver addon. Routes Aimed/Steady/Multi cast through Quiver.CastNoClip to avoid clipping your auto-shot swing timer.",
{ lines = 3 })
local bindStatus = container:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
bindStatus:SetPoint("TOPLEFT", container, "TOPLEFT", OPT_R, -248)
bindStatus:SetText("Key: " .. MTH_EA_OPT_GetBindText())
MTH_EA_OPT_STATE.bindStatus = bindStatus
table.insert(rightGroup, bindStatus)
-- ===== RIGHT: Rotation =====
local rotBox = panel:Box("right", "MTH_ExpAmmoRotBox", "Rotation")
table.insert(rightBoxes, rotBox:Frame())
rotBox:Note("MTH_ExpAmmoRotTip",
"Uncheck a shot to permanently skip it during its proc window. The keybind will cast Steady/Aimed instead.",
{ lines = 2 })
local multiCB = rotBox:Checkbox("MTH_ExpAmmoBlockMultiCB", "Multi-Shot (Explosive)", {
checked = cfg.blockExplosive ~= true,
onClick = function() if MTH_ExpAmmo then MTH_ExpAmmo.SetBlockExplosive(not (this:GetChecked() == 1)) end end,
})
table.insert(rightControls, multiCB)
local serpentCB = rotBox:Checkbox("MTH_ExpAmmoBlockSerpentCB", "Serpent Sting (Poisonous)", {
checked = cfg.blockPoisonous ~= true,
onClick = function() if MTH_ExpAmmo then MTH_ExpAmmo.SetBlockPoisonous(not (this:GetChecked() == 1)) end end,
})
table.insert(rightControls, serpentCB)
local arcaneCB = rotBox:Checkbox("MTH_ExpAmmoBlockArcaneCB", "Arcane Shot (Enchanted)", {
checked = cfg.blockEnchanted ~= true,
onClick = function() if MTH_ExpAmmo then MTH_ExpAmmo.SetBlockEnchanted(not (this:GetChecked() == 1)) end end,
})
table.insert(rightControls, arcaneCB)
local bindButton = CreateFrame("Button", "MTH_ExpAmmoBindButton", container, "UIPanelButtonTemplate")
bindButton:SetPoint("TOPLEFT", container, "TOPLEFT", OPT_R, -264)
bindButton:SetWidth(90)
bindButton:SetHeight(22)
bindButton:SetText("Set Key")
bindButton:EnableKeyboard(false)
bindButton:SetScript("OnClick", function()
if MTH_EA_OPT_STATE.captureFrame and MTH_EA_OPT_STATE.captureFrame:IsShown() then
MTH_EA_OPT_StopCapture()
else
MTH_EA_OPT_StartCapture()
end
end)
MTH_EA_OPT_STATE.bindButton = bindButton
table.insert(rightGroup, bindButton)
panel:Finish()
local clearButton = CreateFrame("Button", "MTH_ExpAmmoBindClear", container, "UIPanelButtonTemplate")
clearButton:SetPoint("LEFT", bindButton, "RIGHT", 6, 0)
clearButton:SetWidth(70)
clearButton:SetHeight(22)
clearButton:SetText("Clear")
clearButton:SetScript("OnClick", function()
MTH_EA_OPT_SaveBinding(nil)
end)
table.insert(rightGroup, clearButton)
-- ── Casting ──────────────────────────────────────────────
table.insert(rightGroup, MTH_EA_OPT_Header(container, "Casting", -304, OPT_R))
local quiverCB = MTH_EA_OPT_CB(container, "MTH_ExpAmmoQuiverNoClipCB",
"Use Quiver no-clip casting",
-324, OPT_R, cfg.useQuiverNoClip == true,
function(v) if MTH_ExpAmmo then MTH_ExpAmmo.SetUseQuiverNoClip(v) end end)
table.insert(rightGroup, quiverCB)
local quiverTip = MTH_EA_OPT_Tip(container,
"|cff4d9cffRequires the Quiver addon.|r \n Routes Aimed/Steady/Multi cast through Quiver.CastNoClip \n to avoid clipping your auto-shot swing timer",
-350, OPT_R, 1, 1, 1)
if quiverTip then quiverTip:SetWidth(290) end
table.insert(rightGroup, quiverTip)
-- ── Rotation ─────────────────────────────────────────────
table.insert(rightGroup, MTH_EA_OPT_Header(container, "Rotation", -400, OPT_R))
local rotTip = MTH_EA_OPT_Tip(container,
"Uncheck a shot to permanently skip it during its proc window.\n The keybind will cast Steady/Aimed instead.",
-418, OPT_R, 0.65, 0.65, 0.65)
if rotTip then rotTip:SetWidth(290) end
table.insert(rightGroup, rotTip)
local multiCB = MTH_EA_OPT_CB(container, "MTH_ExpAmmoBlockMultiCB",
"Multi-Shot (Explosive)",
-452, OPT_R, cfg.blockExplosive ~= true,
function(v) if MTH_ExpAmmo then MTH_ExpAmmo.SetBlockExplosive(not v) end end)
table.insert(rightGroup, multiCB)
local serpentCB = MTH_EA_OPT_CB(container, "MTH_ExpAmmoBlockSerpentCB",
"Serpent Sting (Poisonous)",
-476, OPT_R, cfg.blockPoisonous ~= true,
function(v) if MTH_ExpAmmo then MTH_ExpAmmo.SetBlockPoisonous(not v) end end)
table.insert(rightGroup, serpentCB)
local arcaneCB = MTH_EA_OPT_CB(container, "MTH_ExpAmmoBlockArcaneCB",
"Arcane Shot (Enchanted)",
-500, OPT_R, cfg.blockEnchanted ~= true,
function(v) if MTH_ExpAmmo then MTH_ExpAmmo.SetBlockEnchanted(not v) end end)
table.insert(rightGroup, arcaneCB)
-- Apply initial enabled state
MTH_EA_OPT_SetGroupEnabled(rightGroup, showHint)
-- Apply initial gating state.
setRightEnabled(showHint)
end
function MTH_SetupExpAmmoOptions()