changeset 118:ec5174529e0f

Make more use of g_loot.raiders in the GUI rather than calling GRRI each time.
author Farmbuyer of US-Kilrogg <farmbuyer@gmail.com>
date Thu, 16 Aug 2012 23:04:29 -0400
parents dbdab3780757
children a88d485123b8
files core.lua gui.lua
diffstat 2 files changed, 58 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/core.lua	Thu Aug 16 20:00:03 2012 -0400
+++ b/core.lua	Thu Aug 16 23:04:29 2012 -0400
@@ -2173,6 +2173,37 @@
 	return self._find_next_after, filter_kind, 0
 end
 
+-- Iterate through g_loot.raiders in sorted (alphabetical/collated) order.  If
+-- USE_FULLNAME then the realmname is appended.  If ONLINE_FILTER is present,
+-- then only raider entries with a matching 'online' key are included.  Loop
+-- variables are a running count, the raider name, and the corresponding entry
+-- from g_loot.raiders.
+do
+	local function nextr (list, index)
+		index = index + 1
+		local name = list[index]
+		if not name then
+			flib.del(list)
+			return nil
+		end
+		return index, name, list.__safety[name]
+	end
+
+	function addon:sorted_raiders_iter (use_fullname_p, opt_online_filter)
+		local t = flib.new()
+		for name,info in next, g_loot.raiders do
+			if (not opt_online_filter) or (info.online == opt_online_filter) then
+				-- this is not exactly "A?B:C" semantics, but it is exactly
+				-- the behavior we want when fname is not present
+				tinsert (t, use_fullname_p and info.fname or name)
+			end
+		end
+		table.sort(t)
+		t.__safety = g_loot.raiders
+		return nextr, t, 0
+	end
+end
+
 do
 	local itt
 	local function create()
@@ -2245,6 +2276,9 @@
 	if possible_st then
 		possible_st:SetData(g_loot_wrapper)
 	end
+	-- Make sure we have a current .raiders array, since other dropdowns and
+	-- whatnot depend on that information.
+	self:CheckRoster()
 
 	self.status_text = ("%s(r%s) communicating as ident %s commrev %s"):
 		format (self.version, self.revision, self.ident, self.commrev)
--- a/gui.lua	Thu Aug 16 20:00:03 2012 -0400
+++ b/gui.lua	Thu Aug 16 23:04:29 2012 -0400
@@ -160,8 +160,13 @@
 			cols = {},
 		}
 		if real.kind == 'loot' then
-			e.dperson = real.person_realm and
-				(real.person .. FOREIGN_SERVER_LABEL) or real.person
+			if real.person_realm then
+				e.dperson = real.person .. FOREIGN_SERVER_LABEL
+				e.fperson = real.person .. "-" .. real.person_realm
+			else
+				e.dperson = real.person
+				e.fperson = real.person
+			end
 		end
 		setmetatable(e,e)
 		rawset(t,index,e)
@@ -1122,8 +1127,7 @@
 	elseif kind == 'loot' and column == 2 then
 		tt:SetOwner (cellFrame, "ANCHOR_BOTTOMRIGHT", -50, 5)
 		tt:ClearLines()
-		tt:AddLine(("%s Loot:"):format(e.person_realm
-			and (e.person .. "-" .. e.person_realm) or e.person))
+		tt:AddLine(e.fperson .. " Loot:")
 		local counter = 0
 		for i,e2 in ipairs(data) do
 			if e2.person == e.person then  -- would be awesome to test for alts
@@ -1200,15 +1204,16 @@
 
 	elseif kind == 'loot' and column == 2 then
 		local ddep = gui.dropdown.eoi_player
-		ddep[1].text = e.person -- FIXME realm this too
+		ddep[1].text = e.fperson
 		local raiders = {}
-		for i = 1, GetNumRaidMembers() do
-			tinsert (raiders, (GetRaidRosterInfo(i)))
-		end
-		table.sort(raiders)
-		for i = 1, #raiders do
-			local name = raiders[i]
-			raiders[i] = gen_dd_entry (name, eoi_dropdownfuncs, 'df_REASSIGN', name)
+		for i, name, info in addon:sorted_raiders_iter() do
+			raiders[i] = gen_dd_entry (info.fname or name, eoi_dropdownfuncs,
+				'df_REASSIGN', name)
+			if info.online == 'offline' then
+				raiders[i].colorCode = GRAY_FONT_COLOR_CODE
+			elseif info.online == 'no_longer' then
+				raiders[i].colorCode = RED_FONT_COLOR_CODE
+			end
 		end
 		tinsert (raiders, gen_dd_entry ("Enter name...", eoi_dropdownfuncs))
 		tinsert (raiders, gen_dd_entry (CLOSE, eoi_dropdownfuncs))
@@ -1510,15 +1515,15 @@
 		b:SetDisabled(st.Filter == player_filter_all)
 		specials:AddChild(b)
 
-		-- FIXME iterate over the new raiders table instead
 		local people = { "<nobody>" }
-		for i = 1, GetNumRaidMembers() do
-			tinsert(people,(GetRaidRosterInfo(i)))
-		end
-		table.sort(people)
 		local initial
-		for i,n in ipairs(people) do
-			if n == addon.sharder then initial = i end
+		for i, name, info in
+			addon:sorted_raiders_iter (--[[fullnames=]]true, 'online')
+		do
+			tinsert (people, name)
+			if name == addon.sharder then
+				initial = i + 1   -- +1 offset for "nobody"
+			end
 		end
 		b = mkbutton("Dropdown", nil, "",
 			[[If set, items received by this person will be automatically marked as disenchanted.]])