Skip to content

Commit

Permalink
Partially implement upgrade panel plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
benfrankel committed Dec 5, 2023
1 parent 5ce26b6 commit b03d0b5
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 13 deletions.
6 changes: 5 additions & 1 deletion src/state/editor_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ impl Plugin for EditorScreenStatePlugin {
.init_collection::<EditorScreenAssets>()
.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,
));
}
}

Expand Down
16 changes: 7 additions & 9 deletions src/state/editor_screen/outline_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ pub struct OutlinePanelPlugin;

impl Plugin for OutlinePanelPlugin {
fn build(&self, app: &mut App) {
app.register_type::<IsOutlinePanel>()
app.register_type::<IsOutlineContainer>()
.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 {
Expand All @@ -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();

Expand Down Expand Up @@ -126,17 +126,15 @@ fn add_upgrades_to_outline(
mut events: EventReader<UpgradeEvent>,
config: Res<Config>,
upgrade_list: Res<UpgradeList>,
outline_panel_query: Query<Entity, With<IsOutlinePanel>>,
container_query: Query<Entity, With<IsOutlineContainer>>,
) {
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);
}
}
}
38 changes: 35 additions & 3 deletions src/state/editor_screen/upgrade_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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::<IsUpgradeContainer>().add_systems(
Update,
replace_available_upgrades.run_if(on_event::<UpgradeEvent>()),
);
}
}

const FIRST_UPGRADE: UpgradeKind = UpgradeKind::TouchOfLife;

#[derive(Component, Reflect)]
pub struct IsUpgradeContainer;

pub fn spawn_upgrade_panel(
commands: &mut Commands,
config: &EditorScreenConfig,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -231,3 +247,19 @@ fn spawn_submit_button(commands: &mut Commands, config: &EditorScreenConfig) ->

submit_button
}

fn replace_available_upgrades(
mut commands: Commands,
config: Res<Config>,
container_query: Query<Entity, With<IsUpgradeContainer>>,
) {
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)
}
}

0 comments on commit b03d0b5

Please sign in to comment.