diff gui.lua @ 4:05caaf17b3ca

Get history window in a working state again in prep for redoing orders.
author Farmbuyer of US-Kilrogg <farmbuyer@gmail.com>
date Sun, 24 Apr 2011 07:29:01 +0000
parents 2753b9763882
children 7adbc59de8fe
line wrap: on
line diff
--- a/gui.lua	Fri Apr 22 02:13:18 2011 +0000
+++ b/gui.lua	Sun Apr 24 07:29:01 2011 +0000
@@ -19,7 +19,7 @@
 	time	= { ["r"] = 0x0/255, ["g"] = 0x0/255, ["b"] = 1, ["a"] = 0.3},
 }
 eoi_st_otherrow_bgcolortable[""] = eoi_st_otherrow_bgcolortable["kill"]
-eoi_st_otherrow_bgcolortable["realm"] = eoi_st_otherrow_bgcolortable["time"]
+--eoi_st_otherrow_bgcolortable["realm"] = eoi_st_otherrow_bgcolortable["time"]
 local eoi_st_otherrow_bgcolortable_default
 local eoi_st_lootrow_col3_colortable = {
 	[""]	= { text = "", r = 1.0, g = 1.0, b = 1.0, a = 1.0 },
@@ -239,7 +239,6 @@
 end
 
 do
-	local offset
 	function addon:_fill_out_hist_data (opt_starting_index)
 		-- 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
@@ -251,18 +250,17 @@
 		end
 		if not self.history.st then
 			self.history.st = {
-				{ kind = "realm",
+				--[[{ kind = "realm",
 				  cols = setmetatable({
 					{ value = self.history.realm },
 				  }, time_column1_used_mt)
-			    }
+			    }]]
 			}
-			offset = #self.history.st
 		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+offset
+			local sti = i
 			if not st[sti] then
 				st[sti] = { kind = "history" }
 			end
@@ -276,11 +274,17 @@
 
 			if sth.shown ~= h[1].id then
 				-- things have changed, redo the row with new data
-				local iname, ilink, iquality, _,_,_,_,_,_, itexture = GetItemInfo(h[1].id)
-				local textured = eoi_st_textured_item_format:format (itexture, self.quality_hexes[iquality], iname, h[1].count or "")
+				local itexture = GetItemIcon(h[1].id)
+				local iname, ilink, iquality = GetItemInfo(h[1].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
+				else
+					textured = eoi_st_textured_item_format:format ([[ICONS\INV_Misc_QuestionMark]], self.quality_hexes[1], 'UNKNOWN', "")
+				end
 				sth.cols[2].value = textured
 				sth.cols[3].value = h[1].when
-				sth.shown = h[1].id
 			end
 
 		end
@@ -703,7 +707,7 @@
 end
 
 local function hist_st_OnClick (rowFrame, cellFrame, data, cols, row, realrow, column, stable, button, ...)
-	if (row == nil) or (realrow == nil) then return true end  -- click column header, suppress reordering FOR NOW
+	if (row == nil) or (realrow == nil) then return false end  -- click column header, do default resorting
 	local h = data[realrow]
 	local kind = h.kind
 
@@ -844,7 +848,7 @@
 		-- safety check  begin
 		for i,e in ipairs(g_loot) do
 			if type(e.cols) ~= 'table' then
-				addon:Print("ARGH, index",i,"bad in refresh, refreshed at", opt_index, "type",type(e.cols),
+				addon:Print("ARGH, index",i,"bad in eoi refresh, refreshed at", opt_index, "type",type(e.cols),
 					"entry kind", e.kind, "data", e.itemname or e.bosskill or e.startday.text,
 					"-- please take a screenshot and send to Farmbuyer.")
 				tabledump(e)
@@ -983,7 +987,8 @@
 
 -- Tab 4:  History
 -- Much of the implementation here follows a similar desgin for the first
--- tab's handling of ST objects.
+-- tab's handling of ST objects.  We will even reuse its controlling tables
+-- when feasible.
 do
 	local histST
 	local hist_st_cols = {
@@ -1001,6 +1006,9 @@
 			name	= "When",
 			width	= 250,
 			DoCellUpdate = hist_st_col3_DoCellUpdate,
+			defaultsort = "asc",
+			sort = "asc",
+			sortnext = 1,
 		},
 	}
 
@@ -1060,15 +1068,54 @@
 			self:SortData()  -- calls hooked refresh
 		end
 
+		local function reset_current_realm()
+			local r = assert(GetRealmName())
+			-- new .history table:
+			addon.history_all[r] = addon:_prep_new_history_category (nil, r)
+			addon.history = addon.history_all[r]
+			addon.hist_clean = nil
+			-- 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)
 			local st_widget = GUI:Create("lib-st")
 			histST:OuroLoot_Refresh()
 			st_widget:WrapST(histST)
+			st_widget.head_offset = 15
+			st_widget.tail_offset = 0
 			container:SetLayout("Fill")
 			container:AddChild(st_widget)
 
-			local b = mkbutton("Regenerate",
-				[[Erases all history entries from current realm, and regenerate it from current loot information.]])
+			local b
+			do
+				local realms,current = {},1
+				for realmname,histtable in pairs(addon.history_all) do
+					tinsert(realms,realmname)
+					if addon.history == histtable then current = #realms end
+				end
+				b = mkbutton("Dropdown", nil, "", [[Which realm to display]])
+				b:SetFullWidth(true)
+				b:SetLabel()  -- required even when empty, see ace3 ticket #234
+				b:SetList(realms)
+				b:SetValue(current)
+				b:SetCallback("OnValueChanged", function(_dd,event,choice)
+					print("chose realm", choice, realms[choice])
+				end)
+				specials:AddChild(b)
+			end
+
+			--[[
+			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)
@@ -1078,26 +1125,27 @@
 			end)
 			specials:AddChild(b)
 
-			b = mkbutton('hist_clear_all', "Clear All History",
-				[[Erases ALL history entries from all realms.]])
+			b = mkbutton('hist_clear', "Clear Realm History",
+				[[No confirmation!  |cffff1010Erases absolutely all> history entries from the displayed realm.]])
 			b:SetFullWidth(true)
 			b:SetCallback("OnClick", function (_b)
-				local r = GetRealmName()
-				-- new .history table:
-				addon.history_all[r] = addon:_prep_new_history_category (nil, r)
-				addon.history = addon.history_all[r]
-				addon.hist_clean = nil
-				-- new .history.st table:
-				histST:OuroLoot_Refresh()
-				histST:SetData(addon.history.st)
-				addon:Print("You've clicked the history erase button!")
+				reset_current_realm()
 				return addon:redisplay()
-				--return tabs_OnGroupSelected_func(container,"OnGroupSelected","hist")
+			end)
+			specials:AddChild(b)
+
+			b = mkbutton('hist_clear_all', "Clear All History",
+				[[No confirmation!  |cffff1010Erases absolutely all> history entries from ALL realms.]])
+			b:SetFullWidth(true)
+			b:SetCallback("OnClick", function (_b)
+				addon.history_all = {}
+				reset_current_realm()
+				return addon:redisplay()
 			end)
 			specials:AddChild(b)
 
 			b = mkbutton('hist_clear_old', "Clear Older",
-				[[Preserves only the latest loot entry for each player, removing all others.]])
+				[[Preserves only the latest loot entry for each player on the current realm, removing all earlier ones.]])
 			b:SetFullWidth(true)
 			b:SetCallback("OnClick", function (_b)
 				addon:Print("All loot prior to the most recent entries has been erased.")
@@ -1630,7 +1678,7 @@
 	end)
 	control:AddChild(b)
 
-	b = mkbutton("Clear",
+	b = mkbutton("Clear Loot",
 		[[+Erases> all current loot information and generated text (but not saved texts).]])
 	b:SetFullWidth(true)
 	b:SetCallback("OnClick", function()