changeset 3:7b31138c3c8e

- Add option to print message even on no changes. - Split up options panel into tabs. - Make localization (such as it is) table accessible through addon table.
author Farmbuyer of US-Kilrogg <farmbuyer@gmail.com>
date Mon, 29 Nov 2010 01:52:48 +0000
parents fb9a91642a60
children 9527583a842b
files gd.lua
diffstat 1 files changed, 148 insertions(+), 114 deletions(-) [+]
line wrap: on
line diff
--- a/gd.lua	Fri Nov 05 03:57:42 2010 +0000
+++ b/gd.lua	Mon Nov 29 01:52:48 2010 +0000
@@ -4,28 +4,30 @@
 
 local DEFAULT_CHAT = 2   -- combat log (no constant predefined for that)
 
-local l10n
 --if GetLocale() == "enUS" then
-	l10n= {
-		["LEFT"] = "Players who have left the guild:  ",
-		["JOINED"] = "Players who have joined the guild:  ",
-		["RANK"] = "Players whose rank has changed:",
-		["LEVEL"] = "Players whose level has changed:",
-		["NOTES"] = "Players whose notes have changed:",
+addon.l10n= {
+	["LEFT"] = "Players who have left the guild:  ",
+	["JOINED"] = "Players who have joined the guild:  ",
+	["RANK"] = "Players whose rank has changed:",
+	["LEVEL"] = "Players whose level has changed:",
+	["NOTES"] = "Players whose notes have changed:",
 
-		["Oabbrev"] = "O",       -- abbreviation for "Officer", specifically the non-public note
-		["FIELD_rank"] = "Rank",
-		["FIELD_level"] = "Level",
-		["FIELD_notes"] = "Player/Officer notes",
+	["Oabbrev"] = "O",       -- abbreviation for "Officer", specifically the non-public note
+	["FIELD_rank"] = "Rank",
+	["FIELD_level"] = "Level",
+	["FIELD_notes"] = "Player/Officer notes",
 
-		-- Something needs to be done about the walls of description text below.
-	}
+	["NOCHANGE"] = "No changes to tracked fields have been detected.",
+
+	-- Something needs to be done about the walls of description text below.
+}
 --elseif .... end
 
 local guild_selection, log_ever_shown
 addon.options = {
 	name = "Guild Delta",
 	type = 'group',
+	childGroups = 'tab',
 	handler = addon,    -- functions listed as strings called as addon:func
 	args = {
 		version = {
@@ -43,111 +45,135 @@
 			width = 'full',
 			order = 2,
 		},
-		reset = {
-			name = "Reset Output",
-			desc = "Restores default output settings",
-			type = 'execute',
-			order = 5,
-			func = "SetChat",
-			arg = DEFAULT_CHAT,
+		general = {
+			name = "General",
+			desc = "Tracking options",
+			type = 'group',
+			order = 10,
+			args = {
+				fields = {
+					name = "Fields",
+					desc = "Track changes to these player fields",
+					type = 'multiselect',
+					order = 10,
+					-- these need to be of function type rather than string keys of members
+					values = function(info) return addon:MakeFieldList() end,
+					get = function(info,x) return SV.fields[x] end,
+					set = function(info,x,val) SV.fields[x] = val end,
+				},
+				nochange = {
+					name = "No Change",
+					desc = "Print a message even when no changes are detected",
+					type = 'toggle',
+					order = 15,
+					get = function() return not not SV.notify_nochange end,
+					set = function(info,val) SV.notify_nochange = val end,
+				},
+				spacer2 = {
+					name = '',
+					type = 'description',
+					cmdHidden = true,
+					width = 'full',
+					order = 19,
+				},
+				guilds = {
+					name = "Guilds",
+					desc = "Guilds for which a roster is known",
+					type = 'select',
+					order = 20,
+					width = 'double',
+					values = function(info) return addon:MakeGuildList() end,
+					get = function(info) return guild_selection end,
+					set = function(info,val) guild_selection = val end,
+				},
+				clearguild = {
+					name = "Reset Guild",
+					desc = "Erase stored data for selected guild; information will be scanned from scratch on next login.",
+					type = 'execute',
+					order = 22,
+					disabled = function() return not guild_selection end,
+					func = function()
+						assert(type(guild_selection)=='string')
+						local g,r = guild_selection:match("<([^>]+)> %- (.*)")
+						local m = SV.members[r]
+						if m then
+							m[g] = nil
+						else
+							addon:Print("Hm, error.", r, "can't be matched as a realm name.  Please report this as a bug, including the name of the realm and guild.")
+						end
+					end,
+				},
+			},
 		},
-		spacer2 = {
-			name = '',
-			type = 'description',
-			cmdHidden = true,
-			width = 'full',
-			order = 6,
-		},
-		print_chatframes = {
-			name = "Print Chatframe Numbers",
-			desc = "Print each chat window number in its frame, for easy reference in the next slider option",
-			type = 'execute',
-			--func = print_chatframes filled in below
-			order = 10,
-		},
-		chatframe_num = {
-			name = "Output Chatframe",
-			desc = "Which chat window to prefer for printing all the output during login",
-			type = 'range',
-			min  = 1,
-			max  = NUM_CHAT_WINDOWS,
-			step = 1,
-			get = function() return tonumber(SV.chatframe) or --[[in case of custom name]]DEFAULT_CHAT end,
-			set = "SetChat",
-			order = 15,
-		},
-		chatframe_name = {
-			name = "Chatframe Override",
-			desc = "<Advanced>  If blank, uses the numerical slider.  If set, it is the NAME of a frame with AddMessage capability to use for output.",
-			type = 'input',
-			get = function()
-				return type(SV.chatframe) == 'string' and SV.chatframe or nil
-			end,
-			set = "SetChat",
-			order = 16,
-		},
-		fields = {
-			name = "Fields",
-			desc = "Track changes to these player fields",
-			type = 'multiselect',
+		output = {
+			name = "Output",
+			desc = "What and where to print",
+			type = 'group',
 			order = 20,
-			-- these need to be of function type rather than string keys of members
-			values = function(info) return addon:MakeFieldList() end,
-			get = function(info,x) return SV.fields[x] end,
-			set = function(info,x,val) SV.fields[x] = val end,
-		},
-		spacer1 = {
-			name = '',
-			type = 'description',
-			cmdHidden = true,
-			width = 'full',
-			order = 29,
-		},
-		guilds = {
-			name = "Guilds",
-			desc = "Guilds for which a roster is known",
-			type = 'select',
-			order = 30,
-			width = 'double',
-			values = function(info) return addon:MakeGuildList() end,
-			get = function(info) return guild_selection end,
-			set = function(info,val) guild_selection = val end,
-		},
-		clearguild = {
-			name = "Reset Guild",
-			desc = "Erase stored data for selected guild; information will be scanned from scratch on next login.",
-			type = 'execute',
-			order = 32,
-			disabled = function() return not guild_selection end,
-			func = function()
-				assert(type(guild_selection)=='string')
-				local g,r = guild_selection:match("<([^>]+)> %- (.*)")
-				local m = SV.members[r]
-				if m then
-					m[g] = nil
-				else
-					addon:Print("Hm, error.", r, "can't be matched as a realm name.  Please report this as a bug, including the name of the realm and guild.")
-				end
-			end,
+			args = {
+				reset = {
+					name = "Reset Output",
+					desc = "Restores default output settings",
+					type = 'execute',
+					order = 10,
+					func = "SetChat",
+					arg = DEFAULT_CHAT,
+				},
+				spacer1 = {
+					name = '',
+					type = 'description',
+					cmdHidden = true,
+					width = 'full',
+					order = 11,
+				},
+				print_chatframes = {
+					name = "Print Chatframe Numbers",
+					desc = "Print each chat window number in its frame, for easy reference in the next slider option",
+					type = 'execute',
+					--func = print_chatframes filled in below
+					order = 20,
+				},
+				chatframe_num = {
+					name = "Output Chatframe",
+					desc = "Which chat window to prefer for printing all the output during login",
+					type = 'range',
+					min  = 1,
+					max  = NUM_CHAT_WINDOWS,
+					step = 1,
+					get = function() return tonumber(SV.chatframe) or --[[in case of custom name]]DEFAULT_CHAT end,
+					set = "SetChat",
+					order = 25,
+				},
+				chatframe_name = {
+					name = "Chatframe Override",
+					desc = "<Advanced>  If blank, uses the numerical slider.  If set, it is the NAME of a frame with AddMessage capability to use for output.",
+					type = 'input',
+					get = function()
+						return type(SV.chatframe) == 'string' and SV.chatframe or nil
+					end,
+					set = "SetChat",
+					order = 26,
+				},
+			},
 		},
 		persist = {
 			name = "Logging",
+			desc = "Storing changes for later review",
 			type = 'group',
-			inline = true,
-			order = 60,
+			order = 30,
 			args = {
 				note = {
 					--name = filled in locals section
 					type = 'description',
 					cmdHidden = true,
 					width = 'full',
-					order = 1,
+					order = 10,
 				},
 				enable = {
 					name = "Enable Logging",
 					desc = [[Accumulate all deltas, including a timestamp.  |cffFF0000WARNING|r: if logging was enabled and you turn it off, the log itself will not be saved when exiting the game.]],
 					type = 'toggle',
-					order = 2,
+					order = 15,
 					get = function() return SV.logging end,
 					set = function(i,v)
 						SV.logging = v
@@ -158,7 +184,7 @@
 					name = "Reset Log",
 					desc = "Erase accumulated deltas.",
 					type = 'execute',
-					order = 3,
+					order = 20,
 					hidden = function() return not (SV.logging or log_ever_shown) end,
 					disabled = function() return not SV.logging end,
 					func = function()
@@ -167,9 +193,9 @@
 				},
 				log = {
 					name = "Log",
-					desc = "If you make changes, don't forget to click 'Accept' to save them.",
+					desc = "If you make changes, don't forget to click 'Accept' to save them.  Scroll down if needed.",
 					type = 'input',
-					order = 10,
+					order = 25,
 					multiline = 15,
 					width = 'full',
 					hidden = function() return not (SV.logging or log_ever_shown) end,
@@ -218,7 +244,7 @@
 	return ret
 end
 
-function addon.options.args.print_chatframes.func()
+function addon.options.args.output.args.print_chatframes.func()
 	for i = 1, NUM_CHAT_WINDOWS do
 		local cf = _G['ChatFrame'..i]
 		if not cf then break end
@@ -231,7 +257,7 @@
 "The guild roster has already been scanned by the time you see this.  Therefore, "..
 "if you make any changes to the Fields section below, you should probably relog "..
 "immediately to begin tracking the changed fields.  Changes to the contents *OF* "..
-"those fields will not be noticed until the first login after *that*.\n\n"
+"those fields will not be noticed until the first login after *that*.\n"
 
 addon.options.args.persist.args.note.name = 
 "Enabling logging will accumulate the text of the 'deltas' as you see them.  "..
@@ -245,7 +271,7 @@
 
 -----------------------------------------------------------------------------
 addon = LibStub("AceAddon-3.0"):NewAddon(addon, "GuildDelta",
-		        "AceConsole-3.0")
+                "AceConsole-3.0")
 
 function addon:OnInitialize()
 	if _G.GuildDeltaSV == nil then
@@ -253,7 +279,9 @@
 		_G.GuildDeltaSV = {
 			chatframe = _G.GuildDelta_chatframe or DEFAULT_CHAT,
 			fields = _G.GuildDelta_fields or { rank = true, level = false, notes = true },
-			members = _G.GuildDelta_memberdata or {}
+			members = _G.GuildDelta_memberdata or {},
+			--notify_nochange = nil by default
+			--logging = nil by default
 		}
 	end
 	SV = _G.GuildDeltaSV
@@ -273,7 +301,7 @@
 function addon:unload()
 	self:cleanup()
 	LibStub("AceAddon-3.0").addons["GuildDelta"] = nil
-	l10n = nil; addon = nil;
+	addon = nil;
 	-- put the userdata back so it counts as a Frame object again
 	local ud = self[0]
 	table.wipe(self)
@@ -286,8 +314,7 @@
 		return self:unload()
 	end
 
-	AutoCompleteInfoDelayer:HookScript("OnFinished",
-		function() self:RegisterEvent("GUILD_ROSTER_UPDATE") end)
+	self:RegisterEvent("GUILD_ROSTER_UPDATE")
 	self:SetScript("OnEvent", self.GuildUpdate)
 
 	self.options.args.version.name =
@@ -379,6 +406,7 @@
 
 	local guild, realm = (GetGuildInfo("player")), GetRealmName()
 	local members = SV.members
+	local l10n = self.l10n
 	if members[realm] 
 	   and members[realm][guild]
 	   and #(members[realm][guild]) > 0
@@ -393,7 +421,7 @@
 	end
 
 	-- table.insert with notes if available
-	-- concatentation of all strings faster than string.format
+	-- concatentation of string-only args faster than string.format of same
 	local function tins (t, x)
 		local s = x.name
 		if x.onote and (x.onote ~= "") then
@@ -456,18 +484,21 @@
 
 	-- show results
 	if SV.logging then self.logquay = {} end
-	local m
+	local m, changes
 	if #left > 0 then
+		changes = true
 		m = l10n.LEFT .. table.concat(left, ", ")
 		cprt(m)
 	end
 
 	if #joined > 0 then
+		changes = true
 		m = l10n.JOINED .. table.concat(joined, ", ")
 		cprt(m)
 	end
 
 	if #rank > 0 then
+		changes = true
 		cprt(l10n.RANK)
 		for i = 1, #rank do
 			cprt(rank[i][1]..':  '..rank[i][2])
@@ -475,6 +506,7 @@
 	end
 
 	if #level > 0 then
+		changes = true
 		cprt(l10n.LEVEL)
 		for i = 1, #level do
 			cprt(level[i][1]..':  '..level[i][2])
@@ -482,6 +514,7 @@
 	end
 
 	if #notes > 0 then
+		changes = true
 		cprt(l10n.NOTES)
 		for i = 1, #notes do
 			cprt(notes[i][1]..': "'..notes[i][2]..'"')
@@ -489,6 +522,7 @@
 	end
 
 	if SV.logging then self:FinishLog(guild,realm) end
+	if SV.notify_nochange and (not changes) then cprt(l10n.NOCHANGE) end
 	members[realm][guild] = current
 	self:cleanup()
 end
@@ -498,7 +532,7 @@
 	if not fieldlist then
 		fieldlist = {}
 		for name in pairs(SV.fields) do
-			fieldlist[name] = l10n["FIELD_"..name]
+			fieldlist[name] = self.l10n["FIELD_"..name]
 		end
 	end
 	return fieldlist