Mercurial > wow > itemauditor
changeset 38:e27d13095b49
Added the ability to suspend and resume ItemAuditor (Ticket #8). To access this feature use "/ia suspend".
author | Asa Ayers <Asa.Ayers@Gmail.com> |
---|---|
date | Sun, 18 Jul 2010 22:46:35 -0700 |
parents | 9bd18fce8498 |
children | 003de902ae64 |
files | CHANGELOG.txt Core.lua Modules/DisplayInvested.lua Modules/Events.lua Modules/Options.lua |
diffstat | 5 files changed, 72 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/CHANGELOG.txt Sun Jul 18 21:32:15 2010 -0700 +++ b/CHANGELOG.txt Sun Jul 18 22:46:35 2010 -0700 @@ -3,6 +3,7 @@ - Added color coding to the minimum price tooltip. If your minimum price is below the current auction price, it wll be green, otherwise it is red. - Added the ability to change the price of an item. You can click the Total Invested or the Invested Each to change the value. - Fixed a bug where sometimes the number owned was not being updated, so you might have 3 of an item but it was calculating as if you only had 1. +- Added the ability to suspend and resume ItemAuditor (Ticket #8). To access this feature use "/ia suspend". 2010-07-17 Asa Ayers <Asa.Ayers@Gmail.com>
--- a/Core.lua Sun Jul 18 21:32:15 2010 -0700 +++ b/Core.lua Sun Jul 18 22:46:35 2010 -0700 @@ -27,6 +27,7 @@ cost_updates = true, queue_skip = false, }, + addon_enabled = true, -- This is for development, so I have no plans to turn it into an option. show_debug_frame_on_startup = false, }, @@ -40,8 +41,7 @@ self.items = self.db.factionrealm.items self:RegisterOptions() - - self:RegisterEvent("PLAYER_ENTERING_WORLD") + ItemAuditor:RegisterFrame(ItemAuditor_DebugFrame) -- /run ItemAuditor.db.profile.show_debug_frame_on_startup = true if self.db.profile.show_debug_frame_on_startup then @@ -50,6 +50,44 @@ end end +local registeredEvents = {} +local originalRegisterEvent = addon.RegisterEvent +function addon:RegisterEvent(event, callback, arg) + registeredEvents[event] = true + if arg ~= nil then + return originalRegisterEvent(self, event, callback, arg) + elseif callback ~= nil then + return originalRegisterEvent(self, event, callback) + else + return originalRegisterEvent(self, event) + end +end + +local originalUnregisterEvent = addon.UnregisterEvent +function addon:UnregisterEvent(event) + registeredEvents[event] = nil + return originalUnregisterEvent(self, event) +end + +function addon:UnregisterAllEvents() + for event in pairs(registeredEvents) do + self:UnregisterEvent(event) + end +end + +local registeredFrames = {} +function addon:RegisterFrame(frame) + tinsert(registeredFrames, frame) +end + +function addon:HideAllFrames() + for key, frame in pairs(registeredFrames) do + if frame then + frame:Hide() + end + end +end + function addon:ConvertItems() for itemName, value in pairs(self.db.factionrealm.item_account) do local itemID = self:GetItemID(itemName)
--- a/Modules/DisplayInvested.lua Sun Jul 18 21:32:15 2010 -0700 +++ b/Modules/DisplayInvested.lua Sun Jul 18 22:46:35 2010 -0700 @@ -65,6 +65,7 @@ if not promptFrame then promptFrame = AceGUI:Create("Frame") + ItemAuditor:RegisterFrame(promptFrame) local window = promptFrame.frame; local width = 345 @@ -189,6 +190,7 @@ if not displayFrame then -- Create the frame container displayFrame = AceGUI:Create("Frame") + ItemAuditor:RegisterFrame(displayFrame) local window = displayFrame.frame; displayFrame:SetTitle("ItemAuditor") displayFrame:SetStatusText("")
--- a/Modules/Events.lua Sun Jul 18 21:32:15 2010 -0700 +++ b/Modules/Events.lua Sun Jul 18 22:46:35 2010 -0700 @@ -3,13 +3,19 @@ local utils = addonTable.utils -function addon:PLAYER_ENTERING_WORLD() +function addon:OnEnable() self:RegisterEvent("MAIL_SHOW") self:RegisterEvent("UNIT_SPELLCAST_START") addon:UpdateCurrentInventory() self:WatchBags() - -- addon:ConvertItems() + self:SetEnabled(nil, self.db.profile.addon_enabled) +end + +function addon:OnDisable() + self:UnwatchBags() + self:UnregisterAllEvents() + addon:HideAllFrames() end function addon:MAIL_SHOW()
--- a/Modules/Options.lua Sun Jul 18 21:32:15 2010 -0700 +++ b/Modules/Options.lua Sun Jul 18 22:46:35 2010 -0700 @@ -156,9 +156,30 @@ func = "CreateFrames", guiHidden = false, }, + suspend = { + type = "toggle", + name = "suspend", + desc = "Suspends ItemAuditor", + get = "IsEnabled", + set = "SetEnabled", + guiHidden = true, + }, }, } +function addon:SetEnabled(info, enable) + self.db.profile.addon_enabled = enable + if enable == self:IsEnabled() then + -- do nothing + elseif enable then + self:Enable() + self:Print('ItemAuditor is enabled.') + else + self:Disable() + self:Print('ItemAuditor is supended and will not watch for any events. Use "/ia suspend" to turn it back on.') + end +end + function addon:RegisterOptions() self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("ItemAuditor", "ItemAuditor") LibStub("AceConfig-3.0"):RegisterOptionsTable("ItemAuditor", options, {"ia"})