-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEquipmentManager.lua
More file actions
403 lines (355 loc) · 12.7 KB
/
Copy pathEquipmentManager.lua
File metadata and controls
403 lines (355 loc) · 12.7 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
local addonName, ns = ...
local container = ns.equipContainer
StaticPopupDialogs["MCU_NEW_EQUIPMENT_SET"] = {
text = GEARSETS_POPUP_TEXT or "Enter a name for this equipment set:",
button1 = ACCEPT,
button2 = CANCEL,
hasEditBox = true,
OnAccept = function(self)
local eb = self.editBox or (self.GetEditBox and self:GetEditBox())
local name = strtrim(eb and eb:GetText() or "")
if name ~= "" then
local icon = ns._pendingSetIcon or 132762
C_EquipmentSet.CreateEquipmentSet(name, icon)
end
end,
EditBoxOnEnterPressed = function(self)
local parent = self:GetParent()
local name = strtrim(self:GetText() or "")
if name ~= "" then
local icon = ns._pendingSetIcon or 132762
C_EquipmentSet.CreateEquipmentSet(name, icon)
end
parent:Hide()
end,
timeout = 0,
whileDead = true,
hideOnEscape = true,
}
StaticPopupDialogs["MCU_RENAME_EQUIPMENT_SET"] = {
text = GEARSETS_POPUP_TEXT or "Enter a new name for this equipment set:",
button1 = ACCEPT,
button2 = CANCEL,
hasEditBox = true,
OnShow = function(self)
local data = self.data
local eb = self.editBox or (self.GetEditBox and self:GetEditBox())
if data and eb then
eb:SetText(data.name or "")
eb:HighlightText()
end
end,
OnAccept = function(self, data)
local eb = self.editBox or (self.GetEditBox and self:GetEditBox())
local newName = strtrim(eb and eb:GetText() or "")
if newName ~= "" and data then
C_EquipmentSet.ModifyEquipmentSet(data.setID, newName, data.icon)
end
end,
EditBoxOnEnterPressed = function(self)
local parent = self:GetParent()
local data = parent.data
local newName = strtrim(self:GetText() or "")
if newName ~= "" and data then
C_EquipmentSet.ModifyEquipmentSet(data.setID, newName, data.icon)
end
parent:Hide()
end,
timeout = 0,
whileDead = true,
hideOnEscape = true,
}
StaticPopupDialogs["MCU_CONFIRM_DELETE_SET"] = {
text = CONFIRM_DELETE_EQUIPMENT_SET or "Delete equipment set \"%s\"?",
button1 = YES,
button2 = NO,
OnAccept = function(self, data)
C_EquipmentSet.DeleteEquipmentSet(data)
end,
timeout = 0,
whileDead = true,
hideOnEscape = true,
}
StaticPopupDialogs["MCU_CONFIRM_SAVE_SET"] = {
text = CONFIRM_SAVE_EQUIPMENT_SET or "Save current equipment to \"%s\"?",
button1 = YES,
button2 = NO,
OnAccept = function(self, data)
C_EquipmentSet.SaveEquipmentSet(data)
end,
timeout = 0,
whileDead = true,
hideOnEscape = true,
}
local ENTRY_HEIGHT = 44
local BUTTON_AREA_H = 34
local scrollFrame = CreateFrame("ScrollFrame", nil, container,
"UIPanelScrollFrameTemplate")
scrollFrame:SetPoint("TOPLEFT", 0, 0)
scrollFrame:SetPoint("BOTTOMRIGHT", -22, BUTTON_AREA_H)
local content = CreateFrame("Frame", nil, scrollFrame)
content:SetWidth(scrollFrame:GetWidth() or 240)
scrollFrame:SetScrollChild(content)
container:SetScript("OnSizeChanged", function(self)
local w = self:GetWidth() - 24
content:SetWidth(w > 0 and w or 240)
end)
local equipBtn = CreateFrame("Button", nil, container, "UIPanelButtonTemplate")
equipBtn:SetSize(110, 26)
equipBtn:SetPoint("BOTTOMLEFT", container, "BOTTOMLEFT", 0, 2)
equipBtn:SetText(EQUIP or "Equip")
equipBtn:Disable()
local saveBtn = CreateFrame("Button", nil, container, "UIPanelButtonTemplate")
saveBtn:SetSize(110, 26)
saveBtn:SetPoint("BOTTOMRIGHT", container, "BOTTOMRIGHT", 0, 2)
saveBtn:SetText(SAVE or "Save")
saveBtn:Disable()
local selectedSetID = nil
local pendingEquipSetID = nil
local setButtons = {}
local function CreateSetEntryButton()
local btn = CreateFrame("Button", nil, content)
btn:SetHeight(ENTRY_HEIGHT)
local stripe = btn:CreateTexture(nil, "BACKGROUND")
stripe:SetAllPoints()
stripe:SetColorTexture(1, 1, 1, 0.04)
stripe:Hide()
btn.stripe = stripe
local selBar = btn:CreateTexture(nil, "BACKGROUND", nil, 1)
selBar:SetAllPoints()
selBar:SetColorTexture(0.35, 0.30, 0.10, 0.35)
selBar:Hide()
btn.selBar = selBar
local icon = btn:CreateTexture(nil, "ARTWORK")
icon:SetSize(36, 36)
icon:SetPoint("LEFT", 4, 0)
icon:SetTexCoord(0.08, 0.92, 0.08, 0.92)
btn.icon = icon
local name = btn:CreateFontString(nil, "OVERLAY", "GameFontNormal")
name:SetPoint("LEFT", icon, "RIGHT", 8, 0)
name:SetPoint("RIGHT", -24, 0)
name:SetJustifyH("LEFT")
name:SetWordWrap(false)
btn.name = name
local check = btn:CreateTexture(nil, "OVERLAY")
check:SetSize(14, 14)
check:SetPoint("TOPRIGHT", -2, -2)
check:SetAtlas("common-icon-checkmark")
check:Hide()
btn.check = check
local specIcon = btn:CreateTexture(nil, "OVERLAY")
specIcon:SetSize(16, 16)
specIcon:SetPoint("RIGHT", check, "LEFT", -2, 0)
specIcon:Hide()
btn.specIcon = specIcon
local delBtn = CreateFrame("Button", nil, btn)
delBtn:SetSize(16, 16)
delBtn:SetPoint("BOTTOMRIGHT", -2, 4)
delBtn:SetNormalAtlas("common-icon-redx")
delBtn:SetHighlightAtlas("common-icon-redx")
delBtn:GetHighlightTexture():SetAlpha(0.5)
delBtn:Hide()
delBtn:SetScript("OnClick", function(self)
local setID = self:GetParent().setID
if setID then
local setName = C_EquipmentSet.GetEquipmentSetInfo(setID)
StaticPopup_Show("MCU_CONFIRM_DELETE_SET", setName, nil, setID)
end
end)
btn.delBtn = delBtn
local editBtn = CreateFrame("Button", nil, btn)
editBtn:SetSize(16, 16)
editBtn:SetPoint("RIGHT", delBtn, "LEFT", -2, 0)
editBtn:SetNormalAtlas("common-icon-settings")
editBtn:SetHighlightAtlas("common-icon-settings")
editBtn:GetHighlightTexture():SetAlpha(0.5)
editBtn:Hide()
editBtn:SetScript("OnClick", function(self)
local parent = self:GetParent()
if parent.setID then
local setName, setIcon = C_EquipmentSet.GetEquipmentSetInfo(parent.setID)
StaticPopup_Show("MCU_RENAME_EQUIPMENT_SET", nil, nil,
{ setID = parent.setID, name = setName, icon = setIcon })
end
end)
btn.editBtn = editBtn
local hl = btn:CreateTexture(nil, "HIGHLIGHT")
hl:SetAllPoints()
hl:SetColorTexture(1, 1, 1, 0.07)
btn:SetScript("OnEnter", function(self)
if self.setID then
self.delBtn:Show()
self.editBtn:Show()
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:SetEquipmentSet(self.setID)
GameTooltip:Show()
end
end)
btn:SetScript("OnLeave", function(self)
if self.delBtn:IsMouseOver() or self.editBtn:IsMouseOver() then
return
end
self.delBtn:Hide()
self.editBtn:Hide()
GameTooltip:Hide()
end)
delBtn:SetScript("OnLeave", function(self)
local parent = self:GetParent()
if not parent:IsMouseOver() and not parent.editBtn:IsMouseOver() then
parent.delBtn:Hide()
parent.editBtn:Hide()
GameTooltip:Hide()
end
end)
editBtn:SetScript("OnLeave", function(self)
local parent = self:GetParent()
if not parent:IsMouseOver() and not parent.delBtn:IsMouseOver() then
parent.delBtn:Hide()
parent.editBtn:Hide()
GameTooltip:Hide()
end
end)
btn:SetScript("OnClick", function(self)
if self.setID then
PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON)
selectedSetID = self.setID
ns:UpdateEquipmentSets()
elseif self.isNewSetBtn then
local headTex = GetInventoryItemTexture("player", 1)
or GetInventoryItemTexture("player", 5)
ns._pendingSetIcon = headTex or 132762
StaticPopup_Show("MCU_NEW_EQUIPMENT_SET")
end
end)
btn:SetScript("OnDoubleClick", function(self)
if self.setID then
EquipmentManager_EquipSet(self.setID)
end
end)
btn:RegisterForDrag("LeftButton")
btn:SetScript("OnDragStart", function(self)
if self.setID then
C_EquipmentSet.PickupEquipmentSet(self.setID)
end
end)
return btn
end
local function SortSetIDs(ids)
table.sort(ids, function(a, b)
local specA = C_EquipmentSet.GetEquipmentSetAssignedSpec(a)
local specB = C_EquipmentSet.GetEquipmentSetAssignedSpec(b)
if specA and not specB then return true end
if not specA and specB then return false end
local nameA = select(1, C_EquipmentSet.GetEquipmentSetInfo(a)) or ""
local nameB = select(1, C_EquipmentSet.GetEquipmentSetInfo(b)) or ""
return nameA < nameB
end)
return ids
end
function ns:UpdateEquipmentSets()
local setIDs = SortSetIDs(C_EquipmentSet.GetEquipmentSetIDs())
for _, btn in ipairs(setButtons) do
btn:Hide()
end
local y = 0
local idx = 0
for _, setID in ipairs(setIDs) do
local setName, setTexture, _, isEquipped, _, _, _, numLost =
C_EquipmentSet.GetEquipmentSetInfo(setID)
idx = idx + 1
local btn = setButtons[idx]
if not btn then
btn = CreateSetEntryButton()
setButtons[idx] = btn
end
btn:ClearAllPoints()
btn:SetPoint("TOPLEFT", content, "TOPLEFT", 0, -y)
btn:SetPoint("TOPRIGHT", content, "TOPRIGHT", 0, -y)
btn.setID = setID
btn.isNewSetBtn = false
btn.icon:SetTexture(setTexture or "Interface\\Icons\\INV_Misc_QuestionMark")
btn.icon:SetSize(36, 36)
btn.icon:SetDesaturated(false)
btn.name:SetText(setName or "")
if numLost and numLost > 0 then
btn.name:SetTextColor(RED_FONT_COLOR.r, RED_FONT_COLOR.g, RED_FONT_COLOR.b)
else
btn.name:SetTextColor(NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g,
NORMAL_FONT_COLOR.b)
end
btn.check:SetShown(isEquipped or (pendingEquipSetID == setID))
local specIndex = C_EquipmentSet.GetEquipmentSetAssignedSpec(setID)
if specIndex then
local _, _, _, specTex = GetSpecializationInfo(specIndex)
if specTex then
btn.specIcon:SetTexture(specTex)
btn.specIcon:Show()
else
btn.specIcon:Hide()
end
else
btn.specIcon:Hide()
end
btn.selBar:SetShown(selectedSetID == setID)
btn.stripe:SetShown(idx % 2 == 0)
btn:Show()
y = y + ENTRY_HEIGHT
end
local maxSets = MAX_EQUIPMENT_SETS_PER_PLAYER or 10
if #setIDs < maxSets then
idx = idx + 1
local btn = setButtons[idx]
if not btn then
btn = CreateSetEntryButton()
setButtons[idx] = btn
end
btn:ClearAllPoints()
btn:SetPoint("TOPLEFT", content, "TOPLEFT", 0, -y)
btn:SetPoint("TOPRIGHT", content, "TOPRIGHT", 0, -y)
btn.setID = nil
btn.isNewSetBtn = true
btn.icon:SetTexture("Interface\\PaperDollInfoFrame\\Character-Plus")
btn.icon:SetSize(30, 30)
btn.icon:SetDesaturated(false)
btn.name:SetText(PAPERDOLL_NEWEQUIPMENTSET or "New Equipment Set")
btn.name:SetTextColor(GREEN_FONT_COLOR.r, GREEN_FONT_COLOR.g,
GREEN_FONT_COLOR.b)
btn.check:Hide()
btn.specIcon:Hide()
btn.selBar:Hide()
btn.stripe:SetShown(idx % 2 == 0)
btn:Show()
y = y + ENTRY_HEIGHT
end
content:SetHeight(max(y, 1))
if selectedSetID then
local _, _, _, isEquipped = C_EquipmentSet.GetEquipmentSetInfo(selectedSetID)
local effectivelyEquipped = isEquipped or (pendingEquipSetID == selectedSetID)
if isEquipped and pendingEquipSetID == selectedSetID then
pendingEquipSetID = nil
end
equipBtn:SetEnabled(not effectivelyEquipped)
saveBtn:Enable()
else
equipBtn:Disable()
saveBtn:Disable()
end
end
equipBtn:SetScript("OnClick", function()
if selectedSetID then
PlaySound(SOUNDKIT.IG_CHARACTER_INFO_TAB)
pendingEquipSetID = selectedSetID
EquipmentManager_EquipSet(selectedSetID)
ns:UpdateEquipmentSets()
-- Deferred refresh to pick up isEquipped flag updates
C_Timer.After(0.5, function()
if ns.UpdateEquipmentSets then ns:UpdateEquipmentSets() end
end)
end
end)
saveBtn:SetScript("OnClick", function()
if selectedSetID then
local setName = C_EquipmentSet.GetEquipmentSetInfo(selectedSetID)
StaticPopup_Show("MCU_CONFIRM_SAVE_SET", setName, nil, selectedSetID)
end
end)