diff --git a/assets/ui/disabled_goat.png b/assets/ui/disabled_goat.png new file mode 100644 index 0000000..1e08deb Binary files /dev/null and b/assets/ui/disabled_goat.png differ diff --git a/assets/ui/enabled_goat.png b/assets/ui/enabled_goat.png new file mode 100644 index 0000000..9941dc0 Binary files /dev/null and b/assets/ui/enabled_goat.png differ diff --git a/src/animals.rs b/src/animals.rs new file mode 100644 index 0000000..2cc34ca --- /dev/null +++ b/src/animals.rs @@ -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 { + +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 4e06803..5aead39 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,6 +6,7 @@ pub mod map; pub mod camera; pub mod ui; pub mod time; +pub mod animals; #[bevy_main] pub fn main() { @@ -17,6 +18,7 @@ pub fn main() { map::Plugin, ui::Plugin, time::Plugin, + animals::Plugin, FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin { filter: Some(vec![FrameTimeDiagnosticsPlugin::FPS]), diff --git a/src/ui.rs b/src/ui.rs index ba017e8..d839bad 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -1,7 +1,7 @@ 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 crate::map::{self, CellKind, MapMarker}; +use crate::{animals::AnimalKind, map::{self, CellKind, MapMarker}}; // #77767b 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/enabled_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 { #[default] None, - ChangeCell(CellKind) + ChangeCell(CellKind), + AddAnimal(AnimalKind) } #[derive(Component, Debug)] @@ -119,12 +122,12 @@ fn setup( 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; } + 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 *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; } + 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>, mut ca: ResMut, 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; } }); ]