select buttons

This commit is contained in:
Arkitu 2025-02-28 22:56:30 +01:00
parent ec12ed122b
commit 3f5d4cc9aa
4 changed files with 36 additions and 24 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@ -3,6 +3,12 @@ use bevy::{asset::embedded_asset, input::mouse::MouseWheel, math::{NormedVectorS
use crate::map::{self, CellKind, MapMarker};
// #77767b
const TABBAR_COLOR: Color = Color::srgb(119./255., 118./255., 123./255.);
// #E8E8E8
const ENABLED_BUTTON_COLOR: Color = Color::srgb(232./255., 232./255., 232./255.);
pub struct Plugin;
impl bevy::prelude::Plugin for Plugin {
fn build(&self, app: &mut App) {
@ -18,7 +24,7 @@ impl bevy::prelude::Plugin for Plugin {
}
}
#[derive(Resource, Default)]
#[derive(Resource, Default, PartialEq, Eq)]
pub enum CurrentAction {
#[default]
None,
@ -100,40 +106,46 @@ fn setup(
align_self: AlignSelf::FlexEnd,
!};
Button;
BackgroundColor(#77767b);
[
BackgroundColor(TABBAR_COLOR);
[forest][
ImageNode::new(asset_server.load("embedded://forestiles/../assets/ui/enabled_tree.png"));
Node {
height: 80%,
margin: [>1vh],
// height: 80%,
// margin: [>1vh],
!};
.observe(|trigger: Trigger<Pointer<Click>>, mut ca: ResMut<CurrentAction>| {
BackgroundColor(TABBAR_COLOR);
.observe(move |trigger: Trigger<Pointer<Click>>, mut ca: ResMut<CurrentAction>, mut bg: Query<&mut BackgroundColor>| {
if trigger.button == PointerButton::Primary {
*ca = CurrentAction::ChangeCell(CellKind::Forest);
if *ca == CurrentAction::ChangeCell(CellKind::Forest) {
*ca = CurrentAction::None;
bg.get_mut(forest).unwrap().0 = TABBAR_COLOR;
bg.get_mut(grass).unwrap().0 = TABBAR_COLOR;
} else {
*ca = CurrentAction::ChangeCell(CellKind::Forest);
bg.get_mut(forest).unwrap().0 = ENABLED_BUTTON_COLOR;
bg.get_mut(grass).unwrap().0 = TABBAR_COLOR;
}
}
});
]
[
[grass][
ImageNode::new(asset_server.load("embedded://forestiles/../assets/ui/enabled_grass.png"));
Node {
height: 80%,
margin: [>1vh],
// height: 80%,
// margin: [>1vh],
!};
.observe(|trigger: Trigger<Pointer<Click>>, mut ca: ResMut<CurrentAction>| {
BackgroundColor(TABBAR_COLOR);
.observe(move |trigger: Trigger<Pointer<Click>>, mut ca: ResMut<CurrentAction>, mut bg: Query<&mut BackgroundColor>| {
if trigger.button == PointerButton::Primary {
*ca = CurrentAction::ChangeCell(CellKind::Grass);
}
});
]
[
ImageNode::new(asset_server.load("embedded://forestiles/../assets/ui/enabled_cross.png"));
Node {
height: 80%,
margin: [>1vh],
!};
.observe(|trigger: Trigger<Pointer<Click>>, mut ca: ResMut<CurrentAction>| {
if trigger.button == PointerButton::Primary {
*ca = CurrentAction::None;
if *ca == CurrentAction::ChangeCell(CellKind::Grass) {
*ca = CurrentAction::None;
bg.get_mut(forest).unwrap().0 = TABBAR_COLOR;
bg.get_mut(grass).unwrap().0 = TABBAR_COLOR;
} else {
*ca = CurrentAction::ChangeCell(CellKind::Grass);
bg.get_mut(forest).unwrap().0 = TABBAR_COLOR;
bg.get_mut(grass).unwrap().0 = ENABLED_BUTTON_COLOR;
}
}
});
]