add goat button
This commit is contained in:
parent
24436a0bf4
commit
74708f8b7b
BIN
assets/ui/disabled_goat.png
Normal file
BIN
assets/ui/disabled_goat.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
BIN
assets/ui/enabled_goat.png
Normal file
BIN
assets/ui/enabled_goat.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
19
src/animals.rs
Normal file
19
src/animals.rs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
use bevy::prelude::*;
|
||||||
|
|
||||||
|
pub struct Plugin;
|
||||||
|
impl bevy::prelude::Plugin for Plugin {
|
||||||
|
fn build(&self, app: &mut App) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(PartialEq, Eq)]
|
||||||
|
|
||||||
|
pub enum AnimalKind {
|
||||||
|
Goat
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
pub struct Animal {
|
||||||
|
|
||||||
|
}
|
@ -6,6 +6,7 @@ pub mod map;
|
|||||||
pub mod camera;
|
pub mod camera;
|
||||||
pub mod ui;
|
pub mod ui;
|
||||||
pub mod time;
|
pub mod time;
|
||||||
|
pub mod animals;
|
||||||
|
|
||||||
#[bevy_main]
|
#[bevy_main]
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
@ -17,6 +18,7 @@ pub fn main() {
|
|||||||
map::Plugin,
|
map::Plugin,
|
||||||
ui::Plugin,
|
ui::Plugin,
|
||||||
time::Plugin,
|
time::Plugin,
|
||||||
|
animals::Plugin,
|
||||||
FrameTimeDiagnosticsPlugin,
|
FrameTimeDiagnosticsPlugin,
|
||||||
LogDiagnosticsPlugin {
|
LogDiagnosticsPlugin {
|
||||||
filter: Some(vec![FrameTimeDiagnosticsPlugin::FPS]),
|
filter: Some(vec![FrameTimeDiagnosticsPlugin::FPS]),
|
||||||
|
36
src/ui.rs
36
src/ui.rs
@ -1,7 +1,7 @@
|
|||||||
use mevy::*;
|
use mevy::*;
|
||||||
use bevy::{asset::embedded_asset, input::mouse::MouseWheel, math::{NormedVectorSpace, VectorSpace}, picking::{focus::HoverMap, pointer::PointerId}, prelude::*, utils::{dbg, HashMap}, window::PrimaryWindow};
|
use bevy::{asset::embedded_asset, input::mouse::MouseWheel, math::{NormedVectorSpace, VectorSpace}, picking::{focus::HoverMap, pointer::PointerId}, prelude::*, utils::{dbg, HashMap}, window::PrimaryWindow};
|
||||||
|
|
||||||
use crate::map::{self, CellKind, MapMarker};
|
use crate::{animals::AnimalKind, map::{self, CellKind, MapMarker}};
|
||||||
|
|
||||||
// #77767b
|
// #77767b
|
||||||
const TABBAR_COLOR: Color = Color::srgb(119./255., 118./255., 123./255.);
|
const TABBAR_COLOR: Color = Color::srgb(119./255., 118./255., 123./255.);
|
||||||
@ -21,6 +21,8 @@ impl bevy::prelude::Plugin for Plugin {
|
|||||||
embedded_asset!(app, "../assets/ui/disabled_grass.png");
|
embedded_asset!(app, "../assets/ui/disabled_grass.png");
|
||||||
embedded_asset!(app, "../assets/ui/enabled_cross.png");
|
embedded_asset!(app, "../assets/ui/enabled_cross.png");
|
||||||
embedded_asset!(app, "../assets/ui/disabled_cross.png");
|
embedded_asset!(app, "../assets/ui/disabled_cross.png");
|
||||||
|
embedded_asset!(app, "../assets/ui/enabled_goat.png");
|
||||||
|
embedded_asset!(app, "../assets/ui/disabled_goat.png");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,7 +30,8 @@ impl bevy::prelude::Plugin for Plugin {
|
|||||||
pub enum CurrentAction {
|
pub enum CurrentAction {
|
||||||
#[default]
|
#[default]
|
||||||
None,
|
None,
|
||||||
ChangeCell(CellKind)
|
ChangeCell(CellKind),
|
||||||
|
AddAnimal(AnimalKind)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Component, Debug)]
|
#[derive(Component, Debug)]
|
||||||
@ -119,12 +122,12 @@ fn setup(
|
|||||||
if *ca == CurrentAction::ChangeCell(CellKind::Forest) {
|
if *ca == CurrentAction::ChangeCell(CellKind::Forest) {
|
||||||
*ca = CurrentAction::None;
|
*ca = CurrentAction::None;
|
||||||
bg.get_mut(forest).unwrap().0 = TABBAR_COLOR;
|
bg.get_mut(forest).unwrap().0 = TABBAR_COLOR;
|
||||||
bg.get_mut(grass).unwrap().0 = TABBAR_COLOR;
|
|
||||||
} else {
|
} else {
|
||||||
*ca = CurrentAction::ChangeCell(CellKind::Forest);
|
*ca = CurrentAction::ChangeCell(CellKind::Forest);
|
||||||
bg.get_mut(forest).unwrap().0 = ENABLED_BUTTON_COLOR;
|
bg.get_mut(forest).unwrap().0 = ENABLED_BUTTON_COLOR;
|
||||||
bg.get_mut(grass).unwrap().0 = TABBAR_COLOR;
|
|
||||||
}
|
}
|
||||||
|
bg.get_mut(grass).unwrap().0 = TABBAR_COLOR;
|
||||||
|
bg.get_mut(goat).unwrap().0 = TABBAR_COLOR;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
]
|
]
|
||||||
@ -139,13 +142,34 @@ fn setup(
|
|||||||
if trigger.button == PointerButton::Primary {
|
if trigger.button == PointerButton::Primary {
|
||||||
if *ca == CurrentAction::ChangeCell(CellKind::Grass) {
|
if *ca == CurrentAction::ChangeCell(CellKind::Grass) {
|
||||||
*ca = CurrentAction::None;
|
*ca = CurrentAction::None;
|
||||||
bg.get_mut(forest).unwrap().0 = TABBAR_COLOR;
|
|
||||||
bg.get_mut(grass).unwrap().0 = TABBAR_COLOR;
|
bg.get_mut(grass).unwrap().0 = TABBAR_COLOR;
|
||||||
} else {
|
} else {
|
||||||
*ca = CurrentAction::ChangeCell(CellKind::Grass);
|
*ca = CurrentAction::ChangeCell(CellKind::Grass);
|
||||||
bg.get_mut(forest).unwrap().0 = TABBAR_COLOR;
|
|
||||||
bg.get_mut(grass).unwrap().0 = ENABLED_BUTTON_COLOR;
|
bg.get_mut(grass).unwrap().0 = ENABLED_BUTTON_COLOR;
|
||||||
}
|
}
|
||||||
|
bg.get_mut(forest).unwrap().0 = TABBAR_COLOR;
|
||||||
|
bg.get_mut(goat).unwrap().0 = TABBAR_COLOR;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
]
|
||||||
|
[goat][
|
||||||
|
ImageNode::new(asset_server.load("embedded://forestiles/../assets/ui/enabled_goat.png"));
|
||||||
|
Node {
|
||||||
|
// height: 80%,
|
||||||
|
// margin: [>1vh],
|
||||||
|
!};
|
||||||
|
BackgroundColor(TABBAR_COLOR);
|
||||||
|
.observe(move |trigger: Trigger<Pointer<Click>>, mut ca: ResMut<CurrentAction>, mut bg: Query<&mut BackgroundColor>| {
|
||||||
|
if trigger.button == PointerButton::Primary {
|
||||||
|
if *ca == CurrentAction::AddAnimal(AnimalKind::Goat) {
|
||||||
|
*ca = CurrentAction::None;
|
||||||
|
bg.get_mut(goat).unwrap().0 = TABBAR_COLOR;
|
||||||
|
} else {
|
||||||
|
*ca = CurrentAction::AddAnimal(AnimalKind::Goat);
|
||||||
|
bg.get_mut(goat).unwrap().0 = ENABLED_BUTTON_COLOR;
|
||||||
|
}
|
||||||
|
bg.get_mut(forest).unwrap().0 = TABBAR_COLOR;
|
||||||
|
bg.get_mut(grass).unwrap().0 = TABBAR_COLOR;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user