Compare commits
3 Commits
9b71fff4eb
...
845765513d
| Author | SHA1 | Date | |
|---|---|---|---|
| 845765513d | |||
| 857aefda03 | |||
| 7f651481f6 |
@@ -42,7 +42,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Main game state indicator
|
/// Main game state indicator
|
||||||
#[derive(Debug, Hash, PartialEq, Eq, Clone, States)]
|
#[derive(Clone, Debug, Eq, Hash, PartialEq, States)]
|
||||||
enum GameState {
|
enum GameState {
|
||||||
MainMenu,
|
MainMenu,
|
||||||
Playing,
|
Playing,
|
||||||
@@ -101,7 +101,7 @@ enum WebSocketConnectionMessage {
|
|||||||
// TODO: Presumably a TeardownConnection, right?
|
// TODO: Presumably a TeardownConnection, right?
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Debug, Error)]
|
||||||
enum ConnSetupError {
|
enum ConnSetupError {
|
||||||
#[error("IO")]
|
#[error("IO")]
|
||||||
Io(#[from] std::io::Error),
|
Io(#[from] std::io::Error),
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ use bevy::{
|
|||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use crate::GameState;
|
||||||
|
|
||||||
pub const BTN_BORDER_COLOR: Color = Color::WHITE;
|
pub const BTN_BORDER_COLOR: Color = Color::WHITE;
|
||||||
pub const BTN_BG_COLOR: Color = Color::BLACK;
|
pub const BTN_BG_COLOR: Color = Color::BLACK;
|
||||||
pub const BTN_BG_SELECTED: Color = bevy::prelude::Color::Srgba(DARK_GRAY);
|
pub const BTN_BG_SELECTED: Color = bevy::prelude::Color::Srgba(DARK_GRAY);
|
||||||
@@ -29,13 +31,14 @@ pub fn spawn_main_menu(mut commands: Commands) {
|
|||||||
TextShadow::default(),
|
TextShadow::default(),
|
||||||
));
|
));
|
||||||
let mut start_button = cmds.spawn(button_bundle("Start game"));
|
let mut start_button = cmds.spawn(button_bundle("Start game"));
|
||||||
start_button.observe(|_trigger: On<Pointer<Click>>| {
|
start_button.observe(
|
||||||
info!("The start button was pressed.");
|
|_trigger: On<Pointer<Click>>, mut game_state: ResMut<NextState<GameState>>| {
|
||||||
});
|
game_state.set(GameState::Playing);
|
||||||
|
},
|
||||||
|
);
|
||||||
let mut quit_button = cmds.spawn(button_bundle("Quit Game"));
|
let mut quit_button = cmds.spawn(button_bundle("Quit Game"));
|
||||||
quit_button.observe(
|
quit_button.observe(
|
||||||
|_trigger: On<Pointer<Click>>, mut messages: MessageWriter<AppExit>| {
|
|_trigger: On<Pointer<Click>>, mut messages: MessageWriter<AppExit>| {
|
||||||
info!("The quit button was pressed.");
|
|
||||||
// Quit the game if the quit button was pressed.
|
// Quit the game if the quit button was pressed.
|
||||||
messages.write(AppExit::Success);
|
messages.write(AppExit::Success);
|
||||||
},
|
},
|
||||||
@@ -77,7 +80,7 @@ pub fn button_hover_start(
|
|||||||
trigger: On<Pointer<Over>>,
|
trigger: On<Pointer<Over>>,
|
||||||
mut button_colors: Query<(&mut BackgroundColor, &mut BorderColor), With<Button>>,
|
mut button_colors: Query<(&mut BackgroundColor, &mut BorderColor), With<Button>>,
|
||||||
) {
|
) {
|
||||||
if let Ok((mut bg, mut border)) = button_colors.get_mut(trigger.entity) {
|
if let Ok((mut bg, mut _border)) = button_colors.get_mut(trigger.entity) {
|
||||||
bg.0 = BTN_BG_SELECTED;
|
bg.0 = BTN_BG_SELECTED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -86,7 +89,7 @@ pub fn button_hover_stop(
|
|||||||
trigger: On<Pointer<Out>>,
|
trigger: On<Pointer<Out>>,
|
||||||
mut button_colors: Query<(&mut BackgroundColor, &mut BorderColor), With<Button>>,
|
mut button_colors: Query<(&mut BackgroundColor, &mut BorderColor), With<Button>>,
|
||||||
) {
|
) {
|
||||||
if let Ok((mut bg, mut border)) = button_colors.get_mut(trigger.entity) {
|
if let Ok((mut bg, mut _border)) = button_colors.get_mut(trigger.entity) {
|
||||||
bg.0 = BTN_BG_COLOR;
|
bg.0 = BTN_BG_COLOR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user