Skip to content

Commit 23765a0

Browse files
committed
itemlevel recolors as it's updated
1 parent 298d904 commit 23765a0

File tree

2 files changed

+65
-28
lines changed

2 files changed

+65
-28
lines changed

config/itemcolorpane.lua

Lines changed: 59 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,42 @@ local itemColorPane = addon:NewModule('ItemColorPane')
2020

2121
---@class ItemColorPaneFrame
2222
---@field frame Frame
23+
---@field breakpointsLabel FontString
24+
---@field colorPickerLabels table<string, FontString>
2325
local itemColorPaneProto = {}
2426

27+
function itemColorPaneProto:UpdateBreakpoints()
28+
local maxIlvl = database:GetMaxItemLevel()
29+
local midPoint = math.floor(maxIlvl * 0.61)
30+
local highPoint = math.floor(maxIlvl * 0.86)
31+
32+
self.breakpointsLabel:SetText(string.format(
33+
"Current maximum item level: |cffffffff%d|r\n\n" ..
34+
"Color ranges:\n" ..
35+
" • Low: |cff9d9d9d1-%d|r\n" ..
36+
" • Mid: |cffffffff%d-%d|r (61%% of max)\n" ..
37+
" • High: |cff008dde%d-%d|r (86%% of max)\n" ..
38+
" • Max: |cffff8000%d+|r\n\n" ..
39+
"These ranges update automatically as you obtain higher item level gear.",
40+
maxIlvl,
41+
midPoint - 1,
42+
midPoint, highPoint - 1,
43+
highPoint, maxIlvl - 1,
44+
maxIlvl
45+
))
46+
47+
-- Update color picker labels
48+
self.colorPickerLabels.low:SetText("Low Item Level Color (1-" .. (midPoint - 1) .. ")")
49+
self.colorPickerLabels.mid:SetText("Mid Item Level Color (" .. midPoint .. "-" .. (highPoint - 1) .. ")")
50+
self.colorPickerLabels.high:SetText("High Item Level Color (" .. highPoint .. "-" .. (maxIlvl - 1) .. ")")
51+
self.colorPickerLabels.max:SetText("Max Item Level Color (" .. maxIlvl .. "+)")
52+
end
53+
2554
---@param parent Frame
2655
---@return Frame
2756
function itemColorPane:Create(parent)
2857
local pane = setmetatable({}, {__index = itemColorPaneProto})
58+
pane.colorPickerLabels = {}
2959

3060
-- Create main frame
3161
pane.frame = CreateFrame("Frame", nil, parent)
@@ -54,28 +84,10 @@ function itemColorPane:Create(parent)
5484
yOffset = yOffset - 50
5585

5686
-- Current breakpoints info
57-
local maxIlvl = database:GetMaxItemLevel()
58-
local midPoint = math.floor(maxIlvl * 0.61)
59-
local highPoint = math.floor(maxIlvl * 0.86)
60-
61-
local breakpointsLabel = content:CreateFontString(nil, "OVERLAY", "GameFontNormal")
62-
breakpointsLabel:SetPoint("TOPLEFT", 0, yOffset)
63-
breakpointsLabel:SetPoint("RIGHT", content, "RIGHT", 0, 0)
64-
breakpointsLabel:SetJustifyH("LEFT")
65-
breakpointsLabel:SetText(string.format(
66-
"Current maximum item level: |cffffffff%d|r\n\n" ..
67-
"Color ranges:\n" ..
68-
" • Low: |cff9d9d9d1-%d|r\n" ..
69-
" • Mid: |cffffffff%d-%d|r (61%% of max)\n" ..
70-
" • High: |cff008dde%d-%d|r (86%% of max)\n" ..
71-
" • Max: |cffff8000%d+|r\n\n" ..
72-
"These ranges update automatically as you obtain higher item level gear.",
73-
maxIlvl,
74-
midPoint - 1,
75-
midPoint, highPoint - 1,
76-
highPoint, maxIlvl - 1,
77-
maxIlvl
78-
))
87+
pane.breakpointsLabel = content:CreateFontString(nil, "OVERLAY", "GameFontNormal")
88+
pane.breakpointsLabel:SetPoint("TOPLEFT", 0, yOffset)
89+
pane.breakpointsLabel:SetPoint("RIGHT", content, "RIGHT", 0, 0)
90+
pane.breakpointsLabel:SetJustifyH("LEFT")
7991
yOffset = yOffset - 150
8092

8193
-- Color pickers section
@@ -85,10 +97,10 @@ function itemColorPane:Create(parent)
8597
yOffset = yOffset - 30
8698

8799
-- Helper function to create color picker
88-
local function CreateColorPicker(labelText, colorKey, yPos)
100+
local function CreateColorPicker(colorKey, yPos)
89101
local label = content:CreateFontString(nil, "OVERLAY", "GameFontNormal")
90102
label:SetPoint("TOPLEFT", 20, yPos)
91-
label:SetText(labelText)
103+
pane.colorPickerLabels[colorKey] = label
92104

93105
local colorSwatch = CreateFrame("Button", nil, content)
94106
colorSwatch:SetPoint("TOPLEFT", 200, yPos + 3)
@@ -127,10 +139,13 @@ function itemColorPane:Create(parent)
127139
return yPos - 25
128140
end
129141

130-
yOffset = CreateColorPicker("Low Item Level Color (1-" .. (midPoint - 1) .. ")", "low", yOffset)
131-
yOffset = CreateColorPicker("Mid Item Level Color (" .. midPoint .. "-" .. (highPoint - 1) .. ")", "mid", yOffset)
132-
yOffset = CreateColorPicker("High Item Level Color (" .. highPoint .. "-" .. (maxIlvl - 1) .. ")", "high", yOffset)
133-
yOffset = CreateColorPicker("Max Item Level Color (" .. maxIlvl .. "+)", "max", yOffset)
142+
yOffset = CreateColorPicker("low", yOffset)
143+
yOffset = CreateColorPicker("mid", yOffset)
144+
yOffset = CreateColorPicker("high", yOffset)
145+
yOffset = CreateColorPicker("max", yOffset)
146+
147+
-- Initial update of breakpoints
148+
pane:UpdateBreakpoints()
134149

135150
yOffset = yOffset - 20
136151

@@ -150,5 +165,21 @@ function itemColorPane:Create(parent)
150165
newFrame:Show()
151166
end)
152167

168+
-- Register for max item level changes
169+
pane.frame:RegisterEvent("BAG_UPDATE")
170+
pane.frame:SetScript("OnEvent", function()
171+
-- Check if we're still visible
172+
if pane.frame:IsShown() then
173+
pane:UpdateBreakpoints()
174+
end
175+
end)
176+
177+
-- Also listen for the custom event via Events module
178+
events:RegisterMessage('itemLevel/MaxChanged', function()
179+
if pane.frame:IsShown() then
180+
pane:UpdateBreakpoints()
181+
end
182+
end)
183+
153184
return pane.frame
154185
end

core/database.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,12 @@ function DB:UpdateMaxItemLevel(itemLevel)
230230
local current = byCharacter[characterKey] or 1
231231
if itemLevel > current then
232232
byCharacter[characterKey] = itemLevel
233+
-- Trigger refresh of items and options pane
234+
local events = addon:GetModule('Events')
235+
local context = addon:GetModule('Context')
236+
local ctx = context:New('UpdateMaxItemLevel')
237+
events:SendMessage(ctx, 'itemLevel/MaxChanged', itemLevel)
238+
events:SendMessage(ctx, 'bags/FullRefreshAll')
233239
end
234240
end
235241

0 commit comments

Comments
 (0)