Refactor instrument cluster components into individual modules for improved maintainability and reusability.

This commit is contained in:
geoffsee
2025-07-02 09:41:28 -04:00
parent 2357112ee0
commit f5de8e943b
13 changed files with 112 additions and 62 deletions

View File

@@ -0,0 +1,5 @@
use bevy::prelude::*;
/// AIS indicator component for displaying AIS system status
#[derive(Component)]
pub struct AisIndicator;

View File

@@ -0,0 +1,5 @@
use bevy::prelude::*;
/// Compass gauge component for displaying vessel heading
#[derive(Component)]
pub struct CompassGauge;

View File

@@ -0,0 +1,5 @@
use bevy::prelude::*;
/// Depth gauge component for displaying water depth
#[derive(Component)]
pub struct DepthGauge;

View File

@@ -0,0 +1,5 @@
use bevy::prelude::*;
/// Engine status component for displaying engine information
#[derive(Component)]
pub struct EngineStatus;

View File

@@ -0,0 +1,5 @@
use bevy::prelude::*;
/// GPS indicator component for displaying GPS system status
#[derive(Component)]
pub struct GpsIndicator;

View File

@@ -1,26 +1,21 @@
use bevy::prelude::*;
use super::instruments::*;
use super::theme::*;
use super::composition::*;
use super::speed_gauge::SpeedGauge;
use super::depth_gauge::DepthGauge;
use super::compass_gauge::CompassGauge;
use super::engine_status::EngineStatus;
use super::navigation_display::NavigationDisplay;
use super::gps_indicator::GpsIndicator;
use super::radar_indicator::RadarIndicator;
use super::ais_indicator::AisIndicator;
use super::system_display::SystemDisplay;
use super::wind_display::WindDisplay;
/// Main instrument cluster component
#[derive(Component)]
pub struct InstrumentCluster;
#[derive(Component)]
pub struct GpsIndicator;
#[derive(Component)]
pub struct RadarIndicator;
#[derive(Component)]
pub struct AisIndicator;
#[derive(Component)]
pub struct SystemDisplay;
#[derive(Component)]
pub struct WindDisplay;
/// Sets up the main instrument cluster UI using composable components
pub fn setup_instrument_cluster(mut commands: Commands) {
// Spawn camera since we're bypassing the menu system
@@ -110,45 +105,39 @@ pub fn setup_instrument_cluster(mut commands: Commands) {
grid.spawn(progress_bar_node())
.with_children(|bar| {
bar.spawn(create_text("FUEL", FONT_SIZE_SMALL, TEXT_COLOR_PRIMARY));
bar.spawn((
progress_bar_background_node(),
BackgroundColor(BACKGROUND_COLOR_PRIMARY),
BorderColor(TEXT_COLOR_PRIMARY),
))
.with_children(|bar_bg| {
bar_bg.spawn((
bar.spawn(progress_bar_background_node())
.with_children(|bg| {
bg.spawn((
progress_bar_fill_node(75.0),
BackgroundColor(TEXT_COLOR_SUCCESS),
));
});
bar.spawn(create_text("75%", FONT_SIZE_SMALL, TEXT_COLOR_PRIMARY));
bar.spawn(create_text("75%", FONT_SIZE_SMALL, TEXT_COLOR_SUCCESS));
});
// Battery Level Bar
grid.spawn(progress_bar_node())
.with_children(|bar| {
bar.spawn(create_text("BATTERY", FONT_SIZE_SMALL, TEXT_COLOR_PRIMARY));
bar.spawn((
progress_bar_background_node(),
BackgroundColor(BACKGROUND_COLOR_SECONDARY),
BorderColor(BORDER_COLOR_SECONDARY),
))
.with_children(|bar_bg| {
bar_bg.spawn((
bar.spawn(create_text("BATT", FONT_SIZE_SMALL, TEXT_COLOR_PRIMARY));
bar.spawn(progress_bar_background_node())
.with_children(|bg| {
bg.spawn((
progress_bar_fill_node(88.0),
BackgroundColor(BACKGROUND_COLOR_SECONDARY),
BackgroundColor(TEXT_COLOR_SUCCESS),
));
});
bar.spawn(create_text("88%", FONT_SIZE_SMALL, TEXT_COLOR_PRIMARY));
bar.spawn(create_text("88%", FONT_SIZE_SMALL, TEXT_COLOR_SUCCESS));
});
// System Status Indicators
grid.spawn(Node {
flex_direction: FlexDirection::Row,
justify_content: JustifyContent::SpaceBetween,
width: Val::Percent(100.0),
..default()
})
// System Indicators Row
grid.spawn((
Node {
flex_direction: FlexDirection::Row,
justify_content: JustifyContent::SpaceEvenly,
width: Val::Percent(100.0),
..default()
},
))
.with_children(|indicators| {
// GPS Indicator
indicators.spawn((
@@ -225,4 +214,4 @@ pub fn setup_instrument_cluster(mut commands: Commands) {
display.spawn(create_text("Select a system above to view details", FONT_SIZE_SMALL, TEXT_COLOR_SECONDARY));
});
});
}
}

View File

@@ -3,14 +3,38 @@
// Components crate for yacht pit application
// This crate contains reusable UI and game components
// Shared modules
pub mod ui;
pub mod instruments;
pub mod theme;
pub mod cluster;
pub mod composition;
// Individual component modules
pub mod speed_gauge;
pub mod depth_gauge;
pub mod compass_gauge;
pub mod engine_status;
pub mod navigation_display;
pub mod yacht_data;
pub mod instrument_cluster;
pub mod gps_indicator;
pub mod radar_indicator;
pub mod ais_indicator;
pub mod system_display;
pub mod wind_display;
// Re-export everything
pub use ui::*;
pub use instruments::*;
pub use theme::*;
pub use cluster::*;
pub use composition::*;
pub use speed_gauge::*;
pub use depth_gauge::*;
pub use compass_gauge::*;
pub use engine_status::*;
pub use navigation_display::*;
pub use yacht_data::*;
pub use instrument_cluster::*;
pub use gps_indicator::*;
pub use radar_indicator::*;
pub use ais_indicator::*;
pub use system_display::*;
pub use wind_display::*;

View File

@@ -0,0 +1,5 @@
use bevy::prelude::*;
/// Navigation display component for showing navigation information
#[derive(Component)]
pub struct NavigationDisplay;

View File

@@ -0,0 +1,5 @@
use bevy::prelude::*;
/// Radar indicator component for displaying radar system status
#[derive(Component)]
pub struct RadarIndicator;

View File

@@ -0,0 +1,5 @@
use bevy::prelude::*;
/// Speed gauge component for displaying vessel speed
#[derive(Component)]
pub struct SpeedGauge;

View File

@@ -0,0 +1,5 @@
use bevy::prelude::*;
/// System display component for showing detailed system information
#[derive(Component)]
pub struct SystemDisplay;

View File

@@ -0,0 +1,5 @@
use bevy::prelude::*;
/// Wind display component for showing wind information
#[derive(Component)]
pub struct WindDisplay;

View File

@@ -1,20 +1,7 @@
use bevy::prelude::*;
/// Individual instrument components
#[derive(Component)]
pub struct SpeedGauge;
#[derive(Component)]
pub struct DepthGauge;
#[derive(Component)]
pub struct CompassGauge;
#[derive(Component)]
pub struct EngineStatus;
#[derive(Component)]
pub struct NavigationDisplay;
use super::speed_gauge::SpeedGauge;
use super::depth_gauge::DepthGauge;
use super::compass_gauge::CompassGauge;
/// Yacht data resource containing all sensor readings
#[derive(Resource)]