From 00c6e1486d2995ce5dae02dd3fbd2f89e08f404b Mon Sep 17 00:00:00 2001 From: Kyle Buller Date: Tue, 7 Jul 2020 12:06:31 -0500 Subject: [PATCH] Move threat colors to the addon db --- Main.lua | 7 +++ Modules/LuaTexts/ScriptEnv.lua | 7 ++- Modules/ThreatBar/ThreatBar.lua | 62 ++------------------------- Options/Colors.lua | 75 +++++++++++++++++++++++++++++++++ 4 files changed, 90 insertions(+), 61 deletions(-) diff --git a/Main.lua b/Main.lua index 5cff87c8..ed09d64e 100755 --- a/Main.lua +++ b/Main.lua @@ -181,6 +181,12 @@ local DATABASE_DEFAULTS = { content = { 1, 1, 0 }, unhappy = { 1, 0, 0 }, }, + threat = { + [0] = {0.69, 0.69, 0.69}, + [1] = {1, 1, 0.47}, + [2] = {1, 0.6, 0}, + [3] = {1, 0, 0}, + }, }, class_order = {}, } @@ -1396,6 +1402,7 @@ function PitBull4:OnProfileChanged() self.PowerColors = db.profile.colors.power self.ReactionColors = db.profile.colors.reaction self.HappinessColors = db.profile.colors.happiness + self.ThreatColors = db.profile.colors.threat self.ClassOrder = db.profile.class_order for i = #self.ClassOrder, 1, -1 do local v = self.ClassOrder[i] diff --git a/Modules/LuaTexts/ScriptEnv.lua b/Modules/LuaTexts/ScriptEnv.lua index 724e0767..c95a61ec 100755 --- a/Modules/LuaTexts/ScriptEnv.lua +++ b/Modules/LuaTexts/ScriptEnv.lua @@ -919,8 +919,11 @@ end ScriptEnv.ThreatSituation = ThreatSituation local function ThreatStatusColor(status) - local r, g, b = GetThreatStatusColor(status) - return r * 255, g * 255, b * 255 + local color = PitBull4.ThreatColors[status] + if not color then + return 255, 255, 255 + end + return color[1] * 255, color[2] * 255, color[3] * 255 end ScriptEnv.ThreatStatusColor = ThreatStatusColor diff --git a/Modules/ThreatBar/ThreatBar.lua b/Modules/ThreatBar/ThreatBar.lua index edd509b0..68353500 100755 --- a/Modules/ThreatBar/ThreatBar.lua +++ b/Modules/ThreatBar/ThreatBar.lua @@ -13,13 +13,6 @@ PitBull4_ThreatBar:SetDefaults({ size = 1, position = 5, show_solo = false, -},{ - threat_colors = { - [0] = {0.69, 0.69, 0.69}, -- not tanking, lower threat than tank - [1] = {1, 1, 0.47}, -- not tanking, higher threat than tank - [2] = {1, 0.6, 0}, -- insecurely tanking, another unit has higher threat - [3] = {1, 0, 0}, -- securely tanking, highest threat - }, }) function PitBull4_ThreatBar:OnEnable() @@ -82,13 +75,13 @@ function PitBull4_ThreatBar:GetColor(frame, value) if frame.guid then local _, status = UnitDetailedThreatSituation(frame.unit, "target") if status then - return unpack(self.db.profile.global.threat_colors[status]) + return unpack(PitBull4.ThreatColors[status]) end end - return unpack(self.db.profile.global.threat_colors[0]) + return unpack(PitBull4.ThreatColors[0]) end function PitBull4_ThreatBar:GetExampleColor(frame, value) - return unpack(self.db.profile.global.threat_colors[0]) + return unpack(PitBull4.ThreatColors[0]) end PitBull4_ThreatBar:SetLayoutOptionsFunction(function(self) @@ -105,52 +98,3 @@ PitBull4_ThreatBar:SetLayoutOptionsFunction(function(self) end, } end) - -PitBull4_ThreatBar:SetColorOptionsFunction(function(self) - local function get(info) - return unpack(self.db.profile.global.threat_colors[info.arg]) - end - local function set(info, r, g, b, a) - self.db.profile.global.threat_colors[info.arg] = {r, g, b, a} - self:UpdateAll() - end - return 'threat_0_color', { - type = "color", - name = L["Not tanking, lower threat than tank"], - arg = 0, - get = get, - set = set, - width = "full", - }, - 'threat_1_color', { - type = 'color', - name = L["Not tanking, higher threat than tank"], - arg = 1, - get = get, - set = set, - width = "full", - }, - 'threat_2_color', { - type = "color", - name = L["Insecurely tanking, not highest threat"], - arg = 2, - get = get, - set = set, - width = "full", - }, - 'threat_3_color', { - type = "color", - name = L["Securely tanking, highest threat"], - arg = 3, - get = get, - set = set, - width = "full", - }, - function(info) - local threat_colors = self.db.profile.global.threat_colors - threat_colors[0] = {0.69, 0.69, 0.69} - threat_colors[1] = {1, 1, 0.47} - threat_colors[2] = {1, 0.6, 0} - threat_colors[3] = {1, 0, 0} - end -end) diff --git a/Options/Colors.lua b/Options/Colors.lua index abc5ea7a..0767424d 100755 --- a/Options/Colors.lua +++ b/Options/Colors.lua @@ -335,6 +335,79 @@ local function get_happiness_options() return happiness_options end +local function get_threat_options() + local threat_options = { + type = 'group', + name = L["Threat"], + args = {}, + get = function(info) + return unpack(PitBull4.db.profile.colors.threat[info.arg]) + end, + set = function(info, r, g, b, a) + PitBull4.db.profile.colors.threat[info.arg] = {r, g, b, a} + + for frame in PitBull4:IterateFrames() do + frame:Update() + end + end, + } + + threat_options.args.threat_0 = { + type = 'color', + name = L["Not tanking, lower threat than tank"], + arg = 0, + order = 1, + width = "full", + } + threat_options.args.threat_1 = { + type = 'color', + name = L["Not tanking, higher threat than tank"], + arg = 1, + order = 2, + width = "full", + } + threat_options.args.threat_2 = { + type = 'color', + name = L["Insecurely tanking, not highest threat"], + arg = 2, + order = 3, + width = "full", + } + threat_options.args.threat_3 = { + type = 'color', + name = L["Securely tanking, highest threat"], + arg = 3, + order = 4, + width = "full", + } + + threat_options.args.reset_sep = { + type = 'header', + name = '', + order = -2, + } + threat_options.args.reset = { + type = 'execute', + name = L["Reset to defaults"], + confirm = true, + confirmText = L["Are you sure you want to reset to defaults?"], + order = -1, + func = function(info) + local db_color = PitBull4.db.profile.colors.threat + db_color[0] = {0.69, 0.69, 0.69} + db_color[1] = {1, 1, 0.47} + db_color[2] = {1, 0.6, 0} + db_color[3] = {1, 0, 0} + + for frame in PitBull4:IterateFrames() do + frame:Update() + end + end, + } + + return threat_options +end + function PitBull4.Options.get_color_options() local color_options = { type = 'group', @@ -348,6 +421,8 @@ function PitBull4.Options.get_color_options() color_options.args.power = get_power_options() color_options.args.reaction = get_reaction_options() color_options.args.happiness = get_happiness_options() + color_options.args.threat = get_threat_options() + function PitBull4.Options.colors_handle_module_load(module) if color_functions[module] then