-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecorBorder.lua
More file actions
247 lines (198 loc) · 7.05 KB
/
Copy pathDecorBorder.lua
File metadata and controls
247 lines (198 loc) · 7.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
-- DecorBorder Addon
-- Version 1.2.0
-- Tooltip-based ownership detection (authoritative Blizzard data)
-- Runs only while merchant window is open (no background work / no leaks)
DecorBorder = {}
DecorBorderDB = DecorBorderDB or {}
local OwnedCache = {} -- [itemID] = state
local defaults = {
enableColoring = true,
colorCollected = { r = 0, g = 1, b = 0 }, -- green
colorCollectedEmpty = { r = 1, g = 1, b = 0 }, -- yellow
colorUncollected = { r = 1, g = 0, b = 0 }, -- red
}
local function GetColor(tbl)
return tbl.r, tbl.g, tbl.b
end
local function CopyDefaults(src, dst)
if type(dst) ~= "table" then dst = {} end
for k, v in pairs(src) do
if type(v) == "table" then
dst[k] = CopyDefaults(v, dst[k])
elseif dst[k] == nil then
dst[k] = v
end
end
return dst
end
local function Print(text, ...)
if text then
if text:match("%%[dfqs%d%.]") then
print("DECB " .. format(text, ...))
else
print("DECB " .. strjoin(" ", text, tostringall(...)))
end
end
end
DecorBorderDB = CopyDefaults(defaults, DecorBorderDB)
local function RequestCatalog()
local catalogSearcher = C_HousingCatalog.CreateCatalogSearcher();
catalogSearcher:GetCatalogSearchResults();
end
local function OpenColorPicker(title, colorTable, callback)
local r, g, b = colorTable.r, colorTable.g, colorTable.b
local function ColorCallback(restore)
local nr, ng, nb
if restore then
nr, ng, nb = unpack(restore)
else
nr, ng, nb = ColorPickerFrame:GetColorRGB()
end
colorTable.r, colorTable.g, colorTable.b = nr, ng, nb
if callback then callback() end
end
ColorPickerFrame.func = ColorCallback
ColorPickerFrame.hasOpacity = false
ColorPickerFrame.previousValues = { r, g, b }
ColorPickerFrame:SetColorRGB(r, g, b)
ColorPickerFrame:Hide()
ColorPickerFrame:Show()
ColorPickerFrame.Title:SetText(title)
end
-- ============================================================
-- Hidden Tooltip Scanner
-- ============================================================
local ScanTooltip = CreateFrame("GameTooltip", "DecorBorderScanTooltip", UIParent, "GameTooltipTemplate")
ScanTooltip:SetOwner(UIParent, "ANCHOR_NONE")
local function StripColorCodes(text)
-- removes |cAARRGGBB and |r and |cn... codes
text = text:gsub("|c%x%x%x%x%x%x%x%x", "")
text = text:gsub("|cn.-:", "")
text = text:gsub("|r", "")
return text
end
-- Reads Blizzard's own "Owned:" tooltip line
-- Returns: learned(boolean), placed(number), storage(number)
-- Returns:
-- state = 0 → uncollected
-- state = 1 → collected but storage empty
-- state = 2 → collected and in storage
-- also returns placed, storage, owned for debugging if needed
local function GetOwnedFromTooltip(itemID)
if not itemID then return 0,0,0,0 end
ScanTooltip:ClearLines()
ScanTooltip:SetItemByID(itemID)
local numLines = ScanTooltip:NumLines()
for i = 1, numLines do
local line = _G["DecorBorderScanTooltipTextLeft"..i]
if line then
local text = line:GetText()
-- Fast reject: almost all tooltip lines won't contain this word
if text and text:find("Owned", 1, true) then
-- Only now strip color codes
text = StripColorCodes(text)
local owned, placed, storage = text:match(
"Owned:%s*(%d+)%s*%(%s*Placed:%s*(%d+),%s*Storage:%s*(%d+)%)"
)
if owned then
local numOwned = tonumber(owned) or 0
local numStored = tonumber(storage) or 0
local state
if numOwned == 0 then
-- Uncollected
state = 0
elseif numOwned > 0 and numStored == 0 then
-- Collected but nothing in storage
state = 1
else
-- Collected and storage > 0
state = 2
end
return state
end
end
end
end
-- No Owned line at all → uncollected
return 0, 0, 0, 0
end
-- ============================================================
-- Decor filter helper
-- (keeps your existing classID test)
-- ============================================================
local function _isDecor(itemID)
local _, _, _, _, _, _, _, _, _, _, _, classID = C_Item.GetItemInfo(itemID)
-- Current housing decor classID in your build = 20
return (classID == 20)
end
-- ============================================================
-- Merchant Coloring Function
-- ============================================================
local function DecorBorder_MerchantUpdate()
if not MerchantFrame or not MerchantFrame:IsShown() then return end
if not DecorBorderDB.enableColoring then return end
for i = 1, MERCHANT_ITEMS_PER_PAGE do
local merchantButton = _G["MerchantItem"..i]
local itemButton = _G["MerchantItem"..i.."ItemButton"]
local index = ((MerchantFrame.page - 1) * MERCHANT_ITEMS_PER_PAGE) + i
local itemID = GetMerchantItemID(index)
if merchantButton and itemButton and itemID and _isDecor(itemID) then
local state = GetOwnedFromTooltip(itemID)
-- state:
-- 0 = uncollected
-- 1 = collected but empty storage
-- 2 = collected and in storage
if state == 2 then
-- Collected + in storage → GREEN
SetItemButtonNameFrameVertexColor(merchantButton, GetColor(DecorBorderDB.colorCollected))
SetItemButtonSlotVertexColor(merchantButton, GetColor(DecorBorderDB.colorCollected))
SetItemButtonTextureVertexColor(itemButton, GetColor(DecorBorderDB.colorCollected))
SetItemButtonNormalTextureVertexColor(itemButton, GetColor(DecorBorderDB.colorCollected))
elseif state == 1 then
-- Collected but storage empty → YELLOW
SetItemButtonNameFrameVertexColor(merchantButton, GetColor(DecorBorderDB.colorCollectedEmpty))
SetItemButtonSlotVertexColor(merchantButton, GetColor(DecorBorderDB.colorCollectedEmpty))
SetItemButtonTextureVertexColor(itemButton, GetColor(DecorBorderDB.colorCollectedEmpty))
SetItemButtonNormalTextureVertexColor(itemButton, GetColor(DecorBorderDB.colorCollectedEmpty))
else
-- Uncollected → RED
SetItemButtonNameFrameVertexColor(merchantButton, GetColor(DecorBorderDB.colorUncollected))
SetItemButtonSlotVertexColor(merchantButton, GetColor(DecorBorderDB.colorUncollected))
SetItemButtonTextureVertexColor(itemButton, GetColor(DecorBorderDB.colorUncollected))
SetItemButtonNormalTextureVertexColor(itemButton, GetColor(DecorBorderDB.colorUncollected))
end
end
end
end
-- ============================================================
-- Event Controller (merchant-only execution)
-- ============================================================
local EventFrame = CreateFrame("Frame")
EventFrame:RegisterEvent("MERCHANT_SHOW")
EventFrame:RegisterEvent("MERCHANT_UPDATE")
EventFrame:RegisterEvent("MERCHANT_CLOSED")
local MerchantHooked = false
EventFrame:SetScript("OnEvent", function(_, event)
if event == "PLAYER_LOGIN" then
--RequestCatalog()
--CreateDecorBorderOptions()
return
end
if event == "MERCHANT_SHOW" then
if not MerchantHooked then
--RequestCatalog()
hooksecurefunc("MerchantFrame_UpdateMerchantInfo", DecorBorder_MerchantUpdate)
MerchantHooked = true
end
DecorBorder_MerchantUpdate()
return
end
if event == "MERCHANT_UPDATE" then
DecorBorder_MerchantUpdate()
return
end
if event == "MERCHANT_CLOSED" then
-- Nothing running in background
return
end
end)