diff gui.lua @ 6:df3e27edbd60

Much work on history tab.
author Farmbuyer of US-Kilrogg <farmbuyer@gmail.com>
date Wed, 15 Jun 2011 03:59:13 +0000
parents 7adbc59de8fe
children 9a37bd40eb5e
line wrap: on
line diff
--- a/gui.lua	Wed Apr 27 04:02:02 2011 +0000
+++ b/gui.lua	Wed Jun 15 03:59:13 2011 +0000
@@ -3,7 +3,7 @@
 --[[
 Purely the AceGUI-related routines, and the subroutines needed for support.
 ------ Constants
------- Locals
+------ Globals
 ------ Behind the scenes routines
 ------ Main GUI Window
 ------ Popup dialogs
@@ -38,7 +38,7 @@
 local time_column1_used_mt = addon.time_column1_used_mt
 
 
------- Locals
+------ Globals
 local GUI = LibStub("AceGUI-3.0")
 local flib = LibStub("LibFarmbuyer")
 
@@ -240,6 +240,8 @@
 
 do
 	function addon:_fill_out_hist_data (opt_starting_index)
+		local new, del = flib.new, flib.del
+
 		-- Clearing history finishes this function with #hist==0 and hist_clean==0.
 		-- The next call typically detects this (#<1) and handles it.  If loot is
 		-- recorded before then, it results in hist_clean==0 and #hist==1, which
@@ -249,6 +251,7 @@
 			opt_starting_index = nil
 		end
 		if not self.history.st then
+			--print"creating ST!"
 			self.history.st = {
 				--[[{ kind = "realm",
 				  cols = setmetatable({
@@ -257,39 +260,62 @@
 			    }]]
 			}
 		end
+
+		-- for now
+		if self.hist_clean == #self.history then return end
+
 		local st = self.history.st
-		for i = (opt_starting_index or self.hist_clean or 1), #self.history do
-			local h = self.history[i]
-			local sti = i
-			if not st[sti] then
-				st[sti] = { kind = "history" }
-			end
-			local sth = st[sti]   -- corresponding ST entry for h
+		--print("starting history loop, #st ==", #st, "#history ==", #self.history)
+		for i,t in ipairs(st) do
+			del(t.cols[1])
+			del(t.cols[2])
+			del(t.cols[3])
+			del(t.cols)
+			del(t)
+			st[i] = nil
+		end
 
-			sth.cols = sth.cols or {
-				{ value = h.name },
-				{},--{ value = h[1].id },
-				{},--{ value = h[1].when },
-			}
+		--for i = (opt_starting_index or self.hist_clean or 1), #self.history do
+		local cache_okay = true
+		for pi,player in ipairs(self.history) do
+			local col1 = new()
+			col1.OLi   = pi
+			col1.OLn   = #player
+			col1.value = player.name   -- may spiffy this up in future
 
-			if sth.shown ~= h[1].id then
-				-- things have changed, redo the row with new data
-				local itexture = GetItemIcon(h[1].id)
-				local iname, ilink, iquality = GetItemInfo(h[1].id)
+			for li,loot in ipairs(player) do
+				local col2 = new()
+				col2.OLi   = li
+				local col3 = new()
+				col3.value = loot.when
+
+				local itexture = GetItemIcon(loot.id)
+				local iname, ilink, iquality = GetItemInfo(loot.id)
 				local textured
 				if itexture and iname then
-					textured = eoi_st_textured_item_format:format (itexture, self.quality_hexes[iquality], iname, h[1].count or "")
-					sth.shown = h[1].id
+					textured = eoi_st_textured_item_format:format (itexture,
+						self.quality_hexes[iquality], iname, loot.count or "")
 				else
-					textured = eoi_st_textured_item_format:format ([[ICONS\INV_Misc_QuestionMark]], self.quality_hexes[1], 'UNKNOWN', "")
+					textured = eoi_st_textured_item_format:format ([[ICONS\INV_Misc_QuestionMark]],
+						self.quality_hexes[ITEM_QUALITY_COMMON], 'UNKNOWN - TRY AGAIN', "")
+					cache_okay = false
 				end
-				sth.cols[2].value = textured
-				sth.cols[3].value = h[1].when
+				col2.value = textured
+
+				local dotcols = new (col1, col2, col3)
+				local st_entry = new()
+				st_entry.kind = 'history'
+				st_entry.OLwho = player.name
+				st_entry.cols = dotcols
+				tinsert (st, st_entry)
 			end
+		end
 
-		end
-		self.hist_clean = #self.history
+		--print("finished history loop, #st ==", #st)
+		self.hist_clean = cache_okay and #self.history or nil
 	end
+
+
 end
 
 
@@ -312,9 +338,9 @@
 	["opt"] = {title=[[Options]], desc=[[Options for fine-tuning behavior]]},
 	--["adv"] = {title=[[Advanced]], desc=[[Debugging and testing]]},
 }
-if addon.author_debug then
+--if addon.author_debug then
 _taborder = { "eoi", "hist", "help", "opt" }
-else _taborder = { "eoi", "help", "opt" } end
+--else _taborder = { "eoi", "help", "opt" } end
 
 --[[
 This is a table of callback functions, each responsible for drawing a tab
@@ -356,7 +382,7 @@
 		name, arg = strsplit('%',name)
 		if name == "--" then
 			tinsert (initial, {
-				disabled = true, text = "",
+				disabled = true, notCheckable = true, text = "",
 			})
 		else
 			if not funcs[name] then
@@ -706,25 +732,8 @@
 	return true  -- do not do anything further
 end
 
-local function hist_st_OnClick (rowFrame, cellFrame, data, cols, row, realrow, column, stable, button, ...)
-	if (row == nil) or (realrow == nil) then return false end  -- click column header, do default resorting
-	local h = data[realrow]
-	local kind = h.kind
-
-
-	return true  -- do not do anything further
-end
-
-local function hist_st_OnDoubleClick (rowFrame, cellFrame, data, cols, row, realrow, column, stable, button, ...)
-	if (row == nil) or (realrow == nil) then return true end  -- they clicked on column header, suppress reordering
-	local h = data[realrow]
-	local kind = h.kind
-
-	return true  -- do not do anything further
-end
-
 -- Used for EOI column 2 and Hist column 1.  Both are player name columns.
-local function eoi_st_col2_DoCellUpdate (rowFrame, cellFrame, data, cols, row, realrow, column, fShow, stable, ...) 
+local function eoi_st_col2_DoCellUpdate (rowFrame, cellFrame, data, cols, row, realrow, column, fShow, stable, ...)
 	if not fShow then
 		cellFrame.text:SetText("")
 		if cellFrame.icontexture then
@@ -784,8 +793,8 @@
 	},
 }
 
-local rowfilter_all
-local rowfilter_by_name = function (st, e)
+local player_filter_all
+local player_filter_by_name = function (st, e)
 	if e.kind ~= 'loot' then return true end
 	return e.person == _d:GetUserData("player filter name")
 end
@@ -861,7 +870,7 @@
 	-- No need to keep creating function closures that all just "return true",
 	-- instead we grab the one made inside lib-st.  There's no "get filter" API
 	-- so we just reach inside.
-	rowfilter_all = ST.Filter
+	player_filter_all = ST.Filter
 
 	-- Now set up the future drawing function...
 	tabs_OnGroupSelected["eoi"] = function(container,specials)
@@ -869,8 +878,8 @@
 		local st = _d:GetUserData("eoiST")
 
 		-- This is actually required each time
-		_d:SetUserData ("player filter clear", rowfilter_all)
-		_d:SetUserData ("player filter by name", rowfilter_by_name)
+		_d:SetUserData ("player filter clear", player_filter_all)
+		_d:SetUserData ("player filter by name", player_filter_by_name)
 
 		st:OuroLoot_Refresh()
 		st_widget:WrapST(st)
@@ -893,10 +902,10 @@
 		b:SetFullWidth(true)
 		b:SetCallback("OnClick", function (_b)
 			local st = _d:GetUserData("eoiST")
-			st:SetFilter(rowfilter_all)
+			st:SetFilter(player_filter_all)
 			_b:SetDisabled(true)
 		end)
-		b:SetDisabled(st.Filter == rowfilter_all)
+		b:SetDisabled(st.Filter == player_filter_all)
 		specials:AddChild(b)
 
 		local people = { "<nobody>" }
@@ -1012,12 +1021,28 @@
 		},
 	}
 
+	local hist_normal_status = [[Click on a row to view all history for that player only.  (Click column headers to re-sort.)]]
+	local hist_name_status = [[Right-click on any row to return to normal history display.]]
+
+	local history_filter_by_recent = function (st, e)
+		if e.kind ~= 'history' then return true end
+		return e.cols[2].OLi == 1
+	end
+
+	local history_filter_who
+	local history_filter_by_name = function (st, e)
+		if e.kind ~= 'history' then return true end
+		return e.OLwho == history_filter_who
+	end
+
 	-- Loot column
-	local function hist_st_col2_DoCellUpdate (rowFrame, cellFrame, data, cols, row, realrow, column, fShow, stable, ...) 
+	local function hist_st_col2_DoCellUpdate (rowFrame, cellFrame, data, cols, row, realrow, column, fShow, stable, ...)
+		print("col2 DCU", realrow)
 	end
 
 	-- Formatted timestamp column
-	local function hist_st_col3_DoCellUpdate (rowFrame, cellFrame, data, cols, row, realrow, column, fShow, stable, ...) 
+	local function hist_st_col3_DoCellUpdate (rowFrame, cellFrame, data, cols, row, realrow, column, fShow, stable, ...)
+		print("col3 DCU", realrow)
 		if not fShow then
 			cellFrame.text:SetText("")
 			return
@@ -1036,6 +1061,33 @@
 		--end
 	end
 
+	local function hist_st_OnClick (rowFrame, cellFrame, data, cols, row, realrow, column, stable, button, ...)
+		if (row == nil) or (realrow == nil) then return false end  -- click column header, do default resorting
+		local h = data[realrow]
+		local kind = h.kind
+
+		if history_filter_who and button == "RightButton" then  -- now filtering and wanting not to
+			history_filter_who = nil
+			stable:SetFilter(history_filter_by_recent)
+			setstatus(hist_normal_status)
+		elseif (not history_filter_who) and button == "LeftButton" then  -- not filtering and wanting to
+			history_filter_who = h.OLwho
+			stable:SetFilter(history_filter_by_name)
+			setstatus(hist_name_status)
+		end
+
+		return true  -- do not do anything further
+	end
+
+	--[[
+	local function hist_st_OnDoubleClick (rowFrame, cellFrame, data, cols, row, realrow, column, stable, button, ...)
+		if (row == nil) or (realrow == nil) then return true end  -- they clicked on column header, suppress reordering
+		local h = data[realrow]
+		local kind = h.kind
+
+		return true  -- do not do anything further
+	end]]
+
 	tabs_OnGroupSelected["hist"] = function(container,specials)
 		histST = LibStub("ScrollingTable"):CreateST(hist_st_cols,eoi_st_displayed_rows,eoi_st_rowheight)
 		if addon.author_debug then
@@ -1056,7 +1108,7 @@
 			OnEnter = eoi_st_OnEnter,
 			OnLeave = eoi_st_OnLeave,
 			OnClick = hist_st_OnClick,
-			--OnDoubleClick = eoi_st_OnDoubleClick,
+			--OnDoubleClick = hist_st_OnDoubleClick,
 		}
 		local oldrefresh = histST.Refresh
 		histST.Refresh = function (self, opt_index)
@@ -1068,8 +1120,12 @@
 			self:SortData()  -- calls hooked refresh
 		end
 
-		local function reset_current_realm()
-			local r = assert(GetRealmName())
+		histST:SetFilter(history_filter_by_recent)
+
+		-- Zaps history for the given realm, or the current (current-playing
+		-- realm, not currently-displayed realm) one if not specified.
+		local function reset_current_realm (opt_realmname)
+			local r = assert(opt_realmname or GetRealmName())
 			-- new .history table:
 			addon.history_all[r] = addon:_prep_new_history_category (nil, r)
 			addon.history = addon.history_all[r]
@@ -1077,7 +1133,6 @@
 			-- new .history.st table:
 			histST:OuroLoot_Refresh()
 			histST:SetData(addon.history.st)
-			addon:Print("You've clicked the history erase button!")
 		end
 
 		tabs_OnGroupSelected["hist"] = function(container,specials)
@@ -1088,6 +1143,7 @@
 			st_widget.tail_offset = 0
 			container:SetLayout("Fill")
 			container:AddChild(st_widget)
+			setstatus(hist_normal_status)
 
 			local b
 			do
@@ -1102,26 +1158,32 @@
 				b:SetList(realms)
 				b:SetValue(current)
 				b:SetCallback("OnValueChanged", function(_dd,event,choice)
-					print("chose realm", choice, realms[choice])
+					local r = realms[choice]
+					addon.history = addon:_prep_new_history_category (addon.history_all[r], r)
+					addon.hist_clean = nil
+					histST:OuroLoot_Refresh()
+					histST:SetData(addon.history.st)
+					-- Reset filters to normal
+					history_filter_who = nil
+					histST:SetFilter(history_filter_by_recent)
+					setstatus(hist_normal_status)
+					return addon:redisplay()
 				end)
 				specials:AddChild(b)
 			end
 
-			--[[
-			b = GUI:Create("Spacer")
-			b:SetFullWidth(true)
-			b:SetHeight(10)
-			specials:AddChild(b)
-			]]
+			--[[ b = GUI:Create("Spacer") b:SetFullWidth(true) b:SetHeight(10) specials:AddChild(b) ]]
 
 			b = mkbutton("Regenerate",
 				[[Erases all history entries from the displayed realm, and regenerates it from current loot information.]])
 			b:SetFullWidth(true)
 			b:SetDisabled (#addon.history == 0)
 			b:SetCallback("OnClick", function(_b)
+				addon:rewrite_history (addon.history.realm)
+				histST:OuroLoot_Refresh()
+				histST:SetData(addon.history.st)
 				addon:Print("%s history has been regenerated.", addon.history.realm)
 				return addon:redisplay()
-				--return tabs_OnGroupSelected_func(container,"OnGroupSelected","hist")
 			end)
 			specials:AddChild(b)
 
@@ -1129,7 +1191,8 @@
 				[[No confirmation!  |cffff1010Erases absolutely all> history entries from the displayed realm.]])
 			b:SetFullWidth(true)
 			b:SetCallback("OnClick", function (_b)
-				reset_current_realm()
+				reset_current_realm(addon.history.realm)
+				addon:Print("Stimpy, you idiot!  You've pushed the history erase button!")
 				return addon:redisplay()
 			end)
 			specials:AddChild(b)
@@ -1140,17 +1203,20 @@
 			b:SetCallback("OnClick", function (_b)
 				addon.history_all = {}
 				reset_current_realm()
+				addon:Print("Stimpy, you idiot!  You've pushed the history erase button!")
 				return addon:redisplay()
 			end)
 			specials:AddChild(b)
 
 			b = mkbutton('hist_clear_old', "Clear Older",
-				[[Preserves only the latest loot entry for each player on the current realm, removing all earlier ones.]])
+				[[Preserves only the latest loot entry for each player on the displayed realm, removing all earlier ones.]])
 			b:SetFullWidth(true)
 			b:SetCallback("OnClick", function (_b)
+				addon:preen_history(addon.history.realm)
 				addon:Print("All loot prior to the most recent entries has been erased.")
+				addon.hist_clean = nil
+				histST:OuroLoot_Refresh()
 				return addon:redisplay()
-				--return tabs_OnGroupSelected_func(container,"OnGroupSelected","hist")
 			end)
 			specials:AddChild(b)
 		end
@@ -1158,7 +1224,7 @@
 	end
 end
 
--- Tab 5:  Help (content in lootaux.lua)
+-- Tab 5:  Help (content in verbage.lua)
 do
 	local tabs_help_OnGroupSelected_func = function (treeg,event,category)
 		treeg:ReleaseChildren()
@@ -1487,8 +1553,6 @@
 			grp:AddChild(w)
 		end
 
-		scroll:AddChild(grp)
-
 		addon.sender_list.sort()
 		if #addon.sender_list.namesI > 0 then
 			local senders = table.concat(addon.sender_list.namesI,'\n')   -- sigh
@@ -1504,6 +1568,8 @@
 			grp:AddChild(w)
 		end
 
+		scroll:AddChild(grp)
+
 		w = mkbutton("ReloadUI", [[Does what you think it does.  Loot information is written out and restored.]])
 		w:SetFullWidth(true)
 		w:SetCallback("OnClick", ReloadUI)
@@ -1625,6 +1691,7 @@
 		_d = _display:GetUserData("eoiST")
 		self.display = nil
 		GUI:Release(_display)
+		flib.clear()
 		collectgarbage()
 	end)