Quantcast

Introduce Border module

Scott Sibley [11-01-10 - 02:51]
Introduce Border module
Filename
.pkgmeta
Modules/Border/Border.lua
Modules/Border/StarTip_Border.toc
modules.xml
diff --git a/.pkgmeta b/.pkgmeta
index fc74409..bee8354 100644
--- a/.pkgmeta
+++ b/.pkgmeta
@@ -65,4 +65,5 @@ move-folders:
     StarTip/Modules/UnitTooltip: StarTip_UnitTooltip
     StarTip/Modules/Portrait: StarTip_Portrait
     StarTip/Modules/Icons: StarTip_Icons
-    StarTip/Modules/Gestures: StarTip_Gestures
\ No newline at end of file
+    StarTip/Modules/Gestures: StarTip_Gestures
+    StarTip/Modules/Border: StarTip_Border
\ No newline at end of file
diff --git a/Modules/Border/Border.lua b/Modules/Border/Border.lua
new file mode 100644
index 0000000..50149fb
--- /dev/null
+++ b/Modules/Border/Border.lua
@@ -0,0 +1,132 @@
+local mod = StarTip:NewModule("Border")
+mod.name = "Border"
+mod.toggled = true
+mod.defaultOff = true
+local L = StarTip.L
+local WidgetBorder = LibStub("LibScriptableDisplayWidgetColor-1.0")
+local _G = _G
+local GameTooltip = _G.GameTooltip
+local StarTip = _G.StarTip
+local UIParent = _G.UIParent
+local environment = {}
+
+local defaults = {
+	profile = {
+		borders = {
+			[1] = {
+				name = "Border",
+				enabled = true,
+				expression = [[
+return 1, 1, 0
+]]
+			}
+		}
+	}
+}
+
+local options = {}
+local optionsDefaults = {
+	add = {
+		name = "Add Gesture",
+		desc = "Add a border",
+		type = "input",
+		set = function(info, v)
+			local widget = {
+				name = v,
+				type = "border",
+				enabled = true,
+				expression = "return random(100)",
+			}
+			tinsert(mod.db.profile.borders, widget)
+			StarTip:RebuildOpts()
+
+		end,
+		order = 5
+	},
+	defaults = {
+		name = "Restore Defaults",
+		desc = "Restore Defaults",
+		type = "execute",
+		func = function()
+			mod.db.profile.borders = copy(defaultWidgets);
+			StarTip:RebuildOpts()
+		end,
+		order = 6
+	},
+}
+
+local function copy(tbl)
+	if type(tbl) ~= "table" then return tbl end
+	local newTbl = {}
+	for k, v in pairs(tbl) do
+		newTbl[k] = copy(v)
+	end
+	return newTbl
+end
+
+function mod:CreateBorders()
+	for i, border in ipairs(self.db.profile.borders) do
+		local widget = WidgetColor:New(self.core, border.name, copy(border), StarTip.db.profile.errorLevel)
+		if border.enabled then
+			widget:Start()
+		end
+		tinsert(borders, widget)
+	end
+end
+
+function mod:WipeBorders()
+	for i, border in ipairs(borders) do
+		border:Del()
+	end
+	wipe(borders)
+end
+
+function mod:OnInitialize()
+	self.db = StarTip.db:RegisterNamespace(self:GetName(), defaults)
+	StarTip:SetOptionsDisabled(options, true)
+	self.core = StarTip.core --LibCore:New(mod, environment, "StarTip.Border", {["StarTip.Border"] = {}}, nil, StarTip.db.profile.errorLevel)
+end
+
+function mod:OnEnable()
+
+	StarTip:SetOptionsDisabled(options, false)
+	self:CreateBorders()
+end
+
+function mod:OnDisable()
+	StarTip:SetOptionsDisabled(options, true)
+	self:WipeBorders()
+end
+
+function mod:GetOptions()
+	return options
+end
+
+function mod:RebuildOpts()
+	local defaults = WidgetBorder.defaults
+	self:WipeBorders()
+	self:CreateBorders()
+	wipe(options)
+	for k, v in pairs(optionsDefaults) do
+		options[k] = v
+	end
+	for i, db in ipairs(self.db.profile.borders) do
+		options[db.name:gsub(" ", "_")] = {
+			name = db.name,
+			type="group",
+			order = i,
+			args=WidgetBorder:GetOptions(db, StarTip.RebuildOpts, StarTip)
+		}
+		options[db.name:gsub(" ", "_")].args.delete = {
+			name = "Delete",
+			desc = "Delete this widget",
+			type = "execute",
+			func = function()
+				self.db.profile.borders[i] = nil
+				StarTip:RebuildOpts()
+			end,
+			order = 100
+		}
+	end
+end
+
diff --git a/Modules/Border/StarTip_Border.toc b/Modules/Border/StarTip_Border.toc
new file mode 100644
index 0000000..a709444
--- /dev/null
+++ b/Modules/Border/StarTip_Border.toc
@@ -0,0 +1,8 @@
+## Interface: 40000
+## Title: StarTip [Border]
+## Notes: Tooltips from outerspace
+## Author: Starlon
+## Version: @package-version@
+## Deps: StarTip
+
+Border.lua
\ No newline at end of file
diff --git a/modules.xml b/modules.xml
index 2d1c71c..b98c931 100644
--- a/modules.xml
+++ b/modules.xml
@@ -3,6 +3,7 @@

 <!--@debug@-->
 <Script file = "Modules\Appearance\Appearance.lua"/>
+<Script file = "Modules\Border\Border.lua"/>
 <Script file = "Modules\Fade\Fade.lua"/>
 <Script file = "Modules\Position\Position.lua"/>
 <Script file = "Modules\PvP\PvP.lua"/>