This repository has been archived by the owner on Aug 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBackpack.lua
477 lines (408 loc) · 13.7 KB
/
Backpack.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
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
469
470
471
472
473
474
475
476
477
local addOnName = ...
assert(LibContainer, 'LibContainer dependency missing.')
LibContainer:SetDatabase(addOnName .. 'DB')
local LE_ITEM_QUALITY_UNCOMMON = LE_ITEM_QUALITY_UNCOMMON or Enum.ItemQuality.ItemQualityGood or 2
local LE_ITEM_CLASS_WEAPON = LE_ITEM_CLASS_WEAPON or 2
local LE_ITEM_CLASS_ARMOR = LE_ITEM_CLASS_ARMOR or 4
local LE_ITEM_CLASS_GEM = LE_ITEM_CLASS_GEM or 3
local LE_ITEM_SUBCLASS_RELIC = 11
local ICONS = [[Interface\AddOns\Backpack\assets\icons.tga]]
local TEXTURE = [[Interface\ChatFrame\ChatFrameBackground]]
local BACKDROP = {bgFile = TEXTURE, edgeFile = TEXTURE, edgeSize = 1}
local LDD = LibStub('LibDropDown')
LDD:RegisterStyle(addOnName, {
gap = 18,
padding = 8,
spacing = 0,
backdrop = BACKDROP,
backdropColor = CreateColor(0, 0, 0, 0.9),
backdropBorderColor = CreateColor(0, 0, 0),
normalFont = 'PixelFontNormal',
disabledFont = 'PixelFontDisabled',
titleFont = 'PixelFontTitle'
})
local Dropdown -- gets assigned at the end, needs a parent
-- widget hooks
local function onAutoVendorClick(self)
if(LibContainer:GetVariable('autoSellJunk')) then
self:GetNormalTexture():SetVertexColor(1, 0.1, 0.1)
else
self:GetNormalTexture():SetVertexColor(0.3, 0.3, 0.3)
end
end
local function onAutoDepositClick(self)
if(LibContainer:GetVariable('autoDeposit')) then
self:GetNormalTexture():SetVertexColor(0, 0.6, 1)
else
self:GetNormalTexture():SetVertexColor(0.3, 0.3, 0.3)
end
end
local function onSearchClick(self)
self:SetAlpha(1)
self:SetFrameLevel(self:GetFrameLevel() + 1)
self.Icon:Hide()
local Search = self.Search
Search:Show()
Search:SetFocus()
end
local function onSearchEnter(self)
if(not self.Search:IsShown()) then
self:SetAlpha(0.4)
end
end
local function onSearchLeave(self)
if(not self.Search:IsShown()) then
self:SetAlpha(0)
end
end
local function onSearchEscape(self)
local SearchZone = self.SearchZone
if(not MouseIsOver(SearchZone)) then
SearchZone:SetAlpha(0)
else
SearchZone:SetAlpha(0.4)
end
SearchZone:SetFrameLevel(SearchZone:GetFrameLevel() - 1)
SearchZone.Icon:Show()
self:Hide()
end
local function onBagSlotsToggle(self)
local Parent = self:GetParent():GetParent()
if(Parent.bagSlots) then
local isShown
for _, Slot in next, Parent.bagSlots do
isShown = Slot:IsShown()
break
end
Parent._bagSlotsShown = isShown
Parent:GetContainer(1):UpdateSize()
end
end
local function onBagSlotEnter(self)
-- highlight the slots within the bag when mousing over
local Parent = self:GetParent()
for bagID, Bag in next, Parent:GetBags() do
local currentBag = bagID == self:GetID()
for _, Slot in next, Bag:GetSlots() do
if(Slot:IsShown()) then
if(currentBag) then
Slot:SetAlpha(1)
else
Slot:SetAlpha(0.1)
end
end
end
end
end
local function onBagSlotLeave(self)
local Parent = self:GetParent()
for bagID, Bag in next, Parent:GetBags() do
for _, Slot in next, Bag:GetSlots() do
if(Slot:IsShown()) then
Slot:SetAlpha(1)
end
end
end
end
local function onReagentBankPurchaseButtonClick()
PlaySound(SOUNDKIT.IG_MAINMENU_OPTION)
StaticPopup_Show('CONFIRM_BUY_REAGENTBANK_TAB')
end
local onSlotClick
do
local currentSlot
local function onSlotLineClick(_, _, categoryIndex)
if(categoryIndex) then
if(categoryIndex == true) then
local category = currentSlot:GuessCategory('New')
categoryIndex = category.index
end
currentSlot:AssignCategory(categoryIndex)
else
currentSlot:ClearCategory()
end
currentSlot:GetParent():GetParent():UpdateContainers()
end
function onSlotClick(Slot, button)
if(button ~= 'RightButton' or not IsControlKeyDown()) then
return
end
if(not Dropdown.initialized) then
local info = {func = onSlotLineClick}
info.text = 'Mark as new'
Dropdown:AddLine(info)
info.text = 'Mark as known'
info.args = {true}
Dropdown:AddLine(info)
Dropdown:AddLine({isSpacer = true})
for categoryIndex, data in next, Slot.parent:GetCategories() do
if(categoryIndex ~= 2 and categoryIndex ~= 997 and categoryIndex ~= 999) then
-- ignoring Invalid, New and ReagentBank categories
info.text = data.localizedName
info.args = {categoryIndex}
Dropdown:AddLine(info)
end
end
Dropdown.initialized = true
end
currentSlot = Slot
Dropdown:SetAnchor('TOPRIGHT', Slot)
Dropdown:SetParent(Slot)
Dropdown:Toggle()
end
end
-- callbacks
local function containerUpdateSize(Container)
local Parent = Container:GetParent()
local categoryIndex = Container:GetID()
if(categoryIndex == 1 and Parent._bagSlotsShown) then
-- resize to make space for bagslots
local width, height = Container:GetSize()
Container:SetSize(width, height + 40)
elseif(categoryIndex == 999) then
-- make space for and/or show/hide reagent purchase button
if(not IsReagentBankUnlocked()) then
local width, height = Container:GetSize()
Container:SetSize(width, height + 40)
Container.PurchaseReagentBankButton:Show()
else
Container.PurchaseReagentBankButton:Hide()
end
end
end
local function slotUpdate(Slot)
SetItemButtonTexture(Slot, Slot:GetItemTexture())
SetItemButtonCount(Slot, Slot:GetItemCount())
SetItemButtonDesaturated(Slot, Slot:IsItemLocked())
local itemQuality = Slot:GetItemQuality()
local itemQualityColor = Slot:GetItemQualityColor()
local itemClass = Slot:GetItemClass()
if(itemQuality >= LE_ITEM_QUALITY_UNCOMMON and (itemClass == LE_ITEM_CLASS_WEAPON or itemClass == LE_ITEM_CLASS_ARMOR or (itemClass == LE_ITEM_CLASS_GEM and Slot:GetItemSubClass() == LE_ITEM_SUBCLASS_RELIC))) then
local ItemLevel = Slot.ItemLevel
ItemLevel:SetText(Slot:GetItemLevel())
ItemLevel:SetTextColor(itemQualityColor:GetRGB())
ItemLevel:Show()
else
Slot.ItemLevel:Hide()
end
if(Slot:GetItemQuestID() or Slot:IsItemQuestItem()) then
Slot:SetBackdropBorderColor(1, 1, 0)
elseif(itemQuality >= LE_ITEM_QUALITY_UNCOMMON) then
Slot:SetBackdropBorderColor(itemQualityColor:GetRGB())
else
Slot:SetBackdropBorderColor(0, 0, 0)
end
end
local function slotVisibility(Slot)
if(Slot:IsItemEmpty()) then
local Icon = Slot.Icon
Icon:SetTexture(nil)
Icon:SetDesaturated(false)
Slot.Count:SetText('')
Slot.ItemLevel:Hide()
Slot:SetBackdropBorderColor(0, 0, 0)
end
end
local function styleSlot(Slot)
Slot:SetSize(32, 32)
Slot:SetBackdrop(BACKDROP)
Slot:SetBackdropColor(0.1, 0.1, 0.1, 0.5)
Slot:SetBackdropBorderColor(0, 0, 0)
Slot:HookScript('OnClick', onSlotClick)
Slot.Update = slotUpdate
Slot:On('PostUpdateVisibility', slotVisibility)
local Icon = Slot.Icon
Icon:ClearAllPoints()
Icon:SetPoint('TOPLEFT', 1, -1)
Icon:SetPoint('BOTTOMRIGHT', -1, 1)
Icon:SetTexCoord(0.08, 0.92, 0.08, 0.92)
local Count = Slot.Count
Count:ClearAllPoints()
Count:SetPoint('BOTTOMRIGHT', 0, 2)
Count:SetFontObject('PixelFontNormal')
Count:Show()
local ItemLevel = Slot:CreateFontString('$parentItemLevel', 'ARTWORK', 'PixelFontNormal')
ItemLevel:SetPoint('BOTTOM', 2, 2)
ItemLevel:SetJustifyH('CENTER')
Slot.ItemLevel = ItemLevel
local Pushed = Slot.PushedTexture
Pushed:ClearAllPoints()
Pushed:SetPoint('TOPLEFT', 1, -1)
Pushed:SetPoint('BOTTOMRIGHT', -1, 1)
Pushed:SetColorTexture(1, 1, 1, 0.3)
local Highlight = Slot.HighlightTexture
Highlight:ClearAllPoints()
Highlight:SetPoint('TOPLEFT', 1, -1)
Highlight:SetPoint('BOTTOMRIGHT', -1, 1)
Highlight:SetColorTexture(0, 0.6, 1, 0.3)
Slot.NormalTexture:SetSize(0.01, 0.01)
local QuestIcon = Slot.QuestIcon
if(QuestIcon) then
QuestIcon:Hide()
end
local Flash = Slot.Flash
if(Flash) then
Flash:Hide()
end
local BattlePay = Slot.BattlePay
if(BattlePay) then
BattlePay:Hide()
end
end
local function styleBagSlot(Slot)
styleSlot(Slot)
local Parent = Slot:GetParent()
Slot:HookScript('OnEnter', onBagSlotEnter)
Slot:HookScript('OnLeave', onBagSlotLeave)
local isBank = Parent:GetType() == 'bank'
local yOffset = isBank and 10 or 20
local numBags = isBank and NUM_BANKBAGSLOTS or NUM_BAG_SLOTS
Slot:SetPoint('BOTTOMRIGHT', Parent:GetContainer(1), -(((numBags - Slot.index) * (Slot:GetWidth() + 4)) + 10), yOffset)
end
local function styleContainer(Container)
local isBank = Container:GetParent():GetType() == 'bank'
Container:SetBackdrop(BACKDROP)
Container:SetBackdropColor(0.1, 0.1, 0.1, 0.5)
Container:SetBackdropBorderColor(0, 0, 0)
Container:SetSlotSize(32, 32)
Container:SetSlotSpacing(4)
Container:SetSlotPadding(10)
Container:SetSlotRelPoint('TOPLEFT')
Container:SetSlotGrowDirection('RIGHT', 'DOWN')
Container:SetMaxColumns(8)
Container:SetSpacing(2)
if(isBank) then
Container:SetRelPoint('TOPLEFT')
Container:SetGrowDirection('RIGHT', 'DOWN')
else
Container:SetRelPoint('BOTTOMRIGHT')
Container:SetGrowDirection('LEFT', 'UP')
end
local Name = Container:CreateFontString('$parentName', 'ARTWORK', 'PixelFontNormal')
Name:SetPoint('TOPLEFT', 11, -10)
Name:SetText(Container:GetLocalizedName())
local category = Container:GetName()
if(category == 'Inventory' and not isBank) then
local SearchZone = CreateFrame('Button', nil, Container)
SearchZone:SetPoint('BOTTOMLEFT')
SearchZone:SetPoint('BOTTOMRIGHT')
SearchZone:SetHeight(20)
SearchZone:SetAlpha(0)
SearchZone:SetBackdrop(BACKDROP)
SearchZone:SetBackdropColor(0, 0, 0, 0.9)
SearchZone:SetBackdropBorderColor(0, 0, 0)
SearchZone:RegisterForClicks('AnyUp')
SearchZone:SetScript('OnClick', onSearchClick)
SearchZone:SetScript('OnEnter', onSearchEnter)
SearchZone:SetScript('OnLeave', onSearchLeave)
local SearchZoneIcon = SearchZone:CreateTexture('$parentIcon', 'OVERLAY')
SearchZoneIcon:SetPoint('CENTER')
SearchZoneIcon:SetSize(16, 16)
SearchZoneIcon:SetTexture(ICONS)
SearchZoneIcon:SetTexCoord(0.75, 1, 0.75, 1)
SearchZone.Icon = SearchZoneIcon
local Search = Container:AddWidget('Search')
Search:SetPoint('TOPLEFT', SearchZone, 25, 0)
Search:SetPoint('BOTTOMRIGHT', SearchZone, -5, 0)
Search:SetFontObject('PixelFontNormal')
Search:SetAutoFocus(true)
Search:SetFrameLevel(Search:GetFrameLevel() + 2)
Search:HookScript('OnEscapePressed', onSearchEscape)
Search:Hide()
Search.SearchZone = SearchZone
SearchZone.Search = Search
local SearchIcon = Search:CreateTexture('$parentIcon', 'OVERLAY')
SearchIcon:SetPoint('RIGHT', Search, 'LEFT', -4, 0)
SearchIcon:SetSize(16, 16)
SearchIcon:SetTexture(ICONS)
SearchIcon:SetTexCoord(0.75, 1, 0.75, 1)
local Money = Container:AddWidget('Money')
Money:SetPoint('BOTTOMRIGHT', -8, 6)
Money.Label:SetFontObject('PixelFontNormal')
local Currencies = Container:AddWidget('Currencies')
Currencies:SetPoint('BOTTOMLEFT', 8, 6)
Currencies:SetSize(1, 1)
for index, Currency in next, Currencies.buttons do
Currency.Label:SetFontObject('PixelFontNormal')
Currency.Icon:SetTexCoord(0.08, 0.92, 0.08, 0.92)
if(index ~= 1) then
Currency:ClearAllPoints()
Currency:SetPoint('BOTTOMLEFT', Currencies.buttons[index - 1], 'BOTTOMRIGHT', 5, 0)
end
end
Container:SetPadding(10, 0, 26, 16)
else
Container:SetPadding(10, 0, 26, 0)
end
if(category == 'Junk' and not isBank) then
local AutoVendor = Container:AddWidget('AutoVendor')
AutoVendor:SetPoint('TOPRIGHT', -8, -6)
AutoVendor:SetSize(16, 16)
AutoVendor:SetNormalTexture(ICONS)
AutoVendor:GetNormalTexture():SetTexCoord(0, 0.25, 0, 0.25)
AutoVendor:HookScript('OnClick', onAutoVendorClick)
onAutoVendorClick(AutoVendor)
elseif(category == 'New') then
local MarkKnown = Container:AddWidget('MarkKnown')
MarkKnown:SetPoint('TOPRIGHT', -8, -6)
MarkKnown:SetSize(16, 16)
MarkKnown:SetNormalTexture(ICONS)
MarkKnown:GetNormalTexture():SetTexCoord(0.75, 1, 0, 0.25)
elseif(category == 'ReagentBank') then
local Deposit = Container:AddWidget('Deposit')
Deposit:SetPoint('TOPRIGHT', -28, -6)
Deposit:SetSize(16, 16)
Deposit:SetNormalTexture(ICONS)
Deposit:GetNormalTexture():SetTexCoord(0.5, 0.75, 0, 0.25)
local AutoDeposit = Container:AddWidget('AutoDeposit')
AutoDeposit:SetPoint('TOPRIGHT', -48, -6)
AutoDeposit:SetSize(16, 16)
AutoDeposit:SetNormalTexture(ICONS)
AutoDeposit:GetNormalTexture():SetTexCoord(0.5, 0.75, 0, 0.25)
AutoDeposit:HookScript('OnClick', onAutoDepositClick)
onAutoDepositClick(AutoDeposit)
local PurchaseButton = CreateFrame('Button', nil, Container)
PurchaseButton:SetPoint('TOPLEFT', 50, -30)
PurchaseButton:SetPoint('BOTTOMRIGHT', -50, 20)
PurchaseButton:SetBackdrop(BACKDROP)
PurchaseButton:SetBackdropColor(0.1, 0.1, 0.1, 0.5)
PurchaseButton:SetBackdropBorderColor(0, 0, 0)
PurchaseButton:SetNormalFontObject('PixelFontNormal')
PurchaseButton:SetText(BANKSLOTPURCHASE)
PurchaseButton:SetScript('OnClick', onReagentBankPurchaseButtonClick)
Container.PurchaseReagentBankButton = PurchaseButton
end
if(category == 'Inventory') then
local Bags = Container:AddWidget('Bags')
Bags:SetPoint('TOPRIGHT', -28, -6)
Bags:SetSize(16, 16)
Bags:SetNormalTexture(ICONS)
Bags:GetNormalTexture():SetTexCoord(0, 0.25, 0.25, 0.5)
Bags:HookScript('OnClick', onBagSlotsToggle)
end
if(category == 'Inventory' or category == 'ReagentBank') then
local Restack = Container:AddWidget('Restack')
Restack:SetPoint('TOPRIGHT', -8, -6)
Restack:SetSize(16, 16)
Restack:SetNormalTexture(ICONS)
Restack:GetNormalTexture():SetTexCoord(0.25, 0.5, 0, 0.25)
Container:On('PostUpdateSize', containerUpdateSize)
end
end
local Bags = LibContainer:New('bags', addOnName .. 'Bags', UIParent)
Bags:On('PostCreateSlot', styleSlot)
Bags:On('PostCreateContainer', styleContainer)
Bags:On('PostCreateBagSlot', styleBagSlot)
Bags:SetPoint('BOTTOMRIGHT', -50, 50)
Bags:AddFreeSlot()
Bags:AddBagSlots()
Bags:OverrideToggles()
local Bank = LibContainer:New('bank', addOnName .. 'Bank', UIParent)
Bank:On('PostCreateSlot', styleSlot)
Bank:On('PostCreateContainer', styleContainer)
Bank:On('PostCreateBagSlot', styleBagSlot)
Bank:SetPoint('TOPLEFT', 50, -50)
Bank:AddFreeSlot()
Bank:AddBagSlots()
Dropdown = LDD:NewMenu(Bags)
Dropdown:SetStyle(addOnName)