From d4aa1fca374d8b8fd4051f90e4b63d0edd357bd6 Mon Sep 17 00:00:00 2001 From: urnati Date: Wed, 21 May 2025 11:54:02 -0400 Subject: [PATCH] - Further changes for menu timer --- Titan/TitanUtils.lua | 53 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/Titan/TitanUtils.lua b/Titan/TitanUtils.lua index 6963833..609feec 100644 --- a/Titan/TitanUtils.lua +++ b/Titan/TitanUtils.lua @@ -41,6 +41,15 @@ local drop_down_1 = "" -- changes if using Blizz drop down (retail) or lib (Clas --====== Set the default drop down menu routines per retail or Classic drop_down_1 = "DropDownList1" -- Boo!! Per hard-coded Blizz UIDropDownMenu.lua +--[[ +This set of routines controls the menu timer. +It keeps the menu open as long as the mouse is over an open menu or sub menu. + +The timer is only on the top (drop_down_1) NOT on any sub menu. + +We cannot reliably use OnEnter / OnLeave only because the user may leave the mouse over a menu at any level. +The OnUpdate must do the 'over menu' check. +--]] local function IsMouseOverMenu() for idx = 1, UIDROPDOWNMENU_MAXLEVELS do -- if _G["DropDownList" .. idx]:IsMouseOver() then @@ -63,13 +72,15 @@ end ---@param self Frame ---@param elapsed number local function OnUpdateTimer(self, elapsed) - if (not self.showTimer or not self.isCounting) then + if (not self.showTimer or not self.isCounting) then -- no timer running return; - elseif (self.showTimer < 0) then + elseif (self.showTimer < 0) then -- timer expired self:Hide(); self.showTimer = nil; self.isCounting = nil; - else + elseif IsMouseOverMenu() then -- mouse is over some (sub)menu + self.showTimer = UIDROPDOWNMENU_SHOW_TIME -- reset timer + else -- mouse is elsewhere, decrease timer self.showTimer = self.showTimer - elapsed; --[[ print("Counting" @@ -82,28 +93,52 @@ end ---Start a timer to close menu ---@param frame Frame local function StartCounting(frame) + local str = "" if (frame.parent) then - StartCounting(frame.parent); - elseif IsMouseOverMenu() then + StartCounting(frame.parent) -- walk to top menu + str = str .. "parent" +-- elseif IsMouseOverMenu() then -- Mouse is in the menu +-- str = str .. "over" else + str = str .. "start" -- allow time out frame.showTimer = UIDROPDOWNMENU_SHOW_TIME; frame.isCounting = 1; end +--[[ +print("TU _Leave Start" +.." "..tostring(str).."" +.." "..tostring(frame:GetName()).."" +.." "..tostring(frame.isCounting).."" +.." "..tostring(format("%0.1f", (frame.showTimer or 0.0))).."" +) +--]] end ---Start a timer to close menu ---@param frame Frame local function StopCounting(frame) + local str = "" if (frame.parent) then - StopCounting(frame.parent); - elseif IsMouseOverMenu() then - frame.isCounting = nil; + str = str .. "parent" + StopCounting(frame.parent) -- walk to top menu +-- elseif IsMouseOverMenu() then +-- str = str .. "stop" +-- frame.isCounting = nil; -- Mouse is in the menu else + str = str .. "nop" -- Nothing to do; if timing, allow to run out end +--[[ +print("TU _Enter Stop" +.." "..tostring(str).."" +.." "..tostring(frame:GetName()).."" +.." "..tostring(frame.isCounting).."" +.." "..tostring(format("%0.1f", (frame.showTimer or 0.0))).."" +) +--]] end ---Add scripts and start timer to menu being shown @@ -2355,7 +2390,7 @@ print("RCM" .." "..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) + 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 -- 1.7.9.5