-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainFrame.lua
More file actions
469 lines (404 loc) · 15.1 KB
/
MainFrame.lua
File metadata and controls
469 lines (404 loc) · 15.1 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
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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
local addonName, ns = ...
local frame = CreateFrame("Frame", "ModernCharacterUIFrame", UIParent, "PortraitFrameTemplate")
frame:SetSize(ns.FRAME_WIDTH, ns.FRAME_HEIGHT)
frame:SetPoint("TOPLEFT", UIParent, "TOPLEFT", 20, -104)
frame:SetFrameStrata("HIGH")
frame:SetClampedToScreen(true)
frame:Hide()
ns.frame = frame
tinsert(UISpecialFrames, "ModernCharacterUIFrame")
frame:SetMovable(true)
frame:EnableMouse(true)
frame:RegisterForDrag("LeftButton")
frame:SetScript("OnDragStart", function(self)
self:StartMoving()
end)
frame:SetScript("OnDragStop", function(self)
self:StopMovingOrSizing()
local point, _, relativePoint, xOfs, yOfs = self:GetPoint()
if ns.db and ns.db.global then
ns.db.global.position = { point, relativePoint, xOfs, yOfs }
end
end)
-- Hide the default PortraitFrameTemplate tiled-rock background and layer
-- our own atlases using the same sublevels Blizzard's Transmog panel uses:
-- 0 = base backgrounds, 1 = gradient overlays, 2 = edge details
local SW = ns.STATS_WIDTH
if frame.Bg then frame.Bg:Hide() end
local modelBg = frame:CreateTexture(nil, "BACKGROUND")
modelBg:SetPoint("TOPLEFT", frame, "TOPLEFT", 2, -21)
modelBg:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -(SW + 2), 2)
modelBg:SetAtlas("transmog-locationbg")
ns.modelBg = modelBg
-- Stats panel uses the same layered approach as the Transmog WardrobeCollection:
-- dark base, then transmog-tabs-frame-bg fill, then transmog-tabs-frame border
local statsBg = frame:CreateTexture(nil, "BACKGROUND")
statsBg:SetPoint("TOPLEFT", modelBg, "TOPRIGHT")
statsBg:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -2, 2)
statsBg:SetAtlas("transmog-outfit-darkbg")
local statsFillBg = frame:CreateTexture(nil, "BACKGROUND", nil, 1)
statsFillBg:SetPoint("TOPLEFT", statsBg, "TOPLEFT", 4, -4)
statsFillBg:SetPoint("BOTTOMRIGHT", statsBg, "BOTTOMRIGHT", -4, 4)
statsFillBg:SetAtlas("transmog-tabs-frame-bg")
local statsBorder = frame:CreateTexture(nil, "OVERLAY", nil, -1)
statsBorder:SetPoint("TOPLEFT", statsBg, "TOPLEFT", -11, 12)
statsBorder:SetPoint("BOTTOMRIGHT", statsBg, "BOTTOMRIGHT", 12, -10)
statsBorder:SetAtlas("transmog-tabs-frame")
local leftGrad = frame:CreateTexture(nil, "BACKGROUND", nil, 2)
leftGrad:SetWidth(123)
leftGrad:SetPoint("TOPLEFT", modelBg, "TOPLEFT")
leftGrad:SetPoint("BOTTOMLEFT", modelBg, "BOTTOMLEFT")
leftGrad:SetAtlas("transmog-outfit-darkbg-gradient")
local rightGrad = frame:CreateTexture(nil, "BACKGROUND", nil, 2)
rightGrad:SetWidth(123)
rightGrad:SetPoint("TOPRIGHT", modelBg, "TOPRIGHT")
rightGrad:SetPoint("BOTTOMRIGHT", modelBg, "BOTTOMRIGHT")
rightGrad:SetAtlas("transmog-outfit-darkbg-gradient")
rightGrad:SetRotation(math.rad(180))
local cornerLine = frame:CreateTexture(nil, "BACKGROUND", nil, 2)
cornerLine:SetWidth(6)
cornerLine:SetPoint("TOPRIGHT", modelBg, "TOPRIGHT", 2, 0)
cornerLine:SetPoint("BOTTOMRIGHT", modelBg, "BOTTOMRIGHT", 2, 0)
cornerLine:SetAtlas("transmog-outfit-darkbg-cornerline")
local SLOT_COL_INSET = 28
local leftColumn = CreateFrame("Frame", nil, frame)
leftColumn:SetSize(ns.SLOT_SIZE, (ns.SLOT_SIZE + ns.SLOT_SPACING) * 8)
leftColumn:SetPoint("TOPLEFT", modelBg, "TOPLEFT", SLOT_COL_INSET, -50)
ns.leftColumn = leftColumn
local rightColumn = CreateFrame("Frame", nil, frame)
rightColumn:SetSize(ns.SLOT_SIZE, (ns.SLOT_SIZE + ns.SLOT_SPACING) * 8)
rightColumn:SetPoint("TOPRIGHT", modelBg, "TOPRIGHT", -SLOT_COL_INSET, -50)
ns.rightColumn = rightColumn
local bottomSlots = CreateFrame("Frame", nil, frame)
bottomSlots:SetSize((ns.SLOT_SIZE * 2) + ns.SLOT_SPACING, ns.SLOT_SIZE)
bottomSlots:SetPoint("BOTTOM", modelBg, "BOTTOM", 0, 48)
ns.bottomSlots = bottomSlots
-- Equipment flyout settings (Alt-hover shows equippable items for slot)
local flyoutSettings = {
onClickFunc = PaperDollFrameItemFlyoutButton_OnClick,
getItemsFunc = PaperDollFrameItemFlyout_GetItems,
postGetItemsFunc = PaperDollFrameItemFlyout_PostGetItems,
hasPopouts = true,
parent = frame,
anchorX = 0,
anchorY = -3,
verticalAnchorX = 0,
verticalAnchorY = 0,
highlightSizeX = ns.SLOT_SIZE + 16,
highlightSizeY = ns.SLOT_SIZE + 16,
highlightOfsX = -10,
highlightOfsY = 0,
}
leftColumn.flyoutSettings = flyoutSettings
rightColumn.flyoutSettings = flyoutSettings
bottomSlots.flyoutSettings = flyoutSettings
local TAB_HEIGHT = 24
local tabBar = CreateFrame("Frame", nil, frame)
tabBar:SetHeight(TAB_HEIGHT)
tabBar:SetPoint("TOPLEFT", statsBg, "TOPLEFT", 6, -6)
tabBar:SetPoint("TOPRIGHT", statsBg, "TOPRIGHT", -6, -6)
local tabDivider = frame:CreateTexture(nil, "ARTWORK")
tabDivider:SetHeight(1)
tabDivider:SetPoint("TOPLEFT", tabBar, "BOTTOMLEFT")
tabDivider:SetPoint("TOPRIGHT", tabBar, "BOTTOMRIGHT")
tabDivider:SetColorTexture(0.45, 0.40, 0.25, 0.4)
local function CreateTabButton(parent, text, anchor1, anchor2)
local btn = CreateFrame("Button", nil, parent)
btn:SetPoint(unpack(anchor1))
btn:SetPoint(unpack(anchor2))
local label = btn:CreateFontString(nil, "OVERLAY", "GameFontNormal")
label:SetPoint("CENTER", 0, 1)
label:SetText(text)
btn.label = label
local indicator = btn:CreateTexture(nil, "OVERLAY")
indicator:SetHeight(2)
indicator:SetPoint("BOTTOMLEFT", 4, 0)
indicator:SetPoint("BOTTOMRIGHT", -4, 0)
indicator:SetColorTexture(0.9, 0.75, 0.3, 1)
indicator:Hide()
btn.indicator = indicator
local hl = btn:CreateTexture(nil, "HIGHLIGHT")
hl:SetAllPoints()
hl:SetColorTexture(1, 1, 1, 0.05)
return btn
end
local statsTab = CreateTabButton(tabBar,
STAT_CATEGORY_ATTRIBUTES or "Stats",
{"TOPLEFT"}, {"BOTTOMRIGHT", tabBar, "BOTTOM"})
local equipTab = CreateTabButton(tabBar,
EQUIPMENT_MANAGER or "Equipment Sets",
{"TOPRIGHT"}, {"BOTTOMLEFT", tabBar, "BOTTOM"})
local statsContainer = CreateFrame("Frame", nil, frame)
statsContainer:SetPoint("TOPLEFT", tabBar, "BOTTOMLEFT", 0, -4)
statsContainer:SetPoint("BOTTOMRIGHT", statsBg, "BOTTOMRIGHT", -6, 4)
ns.statsContainer = statsContainer
local equipContainer = CreateFrame("Frame", nil, frame)
equipContainer:SetPoint("TOPLEFT", tabBar, "BOTTOMLEFT", 0, -4)
equipContainer:SetPoint("BOTTOMRIGHT", statsBg, "BOTTOMRIGHT", -6, 4)
equipContainer:Hide()
ns.equipContainer = equipContainer
local activeTab = "stats"
local function SetActiveTab(tabName)
activeTab = tabName
if tabName == "stats" then
statsContainer:Show()
equipContainer:Hide()
statsTab.label:SetTextColor(1, 0.82, 0, 1)
statsTab.indicator:Show()
equipTab.label:SetTextColor(0.6, 0.6, 0.6, 1)
equipTab.indicator:Hide()
if EquipmentFlyoutPopoutButton_HideAll then
EquipmentFlyoutPopoutButton_HideAll()
end
else
statsContainer:Hide()
equipContainer:Show()
statsTab.label:SetTextColor(0.6, 0.6, 0.6, 1)
statsTab.indicator:Hide()
equipTab.label:SetTextColor(1, 0.82, 0, 1)
equipTab.indicator:Show()
if ns.UpdateEquipmentSets then ns:UpdateEquipmentSets() end
if EquipmentFlyoutPopoutButton_ShowAll then
EquipmentFlyoutPopoutButton_ShowAll()
end
end
end
statsTab:SetScript("OnClick", function() SetActiveTab("stats") end)
equipTab:SetScript("OnClick", function() SetActiveTab("equip") end)
SetActiveTab("stats")
ns.SetActiveTab = SetActiveTab
local function UpdateTitle()
local name = UnitPVPName("player") or UnitName("player") or ""
frame:SetTitle(name)
frame:SetPortraitToUnit("player")
end
local function IsBlockedByCombat()
return ns.db and ns.db.global and ns.db.global.blockInCombat
and InCombatLockdown()
end
function ns:ShowPanel()
if IsBlockedByCombat() then return end
frame:Show()
end
function ns:HidePanel()
frame:Hide()
end
function ns:TogglePanel()
if frame:IsShown() then
frame:Hide()
else
if IsBlockedByCombat() then return end
frame:Show()
end
end
function ns:RefreshAll()
UpdateTitle()
if self.UpdateAllSlots then self:UpdateAllSlots() end
if self.UpdateModel then self:UpdateModel() end
if self.UpdateStats then self:UpdateStats() end
end
frame:RegisterEvent("PLAYER_LOGIN")
frame:RegisterEvent("PLAYER_ENTERING_WORLD")
local UNIT_EVENTS = {
"UNIT_STATS",
"UNIT_AURA",
"UNIT_ATTACK_SPEED",
"UNIT_MAXHEALTH",
"UNIT_MODEL_CHANGED",
"UNIT_NAME_UPDATE",
}
local GLOBAL_EVENTS = {
"PLAYER_EQUIPMENT_CHANGED",
"COMBAT_RATING_UPDATE",
"PLAYER_AVG_ITEM_LEVEL_UPDATE",
"PLAYER_DAMAGE_DONE_MODS",
"PLAYER_SPECIALIZATION_CHANGED",
"UNIT_INVENTORY_CHANGED",
"KNOWN_TITLES_UPDATE",
"EQUIPMENT_SETS_CHANGED",
"EQUIPMENT_SWAP_FINISHED",
"ZONE_CHANGED_NEW_AREA",
"UPDATE_FACTION",
"MAJOR_FACTION_RENOWN_LEVEL_CHANGED",
"CURRENCY_DISPLAY_UPDATE",
}
frame:SetScript("OnShow", function(self)
ns:RefreshAll()
for _, ev in ipairs(UNIT_EVENTS) do
self:RegisterUnitEvent(ev, "player")
end
for _, ev in ipairs(GLOBAL_EVENTS) do
self:RegisterEvent(ev)
end
PlaySound(SOUNDKIT.IG_CHARACTER_INFO_OPEN)
end)
frame:SetScript("OnHide", function(self)
for _, ev in ipairs(UNIT_EVENTS) do
self:UnregisterEvent(ev)
end
for _, ev in ipairs(GLOBAL_EVENTS) do
self:UnregisterEvent(ev)
end
if EquipmentFlyoutPopoutButton_HideAll then
EquipmentFlyoutPopoutButton_HideAll()
end
if ns._SetMainTab then ns._SetMainTab("character") end
PlaySound(SOUNDKIT.IG_CHARACTER_INFO_CLOSE)
end)
frame:SetScript("OnEvent", function(self, event, arg1, ...)
if event == "PLAYER_LOGIN" then
local pos = ns.db and ns.db.global and ns.db.global.position
if pos then
self:ClearAllPoints()
self:SetPoint(pos[1], UIParent, pos[2], pos[3], pos[4])
end
if ns.BuildSlots then ns:BuildSlots() end
ns:ApplyFrameScale()
ns:ApplySlotFontSize()
ns:ApplySlotOverlayStyle()
ns:ApplyStatsFontSize()
ns:ApplyRepFontSize()
ns:ApplyCurrencyFontSize()
ns:ApplyIconStyle()
return
end
if event == "PLAYER_ENTERING_WORLD" then
if self:IsShown() then
ns:RefreshAll()
end
return
end
if not self:IsShown() then return end
if event == "PLAYER_EQUIPMENT_CHANGED" then
local slotID = arg1
if ns.UpdateSlot then ns:UpdateSlot(slotID) end
if ns.UpdateModel then ns:UpdateModel() end
if ns.UpdateStats then ns:UpdateStats() end
if ns.UpdateEquipmentSets then ns:UpdateEquipmentSets() end
elseif event == "UNIT_MODEL_CHANGED" then
if ns.UpdateModel then ns:UpdateModel() end
elseif event == "UNIT_NAME_UPDATE" or event == "KNOWN_TITLES_UPDATE" then
UpdateTitle()
if ns.UpdateTitleDropdown then ns:UpdateTitleDropdown() end
if ns.UpdateStats then ns:UpdateStats() end
elseif event == "ZONE_CHANGED_NEW_AREA" then
ns:RefreshAll()
elseif event == "EQUIPMENT_SETS_CHANGED" or event == "EQUIPMENT_SWAP_FINISHED" then
if ns.UpdateEquipmentSets then ns:UpdateEquipmentSets() end
elseif event == "UPDATE_FACTION" or event == "MAJOR_FACTION_RENOWN_LEVEL_CHANGED" then
if ns.UpdateReputation then ns:UpdateReputation() end
elseif event == "CURRENCY_DISPLAY_UPDATE" then
if ns.UpdateCurrency then ns:UpdateCurrency() end
elseif event == "PLAYER_SPECIALIZATION_CHANGED" then
ns:RefreshAll()
else
if ns.UpdateStats then ns:UpdateStats() end
end
end)
local mainCharTab = CreateFrame("Button", "ModernCharacterUITab1", frame,
"PanelTabButtonTemplate")
mainCharTab:SetID(1)
mainCharTab:SetText(CHARACTER or "Character")
mainCharTab:SetPoint("TOPLEFT", frame, "BOTTOMLEFT", 11, 2)
PanelTemplates_TabResize(mainCharTab, 0)
local mainRepTab = CreateFrame("Button", "ModernCharacterUITab2", frame,
"PanelTabButtonTemplate")
mainRepTab:SetID(2)
mainRepTab:SetText(REPUTATION or "Reputation")
mainRepTab:SetPoint("TOPLEFT", mainCharTab, "TOPRIGHT", 1, 0)
PanelTemplates_TabResize(mainRepTab, 0)
local mainCurrTab = CreateFrame("Button", "ModernCharacterUITab3", frame,
"PanelTabButtonTemplate")
mainCurrTab:SetID(3)
mainCurrTab:SetText(CURRENCY or "Currency")
mainCurrTab:SetPoint("TOPLEFT", mainRepTab, "TOPRIGHT", 1, 0)
PanelTemplates_TabResize(mainCurrTab, 0)
frame.numTabs = 3
frame.Tabs = { mainCharTab, mainRepTab, mainCurrTab }
PanelTemplates_SetNumTabs(frame, 3)
PanelTemplates_SetTab(frame, 1)
local function CreateFullContentFrame()
local f = CreateFrame("Frame", nil, frame)
f:SetPoint("TOPLEFT", frame, "TOPLEFT", 2, -21)
f:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", 0, 2)
f:SetFrameLevel(frame:GetFrameLevel() + 1)
f:Hide()
local bg = f:CreateTexture(nil, "BACKGROUND")
bg:SetAllPoints()
bg:SetAtlas("transmog-outfit-darkbg")
local fillBg = f:CreateTexture(nil, "BACKGROUND", nil, 1)
fillBg:SetPoint("TOPLEFT", 4, -4)
fillBg:SetPoint("BOTTOMRIGHT", -4, 4)
fillBg:SetAtlas("transmog-tabs-frame-bg")
local border = f:CreateTexture(nil, "OVERLAY", nil, -1)
border:SetPoint("TOPLEFT", -11, 12)
border:SetPoint("BOTTOMRIGHT", 10, -10)
border:SetAtlas("transmog-tabs-frame")
return f
end
local repContent = CreateFullContentFrame()
ns.repContent = repContent
local currContent = CreateFullContentFrame()
ns.currContent = currContent
local charTextures = {
modelBg, statsBg, statsFillBg, statsBorder,
leftGrad, rightGrad, cornerLine,
}
local function HideCharacterElements()
for _, tex in ipairs(charTextures) do tex:Hide() end
ns.leftColumn:Hide()
ns.rightColumn:Hide()
ns.bottomSlots:Hide()
if ns.model then ns.model:Hide() end
if ns.controlBar then ns.controlBar:Hide() end
tabBar:Hide()
tabDivider:Hide()
statsContainer:Hide()
equipContainer:Hide()
end
local function ShowCharacterElements()
for _, tex in ipairs(charTextures) do tex:Show() end
ns.leftColumn:Show()
ns.rightColumn:Show()
ns.bottomSlots:Show()
if ns.model then ns.model:Show() end
if ns.controlBar then ns.controlBar:Show() end
tabBar:Show()
tabDivider:Show()
SetActiveTab(activeTab)
end
local activeMainTab = "character"
local function SetMainTab(tabName)
activeMainTab = tabName
repContent:Hide()
currContent:Hide()
if tabName == "character" then
PanelTemplates_SetTab(frame, 1)
ShowCharacterElements()
elseif tabName == "reputation" then
PanelTemplates_SetTab(frame, 2)
HideCharacterElements()
repContent:Show()
if ns.UpdateReputation then ns:UpdateReputation() end
elseif tabName == "currency" then
PanelTemplates_SetTab(frame, 3)
HideCharacterElements()
currContent:Show()
if ns.UpdateCurrency then ns:UpdateCurrency() end
end
end
ns._SetMainTab = SetMainTab
mainCharTab:SetScript("OnClick", function()
PlaySound(SOUNDKIT.IG_CHARACTER_INFO_TAB)
SetMainTab("character")
end)
mainRepTab:SetScript("OnClick", function()
PlaySound(SOUNDKIT.IG_CHARACTER_INFO_TAB)
SetMainTab("reputation")
end)
mainCurrTab:SetScript("OnClick", function()
PlaySound(SOUNDKIT.IG_CHARACTER_INFO_TAB)
SetMainTab("currency")
end)
SetMainTab("character")
ns.SetMainTab = SetMainTab