mirror of
https://github.com/JannisX11/blockbench.git
synced 2025-02-11 16:12:06 +08:00
Avoid keybind conflicts between tools
This commit is contained in:
parent
2b0d0787f2
commit
f119107a16
@ -428,10 +428,8 @@ class Tool extends Action {
|
|||||||
this.allowed_view_modes = data.allowed_view_modes || null;
|
this.allowed_view_modes = data.allowed_view_modes || null;
|
||||||
this.tool_settings = {};
|
this.tool_settings = {};
|
||||||
|
|
||||||
if (this.condition == undefined) {
|
if (this.condition == undefined && this.modes instanceof Array) {
|
||||||
this.condition = function() {
|
this.condition = {modes: this.modes};
|
||||||
return !scope.modes || scope.modes.includes(Modes.id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
this.onCanvasClick = data.onCanvasClick;
|
this.onCanvasClick = data.onCanvasClick;
|
||||||
this.onTextureEditorClick = data.onTextureEditorClick;
|
this.onTextureEditorClick = data.onTextureEditorClick;
|
||||||
@ -440,6 +438,7 @@ class Tool extends Action {
|
|||||||
this.node.onclick = () => {
|
this.node.onclick = () => {
|
||||||
scope.select();
|
scope.select();
|
||||||
}
|
}
|
||||||
|
Tool.all.push(this);
|
||||||
}
|
}
|
||||||
select() {
|
select() {
|
||||||
if (this === Toolbox.selected) return;
|
if (this === Toolbox.selected) return;
|
||||||
@ -495,7 +494,12 @@ class Tool extends Action {
|
|||||||
if (BARS.condition(this.condition, this)) {
|
if (BARS.condition(this.condition, this)) {
|
||||||
this.select()
|
this.select()
|
||||||
return true;
|
return true;
|
||||||
} else if (this.modes) {
|
} else if (this.modes && event instanceof KeyboardEvent == false) {
|
||||||
|
return this.switchModeAndSelect();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
switchModeAndSelect() {
|
||||||
for (var i = 0; i < this.modes.length; i++) {
|
for (var i = 0; i < this.modes.length; i++) {
|
||||||
var mode = Modes.options[this.modes[i]]
|
var mode = Modes.options[this.modes[i]]
|
||||||
if (mode && Condition(mode.condition)) {
|
if (mode && Condition(mode.condition)) {
|
||||||
@ -505,9 +509,13 @@ class Tool extends Action {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
delete() {
|
||||||
|
super.delete();
|
||||||
|
Tool.all.remove(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Tool.all = [];
|
||||||
|
Tool.selected = null;
|
||||||
class Toggle extends Action {
|
class Toggle extends Action {
|
||||||
constructor(id, data) {
|
constructor(id, data) {
|
||||||
super(id, data);
|
super(id, data);
|
||||||
@ -1808,6 +1816,7 @@ const BARS = {
|
|||||||
selectElements: true,
|
selectElements: true,
|
||||||
cursor: 'copy',
|
cursor: 'copy',
|
||||||
modes: ['edit'],
|
modes: ['edit'],
|
||||||
|
condition: {modes: ['edit']},
|
||||||
keybind: new Keybind({key: 'x'}),
|
keybind: new Keybind({key: 'x'}),
|
||||||
onCanvasClick(data) {
|
onCanvasClick(data) {
|
||||||
Vertexsnap.canvasClick(data)
|
Vertexsnap.canvasClick(data)
|
||||||
|
@ -795,6 +795,13 @@ addEventListeners(document, 'keydown mousedown', function(e) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
if (!used && !open_dialog) {
|
||||||
|
for (let tool of Tool.all) {
|
||||||
|
if (tool.keybind && typeof tool.trigger === 'function' && tool.keybind.isTriggered(e)) {
|
||||||
|
if (tool.switchModeAndSelect(e)) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Menu
|
// Menu
|
||||||
if (open_menu) {
|
if (open_menu) {
|
||||||
|
@ -2463,7 +2463,6 @@ BARS.defineActions(function() {
|
|||||||
paintTool: true,
|
paintTool: true,
|
||||||
allowed_view_modes: ['textured'],
|
allowed_view_modes: ['textured'],
|
||||||
modes: ['paint'],
|
modes: ['paint'],
|
||||||
condition: {modes: ['paint']},
|
|
||||||
keybind: new Keybind({key: 'm'}),
|
keybind: new Keybind({key: 'm'}),
|
||||||
side_menu: new Menu('selection_tool', () => {
|
side_menu: new Menu('selection_tool', () => {
|
||||||
let modes = {
|
let modes = {
|
||||||
@ -2521,7 +2520,7 @@ BARS.defineActions(function() {
|
|||||||
paintTool: true,
|
paintTool: true,
|
||||||
allowed_view_modes: ['textured'],
|
allowed_view_modes: ['textured'],
|
||||||
modes: ['paint'],
|
modes: ['paint'],
|
||||||
condition: {modes: ['paint']},
|
keybind: new Keybind({key: 'v'}),
|
||||||
onCanvasClick(data) {
|
onCanvasClick(data) {
|
||||||
if (data && data.element) {
|
if (data && data.element) {
|
||||||
Blockbench.showQuickMessage('message.copy_paste_tool_viewport')
|
Blockbench.showQuickMessage('message.copy_paste_tool_viewport')
|
||||||
|
Loading…
Reference in New Issue
Block a user