Quantcast

Starting to piece together display options.

Scott Sibley [08-22-10 - 08:51]
Starting to piece together display options.
Filename
Modules/LCDDisplay.lua
StarTip.toc
config.lua
diff --git a/Modules/LCDDisplay.lua b/Modules/LCDDisplay.lua
index 7da9372..b6de5c9 100644
--- a/Modules/LCDDisplay.lua
+++ b/Modules/LCDDisplay.lua
@@ -6,13 +6,326 @@ local Evaluator = LibStub("StarLibEvaluator-1.0")
 local LibCore = LibStub("StarLibCore-1.0")
 local LibLCDText = LibStub("StarLibLCDText-1.0")
 local LibDriverQTip = LibStub("StarLibDriverQTip-1.0")
+local WidgetText = LibStub("StarLibWidgetText-1.0")
+local LayoutOptions = LibStub("StarLibLayoutOptions-1.0")

 local _G = _G
 local GameTooltip = _G.GameTooltip
-local cores = {}
-local coresDict = {}
-local config = {}
-local defaults = {profile= {cores={}}}
+
+local function copy(tbl)
+	local new = {}
+	for k, v in pairs(tbl) do
+		if type(v) == "table" then
+			new[k] = copy(v)
+		else
+			new[k] = v
+		end
+	end
+	return new
+end
+
+local defaults = {profile= {config=copy(StarTip.config)}}
+local displays = {}
+
+local options
+local blankOptions = {
+	restart = {
+		name = "Restart Displays",
+		type = "execute",
+		func = function()
+			mod:StopDisplays()
+			mod:StartDisplays()
+		end,
+		order = 1
+	},
+	defaults = {
+		name = "Restore Defaults",
+		type = "execute",
+		func = function()
+			mod.db.profile.config = copy(StarTip.config)
+			StarTip:RebuildOpts()
+		end,
+		order = 2
+	},
+	displays = {
+		name = "Displays",
+		type = "group",
+		args = {},
+		order = 3
+	},
+	layouts = {
+		name = "Layouts",
+		type = "group",
+		args = {},
+		order = 4
+	},
+	widgets = {
+		name = "Widgets",
+		type = "group",
+		args = {},
+		order = 5
+	}
+}
+
+function mod:RebuildOpts()
+	options = copy(blankOptions)
+	StarTip:Print("rebuild opts")
+	options.displays.args.add = {
+		name = "Add Display",
+		type = "input",
+		set = function(info, v)
+			self.db.profile.config["display_" .. v] = {name = v, layouts = {}, widgets = {}}
+			StarTip:RebuildOpts()
+		end,
+		order = 1
+	}
+	options.layouts.args.add = {
+		name = "Add Layout",
+		type = "input",
+		set = function(info, v)
+			self.db.profile.config["layout_" .. v] = {name = v}
+			StarTip:RebuildOpts()
+		end,
+		order = 1
+	}
+	options.widgets.args.text = {
+		name = "Text Widgets",
+		type = "group",
+		args = {
+			add = {
+				name = "Add",
+				desc = "Enter a name for your text widget",
+				type = "input",
+				set = function(info, v)
+					self.db.profile.config["widget_" .. v] = {type = "text"}
+					StarTip:RebuildOpts()
+				end,
+				order = 1
+			},
+		}
+	}
+	options.widgets.args.bar = {
+		name = "Bars",
+		type = "group",
+		args = {
+			add = {
+				name = "Add",
+				desc = "Enter a name for your bar widget",
+				type = "input",
+				set = function(info, v)
+					self.db.profile.config["widget_" .. v] = {type = "bar"}
+					StarTip:RebuildOpts()
+				end,
+				order = 1
+			}
+		}
+	}
+	options.widgets.args.histogram = {
+		name = "Histograms",
+		type = "group",
+		args = {
+			add = {
+				name = "Add",
+				desc = "Enter a name for your histogram widget",
+				type = "input",
+				set = function(info, v)
+					self.db.profile.config["widget_" .. v] = {type = "histogram"}
+					StarTip:RebuildOpts()
+				end,
+				order = 1
+			}
+		}
+	}
+	options.widgets.args.icon = {
+		name = "Icons",
+		type = "group",
+		args = {
+			add = {
+				name = "Add",
+				desc = "Enter a name for your icon widget",
+				type = "input",
+				set = function(info, v)
+					self.db.profile.config["widget_" .. v] = {type = "icon"}
+					StarTip:RebuildOpts()
+				end,
+				order = 1
+			}
+		}
+	}
+	options.widgets.args.key = {
+		name = "Keys",
+		type = "group",
+		args = {
+			add = {
+				name = "Add",
+				desc = "Enter a name for your key widget",
+				type = "input",
+				set = function(info, v)
+					self.db.profile.config["widget_" .. v] = {type = "key"}
+					StarTip:RebuildOpts()
+				end,
+				order = 1
+			}
+		}
+	}
+	for k, v in pairs(self.db.profile.config) do
+		if k:match("^display_.*") then
+			options.displays.args[k:gsub(" ", "_")] = {
+				name = k:gsub("display_", ""),
+				type = "group",
+				args = {
+					enable = {
+						name = "Enable",
+						type = "toggle",
+						get = function()
+							return v.enabled
+						end,
+						set = function(info, val)
+							v.enabled = val
+						end,
+						order = 1
+					},
+					driver = {
+						name = "Driver",
+						desc = "This display's driver type",
+						type = "select",
+						values = LibCore.driverList,
+						get = function() return LibCore.driverDict[v.driver] end,
+						set = function(info, val)
+							v.driver = LibCore.driverList[val]
+							StarTip:RebuildOpts()
+						end,
+						order = 2
+
+					},
+					delete = {
+						name = "Delete",
+						type = "execute",
+						func = function()
+							StarTip:Print("delete")
+							self.db.profile.config[k] = nil
+							StarTip:RebuildOpts()
+						end,
+						order = 100
+					}
+				}
+			}
+			local driverOptions = {}
+			if v.driver == "QTip" then
+				driverOptions = LibDriverQTip:RebuildOpts(StarTip, v, k)
+			end
+
+			for kk, vv in pairs(driverOptions) do
+				options.displays.args[k:gsub(" ", "_")].args[kk] = vv
+			end
+		end
+		if k:match("^layout_") then
+			options.layouts.args[k:gsub(" ", "_")] = {
+				name = k,
+				type = "group",
+				args = {}
+			}
+			options.layouts.args[k:gsub(" ", "_")].args = LayoutOptions:RebuildOpts(StarTip, v, k)
+			options.layouts.args[k:gsub(" ", "_")].args.delete = {
+				name = "Delete",
+				type = "execute",
+				func = function()
+					self.db.profile.config[k] = nil
+					StarTip:RebuildOpts()
+				end
+			}
+
+		end
+		if k:match("^widget_") then
+			if v.type == "text" then
+				options.widgets.args.text.args[k:gsub(" ", "_")] = {
+					name = k:gsub("widget_", ""),
+					type = "group",
+					args = WidgetText:GetOptions(StarTip, v, k),
+					order = 1
+				}
+				options.widgets.args.text.args[k:gsub(" ", "_")].args.delete = {
+					name = "Delete",
+					type = "execute",
+					func = function()
+						self.db.profile.config[k] = nil
+						StarTip:RebuildOpts()
+					end,
+					order = 100
+				}
+			elseif v.type == "bar" then
+				options.widgets.args.bar.args[k:gsub(" ", "_")] = {
+					name = k,
+					type = "group",
+					args = {}, --WidgetBar:GetOptions(StarTip, v, k)},
+					order = 1
+				}
+				options.widgets.args.bar.args[k:gsub(" ", "_")].args.delete = {
+					name = "Delete",
+					type = "execute",
+					func = function()
+						self.db.profile.config[k] = nil
+						StarTip:RebuildOpts()
+					end,
+					order = 100
+				}
+			elseif v.type == "histogram" then
+				options.widgets.args.histogram.args[k:gsub(" ", "_")] = {
+					name = k,
+					type = "group",
+					args = {}, --WidgetHistogram:GetOptions(StarTip, v, k)},
+					order = 1
+				}
+				options.widgets.args.histogram.args[k:gsub(" ", "_")].args.delete = {
+					name = "Delete",
+					type = "execute",
+					func = function()
+						self.db.profile.config[k] = nil
+						StarTip:RebuildOpts()
+					end,
+					order = 100
+				}
+			elseif v.type == "icon" then
+				options.widgets.args.icon.args[k:gsub(" ", "_")] = {
+					name = k,
+					type = "group",
+					args = {}, --WidgetIcon:GetOptions(StarTip, v, k)},
+					order = 2
+				}
+				options.widgets.args.icon.args[k:gsub(" ", "_")].args.delete = {
+					name = "Delete",
+					type = "execute",
+					func = function()
+						self.db.profile.config[k] = nil
+						StarTip:RebuildOpts()
+					end,
+					order = 100
+				}
+			elseif v.type == "key" then
+				options.widgets.args.key.args[k:gsub(" ", "_")] = {
+					name = k,
+					type = "group",
+					args = {}, --WidgetKey:GetOptions(StarTip, v, k)}
+					order = 3
+				}
+				options.widgets.args.key.args[k:gsub(" ", "_")].args.delete = {
+					name = "Delete",
+					type = "execute",
+					func = function()
+						self.db.profile.config[k] = nil
+						StarTip:RebuildOpts()
+					end,
+					order = 100
+				}
+			end
+		end
+	end
+end
+
+function mod:GetOptions()
+	self:RebuildOpts()
+	return options
+end

 function mod:OnInitialize()
 	self.db = StarTip.db:RegisterNamespace(self:GetName(), defaults)
