From dcfc406481e6babc1ebdc75d7fb147fd0e7e4aa2 Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Mon, 6 Jan 2025 22:20:09 +0100 Subject: [PATCH] Refactor button colorization --- Modules/Config.lua | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Modules/Config.lua b/Modules/Config.lua index ac6ac19..8109a1c 100644 --- a/Modules/Config.lua +++ b/Modules/Config.lua @@ -310,7 +310,6 @@ function shared.Config.Init() local color = res and buttonColors.enabled or buttonColors.disabled button:SetBackdropColor(unpack(color)) end) - local color = Heimdall_Data.config.spotter.enabled and buttonColors.enabled or buttonColors.disabled button:SetBackdrop({ bgFile = "Interface/Tooltips/UI-Tooltip-Background", edgeFile = "Interface/Tooltips/UI-Tooltip-Border", @@ -324,7 +323,10 @@ function shared.Config.Init() bottom = 2 } }) - button:SetBackdropColor(unpack(color)) + button.UpdateColor = function(self, state) + local color = state and buttonColors.enabled or buttonColors.disabled + self:SetBackdropColor(unpack(color)) + end --spotterEnableButton:SetChecked(Heimdall_Data.config.spotter.enabled) local spotterEnableButtonLabel = button:CreateFontString(nil, "OVERLAY", "GameFontNormal") spotterEnableButtonLabel:SetText(text) @@ -396,13 +398,15 @@ function shared.Config.Init() Heimdall_Data.config.spotter.enabled = not Heimdall_Data.config.spotter.enabled return Heimdall_Data.config.spotter.enabled end) - spotterConfigFrame:Add(spotterEnableButton, 1, 5) + spotterEnableButton:UpdateColor(Heimdall_Data.config.spotter.enabled) + spotterConfigFrame:Add(spotterEnableButton, 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 spotterHostileButton = BasicButton("HeimdallSpotterConfigHostileButton", @@ -410,6 +414,7 @@ function shared.Config.Init() 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 spotterAllianceButton = BasicButton("HeimdallSpotterConfigAllianceButton", @@ -417,6 +422,7 @@ function shared.Config.Init() 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 spotterStinkyButton = BasicButton("HeimdallSpotterConfigStinkyButton", @@ -424,6 +430,7 @@ function shared.Config.Init() 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 testEditBox = CreateBasicSmallEditBox("HeimdallSpotterConfigTestEditBox",