vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 tinsert(UISpecialFrames, "CT_MMInbox_OpenAll");
2 CT_MMINBOX_DELETEDELAY = 1;
3 CT_MMINBOX_DELETEEVENTDELAY = 1;
4  
5 CT_MMInbox_SelectedItems = { };
6 function CT_MMInbox_OnLoad()
7 MailItem1:SetPoint("TOPLEFT", "InboxFrame", "TOPLEFT", 48, -80);
8 for i = 1, 7, 1 do
9 getglobal("MailItem" .. i .. "ExpireTime"):SetPoint("TOPRIGHT", "MailItem" .. i, "TOPRIGHT", 10, -4);
10 getglobal("MailItem" .. i):SetWidth(280);
11 end
12 this.eventFunc = { };
13 this:RegisterEvent("MAIL_INBOX_UPDATE");
14 this:RegisterEvent("UI_ERROR_MESSAGE");
15 this:RegisterEvent("VARIABLES_LOADED");
16 end
17  
18 function CT_MMInbox_OnUpdate(elapsed)
19 if ( CT_Mail_addItem ) then
20 CT_Mail_addItem[4] = CT_Mail_addItem[4] - elapsed;
21 if ( CT_Mail_addItem[4] <= 0 ) then
22 CT_Mail_addItem = nil;
23 for i = 1, NUM_CONTAINER_FRAMES, 1 do
24 if ( getglobal("ContainerFrame" .. i):IsVisible() ) then
25 ContainerFrame_Update(getglobal("ContainerFrame" .. i));
26 end
27 end
28 end
29 end
30 if ( this.num and this.elapsed ) then
31 this.elapsed = this.elapsed - elapsed;
32 if ( this.elapsed <= 0 ) then
33 this.elapsed = nil;
34 if ( this.id[1] ) then
35 local val = this.id[1];
36 local success = CT_MMInbox_PickMail(val, this.openSelected);
37 if ( success ~= 2 ) then
38 tremove(this.id, 1);
39 this.num = this.num - 1;
40 end
41 if ( success == 1 ) then
42 for key, va in this.id do
43 if ( va > val ) then
44 this.id[key] = va-1;
45 end
46 end
47 this.lastVal = val;
48 InboxFrame_Update();
49 else
50 this.elapsed = 1+CT_MMINBOX_DELETEDELAY;
51 this.lastVal = nil;
52 end
53 if ( this.num == 0 ) then
54 this.num = nil;
55 CT_MMInbox_DisableClicks(nil);
56 end
57 end
58 end
59 end
60 if ( this.delete ) then
61 this.delete[1] = this.delete[1] - elapsed;
62 if ( this.delete[1] <= 0 ) then
63 local packageIcon, stationeryIcon, sender, subject, money, CODAmount, daysLeft, itemID, wasRead, wasReturned, textCreated = GetInboxHeaderInfo(this.delete[2]);
64 if ( money == 0 and not itemID ) then
65 GetInboxText(this.delete[2]);
66 DeleteInboxItem(this.delete[2]);
67 end
68 this.delete = nil;
69 this.elapsed = 0.5+CT_MMINBOX_DELETEDELAY;
70 end
71 end
72 end
73  
74 function CT_MMInbox_OnEvent(event)
75 if ( event == "MAIL_INBOX_UPDATE" ) then
76 if ( this.eventDelete ) then
77 this.delete = { CT_MMINBOX_DELETEEVENTDELAY, this.eventDelete };
78 this.eventDelete = nil;
79 end
80 elseif ( event == "UI_ERROR_MESSAGE" and ( arg1 == ERR_INV_FULL or arg1 == ERR_ITEM_MAX_COUNT ) ) then
81 if ( this.num ) then
82 if ( arg1 == ERR_INV_FULL ) then
83 CT_MMInbox_Abort();
84 if ( CT_MMInbox_DisplayMessages ) then
85 CT_MMInbox_Print("<CTMod> Error: Inventory full. Aborting.", 1, 0, 0);
86 end
87 elseif ( arg1 == ERR_ITEM_MAX_COUNT ) then
88 if ( CT_MMInbox_DisplayMessages ) then
89 CT_MMInbox_Print("<CTMod> Error: You already have the maximum amount of that item. Skipping.", 1, 0, 0);
90 end
91 this.elapsed = CT_MMINBOX_DELETEDELAY;
92 if ( this.lastVal ) then
93 for key, va in this.id do
94 if ( va >= this.lastVal ) then
95 this.id[key] = va+1;
96 end
97 end
98 end
99 end
100 end
101 elseif ( event == "VARIABLES_LOADED" ) then
102 CT_MMInboxDisplayMessagesCB:SetChecked(CT_MMInbox_DisplayMessages);
103 end
104 end
105  
106 function CT_MMInbox_PickMail(id, openSelected)
107 if ( not id ) then
108 return 0;
109 end
110 local packageIcon, stationeryIcon, sender, subject, money, CODAmount, daysLeft, hasItem, wasRead, wasReturned, textCreated, canReply = GetInboxHeaderInfo(id);
111 if ( CODAmount > 0 ) then
112 if ( CT_MMInbox_DisplayMessages ) then
113 CT_MMInbox_Print("<CTMod> Mail |c00FFFFFF" .. this.numMails-(this.num-1) .. "|r/|c00FFFFFF" .. this.numMails .. "|r is Cash on Delivery, skipping.", 1, 0, 0);
114 end
115 return 0;
116 elseif ( not hasItem and money == 0 and not openSelected ) then
117 if ( CT_MMInbox_DisplayMessages ) then
118 CT_MMInbox_Print("<CTMod> Mail |c00FFFFFF" .. this.numMails-(this.num-1) .. "|r/|c00FFFFFF" .. this.numMails .. "|r has no money or items, skipping.", 1, 1, 0);
119 end
120 return 0;
121 end
122 if ( CT_MMInbox_DisplayMessages ) then
123 CT_MMInbox_Print("<CTMod> 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);
124 end
125 local eventDelete;
126 if ( hasItem ) then
127 TakeInboxItem(id);
128 eventDelete = 1;
129 if ( money > 0 ) then
130 return 2;
131 end
132 end
133 if ( money > 0 ) then
134 TakeInboxMoney(id);
135 eventDelete = 1;
136 end
137 if ( eventDelete ) then
138 CT_MMInboxFrame.eventDelete = id;
139 else
140 CT_MMInboxFrame.delete = { CT_MMINBOX_DELETEDELAY, id };
141 end
142 return 1;
143 end
144  
145 function CT_MMInbox_SetSelected()
146 local id = this:GetID() + (InboxFrame.pageNum-1)*7;
147 if ( not this:GetChecked() ) then
148 for k, v in CT_MMInbox_SelectedItems do
149 if ( v == id ) then
150 tremove(CT_MMInbox_SelectedItems, k);
151 break;
152 end
153 end
154 else
155 tinsert(CT_MMInbox_SelectedItems, id);
156 end
157 end
158  
159 function CT_MMInbox_OpenSelected(openAll)
160 CT_MMInbox_DisableClicks(1);
161 CT_MMInboxFrame.num = 0;
162 CT_MMInboxFrame.elapsed = CT_MMINBOX_DELETEDELAY;
163 CT_MMInboxFrame.id = { };
164 CT_MMInboxFrame.openSelected = not openAll;
165 if ( openAll ) then
166 for i = 1, GetInboxNumItems(), 1 do
167 CT_MMInboxFrame.num = CT_MMInboxFrame.num + 1;
168 tinsert(CT_MMInboxFrame.id, i);
169 end
170 else
171 for k, v in CT_MMInbox_SelectedItems do
172 CT_MMInboxFrame.num = CT_MMInboxFrame.num + 1;
173 tinsert(CT_MMInboxFrame.id, v);
174 end
175 end
176 CT_MMInboxFrame.numMails = CT_MMInboxFrame.num;
177 CT_MMInbox_SelectedItems = { };
178 end
179  
180 -- Hook InboxFrame_Update
181 CT_MMInbox_oldInboxFrame_Update = InboxFrame_Update;
182 function CT_MMInbox_newInboxFrame_Update()
183 CT_MMInbox_oldInboxFrame_Update();
184 for i = 1, 7, 1 do
185 local index = (i + (InboxFrame.pageNum-1)*7);
186 if ( index > GetInboxNumItems() ) then
187 getglobal("CT_MailBoxItem" .. i .. "CB"):Hide();
188 else
189 getglobal("CT_MailBoxItem" .. i .. "CB"):Show();
190 getglobal("CT_MailBoxItem" .. i .. "CB"):SetChecked(nil);
191 for k, v in CT_MMInbox_SelectedItems do
192 if ( v == index ) then
193 getglobal("CT_MailBoxItem" .. i .. "CB"):SetChecked(1);
194 break;
195 end
196 end
197 end
198 end
199 if ( CT_MMInboxFrame.num ) then
200 CT_MMInbox_DisableClicks(1, 1);
201 end
202 end
203 InboxFrame_Update = CT_MMInbox_newInboxFrame_Update;
204 CT_MMInbox_oldInboxFrame_OnClick = InboxFrame_OnClick;
205 function CT_MMInbox_DisableClicks(disable, loopPrevention)
206 if ( disable ) then
207 for i = 1, 7, 1 do
208 getglobal("MailItem" .. i .. "ButtonIcon"):SetDesaturated(1);
209 end
210 InboxFrame_OnClick = function() this:SetChecked(nil) end;
211 else
212 for i = 1, 7, 1 do
213 getglobal("MailItem" .. i .. "ButtonIcon"):SetDesaturated(nil);
214 end
215 if ( not loopPrevention ) then
216 InboxFrame_Update();
217 end
218 InboxFrame_OnClick = CT_MMInbox_oldInboxFrame_OnClick;
219 end
220 end
221  
222 function CT_MMInbox_Abort()
223 CT_MMInboxFrame.num = nil;
224 CT_MMInboxFrame.elapsed = nil;
225 CT_MMInboxFrame.id = { };
226 CT_MMInbox_SelectedItems = { };
227 CT_MMInbox_DisableClicks();
228 HideUIPanel(CT_MMInbox_OpenAll);
229 end
230  
231 function CT_MMInbox_Print(msg, r, g, b)
232 DEFAULT_CHAT_FRAME:AddMessage(msg, r, g, b);
233 end
234  
235 CT_MMInbox_oldCloseMail = CloseMail;
236 function CT_MMInbox_newCloseMail()
237 CT_MMInbox_oldCloseMail();
238 CT_MMInbox_Abort();
239 end
240 CloseMail = CT_MMInbox_newCloseMail;
241  
242 CT_MMInbox_oldTakeInboxItem = TakeInboxItem;
243 function CT_MMInbox_newTakeInboxItem(id)
244 CT_MMInbox_oldTakeInboxItem(id);
245 local name, itemTexture, count, quality, canUse = GetInboxItem(id);
246 tinsert(CT_MMForwardFrame.pickItem, name);
247 end
248 TakeInboxItem = CT_MMInbox_newTakeInboxItem;
249  
250 -- Mail Forwarding
251 CT_MMForward_BagLinks = { };
252 function CT_MMForward_DisableAttachments(disable)
253 if ( not CT_MMForward_oldTakeInboxMoney ) then
254 CT_MMForward_oldTakeInboxMoney = OpenMailMoneyButton:GetScript("OnClick");
255 CT_MMForward_oldTakeInboxItem = OpenMailPackageButton:GetScript("OnClick");
256 end
257 if ( disable ) then
258 OpenMailMoneyButtonIconTexture:SetDesaturated(1);
259 OpenMailPackageButtonIconTexture:SetDesaturated(1);
260 OpenMailMoneyButton:SetScript("OnClick", function() end);
261 OpenMailPackageButton:SetScript("OnClick", function() end);
262 else
263 OpenMailMoneyButtonIconTexture:SetDesaturated(nil);
264 OpenMailPackageButtonIconTexture:SetDesaturated(nil);
265 OpenMailMoneyButton:SetScript("OnClick", CT_MMForward_oldTakeInboxMoney);
266 OpenMailPackageButton:SetScript("OnClick", CT_MMForward_oldTakeInboxItem);
267 end
268 end
269  
270 CT_MMForward_oldOpenMail_Reply = OpenMail_Reply;
271 function CT_MMForward_newOpenMail_Reply()
272 CT_MMForward_oldOpenMail_Reply();
273 SendMailMoneyCopper:SetText("");
274 SendMailMoneySilver:SetText("");
275 SendMailMoneyGold:SetText("");
276 end
277 OpenMail_Reply = CT_MMForward_newOpenMail_Reply;
278  
279  
280 CT_MMInbox_oldSendMailPackageButton_OnEnter = SendMailPackageButton:GetScript("OnEnter");
281 function CT_MMForward_OpenReply()
282 OpenMail_Reply();
283 local packageIcon, stationeryIcon, sender, subject, money, CODAmount, daysLeft, hasItem, wasRead, wasReturned, textCreated, canReply = GetInboxHeaderInfo(InboxFrame.openMailID);
284  
285 -- Money
286 local gold, silver, copper = "", "", "";
287 if ( money and money > 0 ) then
288 gold = floor(money / (COPPER_PER_SILVER * SILVER_PER_GOLD));
289 silver = floor((money - (gold * COPPER_PER_SILVER * SILVER_PER_GOLD)) / COPPER_PER_SILVER);
290 copper = mod(money, COPPER_PER_SILVER);
291 end
292 SendMailMoneyCopper:SetText(copper);
293 SendMailMoneySilver:SetText(silver);
294 SendMailMoneyGold:SetText(gold);
295  
296 -- Items
297 local name, itemTexture, count, quality, canUse = GetInboxItem(InboxFrame.openMailID);
298 SendMailPackageButton:SetNormalTexture(itemTexture);
299 if ( count > 1 ) then
300 SendMailPackageButtonCount:SetText(count);
301 else
302 SendMailPackageButtonCount:SetText("");
303 end
304  
305 -- Text fields
306 SendMailNameEditBox:SetText("")
307 local subject = OpenMailSubject:GetText();
308 local prefix = "FW:".." ";
309 if ( strsub(subject, 1, strlen(prefix)) ~= prefix ) then
310 subject = prefix..subject;
311 end
312 SendMailSubjectEditBox:SetText(subject or "")
313 SendMailBodyEditBox:SetText(string.gsub(OpenMailBodyText:GetText() or "", "\n", "\n>"));
314 SendMailNameEditBox:SetFocus();
315  
316 -- Set the send mode so the work flow can change accordingly
317 SendMailFrame.sendMode = "reply";
318  
319 CT_MMForward_EnableForward(1);
320 end
321  
322 CT_MMForward_oldSendMailMailButton_OnClick = SendMailMailButton_OnClick;
323 CT_MMForward_oldSendMailPackageButton_OnClick = SendMailPackageButton_OnClick;
324 function CT_MMForward_newSendMailMailButton_OnClick()
325 local name, itemTexture, count, quality, canUse = GetInboxItem(InboxFrame.openMailID);
326 local packageIcon, stationeryIcon, sender, subject, money, CODAmount, daysLeft, hasItem, wasRead, wasReturned, textCreated, canReply = GetInboxHeaderInfo(InboxFrame.openMailID);
327 if ( name ) then
328 CT_MMForwardFrame.searchItem = name;
329 CT_MMForwardFrame.forwardStep = 1;
330 CT_MMForward_oldTakeInboxItem(InboxFrame.openMailID);
331 else
332 CT_MMForwardFrame.forwardStep = 2;
333 if ( money and money > 0 ) then
334 SetSendMailMoney(money);
335 CT_MMForwardFrame.countDown = 2;
336 CT_MMForward_oldTakeInboxMoney(InboxFrame.openMailID);
337 else
338 CT_MMForwardFrame.countDown = 0.5;
339 end
340 end
341 SendMailMailButton:Disable();
342 end
343  
344 function CT_MMForward_OnUpdate(elapsed)
345 if ( this.forwardStep and this.forwardStep > 1 ) then
346 if ( this.countDown ) then
347 this.countDown = this.countDown - elapsed;
348 if ( this.countDown <= 0 ) then
349 if ( this.forwardStep == 2 ) then
350 this.countDown = 0.5;
351 this.forwardStep = 3;
352 -- Send the mail
353 SendMail(SendMailNameEditBox:GetText(), SendMailSubjectEditBox:GetText(), SendMailBodyEditBox:GetText());
354 SendMailMailButton:Disable();
355 elseif ( this.forwardStep == 3 ) then
356 -- Delete the old one
357 local packageIcon, stationeryIcon, sender, subject, money, CODAmount, daysLeft, itemID, wasRead, wasReturned, textCreated = GetInboxHeaderInfo(InboxFrame.openMailID);
358 if ( money == 0 and not itemID ) then
359 DeleteInboxItem(InboxFrame.openMailID);
360 end
361 MailFrameTab_OnClick(1);
362 HideUIPanel(OpenMailFrame);
363 this.countDown = nil;
364 this.forwardStep = nil;
365 end
366 end
367 end
368 end
369 this.process = this.process - elapsed;
370 if ( this.process <= 0 ) then
371 this.process = 3;
372 if ( getn(CT_MMForward_ScheduledStack) > 0 ) then
373 CT_MMForward_ProcessStack();
374 end
375 end
376 end
377  
378 CT_MMForward_oldInboxFrame_OnClick = InboxFrame_OnClick;
379 function CT_MMForward_newInboxFrame_OnClick(id)
380 CT_MMForward_oldInboxFrame_OnClick(id);
381 local packageIcon, stationeryIcon, sender, subject, money, CODAmount, daysLeft, itemID, wasRead, wasReturned, textCreated = GetInboxHeaderInfo(id);
382 if ( CODAmount and CODAmount > 0 ) then
383 OpenMailForwardButton:Disable();
384 else
385 OpenMailForwardButton:Enable();
386 end
387 end
388 InboxFrame_OnClick = CT_MMForward_newInboxFrame_OnClick;
389  
390 function CT_MMForward_EnableForward(enable)
391 if ( enable ) then
392 OpenMailForwardButton:Disable();
393 SendMailPackageButton:SetScript("OnEnter", function() GameTooltip:SetOwner(SendMailPackageButton, "ANCHOR_RIGHT") GameTooltip:SetInboxItem(InboxFrame.openMailID) end);
394 SendMailCODButton:Disable();
395 CT_MMForward_DisableAttachments(1);
396 SendMailMailButton_OnClick = CT_MMForward_newSendMailMailButton_OnClick;
397 SendMailPackageButton_OnClick = function() end;
398 else
399 OpenMailForwardButton:Enable();
400 SendMailPackageButton:SetScript("OnEnter", CT_MMInbox_oldSendMailPackageButton_OnEnter);
401 SendMailCODButton:Enable();
402 CT_MMForward_DisableAttachments(nil);
403 SendMailPackageButton_OnClick = CT_MMForward_oldSendMailPackageButton_OnClick;
404 SendMailMailButton_OnClick = CT_MMForward_oldSendMailMailButton_OnClick;
405 end
406 end
407  
408 function CT_MMForward_AttachSlot(container, item)
409 PickupContainerItem(container, item);
410 ClickSendMailItemButton();
411 CT_MMForwardFrame.searchItem = nil;
412 CT_MMForwardFrame.forwardStep = 2;
413 CT_MMForwardFrame.countDown = 1.5;
414 end
415  
416 function CT_MMForward_ScanItems()
417 local old = { };
418 for k, v in CT_MMForward_BagLinks do
419 if ( type(v) == "table" ) then
420 old[k] = { };
421 for key, val in v do
422 old[k][key] = val;
423 end
424 end
425 end
426 CT_MMForward_BagLinks = { };
427 for i = 0, 4, 1 do
428 CT_MMForward_BagLinks[i] = { };
429 for y = 1, GetContainerNumSlots(i), 1 do
430 local curr = GetContainerItemLink(i, y);
431 local _, _, name = string.find(( curr or "" ), "%[(.+)%]");
432 if ( name ) then
433 if ( CT_MMForwardFrame.searchItem ) then
434 if ( name and name == CT_MMForwardFrame.searchItem and not old[i][y] ) then
435 CT_MMForward_AttachSlot(i, y);
436 end
437 elseif ( CT_MMInbox_StackMail ) then
438 local _, _, name = string.find(( curr or "" ), "%[(.+)%]");
439 if ( name and name == CT_MMForwardFrame.pickItem[1] and not old[i][y] ) then
440 tremove(CT_MMForwardFrame.pickItem, 1);
441 for k, v in old do
442 local hasFound;
443 for key, val in v do
444 if ( val == name and ( k ~= i or key ~= y ) ) then
445 local _,_, link = string.find((GetContainerItemLink(k, key) or ""), "(item:[%d:]+)")
446 if ( link ) then
447 local texture, itemCount = GetContainerItemInfo(k,key);
448 local tex, iC = GetContainerItemInfo(i, y);
449 local sName, sLink, iQuality, iLevel, sType, sSubType, iCount = GetItemInfo(link);
450 if ( sName and itemCount and iCount and iC ) then
451 if ( iCount >= (itemCount+iC) ) then
452 if ( getn(CT_MMForward_ScheduledStack) == 0 ) then
453 CT_MMForwardFrame.process = 2;
454 end
455 tinsert(CT_MMForward_ScheduledStack, { i, y, k, key });
456 hasFound = 1;
457 break;
458 end
459 end
460 end
461 end
462 end
463 if ( hasFound ) then
464 break;
465 end
466 end
467 end
468 end
469 CT_MMForward_BagLinks[i][y] = name;
470 end
471 end
472 end
473 end
474  
475 CT_MMForward_ScheduledStack = { };
476  
477 function CT_MMForward_ProcessStack()
478 local val = tremove(CT_MMForward_ScheduledStack, 1);
479 PickupContainerItem(val[1], val[2]);
480 PickupContainerItem(val[3], val[4]);
481 end
482  
483 CT_MMForward_oldMailFrameTab_OnClick = MailFrameTab_OnClick;
484 function CT_MMForward_newMailFrameTab_OnClick(id)
485 CT_MMForward_EnableForward();
486 CT_MMForward_oldMailFrameTab_OnClick(id);
487 end
488 MailFrameTab_OnClick = CT_MMForward_newMailFrameTab_OnClick;
489  
490 local oldSMMFfunc = SendMailMoneyFrame.onvalueChangedFunc;
491 SendMailMoneyFrame.onvalueChangedFunc = function()
492 if ( oldSMMFfunc ) then
493 oldSMMFfunc();
494 end
495 local subject = SendMailSubjectEditBox:GetText();
496 if ( subject == "" or string.find(subject, "%[%d+G, %d+S, %d+C%]") ) then
497 local copper, silver, gold = SendMailMoneyFrameCopper:GetText(), SendMailMoneyFrameSilver:GetText(), SendMailMoneyFrameGold:GetText();
498 if ( not tonumber(copper) ) then
499 copper = 0;
500 end
501 if ( not tonumber(silver) ) then
502 silver = 0;
503 end
504 if ( not tonumber(gold) ) then
505 gold = 0;
506 end
507 SendMailSubjectEditBox:SetText(format("[%sG, %sS, %sC]", gold, silver, copper));
508 end
509 end