diff --git a/src/menu/pause_menu.rs b/src/menu/pause_menu.rs index ed39c0f..f040b15 100644 --- a/src/menu/pause_menu.rs +++ b/src/menu/pause_menu.rs @@ -1,5 +1,6 @@ use crate::framework::context::Context; use crate::framework::error::GameResult; +use crate::framework::graphics; use crate::framework::keyboard::ScanCode; use crate::input::combined_menu_controller::CombinedMenuController; use crate::menu::MenuEntry; @@ -15,6 +16,7 @@ use super::settings_menu::SettingsMenu; enum CurrentMenu { PauseMenu, OptionsMenu, + ConfirmMenu, } pub struct PauseMenu { @@ -23,6 +25,7 @@ pub struct PauseMenu { option_menu: SettingsMenu, controller: CombinedMenuController, pause_menu: Menu, + confirm_menu: Menu, tick: u32, } @@ -36,6 +39,7 @@ impl PauseMenu { option_menu: SettingsMenu::new(), controller: CombinedMenuController::new(), pause_menu: main, + confirm_menu: Menu::new(0, 0, 75, 0), tick: 0, } } @@ -47,10 +51,15 @@ impl PauseMenu { self.pause_menu.push_entry(MenuEntry::Active("Resume".to_owned())); self.pause_menu.push_entry(MenuEntry::Active("Retry".to_owned())); self.pause_menu.push_entry(MenuEntry::Active("Options".to_owned())); - self.pause_menu.push_entry(MenuEntry::Active("Main Menu".to_owned())); - self.pause_menu.push_entry(MenuEntry::Disabled(" --- ".to_owned())); + self.pause_menu.push_entry(MenuEntry::Active("Title".to_owned())); self.pause_menu.push_entry(MenuEntry::Active("Quit".to_owned())); + self.confirm_menu.push_entry(MenuEntry::Disabled("".to_owned())); + self.confirm_menu.push_entry(MenuEntry::Active("Yes".to_owned())); + self.confirm_menu.push_entry(MenuEntry::Active("No".to_owned())); + + self.confirm_menu.selected = 1; + self.update_sizes(state); self.option_menu.init(state, ctx)?; @@ -65,10 +74,14 @@ impl PauseMenu { self.pause_menu.update_height(); self.pause_menu.x = ((state.canvas_size.0 - self.pause_menu.width as f32) / 2.0).floor() as isize; self.pause_menu.y = ((state.canvas_size.1 - self.pause_menu.height as f32) / 2.0).floor() as isize; + self.confirm_menu.update_height(); + self.confirm_menu.x = ((state.canvas_size.0 - self.confirm_menu.width as f32) / 2.0).floor() as isize; + self.confirm_menu.y = ((state.canvas_size.1 - self.confirm_menu.height as f32) / 2.0).floor() as isize; } - pub fn pause(&mut self) { + pub fn pause(&mut self, state: &mut SharedGameState) { self.is_paused = true; + state.sound_manager.play_sfx(5); } pub fn is_paused(&mut self) -> bool { @@ -81,8 +94,6 @@ impl PauseMenu { self.controller.update(state, ctx)?; self.controller.update_trigger(); - self.is_paused = true; - if ctx.keyboard_context.is_key_pressed(ScanCode::F2) { state.load_or_start_game(ctx)?; } @@ -103,11 +114,12 @@ impl PauseMenu { self.current_menu = CurrentMenu::OptionsMenu; } MenuSelectionResult::Selected(3, _) => { - state.textscript_vm.flags.set_cutscene_skip(false); - state.next_scene = Some(Box::new(TitleScene::new())); + self.confirm_menu.entries[0] = MenuEntry::Disabled("Title?".to_owned()); + self.current_menu = CurrentMenu::ConfirmMenu; } - MenuSelectionResult::Selected(5, _) => { - state.shutdown(); + MenuSelectionResult::Selected(4, _) => { + self.confirm_menu.entries[0] = MenuEntry::Disabled("Quit?".to_owned()); + self.current_menu = CurrentMenu::ConfirmMenu; } _ => (), }, @@ -122,6 +134,22 @@ impl PauseMenu { ctx, )?; } + CurrentMenu::ConfirmMenu => match self.confirm_menu.tick(&mut self.controller, state) { + MenuSelectionResult::Selected(1, _) => match self.pause_menu.selected { + 3 => { + state.textscript_vm.flags.set_cutscene_skip(false); + state.next_scene = Some(Box::new(TitleScene::new())); + } + 4 => { + state.shutdown(); + } + _ => (), + }, + MenuSelectionResult::Selected(2, _) | MenuSelectionResult::Canceled => { + self.current_menu = CurrentMenu::PauseMenu; + } + _ => (), + }, } self.tick += 1; @@ -131,13 +159,29 @@ impl PauseMenu { pub fn draw(&self, state: &mut SharedGameState, ctx: &mut Context) -> GameResult { if self.is_paused { + let clip_y = ((self.tick as f32 + state.frame_time as f32 - 2.0) * state.scale * 10.0) + .clamp(0.0, state.screen_size.1) as isize; + let clip_rect = crate::common::Rect::new_size( + 0, + (state.screen_size.1 / 2.0) as isize - clip_y, + state.screen_size.1 as isize, + clip_y * 2, + ); + match self.current_menu { CurrentMenu::PauseMenu => { + graphics::set_clip_rect(ctx, Some(clip_rect))?; self.pause_menu.draw(state, ctx)?; + graphics::set_clip_rect(ctx, None)?; } CurrentMenu::OptionsMenu => { self.option_menu.draw(state, ctx)?; } + CurrentMenu::ConfirmMenu => { + graphics::set_clip_rect(ctx, Some(clip_rect))?; + self.confirm_menu.draw(state, ctx)?; + graphics::set_clip_rect(ctx, None)?; + } } }