vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | GMail = AceLibrary("AceAddon-2.0"):new("AceEvent-2.0", "AceHook-2.0") |
2 | |||
3 | function GMail:OnInitialize() |
||
4 | |||
5 | tinsert(UISpecialFrames, "GMailInboxOpenAll") |
||
6 | |||
7 | -- Allows the mail frame to be pushed |
||
8 | if ( UIPanelWindows["MailFrame"] ) then |
||
9 | UIPanelWindows["MailFrame"].pushable = 1 |
||
10 | else |
||
11 | UIPanelWindows["MailFrame"] = { area = "left", pushable = 1 } |
||
12 | end |
||
13 | |||
14 | -- Close FriendsFrame will close if you try to open a mail with mailframe+friendsframe open |
||
15 | if ( UIPanelWindows["FriendsFrame"] ) then |
||
16 | UIPanelWindows["FriendsFrame"].pushable = 2 |
||
17 | else |
||
18 | UIPanelWindows["FriendsFrame"] = { area = "left", pushable = 2 } |
||
19 | end |
||
20 | |||
21 | MailItem1:SetPoint("TOPLEFT", "InboxFrame", "TOPLEFT", 48, -80) |
||
22 | for i = 1, 7, 1 do |
||
23 | getglobal("MailItem" .. i .. "ExpireTime"):SetPoint("TOPRIGHT", "MailItem" .. i, "TOPRIGHT", 10, -4) |
||
24 | getglobal("MailItem" .. i):SetWidth(280) |
||
25 | end |
||
26 | |||
27 | GMAIL_NUMITEMBUTTONS = 21 |
||
28 | GMail_BagLinks = { } |
||
29 | GMail_ScheduledStack = { } |
||
30 | GMail_SelectedItems = { } |
||
31 | GMail_DELETEDELAY = 1 |
||
32 | GMail_DELETEEVENTDELAY = 1 |
||
33 | |||
34 | GMailFrame.num = 0 |
||
35 | PanelTemplates_SetNumTabs(MailFrame, 3) |
||
36 | |||
37 | GMailForwardFrame.pickItem = { } |
||
38 | GMailForwardFrame.process = 0 |
||
39 | |||
40 | GMailGlobalFrame.queue = { } |
||
41 | GMailGlobalFrame.update = 0 |
||
42 | GMailGlobalFrame.total = 0 |
||
43 | GMailGlobalFrame.sendmail = 0 |
||
44 | GMailGlobalFrame.latency = 2.25 |
||
45 | |||
46 | GMailTooltip:SetOwner(WorldFrame, "ANCHOR_NONE") |
||
47 | |||
48 | GMailInboxFrame.eventFunc = { } |
||
49 | |||
50 | end |
||
51 | |||
52 | function GMail:OnEnable() |
||
53 | |||
54 | self:RegisterEvent("MAIL_INBOX_UPDATE") |
||
55 | self:RegisterEvent("UI_ERROR_MESSAGE") |
||
56 | self:RegisterEvent("MAIL_SEND_SUCCESS") |
||
57 | self:RegisterEvent("MAIL_SEND_INFO_UPDATE") |
||
58 | self:RegisterEvent("MAIL_CLOSED") |
||
59 | self:RegisterEvent("BAG_UPDATE") |
||
60 | |||
61 | self:Hook("ContainerFrameItemButton_OnClick") |
||
62 | self:Hook("PickupContainerItem") |
||
63 | self:Hook("ContainerFrame_Update") |
||
64 | self:Hook("ClickSendMailItemButton") |
||
65 | self:HookScript(TradeFrame, "OnShow", "TF_Show") |
||
66 | self:Hook("InboxFrameItem_OnEnter") |
||
67 | self:Hook("MailFrameTab_OnClick") |
||
68 | self:Hook("InboxFrame_OnClick") |
||
69 | self:Hook("InboxFrame_Update") |
||
70 | self:Hook("CloseMail") |
||
71 | self:Hook("TakeInboxItem") |
||
72 | self:Hook("OpenMail_Reply") |
||
73 | oldTakeInboxMoney = OpenMailMoneyButton:GetScript("OnClick") |
||
74 | |||
75 | end |
||
76 | |||
77 | function GMail:MAIL_CLOSED() |
||
78 | GMail:ClearItems() |
||
79 | GMailGlobalFrame.total = 0 |
||
80 | GMailGlobalFrame.queue = { } |
||
81 | end |
||
82 | |||
83 | function GMail:MAIL_SEND_SUCCESS() |
||
84 | GMAIL_CANSENDNEXT = 1 |
||
85 | end |
||
86 | |||
87 | function GMail:ContainerFrameItemButton_OnClick(btn, ignore) |
||
88 | if ( self:GetItemFrame(this:GetParent():GetID(), this:GetID()) ) then |
||
89 | return |
||
90 | end |
||
91 | self.hooks["ContainerFrameItemButton_OnClick"].orig(btn, ignore) |
||
92 | self:UpdateItemButtons() |
||
93 | end |
||
94 | |||
95 | function GMail:PickupContainerItem(bag, item, special) |
||
96 | if ( ( self:GetItemFrame(bag, item) or ( GMail_addItem and GMail_addItem[1] == bag and GMail_addItem[2] == item ) ) and not special ) then |
||
97 | return |
||
98 | end |
||
99 | if ( not CursorHasItem() ) then |
||
100 | GMailFrame.bag = bag |
||
101 | GMailFrame.item = item |
||
102 | end |
||
103 | if ( IsAltKeyDown() and GMailFrame:IsVisible() and not CursorHasItem() ) then |
||
104 | local i |
||
105 | for i = 1, GMAIL_NUMITEMBUTTONS, 1 do |
||
106 | if ( not getglobal("GMailButton" .. i).item ) then |
||
107 | |||
108 | if ( self:ItemIsMailable(bag, item) ) then |
||
109 | GMail:Print("GMail: Cannot attach item.", 1, 0.5, 0) |
||
110 | return |
||
111 | end |
||
112 | |||
113 | self.hooks["PickupContainerItem"].orig(bag, item) |
||
114 | self:MailButton_OnClick(getglobal("GMailButton" .. i)) |
||
115 | self:UpdateItemButtons() |
||
116 | return |
||
117 | end |
||
118 | end |
||
119 | elseif ( IsAltKeyDown() and SendMailFrame:IsVisible() and not CursorHasItem() ) then |
||
120 | self.hooks["PickupContainerItem"].orig(bag, item) |
||
121 | ClickSendMailItemButton() |
||
122 | return |
||
123 | elseif ( IsAltKeyDown() and TradeFrame:IsVisible() and not CursorHasItem() ) then |
||
124 | for i = 1, 6, 1 do |
||
125 | if ( not GetTradePlayerItemLink(i) ) then |
||
126 | self.hooks["PickupContainerItem"].orig(bag, item) |
||
127 | ClickTradeButton(i) |
||
128 | return |
||
129 | end |
||
130 | end |
||
131 | elseif ( IsAltKeyDown() and not CursorHasItem() and ( not TradeFrame or not TradeFrame:IsVisible() ) and ( not AuctionFrame or not AuctionFrame:IsVisible() ) and UnitExists("target") and CheckInteractDistance("target", 2) and UnitIsFriend("player", "target") and UnitIsPlayer("target") ) then |
||
132 | InitiateTrade("target") |
||
133 | GMail_addItem = { bag, item, UnitName("target"), 2 } |
||
134 | for i = 1, NUM_CONTAINER_FRAMES, 1 do |
||
135 | if ( getglobal("ContainerFrame" .. i):IsVisible() ) then |
||
136 | ContainerFrame_Update(getglobal("ContainerFrame" .. i)) |
||
137 | end |
||
138 | end |
||
139 | return |
||
140 | end |
||
141 | self.hooks["PickupContainerItem"].orig(bag, item) |
||
142 | self:UpdateItemButtons() |
||
143 | end |
||
144 | |||
145 | function GMail:MailFrameTab_OnClick(tab) |
||
146 | if ( not tab ) then |
||
147 | tab = this:GetID() |
||
148 | end |
||
149 | |||
150 | if ( tab == 3 ) then |
||
151 | PanelTemplates_SetTab(MailFrame, 3) |
||
152 | InboxFrame:Hide() |
||
153 | SendMailFrame:Hide() |
||
154 | GMailFrame:Show() |
||
155 | SendMailFrame.sendMode = "massmail" |
||
156 | MailFrameTopLeft:SetTexture("Interface\\ClassTrainerFrame\\UI-ClassTrainer-TopLeft") |
||
157 | MailFrameTopRight:SetTexture("Interface\\ClassTrainerFrame\\UI-ClassTrainer-TopRight") |
||
158 | MailFrameBotLeft:SetTexture("Interface\\ClassTrainerFrame\\UI-ClassTrainer-BotLeft") |
||
159 | MailFrameBotRight:SetTexture("Interface\\ClassTrainerFrame\\UI-ClassTrainer-BotRight") |
||
160 | MailFrameTopLeft:SetPoint("TOPLEFT", "MailFrame", "TOPLEFT", 2, -1) |
||
161 | return |
||
162 | else |
||
163 | GMailFrame:Hide() |
||
164 | end |
||
165 | self.hooks["MailFrameTab_OnClick"].orig(tab) |
||
166 | self:Forward_EnableForward() |
||
167 | end |
||
168 | |||
169 | function GMail:ClickSendMailItemButton() |
||
170 | if ( not GetSendMailItem() ) then |
||
171 | GMailFrame.mailbag = GMailFrame.bag |
||
172 | GMailFrame.mailitem = GMailFrame.item |
||
173 | end |
||
174 | self.hooks["ClickSendMailItemButton"].orig() |
||
175 | end |
||
176 | |||
177 | -- Handle the dragging of items |
||
178 | function GMail:MailButton_OnClick(button) |
||
179 | if ( not button ) then button = this end |
||
180 | if ( CursorHasItem() ) then |
||
181 | local bag = GMailFrame.bag |
||
182 | local item = GMailFrame.item |
||
183 | if ( not bag or not item ) then return end |
||
184 | if ( self:ItemIsMailable(bag, item) ) then |
||
185 | GMail:Print("GMail: Cannot attach item.", 1, 0.5, 0) |
||
186 | self.hooks["PickupContainerItem"].orig(bag, item) |
||
187 | return |
||
188 | end |
||
189 | self.hooks["PickupContainerItem"].orig(bag, item) |
||
190 | if ( this.bag and this.item ) then |
||
191 | -- There's already an item there |
||
192 | -- Pickup that item to replicate Send Mail's behaviour |
||
193 | self.hooks["PickupContainerItem"].orig(button.bag, button.item) |
||
194 | GMailFrame.bag = button.bag |
||
195 | GMailFrame.item = button.item |
||
196 | else |
||
197 | GMailFrame.bag = nil |
||
198 | GMailFrame.item = nil |
||
199 | end |
||
200 | local texture, count = GetContainerItemInfo(bag, item) |
||
201 | getglobal(button:GetName() .. "IconTexture"):Show() |
||
202 | getglobal(button:GetName() .. "IconTexture"):SetTexture(texture) |
||
203 | if ( count > 1 ) then |
||
204 | getglobal(button:GetName() .. "Count"):SetText(count) |
||
205 | getglobal(button:GetName() .. "Count"):Show() |
||
206 | else |
||
207 | getglobal(button:GetName() .. "Count"):Hide() |
||
208 | end |
||
209 | button.bag = bag |
||
210 | button.item = item |
||
211 | button.texture = texture |
||
212 | button.count = count |
||
213 | elseif ( button.item and button.bag ) then |
||
214 | self.hooks["PickupContainerItem"].orig(button.bag, button.item) |
||
215 | getglobal(button:GetName() .. "IconTexture"):Hide() |
||
216 | getglobal(button:GetName() .. "Count"):Hide() |
||
217 | GMailFrame.bag = button.bag |
||
218 | GMailFrame.item = button.item |
||
219 | button.item = nil |
||
220 | button.bag = nil |
||
221 | button.count = nil |
||
222 | button.texture = nil |
||
223 | |||
224 | end |
||
225 | local num = self:GetNumMails() |
||
226 | GMailFrame.num = num |
||
227 | self:CanSend(GMailNameEditBox) |
||
228 | if ( num == 0 ) then num = 1 end |
||
229 | MoneyFrame_Update("GMailCostMoneyFrame", GetSendMailPrice()*num) |
||
230 | for i = 1, NUM_CONTAINER_FRAMES, 1 do |
||
231 | if ( getglobal("ContainerFrame" .. i):IsVisible() ) then |
||
232 | ContainerFrame_Update(getglobal("ContainerFrame" .. i)) |
||
233 | end |
||
234 | end |
||
235 | end |
||
236 | |||
237 | function GMail:ItemIsMailable(bag, item) |
||
238 | |||
239 | -- Make sure tooltip is cleared |
||
240 | for i = 1, 29, 1 do |
||
241 | getglobal("GMailTooltipTextLeft" .. i):SetText("") |
||
242 | end |
||
243 | |||
244 | GMailTooltip:SetBagItem(bag, item) |
||
245 | for i = 1, GMailTooltip:NumLines(), 1 do |
||
246 | local text = getglobal("GMailTooltipTextLeft" .. i):GetText() |
||
247 | if ( text == ITEM_SOULBOUND or text == ITEM_BIND_QUEST or text == ITEM_CONJURED or text == ITEM_BIND_ON_PICKUP ) then |
||
248 | return 1 |
||
249 | end |
||
250 | end |
||
251 | return nil |
||
252 | end |
||
253 | |||
254 | |||
255 | function GMail:UpdateItemButtons(frame) |
||
256 | local i |
||
257 | for i = 1, GMAIL_NUMITEMBUTTONS, 1 do |
||
258 | local btn = getglobal("GMailButton" .. i) |
||
259 | if ( not frame or btn ~= frame ) then |
||
260 | local texture, count |
||
261 | if ( btn.item and btn.bag ) then |
||
262 | texture, count = GetContainerItemInfo(btn.bag, btn.item) |
||
263 | end |
||
264 | if ( not texture ) then |
||
265 | getglobal(btn:GetName() .. "IconTexture"):Hide() |
||
266 | getglobal(btn:GetName() .. "Count"):Hide() |
||
267 | btn.item = nil |
||
268 | btn.bag = nil |
||
269 | btn.count = nil |
||
270 | btn.texture = nil |
||
271 | else |
||
272 | btn.count = count |
||
273 | btn.texture = texture |
||
274 | getglobal(btn:GetName() .. "IconTexture"):Show() |
||
275 | getglobal(btn:GetName() .. "IconTexture"):SetTexture(texture) |
||
276 | if ( count > 1 ) then |
||
277 | getglobal(btn:GetName() .. "Count"):Show() |
||
278 | getglobal(btn:GetName() .. "Count"):SetText(count) |
||
279 | else |
||
280 | getglobal(btn:GetName() .. "Count"):Hide() |
||
281 | end |
||
282 | end |
||
283 | end |
||
284 | end |
||
285 | end |
||
286 | |||
287 | function GMail:GetItemFrame(bag, item) |
||
288 | local i |
||
289 | for i = 1, GMAIL_NUMITEMBUTTONS, 1 do |
||
290 | local btn = getglobal("GMailButton" .. i) |
||
291 | if ( btn.item == item and btn.bag == bag ) then |
||
292 | return btn |
||
293 | end |
||
294 | end |
||
295 | return nil |
||
296 | end |
||
297 | |||
298 | function GMail:GetNumMails() |
||
299 | local i |
||
300 | local num = 0 |
||
301 | for i = 1, GMAIL_NUMITEMBUTTONS, 1 do |
||
302 | local btn = getglobal("GMailButton" .. i) |
||
303 | if ( btn.item and btn.bag ) then |
||
304 | num = num + 1 |
||
305 | end |
||
306 | end |
||
307 | return num |
||
308 | end |
||
309 | |||
310 | function GMail:ClearItems() |
||
311 | local i |
||
312 | local num = 0 |
||
313 | for i = 1, GMAIL_NUMITEMBUTTONS, 1 do |
||
314 | local btn = getglobal("GMailButton" .. i) |
||
315 | btn.item = nil |
||
316 | btn.count = nil |
||
317 | btn.bag = nil |
||
318 | btn.texture = nil |
||
319 | end |
||
320 | self:UpdateItemButtons() |
||
321 | GMailMailButton:Disable() |
||
322 | GMailNameEditBox:SetText("") |
||
323 | GMailSubjectEditBox:SetText("") |
||
324 | GMailStatusText:SetText("") |
||
325 | GMailAbortButton:Hide() |
||
326 | GMailAcceptSendFrame:Hide() |
||
327 | end |
||
328 | |||
329 | function GMail:CanSend(eb) |
||
330 | if ( not eb ) then eb = this end |
||
331 | if ( strlen(eb:GetText()) > 0 and GMailFrame.num > 0 and GetSendMailPrice()*GMailFrame.num <= GetMoney() ) then |
||
332 | GMailMailButton:Enable() |
||
333 | else |
||
334 | GMailMailButton:Disable() |
||
335 | end |
||
336 | end |
||
337 | |||
338 | function GMail:SendMail() |
||
339 | for key, val in this.queue do |
||
340 | GMailStatusText:SetText(format(GMAIL_SENDING, key, this.total)) |
||
341 | GMailAbortButton:Show() |
||
342 | |||
343 | if ( GetSendMailItem() and GMailFrame.mailbag and GMailFrame.mailitem ) then |
||
344 | -- There's already an item in the slot |
||
345 | ClickSendMailItemButton() |
||
346 | self.hooks["PickupContainerItem"].orig(GMailFrame.mailbag, GMailFrame.mailitem) |
||
347 | GMailFrame.mailbag = nil |
||
348 | GMailFrame.mailitem = nil |
||
349 | elseif ( CursorHasItem() and GMailFrame.bag and GMailFrame.item ) then |
||
350 | PickupContainerItem(GMailFrame.bag, GMailFrame.item) |
||
351 | GMailFrame.bag = nil |
||
352 | GMailFrame.item = nil |
||
353 | end |
||
354 | |||
355 | self.hooks["PickupContainerItem"].orig(val.bag, val.item) |
||
356 | |||
357 | ClickSendMailItemButton() |
||
358 | |||
359 | local name, useless, count = GetSendMailItem() |
||
360 | |||
361 | if ( not name ) then |
||
362 | GMail:Print("GMail: " .. GMAIL_ERROR, 1, 0, 0) |
||
363 | else |
||
364 | |||
365 | local subjectstr = GMailSubjectEditBox:GetText() |
||
366 | if ( strlen(subjectstr) > 0 ) then |
||
367 | subjectstr = subjectstr .. " " |
||
368 | end |
||
369 | |||
370 | if ( count > 1 ) then |
||
371 | subjectstr = subjectstr .. "[" .. name .. " x" .. count .. "]" |
||
372 | else |
||
373 | subjectstr = subjectstr .. "[" .. name .. "]" |
||
374 | end |
||
375 | |||
376 | SendMail(val.to, subjectstr, format(GMAIL_ITEMNUM, key, this.total)) |
||
377 | end |
||
378 | |||
379 | GMailGlobalFrame.queue[key] = nil |
||
380 | return |
||
381 | end |
||
382 | GMailStatusText:SetText(format(GMAIL_DONESENDING, this.total)) |
||
383 | GMailAbortButton:Hide() |
||
384 | GMailGlobalFrame:Hide() |
||
385 | |||
386 | GMailGlobalFrame.total = 0 |
||
387 | GMailGlobalFrame.queue = { } |
||
388 | end |
||
389 | |||
390 | function GMail:FillItemTable() |
||
391 | local arr = { } |
||
392 | for i = 1, GMAIL_NUMITEMBUTTONS, 1 do |
||
393 | local btn = getglobal("GMailButton" .. i) |
||
394 | if ( btn.item and btn.bag ) then |
||
395 | tinsert(arr, { ["item"] = btn.item, ["bag"] = btn.bag, ["to"] = GMailNameEditBox:GetText() }) |
||
396 | end |
||
397 | end |
||
398 | return arr |
||
399 | end |
||
400 | |||
401 | function GMail:ProcessQueue(elapsed) |
||
402 | if ( not GMAIL_CANSENDNEXT ) then |
||
403 | return |
||
404 | end |
||
405 | this.sendmail = this.sendmail + elapsed |
||
406 | if ( this.sendmail > 0.5 ) then |
||
407 | this.sendmail = 0 |
||
408 | if ( this.total > 0 ) then |
||
409 | self:SendMail() |
||
410 | GMAIL_CANSENDNEXT = nil |
||
411 | end |
||
412 | end |
||
413 | end |
||
414 | |||
415 | function GMail:ContainerFrame_Update(frame) |
||
416 | self.hooks["ContainerFrame_Update"].orig(frame) |
||
417 | local id = frame:GetID() |
||
418 | if ( GMailFrame:IsVisible() ) then |
||
419 | local i |
||
420 | for i = 1, GMAIL_NUMITEMBUTTONS, 1 do |
||
421 | local btn = getglobal("GMailButton" .. i) |
||
422 | if ( btn.item and btn.bag ) then |
||
423 | if ( btn.bag == frame:GetID() ) then |
||
424 | SetItemButtonDesaturated(getglobal(frame:GetName() .. "Item" .. (frame.size-btn.item)+1), 1, 0.5, 0.5, 0.5) |
||
425 | end |
||
426 | end |
||
427 | end |
||
428 | end |
||
429 | if ( GMail_addItem and GMail_addItem[1] == frame:GetID() ) then |
||
430 | SetItemButtonDesaturated(getglobal(frame:GetName() .. "Item" .. (frame.size-GMail_addItem[2])+1), 1, 0.5, 0.5, 0.5) |
||
431 | end |
||
432 | end |
||
433 | |||
434 | function GMail:MAIL_SEND_INFO_UPDATE() |
||
435 | if ( not SendMailFrame:IsVisible() ) then return end |
||
436 | local name, useless, count = GetSendMailItem() |
||
437 | |||
438 | if ( name and strlen(SendMailSubjectEditBox:GetText()) == 0 ) then |
||
439 | if ( count > 1 ) then |
||
440 | name = name .. " x" .. count |
||
441 | end |
||
442 | SendMailSubjectEditBox:SetText(name) |
||
443 | end |
||
444 | end |
||
445 | |||
446 | function GMail:InboxFrameItem_OnEnter() |
||
447 | local didSetTooltip |
||
448 | if ( this.index ) then |
||
449 | if ( GetInboxItem(this.index) ) then |
||
450 | GameTooltip:SetOwner(this, "ANCHOR_RIGHT") |
||
451 | GameTooltip:SetInboxItem(this.index) |
||
452 | didSetTooltip = 1 |
||
453 | end |
||
454 | end |
||
455 | if ( not didSetTooltip ) then |
||
456 | GameTooltip:SetOwner(this, "ANCHOR_RIGHT") |
||
457 | end |
||
458 | if (this.money) then |
||
459 | GameTooltip:AddLine(ENCLOSED_MONEY, "", 1, 1, 1) |
||
460 | SetTooltipMoney(GameTooltip, this.money) |
||
461 | SetMoneyFrameColor("GameTooltipMoneyFrame", HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b) |
||
462 | elseif (this.cod) then |
||
463 | GameTooltip:AddLine(COD_AMOUNT, "", 1, 1, 1) |
||
464 | SetTooltipMoney(GameTooltip, this.cod) |
||
465 | if ( this.cod > GetMoney() ) then |
||
466 | SetMoneyFrameColor("GameTooltipMoneyFrame", RED_FONT_COLOR.r, RED_FONT_COLOR.g, RED_FONT_COLOR.b) |
||
467 | else |
||
468 | SetMoneyFrameColor("GameTooltipMoneyFrame", HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b) |
||
469 | end |
||
470 | end |
||
471 | if ( didSetTooltip and ( this.money or this.cod ) ) then |
||
472 | GameTooltip:SetHeight(GameTooltip:GetHeight()+getglobal("GameTooltipTextLeft" .. GameTooltip:NumLines()):GetHeight()) |
||
473 | if ( GameTooltipMoneyFrame:IsVisible() ) then |
||
474 | GameTooltip:SetHeight(GameTooltip:GetHeight()+GameTooltipMoneyFrame:GetHeight()) |
||
475 | end |
||
476 | end |
||
477 | GameTooltip:Show() |
||
478 | end |
||
479 | |||
480 | function GMail:TF_Show() |
||
481 | self.hooks[TradeFrame].OnShow.orig() |
||
482 | if ( GMail_addItem and not CursorHasItem() and UnitName("NPC") == GMail_addItem[3] ) then |
||
483 | self.hooks["PickupContainerItem"].orig(GMail_addItem[1], GMail_addItem[2]) |
||
484 | |||
485 | ClickTradeButton(1) |
||
486 | end |
||
487 | GMail_addItem = nil |
||
488 | end |
||
489 | |||
490 | function GMail:Inbox_OnUpdate(elapsed) |
||
491 | if ( GMail_addItem ) then |
||
492 | GMail_addItem[4] = GMail_addItem[4] - elapsed |
||
493 | if ( GMail_addItem[4] <= 0 ) then |
||
494 | GMail_addItem = nil |
||
495 | for i = 1, NUM_CONTAINER_FRAMES, 1 do |
||
496 | if ( getglobal("ContainerFrame" .. i):IsVisible() ) then |
||
497 | ContainerFrame_Update(getglobal("ContainerFrame" .. i)) |
||
498 | end |
||
499 | end |
||
500 | end |
||
501 | end |
||
502 | if ( this.num and this.elapsed ) then |
||
503 | this.elapsed = this.elapsed - elapsed |
||
504 | if ( this.elapsed <= 0 ) then |
||
505 | this.elapsed = nil |
||
506 | if ( this.id[1] ) then |
||
507 | local val = this.id[1] |
||
508 | local success = GMail:PickMail(val, this.openSelected) |
||
509 | if ( success ~= 2 ) then |
||
510 | tremove(this.id, 1) |
||
511 | this.num = this.num - 1 |
||
512 | end |
||
513 | if ( success == 1 ) then |
||
514 | for key, va in this.id do |
||
515 | if ( va > val ) then |
||
516 | this.id[key] = va-1 |
||
517 | end |
||
518 | end |
||
519 | this.lastVal = val |
||
520 | InboxFrame_Update() |
||
521 | else |
||
522 | this.elapsed = 1+GMail_DELETEDELAY |
||
523 | this.lastVal = nil |
||
524 | end |
||
525 | if ( this.num == 0 ) then |
||
526 | this.num = nil |
||
527 | GMail:Inbox_DisableClicks(nil) |
||
528 | end |
||
529 | end |
||
530 | end |
||
531 | end |
||
532 | if ( this.delete ) then |
||
533 | this.delete[1] = this.delete[1] - elapsed |
||
534 | if ( this.delete[1] <= 0 ) then |
||
535 | local packageIcon, stationeryIcon, sender, subject, money, CODAmount, daysLeft, itemID, wasRead, wasReturned, textCreated = GetInboxHeaderInfo(this.delete[2]) |
||
536 | if ( money == 0 and not itemID ) then |
||
537 | GetInboxText(this.delete[2]) |
||
538 | DeleteInboxItem(this.delete[2]) |
||
539 | end |
||
540 | this.delete = nil |
||
541 | this.elapsed = 0.5+GMail_DELETEDELAY |
||
542 | end |
||
543 | end |
||
544 | end |
||
545 | |||
546 | function GMail:MAIL_INBOX_UPDATE() |
||
547 | if ( GMailInboxFrame.eventDelete ) then |
||
548 | GMailInboxFrame.delete = { GMail_DELETEEVENTDELAY, GMailInboxFrame.eventDelete } |
||
549 | GMailInboxFrame.eventDelete = nil |
||
550 | end |
||
551 | end |
||
552 | function GMail:UI_ERROR_MESSAGE() |
||
553 | if ( event == "UI_ERROR_MESSAGE" and ( arg1 == ERR_INV_FULL or arg1 == ERR_ITEM_MAX_COUNT ) ) then |
||
554 | if ( this.num ) then |
||
555 | if ( arg1 == ERR_INV_FULL ) then |
||
556 | GMail:Inbox_Abort() |
||
557 | GMail:Print("GMail: Inventory full. Aborting.", 1, 0, 0) |
||
558 | elseif ( arg1 == ERR_ITEM_MAX_COUNT ) then |
||
559 | GMail:Print("GMail: You already have the maximum amount of that item. Skipping.", 1, 0, 0) |
||
560 | this.elapsed = GMail_DELETEDELAY |
||
561 | if ( this.lastVal ) then |
||
562 | for key, va in this.id do |
||
563 | if ( va >= this.lastVal ) then |
||
564 | this.id[key] = va+1 |
||
565 | end |
||
566 | end |
||
567 | end |
||
568 | end |
||
569 | end |
||
570 | end |
||
571 | end |
||
572 | |||
573 | function GMail:Print(msg, r, g, b) |
||
574 | DEFAULT_CHAT_FRAME:AddMessage(msg, r, g, b); |
||
575 | end |
||
576 | |||
577 | function GMail:PickMail(id, openSelected) |
||
578 | if ( not id ) then |
||
579 | return 0 |
||
580 | end |
||
581 | local packageIcon, stationeryIcon, sender, subject, money, CODAmount, daysLeft, hasItem, wasRead, wasReturned, textCreated, canReply = GetInboxHeaderInfo(id) |
||
582 | if ( CODAmount > 0 ) then |
||
583 | GMail:Print("GMail: Mail |c00FFFFFF" .. this.numMails-(this.num-1) .. "|r/|c00FFFFFF" .. this.numMails .. "|r is Cash on Delivery, skipping.", 1, 0, 0) |
||
584 | return 0 |
||
585 | elseif ( not hasItem and money == 0 and not openSelected ) then |
||
586 | GMail:Print("GMail: Mail |c00FFFFFF" .. this.numMails-(this.num-1) .. "|r/|c00FFFFFF" .. this.numMails .. "|r has no money or items, skipping.", 1, 1, 0) |
||
587 | return 0 |
||
588 | end |
||
589 | GMail:Print("GMail: Opening mail |c00FFFFFF" .. this.numMails-(this.num-1) .. "|r/|c00FFFFFF" .. this.numMails .. "|r: \"|c00FFFFFF" .. ( subject or "<No Subject>" ) .. "|r\" from |c00FFFFFF" .. ( sender or "<Unknown Sender>" ) .. "|r.", 1, 1, 0) |
||
590 | local eventDelete |
||
591 | if ( hasItem ) then |
||
592 | self.hooks["TakeInboxItem"].orig(id) |
||
593 | eventDelete = 1 |
||
594 | if ( money > 0 ) then |
||
595 | return 2 |
||
596 | end |
||
597 | end |
||
598 | if ( money > 0 ) then |
||
599 | TakeInboxMoney(id) |
||
600 | eventDelete = 1 |
||
601 | end |
||
602 | if ( eventDelete ) then |
||
603 | GMailInboxFrame.eventDelete = id |
||
604 | else |
||
605 | GMailInboxFrame.delete = { GMail_DELETEDELAY, id } |
||
606 | end |
||
607 | return 1 |
||
608 | end |
||
609 | |||
610 | function GMail_Inbox_SetSelected() |
||
611 | local id = this:GetID() + (InboxFrame.pageNum-1)*7 |
||
612 | if ( not this:GetChecked() ) then |
||
613 | for k, v in GMail_SelectedItems do |
||
614 | if ( v == id ) then |
||
615 | tremove(GMail_SelectedItems, k) |
||
616 | break |
||
617 | end |
||
618 | end |
||
619 | else |
||
620 | tinsert(GMail_SelectedItems, id) |
||
621 | end |
||
622 | end |
||
623 | |||
624 | function GMail_Inbox_OpenSelected(openAll) |
||
625 | GMail:Inbox_DisableClicks(1) |
||
626 | GMailInboxFrame.num = 0 |
||
627 | GMailInboxFrame.elapsed = GMail_DELETEDELAY |
||
628 | GMailInboxFrame.id = { } |
||
629 | GMailInboxFrame.openSelected = not openAll |
||
630 | if ( openAll ) then |
||
631 | for i = 1, GetInboxNumItems(), 1 do |
||
632 | GMailInboxFrame.num = GMailInboxFrame.num + 1 |
||
633 | tinsert(GMailInboxFrame.id, i) |
||
634 | end |
||
635 | else |
||
636 | for k, v in GMail_SelectedItems do |
||
637 | GMailInboxFrame.num = GMailInboxFrame.num + 1 |
||
638 | tinsert(GMailInboxFrame.id, v) |
||
639 | end |
||
640 | end |
||
641 | GMailInboxFrame.numMails = GMailInboxFrame.num |
||
642 | GMail_SelectedItems = { } |
||
643 | end |
||
644 | |||
645 | function GMail:InboxFrame_Update() |
||
646 | self.hooks["InboxFrame_Update"].orig() |
||
647 | for i = 1, 7, 1 do |
||
648 | local index = (i + (InboxFrame.pageNum-1)*7) |
||
649 | if ( index > GetInboxNumItems() ) then |
||
650 | getglobal("GMailBoxItem" .. i .. "CB"):Hide() |
||
651 | else |
||
652 | getglobal("GMailBoxItem" .. i .. "CB"):Show() |
||
653 | getglobal("GMailBoxItem" .. i .. "CB"):SetChecked(nil) |
||
654 | for k, v in GMail_SelectedItems do |
||
655 | if ( v == index ) then |
||
656 | getglobal("GMailBoxItem" .. i .. "CB"):SetChecked(1) |
||
657 | break |
||
658 | end |
||
659 | end |
||
660 | end |
||
661 | end |
||
662 | if ( GMailInboxFrame.num ) then |
||
663 | GMail:Inbox_DisableClicks(1, 1) |
||
664 | end |
||
665 | end |
||
666 | |||
667 | function GMail:Inbox_DisableClicks(disable, loopPrevention) |
||
668 | if ( disable ) then |
||
669 | for i = 1, 7, 1 do |
||
670 | getglobal("MailItem" .. i .. "ButtonIcon"):SetDesaturated(1) |
||
671 | end |
||
672 | if not self:IsHooked("InboxFrame_OnClick") then self:Hook("InboxFrame_OnClick", "DummyFunction") end |
||
673 | else |
||
674 | for i = 1, 7, 1 do |
||
675 | getglobal("MailItem" .. i .. "ButtonIcon"):SetDesaturated(nil) |
||
676 | end |
||
677 | if ( not loopPrevention ) then |
||
678 | InboxFrame_Update() |
||
679 | end |
||
680 | if self:IsHooked("InboxFrame_OnClick") then self:Unhook("InboxFrame_OnClick") end |
||
681 | end |
||
682 | end |
||
683 | |||
684 | function GMail:InboxFrame_OnClick() |
||
685 | this:SetChecked(nil) |
||
686 | end |
||
687 | |||
688 | function GMail:Inbox_Abort() |
||
689 | GMailInboxFrame.num = nil |
||
690 | GMailInboxFrame.elapsed = nil |
||
691 | GMailInboxFrame.id = { } |
||
692 | GMail_SelectedItems = { } |
||
693 | GMail:Inbox_DisableClicks() |
||
694 | HideUIPanel(GMailInboxOpenAll) |
||
695 | end |
||
696 | |||
697 | function GMail:CloseMail() |
||
698 | self.hooks["CloseMail"].orig() |
||
699 | GMail:Inbox_Abort() |
||
700 | end |
||
701 | |||
702 | function GMail:TakeInboxItem(id) |
||
703 | self.hooks["TakeInboxItem"].orig(id) |
||
704 | local name, itemTexture, count, quality, canUse = GetInboxItem(id) |
||
705 | tinsert(GMailForwardFrame.pickItem, name) |
||
706 | end |
||
707 | |||
708 | -- Mail Forwarding |
||
709 | function GMail:DisableAttachments(disable) |
||
710 | if ( disable ) then |
||
711 | OpenMailMoneyButtonIconTexture:SetDesaturated(1) |
||
712 | OpenMailPackageButtonIconTexture:SetDesaturated(1) |
||
713 | if not self:IsHooked(OpenMailMoneyButton, "OnClick") then self:HookScript(OpenMailMoneyButton, "OnClick", "DummyFunction") end |
||
714 | if not self:IsHooked(OpenMailPackageButton, "OnClick") then self:HookScript(OpenMailPackageButton, "OnClick", "DummyFunction") end |
||
715 | else |
||
716 | OpenMailMoneyButtonIconTexture:SetDesaturated(nil) |
||
717 | OpenMailPackageButtonIconTexture:SetDesaturated(nil) |
||
718 | if self:IsHooked(OpenMailMoneyButton, "OnClick") then self:Unhook(OpenMailMoneyButton, "OnClick") end |
||
719 | if self:IsHooked(OpenMailPackageButton, "OnClick") then self:Unhook(OpenMailPackageButton, "OnClick") end |
||
720 | end |
||
721 | end |
||
722 | |||
723 | function GMail:DummyFunction() |
||
724 | end |
||
725 | |||
726 | function GMail:OpenMail_Reply() |
||
727 | self.hooks["OpenMail_Reply"].orig() |
||
728 | SendMailMoneyCopper:SetText("") |
||
729 | SendMailMoneySilver:SetText("") |
||
730 | SendMailMoneyGold:SetText("") |
||
731 | end |
||
732 | |||
733 | |||
734 | function GMail:OpenReply() |
||
735 | OpenMail_Reply() |
||
736 | local packageIcon, stationeryIcon, sender, subject, money, CODAmount, daysLeft, hasItem, wasRead, wasReturned, textCreated, canReply = GetInboxHeaderInfo(InboxFrame.openMailID) |
||
737 | |||
738 | -- Money |
||
739 | local gold, silver, copper = "", "", "" |
||
740 | if ( money and money > 0 ) then |
||
741 | gold = floor(money / (COPPER_PER_SILVER * SILVER_PER_GOLD)) |
||
742 | silver = floor((money - (gold * COPPER_PER_SILVER * SILVER_PER_GOLD)) / COPPER_PER_SILVER) |
||
743 | copper = mod(money, COPPER_PER_SILVER) |
||
744 | end |
||
745 | SendMailMoneyCopper:SetText(copper) |
||
746 | SendMailMoneySilver:SetText(silver) |
||
747 | SendMailMoneyGold:SetText(gold) |
||
748 | |||
749 | -- Items |
||
750 | local name, itemTexture, count, quality, canUse = GetInboxItem(InboxFrame.openMailID) |
||
751 | SendMailPackageButton:SetNormalTexture(itemTexture) |
||
752 | if ( count > 1 ) then |
||
753 | SendMailPackageButtonCount:SetText(count) |
||
754 | else |
||
755 | SendMailPackageButtonCount:SetText("") |
||
756 | end |
||
757 | |||
758 | -- Text fields |
||
759 | SendMailNameEditBox:SetText("") |
||
760 | local subject = OpenMailSubject:GetText() |
||
761 | local prefix = "FW:".." " |
||
762 | if ( strsub(subject, 1, strlen(prefix)) ~= prefix ) then |
||
763 | subject = prefix..subject |
||
764 | end |
||
765 | SendMailSubjectEditBox:SetText(subject or "") |
||
766 | SendMailBodyEditBox:SetText(string.gsub(OpenMailBodyText:GetText() or "", "\n", "\n>")) |
||
767 | SendMailNameEditBox:SetFocus() |
||
768 | |||
769 | -- Set the send mode so the work flow can change accordingly |
||
770 | SendMailFrame.sendMode = "reply" |
||
771 | |||
772 | self:Forward_EnableForward(1) |
||
773 | end |
||
774 | |||
775 | function GMail:SendMailMailButton_OnClick() |
||
776 | local name, itemTexture, count, quality, canUse = GetInboxItem(InboxFrame.openMailID) |
||
777 | local packageIcon, stationeryIcon, sender, subject, money, CODAmount, daysLeft, hasItem, wasRead, wasReturned, textCreated, canReply = GetInboxHeaderInfo(InboxFrame.openMailID) |
||
778 | if ( name ) then |
||
779 | GMailForwardFrame.searchItem = name |
||
780 | GMailForwardFrame.forwardStep = 1 |
||
781 | self.hooks["TakeInboxItem"].orig(InboxFrame.openMailID) |
||
782 | else |
||
783 | GMailForwardFrame.forwardStep = 2 |
||
784 | if ( money and money > 0 ) then |
||
785 | SetSendMailMoney(money) |
||
786 | GMailForwardFrame.countDown = 2 |
||
787 | oldTakeInboxMoney(InboxFrame.openMailID) |
||
788 | else |
||
789 | GMailForwardFrame.countDown = 0.5 |
||
790 | end |
||
791 | end |
||
792 | SendMailMailButton:Disable() |
||
793 | end |
||
794 | |||
795 | function GMail:Forward_OnUpdate(elapsed) |
||
796 | if ( this.forwardStep and this.forwardStep > 1 ) then |
||
797 | if ( this.countDown ) then |
||
798 | this.countDown = this.countDown - elapsed |
||
799 | if ( this.countDown <= 0 ) then |
||
800 | if ( this.forwardStep == 2 ) then |
||
801 | this.countDown = 0.5 |
||
802 | this.forwardStep = 3 |
||
803 | -- Send the mail |
||
804 | SendMail(SendMailNameEditBox:GetText(), SendMailSubjectEditBox:GetText(), SendMailBodyEditBox:GetText()) |
||
805 | SendMailMailButton:Disable() |
||
806 | elseif ( this.forwardStep == 3 ) then |
||
807 | -- Delete the old one |
||
808 | local packageIcon, stationeryIcon, sender, subject, money, CODAmount, daysLeft, itemID, wasRead, wasReturned, textCreated = GetInboxHeaderInfo(InboxFrame.openMailID) |
||
809 | if ( money == 0 and not itemID ) then |
||
810 | DeleteInboxItem(InboxFrame.openMailID) |
||
811 | end |
||
812 | self:MailFrameTab_OnClick(1) |
||
813 | HideUIPanel(OpenMailFrame) |
||
814 | this.countDown = nil |
||
815 | this.forwardStep = nil |
||
816 | end |
||
817 | end |
||
818 | end |
||
819 | end |
||
820 | this.process = this.process - elapsed |
||
821 | if ( this.process <= 0 ) then |
||
822 | this.process = 3 |
||
823 | if ( getn(GMail_ScheduledStack) > 0 ) then |
||
824 | self:ProcessStack() |
||
825 | end |
||
826 | end |
||
827 | end |
||
828 | |||
829 | function GMail:InboxFrame_OnClick(id) |
||
830 | self.hooks["InboxFrame_OnClick"].orig(id) |
||
831 | local packageIcon, stationeryIcon, sender, subject, money, CODAmount, daysLeft, itemID, wasRead, wasReturned, textCreated = GetInboxHeaderInfo(id) |
||
832 | if ( CODAmount and CODAmount > 0 ) then |
||
833 | OpenMailForwardButton:Disable() |
||
834 | else |
||
835 | OpenMailForwardButton:Enable() |
||
836 | end |
||
837 | end |
||
838 | |||
839 | function GMail:Forward_EnableForward(enable) |
||
840 | if ( enable ) then |
||
841 | OpenMailForwardButton:Disable() |
||
842 | if not self:IsHooked(SendMailPackageButton, "OnEnter") then self:HookScript(SendMailPackageButton, "OnEnter", "SMPBOE") end |
||
843 | SendMailCODButton:Disable() |
||
844 | self:DisableAttachments(1) |
||
845 | if not self:IsHooked("SendMailMailButton_OnClick") then self:Hook("SendMailMailButton_OnClick") end |
||
846 | if not self:IsHooked("SendMailPackageButton_OnClick") then self:Hook("SendMailPackageButton_OnClick") end |
||
847 | else |
||
848 | OpenMailForwardButton:Enable() |
||
849 | if self:IsHooked(SendMailPackageButton, "OnEnter") then self:Unhook(SendMailPackageButton, "OnEnter") end |
||
850 | SendMailCODButton:Enable() |
||
851 | self:DisableAttachments(nil) |
||
852 | if self:IsHooked("SendMailMailButton_OnClick") then self:Unhook("SendMailMailButton_OnClick") end |
||
853 | if self:IsHooked("SendMailPackageButton_OnClick") then self:Unhook("SendMailPackageButton_OnClick") end |
||
854 | end |
||
855 | end |
||
856 | |||
857 | function GMail:SMPBOE() |
||
858 | GameTooltip:SetOwner(SendMailPackageButton, "ANCHOR_RIGHT") |
||
859 | GameTooltip:SetInboxItem(InboxFrame.openMailID) |
||
860 | end |
||
861 | function GMail:SendMailPackageButton_OnClick() |
||
862 | end |
||
863 | |||
864 | function GMail:Forward_AttachSlot(container, item) |
||
865 | PickupContainerItem(container, item) |
||
866 | ClickSendMailItemButton() |
||
867 | GMailForwardFrame.searchItem = nil |
||
868 | GMailForwardFrame.forwardStep = 2 |
||
869 | GMailForwardFrame.countDown = 1.5 |
||
870 | end |
||
871 | |||
872 | function GMail:BAG_UPDATE() |
||
873 | local old = { } |
||
874 | for k, v in GMail_BagLinks do |
||
875 | if ( type(v) == "table" ) then |
||
876 | old[k] = { } |
||
877 | for key, val in v do |
||
878 | old[k][key] = val |
||
879 | end |
||
880 | end |
||
881 | end |
||
882 | GMail_BagLinks = { } |
||
883 | for i = 0, 4, 1 do |
||
884 | GMail_BagLinks[i] = { } |
||
885 | for y = 1, GetContainerNumSlots(i), 1 do |
||
886 | local curr = GetContainerItemLink(i, y) |
||
887 | local _, _, name = string.find(( curr or "" ), "%[(.+)%]") |
||
888 | if ( name ) then |
||
889 | if ( GMailForwardFrame.searchItem ) then |
||
890 | if ( name and name == GMailForwardFrame.searchItem and not old[i][y] ) then |
||
891 | self:Forward_AttachSlot(i, y) |
||
892 | end |
||
893 | else |
||
894 | local _, _, name = string.find(( curr or "" ), "%[(.+)%]") |
||
895 | if ( name and name == GMailForwardFrame.pickItem[1] and not old[i][y] ) then |
||
896 | tremove(GMailForwardFrame.pickItem, 1) |
||
897 | for k, v in old do |
||
898 | local hasFound |
||
899 | for key, val in v do |
||
900 | if ( val == name and ( k ~= i or key ~= y ) ) then |
||
901 | local _,_, link = string.find((GetContainerItemLink(k, key) or ""), "(item:[%d:]+)") |
||
902 | if ( link ) then |
||
903 | local texture, itemCount = GetContainerItemInfo(k,key) |
||
904 | local tex, iC = GetContainerItemInfo(i, y) |
||
905 | local sName, sLink, iQuality, iLevel, sType, sSubType, iCount = GetItemInfo(link) |
||
906 | if ( sName and itemCount and iCount and iC ) then |
||
907 | if ( iCount >= (itemCount+iC) ) then |
||
908 | if ( getn(GMail_ScheduledStack) == 0 ) then |
||
909 | GMailForwardFrame.process = 2 |
||
910 | end |
||
911 | tinsert(GMail_ScheduledStack, { i, y, k, key }) |
||
912 | hasFound = 1 |
||
913 | break |
||
914 | end |
||
915 | end |
||
916 | end |
||
917 | end |
||
918 | end |
||
919 | if ( hasFound ) then |
||
920 | break |
||
921 | end |
||
922 | end |
||
923 | end |
||
924 | end |
||
925 | GMail_BagLinks[i][y] = name |
||
926 | end |
||
927 | end |
||
928 | end |
||
929 | end |
||
930 | |||
931 | |||
932 | function GMail:ProcessStack() |
||
933 | local val = tremove(GMail_ScheduledStack, 1) |
||
934 | PickupContainerItem(val[1], val[2]) |
||
935 | PickupContainerItem(val[3], val[4]) |
||
936 | end |
||
937 | |||
938 | local oldSMMFfunc = SendMailMoneyFrame.onvalueChangedFunc |
||
939 | SendMailMoneyFrame.onvalueChangedFunc = function() |
||
940 | if ( oldSMMFfunc ) then |
||
941 | oldSMMFfunc() |
||
942 | end |
||
943 | local subject = SendMailSubjectEditBox:GetText() |
||
944 | if ( subject == "" or string.find(subject, "%[%d+G, %d+S, %d+C%]") ) then |
||
945 | local copper, silver, gold = SendMailMoneyFrameCopper:GetText(), SendMailMoneyFrameSilver:GetText(), SendMailMoneyFrameGold:GetText() |
||
946 | if ( not tonumber(copper) ) then |
||
947 | copper = 0 |
||
948 | end |
||
949 | if ( not tonumber(silver) ) then |
||
950 | silver = 0 |
||
951 | end |
||
952 | if ( not tonumber(gold) ) then |
||
953 | gold = 0 |
||
954 | end |
||
955 | SendMailSubjectEditBox:SetText(format("[%sG, %sS, %sC]", gold, silver, copper)) |
||
956 | end |
||
957 | end |