From 2dabe7959fad23617c8a33f8ce67b40b37d1da47 Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Mon, 6 Jan 2025 22:23:41 +0100 Subject: [PATCH] Refactor spotter config into separate do block --- Modules/Config.lua | 98 ++++++++++++++++++++++++---------------------- 1 file changed, 52 insertions(+), 46 deletions(-) diff --git a/Modules/Config.lua b/Modules/Config.lua index 8109a1c..27490ba 100644 --- a/Modules/Config.lua +++ b/Modules/Config.lua @@ -385,59 +385,65 @@ function shared.Config.Init() title:SetText("Heimdall Config") configFrame:Add(title, 1, 12) - local spotterConfigFrame = GridFrame.new("HeimdallSpotterConfig", - UIParent, 12, 20) - configFrame:Add(spotterConfigFrame, 6, 3) + do + local spotterConfigFrame = GridFrame.new("HeimdallSpotterConfig", + UIParent, 12, 20) + configFrame:Add(spotterConfigFrame, 6, 3) - local spotterTitle = spotterConfigFrame.frame:CreateFontString(nil, "ARTWORK", "GameFontNormal") - spotterTitle:SetText("Spotter") - spotterConfigFrame:Add(spotterTitle, 1, 12) + local title = spotterConfigFrame.frame:CreateFontString(nil, "ARTWORK", "GameFontNormal") + title:SetText("Spotter") + spotterConfigFrame:Add(title, 1, 12) - local spotterEnableButton = BasicButton("HeimdallSpotterConfigEnableButton", - spotterConfigFrame.frame, "Enabled", function() - Heimdall_Data.config.spotter.enabled = not Heimdall_Data.config.spotter.enabled - return Heimdall_Data.config.spotter.enabled - end) - spotterEnableButton:UpdateColor(Heimdall_Data.config.spotter.enabled) - spotterConfigFrame:Add(spotterEnableButton, 1, 6) + local enableButton = BasicButton("HeimdallSpotterConfigEnableButton", + spotterConfigFrame.frame, "Enabled", function() + Heimdall_Data.config.spotter.enabled = not Heimdall_Data.config.spotter.enabled + return Heimdall_Data.config.spotter.enabled + end) + enableButton:UpdateColor(Heimdall_Data.config.spotter.enabled) + spotterConfigFrame:Add(enableButton, 1, 6) - local spotterEveryoneButton = BasicButton("HeimdallSpotterConfigEveryoneButton", - spotterConfigFrame.frame, "Everyone", function() - Heimdall_Data.config.spotter.everyone = not Heimdall_Data.config.spotter.everyone - return Heimdall_Data.config.spotter.everyone - end) - spotterEveryoneButton:UpdateColor(Heimdall_Data.config.spotter.everyone) - spotterConfigFrame:Add(spotterEveryoneButton, 1, 6) + local everyoneButton = BasicButton("HeimdallSpotterConfigEveryoneButton", + spotterConfigFrame.frame, "Everyone", function() + Heimdall_Data.config.spotter.everyone = not Heimdall_Data.config.spotter.everyone + return Heimdall_Data.config.spotter.everyone + end) + everyoneButton:UpdateColor(Heimdall_Data.config.spotter.everyone) + spotterConfigFrame:Add(everyoneButton, 1, 6) - local spotterHostileButton = BasicButton("HeimdallSpotterConfigHostileButton", - spotterConfigFrame.frame, "Hostile", function() - Heimdall_Data.config.spotter.hostile = not Heimdall_Data.config.spotter.hostile - return Heimdall_Data.config.spotter.hostile - end) - spotterHostileButton:UpdateColor(Heimdall_Data.config.spotter.hostile) - spotterConfigFrame:Add(spotterHostileButton, 1, 4) + local hostileButton = BasicButton("HeimdallSpotterConfigHostileButton", + spotterConfigFrame.frame, "Hostile", function() + Heimdall_Data.config.spotter.hostile = not Heimdall_Data.config.spotter.hostile + return Heimdall_Data.config.spotter.hostile + end) + hostileButton:UpdateColor(Heimdall_Data.config.spotter.hostile) + spotterConfigFrame:Add(hostileButton, 1, 4) - local spotterAllianceButton = BasicButton("HeimdallSpotterConfigAllianceButton", - spotterConfigFrame.frame, "Alliance", function() - Heimdall_Data.config.spotter.alliance = not Heimdall_Data.config.spotter.alliance - return Heimdall_Data.config.spotter.alliance - end) - spotterAllianceButton:UpdateColor(Heimdall_Data.config.spotter.alliance) - spotterConfigFrame:Add(spotterAllianceButton, 1, 4) + local allianceButton = BasicButton("HeimdallSpotterConfigAllianceButton", + spotterConfigFrame.frame, "Alliance", function() + Heimdall_Data.config.spotter.alliance = not Heimdall_Data.config.spotter.alliance + return Heimdall_Data.config.spotter.alliance + end) + allianceButton:UpdateColor(Heimdall_Data.config.spotter.alliance) + spotterConfigFrame:Add(allianceButton, 1, 4) - local spotterStinkyButton = BasicButton("HeimdallSpotterConfigStinkyButton", - spotterConfigFrame.frame, "Stinky", function() - Heimdall_Data.config.spotter.stinky = not Heimdall_Data.config.spotter.stinky - return Heimdall_Data.config.spotter.stinky - end) - spotterStinkyButton:UpdateColor(Heimdall_Data.config.spotter.stinky) - spotterConfigFrame:Add(spotterStinkyButton, 1, 4) + local stinkyButton = BasicButton("HeimdallSpotterConfigStinkyButton", + spotterConfigFrame.frame, "Stinky", function() + Heimdall_Data.config.spotter.stinky = not Heimdall_Data.config.spotter.stinky + return Heimdall_Data.config.spotter.stinky + end) + stinkyButton:UpdateColor(Heimdall_Data.config.spotter.stinky) + spotterConfigFrame:Add(stinkyButton, 1, 4) - local testEditBox = CreateBasicSmallEditBox("HeimdallSpotterConfigTestEditBox", - spotterConfigFrame.frame, "Test", function(text) - print(text) - end) - spotterConfigFrame:Add(testEditBox, 2, 6) + local notifyChannel = CreateBasicSmallEditBox("HeimdallSpotterConfigTestEditBox", + spotterConfigFrame.frame, "Notify Channel", function(text) + if string.match(text, "%S+") then + Heimdall_Data.config.spotter.notifyChannel = text + else + print("Invalid channel name", tostring(text)) + end + end) + spotterConfigFrame:Add(notifyChannel, 2, 4) + end --local spotterEveryoneButton = BasicButton("HeimdallSpotterEveryone", spotterConfigFrame, "Everyone", function(state) -- Heimdall_Data.config.spotter.everyone = state