vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 -- Titan Panel [Mail]
2 -- tekkub is the original creator of this mod
3 -- Bugfixes and updates by Larholm
4  
5 -- Version information
6 local TITAN_MAIL_VERSION = 1.15;
7 -- Constants
8 TITAN_MAIL_ID = "Mail";
9 TITAN_MAIL_ID_RIGHT = "MailRight";
10 TITAN_MAIL_ICON_NOMAIL = "Interface\\Cursor\\UnableMail";
11 TITAN_MAIL_ICON_NEW = "Interface\\Cursor\\Mail";
12 TITAN_MAIL_ICON_AH = "Interface\\Cursor\\LootAll";
13 TITAN_MAIL_ICON_AH_ALT = "Interface\\Icons\\Spell_Holy_RighteousFury";
14 TITAN_MAIL_SOUND = "Interface\\AddOns\\TitanMail\\mail.wav";
15  
16 --/script TitanMail_TestIcon("Interface\\Icons\\Spell_Nature_ThunderClap");
17 --/script TitanMail_TestIcon("Interface\\Icons\\Spell_Holy_RighteousFury");
18 --/script TitanMail_TestIcon("Interface\\HelpFrame\\OpenTicketIcon");
19 --/script TitanMail_TestIcon("Interface\\Icons\\INV_Letter_16");
20 --/script TitanMail_TestIcon("Interface\\Cursor\\Inspect");
21  
22 TITAN_FORMAT_COUNT_MAIL = "%u/%u";
23 TITAN_FORMAT_COUNT_NOMAIL = "0";
24 TITAN_FORMAT_TEXTCOUNT_MAIL = "%s (%u/%u)";
25  
26 -- Local variables
27 local TPM_numNew = 0;
28 local TPM_numTotal = 0;
29 local TPM_ignorenext = false;
30 local TPM_lastclose = 0;
31 local TPM_closedelay = 5;
32 local TPM_checkedmail = false;
33 local TPM_player = GetCVar("RealmName").. UnitName("player");
34 local TPM_debug = false;
35  
36 -- Events that don't fire UPDATE_PENDING_MAIL like they should
37 local TPM_brokenEvents = {
38 [ERR_AUCTION_WON_S] = false,
39 [ERR_AUCTION_SOLD_S] = false,
40 [ERR_AUCTION_OUTBID_S] = true,
41 [ERR_AUCTION_EXPIRED_S] = false,
42 [ERR_AUCTION_REMOVED_S] = false,
43 };
44  
45 ----------------------------------------------------------------------------------
46  
47 function TPM_Debug(str)
48 if (TPM_debug) then
49 DEFAULT_CHAT_FRAME:AddMessage("|cffff00ff<Mail> ".. str);
50 end
51 end
52  
53 function TitanPanelMailButton_OnLoad()
54 this.registry = {
55 id = TITAN_MAIL_ID,
56 menuText = TITAN_MAIL_MENU_TEXT,
57 buttonTextFunction = "TitanPanelMailButton_GetButtonText",
58 tooltipTitle = TITAN_MAIL_TOOLTIP,
59 tooltipTextFunction = "TitanPanelMailButton_GetTooltipText",
60 icon = TITAN_MAIL_ICON_NEW,
61 category = "Information",
62 version = TITAN_MAIL_VERSION,
63 iconWidth = 16,
64 savedVariables = {
65 ShowIcon = 1,
66 ShowIconAlt = 0,
67 ShowCount = 1,
68 NoIconNoMail = 0,
69 ShowText = 1,
70 compact = 1,
71 hidemm = 1,
72 new = 0,
73 total = 0,
74 sound = 1,
75 chat = 1,
76 }
77 };
78  
79 this:RegisterEvent("VARIABLES_LOADED");
80 this:RegisterEvent("CHAT_MSG_SYSTEM");
81 this:RegisterEvent("MAIL_SHOW");
82 this:RegisterEvent("MAIL_CLOSED");
83 this:RegisterEvent("MAIL_INBOX_UPDATE");
84 this:RegisterEvent("UPDATE_PENDING_MAIL");
85 this:RegisterEvent("PLAYER_ENTERING_WORLD");
86 if( DEFAULT_CHAT_FRAME ) then
87 DEFAULT_CHAT_FRAME:AddMessage("Titan Panel [Mail] v"..TITAN_MAIL_VERSION.." loaded");
88 end
89 end
90  
91 function TitanPanelMailRightButton_OnLoad()
92 this.registry = {
93 id = TITAN_MAIL_ID_RIGHT,
94 menuText = TITAN_MAILRIGHT_MENU_TEXT,
95 buttonTextFunction = "TitanPanelMailButton_GetButtonText",
96 tooltipTitle = TITAN_MAIL_TOOLTIP,
97 tooltipTextFunction = "TitanPanelMailButton_GetTooltipText",
98 icon = TITAN_MAIL_ICON_NEW,
99 version = TITAN_MAIL_VERSION,
100 iconWidth = 16,
101 category = "Information",
102 };
103 end
104  
105 function TitanPanelMailButton_UpdateIcon(forceAH)
106 local hidemm = TitanGetVar(TITAN_MAIL_ID, "hidemm");
107 local total = TitanGetVar(TITAN_MAIL_ID, "total");
108 local iconshown = TitanGetVar(TITAN_MAIL_ID, "ShowIcon");
109 local alticon = TitanGetVar(TITAN_MAIL_ID, "ShowIconAlt");
110 local noiconnomail = TitanGetVar(TITAN_MAIL_ID, "NoIconNoMail");
111  
112 MiniMapMailFrame:Show();
113  
114 if (hidemm and MiniMapMailFrame:IsVisible()) then
115 MiniMapMailFrame:Hide();
116 end
117  
118 local button = TitanUtils_GetButton(TITAN_MAIL_ID, true);
119 local buttonR = TitanUtils_GetButton(TITAN_MAIL_ID_RIGHT, true);
120  
121 if (iconshown) then
122 -- TPM_Debug("Icon is shown");
123 else
124 -- TPM_Debug("Icon is hidden");
125 end
126  
127  
128 if TITAN_MAIL_SETTINGS[TPM_player].ahalerts then
129 if (alticon) then
130 button.registry.icon = TITAN_MAIL_ICON_AH_ALT;
131 buttonR.registry.icon = TITAN_MAIL_ICON_AH_ALT;
132 else
133 button.registry.icon = TITAN_MAIL_ICON_AH;
134 buttonR.registry.icon = TITAN_MAIL_ICON_AH;
135 end
136 elseif ((total and (total > 0)) or (HasNewMail() and (not TPM_checkedmail))) then
137 button.registry.icon = TITAN_MAIL_ICON_NEW;
138 buttonR.registry.icon = TITAN_MAIL_ICON_NEW;
139 elseif (noiconnomail) then
140 button.registry.icon = "";
141 buttonR.registry.icon = "";
142 else
143 button.registry.icon = TITAN_MAIL_ICON_NOMAIL;
144 buttonR.registry.icon = TITAN_MAIL_ICON_NOMAIL;
145 end
146 if (forceAH) then
147 if (alticon) then
148 button.registry.icon = TITAN_MAIL_ICON_AH_ALT;
149 buttonR.registry.icon = TITAN_MAIL_ICON_AH_ALT;
150 else
151 button.registry.icon = TITAN_MAIL_ICON_AH;
152 buttonR.registry.icon = TITAN_MAIL_ICON_AH;
153 end
154 end
155 TitanPanelButton_UpdateButton(TITAN_MAIL_ID);
156 TitanPanelButton_UpdateButton(TITAN_MAIL_ID_RIGHT);
157 end
158  
159 function TitanPanelMailButton_GetButtonText(id)
160 local showt = TitanGetVar(TITAN_MAIL_ID, "ShowText");
161 local showc = TitanGetVar(TITAN_MAIL_ID, "ShowCount");
162 local new = TitanGetVar(TITAN_MAIL_ID, "new");
163 local total = TitanGetVar(TITAN_MAIL_ID, "total");
164  
165 if (not total) then return; end
166  
167 local buttonRichText = "";
168  
169 if (showt and (not showc)) then
170 if TITAN_MAIL_SETTINGS[TPM_player].ahalerts then
171 buttonRichText = TitanUtils_GetRedText(TITAN_MAIL_BUTTON_TEXT_ALERT);
172 elseif ((total > 0) or (HasNewMail() and (not TPM_checkedmail))) then
173 buttonRichText = TitanUtils_GetGreenText(TITAN_MAIL_BUTTON_TEXT_MAIL);
174 else
175 buttonRichText = TitanUtils_GetNormalText(TITAN_MAIL_BUTTON_TEXT_NOMAIL);
176 end
177 elseif (showc and showt) then
178 if TITAN_MAIL_SETTINGS[TPM_player].ahalerts then
179 buttonRichText = TitanUtils_GetRedText(string.format(TITAN_FORMAT_TEXTCOUNT_MAIL, TITAN_MAIL_BUTTON_TEXT_ALERT, new, total));
180 elseif ((total > 0) or (HasNewMail() and (not TPM_checkedmail))) then
181 buttonRichText = TitanUtils_GetGreenText(string.format(TITAN_FORMAT_TEXTCOUNT_MAIL, TITAN_MAIL_BUTTON_TEXT_MAIL, new, total));
182 else
183 buttonRichText = TitanUtils_GetNormalText(TITAN_MAIL_BUTTON_TEXT_NOMAIL);
184 end
185 else
186 if TITAN_MAIL_SETTINGS[TPM_player].ahalerts then
187 buttonRichText = TitanUtils_GetRedText(string.format(TITAN_FORMAT_COUNT_MAIL, new, total));
188 elseif ((total > 0) or (HasNewMail() and (not TPM_checkedmail))) then
189 buttonRichText = TitanUtils_GetGreenText(string.format(TITAN_FORMAT_COUNT_MAIL, new, total));
190 else
191 buttonRichText = TitanUtils_GetNormalText(TITAN_FORMAT_COUNT_NOMAIL);
192 end
193 end
194 return buttonRichText;
195 end
196  
197 function TitanPanelMailButton_GetTooltipText()
198 local retstr = "";
199 local new = TitanGetVar(TITAN_MAIL_ID, "new");
200 local total = TitanGetVar(TITAN_MAIL_ID, "total");
201  
202 if (total > 0) or (HasNewMail()) then
203 retstr = retstr.. TITAN_MAIL_BUTTON_TEXT_MAIL.. "\n\n";
204 retstr = retstr.. TitanUtils_GetGreenText(new.. TITAN_MAIL_TOOLTIP_NEW);
205 retstr = retstr.. TitanUtils_GetNormalText(total.. TITAN_MAIL_TOOLTIP_TOTAL)
206  
207 else
208 retstr = TITAN_MAIL_BUTTON_TEXT_NOMAIL;
209 end
210  
211 if TITAN_MAIL_SETTINGS[TPM_player].ahalerts then
212 retstr = retstr.. "\n";
213 for i=1,table.getn(TITAN_MAIL_SETTINGS[TPM_player].ahalerts) do
214 retstr = retstr.. "\n".. TITAN_MAIL_SETTINGS[TPM_player].ahalerts[i];
215 end
216 end
217  
218 return retstr;
219 end
220  
221 function TitanPanelMailButton_OnEvent()
222 TPM_Debug(time().. " ".. event);
223 if (event == "VARIABLES_LOADED") then
224 if (not TITAN_MAIL_SETTINGS) then TITAN_MAIL_SETTINGS = {}; end
225 if (not TITAN_MAIL_SETTINGS[TPM_player]) then TITAN_MAIL_SETTINGS[TPM_player] = {}; end
226 TitanPanelMailButton_UpdateIcon(false);
227 end
228 if (event == "PLAYER_ENTERING_WORLD") then
229 TPM_Debug("Ignoring next pending");
230 TPM_ignorenext = true;
231 end
232 if (event == "CHAT_MSG_SYSTEM") then
233 TitanMail_ReadAHMsg(arg1);
234 TitanPanelMailButton_UpdateIcon(false);
235 end
236 if (event == "MAIL_SHOW") then
237 TPM_checkedmail = true;
238 TITAN_MAIL_SETTINGS[TPM_player].ahalerts = nil;
239 TitanPanelMailButton_UpdateIcon(false);
240 end
241 if (event == "MAIL_CLOSED") then
242 TPM_lastclose = time()
243 end
244 if ( event == "MAIL_INBOX_UPDATE" ) then
245 TPM_Debug("Inbox: ".. GetInboxNumItems());
246 TitanSetVar(TITAN_MAIL_ID, "new", 0);
247 TitanSetVar(TITAN_MAIL_ID, "total", GetInboxNumItems());
248 TitanPanelMailButton_UpdateIcon(false);
249 end
250 if ( event == "UPDATE_PENDING_MAIL" ) then
251 if ((TPM_lastclose + TPM_closedelay) > time()) then
252 TPM_Debug("Ignoring this pending");
253 TPM_ignorenext = true
254 end
255 if (HasNewMail()) then TPM_Debug("Has mail"); end
256 TitanMail_IncNew()
257 TitanPanelMailButton_UpdateIcon(false);
258 end
259 end
260  
261 function TitanMail_Debug(state)
262 TPM_debug = state
263 end
264  
265 function TitanMail_TestIcon(icon)
266 local button = TitanUtils_GetButton(TITAN_MAIL_ID, true);
267 button.registry.icon = icon;
268 TitanPanelButton_UpdateButton(TITAN_MAIL_ID);
269 end
270  
271 function TitanMail_TestInc(isAH)
272 TitanMail_IncNew()
273 if (isAH) then
274 TitanPanelMailButton_UpdateIcon(true);
275 PlaySound("AuctionWindowOpen");
276 else
277 TitanPanelMailButton_UpdateIcon(false);
278 PlaySoundFile(TITAN_MAIL_SOUND);
279 end
280 end
281  
282 function TitanMail_IncNew()
283 if (TPM_ignorenext) then
284 TPM_Debug("Ignoring that one");
285 TPM_ignorenext = false;
286 else
287 local new = TitanGetVar(TITAN_MAIL_ID, "new") + 1;
288 local total = TitanGetVar(TITAN_MAIL_ID, "total") + 1;
289  
290 if (TPM_checkedmail) then
291 total = GetInboxNumItems() + new;
292 end
293  
294 TitanSetVar(TITAN_MAIL_ID, "new", new)
295 TitanSetVar(TITAN_MAIL_ID, "total", total)
296  
297 if (TitanGetVar(TITAN_MAIL_ID, "chat")) then
298 DEFAULT_CHAT_FRAME:AddMessage(TITAN_MAIL_CHAT_NEW.."("..new.."/"..total..")");
299 end
300 if (TitanGetVar(TITAN_MAIL_ID, "sound")) then
301 PlaySoundFile(TITAN_MAIL_SOUND);
302 TPM_Debug("Play Sound");
303 end
304  
305 end
306 end
307  
308 function TitanMail_ReadAHMsg(msg)
309 local foundAH = false;
310 local strset = {
311 {ERR_AUCTION_WON_S, TITAN_MAIL_TOOLTIP_WON},
312 {ERR_AUCTION_SOLD_S, TITAN_MAIL_TOOLTIP_SOLD},
313 {ERR_AUCTION_OUTBID_S, TITAN_MAIL_TOOLTIP_OUTBID},
314 {ERR_AUCTION_EXPIRED_S, TITAN_MAIL_TOOLTIP_EXPIRED},
315 {ERR_AUCTION_REMOVED_S, TITAN_MAIL_TOOLTIP_CANCELLED},
316 };
317  
318 for i,arr in strset do
319 local searchstr = string.gsub(arr[1], "%%[^%s]+", "(.+)")
320 local _, _, item = string.find(msg, searchstr)
321 if (item) then
322 if (not TITAN_MAIL_SETTINGS[TPM_player].ahalerts) then
323 TITAN_MAIL_SETTINGS[TPM_player].ahalerts = {};
324 end
325 tinsert(TITAN_MAIL_SETTINGS[TPM_player].ahalerts, arr[2].. item);
326 -- Increment our count if this is a bugged event
327 if (TPM_brokenEvents[arr[1]]) then
328 TitanMail_IncNew();
329 brokenevent = true;
330 end
331 foundAH = true;
332 end
333 end
334  
335 if (foundAH) then
336 TPM_Debug("AH Mail");
337 if (TitanGetVar(TITAN_MAIL_ID, "sound")) then
338 --PlaySound("AuctionWindowOpen");
339 --TPM_Debug("Play Sound AH");
340 end
341 else
342 TPM_Debug("Not an AH message.");
343 end
344  
345 end
346  
347 function TitanPanelRightClickMenu_PrepareMailRightMenu()
348 TitanMail_PrepareMenu(true)
349 end
350  
351 function TitanPanelRightClickMenu_PrepareMailMenu()
352 TitanMail_PrepareMenu()
353 end
354  
355 function TitanMail_PrepareMenu(isright)
356 local info;
357  
358 TitanPanelRightClickMenu_AddTitle(TitanPlugins[TITAN_MAIL_ID].menuText);
359 TitanPanelRightClickMenu_AddSpacer();
360  
361 info = {};
362 info.text = TITAN_MAIL_MENU_HIDEMM;
363 info.value = "hidemm";
364 info.keepShownOnClick = 1;
365 info.func = TitanMail_Toggle;
366 info.checked = TitanGetVar(TITAN_MAIL_ID, "hidemm");
367 UIDropDownMenu_AddButton(info);
368  
369 info = {};
370 info.text = TITAN_MAIL_MENU_SOUND;
371 info.value = "sound";
372 info.func = TitanMail_Toggle;
373 info.keepShownOnClick = 1;
374 info.checked = TitanGetVar(TITAN_MAIL_ID, "sound");
375 UIDropDownMenu_AddButton(info);
376  
377 info = {};
378 info.text = TITAN_MAIL_MENU_CHAT;
379 info.value = "chat";
380 info.func = TitanMail_Toggle;
381 info.keepShownOnClick = 1;
382 info.checked = TitanGetVar(TITAN_MAIL_ID, "chat");
383 UIDropDownMenu_AddButton(info);
384  
385 if (not isright) then
386 TitanPanelRightClickMenu_AddSpacer();
387 local info = {};
388 info.text = TITAN_PANEL_MENU_SHOW_ICON;
389 info.value = "ShowIcon";
390 info.func = TitanMail_Toggle;
391 info.checked = TitanGetVar(TITAN_MAIL_ID, "ShowIcon");
392 info.keepShownOnClick = 1;
393 UIDropDownMenu_AddButton(info);
394  
395 info = {};
396 info.text = TITAN_MAIL_MENU_STEXT;
397 info.value = "ShowText";
398 info.func = TitanMail_Toggle;
399 info.checked = TitanGetVar(TITAN_MAIL_ID, "ShowText");
400 info.keepShownOnClick = 1;
401 UIDropDownMenu_AddButton(info);
402  
403 info = {};
404 info.text = TITAN_MAIL_MENU_COUNT;
405 info.value = "ShowCount";
406 info.func = TitanMail_Toggle;
407 info.keepShownOnClick = 1;
408 info.checked = TitanGetVar(TITAN_MAIL_ID, "ShowCount");
409 UIDropDownMenu_AddButton(info);
410 end
411  
412 TitanPanelRightClickMenu_AddSpacer();
413  
414 info = {};
415 info.text = TITAN_MAIL_MENU_ALTICON;
416 info.value = "ShowIconAlt";
417 info.func = TitanMail_Toggle;
418 info.keepShownOnClick = 1;
419 info.checked = TitanGetVar(TITAN_MAIL_ID, "ShowIconAlt");
420 UIDropDownMenu_AddButton(info);
421  
422 info = {};
423 info.text = TITAN_MAIL_MENU_NOICONNOMAIL;
424 info.value = "NoIconNoMail";
425 info.func = TitanMail_Toggle;
426 info.keepShownOnClick = 1;
427 info.checked = TitanGetVar(TITAN_MAIL_ID, "NoIconNoMail");
428 UIDropDownMenu_AddButton(info);
429  
430 TitanPanelRightClickMenu_AddSpacer();
431  
432 if (isright) then
433 TitanPanelRightClickMenu_AddCommand(TITAN_PANEL_MENU_HIDE, TITAN_MAIL_ID_RIGHT, TITAN_PANEL_MENU_FUNC_HIDE);
434 else
435 TitanPanelRightClickMenu_AddCommand(TITAN_PANEL_MENU_HIDE, TITAN_MAIL_ID, TITAN_PANEL_MENU_FUNC_HIDE);
436 end
437  
438 end
439  
440 function TitanMail_Toggle()
441 TitanToggleVar(TITAN_MAIL_ID, this.value);
442 TitanPanelMailButton_UpdateIcon(false);
443 end
444  
445 local function sorted_index(table)
446 local index = {}
447 for key in table do tinsert(index,key); end
448 sort(index)
449 return index
450 end