Create a custom plugin to centralize UI setup

The UI elements need some things set up for them to work properly.
Namely, the `UiTheme` resource and the Observers which handle button
presses.
This commit is contained in:
2025-08-26 12:34:35 -05:00
parent fb1b954262
commit da7f9b3152
2 changed files with 19 additions and 6 deletions

View File

@@ -20,8 +20,7 @@ fn main() {
}))
.add_plugins(EguiPlugin::default())
.add_plugins(WorldInspectorPlugin::new())
.init_resource::<resources::UiTheme>()
.register_type::<resources::UiTheme>()
.add_plugins(widgets::GameUiPlugin)
.add_systems(
Startup,
(
@@ -31,10 +30,6 @@ fn main() {
CuttingMachine::spawn_ui,
),
)
.add_observer(widgets::CloseButton::hover_start)
.add_observer(widgets::CloseButton::hover_stop)
.add_observer(widgets::CloseButton::press_start)
.add_observer(widgets::CloseButton::press_stop)
.run();
}

View File

@@ -6,6 +6,24 @@ use bevy::{color::palettes::css::*, prelude::*, ui::Val::*};
use crate::resources::UiTheme;
/// Plugin to set up systems & resources for the custom UI elements
///
/// The UiTheme resource is initialized and the button press Observers
/// are registered here.
pub struct GameUiPlugin;
impl Plugin for GameUiPlugin {
fn build(&self, app: &mut App) {
app
.init_resource::<UiTheme>()
.register_type::<UiTheme>()
.add_observer(CloseButton::hover_start)
.add_observer(CloseButton::hover_stop)
.add_observer(CloseButton::press_start)
.add_observer(CloseButton::press_stop);
}
}
/// The base panel for the machines that manipulate the room cards.
///
/// This function is not a valid Bevy System because of how the Commands struct