Proof-of-concept for fuel change event handling
Added a `FuelChanged` event which is to be used to trigger Observers watching for a machine's fuel level change. I've written a slapdash observer to emit these events when the cutting machine's big red button is pressed. That observer *must* be replaced because of how it feeds the machine ID into the UI (it only works when there is exactly 1 CuttingMachine, which won't be the case). The dummy machines are missing their machine components. I've added the `CuttingMachine` component to the cutting machine just to test the event passing.
This commit is contained in:
32
src/widgets/fuel_gauge.rs
Normal file
32
src/widgets/fuel_gauge.rs
Normal file
@@ -0,0 +1,32 @@
|
||||
use bevy::{color::palettes::css::*, prelude::*, ui::Val::*};
|
||||
|
||||
use crate::game::consumables::{Fuel, FuelChanged};
|
||||
|
||||
#[derive(Component)]
|
||||
#[require(Label)]
|
||||
pub struct FuelGauge(Entity);
|
||||
|
||||
impl FuelGauge {
|
||||
/// Default bundle for a machine's fuel gauge widget. Give it the ID of the
|
||||
/// machine whose info it is displaying.
|
||||
pub fn bundle(target: Entity) -> impl Bundle {
|
||||
(
|
||||
FuelGauge(target),
|
||||
Node {
|
||||
min_width: Px(20.0),
|
||||
min_height: Px(10.0),
|
||||
..default()
|
||||
},
|
||||
BackgroundColor(GREEN.into()),
|
||||
Text::new("Fuel: "),
|
||||
children![TextSpan::new("<n>"),],
|
||||
)
|
||||
}
|
||||
|
||||
pub fn detect_fuel_change(event: Trigger<FuelChanged>) {
|
||||
dbg!(format!(
|
||||
"Detected fuel change on entity ID: {}",
|
||||
event.target()
|
||||
));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user