Adopt feathers for ui buttons; rough first draft

main
Elijah Voigt 1 month ago
parent f53de2307c
commit da9550d74c

1859
engine/Cargo.lock generated

File diff suppressed because it is too large Load Diff

@ -7,8 +7,18 @@ edition = "2024"
bevy = "0.19.0" bevy = "0.19.0"
[features] [features]
dev = ["bevy/dynamic_linking", "bevy/file_watcher", "bevy/debug", "bevy/bevy_light", "bevy/free_camera"] dev = [
web = [] "bevy/dynamic_linking",
"bevy/file_watcher",
"bevy/debug",
"bevy/bevy_light",
"bevy/free_camera",
"bevy/bevy_feathers"
]
web = [
"bevy/bevy_feathers"
]
default = ["bevy/bevy_feathers"]
# Enable a small amount of optimization in the dev profile. # Enable a small amount of optimization in the dev profile.
[profile.dev] [profile.dev]

@ -1,13 +1,18 @@
pub use std::time::Duration; pub use std::time::Duration;
pub use bevy::{ pub use bevy::{
audio::Volume, asset::{AssetPath, HandleTemplate},
audio::{AudioPlayerTemplate, Volume},
color::palettes::basic::*, color::palettes::basic::*,
feathers::{FeathersPlugins, controls::*},
input::{ input::{
common_conditions::*, common_conditions::*,
mouse::{AccumulatedMouseMotion, MouseMotion}, mouse::{AccumulatedMouseMotion, MouseMotion},
}, },
mesh::Mesh2dTemplate,
picking::hover::Hovered, picking::hover::Hovered,
platform::collections::{HashMap, HashSet}, platform::collections::{HashMap, HashSet},
prelude::*, prelude::*,
sprite_render::MeshMaterial2dTemplate,
ui_widgets::Activate,
}; };

