From b1b3b131e2b3920b2a939283b8e2f2e97f414f63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sallai=20J=C3=B3zsef?= Date: Sun, 21 Aug 2022 22:06:06 +0300 Subject: [PATCH] process debug keys in game scene and add quick save shortcut --- src/framework/backend_sdl2.rs | 4 +++- src/live_debugger.rs | 6 ++++- src/scene/game_scene.rs | 43 +++++++++++++++++++++++++++++++++++ src/scene/mod.rs | 10 ++++++++ src/shared_game_state.rs | 35 ---------------------------- 5 files changed, 61 insertions(+), 37 deletions(-) diff --git a/src/framework/backend_sdl2.rs b/src/framework/backend_sdl2.rs index 6e091d7..85dce41 100644 --- a/src/framework/backend_sdl2.rs +++ b/src/framework/backend_sdl2.rs @@ -276,7 +276,9 @@ impl BackendEventLoop for SDL2EventLoop { Event::KeyDown { scancode: Some(scancode), repeat, keymod, .. } => { if let Some(drs_scan) = conv_scancode(scancode) { if !repeat { - state.process_debug_keys(ctx, drs_scan); + if let Some(scene) = &mut game.scene { + scene.process_debug_keys(state, ctx, drs_scan); + } if keymod.intersects(keyboard::Mod::RALTMOD | keyboard::Mod::LALTMOD) && drs_scan == ScanCode::Return diff --git a/src/live_debugger.rs b/src/live_debugger.rs index 280d189..eb9b44e 100644 --- a/src/live_debugger.rs +++ b/src/live_debugger.rs @@ -154,6 +154,7 @@ impl LiveDebugger { if state.textscript_vm.state == TextScriptExecutionState::Ended { if ui.button("Save") { let _ = state.save_game(game_scene, ctx); + state.sound_manager.play_sfx(18); } } else if ui.button("Busy") { } @@ -162,7 +163,9 @@ impl LiveDebugger { if ui.button("Hotkey List") { self.hotkey_list_visible = !self.hotkey_list_visible; } + ui.checkbox("noclip", &mut state.settings.noclip); + ui.same_line(); ui.checkbox("more rust", &mut state.more_rust); }); @@ -402,7 +405,7 @@ impl LiveDebugger { if self.hotkey_list_visible { Window::new("Hotkeys") .position([400.0, 5.0], Condition::FirstUseEver) - .size([300.0, 240.0], Condition::FirstUseEver) + .size([300.0, 280.0], Condition::FirstUseEver) .resizable(false) .build(ui, || { let key = vec![ @@ -418,6 +421,7 @@ impl LiveDebugger { "F11 > Toggle FPS Counter", "F12 > Toggle Debugger", "Ctrl + F3 > Reload Sound Manager", + "Ctrl + S > Quick Save", ]; for hotkeys in key.iter() { match hotkeys { diff --git a/src/scene/game_scene.rs b/src/scene/game_scene.rs index 348b38c..91c95b3 100644 --- a/src/scene/game_scene.rs +++ b/src/scene/game_scene.rs @@ -30,6 +30,7 @@ use crate::framework::backend::SpriteBatchCommand; use crate::framework::context::Context; use crate::framework::error::GameResult; use crate::framework::graphics::{draw_rect, BlendMode, FilterMode}; +use crate::framework::keyboard::ScanCode; use crate::framework::ui::Components; use crate::framework::{filesystem, gamepad, graphics}; use crate::input::touch_controls::TouchControlType; @@ -2320,4 +2321,46 @@ impl Scene for GameScene { components.live_debugger.run_ingame(self, state, ctx, ui)?; Ok(()) } + + fn process_debug_keys(&mut self, state: &mut SharedGameState, ctx: &mut Context, key_code: ScanCode) -> GameResult { + if key_code == ScanCode::F3 && ctx.keyboard_context.active_mods().ctrl() { + let _ = state.sound_manager.reload(); + return Ok(()); + } + + if key_code == ScanCode::S && ctx.keyboard_context.active_mods().ctrl() { + let _ = state.save_game(self, ctx); + state.sound_manager.play_sfx(18); + return Ok(()); + } + + #[cfg(not(debug_assertions))] + if !state.settings.debug_mode { + return Ok(()); + } + + match key_code { + ScanCode::F3 => state.settings.god_mode = !state.settings.god_mode, + ScanCode::F4 => state.settings.infinite_booster = !state.settings.infinite_booster, + ScanCode::F5 => state.settings.subpixel_coords = !state.settings.subpixel_coords, + ScanCode::F6 => state.settings.motion_interpolation = !state.settings.motion_interpolation, + ScanCode::F7 => state.set_speed(1.0), + ScanCode::F8 => { + if state.settings.speed > 0.2 { + state.set_speed(state.settings.speed - 0.1); + } + } + ScanCode::F9 => { + if state.settings.speed < 3.0 { + state.set_speed(state.settings.speed + 0.1); + } + } + ScanCode::F10 => state.settings.debug_outlines = !state.settings.debug_outlines, + ScanCode::F11 => state.settings.fps_counter = !state.settings.fps_counter, + ScanCode::F12 => state.debugger = !state.debugger, + _ => {} + }; + + Ok(()) + } } diff --git a/src/scene/mod.rs b/src/scene/mod.rs index bf3fd87..4943159 100644 --- a/src/scene/mod.rs +++ b/src/scene/mod.rs @@ -1,5 +1,6 @@ use crate::framework::context::Context; use crate::framework::error::GameResult; +use crate::framework::keyboard::ScanCode; use crate::framework::ui::Components; use crate::shared_game_state::SharedGameState; @@ -44,6 +45,15 @@ pub trait Scene: downcast::Any { ) -> GameResult { Ok(()) } + + fn process_debug_keys( + &mut self, + _state: &mut SharedGameState, + _ctx: &mut Context, + _key_code: ScanCode, + ) -> GameResult { + Ok(()) + } } downcast::impl_downcast!(dyn Scene); diff --git a/src/shared_game_state.rs b/src/shared_game_state.rs index a546389..0444562 100644 --- a/src/shared_game_state.rs +++ b/src/shared_game_state.rs @@ -13,7 +13,6 @@ use crate::framework::backend::BackendTexture; use crate::framework::context::Context; use crate::framework::error::GameResult; use crate::framework::graphics::{create_texture_mutable, set_render_target}; -use crate::framework::keyboard::ScanCode; use crate::framework::vfs::OpenOptions; use crate::framework::{filesystem, graphics}; #[cfg(feature = "hooks")] @@ -489,40 +488,6 @@ impl SharedGameState { }) } - pub fn process_debug_keys(&mut self, ctx: &mut Context, key_code: ScanCode) { - if key_code == ScanCode::F3 && ctx.keyboard_context.active_mods().ctrl() { - let _ = self.sound_manager.reload(); - return; - } - - #[cfg(not(debug_assertions))] - if !self.settings.debug_mode { - return; - } - - match key_code { - ScanCode::F3 => self.settings.god_mode = !self.settings.god_mode, - ScanCode::F4 => self.settings.infinite_booster = !self.settings.infinite_booster, - ScanCode::F5 => self.settings.subpixel_coords = !self.settings.subpixel_coords, - ScanCode::F6 => self.settings.motion_interpolation = !self.settings.motion_interpolation, - ScanCode::F7 => self.set_speed(1.0), - ScanCode::F8 => { - if self.settings.speed > 0.2 { - self.set_speed(self.settings.speed - 0.1); - } - } - ScanCode::F9 => { - if self.settings.speed < 3.0 { - self.set_speed(self.settings.speed + 0.1); - } - } - ScanCode::F10 => self.settings.debug_outlines = !self.settings.debug_outlines, - ScanCode::F11 => self.settings.fps_counter = !self.settings.fps_counter, - ScanCode::F12 => self.debugger = !self.debugger, - _ => {} - } - } - pub fn reload_resources(&mut self, ctx: &mut Context) -> GameResult { self.constants.rebuild_path_list(self.mod_path.clone(), self.season, &self.settings); if !self.constants.is_demo {