Quantcast

Added options based on AceConfig.

Peter Eliasson [02-08-15 - 16:55]
Added options based on AceConfig.

Currently only options for the upcomming purge module.
Filename
lib/lib_include.xml
src/main.lua
src/options.lua
src/src_include.xml
diff --git a/lib/lib_include.xml b/lib/lib_include.xml
index 3fdb57d..20388cd 100644
--- a/lib/lib_include.xml
+++ b/lib/lib_include.xml
@@ -10,4 +10,6 @@
 	<Include file="Ace3\AceGUI-3.0\AceGUI-3.0.xml"/>
 	<Include file="Ace3\AceHook-3.0\AceHook-3.0.xml"/>
 	<Include file="Ace3\AceTimer-3.0\AceTimer-3.0.xml"/>
+
+	<Include file="Ace3\AceConfig-3.0\AceConfig-3.0.xml"/>
 </Ui>
\ No newline at end of file
diff --git a/src/main.lua b/src/main.lua
index fc2266a..d5e5f2d 100644
--- a/src/main.lua
+++ b/src/main.lua
@@ -22,7 +22,8 @@ addon:SetDefaultModulePrototype(modPrototype)
 -- Db default settings
 addon.dbDefaults = {
 	realm = {
-		modules = {}
+		modules = {},
+		options = {}
 	},
 	global = {
 		dbVersion = 1
@@ -31,7 +32,7 @@ addon.dbDefaults = {

 -- The current db version. Clear (migrate?) the database if
 -- version of database doesn't match this version.
-addon.dbVersion = 2
+addon.dbVersion = 2;

 -- Constants
 DEBUG_PRINT = false;
@@ -160,8 +161,12 @@ function addon:OnEnable()
 	self:RegisterEvent("PLAYER_GUILD_UPDATE")
 	self:RegisterEvent("ZONE_CHANGED_NEW_AREA")

-	self:RegisterChatCommand("gshs", function()
-		self.gui:ShowMainFrame();
+	self:RegisterChatCommand("gshs", function(arg)
+		if arg == "config" then
+			self.options:ShowOptionsFrame();
+		else
+			self.gui:ShowMainFrame();
+		end
 	end)

 	self:UpdateMyGuildName();
diff --git a/src/options.lua b/src/options.lua
new file mode 100644
index 0000000..cf620d4
--- /dev/null
+++ b/src/options.lua
@@ -0,0 +1,94 @@
+local addonName, addonTable = ...
+
+-- Set up module
+local addon = addonTable[1];
+local options = addon:NewModule("options");
+addon.options = options;
+
+
+addon.dbDefaults.realm.options = {
+	purgeEnabled = true,
+	purgeMaxParseAge = 30,
+	purgeMinPlayerParsesPerFight = 2,
+}
+addon.dbVersion = addon.dbVersion + 0;
+
+local optionsTable;
+local function createOptionsTable()
+	optionsTable = {
+		name = "Guild Skada High Score",
+		handler = options,
+		get = "GetRealmOptionValue",
+		set = "SetRealmOptionValue",
+		type = 'group',
+		args = {
+			versionHeader = {
+				order = 1,
+				type = "header",
+				name = format("Version: %s", addon.versionName),
+				width = "Full",
+			},
+			purgeSettings = {
+				name = "Purge Settings",
+				type = "group",
+				inline = true,
+				args = {
+					purgeEnabled = {
+						order = 1,
+						type = "toggle",
+						name = "Enable Purging of Parses",
+						desc = "Enables purging of parses matching some specified condition.",
+					},
+					purgeMaxParseAge = {
+						order = 3,
+						type = "range",
+						min = 0,
+						max = 60,
+						step = 1,
+						name = "Max Parse Age (days)",
+						desc = "Number of days to keep parses.",
+						disabled = function() return not addon.db.realm.options.purgeEnabled; end,
+					},
+					purgeMinPlayerParsesPerFight = {
+						order = 5,
+						type = "range",
+						min = 0,
+						softMax = 20,
+						max = 100,
+						step = 1,
+						name = "Min Parses Per Player/Fight",
+						desc = "The minimum number of parses to keep for a specific player and fight. These parses will not be removed even if they are older than the max parse age.",
+						disabled = function() return not addon.db.realm.options.purgeEnabled; end,
+					}
+				},
+				order = 20,
+			},
+		},
+	};
+end
+
+function options.GetRealmOptionValue(self, info)
+	local key = info[#info];
+	return addon.db.realm.options[key];
+end
+
+function options.SetRealmOptionValue(self, info, value)
+	local key = info[#info];
+	addon.db.realm.options[key] = value;
+end
+
+function options:GetOptionsTable()
+	if not optionsTable then
+		createOptionsTable()
+	end
+	return optionsTable
+end
+
+function options:ShowOptionsFrame()
+	InterfaceOptionsFrame_OpenToCategory(self.optionsFrame);
+end
+
+function options:OnEnable()
+	LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable(addonName, options.GetOptionsTable);
+	self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions(addonName);
+end
diff --git a/src/src_include.xml b/src/src_include.xml
index 28ad07e..0bb3dfd 100644
--- a/src/src_include.xml
+++ b/src/src_include.xml
@@ -4,5 +4,6 @@
 	<Script file="highscore.lua"/>
 	<Script file="gui.lua"/>
 	<Script file="report.lua"/>
+	<Script file="options.lua"/>
 	<Include file="parse_modules\parse_modules_include.xml"/>
 </Ui>
\ No newline at end of file