Mercurial > wow > mailopener
comparison Core.lua @ 0:823e33465b6e
Initial commit
| author | Zerotorescue |
|---|---|
| date | Fri, 03 Sep 2010 12:43:36 +0200 |
| parents | |
| children | 6f17035de058 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:823e33465b6e |
|---|---|
| 1 MailOpener = LibStub("AceAddon-3.0"):NewAddon("MailOpener", "AceEvent-3.0", "AceTimer-3.0"); | |
| 2 | |
| 3 local enabled = true; | |
| 4 local MailOpenerConfig, lastAmount, lastQuickAuctionsStatus, opening, freshList, mailboxEmptySoundPlayed; | |
| 5 | |
| 6 function MailOpener:OnInitialize() | |
| 7 local defaults = { | |
| 8 global = { | |
| 9 uses = 0; | |
| 10 }, | |
| 11 profile = { | |
| 12 general = { | |
| 13 defaultStatus = "_enabled", | |
| 14 defaultQAStatus = "__remember", | |
| 15 continueOpeningStackableItems = false, | |
| 16 autoDisableQAAutoMail = true, | |
| 17 autoReenableQAAutoMail = false, | |
| 18 autoSetBackQAAutoMail = true, | |
| 19 continueOpening = false, | |
| 20 waitTime = 5, | |
| 21 initialDelay = 0.5, | |
| 22 }, | |
| 23 modules = { | |
| 24 Collected = true, | |
| 25 }, | |
| 26 notifications = { | |
| 27 welcome = true, | |
| 28 bye = true, | |
| 29 finishedCurrentBatch = true, | |
| 30 mailboxIsEmpty = true, | |
| 31 | |
| 32 skipped = { | |
| 33 all = true, | |
| 34 inventoryFull = true, | |
| 35 keepFreeSpaceLimit = true, | |
| 36 GMMail = true, | |
| 37 COD = true, | |
| 38 normalGoldMail = true, | |
| 39 normalItemsMail = true, | |
| 40 AHexpired = true, | |
| 41 AHsuccess = true, | |
| 42 AHwon = true, | |
| 43 AHcanceled = true, | |
| 44 AHoutbid = true, | |
| 45 other = true, | |
| 46 }, | |
| 47 processed = { | |
| 48 all = true, | |
| 49 normalGoldMail = true, | |
| 50 normalItemsMail = true, | |
| 51 AHexpired = true, | |
| 52 AHsuccess = true, | |
| 53 AHwon = true, | |
| 54 AHcanceled = true, | |
| 55 AHoutbid = true, | |
| 56 other = true, | |
| 57 }, | |
| 58 | |
| 59 bagsFullSound = false, | |
| 60 bagsFullSoundFile = "Sound\\Spells\\SimonGame_Visual_BadPress.wav", | |
| 61 bagsFullSoundFileName = "Simon Error", | |
| 62 bagsFullSoundOnlyOnce = true, | |
| 63 mailboxEmptySound = false, | |
| 64 mailboxEmptySoundFile = "Sound\\Spells\\SimonGame_Visual_GameStart.wav", | |
| 65 mailboxEmptySoundFileName = "Simon Start", | |
| 66 mailboxEmptySoundOnlyOnce = true, | |
| 67 }, | |
| 68 }, | |
| 69 }; | |
| 70 | |
| 71 -- Register our saved variables database | |
| 72 self.db = LibStub("AceDB-3.0"):New("MailOpenerDB", defaults, true); | |
| 73 | |
| 74 -- Set these as object variables so we can use them in our modules | |
| 75 if select(6, GetAddOnInfo("Postal")) == nil then | |
| 76 self.PostalEnabled = true; | |
| 77 | |
| 78 -- Ensure this addon is loaded if AddonLoader is installed | |
| 79 if AddonLoader and AddonLoader.LoadAddOn and not Postal then | |
| 80 AddonLoader:LoadAddOn("Postal"); | |
| 81 end | |
| 82 end | |
| 83 | |
| 84 if select(6, GetAddOnInfo("QuickAuctions")) == nil then | |
| 85 self.QuickAuctionsEnabled = true; | |
| 86 | |
| 87 -- Ensure this addon is loaded if AddonLoader is installed | |
| 88 if AddonLoader and AddonLoader.LoadAddOn then | |
| 89 AddonLoader:LoadAddOn("QuickAuctions"); | |
| 90 end | |
| 91 end | |
| 92 | |
| 93 -- Don't enable the config module until we need it | |
| 94 for name, module in self:IterateModules() do | |
| 95 if name == "Config" then | |
| 96 module:SetEnabledState(false); | |
| 97 elseif self.db.profile.modules[name] ~= nil then | |
| 98 if self.db.profile.modules[name] then | |
| 99 self:Debug("|cff00ff00Enabling|r module: " .. name); | |
| 100 else | |
| 101 self:Debug("|cffff0000Disabling|r module: " .. name); | |
| 102 end | |
| 103 | |
| 104 module:SetEnabledState(self.db.profile.modules[name]); | |
| 105 end | |
| 106 end | |
| 107 | |
| 108 -- Make the open all checkbox | |
| 109 local check = CreateFrame("CheckButton", "cbMailOpenerEnable", MailFrame, "ChatConfigCheckButtonTemplate"); | |
| 110 check:SetHeight(26); | |
| 111 check:SetWidth(26); | |
| 112 check:SetChecked(enabled); | |
| 113 check:SetHitRectInsets(0, -80, 0, 0); | |
| 114 check:SetScript("OnClick", function(self) | |
| 115 if self:GetChecked() then | |
| 116 MailOpener:Enable(); | |
| 117 else | |
| 118 MailOpener:Disable(); | |
| 119 end | |
| 120 end); | |
| 121 check.tooltip = "Toggle Mail Opener on or off."; | |
| 122 check:SetPoint("TOPLEFT", MailFrame, "TOPLEFT", 68, -13) | |
| 123 | |
| 124 if self.QuickAuctionsEnabled then | |
| 125 -- QA is enabled so move the checkbox further to the right | |
| 126 | |
| 127 check:SetPoint("TOPLEFT", MailFrame, "TOPLEFT", 155, -13); | |
| 128 end | |
| 129 | |
| 130 -- Get reference to the text field | |
| 131 local checkboxText = _G[check:GetName() .. "Text"]; | |
| 132 checkboxText:SetText("Mail Opener"); | |
| 133 -- We like this color more | |
| 134 checkboxText:SetTextColor(1, 0.8, 0, 1); | |
| 135 | |
| 136 self.cbOpenAll = check; | |
| 137 | |
| 138 -- Make the config button | |
| 139 local button = CreateFrame("Button", "btnMailOpenerConfig", MailFrame, "UIPanelButtonTemplate") | |
| 140 button:SetText("Config") | |
| 141 button:SetHeight(23) | |
| 142 button:SetWidth(55) | |
| 143 if self.PostalEnabled then | |
| 144 button:SetPoint("TOPRIGHT", MailFrame, "TOPRIGHT", -75, -13); | |
| 145 else | |
| 146 button:SetPoint("TOPRIGHT", MailFrame, "TOPRIGHT", -55, -13); | |
| 147 end | |
| 148 button:SetScript("OnClick", function() | |
| 149 MailOpener:EnableConfigModule(); | |
| 150 | |
| 151 MailOpenerConfig:Show(); | |
| 152 | |
| 153 if MailOpener.db.global.uses >= 15 then | |
| 154 MailOpener:ShowBetaPopup(); | |
| 155 end | |
| 156 end); | |
| 157 | |
| 158 self.btnConfig = button; | |
| 159 | |
| 160 -- Disable the AddonLoader slash commands | |
| 161 SLASH_MO1 = nil; | |
| 162 SLASH_MAILOPEN1 = nil; | |
| 163 SLASH_MAILOPENER1 = nil; | |
| 164 | |
| 165 -- Register our own slash commands | |
| 166 SLASH_MAILOPENER1 = "/mo"; | |
| 167 SLASH_MAILOPENER2 = "/mailopen"; | |
| 168 SLASH_MAILOPENER3 = "/mailopener"; | |
| 169 SlashCmdList["MAILOPENER"] = function(msg) | |
| 170 MailOpener:EnableConfigModule(); | |
| 171 | |
| 172 MailOpenerConfig:CommandHandler(msg); | |
| 173 end | |
| 174 | |
| 175 -- Attempt to remove the interface options added by AddonLoader (if enabled) | |
| 176 if AddonLoader and AddonLoader.RemoveInterfaceOptions then | |
| 177 AddonLoader:RemoveInterfaceOptions("Mail Opener"); | |
| 178 end | |
| 179 | |
| 180 -- Now create our own options frame | |
| 181 local frame = CreateFrame("Frame", nil, UIParent); | |
| 182 frame:Hide(); | |
| 183 frame.name = "Mail Opener"; | |
| 184 frame:HookScript("OnShow", function(self) | |
| 185 -- Enable the config module | |
| 186 MailOpener:EnableConfigModule(); | |
| 187 | |
| 188 -- Load the options and add it to the blizzard interface list | |
| 189 MailOpenerConfig:Load(); | |
| 190 | |
| 191 -- Refresh the frame to instantly show the right options | |
| 192 InterfaceOptionsFrame_OpenToCategory(self.name) | |
| 193 end); | |
| 194 -- And add it to the interface options | |
| 195 InterfaceOptions_AddCategory(frame); | |
| 196 | |
| 197 -- If the above becomes impossible this is another way to load the config module when required due to Interface/AddOns options | |
| 198 --InterfaceOptionsFrameTab2:HookScript("OnClick", function() | |
| 199 -- -- Load the config module | |
| 200 -- MailOpener:EnableConfigModule(); | |
| 201 | |
| 202 -- -- Load the options and add it to the blizzard interface list | |
| 203 -- MailOpenerConfig:Load(); | |
| 204 --end); | |
| 205 end | |
| 206 | |
| 207 function MailOpener:OnEnable() | |
| 208 self:RegisterEvent("MAIL_SHOW"); | |
| 209 self:RegisterEvent("PLAYER_ENTERING_WORLD"); | |
| 210 | |
| 211 self.btnConfig:Show(); | |
| 212 | |
| 213 -- Reset variables | |
| 214 lastAmount = 0; | |
| 215 self.debugChannel = nil; | |
| 216 | |
| 217 self.db.global.uses = ( self.db.global.uses + 1 ); | |
| 218 | |
| 219 if self.db.global.uses == 15 then | |
| 220 self:ShowBetaPopup(); | |
| 221 end | |
| 222 | |
| 223 -- If we were toggling this addon on while the mailbox is opened we must register all events again | |
| 224 if MailFrame:IsVisible() then | |
| 225 self:MAIL_SHOW(); | |
| 226 end | |
| 227 end | |
| 228 | |
| 229 function MailOpener:OnDisable() | |
| 230 self:UnregisterEvent("MAIL_SHOW"); | |
| 231 | |
| 232 self.btnConfig:Hide(); | |
| 233 | |
| 234 enabled = false; | |
| 235 MailOpener:Stop(); | |
| 236 end | |
| 237 | |
| 238 -- 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 | |
| 239 function MailOpener:PLAYER_ENTERING_WORLD() | |
| 240 self:UnregisterEvent("PLAYER_ENTERING_WORLD"); | |
| 241 | |
| 242 self:ToggleQAStatus(); | |
| 243 end | |
| 244 | |
| 245 -- Fired when the mailbox is opened | |
| 246 function MailOpener:MAIL_SHOW() | |
| 247 -- To stop the timer when the mailbox is closed | |
| 248 self:RegisterEvent("MAIL_CLOSED", "Stop"); | |
| 249 self:RegisterEvent("PLAYER_LEAVING_WORLD", "Stop"); | |
| 250 | |
| 251 -- To set the timer for when to refresh again | |
| 252 self:RegisterEvent("MAIL_INBOX_UPDATE"); | |
| 253 | |
| 254 -- We need to know when opening has completed | |
| 255 self:RegisterMessage("MO_OPEN_COMPLETE"); | |
| 256 | |
| 257 self:Debug("defaultStatus:" .. self.db.profile.general.defaultStatus); | |
| 258 -- Change the mail opening status according to our settings | |
| 259 if self.db.profile.general.defaultStatus == "_enabled" then | |
| 260 enabled = true; | |
| 261 else | |
| 262 enabled = false; | |
| 263 end | |
| 264 self.cbOpenAll:SetChecked(enabled); | |
| 265 | |
| 266 self:ToggleQAStatus(); | |
| 267 | |
| 268 -- Hide the InboxTooMuchMail warning to allow room for our mail remaining info line | |
| 269 InboxTooMuchMail:Hide() | |
| 270 InboxTooMuchMail.Show = function() end | |
| 271 | |
| 272 if self.QuickAuctionsEnabled then | |
| 273 -- Go through all children of the mail frame to find the post button | |
| 274 local kids = { InboxFrame:GetChildren() }; | |
| 275 | |
| 276 for _, child in ipairs(kids) do | |
| 277 if child then | |
| 278 local width = floor( child:GetWidth() + .5 ); | |
| 279 local height = floor( child:GetHeight() + .5 ); | |
| 280 | |
| 281 -- The open all button has a static width and height | |
| 282 if width == 130 and height == 24 then | |
| 283 child:Hide(); | |
| 284 break; | |
| 285 end | |
| 286 end | |
| 287 end | |
| 288 end | |
| 289 | |
| 290 if self.db.profile.notifications.welcome then | |
| 291 -- Welcome notification | |
| 292 local _, c = UnitClass("player"); | |
| 293 c = RAID_CLASS_COLORS[c]; | |
| 294 c = string.format("|cff%02x%02x%02x", c.r * 255 + 0.5, c.g * 255 + 0.5, c.b * 255 + 0.5); | |
| 295 | |
| 296 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."); | |
| 297 end | |
| 298 | |
| 299 mailboxEmptySoundPlayed = nil; | |
| 300 | |
| 301 self:Recheck(); | |
| 302 | |
| 303 if self.db.profile.general.continueOpening then | |
| 304 self:ScheduleOpen(true); | |
| 305 end | |
| 306 end | |
| 307 | |
| 308 -- Fired after a successful server sync | |
| 309 -- Fired when mail is deleted (which happens after taking all attachments from a mail sent by the game) | |
| 310 function MailOpener:MAIL_INBOX_UPDATE() | |
| 311 local current, total = GetInboxNumItems(); | |
| 312 | |
| 313 local tempLastAmount = lastAmount; | |
| 314 lastAmount = current; | |
| 315 | |
| 316 if current ~= tempLastAmount then | |
| 317 self:Debug("MAIL_INBOX_UPDATE - lastAmount:" .. tempLastAmount .. " - current:" .. current); | |
| 318 end | |
| 319 | |
| 320 if current > tempLastAmount then | |
| 321 -- New messages arrived in our mailbox, so this was a refresh, so set a timer | |
| 322 | |
| 323 -- Yell that we successfully synced with the server | |
| 324 self:SendMessage("MO_SERVER_SYNCED"); | |
| 325 | |
| 326 -- This list is fresh | |
| 327 freshList = true; | |
| 328 mailboxEmptySoundPlayed = nil; | |
| 329 | |
| 330 -- Stop previous timer | |
| 331 self:CancelTimer(self.tmrRecheck, true); | |
| 332 -- More will arrive in 60 seconds | |
| 333 self.tmrRecheck = self:ScheduleTimer(function() | |
| 334 self:Debug("tmrRecheck 61 finished"); | |
| 335 | |
| 336 -- We can get a fresh list now, so query the server | |
| 337 freshList = false; | |
| 338 | |
| 339 -- Look for mail | |
| 340 self:Recheck(); | |
| 341 end, 61); | |
| 342 self:Debug("tmrRecheck 61"); | |
| 343 | |
| 344 if not IsShiftKeyDown() then | |
| 345 -- Allow overriding of mailopening with the shift key | |
| 346 | |
| 347 -- Open the current mail | |
| 348 self:ScheduleOpen(false); | |
| 349 end | |
| 350 elseif (current == 50 and tempLastAmount == 50) then | |
| 351 if not IsShiftKeyDown() then | |
| 352 -- Allow overriding of mailopening with the shift key | |
| 353 | |
| 354 -- Open the current mail | |
| 355 self:ScheduleOpen(false); | |
| 356 end | |
| 357 end | |
| 358 | |
| 359 tempLastAmount = current; | |
| 360 end | |
| 361 | |
| 362 function MailOpener:ScheduleOpen(continued) | |
| 363 if lastAmount > 0 then | |
| 364 local waitTime; | |
| 365 if continued then | |
| 366 waitTime = self.db.profile.general.waitTime; | |
| 367 else | |
| 368 -- 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 | |
| 369 waitTime = self.db.profile.general.initialDelay; | |
| 370 end | |
| 371 | |
| 372 -- Stop previous timer | |
| 373 self:CancelTimer(self.tmrOpenNow, true); | |
| 374 -- Schedule the next open | |
| 375 self.tmrOpenNow = self:ScheduleTimer("OpenNow", waitTime); | |
| 376 end | |
| 377 end | |
| 378 | |
| 379 function MailOpener:OpenNow() | |
| 380 self:Debug("OpenNow (" .. ((opening and "1") or "0") .. ")"); | |
| 381 if not opening and MailFrame:IsVisible() then | |
| 382 self:Debug("OpenNow"); | |
| 383 | |
| 384 -- BeanCounter is the only addon hiding the mail close button while busy, so we can look for that | |
| 385 local BeanCounterActive = not InboxCloseButton:IsVisible(); | |
| 386 | |
| 387 if not BeanCounterActive then | |
| 388 -- BeanCounter is INACTIVE | |
| 389 | |
| 390 self:CancelTimer(self.tmrTryAgain, true); -- Insurance | |
| 391 | |
| 392 if QuickAuctionsAutoMail then | |
| 393 -- Remember the last known quick auctions status | |
| 394 lastQuickAuctionsStatus = QuickAuctionsAutoMail:GetChecked(); | |
| 395 end | |
| 396 if self.db.profile.general.autoDisableQAAutoMail and self.QuickAuctionsEnabled and QuickAuctionsAutoMail and QuickAuctionsAutoMail:GetChecked() then | |
| 397 -- If auto disable "QA Auto mail" is enabled and QA's auto mail is currently toggled on, turn it off | |
| 398 -- We need to do this with a :click to trigger the right events | |
| 399 | |
| 400 self:Debug("Turning automail |cffff0000off|r."); | |
| 401 | |
| 402 QuickAuctionsAutoMail:Click(); | |
| 403 end | |
| 404 | |
| 405 opening = true; | |
| 406 | |
| 407 self:Debug("MO_OPEN_MAIL"); | |
| 408 | |
| 409 -- Summon the mail opening gods | |
| 410 self:SendMessage("MO_OPEN_MAIL"); | |
| 411 else | |
| 412 -- BeanCounter is ACTIVE | |
| 413 self:Debug("BeanCounter active, waiting .5 seconds..."); | |
| 414 | |
| 415 self:CancelTimer(self.tmrTryAgain, true); -- Insurance | |
| 416 -- Wait with summoning until BeanCounter is done, try again every 0.5 seconds | |
| 417 self.tmrTryAgain = self:ScheduleTimer("OpenNow", 0.5); | |
| 418 end | |
| 419 end | |
| 420 end | |
| 421 | |
| 422 function MailOpener:MO_OPEN_COMPLETE() | |
| 423 opening = false; | |
| 424 | |
| 425 local current, total = GetInboxNumItems(); | |
| 426 | |
| 427 if (total - current) == 0 then | |
| 428 -- Play the sound | |
| 429 if self.db.profile.notifications.mailboxEmptySound and (not MailOpener.db.profile.notifications.mailboxEmptySoundOnlyOnce or not mailboxEmptySoundPlayed) then | |
| 430 PlaySoundFile(self.db.profile.notifications.mailboxEmptySoundFile); | |
| 431 mailboxEmptySoundPlayed = true; | |
| 432 end | |
| 433 end | |
| 434 | |
| 435 if self.db.profile.general.autoReenableQAAutoMail and self.QuickAuctionsEnabled and QuickAuctionsAutoMail and not QuickAuctionsAutoMail:GetChecked() then | |
| 436 -- If auto re-enable "QA Auto mail" is enabled and QA's auto mail is currently toggled OFF, turn it on | |
| 437 -- We need to do this with a :click to trigger the right events | |
| 438 | |
| 439 self:Debug("Turning automail |cff00ff00on|r."); | |
| 440 | |
| 441 QuickAuctionsAutoMail:Click(); | |
| 442 elseif self.db.profile.general.autoSetBackQAAutoMail and self.QuickAuctionsEnabled and QuickAuctionsAutoMail and lastQuickAuctionsStatus ~= QuickAuctionsAutoMail:GetChecked() then | |
| 443 -- 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 | |
| 444 -- We need to do this with a :click to trigger the right events | |
| 445 | |
| 446 if lastQuickAuctionsStatus then | |
| 447 self:Debug("Turning automail |cff00ff00on|r."); | |
| 448 else | |
| 449 self:Debug("Turning automail |cffff0000off|r."); | |
| 450 end | |
| 451 | |
| 452 QuickAuctionsAutoMail:Click(); | |
| 453 end | |
| 454 | |
| 455 if self.db.profile.general.continueOpening then | |
| 456 self:ScheduleOpen(true); | |
| 457 end | |
| 458 end | |
| 459 | |
| 460 -- Run another CheckInbox | |
| 461 function MailOpener:Recheck() | |
| 462 self:Debug("|cffffff00Recheck|r"); | |
| 463 | |
| 464 -- Freshlist prevents this from being run too often | |
| 465 -- It is set to true after a server sync | |
| 466 -- and set to false 61 seconds afterwards with a recheck called instantly after it | |
| 467 if not freshList and MailFrame:IsVisible() then | |
| 468 self:Debug("|cff00ff00Recheck|r"); | |
| 469 | |
| 470 -- If this isn't a fresh list (so messages weren't received within the last 60 seconds) and the mailbox wasn't closed | |
| 471 | |
| 472 -- BeanCounter is the only addon hiding the mail close button while busy, so we can look for that | |
| 473 local BeanCounterActive = not InboxCloseButton:IsVisible(); | |
| 474 | |
| 475 if not BeanCounterActive then | |
| 476 -- Query the server | |
| 477 CheckInbox(); | |
| 478 end | |
| 479 | |
| 480 -- Stop previous timer | |
| 481 self:CancelTimer(self.tmrRecheck, true); | |
| 482 -- Keep trying until it works | |
| 483 self.tmrRecheck = self:ScheduleTimer("Recheck", 2); | |
| 484 | |
| 485 self:Debug("tmrRecheck 2"); | |
| 486 end | |
| 487 end | |
| 488 | |
| 489 -- Stop checking for new mail and unregister the events we needed | |
| 490 function MailOpener:Stop() | |
| 491 if self.db.profile.notifications.bye then | |
| 492 print("|cff15ff00Mail Opener|r: Have a nice day. :)"); | |
| 493 end | |
| 494 | |
| 495 opening = false; | |
| 496 | |
| 497 -- We won't need this anymore | |
| 498 self:UnregisterEvent("MAIL_CLOSED"); | |
| 499 self:UnregisterEvent("PLAYER_LEAVING_WORLD"); | |
| 500 self:UnregisterEvent("MAIL_INBOX_UPDATE"); | |
| 501 | |
| 502 -- Messages | |
| 503 self:UnregisterMessage("MO_OPEN_COMPLETE"); | |
| 504 | |
| 505 -- Timers | |
| 506 self:CancelTimer(self.tmrTryAgain, true); | |
| 507 self:CancelTimer(self.tmrOpenNow, true); | |
| 508 | |
| 509 -- If we wait with disabling QA automail until MAIL_SHOW, QA will beat us to it and already start sending stuff | |
| 510 self:ToggleQAStatus(); | |
| 511 end | |
| 512 | |
| 513 function MailOpener:Debug(t) | |
| 514 if not self.debugChannel and self.debugChannel ~= false then | |
| 515 -- 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) | |
| 516 self.debugChannel = false; | |
| 517 | |
| 518 for i = 1, NUM_CHAT_WINDOWS do | |
| 519 local name = GetChatWindowInfo(i); | |
| 520 | |
| 521 if name:upper() == "DEBUG" then | |
| 522 self.debugChannel = _G["ChatFrame" .. i]; | |
| 523 end | |
| 524 end | |
| 525 end | |
| 526 | |
| 527 if self.debugChannel then | |
| 528 self.debugChannel:AddMessage(t); | |
| 529 end | |
| 530 end | |
| 531 | |
| 532 -- Enable our config module if it's disabled and make a reference to it | |
| 533 function MailOpener:EnableConfigModule() | |
| 534 if not MailOpenerConfig then | |
| 535 MailOpenerConfig = self:GetModule("Config"); | |
| 536 MailOpenerConfig:Enable(); | |
| 537 end | |
| 538 end | |
| 539 | |
| 540 -- Toggle Postal's opening modules on or off | |
| 541 function MailOpener:TogglePostalModule(name, status) | |
| 542 if MailOpener.PostalEnabled and Postal then | |
| 543 -- Postal must be enabled | |
| 544 | |
| 545 -- Remember the setting in Postal | |
| 546 Postal.db.profile.ModuleEnabledState[name] = status; | |
| 547 | |
| 548 -- Toggle module | |
| 549 if status then | |
| 550 Postal:GetModule(name):Enable(); | |
| 551 else | |
| 552 Postal:GetModule(name):Disable(); | |
| 553 end | |
| 554 end | |
| 555 end | |
| 556 | |
| 557 -- Change Quick Auction's auto mail status based on our prefered settings | |
| 558 function MailOpener:ToggleQAStatus() | |
| 559 self:Debug("defaultQAStatus:" .. self.db.profile.general.defaultQAStatus); | |
| 560 | |
| 561 if self.QuickAuctionsEnabled and self.db.profile.general.defaultQAStatus ~= "__remember" and QuickAuctionsAutoMail then | |
| 562 if self.db.profile.general.defaultQAStatus == "_enabled" and not QuickAuctionsAutoMail:GetChecked() then | |
| 563 self:Debug("Turning automail |cff00ff00on|r."); | |
| 564 | |
| 565 QuickAuctionsAutoMail:Click(); | |
| 566 elseif self.db.profile.general.defaultQAStatus == "disabled" and QuickAuctionsAutoMail:GetChecked() then | |
| 567 self:Debug("Turning automail |cffff0000off|r."); | |
| 568 | |
| 569 QuickAuctionsAutoMail:Click(); | |
| 570 end | |
| 571 end | |
| 572 end | |
| 573 | |
| 574 function MailOpener:FormatMoney(copper) | |
| 575 local gold = floor( copper / 10000 ); | |
| 576 local silver = floor( ( copper - ( gold * 10000 ) ) / 100 ); | |
| 577 local copper = mod(copper, 100); | |
| 578 | |
| 579 if gold > 0 then | |
| 580 return format(GOLD_AMOUNT_TEXTURE .. " " .. SILVER_AMOUNT_TEXTURE .. " " .. COPPER_AMOUNT_TEXTURE, gold, 0, 0, silver, 0, 0, copper, 0, 0); | |
| 581 elseif silver > 0 then | |
| 582 return format(SILVER_AMOUNT_TEXTURE .. " " .. COPPER_AMOUNT_TEXTURE, silver, 0, 0, copper, 0, 0); | |
| 583 else | |
| 584 return format(COPPER_AMOUNT_TEXTURE, copper, 0, 0); | |
| 585 end | |
| 586 end | |
| 587 | |
| 588 StaticPopupDialogs["MailOpenerCopyWindow"] = { | |
| 589 text = "Please CTRL-C to copy.", | |
| 590 button2 = CLOSE, | |
| 591 hasEditBox = 1, | |
| 592 hasWideEditBox = 1, | |
| 593 OnShow = function() | |
| 594 local editBox = _G[this:GetName().."WideEditBox"]; | |
| 595 if editBox and MailOpener.currentPopupContents then | |
| 596 editBox:SetText(MailOpener.currentPopupContents); | |
| 597 editBox:SetFocus(); | |
| 598 editBox:HighlightText(0); | |
| 599 end | |
| 600 | |
| 601 -- Position the close button in the middle | |
| 602 local button = _G[this:GetName().."Button2"]; | |
| 603 if button then | |
| 604 -- Remove previous know position | |
| 605 button:ClearAllPoints(); | |
| 606 button:SetWidth(200); | |
| 607 -- Reposition in the center | |
| 608 button:SetPoint("CENTER", editBox, "CENTER", 0, -30); | |
| 609 end | |
| 610 end, | |
| 611 EditBoxOnEscapePressed = function() | |
| 612 this:GetParent():Hide(); | |
| 613 end, | |
| 614 timeout = 0, | |
| 615 whileDead = 1, | |
| 616 hideOnEscape = 1, | |
| 617 maxLetters = 1024, | |
| 618 } | |
| 619 | |
| 620 function MailOpener:ShowBetaPopup() | |
| 621 function TableDump(key, val, jumps) | |
| 622 local cache = ""; | |
| 623 | |
| 624 if not jumps then | |
| 625 jumps = 0; | |
| 626 end | |
| 627 | |
| 628 local spacer = ""; | |
| 629 if jumps > 0 then | |
| 630 for i = 1, jumps do | |
| 631 spacer = spacer .. " "; | |
| 632 end | |
| 633 end | |
| 634 | |
| 635 if type(val) == "table" then | |
| 636 cache = cache .. spacer .. key .. " = {\n"; | |
| 637 foreach(val, function(k, v) | |
| 638 cache = cache .. TableDump(k, v, (jumps + 1)); | |
| 639 end); | |
| 640 cache = cache .. spacer .. "},\n"; | |
| 641 else | |
| 642 cache = cache .. spacer .. key .. " = " .. tostring(val) .. ",\n"; | |
| 643 end | |
| 644 | |
| 645 return cache; | |
| 646 end | |
| 647 | |
| 648 local cache = ""; | |
| 649 foreach(MailOpener.db.profile, function(k, v) | |
| 650 cache = cache .. TableDump(k, v, 0); | |
| 651 end); | |
| 652 | |
| 653 local AceGUI = LibStub("AceGUI-3.0"); | |
| 654 local frame = AceGUI:Create("Frame"); | |
| 655 frame:SetTitle("Mail Opener ALPHA"); | |
| 656 frame:SetWidth(575); | |
| 657 frame:SetHeight(375); | |
| 658 | |
| 659 -- Add a normal description label | |
| 660 local desc = AceGUI:Create("Label"); | |
| 661 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"); | |
| 662 desc:SetFont(GameFontHighlightSmall:GetFont(), 13); | |
| 663 desc:SetFullWidth(true); | |
| 664 frame:AddChild(desc); | |
| 665 | |
| 666 -- Add a MultiLineEditBox | |
| 667 local settingsMLEEB = AceGUI:Create("MultiLineEditBox"); | |
| 668 settingsMLEEB:SetText(cache); | |
| 669 settingsMLEEB:SetLabel("Hit CTRL-A to select all and CTRL-C to copy the text. You can then use CTRL-V to paste."); | |
| 670 settingsMLEEB:SetFullWidth(true); | |
| 671 settingsMLEEB:SetNumLines(8); | |
| 672 settingsMLEEB:DisableButton(true); | |
| 673 settingsMLEEB:SetCallback("OnTextChanged", function() | |
| 674 settingsMLEEB:SetText(cache); | |
| 675 end); | |
| 676 frame:AddChild(settingsMLEEB); | |
| 677 | |
| 678 -- Empty line between the two links | |
| 679 local label = AceGUI:Create("Label"); | |
| 680 label:SetText("Please post the above text at either of these two links:"); | |
| 681 label:SetFullWidth(true); | |
| 682 frame:AddChild(label); | |
| 683 | |
| 684 local desc1 = AceGUI:Create("InteractiveLabel"); | |
| 685 desc1:SetText("|cff00bbbb[http://wow.curseforge.com/addons/mailopener/create-ticket/]|r"); | |
| 686 desc1:SetFont(GameFontHighlightSmall:GetFont(), 13); | |
| 687 desc1:SetFullWidth(true); | |
| 688 desc1:SetCallback("OnClick", function() | |
| 689 MailOpener.currentPopupContents = "http://wow.curseforge.com/addons/mailopener/create-ticket/"; | |
| 690 | |
| 691 StaticPopup_Show("MailOpenerCopyWindow"); | |
| 692 end); | |
| 693 desc1:SetCallback("OnEnter", function() | |
| 694 frame:SetStatusText("Click to copy this URL."); | |
| 695 end); | |
| 696 desc1:SetCallback("OnLeave", function() | |
| 697 frame:SetStatusText(""); | |
| 698 end); | |
| 699 frame:AddChild(desc1); | |
| 700 | |
| 701 -- Empty line between the two links | |
| 702 local spacer = AceGUI:Create("Label"); | |
| 703 spacer:SetText(" "); | |
| 704 frame:AddChild(spacer); | |
| 705 | |
| 706 local desc2 = AceGUI:Create("InteractiveLabel"); | |
| 707 desc2:SetText("|cff00bbbb[http://20kleveling.com/JMTCforum/posting.php?mode=reply&f=9&t=1403]|r"); | |
| 708 desc2:SetFont(GameFontHighlightSmall:GetFont(), 13); | |
| 709 desc2:SetFullWidth(true); | |
| 710 desc2:SetCallback("OnClick", function() | |
| 711 MailOpener.currentPopupContents = "http://20kleveling.com/JMTCforum/posting.php?mode=reply&f=9&t=1403"; | |
| 712 | |
| 713 StaticPopup_Show("MailOpenerCopyWindow"); | |
| 714 end); | |
| 715 desc2:SetCallback("OnEnter", function() | |
| 716 frame:SetStatusText("Click to copy this URL."); | |
| 717 end); | |
| 718 desc2:SetCallback("OnLeave", function() | |
| 719 frame:SetStatusText(""); | |
| 720 end); | |
| 721 frame:AddChild(desc2); | |
| 722 | |
| 723 -- Empty line between the two links | |
| 724 local label = AceGUI:Create("Label"); | |
| 725 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."); | |
| 726 label:SetFullWidth(true); | |
| 727 frame:AddChild(label); | |
| 728 end |
