Add "Unselect" action

Improve behavior of "hide everything except selection"
Make instruction keyframes automatically add ; on export if missing
Auto trim project name and identifier values
This commit is contained in:
JannisX11 2022-06-25 11:14:23 +02:00
parent 3c4935ab28
commit e197e24f8d
5 changed files with 58 additions and 21 deletions

View File

@ -123,6 +123,7 @@ class Keyframe {
var number = parseFloat( start[0].substr(0, start[0].length-1) ) + amount;
if (number == 0) {
value = value.substr(start[0].length + (value[start[0].length-1] == '+' ? 0 : -1));
value = value.trim();
} else {
value = trimFloatNumber(number) + (start[0].substr(-2, 1) == ' ' ? ' ' : '') + value.substr(start[0].length-1);
}
@ -276,7 +277,8 @@ class Keyframe {
scripts.push(...data_point.script.split('\n'));
}
})
scripts = scripts.filter(script => !!script.replace(/[\n\s;.]+/g, ''))
scripts = scripts.filter(script => !!script.replace(/[\n\s;.]+/g, ''));
scripts = scripts.map(line => line.match(/;\s*$/) ? line : (line+';'));
return scripts.length <= 1 ? scripts[0] : scripts;
} else {
let points = [];
@ -492,6 +494,14 @@ function selectAllKeyframes() {
})
updateKeyframeSelection()
}
function unselectAllKeyframes() {
if (!Animation.selected) return;
Timeline.keyframes.forEach((kf) => {
Timeline.selected.remove(kf)
kf.selected = false;
})
updateKeyframeSelection()
}
function removeSelectedKeyframes() {
Undo.initEdit({keyframes: Timeline.selected})
var i = Timeline.keyframes.length;

View File

@ -752,6 +752,7 @@ const MenuBar = {
'_',
'select_window',
'select_all',
'unselect_all',
'invert_selection'
])
new BarMenu('transform', [

View File

@ -824,6 +824,8 @@ BARS.defineActions(function() {
for (var key in ModelProject.properties) {
ModelProject.properties[key].merge(Project, formResult);
}
Project.name = Project.name.trim();
Project.model_identifier = Project.model_identifier.trim();
if (save) {
Undo.finishEdit('Change project UV settings')

View File

@ -1177,38 +1177,60 @@ BARS.defineActions(function() {
category: 'edit',
condition: () => !Modes.display,
keybind: new Keybind({key: 'a', ctrl: true}),
click: function () {selectAll()}
click() {selectAll()}
})
new Action('unselect_all', {
icon: 'border_clear',
category: 'edit',
condition: () => !Modes.display,
click() {
if (Modes.animate) {
unselectAllKeyframes()
} else if (Prop.active_panel == 'uv') {
this.vue.selected_faces.empty();
UVEditor.displayTools();
} else if (Modes.edit && Mesh.selected.length && Mesh.selected.length === Outliner.selected.length && BarItems.selection_mode.value !== 'object') {
Mesh.selected.forEach(mesh => {
delete Project.selected_vertices[mesh.uuid];
})
updateSelection();
} else if (Modes.edit || Modes.paint) {
unselectAll()
}
Blockbench.dispatchEvent('select_all')
}
})
let enabled = false;
let were_hidden_before = [];
new Action('hide_everything_except_selection', {
icon: 'fa-glasses',
category: 'view',
keybind: new Keybind({key: 'i'}),
condition: {modes: ['edit', 'paint']},
click() {
enabled = !enabled;
let enabled = !Project.only_hidden_elements;
let affected = Project.elements.filter(el => typeof el.visibility == 'boolean' && (!el.selected || were_hidden_before.includes(el.uuid)));
if (Project.only_hidden_elements) {
let affected = Project.elements.filter(el => typeof el.visibility == 'boolean' && Project.only_hidden_elements.includes(el.uuid));
Undo.initEdit({elements: affected})
affected.forEach(el => {
if (enabled) {
if (el.visibility) were_hidden_before.push(el.uuid);
el.visibility = !!el.selected;
} else {
el.visibility = were_hidden_before.includes(el.uuid);
}
el.visibility = true;
})
if (!enabled) were_hidden_before.empty();
delete Project.only_hidden_elements;
} else {
let affected = Project.elements.filter(el => typeof el.visibility == 'boolean' && !el.selected && el.visibility);
Undo.initEdit({elements: affected})
affected.forEach(el => {
el.visibility = false;
})
Project.only_hidden_elements = affected.map(el => el.uuid);
}
Canvas.updateVisibility();
Undo.finishEdit('Toggle visibility on everything except selection');
}
})
Blockbench.on('unselect_project', () => {
enabled = false;
were_hidden_before.empty();
})
})
Interface.definePanels(function() {

View File

@ -1055,7 +1055,9 @@
"action.invert_selection": "Invert Selection",
"action.invert_selection.desc": "Invert the current selection of cubes",
"action.select_all": "Select All",
"action.select_all.desc": "Select all cubes",
"action.select_all.desc": "Select all elements, faces, vertices, or keyframes",
"action.unselect_all": "Unselect All",
"action.unselect_all.desc": "Unselect all elements, faces, vertices, or keyframes",
"action.hide_everything_except_selection": "Hide Everything Except Selection",
"action.hide_everything_except_selection.desc": "Toggle visibility on all elements except the ones that are selected",
"action.collapse_groups": "Collapse Groups",