vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | --[[ |
2 | Bags.lua |
||
3 | Functions used by Bagnon Bags |
||
4 | --]] |
||
5 | |||
6 | --[[ OnX Functions ]]-- |
||
7 | |||
8 | function BagnonBag_OnLoad() |
||
9 | this:RegisterForDrag("LeftButton"); |
||
10 | this:RegisterForClicks("LeftButtonUp", "RightButtonUp"); |
||
11 | |||
12 | this:RegisterEvent("BAG_UPDATE"); |
||
13 | this:RegisterEvent("ITEM_LOCK_CHANGED"); |
||
14 | this:RegisterEvent("CURSOR_UPDATE"); |
||
15 | this:RegisterEvent("BAG_UPDATE_COOLDOWN"); |
||
16 | |||
17 | if( Bagnon_IsBankBag(this:GetID() ) ) then |
||
18 | this:RegisterEvent("PLAYERBANKBAGSLOTS_CHANGED"); |
||
19 | end |
||
20 | end |
||
21 | |||
22 | function BagnonBag_OnEvent() |
||
23 | if( not this:IsVisible() or Bagnon_IsCachedFrame(this:GetParent():GetParent()) ) then |
||
24 | return; |
||
25 | end |
||
26 | |||
27 | if ( event == "BAG_UPDATE" ) then |
||
28 | if( arg1 == this:GetID() ) then |
||
29 | BagnonBag_Update(this); |
||
30 | BagnonBag_UpdateFrameSize(this:GetParent()); |
||
31 | end |
||
32 | elseif (event == "ITEM_LOCK_CHANGED") then |
||
33 | BagnonBag_UpdateLock(this); |
||
34 | elseif (event == "CURSOR_UPDATE") then |
||
35 | BagnonBag_UpdateCursor(this); |
||
36 | elseif ( event == "PLAYERBANKBAGSLOTS_CHANGED") then |
||
37 | BagnonBag_Update(this); |
||
38 | BagnonBag_UpdateFrameSize(this:GetParent()); |
||
39 | end |
||
40 | end |
||
41 | |||
42 | function BagnonBag_OnShow() |
||
43 | BagnonBag_UpdateTexture(this:GetParent():GetParent(), this:GetID()); |
||
44 | end |
||
45 | |||
46 | function BagnonBag_OnClick() |
||
47 | if ( Bagnon_IsCachedBag(this:GetParent():GetParent().player, this:GetID() ) ) then |
||
48 | return; |
||
49 | end |
||
50 | |||
51 | if(not IsShiftKeyDown() ) then |
||
52 | --damn you blizzard for making the keyring specific code! |
||
53 | if( this:GetID() == KEYRING_CONTAINER ) then |
||
54 | PutKeyInKeyRing(); |
||
55 | else |
||
56 | PutItemInBag(ContainerIDToInventoryID(this:GetID())); |
||
57 | end |
||
58 | else |
||
59 | BagnonFrame_ToggleBag(this:GetParent():GetParent(), this:GetID()); |
||
60 | end |
||
61 | end |
||
62 | |||
63 | function BagnonBag_OnDrag() |
||
64 | if (Bagnon_IsCachedBag(this:GetParent():GetParent().player, this:GetID()) ) then |
||
65 | return; |
||
66 | end |
||
67 | |||
68 | PickupBagFromSlot( ContainerIDToInventoryID(this:GetID()) ); |
||
69 | PlaySound("BAGMENUBUTTONPRESS"); |
||
70 | end |
||
71 | |||
72 | --tooltip functions |
||
73 | function BagnonBag_OnEnter() |
||
74 | local frame = this:GetParent():GetParent(); |
||
75 | |||
76 | BagnonFrame_HighlightSlots(frame, this:GetID()); |
||
77 | |||
78 | if( this:GetLeft() < ( UIParent:GetRight() / 2) ) then |
||
79 | GameTooltip:SetOwner(this, "ANCHOR_RIGHT"); |
||
80 | else |
||
81 | GameTooltip:SetOwner(this, "ANCHOR_LEFT"); |
||
82 | end |
||
83 | |||
84 | --mainmenubag specific code |
||
85 | if( this:GetID() == 0 ) then |
||
86 | GameTooltip:SetText(TEXT(BACKPACK_TOOLTIP), 1.0, 1.0, 1.0); |
||
87 | --keyring specific code...again |
||
88 | elseif ( this:GetID() == KEYRING_CONTAINER ) then |
||
89 | GameTooltip:SetText(KEYRING, HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b); |
||
90 | --cached bags |
||
91 | elseif( Bagnon_IsCachedBag(frame.player, this:GetID()) ) then |
||
92 | local _, link = BagnonDB.GetBagData(frame.player, this:GetID()); |
||
93 | |||
94 | if(link) then |
||
95 | GameTooltip:SetHyperlink( link ); |
||
96 | GameTooltip:Show(); |
||
97 | else |
||
98 | GameTooltip:SetText(TEXT(EQUIP_CONTAINER), 1.0, 1.0, 1.0); |
||
99 | end |
||
100 | elseif ( not GameTooltip:SetInventoryItem("player", ContainerIDToInventoryID(this:GetID()) ) ) then |
||
101 | GameTooltip:SetText(TEXT(EQUIP_CONTAINER), 1.0, 1.0, 1.0); |
||
102 | end |
||
103 | |||
104 | if(not Bagnon_IsCachedBag(frame.player, this:GetID()) ) then |
||
105 | --add the shift click to hide/show tooltip |
||
106 | if(BagnonSets.showTooltips) then |
||
107 | if( Bagnon_FrameHasBag(frame:GetName(), this:GetID()) ) then |
||
108 | GameTooltip:AddLine(BAGNON_BAGS_HIDE); |
||
109 | else |
||
110 | GameTooltip:AddLine(BAGNON_BAGS_SHOW); |
||
111 | end |
||
112 | end |
||
113 | end |
||
114 | |||
115 | GameTooltip:Show(); |
||
116 | end |
||
117 | |||
118 | function BagnonBag_OnLeave() |
||
119 | BagnonFrame_UnhighlightAll(this:GetParent():GetParent()); |
||
120 | GameTooltip:Hide(); |
||
121 | end |
||
122 | |||
123 | --[[ Update Functions ]]-- |
||
124 | |||
125 | function BagnonBag_Update(bag) |
||
126 | local invID = ContainerIDToInventoryID(bag:GetID()); |
||
127 | |||
128 | local textureName = GetInventoryItemTexture("player", invID); |
||
129 | if ( textureName ) then |
||
130 | SetItemButtonTexture(bag, textureName); |
||
131 | BagnonBag_SetCount(bag, GetInventoryItemCount("player", invID)); |
||
132 | |||
133 | if ( not IsInventoryItemLocked(invID) ) then |
||
134 | SetItemButtonTextureVertexColor(bag, 1.0, 1.0, 1.0); |
||
135 | SetItemButtonNormalTextureVertexColor(bag, 1.0, 1.0, 1.0); |
||
136 | end |
||
137 | bag.hasItem = 1; |
||
138 | else |
||
139 | SetItemButtonTexture(bag, nil); |
||
140 | BagnonBag_SetCount(bag, 0); |
||
141 | SetItemButtonTextureVertexColor(bag, 1.0, 1.0, 1.0); |
||
142 | SetItemButtonNormalTextureVertexColor(bag, 1.0, 1.0, 1.0); |
||
143 | getglobal(bag:GetName().."Cooldown"):Hide(); |
||
144 | bag.hasItem = nil; |
||
145 | end |
||
146 | if ( GameTooltip:IsOwned(bag) ) then |
||
147 | if ( textureName ) then |
||
148 | BagnonBag_OnEnter(bag); |
||
149 | else |
||
150 | GameTooltip:Hide(); |
||
151 | ResetCursor(); |
||
152 | end |
||
153 | end |
||
154 | BagnonBag_UpdateLock(bag); |
||
155 | |||
156 | -- Update repair all button status |
||
157 | if ( MerchantRepairAllIcon ) then |
||
158 | local repairAllCost, canRepair = GetRepairAllCost(); |
||
159 | if ( canRepair ) then |
||
160 | SetDesaturation(MerchantRepairAllIcon, nil); |
||
161 | MerchantRepairAllButton:Enable(); |
||
162 | else |
||
163 | SetDesaturation(MerchantRepairAllIcon, 1); |
||
164 | MerchantRepairAllButton:Disable(); |
||
165 | end |
||
166 | end |
||
167 | end |
||
168 | |||
169 | function BagnonBag_UpdateLock(bag) |
||
170 | if ( IsInventoryItemLocked( ContainerIDToInventoryID(bag:GetID()) ) ) then |
||
171 | SetItemButtonDesaturated(bag, 1, 0.5, 0.5, 0.5); |
||
172 | else |
||
173 | SetItemButtonDesaturated(bag, nil); |
||
174 | end |
||
175 | end |
||
176 | |||
177 | function BagnonBag_UpdateCursor(bag) |
||
178 | if ( CursorCanGoInSlot( ContainerIDToInventoryID( bag:GetID() ) ) ) then |
||
179 | bag:LockHighlight(); |
||
180 | else |
||
181 | bag:UnlockHighlight(); |
||
182 | end |
||
183 | end |
||
184 | |||
185 | |||
186 | --[[ |
||
187 | Update the texture and count of the bag |
||
188 | Used mainly for cached bags |
||
189 | --]] |
||
190 | function BagnonBag_UpdateTexture(frame, bagID) |
||
191 | local bag = getglobal(frame:GetName() .. "Bags" .. bagID); |
||
192 | if(not bag or bag:GetID() <= 0) then return; end |
||
193 | |||
194 | if( Bagnon_IsCachedBag(frame.player, bagID) ) then |
||
195 | local _, link, count = BagnonDB.GetBagData(frame.player, bagID); |
||
196 | if(link) then |
||
197 | local _, _, _, _, _, _, _, _, texture = GetItemInfo(link); |
||
198 | SetItemButtonTexture(bag, texture); |
||
199 | else |
||
200 | SetItemButtonTexture(bag, nil); |
||
201 | end |
||
202 | if(count) then |
||
203 | BagnonBag_SetCount(bag, count); |
||
204 | end |
||
205 | else |
||
206 | local texture = GetInventoryItemTexture("player", ContainerIDToInventoryID(bagID)); |
||
207 | if(texture) then |
||
208 | SetItemButtonTexture(bag, texture); |
||
209 | else |
||
210 | SetItemButtonTexture(bag, nil); |
||
211 | end |
||
212 | BagnonBag_SetCount(bag, GetInventoryItemCount("player", ContainerIDToInventoryID(bagID))); |
||
213 | end |
||
214 | end |
||
215 | |||
216 | --this function is used when updating the frame's size based on a bag being replaced/removed/added, so we don't care about the keyring |
||
217 | function BagnonBag_UpdateFrameSize(bagFrame) |
||
218 | local size = 0; |
||
219 | for _, bag in pairs( { bagFrame:GetChildren() } ) do |
||
220 | if(bag:GetID() ~= KEYRING_CONTAINER) then |
||
221 | size = size + GetContainerNumSlots(bag:GetID()); |
||
222 | end |
||
223 | end |
||
224 | |||
225 | --only generate the frame again if the size of the frame changed |
||
226 | if(bagFrame.size ~= size) then |
||
227 | BagnonFrame_Generate( bagFrame:GetParent() ); |
||
228 | end |
||
229 | bagFrame.size = size; |
||
230 | end |
||
231 | |||
232 | function BagnonBag_SetCount(button, count) |
||
233 | if ( not button ) then return; end |
||
234 | |||
235 | if ( not count ) then |
||
236 | count = 0; |
||
237 | end |
||
238 | |||
239 | button.count = count; |
||
240 | if ( count > 1 or (button.isBag and count > 0) ) then |
||
241 | local countText = getglobal(button:GetName().."Count"); |
||
242 | if(count > 9999) then |
||
243 | countText:SetFont(NumberFontNormal:GetFont(), 10, "OUTLINE"); |
||
244 | elseif(count > 999) then |
||
245 | countText:SetFont(NumberFontNormal:GetFont(), 11, "OUTLINE"); |
||
246 | else |
||
247 | countText:SetFont(NumberFontNormal:GetFont(), 12, "OUTLINE"); |
||
248 | end |
||
249 | countText:SetText(count); |
||
250 | countText:Show(); |
||
251 | else |
||
252 | getglobal(button:GetName().."Count"):Hide(); |
||
253 | end |
||
254 | end |