diff gui.lua @ 75:676fb79a4ae2

StaticPopupDialog + Slider = controllable threshold for how far back to preserve events when preening history tables. (Updated preen routine written but not with this commit.)
author Farmbuyer of US-Kilrogg <farmbuyer@gmail.com>
date Fri, 01 Jun 2012 02:17:57 +0000
parents 5edaac60449b
children 124da015c4a2
line wrap: on
line diff
--- a/gui.lua	Thu May 31 00:06:20 2012 +0000
+++ b/gui.lua	Fri Jun 01 02:17:57 2012 +0000
@@ -1637,13 +1637,13 @@
 		specials:AddChild(b)
 
 		b = mkbutton('hist_clear_old', "Clear Older",
-			[[Preserves only the latest loot entry for each player on the displayed realm, removing all earlier ones.]])
+			[[Preserves only the latest loot entries for players on the displayed realm, removing all earlier ones.]])
 		b:SetFullWidth(true)
 		b:SetCallback("OnClick", function (_b)
-			local dialog = StaticPopup_Show("OUROL_HIST_PREEN", addon.history.realm)
+			local dialog = StaticPopup_Show("OUROL_HIST_PREEN", '', addon.history.realm, addon)
 			dialog.data = addon
-			dialog.data2 = function(_addon)
-				_addon:preen_history(_addon.history.realm)
+			dialog.data2 = function (_addon, howmany)
+				_addon:preen_history (_addon.history.realm, howmany)
 				_addon.hist_clean = nil
 				histST:OuroLoot_Refresh()
 			end
@@ -2518,6 +2518,22 @@
 
 
 ------ Popup dialogs
+local function build_my_slider_widget()
+	local s = CreateFrame("Slider", "OuroLootSlider", nil, "OptionsSliderTemplate")
+	s.text = OuroLootSliderText
+	s.low = OuroLootSliderLow
+	s.high = OuroLootSliderHigh
+	s:SetScript("OnValueChanged", function (_s, value)
+		_s.value = value  -- conveniently, this is already of numeric type
+		--_s.text:SetText(tostring(value))
+		if _s.DoOnValueChanged then
+			_s:DoOnValueChanged()
+		end
+	end)
+	build_my_slider_widget = nil
+	return s
+end
+
 StaticPopupDialogs["OUROL_CLEAR"] = flib.StaticPopup{
 	text = "Clear current loot information and text?",
 	button1 = YES,
@@ -2529,7 +2545,8 @@
 
 StaticPopupDialogs["OUROL_HIST_REGEN"] = flib.StaticPopup{
 	-- Concatenate this once at load time.  There is no ITEM_QUALITY_LEGENDARY constant.
-	text = "Erase all history entries from " .. ITEM_QUALITY_COLORS[5].hex .. "%s|r, and generate it anew from current loot?",
+	text = "Erase all history entries from " .. ITEM_QUALITY_COLORS[5].hex
+		.. "%s|r, and generate it anew from current loot?",
 	button1 = YES,
 	button2 = NO,
 	OnAccept = function (dialog, addon, data2)
@@ -2553,14 +2570,65 @@
 
 StaticPopupDialogs["OUROL_HIST_PREEN"] = flib.StaticPopup{
 	-- Concatenate this once at load time.  There is no ITEM_QUALITY_LEGENDARY constant.
-	text = "Erase all but the latest entry for players on " .. ITEM_QUALITY_COLORS[5].hex .. "%s|r?",
+	text = "This will erase all but the latest "
+		.. ITEM_QUALITY_COLORS[ITEM_QUALITY_UNCOMMON].hex
+		.. "%s|r for each player on "
+		.. ITEM_QUALITY_COLORS[5].hex .. "%s|r.  " .. CONTINUE .. "?",
 	button1 = YES,
 	button2 = NO,
-	OnAccept = function (dialog, addon, data2)
-		data2(addon)
-		addon:Print("All loot prior to the most recent entries has been erased.")
+	OnShow = function (dialog, addon)
+		local thistable = StaticPopupDialogs[dialog.which]
+		-- StaticPopup_Resize does not take extraFrame into account, so we
+		-- hook the sizing method that _Resize calls at the end.
+		dialog.saved_setheight = dialog.SetHeight
+		dialog.SetHeight = function (d, h)
+			return d.saved_setheight(d,h+35)
+		end
+		dialog.extraFrame:ClearAllPoints()
+		dialog.extraFrame:SetPoint("TOP", dialog.text, "BOTTOM")
+		dialog.extraFrame:SetWidth(150)
+		dialog.extraFrame:SetHeight(35)
+		dialog.extraFrame:Show()
+		local slider = _G.OuroLootSlider or build_my_slider_widget()
+		slider.DoOnValueChanged = function(s)
+			dialog.text:SetFormattedText (thistable.text,
+				s.value == 1 and "single entry" or (s.value .. " entries"),
+				addon.history.realm)
+			StaticPopup_Resize (dialog, "OUROL_HIST_PREEN")
+		end
+		slider:SetOrientation('HORIZONTAL')
+		slider:SetMinMaxValues(1,30)
+		slider:SetValueStep(1)
+		slider.low:SetText("1")
+		slider.high:SetText("30")
+		--slider.tooltipText = ???
+		slider:SetParent(dialog.extraFrame)
+		slider:ClearAllPoints()
+		slider:SetPoint("TOPLEFT",dialog.extraFrame,"TOPLEFT",0, -15)
+		slider:SetPoint("BOTTOMRIGHT",dialog.extraFrame,"BOTTOMRIGHT",0, 0)
+		slider:Show()
+		-- This causes OnValueChanged to fire, reformatting the text.  Except
+		-- IF the slider has already been shown, and IF at the time it was hidden
+		-- it had the same value here, THEN there is technically no "change"
+		-- and no event is fired.  We work around this clever optimization by
+		-- doing a pair of set's, forcing the last one to fire OVC.
+		slider:SetValue(1)
+		slider:SetValue(5)
+	end,
+	OnAccept = function (dialog, addon, callback)
+		local howmany = assert(tonumber(_G.OuroLootSlider.value))
+		callback (addon, howmany)
+		addon:Print("All loot prior to the most recent %d |4entry:entries; has been erased.", howmany)
 		addon:redisplay()
 	end,
+	OnHide = function (dialog, addon)
+		dialog.SetHeight = nil
+		dialog.saved_setheight = nil
+		dialog.extraFrame:ClearAllPoints()
+		_G.OuroLootSlider:Hide()  -- parent is hidden, why is this required?
+		_G.OuroLootSlider:ClearAllPoints()
+		_G.OuroLootSlider:SetParent(nil)
+	end,
 }
 
 StaticPopupDialogs["OUROL_URL"] = { --flib.StaticPopup{
@@ -2733,8 +2801,8 @@
 -- {rowindex=<GUI row receiving click>, display=_d, kind=<loot/boss>}
 do
 	local t = flib.StaticPopup{
-		text = "Enter name of new %s, then click Next or press Enter:",
-		button1 = "Next >",
+		text = "Enter name of new %s, then click "..CONTINUE.." or press Enter:",
+		button1 = CONTINUE.." ->",
 		button2 = CANCEL,
 		hasEditBox = true,
 		editBoxWidth = 350,
@@ -2759,7 +2827,7 @@
 
 	-- This seems to be gratuitous use of metatables, really.
 	local OEIL = {
-		text = "Paste the new item into here, then click Next or press Enter:",
+		text = "Paste the new item into here, then click "..CONTINUE.." or press Enter:",
 		__index = StaticPopupDialogs["OUROL_EOI_INSERT"]
 	}
 	StaticPopupDialogs["OUROL_EOI_INSERT_LOOT"] = setmetatable(OEIL,OEIL)