select buttons
This commit is contained in:
parent
ec12ed122b
commit
3f5d4cc9aa
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 |
60
src/ui.rs
60
src/ui.rs
@ -3,6 +3,12 @@ use bevy::{asset::embedded_asset, input::mouse::MouseWheel, math::{NormedVectorS
|
|||||||
|
|
||||||
use crate::map::{self, CellKind, MapMarker};
|
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;
|
pub struct Plugin;
|
||||||
impl bevy::prelude::Plugin for Plugin {
|
impl bevy::prelude::Plugin for Plugin {
|
||||||
fn build(&self, app: &mut App) {
|
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 {
|
pub enum CurrentAction {
|
||||||
#[default]
|
#[default]
|
||||||
None,
|
None,
|
||||||
@ -100,40 +106,46 @@ fn setup(
|
|||||||
align_self: AlignSelf::FlexEnd,
|
align_self: AlignSelf::FlexEnd,
|
||||||
!};
|
!};
|
||||||
Button;
|
Button;
|
||||||
BackgroundColor(#77767b);
|
BackgroundColor(TABBAR_COLOR);
|
||||||
[
|
[forest][
|
||||||
ImageNode::new(asset_server.load("embedded://forestiles/../assets/ui/enabled_tree.png"));
|
ImageNode::new(asset_server.load("embedded://forestiles/../assets/ui/enabled_tree.png"));
|
||||||
Node {
|
Node {
|
||||||
height: 80%,
|
// height: 80%,
|
||||||
margin: [>1vh],
|
// 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 {
|
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"));
|
ImageNode::new(asset_server.load("embedded://forestiles/../assets/ui/enabled_grass.png"));
|
||||||
Node {
|
Node {
|
||||||
height: 80%,
|
// height: 80%,
|
||||||
margin: [>1vh],
|
// 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 {
|
if trigger.button == PointerButton::Primary {
|
||||||
*ca = CurrentAction::ChangeCell(CellKind::Grass);
|
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 {
|
||||||
ImageNode::new(asset_server.load("embedded://forestiles/../assets/ui/enabled_cross.png"));
|
*ca = CurrentAction::ChangeCell(CellKind::Grass);
|
||||||
Node {
|
bg.get_mut(forest).unwrap().0 = TABBAR_COLOR;
|
||||||
height: 80%,
|
bg.get_mut(grass).unwrap().0 = ENABLED_BUTTON_COLOR;
|
||||||
margin: [>1vh],
|
}
|
||||||
!};
|
|
||||||
.observe(|trigger: Trigger<Pointer<Click>>, mut ca: ResMut<CurrentAction>| {
|
|
||||||
if trigger.button == PointerButton::Primary {
|
|
||||||
*ca = CurrentAction::None;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user