changeset 58:59718ec80610

Consolidate some common code out of modules.
author Farmbuyer of US-Kilrogg <farmbuyer@gmail.com>
date Tue, 17 Apr 2012 06:26:11 +0000
parents 81d5449621f8
children 1cbaa1ce8253
files core.lua gui.lua
diffstat 2 files changed, 57 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/core.lua	Tue Apr 17 04:57:06 2012 +0000
+++ b/core.lua	Tue Apr 17 06:26:11 2012 +0000
@@ -663,6 +663,52 @@
 end
 --function addon:OnDisable() end
 
+do
+	local prototype = {}
+	local function module_OnEnable (plugin)
+		if plugin.option_defaults then
+			local SVname = 'OuroLoot'..plugin:GetName()..'_opts'
+			if not _G[SVname] then
+				_G[SVname] = {}
+				if type(plugin.OnFirstTime) == 'function' then
+					plugin:OnFirstTime()
+				end
+			end
+			plugin.opts = _G[SVname]
+			for option,default in pairs(plugin.option_defaults) do
+				if plugin.opts[option] == nil then
+					plugin.opts[option] = default
+				end
+			end
+			plugin.option_defaults = nil
+		end
+	end
+
+	-- By default, no plugins.  First plugin to use the special registration
+	-- sets up code for any subsequent plugins.
+	addon.is_plugin = flib.nullfunc
+	local function module_rtg (plugin, text_type, ...)
+		local registry = { [text_type]=plugin }
+		addon.is_plugin = function(a,t) return registry[t] end
+		prototype.register_text_generator = function(p,t,...)
+			registry[t] = p
+			return addon:register_text_generator(t,...)
+		end
+		return addon:register_text_generator(text_type,...)
+	end
+
+	prototype.OnEnable = module_OnEnable
+	prototype.default_OnEnable = module_OnEnable
+	prototype.register_text_generator = module_rtg
+
+	addon:SetDefaultModuleLibraries("AceConsole-3.0")
+	addon:SetDefaultModulePrototype(prototype)
+	-- Fires before the plugin's own OnEnable (inherited or otherwise).
+	--function addon:OnModuleCreated (plugin)
+	--	print("created plugin", plugin:GetName())
+	--end
+end
+
 
 ------ Event handlers
 function addon:_clear_SVs()
--- a/gui.lua	Tue Apr 17 04:57:06 2012 +0000
+++ b/gui.lua	Tue Apr 17 06:26:11 2012 +0000
@@ -1173,6 +1173,17 @@
 		--return tabs_OnGroupSelected_func(container,"OnGroupSelected",text_kind)
 	end)
 	specials:AddChild(w)
+	if addon:is_plugin(text_kind) then
+		local pname = addon:is_plugin(text_kind):GetName()
+		w = mkbutton("Reset SVs & ReloadUI",
+			([[+DEBUG:> Reset savedvariables for %s plugin back to defaults, and trigger a UI reload.]]):format(pname))
+		w:SetFullWidth(true)
+		w:SetCallback("OnClick", function(_w)
+			_G['OuroLoot'..pname..'_opts'] = nil
+			ReloadUI()
+		end)
+		specials:AddChild(w)
+	end
 	_populate_text_specials (box, specials, mkbutton, text_kind)
 end