changeset 72:bb19899c65a7

Add a tooltip for debugging g_loot contents; toggle from the advanced debug options. (Font is ginormous, why?)
author Farmbuyer of US-Kilrogg <farmbuyer@gmail.com>
date Sat, 12 May 2012 11:08:23 +0000
parents fb330a1fb6e9
children 32eb24fb2ebf
files gui.lua
diffstat 1 files changed, 105 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/gui.lua	Sat May 12 07:17:55 2012 +0000
+++ b/gui.lua	Sat May 12 11:08:23 2012 +0000
@@ -57,6 +57,7 @@
 -- En masse forward decls of symbols defined inside local blocks
 local _generate_text, _populate_text_specials
 local _tabtexts, _taborder -- filled out in gui block scope
+local _do_debugging_tooltip, _hide_debugging_tooltip, _build_debugging_tooltip
 
 --[[
 This is a table of callback functions, each responsible for drawing a tab
@@ -397,8 +398,84 @@
 		--print("finished history loop, #st ==", #st)
 		self.hist_clean = cache_okay and #self.history or nil
 	end
+end
 
+-- Debugging tooltip
+do
+	-- 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")
+
+		tt:SetBackdrop{
+			bgFile = [[Interface\Tooltips\UI-Tooltip-Background]],
+			edgeFile = [[Interface\Tooltips\UI-Tooltip-Border]],
+			tile = true,
+			tileSize = 8,
+			edgeSize = 12,
+			insets = { left = 2, right = 2, top = 2, bottom = 2 }
+		}
+		tt:SetBackdropColor(TOOLTIP_DEFAULT_BACKGROUND_COLOR.r,
+			TOOLTIP_DEFAULT_BACKGROUND_COLOR.g, TOOLTIP_DEFAULT_BACKGROUND_COLOR.b)
+		tt:SetBackdropBorderColor(TOOLTIP_DEFAULT_COLOR.r, TOOLTIP_DEFAULT_COLOR.g,
+			TOOLTIP_DEFAULT_COLOR.b)
+		tt:SetMovable(false)
+		tt:EnableMouse(false)
+		tt:SetFrameStrata("TOOLTIP")
+		tt:SetToplevel(true)
+		tt:SetClampedToScreen(true)
+
+		local font = GameTooltipTextSmall
+		local left, right, prevleft
+		-- Only create as many lines as we might need (the auto growth
+		-- by Add*Line does odd things sometimes).
+		for i = 1, math.max(#loot,#boss)+2 do
+			prevleft = left
+			left = tt:CreateFontString(nil,"ARTWORK")
+			right = tt:CreateFontString(nil,"ARTWORK")
+			left:SetFontObject(font)
+			right:SetFontObject(font)
+			tt:AddFontStrings(left,right)
+			if prevleft then
+				left:SetPoint("TOPLEFT",prevleft,"BOTTOMLEFT",0,-2)
+			else
+				left:SetPoint("TOPLEFT",10,-10)  -- top line
+			end
+			right:SetPoint("RIGHT",left,"LEFT")
+		end
+
+		_create_tooltip = nil
+	end
+
+	function _build_debugging_tooltip (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()
+
+		-- change these, change the +2 above
+		tt:AddDoubleLine (tostring(index), tostring(e), 1,1,1)
+		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)
+			end
+		end
+		tt:Show()
+	end
+	function _hide_debugging_tooltip()
+		if tt then tt:Hide() end
+	end
 end
 
 
@@ -461,7 +538,6 @@
 	end
 end
 
-
 -- Done at startup, and whenever we've changed the population of tabs.
 function addon:gui_init (loot_pointer)
 	g_loot = assert(loot_pointer, "something went wrong at startup")
@@ -736,40 +812,44 @@
 	if (row == nil) or (realrow == nil) then return end  -- mouseover column header
 	local e = data[realrow]
 	local kind = e.kind
+	local tt = GameTooltip   -- can this be hoisted? does GT ever get securely replaced?
 
+	if _do_debugging_tooltip and column == 1 and kind~='history' then -- FIXME history
+		_build_debugging_tooltip (cellFrame, realrow)
+	end
 	if (kind == 'loot' and column == 1) or (kind == 'history' and column == 2) then
-		GameTooltip:SetOwner (cellFrame, "ANCHOR_RIGHT", -20, 0)
+		tt:SetOwner (cellFrame, "ANCHOR_RIGHT", -20, 0)
 		if e.cache_miss then
-			GameTooltip:ClearLines()
-			GameTooltip:AddLine("Missing Cache Data")
-			GameTooltip:AddLine([[Wait a few seconds, then type]], 0.8, 0.8, 0.8, 1)
-			GameTooltip:AddLine([[/ouroloot fixcache]], 0, 1, 64/255, nil)
-			GameTooltip:AddLine([[and redisplay this window.]], 0.8, 0.8, 0.8, 1)
-			GameTooltip:Show()
+			tt:ClearLines()
+			tt:AddLine("Missing Cache Data")
+			tt:AddLine([[Wait a few seconds, then type]], 0.8, 0.8, 0.8, 1)
+			tt:AddLine([[/ouroloot fixcache]], 0, 1, 64/255, nil)
+			tt:AddLine([[and redisplay this window.]], 0.8, 0.8, 0.8, 1)
+			tt:Show()
 		elseif e.itemlink then
-			GameTooltip:SetHyperlink (e.itemlink)
+			tt:SetHyperlink (e.itemlink)
 		end
 
 	elseif kind == 'loot' and column == 2 then
-		GameTooltip:SetOwner (cellFrame, "ANCHOR_BOTTOMRIGHT", -50, 5)
-		GameTooltip:ClearLines()
-		GameTooltip:AddLine(e.person.." Loot:")
+		tt:SetOwner (cellFrame, "ANCHOR_BOTTOMRIGHT", -50, 5)
+		tt:ClearLines()
+		tt:AddLine(e.person.." Loot:")
 		local counter = 0
 		for i,e2 in ipairs(data) do
 			if e2.person == e.person then  -- would be awesome to test for alts
 				if counter > 10 then
-					GameTooltip:AddLine("...")
+					tt:AddLine("...")
 					break
 				else
 					-- textures screw up too badly, strip them
 					local textured = e2.cols[1].value
 					local space = textured:find(" ")
-					GameTooltip:AddLine(textured:sub(space+1))
+					tt:AddLine(textured:sub(space+1))
 					counter = counter + 1
 				end
 			end
 		end
-		GameTooltip:Show()
+		tt:Show()
 
 	elseif kind == 'loot' and column == 3 then
 		setstatus(e.cols[column].value)
@@ -780,6 +860,7 @@
 end
 local function eoi_st_OnLeave (rowFrame, cellFrame, data, cols, row, realrow, column, table, button, ...)
 	GameTooltip:Hide()
+	_hide_debugging_tooltip()
 	if row and realrow and data[realrow].kind ~= 'loot' then
 		table:SetHighLightColor (rowFrame, eoi_st_otherrow_bgcolortable[data[realrow].reason or data[realrow].kind])
 		return true   -- do not do anything further
@@ -1608,6 +1689,15 @@
 		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:SetValue(addon.DEBUG_PRINT)
 		w:SetCallback("OnValueChanged", function(_w,event,value)