@@ -20,22 +333,32 @@ function mod:OnInitialize()
 end

 function mod:OnEnable()
-	self.lcd = LibDriverQTip:New(self, "display_startip", StarTip.config, StarTip.db.profile.errorLevel)
-	self.lcd.core:CFGSetup()
-	self.lcd.core:BuildLayouts()
-
-	self.lcd.core:Start()
-	self.lcd:Show()
+	self:StartDisplays()
 end

 function mod:OnDisable()
-	self.lcd.core:Stop()
-	self.lcd:Hide()
-	self.lcd:Del()
+	self:StopDisplays()
 end

-function mod:AddLCD(core)
-	tinsert(coresList, core)
-	coresDict[core.name] = {core=core, i = #coresList}
-	self:RebuildOpts()
+function mod:StartDisplays()
+	for k, v in pairs(self.db.profile.config) do
+		if k:match("^display_") then
+			if v.driver == "QTip" then
+				local display = LibDriverQTip:New(self, k, self.db.profile.config, StarTip.db.profile.errorLevel)
+				display.core:CFGSetup()
+				display.core:BuildLayouts()
+				display.core:Start()
+				display:Show()
+				tinsert(displays, display)
+			end
+		end
+	end
+end
+
+function mod:StopDisplays()
+	for i, v in ipairs(displays) do
+		v:Hide()
+		v:Del()
+	end
+	table.wipe(displays)
 end
\ No newline at end of file
diff --git a/StarTip.toc b/StarTip.toc
index b8510e1..e254f25 100644
--- a/StarTip.toc
+++ b/StarTip.toc
@@ -20,7 +20,8 @@ embeds.xml

 StarTip.lua

+config.lua
+
 modules.xml

-config.lua

diff --git a/config.lua b/config.lua
index dbf98f3..993b9f6 100644
--- a/config.lua
+++ b/config.lua
@@ -7,47 +7,47 @@ local foo = 500

 StarTip.config = {
     ["display_startip"] = {
-		["driver"] = "qtip",
+		["enabled"] = true,
+		["driver"] = "QTip",
 		["layers"] = 3,
 		["background"] = "d9ccf16f",
 		["rows"] = 6,
 		["cols"] = 30,
-		["layout-timeout"] = 0,
+		["layout_timeout"] = 0,
 		["update"] = 25,
-		["widget0"] = "widget_key_up",
-		["widget1"] = "widget_key_down",
-		["transition-speed"] = 50,
-		["refresh-rate"] = 25,
-		["layout0"] = "layout_startip"
+		["widgets"] = {"widget_key_up", "widget_key_down"},
+		["transition_speed"] = 50,
+		["refresh_rate"] = 25,
+		["layouts"] = {"layout_startip"}
     },
 	["layout_blank"] = {
 		["keyless"] = 1,
 		["layout-timeout"] = 0
     },
 	["layout_startip"] = {
-		["row1"] = {
-    		["col1"] = "widget_name_label",
-    		["col10"] = "widget_name"
+		[1] = { -- row
+    		[1] = "widget_name_label", -- column
+    		[10] = "widget_name"
         },
-		["row2"] = {
-    		["col1"] = "widget_class_label",
-    		["col10"] = "widget_class"
+		[2] = {
+    		[1] = "widget_class_label",
+    		[10] = "widget_class"
         },
-		["row3"] = {
-			["col1"] = "widget_race_label",
-			["col10"] = "widget_race",
+		[3] = {
+			[1] = "widget_race_label",
+			[10] = "widget_race",
 		},
-		["row4"] = {
-			["col1"] = "widget_level_label",
-			["col10"] = "widget_level",
+		[4] = {
+			[1] = "widget_level_label",
+			[10] = "widget_level",
 		},
-		["row5"] = {
-			["col1"] = "widget_mem_label",
-			["col10"] = "widget_mem"
+		[5] = {
+			[1] = "widget_mem_label",
+			[10] = "widget_mem"
 		},
-		["row6"] = {
-			["col1"] = "widget_cpu_label",
-			["col10"] = "widget_cpu"
+		[6] = {
+			[1] = "widget_cpu_label",
+			[10] = "widget_cpu"
 		},
 		["transition"] = "U"
     },