Very basic notification, need to close it when clicked

main
Elijah Voigt 3 months ago
parent 5e246d21dc
commit 6433f7bb6a

@ -723,6 +723,7 @@ struct AssignMonologue(Handle<Monologue>);
fn assign_monologue_to_tree(
mut events: EventReader<AssignMonologue>,
query: Query<Entity, (With<Tree>, Without<TreeMonologue>)>,
mut notice: ResMut<Notice>,
mut commands: Commands,
) {
// Kinda a weird hack because query does not update
@ -739,8 +740,10 @@ fn assign_monologue_to_tree(
commands.entity(tree).insert(monologue);
} else if let Some(path) = event.0.path() {
error!("No trees avaliable for {path:?}");
notice.0 = format!("No trees avaliable for {path:?}");
} else {
error!("Monologue is not yet loaded!");
notice.0 = "Monologue is not yet loaded!".into();
}
});
}

@ -11,6 +11,7 @@ impl Plugin for DebuggingPlugin {
.init_resource::<ToolTip>()
.init_resource::<Fps>()
.init_resource::<EntityCount>()
.init_resource::<Notice>()
.add_plugins(RapierDebugRenderPlugin::default().disabled())
// Added by Rapier
// .add_plugins(AabbGizmoPlugin)
@ -32,6 +33,7 @@ impl Plugin for DebuggingPlugin {
sync_resource_to_ui::<Fps>.run_if(resource_changed::<Fps>),
track_entity_count,
sync_resource_to_ui::<EntityCount>.run_if(resource_changed::<EntityCount>),
sync_resource_to_ui::<Notice>.run_if(resource_changed::<Notice>),
)
.run_if(in_state(DebuggingState::On)),
),
@ -74,13 +76,29 @@ fn init_debug_ui(mut commands: Commands) {
children![Text::new(VERSION),],
GlobalZIndex(i32::MAX - 1),
Node {
width: Val::Auto,
max_width: Val::Percent(50.0),
align_self: AlignSelf::End,
justify_self: JustifySelf::End,
..default()
},
));
commands.spawn((
DebuggingState::On,
Name::new("Notice"),
children![(
Text::new(""),
SyncResource::<Notice>::default(),
)],
GlobalZIndex(i32::MAX - 1),
Node {
max_width: Val::Percent(50.0),
align_self: AlignSelf::End,
justify_self: JustifySelf::Start,
..default()
},
));
// "Turn on Debugging" button
commands
.spawn((
@ -186,6 +204,15 @@ fn toggle_rapier_debug_render(
context.enabled = *state.get() == DebuggingState::On;
}
#[derive(Default, Resource)]
pub struct Notice(pub String);
impl Display for Notice {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
writeln!(f, "{}", self.0)
}
}
/// Add a generic Tooltip that follows the mouse in debug mode
#[derive(Default, Resource)]
pub struct ToolTip(HashMap<String, String>);

Loading…
Cancel
Save