From 6ed40705c803744fa44159f24adde084814a092a Mon Sep 17 00:00:00 2001 From: Felix Rath Date: Thu, 18 Jul 2024 15:23:42 +0200 Subject: [PATCH] feat: Tooltip for unknown GameEffects --- docs/notes.md | 21 +++++++++++---------- src/fight_ui/render_fight_window.rs | 26 ++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/docs/notes.md b/docs/notes.md index cb7ed57..6cc9d1d 100644 --- a/docs/notes.md +++ b/docs/notes.md @@ -1,19 +1,11 @@ # Todos ## Next: -- [ ] fight-ui display for effects - - Probably using `OnAdd` for each effect in the UI to attach UI info/save it to an `EntityHashMap`/`HashMap` or sth.? - - [x] With remaining _total_ time (also remaining ticks?) - - [ ] With tooltip - - [ ] How to handle "unknown" (i.e., not modeled for UI) effects? - - Idea: "Unknown effect `TypeName`" - - Currently: `warn_once!()` in console; probably also want a warning-tooltip - -- [ ] Resetting fights/fight selection menu - - [ ] Figure out what's next :) More complicated abilities? More units per side? AI/Enemy behavior :O? - Cooldowns? Cast-Times? Icons for Slots/Abilities/Effects? :O +- [ ] Resetting fights/fight selection menu + ## Possible Next - [ ] 1 or 2 basic tests, also just to try out how well it works/how easy it is @@ -38,6 +30,15 @@ --- # Done --- +- [x] fight-ui display for effects + - Probably using `OnAdd` for each effect in the UI to attach UI info/save it to an `EntityHashMap`/`HashMap` or sth.? + - For now just immediate re-render; probably a target for reactivity later on (but don't care yet :) ) + - [x] With remaining _total_ time (also remaining ticks?) + - [x] With tooltip + - [x] How to handle "unknown" (i.e., not modeled for UI) effects? + - Idea: "Unknown effect `TypeName`" + - Currently: `warn_once!()` in console; probably also want a warning-tooltip <- added tooltip + - [x] Simple test(s) for `FiniteRepeatingTimer` - [x] Let's build a basic DoT! diff --git a/src/fight_ui/render_fight_window.rs b/src/fight_ui/render_fight_window.rs index 1518e30..7edf0a7 100644 --- a/src/fight_ui/render_fight_window.rs +++ b/src/fight_ui/render_fight_window.rs @@ -73,6 +73,7 @@ pub fn render_fight_windows( for fight_window_e in fight_windows.into_iter() { egui::Window::new("Fight") .id(Id::new(fight_window_e)) + .default_size((500.0, 500.0)) .show(&ui_ctx, |ui: &mut Ui| { run_ui_system( ui, @@ -534,10 +535,6 @@ fn ui_abilities( (ui, ui_column_state) } -// #[expect( -// clippy::type_complexity, -// reason = "SystemState<..> big but ok, part of the ui-pattern (for now)" -// )] fn ui_effects( In((mut ui, (model_e,))): In<(Ui, (Entity,))>, world: &mut World, @@ -611,6 +608,27 @@ fn ui_effects( "Component `{}` is ReflectGameEffect but not ReflectRenderGameEffectImmediate!", component_info.name() ); + + let short_name = component_info + .name() + .rsplit_once(':') + .map(|(_prefix, shortname)| shortname) + .unwrap_or(component_info.name()); + + let label = ui.label(format!("[UNKNOWN] {short_name}")); + + if label.contains_pointer() { + egui::containers::popup::show_tooltip_at( + ui.ctx(), + ui.layer_id(), + Id::new("UnknownEffectTooltip").with(comp_as_reflect as *const _), + label.rect.right_top(), + |ui| { + ui.label(component_info.name()); + }, + ); + } + continue; };