-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathslots.lua
More file actions
176 lines (147 loc) · 4.49 KB
/
slots.lua
File metadata and controls
176 lines (147 loc) · 4.49 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
local _NAME, _NS = ...
local Butsu = _G[_NAME]
local slots = {}
_NS.slots = slots
local OnEnter = function(self)
local slot = self:GetID()
if(GetLootSlotType(slot) == LOOT_SLOT_ITEM) then
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:SetLootItem(slot)
CursorUpdate(self)
end
if(self.drop:IsShown()) then
local r, g, b = self.drop:GetVertexColor()
self.drop:SetVertexColor(r * .6, g * .6, b * .6)
else
self.drop:SetVertexColor(1, 1, 0)
end
self.drop:Show()
end
local OnLeave = function(self)
if(self.quality and self.quality > 1) then
local color = ITEM_QUALITY_COLORS[self.quality]
self.drop:SetVertexColor(color.r, color.g, color.b)
elseif(self.isQuestItem) then
self.drop:SetVertexColor(1, 1, .2)
else
self.drop:Hide()
end
GameTooltip:Hide()
ResetCursor()
end
local OnClick = function(self)
if(IsModifiedClick()) then
HandleModifiedItemClick(GetLootSlotLink(self:GetID()))
else
StaticPopup_Hide"CONFIRM_LOOT_DISTRIBUTION"
LootFrame.selectedLootButton = self
LootFrame.selectedSlot = self:GetID()
LootFrame.selectedQuality = self.quality
LootFrame.selectedItemName = self.name:GetText()
LootSlot(self:GetID())
end
end
local OnUpdate = function(self)
if(GameTooltip:IsOwned(self)) then
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:SetLootItem(self:GetID())
CursorOnUpdate(self)
end
end
function _NS.CreateSlot(id)
local db = _NS.db
local iconSize = db.iconSize
local fontSizeItem = db.fontSizeItem
local fontSizeCount = db.fontSizeCount
local fontItem = GameFontWhite:GetFont()
local fontCount = NumberFontNormalSmall:GetFont()
local frame = CreateFrame("Button", 'ButsuSlot'..id, Butsu)
frame:SetHeight(math.max(fontSizeItem, iconSize))
frame:SetID(id)
frame:RegisterForClicks("LeftButtonUp", "RightButtonUp")
frame:SetScript("OnEnter", OnEnter)
frame:SetScript("OnLeave", OnLeave)
frame:SetScript("OnClick", OnClick)
frame:SetScript("OnUpdate", OnUpdate)
local iconFrame = CreateFrame("Frame", nil, frame)
iconFrame:SetSize(iconSize, iconSize)
iconFrame:SetPoint("RIGHT", frame)
frame.iconFrame = iconFrame
local icon = iconFrame:CreateTexture(nil, "ARTWORK")
icon:SetAlpha(.8)
icon:SetTexCoord(.07, .93, .07, .93)
icon:SetAllPoints(iconFrame)
frame.icon = icon
local quest = iconFrame:CreateTexture(nil, 'OVERLAY')
quest:SetTexture([[Interface\Minimap\ObjectIcons]])
quest:SetTexCoord(1/8, 2/8, 1/8, 2/8)
quest:SetSize(iconSize * .8, iconSize * .8)
quest:SetPoint('BOTTOMLEFT', -iconSize * .15, 0)
frame.quest = quest
local count = iconFrame:CreateFontString(nil, "OVERLAY")
count:SetJustifyH"RIGHT"
count:SetPoint("BOTTOMRIGHT", iconFrame, 2, 2)
count:SetFont(fontCount, fontSizeCount, 'OUTLINE')
count:SetShadowOffset(.8, -.8)
count:SetShadowColor(0, 0, 0, 1)
count:SetText(1)
frame.count = count
local name = frame:CreateFontString(nil, "OVERLAY")
name:SetJustifyH"LEFT"
name:SetPoint("LEFT", frame)
name:SetPoint("RIGHT", iconFrame, "LEFT")
name:SetNonSpaceWrap(true)
name:SetFont(fontItem, fontSizeItem)
name:SetShadowOffset(.8, -.8)
name:SetShadowColor(0, 0, 0, 1)
frame.name = name
local drop = frame:CreateTexture(nil, "ARTWORK")
drop:SetTexture[[Interface\QuestFrame\UI-QuestLogTitleHighlight]]
drop:SetPoint("LEFT", icon, "RIGHT")
drop:SetPoint("RIGHT", frame)
drop:SetAllPoints(frame)
drop:SetAlpha(.3)
frame.drop = drop
slots[id] = frame
return frame
end
function Butsu:UpdateWidth()
local maxWidth = 0
for _, slot in next, _NS.slots do
if(slot:IsShown()) then
local width = slot.name:GetStringWidth()
if(width > maxWidth) then
maxWidth = width
end
end
end
self:SetWidth(math.max(maxWidth + 30 + _NS.db.iconSize, self.title:GetStringWidth() + 5))
end
function Butsu:AnchorSlots()
local frameSize = math.max(_NS.db.iconSize, _NS.db.fontSizeItem)
local iconSize = _NS.db.iconSize
local shownSlots = 0
local prevShown
for i=1, #slots do
local frame = slots[i]
if(frame:IsShown()) then
frame:ClearAllPoints()
frame:SetPoint("LEFT", 8, 0)
frame:SetPoint("RIGHT", -8, 0)
if(not prevShown) then
frame:SetPoint('TOPLEFT', self, 8, -8)
else
frame:SetPoint('TOP', prevShown, 'BOTTOM')
end
frame:SetHeight(frameSize)
shownSlots = shownSlots + 1
prevShown = frame
end
end
local offset = self:GetTop() or 0
self:SetHeight(math.max((shownSlots * frameSize + 16), 20))
-- Reposition the frame so it doesn't move.
local point, parent, relPoint, x, y = self:GetPoint()
offset = offset - (self:GetTop() or 0)
self:SetPoint(point, parent, relPoint, x, y + offset)
end