From b985269dff699d3713d053dda3f7c9123817d314 Mon Sep 17 00:00:00 2001 From: salmonik Date: Tue, 27 Oct 2026 14:36:11 +0100 Subject: Menu: latch the Insert key and expand the root on open --- src/menu.cpp | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'src/menu.cpp') diff --git a/src/menu.cpp b/src/menu.cpp index 4f76529..8df67fe 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -143,8 +143,10 @@ static MenuNode *g_visible[48]; // flattened visible nodes for arrow navigation static int g_visible_count = 0; static int g_selected = 0; bool g_menu_open = false; +static bool g_menu_draw_logged = false; static bool g_bind_mode = false; +static bool g_insert_latch = false; static void build_tree() { g_bhop_feat.children[0] = &g_bhop_active; g_bhop_feat.children[1] = &g_bhop_autostrafe_node; @@ -598,12 +600,24 @@ bool aimbot_fov_circle() { return g_aim_fov_circle; } static void menu_handle_input() { poll_keyboard(); + // SDL state can be sampled several times per rendered frame (both ISurface + // hooks call outer_draw). Use a physical-key latch instead of the one-poll + // edge so one press cannot open and close the menu in the same frame. + bool insert_down = key_held(SCAN_INSERT); + bool insert_edge = insert_down && !g_insert_latch; + if (insert_down) + g_insert_latch = true; + else + g_insert_latch = false; + if (!g_menu_open) { - if (key_pressed(SCAN_INSERT)) { - std::logf("insert pressed"); + if (insert_edge) { g_menu_open = true; g_bind_mode = false; + if (!g_root.expanded) + g_root.expanded = true; rebuild_visible(); + logf("menu: open rows=%d", g_visible_count); } return; } @@ -646,8 +660,10 @@ static void menu_handle_input() { } // normal navigation - if (key_pressed(SCAN_INSERT) || key_pressed(SCAN_ESCAPE)) { + if (insert_edge || key_pressed(SCAN_ESCAPE)) { g_menu_open = false; + g_menu_draw_logged = false; + logf("menu: closed"); return; } if (key_pressed(SCAN_UP) && g_selected > 0) { @@ -856,6 +872,10 @@ void outer_draw() { surf_pop_make_current(panel); return; } + if (!g_menu_draw_logged) { + g_menu_draw_logged = true; + logf("menu: drawing rows=%d selected=%d", g_visible_count, g_selected); + } for (int i = 0; i < g_visible_count; i++) { MenuNode *n = g_visible[i]; char line[96]; -- cgit v1.2.3