Compare commits
6 Commits
b0b8c43700
...
f72f92d4c2
Author | SHA1 | Date |
---|---|---|
|
f72f92d4c2 | |
|
07a7149abc | |
|
1ea6f74296 | |
|
5de07073d3 | |
|
7967c6824f | |
|
1e86738f04 |
|
@ -4,7 +4,7 @@ use crate::{gui::{self, main_tab::{MainTab, NewVRAMImageInfo}, MutexTIMManager,
|
|||
use super::FileTab;
|
||||
use rfd::FileDialog;
|
||||
use slint::SharedString;
|
||||
use tim_tool::logic::{project::{ImagePosition, Job, PaletteRect, Project}, tim::types::Encoding, TIMManager};
|
||||
use tim_tool::logic::{project::{FileSettings, ImagePosition, Job, PaletteRect, Project}, tim::types::Encoding, TIMManager};
|
||||
use tool_helper::Error;
|
||||
|
||||
pub(super) fn on_browse_file(tim_manager: MutexTIMManager) -> impl FnMut(&mut FileTab, &MainWindow) -> Result<(), Error> + 'static {
|
||||
|
@ -79,16 +79,16 @@ pub(super) fn on_load_project_clicked(tim_manager: MutexTIMManager) -> impl FnMu
|
|||
for job in new_project.jobs {
|
||||
let file_path = Job::create_file_path(job.file_path, open_location.as_str());
|
||||
let (_, _) = tim_manager.load_unadded_tim(&file_path)?;
|
||||
let (pal_width, pal_height) = job.palette_rect.size.into();
|
||||
let (pal_x, pal_y, pal_width, pal_height) = if let Some(palette_rect) = job.palette_rect {palette_rect.into()} else {(0, 0, 0, 0)};
|
||||
|
||||
tim_manager.change_unadded_tim_palette_size(pal_width, pal_height)?;
|
||||
let unadded_tim = UnaddedTIM{
|
||||
file_name: &job.name,
|
||||
image_x: job.image_pos.x,
|
||||
image_y: job.image_pos.y,
|
||||
palette_x: job.palette_rect.pos.x,
|
||||
palette_y: job.palette_rect.pos.y,
|
||||
encoding: job.encoding
|
||||
palette_x: pal_x,
|
||||
palette_y: pal_y,
|
||||
encoding: job.settings.encoding
|
||||
};
|
||||
add_unadded_tim(main_tab, &mut tim_manager, unadded_tim)?;
|
||||
}
|
||||
|
@ -126,7 +126,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.palette_rect = cur_palette;
|
||||
cur_job.palette_rect = Some(cur_palette);
|
||||
}
|
||||
}
|
||||
None
|
||||
|
@ -149,7 +149,7 @@ pub(super) fn on_save_project_clicked(tim_manager: MutexTIMManager) -> impl FnMu
|
|||
}
|
||||
}
|
||||
} else {tim.get_path()};
|
||||
cur_job = Some(Job::new(name, file_path, (vram.x as u16, vram.y as u16), Encoding::from_str(vram.encoding_str.as_str())));
|
||||
cur_job = Some(Job::new(name, file_path, (vram.x as u16, vram.y as u16), FileSettings::compatible(Encoding::from_str(vram.encoding_str.as_str()))));
|
||||
}
|
||||
prev_job
|
||||
}
|
||||
|
|
|
@ -94,6 +94,8 @@ impl MainTab {
|
|||
x: vram_image.x as i32,
|
||||
y: vram_image.y as i32,
|
||||
encoding_str: SharedString::from(encoding_str),
|
||||
use_compression: false,
|
||||
trans_setting: 0,
|
||||
palette_count,
|
||||
is_palette,
|
||||
}
|
||||
|
|
|
@ -2,6 +2,68 @@ use super::tim::types::Encoding;
|
|||
use serde::{Deserialize, Serialize};
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct FileSettings {
|
||||
pub compress: bool,
|
||||
pub transparency: Transparency,
|
||||
pub encoding: Encoding,
|
||||
}
|
||||
|
||||
impl FileSettings {
|
||||
pub fn compatible(encoding: Encoding) -> FileSettings {
|
||||
let mut new_type = FileSettings::default();
|
||||
|
||||
new_type.encoding = encoding;
|
||||
new_type
|
||||
}
|
||||
}
|
||||
|
||||
impl std::default::Default for FileSettings {
|
||||
fn default() -> Self {
|
||||
Self{compress: Default::default(), transparency: Transparency::None, encoding: Encoding::FullColor}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Job {
|
||||
pub name: String,
|
||||
pub file_path: PathBuf,
|
||||
pub image_pos: ImagePosition,
|
||||
pub palette_rect: Option<PaletteRect>,
|
||||
pub settings: FileSettings,
|
||||
}
|
||||
|
||||
impl Job {
|
||||
pub fn new(name: String, file_path: PathBuf, image_pos: (u16, u16), settings: FileSettings) -> Job {
|
||||
Job{name, file_path, image_pos: ImagePosition{x: image_pos.0, y: image_pos.1}, palette_rect: None, settings}
|
||||
}
|
||||
|
||||
pub fn create_file_path<T:?Sized + std::convert::AsRef<std::ffi::OsStr>>(file_path: PathBuf, location_path: &T) -> PathBuf {
|
||||
if file_path.is_file() {
|
||||
file_path
|
||||
}
|
||||
|
||||
else {
|
||||
let mut new_file_path = PathBuf::from(location_path);
|
||||
|
||||
new_file_path.pop();
|
||||
new_file_path.push(file_path);
|
||||
new_file_path
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Project {
|
||||
pub jobs: Vec<Job>
|
||||
}
|
||||
|
||||
impl Project {
|
||||
pub fn new(jobs: Vec<Job>) -> Project {
|
||||
Project{jobs}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct ImagePosition {
|
||||
pub x: u16,
|
||||
|
@ -56,6 +118,12 @@ impl PaletteRect {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<PaletteRect> for (u16, u16, u16, u16) {
|
||||
fn from(value: PaletteRect) -> Self {
|
||||
(value.pos.x, value.pos.y, value.size.width, value.size.height)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::default::Default for PaletteRect {
|
||||
fn default() -> Self {
|
||||
PaletteRect{pos: ImagePosition::default(), size: ImageSize::default()}
|
||||
|
@ -63,41 +131,9 @@ impl std::default::Default for PaletteRect {
|
|||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Job {
|
||||
pub name: String,
|
||||
pub file_path: PathBuf,
|
||||
pub image_pos: ImagePosition,
|
||||
pub palette_rect: PaletteRect,
|
||||
pub encoding: Encoding,
|
||||
}
|
||||
|
||||
impl Job {
|
||||
pub fn new(name: String, file_path: PathBuf, image_pos: (u16, u16), encoding: Encoding) -> Job {
|
||||
Job{name, file_path, image_pos: ImagePosition{x: image_pos.0, y: image_pos.1}, palette_rect: PaletteRect::default(), encoding}
|
||||
}
|
||||
|
||||
pub fn create_file_path<T:?Sized + std::convert::AsRef<std::ffi::OsStr>>(file_path: PathBuf, location_path: &T) -> PathBuf {
|
||||
if file_path.is_file() {
|
||||
file_path
|
||||
}
|
||||
|
||||
else {
|
||||
let mut new_file_path = PathBuf::from(location_path);
|
||||
|
||||
new_file_path.pop();
|
||||
new_file_path.push(file_path);
|
||||
new_file_path
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Project {
|
||||
pub jobs: Vec<Job>
|
||||
}
|
||||
|
||||
impl Project {
|
||||
pub fn new(jobs: Vec<Job>) -> Project {
|
||||
Project{jobs}
|
||||
}
|
||||
pub enum Transparency {
|
||||
None,
|
||||
FirstColor,
|
||||
PSXSemi,
|
||||
Both,
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
import { VRAMArea } from "../vram-components.slint";
|
||||
import { Button, ComboBox, GroupBox, StandardListView, LineEdit, ScrollView, Slider } from "std-widgets.slint";
|
||||
import { Button, CheckBox, ComboBox, GroupBox, StandardListView, LineEdit, ScrollView, Slider } from "std-widgets.slint";
|
||||
|
||||
struct VRAMImgData {
|
||||
full_image: image,
|
||||
|
@ -10,6 +10,8 @@ struct VRAMInfo {
|
|||
x: int,
|
||||
y: int,
|
||||
encoding_str: string,
|
||||
use_compression: bool,
|
||||
trans_setting: int,
|
||||
palette_count: int,
|
||||
is_palette: bool, // < Can we combine the palette into this, instead of having it separate?
|
||||
}
|
||||
|
@ -96,6 +98,14 @@ export component MainTab inherits Rectangle {
|
|||
encoding_text.encoding_str = vram_data.info.encoding_str;
|
||||
cur_sel_img.visible = true;
|
||||
|
||||
if !vram-data.info.is_palette {
|
||||
file_settings_box.set_active(i);
|
||||
}
|
||||
|
||||
else {
|
||||
file_settings_box.set_inactive();
|
||||
}
|
||||
|
||||
vram_files_list.current-item = i;
|
||||
}
|
||||
}
|
||||
|
@ -171,6 +181,14 @@ export component MainTab inherits Rectangle {
|
|||
cur_sel_img.source = root.vram_data[current-item].images.full_image;
|
||||
encoding_text.encoding_str = root.vram_data[current-item].info.encoding_str;
|
||||
cur_sel_img.visible = true;
|
||||
|
||||
if !root.vram_data[current-item].info.is_palette {
|
||||
file_settings_box.set_active(current-item);
|
||||
}
|
||||
|
||||
else {
|
||||
file_settings_box.set_inactive();
|
||||
}
|
||||
}
|
||||
|
||||
item-pointer-event(item, event, position) => {
|
||||
|
@ -279,6 +297,54 @@ export component MainTab inherits Rectangle {
|
|||
}
|
||||
}
|
||||
}
|
||||
file_settings_box := GroupBox {
|
||||
title: "File settings";
|
||||
enabled: false;
|
||||
|
||||
VerticalLayout {
|
||||
alignment: start;
|
||||
lz4_check_box := CheckBox {
|
||||
text: "Compress (lz4)";
|
||||
enabled: file_settings_box.enabled;
|
||||
|
||||
toggled => {
|
||||
if(vram_files_list.current-item != -1) {
|
||||
root.vram_data[vram_files_list.current-item].info.use_compression = self.checked;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GroupBox {
|
||||
title: "Transparency:";
|
||||
enabled: file_settings_box.enabled;
|
||||
VerticalLayout {
|
||||
alignment: start;
|
||||
trans_combo_box := ComboBox {
|
||||
model: ["No transparency", "First color transparent", "PSX semi-transparency", "Both"];
|
||||
enabled: file_settings_box.enabled;
|
||||
|
||||
selected(current-value) => {
|
||||
if(vram_files_list.current-item != -1) {
|
||||
root.vram_data[vram_files_list.current-item].info.trans_setting = self.current-index;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function set_active(current-item: int) {
|
||||
lz4_check_box.checked = root.vram_data[current-item].info.use_compression;
|
||||
trans_combo_box.current-index = root.vram_data[current-item].info.trans_setting;
|
||||
self.enabled = true;
|
||||
}
|
||||
|
||||
public function set_inactive() {
|
||||
lz4_check_box.checked = false;
|
||||
trans_combo_box.current-index = 0;
|
||||
self.enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue