From 0bb7840b30cd8cf0909750bb61886cf57b893ffb Mon Sep 17 00:00:00 2001 From: Melody Madeline Lyons Date: Tue, 25 Jun 2024 13:05:01 -0700 Subject: [PATCH] Add picker window --- Cargo.lock | 2 + crates/modals/Cargo.toml | 2 + crates/modals/src/event_graphic_picker.rs | 47 +++++++++++++++-------- 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9759b3eb..ea9b8437 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3213,9 +3213,11 @@ dependencies = [ "camino", "egui", "fuzzy-matcher", + "glam", "luminol-components", "luminol-core", "luminol-data", + "luminol-egui-wgpu", "ouroboros", ] diff --git a/crates/modals/Cargo.toml b/crates/modals/Cargo.toml index a575e5a3..31fb90cf 100644 --- a/crates/modals/Cargo.toml +++ b/crates/modals/Cargo.toml @@ -24,6 +24,8 @@ camino.workspace = true luminol-core.workspace = true luminol-data.workspace = true luminol-components.workspace = true +luminol-egui-wgpu.workspace = true +glam.workspace = true fuzzy-matcher = "0.3.7" diff --git a/crates/modals/src/event_graphic_picker.rs b/crates/modals/src/event_graphic_picker.rs index bb6e7738..addeadec 100644 --- a/crates/modals/src/event_graphic_picker.rs +++ b/crates/modals/src/event_graphic_picker.rs @@ -100,24 +100,31 @@ impl luminol_core::Modal for Modal { update_state: &'m mut UpdateState<'_>, ) -> impl egui::Widget + 'm { move |ui: &mut egui::Ui| { - let button_text = match data { - rpg::Graphic { - character_name: Some(name), - .. - } => name.to_string(), - rpg::Graphic { - tile_id: Some(id), .. - } => format!("Tile {id}"), - _ => "None".to_string(), - }; - - let button_response = ui.button(button_text); - if button_response.clicked() { + let desired_size = self + .button_sprite + .as_ref() + .map(|s| s.sprite_size) + .unwrap_or(egui::vec2(32., 32.)); + let (response, painter) = ui.allocate_painter(desired_size, egui::Sense::click()); + + if let Some(sprite) = &mut self.button_sprite { + self.button_viewport.set_size( + &update_state.graphics.render_state, + glam::vec2(desired_size.x, desired_size.y), + ); + let callback = luminol_egui_wgpu::Callback::new_paint_callback( + response.rect, + Painter::new(sprite.prepare(&update_state.graphics)), + ); + painter.add(callback); + } + + if response.clicked() { self.open = true; } self.show_window(update_state, ui.ctx(), data); - button_response + response } } @@ -127,7 +134,17 @@ impl luminol_core::Modal for Modal { } impl Modal { - pub fn update_graphic(&mut self, update_state: &UpdateState<'_>, graphic: &rpg::Graphic) {} + pub fn update_graphic(&mut self, update_state: &UpdateState<'_>, graphic: &rpg::Graphic) { + self.button_sprite = Event::new_standalone( + &update_state.graphics, + update_state.filesystem, + &self.button_viewport, + graphic, + &self.tilepicker.atlas, + ) + .unwrap(); + self.sprite = None; + } fn show_window( &mut self,