Well I got endgame working, then I kept going

Probably broke something, but I'm working on escape handling in
different contexts. Mostly going to the "expected" menu.
main
Elijah C. Voigt 2 years ago
parent aef8c719f2
commit 1ffb34b93b

@ -34,7 +34,7 @@ impl Plugin for GamePlugin {
reset_game.run_if(just_pressed(KeyCode::R)), reset_game.run_if(just_pressed(KeyCode::R)),
), ),
) )
.add_systems(OnEnter(GameState::Endgame), set_endgame) .add_systems(OnEnter(GameState::Endgame), set_endgame.after(manage_score))
.add_systems(OnExit(GameState::Endgame), clear_endgame) .add_systems(OnExit(GameState::Endgame), clear_endgame)
.add_systems( .add_systems(
PreUpdate, PreUpdate,
@ -246,8 +246,8 @@ impl Board {
inner: vec![ inner: vec![
vec![ vec![
Some(Queen), Some(Queen),
Some(Queen), None, // Some(Queen),
Some(Drone), None, // Some(Drone),
None, None,
None, None,
None, None,
@ -255,24 +255,20 @@ impl Board {
None, None,
], ],
vec![ vec![
Some(Queen), None, // Some(Queen),
Some(Drone), None, // Some(Drone),
Some(Pawn), None, // Some(Pawn),
None, None, None, None, // Some(Pawn),
None, None, // Some(Pawn),
Some(Pawn), None, // Some(Drone),
Some(Pawn),
Some(Drone),
], ],
vec![ vec![
Some(Drone), None, // Some(Drone),
Some(Pawn), None, // Some(Pawn),
Some(Pawn), None, // Some(Pawn),
None, None, None, None, // Some(Pawn),
None, None, // Some(Drone),
Some(Pawn), None, // Some(Queen),
Some(Drone),
Some(Queen),
], ],
vec![ vec![
None, None,
@ -280,8 +276,8 @@ impl Board {
None, None,
None, None,
None, None,
Some(Drone), None, // Some(Drone),
Some(Queen), None, // Some(Queen),
Some(Queen), Some(Queen),
], ],
], ],
@ -640,6 +636,70 @@ fn set_endgame(score: Res<Score>, mut commands: Commands) {
..default() ..default()
}, },
)); ));
parent
.spawn((
Endgame,
NodeBundle {
style: Style {
flex_direction: FlexDirection::Row,
..default()
},
..default()
},
))
.with_children(|parent| {
parent
.spawn((
menu::ButtonAction(GameState::Restart),
menu::ButtonAction(menu::MenuState::None),
ButtonBundle {
style: Style {
padding: UiRect::all(Val::Px(5.0)),
margin: UiRect::all(Val::Px(5.0)),
..default()
},
background_color: Color::ORANGE.with_a(0.5).into(),
..default()
},
))
.with_children(|parent| {
parent.spawn((TextBundle::from_section(
"New Game",
TextStyle {
color: Color::BLACK,
font_size: 32.0,
..default()
},
),));
});
// Quit button
parent
.spawn((
menu::ButtonAction(menu::MenuState::None),
menu::ButtonAction(GameState::Quit),
ButtonBundle {
style: Style {
padding: UiRect::all(Val::Px(5.0)),
margin: UiRect::all(Val::Px(5.0)),
..default()
},
background_color: Color::ORANGE.with_a(0.5).into(),
..default()
},
))
.with_children(|parent| {
parent.spawn((TextBundle::from_section(
"Quit",
TextStyle {
color: Color::BLACK,
font_size: 32.0,
..default()
},
),));
});
});
}); });
} }

