diff Libs/DF/fw.lua @ 20:dc1c77254f80

- added close button to users panel. - framework update.
author Tercio
date Tue, 11 Aug 2015 12:46:46 -0300
parents 680465749fc7
children dbd417f413a8
line wrap: on
line diff
--- a/Libs/DF/fw.lua	Sat Jul 18 17:32:30 2015 -0300
+++ b/Libs/DF/fw.lua	Tue Aug 11 12:46:46 2015 -0300
@@ -1,13 +1,13 @@
 
-local major, minor = "DetailsFramework-1.0", 3
+local major, minor = "DetailsFramework-1.0", 5
 local DF, oldminor = LibStub:NewLibrary (major, minor)
 
 if (not DF) then
-	DetailsFrameWorkLoadValid = false
+	DetailsFrameworkCanLoad = false
 	return 
 end
 
-DetailsFrameWorkLoadValid = true
+DetailsFrameworkCanLoad = true
 
 local _type = type
 local _unpack = unpack
@@ -38,6 +38,9 @@
 
 DF.embeds = DF.embeds or {}
 local embed_functions = {
+	"RemoveRealName",
+	"table",
+	"BuildDropDownFontList",
 	"SetFontSize",
 	"SetFontFace",
 	"SetFontColor",
@@ -55,6 +58,7 @@
 	"ShowTutorialAlertFrame",
 	"GetNpcIdFromGuid",
 	"ShowFeedbackPanel",
+	"SetAsOptionsPanel",
 	
 	"CreateDropDown",
 	"CreateButton",
@@ -75,10 +79,77 @@
 	"CreateTextEntry",
 	"Create1PxPanel",
 	"CreateFeedbackButton",
-	
+	"CreateOptionsFrame",
+	"ShowPromptPanel",
 	"www_icons",
 }
 
