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 | --]] |
||
9 | |||
10 | --[[ |
||
11 | Item Button Constructor |
||
12 | The dummyBag is purely for compatibility with mods that need the same structure as a blizzard bag |
||
13 | Blizzard bag functions use item:GetID() to reference the item slot, and item:GetParent():GetID() to reference their bag |
||
14 | |||
15 | I'm fairly certain that the memory impact is still quite minimal. |
||
16 | --]] |
||
17 | |||
18 | function BagnonItem_Create(name, parent) |
||
19 | --create the button |
||
20 | local button = CreateFrame("Button", name, parent, "BagnonItemTemplate"); |
||
21 | button:SetAlpha(parent:GetParent():GetAlpha()); |
||
22 | |||
23 | button:RegisterForClicks("LeftButtonUp", "RightButtonUp"); |
||
24 | button:RegisterForDrag("LeftButton"); |
||
25 | |||
26 | --Fix for AxuItemMenus |
||
27 | if(AxuItemMenus_DropDown) then |
||
28 | button.SplitStack = function(itemButton, split) SplitContainerItem( itemButton:GetParent():GetID() , itemButton:GetID(), split); end; |
||
29 | end |
||
30 | |||
31 | return button; |
||
32 | end |
||
33 | |||
34 | function BagnonItem_OnClick(mouseButton, ignoreModifiers) |
||
35 | if ( this.isLink ) then |
||
36 | if(this.hasItem) then |
||
37 | if ( mouseButton == "LeftButton" ) then |
||
38 | if ( IsControlKeyDown() ) then |
||
39 | local itemSlot = this:GetID(); |
||
40 | local bagID = this:GetParent():GetID(); |
||
41 | local player = this:GetParent():GetParent().player; |
||
42 | |||
43 | DressUpItemLink( (BagnonDB.GetItemData(player, bagID, itemSlot)) ); |
||
44 | elseif( IsShiftKeyDown() ) then |
||
45 | local itemSlot = this:GetID(); |
||
46 | local bagID = this:GetParent():GetID(); |
||
47 | local player = this:GetParent():GetParent().player; |
||
48 | |||
49 | ChatFrameEditBox:Insert( BagnonDB.GetItemHyperlink(player, bagID, itemSlot) ); |
||
50 | end |
||
51 | end |
||
52 | end |
||
53 | else |
||
54 | ContainerFrameItemButton_OnClick(mouseButton, ignoreModifiers); |
||
55 | end |
||
56 | end |
||
57 | |||
58 | --[[ |
||
59 | Show tooltip on hover |
||
60 | --]] |
||
61 | |||
62 | function BagnonItem_OnEnter(item) |
||
63 | --link case |
||
64 | if(item.isLink) then |
||
65 | if(item.hasItem)then |
||
66 | GameTooltip:SetOwner(item); |
||
67 | |||
68 | local itemSlot = item:GetID(); |
||
69 | local bagID = item:GetParent():GetID(); |
||
70 | local player = item:GetParent():GetParent().player; |
||
71 | |||
72 | local link, count = BagnonDB.GetItemData(player, bagID, itemSlot); |
||
73 | GameTooltip:SetHyperlink( link, count ); |
||
74 | |||
75 | Bagnon_AnchorTooltip(item); |
||
76 | end |
||
77 | --normal bag case |
||
78 | else |
||
79 | --blizzard totally needs to make the bank item not a special case |
||
80 | if( item:GetParent():GetID() == -1) then |
||
81 | GameTooltip:SetOwner(item); |
||
82 | GameTooltip:SetInventoryItem("player", BankButtonIDToInvSlotID( item:GetID() ) ); |
||
83 | --normal item case |
||
84 | else |
||
85 | ContainerFrameItemButton_OnEnter(item); |
||
86 | end |
||
87 | |||
88 | --Don't reposition tooltips for things using EnhTooltip |
||
89 | if(not EnhTooltip) then |
||
90 | Bagnon_AnchorTooltip(item); |
||
91 | end |
||
92 | end |
||
93 | end |
||
94 | |||
95 | function BagnonItem_OnUpdate() |
||
96 | if ( GameTooltip:IsOwned(this) ) then |
||
97 | BagnonItem_OnEnter(this); |
||
98 | end |
||
99 | end |
||
100 | |||
101 | --[[ |
||
102 | Update Functions |
||
103 | --]] |
||
104 | |||
105 | -- Update the texture, lock status, and other information about an item |
||
106 | function BagnonItem_Update(item) |
||
107 | local itemLink, texture, itemCount, readable, locked; |
||
108 | |||
109 | if( Bagnon_IsCachedItem(item) ) then |
||
110 | item.isLink = 1; |
||
111 | |||
112 | local itemSlot = item:GetID(); |
||
113 | local bagID = item:GetParent():GetID(); |
||
114 | local player = item:GetParent():GetParent().player; |
||
115 | |||
116 | _, itemCount, texture, quality = BagnonDB.GetItemData(player, bagID, itemSlot); |
||
117 | BagnonItem_UpdateLinkBorder(item, quality); |
||
118 | |||
119 | if ( texture ) then |
||
120 | item.hasItem = 1; |
||
121 | else |
||
122 | item.hasItem = nil; |
||
123 | end |
||
124 | |||
125 | --hide cooldown since there isn't one for linked items |
||
126 | BagnonItem_UpdateCooldown(bagID, item); |
||
127 | else |
||
128 | item.isLink = nil; |
||
129 | |||
130 | texture, itemCount, locked, _, readable = GetContainerItemInfo(item:GetParent():GetID(), item:GetID()); |
||
131 | BagnonItem_UpdateBorder(item); |
||
132 | |||
133 | if ( texture ) then |
||
134 | BagnonItem_UpdateCooldown(item:GetParent():GetID() , item); |
||
135 | item.hasItem = 1; |
||
136 | else |
||
137 | getglobal(item:GetName() .. "Cooldown"):Hide(); |
||
138 | item.hasItem = nil; |
||
139 | end |
||
140 | |||
141 | SetItemButtonDesaturated(item, locked, 0.5, 0.5, 0.5); |
||
142 | item.readable = readable; |
||
143 | end |
||
144 | |||
145 | --update texture and count |
||
146 | SetItemButtonTexture( item, texture ); |
||
147 | SetItemButtonCount( item, itemCount ); |
||
148 | end |
||
149 | |||
150 | function BagnonItem_UpdateBorder(button) |
||
151 | local bagID = button:GetParent():GetID(); |
||
152 | |||
153 | if BagnonSets.qualityBorders then |
||
154 | --Adapted from OneBag. The author had a clever idea of using the link to generate the color |
||
155 | local link = ( GetContainerItemLink(bagID , button:GetID()) ); |
||
156 | if link then |
||
157 | local _, _, hexString = strfind(link ,"|cff([%l%d]+)|H"); |
||
158 | local red = tonumber(strsub(hexString, 1, 2), 16)/256; |
||
159 | local green = tonumber(strsub(hexString, 3, 4), 16)/256; |
||
160 | local blue = tonumber(strsub(hexString, 5, 6), 16)/256; |
||
161 | if red ~= green and red ~= blue then |
||
162 | getglobal(button:GetName() .. "Border"):SetVertexColor(red, green, blue, 0.5); |
||
163 | getglobal(button:GetName() .. "Border"):Show(); |
||
164 | else |
||
165 | getglobal(button:GetName() .. "Border"):Hide(); |
||
166 | end |
||
167 | else |
||
168 | getglobal(button:GetName() .. "Border"):Hide(); |
||
169 | end |
||
170 | else |
||
171 | getglobal(button:GetName() .. "Border"):Hide(); |
||
172 | end |
||
173 | |||
174 | --ammo slot coloring |
||
175 | if( bagID == KEYRING_CONTAINER ) then |
||
176 | getglobal(button:GetName() .. "NormalTexture"):SetVertexColor(1, 0.7, 0); |
||
177 | elseif( Bagnon_IsAmmoBag( bagID ) ) then |
||
178 | getglobal(button:GetName() .. "NormalTexture"):SetVertexColor(1, 1, 0); |
||
179 | elseif( Bagnon_IsProfessionBag( bagID ) ) then |
||
180 | getglobal(button:GetName() .. "NormalTexture"):SetVertexColor(0, 1, 0); |
||
181 | else |
||
182 | getglobal(button:GetName() .. "NormalTexture"):SetVertexColor(1, 1, 1); |
||
183 | end |
||
184 | end |
||
185 | |||
186 | function BagnonItem_UpdateLinkBorder(item, quality) |
||
187 | local itemSlot = item:GetID(); |
||
188 | local bagID = item:GetParent():GetID(); |
||
189 | local player = item:GetParent():GetParent().player; |
||
190 | |||
191 | if( BagnonSets.qualityBorders ) then |
||
192 | if(not quality) then |
||
193 | local link = (BagnonDB.GetItemData(player, bagID, itemSlot)); |
||
194 | if(link) then |
||
195 | _, _, quality = GetItemInfo(link); |
||
196 | end |
||
197 | end |
||
198 | if(quality and quality > 1) then |
||
199 | local red, green, blue = GetItemQualityColor(quality); |
||
200 | getglobal(item:GetName() .. "Border"):SetVertexColor(red, green, blue, 0.5); |
||
201 | getglobal(item:GetName() .. "Border"):Show(); |
||
202 | else |
||
203 | getglobal(item:GetName() .. "Border"):Hide(); |
||
204 | end |
||
205 | else |
||
206 | getglobal(item:GetName() .. "Border"):Hide(); |
||
207 | end |
||
208 | |||
209 | if( bagID == KEYRING_CONTAINER ) then |
||
210 | getglobal(item:GetName() .. "NormalTexture"):SetVertexColor(1, 0.7, 0); |
||
211 | elseif( Bagnon_IsAmmoBag(bagID, player) ) then |
||
212 | getglobal(item:GetName() .. "NormalTexture"):SetVertexColor(1, 1, 0); |
||
213 | elseif( Bagnon_IsProfessionBag(bagID , player) ) then |
||
214 | getglobal(item:GetName() .. "NormalTexture"):SetVertexColor(0, 1, 0); |
||
215 | else |
||
216 | getglobal(item:GetName() .. "NormalTexture"):SetVertexColor(1, 1, 1); |
||
217 | end |
||
218 | end |
||
219 | |||
220 | --Update cooldown |
||
221 | function BagnonItem_UpdateCooldown(container, button) |
||
222 | if(button.isLink) then |
||
223 | CooldownFrame_SetTimer(getglobal(button:GetName().."Cooldown"), 0, 0, 0); |
||
224 | else |
||
225 | local cooldown = getglobal(button:GetName().."Cooldown"); |
||
226 | local start, duration, enable = GetContainerItemCooldown( container, button:GetID() ); |
||
227 | |||
228 | CooldownFrame_SetTimer(cooldown, start, duration, enable); |
||
229 | |||
230 | if ( duration > 0 and enable == 0 ) then |
||
231 | SetItemButtonTextureVertexColor(button, 0.4, 0.4, 0.4); |
||
232 | end |
||
233 | end |
||
234 | end |