diff --git a/Modules/Config.lua b/Modules/Config.lua index 443cf68..522c393 100644 --- a/Modules/Config.lua +++ b/Modules/Config.lua @@ -7,16 +7,27 @@ local configFrame = CreateFrame("Frame", "HeimdallConfig", UIParent) ---@diagnostic disable-next-line: missing-fields shared.Config = {} function shared.Config.Init() - ---@class UIElement - shared.UIElement = { - ---@return UIElement - new = function() - local self = setmetatable({}, { - __index = shared.UIElement - }) - return self - end - } + local function PutBelow(a, b) + a:SetPoint("LEFT", b, "LEFT", 0, -24) + end + local function PutRight(a, b) + a:SetPoint("LEFT", b, "LEFT", 128, 0) + end + ---@param name string + ---@param parent Frame + ---@param text string + ---@param onClick function + local function BasicButton(name, parent, text, onClick) + local button = CreateFrame("CheckButton", name, parent, "UICheckButtonTemplate") + button.text = button:CreateFontString(nil, "OVERLAY", "GameFontNormal") + button.text:SetText(text) + button.text:SetPoint("LEFT", button, "RIGHT", 0, 0) + button:SetSize(24, 24) + button:SetScript("OnClick", onClick) + button.PutBelow = PutBelow + button.PutRight = PutRight + return button + end configFrame:SetSize(256 + 256, 512) configFrame:SetPoint("CENTER") @@ -76,65 +87,35 @@ function shared.Config.Init() spotterConfigFrame:SetBackdropColor(0, 0, 0, 0.8) spotterConfigFrame:SetBackdropBorderColor(0.5, 0.5, 0.5, 1) - local spotterEnableButton = CreateFrame("CheckButton", "HeimdallSpotterEnable", spotterConfigFrame, - "UICheckButtonTemplate") - spotterEnableButton.text = spotterEnableButton:CreateFontString(nil, "OVERLAY", "GameFontNormal") - spotterEnableButton.text:SetText("Enable Spotter") - spotterEnableButton.text:SetPoint("LEFT", spotterEnableButton, "RIGHT", 0, 0) - spotterEnableButton:SetSize(24, 24) - spotterEnableButton:SetPoint("TOPLEFT", spotterConfigFrame, "TOPLEFT", 4, -4) - spotterEnableButton:SetChecked(Heimdall_Data.config.spotter.enabled) - spotterEnableButton:SetScript("OnClick", function() + local spotterEnableButton = BasicButton("HeimdallSpotterEnable", spotterConfigFrame, "Enable Spotter", function() Heimdall_Data.config.spotter.enabled = spotterEnableButton:GetChecked() end) + spotterEnableButton:SetPoint("TOPLEFT", spotterConfigFrame, "TOPLEFT", 4, -4) + spotterEnableButton:SetChecked(Heimdall_Data.config.spotter.enabled) - local spotterEveryoneButton = CreateFrame("CheckButton", "HeimdallSpotterEveryone", spotterConfigFrame, - "UICheckButtonTemplate") - spotterEveryoneButton.text = spotterEveryoneButton:CreateFontString(nil, "OVERLAY", "GameFontNormal") - spotterEveryoneButton.text:SetText("Everyone") - spotterEveryoneButton.text:SetPoint("LEFT", spotterEveryoneButton, "RIGHT", 0, 0) - spotterEveryoneButton:SetSize(24, 24) - spotterEveryoneButton:SetPoint("LEFT", spotterEnableButton, "LEFT", 128, 0) - spotterEveryoneButton:SetChecked(Heimdall_Data.config.spotter.everyone) - spotterEveryoneButton:SetScript("OnClick", function() + local spotterEveryoneButton = BasicButton("HeimdallSpotterEveryone", spotterConfigFrame, "Everyone", function() Heimdall_Data.config.spotter.everyone = spotterEveryoneButton:GetChecked() end) + spotterEveryoneButton:PutRight(spotterEnableButton) + spotterEveryoneButton:SetChecked(Heimdall_Data.config.spotter.everyone) - local spotterHostileButton = CreateFrame("CheckButton", "HeimdallSpotterHostile", spotterConfigFrame, - "UICheckButtonTemplate") - spotterHostileButton.text = spotterHostileButton:CreateFontString(nil, "OVERLAY", "GameFontNormal") - spotterHostileButton.text:SetText("Hostile") - spotterHostileButton.text:SetPoint("LEFT", spotterHostileButton, "RIGHT", 0, 0) - spotterHostileButton:SetSize(24, 24) - spotterHostileButton:SetPoint("LEFT", spotterEnableButton, "LEFT", 0, -24) - spotterHostileButton:SetChecked(Heimdall_Data.config.spotter.hostile) - spotterHostileButton:SetScript("OnClick", function() + local spotterHostileButton = BasicButton("HeimdallSpotterHostile", spotterConfigFrame, "Hostile", function() Heimdall_Data.config.spotter.hostile = spotterHostileButton:GetChecked() end) + spotterHostileButton:PutBelow(spotterEnableButton) + spotterHostileButton:SetChecked(Heimdall_Data.config.spotter.hostile) - local spotterAllianceButton = CreateFrame("CheckButton", "HeimdallSpotterAlliance", spotterConfigFrame, - "UICheckButtonTemplate") - spotterAllianceButton.text = spotterAllianceButton:CreateFontString(nil, "OVERLAY", "GameFontNormal") - spotterAllianceButton.text:SetText("Alliance") - spotterAllianceButton.text:SetPoint("LEFT", spotterAllianceButton, "RIGHT", 0, 0) - spotterAllianceButton:SetSize(24, 24) - spotterAllianceButton:SetPoint("LEFT", spotterEveryoneButton, "LEFT", 0, -24) - spotterAllianceButton:SetChecked(Heimdall_Data.config.spotter.alliance) - spotterAllianceButton:SetScript("OnClick", function() + local spotterAllianceButton = BasicButton("HeimdallSpotterAlliance", spotterConfigFrame, "Alliance", function() Heimdall_Data.config.spotter.alliance = spotterAllianceButton:GetChecked() end) + spotterAllianceButton:PutRight(spotterHostileButton) + spotterAllianceButton:SetChecked(Heimdall_Data.config.spotter.alliance) - local spotterStinkyButton = CreateFrame("CheckButton", "HeimdallSpotterStinky", spotterConfigFrame, - "UICheckButtonTemplate") - spotterStinkyButton.text = spotterStinkyButton:CreateFontString(nil, "OVERLAY", "GameFontNormal") - spotterStinkyButton.text:SetText("Stinky") - spotterStinkyButton.text:SetPoint("LEFT", spotterStinkyButton, "RIGHT", 0, 0) - spotterStinkyButton:SetSize(24, 24) - spotterStinkyButton:SetPoint("LEFT", spotterHostileButton, "LEFT", 0, -24) - spotterStinkyButton:SetChecked(Heimdall_Data.config.spotter.stinky) - spotterStinkyButton:SetScript("OnClick", function() + local spotterStinkyButton = BasicButton("HeimdallSpotterStinky", spotterConfigFrame, "Stinky", function() Heimdall_Data.config.spotter.stinky = spotterStinkyButton:GetChecked() end) + spotterStinkyButton:PutBelow(spotterHostileButton) + spotterStinkyButton:SetChecked(Heimdall_Data.config.spotter.stinky) local spotterThrottleBox = CreateFrame("EditBox", "HeimdallSpotterThrottle", configFrame) spotterThrottleBox.text = spotterThrottleBox:CreateFontString(nil, "OVERLAY", "GameFontNormal")