From 4d8c8b5302a204c430611d442ead15a5da8d0098 Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Tue, 26 Aug 2025 16:34:18 -0500 Subject: [PATCH] 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. --- src/main.rs | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0396710..ebf503f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 crate::game::machines::{CuttingMachine, RotatingMachine}; +use crate::{ + game::machines::{CuttingMachine, RotatingMachine}, + resources::UiTheme, +}; mod assets; mod card; @@ -21,15 +24,7 @@ fn main() { .add_plugins(EguiPlugin::default()) .add_plugins(WorldInspectorPlugin::new()) .add_plugins(widgets::GameUiPlugin) - .add_systems( - Startup, - ( - setup, - assets::load_assets, - RotatingMachine::spawn_ui, - CuttingMachine::spawn_ui, - ), - ) + .add_systems(Startup, (setup, assets::load_assets, dummy_machine)) .run(); } @@ -43,3 +38,27 @@ fn despawn(mut commands: Commands, to_despawn: Query>, + // mut materials: ResMut>, +) { + 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>, commands: Commands, theme: Res| { + let entity = event.target; + CuttingMachine::spawn_ui(commands, theme); + }, + ); +}