Quantcast

So the tooltip module doesn't play well with profile changes. For now I've provided a warning message, suggesting the player reloads the UI.

Scott Sibley [09-16-10 - 04:29]
So the tooltip module doesn't play well with profile changes. For now I've provided a warning message, suggesting the player reloads the UI.
Filename
Modules/Bars.lua
Modules/Histograms.lua
Modules/Text.lua
Modules/UnitTooltip.lua
StarTip.lua
diff --git a/Modules/Bars.lua b/Modules/Bars.lua
index 6d8587b..6851c8d 100644
--- a/Modules/Bars.lua
+++ b/Modules/Bars.lua
@@ -101,6 +101,7 @@ return PowerColor(nil, unit)
 local defaults = {
 	profile = {
 		classColors = true,
+		bars = {}
 	}
 }

@@ -273,9 +274,7 @@ function mod:CreateBars()
 	createBars()
 end

-function mod:OnInitialize()
-	self.db = StarTip.db:RegisterNamespace(self:GetName(), defaults)
-
+function mod:ReInit()
 	if not self.db.profile.bars then
 		self.db.profile.bars = {}
 	end
@@ -299,7 +298,13 @@ function mod:OnInitialize()
 			end
 		end
 	end
+end
+
+function mod:OnInitialize()
+	self.db = StarTip.db:RegisterNamespace(self:GetName(), defaults)

+	self:ReInit()
+
 	for k, v in pairs(defaultWidgets) do
 		if not v.tagged and not v.deleted then
 			self.db.profile.bars[k] = copy(v)
diff --git a/Modules/Histograms.lua b/Modules/Histograms.lua
index bcf7d64..cc600be 100644
--- a/Modules/Histograms.lua
+++ b/Modules/Histograms.lua
@@ -151,6 +151,7 @@ end
 local defaults = {
 	profile = {
 		classColors = true,
+		histograms = {}
 	}
 }

@@ -321,9 +322,7 @@ function mod:CreateHistograms()
 	createHistograms()
 end

-function mod:OnInitialize()
-	self.db = StarTip.db:RegisterNamespace(self:GetName(), defaults)
-
+function mod:ReInit()
 	if not self.db.profile.histograms then
 		self.db.profile.histograms = {}
 	end
@@ -353,7 +352,14 @@ function mod:OnInitialize()
 			tinsert(self.db.profile.histograms, copy(v))
 		end
 	end
+end
+
+function mod:OnInitialize()
+	self.db = StarTip.db:RegisterNamespace(self:GetName(), defaults)

+	wipe(self.db.profile.histograms)
+	self:ReInit()
+
 	self.core = LibCore:New(mod, environment, "StarTip.Histograms", {["StarTip.Histograms"] = {}}, nil, StarTip.db.profile.errorLevel)

 	self.offset = 0
diff --git a/Modules/Text.lua b/Modules/Text.lua
index d3598ee..26359d7 100644
--- a/Modules/Text.lua
+++ b/Modules/Text.lua
@@ -227,6 +227,7 @@ return 1, 1, 0
 local defaults = {
 	profile = {
 		classColors = true,
+		texts = {}
 	}
 }

@@ -380,13 +381,13 @@ function createTexts()
 	end
 end

-function mod:OnInitialize()
-	self.db = StarTip.db:RegisterNamespace(self:GetName(), defaults)
-
+function mod:ReInit()
 	if not self.db.profile.texts then
 		self.db.profile.texts = {}
 	end

+	--wipe(self.db.profile.texts)
+
 	for i, v in ipairs(defaultWidgets) do
 		for j, vv in ipairs(self.db.profile.texts) do
 			if v.name == vv.name and not vv.custom then
@@ -405,7 +406,15 @@ function mod:OnInitialize()
 			tinsert(self.db.profile.texts, copy(v))
 		end
 	end
+end
+
+function mod:OnInitialize()
+	self.db = StarTip.db:RegisterNamespace(self:GetName(), defaults)

+	wipe(self.db.profile.texts)
+
+	self:ReInit()
+
 	self.core = LibCore:New(mod, environment, "StarTip.Texts", {["StarTip.Texts"] = {}}, nil, StarTip.db.profile.errorLevel)

 	StarTip:SetOptionsDisabled(options, true)
diff --git a/Modules/UnitTooltip.lua b/Modules/UnitTooltip.lua
index ce22ddb..619a818 100644
--- a/Modules/UnitTooltip.lua
+++ b/Modules/UnitTooltip.lua
@@ -351,9 +351,8 @@ return SpecText(unit)

 local options = {}

-function mod:OnInitialize()
-    self.db = StarTip.db:RegisterNamespace(self:GetName(), defaults)
-
+function mod:ReInit()
+	self:ClearLines()
 	for k, v in ipairs(defaultLines) do
 		for j, vv in ipairs(self.db.profile.lines) do
 			vv.colorLeft = nil
