|
Zerotorescue@3
|
1 -- You can access this addon's object through: LibStub("AceAddon-3.0"):GetAddon("MailOpener")
|
|
Zerotorescue@3
|
2 local MailOpener = LibStub("AceAddon-3.0"):NewAddon("MailOpener", "AceEvent-3.0", "AceTimer-3.0");
|
|
Zerotorescue@68
|
3 local L = LibStub("AceLocale-3.0"):GetLocale("MailOpener");
|
|
Zerotorescue@0
|
4
|
|
Zerotorescue@8
|
5 -- You can check if MailOpener is busy with the global MailAddonBusy (if not MailAddonBusy then ...do something... end)
|
|
Zerotorescue@8
|
6 -- MailAddonBusy will be nil when nothing is happening or filled with the addon name when MO is working
|
|
Zerotorescue@8
|
7 -- Another addon can use this variable to indicate they're working too, MailOpener will then wait for that to finish
|
|
Zerotorescue@3
|
8
|
|
Zerotorescue@115
|
9 local AutoOpenMail, MailOpenerConfig, lastAmount, lastQuickAuctionsStatus, freshList, mailboxEmptySoundPlayed, mailboxEmptySoundPlayedThisVisit, hasOpenedMailAlready, originalCheckInbox;
|
|
Zerotorescue@0
|
10
|
|
Zerotorescue@0
|
11 function MailOpener:OnInitialize()
|
|
Zerotorescue@31
|
12 self:Debug("OnInitialize");
|
|
Zerotorescue@31
|
13
|
|
Zerotorescue@31
|
14
|
|
Zerotorescue@31
|
15
|
|
Zerotorescue@31
|
16
|
|
Zerotorescue@31
|
17 -- SAVED VARIABLES
|
|
Zerotorescue@31
|
18
|
|
Zerotorescue@0
|
19 local defaults = {
|
|
Zerotorescue@60
|
20 global = {
|
|
Zerotorescue@60
|
21 currentTip = -1, -- even though LUA table indexes start at one, Config's OnEnable will increase this value by one the first time you run it and another 1 to adjust for the % modifier, so we still actually start at the table index 1
|
|
Zerotorescue@60
|
22 },
|
|
Zerotorescue@0
|
23 profile = {
|
|
Zerotorescue@8
|
24 uses = 0,
|
|
Zerotorescue@0
|
25 general = {
|
|
Zerotorescue@8
|
26 defaultStatus = "disabled", -- addon enabled, but mail opening not auto on
|
|
Zerotorescue@0
|
27 defaultQAStatus = "__remember",
|
|
Zerotorescue@0
|
28 continueOpeningStackableItems = false,
|
|
Zerotorescue@51
|
29 showHelpTooltips = true,
|
|
Zerotorescue@0
|
30 autoDisableQAAutoMail = true,
|
|
Zerotorescue@0
|
31 autoReenableQAAutoMail = false,
|
|
Zerotorescue@0
|
32 autoSetBackQAAutoMail = true,
|
|
Zerotorescue@0
|
33 continueOpening = false,
|
|
Zerotorescue@0
|
34 waitTime = 5,
|
|
Zerotorescue@0
|
35 initialDelay = 0.5,
|
|
Zerotorescue@111
|
36 overrideCheckInbox = true,
|
|
Zerotorescue@0
|
37 },
|
|
Zerotorescue@0
|
38 modules = {
|
|
Zerotorescue@31
|
39 BeanCounterSupport = true,
|
|
Zerotorescue@31
|
40 Config = false,
|
|
Zerotorescue@0
|
41 Collected = true,
|
|
Zerotorescue@5
|
42 FailSafe = true,
|
|
Zerotorescue@0
|
43 },
|
|
Zerotorescue@0
|
44 notifications = {
|
|
Zerotorescue@3
|
45 welcome = false,
|
|
Zerotorescue@3
|
46 bye = false,
|
|
Zerotorescue@0
|
47 finishedCurrentBatch = true,
|
|
Zerotorescue@0
|
48 mailboxIsEmpty = true,
|
|
Zerotorescue@0
|
49
|
|
Zerotorescue@0
|
50 skipped = {
|
|
Zerotorescue@0
|
51 all = true,
|
|
Zerotorescue@0
|
52 inventoryFull = true,
|
|
Zerotorescue@0
|
53 keepFreeSpaceLimit = true,
|
|
Zerotorescue@0
|
54 GMMail = true,
|
|
Zerotorescue@0
|
55 COD = true,
|
|
Zerotorescue@0
|
56 normalGoldMail = true,
|
|
Zerotorescue@0
|
57 normalItemsMail = true,
|
|
Zerotorescue@0
|
58 AHexpired = true,
|
|
Zerotorescue@0
|
59 AHsuccess = true,
|
|
Zerotorescue@0
|
60 AHwon = true,
|
|
Zerotorescue@0
|
61 AHcanceled = true,
|
|
Zerotorescue@0
|
62 AHoutbid = true,
|
|
Zerotorescue@0
|
63 other = true,
|
|
Zerotorescue@0
|
64 },
|
|
Zerotorescue@0
|
65 processed = {
|
|
Zerotorescue@0
|
66 all = true,
|
|
Zerotorescue@0
|
67 normalGoldMail = true,
|
|
Zerotorescue@0
|
68 normalItemsMail = true,
|
|
Zerotorescue@0
|
69 AHexpired = true,
|
|
Zerotorescue@0
|
70 AHsuccess = true,
|
|
Zerotorescue@0
|
71 AHwon = true,
|
|
Zerotorescue@0
|
72 AHcanceled = true,
|
|
Zerotorescue@0
|
73 AHoutbid = true,
|
|
Zerotorescue@0
|
74 other = true,
|
|
Zerotorescue@0
|
75 },
|
|
Zerotorescue@0
|
76
|
|
Zerotorescue@0
|
77 bagsFullSound = false,
|
|
Zerotorescue@0
|
78 bagsFullSoundFile = "Sound\\Spells\\SimonGame_Visual_BadPress.wav",
|
|
Zerotorescue@0
|
79 bagsFullSoundFileName = "Simon Error",
|
|
Zerotorescue@0
|
80 bagsFullSoundOnlyOnce = true,
|
|
Zerotorescue@42
|
81 bagsFullSoundOnlyOncePerMailboxVisit = false,
|
|
Zerotorescue@0
|
82 mailboxEmptySound = false,
|
|
Zerotorescue@0
|
83 mailboxEmptySoundFile = "Sound\\Spells\\SimonGame_Visual_GameStart.wav",
|
|
Zerotorescue@0
|
84 mailboxEmptySoundFileName = "Simon Start",
|
|
Zerotorescue@0
|
85 mailboxEmptySoundOnlyOnce = true,
|
|
Zerotorescue@42
|
86 mailboxEmptySoundOnlyOncePerMailboxVisit = false,
|
|
Zerotorescue@0
|
87 },
|
|
Zerotorescue@0
|
88 },
|
|
Zerotorescue@0
|
89 };
|
|
Zerotorescue@0
|
90
|
|
Zerotorescue@0
|
91 -- Register our saved variables database
|
|
Zerotorescue@0
|
92 self.db = LibStub("AceDB-3.0"):New("MailOpenerDB", defaults, true);
|
|
Zerotorescue@0
|
93
|
|
Zerotorescue@0
|
94
|
|
Zerotorescue@31
|
95
|
|
Zerotorescue@31
|
96
|
|
Zerotorescue@31
|
97
|
|
Zerotorescue@31
|
98 -- MODULE TOGGLING
|
|
Zerotorescue@0
|
99
|
|
Zerotorescue@0
|
100 -- Don't enable the config module until we need it
|
|
Zerotorescue@0
|
101 for name, module in self:IterateModules() do
|
|
Zerotorescue@31
|
102 if self.db.profile.modules[name] ~= nil then
|
|
Zerotorescue@0
|
103 if self.db.profile.modules[name] then
|
|
Zerotorescue@68
|
104 self:Debug(("|cff00ff00Enabling|r module: "):format(name));
|
|
Zerotorescue@0
|
105 else
|
|
Zerotorescue@68
|
106 self:Debug(("|cffff0000Disabling|r module: "):format(name));
|
|
Zerotorescue@0
|
107 end
|
|
Zerotorescue@0
|
108
|
|
Zerotorescue@0
|
109 module:SetEnabledState(self.db.profile.modules[name]);
|
|
Zerotorescue@0
|
110 end
|
|
Zerotorescue@0
|
111 end
|
|
Zerotorescue@0
|
112
|
|
Zerotorescue@31
|
113
|
|
Zerotorescue@31
|
114
|
|
Zerotorescue@31
|
115
|
|
Zerotorescue@31
|
116
|
|
Zerotorescue@31
|
117 -- SLASH COMMANDS
|
|
Zerotorescue@31
|
118
|
|
Zerotorescue@31
|
119 -- Disable the AddonLoader slash commands
|
|
Zerotorescue@31
|
120 SLASH_MO1 = nil;
|
|
Zerotorescue@31
|
121 SLASH_MAILOPEN1 = nil;
|
|
Zerotorescue@31
|
122 SLASH_MAILOPENER1 = nil;
|
|
Zerotorescue@31
|
123
|
|
Zerotorescue@31
|
124 -- Register our own slash commands
|
|
Zerotorescue@31
|
125 SLASH_MAILOPENER1 = "/mo";
|
|
Zerotorescue@31
|
126 SLASH_MAILOPENER2 = "/mailopen";
|
|
Zerotorescue@31
|
127 SLASH_MAILOPENER3 = "/mailopener";
|
|
Zerotorescue@31
|
128 SlashCmdList["MAILOPENER"] = function(msg)
|
|
Zerotorescue@31
|
129 MailOpener:EnableConfigModule();
|
|
Zerotorescue@31
|
130
|
|
Zerotorescue@31
|
131 MailOpenerConfig:CommandHandler(msg);
|
|
Zerotorescue@31
|
132 end
|
|
Zerotorescue@31
|
133
|
|
Zerotorescue@31
|
134
|
|
Zerotorescue@31
|
135
|
|
Zerotorescue@31
|
136
|
|
Zerotorescue@31
|
137
|
|
Zerotorescue@31
|
138 -- INTERFACE OPTIONS
|
|
Zerotorescue@31
|
139
|
|
Zerotorescue@31
|
140 -- Attempt to remove the interface options added by AddonLoader (if enabled)
|
|
Zerotorescue@31
|
141 if AddonLoader and AddonLoader.RemoveInterfaceOptions then
|
|
Zerotorescue@31
|
142 AddonLoader:RemoveInterfaceOptions("Mail Opener");
|
|
Zerotorescue@31
|
143 end
|
|
Zerotorescue@31
|
144
|
|
Zerotorescue@31
|
145 -- Now create our own options frame
|
|
Zerotorescue@31
|
146 local frame = CreateFrame("Frame", nil, UIParent);
|
|
Zerotorescue@31
|
147 frame:Hide();
|
|
Zerotorescue@31
|
148 frame.name = "Mail Opener";
|
|
Zerotorescue@31
|
149 frame:HookScript("OnShow", function(self)
|
|
Zerotorescue@31
|
150 -- Enable the config module
|
|
Zerotorescue@31
|
151 MailOpener:EnableConfigModule();
|
|
Zerotorescue@31
|
152
|
|
Zerotorescue@31
|
153 -- Load the options and add it to the blizzard interface list
|
|
Zerotorescue@31
|
154 MailOpenerConfig:Load();
|
|
Zerotorescue@31
|
155
|
|
Zerotorescue@31
|
156 -- Refresh the frame to instantly show the right options
|
|
Zerotorescue@31
|
157 InterfaceOptionsFrame_OpenToCategory(self.name)
|
|
Zerotorescue@31
|
158 end);
|
|
Zerotorescue@31
|
159 -- And add it to the interface options
|
|
Zerotorescue@31
|
160 InterfaceOptions_AddCategory(frame);
|
|
Zerotorescue@31
|
161
|
|
Zerotorescue@31
|
162
|
|
Zerotorescue@31
|
163
|
|
Zerotorescue@31
|
164
|
|
Zerotorescue@31
|
165
|
|
Zerotorescue@31
|
166 -- ADDON / MAIL OPENING STATUS TOGGLER
|
|
Zerotorescue@31
|
167
|
|
Zerotorescue@0
|
168 -- Make the open all checkbox
|
|
Zerotorescue@50
|
169 local check = CreateFrame("CheckButton", "cbMailOpenerEnable", MailFrame, "OptionsCheckButtonTemplate");
|
|
Zerotorescue@0
|
170 check:SetHeight(26);
|
|
Zerotorescue@0
|
171 check:SetWidth(26);
|
|
Zerotorescue@50
|
172 check:SetPoint("TOPLEFT", MailFrame, "TOPLEFT", 68, -13);
|
|
Zerotorescue@3
|
173 check:SetChecked(true);
|
|
Zerotorescue@0
|
174 check:SetHitRectInsets(0, -80, 0, 0);
|
|
Zerotorescue@91
|
175 check:SetScript("OnClick", function(cbSelf)
|
|
Zerotorescue@3
|
176 if IsShiftKeyDown() then
|
|
Zerotorescue@3
|
177 -- Shift key = toggle addon on or off, since addon is already on there's only one option
|
|
Zerotorescue@3
|
178
|
|
Zerotorescue@91
|
179 if not self:IsEnabled() then
|
|
Zerotorescue@91
|
180 self:Print(L["Shift key was held down, so |cff00ff00enabling|r the entire addon as well as automatic opening of mail."]);
|
|
Zerotorescue@3
|
181
|
|
Zerotorescue@91
|
182 self:Enable();
|
|
Zerotorescue@3
|
183
|
|
Zerotorescue@3
|
184 -- The above calls MAIL_SHOW which changes AutoOpenMail, so we can't remember the old setting
|
|
Zerotorescue@3
|
185 AutoOpenMail = true;
|
|
Zerotorescue@3
|
186
|
|
Zerotorescue@91
|
187 cbSelf:SetChecked(true);
|
|
Zerotorescue@3
|
188 else
|
|
Zerotorescue@91
|
189 self:Print(L["Shift key was held down, so |cffff0000disabling|r the entire addon."]);
|
|
Zerotorescue@3
|
190
|
|
Zerotorescue@91
|
191 self:Disable();
|
|
Zerotorescue@3
|
192
|
|
Zerotorescue@91
|
193 cbSelf:SetChecked(false);
|
|
Zerotorescue@3
|
194 end
|
|
Zerotorescue@0
|
195 else
|
|
Zerotorescue@3
|
196 -- Normal click
|
|
Zerotorescue@3
|
197
|
|
Zerotorescue@91
|
198 if cbSelf:GetChecked() then
|
|
Zerotorescue@91
|
199 self:Print(L["|cff00ff00Enabling|r automatic opening of mail."]);
|
|
Zerotorescue@3
|
200
|
|
Zerotorescue@3
|
201 AutoOpenMail = true;
|
|
Zerotorescue@91
|
202 self:ScheduleOpen(false);
|
|
Zerotorescue@3
|
203 else
|
|
Zerotorescue@91
|
204 self:Print(L["|cffff0000Disabling|r automatic opening of mail."]);
|
|
Zerotorescue@3
|
205
|
|
Zerotorescue@3
|
206 AutoOpenMail = false;
|
|
Zerotorescue@3
|
207 end
|
|
Zerotorescue@0
|
208 end
|
|
Zerotorescue@0
|
209 end);
|
|
Zerotorescue@68
|
210 check.tooltipTitle = L["Mail Opener status"];
|
|
Zerotorescue@68
|
211 check.tooltip = L["Toggle automatic mail opening |cff00ff00on|r or |cffff0000off|r (you can also enforce this by holding shift when opening the mailbox).\n\nYou can toggle this addon |cff00ff00on|r or |cffff0000off|r by |cfffed000shift-clicking|r this checkbox."];
|
|
Zerotorescue@91
|
212 check:SetScript("OnEnter", function(cbSelf)
|
|
Zerotorescue@91
|
213 if self.db.profile.general.showHelpTooltips then
|
|
Zerotorescue@91
|
214 GameTooltip:SetOwner(cbSelf, "ANCHOR_BOTTOM")
|
|
Zerotorescue@91
|
215 GameTooltip:SetPoint("BOTTOM", cbSelf, "BOTTOM")
|
|
Zerotorescue@91
|
216 GameTooltip:SetText(cbSelf.tooltipTitle, 1, .82, 0, 1)
|
|
Zerotorescue@51
|
217
|
|
Zerotorescue@91
|
218 if type(cbSelf.tooltip) == "string" then
|
|
Zerotorescue@91
|
219 GameTooltip:AddLine(cbSelf.tooltip, 1, 1, 1, 1);
|
|
Zerotorescue@51
|
220 end
|
|
Zerotorescue@51
|
221
|
|
Zerotorescue@51
|
222 GameTooltip:Show();
|
|
Zerotorescue@50
|
223 end
|
|
Zerotorescue@50
|
224 end);
|
|
Zerotorescue@91
|
225 check:SetScript("OnLeave", function(cbSelf)
|
|
Zerotorescue@50
|
226 GameTooltip:Hide();
|
|
Zerotorescue@50
|
227 end);
|
|
Zerotorescue@0
|
228
|
|
Zerotorescue@0
|
229 -- Get reference to the text field
|
|
Zerotorescue@0
|
230 local checkboxText = _G[check:GetName() .. "Text"];
|
|
Zerotorescue@68
|
231 checkboxText:SetText(L["Mail Opener"]);
|
|
Zerotorescue@0
|
232
|
|
Zerotorescue@0
|
233 self.cbOpenAll = check;
|
|
Zerotorescue@0
|
234
|
|
Zerotorescue@31
|
235
|
|
Zerotorescue@31
|
236
|
|
Zerotorescue@31
|
237
|
|
Zerotorescue@31
|
238 -- CONFIG BUTTON
|
|
Zerotorescue@31
|
239
|
|
Zerotorescue@0
|
240 -- Make the config button
|
|
Zerotorescue@0
|
241 local button = CreateFrame("Button", "btnMailOpenerConfig", MailFrame, "UIPanelButtonTemplate")
|
|
Zerotorescue@68
|
242 button:SetText(L["Config"])
|
|
Zerotorescue@0
|
243 button:SetHeight(23)
|
|
Zerotorescue@0
|
244 button:SetWidth(55)
|
|
Zerotorescue@31
|
245 button:SetPoint("TOPRIGHT", MailFrame, "TOPRIGHT", -55, -13);
|
|
Zerotorescue@0
|
246 button:SetScript("OnClick", function()
|
|
Zerotorescue@0
|
247 MailOpener:EnableConfigModule();
|
|
Zerotorescue@0
|
248
|
|
Zerotorescue@0
|
249 MailOpenerConfig:Show();
|
|
Zerotorescue@0
|
250
|
|
Zerotorescue@8
|
251 --BETA:if MailOpener.db.profile.uses >= 15 then
|
|
Zerotorescue@7
|
252 --BETA: MailOpener:ShowBetaPopup();
|
|
Zerotorescue@7
|
253 --BETA:end
|
|
Zerotorescue@0
|
254 end);
|
|
Zerotorescue@68
|
255 button.tooltipTitle = L["Mail Opener Config"];
|
|
Zerotorescue@68
|
256 button.tooltip = L["Click to open the configuration window for Mail Opener."];
|
|
Zerotorescue@91
|
257 button:SetScript("OnEnter", function(btnSelf)
|
|
Zerotorescue@91
|
258 if self.db.profile.general.showHelpTooltips then
|
|
Zerotorescue@91
|
259 GameTooltip:SetOwner(btnSelf, "ANCHOR_BOTTOM")
|
|
Zerotorescue@91
|
260 GameTooltip:SetPoint("BOTTOM", btnSelf, "TOP")
|
|
Zerotorescue@91
|
261 GameTooltip:SetText(btnSelf.tooltipTitle, 1, .82, 0, 1)
|
|
Zerotorescue@51
|
262
|
|
Zerotorescue@91
|
263 if type(btnSelf.tooltip) == "string" then
|
|
Zerotorescue@91
|
264 GameTooltip:AddLine(btnSelf.tooltip, 1, 1, 1, 1);
|
|
Zerotorescue@51
|
265 end
|
|
Zerotorescue@51
|
266
|
|
Zerotorescue@51
|
267 GameTooltip:Show();
|
|
Zerotorescue@50
|
268 end
|
|
Zerotorescue@50
|
269 end);
|
|
Zerotorescue@91
|
270 button:SetScript("OnLeave", function(btnSelf)
|
|
Zerotorescue@50
|
271 GameTooltip:Hide();
|
|
Zerotorescue@50
|
272 end);
|
|
Zerotorescue@0
|
273
|
|
Zerotorescue@0
|
274 self.btnConfig = button;
|
|
Zerotorescue@0
|
275
|
|
Zerotorescue@31
|
276
|
|
Zerotorescue@31
|
277
|
|
Zerotorescue@31
|
278
|
|
Zerotorescue@31
|
279
|
|
Zerotorescue@31
|
280 -- ADDON LOADING
|
|
Zerotorescue@31
|
281 -- THE BELOW WILL TAKE SOME TIME; WE WILL BE LOADING OTHER ADDONS
|
|
Zerotorescue@31
|
282
|
|
Zerotorescue@31
|
283 if select(6, GetAddOnInfo("Postal")) == nil then
|
|
Zerotorescue@31
|
284 self.PostalEnabled = true; -- Set this as an object variable so we can use it in our modules
|
|
Zerotorescue@0
|
285
|
|
Zerotorescue@31
|
286 -- Ensure this addon is loaded if AddonLoader is installed
|
|
Zerotorescue@126
|
287 if AddonLoader and AddonLoader.LoadAddOn and not IsAddOnLoaded("Postal") and not Postal then
|
|
Zerotorescue@31
|
288 AddonLoader:LoadAddOn("Postal");
|
|
Zerotorescue@31
|
289 end
|
|
Zerotorescue@0
|
290 end
|
|
Zerotorescue@0
|
291
|
|
Zerotorescue@118
|
292 if select(6, GetAddOnInfo("ZeroAuctions")) == nil then
|
|
Zerotorescue@118
|
293 self.ZeroAuctionsEnabled = true; -- Set this as an object variable so we can use it in our modules
|
|
Zerotorescue@116
|
294
|
|
Zerotorescue@116
|
295 -- Ensure this addon is loaded if AddonLoader is installed
|
|
Zerotorescue@126
|
296 if AddonLoader and AddonLoader.LoadAddOn and not IsAddOnLoaded("ZeroAuctions") then
|
|
Zerotorescue@116
|
297 AddonLoader:LoadAddOn("ZeroAuctions");
|
|
Zerotorescue@116
|
298 end
|
|
Zerotorescue@31
|
299 end
|
|
Zerotorescue@31
|
300
|
|
Zerotorescue@31
|
301
|
|
Zerotorescue@31
|
302
|
|
Zerotorescue@31
|
303
|
|
Zerotorescue@31
|
304
|
|
Zerotorescue@31
|
305 -- ADJUST POSITIONS
|
|
Zerotorescue@31
|
306
|
|
Zerotorescue@123
|
307 if self.ZeroAuctionsEnabled then
|
|
Zerotorescue@31
|
308 -- QA is enabled so move the checkbox further to the right
|
|
Zerotorescue@0
|
309
|
|
Zerotorescue@31
|
310 self.cbOpenAll:SetPoint("TOPLEFT", MailFrame, "TOPLEFT", 155, -13);
|
|
Zerotorescue@31
|
311 end
|
|
Zerotorescue@31
|
312
|
|
Zerotorescue@31
|
313 if self.PostalEnabled then
|
|
Zerotorescue@31
|
314 self.btnConfig:SetPoint("TOPRIGHT", MailFrame, "TOPRIGHT", -75, -13);
|
|
Zerotorescue@31
|
315 end
|
|
Zerotorescue@0
|
316 end
|
|
Zerotorescue@0
|
317
|
|
Zerotorescue@0
|
318 function MailOpener:OnEnable()
|
|
Zerotorescue@0
|
319 self:RegisterEvent("MAIL_SHOW");
|
|
Zerotorescue@0
|
320 self:RegisterEvent("PLAYER_ENTERING_WORLD");
|
|
Zerotorescue@0
|
321
|
|
Zerotorescue@0
|
322 self.btnConfig:Show();
|
|
Zerotorescue@0
|
323
|
|
Zerotorescue@115
|
324 if not originalCheckInbox then
|
|
Zerotorescue@115
|
325 -- Override the CheckInbox function
|
|
Zerotorescue@115
|
326 -- Remember the original
|
|
Zerotorescue@115
|
327 originalCheckInbox = CheckInbox;
|
|
Zerotorescue@115
|
328 -- Then override that
|
|
Zerotorescue@115
|
329 CheckInbox = NewCheckInbox;
|
|
Zerotorescue@115
|
330 end
|
|
Zerotorescue@115
|
331
|
|
Zerotorescue@0
|
332 -- Reset variables
|
|
Zerotorescue@0
|
333 lastAmount = 0;
|
|
Zerotorescue@0
|
334 self.debugChannel = nil;
|
|
Zerotorescue@0
|
335
|
|
Zerotorescue@0
|
336 -- If we were toggling this addon on while the mailbox is opened we must register all events again
|
|
Zerotorescue@0
|
337 if MailFrame:IsVisible() then
|
|
Zerotorescue@0
|
338 self:MAIL_SHOW();
|
|
Zerotorescue@0
|
339 end
|
|
Zerotorescue@0
|
340 end
|
|
Zerotorescue@0
|
341
|
|
Zerotorescue@0
|
342 function MailOpener:OnDisable()
|
|
Zerotorescue@0
|
343 self:UnregisterEvent("MAIL_SHOW");
|
|
Zerotorescue@0
|
344
|
|
Zerotorescue@0
|
345 self.btnConfig:Hide();
|
|
Zerotorescue@0
|
346
|
|
Zerotorescue@115
|
347 if originalCheckInbox then
|
|
Zerotorescue@115
|
348 -- Change checkinbox back to the original value
|
|
Zerotorescue@115
|
349 CheckInbox = originalCheckInbox;
|
|
Zerotorescue@115
|
350 -- Forget the other reference
|
|
Zerotorescue@115
|
351 originalCheckInbox = nil;
|
|
Zerotorescue@115
|
352 end
|
|
Zerotorescue@115
|
353
|
|
Zerotorescue@0
|
354 MailOpener:Stop();
|
|
Zerotorescue@0
|
355 end
|
|
Zerotorescue@0
|
356
|
|
Zerotorescue@0
|
357 -- We must disable Quick Auction's auto mail (if set up that way in the settings) before opening the mailbox or it will instantly start sending stuff
|
|
Zerotorescue@0
|
358 function MailOpener:PLAYER_ENTERING_WORLD()
|
|
Zerotorescue@0
|
359 self:UnregisterEvent("PLAYER_ENTERING_WORLD");
|
|
Zerotorescue@0
|
360
|
|
Zerotorescue@0
|
361 self:ToggleQAStatus();
|
|
Zerotorescue@0
|
362 end
|
|
Zerotorescue@0
|
363
|
|
Zerotorescue@0
|
364 -- Fired when the mailbox is opened
|
|
Zerotorescue@0
|
365 function MailOpener:MAIL_SHOW()
|
|
Zerotorescue@0
|
366 -- To stop the timer when the mailbox is closed
|
|
Zerotorescue@0
|
367 self:RegisterEvent("MAIL_CLOSED", "Stop");
|
|
Zerotorescue@0
|
368 self:RegisterEvent("PLAYER_LEAVING_WORLD", "Stop");
|
|
Zerotorescue@0
|
369
|
|
Zerotorescue@0
|
370 -- To set the timer for when to refresh again
|
|
Zerotorescue@0
|
371 self:RegisterEvent("MAIL_INBOX_UPDATE");
|
|
Zerotorescue@0
|
372
|
|
Zerotorescue@0
|
373 -- We need to know when opening has completed
|
|
Zerotorescue@0
|
374 self:RegisterMessage("MO_OPEN_COMPLETE");
|
|
Zerotorescue@0
|
375
|
|
Zerotorescue@19
|
376 if self.db.profile.uses == 0 and MailOpener.db.profile.general.defaultStatus ~= "_enabled" then
|
|
Zerotorescue@19
|
377 StaticPopupDialogs["MailOpenerFirstUseConfirmBox"] = {
|
|
Zerotorescue@68
|
378 text = L["You are using |cff15ff00Mail Opener|r for the first time. Do you wish to always |cf00ff000enable|r |cfffed000automatic mail opening when you open the mailbox|r?\n\nYou can always change the standard behavior in the General options."],
|
|
Zerotorescue@68
|
379 button1 = L["Yes"],
|
|
Zerotorescue@68
|
380 button2 = L["No"],
|
|
Zerotorescue@19
|
381 OnAccept = function()
|
|
Zerotorescue@19
|
382 MailOpener.db.profile.general.defaultStatus = "_enabled";
|
|
Zerotorescue@85
|
383 MailOpener:Print(L["You can always change the default status in the General config (|cff00ffff/mo c|r)."]);
|
|
Zerotorescue@19
|
384
|
|
Zerotorescue@85
|
385 MailOpener:Print(L["|cff00ff00Enabling|r automatic opening of mail."]);
|
|
Zerotorescue@19
|
386 MailOpener.cbOpenAll:SetChecked(true);
|
|
Zerotorescue@19
|
387
|
|
Zerotorescue@19
|
388 AutoOpenMail = true;
|
|
Zerotorescue@19
|
389 MailOpener:ScheduleOpen(false);
|
|
Zerotorescue@19
|
390 end,
|
|
Zerotorescue@91
|
391 OnCancel = function ()
|
|
Zerotorescue@85
|
392 MailOpener:Print(L["You can always change the default status in the General config (|cff00ffff/mo c|r)."]);
|
|
Zerotorescue@19
|
393 end,
|
|
Zerotorescue@19
|
394 timeout = 0,
|
|
Zerotorescue@19
|
395 whileDead = 1,
|
|
Zerotorescue@19
|
396 hideOnEscape = 1,
|
|
Zerotorescue@19
|
397 };
|
|
Zerotorescue@19
|
398 StaticPopup_Show("MailOpenerFirstUseConfirmBox");
|
|
Zerotorescue@8
|
399 end
|
|
Zerotorescue@8
|
400
|
|
Zerotorescue@8
|
401 self.db.profile.uses = ( self.db.profile.uses + 1 );
|
|
Zerotorescue@8
|
402
|
|
Zerotorescue@0
|
403 self:Debug("defaultStatus:" .. self.db.profile.general.defaultStatus);
|
|
Zerotorescue@0
|
404 -- Change the mail opening status according to our settings
|
|
Zerotorescue@0
|
405 if self.db.profile.general.defaultStatus == "_enabled" then
|
|
Zerotorescue@3
|
406 AutoOpenMail = true;
|
|
Zerotorescue@3
|
407 self.cbOpenAll:SetChecked(true);
|
|
Zerotorescue@3
|
408 elseif self.db.profile.general.defaultStatus == "disabled" then
|
|
Zerotorescue@3
|
409 -- Disable auto opening but leave mail opener enabled
|
|
Zerotorescue@3
|
410
|
|
Zerotorescue@3
|
411 AutoOpenMail = false;
|
|
Zerotorescue@3
|
412 self.cbOpenAll:SetChecked(false);
|
|
Zerotorescue@3
|
413 elseif self.db.profile.general.defaultStatus == "xdisabled" then
|
|
Zerotorescue@3
|
414 -- Disable entire addon
|
|
Zerotorescue@3
|
415
|
|
Zerotorescue@3
|
416 MailOpener:Disable();
|
|
Zerotorescue@3
|
417 self.cbOpenAll:SetChecked(false);
|
|
Zerotorescue@0
|
418 end
|
|
Zerotorescue@0
|
419
|
|
Zerotorescue@46
|
420 if IsShiftKeyDown() then
|
|
Zerotorescue@68
|
421 self:Print(L["|cffff0000Disabling|r automatic opening of mail, shift key was down when opening the mailbox."]);
|
|
Zerotorescue@46
|
422
|
|
Zerotorescue@46
|
423 AutoOpenMail = false;
|
|
Zerotorescue@46
|
424 self.cbOpenAll:SetChecked(false);
|
|
Zerotorescue@46
|
425 end
|
|
Zerotorescue@46
|
426
|
|
Zerotorescue@0
|
427 self:ToggleQAStatus();
|
|
Zerotorescue@0
|
428
|
|
Zerotorescue@0
|
429 -- Hide the InboxTooMuchMail warning to allow room for our mail remaining info line
|
|
Zerotorescue@0
|
430 InboxTooMuchMail:Hide()
|
|
Zerotorescue@0
|
431 InboxTooMuchMail.Show = function() end
|
|
Zerotorescue@0
|
432
|
|
Zerotorescue@118
|
433 if self.ZeroAuctionsEnabled then
|
|
Zerotorescue@118
|
434 local QAMail = LibStub("AceAddon-3.0"):GetAddon("ZeroAuctions", true):GetModule("Mail", true)
|
|
Zerotorescue@118
|
435
|
|
Zerotorescue@118
|
436 if QAMail then
|
|
Zerotorescue@118
|
437 -- Hide the open all button
|
|
Zerotorescue@118
|
438 QAMail.massOpening:Hide();
|
|
Zerotorescue@118
|
439 -- Hide the x mail remaining text
|
|
Zerotorescue@118
|
440 QAMail.totalMail:Hide();
|
|
Zerotorescue@8
|
441 end
|
|
Zerotorescue@0
|
442 end
|
|
Zerotorescue@0
|
443
|
|
Zerotorescue@108
|
444 hasOpenedMailAlready = nil;
|
|
Zerotorescue@0
|
445 mailboxEmptySoundPlayed = nil;
|
|
Zerotorescue@42
|
446 mailboxEmptySoundPlayedThisVisit = nil;
|
|
Zerotorescue@0
|
447
|
|
Zerotorescue@0
|
448 self:Recheck();
|
|
Zerotorescue@0
|
449
|
|
Zerotorescue@0
|
450 if self.db.profile.general.continueOpening then
|
|
Zerotorescue@6
|
451 -- Continue opening mail, but use the "initial mail opening interval" as time
|
|
Zerotorescue@6
|
452 self:ScheduleOpen(false);
|
|
Zerotorescue@0
|
453 end
|
|
Zerotorescue@0
|
454 end
|
|
Zerotorescue@0
|
455
|
|
Zerotorescue@0
|
456 -- Fired after a successful server sync
|
|
Zerotorescue@0
|
457 -- Fired when mail is deleted (which happens after taking all attachments from a mail sent by the game)
|
|
Zerotorescue@0
|
458 function MailOpener:MAIL_INBOX_UPDATE()
|
|
Zerotorescue@0
|
459 local current, total = GetInboxNumItems();
|
|
Zerotorescue@0
|
460
|
|
Zerotorescue@3
|
461 -- Calculate the amount of mail waiting that actually have attachments
|
|
Zerotorescue@3
|
462 -- If we just compare numbers we won't be including mail that isn't automatically deleted when opened, such as mail with attachments sent by other players
|
|
Zerotorescue@3
|
463 local currentMailWithAttachments = 0;
|
|
Zerotorescue@3
|
464 for i = 1, current do
|
|
Zerotorescue@3
|
465 local _, _, _, _, money, _, _, items = GetInboxHeaderInfo(i);
|
|
Zerotorescue@3
|
466
|
|
Zerotorescue@3
|
467 if (items and items > 0) or (money and money > 0) then
|
|
Zerotorescue@3
|
468 currentMailWithAttachments = currentMailWithAttachments + 1;
|
|
Zerotorescue@3
|
469 end
|
|
Zerotorescue@0
|
470 end
|
|
Zerotorescue@0
|
471
|
|
Zerotorescue@3
|
472 local tempLastAmount = lastAmount;
|
|
Zerotorescue@3
|
473 lastAmount = currentMailWithAttachments;
|
|
Zerotorescue@3
|
474
|
|
Zerotorescue@11
|
475 --if currentMailWithAttachments ~= tempLastAmount then
|
|
Zerotorescue@11
|
476 -- self:Debug("MAIL_INBOX_UPDATE - lastAmount:" .. tempLastAmount .. " - current:" .. currentMailWithAttachments);
|
|
Zerotorescue@11
|
477 --end
|
|
Zerotorescue@3
|
478
|
|
Zerotorescue@3
|
479 if currentMailWithAttachments > tempLastAmount then
|
|
Zerotorescue@0
|
480 -- New messages arrived in our mailbox, so this was a refresh, so set a timer
|
|
Zerotorescue@0
|
481
|
|
Zerotorescue@3
|
482 self:Debug("MO_SERVER_SYNCED");
|
|
Zerotorescue@3
|
483
|
|
Zerotorescue@0
|
484 -- Yell that we successfully synced with the server
|
|
Zerotorescue@0
|
485 self:SendMessage("MO_SERVER_SYNCED");
|
|
Zerotorescue@0
|
486
|
|
Zerotorescue@29
|
487 if MailAddonBusy == MailOpener:GetName() then
|
|
Zerotorescue@29
|
488 MailAddonBusy = nil;
|
|
Zerotorescue@29
|
489 end
|
|
Zerotorescue@29
|
490
|
|
Zerotorescue@0
|
491 -- This list is fresh
|
|
Zerotorescue@0
|
492 freshList = true;
|
|
Zerotorescue@0
|
493 mailboxEmptySoundPlayed = nil;
|
|
Zerotorescue@0
|
494
|
|
Zerotorescue@0
|
495 -- Stop previous timer
|
|
Zerotorescue@0
|
496 self:CancelTimer(self.tmrRecheck, true);
|
|
Zerotorescue@0
|
497 -- More will arrive in 60 seconds
|
|
Zerotorescue@0
|
498 self.tmrRecheck = self:ScheduleTimer(function()
|
|
Zerotorescue@0
|
499 self:Debug("tmrRecheck 61 finished");
|
|
Zerotorescue@0
|
500
|
|
Zerotorescue@0
|
501 -- We can get a fresh list now, so query the server
|
|
Zerotorescue@0
|
502 freshList = false;
|
|
Zerotorescue@0
|
503
|
|
Zerotorescue@0
|
504 -- Look for mail
|
|
Zerotorescue@0
|
505 self:Recheck();
|
|
Zerotorescue@0
|
506 end, 61);
|
|
Zerotorescue@0
|
507 self:Debug("tmrRecheck 61");
|
|
Zerotorescue@0
|
508
|
|
Zerotorescue@46
|
509 -- Open the current mail
|
|
Zerotorescue@46
|
510 self:ScheduleOpen(false);
|
|
Zerotorescue@3
|
511 elseif currentMailWithAttachments < tempLastAmount then
|
|
Zerotorescue@2
|
512 -- We lost a mail
|
|
Zerotorescue@2
|
513
|
|
Zerotorescue@19
|
514 --TODO: NYI: May need to delay this until the mail is actually deleted to keep the mail count more realtime
|
|
Zerotorescue@3
|
515
|
|
Zerotorescue@3
|
516 self:Debug("MO_MAIL_EMPTIED");
|
|
Zerotorescue@3
|
517
|
|
Zerotorescue@2
|
518 -- Yell that we successfully opened/removed a mail
|
|
Zerotorescue@3
|
519 self:SendMessage("MO_MAIL_EMPTIED");
|
|
Zerotorescue@3
|
520 elseif (currentMailWithAttachments == 50 and tempLastAmount == 50) then
|
|
Zerotorescue@46
|
521 -- Open the current mail
|
|
Zerotorescue@46
|
522 self:ScheduleOpen(false);
|
|
Zerotorescue@0
|
523 end
|
|
Zerotorescue@0
|
524 end
|
|
Zerotorescue@0
|
525
|
|
Zerotorescue@0
|
526 function MailOpener:ScheduleOpen(continued)
|
|
Zerotorescue@0
|
527 if lastAmount > 0 then
|
|
Zerotorescue@0
|
528 local waitTime;
|
|
Zerotorescue@0
|
529 if continued then
|
|
Zerotorescue@0
|
530 waitTime = self.db.profile.general.waitTime;
|
|
Zerotorescue@0
|
531 else
|
|
Zerotorescue@0
|
532 -- Even though this is not a continuation and should be instant, we set a .5 second timer to prevent multiple calls of the OpenNow function
|
|
Zerotorescue@0
|
533 waitTime = self.db.profile.general.initialDelay;
|
|
Zerotorescue@0
|
534 end
|
|
Zerotorescue@0
|
535
|
|
Zerotorescue@0
|
536 -- Stop previous timer
|
|
Zerotorescue@0
|
537 self:CancelTimer(self.tmrOpenNow, true);
|
|
Zerotorescue@0
|
538 -- Schedule the next open
|
|
Zerotorescue@0
|
539 self.tmrOpenNow = self:ScheduleTimer("OpenNow", waitTime);
|
|
Zerotorescue@0
|
540 end
|
|
Zerotorescue@0
|
541 end
|
|
Zerotorescue@0
|
542
|
|
Zerotorescue@0
|
543 function MailOpener:OpenNow()
|
|
Zerotorescue@8
|
544 self:Debug("OpenNow (" .. ((MailAddonBusy and "1") or "0") .. ")");
|
|
Zerotorescue@8
|
545 if MailFrame:IsVisible() and AutoOpenMail then
|
|
Zerotorescue@0
|
546 self:Debug("OpenNow");
|
|
Zerotorescue@0
|
547
|
|
Zerotorescue@0
|
548 -- BeanCounter is the only addon hiding the mail close button while busy, so we can look for that
|
|
Zerotorescue@31
|
549 --local BeanCounterActive = not InboxCloseButton:IsVisible();
|
|
Zerotorescue@0
|
550
|
|
Zerotorescue@31
|
551 --if not BeanCounterActive and not MailAddonBusy then
|
|
Zerotorescue@31
|
552 if not MailAddonBusy then
|
|
Zerotorescue@8
|
553 -- No other addon is currently active
|
|
Zerotorescue@0
|
554
|
|
Zerotorescue@0
|
555 self:CancelTimer(self.tmrTryAgain, true); -- Insurance
|
|
Zerotorescue@0
|
556
|
|
Zerotorescue@118
|
557 if self.ZeroAuctionsEnabled and ZeroAuctionsAutoMail then
|
|
Zerotorescue@118
|
558 -- Remember the last known quick auctions status
|
|
Zerotorescue@118
|
559 lastQuickAuctionsStatus = ZeroAuctionsAutoMail:GetChecked();
|
|
Zerotorescue@118
|
560 end
|
|
Zerotorescue@118
|
561 if self.db.profile.general.autoDisableQAAutoMail and self.ZeroAuctionsEnabled and ZeroAuctionsAutoMail and ZeroAuctionsAutoMail:GetChecked() then
|
|
Zerotorescue@118
|
562 -- If auto disable "QA Auto mail" is enabled and QA's auto mail is currently toggled on, turn it off
|
|
Zerotorescue@118
|
563 -- We need to do this with a :click to trigger the right events
|
|
Zerotorescue@118
|
564
|
|
Zerotorescue@118
|
565 self:Debug("Turning automail |cffff0000off|r.");
|
|
Zerotorescue@118
|
566
|
|
Zerotorescue@118
|
567 ZeroAuctionsAutoMail:Click();
|
|
Zerotorescue@118
|
568 end
|
|
Zerotorescue@118
|
569
|
|
Zerotorescue@0
|
570
|
|
Zerotorescue@8
|
571 MailAddonBusy = self:GetName();
|
|
Zerotorescue@0
|
572
|
|
Zerotorescue@0
|
573 self:Debug("MO_OPEN_MAIL");
|
|
Zerotorescue@0
|
574
|
|
Zerotorescue@0
|
575 -- Summon the mail opening gods
|
|
Zerotorescue@0
|
576 self:SendMessage("MO_OPEN_MAIL");
|
|
Zerotorescue@129
|
577 elseif MailAddonBusy ~= self:GetName() then
|
|
Zerotorescue@8
|
578 -- Another addon is ACTIVE
|
|
Zerotorescue@31
|
579 self:Debug("Another addon active, waiting .5 seconds... (" .. MailAddonBusy .. ")");
|
|
Zerotorescue@0
|
580
|
|
Zerotorescue@0
|
581 self:CancelTimer(self.tmrTryAgain, true); -- Insurance
|
|
Zerotorescue@8
|
582 -- Try again every 0.5 seconds
|
|
Zerotorescue@0
|
583 self.tmrTryAgain = self:ScheduleTimer("OpenNow", 0.5);
|
|
Zerotorescue@0
|
584 end
|
|
Zerotorescue@0
|
585 end
|
|
Zerotorescue@0
|
586 end
|
|
Zerotorescue@0
|
587
|
|
Zerotorescue@0
|
588 function MailOpener:MO_OPEN_COMPLETE()
|
|
Zerotorescue@8
|
589 if MailAddonBusy == self:GetName() then
|
|
Zerotorescue@8
|
590 MailAddonBusy = nil;
|
|
Zerotorescue@8
|
591 end
|
|
Zerotorescue@1
|
592
|
|
Zerotorescue@108
|
593 hasOpenedMailAlready = true;
|
|
Zerotorescue@108
|
594
|
|
Zerotorescue@1
|
595 -- Try a recheck
|
|
Zerotorescue@1
|
596 self:Recheck();
|
|
Zerotorescue@1
|
597
|
|
Zerotorescue@0
|
598 local current, total = GetInboxNumItems();
|
|
Zerotorescue@0
|
599
|
|
Zerotorescue@0
|
600 if (total - current) == 0 then
|
|
Zerotorescue@3
|
601 -- There is probably no unopenable mail remaining, so play the sound (if enabled)
|
|
Zerotorescue@3
|
602
|
|
Zerotorescue@42
|
603 if self.db.profile.notifications.mailboxEmptySound and (not MailOpener.db.profile.notifications.mailboxEmptySoundOnlyOnce or not mailboxEmptySoundPlayed) and (not MailOpener.db.profile.notifications.mailboxEmptySoundOnlyOncePerMailboxVisit or not mailboxEmptySoundPlayedThisVisit) then
|
|
Zerotorescue@0
|
604 PlaySoundFile(self.db.profile.notifications.mailboxEmptySoundFile);
|
|
Zerotorescue@0
|
605 mailboxEmptySoundPlayed = true;
|
|
Zerotorescue@42
|
606 mailboxEmptySoundPlayedThisVisit = true;
|
|
Zerotorescue@0
|
607 end
|
|
Zerotorescue@0
|
608 end
|
|
Zerotorescue@0
|
609
|
|
Zerotorescue@118
|
610 if self.ZeroAuctionsEnabled then
|
|
Zerotorescue@118
|
611 -- Zero Auctions enabled?
|
|
Zerotorescue@118
|
612 -- Toggle automailing as per settings
|
|
Zerotorescue@118
|
613
|
|
Zerotorescue@118
|
614 if self.db.profile.general.autoReenableQAAutoMail and ZeroAuctionsAutoMail and not ZeroAuctionsAutoMail:GetChecked() then
|
|
Zerotorescue@118
|
615 -- If auto re-enable "QA Auto mail" is enabled and QA's auto mail is currently toggled OFF, turn it on
|
|
Zerotorescue@118
|
616 -- We need to do this with a :click to trigger the right events
|
|
Zerotorescue@118
|
617
|
|
Zerotorescue@118
|
618 self:Debug("Turning automail |cff00ff00on|r.");
|
|
Zerotorescue@118
|
619
|
|
Zerotorescue@118
|
620 ZeroAuctionsAutoMail:Click();
|
|
Zerotorescue@118
|
621 elseif self.db.profile.general.autoSetBackQAAutoMail and ZeroAuctionsAutoMail and lastQuickAuctionsStatus ~= ZeroAuctionsAutoMail:GetChecked() then
|
|
Zerotorescue@118
|
622 -- If auto set back "QA Auto mail" is enabled and QA's auto mail is currently not the same as it was before starting, toggle it
|
|
Zerotorescue@118
|
623 -- We need to do this with a :click to trigger the right events
|
|
Zerotorescue@118
|
624
|
|
Zerotorescue@118
|
625 if lastQuickAuctionsStatus then
|
|
Zerotorescue@118
|
626 self:Debug("Turning automail |cff00ff00on|r.");
|
|
Zerotorescue@118
|
627 else
|
|
Zerotorescue@118
|
628 self:Debug("Turning automail |cffff0000off|r.");
|
|
Zerotorescue@118
|
629 end
|
|
Zerotorescue@118
|
630
|
|
Zerotorescue@118
|
631 ZeroAuctionsAutoMail:Click();
|
|
Zerotorescue@118
|
632 end
|
|
Zerotorescue@118
|
633 end
|
|
Zerotorescue@118
|
634
|
|
Zerotorescue@0
|
635 if self.db.profile.general.continueOpening then
|
|
Zerotorescue@0
|
636 self:ScheduleOpen(true);
|
|
Zerotorescue@0
|
637 end
|
|
Zerotorescue@0
|
638 end
|
|
Zerotorescue@0
|
639
|
|
Zerotorescue@0
|
640 -- Run another CheckInbox
|
|
Zerotorescue@0
|
641 function MailOpener:Recheck()
|
|
Zerotorescue@0
|
642 self:Debug("|cffffff00Recheck|r");
|
|
Zerotorescue@0
|
643
|
|
Zerotorescue@0
|
644 -- Freshlist prevents this from being run too often
|
|
Zerotorescue@0
|
645 -- It is set to true after a server sync
|
|
Zerotorescue@0
|
646 -- and set to false 61 seconds afterwards with a recheck called instantly after it
|
|
Zerotorescue@3
|
647
|
|
Zerotorescue@3
|
648 -- We're not refreshing while we're opening because it is automatically done when current batch was completely opened
|
|
Zerotorescue@8
|
649 if not freshList and MailFrame:IsVisible() then
|
|
Zerotorescue@0
|
650 self:Debug("|cff00ff00Recheck|r");
|
|
Zerotorescue@0
|
651
|
|
Zerotorescue@0
|
652 -- If this isn't a fresh list (so messages weren't received within the last 60 seconds) and the mailbox wasn't closed
|
|
Zerotorescue@0
|
653
|
|
Zerotorescue@0
|
654 -- BeanCounter is the only addon hiding the mail close button while busy, so we can look for that
|
|
Zerotorescue@31
|
655 --local BeanCounterActive = not InboxCloseButton:IsVisible();
|
|
Zerotorescue@0
|
656
|
|
Zerotorescue@31
|
657 --if not BeanCounterActive and AutoOpenMail and not MailAddonBusy then
|
|
Zerotorescue@31
|
658 if AutoOpenMail and not MailAddonBusy then
|
|
Zerotorescue@0
|
659 -- Query the server
|
|
Zerotorescue@0
|
660 CheckInbox();
|
|
Zerotorescue@0
|
661 end
|
|
Zerotorescue@0
|
662
|
|
Zerotorescue@0
|
663 -- Stop previous timer
|
|
Zerotorescue@0
|
664 self:CancelTimer(self.tmrRecheck, true);
|
|
Zerotorescue@0
|
665 -- Keep trying until it works
|
|
Zerotorescue@0
|
666 self.tmrRecheck = self:ScheduleTimer("Recheck", 2);
|
|
Zerotorescue@0
|
667
|
|
Zerotorescue@0
|
668 self:Debug("tmrRecheck 2");
|
|
Zerotorescue@0
|
669 end
|
|
Zerotorescue@0
|
670 end
|
|
Zerotorescue@0
|
671
|
|
Zerotorescue@0
|
672 -- Stop checking for new mail and unregister the events we needed
|
|
Zerotorescue@0
|
673 function MailOpener:Stop()
|
|
Zerotorescue@8
|
674 if MailAddonBusy == self:GetName() then
|
|
Zerotorescue@8
|
675 MailAddonBusy = nil;
|
|
Zerotorescue@8
|
676 end
|
|
Zerotorescue@0
|
677
|
|
Zerotorescue@108
|
678 hasOpenedMailAlready = nil;
|
|
Zerotorescue@108
|
679
|
|
Zerotorescue@0
|
680 -- We won't need this anymore
|
|
Zerotorescue@0
|
681 self:UnregisterEvent("MAIL_CLOSED");
|
|
Zerotorescue@0
|
682 self:UnregisterEvent("PLAYER_LEAVING_WORLD");
|
|
Zerotorescue@0
|
683 self:UnregisterEvent("MAIL_INBOX_UPDATE");
|
|
Zerotorescue@0
|
684
|
|
Zerotorescue@0
|
685 -- Messages
|
|
Zerotorescue@0
|
686 self:UnregisterMessage("MO_OPEN_COMPLETE");
|
|
Zerotorescue@0
|
687
|
|
Zerotorescue@0
|
688 -- Timers
|
|
Zerotorescue@0
|
689 self:CancelTimer(self.tmrTryAgain, true);
|
|
Zerotorescue@0
|
690 self:CancelTimer(self.tmrOpenNow, true);
|
|
Zerotorescue@0
|
691
|
|
Zerotorescue@0
|
692 -- If we wait with disabling QA automail until MAIL_SHOW, QA will beat us to it and already start sending stuff
|
|
Zerotorescue@0
|
693 self:ToggleQAStatus();
|
|
Zerotorescue@0
|
694 end
|
|
Zerotorescue@0
|
695
|
|
Zerotorescue@0
|
696 function MailOpener:Debug(t)
|
|
Zerotorescue@0
|
697 if not self.debugChannel and self.debugChannel ~= false then
|
|
Zerotorescue@0
|
698 -- We want to check just once, so if you add a debug channel later just do a /reload (registering an event for this is wasted resources)
|
|
Zerotorescue@0
|
699 self.debugChannel = false;
|
|
Zerotorescue@0
|
700
|
|
Zerotorescue@0
|
701 for i = 1, NUM_CHAT_WINDOWS do
|
|
Zerotorescue@0
|
702 local name = GetChatWindowInfo(i);
|
|
Zerotorescue@0
|
703
|
|
Zerotorescue@0
|
704 if name:upper() == "DEBUG" then
|
|
Zerotorescue@0
|
705 self.debugChannel = _G["ChatFrame" .. i];
|
|
Zerotorescue@0
|
706 end
|
|
Zerotorescue@0
|
707 end
|
|
Zerotorescue@0
|
708 end
|
|
Zerotorescue@0
|
709
|
|
Zerotorescue@0
|
710 if self.debugChannel then
|
|
Zerotorescue@0
|
711 self.debugChannel:AddMessage(t);
|
|
Zerotorescue@0
|
712 end
|
|
Zerotorescue@0
|
713 end
|
|
Zerotorescue@0
|
714
|
|
Zerotorescue@68
|
715 function MailOpener:Print(text)
|
|
Zerotorescue@68
|
716 print(L["|cff15ff00Mail Opener|r: %s"]:format(text));
|
|
Zerotorescue@68
|
717 end
|
|
Zerotorescue@68
|
718
|
|
Zerotorescue@0
|
719 -- Enable our config module if it's disabled and make a reference to it
|
|
Zerotorescue@0
|
720 function MailOpener:EnableConfigModule()
|
|
Zerotorescue@0
|
721 if not MailOpenerConfig then
|
|
Zerotorescue@0
|
722 MailOpenerConfig = self:GetModule("Config");
|
|
Zerotorescue@0
|
723 MailOpenerConfig:Enable();
|
|
Zerotorescue@0
|
724 end
|
|
Zerotorescue@0
|
725 end
|
|
Zerotorescue@0
|
726
|
|
Zerotorescue@0
|
727 -- Toggle Postal's opening modules on or off
|
|
Zerotorescue@0
|
728 function MailOpener:TogglePostalModule(name, status)
|
|
Zerotorescue@60
|
729 if self.PostalEnabled and Postal then
|
|
Zerotorescue@0
|
730 -- Postal must be enabled
|
|
Zerotorescue@0
|
731
|
|
Zerotorescue@3
|
732 -- Toggle module (let Postal handle this)
|
|
Zerotorescue@3
|
733 Postal.ToggleModule(nil, name, Postal:GetModule(name), status);
|
|
Zerotorescue@0
|
734 end
|
|
Zerotorescue@0
|
735 end
|
|
Zerotorescue@0
|
736
|
|
Zerotorescue@0
|
737 -- Change Quick Auction's auto mail status based on our prefered settings
|
|
Zerotorescue@0
|
738 function MailOpener:ToggleQAStatus()
|
|
Zerotorescue@0
|
739 self:Debug("defaultQAStatus:" .. self.db.profile.general.defaultQAStatus);
|
|
Zerotorescue@0
|
740
|
|
Zerotorescue@118
|
741 if self.ZeroAuctionsEnabled and self.db.profile.general.defaultQAStatus ~= "__remember" and ZeroAuctionsAutoMail then
|
|
Zerotorescue@118
|
742 if self.db.profile.general.defaultQAStatus == "_enabled" and not ZeroAuctionsAutoMail:GetChecked() then
|
|
Zerotorescue@118
|
743 self:Debug("Turning automail |cff00ff00on|r.");
|
|
Zerotorescue@118
|
744
|
|
Zerotorescue@118
|
745 ZeroAuctionsAutoMail:Click();
|
|
Zerotorescue@118
|
746 elseif self.db.profile.general.defaultQAStatus == "disabled" and ZeroAuctionsAutoMail:GetChecked() then
|
|
Zerotorescue@118
|
747 self:Debug("Turning automail |cffff0000off|r.");
|
|
Zerotorescue@118
|
748
|
|
Zerotorescue@118
|
749 ZeroAuctionsAutoMail:Click();
|
|
Zerotorescue@118
|
750 end
|
|
Zerotorescue@118
|
751 end
|
|
Zerotorescue@0
|
752 end
|
|
Zerotorescue@0
|
753
|
|
Zerotorescue@0
|
754 function MailOpener:FormatMoney(copper)
|
|
Zerotorescue@0
|
755 local gold = floor( copper / 10000 );
|
|
Zerotorescue@0
|
756 local silver = floor( ( copper - ( gold * 10000 ) ) / 100 );
|
|
Zerotorescue@0
|
757 local copper = mod(copper, 100);
|
|
Zerotorescue@0
|
758
|
|
Zerotorescue@0
|
759 if gold > 0 then
|
|
Zerotorescue@0
|
760 return format(GOLD_AMOUNT_TEXTURE .. " " .. SILVER_AMOUNT_TEXTURE .. " " .. COPPER_AMOUNT_TEXTURE, gold, 0, 0, silver, 0, 0, copper, 0, 0);
|
|
Zerotorescue@0
|
761 elseif silver > 0 then
|
|
Zerotorescue@0
|
762 return format(SILVER_AMOUNT_TEXTURE .. " " .. COPPER_AMOUNT_TEXTURE, silver, 0, 0, copper, 0, 0);
|
|
Zerotorescue@0
|
763 else
|
|
Zerotorescue@0
|
764 return format(COPPER_AMOUNT_TEXTURE, copper, 0, 0);
|
|
Zerotorescue@0
|
765 end
|
|
Zerotorescue@0
|
766 end
|
|
Zerotorescue@0
|
767
|
|
Zerotorescue@7
|
768 -- General copy window for multiple things (clickable URLs, the time remaining, and such)
|
|
Zerotorescue@0
|
769 StaticPopupDialogs["MailOpenerCopyWindow"] = {
|
|
Zerotorescue@68
|
770 text = L["Press CTRL-C to copy."],
|
|
Zerotorescue@0
|
771 button2 = CLOSE,
|
|
Zerotorescue@0
|
772 hasEditBox = 1,
|
|
Zerotorescue@123
|
773 editBoxWidth = 360,
|
|
Zerotorescue@123
|
774 OnShow = function(self)
|
|
Zerotorescue@123
|
775 if self.editBox and MailOpener.currentPopupContents then
|
|
Zerotorescue@123
|
776 self.editBox:SetText(MailOpener.currentPopupContents);
|
|
Zerotorescue@123
|
777 self.editBox:SetFocus();
|
|
Zerotorescue@123
|
778 self.editBox:HighlightText(0);
|
|
Zerotorescue@0
|
779 end
|
|
Zerotorescue@0
|
780
|
|
Zerotorescue@0
|
781 -- Position the close button in the middle
|
|
Zerotorescue@123
|
782 if self.button2 then
|
|
Zerotorescue@0
|
783 -- Remove previous know position
|
|
Zerotorescue@123
|
784 self.button2:ClearAllPoints();
|
|
Zerotorescue@123
|
785 self.button2:SetWidth(200);
|
|
Zerotorescue@0
|
786 -- Reposition in the center
|
|
Zerotorescue@123
|
787 self.button2:SetPoint("CENTER", self.editBox, "CENTER", 0, -30);
|
|
Zerotorescue@0
|
788 end
|
|
Zerotorescue@0
|
789 end,
|
|
Zerotorescue@92
|
790 EditBoxOnEscapePressed = function(self)
|
|
Zerotorescue@92
|
791 self:GetParent():Hide();
|
|
Zerotorescue@0
|
792 end,
|
|
Zerotorescue@0
|
793 timeout = 0,
|
|
Zerotorescue@0
|
794 whileDead = 1,
|
|
Zerotorescue@0
|
795 hideOnEscape = 1,
|
|
Zerotorescue@0
|
796 maxLetters = 1024,
|
|
Zerotorescue@1
|
797 };
|
|
Zerotorescue@1
|
798
|
|
Zerotorescue@0
|
799
|
|
Zerotorescue@108
|
800 -- The idea for this is to wait with refresing while there is still mail remaining which can be opened
|
|
Zerotorescue@108
|
801 -- This should speed things up a tiny bit, but might become buggy if coded wrong
|
|
Zerotorescue@115
|
802 -- We actually override the function in the onenable
|
|
Zerotorescue@115
|
803 function NewCheckInbox(...)
|
|
Zerotorescue@108
|
804 if not MailOpener.db.profile.general.overrideCheckInbox or not MailOpener.db.profile.general.continueOpening or lastAmount == 0 then
|
|
Zerotorescue@108
|
805 -- If the override Check Inbox option is off
|
|
Zerotorescue@108
|
806 -- or continuous opening is off
|
|
Zerotorescue@108
|
807 -- or there's currently no mail visible
|
|
Zerotorescue@0
|
808
|
|
Zerotorescue@115
|
809 MailOpener:Debug("CheckInbox:" .. tostring((not MailOpener.db.profile.general.overrideCheckInbox)) .. "/" .. tostring((not MailOpener.db.profile.general.continueOpening)) .. "/" .. tostring(lastAmount == 0));
|
|
Zerotorescue@0
|
810
|
|
Zerotorescue@108
|
811 -- Just call the original function
|
|
Zerotorescue@108
|
812 return originalCheckInbox(...);
|
|
Zerotorescue@0
|
813 end
|
|
Zerotorescue@0
|
814
|
|
Zerotorescue@108
|
815 if not hasOpenedMailAlready then
|
|
Zerotorescue@108
|
816 -- If MO hasn't opened mail yet, we wait.
|
|
Zerotorescue@108
|
817 -- MO will call this function when mail opening is done
|
|
Zerotorescue@0
|
818
|
|
Zerotorescue@108
|
819 MailOpener:Debug("CheckInbox:Waiting...");
|
|
Zerotorescue@0
|
820
|
|
Zerotorescue@108
|
821 return false;
|
|
Zerotorescue@108
|
822 else
|
|
Zerotorescue@108
|
823 MailOpener:Debug("CheckInbox:Refresh!");
|
|
Zerotorescue@108
|
824
|
|
Zerotorescue@108
|
825 return originalCheckInbox(...);
|
|
Zerotorescue@108
|
826 end
|
|
Zerotorescue@108
|
827 end |