@ -1,4 +1,9 @@
use bevy::{asset::{AssetPath, HandleTemplate}, audio::AudioPlayerTemplate, mesh::Mesh2dTemplate, sprite_render::MeshMaterial2dTemplate}; use bevy::{
asset::{AssetPath, HandleTemplate},
audio::AudioPlayerTemplate,
mesh::Mesh2dTemplate,
sprite_render::MeshMaterial2dTemplate,
};
use engine::*; use engine::*;
const TILE: &str = "tileGrey_01.png"; const TILE: &str = "tileGrey_01.png";
@ -10,6 +15,7 @@ fn main() {
file_path: "assets".into(), file_path: "assets".into(),
..default() ..default()
})) }))
.add_plugins(FeathersPlugins)
.init_resource::<NextCoordinates>() .init_resource::<NextCoordinates>()
.init_resource::<CellAssets>() .init_resource::<CellAssets>()
.init_resource::<Panning>() .init_resource::<Panning>()
@ -96,6 +102,10 @@ enum UiButton {
ZoomIn, ZoomIn,
PlayAudio, PlayAudio,
MuteAudio, MuteAudio,
AddHighOctave,
SubHighOctave,
AddLowOctave,
SubLowOctave,
#[default] #[default]
None, None,
} }
@ -111,30 +121,24 @@ impl UiButton {
Self::ZoomIn => "zoomIn.png", Self::ZoomIn => "zoomIn.png",
Self::PlayAudio => "audioOn.png", Self::PlayAudio => "audioOn.png",
Self::MuteAudio => "audioOff.png", Self::MuteAudio => "audioOff.png",
Self::AddHighOctave => "todo.png",
Self::SubHighOctave => "todo.png",
Self::AddLowOctave => "todo.png",
Self::SubLowOctave => "todo.png",
Self::None => todo!(), Self::None => todo!(),
} }
} }
} }
fn ui_button(button: UiButton) -> impl Scene { fn ui_button(button: UiButton) -> impl Scene {
let color: Color = WHITE.with_alpha(0.5).into();
bsn! { bsn! {
Button @FeathersButton
Hovered Hovered
Outline {
width: Val::Px(5.0),
color: Color::NONE,
}
Node { Node {
top: Val::Px(2.5), top: Val::Px(2.5),
left: Val::Px(2.5), left: Val::Px(2.5),
margin: UiRect::all(Val::Px(2.5)), margin: UiRect::all(Val::Px(2.5)),
} }
BackgroundColor(GRAY)
ImageNode {
image: HandleTemplate::Path(TILE),
color,
}
Children [ Children [
Node { Node {
align_self: AlignSelf::Center, align_self: AlignSelf::Center,
@ -168,27 +172,27 @@ fn the_ui() -> impl Scene {
Transform Transform
Children [ Children [
ui_button(UiButton::Power) ui_button(UiButton::Power)
on(|_: On<Pointer<Press>>, mut writer: MessageWriter<AppExit>| { on(|_: On<Activate>, mut writer: MessageWriter<AppExit>| {
writer.write(AppExit::Success); writer.write(AppExit::Success);
}), }),
ui_button(UiButton::Pause) ui_button(UiButton::Pause)
SimulationPlayback::Run SimulationPlayback::Run
on(|_: On<Pointer<Press>>, mut next: ResMut<NextState<SimulationPlayback>>| { on(|_: On<Activate>, mut next: ResMut<NextState<SimulationPlayback>>| {
// Set simulation state // Set simulation state
next.set(SimulationPlayback::Pause); next.set(SimulationPlayback::Pause);
}), }),
ui_button(UiButton::Play) ui_button(UiButton::Play)
SimulationPlayback::Pause SimulationPlayback::Pause
on(|_: On<Pointer<Press>>, mut next: ResMut<NextState<SimulationPlayback>>| { on(|_: On<Activate>, mut next: ResMut<NextState<SimulationPlayback>>| {
// Set simulation state // Set simulation state
next.set(SimulationPlayback::Run); next.set(SimulationPlayback::Run);
}), }),
ui_button(UiButton::Step) ui_button(UiButton::Step)
on(|_: On<Pointer<Press>>, mut next: ResMut<NextState<SimulationPlayback>>| { on(|_: On<Activate>, mut next: ResMut<NextState<SimulationPlayback>>| {
next.set(SimulationPlayback::Step); next.set(SimulationPlayback::Step);
}), }),
ui_button(UiButton::ZoomOut) ui_button(UiButton::ZoomOut)
on(|_: On<Pointer<Press>>, mut projection: Query<&mut Projection>| { on(|_: On<Activate>, mut projection: Query<&mut Projection>| {
projection.iter_mut().for_each(|mut p| match *p { projection.iter_mut().for_each(|mut p| match *p {
Projection::Orthographic(ref mut o) => { Projection::Orthographic(ref mut o) => {
o.scale /= 0.5; o.scale /= 0.5;
@ -197,7 +201,7 @@ fn the_ui() -> impl Scene {
}); });
}), }),
ui_button(UiButton::ZoomIn) ui_button(UiButton::ZoomIn)
on(|_: On<Pointer<Press>>, mut projection: Query<&mut Projection>| { on(|_: On<Activate>, mut projection: Query<&mut Projection>| {
projection.iter_mut().for_each(|mut p| match *p { projection.iter_mut().for_each(|mut p| match *p {
Projection::Orthographic(ref mut o) => { Projection::Orthographic(ref mut o) => {
o.scale *= 0.5; o.scale *= 0.5;
@ -207,14 +211,30 @@ fn the_ui() -> impl Scene {
}), }),
ui_button(UiButton::MuteAudio) ui_button(UiButton::MuteAudio)
AudioPlayback::Play AudioPlayback::Play
on(|_: On<Pointer<Press>>, mut next: ResMut<NextState<AudioPlayback>>| { on(|_: On<Activate>, mut next: ResMut<NextState<AudioPlayback>>| {
next.set(AudioPlayback::Mute); next.set(AudioPlayback::Mute);
}), }),
ui_button(UiButton::PlayAudio) ui_button(UiButton::PlayAudio)
AudioPlayback::Mute AudioPlayback::Mute
on(|_: On<Pointer<Press>>, mut next: ResMut<NextState<AudioPlayback>>| { on(|_: On<Activate>, mut next: ResMut<NextState<AudioPlayback>>| {
next.set(AudioPlayback::Play); next.set(AudioPlayback::Play);
}), }),
ui_button(UiButton::AddLowOctave)
on(|_: On<Activate>| {
warn!("TODO")
}),
ui_button(UiButton::SubLowOctave)
on(|_: On<Activate>| {
warn!("TODO")
}),
ui_button(UiButton::AddHighOctave)
on(|_: On<Activate>| {
warn!("TODO")
}),
ui_button(UiButton::SubHighOctave)
on(|_: On<Activate>| {
warn!("TODO")
}),
] ]
} }
} }
@ -490,7 +510,11 @@ fn new_cell(Coordinates { x, y }: Coordinates, cell_assets: &Res<CellAssets>) ->
} }
} }
fn cell_lifecycle(mut reader: MessageReader<Lifecycle>, mut commands: Commands, cell_assets: Res<CellAssets>) { fn cell_lifecycle(
mut reader: MessageReader<Lifecycle>,
mut commands: Commands,
cell_assets: Res<CellAssets>,
) {
reader.read().for_each(|msg| match msg { reader.read().for_each(|msg| match msg {
Lifecycle::Alive(c) => { Lifecycle::Alive(c) => {
debug!("creating {:?}", c); debug!("creating {:?}", c);

Loading…
Cancel
Save