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:
@@ -20,8 +20,7 @@ fn main() {
|
|||||||
}))
|
}))
|
||||||
.add_plugins(EguiPlugin::default())
|
.add_plugins(EguiPlugin::default())
|
||||||
.add_plugins(WorldInspectorPlugin::new())
|
.add_plugins(WorldInspectorPlugin::new())
|
||||||
.init_resource::<resources::UiTheme>()
|
.add_plugins(widgets::GameUiPlugin)
|
||||||
.register_type::<resources::UiTheme>()
|
|
||||||
.add_systems(
|
.add_systems(
|
||||||
Startup,
|
Startup,
|
||||||
(
|
(
|
||||||
@@ -31,10 +30,6 @@ fn main() {
|
|||||||
CuttingMachine::spawn_ui,
|
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();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,24 @@ use bevy::{color::palettes::css::*, prelude::*, ui::Val::*};
|
|||||||
|
|
||||||
use crate::resources::UiTheme;
|
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.
|
/// 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
|
/// This function is not a valid Bevy System because of how the Commands struct
|
||||||
|
|||||||
Reference in New Issue
Block a user