changeset 128:dc39ce56a62d

- Adding new loot dispositions requires plugin module. - 'NewLootEntry' and 'NewEOIEntry' events also take a row index. (Hmmm) - Loot disposition options broken out into a submenu, and use the same color their notes text do. Toggle a checkbox for the current value.
author Farmbuyer of US-Kilrogg <farmbuyer@gmail.com>
date Wed, 22 Aug 2012 23:37:24 -0400
parents c6d8e096296e
children 2731702567c4
files core.lua gui.lua
diffstat 2 files changed, 100 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- a/core.lua	Sun Aug 19 22:08:17 2012 -0400
+++ b/core.lua	Wed Aug 22 23:37:24 2012 -0400
@@ -396,7 +396,7 @@
 -- En masse forward decls of symbols defined inside local blocks
 local _register_bossmod, makedate, create_new_cache, _init, _log, _do_loot_metas
 local _history_by_loot_id, _setup_unique_replace, _unavoidable_collision
-local _notify_about_change, _LFR_suppressing
+local _notify_about_change, _LFR_suppressing, _add_loot_disposition
 
 -- Try to extract numbers from the .toc "Version" and munge them into an
 -- integral form for comparison.  The result doesn't need to be meaningful as
@@ -999,17 +999,16 @@
 		text_notes, opt_text_menu (uses notes if nil), opt_tooltip_txt,
 		can_reassign_p, do_history_p, from_notes_text_p
 	]]
