From b03d0b501fb4c7acaa02f4658c90b39a634d0db9 Mon Sep 17 00:00:00 2001 From: Ben Frankel Date: Tue, 5 Dec 2023 01:01:26 -0800 Subject: [PATCH] Partially implement upgrade panel plugin --- src/state/editor_screen.rs | 6 +++- src/state/editor_screen/outline_panel.rs | 16 +++++----- src/state/editor_screen/upgrade_panel.rs | 38 ++++++++++++++++++++++-- 3 files changed, 47 insertions(+), 13 deletions(-) diff --git a/src/state/editor_screen.rs b/src/state/editor_screen.rs index c31cfe1..50a0234 100644 --- a/src/state/editor_screen.rs +++ b/src/state/editor_screen.rs @@ -27,7 +27,11 @@ impl Plugin for EditorScreenStatePlugin { .init_collection::() .add_systems(OnEnter(EditorScreen), enter_editor_screen) .add_systems(OnExit(EditorScreen), exit_editor_screen) - .add_plugins((info_bar::InfoBarPlugin, outline_panel::OutlinePanelPlugin)); + .add_plugins(( + info_bar::InfoBarPlugin, + outline_panel::OutlinePanelPlugin, + upgrade_panel::UpgradePanelPlugin, + )); } } diff --git a/src/state/editor_screen/outline_panel.rs b/src/state/editor_screen/outline_panel.rs index 5083b5d..6ee5748 100644 --- a/src/state/editor_screen/outline_panel.rs +++ b/src/state/editor_screen/outline_panel.rs @@ -17,13 +17,13 @@ pub struct OutlinePanelPlugin; impl Plugin for OutlinePanelPlugin { fn build(&self, app: &mut App) { - app.register_type::() + app.register_type::() .add_systems(Update, add_upgrades_to_outline); } } #[derive(Component, Reflect)] -struct IsOutlinePanel; +struct IsOutlineContainer; // TODO: Add scrollbar pub fn spawn_outline_panel(commands: &mut Commands, config: &EditorScreenConfig) -> Entity { @@ -41,7 +41,7 @@ pub fn spawn_outline_panel(commands: &mut Commands, config: &EditorScreenConfig) background_color: config.outline_panel_background_color.into(), ..default() }, - IsOutlinePanel, + IsOutlineContainer, )) .id(); @@ -126,17 +126,15 @@ fn add_upgrades_to_outline( mut events: EventReader, config: Res, upgrade_list: Res, - outline_panel_query: Query>, + container_query: Query>, ) { let config = &config.editor_screen; for event in events.read() { - println!("A"); let upgrade = upgrade_list.get(event.0); - for outline_panel in &outline_panel_query { - println!("B"); - let outline_entry = spawn_outline_entry(&mut commands, &config, upgrade); - commands.entity(outline_entry).set_parent(outline_panel); + for container in &container_query { + let outline_entry = spawn_outline_entry(&mut commands, config, upgrade); + commands.entity(outline_entry).set_parent(container); } } } diff --git a/src/state/editor_screen/upgrade_panel.rs b/src/state/editor_screen/upgrade_panel.rs index b2563f2..72443ac 100644 --- a/src/state/editor_screen/upgrade_panel.rs +++ b/src/state/editor_screen/upgrade_panel.rs @@ -2,6 +2,7 @@ use bevy::math::vec2; use bevy::prelude::*; use bevy_mod_picking::prelude::*; +use crate::config::Config; use crate::simulation::Simulation; use crate::state::editor_screen::EditorScreenConfig; use crate::state::AppState; @@ -15,6 +16,22 @@ use crate::upgrade::UpgradeEvent; use crate::upgrade::UpgradeKind; use crate::upgrade::UpgradeList; +pub struct UpgradePanelPlugin; + +impl Plugin for UpgradePanelPlugin { + fn build(&self, app: &mut App) { + app.register_type::().add_systems( + Update, + replace_available_upgrades.run_if(on_event::()), + ); + } +} + +const FIRST_UPGRADE: UpgradeKind = UpgradeKind::TouchOfLife; + +#[derive(Component, Reflect)] +pub struct IsUpgradeContainer; + pub fn spawn_upgrade_panel( commands: &mut Commands, config: &EditorScreenConfig, @@ -69,13 +86,12 @@ pub fn spawn_upgrade_panel( }, ..default() }, + IsUpgradeContainer, )) .set_parent(upgrade_panel) .id(); - // TODO: Replace this dummy upgrade - let upgrade_button = - spawn_upgrade_button(commands, config, upgrade_list, UpgradeKind::TouchOfLife); + let upgrade_button = spawn_upgrade_button(commands, config, upgrade_list, FIRST_UPGRADE); commands .entity(upgrade_button) .set_parent(upgrade_container); @@ -231,3 +247,19 @@ fn spawn_submit_button(commands: &mut Commands, config: &EditorScreenConfig) -> submit_button } + +fn replace_available_upgrades( + mut commands: Commands, + config: Res, + container_query: Query>, +) { + let _config = &config.editor_screen; + for container in &container_query { + commands.entity(container).despawn_descendants(); + + // TODO: Spawn the next set of upgrades + // - # of upgrade slots + // - Initial fixed sequence of upgrades + // - Randomly chosen upgrades (weighted) + } +}