Skip to content

Commit

Permalink
Move threat colors to the addon db
Browse files Browse the repository at this point in the history
  • Loading branch information
nebularg committed Jul 7, 2020
1 parent 0f15bf7 commit 00c6e14
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 61 deletions.
7 changes: 7 additions & 0 deletions Main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {},
}
Expand Down Expand Up @@ -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]
Expand Down
7 changes: 5 additions & 2 deletions Modules/LuaTexts/ScriptEnv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
62 changes: 3 additions & 59 deletions Modules/ThreatBar/ThreatBar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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)
75 changes: 75 additions & 0 deletions Options/Colors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
Expand Down

0 comments on commit 00c6e14

Please sign in to comment.