Allow position information for newly added VRAM items
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use std::{fs::File, io::Write, path::PathBuf};
|
||||
|
||||
use crate::{gui::{self, main_tab::MainTab, MutexTIMManager, VRAM_HEIGHT, VRAM_WIDTH}, MainWindow};
|
||||
use crate::{gui::{self, main_tab::{MainTab, NewVRAMImageInfo}, MutexTIMManager, VRAM_HEIGHT, VRAM_WIDTH}, MainWindow};
|
||||
use super::FileTab;
|
||||
use rfd::FileDialog;
|
||||
use slint::SharedString;
|
||||
@@ -45,15 +45,8 @@ pub(super) fn on_add_image(tim_manager: MutexTIMManager) -> impl FnMut(&mut File
|
||||
return move |file_tab, main_tab, main_window| {
|
||||
let file_name = file_tab.get_file_name();
|
||||
let encoding = file_tab.get_encoding()?;
|
||||
let mut tim_mgr = tim_manager.lock().expect("VRAM already locked");
|
||||
let (image, palette_image) = tim_mgr.get_converted_unadded_tim_image(encoding)?;
|
||||
let (full_image, _) = tim_mgr.get_converted_unadded_tim_image(Encoding::FullColor)?;
|
||||
|
||||
let images_created = main_tab.add_new_vram_file(&file_name, full_image, image, encoding, palette_image);
|
||||
if let Err(error) = tim_mgr.add_unadded_tim(images_created) {
|
||||
main_tab.pop_vram_files(images_created);
|
||||
return Err(error);
|
||||
}
|
||||
add_unadded_tim(main_tab, tim_manager.clone(), &file_name, encoding)?;
|
||||
|
||||
file_tab.clear_load();
|
||||
main_window.invoke_change_to_main();
|
||||
@@ -61,7 +54,7 @@ pub(super) fn on_add_image(tim_manager: MutexTIMManager) -> impl FnMut(&mut File
|
||||
};
|
||||
}
|
||||
|
||||
pub(super) fn on_load_project_clicked() -> impl FnMut(&mut FileTab, &MainWindow) -> Result<(), Error> + 'static {
|
||||
pub(super) fn on_load_project_clicked(tim_manager: MutexTIMManager) -> impl FnMut(&mut FileTab, &MainWindow) -> Result<(), Error> + 'static {
|
||||
move |_file_tab, main_window| {
|
||||
let open_location = main_window.get_project_widget_open_project_path();
|
||||
if open_location.is_empty() {
|
||||
@@ -69,13 +62,17 @@ pub(super) fn on_load_project_clicked() -> impl FnMut(&mut FileTab, &MainWindow)
|
||||
}
|
||||
|
||||
let file_content = tool_helper::read_file_to_string(&PathBuf::from(open_location.as_str()))?;
|
||||
let _new_project = match serde_json::from_str::<Project>(&file_content) {
|
||||
let new_project = match serde_json::from_str::<Project>(&file_content) {
|
||||
Ok(project) => project,
|
||||
Err(error) => {
|
||||
return Err(Error::from_error(error));
|
||||
}
|
||||
};
|
||||
|
||||
for job in new_project.jobs {
|
||||
let (_, _) = tim_manager.lock().expect("VRAM already locked").load_unadded_tim(&job.file_path)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -102,7 +99,7 @@ pub(super) fn on_save_project_clicked(tim_manager: MutexTIMManager) -> impl FnMu
|
||||
if let Some(mut cur_palette) = cur_palette {
|
||||
cur_palette.pos = ImagePosition::new(vram.x as u16, vram.y as u16);
|
||||
if let Some(cur_job) = &mut cur_job {
|
||||
cur_job.add_palette(cur_palette);
|
||||
cur_job.palette_rect = cur_palette;
|
||||
}
|
||||
}
|
||||
None
|
||||
@@ -122,7 +119,7 @@ pub(super) fn on_save_project_clicked(tim_manager: MutexTIMManager) -> impl FnMu
|
||||
}
|
||||
}).collect());
|
||||
if let Some(cur_job) = cur_job {
|
||||
project.push(cur_job);
|
||||
project.jobs.push(cur_job);
|
||||
}
|
||||
|
||||
let json_content = match serde_json::to_string(&project) {
|
||||
@@ -170,6 +167,22 @@ pub(super) fn on_browse_save_project_clicked() -> impl FnMut(&mut FileTab, &Main
|
||||
}
|
||||
}
|
||||
|
||||
fn add_unadded_tim(main_tab: &mut MainTab, tim_manager: MutexTIMManager, file_name: &String, encoding: Encoding) -> Result<(), Error> {
|
||||
let mut tim_mgr = tim_manager.lock().expect("VRAM already locked");
|
||||
let (image, palette_image) = tim_mgr.get_converted_unadded_tim_image(encoding)?;
|
||||
let (full_image, _) = tim_mgr.get_converted_unadded_tim_image(Encoding::FullColor)?;
|
||||
let image = NewVRAMImageInfo::new(image, 0, 0, encoding);
|
||||
let palette_image = if let Some(palette_image) = palette_image { Some(NewVRAMImageInfo::new(palette_image, 0, 0, Encoding::FullColor)) } else { None };
|
||||
|
||||
let images_created = main_tab.add_new_vram_file(file_name, full_image, image, palette_image);
|
||||
if let Err(error) = tim_mgr.add_unadded_tim(images_created) {
|
||||
main_tab.pop_vram_files(images_created);
|
||||
return Err(error);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn create_project_file_dialog() -> FileDialog {
|
||||
FileDialog::new()
|
||||
.add_filter("TIM project file (.tim_project)", &["tim_project"])
|
||||
|
||||
Reference in New Issue
Block a user