vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | --[[ |
2 | Events.lua |
||
3 | The main event handler for Bagnon and Banknon. |
||
4 | It controls when the frames update, and when and when they are not shown. |
||
5 | |||
6 | The UI by default partially supports showing/hiding at the mailbox, and fully supports the inventory frame showing/hiding at a vendor. |
||
7 | |||
8 | I've extended the behavior in the following ways: |
||
9 | If a frame was previously shown by a user, it will not automatically close. |
||
10 | The events of showing the bank, tradeskill, auction, and trading can also be set to open the inventory or bank windows. |
||
11 | --]] |
||
12 | |||
13 | bgn_atBank = nil; --a flag for if the player is at the bank or not |
||
14 | |||
15 | function BagnonEvents_OnEvent() |
||
16 | --[[ |
||
17 | Events For Updating Items |
||
18 | --]] |
||
19 | if ( event == "BAG_UPDATE" or event == "BAG_UPDATE_COOLDOWN") then |
||
20 | if( Bagnon and Bagnon:IsVisible() and Bagnon_FrameHasBag("Bagnon", arg1) ) then |
||
21 | BagnonFrame_Update(Bagnon, arg1); |
||
22 | elseif( Banknon and Banknon:IsVisible() and Bagnon_FrameHasBag("Banknon", arg1) ) then |
||
23 | BagnonFrame_Update(Banknon, arg1); |
||
24 | end |
||
25 | elseif( event == "PLAYERBANKSLOTS_CHANGED") then |
||
26 | if( Banknon and Banknon:IsVisible() and Bagnon_FrameHasBag("Banknon", -1) ) then |
||
27 | BagnonFrame_Update(Banknon, -1); |
||
28 | end |
||
29 | elseif( event == "ITEM_LOCK_CHANGED" ) then |
||
30 | if( Bagnon and Bagnon:IsVisible() ) then |
||
31 | BagnonFrame_UpdateLock(Bagnon); |
||
32 | end |
||
33 | if( Banknon and Banknon:IsVisible() ) then |
||
34 | BagnonFrame_UpdateLock(Banknon); |
||
35 | end |
||
36 | --the keyring's size changes based on the player's level |
||
37 | elseif( event == "PLAYER_LEVEL_UP") then |
||
38 | if( Bagnon and Bagnon:IsVisible() and Bagnon_FrameHasBag("Bagnon", KEYRING_CONTAINER) ) then |
||
39 | BagnonFrame_Generate(Bagnon); |
||
40 | end |
||
41 | --[[ |
||
42 | Automatic Frame Opening/Closing Events |
||
43 | --]] |
||
44 | elseif(event == "BANKFRAME_OPENED") then |
||
45 | bgn_atBank = 1; |
||
46 | if(BagnonSets.showBagsAtBank) then |
||
47 | BagnonFrame_Open("Bagnon", 1); |
||
48 | end |
||
49 | |||
50 | if(BagnonSets.showBankAtBank and Bagnon_IsAddOnEnabled("Banknon")) then |
||
51 | BagnonFrame_Open("Banknon", 1); |
||
52 | else |
||
53 | BagnonEvents_ShowBlizBank(); |
||
54 | end |
||
55 | elseif(event == "BANKFRAME_CLOSED") then |
||
56 | bgn_atBank = nil; |
||
57 | if(BagnonSets.showBagsAtBank) then |
||
58 | BagnonFrame_Close("Bagnon", 1); |
||
59 | end |
||
60 | if(BagnonSets.showBankAtBank) then |
||
61 | BagnonFrame_Close("Banknon", 1); |
||
62 | end |
||
63 | elseif(event == "TRADE_SHOW") then |
||
64 | if(BagnonSets.showBagsAtTrade) then |
||
65 | BagnonFrame_Open("Bagnon", 1); |
||
66 | end |
||
67 | if(BagnonSets.showBankAtTrade) then |
||
68 | BagnonFrame_Open("Banknon", 1); |
||
69 | end |
||
70 | elseif(event == "TRADE_CLOSED") then |
||
71 | if(BagnonSets.showBagsAtTrade) then |
||
72 | BagnonFrame_Close("Bagnon", 1); |
||
73 | end |
||
74 | if(BagnonSets.showBankAtTrade) then |
||
75 | BagnonFrame_Close("Banknon", 1); |
||
76 | end |
||
77 | elseif(event == "TRADE_SKILL_SHOW") then |
||
78 | if(BagnonSets.showBagsAtCraft) then |
||
79 | BagnonFrame_Open("Bagnon", 1); |
||
80 | end |
||
81 | if(BagnonSets.showBankAtCraft) then |
||
82 | BagnonFrame_Open("Banknon", 1); |
||
83 | end |
||
84 | elseif(event == "TRADE_SKILL_CLOSE") then |
||
85 | if(BagnonSets.showBagsAtCraft) then |
||
86 | BagnonFrame_Close("Bagnon", 1); |
||
87 | end |
||
88 | if(BagnonSets.showBankAtCraft) then |
||
89 | BagnonFrame_Close("Banknon", 1); |
||
90 | end |
||
91 | elseif(event == "AUCTION_HOUSE_SHOW") then |
||
92 | if(BagnonSets.showBagsAtAH) then |
||
93 | BagnonFrame_Open("Bagnon", 1); |
||
94 | end |
||
95 | if(BagnonSets.showBankAtAH) then |
||
96 | BagnonFrame_Open("Banknon", 1); |
||
97 | end |
||
98 | elseif(event == "AUCTION_HOUSE_CLOSED") then |
||
99 | if(BagnonSets.showBagsAtAH) then |
||
100 | BagnonFrame_Close("Bagnon", 1); |
||
101 | end |
||
102 | if(BagnonSets.showBankAtAH) then |
||
103 | BagnonFrame_Close("Banknon", 1); |
||
104 | end |
||
105 | elseif(event == "MAIL_SHOW") then |
||
106 | if(BagnonSets.showBankAtMail) then |
||
107 | BagnonFrame_Open("Banknon", 1); |
||
108 | end |
||
109 | elseif(event == "MAIL_CLOSED") then |
||
110 | BagnonFrame_Close("Bagnon", 1); |
||
111 | |||
112 | if(BagnonSets.showBankAtMail) then |
||
113 | BagnonFrame_Close("Banknon", 1); |
||
114 | end |
||
115 | elseif(event == "MERCHANT_SHOW") then |
||
116 | if(BagnonSets.showBankAtVendor) then |
||
117 | BagnonFrame_Open("Banknon", 1); |
||
118 | end |
||
119 | elseif(event == "MERCHANT_CLOSED") then |
||
120 | if(BagnonSets.showBankAtVendor) then |
||
121 | BagnonFrame_Close("Banknon", 1); |
||
122 | end |
||
123 | --[[ Loading Event ]]-- |
||
124 | elseif(event == "ADDON_LOADED" and arg1 == "Bagnon_Core") then |
||
125 | BagnonEvents:UnregisterEvent("ADDON_LOADED"); |
||
126 | BagnonEvents_Load(this); |
||
127 | end |
||
128 | end |
||
129 | |||
130 | function BagnonEvents_Load(eventFrame) |
||
131 | BankFrame:UnregisterEvent("BANKFRAME_OPENED"); |
||
132 | |||
133 | --disable the ItemOnUpdate function for those using KCItems, since it causes a pretty bad memory leak |
||
134 | if KC_Items then |
||
135 | BagnonItem_OnUpdate = function() return; end; |
||
136 | end |
||
137 | |||
138 | BagnonEvents_LoadVariables(); |
||
139 | BagnonEvents_ObtainLocalizedNames(); |
||
140 | Infield.AddRescaleAction(BagnonEvents_RescaleAll); |
||
141 | |||
142 | eventFrame:RegisterEvent("BAG_UPDATE"); |
||
143 | eventFrame:RegisterEvent("PLAYERBANKSLOTS_CHANGED"); |
||
144 | eventFrame:RegisterEvent("ITEM_LOCK_CHANGED"); |
||
145 | eventFrame:RegisterEvent("BAG_UPDATE_COOLDOWN"); |
||
146 | eventFrame:RegisterEvent("PLAYER_LEVEL_UP"); |
||
147 | |||
148 | eventFrame:RegisterEvent("BANKFRAME_OPENED"); |
||
149 | eventFrame:RegisterEvent("BANKFRAME_CLOSED"); |
||
150 | eventFrame:RegisterEvent("TRADE_SHOW"); |
||
151 | eventFrame:RegisterEvent("TRADE_CLOSED"); |
||
152 | eventFrame:RegisterEvent("TRADE_SKILL_SHOW"); |
||
153 | eventFrame:RegisterEvent("TRADE_SKILL_CLOSE"); |
||
154 | eventFrame:RegisterEvent("AUCTION_HOUSE_SHOW"); |
||
155 | eventFrame:RegisterEvent("AUCTION_HOUSE_CLOSED"); |
||
156 | eventFrame:RegisterEvent("MAIL_SHOW"); |
||
157 | eventFrame:RegisterEvent("MAIL_CLOSED"); |
||
158 | eventFrame:RegisterEvent("MERCHANT_SHOW"); |
||
159 | eventFrame:RegisterEvent("MERCHANT_CLOSED"); |
||
160 | end |
||
161 | |||
162 | function BagnonEvents_LoadVariables() |
||
163 | if(not BagnonSets) then |
||
164 | BagnonSets = { |
||
165 | showBagsAtBank = 1, |
||
166 | showBagsAtAH = 1, |
||
167 | showBankAtBank = 1, |
||
168 | showTooltips = 1, |
||
169 | qualityBorders = 1, |
||
170 | version = BAGNON_VERSION, |
||
171 | }; |
||
172 | BagnonMsg(BAGNON_INITIALIZED); |
||
173 | elseif(BagnonSets.version ~= BAGNON_VERSION) then |
||
174 | |||
175 | if(BagnonSets.overrideBank) then |
||
176 | BagnonSets.showBankAtBank = 1; |
||
177 | BagnonSets.overrideBank = nil; |
||
178 | end |
||
179 | |||
180 | BagnonSets.version = BAGNON_VERSION; |
||
181 | BagnonMsg(BAGNON_UPDATED); |
||
182 | end |
||
183 | end |
||
184 | |||
185 | local function BagnonHasInfo() |
||
186 | return (GetLocale() == "enUS" or |
||
187 | GetLocale() == "deDE" or |
||
188 | GetLocale() == "frFR" or |
||
189 | GetLocale() == "zhCN" or |
||
190 | GetLocale() == "zhTW" or |
||
191 | BagnonSets.noDebug); |
||
192 | end |
||
193 | |||
194 | --try and get localized names, so that its possible to do special bag coloring |
||
195 | function BagnonEvents_ObtainLocalizedNames() |
||
196 | if( not BagnonHasInfo() ) then |
||
197 | BagnonMsg("Obtaining localized data. Please report the following to where you downloaded Bagnon from."); |
||
198 | BagnonMsg( GetLocale() ); |
||
199 | end |
||
200 | |||
201 | --backpack |
||
202 | local name, _, _, _, iType, subType = GetItemInfo(4500); |
||
203 | if(name) then |
||
204 | if( not BagnonHasInfo() ) then |
||
205 | BagnonMsg( "Backpack: " .. (iType or "null") .. ", " .. (subType or "null") ); |
||
206 | end |
||
207 | if(iType) then |
||
208 | BAGNON_ITEMTYPE_CONTAINER = iType; |
||
209 | BAGNON_SUBTYPE_BAG = subType; |
||
210 | end |
||
211 | end |
||
212 | |||
213 | --ammo |
||
214 | name, _, _, _, iType, subType = GetItemInfo(8218); |
||
215 | if(name) then |
||
216 | if( not BagnonHasInfo() ) then |
||
217 | BagnonMsg( "Ammo: " .. (iType or "null") .. ", " .. (subType or "null") ); |
||
218 | end |
||
219 | if(iType) then |
||
220 | BAGNON_ITEMTYPE_QUIVER = iType; |
||
221 | end |
||
222 | end |
||
223 | |||
224 | --soul pouch |
||
225 | name, _, _, _, iType, subType = GetItemInfo(21340); |
||
226 | if(name) then |
||
227 | if( not BagnonHasInfo() ) then |
||
228 | BagnonMsg( "Soul Bag: " .. (iType or "null") .. ", " .. (subType or "null") ); |
||
229 | end |
||
230 | if(subType) then |
||
231 | BAGNON_SUBTYPE_SOULBAG = subType; |
||
232 | end |
||
233 | end |
||
234 | end |
||
235 | |||
236 | function BagnonEvents_RescaleAll() |
||
237 | if(Bagnon) then |
||
238 | BagnonFrame_Reposition(Bagnon); |
||
239 | end |
||
240 | |||
241 | if(Banknon) then |
||
242 | BagnonFrame_Reposition(Banknon); |
||
243 | end |
||
244 | end |
||
245 | |||
246 | --[[ |
||
247 | Taken from Blizzard's code |
||
248 | Shows the normal bank frame |
||
249 | --]] |
||
250 | |||
251 | function BagnonEvents_ShowBlizBank() |
||
252 | BankFrameTitleText:SetText( UnitName("npc") ); |
||
253 | SetPortraitTexture(BankPortraitTexture,"npc"); |
||
254 | ShowUIPanel(BankFrame); |
||
255 | |||
256 | if( not BankFrame:IsVisible() ) then |
||
257 | CloseBankFrame(); |
||
258 | end |
||
259 | UpdateBagSlotStatus(); |
||
260 | end |
||
261 | |||
262 | --[[ Create the Event Handler Frame ]]-- |
||
263 | CreateFrame("Frame", "BagnonEvents") |
||
264 | BagnonEvents:RegisterEvent("ADDON_LOADED"); |
||
265 | BagnonEvents:SetScript("OnEvent", BagnonEvents_OnEvent); |
||
266 | BagnonEvents:Hide(); |