changeset 57:81d5449621f8

Fix some sloppy indentation. Correct handling of delayed-load plugins registering multiple tabs in arbitrary order. Add option to not display tabs for disabled plugins (would normally allow enabling of them).
author Farmbuyer of US-Kilrogg <farmbuyer@gmail.com>
date Tue, 17 Apr 2012 04:57:06 +0000
parents fcc0d0ff5832
children 59718ec80610
files LibFarmbuyer.lua core.lua gui.lua
diffstat 3 files changed, 80 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/LibFarmbuyer.lua	Fri Apr 13 04:28:46 2012 +0000
+++ b/LibFarmbuyer.lua	Tue Apr 17 04:57:06 2012 +0000
@@ -192,32 +192,32 @@
 	StaticPopup
 ]]
 function lib.StaticPopup (t)
-    if t.hasEditBox then
-        t.EditBoxOnTextChanged = EditBoxOnTextChanged_notempty
-        t.EditBoxOnEnterPressed = EditBoxOnEnterPressed_accept
+	if t.hasEditBox then
+		t.EditBoxOnTextChanged = EditBoxOnTextChanged_notempty
+		t.EditBoxOnEnterPressed = EditBoxOnEnterPressed_accept
 		if t.OnShow then
 			t.farm_OnShow = t.OnShow
 		end
-        t.OnShow = OnShow_witheditbox
+		t.OnShow = OnShow_witheditbox
 		if t.OnAccept then
 			t.farm_OnAccept = t.OnAccept
 		end
-        t.OnAccept = OnAccept_witheditbox
+		t.OnAccept = OnAccept_witheditbox
 		-- this calls OnCancel with "clicked", unless noCancelOnEscape is set
-        t.EditBoxOnEscapePressed = StaticPopup_EscapePressed
-    end
+		t.EditBoxOnEscapePressed = StaticPopup_EscapePressed
+	end
 
 	if not t.OnHide then
 		t.OnHide = OnHide_cleanup
 	end
 
-    t.timeout = 0
-    t.whileDead = true
-    t.hideOnEscape = true
+	t.timeout = 0
+	t.whileDead = true
+	t.hideOnEscape = true
 	t.enterClicksFirstButton = true
 	t.preferredIndex = 3  -- http://forums.wowace.com/showthread.php?t=19960
 
-    return t
+	return t
 end
 
 
--- a/core.lua	Fri Apr 13 04:28:46 2012 +0000
+++ b/core.lua	Tue Apr 17 04:57:06 2012 +0000
@@ -7,7 +7,7 @@
 - attend		saved text from raid attendence window, default nil
 - printed.FOO	last loot index formatted into text window FOO, default 0
 - raiders		accumulating raid roster data as we see raid members; indexed
-				by player name with subtable fields:
+                by player name with subtable fields:
 -    class		capitalized English codename ("WARRIOR", "DEATHKNIGHT", etc)
 -    subgroup	1-8
 -    race		English codename ("BloodElf", etc)
@@ -15,7 +15,7 @@
 -    level		can be 0 if player was offline at the time
 -    guild		guild name, or missing if unguilded
 -    online		1 = online, 2 = offline, 3 = no longer in raid