@@ -371,10 +370,17 @@ function mod:OnInitialize()

 	for k, v in ipairs(defaultLines) do
 		if not v.tagged and not v.deleted then
-			tinsert(self.db.profile.lines, v)
+			tinsert(self.db.profile.lines, copy(v))
 		end
 	end
+	self:CreateLines()
+end

+function mod:OnInitialize()
+    self.db = StarTip.db:RegisterNamespace(self:GetName(), defaults)
+
+	self:ReInit()
+
 	local text = StarTip:GetModule("Text")
 	if text.db.profile.lines then
 		local lines = copy(text.db.profile.lines)
@@ -402,7 +408,6 @@ local draw
 local update
 function mod:OnEnable()
 	StarTip:SetOptionsDisabled(options, false)
-	self:CreateLines()
 	if self.db.profile.refreshRate > 0 then
 		self.timer = LibTimer:New("Text module", self.db.profile.refreshRate, true, draw, nil, self.db.profile.errorLevel, self.db.profile.durationLimit)
 	end
@@ -477,6 +482,18 @@ local plugin = {}
 LibStub("StarLibPluginString-1.0"):New(plugin)
 --@end-debug@

+function mod:ClearLines()
+	for k, v in pairs(lines) do
+		if v.leftObj then
+			v.leftObj:Del()
+		end
+		if v.rightObj then
+			v.rightObj:Del()
+		end
+	end
+	wipe(lines)
+end
+
 local tbl
 function mod:CreateLines()
     local llines = {}
@@ -488,6 +505,7 @@ function mod:CreateLines()
 			llines[j].config = copy(v)
 		end
     end
+	self:ClearLines()
     lines = setmetatable(llines, {__call=function(self)
 		--@debug@
 		if debugging then
@@ -603,6 +621,7 @@ function mod:RebuildOpts()
 				tinsert(self.db.profile.lines, {name = v, left = "", right = "", rightUpdating = false, enabled = true})
 				self:RebuildOpts()
 				StarTip:RebuildOpts()
+				self:ClearLines()
 				self:CreateLines()
 			end,
 			order = 5
@@ -784,6 +803,7 @@ function mod:RebuildOpts()
 								tinsert(self.db.profile.lines, v)
 							end
 							StarTip:RebuildOpts()
+							self:ClearLines()
 							self:CreateLines()
 						end,
 						order = 8
@@ -801,9 +821,7 @@ function mod:RebuildOpts()
 						set = function(info, val)
 							v.left = unescape(val)
 							v.leftDirty = true
-							if val == "" then
-								v.left = nil
-							end
+							if val == "" then v.left = nil end
 							self:CreateLines()
 						end,
 						--[[validate = function(info, str)
@@ -821,9 +839,7 @@ function mod:RebuildOpts()
 						set = function(info, val)
 							v.right = unescape(val);
 							v.rightDirty = true
-							if val == "" then
-								v.right = nil
-							end
+							if val == "" then v.right = nil end
 							self:CreateLines()
 						end,
 						multiline = true,
diff --git a/StarTip.lua b/StarTip.lua
index 7b4676b..a3a68ee 100644
--- a/StarTip.lua
+++ b/StarTip.lua
@@ -161,6 +161,7 @@ StarTip.UNIT_RAID_GROUPS = UNIT_RAID_GROUPS
 local defaults = {
 	profile = {
 		modules = {},
+		timers = {},
 		minimap = {hide=true},
 		modifier = 1,
 		unitShow = 1,
@@ -402,6 +403,16 @@ Update()
 	},
 }

+function StarTip:RefreshConfig()
+	for k, v in self:IterateModules() do
+		if v.ReInit then
+			v:ReInit()
+		end
+	end
+	self:RebuildOpts()
+	self:Print("You may need to reload your UI. I'm not sure why yet.")
+end
+
 local checkTooltipAlphaFrame
 local checkTooltipAlpha = function()
 	if GameTooltip:GetAlpha() < 1 then
@@ -414,6 +425,9 @@ checkTooltipAlphaFrame = CreateFrame("Frame")

 function StarTip:OnInitialize()
 	self.db = LibStub("AceDB-3.0"):New("StarTipDB", defaults, "Default")
+	self.db.RegisterCallback(self, "OnProfileChanged", "RefreshConfig")
+	self.db.RegisterCallback(self, "OnProfileCopied", "RefreshConfig")
+	self.db.RegisterCallback(self, "OnProfileReset", "RefreshConfig")

 	LibStub("AceConfig-3.0"):RegisterOptionsTable("StarTip", options)
 	self:RegisterChatCommand("startip", "OpenConfig")