From a88e2e330068eef4296df91e0e06df6a80c42599 Mon Sep 17 00:00:00 2001 From: Melody Madeline Lyons Date: Sat, 29 Jun 2024 01:02:48 -0700 Subject: [PATCH] Grey out invalid sprites --- crates/modals/src/event_graphic_picker.rs | 26 ++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/crates/modals/src/event_graphic_picker.rs b/crates/modals/src/event_graphic_picker.rs index fc8f8e35..4f19a7db 100644 --- a/crates/modals/src/event_graphic_picker.rs +++ b/crates/modals/src/event_graphic_picker.rs @@ -28,7 +28,7 @@ use luminol_components::UiExt; use luminol_core::prelude::*; pub struct Modal { - entries: Vec, + entries: Vec, open: bool, id_source: egui::Id, @@ -47,6 +47,12 @@ pub struct Modal { sprite: Option, } +#[derive(PartialEq, PartialOrd, Eq, Ord)] +struct Entry { + path: camino::Utf8PathBuf, + invalid: bool, +} + struct PreviewSprite { sprite: Sprite, sprite_size: egui::Vec2, @@ -80,10 +86,15 @@ impl Modal { .unwrap() .into_iter() .map(|m| { - m.path + let path = m + .path .strip_prefix("Graphics/Characters") .unwrap_or(&m.path) - .with_extension("") + .with_extension(""); + Entry { + path, + invalid: false, + } }) .collect(); entries.sort_unstable(); @@ -334,7 +345,7 @@ impl Modal { let mut is_faint = false; let matcher = fuzzy_matcher::skim::SkimMatcherV2::default(); - for entry in self.entries.iter() { + for Entry { path: entry ,invalid} in self.entries.iter_mut() { if matcher.fuzzy(entry.as_str(), &self.search_text, false).is_none() { continue; } @@ -344,13 +355,18 @@ impl Modal { ui.with_stripe(is_faint, |ui| { let checked = matches!(self.selected, Selected::Graphic { ref path, .. } if path == entry); - let res = ui.selectable_label(checked, entry.as_str()); + let mut text = egui::RichText::new(entry.as_str()); + if *invalid { + text = text.color(egui::Color32::LIGHT_RED); + } + let res = ui.add_enabled(!*invalid, egui::SelectableLabel::new(checked, text)); ui.add_space(ui.available_width()); if res.clicked() { let sprite = match Self::load_preview_sprite(update_state, entry, self.hue, self.opacity) { Ok(sprite) => sprite, Err(e) => { luminol_core::error!(update_state.toasts, e); + *invalid = true; return; } };