Quantcast

- Gold : On Hide stop events to save cycles; on Show start plugin

urnati [01-19-24 - 00:19]
- Gold : On Hide stop events to save cycles; on Show start plugin
Filename
TitanGold/TitanGold.lua
diff --git a/TitanGold/TitanGold.lua b/TitanGold/TitanGold.lua
index 6c2f1f5..04d51b6 100644
--- a/TitanGold/TitanGold.lua
+++ b/TitanGold/TitanGold.lua
@@ -25,8 +25,8 @@ local GOLD_SESS_STATUS;
 local GOLD_PERHOUR_STATUS;
 local GOLD_STARTINGGOLD;
 local GOLD_SESSIONSTART;
-local L = {} -- For AceLocale
-local TitanGold = {} -- For Ace
+local TitanGold = LibStub("AceAddon-3.0"):NewAddon("TitanGold", "AceTimer-3.0")
+local L = LibStub("AceLocale-3.0"):GetLocale(TITAN_ID, true)
 local GoldTimer = nil;
 local _G = getfenv(0);
 local realmName = GetRealmName();
@@ -221,7 +221,6 @@ function TitanPanelGoldButton_OnLoad(self)
 		}
 	};

-	self:RegisterEvent("PLAYER_MONEY");
 	self:RegisterEvent("PLAYER_ENTERING_WORLD");

 	if (not GoldSave) then
@@ -238,7 +237,8 @@ end
 -- DESC : Create repeating timer when plugin is visible
 -- **************************************************************************
 --]]
-function TitanPanelGoldButton_OnShow()
+function TitanPanelGoldButton_OnShow(self)
+	self:RegisterEvent("PLAYER_MONEY");
 	if not GoldTimer and GoldSave and TitanGetVar(TITAN_GOLD_ID, "DisplayGoldPerHour") then
 		GoldTimer = TitanGold:ScheduleRepeatingTimer(TitanPanelPluginHandle_OnUpdate, 1, updateTable)
 	end
@@ -250,7 +250,8 @@ end
 -- DESC : Destroy repeating timer when plugin is hidden
 -- **************************************************************************
 --]]
-function TitanPanelGoldButton_OnHide()
+function TitanPanelGoldButton_OnHide(self)
+	self:UnregisterEvent("PLAYER_MONEY");
 	TitanGold:CancelTimer(GoldTimer, true)
 	GoldTimer = nil;
 end
@@ -262,6 +263,11 @@ end
 -- **************************************************************************
 --]]
 function TitanGold_OnEvent(self, event, ...)
+--[[
+print("_OnEvent"
+.." "..tostring(event)..""
+)
+--]]
 	if (event == "PLAYER_MONEY") then
 		if (GOLD_INITIALIZED) then
 			GoldSave[GOLD_INDEX].gold = GetMoney("player")
@@ -1240,8 +1246,4 @@ local function Create_Frames()
 end


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