annotate Modules/OpenAll.lua @ 110:4b779ae4f41f

Added tag v1.2.4-BETA for changeset 71e2a651d667
author Zerotorescue
date Thu, 30 Sep 2010 15:23:35 +0200
parents 5c06ce56297a
children 981c6ac45a3f
rev   line source
Zerotorescue@0 1 local MailOpener = LibStub("AceAddon-3.0"):GetAddon("MailOpener");
Zerotorescue@31 2 local mod = MailOpener:NewModule("OpenAll", "AceEvent-3.0", "AceTimer-3.0");
Zerotorescue@68 3 local L = LibStub("AceLocale-3.0"):GetLocale("MailOpener");
Zerotorescue@31 4
Zerotorescue@68 5 mod.moduleDescription = L["The actual mail opening initiated by the core."];
Zerotorescue@31 6 mod.moduleRequired = true;
Zerotorescue@0 7
Zerotorescue@3 8 --[[
Zerotorescue@3 9 Dev notes:
Zerotorescue@3 10 When shift clicking the Open All button it should override all filters.
Zerotorescue@3 11 ]]
Zerotorescue@3 12
Zerotorescue@106 13 local MAIL_ITEM_INDEX, MAIL_OPEN_EVERYTHING, mailTimer, inventoryFull, inventoryFullSoundPlayed, inventoryFullSoundPlayedThisVisit, opening, lastSync, numCurrentMail, numHiddenMail, continue, firstOpenThisSync;
Zerotorescue@0 14
Zerotorescue@31 15 function mod:OnInitialize()
Zerotorescue@0 16 local defaults = {
Zerotorescue@0 17 profile = {
Zerotorescue@0 18 speed = 0.05,
Zerotorescue@0 19 keepFreeSpace = 0,
Zerotorescue@0 20 filter = {
Zerotorescue@0 21 AH = {
Zerotorescue@0 22 canceled = true,
Zerotorescue@0 23 expired = true,
Zerotorescue@0 24 outbid = true,
Zerotorescue@0 25 success = true,
Zerotorescue@0 26 won = true,
Zerotorescue@0 27 },
Zerotorescue@0 28 normalAttachments = false,
Zerotorescue@0 29 normalMoney = true,
Zerotorescue@50 30 allowShiftClick = true,
Zerotorescue@0 31 },
Zerotorescue@0 32 },
Zerotorescue@0 33 };
Zerotorescue@0 34
Zerotorescue@0 35 -- Register our saved variables NameSpace
Zerotorescue@0 36 self.db = MailOpener.db:RegisterNamespace("OpenAll", defaults);
Zerotorescue@0 37 end
Zerotorescue@0 38
Zerotorescue@31 39 function mod:OnEnable()
Zerotorescue@0 40 self:RegisterEvent("MAIL_SHOW");
Zerotorescue@42 41
Zerotorescue@0 42 if not self.btnOpenAll then
Zerotorescue@0 43 -- Open all button
Zerotorescue@46 44 local button = CreateFrame("Button", "btnMailOpenerOpenAll", InboxFrame, "UIPanelButtonTemplate");
Zerotorescue@68 45 button:SetText(L["Open all"]);
Zerotorescue@46 46 button:SetHeight(26);
Zerotorescue@46 47 button:SetWidth(120);
Zerotorescue@46 48 button:SetPoint("BOTTOM", InboxFrame, "CENTER", -10, -165);
Zerotorescue@48 49 button:RegisterForClicks("LeftButtonUp", "RightButtonUp");
Zerotorescue@48 50 button:SetScript("OnClick", function(self, mouseButton)
Zerotorescue@48 51 if mouseButton == "RightButton" then
Zerotorescue@48 52 -- Hide the gametooltip
Zerotorescue@48 53 GameTooltip:Hide();
Zerotorescue@48 54
Zerotorescue@48 55 if not mod.ddmFilters then
Zerotorescue@48 56 -- Build the drop down menu
Zerotorescue@48 57 local info = {};
Zerotorescue@48 58
Zerotorescue@48 59 local dropDownMenu = CreateFrame("Frame", "MailOpenerFiltersDropDownMenu");
Zerotorescue@48 60 dropDownMenu.displayMode = "MENU";
Zerotorescue@48 61 dropDownMenu.initialize = function(s, level)
Zerotorescue@48 62 if not level then return; end
Zerotorescue@48 63
Zerotorescue@48 64 if level == 1 then
Zerotorescue@48 65 -- Create the title of the menu
Zerotorescue@48 66 info.isTitle = true;
Zerotorescue@68 67 info.text = L["Toggle filters for %s profile."]:format(MailOpener.db:GetCurrentProfile());
Zerotorescue@48 68 info.notCheckable = true;
Zerotorescue@48 69 UIDropDownMenu_AddButton(info, level);
Zerotorescue@48 70
Zerotorescue@48 71 -- Reset title specific values
Zerotorescue@48 72 info.isTitle = nil;
Zerotorescue@48 73 info.disabled = nil;
Zerotorescue@48 74 info.notCheckable = nil;
Zerotorescue@48 75
Zerotorescue@48 76 -- We don't want to close the DDM when something is toggled
Zerotorescue@48 77 info.keepShownOnClick = true;
Zerotorescue@48 78
Zerotorescue@48 79 -- Make Auction canceled option
Zerotorescue@68 80 info.text = L["Auction canceled"];
Zerotorescue@48 81 info.func = function(this) mod.db.profile.filter.AH.canceled = this.checked; end;
Zerotorescue@48 82 info.checked = mod.db.profile.filter.AH.canceled;
Zerotorescue@48 83 UIDropDownMenu_AddButton(info, level);
Zerotorescue@48 84
Zerotorescue@48 85 -- Make Auction expired option
Zerotorescue@68 86 info.text = L["Auction expired"];
Zerotorescue@48 87 info.func = function(this) mod.db.profile.filter.AH.expired = this.checked; end;
Zerotorescue@48 88 info.checked = mod.db.profile.filter.AH.expired;
Zerotorescue@48 89 UIDropDownMenu_AddButton(info, level);
Zerotorescue@48 90
Zerotorescue@48 91 -- Make Auction outbid option
Zerotorescue@68 92 info.text = L["Auction outbid"];
Zerotorescue@48 93 info.func = function(this) mod.db.profile.filter.AH.outbid = this.checked; end;
Zerotorescue@48 94 info.checked = mod.db.profile.filter.AH.outbid;
Zerotorescue@48 95 UIDropDownMenu_AddButton(info, level);
Zerotorescue@48 96
Zerotorescue@48 97 -- Make Auction successful option
Zerotorescue@68 98 info.text = L["Auction successful"];
Zerotorescue@48 99 info.func = function(this) mod.db.profile.filter.AH.success = this.checked; end;
Zerotorescue@48 100 info.checked = mod.db.profile.filter.AH.success;
Zerotorescue@48 101 UIDropDownMenu_AddButton(info, level);
Zerotorescue@48 102
Zerotorescue@48 103 -- Make Auction won option
Zerotorescue@68 104 info.text = L["Auction won"];
Zerotorescue@48 105 info.func = function(this) mod.db.profile.filter.AH.won = this.checked; end;
Zerotorescue@48 106 info.checked = mod.db.profile.filter.AH.won;
Zerotorescue@48 107 UIDropDownMenu_AddButton(info, level);
Zerotorescue@48 108
Zerotorescue@48 109 -- Make Other mail with attachments
Zerotorescue@68 110 info.text = L["Other mail with attachments"];
Zerotorescue@48 111 info.func = function(this) mod.db.profile.filter.normalAttachments = this.checked; end;
Zerotorescue@48 112 info.checked = mod.db.profile.filter.normalAttachments;
Zerotorescue@48 113 UIDropDownMenu_AddButton(info, level);
Zerotorescue@48 114
Zerotorescue@48 115 -- Make Other mail with gold
Zerotorescue@68 116 info.text = L["Other mail with gold"];
Zerotorescue@48 117 info.func = function(this) mod.db.profile.filter.normalMoney = this.checked; end;
Zerotorescue@48 118 info.checked = mod.db.profile.filter.normalMoney;
Zerotorescue@48 119 UIDropDownMenu_AddButton(info, level);
Zerotorescue@48 120
Zerotorescue@48 121 -- Make Other mail with gold
Zerotorescue@48 122 info.text = CLOSE;
Zerotorescue@48 123 info.func = function() CloseDropDownMenus(); end;
Zerotorescue@48 124 info.checked = nil;
Zerotorescue@48 125 info.notCheckable = true;
Zerotorescue@48 126 UIDropDownMenu_AddButton(info, level);
Zerotorescue@48 127
Zerotorescue@48 128 wipe(info);
Zerotorescue@48 129 end
Zerotorescue@48 130 end
Zerotorescue@48 131
Zerotorescue@48 132 mod.ddmFilters = dropDownMenu;
Zerotorescue@48 133 end
Zerotorescue@48 134
Zerotorescue@48 135 ToggleDropDownMenu(1, nil, mod.ddmFilters, self:GetName(), 0, 0);
Zerotorescue@48 136 else
Zerotorescue@48 137 mod:Open(true, IsShiftKeyDown());
Zerotorescue@48 138 end
Zerotorescue@48 139 end);
Zerotorescue@68 140 button.tooltipTitle = L["Open all"];
Zerotorescue@68 141 button.tooltip = L["Hold |cfffed000shift|r while clicking this button to temporarily override your filters and loot every single mail containing attachments and/or gold.\n\n|cfffed000Right|r click this button to quickly adjust mail opening filters for this profile."];
Zerotorescue@48 142 button:SetScript("OnEnter", function(self)
Zerotorescue@51 143 if MailOpener.db.profile.general.showHelpTooltips then
Zerotorescue@51 144 GameTooltip:SetOwner(self, "ANCHOR_NONE")
Zerotorescue@51 145 GameTooltip:SetPoint("BOTTOM", self, "TOP")
Zerotorescue@51 146 GameTooltip:SetText(self.tooltipTitle, 1, .82, 0, 1)
Zerotorescue@51 147
Zerotorescue@51 148 if type(self.tooltip) == "string" then
Zerotorescue@51 149 GameTooltip:AddLine(self.tooltip, 1, 1, 1, 1);
Zerotorescue@51 150 end
Zerotorescue@51 151
Zerotorescue@51 152 GameTooltip:Show();
Zerotorescue@48 153 end
Zerotorescue@48 154 end);
Zerotorescue@48 155 button:SetScript("OnLeave", function(self)
Zerotorescue@48 156 GameTooltip:Hide();
Zerotorescue@46 157 end);
Zerotorescue@0 158
Zerotorescue@0 159 self.btnOpenAll = button;
Zerotorescue@0 160 end
Zerotorescue@0 161
Zerotorescue@0 162 self.btnOpenAll:Show();
Zerotorescue@0 163
Zerotorescue@0 164 if not self.timeLeftFrame then
Zerotorescue@0 165 -- If the timeLeftFrame doesn't exist we will have to build it
Zerotorescue@0 166
Zerotorescue@0 167 self:Debug("Building text frame");
Zerotorescue@0 168
Zerotorescue@0 169 local frame = CreateFrame("Button", "MailOpenerTimeLeftButton", InboxFrame);
Zerotorescue@0 170
Zerotorescue@0 171 -- Mail counter
Zerotorescue@0 172 frame.text = frame:CreateFontString("MailOpenerTimeLeftFrameMailCount", "OVERLAY", "GameFontHighlight");
Zerotorescue@0 173 frame.text:SetPoint("CENTER", MailFrame, "TOPLEFT", 40, -35);
Zerotorescue@0 174
Zerotorescue@0 175 -- Long time left indicator
Zerotorescue@0 176 frame.smallText = frame:CreateFontString("MailOpenerTimeLeftFrameTimeRemaining", "OVERLAY", "GameFontNormal");
Zerotorescue@0 177 frame.smallText:SetFont(GameFontHighlight:GetFont(), 11, "OUTLINE");
Zerotorescue@0 178 frame.smallText:SetPoint("TOPLEFT", MailFrame, "TOPLEFT", 75, -38);
Zerotorescue@0 179 frame.smallText:SetWidth(270);
Zerotorescue@0 180 frame.smallText:SetJustifyH("LEFT");
Zerotorescue@0 181 frame.smallText:SetJustifyV("MIDDLE");
Zerotorescue@0 182
Zerotorescue@0 183 frame:SetPoint("TOPLEFT", MailFrame, "TOPLEFT", 75, -38);
Zerotorescue@0 184 frame:SetWidth(270);
Zerotorescue@0 185 frame:SetHeight(35);
Zerotorescue@0 186 frame:SetScript("OnClick", function(self)
Zerotorescue@0 187 local timeRemainingUntillOpened = frame.smallText:GetText();
Zerotorescue@0 188 if timeRemainingUntillOpened then
Zerotorescue@0 189 MailOpener.currentPopupContents = "|cffffd700" .. timeRemainingUntillOpened .. "|r";
Zerotorescue@0 190
Zerotorescue@0 191 StaticPopup_Show("MailOpenerCopyWindow");
Zerotorescue@0 192 end
Zerotorescue@0 193 end);
Zerotorescue@0 194
Zerotorescue@0 195 self.timeLeftFrame = frame;
Zerotorescue@0 196 end
Zerotorescue@0 197
Zerotorescue@0 198 self.timeLeftFrame:Show();
Zerotorescue@0 199
Zerotorescue@3 200 -- Go through all children of the mail frame to find QA's element and hide it
Zerotorescue@42 201 -- There's no other way to do this because QuickAuctions has a local referrence to it (not as a property of the object like most other frames)
Zerotorescue@0 202 local kids = { MailFrame:GetChildren() };
Zerotorescue@0 203
Zerotorescue@0 204 for _, child in ipairs(kids) do
Zerotorescue@0 205 if child and child.text then
Zerotorescue@0 206 child.text:Hide();
Zerotorescue@0 207 end
Zerotorescue@0 208 end
Zerotorescue@0 209
Zerotorescue@0 210 -- If we were toggling this module on while the mailbox is opened we must register all events again
Zerotorescue@0 211 if MailFrame:IsVisible() then
Zerotorescue@0 212 self:MAIL_SHOW();
Zerotorescue@0 213 end
Zerotorescue@0 214 end
Zerotorescue@0 215
Zerotorescue@31 216 function mod:OnDisable()
Zerotorescue@0 217 self:UnregisterEvent("MAIL_SHOW");
Zerotorescue@0 218
Zerotorescue@0 219 if self.btnOpenAll then
Zerotorescue@0 220 self.btnOpenAll:Hide();
Zerotorescue@0 221 end
Zerotorescue@0 222
Zerotorescue@0 223 if self.timeLeftFrame then
Zerotorescue@0 224 self.timeLeftFrame:Hide();
Zerotorescue@0 225 end
Zerotorescue@0 226
Zerotorescue@0 227 if MailOpener.PostalEnabled then
Zerotorescue@0 228 -- Enable Postal's openers again
Zerotorescue@0 229
Zerotorescue@0 230 MailOpener:TogglePostalModule("OpenAll", true);
Zerotorescue@0 231 MailOpener:TogglePostalModule("Select", true);
Zerotorescue@0 232 end
Zerotorescue@0 233
Zerotorescue@0 234 -- Go through all children of the mail frame to find QA's elements and SHOW these
Zerotorescue@42 235 -- There's no other way to do this because QuickAuctions has a local referrence to it (not as a property of the object like most other frames)
Zerotorescue@0 236 local kids = { MailFrame:GetChildren() };
Zerotorescue@0 237
Zerotorescue@0 238 for _, child in ipairs(kids) do
Zerotorescue@0 239 if child and child.text then
Zerotorescue@0 240 child.text:Show();
Zerotorescue@0 241 end
Zerotorescue@0 242 end
Zerotorescue@0 243
Zerotorescue@0 244 self:Stop();
Zerotorescue@0 245 end
Zerotorescue@0 246
Zerotorescue@31 247 function mod:MAIL_SHOW()
Zerotorescue@0 248 self:Debug("MAIL_SHOW");
Zerotorescue@0 249
Zerotorescue@0 250 self:StopOpening(false);
Zerotorescue@42 251
Zerotorescue@42 252 inventoryFullSoundPlayedThisVisit = nil;
Zerotorescue@0 253
Zerotorescue@0 254 if MailOpener.PostalEnabled then
Zerotorescue@0 255 -- Disable Postal's openers so we can do it ourselves
Zerotorescue@0 256
Zerotorescue@0 257 MailOpener:TogglePostalModule("OpenAll", false);
Zerotorescue@0 258 MailOpener:TogglePostalModule("Select", false);
Zerotorescue@0 259 end
Zerotorescue@0 260
Zerotorescue@0 261 -- Keep an eye for closing of the mailbox
Zerotorescue@0 262 self:RegisterEvent("MAIL_CLOSED", "Stop");
Zerotorescue@0 263 self:RegisterEvent("PLAYER_LEAVING_WORLD", "Stop");
Zerotorescue@0 264
Zerotorescue@0 265 -- Look if the mailbox is full
Zerotorescue@0 266 self:RegisterEvent("UI_ERROR_MESSAGE");
Zerotorescue@0 267 -- Only look again after bags updated
Zerotorescue@0 268 self:RegisterEvent("BAG_UPDATE");
Zerotorescue@0 269
Zerotorescue@0 270 -- We need to know when to start opening
Zerotorescue@0 271 self:RegisterMessage("MO_OPEN_MAIL", "Open");
Zerotorescue@0 272 self:RegisterMessage("MO_SERVER_SYNCED");
Zerotorescue@3 273 self:RegisterMessage("MO_MAIL_EMPTIED");
Zerotorescue@0 274
Zerotorescue@0 275 self:CancelTimer(self.tmrTimeRemaining, true);
Zerotorescue@0 276 self.tmrTimeRemaining = self:ScheduleRepeatingTimer("UpdateTimer", 1);
Zerotorescue@0 277 self:UpdateTimer();
Zerotorescue@0 278 end
Zerotorescue@0 279
Zerotorescue@31 280 function mod:Stop()
Zerotorescue@0 281 self:Debug("Stop");
Zerotorescue@0 282
Zerotorescue@0 283 -- We shutdown, so nothing to do when the mailbox is closed anymore
Zerotorescue@0 284 self:UnregisterEvent("MAIL_CLOSED");
Zerotorescue@0 285 self:UnregisterEvent("PLAYER_LEAVING_WORLD");
Zerotorescue@0 286
Zerotorescue@0 287 -- We care about a full inventory just a little
Zerotorescue@0 288 self:UnregisterEvent("UI_ERROR_MESSAGE");
Zerotorescue@0 289 self:UnregisterEvent("BAG_UPDATE");
Zerotorescue@0 290
Zerotorescue@0 291 -- We no longer care
Zerotorescue@0 292 self:UnregisterMessage("MO_OPEN_MAIL");
Zerotorescue@0 293 self:UnregisterMessage("MO_SERVER_SYNCED");
Zerotorescue@3 294 self:UnregisterMessage("MO_MAIL_EMPTIED");
Zerotorescue@0 295
Zerotorescue@0 296 self:CancelTimer(self.tmrMailOpener, true);
Zerotorescue@0 297 self:CancelTimer(self.tmrTimeRemaining, true);
Zerotorescue@0 298
Zerotorescue@0 299 self:SetOpeningStatus(false);
Zerotorescue@0 300 end
Zerotorescue@0 301
Zerotorescue@31 302 function mod:MO_SERVER_SYNCED()
Zerotorescue@0 303 self:Debug("MO_SERVER_SYNCED");
Zerotorescue@0 304
Zerotorescue@31 305 -- Stop opening now to prevent the opener from continueing while BeanCounter is counting
Zerotorescue@2 306 self:StopOpening(false);
Zerotorescue@2 307
Zerotorescue@0 308 lastSync = GetTime();
Zerotorescue@0 309
Zerotorescue@2 310 self:UpdateMailCount();
Zerotorescue@106 311
Zerotorescue@106 312 -- While this is true, we'll announce mail skipped - will be set to false after opening happened once
Zerotorescue@106 313 firstOpenThisSync = true;
Zerotorescue@2 314 end
Zerotorescue@2 315
Zerotorescue@31 316 function mod:MO_MAIL_EMPTIED()
Zerotorescue@3 317 -- A mail has been processed so we can process the next
Zerotorescue@2 318 continue = true;
Zerotorescue@2 319
Zerotorescue@3 320 self:UpdateTimer();
Zerotorescue@2 321 end
Zerotorescue@2 322
Zerotorescue@31 323 function mod:UpdateMailCount()
Zerotorescue@0 324 local numItems, totalItems = GetInboxNumItems();
Zerotorescue@0 325
Zerotorescue@0 326 numCurrentMail = numItems;
Zerotorescue@0 327 numHiddenMail = ( totalItems - numItems );
Zerotorescue@0 328 end
Zerotorescue@0 329
Zerotorescue@31 330 function mod:BAG_UPDATE()
Zerotorescue@0 331 -- If the bags are updated we should check if the inventory is full again
Zerotorescue@0 332 inventoryFull = false;
Zerotorescue@1 333 -- Replay sound
Zerotorescue@1 334 inventoryFullSoundPlayed = nil;
Zerotorescue@0 335 end
Zerotorescue@0 336
Zerotorescue@0 337 -- 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
Zerotorescue@31 338 function mod:UI_ERROR_MESSAGE(e, errorMessage)
Zerotorescue@0 339 if errorMessage == ERR_INV_FULL then
Zerotorescue@0 340 -- Inventory is full.
Zerotorescue@0 341
Zerotorescue@0 342 if not inventoryFull then
Zerotorescue@0 343 inventoryFull = true;
Zerotorescue@0 344
Zerotorescue@0 345 -- Play the sound
Zerotorescue@42 346 if MailOpener.db.profile.notifications.bagsFullSound and (not MailOpener.db.profile.notifications.bagsFullSoundOnlyOnce or not inventoryFullSoundPlayed) and (not MailOpener.db.profile.notifications.bagsFullSoundOnlyOncePerMailboxVisit or not inventoryFullSoundPlayedThisVisit) then
Zerotorescue@0 347 PlaySoundFile(MailOpener.db.profile.notifications.bagsFullSoundFile);
Zerotorescue@0 348 inventoryFullSoundPlayed = true;
Zerotorescue@42 349 inventoryFullSoundPlayedThisVisit = true;
Zerotorescue@0 350 end
Zerotorescue@0 351 end
Zerotorescue@0 352
Zerotorescue@0 353 -- Continue opening mail (we still want to open gold mail)
Zerotorescue@0 354 continue = true;
Zerotorescue@0 355 elseif errorMessage == ERR_ITEM_MAX_COUNT or errorMessage == ERR_MAIL_DATABASE_ERROR then
Zerotorescue@0 356 -- Can't carry more of this item OR mail database error
Zerotorescue@0 357
Zerotorescue@0 358 -- Continue opening mail (we still want to retrieve other items or gold)
Zerotorescue@0 359 continue = true;
Zerotorescue@0 360 end
Zerotorescue@0 361 end
Zerotorescue@0 362
Zerotorescue@46 363 function mod:Open(forced, everything)
Zerotorescue@46 364 self:Debug("Open (" .. ((everything and "1") or "0") .. ")");
Zerotorescue@0 365
Zerotorescue@0 366 if not opening or forced == true then
Zerotorescue@0 367 local numItems, totalItems = GetInboxNumItems();
Zerotorescue@0 368 -- Start at the end, add one because OpenNext will take it away again
Zerotorescue@0 369 local newMailItemIndex = ( ( numItems or 0 ) + 1 );
Zerotorescue@0 370
Zerotorescue@0 371 if newMailItemIndex > 1 then
Zerotorescue@0 372 self:Debug("Open succes");
Zerotorescue@0 373
Zerotorescue@0 374 -- Stop the previous opening and restart
Zerotorescue@0 375 if forced == true then
Zerotorescue@106 376 -- Show skips again
Zerotorescue@106 377 firstOpenThisSync = true;
Zerotorescue@106 378
Zerotorescue@0 379 self:StopOpening(false); -- this is not a "simple" stop, so also reset inventory full warning
Zerotorescue@0 380 else
Zerotorescue@0 381 self:StopOpening(true); -- forced is false - automated action - simple reset, skip inventory full reset to avoid sound spam
Zerotorescue@0 382 end
Zerotorescue@0 383
Zerotorescue@0 384 -- Update the caret
Zerotorescue@0 385 MAIL_ITEM_INDEX = newMailItemIndex;
Zerotorescue@46 386 -- Do we want to override filters and open every single mail?
Zerotorescue@50 387 if everything and self.db.profile.filter.allowShiftClick then
Zerotorescue@46 388 MAIL_OPEN_EVERYTHING = true;
Zerotorescue@46 389
Zerotorescue@68 390 MailOpener:Print(L["Shift key was held while pressing the open all button. Temporarily overriding filters; going to open every mail with attachments."]);
Zerotorescue@46 391 else
Zerotorescue@46 392 MAIL_OPEN_EVERYTHING = nil;
Zerotorescue@46 393 end
Zerotorescue@0 394
Zerotorescue@0 395 -- We're now going to be busy again
Zerotorescue@0 396 self:SetOpeningStatus(true);
Zerotorescue@0 397
Zerotorescue@0 398 -- Open the next mail in line
Zerotorescue@0 399 self:OpenNext();
Zerotorescue@0 400 else
Zerotorescue@0 401 if MailOpener.db.profile.notifications.mailboxIsEmpty then
Zerotorescue@68 402 print(L["|cffff0000There is currently no mail available.|r"]);
Zerotorescue@0 403 end
Zerotorescue@0 404
Zerotorescue@0 405 self:Debug("MO_OPEN_COMPLETE");
Zerotorescue@0 406
Zerotorescue@0 407 -- Report that we're all done
Zerotorescue@0 408 self:SendMessage("MO_OPEN_COMPLETE");
Zerotorescue@0 409 end
Zerotorescue@0 410 end
Zerotorescue@0 411 end
Zerotorescue@0 412
Zerotorescue@0 413 -- Return the type of mail a message subject is
Zerotorescue@0 414 local knownAHSubjectPatterns = {
Zerotorescue@0 415 canceled = AUCTION_REMOVED_MAIL_SUBJECT:replace("%s", ""),
Zerotorescue@0 416 expired = AUCTION_EXPIRED_MAIL_SUBJECT:replace("%s", ""),
Zerotorescue@0 417 outbid = AUCTION_OUTBID_MAIL_SUBJECT:replace("%s", ""),
Zerotorescue@0 418 success = AUCTION_SOLD_MAIL_SUBJECT:replace("%s", ""),
Zerotorescue@0 419 won = AUCTION_WON_MAIL_SUBJECT:replace("%s", ""),
Zerotorescue@0 420 };
Zerotorescue@31 421 function mod:GetAuctionMailType(subject)
Zerotorescue@0 422 if subject then
Zerotorescue@0 423 -- Check if any of our patterns match, sorted by most likely matches first (if one is true the rest shouldn't be evaluated)
Zerotorescue@0 424 if subject:find(knownAHSubjectPatterns.expired) then
Zerotorescue@0 425 return "expired";
Zerotorescue@0 426 elseif subject:find(knownAHSubjectPatterns.success) then
Zerotorescue@0 427 return "success";
Zerotorescue@0 428 elseif subject:find(knownAHSubjectPatterns.won) then
Zerotorescue@0 429 return "won";
Zerotorescue@0 430 elseif subject:find(knownAHSubjectPatterns.canceled) then
Zerotorescue@0 431 return "canceled";
Zerotorescue@0 432 elseif subject:find(knownAHSubjectPatterns.outbid) then
Zerotorescue@0 433 return "outbid";
Zerotorescue@0 434 end
Zerotorescue@0 435 end
Zerotorescue@0 436
Zerotorescue@0 437 return; -- not auction mail
Zerotorescue@0 438 end
Zerotorescue@0 439
Zerotorescue@31 440 function mod:OpenMail(index)
Zerotorescue@68 441 if index and index > 0 then
Zerotorescue@0 442 -- LUA arrays start at 1, so mail with index 0 doesn't exist, so we're finished
Zerotorescue@0 443
Zerotorescue@0 444 local sender, subject, gold, cod, _, items, _, _, _, _, isGM = select(3, GetInboxHeaderInfo(index));
Zerotorescue@0 445 local auctionMailType = self:GetAuctionMailType(subject);
Zerotorescue@0 446
Zerotorescue@68 447 if not subject then subject = ""; end
Zerotorescue@68 448
Zerotorescue@106 449 local onlyShowOnceCheck = firstOpenThisSync;
Zerotorescue@106 450
Zerotorescue@68 451 local skippingString = L["Skipping %d: %s (%s)"];
Zerotorescue@68 452
Zerotorescue@0 453 if isGM then
Zerotorescue@68 454 -- Blizzard Mail
Zerotorescue@106 455 if MailOpener.db.profile.notifications.skipped.all and onlyShowOnceCheck and MailOpener.db.profile.notifications.skipped.GMMail then
Zerotorescue@68 456 print(skippingString:format(index, subject, L["Blizzard mail"]));
Zerotorescue@0 457 end
Zerotorescue@0 458
Zerotorescue@0 459 self:OpenNext();
Zerotorescue@0 460
Zerotorescue@0 461 return;
Zerotorescue@0 462 elseif cod and cod > 0 then
Zerotorescue@0 463 -- Cost on delivery
Zerotorescue@106 464 if MailOpener.db.profile.notifications.skipped.all and onlyShowOnceCheck and MailOpener.db.profile.notifications.skipped.COD then
Zerotorescue@68 465 print(skippingString:format(index, subject, L["C.O.D."]));
Zerotorescue@0 466 end
Zerotorescue@0 467
Zerotorescue@0 468 self:OpenNext();
Zerotorescue@0 469
Zerotorescue@0 470 return;
Zerotorescue@0 471 elseif ((gold and gold > 0) or (items and items > 0)) then
Zerotorescue@0 472 -- Mail with some sort of attachments
Zerotorescue@0 473
Zerotorescue@79 474 local slotsAvailable;
Zerotorescue@0 475 if self.db.profile.keepFreeSpace > 0 then
Zerotorescue@79 476 slotsAvailable = 0;
Zerotorescue@79 477
Zerotorescue@79 478 -- First find out the amount of empty bag slots
Zerotorescue@91 479 for bag = 0, NUM_BAG_SLOTS do
Zerotorescue@79 480 local numberOfFreeSlots, _ = GetContainerNumFreeSlots(bag);
Zerotorescue@0 481 slotsAvailable = ( slotsAvailable + numberOfFreeSlots );
Zerotorescue@0 482 end
Zerotorescue@79 483
Zerotorescue@79 484 -- Then calculate how much is available after the space we need to leave empty
Zerotorescue@79 485 slotsAvailable = ( slotsAvailable - self.db.profile.keepFreeSpace );
Zerotorescue@0 486 end
Zerotorescue@0 487
Zerotorescue@79 488 -- and not MAIL_OPEN_EVERYTHING
Zerotorescue@79 489 -- Removed above part from below if statement, I forgot why I put it here and now it makes no sense
Zerotorescue@79 490 if inventoryFull and not MailOpener.db.profile.general.continueOpeningStackableItems and items and items > 0 then
Zerotorescue@106 491 if MailOpener.db.profile.notifications.skipped.all and onlyShowOnceCheck and MailOpener.db.profile.notifications.skipped.inventoryFull then
Zerotorescue@68 492 print(skippingString:format(index, subject, L["inventory is full"]));
Zerotorescue@0 493 end
Zerotorescue@0 494
Zerotorescue@0 495 self:OpenNext();
Zerotorescue@0 496
Zerotorescue@0 497 return;
Zerotorescue@79 498 elseif self.db.profile.keepFreeSpace > 0 and items and slotsAvailable ~= nil and slotsAvailable <= 0 then
Zerotorescue@106 499 if MailOpener.db.profile.notifications.skipped.all and onlyShowOnceCheck and MailOpener.db.profile.notifications.skipped.keepFreeSpaceLimit then
Zerotorescue@68 500 print(skippingString:format(index, subject, L["keep free space limit"]));
Zerotorescue@0 501 end
Zerotorescue@0 502
Zerotorescue@0 503 self:OpenNext();
Zerotorescue@0 504
Zerotorescue@0 505 return;
Zerotorescue@0 506 else
Zerotorescue@0 507 -- This string will hold the mailtype, MailOpener.db.profile.notifications.skipped/processed[mailType] will be checked if this should be announced
Zerotorescue@0 508 local mailType = "other";
Zerotorescue@0 509
Zerotorescue@0 510 if not auctionMailType then
Zerotorescue@0 511 -- This is a normal mail
Zerotorescue@0 512
Zerotorescue@0 513 if gold and gold > 0 then
Zerotorescue@0 514 mailType = "normalGoldMail";
Zerotorescue@0 515 elseif items and items > 0 then
Zerotorescue@0 516 mailType = "normalItemsMail";
Zerotorescue@0 517 end
Zerotorescue@0 518 else
Zerotorescue@0 519 -- This is an auction house mail
Zerotorescue@0 520
Zerotorescue@0 521 mailType = "AH" .. auctionMailType;
Zerotorescue@0 522 end
Zerotorescue@0 523
Zerotorescue@46 524 if not MAIL_OPEN_EVERYTHING and not self.db.profile.filter.normalMoney and mailType == "normalGoldMail" then
Zerotorescue@106 525 if MailOpener.db.profile.notifications.skipped.all and onlyShowOnceCheck and MailOpener.db.profile.notifications.skipped[mailType] then
Zerotorescue@68 526 print(skippingString:format(index, subject, L["normal mail with gold"]));
Zerotorescue@0 527 end
Zerotorescue@0 528
Zerotorescue@0 529 self:OpenNext();
Zerotorescue@0 530
Zerotorescue@0 531 return;
Zerotorescue@46 532 elseif not MAIL_OPEN_EVERYTHING and not self.db.profile.filter.normalAttachments and mailType == "normalItemsMail" then
Zerotorescue@106 533 if MailOpener.db.profile.notifications.skipped.all and onlyShowOnceCheck and MailOpener.db.profile.notifications.skipped[mailType] then
Zerotorescue@68 534 print(skippingString:format(index, subject, L["normal mail with attachments"]));
Zerotorescue@0 535 end
Zerotorescue@0 536
Zerotorescue@0 537 self:OpenNext();
Zerotorescue@0 538
Zerotorescue@0 539 return;
Zerotorescue@46 540 elseif not MAIL_OPEN_EVERYTHING and not self.db.profile.filter.AH.expired and mailType == "AHexpired" then
Zerotorescue@106 541 if MailOpener.db.profile.notifications.skipped.all and onlyShowOnceCheck and MailOpener.db.profile.notifications.skipped[mailType] then
Zerotorescue@68 542 print(skippingString:format(index, subject, L["expired auction"]));
Zerotorescue@0 543 end
Zerotorescue@0 544
Zerotorescue@0 545 self:OpenNext();
Zerotorescue@0 546
Zerotorescue@0 547 return;
Zerotorescue@46 548 elseif not MAIL_OPEN_EVERYTHING and not self.db.profile.filter.AH.success and mailType == "AHsuccess" then
Zerotorescue@106 549 if MailOpener.db.profile.notifications.skipped.all and onlyShowOnceCheck and MailOpener.db.profile.notifications.skipped[mailType] then
Zerotorescue@68 550 print(skippingString:format(index, subject, L["successful auction"]));
Zerotorescue@0 551 end
Zerotorescue@0 552
Zerotorescue@0 553 self:OpenNext();
Zerotorescue@0 554
Zerotorescue@0 555 return;
Zerotorescue@46 556 elseif not MAIL_OPEN_EVERYTHING and not self.db.profile.filter.AH.won and mailType == "AHwon" then
Zerotorescue@106 557 if MailOpener.db.profile.notifications.skipped.all and onlyShowOnceCheck and MailOpener.db.profile.notifications.skipped[mailType] then
Zerotorescue@68 558 print(skippingString:format(index, subject, L["auction won"]));
Zerotorescue@0 559 end
Zerotorescue@0 560
Zerotorescue@0 561 self:OpenNext();
Zerotorescue@0 562
Zerotorescue@0 563 return;
Zerotorescue@46 564 elseif not MAIL_OPEN_EVERYTHING and not self.db.profile.filter.AH.canceled and mailType == "AHcanceled" then
Zerotorescue@106 565 if MailOpener.db.profile.notifications.skipped.all and onlyShowOnceCheck and MailOpener.db.profile.notifications.skipped[mailType] then
Zerotorescue@68 566 print(skippingString:format(index, subject, L["canceled auction"]));
Zerotorescue@0 567 end
Zerotorescue@0 568
Zerotorescue@0 569 self:OpenNext();
Zerotorescue@0 570
Zerotorescue@0 571 return;
Zerotorescue@46 572 elseif not MAIL_OPEN_EVERYTHING and not self.db.profile.filter.AH.outbid and mailType == "AHoutbid" then
Zerotorescue@106 573 if MailOpener.db.profile.notifications.skipped.all and onlyShowOnceCheck and MailOpener.db.profile.notifications.skipped[mailType] then
Zerotorescue@68 574 print(skippingString:format(index, subject, L["outbid on auction"]));
Zerotorescue@0 575 end
Zerotorescue@0 576
Zerotorescue@0 577 self:OpenNext();
Zerotorescue@0 578
Zerotorescue@0 579 return;
Zerotorescue@0 580 else
Zerotorescue@0 581 continue = false;
Zerotorescue@3 582
Zerotorescue@11 583 self:Debug("MO_OPENING_MAIL (#" .. index .. ")");
Zerotorescue@0 584
Zerotorescue@2 585 -- Notifiy other modules of opening
Zerotorescue@2 586 self:SendMessage("MO_OPENING_MAIL");
Zerotorescue@2 587
Zerotorescue@82 588 if self.db.profile.keepFreeSpace > 0 and items and slotsAvailable and items > slotsAvailable then
Zerotorescue@79 589 -- If this mail contains more items than the space available, we must only take a few attachments
Zerotorescue@79 590
Zerotorescue@79 591 for attachIndex = 1, ATTACHMENTS_MAX_RECEIVE do
Zerotorescue@79 592 if GetInboxItemLink(index, attachIndex) then
Zerotorescue@79 593 -- If this attachment actually exists
Zerotorescue@79 594
Zerotorescue@79 595 if slotsAvailable > 0 then
Zerotorescue@79 596 -- If we still have slots available, then loot this one item
Zerotorescue@79 597
Zerotorescue@79 598 self:Debug("Taking attachment " .. attachIndex);
Zerotorescue@79 599
Zerotorescue@79 600 TakeInboxItem(index, attachIndex);
Zerotorescue@79 601
Zerotorescue@79 602 -- Gained an item, lost an available slot
Zerotorescue@79 603 slotsAvailable = ( slotsAvailable - 1 );
Zerotorescue@79 604 else
Zerotorescue@79 605 -- No more room available, announce and go to next item
Zerotorescue@106 606 if MailOpener.db.profile.notifications.skipped.all and onlyShowOnceCheck and MailOpener.db.profile.notifications.skipped.keepFreeSpaceLimit then
Zerotorescue@79 607 print(skippingString:format(index, subject, L["keep free space limit"]));
Zerotorescue@79 608 end
Zerotorescue@79 609
Zerotorescue@79 610 -- We're done with this mail, it isn't empty so that event won't be triggered, but we may still continue
Zerotorescue@79 611 continue = true;
Zerotorescue@79 612
Zerotorescue@79 613 self:OpenNext();
Zerotorescue@79 614
Zerotorescue@79 615 return;
Zerotorescue@79 616 end
Zerotorescue@79 617 end
Zerotorescue@79 618 end
Zerotorescue@79 619 else
Zerotorescue@79 620 -- Take everything from this mail
Zerotorescue@79 621 AutoLootMailItem(index);
Zerotorescue@79 622 end
Zerotorescue@0 623
Zerotorescue@0 624 if MailOpener.db.profile.notifications.processed.all and MailOpener.db.profile.notifications.processed[mailType] then
Zerotorescue@0 625 if gold and gold > 0 then
Zerotorescue@68 626 print(L["Processing %d: %s (%s)"]:format(index, subject, MailOpener:FormatMoney(gold)));
Zerotorescue@0 627 else
Zerotorescue@68 628 print(L["Processing %d: %s"]:format(index, subject));
Zerotorescue@0 629 end
Zerotorescue@0 630 end
Zerotorescue@0 631
Zerotorescue@0 632 -- And prepare for the next
Zerotorescue@0 633 self.tmrMailOpener = self:ScheduleTimer("OpenNext", self.db.profile.speed);
Zerotorescue@0 634 end
Zerotorescue@0 635 end
Zerotorescue@0 636 else
Zerotorescue@0 637 -- Unknown, probably just text
Zerotorescue@106 638 if MailOpener.db.profile.notifications.skipped.all and onlyShowOnceCheck and MailOpener.db.profile.notifications.skipped.other then
Zerotorescue@68 639 print(L["Skipping %d: %s"]:format(index, subject));
Zerotorescue@0 640 end
Zerotorescue@0 641
Zerotorescue@0 642 self:OpenNext();
Zerotorescue@0 643 end
Zerotorescue@0 644 else
Zerotorescue@0 645 -- Finished!
Zerotorescue@106 646 if MailOpener.db.profile.notifications.finishedCurrentBatch and firstOpenThisSync then
Zerotorescue@68 647 print(L["Finished opening the current batch."]);
Zerotorescue@0 648 end
Zerotorescue@0 649
Zerotorescue@106 650 -- We have opened mail once this batch, so quit notifying
Zerotorescue@106 651 firstOpenThisSync = nil;
Zerotorescue@106 652
Zerotorescue@0 653 self:SetOpeningStatus(false);
Zerotorescue@3 654
Zerotorescue@0 655 self:Debug("MO_OPEN_COMPLETE");
Zerotorescue@0 656
Zerotorescue@0 657 -- Report that we're all done
Zerotorescue@0 658 self:SendMessage("MO_OPEN_COMPLETE");
Zerotorescue@0 659 end
Zerotorescue@0 660 end
Zerotorescue@0 661
Zerotorescue@31 662 function mod:OpenNext()
Zerotorescue@0 663 if continue then
Zerotorescue@0 664 -- If the previous mail was opened successful, open the next
Zerotorescue@0 665
Zerotorescue@0 666 -- Next mail in line
Zerotorescue@0 667 MAIL_ITEM_INDEX = ( MAIL_ITEM_INDEX - 1 );
Zerotorescue@0 668
Zerotorescue@0 669 -- Open it
Zerotorescue@0 670 self:OpenMail(MAIL_ITEM_INDEX);
Zerotorescue@0 671 else
Zerotorescue@0 672 -- Try again at the next interval
Zerotorescue@0 673
Zerotorescue@0 674 self.tmrMailOpener = self:ScheduleTimer("OpenNext", self.db.profile.speed);
Zerotorescue@0 675 end
Zerotorescue@0 676 end
Zerotorescue@0 677
Zerotorescue@31 678 function mod:Continue()
Zerotorescue@2 679 continue = true;
Zerotorescue@2 680 self:OpenNext();
Zerotorescue@2 681 end
Zerotorescue@2 682
Zerotorescue@0 683 local mailRemainingPatterns = {
Zerotorescue@68 684 minutesSeconds = L["|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)."],
Zerotorescue@68 685 minutes = L["|cffffffff%d|r/|cffffffff%d|r mail remaining, opening everything will take about |cffffffff%d|r minutes (next refresh in |cffffffff%d|r seconds)."],
Zerotorescue@68 686 seconds = L["|cffffffff%d|r/|cffffffff%d|r mail remaining, opening everything will take about |cffffffff%d|r seconds (next refresh in |cffffffff%d|r seconds)."],
Zerotorescue@68 687 nextRefresh = L["|cffffffff%d|r/|cffffffff%d|r mail remaining, next refresh in |cffffffff%d|r seconds."],
Zerotorescue@68 688 waitingBatch = L["|cffffffff%d|r/|cffffffff%d|r mail remaining - waiting for something from the current batch to be opened..."],
Zerotorescue@68 689 waitingSync = L["|cffffffff%d|r/|cffffffff%d|r mail remaining - waiting for the next mailbox refresh..."],
Zerotorescue@68 690 soon = L["|cffffffff%d|r/|cffffffff%d|r mail remaining - everything will be opened soon..."],
Zerotorescue@0 691 };
Zerotorescue@0 692
Zerotorescue@31 693 function mod:UpdateTimer()
Zerotorescue@0 694 if lastSync then
Zerotorescue@3 695 self:UpdateMailCount();
Zerotorescue@3 696
Zerotorescue@0 697 -- Calculate the total amount of mail waiting
Zerotorescue@0 698 local numTotalMail = ( numHiddenMail + numCurrentMail );
Zerotorescue@0 699
Zerotorescue@0 700 -- Resize the font based on mail left so the counter always fits perfectly
Zerotorescue@0 701 if numTotalMail < 100 then
Zerotorescue@0 702 self.timeLeftFrame.text:SetFont(GameFontHighlight:GetFont(), 30, "THICKOUTLINE");
Zerotorescue@0 703 elseif numTotalMail < 1000 then
Zerotorescue@0 704 self.timeLeftFrame.text:SetFont(GameFontHighlight:GetFont(), 24, "THICKOUTLINE");
Zerotorescue@0 705 else
Zerotorescue@0 706 self.timeLeftFrame.text:SetFont(GameFontHighlight:GetFont(), 18, "THICKOUTLINE");
Zerotorescue@0 707 end
Zerotorescue@0 708 self.timeLeftFrame.text:SetText(numTotalMail);
Zerotorescue@3 709
Zerotorescue@3 710 -- Calculate the next server sync based on the last server sync plus sync interval
Zerotorescue@3 711 local nextSync = ( lastSync + 61 );
Zerotorescue@0 712
Zerotorescue@3 713 -- Calculate the timer remaining untill the next sync
Zerotorescue@3 714 local timeRemaining = floor( nextSync - GetTime() );
Zerotorescue@3 715
Zerotorescue@3 716 if numHiddenMail > 0 or timeRemaining > 0 then
Zerotorescue@3 717 -- If there is still mail being hidden or the timer is still know, display stuff
Zerotorescue@0 718
Zerotorescue@0 719 -- If the next sync was already due, our nextSync calculation was wrong and we must wait a little longer (lag?)
Zerotorescue@0 720 local syncTimeOut = false;
Zerotorescue@0 721 -- If time remaining is below 0, next sync should be soon
Zerotorescue@0 722 if timeRemaining < 0 then
Zerotorescue@0 723 timeRemaining = 0;
Zerotorescue@0 724 syncTimeOut = true;
Zerotorescue@0 725 end
Zerotorescue@0 726
Zerotorescue@0 727 -- Calculate the amount of server syncs required to open all mail
Zerotorescue@0 728 local syncsRequired = ceil( numHiddenMail / 50 );
Zerotorescue@0 729 -- Calculate the time required to execute all these syncs
Zerotorescue@0 730 local timeRequired = ( ( syncsRequired - 1 ) * 61 ) + timeRemaining;
Zerotorescue@0 731
Zerotorescue@0 732 local minutes = floor( timeRequired / 60 );
Zerotorescue@0 733 local seconds = floor( timeRequired % 60 );
Zerotorescue@0 734
Zerotorescue@0 735 local remainingText;
Zerotorescue@0 736 if syncTimeOut then
Zerotorescue@3 737 -- Previous server sync was expected earlier, notify user
Zerotorescue@3 738
Zerotorescue@0 739 if numCurrentMail == 50 then
Zerotorescue@3 740 -- Sync couldn't occur because we were still waiting for the current batch to be opened
Zerotorescue@0 741 remainingText = format(mailRemainingPatterns.waitingBatch, numCurrentMail, numTotalMail);
Zerotorescue@0 742 else
Zerotorescue@0 743 remainingText = format(mailRemainingPatterns.waitingSync, numCurrentMail, numTotalMail);
Zerotorescue@0 744 end
Zerotorescue@3 745 elseif numHiddenMail == 0 then
Zerotorescue@3 746 -- If no hidden mail is remaining, only show the timer for as long as we can be sure
Zerotorescue@3 747
Zerotorescue@3 748 remainingText = format(mailRemainingPatterns.nextRefresh, numCurrentMail, numTotalMail, timeRemaining);
Zerotorescue@0 749 elseif minutes ~= 0 then
Zerotorescue@0 750 if seconds ~= 0 then
Zerotorescue@0 751 remainingText = format(mailRemainingPatterns.minutesSeconds, numCurrentMail, numTotalMail, minutes, seconds, timeRemaining);
Zerotorescue@0 752 else
Zerotorescue@0 753 remainingText = format(mailRemainingPatterns.minutes, numCurrentMail, numTotalMail, minutes, timeRemaining);
Zerotorescue@0 754 end
Zerotorescue@0 755 elseif seconds ~= 0 then
Zerotorescue@0 756 remainingText = format(mailRemainingPatterns.seconds, numCurrentMail, numTotalMail, seconds, timeRemaining);
Zerotorescue@0 757 else
Zerotorescue@0 758 remainingText = format(mailRemainingPatterns.soon, numCurrentMail, numTotalMail);
Zerotorescue@0 759 end
Zerotorescue@0 760
Zerotorescue@0 761 self.timeLeftFrame.smallText:SetText(remainingText);
Zerotorescue@3 762 else
Zerotorescue@0 763 self.timeLeftFrame.smallText:SetText("");
Zerotorescue@0 764 end
Zerotorescue@0 765 end
Zerotorescue@0 766 end
Zerotorescue@0 767
Zerotorescue@31 768 function mod:StopOpening(simple)
Zerotorescue@2 769 -- Stop opener timer
Zerotorescue@2 770 self:CancelTimer(self.tmrMailOpener, true);
Zerotorescue@2 771
Zerotorescue@0 772 if not simple then
Zerotorescue@39 773 -- A simple stop is an automated stop, an advanced stop is one manually or after a sever sync
Zerotorescue@2 774
Zerotorescue@0 775 -- Recheck inventory full
Zerotorescue@0 776 inventoryFull = false;
Zerotorescue@0 777 -- Replay sound
Zerotorescue@0 778 inventoryFullSoundPlayed = nil;
Zerotorescue@0 779 end
Zerotorescue@0 780
Zerotorescue@0 781 -- Reset opener position
Zerotorescue@0 782 MAIL_ITEM_INDEX = 0;
Zerotorescue@46 783 -- Reset open everything state
Zerotorescue@46 784 MAIL_OPEN_EVERYTHING = nil;
Zerotorescue@0 785 -- Stopped opening, so allow to continue
Zerotorescue@0 786 continue = true;
Zerotorescue@31 787
Zerotorescue@0 788 self:SetOpeningStatus(false);
Zerotorescue@0 789 end
Zerotorescue@0 790
Zerotorescue@31 791 function mod:SetOpeningStatus(openingStatus)
Zerotorescue@0 792 opening = openingStatus;
Zerotorescue@0 793
Zerotorescue@0 794 if openingStatus then
Zerotorescue@68 795 self.btnOpenAll:SetText(L["Opening..."]);
Zerotorescue@0 796 else
Zerotorescue@68 797 self.btnOpenAll:SetText(L["Open all"]);
Zerotorescue@0 798 end
Zerotorescue@0 799 end
Zerotorescue@0 800
Zerotorescue@31 801 function mod:GetOptionsGroup()
Zerotorescue@0 802 local configGroup = {
Zerotorescue@0 803 order = 300,
Zerotorescue@0 804 type = "group",
Zerotorescue@68 805 name = L["Open All"],
Zerotorescue@68 806 desc = L["Change open all settings."],
Zerotorescue@0 807 args = {
Zerotorescue@0 808 filters = {
Zerotorescue@0 809 order = 10,
Zerotorescue@0 810 type = "group",
Zerotorescue@0 811 inline = true,
Zerotorescue@68 812 name = L["Filters"],
Zerotorescue@0 813 args = {
Zerotorescue@0 814 description = {
Zerotorescue@0 815 order = 10,
Zerotorescue@0 816 type = "description",
Zerotorescue@68 817 name = L["Toggle which mail the opener should autoloot."],
Zerotorescue@0 818 },
Zerotorescue@0 819 AHHeader = {
Zerotorescue@0 820 order = 15,
Zerotorescue@0 821 type = "header",
Zerotorescue@68 822 name = L["Auction House Mail"],
Zerotorescue@0 823 },
Zerotorescue@0 824 canceled = {
Zerotorescue@0 825 order = 20,
Zerotorescue@0 826 type = "toggle",
Zerotorescue@68 827 name = L["Open all |cfffed000auction canceled|r mail"],
Zerotorescue@68 828 desc = L["Automatically loot all auction canceled mail from the auction house."],
Zerotorescue@0 829 set = function(i, v) self.db.profile.filter.AH.canceled = v; end,
Zerotorescue@0 830 get = function() return self.db.profile.filter.AH.canceled; end,
Zerotorescue@0 831 width = "double",
Zerotorescue@0 832 },
Zerotorescue@0 833 expired = {
Zerotorescue@0 834 order = 21,
Zerotorescue@0 835 type = "toggle",
Zerotorescue@68 836 name = L["Open all |cfffed000auction expired|r mail"],
Zerotorescue@68 837 desc = L["Automatically loot all auction expired mail from the auction house."],
Zerotorescue@0 838 set = function(i, v) self.db.profile.filter.AH.expired = v; end,
Zerotorescue@0 839 get = function() return self.db.profile.filter.AH.expired; end,
Zerotorescue@0 840 width = "double",
Zerotorescue@0 841 },
Zerotorescue@0 842 outbid = {
Zerotorescue@0 843 order = 22,
Zerotorescue@0 844 type = "toggle",
Zerotorescue@68 845 name = L["Open all |cfffed000outbid on|r mail"],
Zerotorescue@68 846 desc = L["Automatically loot all auction outbid mail from the auction house."],
Zerotorescue@0 847 set = function(i, v) self.db.profile.filter.AH.outbid = v; end,
Zerotorescue@0 848 get = function() return self.db.profile.filter.AH.outbid; end,
Zerotorescue@0 849 width = "double",
Zerotorescue@0 850 },
Zerotorescue@0 851 success = {
Zerotorescue@0 852 order = 23,
Zerotorescue@0 853 type = "toggle",
Zerotorescue@68 854 name = L["Open all |cfffed000auction successful|r mail"],
Zerotorescue@68 855 desc = L["Automatically loot all auction successful mail from the auction house."],
Zerotorescue@0 856 set = function(i, v) self.db.profile.filter.AH.success = v; end,
Zerotorescue@0 857 get = function() return self.db.profile.filter.AH.success; end,
Zerotorescue@0 858 width = "double",
Zerotorescue@0 859 },
Zerotorescue@0 860 won = {
Zerotorescue@0 861 order = 24,
Zerotorescue@0 862 type = "toggle",
Zerotorescue@68 863 name = L["Open all |cfffed000auction won|r mail"],
Zerotorescue@68 864 desc = L["Automatically loot all auction won mail from the auction house."],
Zerotorescue@0 865 set = function(i, v) self.db.profile.filter.AH.won = v; end,
Zerotorescue@0 866 get = function() return self.db.profile.filter.AH.won; end,
Zerotorescue@0 867 width = "double",
Zerotorescue@0 868 },
Zerotorescue@0 869 normalHeader = {
Zerotorescue@0 870 order = 30,
Zerotorescue@0 871 type = "header",
Zerotorescue@68 872 name = L["Remaining Mail"],
Zerotorescue@0 873 },
Zerotorescue@0 874 normalAttachments = {
Zerotorescue@0 875 order = 40,
Zerotorescue@0 876 type = "toggle",
Zerotorescue@68 877 name = L["Normal mail with |cfffed000attachments|r"],
Zerotorescue@68 878 desc = L["Automatically loot all normal mail containing attachments (CoDs and Blizzard mail will be skipped)."],
Zerotorescue@0 879 set = function(i, v) self.db.profile.filter.normalAttachments = v; end,
Zerotorescue@0 880 get = function() return self.db.profile.filter.normalAttachments; end,
Zerotorescue@0 881 width = "double",
Zerotorescue@0 882 },
Zerotorescue@0 883 normalMoney = {
Zerotorescue@0 884 order = 50,
Zerotorescue@0 885 type = "toggle",
Zerotorescue@68 886 name = L["Normal mail with |cfffed000gold|r"],
Zerotorescue@68 887 desc = L["Automatically loot all normal mail containing gold (CoDs and Blizzard mail will be skipped)."],
Zerotorescue@0 888 set = function(i, v) self.db.profile.filter.normalMoney = v; end,
Zerotorescue@0 889 get = function() return self.db.profile.filter.normalMoney; end,
Zerotorescue@0 890 width = "double",
Zerotorescue@0 891 },
Zerotorescue@50 892 allowShiftClick = {
Zerotorescue@50 893 order = 60,
Zerotorescue@50 894 type = "toggle",
Zerotorescue@68 895 name = L["Allow shift-clicking of the |cfffed000Open All|r button to autoloot |cfffed000everything|r, regardless of the above filters."],
Zerotorescue@68 896 desc = L["Allow shift-clicking of the |cfffed000Open All|r button to autoloot |cfffed000everything|r with attachments, temporarily overriding all filters."],
Zerotorescue@50 897 set = function(i, v) self.db.profile.filter.allowShiftClick = v; end,
Zerotorescue@50 898 get = function() return self.db.profile.filter.allowShiftClick; end,
Zerotorescue@50 899 width = "full",
Zerotorescue@50 900 },
Zerotorescue@0 901 },
Zerotorescue@0 902 },
Zerotorescue@0 903 -- Continuous opening config inline group
Zerotorescue@0 904 continuousOpening = {
Zerotorescue@0 905 order = 20,
Zerotorescue@0 906 type = "group",
Zerotorescue@0 907 inline = true,
Zerotorescue@68 908 name = L["Opening Interval"],
Zerotorescue@0 909 args = {
Zerotorescue@0 910 description = {
Zerotorescue@0 911 order = 10,
Zerotorescue@0 912 type = "description",
Zerotorescue@0 913 name = function()
Zerotorescue@68 914 local defaultString = L["The default behavior 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";
Zerotorescue@0 915
Zerotorescue@0 916 local currentSettings = "";
Zerotorescue@0 917 if MailOpener.db.profile.general.continueOpening then
Zerotorescue@68 918 currentSettings = currentSettings .. L["Mail Opener will |cff00ff00continue|r to attempt to open the remaining mail every |cfffed000%d seconds|r."]:format(MailOpener.db.profile.general.waitTime) .. " ";
Zerotorescue@0 919 else
Zerotorescue@68 920 currentSettings = currentSettings .. L["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."] .. " ";
Zerotorescue@0 921 end
Zerotorescue@68 922 currentSettings = currentSettings .. L["The first batch after each server refresh will be opened after waiting |cfffed000%d seconds|r."]:format(MailOpener.db.profile.general.initialDelay);
Zerotorescue@0 923 return defaultString .. currentSettings;
Zerotorescue@0 924 end,
Zerotorescue@0 925 },
Zerotorescue@0 926 header = {
Zerotorescue@0 927 order = 15,
Zerotorescue@0 928 type = "header",
Zerotorescue@0 929 name = "",
Zerotorescue@0 930 },
Zerotorescue@0 931 continueOpening = {
Zerotorescue@0 932 order = 20,
Zerotorescue@0 933 type = "toggle",
Zerotorescue@68 934 name = L["Continue opening mail"],
Zerotorescue@68 935 desc = L["Continue opening mail at the interval set below, even if the mailbox wasn't refreshed recently."],
Zerotorescue@0 936 width = "full",
Zerotorescue@0 937 get = function() return MailOpener.db.profile.general.continueOpening; end,
Zerotorescue@0 938 set = function(i, v) MailOpener.db.profile.general.continueOpening = v; end,
Zerotorescue@0 939 },
Zerotorescue@0 940 waitTime = {
Zerotorescue@0 941 order = 30,
Zerotorescue@0 942 type = "range",
Zerotorescue@0 943 width = "double",
Zerotorescue@0 944 min = 0.5,
Zerotorescue@0 945 max = 60,
Zerotorescue@0 946 step = 0.5,
Zerotorescue@68 947 name = L["Continued Mail Opening Interval"],
Zerotorescue@68 948 desc = L["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."],
Zerotorescue@0 949 get = function() return MailOpener.db.profile.general.waitTime; end,
Zerotorescue@0 950 set = function(i, v) MailOpener.db.profile.general.waitTime = v; end,
Zerotorescue@0 951 disabled = function() return (not MailOpener.db.profile.general.continueOpening); end,
Zerotorescue@0 952 },
Zerotorescue@0 953 initialDelay = {
Zerotorescue@0 954 order = 40,
Zerotorescue@0 955 type = "range",
Zerotorescue@0 956 width = "double",
Zerotorescue@0 957 min = 0.5,
Zerotorescue@0 958 max = 60,
Zerotorescue@0 959 step = 0.5,
Zerotorescue@68 960 name = L["Initial Mail Opening Delay"],
Zerotorescue@68 961 desc = L["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."],
Zerotorescue@0 962 get = function() return MailOpener.db.profile.general.initialDelay; end,
Zerotorescue@0 963 set = function(i, v) MailOpener.db.profile.general.initialDelay = v; end,
Zerotorescue@0 964 },
Zerotorescue@0 965 },
Zerotorescue@0 966 }, -- end Continuous opening config inline group
Zerotorescue@0 967 keepFree = {
Zerotorescue@0 968 order = 30,
Zerotorescue@0 969 type = "group",
Zerotorescue@0 970 inline = true,
Zerotorescue@68 971 name = L["Keep Free Space"],
Zerotorescue@0 972 args = {
Zerotorescue@0 973 description = {
Zerotorescue@0 974 order = 10,
Zerotorescue@0 975 type = "description",
Zerotorescue@79 976 name = L["You can set an amount of bag space you wish to reserve when opening mail."],
Zerotorescue@0 977 },
Zerotorescue@0 978 header = {
Zerotorescue@0 979 order = 15,
Zerotorescue@0 980 type = "header",
Zerotorescue@0 981 name = "",
Zerotorescue@0 982 },
Zerotorescue@0 983 keepFreeSpace = {
Zerotorescue@0 984 order = 20,
Zerotorescue@0 985 type = "range",
Zerotorescue@0 986 min = 0,
Zerotorescue@0 987 max = 100,
Zerotorescue@0 988 step = 1,
Zerotorescue@0 989 width = "double",
Zerotorescue@68 990 name = L["Keep free space"],
Zerotorescue@79 991 desc = L["Change the amount of space to reserve for other things when opening mail.\n\nEnabling this functionality by setting this value above 0 may increase resource usage slightly."],
Zerotorescue@0 992 set = function(i, v) self.db.profile.keepFreeSpace = v; end,
Zerotorescue@0 993 get = function() return self.db.profile.keepFreeSpace; end,
Zerotorescue@0 994 },
Zerotorescue@0 995 },
Zerotorescue@0 996 },
Zerotorescue@0 997 speed = {
Zerotorescue@0 998 order = 40,
Zerotorescue@0 999 type = "group",
Zerotorescue@0 1000 inline = true,
Zerotorescue@0 1001 name = "Opening Speed",
Zerotorescue@0 1002 args = {
Zerotorescue@0 1003 description = {
Zerotorescue@0 1004 order = 10,
Zerotorescue@0 1005 type = "description",
Zerotorescue@68 1006 name = L["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."],
Zerotorescue@0 1007 },
Zerotorescue@0 1008 header = {
Zerotorescue@0 1009 order = 15,
Zerotorescue@0 1010 type = "header",
Zerotorescue@0 1011 name = "",
Zerotorescue@0 1012 },
Zerotorescue@0 1013 openMailInterval = {
Zerotorescue@0 1014 order = 20,
Zerotorescue@0 1015 type = "range",
Zerotorescue@0 1016 min = 5,
Zerotorescue@0 1017 max = 2500,
Zerotorescue@0 1018 step = 5,
Zerotorescue@0 1019 width = "double",
Zerotorescue@68 1020 name = L["Open single mail interval"],
Zerotorescue@68 1021 desc = L["Change the mail opening speed (in microseconds) for each mail. Lower may not always be faster."],
Zerotorescue@0 1022 get = function() return ( self.db.profile.speed * 1000 ); end,
Zerotorescue@0 1023 set = function(i, v) self.db.profile.speed = ( v / 1000 ); end,
Zerotorescue@0 1024 },
Zerotorescue@0 1025 },
Zerotorescue@0 1026 },
Zerotorescue@0 1027 },
Zerotorescue@0 1028 };
Zerotorescue@0 1029
Zerotorescue@0 1030 return configGroup;
Zerotorescue@0 1031 end
Zerotorescue@0 1032
Zerotorescue@31 1033 function mod:Debug(t)
Zerotorescue@68 1034 return MailOpener:Debug(("|cff00ff00OpenAll|r:%s"):format(t));
Zerotorescue@0 1035 end