vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | --[[ |
2 | item.lua |
||
3 | Functions used by the item slots in Bagnon |
||
4 | |||
5 | TODO: |
||
6 | Code review |
||
7 | Ability to disable item borders |
||
8 | 1.11 code improvements |
||
9 | --]] |
||
10 | |||
11 | BAGNON_HEX = { |
||
12 | ["a"] = 10, |
||
13 | ["b"] = 11, |
||
14 | ["c"] = 12, |
||
15 | ["d"] = 13, |
||
16 | ["e"] = 14, |
||
17 | ["f"] = 15, |
||
18 | ["0"] = 0, |
||
19 | ["1"] = 1, |
||
20 | ["2"] = 2, |
||
21 | ["3"] = 3, |
||
22 | ["4"] = 4, |
||
23 | ["5"] = 5, |
||
24 | ["6"] = 6, |
||
25 | ["7"] = 7, |
||
26 | ["8"] = 8, |
||
27 | ["9"] = 9, |
||
28 | }; |
||
29 | |||
30 | --[[ Item Button Constructor ]]-- |
||
31 | function BagnonItem_Create(name, parent) |
||
32 | --[[ |
||
33 | this is purely for compatibility with mods that need the same structure as a blizzard bag |
||
34 | Blizzard bag functions use item:GetID() to reference the item slot, and item:GetParent():GetID() to reference their bag |
||
35 | |||
36 | I'm fairly certain that the memory impact is still quite minimal. |
||
37 | --]] |
||
38 | local dummyBag = CreateFrame("Frame", nil, parent); |
||
39 | |||
40 | --create the button |
||
41 | local button = CreateFrame("Button", name, dummyBag); |
||
42 | button:SetHeight(37); |
||
43 | button:SetWidth(37); |
||
44 | |||
45 | --[[ Textures ]]-- |
||
46 | |||
47 | --border |
||
48 | local border = button:CreateTexture(name .. "Border", "OVERLAY"); |
||
49 | border:SetTexture("Interface\\Buttons\\UI-ActionButton-Border"); |
||
50 | border:SetBlendMode("ADD"); |
||
51 | border:SetHeight(68); |
||
52 | border:SetWidth(68); |
||
53 | border:SetPoint("CENTER", button, "CENTER", 0, 1); |
||
54 | |||
55 | --icon texture |
||
56 | local iconTexture = button:CreateTexture(name .. "IconTexture", "BORDER"); |
||
57 | iconTexture:SetAllPoints(button); |
||
58 | |||
59 | --normal, pushed, highlight |
||
60 | local normalTexture = button:CreateTexture(name .. "NormalTexture"); |
||
61 | normalTexture:SetTexture("Interface\\Buttons\\UI-Quickslot2"); |
||
62 | normalTexture:SetHeight(64); |
||
63 | normalTexture:SetWidth(64); |
||
64 | normalTexture:SetPoint("CENTER", button, "CENTER", 0, -1); |
||
65 | button:SetNormalTexture(normalTexture); |
||
66 | button:SetPushedTexture("Interface\\Buttons\\UI-Quickslot-Depress"); |
||
67 | button:SetHighlightTexture("Interface\\Buttons\\ButtonHilight-Square"); |
||
68 | |||
69 | --[[ Font Strings ]]-- |
||
70 | local count = button:CreateFontString(name .. "Count", "BORDER"); |
||
71 | count:SetFontObject(NumberFontNormal); |
||
72 | count:SetPoint("BOTTOMRIGHT", button, "BOTTOMRIGHT", -2, 2); |
||
73 | count:SetJustifyH("RIGHT"); |
||
74 | count:Hide(); |
||
75 | |||
76 | local stock = button:CreateFontString(name .. "Stock", "BORDER"); |
||
77 | stock:SetFontObject(NumberFontNormalYellow); |
||
78 | stock:SetPoint("TOPLEFT", button, "TOPLEFT", 0, -2); |
||
79 | stock:SetJustifyH("LEFT"); |
||
80 | stock:Hide(); |
||
81 | |||
82 | --[[ Frames ]]-- |
||
83 | |||
84 | --cooldown model |
||
85 | local cooldown = CreateFrame("Model", name .. "Cooldown", button); |
||
86 | cooldown:SetScale(0.85); |
||
87 | cooldown:SetAllPoints(button); |
||
88 | cooldown:SetModel("Interface\\Cooldown\\UI-Cooldown-Indicator.mdx"); |
||
89 | cooldown:Hide(); |
||
90 | |||
91 | cooldown:SetScript("OnUpdateModel", CooldownFrame_OnUpdateModel); |
||
92 | cooldown:SetScript("OnAnimFinished", CooldownFrame_OnAnimFinished); |
||
93 | |||
94 | button:Hide(); |
||
95 | |||
96 | --[[ Scripts ]]-- |
||
97 | |||
98 | button:SetScript("OnUpdate", function() |
||
99 | BagnonItem_OnUpdate() |
||
100 | end); |
||
101 | |||
102 | button:SetScript("OnClick", function() |
||
103 | BagnonItem_OnClick(arg1); |
||
104 | end); |
||
105 | |||
106 | button:SetScript("OnHide", function() |
||
107 | if ( this.hasStackSplit and (this.hasStackSplit == 1) ) then |
||
108 | StackSplitFrame:Hide(); |
||
109 | end |
||
110 | end); |
||
111 | |||
112 | button:SetScript("OnEnter", function() |
||
113 | BagnonItem_OnEnter(this); |
||
114 | end); |
||
115 | |||
116 | button:SetScript("OnLeave", function() |
||
117 | this.updateTooltip = nil; |
||
118 | GameTooltip:Hide(); |
||
119 | ResetCursor(); |
||
120 | end); |
||
121 | |||
122 | button:SetScript("OnDragStart", function() |
||
123 | BagnonItem_OnClick("LeftButton", 1); |
||
124 | end); |
||
125 | |||
126 | button:SetScript("OnReceiveDrag", function() |
||
127 | BagnonItem_OnClick("LeftButton", 1); |
||
128 | end); |
||
129 | |||
130 | button:RegisterForClicks("LeftButtonUp", "RightButtonUp"); |
||
131 | button:RegisterForDrag("LeftButton"); |
||
132 | |||
133 | --Fix for AxuItemMenus |
||
134 | if(AxuItemMenus_DropDown) then |
||
135 | button.SplitStack = function(itemButton, split) SplitContainerItem( itemButton:GetParent():GetID() , itemButton:GetID(), split); end; |
||
136 | end |
||
137 | |||
138 | return button; |
||
139 | end |
||
140 | |||
141 | function BagnonItem_OnClick(mouseButton, ignoreModifiers) |
||
142 | if ( this.isLink ) then |
||
143 | if(this.hasItem) then |
||
144 | if ( mouseButton == "LeftButton" ) then |
||
145 | if ( IsControlKeyDown() ) then |
||
146 | DressUpItemLink( BagnonDB_GetItemData(this) ); |
||
147 | elseif( IsShiftKeyDown() ) then |
||
148 | ChatFrameEditBox:Insert( BagnonDB_GetFullItemLink(this) ); |
||
149 | end |
||
150 | end |
||
151 | end |
||
152 | else |
||
153 | ContainerFrameItemButton_OnClick(mouseButton, ignoreModifiers); |
||
154 | end |
||
155 | end |
||
156 | |||
157 | --[[ |
||
158 | Show tooltip on hover |
||
159 | --]] |
||
160 | |||
161 | function BagnonItem_OnEnter(button) |
||
162 | --link case |
||
163 | if(button.isLink) then |
||
164 | if(button.hasItem)then |
||
165 | GameTooltip:SetOwner(button); |
||
166 | local link, _, count = BagnonDB_GetItemData(button); |
||
167 | --this is a tweak for one of my personal mods, Ludwig. It allows for mods to add sellvalue to linked items. |
||
168 | GameTooltip:SetHyperlink( link, count ); |
||
169 | |||
170 | Bagnon_AnchorTooltip(button); |
||
171 | end |
||
172 | --normal bag case |
||
173 | else |
||
174 | --blizzard totally needs to make the bank button not a special case |
||
175 | if( button:GetParent():GetID() == -1) then |
||
176 | GameTooltip:SetOwner(button); |
||
177 | GameTooltip:SetInventoryItem("player", BankButtonIDToInvSlotID( button:GetID() ) ); |
||
178 | --normal item case |
||
179 | else |
||
180 | ContainerFrameItemButton_OnEnter(button); |
||
181 | end |
||
182 | |||
183 | --Don't reposition tooltips for things using EnhTooltip |
||
184 | if(not EnhTooltip) then |
||
185 | Bagnon_AnchorTooltip(button); |
||
186 | end |
||
187 | end |
||
188 | end |
||
189 | |||
190 | function BagnonItem_OnUpdate() |
||
191 | if ( GameTooltip:IsOwned(this) ) then |
||
192 | BagnonItem_OnEnter(this); |
||
193 | end |
||
194 | end |
||
195 | |||
196 | --[[ |
||
197 | Update tooltip info |
||
198 | --]] |
||
199 | |||
200 | --Adapted from OneBag. The author had a clever idea of using the link to generate the color instead of getting the quality, then the color |
||
201 | function BagnonItem_UpdateBorder(button) |
||
202 | local link = GetContainerItemLink(button:GetParent():GetID() , button:GetID()); |
||
203 | |||
204 | if(link) then |
||
205 | --item border coloring |
||
206 | local _, _, hexString = strfind( link ,"|cff(%w+)|H"); |
||
207 | local red = ( 16 * BAGNON_HEX[string.sub(hexString, 1, 1)] + BAGNON_HEX[string.sub(hexString, 2, 2)] ) / 256; |
||
208 | local green = ( 16 * BAGNON_HEX[string.sub(hexString, 3, 3)] + BAGNON_HEX[string.sub(hexString, 4, 4)] ) / 256; |
||
209 | local blue = ( 16 * BAGNON_HEX[string.sub(hexString, 5, 5)] + BAGNON_HEX[string.sub(hexString, 6, 6)] ) / 256; |
||
210 | |||
211 | local border = getglobal(button:GetName() .. "Border"); |
||
212 | if( border and (red ~= green and red ~= blue ) ) then |
||
213 | border:SetVertexColor(red, green, blue, 0.4); |
||
214 | border:Show(); |
||
215 | else |
||
216 | border:Hide(); |
||
217 | end |
||
218 | else |
||
219 | --ammo slot coloring |
||
220 | getglobal(button:GetName() .. "Border"):Hide(); |
||
221 | |||
222 | local bagID = button:GetParent():GetID(); |
||
223 | if( bagID == KEYRING_CONTAINER) then |
||
224 | getglobal(button:GetName() .. "NormalTexture"):SetVertexColor(1, 0.7, 0); |
||
225 | elseif( Bagnon_IsAmmoBag( bagID ) ) then |
||
226 | getglobal(button:GetName() .. "NormalTexture"):SetVertexColor(1, 1, 0); |
||
227 | elseif( Bagnon_IsProfessionBag( bagID ) ) then |
||
228 | getglobal(button:GetName() .. "NormalTexture"):SetVertexColor(0, 1, 0); |
||
229 | else |
||
230 | getglobal(button:GetName() .. "NormalTexture"):SetVertexColor(1, 1, 1); |
||
231 | end |
||
232 | end |
||
233 | end |
||
234 | |||
235 | function BagnonItem_UpdateLinkBorder(item) |
||
236 | local iLink = ( BagnonDB_GetItemData(item) ); |
||
237 | |||
238 | if(iLink) then |
||
239 | local name, link, quality = GetItemInfo( iLink ); |
||
240 | local red, green, blue; |
||
241 | |||
242 | if(quality) then |
||
243 | red, green, blue = GetItemQualityColor(quality); |
||
244 | end |
||
245 | |||
246 | if( getglobal(item:GetName() .. "Border") and (red ~= green and red ~= blue) ) then |
||
247 | getglobal(item:GetName() .. "Border"):SetVertexColor(red, green, blue, 0.4); |
||
248 | getglobal(item:GetName() .. "Border"):Show(); |
||
249 | else |
||
250 | getglobal(item:GetName() .. "Border"):Hide(); |
||
251 | end |
||
252 | else |
||
253 | getglobal(item:GetName() .. "Border"):Hide(); |
||
254 | end |
||
255 | |||
256 | getglobal(item:GetName() .. "NormalTexture"):SetVertexColor(1, 1, 1); |
||
257 | end |
||
258 | |||
259 | --[[ |
||
260 | Update cooldown |
||
261 | It mainly handles the special case of |
||
262 | --]] |
||
263 | |||
264 | function BagnonItem_UpdateCooldown(container, button) |
||
265 | if(button.isLink) then |
||
266 | CooldownFrame_SetTimer(getglobal(button:GetName().."Cooldown"), 0, 0, 0); |
||
267 | else |
||
268 | local cooldown = getglobal(button:GetName().."Cooldown"); |
||
269 | local start, duration, enable = GetContainerItemCooldown( container, button:GetID() ); |
||
270 | |||
271 | CooldownFrame_SetTimer(cooldown, start, duration, enable); |
||
272 | |||
273 | if ( duration > 0 and enable == 0 ) then |
||
274 | SetItemButtonTextureVertexColor(button, 0.4, 0.4, 0.4); |
||
275 | end |
||
276 | end |
||
277 | end |