Quantcast

- Bag : On hide stop events to reduce cycles; on show register to start plugin

urnati [01-18-24 - 20:26]
- Bag : On hide stop events to reduce cycles; on show register to start plugin
Filename
TitanBag/TitanBag.lua
diff --git a/TitanBag/TitanBag.lua b/TitanBag/TitanBag.lua
index 406b87a..a3e9d64 100644
--- a/TitanBag/TitanBag.lua
+++ b/TitanBag/TitanBag.lua
@@ -15,8 +15,8 @@ local TITAN_BAG_THRESHOLD_TABLE = {
 }
 local updateTable = {TITAN_BAG_ID, TITAN_PANEL_UPDATE_BUTTON};
 -- ******************************** Variables *******************************
-local L = {} -- For AceLocale
-local AceTimer = {}
+local AceTimer = LibStub("AceTimer-3.0")
+local L = LibStub("AceLocale-3.0"):GetLocale(TITAN_ID, true)
 local BagTimer

 local bag_info = {
@@ -276,7 +276,6 @@ function TitanPanelBagButton_OnLoad(self)
 	end

 	self:RegisterEvent("PLAYER_ENTERING_WORLD");
-
 end

 --[[ plugin
@@ -287,11 +286,6 @@ end
 --]]
 function TitanPanelBagButton_OnEvent(self, event, a1, a2, ...)
 	if event == "PLAYER_ENTERING_WORLD" then
-
-		-- Register for bag updates and update the plugin text
-		self:RegisterEvent("BAG_UPDATE")
-		TitanPanelButton_UpdateButton(TITAN_BAG_ID);
-
 		if a1 == true and TITAN_ID == "Titan" then -- 10.* / Retail
 			-- initial login

@@ -315,16 +309,14 @@ function TitanPanelBagButton_OnEvent(self, event, a1, a2, ...)
 	end

 	if event == "BAG_UPDATE" then
-		-- Create only when the event is active
-		self:SetScript("OnUpdate", TitanPanelBagButton_OnUpdate)
+		-- update the plugin text
+		TitanPanelButton_UpdateButton(TITAN_BAG_ID);
 	end
-end
-
-function TitanPanelBagButton_OnUpdate(self)
-	-- update the button
-	TitanPanelPluginHandle_OnUpdate(updateTable)
-	-- remove until the next bag event
-	self:SetScript("OnUpdate", nil)
+--[[
+print("_OnEvent"
+.." "..tostring(event)..""
+)
+--]]
 end

 --[[ plugin
@@ -538,6 +530,16 @@ function TitanPanelBagButton_ShowDetailedInfo()
 	TitanToggleVar(TITAN_BAG_ID, "ShowDetailedInfo");
 end

+function TitanPanelBagButton_OnShow(self)
+	-- Register for bag updates and update the plugin text
+	self:RegisterEvent("BAG_UPDATE")
+	TitanPanelButton_UpdateButton(TITAN_BAG_ID);
+end
+
+function TitanPanelBagButton_OnHide(self)
+	self:UnregisterEvent("BAG_UPDATE")
+end
+
 -- ====== Create needed frames
 local function Create_Frames()
 	if _G[TITAN_BUTTON] then
@@ -555,6 +557,13 @@ local function Create_Frames()
 	TitanPanelBagButton_OnLoad(window);
 --	TitanPanelButton_OnLoad(window); -- Titan XML template calls this...

+	window:SetScript("OnShow", function(self)
+		TitanPanelBagButton_OnShow(self);
+		TitanPanelButton_OnShow(self);
+	end)
+	window:SetScript("OnHide", function(self)
+		TitanPanelBagButton_OnHide(self)
+	end)
 	window:SetScript("OnEvent", function(self, event, ...)
 		TitanPanelBagButton_OnEvent(self, event, ...)
 	end)
@@ -565,8 +574,4 @@ local function Create_Frames()
 end


-if TITAN_ID then -- it exists
-	AceTimer = LibStub("AceTimer-3.0")
-	L = LibStub("AceLocale-3.0"):GetLocale(TITAN_ID, true)
-	Create_Frames() -- do the work
-end
+Create_Frames() -- do the work