-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotificationRow.lua
More file actions
232 lines (195 loc) · 8.49 KB
/
Copy pathNotificationRow.lua
File metadata and controls
232 lines (195 loc) · 8.49 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
local addonName, ns = ...
ns.NotificationRow = {}
local NotificationRow = ns.NotificationRow
local rowIdCounter = 0
local ROUNDED_BACKDROP = {
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true,
tileSize = 16,
edgeSize = 12,
insets = { left = 4, right = 4, top = 4, bottom = 4 },
}
function NotificationRow.Create(parent)
rowIdCounter = rowIdCounter + 1
local frame = CreateFrame("Button", "SimpleScrollingLootRow" .. rowIdCounter, parent, "BackdropTemplate")
frame:SetSize(200, 28)
frame:SetFrameStrata("HIGH")
-- Mouse interaction is opt-in so notifications do not block camera or
-- character clicks during normal play.
frame:EnableMouse(false)
frame:RegisterForClicks("AnyUp")
-- Background texture
local bg = frame:CreateTexture(nil, "BACKGROUND")
bg:SetAllPoints(frame)
bg:SetColorTexture(0, 0, 0, 0.35)
bg:Hide()
frame.bg = bg
function frame:ApplyBackground(config)
local opacity = config.backgroundOpacity or 0.35
self.bg:ClearAllPoints()
self.bg:SetAllPoints(self)
if not config.showBackground then
self.bg:Hide()
self:SetBackdrop(nil)
return
end
if config.backgroundRounded then
self.bg:Hide()
self:SetBackdrop(ROUNDED_BACKDROP)
self:SetBackdropColor(0.0, 0.0, 0.0, opacity)
self:SetBackdropBorderColor(1.0, 1.0, 1.0, opacity)
return
end
self:SetBackdrop(nil)
self.bg:SetColorTexture(0.0, 0.0, 0.0, opacity)
self.bg:Show()
end
-- Icon texture
local icon = frame:CreateTexture(nil, "ARTWORK")
icon:SetSize(24, 24)
icon:SetPoint("LEFT", frame, "LEFT", 4, 0)
frame.icon = icon
-- Main text (Item Name, Money String, or Honor String)
local mainText = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
mainText:SetPoint("LEFT", icon, "RIGHT", 6, 0)
mainText:SetJustifyH("LEFT")
mainText:SetWordWrap(false)
if type(mainText.SetMaxLines) == "function" then
mainText:SetMaxLines(1)
end
frame.mainText = mainText
-- Quantity text
local quantityText = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
quantityText:SetPoint("LEFT", mainText, "RIGHT", 6, 0)
quantityText:SetTextColor(0.8, 0.8, 0.8, 1.0)
frame.quantityText = quantityText
-- Total owned in carried bags and bank
local ownedText = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
ownedText:SetPoint("LEFT", quantityText, "RIGHT", 10, 0)
ownedText:SetTextColor(0.7, 0.7, 0.7, 1.0)
frame.ownedText = ownedText
-- Vendor value text
local vendorText = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
vendorText:SetPoint("LEFT", ownedText, "RIGHT", 10, 0)
vendorText:SetTextColor(0.7, 0.7, 0.7, 1.0)
frame.vendorText = vendorText
-- Tooltip events
frame:SetScript("OnEnter", function(self)
if self.itemLink and GameTooltip then
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:SetHyperlink(self.itemLink)
GameTooltip:Show()
end
end)
frame:SetScript("OnLeave", function(self)
if GameTooltip then
GameTooltip:Hide()
end
end)
-- Click event (standard item link chat insertion if shift-clicked)
frame:SetScript("OnClick", function(self, button)
if self.itemLink and IsModifiedClick("CHATLINK") then
HandleModifiedItemClick(self.itemLink)
end
end)
function frame:SetRecord(record, config)
self.record = record
self.itemLink = record.itemLink
local iconSize = config.iconSize or 24
local fontSize = config.fontSize or 14
local maxWidth = config.maxWidth or 480
self:SetHeight(iconSize + 4)
self:EnableMouse(config.mouseInteraction and record.kind == "item")
-- Icon
if config.showIcons and record.texture then
self.icon:SetTexture(record.texture)
self.icon:SetSize(iconSize, iconSize)
self.icon:Show()
self.mainText:ClearAllPoints()
self.mainText:SetPoint("LEFT", self.icon, "RIGHT", 6, 0)
else
self.icon:Hide()
self.mainText:ClearAllPoints()
self.mainText:SetPoint("LEFT", self, "LEFT", 6, 0)
end
-- Font sizing
local fontPath, _, fontFlags = GameFontHighlight:GetFont()
self.mainText:SetFont(fontPath, fontSize, fontFlags)
self.quantityText:SetFont(fontPath, fontSize, fontFlags)
-- Scale secondary text proportionally; no arbitrary fixed floor.
self.ownedText:SetFont(fontPath, math.max(6, fontSize - 2), fontFlags)
self.vendorText:SetFont(fontPath, math.max(6, fontSize - 2), fontFlags)
self:ApplyBackground(config)
if record.kind == "item" then
local r, g, b = ns.ApiCompat.GetItemQualityColor(record.quality)
self.mainText:SetText(record.name or record.itemLink or "Unknown Item")
self.mainText:SetTextColor(r, g, b, 1.0)
if config.showQuantity and record.quantity and record.quantity > 1 then
self.quantityText:SetText("x" .. record.quantity)
self.quantityText:Show()
else
self.quantityText:Hide()
self.quantityText:SetText("")
end
local countParts = {}
if config.showOwnedCount and type(record.bagCount) == "number" and record.bagCount > 0 then
local bagsFormat = ns.L.BAGS_COUNT_FORMAT or "Bags: %d"
table.insert(countParts, string.format(bagsFormat, record.bagCount))
end
if config.showOwnedCount and type(record.bankCount) == "number" and record.bankCount > 0 then
local bankFormat = ns.L.BANK_COUNT_FORMAT or "Bank: %d"
table.insert(countParts, string.format(bankFormat, record.bankCount))
end
if #countParts > 0 then
self.ownedText:SetText(table.concat(countParts, " / "))
self.ownedText:Show()
else
self.ownedText:Hide()
self.ownedText:SetText("")
end
if config.showVendorValue and record.sellPrice and record.sellPrice > 0 then
self.vendorText:SetText(ns.ApiCompat.FormatMoney(record.sellPrice))
self.vendorText:Show()
else
self.vendorText:Hide()
self.vendorText:SetText("")
end
elseif record.kind == "money" then
self.mainText:SetText(record.coinIconsText or record.formattedText or "Money")
self.mainText:SetTextColor(1.0, 1.0, 1.0, 1.0)
self.quantityText:Hide()
self.ownedText:Hide()
self.vendorText:Hide()
end
-- Bound long localized names without changing the stored item link used
-- by tooltips and modified clicks.
self.mainText:SetWidth(maxWidth)
local mainWidth = self.mainText:GetStringWidth() or 0
local quantWidth = self.quantityText:IsShown() and (self.quantityText:GetStringWidth() or 0) or 0
local ownedWidth = self.ownedText:IsShown() and (self.ownedText:GetStringWidth() or 0) or 0
local vendorWidth = self.vendorText:IsShown() and (self.vendorText:GetStringWidth() or 0) or 0
local iconWidth = self.icon:IsShown() and iconSize or 0
local fixedWidth = iconWidth
if iconWidth > 0 then fixedWidth = fixedWidth + 6 end
if quantWidth > 0 then fixedWidth = fixedWidth + 6 + quantWidth end
if ownedWidth > 0 then fixedWidth = fixedWidth + 10 + ownedWidth end
if vendorWidth > 0 then fixedWidth = fixedWidth + 10 + vendorWidth end
local availableMainWidth = math.max(40, maxWidth - fixedWidth - 12)
mainWidth = math.min(mainWidth, availableMainWidth)
self.mainText:SetWidth(mainWidth)
self:SetWidth(math.max(80, fixedWidth + mainWidth + 12))
-- Visibility, alpha, and position are animation state owned by
-- NotificationManager. Content refreshes must not flash a fading row
-- back to full opacity or expose a pooled row before it is positioned.
end
function frame:Reset()
self.record = nil
self.itemLink = nil
self:Hide()
self:EnableMouse(false)
self:ClearAllPoints()
self:SetAlpha(1.0)
end
return frame
end