Quantcast

Make all aspects of LMG scriptable

Scott Sibley [10-07-10 - 07:55]
Make all aspects of LMG scriptable
Filename
Localization/enUS.lua
Modules/Gestures/Gestures.lua
StarTip.lua
diff --git a/Localization/enUS.lua b/Localization/enUS.lua
index eec5cf4..23143b6 100644
--- a/Localization/enUS.lua
+++ b/Localization/enUS.lua
@@ -1,5 +1,5 @@
 local AceLocale = LibStub:GetLibrary("AceLocale-3.0")
-local L = AceLocale:NewLocale("StarTip", "enUS", true)
+local L = AceLocale:NewLocale("StarTip", "enUS", true, true)
 if not L then return end

 L["Welcome to "] = true
diff --git a/Modules/Gestures/Gestures.lua b/Modules/Gestures/Gestures.lua
index d10fa41..3ddd870 100644
--- a/Modules/Gestures/Gestures.lua
+++ b/Modules/Gestures/Gestures.lua
@@ -2,6 +2,7 @@ local mod = StarTip:NewModule("Gestures")
 mod.name = "Gestures"
 mod.toggled = true
 mod.defaultOff = true
+local L = StarTip.L
 local WidgetGestures = LibStub("LibScriptableDisplayWidgetGestures-1.0")
 local LibCore = LibStub("LibScriptableDisplayCore-1.0")
 local _G = _G
@@ -11,6 +12,12 @@ local UIParent = _G.UIParent
 local gestures = {}
 local environment = {}

+-- LeftButtonDown
+local buttonsList = {L["Left Button"], L["Right Button"], L["Center Button"]}
+local buttons = {"LeftButton", "RightButton", "CenterButton"}
+local directionsList = {L["Up"], L["Down"]}
+local directions = {"Up", "Down"}
+
 local defaults = {
 	profile = {
 		gestures = {
@@ -27,8 +34,38 @@ _G.GameTooltip:Hide()
 	}
 }

+local options = {}
+local optionsDefaults = {
+	add = {
+		name = "Add Gesture",
+		desc = "Add a gesture",
+		type = "input",
+		set = function(info, v)
+			local widget = {
+				name = v,
+				type = "gesture",
+				enabled = true,
+				points = {{"TOPLEFT", "GameTooltip", "BOTTOMLEFT", 0, -50}},
+				frame = "UIParent",
+				expression = "return random(100)",
+				custom = true
+			}
+			tinsert(mod.db.profile.gestures, widget)
+			StarTip:RebuildOpts()

-local options = {
+		end,
+		order = 5
+	},
+	defaults = {
+		name = "Restore Defaults",
+		desc = "Restore Defaults",
+		type = "execute",
+		func = function()
+			mod.db.profile.gestures = copy(defaultWidgets);
+			StarTip:RebuildOpts()
+		end,
+		order = 6
+	},
 }

 local function copy(tbl)
@@ -40,6 +77,22 @@ local function copy(tbl)
 	return newTbl
 end

+function mod:CreateGestures()
+	for i, gesture in ipairs(self.db.profile.gestures) do
+		local widget = WidgetGestures:New(self.core, gesture.name, copy(gesture), StarTip.db.profile.errorLevel, timer)
+		if gesture.enabled then
+			widget:Start()
+		end
+		tinsert(gestures, widget)
+	end
+end
+
+function mod:WipeGestures()
+	for i, gesture in ipairs(gestures) do
+		gesture:Del()
+	end
+	wipe(gestures)
+end

 function mod:OnInitialize()
 	self.db = StarTip.db:RegisterNamespace(self:GetName(), defaults)
@@ -50,24 +103,43 @@ end

 function mod:OnEnable()
 	StarTip:SetOptionsDisabled(options, false)
-	for i, gesture in ipairs(self.db.profile.gestures) do
-		local widget = WidgetGestures:New(self.core, gesture.name, copy(gesture), StarTip.db.profile.errorLevel, timer)
-		if gesture.enabled then
-			widget:Start()
-		end
-		tinsert(gestures, widget)
-	end
+	self:CreateGestures()
 end

 function mod:OnDisable()
 	StarTip:SetOptionsDisabled(options, true)
-	for i, widget in ipairs(gestures) do
-		widget:Del()
-	end
-	wipe(gestures)
+	self:WipeGestures()
 end

 function mod:GetOptions()
 	return options
 end

+function mod:RebuildOpts()
+	local defaults = WidgetGestures.defaults
+	self:WipeGestures()
+	self:CreateGestures()
+	wipe(options)
+	for k, v in pairs(optionsDefaults) do
+		options[k] = v
+	end
+	for i, db in ipairs(self.db.profile.gestures) do
+		options[db.name:gsub(" ", "_")] = {
+			name = db.name,
+			type="group",
+			order = i,
+			args=WidgetGestures:GetOptions(db, StarTip.RebuildOpts, StarTip)
+		}
+		options[db.name:gsub(" ", "_")].args.delete = {
+			name = "Delete",
+			desc = "Delete this widget",
+			type = "execute",
+			func = function()
+				self.db.profile.gestures[i] = nil
+				StarTip:RebuildOpts()
+			end,
+			order = 100
+		}
+	end
+end
+
diff --git a/StarTip.lua b/StarTip.lua
index 6e50e03..550012a 100644
--- a/StarTip.lua
+++ b/StarTip.lua
@@ -9,6 +9,7 @@ local LSM = _G.LibStub("LibSharedMedia-3.0")
 local LDB = LibStub:GetLibrary("LibDataBroker-1.1")
 local AceConfigDialog = LibStub("AceConfigDialog-3.0")
 local L = LibStub("AceLocale-3.0"):GetLocale("StarTip")
+StarTip.L = L

 local LibCore = LibStub("LibScriptableDisplayCore-1.0")
 local LibTimer = LibStub("LibScriptableDisplayTimer-1.0")