From 8642efab86b9d81e507e7dff79c73bed1c4982e2 Mon Sep 17 00:00:00 2001 From: shagu Date: Fri, 19 Apr 2019 00:23:08 +0200 Subject: [PATCH] unitframes: option to use variable health bg color --- api/config.lua | 1 + api/unitframes.lua | 47 +++++++++++++++++++++++++++++----------------- modules/gui.lua | 8 +++++++- 3 files changed, 38 insertions(+), 18 deletions(-) diff --git a/api/config.lua b/api/config.lua index 38d5e49a..4cd30703 100644 --- a/api/config.lua +++ b/api/config.lua @@ -166,6 +166,7 @@ function pfUI:LoadConfig() pfUI:UpdateConfig("unitframes", nil, "disable", "0") pfUI:UpdateConfig("unitframes", nil, "pastel", "1") pfUI:UpdateConfig("unitframes", nil, "custom", "0") + pfUI:UpdateConfig("unitframes", nil, "customfullhp", "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") diff --git a/api/unitframes.lua b/api/unitframes.lua index 6fe2e233..b3842d48 100644 --- a/api/unitframes.lua +++ b/api/unitframes.lua @@ -1481,27 +1481,40 @@ function pfUI.uf:RefreshUnit(unit, component) end local r, g, b, a = .2, .2, .2, 1 - if UnitIsPlayer(unitstr) then - local _, class = UnitClass(unitstr) - local color = RAID_CLASS_COLORS[class] - if color then r, g, b = color.r, color.g, color.b end - elseif unit.label == "pet" then - local happiness = GetPetHappiness() - if happiness == 1 then - r, g, b = 1, 0, 0 - elseif happiness == 2 then - r, g, b = 1, 1, 0 + local custom = nil + if C.unitframes.customfullhp == "1" and UnitHealth(unitstr) == UnitHealthMax(unitstr) then + r, g, b, a = pfUI.api.strsplit(",", C.unitframes.customcolor) + custom = true + elseif C.unitframes.custom == "0" then + if UnitIsPlayer(unitstr) then + local _, class = UnitClass(unitstr) + local color = RAID_CLASS_COLORS[class] + if color then r, g, b = color.r, color.g, color.b end + elseif unit.label == "pet" then + local happiness = GetPetHappiness() + if happiness == 1 then + r, g, b = 1, 0, 0 + elseif happiness == 2 then + r, g, b = 1, 1, 0 + else + r, g, b = 0, 1, 0 + end else - r, g, b = 0, 1, 0 + local color = UnitReactionColor[UnitReaction(unitstr, "player")] + if color then r, g, b = color.r, color.g, color.b end + end + elseif C.unitframes.custom == "1" then + r, g, b, a = pfUI.api.strsplit(",", C.unitframes.customcolor) + custom = true + elseif C.unitframes.custom == "2" then + if UnitHealthMax(unitstr) > 0 then + r, g, b = GetColorGradient(UnitHealth(unitstr) / UnitHealthMax(unitstr)) + else + r, g, b = 0, 0, 0 end - else - local color = UnitReactionColor[UnitReaction(unitstr, "player")] - if color then r, g, b = color.r, color.g, color.b end end - if C.unitframes.custom == "1" then - r, g, b, a = pfUI.api.strsplit(",", C.unitframes.customcolor) - elseif C.unitframes.pastel == "1" then + if C.unitframes.pastel == "1" and not custom then r, g, b = (r + .5) * .5, (g + .5) * .5, (b + .5) * .5 end diff --git a/modules/gui.lua b/modules/gui.lua index 5c988926..79688536 100644 --- a/modules/gui.lua +++ b/modules/gui.lua @@ -950,6 +950,11 @@ pfUI:RegisterModule("gui", 20400, function () "default:" .. T["Default"], "tukui:TukUI" }, + ["uf_color"] = { + "0:" .. T["Class"], + "1:" .. T["Custom"], + "2:" .. T["Health"], + }, ["uf_texts"] = { "none:" .. T["Disable"], "unit:" .. T["Unit String"], @@ -1411,8 +1416,9 @@ pfUI:RegisterModule("gui", 20400, function () CreateGUIEntry(T["Unit Frames"], T["General"], function() CreateConfig(nil, T["Disable pfUI Unit Frames"], C.unitframes, "disable", "checkbox") CreateConfig(nil, T["Enable Pastel Colors"], C.unitframes, "pastel", "checkbox") - CreateConfig(nil, T["Enable Custom Color Health Bars"], C.unitframes, "custom", "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["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") CreateConfig(nil, T["Healthbar Animation Speed"], C.unitframes, "animation_speed", "dropdown", pfUI.gui.dropdowns.uf_animationspeed)