diff gui.lua @ 16:5ee4edd24c13

- new blizz methods for editboxes in dialog popups - initial code for dropdowns in history (not active yet) - hovering and shift-clicking to link out of history - proper confirmations for history rewriting - options checkboxes more grid-like - saved texts get a scrollbar instead of expanding indefinitely (duh) - rearranged savedvars a bit (and added transition code) - stores raider join/leave times and "demographic" info, all for MLEQDKP - minor bugfixes and tweaks
author Farmbuyer of US-Kilrogg <farmbuyer@gmail.com>
date Thu, 25 Aug 2011 00:45:31 +0000
parents 952c3ac0e783
children d929c40cdb09
line wrap: on
line diff
--- a/gui.lua	Sun Jul 17 17:40:00 2011 +0000
+++ b/gui.lua	Thu Aug 25 00:45:31 2011 +0000
@@ -11,7 +11,7 @@
 
 ------ Constants
 local eoi_st_rowheight			= 20
-local eoi_st_displayed_rows		= math.floor(366/eoi_st_rowheight)
+local eoi_st_displayed_rows		= math.floor(416/eoi_st_rowheight) --math.floor(366/eoi_st_rowheight)
 local eoi_st_textured_item_format = "|T%s:"..(eoi_st_rowheight-2).."|t %s[%s]|r%s"
 local eoi_st_otherrow_bgcolortable = {
 	wipe	= { ["r"] = 0.3, ["g"] = 0.3, ["b"] = 0.3},
@@ -214,7 +214,7 @@
 					if e.attempts == 1 then
 						v = "one-shot"
 					else
-						v = ("kill on %d%s attempt"):format(e.attempts, grammar[e.attempts] or "th")
+						v = ("kill on %d%s attempt"):format(e.attempts or 0, grammar[e.attempts] or "th")
 					end
 					v = ("%s (%d:%.2d)"):format(v, math.floor(e.duration/60), math.floor(e.duration%60))
 				elseif e.reason == 'wipe' then
@@ -311,6 +311,7 @@
 				st_entry.kind = 'history'
 				st_entry.OLwho = player.name
 				st_entry.cols = dotcols
+				st_entry.itemlink = ilink  -- for onenter and onclick
 				tinsert (st, st_entry)
 			end
 		end
@@ -414,7 +415,7 @@
 	df_INSERT = function(rowi,text)
 		local which = (text == 'loot') and "OUROL_EOI_INSERT_LOOT" or "OUROL_EOI_INSERT"
 		local dialog = StaticPopup_Show(which,text)
-		dialog.wideEditBox:SetScript("OnTextChanged",StaticPopup_EditBoxOnTextChanged)
+		dialog.editBox:SetScript("OnTextChanged",StaticPopup_EditBoxOnTextChanged)
 		dialog.data = {rowindex=rowi, display=_d, kind=text}
 	end,
 
@@ -424,6 +425,12 @@
 			gone.itemlink or gone.bosskill or gone.startday.text)
 	end,
 
+	["Delete this history event"] = function(rowi)
+		--local gone = tremove(g_loot,rowi)
+		--addon:Print("Removed %s.",
+			--gone.itemlink or gone.bosskill or gone.startday.text)
+	end,
+
 	-- if kind is boss, also need to stop at new timestamp
 	["Delete remaining entries for this day"] = function(rowi,kind)
 		local fencepost
@@ -484,6 +491,7 @@
 	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
 		CloseDropDownMenus()  -- also need to close parent menu
 	end,
 	["Enter name..."] = function(rowi)
@@ -572,6 +580,18 @@
 		"--",
 		CLOSE
 	}, dropdownfuncs)
