Skip to content

Commit

Permalink
Very destructive commit
Browse files Browse the repository at this point in the history
Not very happy with this because it clones things, which is a waste of memory
  • Loading branch information
melody-rs committed Jun 30, 2024
1 parent 787c5cb commit 471b014
Show file tree
Hide file tree
Showing 18 changed files with 568 additions and 614 deletions.
6 changes: 3 additions & 3 deletions crates/components/src/database_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ impl DatabaseView {
pub fn show<T, R>(
&mut self,
ui: &mut egui::Ui,
update_state: &luminol_core::UpdateState<'_>,
update_state: &mut luminol_core::UpdateState<'_>,
label: impl Into<egui::WidgetText>,
vec: &mut Vec<T>,
formatter: impl Fn(&T) -> String,
inner: impl FnOnce(&mut egui::Ui, &mut Vec<T>, usize) -> R,
inner: impl FnOnce(&mut egui::Ui, &mut Vec<T>, usize, &mut luminol_core::UpdateState<'_>) -> R,
) -> egui::InnerResponse<DatabaseViewResponse<R>>
where
T: luminol_data::rpg::DatabaseEntry,
Expand Down Expand Up @@ -262,7 +262,7 @@ impl DatabaseView {

DatabaseViewResponse {
inner: (self.selected_id < vec.len())
.then(|| inner(ui, vec, self.selected_id)),
.then(|| inner(ui, vec, self.selected_id, update_state)),
modified,
}
})
Expand Down
2 changes: 1 addition & 1 deletion crates/data/src/rmxp/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
optional_path_serde, Path, Table2,
};

#[derive(Default, Debug, serde::Deserialize, serde::Serialize)]
#[derive(Default, Debug, serde::Deserialize, serde::Serialize, Clone)]
#[derive(alox_48::Deserialize, alox_48::Serialize)]
#[marshal(class = "RPG::Actor")]
pub struct Actor {
Expand Down
2 changes: 1 addition & 1 deletion crates/data/src/rmxp/armor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
optional_path_alox, optional_path_serde, Path,
};