-	[both of these next two fields use time_t values:]
+    [both of these next two fields use time_t values:]
 -    join		time player joined the raid (or first time we've seen them)
 -    leave		time player left the raid (or time we've left the raid)
 
@@ -23,37 +23,38 @@
 - kind			time/boss/loot
 - hour			0-23, on the *physical instance server*, not the realm server
 - minute		0-59, ditto
-- stamp			date+timestamp, on the local computer
+- stamp			time_t on the local computer
 - cols			graphical display data; cleared when logging out
 
 Time specific g_loot indices:
 - startday		table with month/day/year/text fields from makedate()
+                text is always "dd Month yyyy"
 
 Boss specific g_loot indices:
 - bossname		name of boss/encounter;
- 				may be changed if "snarky boss names" option is enabled
+                may be changed if "snarky boss names" option is enabled
 - reason		wipe/kill ("pull" does not generate an entry)
 - instance		name of instance, including size and difficulty
 - maxsize		5/10/25, presumably also 15 and 40 could show up; can be
-				0 if we're outside an instance and the player inside has
-				an older version
+                0 if we're outside an instance and the player inside has
+                an older version
 - duration		in seconds; may be missing (only present if local)
 - raidersnap	copy of g_loot.raiders at the time of the boss event
 
 Loot specific g_loot indices:
 - person		recipient
 - person_class	class of recipient if available; may be missing;
- 				will be classID-style (e.g., DEATHKNIGHT)
+                will be classID-style (e.g., DEATHKNIGHT)
 - itemname		not including square brackets
 - id			itemID as number
 - itemlink		full clickable link
 - itexture		icon path (e.g., Interface\Icons\INV_Misc_Rune_01)
 - quality		ITEM_QUALITY_* number
 - disposition	offspec/gvault/shard; missing otherwise; can be set from
-				the extratext field
+                the extratext field
 - count			e.g., "x3"; missing otherwise; can be set/removed from
-				extratext; triggers only for a stack of items, not "the boss
-				dropped double axes today"
+                extratext; triggers only for a stack of items, not "the boss
+                dropped double axes today"
 - is_heroic		true if item is heroic; missing otherwise
 - cache_miss	if GetItemInfo failed; SHOULD be missing (changes other fields)
 - bcast_from	if rebroadcast from another player; missing otherwise
@@ -121,6 +122,7 @@
 		['Custom...'] = '',
 	},
 	['forum_current'] = '[item] by name',
+	['display_disabled_LODs'] = false,
 }
 local virgin = "First time loaded?  Hi!  Use the /ouroloot or /loot command"
 	.." to show the main display.  You should probably browse the instructions"
@@ -1219,8 +1221,10 @@
 		   and not IsAddOnLoaded(i)
 		then
 			local folder, _, _, enabled, _, reason = GetAddOnInfo(i)
-			local tabtitle = GetAddOnMetadata (i, "X-OuroLoot-Plugin")
-			self:_gui_add_LOD_tab (tabtitle, folder, i, enabled, reason)
+			if enabled or opts.display_disabled_LODs then
+				local tabtitle = GetAddOnMetadata (i, "X-OuroLoot-Plugin")
+				self:_gui_add_LOD_tab (tabtitle, folder, i, enabled, reason)
+			end
 		end
 	end
 end
--- a/gui.lua	Fri Apr 13 04:28:46 2012 +0000
+++ b/gui.lua	Tue Apr 17 04:57:06 2012 +0000
@@ -95,7 +95,6 @@
 ------ Behind the scenes routines
 -- Text generation
 do
-	local next_insertion_position = 2   -- position in _taborder
 	local text_gen_funcs, specials_gen_funcs = {}, {}
 	local accumulator = {}
 
@@ -116,8 +115,7 @@
 			error(("Generator for text type '%s' must be a function!"):format(text_type))
 		end
 		_tabtexts[text_type] = { title=title, desc=description }
-		tinsert (_taborder, next_insertion_position, text_type)
-		next_insertion_position = next_insertion_position + 1
+		self:tabposition_insert (text_type)
 		text_gen_funcs[text_type] = generator
 		specials_gen_funcs[text_type] = opt_specgen
 		dirty_tabs = true
@@ -159,24 +157,19 @@
 		-- "tabtitle" here is the name in _taborder, not the colorized string
 		local what = _tabtexts[tabtitle]
 		local addon_index = what.LOD
-		local loaded_at = what.loaded_at
-		local real_nip = next_insertion_position
 		local function LOAD()
 			_tabtexts[tabtitle] = nil
-			tremove (_taborder, loaded_at)
-			next_insertion_position = loaded_at
-			local saved_next_insertion_position = loaded_at
+			addon:tabposition_remove_and_remember (tabtitle)
 			local loaded, whynot = LoadAddOn(addon_index)
+			local tabdelta = addon:tabposition_restore()
 			if loaded then
-				addon:Print("%s loaded.  %d |4tab:tabs; added.", tabtitle,
-					next_insertion_position - saved_next_insertion_position)
+				addon:Print("%s loaded, %d |4tab:tabs; added.", tabtitle, tabdelta)
 			else
 				what.disabled = true
 				_tabtexts[tabtitle] = what -- restore this for mouseovers
 				addon:Print("%s could not load (game client reason was '%s').", tabtitle, whynot)
 				DisableAddOn(addon_index)
 			end