+local hist_dropdown = gen_easymenu_table(
+	{{
+		-- this is the dropdown title, text filled in on the fly
+		notClickable = true,
+		notCheckable = true,
+	}},
+	{
+		"Delete this history event|Permanent, no going back!",
+		--"Delete remaining entries for this boss%boss|Erases everything from here down until a new boss/day",
+		"--",
+		CLOSE
+	}, dropdownfuncs)
 
 --[[ quoted verbatim from lib-st docs:
 rowFrame This is the UI Frame table for the row.
@@ -589,9 +609,11 @@
 	local e = data[realrow]
 	local kind = e.kind
 
-	if kind == 'loot' and column == 1 then
-		GameTooltip:SetOwner (cellFrame, "ANCHOR_RIGHT", -20, 0)
-		GameTooltip:SetHyperlink (e.itemlink)
+	if (kind == 'loot' and column == 1) or (kind == 'history' and column == 2) then
+		if e.itemlink then
+			GameTooltip:SetOwner (cellFrame, "ANCHOR_RIGHT", -20, 0)
+			GameTooltip:SetHyperlink (e.itemlink)
+		end
 
 	elseif kind == 'loot' and column == 2 then
 		GameTooltip:SetOwner (cellFrame, "ANCHOR_BOTTOMRIGHT", -50, 5)
@@ -638,7 +660,9 @@
 	local kind = e.kind
 
 	-- Check for shift-clicking a loot line
-	if IsModifiedClick("CHATLINK") and kind == 'loot' and column == 1 then
+	if IsModifiedClick("CHATLINK") and
+	   ((kind == 'loot' and column == 1) or (kind == 'history' and column == 2))
+	then
 		ChatEdit_InsertLink (e.itemlink)
 		return true  -- do not do anything further
 	end
@@ -682,6 +706,10 @@
 		eoi_time_dropdown[1].text = e.startday.text
 		EasyMenu (eoi_time_dropdown, dropdownmenuframe, cellFrame, 0, 0, "MENU")
 
+	elseif kind == 'history' then  -- XXX need to move this into new onclick handler
+		_d:SetUserData("DD loot cell", cellFrame)
+		hist_dropdown[1].text = e.itemlink
+		EasyMenu (hist_dropdown, dropdownmenuframe, cellFrame, 0, 0, "MENU")
 	end
 
 	return true  -- do not do anything further
@@ -1194,23 +1222,27 @@
 			specials:AddChild(b)
 
 			b = mkbutton('hist_clear', "Clear Realm History",
-				[[No confirmation!  |cffff1010Erases absolutely all> history entries from the displayed realm.]])
+				[[|cffff1010Erases absolutely all> history entries from the displayed realm.]])
 			b:SetFullWidth(true)
 			b:SetCallback("OnClick", function (_b)
-				reset_current_realm(addon.history.realm)
-				addon:Print("Stimpy, you eeediot, you've pushed the history erase button!")
-				return addon:redisplay()
+				local dialog = StaticPopup_Show("OUROL_HIST_CLEAR", addon.history.realm)
+				dialog.data = addon
+				dialog.data2 = function(_addon)
+					reset_current_realm(_addon.history.realm)
+				end
 			end)
 			specials:AddChild(b)
 
 			b = mkbutton('hist_clear_all', "Clear All History",
-				[[No confirmation!  |cffff1010Erases absolutely all> history entries from ALL realms.]])
+				[[|cffff1010Erases absolutely all> history entries from ALL realms.]])
 			b:SetFullWidth(true)
 			b:SetCallback("OnClick", function (_b)
-				addon.history_all = {}
-				reset_current_realm()
-				addon:Print("Stimpy, you eeediot, you've pushed the history erase button!")
-				return addon:redisplay()
+				local dialog = StaticPopup_Show("OUROL_HIST_CLEAR", "ALL realms")
+				dialog.data = addon
+				dialog.data2 = function(_addon)
+					_addon.history_all = {}
+					reset_current_realm()
+				end
 			end)
 			specials:AddChild(b)
 
@@ -1218,11 +1250,13 @@
 				[[Preserves only the latest loot entry for each player on the displayed realm, removing all earlier ones.]])
 			b:SetFullWidth(true)
 			b:SetCallback("OnClick", function (_b)
-				addon:preen_history(addon.history.realm)
-				addon:Print("All loot prior to the most recent entries has been erased.")
-				addon.hist_clean = nil
-				histST:OuroLoot_Refresh()
-				return addon:redisplay()
+				local dialog = StaticPopup_Show("OUROL_HIST_PREEN", addon.history.realm)
+				dialog.data = addon
+				dialog.data2 = function(_addon)
+					_addon:preen_history(_addon.history.realm)
+					_addon.hist_clean = nil
+					histST:OuroLoot_Refresh()
+				end
 			end)
 			specials:AddChild(b)
 		end
@@ -1462,32 +1496,32 @@
 		-- that turned out to look messy.  Now they're just a straight line for the most part.
 
 		-- reminder popup
