diff --git a/crates/app/src/service/dev/console/ui.rs b/crates/app/src/service/dev/console/ui.rs index 2a47e1f..30e30f7 100644 --- a/crates/app/src/service/dev/console/ui.rs +++ b/crates/app/src/service/dev/console/ui.rs @@ -5,17 +5,6 @@ use crate::prelude::*; use bevy::input_focus::InputFocus; use q_cmd_prompt::prelude::*; -fn on_switch_screen( - trigger: On, - screens: Screens, - mut prompts: Query<&mut ConsolePrompt>, -) { - for mut prompt in &mut prompts { - let screen_name = screens.get_by_id(trigger.to).unwrap().name(); - prompt.0 = format!("<{screen_name}>\n> "); - } -} - fn toggle_console( keys: Res>, mut focus: ResMut, @@ -51,14 +40,13 @@ fn toggle_console( // this should really be an observer but AcquireFocus isn't publically accessible fn on_focus( focus: Res, - console: Query<&ConsoleUiSettings>, + console: Query>, mut commands: Commands, - mut last_focus: Local>, ) { - let focus_entity = focus.get(); - if *last_focus == focus_entity { + if !focus.is_changed() { return; } + let focus_entity = focus.get(); if let Some(id) = focus_entity && console.get(id).is_ok() { @@ -66,17 +54,17 @@ fn on_focus( font_color: LinearRgba::new(1., 1., 1., 1.).into(), background_color: LinearRgba::new(0., 0., 0., 0.8).into(), }); - } else if let Some(last_focus) = *last_focus { - commands.entity(last_focus).insert(ConsoleUiSettings { - font_color: LinearRgba::new(1., 1., 1., 0.5).into(), - background_color: LinearRgba::new(0., 0., 0., 0.4).into(), + } else { + console.iter().for_each(|entity| { + commands.entity(entity).insert(ConsoleUiSettings { + font_color: LinearRgba::new(1., 1., 1., 0.5).into(), + background_color: LinearRgba::new(0., 0., 0., 0.4).into(), + }); }); } - *last_focus = focus_entity; } pub fn plugin(app: &mut App) { - app.add_observer(on_switch_screen); app.add_systems(PostUpdate, (toggle_console, on_focus).chain()); app.add_systems(Startup, |mut commands: Commands| { // TODO: Dev overlay should be put into a more generalized editor mod @@ -96,7 +84,12 @@ pub fn plugin(app: &mut App) { top: percent(67), ..Default::default() }, - children![(Name::new("Console"), Visibility::Hidden, Console,)], + children![( + Name::new("Console"), + Visibility::Hidden, + Console, + ConsolePrompt("\n\n> ".into()) + )], )], )); });