Quantcast

- Hook different routine for menu in 'classic'

urnati [05-24-25 - 21:26]
- Hook different routine for menu in 'classic'
Filename
Titan/TitanUtils.lua
diff --git a/Titan/TitanUtils.lua b/Titan/TitanUtils.lua
index 609feec..0bb1465 100644
--- a/Titan/TitanUtils.lua
+++ b/Titan/TitanUtils.lua
@@ -68,34 +68,48 @@ print("TU _Mouse on menu"
 	return false
 end

+local tstr = ""
 ---Implement timer to close drop down menu (right click menu)
 ---@param self Frame
 ---@param elapsed number
 local function OnUpdateTimer(self, elapsed)
+	local str = "Counting" .." "..tostring(self:GetName()).." "
 	if (not self.showTimer or not self.isCounting) then -- no timer running
-		return;
+		str = str .. "no timer"
+--		return;
 	elseif (self.showTimer < 0) then -- timer expired
+		str = str .. "expired"
 		self:Hide();
 		self.showTimer = nil;
 		self.isCounting = nil;
 	elseif IsMouseOverMenu() then -- mouse is over some (sub)menu
+		str = str .. "mouse over"
 		self.showTimer = UIDROPDOWNMENU_SHOW_TIME -- reset timer
 	else -- mouse is elsewhere, decrease timer
+		str = str .. "count down"
 		self.showTimer = self.showTimer - elapsed;
-		--[[
-print("Counting"
-.." "..tostring(self:GetName())..""
+	end
+	str = str
+		.." "..tostring(self.showTimer)..""
+		.." "..tostring(self.isCounting)..""
+--[[
+if str == tstr then
+-- same, prevent run away text
+else
+print(tostring(str)
+.." "..tostring(format("%0.1f", (elapsed or 0.0)))..""
 )
+tstr = str
+end
 --]]
-	end
 end

 ---Start a timer to close menu
----@param frame Frame
-local function StartCounting(frame)
+---@param self Frame
+local function StartCounting(self)
 	local str = ""
-	if (frame.parent) then
-		StartCounting(frame.parent) -- walk to top menu
+	if (self.parent) then
+		StartCounting(self.parent) -- walk to top menu
 		str = str .. "parent"
 --	elseif IsMouseOverMenu() then
 		-- Mouse is in the menu
@@ -103,15 +117,15 @@ local function StartCounting(frame)
 	else
 		str = str .. "start"
 		-- allow time out
-		frame.showTimer = UIDROPDOWNMENU_SHOW_TIME;
-		frame.isCounting = 1;
+		self.showTimer = UIDROPDOWNMENU_SHOW_TIME;
+		self.isCounting = 1;
 	end
 --[[
 print("TU _Leave Start"
 .." "..tostring(str)..""
-.." "..tostring(frame:GetName())..""
-.." "..tostring(frame.isCounting)..""
-.." "..tostring(format("%0.1f", (frame.showTimer or 0.0)))..""
+.." "..tostring(self:GetName())..""
+.." "..tostring(self.isCounting)..""
+.." "..tostring(format("%0.1f", (self.showTimer or 0.0)))..""
 )
 --]]
 end
@@ -145,6 +159,12 @@ end
 ---@param level number
 ---@param index number
 function TitanUtils_AddHide(level, index)
+--[[
+print("TU _AddHide"
+.." "..tostring(level)..""
+.." "..tostring(index)..""
+)
+--]]
 	local frame = _G["DropDownList" .. level]
 	-- Add these to start and stop the hide timer
 	frame:SetScript("OnEnter", function(self) StopCounting(self) end)
@@ -154,10 +174,17 @@ function TitanUtils_AddHide(level, index)
 	StartCounting(frame)
 end

+local function StartTimer(frame)
+	-- The user may not mouse into the menu
+	StartCounting(frame)
+end
+
 ---@diagnostic disable-next-line: undefined-global
 if UIDropDownMenu_StartCounting then
 	-- This version of WoW is using an older timeout for menu hiding
 	-- Seems to work for now
+	-- Post Hook the OnShow of DropDownList
+	AceHook:SecureHookScript(DropDownList1, "OnShow", StartTimer)
 else
 	--[[
 	for idx = 1, UIDROPDOWNMENU_MAXLEVELS do -- should be first 3 ...
@@ -1313,11 +1340,7 @@ end
 ---@param info table Filled in button to add
 ---@param level number menu level
 local function Add_button(info, level)
-	--	if TITAN_ID == "TitanClassic" then
-	--		L_UIDropDownMenu_AddButton(info, level);
-	--	else
 	UIDropDownMenu_AddButton(info, level)
-	--	end
 end

 ---API Menu - Get the base frame name of the user selected menu (without level).
@@ -1448,22 +1471,16 @@ end
 ---@param level? number menu level or 1
 function TitanPanelRightClickMenu_AddSeparator(level)
 	level = level or 1
-	--	if TITAN_ID == "TitanClassic" then
-	--		L_UIDropDownMenu_AddSeparator(level)
-	--	else
+
 	UIDropDownMenu_AddSeparator(level)
-	--	end
 end

 ---API Menu - add a blank line at the given level in the form of an inactive button.
 ---@param level? number menu level or 1
 function TitanPanelRightClickMenu_AddSpacer(level)
 	level = level or 1
-	--	if TITAN_ID == "TitanClassic" then
-	--		L_UIDropDownMenu_AddSpace(level)
-	--	else
+
 	UIDropDownMenu_AddSpace(level)
-	--	end
 end

 ---API This will remove the plugin from whichever Titan bar it is on.
@@ -2389,11 +2406,6 @@ print("RCM"
 .." "..tostring(menu.relativePoint)..""
 .." "..tostring(format("%0.1f", left))..""
 )
-	if TITAN_ID == "TitanClassic" then
-		L_ ToggleDropDownMenu(1, nil, menu, frame, TitanUtils_Max(x_offset - 40, 0), 0, nil, self)
-	else
-		ToggleDropDownMenu(1, nil, menu, frame, x_offset, 0, nil, self);
-	end
 --]]
 	ToggleDropDownMenu(1, nil, menu, frame, x_offset, 0, nil, self);
 end