From a4796e6c85537cf28619b15fc00bbd910925730a Mon Sep 17 00:00:00 2001 From: shagu Date: Mon, 13 Dec 2021 03:20:28 +0100 Subject: [PATCH] unitframes: option to fade health to custom color --- api/config.lua | 2 ++ api/unitframes.lua | 11 +++++++++++ modules/gui.lua | 2 ++ 3 files changed, 15 insertions(+) diff --git a/api/config.lua b/api/config.lua index 22df6a77..df621f50 100644 --- a/api/config.lua +++ b/api/config.lua @@ -191,6 +191,7 @@ function pfUI:LoadConfig() pfUI:UpdateConfig("unitframes", nil, "pastel", "1") pfUI:UpdateConfig("unitframes", nil, "custom", "0") pfUI:UpdateConfig("unitframes", nil, "customfullhp", "0") + pfUI:UpdateConfig("unitframes", nil, "customfade", "0") pfUI:UpdateConfig("unitframes", nil, "customcolor", ".2,.2,.2,1") pfUI:UpdateConfig("unitframes", nil, "custombg", "0") pfUI:UpdateConfig("unitframes", nil, "custombgcolor", ".5,.2,.2,1") @@ -451,6 +452,7 @@ function pfUI:LoadConfig() pfUI:UpdateConfig("unitframes", unit, "defcolor", "1") pfUI:UpdateConfig("unitframes", unit, "custom", "0") pfUI:UpdateConfig("unitframes", unit, "customfullhp", "0") + pfUI:UpdateConfig("unitframes", unit, "customfade", "0") pfUI:UpdateConfig("unitframes", unit, "customcolor", ".2,.2,.2,1") pfUI:UpdateConfig("unitframes", unit, "custombg", "0") pfUI:UpdateConfig("unitframes", unit, "custombgcolor", ".5,.2,.2,1") diff --git a/api/unitframes.lua b/api/unitframes.lua index 6a6a1283..2cec588a 100644 --- a/api/unitframes.lua +++ b/api/unitframes.lua @@ -1800,6 +1800,7 @@ function pfUI.uf:RefreshUnit(unit, component) local custom_active = nil local customfullhp = unit.config.defcolor == "0" and unit.config.customfullhp or C.unitframes.customfullhp local customcolor = unit.config.defcolor == "0" and unit.config.customcolor or C.unitframes.customcolor + local customfade = unit.config.defcolor == "0" and unit.config.customfade or C.unitframes.customfade local custom = unit.config.defcolor == "0" and unit.config.custom or C.unitframes.custom local r, g, b, a = .2, .2, .2, 1 @@ -1839,6 +1840,16 @@ function pfUI.uf:RefreshUnit(unit, component) r, g, b = (r + .5) * .5, (g + .5) * .5, (b + .5) * .5 end + if customfade == "1" then + -- fade custom color into default color + local perc = UnitHealth(unitstr) / UnitHealthMax(unitstr) * 2 - 1 + local cr, cg, cb, ca = pfUI.api.strsplit(",", customcolor) + + r = (cr*perc) + (r*(1-perc)) + g = (cr*perc) + (g*(1-perc)) + b = (cr*perc) + (b*(1-perc)) + end + unit.hp.bar:SetStatusBarColor(r, g, b, a) -- set powerbar color diff --git a/modules/gui.lua b/modules/gui.lua index f4476fe6..2484cf15 100644 --- a/modules/gui.lua +++ b/modules/gui.lua @@ -1607,6 +1607,7 @@ pfUI:RegisterModule("gui", "vanilla:tbc", function () CreateConfig(nil, T["Enable Pastel Colors"], C.unitframes, "pastel", "checkbox") CreateConfig(nil, T["Health Bar Color"], C.unitframes, "custom", "dropdown", pfUI.gui.dropdowns.uf_color) CreateConfig(nil, T["Custom Health Bar Color"], C.unitframes, "customcolor", "color") + CreateConfig(nil, T["Fade To Custom Color"], C.unitframes, "customfade", "checkbox") CreateConfig(nil, T["Use Custom Color On Full Health"], C.unitframes, "customfullhp", "checkbox") CreateConfig(nil, T["Enable Custom Color Health Bar Background"], C.unitframes, "custombg", "checkbox") CreateConfig(nil, T["Custom Health Bar Background Color"], C.unitframes, "custombgcolor", "color") @@ -1797,6 +1798,7 @@ pfUI:RegisterModule("gui", "vanilla:tbc", function () CreateConfig(U[c], T["Inherit Default Colors"], C.unitframes[c], "defcolor", "checkbox") CreateConfig(U[c], T["Health Bar Color"], C.unitframes[c], "custom", "dropdown", pfUI.gui.dropdowns.uf_color) CreateConfig(U[c], T["Custom Health Bar Color"], C.unitframes[c], "customcolor", "color") + CreateConfig(U[c], T["Fade To Custom Color"], C.unitframes[c], "customfade", "checkbox") CreateConfig(U[c], T["Use Custom Color On Full Health"], C.unitframes[c], "customfullhp", "checkbox") CreateConfig(U[c], T["Custom Health Bar Background Color"], C.unitframes[c], "custombgcolor", "color") CreateConfig(U[c], T["Use Custom Color Health Bar Background"], C.unitframes[c], "custombg", "checkbox")