summaryrefslogtreecommitdiff
path: root/pixel-client/src/menu.rs
diff options
context:
space:
mode:
Diffstat (limited to 'pixel-client/src/menu.rs')
-rw-r--r--pixel-client/src/menu.rs21
1 files changed, 17 insertions, 4 deletions
diff --git a/pixel-client/src/menu.rs b/pixel-client/src/menu.rs
index bce5198b..9ebe525e 100644
--- a/pixel-client/src/menu.rs
+++ b/pixel-client/src/menu.rs
@@ -1,7 +1,10 @@
use crate::{
+ game::Game,
+ network::Network,
render::{sprite::SpriteDraw, AtlasLayout, Renderer},
tilemap::Tilemap,
ui::UiState,
+ State,
};
use hurrycurry_protocol::{
glam::{IVec2, Vec2},
@@ -13,12 +16,12 @@ use sdl2::{
mouse::MouseState,
};
-#[derive(Debug)]
pub struct Menu {
map: Tilemap,
fade_in: f32,
ui_state: UiState,
background: Vec2,
+ next_state: Option<Box<State>>,
}
impl Menu {
@@ -56,6 +59,7 @@ impl Menu {
fade_in: 0.,
ui_state: UiState::default(),
background: Vec2::ZERO,
+ next_state: None,
}
}
pub fn tick(
@@ -64,10 +68,12 @@ impl Menu {
keyboard: &KeyboardState,
mouse: &MouseState,
_layout: &AtlasLayout,
- ) {
+ ) -> Option<Box<State>> {
self.fade_in = (self.fade_in + dt).min(1.);
self.background += Vec2::new(2., 3.) * dt;
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);
@@ -97,18 +103,25 @@ impl Menu {
self.map.draw(ctx);
+ let mut request_join = false;
self.ui_state.draw(ctx, |ui| {
if ui.button(80., "Join") {
- eprintln!("join button")
+ request_join = true
}
if ui.button(80., "Settings") {
eprintln!("settings button")
}
if ui.button(80., "Quit") {
- eprintln!("quit button")
+ self.next_state = Some(Box::new(State::Quit));
}
ui.fill();
});
+ if request_join {
+ self.next_state = Some(Box::new(State::Ingame(Box::new(Game::new(
+ Network::connect("ws://127.0.0.1").unwrap(),
+ ctx.atlas_layout(),
+ )))))
+ }
ctx.draw_ui(SpriteDraw::overlay(
ctx.misc_textures.solid,