From a0dd6d45a023a28dfa2c1a113e523d578fcae775 Mon Sep 17 00:00:00 2001 From: hut Date: Tue, 14 May 2024 18:58:47 +0200 Subject: [PATCH] wrap cursor in menu --- src/menu.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/menu.rs b/src/menu.rs index 643594d..964b1d5 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -431,6 +431,8 @@ pub fn handle_input( mut ew_sfx: EventWriter, mut ew_updatemenu: EventWriter, ) { + let last_menu_entry = MENUDEF.len() - 1; + if keyboard_input.just_pressed(settings.key_menu) || keyboard_input.just_pressed(settings.key_vehicle) && settings.menu_active { @@ -443,7 +445,11 @@ pub fn handle_input( || keyboard_input.just_pressed(settings.key_mouseup) || keyboard_input.just_pressed(KeyCode::ArrowUp) { - menustate.cursor = menustate.cursor.saturating_sub(1); + menustate.cursor = if menustate.cursor == 0 { + last_menu_entry + } else { + menustate.cursor.saturating_sub(1) + }; ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Click)); ew_updatemenu.send(UpdateMenuEvent); } @@ -451,7 +457,11 @@ pub fn handle_input( || keyboard_input.just_pressed(settings.key_mousedown) || keyboard_input.just_pressed(KeyCode::ArrowDown) { - menustate.cursor = (menustate.cursor + 1).min(MENUDEF.len() - 1); + menustate.cursor = if menustate.cursor == last_menu_entry { + 0 + } else { + menustate.cursor.saturating_add(1) + }; ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Click)); ew_updatemenu.send(UpdateMenuEvent); }