From ca092ddbc01ed33b3a0838fbe8602fa3d7da9337 Mon Sep 17 00:00:00 2001 From: "Elijah C. Voigt" Date: Sun, 25 Feb 2024 17:29:30 -0800 Subject: [PATCH] Saving my place, reworking menus --- src/display3d.rs | 28 +++++++++++--- src/loading.rs | 2 + src/menu.rs | 98 ++++++++++++++++++++++++++++++++++-------------- src/tutorial.rs | 32 ---------------- 4 files changed, 93 insertions(+), 67 deletions(-) diff --git a/src/display3d.rs b/src/display3d.rs index 487190d..868f59c 100644 --- a/src/display3d.rs +++ b/src/display3d.rs @@ -104,10 +104,12 @@ impl Plugin for Display3dPlugin { .run_if(in_state(GameState::Play)) .run_if(in_state(DisplayState::Display3d)), ) - // Manage visible/hidden states .add_systems( - Update, - manage_state_entities::().run_if(state_changed::()), + OnEnter(GameState::Intro), + ( + // Toggle hidden/visible 3d entities + manage_state_entities::(), + ), ) .add_systems( OnEnter(GameState::Play), @@ -166,20 +168,32 @@ fn initialize(mut commands: Commands, board: Res, assets: Res, assets: Res, assets: Res) { commands.spawn(( Loading, + GameState::Loading, Camera2dBundle { ..default() }, UiCameraConfig { show_ui: true }, )); commands.spawn(( Loading, + GameState::Loading, ImageBundle { image: UiImage { texture: server.load("images/Liquid Mirror.jpg"), diff --git a/src/menu.rs b/src/menu.rs index 6c3086c..4a10d7b 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -1,3 +1,5 @@ +use bevy::ecs::system::EntityCommands; + use crate::prelude::*; pub(crate) struct MenuPlugin; @@ -27,34 +29,43 @@ enum MenuState { Endgame, } -fn init_menu_ui(mut commands: Commands) { +fn init_play_menu(mut commands: Commands) { + info!("Initializing Play menu"); + commands - .spawn((NodeBundle { - style: Style { - width: Val::Percent(100.0), - height: Val::Percent(100.0), - justify_content: JustifyContent::Center, - align_items: AlignItems::Center, - flex_direction: FlexDirection::Column, - position_type: PositionType::Absolute, + .spawn(( + MenuState::Play, + NodeBundle { + style: Style { + width: Val::Percent(100.0), + height: Val::Percent(100.0), + justify_content: JustifyContent::Center, + align_items: AlignItems::Center, + flex_direction: FlexDirection::Column, + position_type: PositionType::Absolute, + ..default() + }, + background_color: Color::NONE.into(), + visibility: Visibility::Hidden, ..default() }, - background_color: Color::NONE.into(), - visibility: Visibility::Hidden, - ..default() - },)) + )) .with_children(|parent| { - parent.spawn(TextBundle::from_section( - "M A R T I A N C H E S S", - TextStyle { - font_size: 48.0, - color: Color::ORANGE_RED, - ..default() - }, + parent.spawn(( + MenuState::Play, + TextBundle::from_section( + "M A R T I A N C H E S S", + TextStyle { + font_size: 48.0, + color: Color::ORANGE_RED, + ..default() + }, + ), )); parent .spawn(( - GameState::Intro, + GameState::Play, + MenuState::None, ButtonBundle { style: Style { padding: UiRect::all(Val::Px(5.0)), @@ -67,9 +78,10 @@ fn init_menu_ui(mut commands: Commands) { )) .with_children(|parent| { parent.spawn(( - GameState::Intro, + GameState::Play, + MenuState::None, TextBundle::from_section( - "Start", + "Continue", TextStyle { color: Color::BLACK, font_size: 32.0, @@ -82,6 +94,7 @@ fn init_menu_ui(mut commands: Commands) { parent .spawn(( GameState::Credits, + MenuState::None, ButtonBundle { style: Style { padding: UiRect::all(Val::Px(5.0)), @@ -95,6 +108,7 @@ fn init_menu_ui(mut commands: Commands) { .with_children(|parent| { parent.spawn(( GameState::Credits, + MenuState::None, TextBundle::from_section( "Credits", TextStyle { @@ -126,17 +140,43 @@ fn init_menu_ui(mut commands: Commands) { }, ),)); }); - }); -} -fn init_play_menu(mut commands: Commands) { - todo!("Play Menu"); + parent + .spawn(( + tutorial::TutorialState::Intro, // Marks the button to start the tutorial + GameState::Play, // Marks the button to be ignored during tutorial step cleanup + MenuState::None, + ButtonBundle { + style: Style { + padding: UiRect::all(Val::Px(5.0)), + margin: UiRect::all(Val::Px(5.0)), + position_type: PositionType::Absolute, + top: Val::Px(0.0), + right: Val::Px(0.0), + ..default() + }, + background_color: Color::ORANGE.with_a(0.5).into(), + visibility: Visibility::Hidden, + ..default() + }, + )) + .with_children(|parent| { + parent.spawn((TextBundle::from_section( + "Tutorial", + TextStyle { + color: Color::BLACK, + font_size: 16.0, + ..default() + }, + ),)); + }); + }); } fn init_tutorial_menu(mut commands: Commands) { - todo!("Tutorial Menu"); + error!("Tutorial Menu"); } fn init_endgame_menu(mut commands: Commands) { - todo!("Endgame Menu"); + error!("Endgame Menu"); } diff --git a/src/tutorial.rs b/src/tutorial.rs index 265939a..299ca4d 100644 --- a/src/tutorial.rs +++ b/src/tutorial.rs @@ -82,38 +82,6 @@ fn initialize_tutorial( info!("Initializing tutorial entities"); - // Tutorial button used for toggling on/off during gameplay - { - commands - .spawn(( - TutorialState::Intro, // Marks the button to start the tutorial - GameState::Play, // Marks the button to be ignored during tutorial step cleanup - ButtonBundle { - style: Style { - padding: UiRect::all(Val::Px(5.0)), - margin: UiRect::all(Val::Px(5.0)), - position_type: PositionType::Absolute, - top: Val::Px(0.0), - right: Val::Px(0.0), - ..default() - }, - background_color: Color::ORANGE.with_a(0.5).into(), - visibility: Visibility::Hidden, - ..default() - }, - )) - .with_children(|parent| { - parent.spawn((TextBundle::from_section( - "Tutorial", - TextStyle { - color: Color::BLACK, - font_size: 16.0, - ..default() - }, - ),)); - }); - } - let background_hex = tweak.get::("tutorial_rgba_background").unwrap(); let text_visible_hex = tweak.get::("tutorial_rgba_visible").unwrap();