-		w = mkoption ('popup_on_join', "Show reminder popup", 0.95,
+		w = mkoption ('popup_on_join', "Show reminder popup", 0.49,
 			[[When joining a raid and not already tracking, display a dialog asking for instructions.]])
 		grp:AddChild(w)
 
 		-- toggle scroll-to-bottom on first tab
-		w = mkoption('scroll_to_bottom', "Scroll to bottom when opening display", 0.95,
+		w = mkoption('scroll_to_bottom', "Scroll to bottom when opening display", 0.49,
 			[[Scroll to the bottom of the loot window (most recent entries) when displaying the GUI.]])
 		grp:AddChild(w)
 
 		-- /loot option
-		w = mkoption('register_slashloot', "Register /loot slash command on login", 0.95,
+		w = mkoption('register_slashloot', "Register /loot slash command on login", 0.49,
 			[[Register "/loot" as a slash command in addition to the normal "/ouroloot".  Relog to take effect.]])
 		grp:AddChild(w)
 
 		-- chatty mode
-		w = mkoption('chatty_on_kill', "Be chatty on boss kill", 0.95,
+		w = mkoption('chatty_on_kill', "Be chatty on boss kill", 0.49,
 			[[Print something to chat output when DBM tells Ouro Loot about a successful boss kill.]])
 		grp:AddChild(w)
 
 		-- less noise in main panel
-		w = mkoption('no_tracking_wipes', "Do not track wipes", 0.95,
+		w = mkoption('no_tracking_wipes', "Do not track wipes", 0.49,
 			[[Do not add 'wipe' entries on the main loot grid, or generate any text for them.]])
 		grp:AddChild(w)
 
 		-- cutesy abbrevs
-		w = mkoption('snarky_boss', "Use snarky boss names", 0.95,
+		w = mkoption('snarky_boss', "Use snarky boss names", 0.49,
 			[[Irreverent replacement names for boss events.]])
 		grp:AddChild(w)
 
@@ -1701,7 +1735,7 @@
 	display:SetTitle("Ouro Loot")
 	display:SetStatusText(self.status_text)
 	display:SetLayout("Flow")
-	display:SetStatusTable{width=900}
+	display:SetStatusTable{width=900,height=550}   -- default height is 500
 	-- prevent resizing, also see ace3 tickets 80 and 214
 	-- grrrr, no longer works after frame rewrite
 	--[[
@@ -1780,7 +1814,7 @@
 
 	b = GUI:Create("Spacer")
 	b:SetFullWidth(true)
-	b:SetHeight(15)
+	b:SetHeight(10)
 	control:AddChild(b)
 
 	--[[
@@ -1804,30 +1838,42 @@
 	end)
 	control:AddChild(b)
 
-	local saved = self:check_saved_table(--[[silent_on_empty=]]true)
-	if saved then for i,s in ipairs(saved) do
-		local il = GUI:Create("InteractiveLabel")
-		il:SetFullWidth(true)
-		il:SetText(s.name)
-		il:SetUserData("num",i)
-		il:SetHighlight(1,1,1,0.4)
-		local str = ("%s    %d entries     %s"):format(s.date,s.count,s.name)
-		il:SetCallback("OnEnter", function() setstatus(str) end)
-		il:SetCallback("OnLeave", statusy_OnLeave)
-		il:SetCallback("OnClick", function(_il)
-			local prev = _d:GetUserData("saved selection")
-			if prev then
-				prev.highlight:Hide()
-				prev:SetColor()
-			end
-			_il:SetColor(0,1,0)
-			_il.highlight:Show()
-			_d:SetUserData("saved selection",_il)
-			_d:GetUserData("Load"):SetDisabled(false)
-			_d:GetUserData("Delete"):SetDisabled(false)
-		end)
-		control:AddChild(il)
-	end end
+	do
+		local scontainer = GUI:Create("SimpleGroup")
+		scontainer:SetFullWidth(true)
+		scontainer:SetFullHeight(false)
+		scontainer:SetAutoAdjustHeight(false)
+		scontainer:SetHeight(40)  -- no relative height available anymore
+		scontainer:SetLayout("Fill")
+		local scroll = GUI:Create("ScrollFrame")
+		scroll:SetLayout("List")
+		local saved = self:check_saved_table(--[[silent_on_empty=]]true)
+		if saved then for i,s in ipairs(saved) do
+			local il = GUI:Create("InteractiveLabel")
+			il:SetFullWidth(true)
+			il:SetText(s.name)
+			il:SetUserData("num",i)
+			il:SetHighlight(1,1,1,0.4)
+			local str = ("%s    %d entries     %s"):format(s.date,s.count,s.name)
+			il:SetCallback("OnEnter", function() setstatus(str) end)
+			il:SetCallback("OnLeave", statusy_OnLeave)
+			il:SetCallback("OnClick", function(_il)
+				local prev = _d:GetUserData("saved selection")
+				if prev then
+					prev.highlight:Hide()
+					prev:SetColor()
+				end
+				_il:SetColor(0,1,0)
+				_il.highlight:Show()
+				_d:SetUserData("saved selection",_il)
+				_d:GetUserData("Load"):SetDisabled(false)
+				_d:GetUserData("Delete"):SetDisabled(false)
+			end)
+			scroll:AddChild(il)
+		end end
+		scontainer:AddChild(scroll)
+		control:AddChild(scontainer)
+	end
 
 	b = mkbutton("Load",
 		[[Load previously saved text.  +REPLACES> all current loot information!]])
@@ -1852,7 +1898,7 @@
 
 	b = GUI:Create("Spacer")
 	b:SetFullWidth(true)
-	b:SetHeight(15)
+	b:SetHeight(10)
 	control:AddChild(b)
 
 	-- Other stuff on right-hand side
@@ -1930,7 +1976,7 @@
 		return
 	end
 
-	local text = dialog.wideEditBox:GetText()
+	local text = dialog.editBox:GetText()
 
 	-- second click
 	if data.name and text then
@@ -1945,7 +1991,7 @@
 		data.name = text
 		local getinstance = StaticPopup_Show("OUROL_EOI_INSERT","instance")
 		getinstance.data = data
-		getinstance.wideEditBox:SetText(addon.instance_tag())
+		getinstance.editBox:SetText(addon.instance_tag())
 		-- This suppresses auto-hide (which would case the getinstance dialog
 		-- to go away), but only when mouse clicking.  OnEnter is on its own.
 		return true
@@ -1969,7 +2015,7 @@
 		return
 	end
 
-	local text = dialog.wideEditBox:GetText():trim()
+	local text = dialog.editBox:GetText():trim()
 
 	-- third click
 	if data.name and data.recipient and text then
@@ -1983,8 +2029,8 @@
 		data.recipient = text
 		local getnotes = StaticPopup_Show("OUROL_EOI_INSERT","notes")
 		getnotes.data = data
-		getnotes.wideEditBox:SetText("<none>")
-		getnotes.wideEditBox:HighlightText()
+		getnotes.editBox:SetText("<none>")
+		getnotes.editBox:HighlightText()
 		return true
 	end
 
@@ -1994,7 +2040,7 @@
 		dialog:Hide()  -- technically a "different" one about to be shown
 		local getrecipient = StaticPopup_Show("OUROL_EOI_INSERT","recipient")
 		getrecipient.data = data
-		getrecipient.wideEditBox:SetText("")
+		getrecipient.editBox:SetText("")
 		return true
 	end
 end
@@ -2009,13 +2055,35 @@
 
 StaticPopupDialogs["OUROL_CLEAR"] = flib.StaticPopup{
 	text = "Clear current loot information and text?",
-	button1 = ACCEPT,
-	button2 = CANCEL,
+	button1 = YES,
+	button2 = NO,
 	OnAccept = function (dialog, addon)
 		addon:Clear(--[[verbose_p=]]true)
 	end,
 }
 
+StaticPopupDialogs["OUROL_HIST_CLEAR"] = flib.StaticPopup{
+	text = "Erase all history entries from %s?",
+	button1 = YES,
+	button2 = NO,
+	OnAccept = function (dialog, addon, data2)
+		data2(addon)
+		addon:Print("Stimpy, you eeediot, you've pushed the history erase button!")
+		addon:redisplay()
+	end,
+}
+
+StaticPopupDialogs["OUROL_HIST_PREEN"] = flib.StaticPopup{
+	text = "Erase all but the latest entry for players on %s?",
+	button1 = YES,
+	button2 = NO,
+	OnAccept = function (dialog, addon, data2)
+		data2(addon)
+		addon:Print("All loot prior to the most recent entries has been erased.")
+		addon:redisplay()
+	end,
+}
+
 StaticPopupDialogs["OUROL_REMIND"] = flib.StaticPopup{
 	text = "Do you wish to activate Ouro Loot?\n\n(Hit the Escape key to close this window without clicking)",
 	button1 = "Activate recording",  -- "accept", left
@@ -2050,7 +2118,7 @@
 		button1 = "Next >",
 		button2 = CANCEL,
 		hasEditBox = true,
-		hasWideEditBox = true,
+		editBoxWidth = 350,
 		maxLetters = 50,
 		noCancelOnReuse = true,
 		--[[ XXX still needed?
@@ -2081,7 +2149,7 @@
 	hooksecurefunc("ChatEdit_InsertLink", function (link,...)
 		local dialogname = StaticPopup_Visible "OUROL_EOI_INSERT_LOOT"
 		if dialogname then
-			_G[dialogname.."WideEditBox"]:SetText(link)
+			_G[dialogname.."EditBox"]:SetText(link)
 			return true
 		end
 	end)
@@ -2101,6 +2169,7 @@
 		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)
 		data.display:GetUserData("eoiST"):OuroLoot_Refresh(data.index)
 	end,