vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 -- Allows the mail frame to be pushed
2 if ( UIPanelWindows["MailFrame"] ) then
3 UIPanelWindows["MailFrame"].pushable = 1;
4 else
5 UIPanelWindows["MailFrame"] = { area = "left", pushable = 1 };
6 end
7 -- This makes sure the FriendsFrame will close if you try to open a mail with mailframe+friendsframe open
8 if ( UIPanelWindows["FriendsFrame"] ) then
9 UIPanelWindows["FriendsFrame"].pushable = 2;
10 else
11 UIPanelWindows["FriendsFrame"] = { area = "left", pushable = 2 };
12 end
13 CT_MAIL_NUMITEMBUTTONS = 21;
14  
15 -- Hook the ContainerFrameItemButton_OnClick function
16 local CT_MM_oldCFIB_OC = ContainerFrameItemButton_OnClick;
17  
18 function CT_MM_ContainerFrameItemButton_OnClick(btn, ignore)
19 if ( CT_Mail_GetItemFrame(this:GetParent():GetID(), this:GetID()) ) then
20 return;
21 end
22  
23 CT_MM_oldCFIB_OC(btn, ignore);
24  
25 CT_Mail_UpdateItemButtons();
26 end
27  
28 ContainerFrameItemButton_OnClick = CT_MM_ContainerFrameItemButton_OnClick;
29  
30 CT_oldPickupContainerItem = PickupContainerItem;
31  
32 function CT_newPickupContainerItem(bag, item, special)
33 if ( ( CT_Mail_GetItemFrame(bag, item) or ( CT_Mail_addItem and CT_Mail_addItem[1] == bag and CT_Mail_addItem[2] == item ) ) and not special ) then
34 return;
35 end
36 if ( not CursorHasItem() ) then
37 CT_MailFrame.bag = bag;
38 CT_MailFrame.item = item;
39 end
40 if ( IsAltKeyDown() and CT_MailFrame:IsVisible() and not CursorHasItem() ) then
41 local i;
42 for i = 1, CT_MAIL_NUMITEMBUTTONS, 1 do
43 if ( not getglobal("CT_MailButton" .. i).item ) then
44  
45 local canMail = CT_Mail_ItemIsMailable(bag, item);
46 if ( canMail ) then
47 DEFAULT_CHAT_FRAME:AddMessage("<CTMod> Cannot attach item, item is " .. canMail, 1, 0.5, 0);
48 return;
49 end
50  
51 CT_oldPickupContainerItem(bag, item);
52 CT_MailButton_OnClick(getglobal("CT_MailButton" .. i));
53 CT_Mail_UpdateItemButtons();
54 return;
55 end
56 end
57 elseif ( IsAltKeyDown() and SendMailFrame:IsVisible() and not CursorHasItem() ) then
58 CT_oldPickupContainerItem(bag, item);
59 ClickSendMailItemButton();
60 return;
61 elseif ( IsAltKeyDown() and TradeFrame:IsVisible() and not CursorHasItem() ) then
62 for i = 1, 6, 1 do
63 if ( not GetTradePlayerItemLink(i) ) then
64 CT_oldPickupContainerItem(bag, item);
65 ClickTradeButton(i);
66 return;
67 end
68 end
69 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
70 InitiateTrade("target");
71 CT_Mail_addItem = { bag, item, UnitName("target"), 2 };
72 for i = 1, NUM_CONTAINER_FRAMES, 1 do
73 if ( getglobal("ContainerFrame" .. i):IsVisible() ) then
74 ContainerFrame_Update(getglobal("ContainerFrame" .. i));
75 end
76 end
77 return;
78 end
79 CT_oldPickupContainerItem(bag, item);
80 CT_Mail_UpdateItemButtons();
81 end
82  
83 PickupContainerItem = CT_newPickupContainerItem;
84  
85 -- Hook the MailFrameTab_OnClick function
86 local CT_MM_oldMFT_OC = MailFrameTab_OnClick;
87 function CT_MM_MailFrameTab_OnClick(tab)
88 if ( not tab ) then
89 tab = this:GetID();
90 end
91  
92 if ( tab == 3 ) then
93 PanelTemplates_SetTab(MailFrame, 3);
94 InboxFrame:Hide();
95 SendMailFrame:Hide();
96 CT_MailFrame:Show();
97 SendMailFrame.sendMode = "massmail";
98 MailFrameTopLeft:SetTexture("Interface\\ClassTrainerFrame\\UI-ClassTrainer-TopLeft");
99 MailFrameTopRight:SetTexture("Interface\\ClassTrainerFrame\\UI-ClassTrainer-TopRight");
100 MailFrameBotLeft:SetTexture("Interface\\ClassTrainerFrame\\UI-ClassTrainer-BotLeft");
101 MailFrameBotRight:SetTexture("Interface\\ClassTrainerFrame\\UI-ClassTrainer-BotRight");
102 MailFrameTopLeft:SetPoint("TOPLEFT", "MailFrame", "TOPLEFT", 2, -1);
103 return;
104 else
105 CT_MailFrame:Hide();
106 end
107 CT_MM_oldMFT_OC(tab);
108 end
109  
110 MailFrameTab_OnClick = CT_MM_MailFrameTab_OnClick;
111  
112 -- Hook the ClickSendMailItemButton function
113 local CT_MM_oldCSMIB = ClickSendMailItemButton;
114 function CT_MM_newCSMIB()
115 if ( not GetSendMailItem() ) then
116 CT_MailFrame.mailbag = CT_MailFrame.bag;
117 CT_MailFrame.mailitem = CT_MailFrame.item;
118 end
119 CT_MM_oldCSMIB();
120 end
121  
122 ClickSendMailItemButton = CT_MM_newCSMIB;
123  
124 -- Handle the dragging of items
125  
126 function CT_MailButton_OnClick(button)
127  
128 if ( not button ) then button = this; end
129 if ( CursorHasItem() ) then
130  
131 local bag = CT_MailFrame.bag;
132 local item = CT_MailFrame.item;
133  
134 if ( not bag or not item ) then return; end
135  
136 local canMail = CT_Mail_ItemIsMailable(bag, item)
137 if ( canMail ) then
138 DEFAULT_CHAT_FRAME:AddMessage("<CTMod> Cannot attach item, item is " .. canMail, 1, 0.5, 0);
139 CT_oldPickupContainerItem(bag, item);
140 return;
141 end
142  
143 CT_oldPickupContainerItem(bag, item);
144  
145 if ( this.bag and this.item ) then
146 -- There's already an item there
147 -- Pickup that item to replicate Send Mail's behaviour
148 CT_oldPickupContainerItem(button.bag, button.item);
149 CT_MailFrame.bag = button.bag;
150 CT_MailFrame.item = button.item;
151 else
152 CT_MailFrame.bag = nil;
153 CT_MailFrame.item = nil;
154 end
155  
156 local texture, count = GetContainerItemInfo(bag, item);
157  
158 getglobal(button:GetName() .. "IconTexture"):Show();
159 getglobal(button:GetName() .. "IconTexture"):SetTexture(texture);
160  
161 if ( count > 1 ) then
162 getglobal(button:GetName() .. "Count"):SetText(count);
163 getglobal(button:GetName() .. "Count"):Show();
164 else
165 getglobal(button:GetName() .. "Count"):Hide();
166 end
167  
168 button.bag = bag;
169 button.item = item;
170 button.texture = texture;
171 button.count = count;
172  
173 elseif ( button.item and button.bag ) then
174  
175 CT_oldPickupContainerItem(button.bag, button.item);
176 getglobal(button:GetName() .. "IconTexture"):Hide();
177 getglobal(button:GetName() .. "Count"):Hide();
178  
179 CT_MailFrame.bag = button.bag;
180 CT_MailFrame.item = button.item;
181  
182 button.item = nil;
183 button.bag = nil;
184 button.count = nil;
185 button.texture = nil;
186  
187 end
188 local num = CT_Mail_GetNumMails();
189 CT_MailFrame.num = num;
190 CT_Mail_CanSend(CT_MailNameEditBox);
191 if ( num == 0 ) then num = 1; end
192 MoneyFrame_Update("CT_MailCostMoneyFrame", GetSendMailPrice()*num);
193 for i = 1, NUM_CONTAINER_FRAMES, 1 do
194 if ( getglobal("ContainerFrame" .. i):IsVisible() ) then
195 ContainerFrame_Update(getglobal("ContainerFrame" .. i));
196 end
197 end
198 end
199  
200 function CT_Mail_ItemIsMailable(bag, item)
201  
202 -- Make sure tooltip is cleared
203 for i = 1, 29, 1 do
204 getglobal("CT_MMTooltipTextLeft" .. i):SetText("");
205 end
206  
207 CT_MMTooltip:SetBagItem(bag, item);
208 for i = 1, CT_MMTooltip:NumLines(), 1 do
209 local text = getglobal("CT_MMTooltipTextLeft" .. i):GetText();
210 if ( text == ITEM_SOULBOUND ) then
211 return "soulbound.";
212 elseif ( text == ITEM_BIND_QUEST ) then
213 return "a quest item.";
214 elseif ( text == ITEM_CONJURED ) then
215 return "a conjured item.";
216 end
217 end
218 return nil;
219 end
220  
221  
222 function CT_Mail_UpdateItemButtons(frame)
223 local i;
224 for i = 1, CT_MAIL_NUMITEMBUTTONS, 1 do
225 local btn = getglobal("CT_MailButton" .. i);
226 if ( not frame or btn ~= frame ) then
227 local texture, count;
228 if ( btn.item and btn.bag ) then
229 texture, count = GetContainerItemInfo(btn.bag, btn.item);
230 end
231 if ( not texture ) then
232 getglobal(btn:GetName() .. "IconTexture"):Hide();
233 getglobal(btn:GetName() .. "Count"):Hide();
234 btn.item = nil; btn.bag = nil; btn.count = nil; btn.texture = nil;
235 else
236 btn.count = count;
237 btn.texture = texture;
238 getglobal(btn:GetName() .. "IconTexture"):Show();
239 getglobal(btn:GetName() .. "IconTexture"):SetTexture(texture);
240 if ( count > 1 ) then
241 getglobal(btn:GetName() .. "Count"):Show();
242 getglobal(btn:GetName() .. "Count"):SetText(count);
243 else
244 getglobal(btn:GetName() .. "Count"):Hide();
245 end
246 end
247 end
248 end
249 end
250  
251 function CT_Mail_GetItemFrame(bag, item)
252 local i;
253 for i = 1, CT_MAIL_NUMITEMBUTTONS, 1 do
254 local btn = getglobal("CT_MailButton" .. i);
255 if ( btn.item == item and btn.bag == bag ) then
256 return btn;
257 end
258 end
259 return nil;
260 end
261  
262 function CT_Mail_GetNumMails()
263 local i;
264 local num = 0;
265 for i = 1, CT_MAIL_NUMITEMBUTTONS, 1 do
266 local btn = getglobal("CT_MailButton" .. i);
267 if ( btn.item and btn.bag ) then
268 num = num + 1;
269 end
270 end
271 return num;
272 end
273  
274 function CT_Mail_ClearItems()
275 local i;
276 local num = 0;
277 for i = 1, CT_MAIL_NUMITEMBUTTONS, 1 do
278 local btn = getglobal("CT_MailButton" .. i);
279 btn.item = nil;
280 btn.count = nil;
281 btn.bag = nil;
282 btn.texture = nil;
283 end
284 CT_Mail_UpdateItemButtons();
285 CT_MailMailButton:Disable();
286 CT_MailNameEditBox:SetText("");
287 CT_MailSubjectEditBox:SetText("");
288 CT_MailStatusText:SetText("");
289 CT_MailAbortButton:Hide();
290  
291 CT_Mail_AcceptSendFrame:Hide();
292 end
293  
294 function CT_Mail_AutoComplete()
295 local text = this:GetText();
296 local textlen = strlen(text);
297 local numFriends = GetNumFriends();
298 local name;
299 if ( numFriends > 0 ) then
300 for i=1, numFriends do
301 name = GetFriendInfo(i);
302 if ( name ) then
303 if ( strfind(strupper(name), "^"..strupper(text)) ) then
304 this:SetText(name);
305 this:HighlightText(textlen, -1);
306 return;
307 end
308 end
309 end
310 end
311  
312 -- Hack to scan offline members
313 local oldOffline = GetGuildRosterShowOffline();
314 SetGuildRosterShowOffline(true);
315  
316 local numGuildMembers = GetNumGuildMembers();
317 if ( numGuildMembers > 0 ) then
318 for i=1, numGuildMembers do
319 name = GetGuildRosterInfo(i);
320 if ( strfind(strupper(name), "^"..strupper(text)) ) then
321 this:SetText(name);
322 this:HighlightText(textlen, -1);
323 return;
324 end
325 end
326 end
327  
328 -- Revert to old scanning
329 SetGuildRosterShowOffline(oldOffline);
330 end
331  
332 SendMailFrame_SendeeAutocomplete = CT_Mail_AutoComplete; -- No need for a before/after hook, since our function does both friends & guildies
333  
334 function CT_Mail_CanSend(eb)
335 if ( not eb ) then eb = this; end
336 if ( strlen(eb:GetText()) > 0 and CT_MailFrame.num > 0 and GetSendMailPrice()*CT_MailFrame.num <= GetMoney() ) then
337 CT_MailMailButton:Enable();
338 else
339 CT_MailMailButton:Disable();
340 end
341 end
342  
343 function CT_Mail_SendMail()
344 for key, val in this.queue do
345 CT_MailStatusText:SetText(format(CT_MAIL_SENDING, key, this.total));
346 CT_MailAbortButton:Show();
347  
348 if ( GetSendMailItem() and CT_MailFrame.mailbag and CT_MailFrame.mailitem ) then
349 -- There's already an item in the slot
350 ClickSendMailItemButton();
351 CT_oldPickupContainerItem(CT_MailFrame.mailbag, CT_MailFrame.mailitem);
352 CT_MailFrame.mailbag = nil;
353 CT_MailFrame.mailitem = nil;
354 elseif ( CursorHasItem() and CT_MailFrame.bag and CT_MailFrame.item ) then
355 PickupContainerItem(CT_MailFrame.bag, CT_MailFrame.item);
356 CT_MailFrame.bag = nil;
357 CT_MailFrame.item = nil;
358 end
359  
360 CT_oldPickupContainerItem(val.bag, val.item);
361  
362 ClickSendMailItemButton();
363  
364 local name, useless, count = GetSendMailItem();
365  
366 if ( not name ) then
367 DEFAULT_CHAT_FRAME:AddMessage("<CTMod> " .. CT_MAIL_ERROR, 1, 0, 0);
368 else
369  
370 local subjectstr = CT_MailSubjectEditBox:GetText();
371 if ( strlen(subjectstr) > 0 ) then
372 subjectstr = subjectstr .. " ";
373 end
374  
375 if ( count > 1 ) then
376 subjectstr = subjectstr .. "[" .. name .. " x" .. count .. "]";
377 else
378 subjectstr = subjectstr .. "[" .. name .. "]";
379 end
380  
381 SendMail(val.to, subjectstr, format(CT_MAIL_ITEMNUM, key, this.total));
382 end
383  
384 CT_MailGlobalFrame.queue[key] = nil;
385 return;
386 end
387 CT_MailStatusText:SetText(format(CT_MAIL_DONESENDING, this.total));
388 CT_MailAbortButton:Hide();
389 CT_MailGlobalFrame:Hide();
390  
391 CT_MailGlobalFrame.total = 0;
392 CT_MailGlobalFrame.queue = { };
393 end
394  
395 function CT_Mail_FillItemTable()
396 local arr = { };
397 for i = 1, CT_MAIL_NUMITEMBUTTONS, 1 do
398 local btn = getglobal("CT_MailButton" .. i);
399 if ( btn.item and btn.bag ) then
400 tinsert(arr, { ["item"] = btn.item, ["bag"] = btn.bag, ["to"] = CT_MailNameEditBox:GetText() });
401 end
402 end
403 return arr;
404 end
405  
406 function CT_Mail_ProcessQueue(elapsed)
407 if ( not CT_Mail_CanSendNext ) then
408 return;
409 end
410 this.sendmail = this.sendmail + elapsed;
411 if ( this.sendmail > 0.5 ) then
412 this.sendmail = 0;
413 if ( this.total > 0 ) then
414 CT_Mail_SendMail();
415 CT_Mail_CanSendNext = nil;
416 end
417 end
418 end
419  
420 local CT_oldMM_CF_U = ContainerFrame_Update
421  
422 function CT_Mail_ContainerFrame_Update(frame)
423 CT_oldMM_CF_U(frame);
424  
425 local id = frame:GetID();
426 if ( CT_MailFrame:IsVisible() ) then
427 local i;
428 for i = 1, CT_MAIL_NUMITEMBUTTONS, 1 do
429 local btn = getglobal("CT_MailButton" .. i);
430 if ( btn.item and btn.bag ) then
431 if ( btn.bag == frame:GetID() ) then
432 SetItemButtonDesaturated(getglobal(frame:GetName() .. "Item" .. (frame.size-btn.item)+1), 1, 0.5, 0.5, 0.5);
433 end
434 end
435 end
436 end
437  
438 if ( CT_Mail_addItem and CT_Mail_addItem[1] == frame:GetID() ) then
439 SetItemButtonDesaturated(getglobal(frame:GetName() .. "Item" .. (frame.size-CT_Mail_addItem[2])+1), 1, 0.5, 0.5, 0.5);
440 end
441  
442 end
443  
444 ContainerFrame_Update = CT_Mail_ContainerFrame_Update;
445  
446 function CT_Mail_AddSubject()
447 if ( not SendMailFrame:IsVisible() ) then return; end
448 local name, useless, count = GetSendMailItem();
449  
450 if ( name and strlen(SendMailSubjectEditBox:GetText()) == 0 ) then
451 if ( count > 1 ) then
452 name = name .. " x" .. count;
453 end
454 SendMailSubjectEditBox:SetText(name);
455 end
456 end
457  
458 function CT_Mail_OnEvent(event)
459 if ( event == "MAIL_SEND_SUCCESS" ) then
460 CT_Mail_CanSendNext = 1;
461 else
462 CT_Mail_AddSubject();
463 end
464 end
465  
466 -- Show item link if there is one
467 CT_Mail_oldInboxFrameItem_OnEnter = InboxFrameItem_OnEnter;
468 function CT_Mail_newInboxFrameItem_OnEnter()
469 local didSetTooltip;
470 if ( this.index ) then
471 if ( GetInboxItem(this.index) ) then
472 GameTooltip:SetOwner(this, "ANCHOR_RIGHT");
473 GameTooltip:SetInboxItem(this.index);
474 didSetTooltip = 1;
475 end
476 end
477 if ( not didSetTooltip ) then
478 GameTooltip:SetOwner(this, "ANCHOR_RIGHT");
479 end
480 if (this.money) then
481 GameTooltip:AddLine(ENCLOSED_MONEY, "", 1, 1, 1);
482 SetTooltipMoney(GameTooltip, this.money);
483 SetMoneyFrameColor("GameTooltipMoneyFrame", HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b);
484 elseif (this.cod) then
485 GameTooltip:AddLine(COD_AMOUNT, "", 1, 1, 1);
486 SetTooltipMoney(GameTooltip, this.cod);
487 if ( this.cod > GetMoney() ) then
488 SetMoneyFrameColor("GameTooltipMoneyFrame", RED_FONT_COLOR.r, RED_FONT_COLOR.g, RED_FONT_COLOR.b);
489 else
490 SetMoneyFrameColor("GameTooltipMoneyFrame", HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b);
491 end
492 end
493 if ( didSetTooltip and ( this.money or this.cod ) ) then
494 GameTooltip:SetHeight(GameTooltip:GetHeight()+getglobal("GameTooltipTextLeft" .. GameTooltip:NumLines()):GetHeight());
495 if ( GameTooltipMoneyFrame:IsVisible() ) then
496 GameTooltip:SetHeight(GameTooltip:GetHeight()+GameTooltipMoneyFrame:GetHeight());
497 end
498 end
499 GameTooltip:Show();
500 end
501 InboxFrameItem_OnEnter = CT_Mail_newInboxFrameItem_OnEnter;
502  
503 -- Hook the TradeFrame OnShow
504 CT_Mail_oldTradeFrameShow = TradeFrame:GetScript("OnShow");
505 function CT_Mail_newTradeFrameShow()
506 CT_Mail_oldTradeFrameShow();
507 if ( CT_Mail_addItem and not CursorHasItem() and UnitName("NPC") == CT_Mail_addItem[3] ) then
508 CT_oldPickupContainerItem(CT_Mail_addItem[1], CT_Mail_addItem[2]);
509 ClickTradeButton(1);
510 end
511 CT_Mail_addItem = nil;
512 end
513 TradeFrame:SetScript("OnShow", CT_Mail_newTradeFrameShow);
514  
515 -- Add slash command for stacking
516 SlashCmdList["MAILSTACK"] = function()
517 CT_MMInbox_StackMail = not CT_MMInbox_StackMail;
518 if ( CT_MMInbox_StackMail ) then
519 CT_MMInbox_Print("<CTMod> Mail Stacking is now turned |cFF00FF00on|r.", 1, 1, 0);
520 else
521 CT_MMInbox_Print("<CTMod> Mail Stacking is now turned |cFFFF0000off|r.", 1, 1, 0);
522 end
523 end
524 SLASH_MAILSTACK1 = "/mailstack";
525 SLASH_MAILSTACK2 = "/ms";