generated from tipragot/rust
parent
479f83cca7
commit
1668735c04
|
@ -9,10 +9,11 @@ pub struct MenuPlugin;
|
||||||
|
|
||||||
impl Plugin for MenuPlugin {
|
impl Plugin for MenuPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
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, change_scaling);
|
||||||
app.add_systems(Update, hover_system);
|
app.add_systems(Update, hover_system);
|
||||||
app.add_systems(Update, pressed_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>,
|
hovered_texture: Handle<Image>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// TODO
|
||||||
|
#[derive(Component)]
|
||||||
|
struct MenuEntity;
|
||||||
|
|
||||||
/// Display the UI of the menu to host a game or join one.
|
/// Display the UI of the menu to host a game or join one.
|
||||||
fn menu_ui(mut commands: Commands, asset_server: Res<AssetServer>) {
|
fn menu_ui(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
commands.spawn(Camera2dBundle::default());
|
commands.spawn(Camera2dBundle::default());
|
||||||
|
@ -42,6 +47,7 @@ fn menu_ui(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
z_index: ZIndex::Local(0),
|
z_index: ZIndex::Local(0),
|
||||||
..default()
|
..default()
|
||||||
})
|
})
|
||||||
|
.insert(MenuEntity)
|
||||||
.with_children(|child: &mut ChildBuilder| main_node(child, &asset_server));
|
.with_children(|child: &mut ChildBuilder| main_node(child, &asset_server));
|
||||||
|
|
||||||
create_side_button(
|
create_side_button(
|
||||||
|
@ -51,7 +57,7 @@ fn menu_ui(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
top: Val::Px(25.),
|
top: Val::Px(25.),
|
||||||
bottom: Val::Auto,
|
bottom: Val::Auto,
|
||||||
},
|
},
|
||||||
CurrentScene::Lobby,
|
CurrentScene::Setting,
|
||||||
&mut commands,
|
&mut commands,
|
||||||
HoveredTexture {
|
HoveredTexture {
|
||||||
texture: asset_server.load("button_settings_icon.png"),
|
texture: asset_server.load("button_settings_icon.png"),
|
||||||
|
@ -94,7 +100,7 @@ fn create_side_button(
|
||||||
image: textures.texture.clone().into(),
|
image: textures.texture.clone().into(),
|
||||||
..default()
|
..default()
|
||||||
})
|
})
|
||||||
.insert((target_scene, textures));
|
.insert((target_scene, textures, MenuEntity));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TODO
|
/// TODO
|
||||||
|
@ -115,7 +121,7 @@ fn create_button(
|
||||||
image: textures.texture.clone().into(),
|
image: textures.texture.clone().into(),
|
||||||
..default()
|
..default()
|
||||||
})
|
})
|
||||||
.insert((target_scene, textures));
|
.insert((target_scene, textures, MenuEntity));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TODO
|
/// TODO
|
||||||
|
@ -159,21 +165,23 @@ fn default_style() -> Style {
|
||||||
|
|
||||||
/// TODO
|
/// TODO
|
||||||
fn main_node(main_node: &mut ChildBuilder<'_, '_, '_>, asset_server: &Res<AssetServer>) {
|
fn main_node(main_node: &mut ChildBuilder<'_, '_, '_>, asset_server: &Res<AssetServer>) {
|
||||||
main_node.spawn(ImageBundle {
|
main_node
|
||||||
style: Style {
|
.spawn(ImageBundle {
|
||||||
height: Val::Px(150.),
|
style: Style {
|
||||||
width: Val::Px(613.5),
|
height: Val::Px(150.),
|
||||||
margin: UiRect {
|
width: Val::Px(613.5),
|
||||||
left: Val::Auto,
|
margin: UiRect {
|
||||||
right: Val::Auto,
|
left: Val::Auto,
|
||||||
top: Val::Px(25.),
|
right: Val::Auto,
|
||||||
bottom: Val::Px(50.),
|
top: Val::Px(25.),
|
||||||
|
bottom: Val::Px(50.),
|
||||||
|
},
|
||||||
|
..default()
|
||||||
},
|
},
|
||||||
|
image: asset_server.load("bw.png").into(),
|
||||||
..default()
|
..default()
|
||||||
},
|
})
|
||||||
image: asset_server.load("bw.png").into(),
|
.insert(MenuEntity);
|
||||||
..default()
|
|
||||||
});
|
|
||||||
|
|
||||||
main_node
|
main_node
|
||||||
.spawn(NodeBundle {
|
.spawn(NodeBundle {
|
||||||
|
@ -197,12 +205,14 @@ fn main_node(main_node: &mut ChildBuilder<'_, '_, '_>, asset_server: &Res<AssetS
|
||||||
style: default_style(),
|
style: default_style(),
|
||||||
..default()
|
..default()
|
||||||
})
|
})
|
||||||
|
.insert(MenuEntity)
|
||||||
.with_children(|host| {
|
.with_children(|host| {
|
||||||
host.spawn(NodeBundle {
|
host.spawn(NodeBundle {
|
||||||
style: default_style(),
|
style: default_style(),
|
||||||
background_color: BackgroundColor(Color::YELLOW),
|
background_color: BackgroundColor(Color::YELLOW),
|
||||||
..default()
|
..default()
|
||||||
});
|
})
|
||||||
|
.insert(MenuEntity);
|
||||||
create_button(
|
create_button(
|
||||||
CurrentScene::Lobby,
|
CurrentScene::Lobby,
|
||||||
host,
|
host,
|
||||||
|
@ -218,12 +228,14 @@ fn main_node(main_node: &mut ChildBuilder<'_, '_, '_>, asset_server: &Res<AssetS
|
||||||
style: default_style(),
|
style: default_style(),
|
||||||
..default()
|
..default()
|
||||||
})
|
})
|
||||||
|
.insert(MenuEntity)
|
||||||
.with_children(|join| {
|
.with_children(|join| {
|
||||||
join.spawn(NodeBundle {
|
join.spawn(NodeBundle {
|
||||||
style: default_style(),
|
style: default_style(),
|
||||||
background_color: BackgroundColor(Color::YELLOW),
|
background_color: BackgroundColor(Color::YELLOW),
|
||||||
..default()
|
..default()
|
||||||
});
|
})
|
||||||
|
.insert(MenuEntity);
|
||||||
create_button(
|
create_button(
|
||||||
CurrentScene::Lobby,
|
CurrentScene::Lobby,
|
||||||
join,
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_egui::EguiPlugin;
|
use bevy_egui::EguiPlugin;
|
||||||
|
|
||||||
use crate::CurrentScene;
|
use crate::{change_scaling, CurrentScene};
|
||||||
|
|
||||||
pub mod lobby;
|
pub mod lobby;
|
||||||
pub mod menu;
|
pub mod menu;
|
||||||
|
@ -16,6 +16,7 @@ impl Plugin for ScenesPlugin {
|
||||||
app.add_plugins(EguiPlugin)
|
app.add_plugins(EguiPlugin)
|
||||||
.add_state::<CurrentScene>()
|
.add_state::<CurrentScene>()
|
||||||
.add_plugins(menu::MenuPlugin)
|
.add_plugins(menu::MenuPlugin)
|
||||||
.add_plugins(lobby::LobbyPlugin);
|
.add_plugins(lobby::LobbyPlugin)
|
||||||
|
.add_systems(Update, change_scaling);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue