Add image import menu

Add command option in message boxes
Fix changeFormValues in dialog not updating file input visually
This commit is contained in:
JannisX11 2022-08-01 21:38:45 +02:00
parent 280b3777d0
commit 4e26a71d6f
8 changed files with 133 additions and 21 deletions

View File

@ -203,6 +203,26 @@
user-select: text;
}
.dialog_message_box_command {
padding: 6px 12px;
cursor: pointer;
font-size: 1.1em;
background-color: var(--color-back);
margin-top: 6px;
}
.dialog_message_box_command:hover {
background-color: var(--color-accent);
color: var(--color-accent_text);
}
.dialog_message_box_command::after {
float: right;
content: "\f105";
font-family: 'Font Awesome 6 Free';
font-weight: 900;
margin-right: 10px;
pointer-events: none;
}
dialog .form_bar_file .input_wrapper {
position: relative;
flex-grow: 1;

View File

@ -206,14 +206,32 @@ const Blockbench = {
<div class="dialog_close_button" onclick="open_interface.cancel()"><i class="material-icons">clear</i></div>
</dialog>`)
jq_dialog.append('<div class="dialog_content"><div class="dialog_bar markdown" style="height: auto; min-height: 56px; margin-bottom: 16px;">'+
marked(tl(options.message))+
'</div></div>'
)
let content = $('<div class="dialog_content"></div>');
jq_dialog.append(content);
if (options.message) {
content.append('<div class="dialog_bar markdown" style="height: auto; min-height: 56px; margin-bottom: 16px;">'+
marked(tl(options.message))+
'</div></div>')
}
if (options.icon) {
jq_dialog.find('.dialog_bar').prepend($(Blockbench.getIconNode(options.icon)).addClass('message_box_icon'))
}
if (options.commands) {
let list = Interface.createElement('ul');
for (let id in options.commands) {
let command = options.commands[id];
let text = tl(typeof command == 'string' ? command : command.text);
let entry = Interface.createElement('li', {class: 'dialog_message_box_command'}, text)
entry.addEventListener('click', e => {
close(id);
})
list.append(entry);
}
content.append(list);
}
function close(button) {
hideDialog();
setTimeout(function() {

View File

@ -80,9 +80,14 @@ function loadOpenWithBlockbenchFile() {
})
})
if (electron.process.argv.length >= 2) {
var extension = pathToExtension(electron.process.argv.last())
if (Codec.getAllExtensions().includes(extension)) {
Blockbench.read([electron.process.argv.last()], {}, (files) => {
let path = electron.process.argv.last();
var extension = pathToExtension(path);
if (extension == 'png') {
Blockbench.read([path], {readtype: 'image'}, (files) => {
loadImages(files);
})
} else if (Codec.getAllExtensions().includes(extension)) {
Blockbench.read([path], {}, (files) => {
loadModelFile(files[0])
})
}

View File

@ -480,6 +480,7 @@ window.Dialog = class Dialog {
} else {
data.content = value;
}
data.bar.find('input').val(value);
break;
}
}

View File

@ -282,6 +282,7 @@ const skin_dialog = new Dialog({
Format = 0;
}
});
format.setup_dialog = skin_dialog;
BARS.defineActions(function() {

View File

@ -34,20 +34,9 @@ function setupDragHandlers() {
)
Blockbench.addDragHandler(
'texture',
{extensions: ['png', 'tga'], propagate: true, readtype: 'image', condition: () => Project && !Dialog.open},
{extensions: ['png', 'tga'], propagate: true, readtype: 'image', condition: () => !Dialog.open},
function(files, event) {
var texture_li = $(event.target).parents('li.texture')
if (texture_li.length) {
var tex = Texture.all.findInArray('uuid', texture_li.attr('texid'))
if (tex) {
tex.fromFile(files[0])
TickUpdates.selection = true;
return;
}
}
files.forEach(function(f) {
new Texture().fromFile(f).add().fillParticle()
})
loadImages(files, event)
}
)
}
@ -85,6 +74,81 @@ function loadModelFile(file) {
if (success) return;
}
}
function loadImages(files) {
let options = {};
let texture_li = $(event.target).parents('li.texture');
let replace_texture;
if (Project && texture_li.length) {
replace_texture = Texture.all.findInArray('uuid', texture_li.attr('texid'))
if (replace_texture) {
options.replace_texture = 'menu.texture.change';
}
}
if (Project) {
options.texture = 'action.import_texture';
options.background = 'menu.view.background';
}
//options.edit = 'message.load_images.edit_image';
options.minecraft_skin = 'format.skin';
if (Project && !Project.box_uv) {
options.extrude_with_cubes = 'dialog.extrude.title';
}
function doLoadImages(method) {
if (method == 'texture') {
files.forEach(function(f) {
new Texture().fromFile(f).add().fillParticle()
})
} else if (method == 'replace_texture') {
replace_texture.fromFile(files[0])
updateSelection();
} else if (method == 'background') {
let preview = Preview.selected;
let image = isApp ? files[0].path : files[0].content;
if (isApp && preview.background.image && preview.background.image.replace(/\?\w+$/, '') == image) {
image = image + '?' + Math.floor(Math.random() * 1000);
}
preview.background.image = image;
preview.loadBackground();
Settings.saveLocalStorages();
preview.startMovingBackground();
} else if (method == 'edit') {
} else if (method == 'minecraft_skin') {
Formats.skin.setup_dialog.show();
Formats.skin.setup_dialog.setFormValues({
texture: isApp ? files[0].path : files[0].content
})
} else if (method == 'extrude_with_cubes') {
showDialog('image_extruder');
Extruder.drawImage(files[0]);
}
}
let all_methods = Object.keys(options);
if (all_methods.length) {
let title = tl('message.load_images.title');
let message = `${files[0].name}`;
if (files.length > 1) message += ` (${files.length})`;
let img = new Image();
img.src = isApp ? files[0].path : files[0].content;
Blockbench.showMessageBox({
id: 'load_images',
commands: options,
title, message,
icon: img,
buttons: ['dialog.cancel'],
}, result => {
doLoadImages(result);
})
}
}
//Extruder
var Extruder = {
drawImage: function(file) {

File diff suppressed because one or more lines are too long

View File

@ -331,6 +331,9 @@
"message.merged_vertices": "Found and merged %0 vertices in %1 locations",
"message.load_images.title": "Load Images",
"message.load_images.edit_image": "Edit Image",
"message.import_palette.replace_palette": "Replace old palette",
"message.import_palette.threshold": "Merge Threshold",