diff --git a/modules/Input/module.jai b/modules/Input/module.jai index d35a4c5..3c0c68c 100644 --- a/modules/Input/module.jai +++ b/modules/Input/module.jai @@ -4,6 +4,28 @@ #load "sokol.jai"; +#scope_file +shouldLockMouseCursor : bool = false; +#scope_export; + +set_should_lock_cursor :: (shouldLock: bool) { + shouldLockMouseCursor = shouldLock; +} + +is_cursor_locked :: () -> bool { + return shouldLockMouseCursor; +} + +unlock_cursor :: () { + plat_set_cursor_lock(false); +} + +// We use this so menu and editor is unlocked and game is locked if the game sets the should lock. +lock_cursor_if_should :: () { + if shouldLockMouseCursor then plat_set_cursor_lock(true); +} + + Event_Type :: enum u32 { // If we set this to u8, our packing will stop matching C's. UNINITIALIZED :: 0; KEYBOARD :: 1; diff --git a/modules/Input/sokol.jai b/modules/Input/sokol.jai index 23d1300..8d4bfbb 100644 --- a/modules/Input/sokol.jai +++ b/modules/Input/sokol.jai @@ -7,6 +7,10 @@ input_mouse_y : float; set_custom_cursor_handling :: (is_custom: bool) { } +plat_set_cursor_lock :: (locked: bool) { + sapp_lock_mouse(locked); +} + get_key_code :: (key: sapp_keycode) -> Key_Code { using Key_Code; // non-ascii ordered as in ./module.jai/Key_Code diff --git a/src/editor/editor.jai b/src/editor/editor.jai index 36762a1..ce19cee 100644 --- a/src/editor/editor.jai +++ b/src/editor/editor.jai @@ -109,6 +109,11 @@ tick_editor_ui :: () { in_editor_view = !in_editor_view; g_mixer.paused = in_editor_view; clear_particles(); + if in_editor_view { + unlock_cursor(); + } else { + lock_cursor_if_should(); + } } #if !FLAG_RELEASE_BUILD && OS != .WASM { diff --git a/src/main.jai b/src/main.jai index 1eee5d1..263e6da 100644 --- a/src/main.jai +++ b/src/main.jai @@ -167,7 +167,7 @@ init_after_core :: () { // We want to do this last. game_init(); - // #if UNCAPPED_FRAMES then sapp_glx_swapinterval(0); + lock_cursor_if_should(); } diff --git a/src/settings_menu.jai b/src/settings_menu.jai index 9986067..49ecee7 100644 --- a/src/settings_menu.jai +++ b/src/settings_menu.jai @@ -220,10 +220,15 @@ navigate_to :: (page: Settings_Page) { g_settings.cursor = 0; } +close_settings_menu :: () { + save_settings(); + lock_cursor_if_should(); + g_settings.open = false; +} + go_back :: () { if g_settings.page == .MAIN { - save_settings(); - g_settings.open = false; + close_settings_menu(); } else { navigate_to(page_parent()); } @@ -234,10 +239,9 @@ handle_enter :: (index: s32 = -1) { if g_settings.page == { case .MAIN; game_items := cast(s32) g_settings_config.main_items.count; - if i == 0 { save_settings(); g_settings.open = false; } + if i == 0 then close_settings_menu(); else if i <= game_items { - save_settings(); - g_settings.open = false; + close_settings_menu(); g_settings_config.main_items[i - 1].on_select(); } else { i -= game_items; @@ -306,6 +310,7 @@ tick_settings_menu :: () { if is_action_start(Editor_Action.TOGGLE_SETTINGS) { if !g_settings.open { g_settings.open = true; + unlock_cursor(); navigate_to(.MAIN); generate_blobs(); } else {