changeset 24:61d932f0e8f2

Reassigning loot in the main tab also updates entries in the history tab.
author Farmbuyer of US-Kilrogg <farmbuyer@gmail.com>
date Wed, 21 Sep 2011 06:21:48 +0000
parents 8664134bba4f
children cb9635999171
files Ouro_Loot.toc core.lua gui.lua
diffstat 3 files changed, 49 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/Ouro_Loot.toc	Fri Sep 09 00:56:13 2011 +0000
+++ b/Ouro_Loot.toc	Wed Sep 21 06:21:48 2011 +0000
@@ -18,9 +18,6 @@
 libs\lib-st\lib-st.xml
 #@end-no-lib-strip@
 
-#Libs\lib-st-Core-r118.lua
-#Libs\lib-st-Core-r137v38.lua
-
 # extra bits
 LibFarmbuyer.lua
 AceGUIWidget-Spacer.lua
--- a/core.lua	Fri Sep 09 00:56:13 2011 +0000
+++ b/core.lua	Wed Sep 21 06:21:48 2011 +0000
@@ -1537,8 +1537,10 @@
 			count = e.count,
 		}
 		tinsert (h, 1, n)
+		e.history_unique = n.id .. ' ' .. n.when
 	end
 
+	-- Create new history table based on current loot.
 	function addon:rewrite_history (realmname)
 		local r = assert(realmname)
 		self.history_all[r] = self:_prep_new_history_category (nil, r)
@@ -1561,6 +1563,7 @@
 		end
 	end
 
+	-- Clears all but latest entry for each player.
 	function addon:preen_history (realmname)
 		local r = assert(realmname)
 		for i,h in ipairs(self.history) do
@@ -1570,6 +1573,50 @@
 			end
 		end
 	end
+
+	function addon:reassign_loot (index, name_to)
+		local e = assert(g_loot[index], "trying to reassign nonexistant entry")
+		assert(e.kind=='loot', "trying to reassign something that isn't loot")
+		assert(type(name_to)=='string' and name_to:len()>0)
+
+		local name_from = e.person
+		local tag = e.history_unique
+		local errtxt
+
+		if not tag then
+			errtxt = "Entry for %s is missing a history tag!"
+		else
+			local from_i,from_h = self:get_loot_history(name_from)
+			local to_i,to_h = self:get_loot_history(name_to)
+
+			local hi
+			for i,h in ipairs(from_h) do
+				local unique = h.id .. ' ' .. h.when
+				if unique == tag then
+					hi = i
+					break
+				end
+			end
+			if not hi then
+				-- 1) loot an item, 2) clear old history, 3) reassign from current loot
+				-- Bah.  Anybody that tricky is already recoding the tables directly anyhow.
+				errtxt = "There is no record of %s ever having been assigned!"
+			else
+				hi = tremove (from_h, hi)
+				tinsert (to_h, 1, hi)
+				tsort (from_h, comp)
+				tsort (to_h, comp)
+			end
+		end
+
+		if errtxt then
+			self:Print(errtxt .. "  Loot will be reassigned but history will NOT be updated.", e.itemlink)
+		end
+		e.person = name_to
+		e.person_class = select(2,UnitClass(name_to))
+
+		self:Print("Reassigned entry %d from '%s' to '%s'.", index, name_from, name_to)
+	end
 end
 
 
--- a/gui.lua	Fri Sep 09 00:56:13 2011 +0000
+++ b/gui.lua	Wed Sep 21 06:21:48 2011 +0000
@@ -491,9 +491,7 @@
 	end,
 
 	df_REASSIGN = function(rowi,to_whom)
-		g_loot[rowi].person = to_whom
-		g_loot[rowi].person_class = select(2,UnitClass(to_whom))
-		-- FIXME also update history
+		addon:reassign_loot (rowi, to_whom)
 		CloseDropDownMenus()  -- also need to close parent menu
 	end,
 	["Enter name..."] = function(rowi)
@@ -2188,10 +2186,7 @@
 	end,]]
 	OnAccept = function(dialog, data)
 		local name = dialog.usertext --editBox:GetText()
-		g_loot[data.index].person = name
-		g_loot[data.index].person_class = select(2,UnitClass(name))
-		-- FIXME also update history
-		addon:Print("Reassigned entry %d to '%s'.", data.index, name)
+		addon:reassign_loot (data.index, name)
 		data.display:GetUserData("eoiST"):OuroLoot_Refresh(data.index)
 	end,
 }