commit
Some checks failed
Rust Checks / checks (push) Failing after 4s

This commit is contained in:
Raphaël 2024-03-03 01:56:36 +01:00
parent 479f83cca7
commit 1668735c04
2 changed files with 41 additions and 21 deletions

View file

@ -9,10 +9,11 @@ pub struct MenuPlugin;
impl Plugin for MenuPlugin {
fn build(&self, app: &mut App) {
app.add_systems(Startup, menu_ui.run_if(in_state(CurrentScene::Menu)));
app.add_systems(OnEnter(CurrentScene::Menu), menu_ui);
app.add_systems(Update, change_scaling);
app.add_systems(Update, hover_system);
app.add_systems(Update, pressed_system);
app.add_systems(OnExit(CurrentScene::Menu), destroy_menu);
}
}
@ -26,6 +27,10 @@ struct HoveredTexture {
hovered_texture: Handle<Image>,
}
/// TODO
#[derive(Component)]
struct MenuEntity;
/// Display the UI of the menu to host a game or join one.
fn menu_ui(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera2dBundle::default());
@ -42,6 +47,7 @@ fn menu_ui(mut commands: Commands, asset_server: Res<AssetServer>) {
z_index: ZIndex::Local(0),
..default()
})
.insert(MenuEntity)
.with_children(|child: &mut ChildBuilder| main_node(child, &asset_server));
create_side_button(
@ -51,7 +57,7 @@ fn menu_ui(mut commands: Commands, asset_server: Res<AssetServer>) {
top: Val::Px(25.),
bottom: Val::Auto,
},
CurrentScene::Lobby,
CurrentScene::Setting,
&mut commands,
HoveredTexture {
texture: asset_server.load("button_settings_icon.png"),
@ -94,7 +100,7 @@ fn create_side_button(
image: textures.texture.clone().into(),
..default()
})
.insert((target_scene, textures));
.insert((target_scene, textures, MenuEntity));
}
/// TODO
@ -115,7 +121,7 @@ fn create_button(
image: textures.texture.clone().into(),
..default()
})
.insert((target_scene, textures));
.insert((target_scene, textures, MenuEntity));
}
/// TODO
@ -159,7 +165,8 @@ fn default_style() -> Style {
/// TODO
fn main_node(main_node: &mut ChildBuilder<'_, '_, '_>, asset_server: &Res<AssetServer>) {
main_node.spawn(ImageBundle {
main_node
.spawn(ImageBundle {
style: Style {
height: Val::Px(150.),
width: Val::Px(613.5),
@ -173,7 +180,8 @@ fn main_node(main_node: &mut ChildBuilder<'_, '_, '_>, asset_server: &Res<AssetS
},
image: asset_server.load("bw.png").into(),
..default()
});
})
.insert(MenuEntity);
main_node
.spawn(NodeBundle {
@ -197,12 +205,14 @@ fn main_node(main_node: &mut ChildBuilder<'_, '_, '_>, asset_server: &Res<AssetS
style: default_style(),
..default()
})
.insert(MenuEntity)
.with_children(|host| {
host.spawn(NodeBundle {
style: default_style(),
background_color: BackgroundColor(Color::YELLOW),
..default()
});
})
.insert(MenuEntity);
create_button(
CurrentScene::Lobby,
host,
@ -218,12 +228,14 @@ fn main_node(main_node: &mut ChildBuilder<'_, '_, '_>, asset_server: &Res<AssetS
style: default_style(),
..default()
})
.insert(MenuEntity)
.with_children(|join| {
join.spawn(NodeBundle {
style: default_style(),
background_color: BackgroundColor(Color::YELLOW),
..default()
});
})
.insert(MenuEntity);
create_button(
CurrentScene::Lobby,
join,
@ -235,3 +247,10 @@ fn main_node(main_node: &mut ChildBuilder<'_, '_, '_>, asset_server: &Res<AssetS
});
});
}
/// TODO
fn destroy_menu(mut commands: Commands, query: Query<Entity, With<MenuEntity>>) {
for entity in query.iter() {
commands.entity(entity).despawn_recursive();
}
}

View file

@ -3,7 +3,7 @@
use bevy::prelude::*;
use bevy_egui::EguiPlugin;
use crate::CurrentScene;
use crate::{change_scaling, CurrentScene};
pub mod lobby;
pub mod menu;
@ -16,6 +16,7 @@ impl Plugin for ScenesPlugin {
app.add_plugins(EguiPlugin)
.add_state::<CurrentScene>()
.add_plugins(menu::MenuPlugin)
.add_plugins(lobby::LobbyPlugin);
.add_plugins(lobby::LobbyPlugin)
.add_systems(Update, change_scaling);
}
}