aboutsummaryrefslogtreecommitdiff
path: root/pixel-client/src/menu
diff options
context:
space:
mode:
Diffstat (limited to 'pixel-client/src/menu')
-rw-r--r--pixel-client/src/menu/background.rs97
-rw-r--r--pixel-client/src/menu/credits.rs52
-rw-r--r--pixel-client/src/menu/ingame.rs78
-rw-r--r--pixel-client/src/menu/main.rs116
-rw-r--r--pixel-client/src/menu/mod.rs22
-rw-r--r--pixel-client/src/menu/settings.rs66
6 files changed, 0 insertions, 431 deletions
diff --git a/pixel-client/src/menu/background.rs b/pixel-client/src/menu/background.rs
deleted file mode 100644
index 190858a6..00000000
--- a/pixel-client/src/menu/background.rs
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- Hurry Curry! - a game about cooking
- Copyright (C) 2025 Hurry Curry! Contributors
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, version 3 of the License only.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <https://www.gnu.org/licenses/>.
-
-*/
-use crate::{
- render::{sprite::SpriteDraw, AtlasLayout, Renderer},
- tilemap::Tilemap,
-};
-use hurrycurry_protocol::{
- glam::{IVec2, Vec2},
- TileIndex,
-};
-use rand::{random, rng, seq::IndexedRandom};
-
-pub struct MenuBackground {
- background: Vec2,
- map: Tilemap,
-}
-
-impl MenuBackground {
- pub fn new(layout: &AtlasLayout) -> Self {
- let mut map = Tilemap::default();
- map.init(
- &[
- "floor",
- "tomato-crate",
- "steak-crate",
- "table",
- "chair",
- "counter",
- "sink",
- "stove",
- ]
- .map(String::from),
- layout,
- );
- static BUCKETS: &[&[usize]] = &[&[], &[0, 0, 0, 0, 1, 2], &[3, 4, 5], &[6, 7]];
-
- for x in -10..11 {
- for y in -10..11 {
- let p = Vec2::new(x as f32, y as f32);
- let w = (-p.length() * 0.15).exp();
- let k = ((random::<f32>() * w) * BUCKETS.len() as f32) as usize;
- if let Some(ti) = BUCKETS[k.min(BUCKETS.len())].choose(&mut rng()) {
- map.set(IVec2::new(x, y), Some(TileIndex(*ti)), [None; 4])
- }
- }
- }
- Self {
- map,
- background: Vec2::ZERO,
- }
- }
-
- pub fn tick(&mut self, dt: f32) {
- self.background += Vec2::new(2., 3.) * dt;
- self.background %= 256.;
- }
- pub fn draw(&self, ctx: &mut Renderer) {
- ctx.set_world_view(
- ctx.size / ctx.get_world_scale() * Vec2::new(0.8, 0.2),
- ctx.size.max_element() / 32. / 15.,
- );
-
- for x in -1..=2 {
- for y in -1..=2 {
- ctx.draw_ui(SpriteDraw::underlay(
- ctx.misc_textures.clouds,
- Vec2::new(x as f32, y as f32) * 256. + self.background,
- Vec2::ONE * 256.,
- None,
- ));
- }
- }
- ctx.draw_ui(SpriteDraw::underlay(
- ctx.misc_textures.solid,
- Vec2::ZERO,
- ctx.ui_size,
- Some([0, 0, 0, 50]),
- ));
-
- self.map.draw(ctx);
- }
-}
diff --git a/pixel-client/src/menu/credits.rs b/pixel-client/src/menu/credits.rs
deleted file mode 100644
index abf71ffe..00000000
--- a/pixel-client/src/menu/credits.rs
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- Hurry Curry! - a game about cooking
- Copyright (C) 2025 Hurry Curry! Contributors
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, version 3 of the License only.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <https://www.gnu.org/licenses/>.
-
-*/
-use crate::{render::sprite::SpriteDraw, strings::tr, ui::Ui};
-use hurrycurry_protocol::glam::Vec2;
-
-#[derive(Default)]
-pub struct CreditsMenu {}
-
-impl CreditsMenu {
- pub fn draw(&mut self, ui: &mut Ui) -> bool {
- ui.renderer.draw_ui(SpriteDraw::overlay(
- ui.renderer.misc_textures.solid,
- Vec2::ZERO,
- ui.renderer.ui_size,
- Some([0, 0, 0, 150]),
- ));
-
- let mut back = false;
-
- ui.horizontal(|ui| {
- ui.advance(Vec2::splat(30.));
- ui.vertical(|ui| {
- ui.advance(Vec2::splat(30.));
- ui.text("Pixel Curry!");
-
- ui.small_text(tr("c.credits.developed_by"));
-
- ui.text("metamuffin, BigBrotherNii");
-
- ui.advance(ui.get_remaining() - Vec2::Y * 30.);
- back = ui.button(80., tr("c.menu.back"));
- });
- });
-
- back
- }
-}
diff --git a/pixel-client/src/menu/ingame.rs b/pixel-client/src/menu/ingame.rs
deleted file mode 100644
index 66c77bce..00000000
--- a/pixel-client/src/menu/ingame.rs
+++ /dev/null
@@ -1,78 +0,0 @@
-use super::main::MainMenu;
-use crate::{
- config::Config,
- game::Game,
- render::{sprite::SpriteDraw, AtlasLayout, Renderer},
- strings::tr,
- 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, tr("c.menu.ingame.resume"));
- ui.advance(Vec2::Y * 10.);
- main_menu |= ui.button(w, tr("c.menu.ingame.main_menu"));
- if ui.button(w, tr("c.menu.ingame.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()))))
- }
- }
- }
-}
diff --git a/pixel-client/src/menu/main.rs b/pixel-client/src/menu/main.rs
deleted file mode 100644
index e50473d9..00000000
--- a/pixel-client/src/menu/main.rs
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- Hurry Curry! - a game about cooking
- Copyright (C) 2025 Hurry Curry! Contributors
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, version 3 of the License only.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <https://www.gnu.org/licenses/>.
-
-*/
-use super::{
- background::MenuBackground, credits::CreditsMenu, ingame::IngameMenu, settings::SettingsMenu,
-};
-use crate::{
- config::Config,
- game::Game,
- render::{sprite::SpriteDraw, AtlasLayout, Renderer},
- strings::tr,
- ui::UiState,
- State,
-};
-use hurrycurry_client_lib::network::sync::Network;
-use hurrycurry_protocol::glam::Vec2;
-use sdl2::{
- keyboard::{KeyboardState, Keycode},
- mouse::MouseState,
-};
-
-pub struct MainMenu {
- background: MenuBackground,
- fade_in: f32,
- pub ui_state: UiState,
- server_address: String,
- next_state: Option<Box<State>>,
- settings: Option<SettingsMenu>,
- credits: Option<CreditsMenu>,
-}
-
-impl MainMenu {
- pub fn new(layout: &AtlasLayout) -> Self {
- Self {
- background: MenuBackground::new(layout),
- fade_in: 0.,
- server_address: String::from("ws://127.0.0.1"),
- ui_state: UiState::default(),
- next_state: None,
- settings: None,
- credits: None,
- }
- }
- pub fn tick(
- &mut self,
- dt: f32,
- keyboard: &KeyboardState,
- mouse: &MouseState,
- _layout: &AtlasLayout,
- ) -> Option<Box<State>> {
- self.fade_in = (self.fade_in + dt).min(1.);
- self.ui_state.update(keyboard, mouse, dt);
- self.background.tick(dt);
- self.next_state.take()
- }
- pub fn keyboard_event(&mut self, keycode: Keycode, down: bool) {
- self.ui_state.keyboard_event(keycode, down);
- }
- pub fn draw(&mut self, ctx: &mut Renderer, config: &mut Config) {
- self.background.draw(ctx);
-
- self.ui_state.draw(ctx, |ui| {
- if let Some(settings) = &mut self.settings {
- if settings.draw(ui, config) {
- self.settings = None;
- }
- return;
- }
- if let Some(credits) = &mut self.credits {
- if credits.draw(ui) {
- self.credits = None;
- }
- return;
- }
- if ui.button(80., tr("c.menu.play.connect")) {
- self.next_state = Some(Box::new(State::Ingame(IngameMenu::new(Game::new(
- Network::connect(&self.server_address).unwrap(),
- config,
- ui.renderer.atlas_layout(),
- )))))
- }
- ui.textedit(80., &mut self.server_address);
- if ui.button(80., tr("c.menu.settings")) {
- self.settings = Some(SettingsMenu::default())
- }
- if ui.button(80., tr("c.menu.about.credits")) {
- self.credits = Some(CreditsMenu::default())
- }
- if ui.button(80., tr("c.menu.quit")) {
- self.next_state = Some(Box::new(State::Quit));
- }
- ui.fill();
- });
-
- ctx.draw_ui(SpriteDraw::overlay(
- ctx.misc_textures.solid,
- Vec2::ZERO,
- ctx.ui_size,
- Some([0, 0, 0, 255 - (self.fade_in * 255.) as u8]),
- ));
- }
-}
diff --git a/pixel-client/src/menu/mod.rs b/pixel-client/src/menu/mod.rs
deleted file mode 100644
index ea8b6fbd..00000000
--- a/pixel-client/src/menu/mod.rs
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- Hurry Curry! - a game about cooking
- Copyright (C) 2025 Hurry Curry! Contributors
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, version 3 of the License only.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <https://www.gnu.org/licenses/>.
-
-*/
-pub mod background;
-pub mod credits;
-pub mod ingame;
-pub mod main;
-pub mod settings;
diff --git a/pixel-client/src/menu/settings.rs b/pixel-client/src/menu/settings.rs
deleted file mode 100644
index 27a0e3f4..00000000
--- a/pixel-client/src/menu/settings.rs
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- Hurry Curry! - a game about cooking
- Copyright (C) 2025 Hurry Curry! Contributors
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, version 3 of the License only.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <https://www.gnu.org/licenses/>.
-
-*/
-use crate::{config::Config, render::sprite::SpriteDraw, strings::tr, ui::Ui};
-use hurrycurry_protocol::glam::Vec2;
-use log::warn;
-
-pub struct Settings {
- pub username: String,
-}
-
-#[derive(Default)]
-pub struct SettingsMenu {}
-
-impl SettingsMenu {
- pub fn draw(&mut self, ui: &mut Ui, config: &mut Config) -> bool {
- ui.renderer.draw_ui(SpriteDraw::overlay(
- ui.renderer.misc_textures.solid,
- Vec2::ZERO,
- ui.renderer.ui_size,
- Some([0, 0, 0, 150]),
- ));
-
- let mut back = false;
-
- ui.horizontal(|ui| {
- ui.advance(Vec2::splat(20.));
- ui.vertical(|ui| {
- ui.advance(Vec2::splat(10.));
- ui.text(tr("c.menu.settings"));
-
- ui.horizontal(|ui| {
- ui.text(tr("c.settings.username"));
- ui.advance(Vec2::X * 20.);
- ui.textedit(100., &mut config.username);
- });
-
- ui.advance(ui.get_remaining() - Vec2::Y * 30.);
-
- if ui.button(80., tr("c.menu.back")) {
- if let Err(e) = config.save() {
- warn!("cannot save config: {e}");
- } else {
- back = true
- }
- }
- });
- });
-
- back
- }
-}