From af1a4475acabffb2e849cedf0944c3ce5aca2c64 Mon Sep 17 00:00:00 2001 From: Melody Madeline Lyons Date: Tue, 2 Jul 2024 07:02:05 -0700 Subject: [PATCH] Hack in the enemy battler picker --- crates/modals/src/graphic_picker/hue.rs | 19 ++++++++ crates/ui/src/windows/enemies.rs | 59 ++++++++++++++++++++----- crates/ui/src/windows/items.rs | 2 +- src/app/top_bar.rs | 2 +- 4 files changed, 70 insertions(+), 12 deletions(-) diff --git a/crates/modals/src/graphic_picker/hue.rs b/crates/modals/src/graphic_picker/hue.rs index 8ee4e68d..a56514df 100644 --- a/crates/modals/src/graphic_picker/hue.rs +++ b/crates/modals/src/graphic_picker/hue.rs @@ -273,6 +273,25 @@ impl Modal { }); }); + egui::TopBottomPanel::top(self.id_source.with("top")).show_inside(ui, |ui| { + ui.add_space(1.0); // pad out the top + ui.horizontal(|ui| { + ui.label("Hue"); + if ui.add(egui::Slider::new(hue, 0..=360)).changed() { + match selected { + Selected::Entry { sprite, .. } => { + sprite + .sprite + .graphic + .set_hue(&update_state.graphics.render_state, *hue); + } + Selected::None => {} + } + } + }); + ui.add_space(1.0); // pad out the bottom + }); + egui::TopBottomPanel::bottom(self.id_source.with("bottom")).show_inside(ui, |ui| { ui.add_space(ui.style().spacing.item_spacing.y); luminol_components::close_options_ui(ui, &mut keep_open, &mut needs_save); diff --git a/crates/ui/src/windows/enemies.rs b/crates/ui/src/windows/enemies.rs index c8091b15..070ea7a7 100644 --- a/crates/ui/src/windows/enemies.rs +++ b/crates/ui/src/windows/enemies.rs @@ -23,6 +23,8 @@ // Program grant you additional permission to convey the resulting work. use luminol_components::UiExt; +use luminol_core::Modal; +use luminol_modals::graphic_picker::hue::Modal as GraphicPicker; #[derive(Clone, Copy, Debug, Eq, PartialEq, Default)] #[derive(strum::Display, strum::EnumIter)] @@ -35,18 +37,36 @@ pub enum TreasureType { Armor, } -#[derive(Default)] pub struct Window { selected_enemy_name: Option, previous_enemy: Option, + graphic_picker: GraphicPicker, + collapsing_view: luminol_components::CollapsingView, view: luminol_components::DatabaseView, } impl Window { - pub fn new() -> Self { - Default::default() + pub fn new(update_state: &luminol_core::UpdateState<'_>) -> Self { + let enemies = update_state.data.enemies(); + let enemy = &enemies.data[0]; + Self { + selected_enemy_name: None, + previous_enemy: None, + + graphic_picker: GraphicPicker::new( + update_state, + "Graphics/Battlers".into(), + enemy.battler_name.as_deref(), + enemy.battler_hue, + egui::vec2(196., 256.), + "enemy_battler_picker", + ), + + collapsing_view: luminol_components::CollapsingView::new(), + view: luminol_components::DatabaseView::new(), + } } fn show_action_header( @@ -279,13 +299,32 @@ impl luminol_core::Window for Window { self.selected_enemy_name = Some(enemy.name.clone()); ui.with_padded_stripe(false, |ui| { - modified |= ui - .add(luminol_components::Field::new( - "Name", - egui::TextEdit::singleline(&mut enemy.name) - .desired_width(f32::INFINITY), - )) - .changed(); + ui.horizontal(|ui| { + modified |= ui + .add(luminol_components::Field::new( + "Graphic", + self.graphic_picker.button( + (&mut enemy.battler_name, &mut enemy.battler_hue), + update_state, + ), + )) + .changed(); + if self.previous_enemy != Some(enemy.id) { + // avoid desyncs by resetting the modal if the item has changed + self.graphic_picker.reset( + update_state, + (&mut enemy.battler_name, &mut enemy.battler_hue), + ); + } + + modified |= ui + .add(luminol_components::Field::new( + "Name", + egui::TextEdit::singleline(&mut enemy.name) + .desired_width(f32::INFINITY), + )) + .changed(); + }); }); ui.with_padded_stripe(true, |ui| { diff --git a/crates/ui/src/windows/items.rs b/crates/ui/src/windows/items.rs index a8364d2a..c5fac9fe 100644 --- a/crates/ui/src/windows/items.rs +++ b/crates/ui/src/windows/items.rs @@ -49,7 +49,7 @@ impl Window { menu_se_picker: SoundPicker::new(luminol_audio::Source::SE, "item_menu_se_picker"), graphic_picker: GraphicPicker::new( update_state, - camino::Utf8PathBuf::from("Graphics/Icons"), + "Graphics/Icons".into(), item.icon_name.as_deref(), egui::vec2(32., 32.), "item_icon_picker", diff --git a/src/app/top_bar.rs b/src/app/top_bar.rs index e3a4027d..964006f2 100644 --- a/src/app/top_bar.rs +++ b/src/app/top_bar.rs @@ -255,7 +255,7 @@ impl TopBar { if ui.button("Enemies").clicked() { update_state .edit_windows - .add_window(luminol_ui::windows::enemies::Window::new()); + .add_window(luminol_ui::windows::enemies::Window::new(update_state)); } ui.add_enabled_ui(false, |ui| {