Rewrite new image project dialog

Fix #2142 stretched image size
Fix missing image when canceling dialog
Fix "toggle all grids" icon
This commit is contained in:
JannisX11 2023-12-06 18:06:29 +01:00
parent d5bf608e69
commit ed85a4a67a
4 changed files with 52 additions and 16 deletions

View File

@ -588,7 +588,7 @@ window.Dialog = class Dialog {
}
return form_result;
}
setFormValues(values) {
setFormValues(values, update = true) {
for (let form_id in this.form) {
let data = this.form[form_id];
if (values[form_id] != undefined && typeof data == 'object' && data.bar) {
@ -642,7 +642,7 @@ window.Dialog = class Dialog {
}
}
}
this.updateFormValues();
if (update) this.updateFormValues();
}
getFormResult() {
let result = {}

View File

@ -126,16 +126,50 @@ new ModelFormat('image', {
]
},
new() {
if (newProject(this)) {
TextureGenerator.addBitmapDialog(() => {
setTimeout(() => {
Undo.history.empty();
Undo.index = 0;
UVEditor.vue.centerView();
}, 1);
});
return true;
}
newProject(this);
let callback = () => {
setTimeout(() => {
Undo.history.empty();
Undo.index = 0;
UVEditor.vue.centerView();
}, 1);
};
let size_presets = {
'': 'Unset',
'16x16': '16 x 16',
'32x32': '32 x 32',
'64x64': '64 x 64',
'128x128': '128 x 128',
'256x256': '256 x 256',
'512x512': '512 x 512',
'1920x1080': '1920 x 1080',
};
let previous_size_preset = '';
let dialog = new Dialog({
id: 'add_bitmap',
title: tl('action.create_texture'),
buttons: ['dialog.confirm'],
form: {
name: {label: 'generic.name', value: 'texture'},
section2: "_",
size_preset:{label: 'dialog.create_texture.resolution', type: 'select', options: size_presets},
resolution: {label: 'dialog.create_texture.resolution', type: 'vector', dimensions: 2, value: [16, 16], min: 1, max: 2048},
color: {label: 'data.color', type: 'color', colorpicker: TextureGenerator.background_color, toggle_enabled: true, toggle_default: false},
},
onFormChange(result) {
console.log(result)
if (result.size_preset && result.size_preset != previous_size_preset) {
let size = result.size_preset.split('x').map(v => parseInt(v));
dialog.setFormValues({resolution: size}, false);
}
previous_size_preset = result.size_preset;
},
onConfirm: function(results) {
results.type = 'blank';
TextureGenerator.addBitmap(results, callback);
}
}).show();
},
onActivation() {
Interface.preview.classList.add('image_mode');

View File

@ -2085,7 +2085,7 @@ BARS.defineActions(function() {
new Toggle('toggle_all_grids', {
name: tl('settings.grids'),
description: tl('settings.grids.desc'),
icon: 'grid',
icon: 'grid_on',
category: 'view',
linked_setting: 'grids',
condition: () => !Modes.paint

View File

@ -145,7 +145,7 @@ const TextureGenerator = {
TextureGenerator.generateColorMapTemplate(options, makeTexture);
} else {
Undo.initEdit({textures: [], selected_texture: true})
TextureGenerator.generateBlank(options.resolution[1], options.resolution[0], options.color, makeTexture)
TextureGenerator.generateBlank(options.resolution[1], options.resolution[0], options.color, makeTexture);
}
},
generateBlank(height, width, color, cb) {
@ -158,8 +158,10 @@ const TextureGenerator = {
ctx.fillStyle = new tinycolor(color).toRgbString();
ctx.fillRect(0, 0, width, height);
}
cb(canvas.toDataURL())
let texture = cb(canvas.toDataURL());
texture.uv_width = width;
texture.uv_height = height;
return texture;
},
//constructors
boxUVCubeTemplate: function(obj, min_size) {