Skip to content

Commit 6d7fcab

Browse files
TimMenu: idk anymore
1 parent 545f4d0 commit 6d7fcab

6 files changed

Lines changed: 27 additions & 46 deletions

File tree

TimMenu/Globals.lua

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,6 @@ Globals.LayersPerGroup = 10
129129
-- Popup layer that's always on top (above all sectors)
130130
Globals.POPUP_LAYER_BASE = 1000
131131

132-
-- Global click consumption flag to prevent race conditions
133-
-- When true, indicates a widget has already handled the click
134-
-- Window manager should respect this and not change focus
135-
Globals.isClickConsumed = false
136-
137132
-- Preload interactive widget images
138133
local ImgDecoder = require("TimMenu.images.imageDecoder")
139134
Globals.Images = Globals.Images or {}

TimMenu/Main.lua

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,6 @@ local function _TimMenu_GlobalDraw()
278278

279279
local mouseX, mouseY = table.unpack(input.GetMousePos())
280280
TimMenuGlobal.mouseX, TimMenuGlobal.mouseY = mouseX, mouseY
281-
local focusedWindowKey = nil
282281

283282
local currentFrame = globals.FrameCount()
284283
local keysToRemove = {}
@@ -297,20 +296,39 @@ local function _TimMenu_GlobalDraw()
297296
end
298297
end
299298

299+
-- PRIMARY FOCUS LOOP: Top-to-bottom search for window under mouse
300+
local windowUnderMouse = nil
301+
local mousePressed = input.IsButtonPressed(MOUSE_LEFT)
302+
300303
for i = #TimMenuGlobal.order, 1, -1 do
301304
local key = TimMenuGlobal.order[i]
302305
local win = TimMenuGlobal.windows[key]
303306
if win and win.visible and win:_HitTest(mouseX, mouseY) then
304-
focusedWindowKey = key
305-
break
307+
windowUnderMouse = key
308+
break -- FOUND THE TOPMOST OWNER. STOP SEARCHING.
309+
end
310+
end
311+
312+
-- Handle focus changes only when clicking
313+
if mousePressed and windowUnderMouse then
314+
-- Bring the owner window to front
315+
if TimMenuGlobal.order[#TimMenuGlobal.order] ~= windowUnderMouse then
316+
for j, v_key in ipairs(TimMenuGlobal.order) do
317+
if v_key == windowUnderMouse then
318+
table.remove(TimMenuGlobal.order, j)
319+
break
320+
end
321+
end
322+
table.insert(TimMenuGlobal.order, windowUnderMouse)
306323
end
307324
end
308325

326+
-- Update logic for all visible windows
309327
for i = 1, #TimMenuGlobal.order do
310328
local key = TimMenuGlobal.order[i]
311329
local win = TimMenuGlobal.windows[key]
312330
if win and win.visible then
313-
local isFocused = (key == focusedWindowKey)
331+
local isFocused = (key == windowUnderMouse)
314332
win:_UpdateLogic(
315333
mouseX,
316334
mouseY,
@@ -319,25 +337,6 @@ local function _TimMenu_GlobalDraw()
319337
input.IsButtonDown(MOUSE_LEFT),
320338
input.IsButtonReleased(MOUSE_LEFT)
321339
)
322-
323-
-- Only change focus if window allows it (prevents popup focus stealing)
324-
-- AND no widget has consumed the click
325-
if
326-
isFocused
327-
and input.IsButtonPressed(MOUSE_LEFT)
328-
and win:ShouldChangeFocus(mouseX, mouseY)
329-
and not Globals.isClickConsumed
330-
then
331-
if TimMenuGlobal.order[#TimMenuGlobal.order] ~= key then
332-
for j, v_key in ipairs(TimMenuGlobal.order) do
333-
if v_key == key then
334-
table.remove(TimMenuGlobal.order, j)
335-
break
336-
end
337-
end
338-
table.insert(TimMenuGlobal.order, key)
339-
end
340-
end
341340
end
342341
end
343342

@@ -358,9 +357,6 @@ local function _TimMenu_GlobalDraw()
358357
end
359358
end
360359

361-
-- Reset click consumption flag at end of frame
362-
Globals.isClickConsumed = false
363-
364360
if not reRegistered then
365361
callbacks.Unregister("Draw", "zTimMenu_GlobalDraw")
366362
callbacks.Register("Draw", "zTimMenu_GlobalDraw", _TimMenu_GlobalDraw)

TimMenu/WidgetBase.lua

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,4 @@ function WidgetBase.MeasureText(text)
111111
return draw.GetTextSize(text)
112112
end
113113

114-
--- Mark the current click as consumed by a widget
115-
--- This prevents the window manager from changing focus
116-
function WidgetBase.ConsumeClick()
117-
Globals.isClickConsumed = true
118-
end
119-
120114
return WidgetBase

TimMenu/Widgets/Combo.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,6 @@ local function Combo(win, label, selected, options)
164164
local idx = math.floor((input.GetMousePos()[2] - popupBounds.y) / height) + 1
165165
if idx >= 1 and idx <= #options then
166166
entry.selected[idx] = not entry.selected[idx]
167-
-- Consume the click to prevent window focus changes
168-
WidgetBase.ConsumeClick()
169167
end
170168
else
171169
entry.open = false

TimMenu/Widgets/Dropdown.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,6 @@ local function Dropdown(win, label, selectedIndex, options)
155155
entry.selected = idx
156156
entry.open = false
157157
win._widgetBlockedRegions = {}
158-
-- Consume the click to prevent window focus changes
159-
WidgetBase.ConsumeClick()
160158
end
161159
else
162160
entry.open = false

TimMenu/Window.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,16 @@ end
7676

7777
--- Hit test: is a point inside this window (including title bar, content area, and popups)?
7878
function Window:_HitTest(x, y)
79-
-- Basic window bounds (title and content)
79+
-- Check main window bounds (title bar + content area)
8080
local titleHeight = Globals.Defaults.TITLE_BAR_HEIGHT
81-
local basicBounds = x >= self.X and x <= self.X + self.W and y >= self.Y and y <= self.Y + titleHeight + self.H
81+
local mainBounds = x >= self.X and x <= self.X + self.W and y >= self.Y and y <= self.Y + titleHeight + self.H
8282

83-
-- If basic bounds pass, return true
84-
if basicBounds then
83+
-- If main bounds pass, return true
84+
if mainBounds then
8585
return true
8686
end
8787

88-
-- Check if point is in any widget blocked regions (popups)
88+
-- Check if point is in any popup regions (extended volume)
8989
if self._widgetBlockedRegions then
9090
for _, region in ipairs(self._widgetBlockedRegions) do
9191
if x >= region.x and x <= region.x + region.w and y >= region.y and y <= region.y + region.h then

0 commit comments

Comments
 (0)