@ -9,8 +9,9 @@ impl Plugin for MenuPlugin {
app.add_state::<MenuState>() app.add_state::<MenuState>()
// Initialize menus // Initialize menus
.add_systems( .add_systems(
// TODO: move this to game.rs or display3d.rs
OnExit(GameState::Loading), OnExit(GameState::Loading),
(init_play_menu, init_tutorial_menu, init_endgame_menu), init_play_menu,
) )
// Manage visible/hidden states // Manage visible/hidden states
.add_systems( .add_systems(
@ -26,7 +27,7 @@ impl Plugin for MenuPlugin {
) )
.run_if(any_component_changed::<Interaction>()), .run_if(any_component_changed::<Interaction>()),
) )
.add_systems(Update, set_menu_state.run_if(just_pressed(KeyCode::Escape))); .add_systems(Update, handle_escape.run_if(just_pressed(KeyCode::Escape)));
} }
} }
@ -180,165 +181,44 @@ fn init_play_menu(mut commands: Commands) {
}); });
} }
fn init_tutorial_menu(mut commands: Commands) { fn handle_escape(
commands
.spawn((
MenuState::Tutorial,
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()
},
))
.with_children(|parent| {
// Continue button
parent
.spawn((
ButtonAction(GameState::Play),
ButtonAction(MenuState::None),
ButtonBundle {
style: Style {
padding: UiRect::all(Val::Px(5.0)),
margin: UiRect::all(Val::Px(5.0)),
..default()
},
background_color: Color::ORANGE.with_a(0.5).into(),
..default()
},
))
.with_children(|parent| {
parent.spawn((TextBundle::from_section(
"Continue Game",
TextStyle {
color: Color::BLACK,
font_size: 32.0,
..default()
},
),));
});
// Quit button
parent
.spawn((
ButtonAction(GameState::Restart),
ButtonAction(MenuState::None),
ButtonBundle {
style: Style {
padding: UiRect::all(Val::Px(5.0)),
margin: UiRect::all(Val::Px(5.0)),
..default()
},
background_color: Color::ORANGE.with_a(0.5).into(),
..default()
},
))
.with_children(|parent| {
parent.spawn((TextBundle::from_section(
"Restart",
TextStyle {
color: Color::BLACK,
font_size: 32.0,
..default()
},
),));
});
});
}
fn init_endgame_menu(mut commands: Commands) {
commands
.spawn((
MenuState::Endgame,
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()
},
))
.with_children(|parent| {
// New Game button
parent
.spawn((
ButtonAction(GameState::Restart),
ButtonAction(MenuState::None),
ButtonBundle {
style: Style {
padding: UiRect::all(Val::Px(5.0)),
margin: UiRect::all(Val::Px(5.0)),
..default()
},
background_color: Color::ORANGE.with_a(0.5).into(),
..default()
},
))
.with_children(|parent| {
parent.spawn((TextBundle::from_section(
"New Game",
TextStyle {
color: Color::BLACK,
font_size: 32.0,
..default()
},
),));
});
// Quit button
parent
.spawn((
ButtonAction(MenuState::None),
ButtonAction(GameState::Quit),
ButtonBundle {
style: Style {
padding: UiRect::all(Val::Px(5.0)),
margin: UiRect::all(Val::Px(5.0)),
..default()
},
background_color: Color::ORANGE.with_a(0.5).into(),
..default()
},
))
.with_children(|parent| {
parent.spawn((TextBundle::from_section(
"Quit",
TextStyle {
color: Color::BLACK,
font_size: 32.0,
..default()
},
),));
});
});
}
fn set_menu_state(
game_state: Res<State<GameState>>, game_state: Res<State<GameState>>,
tutorial_state: Res<State<TutorialState>>,
mut next_game_state: ResMut<NextState<GameState>>,
mut next_menu_state: ResMut<NextState<MenuState>>, mut next_menu_state: ResMut<NextState<MenuState>>,
mut next_tutorial_state: ResMut<NextState<TutorialState>>,
) { ) {
match game_state.get() { match game_state.get() {
GameState::Loading => error!("No menu while loading!"), GameState::Loading => error!("No menu while loading!"),
GameState::Play => next_menu_state.set(MenuState::Play), // State(Play): ...
GameState::Endgame => next_menu_state.set(MenuState::Endgame), GameState::Play => {
GameState::Intro => error!("Should skip to GameState::Play"), match tutorial_state.get() {
GameState::Credits => error!("Should pop back to GameState::Play"), // State(Tutorial::None): Escape -> Play Menu
GameState::Restart | GameState::Quit => panic!("This shouldn't be possible!"), TutorialState::None => {
next_menu_state.set(MenuState::Play);
}
// State(Tutorial::*): Escape -> Quit Tutorial
_ => {
next_tutorial_state.set(TutorialState::None);
}
}
}
// State(Endgame): Escape -> Quit game
GameState::Endgame => {
next_game_state.set(GameState::Quit);
}
// State(Credits): Escape -> Play + Menu
GameState::Credits => {
next_game_state.set(GameState::Play);
next_menu_state.set(MenuState::Play);
}
// State(Intro): Escape -> Play
GameState::Intro => {
next_game_state.set(GameState::Play);
}
GameState::Restart | GameState::Quit => {
panic!("This shouldn't be possible!");
}
} }
} }

Loading…
Cancel
Save