Demo the UI with a dummy machine

This finally shows the basic operating principle of the machine UIs.
There will be some object out in the world that, when clicked, will open
a new UI screen to operate the machine.

Next up is to attach various bits of info, like a `Fuel` component on
the machine which the UI widget locates and displays as text. This gives
me the infrastructure necessary to begin that work.
This commit is contained in:
2025-08-26 16:34:18 -05:00
parent 112b22875a
commit 4d8c8b5302

View File

@@ -1,7 +1,10 @@
use bevy::{prelude::*, window::WindowResolution}; use bevy::{color::palettes::css::GREEN, prelude::*, window::WindowResolution};
use bevy_inspector_egui::{bevy_egui::EguiPlugin, quick::WorldInspectorPlugin}; use bevy_inspector_egui::{bevy_egui::EguiPlugin, quick::WorldInspectorPlugin};
use crate::game::machines::{CuttingMachine, RotatingMachine}; use crate::{
game::machines::{CuttingMachine, RotatingMachine},
resources::UiTheme,
};
mod assets; mod assets;
mod card; mod card;
@@ -21,15 +24,7 @@ fn main() {
.add_plugins(EguiPlugin::default()) .add_plugins(EguiPlugin::default())
.add_plugins(WorldInspectorPlugin::new()) .add_plugins(WorldInspectorPlugin::new())
.add_plugins(widgets::GameUiPlugin) .add_plugins(widgets::GameUiPlugin)
.add_systems( .add_systems(Startup, (setup, assets::load_assets, dummy_machine))
Startup,
(
setup,
assets::load_assets,
RotatingMachine::spawn_ui,
CuttingMachine::spawn_ui,
),
)
.run(); .run();
} }
@@ -43,3 +38,27 @@ fn despawn<T: Component>(mut commands: Commands, to_despawn: Query<Entity, With<
commands.entity(entity).despawn(); commands.entity(entity).despawn();
} }
} }
fn dummy_machine(
mut commands: Commands,
// mut meshes: ResMut<Assets<Mesh>>,
// mut materials: ResMut<Assets<ColorMaterial>>,
) {
commands
.spawn((
Sprite::from_color(GREEN, Vec2::splat(40.0)),
// WARN: Mesh picking is not part of the `DefaultPlugins` plugin collection!
// (but sprite picking is!)
// Mesh2d(meshes.add(Rectangle::new(25., 25.))),
// MeshMaterial2d(materials.add(ColorMaterial::from_color(GREEN))),
Transform::default(),
Pickable::default(),
))
.observe(
|event: Trigger<Pointer<Click>>, commands: Commands, theme: Res<UiTheme>| {
let entity = event.target;
CuttingMachine::spawn_ui(commands, theme);
},
);
}