-			next_insertion_position = real_nip
 			dirty_tabs = true
 			return addon:OpenMainDisplayToTab(tabtitle) or addon:BuildMainDisplay()
 		end
@@ -187,7 +180,7 @@
 		else
 			-- was disabled at addons menu
 			StaticPopupDialogs["OUROL_LOD_DISABLED"] = flib.StaticPopup{
-				text = tabtitle.." was disabled at the character loading screen.  Do you want to enable it?",
+				text = tabtitle.." was disabled at the character selection screen.  Do you want to enable it?",
 				button1 = YES,
 				button2 = NO,
 				OnAccept = function()
@@ -211,15 +204,13 @@
 	function addon:_gui_add_LOD_tab (tabtitle, folder, addon_index, enabled_p, why_not)
 		_tabtexts[tabtitle] = {
 			title = ("|cffff0000(%s)|r"):format(tabtitle),
-			desc = ("'|cffff0000%s|r' is not loaded yet.  Click the tab to load it now."):format(folder),
+			desc = ("Plugin '|cffff0000%s|r' is not loaded yet.  Click the tab to load it now."):format(folder),
 			LOD = addon_index,
 			LOD_enabled = enabled_p,
 			LOD_why_not = why_not,
-			loaded_at = next_insertion_position,
 		}
 		tabs_OnGroupSelected[tabtitle] = _handle_LOD
-		tinsert (_taborder, next_insertion_position, tabtitle)
-		next_insertion_position = next_insertion_position + 1
+		self:tabposition_insert (tabtitle)
 		dirty_tabs = true
 	end
 end
@@ -417,6 +408,11 @@
 --[[
 Controls for the tabs on the left side of the main display.
 ]]
+
+-- The _tabtexts and _taborder tables have distressingly wide visibility.
+-- They are used to build the tabgroup_tabs array fed to TabGroup, and for the
+-- official source of mouseover tab titles, etc.  Not completely encapsulated
+-- because we need to reach in and fiddle too often to be worth it.
 _tabtexts = {
 	["eoi"] = {title=[[Loot]], desc=[[Observed loot, plus boss kills and other events of interest]]},
 	["hist"] = {title=[[History]], desc=[[A short semi-permanent record]]},
@@ -428,6 +424,42 @@
 _taborder = { "eoi", "hist", "help", "opt" }
 --else _taborder = { "eoi", "help", "opt" } end
 
+do
+	local next_insertion_position = 2   -- position in _taborder
+	local removed, saved_offset
+
+	function addon:tabposition_insert (tabcode)
+		tinsert (_taborder, next_insertion_position, tabcode)
+		next_insertion_position = next_insertion_position + 1
+	end
+
+	-- These two functions are push/pop pairs, sort of.  The first removes
+	-- a tab and prepares to insert more tab(s) in its place.  The second
+	-- returns the "next tab goes here" marker back to the proper end.  (And
+	-- doing all 3 adjustments below at once is amazingly hard to read.)
+	function addon:tabposition_remove_and_remember (tabcode)
+		assert(not removed)   -- enforce stack-ish discipline
+		for i = 2, #_taborder do
+			if _taborder[i] == tabcode then
+				tremove (_taborder, i)
+				saved_offset = next_insertion_position - i - 1
+				removed, next_insertion_position = i, i
+				return
+			end
+		end
+		error(("'%s' not used as a tab-text code"):format(tabcode))
+	end
+	function addon:tabposition_restore()
+		assert(removed)
+		local count = next_insertion_position - removed
+		next_insertion_position = next_insertion_position + saved_offset
+		removed, saved_offset = nil, nil
+		return count
+	end
+end
+
+
+-- Done at startup, and whenever we've changed the population of tabs.
 function addon:gui_init (loot_pointer)
 	g_loot = loot_pointer
 	g_generated = nil
@@ -1690,6 +1722,11 @@
 			[[Irreverent replacement names for boss events.]])
 		grp:AddChild(w)
 
+		-- LOD plugins in all cases
+		w = mkoption('display_disabled_LODs', "Include disabled plugins", 0.49,
+			[[Show loadable plugins even if they've been disabled (and offer to enable them).  Relog to take effect.]])
+		grp:AddChild(w)
+
 		-- possible keybindings
 		do
 			local pair = GUI:Create("SimpleGroup")