generated from tipragot/rust
parent
65db8d8492
commit
479f83cca7
|
@ -6,6 +6,7 @@ resolver = "2"
|
||||||
missing_docs = "warn"
|
missing_docs = "warn"
|
||||||
|
|
||||||
[workspace.lints.clippy]
|
[workspace.lints.clippy]
|
||||||
|
type_complexity = "allow"
|
||||||
missing_docs_in_private_items = "warn"
|
missing_docs_in_private_items = "warn"
|
||||||
unwrap_in_result = "warn"
|
unwrap_in_result = "warn"
|
||||||
unwrap_used = "warn"
|
unwrap_used = "warn"
|
||||||
|
|
BIN
crates/border-wars/assets/button_menu_icon_hover.png
Normal file
BIN
crates/border-wars/assets/button_menu_icon_hover.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.9 KiB |
BIN
crates/border-wars/assets/button_settings_icon_hover.png
Normal file
BIN
crates/border-wars/assets/button_settings_icon_hover.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4 KiB |
BIN
crates/border-wars/assets/bw.png
Normal file
BIN
crates/border-wars/assets/bw.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 205 KiB |
BIN
crates/border-wars/assets/host.png
Normal file
BIN
crates/border-wars/assets/host.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
BIN
crates/border-wars/assets/join.png
Normal file
BIN
crates/border-wars/assets/join.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
|
@ -11,14 +11,18 @@ 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(Startup, menu_ui.run_if(in_state(CurrentScene::Menu)));
|
||||||
app.add_systems(Update, change_scaling);
|
app.add_systems(Update, change_scaling);
|
||||||
app.add_systems(Update, handle_button);
|
app.add_systems(Update, hover_system);
|
||||||
|
app.add_systems(Update, pressed_system);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TODO
|
/// TODO
|
||||||
#[derive(Component, Clone)]
|
#[derive(Component, Clone)]
|
||||||
struct HoveredTexture {
|
struct HoveredTexture {
|
||||||
|
/// TODO
|
||||||
texture: Handle<Image>,
|
texture: Handle<Image>,
|
||||||
|
|
||||||
|
/// TODO
|
||||||
hovered_texture: Handle<Image>,
|
hovered_texture: Handle<Image>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,10 +40,9 @@ fn menu_ui(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
z_index: ZIndex::Local(0),
|
z_index: ZIndex::Local(0),
|
||||||
background_color: Color::GREEN.into(),
|
|
||||||
..default()
|
..default()
|
||||||
})
|
})
|
||||||
.with_children(|node| main_node(node));
|
.with_children(|child: &mut ChildBuilder| main_node(child, &asset_server));
|
||||||
|
|
||||||
create_side_button(
|
create_side_button(
|
||||||
UiRect {
|
UiRect {
|
||||||
|
@ -52,7 +55,7 @@ fn menu_ui(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
&mut commands,
|
&mut commands,
|
||||||
HoveredTexture {
|
HoveredTexture {
|
||||||
texture: asset_server.load("button_settings_icon.png"),
|
texture: asset_server.load("button_settings_icon.png"),
|
||||||
hovered_texture: asset_server.load("button_menu_icon.png"),
|
hovered_texture: asset_server.load("button_settings_icon_hover.png"),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -67,7 +70,7 @@ fn menu_ui(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
&mut commands,
|
&mut commands,
|
||||||
HoveredTexture {
|
HoveredTexture {
|
||||||
texture: asset_server.load("button_menu_icon.png"),
|
texture: asset_server.load("button_menu_icon.png"),
|
||||||
hovered_texture: asset_server.load("button_settings_icon.png"),
|
hovered_texture: asset_server.load("button_menu_icon_hover.png"),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -87,52 +90,60 @@ fn create_side_button(
|
||||||
margin,
|
margin,
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
z_index: ZIndex::Local(1),
|
z_index: ZIndex::Global(14),
|
||||||
background_color: Color::NONE.into(),
|
image: textures.texture.clone().into(),
|
||||||
..default()
|
..default()
|
||||||
})
|
})
|
||||||
.insert((target_scene, textures.clone()))
|
.insert((target_scene, textures));
|
||||||
.with_children(|button| {
|
|
||||||
button.spawn(ImageBundle {
|
|
||||||
style: Style {
|
|
||||||
width: Val::Percent(100.),
|
|
||||||
height: Val::Percent(100.),
|
|
||||||
..default()
|
|
||||||
},
|
|
||||||
image: textures.texture.into(),
|
|
||||||
..default()
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_button(
|
/// TODO
|
||||||
interaction_query: Query<
|
fn create_button(
|
||||||
(&Interaction, &CurrentScene, &mut Children, &HoveredTexture),
|
target_scene: CurrentScene,
|
||||||
(Changed<Interaction>, With<Button>),
|
commands: &mut ChildBuilder,
|
||||||
>,
|
textures: HoveredTexture,
|
||||||
mut image_query: Query<&mut UiImage>,
|
) {
|
||||||
|
commands
|
||||||
|
.spawn(ButtonBundle {
|
||||||
|
style: Style {
|
||||||
|
width: Val::Px(266.),
|
||||||
|
height: Val::Px(70.),
|
||||||
|
margin: UiRect::all(Val::Auto),
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
z_index: ZIndex::Global(1),
|
||||||
|
image: textures.texture.clone().into(),
|
||||||
|
..default()
|
||||||
|
})
|
||||||
|
.insert((target_scene, textures));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// TODO
|
||||||
|
fn pressed_system(
|
||||||
|
interaction_query: Query<(&Interaction, &CurrentScene), (Changed<Interaction>, With<Button>)>,
|
||||||
mut next_scene: ResMut<NextState<CurrentScene>>,
|
mut next_scene: ResMut<NextState<CurrentScene>>,
|
||||||
) {
|
) {
|
||||||
for (interaction, target_scene, children, textures) in interaction_query.iter() {
|
for (interaction, target_scene) in interaction_query.iter() {
|
||||||
match *interaction {
|
if *interaction == Interaction::Pressed {
|
||||||
Interaction::Pressed => {
|
next_scene.set(*target_scene);
|
||||||
next_scene.set(*target_scene);
|
|
||||||
}
|
|
||||||
Interaction::Hovered => {
|
|
||||||
hover_system(children, &mut image_query, textures.texture.clone())
|
|
||||||
}
|
|
||||||
Interaction::None => hover_system(children, &mut image_query, textures.hovered_texture.clone()),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// TODO
|
||||||
fn hover_system(
|
fn hover_system(
|
||||||
children: &Children,
|
mut interaction_query: Query<
|
||||||
image_query: &mut Query<&mut UiImage>,
|
(&Interaction, &HoveredTexture, &mut UiImage),
|
||||||
texture: Handle<Image>,
|
Changed<Interaction>,
|
||||||
|
>,
|
||||||
) {
|
) {
|
||||||
let mut image = image_query.get_mut(children[0]).unwrap();
|
for (interaction, textures, mut image) in interaction_query.iter_mut() {
|
||||||
image.texture = texture
|
match *interaction {
|
||||||
|
Interaction::Hovered => image.texture = textures.hovered_texture.clone(),
|
||||||
|
Interaction::None => image.texture = textures.texture.clone(),
|
||||||
|
Interaction::Pressed => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TODO
|
/// TODO
|
||||||
|
@ -140,27 +151,27 @@ fn default_style() -> Style {
|
||||||
Style {
|
Style {
|
||||||
flex_direction: FlexDirection::Column,
|
flex_direction: FlexDirection::Column,
|
||||||
width: Val::Percent(100.),
|
width: Val::Percent(100.),
|
||||||
height: Val::Percent(45.),
|
height: Val::Percent(55.),
|
||||||
margin: UiRect::all(Val::Auto),
|
margin: UiRect::all(Val::Auto),
|
||||||
..default()
|
..default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TODO
|
/// TODO
|
||||||
fn main_node(main_node: &mut ChildBuilder<'_, '_, '_>) {
|
fn main_node(main_node: &mut ChildBuilder<'_, '_, '_>, asset_server: &Res<AssetServer>) {
|
||||||
main_node.spawn(NodeBundle {
|
main_node.spawn(ImageBundle {
|
||||||
style: Style {
|
style: Style {
|
||||||
|
height: Val::Px(150.),
|
||||||
|
width: Val::Px(613.5),
|
||||||
margin: UiRect {
|
margin: UiRect {
|
||||||
left: (Val::Auto),
|
left: Val::Auto,
|
||||||
right: (Val::Auto),
|
right: Val::Auto,
|
||||||
top: (Val::Px(25.)),
|
top: Val::Px(25.),
|
||||||
bottom: (Val::Px(25.)),
|
bottom: Val::Px(50.),
|
||||||
},
|
},
|
||||||
width: Val::Px(650.),
|
|
||||||
height: Val::Px(300.),
|
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
background_color: BackgroundColor(Color::RED),
|
image: asset_server.load("bw.png").into(),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -174,8 +185,8 @@ fn main_node(main_node: &mut ChildBuilder<'_, '_, '_>) {
|
||||||
top: (Val::Auto),
|
top: (Val::Auto),
|
||||||
bottom: (Val::Px(25.)),
|
bottom: (Val::Px(25.)),
|
||||||
},
|
},
|
||||||
width: Val::Px(552.5),
|
width: Val::Px(500.),
|
||||||
height: Val::Percent(70.),
|
height: Val::Percent(65.),
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
..default()
|
..default()
|
||||||
|
@ -184,7 +195,6 @@ fn main_node(main_node: &mut ChildBuilder<'_, '_, '_>) {
|
||||||
container
|
container
|
||||||
.spawn(NodeBundle {
|
.spawn(NodeBundle {
|
||||||
style: default_style(),
|
style: default_style(),
|
||||||
background_color: Color::YELLOW_GREEN.into(),
|
|
||||||
..default()
|
..default()
|
||||||
})
|
})
|
||||||
.with_children(|host| {
|
.with_children(|host| {
|
||||||
|
@ -193,17 +203,19 @@ fn main_node(main_node: &mut ChildBuilder<'_, '_, '_>) {
|
||||||
background_color: BackgroundColor(Color::YELLOW),
|
background_color: BackgroundColor(Color::YELLOW),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
host.spawn(NodeBundle {
|
create_button(
|
||||||
style: default_style(),
|
CurrentScene::Lobby,
|
||||||
background_color: BackgroundColor(Color::YELLOW),
|
host,
|
||||||
..default()
|
HoveredTexture {
|
||||||
});
|
texture: asset_server.load("host.png"),
|
||||||
|
hovered_texture: asset_server.load("host.png"),
|
||||||
|
},
|
||||||
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
container
|
container
|
||||||
.spawn(NodeBundle {
|
.spawn(NodeBundle {
|
||||||
style: default_style(),
|
style: default_style(),
|
||||||
background_color: Color::YELLOW_GREEN.into(),
|
|
||||||
..default()
|
..default()
|
||||||
})
|
})
|
||||||
.with_children(|join| {
|
.with_children(|join| {
|
||||||
|
@ -212,11 +224,14 @@ fn main_node(main_node: &mut ChildBuilder<'_, '_, '_>) {
|
||||||
background_color: BackgroundColor(Color::YELLOW),
|
background_color: BackgroundColor(Color::YELLOW),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
join.spawn(NodeBundle {
|
create_button(
|
||||||
style: default_style(),
|
CurrentScene::Lobby,
|
||||||
background_color: BackgroundColor(Color::YELLOW),
|
join,
|
||||||
..default()
|
HoveredTexture {
|
||||||
});
|
texture: asset_server.load("join.png"),
|
||||||
|
hovered_texture: asset_server.load("join.png"),
|
||||||
|
},
|
||||||
|
)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue