changeset 78:f8118aa5fbb8

Manually inserting loot entries now (1) uses autocomplete dropdowns for the recipient name (raid members if in a raid, online guild members otherwise), and (2) adds a rebroadcasting hyperlink to the text response. Clicking the link rebroadcasts just like the context menu.
author Farmbuyer of US-Kilrogg <farmbuyer@gmail.com>
date Tue, 12 Jun 2012 03:46:00 +0000
parents a07c9dd79f3a
children 0235a1695b83
files core.lua gui.lua
diffstat 2 files changed, 48 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/core.lua	Mon Jun 11 21:03:16 2012 +0000
+++ b/core.lua	Tue Jun 12 03:46:00 2012 +0000
@@ -382,9 +382,12 @@
 	-- COLOR can be ITEM_QUALITY_* or a formatting string ("|cff...")
 	-- FUNC can be "MethodName", "tab_title", or a function
 	--
-	-- Returns an obaque token.  Calling tostring() on the token will yield a
-	-- formatted clickable string that can be displayed in chat.  This is
-	-- largely an excuse to fool around with Lua data constructs.
+	-- Returns an opaque token and a matching number.  Calling tostring() on
+	-- the token will yield a formatted clickable string that can be displayed
+	-- in chat.  The MethodName and raw function callbacks will both be
+	-- passed the addon table and the same matching number.
+	--
+	-- This is largely an excuse to fool around with Lua data constructs.
 	function addon.format_hypertext (text, color, func)
 		local ret = _G.newproxy(base)
 		local num = #text_map + 1
@@ -393,7 +396,7 @@
 				text)
 		text_map[num] = ret
 		func_map[ret] = func
