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