Add frames option in texture resize dialog

This commit is contained in:
JannisX11 2022-02-06 20:50:21 +01:00
parent fee106b08a
commit 4c5705c2e6
5 changed files with 26 additions and 4 deletions

View File

@ -468,7 +468,7 @@ window.Dialog = class Dialog {
data.bar.find('textarea').val(value);
break;
case 'select':
data.bar.find('select').val(value);
data.bar.find(`select option#${value}`).attr('selected', 'selected');
break;
case 'radio':
data.bar.find('.form_part_radio input#'+value).prop('checked', value);

View File

@ -553,7 +553,7 @@ BARS.defineActions(function() {
new Action('resize_texture', {
icon: 'photo_size_select_large',
category: 'textures',
condition: {modes: ['paint'], method: () => Texture.all.length},
condition: () => Texture.all.length,
click() {
let texture = Texture.getDefault();
texture.resizeDialog();

View File

@ -839,6 +839,7 @@ class Texture {
}
resizeDialog() {
let scope = this;
let updated_to_repeat = false;
let dialog = new Dialog({
id: 'resize_texture',
title: 'action.resize_texture',
@ -850,6 +851,15 @@ class Texture {
value: [this.width, this.height],
min: 1
},
frames: {
label: 'dialog.resize_texture.animation_frames',
type: 'number',
condition: () => Format.animated_textures,
value: this.frameCount || 1,
min: 1,
max: 2048,
step: 1,
},
fill: {label: 'dialog.resize_texture.fill', type: 'select', default: 'transparent', options: {
transparent: 'dialog.resize_texture.fill.transparent',
color: 'dialog.resize_texture.fill.color',
@ -857,6 +867,12 @@ class Texture {
stretch: 'dialog.resize_texture.fill.stretch'
}}
},
onFormChange(formResult) {
if (formResult.frames > (scope.frameCount || 1) && !updated_to_repeat) {
updated_to_repeat = true;
this.setFormValues({fill: 'repeat'});
}
},
onConfirm: function(formResult) {
let old_width = scope.width;
@ -870,6 +886,9 @@ class Texture {
})
if (elements.length) elements_to_change = elements;
}
if (Format.animated_textures && formResult.frames > 1) {
formResult.size[1] *= formResult.frames / (scope.frameCount || 1);
}
Undo.initEdit({
textures: [scope],
@ -912,7 +931,9 @@ class Texture {
delete Painter.current.canvas;
}
scope.keep_size = true;
if (formResult.fill !== 'stretch' && (Format.single_texture || Texture.all.length == 1)) {
if (formResult.fill === 'repeat' && Format.animated_textures && formResult.size[0] < formResult.size[1]) {
// Animated
} else if (formResult.fill !== 'stretch' && (Format.single_texture || Texture.all.length == 1)) {
Undo.current_save.uv_mode = {
box_uv: Project.box_uv,
width: Project.texture_width,

File diff suppressed because one or more lines are too long

View File

@ -320,6 +320,7 @@
"dialog.texture.namespace": "Namespace",
"dialog.texture.folder": "Folder",
"dialog.resize_texture.animation_frames": "Animation Frames",
"dialog.resize_texture.fill": "Fill with",
"dialog.resize_texture.fill.transparent": "Transparent",
"dialog.resize_texture.fill.color": "Color",