-	local norm = self:_add_loot_disposition ('normal', "ff","ff","ff", "", "normal",
+	local norm = _add_loot_disposition (self, 'normal', "ff","ff","ff", "", "normal/mainspec",
 		[[This is the default.  Selecting any 'Mark as <x>' action blanks out extra notes about who broadcast this entry, etc.]],
 		true, true, false)
-	self:_add_loot_disposition ('offspec', "c6","9b","6d", "offspec", nil, nil,
+	_add_loot_disposition (self, 'offspec', "c6","9b","6d", "offspec", nil, nil,
 		true, true, true)
-	self:_add_loot_disposition ('shard',   "a3","35","ee", "shard",
+	_add_loot_disposition (self, 'shard',   "a3","35","ee", "shard",
 		"disenchanted", nil, false, false, true)
-	-- suddenly changing localization mid-phrase is horky, change this to a submenu:
-	self:_add_loot_disposition ('gvault',  "33","ff","99", _G.GUILD_BANK:lower(),
+	_add_loot_disposition (self, 'gvault',  "33","ff","99", _G.GUILD_BANK:lower(),
 		nil, nil, false, false, true)
-	-- fix up the odd (!) standard case of having a nil disposition field
+	-- fix up the odd(!) standard case of having a nil disposition field
 	norm.arg2 = nil
 
 	--[[
@@ -1058,6 +1057,7 @@
 	- opts:  (OUT) Pointer to plugin's "db.profile" subtable.
 
 	Inherited unchanged:
+	- _add_loot_disposition
 
 	Inherited module variants:
 	- OnInitialize, OnEnable
@@ -1152,6 +1152,13 @@
 		end
 	end
 
+	-- For references that would be nil at load time, and I don't feel like
+	-- rearranging the entire file.
+	function addon:MODULE_PROTOTYPE_POINTERS()
+		prototype.add_loot_disposition = _add_loot_disposition
+		self.MODULE_PROTOTYPE_POINTERS = nil
+	end
+
 	addon:SetDefaultModuleLibraries("AceConsole-3.0")
 	addon:SetDefaultModulePrototype(prototype)
 
@@ -1203,15 +1210,18 @@
     New row in primary EOI table of kind=='boss'.  Includes all 'NewBoss'
     occasions, plus manual boss additions, testing, etc.  Arg same as NewBoss.
 
-'NewLootEntry', loot
+'NewLootEntry', loot, row_index
 'DelLootEntry', loot
     New or removed row in primary EOI table of kind=='loot'.  Argument is a
-    g_loot table entry of kind=='loot'.
-
-'NewEOIEntry', entry
+    g_loot table entry of kind=='loot', and the index into g_loot of where
+	the entry "is" (read: "will be" by the time the event fires).
+
+'NewEOIEntry', entry, row_index
 'DelEOIEntry', entry
     New or removed row in primary EOI table, of any kind.  Argument is the
-    g_loot entry, already inserted into or removed from g_loot.
+    g_loot entry, already inserted into or removed from g_loot.  Note that
+	boss entries may shift around after this event (if loot has happened and
+	needs to be re-sorted).
 
 'NewHistory', player_name, uniqueID
 'DelHistory', player_name, uniqueID
@@ -2665,15 +2675,15 @@
 		e.hour = h
 		e.minute = m
 		e.stamp = time_t --localuptime
+		local index = #g_loot + 1
 		if e.kind == 'loot' then
 			if (not e.unique) or (#e.unique==0) then
 				e.unique = e.id .. (e.disposition or e.person) .. date("%Y/%m/%d %H:%M",e.stamp)
 			end
-			addon:Fire ('NewLootEntry', e)
+			addon:Fire ('NewLootEntry', e, index)
 		end
-		local index = #g_loot + 1
 		g_loot[index] = e
-		addon:Fire ('NewEOIEntry', e)
+		addon:Fire ('NewEOIEntry', e, index)
 		return index
 	end
 
@@ -2690,7 +2700,7 @@
 			if needSnap then e.raidersnap = ss end
 			if needInst then e.instance = inst end
 		end
-		addon:Fire ('NewBossEntry', e)
+		addon:Fire ('NewBossEntry', e, ret)
 		return ret
 	end
 
@@ -2754,7 +2764,7 @@
 		return next, r
 	end
 
-	function addon:_add_loot_disposition (code, rhex, ghex, bhex, text_notes,
+	function _add_loot_disposition (self, code, rhex, ghex, bhex, text_notes,
 		text_menu, tooltip_txt, can_reassign_p, do_history_p, from_notes_text_p
 	)
 		assert(type(code)=='string' and #code>0)
@@ -2763,7 +2773,7 @@
 		assert(type(bhex)=='string')
 		assert(type(ghex)=='string')
 
-		self.disposition_colors[code] = {
+		addon.disposition_colors[code] = {
 			text = text_notes,
 			-- for chat output by core code
 			hex = "|cff" .. rhex .. ghex .. bhex,
@@ -2782,8 +2792,13 @@
 			from_notes_text = not not from_notes_text_p,
 		}
 
-		return g_gui.add_dropdown_entry ('eoi_loot', "Mark as "..(text_menu or text_notes),
+		local dd = g_gui.add_dropdown_entry ('eoi_loot_mark', text_menu or text_notes,
 			--[[function_table=]]nil, 'df_DISPOSITION', code, tooltip_txt)
+		dd.colorCode = addon.disposition_colors[code].hex
+		addon.dprint('flow', ("Source '%s' adds loot disposition '%s', flags"):
+			format(self.name or tostring(self), code),
+			can_reassign_p, do_history_p, from_notes_text_p)
+		return dd
 	end
 end
 
@@ -3662,8 +3677,8 @@
 	-- This is not entirely "history" but not completely anything else either.
 	-- Handles the primary "Mark as <x>" action.  Arguments depend on who's
 	-- calling it:
-	--     "local", row_index, new_disposition
-	--     "remote", sender, unique_id, item_id, old_disposition, new_disposition
+	--     'local', row_index, new_disposition
+	--     'remote', sender, unique_id, item_id, old_disposition, new_disposition
 	-- In the local case, must also broadcast a trigger.  In the remote case,
 	-- must figure out the corresponding loot entry (if it exists).  In both
 	-- cases, must update history appropriately.  Returns nil if anything odd
@@ -3675,7 +3690,7 @@
 		-- Only set in remote case:
 		local sender
 
-		if how == "local" then
+		if how == 'local' then
 			index, newdisp = ...
 			index = assert(tonumber(index))
 			e = g_loot[index]
@@ -3683,7 +3698,7 @@
 			unique = e.unique   -- can potentially still be nil at this step
 			olddisp = e.disposition
 
-		elseif how == "remote" then
+		elseif how == 'remote' then
 			sender, unique, id, olddisp, newdisp = ...
 			id = tonumber(id)
 			local cache
@@ -3726,7 +3741,7 @@
 		self.hist_clean = nil
 		self.loot_clean = nil
 		-- A unique tag has been set by this point.
-		if how == "local" then
+		if how == 'local' then
 			unique = assert(e.unique)
 			if opts.chatty_on_local_changes then
 				_notify_about_change (_G.UNIT_YOU, index, olddisp)
@@ -3949,5 +3964,6 @@
 	end
 end
 
+addon:MODULE_PROTOTYPE_POINTERS()
 addon.FILES_LOADED = 1
 -- vim:noet
--- a/gui.lua	Sun Aug 19 22:08:17 2012 -0400
+++ b/gui.lua	Wed Aug 22 23:37:24 2012 -0400
@@ -449,9 +449,10 @@
 			e.cols[3].value = ""
 
 		end
+		self.loot_clean = i
 		break
 	end end
-	self.loot_clean = #g_loot
+	--self.loot_clean = #g_loot
 end
 
 do
@@ -1029,12 +1030,21 @@
 		E("Insert new boss kill event", 'df_INSERT', 'boss', "Inserts new event above this one, prompting you for information."),
 		E(CLOSE),
 	}
+	gui.dropdown.eoi_loot_mark = {}
 	gui.dropdown.eoi_loot = {
 		{
 			-- this is the dropdown title, text filled in on the fly
 			notClickable = true,
 			notCheckable = true,
 		},
+		{
+			text = "Mark as...",
+			hasArrow = true,
+			menuList = gui.dropdown.eoi_loot_mark,
+			tooltipOnButton = true,
+			tooltipWhileDisabled = true,
+			notCheckable = true,
+		},
 		E("--"),
 		E("Rebroadcast this loot entry", nil, nil, "Sends this loot event, including special notes, as if it just happened."),
 		E("Delete this loot event", 'df_DELETE', nil, "Permanent, no going back!\n\nHold down the Shift key to also delete the corresponding entry from player's History."),
@@ -1058,6 +1068,7 @@
 			--menuList = filled in in the fly,
 			tooltipOnButton = true,
 			tooltipWhileDisabled = true,
+			notCheckable = true,
 		},
 		E("Show only this player"),
 		E(CLOSE),
@@ -2329,36 +2340,57 @@
 
 -- We need to be able to reference the dropdownmenu locals, and I didn't want to
 -- bubble them up any higher.
-function gui.add_dropdown_entry (menutag, name, func_tbl, func_or_othername, arg, tooltiptext)
-	local emtbl = assert(gui.dropdown[menutag])
-
-	if type(func_tbl) == 'table' then
-		-- use it directly
-	elseif func_tbl == nil then
-		-- determine it from the menu tag
-		func_tbl = (menutag:sub(1,3) == 'eoi' and eoi_dropdownfuncs)
-			or (menutag:sub(1,4) == 'hist' and hist_dropdownfuncs)
-			or error("Cannot figure out function table from menu tag name")
+do
+	-- If the UIDropDownMenu_SetSelected* functions could be used with EasyMenu
+	-- in a sane fashion, we could dispense with the 'checked' field.
+	local function disposition_is_checked (buttonframe)
+		-- arg2 == disp code, GetID == index into dropdown array
+		local i = _d and _d.GetUserData and _d:GetUserData("DD index")
+		if i then
+			return g_loot[i].disposition == buttonframe.arg2
+		end
 	end
 
-	if type(func_or_othername) == 'string' then
-		-- gen_dd_entry handles this
-	elseif type(func_or_othername) == 'function' then
-		error"bah"
+	function gui.add_dropdown_entry (menutag, name, func_tbl, func_or_othername, arg, tooltiptext)
+		local emtbl = assert(gui.dropdown[menutag])
+
+		if type(func_tbl) == 'table' then
+			-- use it directly
+		elseif func_tbl == nil then
+			-- determine it from the menu tag
+			func_tbl = (menutag:sub(1,3) == 'eoi' and eoi_dropdownfuncs)
+				or (menutag:sub(1,4) == 'hist' and hist_dropdownfuncs)
+				or error("Cannot figure out function table from menu tag name")
+		end
+
+		if type(func_or_othername) == 'string' then
+			-- gen_dd_entry handles this
+		elseif type(func_or_othername) == 'function' then
+			error"bah"
+		end
+
+		-- Insert most new entries right under the title
+		local index
+		if menutag == 'eoi_loot' then
+			index = 3
+		elseif menutag == 'eoi_player' then
+			index = 3
+		elseif menutag == 'eoi_loot_mark' then
+			index = #emtbl + 1
+		else
+			index = 2
+		end
+
+		local ent = gen_dd_entry (name, func_tbl, func_or_othername, arg, tooltiptext)
+		tinsert (emtbl, index, ent)
+
+		if menutag == 'eoi_loot_mark' then
+			ent.notCheckable = nil
+			ent.checked = disposition_is_checked
+		end
+
+		return ent
 	end
-
-	local index
-	if menutag == 'eoi_loot' then
-		index = 2
-	elseif menutag == 'eoi_player' then
-		index = 3
-	else
-		index = 2
-	end
-
-	local ent = gen_dd_entry (name, func_tbl, func_or_othername, arg, tooltiptext)
-	tinsert (emtbl, index, ent)
-	return ent
 end