From 13e0d08571e2598aeb4c5660dc4f5e46b0b57c06 Mon Sep 17 00:00:00 2001 From: JannisX11 Date: Wed, 28 Aug 2024 19:40:03 +0200 Subject: [PATCH] Improve automatic animation loading --- css/dialogs.css | 12 ++++++++++++ js/animations/animation_mode.js | 28 ++++++++++++++++++++++------ lang/en.json | 1 + 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/css/dialogs.css b/css/dialogs.css index 7eab5ac6..d1811ac0 100644 --- a/css/dialogs.css +++ b/css/dialogs.css @@ -170,6 +170,9 @@ .dialog_bar > .molang_input { width: calc(100% - var(--max_label_width)); } + .dialog_bar.form_bar.small_text { + word-break: break-word; + } /*.dialog_bar::after { content: ""; clear: both; @@ -2079,6 +2082,15 @@ right: 0; background: var(--color-back); } +/* Animation import */ + dialog#animation_import .form_bar__path { + padding: 2px; + color: var(--color-subtle_text); + overflow-x: auto; + white-space: nowrap; + text-align: right; + direction: rtl; + } /* Texture Edit */ div.texture_adjust_previews { diff --git a/js/animations/animation_mode.js b/js/animations/animation_mode.js index b6be8d61..5efff5aa 100644 --- a/js/animations/animation_mode.js +++ b/js/animations/animation_mode.js @@ -26,7 +26,7 @@ const Animator = { if (paths.length) { Blockbench.read(paths, {}, files => { files.forEach(file => { - Animator.importFile(file); + Animator.importFile(file, true); }) }) } @@ -689,8 +689,11 @@ const Animator = { animation_controllers: controllers } }, - importFile(file) { + importFile(file, auto_loaded) { let form = {}; + if (auto_loaded && file.path) { + form['_path'] = {type: 'info', text: file.path}; + } let json = autoParseJSON(file.content) let keys = []; let is_controller = !!json.animation_controllers; @@ -707,7 +710,7 @@ const Animator = { } if (is_already_loaded) continue; } - form[key.hashCode()] = {label: key, type: 'checkbox', value: true, nocolon: true}; + form['anim' + key.hashCode()] = {label: key, type: 'checkbox', value: true, nocolon: true}; keys.push(key); } file.json = json; @@ -721,15 +724,21 @@ const Animator = { } else { return new Promise(resolve => { + let buttons = ['dialog.ok', 'dialog.ignore']; + if (auto_loaded && Project?.memory_animation_files_to_load?.length > 1) { + buttons.push('dialog.ignore_all'); + } let dialog = new Dialog({ id: 'animation_import', title: 'dialog.animation_import.title', form, + buttons, + cancelIndex: 1, onConfirm(form_result) { this.hide(); let names = []; for (var key of keys) { - if (form_result[key.hashCode()]) { + if (form_result['anim' + key.hashCode()]) { names.push(key); } } @@ -738,7 +747,14 @@ const Animator = { Undo.finishEdit('Import animations', {animations: new_animations}) resolve(); }, - onCancel() { + onCancel(index) { + Project.memory_animation_files_to_load.remove(file.path); + resolve(); + }, + onButton(index) { + if (auto_loaded && index == 2) { + Project.memory_animation_files_to_load.empty(); + } resolve(); } }); @@ -747,7 +763,7 @@ const Animator = { buttons: ['generic.select_all', 'generic.select_none'], click(index) { let values = {}; - keys.forEach(key => values[key.hashCode()] = (index == 0)); + keys.forEach(key => values['anim' + key.hashCode()] = (index == 0)); dialog.setFormValues(values); } } diff --git a/lang/en.json b/lang/en.json index 889ed1eb..f3aa205a 100644 --- a/lang/en.json +++ b/lang/en.json @@ -12,6 +12,7 @@ "dialog.discard": "Discard", "dialog.continue": "Continue", "dialog.ignore": "Ignore", + "dialog.ignore_all": "Ignore All", "dialog.dontshowagain": "Don't Show Again", "dialog.copy_to_clipboard": "Copy to clipboard", "dialog.open_url": "Open URL",