Skip to content

Commit

Permalink
Make Modal::reset actually useful
Browse files Browse the repository at this point in the history
  • Loading branch information
melody-rs committed Jul 2, 2024
1 parent 7eb948d commit 81e81a3
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 12 deletions.
3 changes: 1 addition & 2 deletions crates/core/src/modal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,5 @@ pub trait Modal: Sized {
update_state: &'m mut crate::UpdateState<'_>,
) -> impl egui::Widget + 'm; // woah rpitit (so cool)

// FIXME is this used anywhere?
fn reset(&mut self);
fn reset(&mut self, update_state: &mut crate::UpdateState<'_>, data: &Self::Data);
}
3 changes: 2 additions & 1 deletion crates/modals/src/database_modal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ where
}
}

fn reset(&mut self) {
fn reset(&mut self, _update_state: &mut luminol_core::UpdateState<'_>, _data: &Self::Data) {
// not much internal state, so we dont need to do much here
self.state = State::Closed;
}
}
Expand Down
7 changes: 4 additions & 3 deletions crates/modals/src/event_graphic_picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,14 @@ impl luminol_core::Modal for Modal {
}
}

fn reset(&mut self) {
fn reset(&mut self, update_state: &mut UpdateState<'_>, data: &Self::Data) {
self.update_graphic(update_state, data); // we need to update the button sprite to prevent desyncs
self.state = State::Closed;
}
}

impl Modal {
pub fn update_graphic(&mut self, update_state: &UpdateState<'_>, graphic: &rpg::Graphic) {
fn update_graphic(&mut self, update_state: &UpdateState<'_>, graphic: &rpg::Graphic) {
let atlas = update_state
.graphics
.atlas_loader
Expand All @@ -240,7 +241,7 @@ impl Modal {
graphic,
&atlas,
)
.unwrap();
.unwrap(); // FIXME
}

fn load_tilepicker(
Expand Down
2 changes: 1 addition & 1 deletion crates/modals/src/graphic_picker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl luminol_core::Modal for Modal {
|ui: &mut egui::Ui| todo!()
}

fn reset(&mut self) {
fn reset(&mut self, update_state: &mut luminol_core::UpdateState<'_>, data: &Self::Data) {
todo!()
}
}
3 changes: 2 additions & 1 deletion crates/modals/src/sound_picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ impl luminol_core::Modal for Modal {
}
}

fn reset(&mut self) {
fn reset(&mut self, update_state: &mut luminol_core::UpdateState<'_>, _data: &Self::Data) {
// we don't need to do much here
self.state = State::Closed;
}
}
Expand Down
5 changes: 2 additions & 3 deletions crates/ui/src/windows/event_edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,8 @@ impl luminol_core::Window for Window {

let page = &mut self.event.pages[self.selected_page];
if self.selected_page != previous_page {
// we need to update the modal to prevent desyncs
self.graphic_modal
.update_graphic(update_state, &page.graphic);
// reset the modal if we've changed pages
self.graphic_modal.reset(update_state, &page.graphic);
}

egui::SidePanel::left(id_source.with("side_panel")).show_inside(ui, |ui| {
Expand Down
3 changes: 2 additions & 1 deletion crates/ui/src/windows/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ impl luminol_core::Window for Window {
))
.changed();
if self.previous_item != Some(item.id) {
self.menu_se_picker.reset();
// reset the modal if the item has changed (this is practically a no-op)
self.menu_se_picker.reset(update_state, &item.menu_se);
}

modified |= columns[1]
Expand Down

0 comments on commit 81e81a3

Please sign in to comment.