comparison Modules/OpenAll.lua @ 0:823e33465b6e

Initial commit
author Zerotorescue
date Fri, 03 Sep 2010 12:43:36 +0200
parents
children 6f17035de058
comparison
equal deleted inserted replaced
-1:000000000000 0:823e33465b6e
1 local MailOpener = LibStub("AceAddon-3.0"):GetAddon("MailOpener");
2 local OpenAll = MailOpener:NewModule("OpenAll", "AceEvent-3.0", "AceTimer-3.0");
3
4 local MAIL_ITEM_INDEX, mailTimer, inventoryFull, inventoryFullSoundPlayed, opening, lastSync, numCurrentMail, numHiddenMail, continue;
5
6 function OpenAll:OnInitialize()
7 local defaults = {
8 profile = {
9 speed = 0.05,
10 keepFreeSpace = 0,
11 filter = {
12 AH = {
13 canceled = true,
14 expired = true,
15 outbid = true,
16 success = true,
17 won = true,
18 },
19 normalAttachments = false,
20 normalMoney = true,
21 },
22 },
23 };
24
25 -- Register our saved variables NameSpace
26 self.db = MailOpener.db:RegisterNamespace("OpenAll", defaults);
27 end
28
29 function OpenAll:OnEnable()
30 self:RegisterEvent("MAIL_SHOW");
31
32 if not self.btnOpenAll then
33 -- Open all button
34 local button = CreateFrame("Button", "btnMailOpenerOpenAll", InboxFrame, "UIPanelButtonTemplate")
35 button:SetText("Open all")
36 button:SetHeight(26)
37 button:SetWidth(120)
38 button:SetPoint("BOTTOM", InboxFrame, "CENTER", -10, -165)
39 button:SetScript("OnClick", function() OpenAll:Open(true) end)
40
41 self.btnOpenAll = button;
42 end
43
44 self.btnOpenAll:Show();
45
46 if not self.timeLeftFrame then
47 -- If the timeLeftFrame doesn't exist we will have to build it
48
49 self:Debug("Building text frame");
50
51 local frame = CreateFrame("Button", "MailOpenerTimeLeftButton", InboxFrame);
52
53 -- Mail counter
54 frame.text = frame:CreateFontString("MailOpenerTimeLeftFrameMailCount", "OVERLAY", "GameFontHighlight");
55 frame.text:SetPoint("CENTER", MailFrame, "TOPLEFT", 40, -35);
56
57 -- Long time left indicator
58 frame.smallText = frame:CreateFontString("MailOpenerTimeLeftFrameTimeRemaining", "OVERLAY", "GameFontNormal");
59 frame.smallText:SetFont(GameFontHighlight:GetFont(), 11, "OUTLINE");
60 frame.smallText:SetPoint("TOPLEFT", MailFrame, "TOPLEFT", 75, -38);
61 frame.smallText:SetWidth(270);
62 frame.smallText:SetJustifyH("LEFT");
63 frame.smallText:SetJustifyV("MIDDLE");
64
65 frame:SetPoint("TOPLEFT", MailFrame, "TOPLEFT", 75, -38);
66 frame:SetWidth(270);
67 frame:SetHeight(35);
68 frame:SetScript("OnClick", function(self)
69 local timeRemainingUntillOpened = frame.smallText:GetText();
70 if timeRemainingUntillOpened then
71 MailOpener.currentPopupContents = "|cffffd700" .. timeRemainingUntillOpened .. "|r";
72
73 StaticPopup_Show("MailOpenerCopyWindow");
74 end
75 end);
76
77 self.timeLeftFrame = frame;
78 end
79
80 self.timeLeftFrame:Show();
81
82 -- Go through all children of the mail frame to find QA's elements and hide these
83 local kids = { MailFrame:GetChildren() };
84
85 for _, child in ipairs(kids) do
86 if child and child.text then
87 child.text:Hide();
88 end
89 end
90
91 -- If we were toggling this module on while the mailbox is opened we must register all events again
92 if MailFrame:IsVisible() then
93 self:MAIL_SHOW();
94 end
95 end
96
97 function OpenAll:OnDisable()
98 self:UnregisterEvent("MAIL_SHOW");
99
100 if self.btnOpenAll then
101 self.btnOpenAll:Hide();
102 end
103
104 if self.timeLeftFrame then
105 self.timeLeftFrame:Hide();
106 end
107
108 if MailOpener.PostalEnabled then
109 -- Enable Postal's openers again
110
111 MailOpener:TogglePostalModule("OpenAll", true);
112 MailOpener:TogglePostalModule("Select", true);
113 end
114
115 -- Go through all children of the mail frame to find QA's elements and SHOW these
116 local kids = { MailFrame:GetChildren() };
117
118 for _, child in ipairs(kids) do
119 if child and child.text then
120 child.text:Show();
121 end
122 end
123
124 self:Stop();
125 end
126
127 function OpenAll:MAIL_SHOW()
128 self:Debug("MAIL_SHOW");
129
130 self:StopOpening(false);
131
132 if MailOpener.PostalEnabled then
133 -- Disable Postal's openers so we can do it ourselves
134
135 MailOpener:TogglePostalModule("OpenAll", false);
136 MailOpener:TogglePostalModule("Select", false);
137 end
138
139 -- Keep an eye for closing of the mailbox
140 self:RegisterEvent("MAIL_CLOSED", "Stop");
141 self:RegisterEvent("PLAYER_LEAVING_WORLD", "Stop");
142
143 -- Look if the mailbox is full
144 self:RegisterEvent("UI_ERROR_MESSAGE");
145 -- Only look again after bags updated
146 self:RegisterEvent("BAG_UPDATE");
147 self:RegisterEvent("MAIL_INBOX_UPDATE");
148
149 -- We need to know when to start opening
150 self:RegisterMessage("MO_OPEN_MAIL", "Open");
151 self:RegisterMessage("MO_SERVER_SYNCED");
152
153 self:CancelTimer(self.tmrTimeRemaining, true);
154 self.tmrTimeRemaining = self:ScheduleRepeatingTimer("UpdateTimer", 1);
155 self:UpdateTimer();
156 end
157
158 function OpenAll:Stop()
159 self:Debug("Stop");
160
161 -- We shutdown, so nothing to do when the mailbox is closed anymore
162 self:UnregisterEvent("MAIL_CLOSED");
163 self:UnregisterEvent("PLAYER_LEAVING_WORLD");
164
165 -- We care about a full inventory just a little
166 self:UnregisterEvent("UI_ERROR_MESSAGE");
167 self:UnregisterEvent("BAG_UPDATE");
168 self:UnregisterEvent("MAIL_INBOX_UPDATE");
169
170 -- We no longer care
171 self:UnregisterMessage("MO_OPEN_MAIL");
172 self:UnregisterMessage("MO_SERVER_SYNCED");
173
174 self:CancelTimer(self.tmrMailOpener, true);
175 self:CancelTimer(self.tmrTimeRemaining, true);
176
177 self:SetOpeningStatus(false);
178 end
179
180 function OpenAll:MO_SERVER_SYNCED()
181 self:Debug("MO_SERVER_SYNCED");
182
183 lastSync = GetTime();
184
185 local numItems, totalItems = GetInboxNumItems();
186
187 numCurrentMail = numItems;
188 numHiddenMail = ( totalItems - numItems );
189 end
190
191 function OpenAll:BAG_UPDATE()
192 -- If the bags are updated we should check if the inventory is full again
193 inventoryFull = false;
194 end
195
196 function OpenAll:MAIL_INBOX_UPDATE()
197 local numItems, totalItems = GetInboxNumItems();
198
199 if numItems ~= numCurrentMail then
200 continue = true;
201
202 if numCurrentMail ~= nil and numItems > numCurrentMail then
203 -- This is a server sync
204
205 self:StopOpening(false);
206 end
207 end
208
209 numCurrentMail = numItems;
210 numHiddenMail = ( totalItems - numItems );
211
212 self:UpdateTimer();
213 end
214
215 -- We registered this event to look for the inventory full error message because this is faster than counting the amount of items in the inventory all the time
216 function OpenAll:UI_ERROR_MESSAGE(e, errorMessage)
217 if errorMessage == ERR_INV_FULL then
218 -- Inventory is full.
219
220 if not inventoryFull then
221 inventoryFull = true;
222
223 -- Play the sound
224 if MailOpener.db.profile.notifications.bagsFullSound and (not MailOpener.db.profile.notifications.bagsFullSoundOnlyOnce or not inventoryFullSoundPlayed) then
225 PlaySoundFile(MailOpener.db.profile.notifications.bagsFullSoundFile);
226 inventoryFullSoundPlayed = true;
227 end
228 end
229
230 -- Continue opening mail (we still want to open gold mail)
231 continue = true;
232 elseif errorMessage == ERR_ITEM_MAX_COUNT or errorMessage == ERR_MAIL_DATABASE_ERROR then
233 -- Can't carry more of this item OR mail database error
234
235 -- Continue opening mail (we still want to retrieve other items or gold)
236 continue = true;
237 end
238 end
239
240 function OpenAll:Open(forced)
241 self:Debug("Open");
242
243 if not opening or forced == true then
244 local numItems, totalItems = GetInboxNumItems();
245 -- Start at the end, add one because OpenNext will take it away again
246 local newMailItemIndex = ( ( numItems or 0 ) + 1 );
247
248 if newMailItemIndex > 1 then
249 self:Debug("Open succes");
250
251 -- Stop the previous opening and restart
252 if forced == true then
253 self:StopOpening(false); -- this is not a "simple" stop, so also reset inventory full warning
254 else
255 self:StopOpening(true); -- forced is false - automated action - simple reset, skip inventory full reset to avoid sound spam
256 end
257
258 -- Update the caret
259 MAIL_ITEM_INDEX = newMailItemIndex;
260
261 -- We're now going to be busy again
262 self:SetOpeningStatus(true);
263
264 -- Open the next mail in line
265 self:OpenNext();
266 else
267 if MailOpener.db.profile.notifications.mailboxIsEmpty then
268 print("|cffff0000There is currently no mail available.|r");
269 end
270
271 self:Debug("MO_OPEN_COMPLETE");
272
273 -- Report that we're all done
274 self:SendMessage("MO_OPEN_COMPLETE");
275 end
276 end
277 end
278
279 -- Return the type of mail a message subject is
280 local knownAHSubjectPatterns = {
281 canceled = AUCTION_REMOVED_MAIL_SUBJECT:replace("%s", ""),
282 expired = AUCTION_EXPIRED_MAIL_SUBJECT:replace("%s", ""),
283 outbid = AUCTION_OUTBID_MAIL_SUBJECT:replace("%s", ""),
284 success = AUCTION_SOLD_MAIL_SUBJECT:replace("%s", ""),
285 won = AUCTION_WON_MAIL_SUBJECT:replace("%s", ""),
286 };
287 function OpenAll:GetAuctionMailType(subject)
288 if subject then
289 -- Check if any of our patterns match, sorted by most likely matches first (if one is true the rest shouldn't be evaluated)
290 if subject:find(knownAHSubjectPatterns.expired) then
291 return "expired";
292 elseif subject:find(knownAHSubjectPatterns.success) then
293 return "success";
294 elseif subject:find(knownAHSubjectPatterns.won) then
295 return "won";
296 elseif subject:find(knownAHSubjectPatterns.canceled) then
297 return "canceled";
298 elseif subject:find(knownAHSubjectPatterns.outbid) then
299 return "outbid";
300 end
301 end
302
303 return; -- not auction mail
304 end
305
306 function OpenAll:OpenMail(index)
307 if index > 0 then
308 -- LUA arrays start at 1, so mail with index 0 doesn't exist, so we're finished
309
310 local sender, subject, gold, cod, _, items, _, _, _, _, isGM = select(3, GetInboxHeaderInfo(index));
311 local auctionMailType = self:GetAuctionMailType(subject);
312
313 if isGM then
314 -- GM Mail
315 if MailOpener.db.profile.notifications.skipped.all and MailOpener.db.profile.notifications.skipped.GMMail then
316 print("Skipping " .. index .. ": " .. subject .. " (GM mail)");
317 end
318
319 self:OpenNext();
320
321 return;
322 elseif cod and cod > 0 then
323 -- Cost on delivery
324 if MailOpener.db.profile.notifications.skipped.all and MailOpener.db.profile.notifications.skipped.COD then
325 print("Skipping " .. index .. ": " .. subject .. " (C.O.D.)");
326 end
327
328 self:OpenNext();
329
330 return;
331 elseif ((gold and gold > 0) or (items and items > 0)) then
332 -- Mail with some sort of attachments
333
334 local slotsAvailable = 0;
335 if self.db.profile.keepFreeSpace > 0 then
336 for bag = 0, 4 do
337 local numberOfFreeSlots = GetContainerNumFreeSlots(bag);
338 slotsAvailable = ( slotsAvailable + numberOfFreeSlots );
339 end
340 end
341
342 if inventoryFull and not MailOpener.db.profile.general.continueOpeningStackableItems and items and items > 0 then
343 if MailOpener.db.profile.notifications.skipped.all and MailOpener.db.profile.notifications.skipped.inventoryFull then
344 print("Skipping " .. index .. ": " .. subject .. " (inventory is full)");
345 end
346
347 self:OpenNext();
348
349 return;
350 elseif self.db.profile.keepFreeSpace > 0 and items and ( slotsAvailable - items ) < self.db.profile.keepFreeSpace then
351 if MailOpener.db.profile.notifications.skipped.all and MailOpener.db.profile.notifications.skipped.keepFreeSpaceLimit then
352 print("Skipping " .. index .. ": " .. subject .. " (keep free space limit)");
353 end
354
355 self:OpenNext();
356
357 return;
358 else
359 -- This string will hold the mailtype, MailOpener.db.profile.notifications.skipped/processed[mailType] will be checked if this should be announced
360 local mailType = "other";
361
362 if not auctionMailType then
363 -- This is a normal mail
364
365 if gold and gold > 0 then
366 mailType = "normalGoldMail";
367 elseif items and items > 0 then
368 mailType = "normalItemsMail";
369 end
370 else
371 -- This is an auction house mail
372
373 mailType = "AH" .. auctionMailType;
374 end
375
376 if not self.db.profile.filter.normalMoney and mailType == "normalGoldMail" then
377 if MailOpener.db.profile.notifications.skipped.all and MailOpener.db.profile.notifications.skipped[mailType] then
378 print("Skipping " .. index .. ": " .. subject .. " (normal mail with gold)");
379 end
380
381 self:OpenNext();
382
383 return;
384 elseif not self.db.profile.filter.normalAttachments and mailType == "normalItemsMail" then
385 if MailOpener.db.profile.notifications.skipped.all and MailOpener.db.profile.notifications.skipped[mailType] then
386 print("Skipping " .. index .. ": " .. subject .. " (normal mail with attachments)");
387 end
388
389 self:OpenNext();
390
391 return;
392 elseif not self.db.profile.filter.AH.expired and mailType == "AHexpired" then
393 if MailOpener.db.profile.notifications.skipped.all and MailOpener.db.profile.notifications.skipped[mailType] then
394 print("Skipping " .. index .. ": " .. subject .. " (expired auction)");
395 end
396
397 self:OpenNext();
398
399 return;
400 elseif not self.db.profile.filter.AH.success and mailType == "AHsuccess" then
401 if MailOpener.db.profile.notifications.skipped.all and MailOpener.db.profile.notifications.skipped[mailType] then
402 print("Skipping " .. index .. ": " .. subject .. " (successful auction)");
403 end
404
405 self:OpenNext();
406
407 return;
408 elseif not self.db.profile.filter.AH.won and mailType == "AHwon" then
409 if MailOpener.db.profile.notifications.skipped.all and MailOpener.db.profile.notifications.skipped[mailType] then
410 print("Skipping " .. index .. ": " .. subject .. " (auction won)");
411 end
412
413 self:OpenNext();
414
415 return;
416 elseif not self.db.profile.filter.AH.canceled and mailType == "AHcanceled" then
417 if MailOpener.db.profile.notifications.skipped.all and MailOpener.db.profile.notifications.skipped[mailType] then
418 print("Skipping " .. index .. ": " .. subject .. " (canceled auction)");
419 end
420
421 self:OpenNext();
422
423 return;
424 elseif not self.db.profile.filter.AH.outbid and mailType == "AHoutbid" then
425 if MailOpener.db.profile.notifications.skipped.all and MailOpener.db.profile.notifications.skipped[mailType] then
426 print("Skipping " .. index .. ": " .. subject .. " (outbid on auction)");
427 end
428
429 self:OpenNext();
430
431 return;
432 else
433 continue = false;
434
435 -- Open current mail
436 AutoLootMailItem(index);
437
438 if MailOpener.db.profile.notifications.processed.all and MailOpener.db.profile.notifications.processed[mailType] then
439 if gold and gold > 0 then
440 print("Processing " .. index .. ": " .. subject .. " (" .. MailOpener:FormatMoney(gold) .. ")");
441 else
442 print("Processing " .. index .. ": " .. subject);
443 end
444 end
445
446 -- And prepare for the next
447 self.tmrMailOpener = self:ScheduleTimer("OpenNext", self.db.profile.speed);
448 end
449 end
450 else
451 -- Unknown, probably just text
452 if MailOpener.db.profile.notifications.skipped.all and MailOpener.db.profile.notifications.skipped.other then
453 if subject then
454 print("Skipping " .. index .. ": " .. subject);
455 else
456 print("Skipping " .. index);
457 end
458 end
459
460 self:OpenNext();
461 end
462 else
463 -- Finished!
464 if MailOpener.db.profile.notifications.finishedCurrentBatch then
465 print("Finished opening the current batch.");
466 end
467
468 self:SetOpeningStatus(false);
469
470 self:Debug("MO_OPEN_COMPLETE");
471
472 -- Report that we're all done
473 self:SendMessage("MO_OPEN_COMPLETE");
474 end
475 end
476
477 function OpenAll:OpenNext()
478 if continue then
479 -- If the previous mail was opened successful, open the next
480
481 -- Next mail in line
482 MAIL_ITEM_INDEX = ( MAIL_ITEM_INDEX - 1 );
483
484 -- Open it
485 self:OpenMail(MAIL_ITEM_INDEX);
486 else
487 -- Try again at the next interval
488
489 self.tmrMailOpener = self:ScheduleTimer("OpenNext", self.db.profile.speed);
490 end
491 end
492
493 local mailRemainingPatterns = {
494 minutesSeconds = "|cffffffff%d|r/|cffffffff%d|r mail remaining, opening everything will take about |cffffffff%d|r minutes and |cffffffff%d|r seconds (next refresh in |cffffffff%d|r seconds)";
495 minutes = "|cffffffff%d|r/|cffffffff%d|r mail remaining, opening everything will take about |cffffffff%d|r minutes (next refresh in |cffffffff%d|r seconds)";
496 seconds = "|cffffffff%d|r/|cffffffff%d|r mail remaining, opening everything will take about |cffffffff%d|r seconds (next refresh in |cffffffff%d|r seconds)";
497 waitingBatch = "|cffffffff%d|r/|cffffffff%d|r mail remaining - waiting for something from the current batch to be opened...";
498 waitingSync = "|cffffffff%d|r/|cffffffff%d|r mail remaining - waiting for the next mailbox refresh...";
499 soon = "|cffffffff%d|r/|cffffffff%d|r mail remaining - everything will be opened soon...";
500 };
501
502 function OpenAll:UpdateTimer()
503 if lastSync then
504 -- Calculate the total amount of mail waiting
505 local numTotalMail = ( numHiddenMail + numCurrentMail );
506
507 -- Resize the font based on mail left so the counter always fits perfectly
508 if numTotalMail < 100 then
509 self.timeLeftFrame.text:SetFont(GameFontHighlight:GetFont(), 30, "THICKOUTLINE");
510 elseif numTotalMail < 1000 then
511 self.timeLeftFrame.text:SetFont(GameFontHighlight:GetFont(), 24, "THICKOUTLINE");
512 else
513 self.timeLeftFrame.text:SetFont(GameFontHighlight:GetFont(), 18, "THICKOUTLINE");
514 end
515 self.timeLeftFrame.text:SetText(numTotalMail);
516
517 if numHiddenMail > 0 then
518 -- Calculate the next server sync based on the last server sync plus sync interval
519 local nextSync = ( lastSync + 61 );
520
521 -- Calculate the timer remaining untill the next sync
522 local timeRemaining = floor( nextSync - GetTime() );
523 -- If the next sync was already due, our nextSync calculation was wrong and we must wait a little longer (lag?)
524 local syncTimeOut = false;
525 -- If time remaining is below 0, next sync should be soon
526 if timeRemaining < 0 then
527 timeRemaining = 0;
528 syncTimeOut = true;
529 end
530
531 -- Calculate the amount of server syncs required to open all mail
532 local syncsRequired = ceil( numHiddenMail / 50 );
533 -- Calculate the time required to execute all these syncs
534 local timeRequired = ( ( syncsRequired - 1 ) * 61 ) + timeRemaining;
535
536 local minutes = floor( timeRequired / 60 );
537 local seconds = floor( timeRequired % 60 );
538
539 local remainingText;
540 if syncTimeOut then
541 if numCurrentMail == 50 then
542 remainingText = format(mailRemainingPatterns.waitingBatch, numCurrentMail, numTotalMail);
543 else
544 remainingText = format(mailRemainingPatterns.waitingSync, numCurrentMail, numTotalMail);
545 end
546 elseif minutes ~= 0 then
547 if seconds ~= 0 then
548 remainingText = format(mailRemainingPatterns.minutesSeconds, numCurrentMail, numTotalMail, minutes, seconds, timeRemaining);
549 else
550 remainingText = format(mailRemainingPatterns.minutes, numCurrentMail, numTotalMail, minutes, timeRemaining);
551 end
552 elseif seconds ~= 0 then
553 remainingText = format(mailRemainingPatterns.seconds, numCurrentMail, numTotalMail, seconds, timeRemaining);
554 else
555 remainingText = format(mailRemainingPatterns.soon, numCurrentMail, numTotalMail);
556 end
557
558 self.timeLeftFrame.smallText:SetText(remainingText);
559 elseif numHiddenMail == 0 then
560 self.timeLeftFrame.smallText:SetText("");
561 end
562 end
563 end
564
565 function OpenAll:StopOpening(simple)
566 if not simple then
567 -- Recheck inventory full
568 inventoryFull = false;
569 -- Replay sound
570 inventoryFullSoundPlayed = nil;
571 end
572
573 -- Stop opener timer
574 self:CancelTimer(self.tmrMailOpener, true);
575
576 -- Reset opener position
577 MAIL_ITEM_INDEX = 0;
578 -- Stopped opening, so allow to continue
579 continue = true;
580 self:SetOpeningStatus(false);
581 end
582
583 function OpenAll:SetOpeningStatus(openingStatus)
584 opening = openingStatus;
585
586 if openingStatus then
587 self.btnOpenAll:SetText("Opening...");
588 else
589 self.btnOpenAll:SetText("Open all");
590 end
591 end
592
593 function OpenAll:GetOptionsGroup()
594 local configGroup = {
595 order = 300,
596 type = "group",
597 name = "Open All",
598 desc = "Change open all settings.",
599 args = {
600 filters = {
601 order = 10,
602 type = "group",
603 inline = true,
604 name = "Filters",
605 args = {
606 description = {
607 order = 10,
608 type = "description",
609 name = "Toggle which mail the opener should autoloot.",
610 },
611 AHHeader = {
612 order = 15,
613 type = "header",
614 name = "Auction House Mail",
615 },
616 canceled = {
617 order = 20,
618 type = "toggle",
619 name = "Open all |cfffed000auction canceled|r mail",
620 desc = "Automatically loot all auction canceled mails from the auction house.",
621 set = function(i, v) self.db.profile.filter.AH.canceled = v; end,
622 get = function() return self.db.profile.filter.AH.canceled; end,
623 width = "double",
624 },
625 expired = {
626 order = 21,
627 type = "toggle",
628 name = "Open all |cfffed000auction expired|r mail",
629 desc = "Automatically loot all auction canceled mails from the auction house.",
630 set = function(i, v) self.db.profile.filter.AH.expired = v; end,
631 get = function() return self.db.profile.filter.AH.expired; end,
632 width = "double",
633 },
634 outbid = {
635 order = 22,
636 type = "toggle",
637 name = "Open all |cfffed000outbid on|r mail",
638 desc = "Automatically loot all auction outbid mails from the auction house.",
639 set = function(i, v) self.db.profile.filter.AH.outbid = v; end,
640 get = function() return self.db.profile.filter.AH.outbid; end,
641 width = "double",
642 },
643 success = {
644 order = 23,
645 type = "toggle",
646 name = "Open all |cfffed000auction successful|r mail",
647 desc = "Automatically loot all auction successful mails from the auction house.",
648 set = function(i, v) self.db.profile.filter.AH.success = v; end,
649 get = function() return self.db.profile.filter.AH.success; end,
650 width = "double",
651 },
652 won = {
653 order = 24,
654 type = "toggle",
655 name = "Open all |cfffed000auction won|r mail",
656 desc = "Automatically loot all auction won mails from the auction house.",
657 set = function(i, v) self.db.profile.filter.AH.won = v; end,
658 get = function() return self.db.profile.filter.AH.won; end,
659 width = "double",
660 },
661 normalHeader = {
662 order = 30,
663 type = "header",
664 name = "Remaining Mail",
665 },
666 normalAttachments = {
667 order = 40,
668 type = "toggle",
669 name = "Other mail with |cfffed000attachments|r",
670 desc = "Automatically loot all mails with attachments not sent by any of the above sources.",
671 set = function(i, v) self.db.profile.filter.normalAttachments = v; end,
672 get = function() return self.db.profile.filter.normalAttachments; end,
673 width = "double",
674 },
675 normalMoney = {
676 order = 50,
677 type = "toggle",
678 name = "Other mail with |cfffed000gold|r",
679 desc = "Automatically loot all mails with gold not sent by any of the above sources.",
680 set = function(i, v) self.db.profile.filter.normalMoney = v; end,
681 get = function() return self.db.profile.filter.normalMoney; end,
682 width = "double",
683 },
684 },
685 },
686 -- Continuous opening config inline group
687 continuousOpening = {
688 order = 20,
689 type = "group",
690 inline = true,
691 name = "Opening Interval",
692 args = {
693 description = {
694 order = 10,
695 type = "description",
696 name = function()
697 local defaultString = "The default behaviour for opening mail is to only do so right after new mail was received from the server. If you close the mailbox or your inventory is full before everything is opened you will have to click the open all button manually or wait for a next mailbox refresh.\n\n";
698
699 local currentSettings = "";
700 if MailOpener.db.profile.general.continueOpening then
701 currentSettings = currentSettings .. "Mail Opener will |cff00ff00continue|r to attempt to open the remaining mail every |cfffed000" .. MailOpener.db.profile.general.waitTime .. " seconds|r. ";
702 else
703 currentSettings = currentSettings .. "Mail Opener will |cffff0000not|r continue to attempt to open the remaining mail and will only start opening when new mail has just been received from the server. ";
704 end
705 currentSettings = currentSettings .. "The first batch after each server refresh will be opened after waiting |cfffed000" .. MailOpener.db.profile.general.initialDelay .. " seconds|r.";
706 return defaultString .. currentSettings;
707 end,
708 },
709 header = {
710 order = 15,
711 type = "header",
712 name = "",
713 },
714 continueOpening = {
715 order = 20,
716 type = "toggle",
717 name = "Continue opening mail",
718 desc = "Continue opening mail at the interval set below, even if the mailbox wasn't refreshed recently.",
719 width = "full",
720 get = function() return MailOpener.db.profile.general.continueOpening; end,
721 set = function(i, v) MailOpener.db.profile.general.continueOpening = v; end,
722 },
723 waitTime = {
724 order = 30,
725 type = "range",
726 width = "double",
727 min = 0.5,
728 max = 60,
729 step = 0.5,
730 name = "Continued Mail Opening Interval",
731 desc = "Change the interval at which Mail Opener tries to continue opening mail after opening the mailbox. Please note that this setting does not reduce the game's normal 60 seconds wait time for mail.\n\nThe default value is 5 seconds",
732 get = function() return MailOpener.db.profile.general.waitTime; end,
733 set = function(i, v) MailOpener.db.profile.general.waitTime = v; end,
734 disabled = function() return (not MailOpener.db.profile.general.continueOpening); end,
735 },
736 initialDelay = {
737 order = 40,
738 type = "range",
739 width = "double",
740 min = 0.5,
741 max = 60,
742 step = 0.5,
743 name = "Initial Mail Opening Delay",
744 desc = "Change the delay before Mail Opener tries opening mail after opening the mailbox or new mail has been received from the server.\n\nThe default value is 0.5 seconds.",
745 get = function() return MailOpener.db.profile.general.initialDelay; end,
746 set = function(i, v) MailOpener.db.profile.general.initialDelay = v; end,
747 },
748 },
749 }, -- end Continuous opening config inline group
750 keepFree = {
751 order = 30,
752 type = "group",
753 inline = true,
754 name = "Keep Free Space",
755 args = {
756 description = {
757 order = 10,
758 type = "description",
759 name = "You can set an amount of bag space you wish to reserve when opening mail. Mail with a higher amount of attachments than available space will be skipped completely with this option set above 0.",
760 },
761 header = {
762 order = 15,
763 type = "header",
764 name = "",
765 },
766 keepFreeSpace = {
767 order = 20,
768 type = "range",
769 min = 0,
770 max = 100,
771 step = 1,
772 width = "double",
773 name = "Keep free space",
774 desc = "Change the amount of space to reserve for other things when opening mail. If this option is set higher than 0, mail with a higher amount of attachments than available space will be skipped completely.\n\nE.g. If this is set to 1 and you have a total of 12 slots left then any mail with 12 attachments will be skipped while one with 11 attachments would be opened.",
775 set = function(i, v) self.db.profile.keepFreeSpace = v; end,
776 get = function() return self.db.profile.keepFreeSpace; end,
777 },
778 },
779 },
780 speed = {
781 order = 40,
782 type = "group",
783 inline = true,
784 name = "Opening Speed",
785 args = {
786 description = {
787 order = 10,
788 type = "description",
789 name = "Change the speed at which mail is opened. You should set the opening speed to the lowest latency you have in a city or experiment with setting it to the minimum.",
790 },
791 header = {
792 order = 15,
793 type = "header",
794 name = "",
795 },
796 openMailInterval = {
797 order = 20,
798 type = "range",
799 min = 5,
800 max = 2500,
801 step = 5,
802 width = "double",
803 name = "Open single mail interval",
804 desc = "Change the mail opening speed (in microseconds) for each mail. Lower may not always be faster.",
805 get = function() return ( self.db.profile.speed * 1000 ); end,
806 set = function(i, v) self.db.profile.speed = ( v / 1000 ); end,
807 },
808 },
809 },
810 },
811 };
812
813 return configGroup;
814 end
815
816 function OpenAll:Debug(t)
817 return MailOpener:Debug("|cff00ff00OpenAll|r:" .. t);
818 end