#[derive(Default, Debug, serde::Deserialize, serde::Serialize)]
#[derive(Default, Debug, serde::Deserialize, serde::Serialize, Clone)]
#[derive(alox_48::Deserialize, alox_48::Serialize)]
#[marshal(class = "RPG::Armor")]
pub struct Armor {
Expand Down
4 changes: 2 additions & 2 deletions crates/data/src/rmxp/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// along with Luminol. If not, see <http://www.gnu.org/licenses/>.
pub use crate::{id_alox, id_serde, id_vec_alox, id_vec_serde, Table1};

#[derive(Default, Debug, serde::Deserialize, serde::Serialize)]
#[derive(Default, Debug, serde::Deserialize, serde::Serialize, Clone)]
#[derive(alox_48::Deserialize, alox_48::Serialize)]
#[marshal(class = "RPG::Class")]
pub struct Class {
Expand All @@ -36,7 +36,7 @@ pub struct Class {
pub learnings: Vec<Learning>,
}

#[derive(Default, Debug, serde::Deserialize, serde::Serialize)]
#[derive(Default, Debug, serde::Deserialize, serde::Serialize, Clone)]
#[derive(alox_48::Deserialize, alox_48::Serialize)]
#[marshal(class = "RPG::Class::Learning")]
pub struct Learning {
Expand Down
4 changes: 2 additions & 2 deletions crates/data/src/rmxp/enemy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub use crate::{
optional_path_serde, Path, Table1,
};

#[derive(Default, Debug, serde::Deserialize, serde::Serialize)]
#[derive(Default, Debug, serde::Deserialize, serde::Serialize, Clone)]
#[derive(alox_48::Deserialize, alox_48::Serialize)]
#[marshal(class = "RPG::Enemy")]
pub struct Enemy {
Expand Down Expand Up @@ -65,7 +65,7 @@ pub struct Enemy {
pub treasure_prob: i32,
}

#[derive(Debug, serde::Deserialize, serde::Serialize)]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
#[derive(alox_48::Deserialize, alox_48::Serialize)]
#[marshal(class = "RPG::Enemy::Action")]
pub struct Action {
Expand Down
2 changes: 1 addition & 1 deletion crates/data/src/rmxp/skill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub use crate::{
optional_path_alox, optional_path_serde, rpg::AudioFile, Path,
};

#[derive(Default, Debug, serde::Deserialize, serde::Serialize)]
#[derive(Default, Debug, serde::Deserialize, serde::Serialize, Clone)]
#[derive(alox_48::Deserialize, alox_48::Serialize)]
#[marshal(class = "RPG::Skill")]
pub struct Skill {
Expand Down
2 changes: 1 addition & 1 deletion crates/data/src/rmxp/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// along with Luminol. If not, see <http://www.gnu.org/licenses/>.
use crate::{id_alox, id_serde, id_vec_alox, id_vec_serde, optional_id_alox, optional_id_serde};

#[derive(Default, Debug, serde::Deserialize, serde::Serialize)]
#[derive(Default, Debug, serde::Deserialize, serde::Serialize, Clone)]
#[derive(alox_48::Deserialize, alox_48::Serialize)]
#[marshal(class = "RPG::State")]
pub struct State {
Expand Down
2 changes: 1 addition & 1 deletion crates/data/src/rmxp/weapon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub use crate::{
optional_path_alox, optional_path_serde, rpg::AudioFile, Path,
};

#[derive(Default, Debug, serde::Deserialize, serde::Serialize)]
#[derive(Default, Debug, serde::Deserialize, serde::Serialize, Clone)]
#[derive(alox_48::Deserialize, alox_48::Serialize)]
#[marshal(class = "RPG::Weapon")]
pub struct Weapon {
Expand Down
50 changes: 33 additions & 17 deletions crates/modals/src/sound_picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,23 @@
use luminol_core::prelude::*;

pub struct Modal {
tab: luminol_components::SoundTab,
open: bool,
state: State,
id_source: egui::Id,
source: Source,
}

enum State {
Closed,
Open { tab: luminol_components::SoundTab },
}

impl Modal {
pub fn new(
filesystem: &impl FileSystem,
source: Source,
selected_track: luminol_data::rpg::AudioFile,
) -> Self {
let tab = luminol_components::SoundTab::new(filesystem, source, selected_track);
Self { tab, open: false }
pub fn new(source: Source, id_source: impl Into<egui::Id>) -> Self {
Self {
state: State::Closed,
id_source: id_source.into(),
source,
}
}
}

Expand All @@ -48,16 +53,21 @@ impl luminol_core::Modal for Modal {
update_state: &'m mut luminol_core::UpdateState<'_>,
) -> impl egui::Widget + 'm {
|ui: &mut egui::Ui| {
let button_text = if let Some(track) = &self.tab.audio_file.name {
format!("Audio/{}/{}", self.tab.source, track)
let button_text = if let Some(track) = &data.name {
format!("Audio/{}/{}", self.source, track)
} else {
"(None)".to_string()
};

let mut button_response = ui.button(button_text);

if button_response.clicked() {
self.open = true;
let tab = luminol_components::SoundTab::new(
update_state.filesystem,
self.source,
data.clone(),
);
self.state = State::Open { tab };
}
if self.show_window(update_state, ui.ctx(), data) {
button_response.mark_changed()
Expand All @@ -68,7 +78,7 @@ impl luminol_core::Modal for Modal {
}

fn reset(&mut self) {
self.open = false;
self.state = State::Closed;
}
}

Expand All @@ -79,24 +89,30 @@ impl Modal {
ctx: &egui::Context,
data: &mut luminol_data::rpg::AudioFile,
) -> bool {
let mut win_open = self.open;
let mut win_open = true;
let mut keep_open = true;
let mut needs_save = false;

let State::Open { tab } = &mut self.state else {
return false;
};

egui::Window::new("Graphic Picker")
.open(&mut win_open)
.show(ctx, |ui| {
self.tab.ui(ui, update_state);
tab.ui(ui, update_state);
ui.separator();

luminol_components::close_options_ui(ui, &mut keep_open, &mut needs_save);
});

if needs_save {
*data = self.tab.audio_file.clone();
*data = tab.audio_file.clone();
}

self.open = win_open && keep_open;
if !(win_open && keep_open) {
self.state = State::Closed;
}
needs_save
}
}
Loading

0 comments on commit 471b014

Please sign in to comment.