diff options
Diffstat (limited to 'pixel-client/src/menu/ingame.rs')
-rw-r--r-- | pixel-client/src/menu/ingame.rs | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/pixel-client/src/menu/ingame.rs b/pixel-client/src/menu/ingame.rs new file mode 100644 index 00000000..ed1ad1bb --- /dev/null +++ b/pixel-client/src/menu/ingame.rs @@ -0,0 +1,77 @@ +use super::main::MainMenu; +use crate::{ + config::Config, + game::Game, + render::{sprite::SpriteDraw, AtlasLayout, Renderer}, + ui::UiState, + State, +}; +use hurrycurry_protocol::glam::Vec2; +use sdl2::{ + keyboard::{KeyboardState, Keycode}, + mouse::MouseState, +}; + +pub struct IngameMenu { + game: Box<Game>, + pub ui_state: UiState, + overlay_shown: bool, + next_state: Option<Box<State>>, +} +impl IngameMenu { + pub fn new(game: Game) -> Self { + Self { + overlay_shown: false, + game: Box::new(game), + ui_state: UiState::default(), + next_state: None, + } + } + pub fn tick( + &mut self, + dt: f32, + keyboard: &KeyboardState, + mouse: &MouseState, + layout: &AtlasLayout, + ) -> Option<Box<State>> { + self.game.tick(dt, keyboard, layout); + self.ui_state.update(keyboard, mouse, dt); + self.next_state.take() + } + pub fn keyboard_event(&mut self, keycode: Keycode, down: bool) { + self.ui_state.keyboard_event(keycode, down); + if down && keycode == Keycode::Escape { + self.overlay_shown = !self.overlay_shown + } + } + pub fn draw(&mut self, ctx: &mut Renderer, _config: &mut Config) { + self.game.draw(ctx); + if self.overlay_shown { + let mut main_menu = false; + ctx.draw_ui(SpriteDraw::overlay( + ctx.misc_textures.solid, + Vec2::ZERO, + ctx.ui_size, + Some([0, 0, 0, 130]), + )); + self.ui_state.draw(ctx, |ui| { + ui.horizontal(|ui| { + ui.advance(Vec2::splat(20.)); + ui.vertical(|ui| { + ui.advance(Vec2::splat(20.)); + let w = 80.; + main_menu |= ui.button(w, "Resume"); + ui.advance(Vec2::Y * 10.); + main_menu |= ui.button(w, "Main menu"); + if ui.button(w, "Quit") { + self.next_state = Some(Box::new(State::Quit)) + } + }); + }); + }); + if main_menu { + self.next_state = Some(Box::new(State::MainMenu(MainMenu::new(ctx.atlas_layout())))) + } + } + } +} |