Skip to content

Commit

Permalink
[Feature] Pet Frame Class Color (#71)
Browse files Browse the repository at this point in the history
* defaults

* add toggles for color tab

* util function

* locale
  • Loading branch information
Krealle authored Sep 14, 2024
1 parent 10b0ca9 commit 3299023
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
10 changes: 6 additions & 4 deletions Data/Defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ Defaults.Colors = {
hostile = { 0.78, 0.25, 0.25, 1 },
neutral = { 0.85, 0.77, 0.36, 1 },
pet = { 0.29, 0.69, 0.3, 1 },
useClassColorForPet = false,
},
essence = {
["1"] = { 0.2, 0.57, 0.5, 1 },
Expand Down Expand Up @@ -192,10 +193,11 @@ Defaults.ColorsMenuOrder = {
{ "fullyCharged", "rgb" }
},
reaction = {
{ "friendly", "rgb" },
{ "hostile", "rgb" },
{ "neutral", "rgb" },
{ "pet", "rgb" },
{ "friendly", "rgb" },
{ "hostile", "rgb" },
{ "neutral", "rgb" },
{ "pet", "rgb" },
{ "useClassColorForPet", "toggle" },
},
essence = {
{ "1", "rgb" },
Expand Down
1 change: 1 addition & 0 deletions Locales/enUS.lua
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ L.comboPoints = "Combo Points"
L.chi = "Chi"
L.essence = "Essence"
L.classResources = "Class Resources"
L.useClassColorForPet = "Use Class Color for Pet"

L.reaction = "Reaction"
L.friendly = "Friendly"
Expand Down
38 changes: 34 additions & 4 deletions Menu/ColorTab.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ local function CreateColorPicker(which, colorName, colorTable, parent)
CUF:Fire("UpdateAppearance", "color")
end
end
cp.type = "colorPicker"

local cpWidth = math.max(cp:GetWidth() + cp.label:GetWidth() + 5, (ColorTab.window:GetWidth() / 3) - 15)

Expand Down Expand Up @@ -135,6 +136,26 @@ local function CreateTextureDropdown(which, colorName, colorTable, parent)
return textureDropdown
end

---@param which Defaults.Colors.Types
---@param colorName string
---@param colorTable table<string, RGBAOpt>
---@param parent Frame
---@return CUF.ColorSection.Checkbox, number
local function CreateCheckbox(which, colorName, colorTable, parent)
---@class CUF.ColorSection.Checkbox: CellCheckButton
local cb = Cell:CreateCheckButton(parent, L[colorName], function(checked)
DB.SetColor(which, colorName, checked)
CUF:Fire("UpdateAppearance", "color")
CUF:Fire("UpdateWidget", DB.GetMasterLayout())
end)

local val = colorTable[colorName] --[[@as boolean]]
cb:SetChecked(val)
cb.type = "toggle"

return cb, math.max(cb:GetWidth() + cb.label:GetWidth() + 5, (ColorTab.window:GetWidth() / 3) - 15)
end

-------------------------------------------------
-- MARK: Sections
-------------------------------------------------
Expand All @@ -146,7 +167,12 @@ function ColorTab:UpdateColors()
for _, section in pairs(self.colorSections) do
local colorTable = DB.GetColors()[section.id]
for _, cp in pairs(section.cps) do
cp:SetColor(colorTable[cp.id])
if cp.type == "toggle" then
cp:SetChecked(colorTable[cp.id])
elseif cp.type == "colorPicker" then
---@cast cp CUF.ColorSection.ColorPicker
cp:SetColor(colorTable[cp.id])
end
end
for _, dropdown in pairs(section.dropdowns) do
dropdown:SetSelected(Builder.textureToName[colorTable[dropdown.id]], colorTable[dropdown.id])
Expand Down Expand Up @@ -180,7 +206,7 @@ function ColorTab:CreateSections()
local section = CUF:CreateFrame(colorSection:GetName() .. "_" .. Util:ToTitleCase(which),
colorSection.scrollFrame.content, self.window:GetWidth() - 10, 1, false, true)
section.id = which
section.cps = {} ---@type CUF.ColorSection.ColorPicker[]
section.cps = {} ---@type (CUF.ColorSection.ColorPicker|CUF.ColorSection.Checkbox)[]
section.dropdowns = {} ---@type CUF.ColorSection.Dropdown[]

local sectionTitle = CUF:CreateFrame(nil, section, 1, 1, true, true) --[[@as OptionTitle]]
Expand Down Expand Up @@ -235,8 +261,12 @@ function ColorTab:CreateSections()
baseHeight = baseHeight + element:GetHeight() + sectionGap * 2.5

tinsert(section.dropdowns, element)
elseif colorType == "rgb" then
element, elementWidth = CreateColorPicker(which, colorName, colorTable, section)
elseif colorType == "rgb" or colorType == "toggle" then
if colorType == "toggle" then
element, elementWidth = CreateCheckbox(which, colorName, colorTable, section)
else
element, elementWidth = CreateColorPicker(which, colorName, colorTable, section)
end

-- Move to the next column, or wrap to the next row if necessary
if gridLayout.currentColumn > gridLayout.maxColumns
Expand Down
4 changes: 4 additions & 0 deletions Util/Utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ function Util:GetUnitClassColor(unit, class, guid)
return unpack(DB.GetColors().reaction.hostile)
end

if unit == "pet" and DB.GetColors().reaction.useClassColorForPet then
return F:GetClassColor(select(2, UnitClass("player")))
end

return unpack(DB.GetColors().reaction.pet)
end

Expand Down

0 comments on commit 3299023

Please sign in to comment.