-		return ret
+		return ret, num
 	end
 
 	--[[
@@ -408,12 +411,13 @@
 	DEFAULT_CHAT_FRAME:HookScript("OnHyperlinkClick", function(self, link, fullstring, mousebutton)
 		local ltype, arg = strsplit(":",link)
 		if ltype ~= "OuroLoot" then return end
-		local f = func_map[text_map[tonumber(arg)]]
+		arg = tonumber(arg)
+		local f = func_map[text_map[arg]]
 		if type(f) == 'function' then
-			f()
+			f (addon, arg)
 		elseif type(f) == 'string' then
 			if type(addon[f]) == 'function' then
-				addon[f](addon)             -- method name
+				addon[f](addon,arg)         -- method name
 			else
 				addon:BuildMainDisplay(f)   -- tab title fragment
 			end
@@ -1666,7 +1670,7 @@
 			self.dprint('flow', ">:Activate restored generated texts, un-popping")
 			return
 		end
-		self:Print("Ouro Raid Loot restored previous data, but not in a raid",
+		self:Print("Restored previous data, but not in a raid",
 				"and 5-player mode not active.  |cffff0505NOT tracking loot|r;",
 				"use 'enable' to activate loot tracking, or 'clear' to erase",
 				"previous data, or 'help' to read about saved-texts commands.")
@@ -3171,16 +3175,16 @@
 	OCR_funcs['17boss'] = OCR_funcs['16boss']
 
 	local bcast_on = addon.format_hypertext ([[the red pill]], '|cffff4040',
-		function()
-			if not addon.rebroadcast then
-				addon:Activate(nil,true)
+		function (self)
+			if not self.rebroadcast then
+				self:Activate(nil,true)
 			end
-			addon:broadcast('bcast_responder')
+			self:broadcast('bcast_responder')
 		end)
 	local waferthin = addon.format_hypertext ([[the blue pill]], '|cff0070dd',
-		function()
+		function (self)
 			g_wafer_thin = true               -- mint? it's wafer thin!
-			addon:broadcast('bcast_denied')   -- fuck off, I'm full
+			self:broadcast('bcast_denied')   -- fuck off, I'm full
 		end)
 	OCR_funcs.bcast_req = function (sender)
 		if addon.debug.comm or ((not g_wafer_thin) and (not addon.rebroadcast))
--- a/gui.lua	Mon Jun 11 21:03:16 2012 +0000
+++ b/gui.lua	Tue Jun 12 03:46:00 2012 +0000
@@ -66,11 +66,13 @@
 
 local pprint, tabledump = addon.pprint, flib.tabledump
 local GetItemInfo, ITEM_QUALITY_COLORS = GetItemInfo, ITEM_QUALITY_COLORS
+local GetNumRaidMembers = GetNumRaidMembers
 
 -- 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 eoi_dropdownfuncs, _tabtexts, _taborder -- filled out in gui block scope
 local _do_debugging_tooltip, _hide_debugging_tooltip, _build_debugging_tooltip
+local _new_rebroadcast_hyperlink
 
 --[[
 This is a table of callback functions, each responsible for drawing a tab
@@ -600,6 +602,26 @@
 	end
 end
 
+do
+	local rebroadcast_map  -- XXX weaken this somehow?
+
+	local function onclick (self, ident)
+		local data = assert(rebroadcast_map[ident])
+		eoi_dropdownfuncs["Rebroadcast this loot entry"](data.rowindex)
+		-- XXX delete the entry maybe?
+	end
+
+	function _new_rebroadcast_hyperlink (data)
+		rebroadcast_map = rebroadcast_map or flib.new()
+		local clicky, ident = addon.format_hypertext(
+			-- same color sequence as what DBM uses to announce pizza timers,
+			-- which looks reasonably pleasing
+			[[Broadcast this entry]], "|cff3588ff", onclick)
+		rebroadcast_map[ident] = data
+		return clicky
+	end
+end
+
 
 ------ Main GUI Window
 local _d   -- display when it's open, eoiST when it's not
@@ -746,7 +768,6 @@
 
 -- Tab 1:  Events Of Interest
 -- This actually takes up quite a bit of the file.
-local eoi_dropdownfuncs
 eoi_dropdownfuncs = dropdownfuncs{
 	df_INSERT = function(rowi,text)
 		local which = (text == 'loot') and "OUROL_EOI_INSERT_LOOT" or "OUROL_EOI_INSERT"
@@ -2720,7 +2741,7 @@
 		addon:_mark_boss_kill(data.rowindex)
 		data.display:GetUserData("eoiST"):OuroLoot_Refresh(data.rowindex)
 		dialog.data = nil   -- free up memory
-		addon:Print("Inserted %s %s (entry %d).", data.kind, data.name, data.rowindex)
+		addon:Print("Inserted %s %s at entry %d.", data.kind, data.name, data.rowindex)
 		return
 	end
 
@@ -2764,18 +2785,16 @@
 
 local function eoi_st_insert_OnAccept_loot (dialog, data)
 	if data.all_done then
-		--local real_rebroadcast, real_enabled = addon.rebroadcast, addon.enabled
-		--g_rebroadcast, g_enabled = false, true
 		data.display:Hide()
 		local loot_index = assert(addon:CHAT_MSG_LOOT ("manual", data.recipient, data.name, data.notes))
-		--g_rebroadcast, g_enabled = real_g_rebroadcast, real_g_enabled
 		local entry = tremove(g_loot,loot_index)
 		tinsert(g_loot,data.rowindex,entry)
-		--data.display:GetUserData("eoiST"):OuroLoot_Refresh(data.rowindex)
 		addon:_fill_out_eoi_data(data.rowindex)
 		addon:BuildMainDisplay()
+		local clicky = _new_rebroadcast_hyperlink (data)
 		dialog.data = nil
-		addon:Print("Inserted %s %s (entry %d).", data.kind, data.name, data.rowindex)
+		addon:Print ("Inserted %s %s at entry %d.  %s",
+			data.kind, data.name, data.rowindex, tostring(clicky))
 		return
 	end
 
@@ -2802,7 +2821,10 @@
 	if text then
 		data.name = text
 		dialog:Hide()  -- technically a "different" one about to be shown
+		StaticPopupDialogs["OUROL_EOI_INSERT"].autoCompleteParams =
+			AUTOCOMPLETE_LIST_TEMPLATES[GetNumRaidMembers() > 0 and "IN_GROUP" or "IN_GUILD"]
 		local getrecipient = StaticPopup_Show("OUROL_EOI_INSERT","recipient")
+		StaticPopupDialogs["OUROL_EOI_INSERT"].autoCompleteParams = nil
 		getrecipient.data = data
 		getrecipient.editBox:SetText("")
 		return true
@@ -2828,11 +2850,6 @@
 		editBoxWidth = 350,
 		maxLetters = 50,
 		noCancelOnReuse = true,
-		--[[ XXX still needed?
-		OnShow = function(dialog)
-			dialog.wideEditBox:SetText("")
-			dialog.wideEditBox:SetFocus()
-		end,]]
 	}
 	t.EditBoxOnEnterPressed = function(editbox)
 		if editbox:GetText() == "" then return end