diff gui.lua @ 74:5edaac60449b

Replace kludgey debug tooltip toggle with a dropdown, workable at runtime.
author Farmbuyer of US-Kilrogg <farmbuyer@gmail.com>
date Thu, 31 May 2012 00:06:20 +0000
parents 32eb24fb2ebf
children 676fb79a4ae2
line wrap: on
line diff
--- a/gui.lua	Tue May 29 22:50:09 2012 +0000
+++ b/gui.lua	Thu May 31 00:06:20 2012 +0000
@@ -432,11 +432,32 @@
 	end
 end
 
--- Debugging tooltip
-if true then
-	local tt
+-- Debugging tooltip (unfortunately managed by global and semi-global state
+-- rather than passing around stack parameters)
+do
+	local debug_tt
+
+	local _creators, _builders = {}, {}
 	local function _create_tooltip()
-		tt = CreateFrame("GameTooltip")
+		local which = assert(tonumber(_do_debugging_tooltip))
+		if type(_creators[which]) == 'function' then
+			_creators[which]()
+		end
+		debug_tt = _creators[which]
+	end
+	function _build_debugging_tooltip (parent, index)
+		local which = assert(tonumber(_do_debugging_tooltip))
+		if type(_builders[which]) == 'function' then
+			_builders[which](parent,index)
+		end
+	end
+	function _hide_debugging_tooltip()
+		if debug_tt then debug_tt:Hide() end
+	end
+
+	-- 2 == /dump
+	_creators[2] = function()
+		local tt = CreateFrame("GameTooltip")
 		UIParentLoadAddOn("Blizzard_DebugTools")
 
 		tt:SetBackdrop{
@@ -484,39 +505,36 @@
 		end
 		tt.AddMessage = tt.AddLine
 
-		_create_tooltip = nil
+		_creators[2] = tt
 	end
 
-	function _build_debugging_tooltip (parent, index)
+	_builders[2] = function (parent, index)
 		local e = g_loot[index]; assert(type(e)=='table')
-		if not tt then _create_tooltip() end
-		tt:SetOwner (parent, "ANCHOR_LEFT", -15, -5)
-		tt:ClearLines()
+		_create_tooltip()
+		debug_tt:SetOwner (parent, "ANCHOR_LEFT", -15, -5)
+		debug_tt:ClearLines()
 
 		local real = DEFAULT_CHAT_FRAME
-		DEFAULT_CHAT_FRAME = tt
+		DEFAULT_CHAT_FRAME = debug_tt
 		DevTools_Dump{ [index] = e }
 		DEFAULT_CHAT_FRAME = real
 
-		tt:Show()
+		debug_tt:Show()
 	end
 
-	function _hide_debugging_tooltip()
-		if tt then tt:Hide() end
-	end
-else
-	-- Fields to put in the tooltip (maybe move these into the options window
-	-- if I spend too much time fiddling).
-	local loot = {'person', 'id', 'unique', 'disposition', 'count', 'variant'}
-	local boss = {'bossname', 'reason', 'instance', 'maxsize', 'duration', 'raidersnap'}
-
 	-- Now here's a thing unheard-of.  A tooltip not inheriting from the big
 	-- memory-wasteful template, but also not intended merely for scanning
 	-- invisible tooltips.
 	-- (If this ever grows beyond a text dump, then replace it with libqtip.)
-	local tt
-	local function _create_tooltip()
-		tt = CreateFrame("GameTooltip")
+	--
+	-- Fields to put in the fixed-fields tooltip (maybe move these into the
+	-- options window if I spend too much time fiddling).
+	local loot = {'person', 'id', 'unique', 'disposition', 'count', 'variant'}
+	local boss = {'bossname', 'reason', 'instance', 'maxsize', 'duration', 'raidersnap'}
+
+	-- 3 == fixed fields
+	_creators[3] = function()
+		local tt = CreateFrame("GameTooltip")
 
 		tt:SetBackdrop{
 			bgFile = [[Interface\Tooltips\UI-Tooltip-Background]],
@@ -555,29 +573,26 @@
 			right:SetPoint("RIGHT",left,"LEFT")
 		end
 
-		_create_tooltip = nil
+		_creators[3] = tt
 	end
 
-	function _build_debugging_tooltip (parent, index)
+	_builders[3] = function (parent, index)
 		local e = g_loot[index]; assert(type(e)=='table')
-		if not tt then _create_tooltip() end
-		tt:SetOwner (parent, "ANCHOR_LEFT", -15, -5)
-		tt:ClearLines()
+		_create_tooltip()
+		debug_tt:SetOwner (parent, "ANCHOR_LEFT", -15, -5)
+		debug_tt:ClearLines()
 
 		-- change these, change the +2 above
-		tt:AddDoubleLine (tostring(index), tostring(e), 1,1,1)
-		tt:AddDoubleLine ('kind', e.kind, 1,1,1)
+		debug_tt:AddDoubleLine (tostring(index), tostring(e), 1,1,1)
+		debug_tt:AddDoubleLine ('kind', e.kind, 1,1,1)
 
 		local source = (e.kind == 'loot' and loot) or (e.kind == 'boss' and boss)
 		if source then
 			for _,field in ipairs(source) do
-				tt:AddDoubleLine (field, tostring(e[field]), 1,1,1, 0,156/255,1)
+				debug_tt:AddDoubleLine (field, tostring(e[field]), 1,1,1, 0,156/255,1)
 			end
 		end
-		tt:Show()
-	end
-	function _hide_debugging_tooltip()
-		if tt then tt:Hide() end
+		debug_tt:Show()
 	end
 end
 
@@ -1786,19 +1801,26 @@
 		local simple = GUI:Create("SimpleGroup")
 		simple:SetLayout("List")
 		simple:SetRelativeWidth(0.3)
+		w = mkbutton("Dropdown", nil, "", [[hovering over Item column only]])
+		w:SetFullWidth(true)
+		w:SetLabel("loot debugging tooltip")
+		w:SetList{
+			[1] = "Off",
+			[2] = "/dump into tooltip",
+			[3] = "small fixed fields",
+		}
+		w:SetValue(_do_debugging_tooltip or 1)
+		w:SetCallback("OnValueChanged", function(_w,event,choice)
+			_do_debugging_tooltip = choice > 1 and choice or nil
+		end)
+		simple:AddChild(w)
+
+		w = GUI:Create("Spacer") w:SetFullWidth(true) w:SetHeight(10) simple:AddChild(w)
+
 		w = GUI:Create("CheckBoxSmallLabel")
 		w:SetFullWidth(true)
 		w:SetType("checkbox")
-		w:SetLabel("loot debugging tooltip")
-		w:SetValue(_do_debugging_tooltip)
-		w:SetCallback("OnValueChanged", function(_w,event,value)
-			_do_debugging_tooltip = value
-		end)
-		simple:AddChild(w)
-		w = GUI:Create("CheckBoxSmallLabel")
-		w:SetFullWidth(true)
-		w:SetType("checkbox")
-		w:SetLabel("debug toggle")
+		w:SetLabel("debug toggle  --->")
 		w:SetValue(addon.DEBUG_PRINT)
 		w:SetCallback("OnValueChanged", function(_w,event,value)
 			addon.DEBUG_PRINT = value