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"
[features]
dev = ["bevy/dynamic_linking", "bevy/file_watcher", "bevy/debug", "bevy/bevy_light", "bevy/free_camera"]
web = []
dev = [
"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.
[profile.dev]

@ -1,13 +1,18 @@
pub use std::time::Duration;
pub use bevy::{
audio::Volume,
asset::{AssetPath, HandleTemplate},
audio::{AudioPlayerTemplate, Volume},
color::palettes::basic::*,
feathers::{FeathersPlugins, controls::*},
input::{
common_conditions::*,
mouse::{AccumulatedMouseMotion, MouseMotion},
},
mesh::Mesh2dTemplate,
picking::hover::Hovered,
platform::collections::{HashMap, HashSet},
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::*;
const TILE: &str = "tileGrey_01.png";
@ -10,6 +15,7 @@ fn main() {
file_path: "assets".into(),
..default()
}))
.add_plugins(FeathersPlugins)
.init_resource::<NextCoordinates>()
.init_resource::<CellAssets>()
.init_resource::<Panning>()
@ -96,6 +102,10 @@ enum UiButton {
ZoomIn,
PlayAudio,
MuteAudio,
AddHighOctave,
SubHighOctave,
AddLowOctave,
SubLowOctave,
#[default]
None,
}
@ -111,30 +121,24 @@ impl UiButton {
Self::ZoomIn => "zoomIn.png",
Self::PlayAudio => "audioOn.png",
Self::MuteAudio => "audioOff.png",
Self::AddHighOctave => "todo.png",
Self::SubHighOctave => "todo.png",
Self::AddLowOctave => "todo.png",
Self::SubLowOctave => "todo.png",
Self::None => todo!(),
}
}
}
fn ui_button(button: UiButton) -> impl Scene {
let color: Color = WHITE.with_alpha(0.5).into();
bsn! {
Button
@FeathersButton
Hovered
Outline {
width: Val::Px(5.0),
color: Color::NONE,
}
Node {
top: Val::Px(2.5),
left: Val::Px(2.5),
margin: UiRect::all(Val::Px(2.5)),
}
BackgroundColor(GRAY)
ImageNode {
image: HandleTemplate::Path(TILE),
color,
}
Children [
Node {
align_self: AlignSelf::Center,
@ -168,27 +172,27 @@ fn the_ui() -> impl Scene {
Transform
Children [
ui_button(UiButton::Power)
on(|_: On<Pointer<Press>>, mut writer: MessageWriter<AppExit>| {
on(|_: On<Activate>, mut writer: MessageWriter<AppExit>| {
writer.write(AppExit::Success);
}),
ui_button(UiButton::Pause)
SimulationPlayback::Run
on(|_: On<Pointer<Press>>, mut next: ResMut<NextState<SimulationPlayback>>| {
on(|_: On<Activate>, mut next: ResMut<NextState<SimulationPlayback>>| {
// Set simulation state
next.set(SimulationPlayback::Pause);
}),
ui_button(UiButton::Play)
SimulationPlayback::Pause
on(|_: On<Pointer<Press>>, mut next: ResMut<NextState<SimulationPlayback>>| {
on(|_: On<Activate>, mut next: ResMut<NextState<SimulationPlayback>>| {
// Set simulation state
next.set(SimulationPlayback::Run);
}),
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);
}),
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::Orthographic(ref mut o) => {
o.scale /= 0.5;
@ -197,7 +201,7 @@ fn the_ui() -> impl Scene {
});
}),
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::Orthographic(ref mut o) => {
o.scale *= 0.5;
@ -207,14 +211,30 @@ fn the_ui() -> impl Scene {
}),
ui_button(UiButton::MuteAudio)
AudioPlayback::Play
on(|_: On<Pointer<Press>>, mut next: ResMut<NextState<AudioPlayback>>| {
on(|_: On<Activate>, mut next: ResMut<NextState<AudioPlayback>>| {
next.set(AudioPlayback::Mute);
}),
ui_button(UiButton::PlayAudio)
AudioPlayback::Mute
on(|_: On<Pointer<Press>>, mut next: ResMut<NextState<AudioPlayback>>| {
on(|_: On<Activate>, mut next: ResMut<NextState<AudioPlayback>>| {
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 {
Lifecycle::Alive(c) => {
debug!("creating {:?}", c);

Loading…
Cancel
Save