+DF.table = {}
+
+function DF.table.reverse (t)
+	local new = {}
+	local index = 1
+	for i = #t, 1, -1 do
+		new [index] = t[i]
+		index = index + 1
+	end
+	return new
+end
+
+--> copy from table2 to table1 overwriting values
+function DF.table.copy (t1, t2)
+	for key, value in pairs (t2) do 
+		if (type (value) == "table") then
+			t1 [key] = t1 [key] or {}
+			DF.table.copy (t1 [key], t2 [key])
+		else
+			t1 [key] = value
+		end
+	end
+	return t1
+end
+
+--> copy values that does exist on table2 but not on table1
+function DF.table.deploy (t1, t2)
+	for key, value in pairs (t2) do 
+		if (type (value) == "table") then
+			t1 [key] = t1 [key] or {}
+			DF.table.deploy (t1 [key], t2 [key])
+		elseif (not t1 [key]) then
+			t1 [key] = value
+		end
+	end
+end
+
+function DF.table.dump (t, s, deep)
+	s = s or ""
+	deep = deep or 0
+	local space = ""
+	for i = 1, deep do
+		space = space .. "   "
+	end
+	for key, value in pairs (t) do
+		local tpe = _type (value)
+		if (type (key) ~= "string") then
+			key = "unknown?"
+		end		
+		if (tpe == "table") then
+			s = s .. space .. "[" .. key .. "] = |cFFa9ffa9table {|r\n"
+			s = s .. DF.table.dump (value, nil, deep+1)
+			s = s .. space .. "|cFFa9ffa9}|r\n"
+		elseif (tpe == "string") then
+			s = s .. space .. "[" .. key .. "] = '|cFFfff1c1" .. value .. "|r'\n"
+		elseif (tpe == "number") then
+			s = s .. space .. "[" .. key .. "] = |cFFffc1f4" .. value .. "|r\n"
+		elseif (tpe == "function") then
+			s = s .. space .. "[" .. key .. "] = function()\n"
+		elseif (tpe == "boolean") then
+			s = s .. space .. "[" .. key .. "] = |cFF99d0ff" .. (value and "true" or "false") .. "|r\n"
+		end
+	end
+	return s
+end
+
 DF.www_icons = {
 	texture = "feedback_sites",
 	wowi = {0, 0.7890625, 0, 37/128},
@@ -94,6 +165,10 @@
 	return target
 end
 
+function DF:RemoveRealName (name)
+	return name:gsub (("%-.*"), "")
+end
+
 function DF:SetFontSize (fontString, ...)
 	local fonte, _, flags = fontString:GetFont()
 	fontString:SetFont (fonte, max (...), flags)
@@ -492,7 +567,7 @@
 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 --> menus
 	
-	function DF:BuildMenu (parent, menu, x_offset, y_offset, height)
+	function DF:BuildMenu (parent, menu, x_offset, y_offset, height, use_two_points)
 		
 		local cur_x = x_offset
 		local cur_y = y_offset
@@ -503,10 +578,22 @@
 		
 		for index, widget_table in ipairs (menu) do 
 		
-			if (widget_table.type == "select" or widget_table.type == "dropdown") then
-				local dropdown = self:NewDropDown (parent, nil, "$parentWidget" .. index, nil, 140, 18, widget_table.values, widget_table.get())
+			if (widget_table.type == "blank" or widget_table.type == "space") then
+				-- do nothing
+		
+			elseif (widget_table.type == "label" or widget_table.type == "text") then
+				local label = DF:CreateLabel (parent, widget_table.get() or widget_table.text, widget_table.text_template or widget_table.size, widget_table.color, widget_table.font, nil, "$parentWidget" .. index, "overlay")
+				label._get = widget_table.get
+				label.widget_type = "label"
+				label:SetPoint (cur_x, cur_y)
+				tinsert (parent.widget_list, label)
+			
+			elseif (widget_table.type == "select" or widget_table.type == "dropdown") then
+				local dropdown = DF:NewDropDown (parent, nil, "$parentWidget" .. index, nil, 140, 18, widget_table.values, widget_table.get())
 				dropdown.tooltip = widget_table.desc
-				local label = self:NewLabel (parent, nil, "$parentLabel" .. index, nil, widget_table.name, "GameFontNormal", 12)
+				dropdown._get = widget_table.get
+				dropdown.widget_type = "select"
+				local label = DF:NewLabel (parent, nil, "$parentLabel" .. index, nil, widget_table.name .. (use_two_points and ": " or ""), "GameFontNormal", widget_table.text_template or 12)
 				dropdown:SetPoint ("left", label, "right", 2)
 				label:SetPoint (cur_x, cur_y)
 				
@@ -515,12 +602,16 @@
 					max_x = size
 				end
 				
+				tinsert (parent.widget_list, dropdown)
+				
 			elseif (widget_table.type == "toggle" or widget_table.type == "switch") then
-				local switch = self:NewSwitch (parent, nil, "$parentWidget" .. index, nil, 60, 20, nil, nil, widget_table.get())
+				local switch = DF:NewSwitch (parent, nil, "$parentWidget" .. index, nil, 60, 20, nil, nil, widget_table.get())
 				switch.tooltip = widget_table.desc
+				switch._get = widget_table.get
+				switch.widget_type = "toggle"
 				switch.OnSwitch = widget_table.set
 				
-				local label = self:NewLabel (parent, nil, "$parentLabel" .. index, nil, widget_table.name, "GameFontNormal", 12)
+				local label = DF:NewLabel (parent, nil, "$parentLabel" .. index, nil, widget_table.name .. (use_two_points and ": " or ""), "GameFontNormal", widget_table.text_template or 12)
 				switch:SetPoint ("left", label, "right", 2)
 				label:SetPoint (cur_x, cur_y)
 				
@@ -529,13 +620,17 @@
 					max_x = size
 				end
 				
+				tinsert (parent.widget_list, switch)
+				
 			elseif (widget_table.type == "range" or widget_table.type == "slider") then
 				local is_decimanls = widget_table.usedecimals
-				local slider = self:NewSlider (parent, nil, "$parentWidget" .. index, nil, 140, 20, widget_table.min, widget_table.max, widget_table.step, widget_table.get(),  is_decimanls)
+				local slider = DF:NewSlider (parent, nil, "$parentWidget" .. index, nil, 140, 20, widget_table.min, widget_table.max, widget_table.step, widget_table.get(),  is_decimanls)
 				slider.tooltip = widget_table.desc
+				slider._get = widget_table.get
+				slider.widget_type = "range"
 				slider:SetHook ("OnValueChange", widget_table.set)
 				
-				local label = self:NewLabel (parent, nil, "$parentLabel" .. index, nil, widget_table.name, "GameFontNormal", 12)
+				local label = DF:NewLabel (parent, nil, "$parentLabel" .. index, nil, widget_table.name .. (use_two_points and ": " or ""), "GameFontNormal", widget_table.text_template or 12)
 				slider:SetPoint ("left", label, "right", 2)
 				label:SetPoint (cur_x, cur_y)
 				
@@ -544,9 +639,13 @@
 					max_x = size
 				end
 				
+				tinsert (parent.widget_list, slider)
+				
 			elseif (widget_table.type == "color" or widget_table.type == "color") then
-				local colorpick = self:NewColorPickButton (parent, "$parentWidget" .. index, nil, widget_table.set)
+				local colorpick = DF:NewColorPickButton (parent, "$parentWidget" .. index, nil, widget_table.set)
 				colorpick.tooltip = widget_table.desc
+				colorpick._get = widget_table.get
+				colorpick.widget_type = "color"
 
 				local default_value, g, b, a = widget_table.get()
 				if (type (default_value) == "table") then
@@ -555,7 +654,7 @@
 					colorpick:SetColor (default_value, g, b, a)
 				end
 				
-				local label = self:NewLabel (parent, nil, "$parentLabel" .. index, nil, widget_table.name, "GameFontNormal", 12)
+				local label = DF:NewLabel (parent, nil, "$parentLabel" .. index, nil, widget_table.name .. (use_two_points and ": " or ""), "GameFontNormal", widget_table.text_template or 12)
 				colorpick:SetPoint ("left", label, "right", 2)
 				label:SetPoint (cur_x, cur_y)
 				
@@ -564,18 +663,23 @@
 					max_x = size
 				end
 				
+				tinsert (parent.widget_list, colorpick)
+				
 			elseif (widget_table.type == "execute" or widget_table.type == "button") then
 			
-				local button = self:NewButton (parent, nil, "$parentWidget", nil, 120, 18, widget_table.func, widget_table.param1, widget_table.param2, nil, widget_table.name)
+				local button = DF:NewButton (parent, nil, "$parentWidget", nil, 120, 18, widget_table.func, widget_table.param1, widget_table.param2, nil, widget_table.name)
 				button:InstallCustomTexture()
 				button:SetPoint (cur_x, cur_y)
 				button.tooltip = widget_table.desc
+				button.widget_type = "execute"
 				
 				local size = button:GetWidth() + 4
 				if (size > max_x) then
 					max_x = size
 				end
 				
+				tinsert (parent.widget_list, button)
+				
 			end
 		
 			if (widget_table.spacement) then
@@ -663,6 +767,34 @@
 		DetailsTutorialAlertFrame_SlideInFrame (TutorialAlertFrame, "AUTOQUEST")
 	end
 	
+	local refresh_options = function (self)
+		for _, widget in ipairs (self.widget_list) do
+			if (widget._get) then
+				if (widget.widget_type == "label") then
+					if (widget._get()) then
+						widget:SetText (widget._get())
+					end
+				elseif (widget.widget_type == "select") then
+					widget:Select (widget._get())
+				elseif (widget.widget_type == "toggle" or widget.widget_type == "range") then
+					widget:SetValue (widget._get())
+				elseif (widget.widget_type == "color") then
+					local default_value, g, b, a = widget._get()
+					if (type (default_value) == "table") then
+						widget:SetColor (unpack (default_value))
+					else
+						widget:SetColor (default_value, g, b, a)
+					end
+				end
+			end
+		end
+	end
+	
+	function DF:SetAsOptionsPanel (frame)
+		frame.RefreshOptions = refresh_options
+		frame.widget_list = {}
+	end
+	
 	function DF:CreateOptionsFrame (name, title, template)
 	
 		template = template or 1
@@ -671,6 +803,8 @@
 			local options_frame = CreateFrame ("frame", name, UIParent, "ButtonFrameTemplate")
 			tinsert (UISpecialFrames, name)
 			options_frame:SetSize (500, 200)
+			options_frame.RefreshOptions = refresh_options
+			options_frame.widget_list = {}
 			
 			options_frame:SetScript ("OnMouseDown", function(self, button)
 				if (button == "RightButton") then
@@ -709,6 +843,8 @@
 			local options_frame = CreateFrame ("frame", name, UIParent)
 			tinsert (UISpecialFrames, name)
 			options_frame:SetSize (500, 200)
+			options_frame.RefreshOptions = refresh_options
+			options_frame.widget_list = {}
 
 			options_frame:SetScript ("OnMouseDown", function(self, button)
 				if (button == "RightButton") then