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