-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.lua
88 lines (74 loc) · 2.7 KB
/
main.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
local Addon = Bagnon
local ItemSlot = Addon.ItemSlot
local UpdateBorder = ItemSlot.UpdateBorder
local Search = LibStub('CustomSearch-1.0')
local ItemSearch = LibStub('LibItemSearch-1.2')
-- Creates a list of icons for each item slot which represent the existing equipment sets by
-- their current icons
local function CreateIcons(slot)
local equipmentSetIcons = {}
for i = 0, C_EquipmentSet.GetNumEquipmentSets() - 1 do
local name, iconTexture = C_EquipmentSet.GetEquipmentSetInfo(i)
local icon = slot:CreateTexture(nil, 'OVERLAY')
icon:SetTexture(iconTexture)
icon:SetSize(15, 15)
equipmentSetIcons[name] = icon
end
slot.EquipmentSetIcons = equipmentSetIcons
return equipmentSetIcons
end
-- Called when the inventory is loaded for each item
function ItemSlot:UpdateBorder()
UpdateBorder(self)
local item = self:GetItem()
local equipmentSetIcons = self.EquipmentSetIcons or CreateIcons(self)
-- self:HideBorder()
-- Hide all equipment set icons first
for curName, _ in pairs(equipmentSetIcons) do
equipmentSetIcons[curName]:Hide()
end
-- If this is an equipment set item
if item then
if ItemSearch:InSet(item) then
-- Figure out which ones it belongs to
local equipmentSets = GetEquipmentSetNames(item)
-- For every equipment set this belongs to:
local iteration = 0
for equipmentSetName, _ in pairs(equipmentSets) do
-- Set the draw layer (so the icons render over each other properly),
-- the position, and display the icon
equipmentSetIcons[equipmentSetName]:SetDrawLayer('OVERLAY', (7 - iteration))
equipmentSetIcons[equipmentSetName]:SetPoint('BOTTOMLEFT',
(iteration * (equipmentSetIcons[equipmentSetName]:GetWidth() / 2)),
0)
equipmentSetIcons[equipmentSetName]:SetShown(true)
iteration = iteration + 1
-- Note: Due to inventory item frame size constraints,
-- the max number of equipment sets we will display for a single item is 3.
if iteration == 3 then
break
end
end
return true
end
end
end
-- Gets the equipment set names for a single item
function GetEquipmentSetNames(link, search)
local equipmentSets = {}
if IsEquippableItem(link) then
local id = tonumber(link:match('item:(%-?%d+)'))
for i = 1, C_EquipmentSet.GetNumEquipmentSets() do
local name, _, setID = C_EquipmentSet.GetEquipmentSetInfo(i - 1)
if Search:Find((search or ''):lower(), name) then
local items = C_EquipmentSet.GetItemIDs(setID)
for _, item in pairs(items) do
if id == item then
equipmentSets[name] = true
end
end
end
end
end
return equipmentSets
end