Mercurial > wow > mailopener
comparison Modules/Collected.lua @ 31:90d58723ac0a
- Removed all BeanCounter checks in files.
+ Added a new module: BeanCounter Support. This module will now take care of preventing mail opening while BeanCounter is scanning.
+ Added AceHook library for the BeanCounter Support module.
~ Sorted the Core.lua OnInitialize to properly toggle modules before doing time consuming things.
~ All module comments are now a property of the modules themselves and can be retrieved with (string)?.moduleDescription? and (bool)?.moduleRequired?.
~ All module references are now called ?mod?.
! Added a new config group: Modules. This group will show the module statuses and descriptions and it will contain all optional modules (with their settings) as subgroups.
- Removed all libraries from the repository.
| author | Zerotorescue |
|---|---|
| date | Fri, 10 Sep 2010 18:59:58 +0200 |
| parents | c6f0976069c7 |
| children | 81e7cfcc36b9 |
comparison
equal
deleted
inserted
replaced
| 30:4ab03ed958ed | 31:90d58723ac0a |
|---|---|
| 1 local MailOpener = LibStub("AceAddon-3.0"):GetAddon("MailOpener"); | 1 local MailOpener = LibStub("AceAddon-3.0"):GetAddon("MailOpener"); |
| 2 local Collected = MailOpener:NewModule("Collected", "AceEvent-3.0", "AceTimer-3.0"); | 2 local mod = MailOpener:NewModule("Collected", "AceEvent-3.0", "AceTimer-3.0"); |
| 3 | 3 |
| 4 --[[ | 4 mod.moduleDescription = "Shows a simple summary of what has been collected at the mailbox."; |
| 5 Module name: Collected | 5 mod.moduleRequired = false; |
| 6 Description: Shows a simple summary of what has been collected at the mailbox. | 6 |
| 7 Required: No. | 7 -- Gold |
| 8 ]] | |
| 9 | |
| 10 local previousGold, earned, sessionEarned; | 8 local previousGold, earned, sessionEarned; |
| 9 -- Items | |
| 11 local previousFreeSlotsAvailable, itemsGained, sessionItemsgained; | 10 local previousFreeSlotsAvailable, itemsGained, sessionItemsgained; |
| 11 -- Mail | |
| 12 local previousMailCount, mailOpened, sessionMailOpened; | 12 local previousMailCount, mailOpened, sessionMailOpened; |
| 13 -- Time | |
| 13 local timeStarted, sessionTimeSpent; -- even though the first contains GetTime(), the second var will be filled with actual seconds | 14 local timeStarted, sessionTimeSpent; -- even though the first contains GetTime(), the second var will be filled with actual seconds |
| 15 | |
| 14 local updated; | 16 local updated; |
| 15 | 17 |
| 16 function Collected:OnInitialize() | 18 function mod:OnInitialize() |
| 17 local defaults = { | 19 local defaults = { |
| 18 profile = { | 20 profile = { |
| 19 trackGold = true, | 21 trackGold = true, |
| 20 trackItems = true, | 22 trackItems = true, |
| 21 trackMail = true, | 23 trackMail = true, |
| 26 | 28 |
| 27 -- Register our saved variables NameSpace | 29 -- Register our saved variables NameSpace |
| 28 self.db = MailOpener.db:RegisterNamespace("Collected", defaults); | 30 self.db = MailOpener.db:RegisterNamespace("Collected", defaults); |
| 29 end | 31 end |
| 30 | 32 |
| 31 function Collected:OnEnable() | 33 function mod:OnEnable() |
| 32 self:Debug("OnEnable"); | 34 self:Debug("OnEnable"); |
| 33 | 35 |
| 34 self:RegisterEvent("MAIL_SHOW"); | 36 self:RegisterEvent("MAIL_SHOW"); |
| 35 | 37 |
| 36 MailOpener:TogglePostalModule("Rake", false); | 38 MailOpener:TogglePostalModule("Rake", false); |
| 45 self:MAIL_SHOW(); | 47 self:MAIL_SHOW(); |
| 46 end | 48 end |
| 47 end | 49 end |
| 48 | 50 |
| 49 -- Even though Ace can unregister our events it's neater to do it manually too | 51 -- Even though Ace can unregister our events it's neater to do it manually too |
| 50 function Collected:OnDisable() | 52 function mod:OnDisable() |
| 51 self:Debug("OnDisable"); | 53 self:Debug("OnDisable"); |
| 52 | 54 |
| 53 self:UnregisterEvent("MAIL_SHOW"); | 55 self:UnregisterEvent("MAIL_SHOW"); |
| 54 | 56 |
| 55 self:Stop(); | 57 self:Stop(); |
| 56 | 58 |
| 57 MailOpener:TogglePostalModule("Rake", true); | 59 MailOpener:TogglePostalModule("Rake", true); |
| 58 end | 60 end |
| 59 | 61 |
| 60 function Collected:MAIL_SHOW() | 62 function mod:MAIL_SHOW() |
| 61 self:Debug("MAIL_SHOW"); | 63 self:Debug("MAIL_SHOW"); |
| 62 | 64 |
| 63 -- Unbind / reset all previous events and settings | 65 -- Unbind / reset all previous events and settings |
| 64 self:Stop(); | 66 self:Stop(); |
| 65 | 67 |
| 97 if self.db.profile.trackTimeSpent then | 99 if self.db.profile.trackTimeSpent then |
| 98 timeStarted = GetTime(); | 100 timeStarted = GetTime(); |
| 99 end | 101 end |
| 100 end | 102 end |
| 101 | 103 |
| 102 function Collected:MAIL_CLOSED() | 104 function mod:MAIL_CLOSED() |
| 103 self:Debug("MAIL_CLOSED"); | 105 self:Debug("MAIL_CLOSED"); |
| 104 | 106 |
| 105 self:Summarize(); | 107 self:Summarize(); |
| 106 | 108 |
| 107 self:Stop(); | 109 self:Stop(); |
| 108 end | 110 end |
| 109 | 111 |
| 110 function Collected:PLAYER_MONEY() | 112 function mod:PLAYER_MONEY() |
| 111 -- Sending mail does not interest us, so only remember what we earned | 113 -- Sending mail does not interest us, so only remember what we earned |
| 112 local currentGold = GetMoney(); | 114 local currentGold = GetMoney(); |
| 113 | 115 |
| 114 if currentGold > previousGold then | 116 if currentGold > previousGold then |
| 115 local goldEarned = ( currentGold - previousGold ); | 117 local goldEarned = ( currentGold - previousGold ); |
| 124 end | 126 end |
| 125 | 127 |
| 126 previousGold = currentGold; | 128 previousGold = currentGold; |
| 127 end | 129 end |
| 128 | 130 |
| 129 function Collected:BAG_UPDATE() | 131 function mod:BAG_UPDATE() |
| 130 -- Sending mail does not interest us, so only remember what we earned | 132 -- Sending mail does not interest us, so only remember what we earned |
| 131 local freeSlotAvailable = self:GetNumFreeSlots(); | 133 local freeSlotAvailable = self:GetNumFreeSlots(); |
| 132 | 134 |
| 133 if freeSlotAvailable < previousFreeSlotsAvailable then | 135 if freeSlotAvailable < previousFreeSlotsAvailable then |
| 134 -- we lost a slot, so gained an item | 136 -- we lost a slot, so gained an item |
| 154 end | 156 end |
| 155 | 157 |
| 156 previousFreeSlotsAvailable = freeSlotAvailable; | 158 previousFreeSlotsAvailable = freeSlotAvailable; |
| 157 end | 159 end |
| 158 | 160 |
| 159 function Collected:MAIL_INBOX_UPDATE() | 161 function mod:MAIL_INBOX_UPDATE() |
| 160 local numItems, _ = GetInboxNumItems(); | 162 local numItems, _ = GetInboxNumItems(); |
| 161 | 163 |
| 162 if previousMailCount == nil then | 164 if previousMailCount == nil then |
| 163 previousMailCount = numItems; | 165 previousMailCount = numItems; |
| 164 else | 166 else |
| 178 | 180 |
| 179 previousMailCount = numItems; | 181 previousMailCount = numItems; |
| 180 end | 182 end |
| 181 end | 183 end |
| 182 | 184 |
| 183 function Collected:MO_OPEN_COMPLETE() | 185 function mod:MO_OPEN_COMPLETE() |
| 184 -- Only summarize when changed | 186 -- Only summarize when changed |
| 185 if updated then | 187 if updated then |
| 186 self:Summarize(); | 188 self:Summarize(); |
| 187 | 189 |
| 188 updated = false; | 190 updated = false; |
| 189 end | 191 end |
| 190 end | 192 end |
| 191 | 193 |
| 192 function Collected:Stop() | 194 function mod:Stop() |
| 193 self:UnregisterEvent("MAIL_CLOSED"); | 195 self:UnregisterEvent("MAIL_CLOSED"); |
| 194 | 196 |
| 195 -- Batch summary | 197 -- Batch summary |
| 196 self:UnregisterMessage("MO_OPEN_COMPLETE"); | 198 self:UnregisterMessage("MO_OPEN_COMPLETE"); |
| 197 | 199 |
| 214 | 216 |
| 215 -- Time Spent | 217 -- Time Spent |
| 216 timeStarted = nil; | 218 timeStarted = nil; |
| 217 end | 219 end |
| 218 | 220 |
| 219 function Collected:Summarize() | 221 function mod:Summarize() |
| 220 -- Message buffer, append details we have data for | 222 -- Message buffer, append details we have data for |
| 221 local printMessage = ""; | 223 local printMessage = ""; |
| 222 | 224 |
| 223 local timeSpent; | 225 local timeSpent; |
| 224 if timeStarted then | 226 if timeStarted then |
| 285 print(printMessage); | 287 print(printMessage); |
| 286 end | 288 end |
| 287 end | 289 end |
| 288 end | 290 end |
| 289 | 291 |
| 290 function Collected:GetNumFreeSlots() | 292 function mod:GetNumFreeSlots() |
| 291 local slotsAvailable = 0; | 293 local slotsAvailable = 0; |
| 292 for bag = 0, 4 do | 294 for bag = 0, 4 do |
| 293 slotsAvailable = ( slotsAvailable + GetContainerNumFreeSlots(bag) ); | 295 slotsAvailable = ( slotsAvailable + GetContainerNumFreeSlots(bag) ); |
| 294 end | 296 end |
| 295 | 297 |
| 296 return slotsAvailable; | 298 return slotsAvailable; |
| 297 end | 299 end |
| 298 | 300 |
| 299 function Collected:GetOptionsGroup() | 301 function mod:GetOptionsGroup() |
| 300 local configGroup = { | 302 local configGroup = { |
| 301 order = 400, | 303 order = 0, |
| 302 type = "group", | 304 type = "modulesSubGroup", |
| 303 name = "Collected", | 305 name = "Collected", |
| 304 desc = "Change settings for the collected module.", | 306 desc = "Change settings for the collected module.", |
| 305 args = { | 307 args = { |
| 306 General = { | 308 General = { |
| 307 order = 10, | 309 order = 10, |
| 311 args = { | 313 args = { |
| 312 description = { | 314 description = { |
| 313 order = 10, | 315 order = 10, |
| 314 type = "description", | 316 type = "description", |
| 315 name = function() | 317 name = function() |
| 316 local default = "With this button you can completely toggle this module |cff00ff00on|r or |cffff0000off|r. This setting will be remembered and the module will be automatically toggled |cff00ff00on|r or |cffff0000off|r upon logon as it was last set.\n\n"; | 318 local descText = "With this button you can completely toggle this module |cff00ff00on|r or |cffff0000off|r. This setting will be remembered and the module will be automatically toggled |cff00ff00on|r or |cffff0000off|r upon logon as it was last set.\n\n"; |
| 317 | 319 |
| 318 if self:IsEnabled() then | 320 if self:IsEnabled() then |
| 319 return default .. "Status: |cff00ff00Enabled|r"; | 321 descText = descText .. "Status: |cff00ff00Enabled|r"; |
| 320 else | 322 else |
| 321 return default .. "Status: |cffff0000Disabled|r"; | 323 descText = descText .. "Status: |cffff0000Disabled|r"; |
| 322 end | 324 end |
| 325 | |
| 326 return descText; | |
| 323 end, | 327 end, |
| 324 }, | 328 }, |
| 325 disable = { | 329 disable = { |
| 326 order = 20, | 330 order = 20, |
| 327 type = "execute", | 331 type = "execute", |
| 464 }; | 468 }; |
| 465 | 469 |
| 466 return configGroup; | 470 return configGroup; |
| 467 end | 471 end |
| 468 | 472 |
| 469 function Collected:Debug(t) | 473 function mod:Debug(t) |
| 470 return MailOpener:Debug("|cffff0000Collected|r:" .. t); | 474 return MailOpener:Debug("|cffff0000Collected|r:" .. t); |
| 471 end | 475 end |
