-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DisplayCreation.lua
317 lines (277 loc) · 10.6 KB
/
DisplayCreation.lua
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
---@class GT
local GT = LibStub("AceAddon-3.0"):GetAddon("GatheringTracker")
local media = LibStub:GetLibrary("LibSharedMedia-3.0")
-- Localize global functions
local ipairs = ipairs
local math = math
local max = max
local next = next
local pairs = pairs
local select = select
local string = string
local table = table
local time = time
local tonumber = tonumber
local tostring = tostring
local type = type
local unpack = unpack
local function FramePool_Resetter(framePool, frame)
frame:Hide()
frame:ClearAllPoints()
if frame.icon then
frame.icon:SetScript("OnEnter", nil)
frame.icon:SetScript("OnLeave", nil)
frame.icon:SetMouseClickEnabled(false)
frame.icon:SetMouseMotionEnabled(false)
GT.Pools.texturePool:Release(frame.icon)
frame.icon = nil
end
if frame.iconQuality then
GT.Pools.texturePool:Release(frame.iconQuality)
frame.iconQuality = nil
end
if frame.iconRarity then
frame.iconRarity:SetVertexColor(1, 1, 1, 1)
GT.Pools.texturePool:Release(frame.iconRarity)
frame.iconRarity = nil
end
if frame.highlight then
frame.highlight:SetVertexColor(1, 1, 1, 1)
GT.Pools.texturePool:Release(frame.highlight)
frame.highlight = nil
end
if frame.text == nil then
return
end
for index, fontString in ipairs(frame.text) do
GT.Pools.fontStringPool:Release(fontString)
end
frame.text = nil
if frame.totalItemCount then
frame.totalItemCount = nil
end
if frame.pricePerItem then
frame.pricePerItem = nil
end
if frame.priceTotalItem then
frame.priceTotalItem = nil
end
if frame.timer then
frame.timer = nil
end
frame:SetScript("OnEnter", nil)
frame:SetMouseClickEnabled(false)
frame:SetMouseMotionEnabled(false)
end
function GT:InitializePools()
GT.Pools.framePool = GT.Pools.framePool or CreateFramePool("Frame", GT.baseFrame.frame, nil, FramePool_Resetter)
GT.Pools.texturePool = GT.Pools.texturePool or CreateTexturePool(GT.baseFrame.frame, "BACKGROUND")
GT.Pools.fontStringPool = GT.Pools.fontStringPool or CreateFontStringPool(GT.baseFrame.frame, "BACKGROUND")
end
local function CreateTextDisplay(frame, id, text, type, height, anchor)
local string = GT.Pools.fontStringPool:Acquire()
string:SetParent(frame)
if id < 9999999998 then
string:SetFont(media:Fetch("font", GT.db.profile.General.textFont), GT.db.profile.General.textSize, "OUTLINE")
string:SetVertexColor(GT.db.profile.General.textColor[1], GT.db.profile.General.textColor[2],
GT.db.profile.General.textColor[3])
else
string:SetFont(media:Fetch("font", GT.db.profile.General.totalFont), GT.db.profile.General.totalSize, "OUTLINE")
string:SetVertexColor(GT.db.profile.General.totalColor[1], GT.db.profile.General.totalColor[2],
GT.db.profile.General.totalColor[3])
end
string:SetHeight(height)
local offset = 3
if anchor ~= frame.icon then
offset = 8 --make spacing fraction of height? (make this adjustable?)
end
string.textType = type
string:SetPoint("LEFT", anchor, "RIGHT", offset, 0)
string:SetJustifyH("LEFT") --add option for this?
if id ~= 3 then
string:SetText(text)
end
string:Show()
if id == 3 then
frame.timer = true
string:SetText("00:00:00")
GT:UpdateTimer(frame)
end
return string
end
function GT:CreateDisplayFrame(id, iconId, iconQuality, iconRarity, displayText,
pricePerItem, priceTotalItem, itemsPerHour, goldPerHour)
GT.Debug("CreateDisplayFrame", 4, id, iconId, iconQuality, iconRarity, displayText,
pricePerItem, priceTotalItem, itemsPerHour, goldPerHour)
if displayText == nil then
return
end
local frame = GT:DisplayFrameBase(id)
GT.Display.Frames[id] = frame
GT:DisplayFrameHighlight(frame)
GT:DisplayFrameIcon(frame, iconId, id)
if iconQuality then
GT:DisplayFrameQuality(frame, iconQuality)
end
GT:DisplayFrameRarity(frame, iconRarity)
local frameHeight = frame:GetHeight()
frame.text = {}
if type(displayText) == "table" then
for index, text in ipairs(displayText) do
GT:DisplayFrameCounts(frame, id, text, index)
end
else
GT:DisplayFrameCounts(frame, id, displayText)
end
if pricePerItem and GT.db.profile.General.perItemPrice then
GT:DisplayFramePricePer(frame, id, pricePerItem)
end
if priceTotalItem and GT.db.profile.General.tsmPrice > 0 then
GT:DisplayFramePriceTotal(frame, id, priceTotalItem)
end
if itemsPerHour and GT.db.profile.General.itemsPerHour then
GT:DisplayFrameItemsPerHour(frame, id, itemsPerHour)
end
if goldPerHour and GT.db.profile.General.goldPerHour then
GT:DisplayFrameGoldPerHour(frame, id, goldPerHour)
end
GT.Display.Order = GT.Display.Order or {}
table.insert(GT.Display.Order, id)
table.sort(GT.Display.Order)
end
function GT:DisplayFrameBase(id)
local frame = GT.Pools.framePool:Acquire()
frame:SetPoint("TOPLEFT", GT.baseFrame.backdrop, "TOPLEFT")
frame:SetWidth(GT.db.profile.General.iconWidth)
local frameHeight = math.max(GT.db.profile.General.iconHeight, GT.db.profile.General.totalSize)
frame:SetHeight(frameHeight + 3)
frame:SetFrameStrata("BACKGROUND")
frame:SetFrameLevel(3)
frame:Show()
return frame
end
function GT:DisplayFrameIcon(frame, iconId, id)
frame.icon = GT.Pools.texturePool:Acquire()
frame.icon:SetParent(frame)
frame.icon:SetDrawLayer("BACKGROUND", 0)
frame.icon:SetTexture(iconId)
frame.icon:SetPoint("LEFT", frame, "LEFT")
frame.icon:SetWidth(GT.db.profile.General.iconWidth)
frame.icon:SetHeight(GT.db.profile.General.iconHeight)
frame.icon:Show()
if id <= #GT.ItemData.Other.Other or id >= 9999999998 then
return
end
if not GT.db.profile.General.itemTooltip then
return
end
frame.icon:SetScript("OnEnter", function(self, motion)
if motion then
GameTooltip:SetOwner(self, self:GetTooltipAnchor())
GameTooltip:SetItemByID(id)
GameTooltip:Show()
end
end)
frame.icon:SetScript("OnLeave", function(self)
if GameTooltip:GetOwner() == self then
GameTooltip:Hide()
end
end)
function frame.icon:GetTooltipAnchor()
local x = self:GetRight() / GetScreenWidth() > 0.8
return x and 'ANCHOR_LEFT' or 'ANCHOR_RIGHT'
end
frame.icon:SetMouseClickEnabled(false)
end
function GT:DisplayFrameQuality(frame, iconQuality)
frame.iconQuality = GT.Pools.texturePool:Acquire()
frame.iconQuality:SetParent(frame)
frame.iconQuality:SetDrawLayer("BACKGROUND", 2)
if iconQuality == 1 then
frame.iconQuality:SetAtlas("professions-icon-quality-tier1-inv", true)
elseif iconQuality == 2 then
frame.iconQuality:SetAtlas("professions-icon-quality-tier2-inv", true)
elseif iconQuality == 3 then
frame.iconQuality:SetAtlas("professions-icon-quality-tier3-inv", true)
end
frame.iconQuality:SetAllPoints(frame.icon)
frame.iconQuality:Show()
end
function GT:DisplayFrameRarity(frame, iconRarity)
if not GT.db.profile.General.rarityBorder then
return
end
frame.iconRarity = GT.Pools.texturePool:Acquire()
frame.iconRarity:SetParent(frame)
frame.iconRarity:SetDrawLayer("BACKGROUND", 1)
local rarity = iconRarity or 1
if rarity <= 1 then
frame.iconRarity:SetTexture("Interface\\Common\\WhiteIconFrame")
else
frame.iconRarity:SetAtlas("bags-glow-white")
end
local R, G, B = C_Item.GetItemQualityColor(rarity)
frame.iconRarity:SetVertexColor(R, G, B, 0.8)
frame.iconRarity:SetAllPoints(frame.icon)
frame.iconRarity:Show()
end
function GT:DisplayFrameHighlight(frame)
frame.highlight = GT.Pools.texturePool:Acquire()
frame.highlight:SetParent(frame)
frame.highlight:SetDrawLayer("BACKGROUND", 7)
frame.highlight:SetAllPoints(frame)
frame.highlight:Hide()
end
function GT:DisplayFrameCounts(frame, id, text, index)
index = index or 1
local anchor = frame.icon
if index > 1 then
anchor = frame.text[index - 1]
end
if type(text) == "number" then
text = math.ceil(text - 0.5)
else
text = text
end
frame.text[index] = CreateTextDisplay(frame, id, text, "count", frame:GetHeight(), anchor)
if id <= #GT.ItemData.Other.Other then
-- 3 is the offset from the icon, 8 is the offset to the next column
local offset = GT.db.profile.General.iconWidth + 3 + 8
local parentWidth = frame:GetWidth()
local width = parentWidth - offset
local stringWidth = frame.text[index]:GetUnboundedStringWidth()
frame.text[index]:SetWidth(stringWidth)
end
GT:CheckColumnSize(index, frame.text[index], id)
end
function GT:DisplayFrameTotal(frame, id, totalItemCount)
frame.text[#frame.text + 1] = CreateTextDisplay(frame, id, "[" .. math.ceil(totalItemCount - 0.5) .. "]", "totalItemCount", frame:GetHeight(), frame.text[#frame.text])
GT:CheckColumnSize(#frame.text, frame.text[#frame.text], id)
frame.totalItemCount = #frame.text
end
function GT:DisplayFramePricePer(frame, id, pricePerItem)
local text = ""
if type(pricePerItem) == "number" then
text = "{" .. math.ceil(pricePerItem - 0.5) .. "g}"
else
text = ""
end
frame.text[#frame.text + 1] = CreateTextDisplay(frame, id, text, "pricePerItem", frame:GetHeight(), frame.text[#frame.text])
GT:CheckColumnSize(#frame.text, frame.text[#frame.text], id)
frame.pricePerItem = #frame.text
end
function GT:DisplayFramePriceTotal(frame, id, priceTotalItem)
frame.text[#frame.text + 1] = CreateTextDisplay(frame, id, "(" .. math.ceil(priceTotalItem - 0.5) .. "g)", "priceTotalItem", frame:GetHeight(), frame.text[#frame.text])
GT:CheckColumnSize(#frame.text, frame.text[#frame.text], id)
frame.priceTotalItem = #frame.text
end
function GT:DisplayFrameItemsPerHour(frame, id, itemsPerHour)
frame.text[#frame.text + 1] = CreateTextDisplay(frame, id, math.ceil(itemsPerHour - 0.5) .. "/h", "itemsPerHour", frame:GetHeight(), frame.text[#frame.text])
GT:CheckColumnSize(#frame.text, frame.text[#frame.text], id)
frame.itemsPerHour = #frame.text
end
function GT:DisplayFrameGoldPerHour(frame, id, goldPerHour)
frame.text[#frame.text + 1] = CreateTextDisplay(frame, id, math.ceil(goldPerHour - 0.5) .. "g/h", "goldPerHour", frame:GetHeight(), frame.text[#frame.text])
GT:CheckColumnSize(#frame.text, frame.text[#frame.text], id)
frame.goldPerHour = #frame.text
end