From 01c1f02eee482cbedf0f3480ce56b5e626cb439b Mon Sep 17 00:00:00 2001 From: Caio Raphael Date: Sun, 14 Jul 2024 12:57:44 -0300 Subject: [PATCH 1/7] [AWSD Controls] Option to only work when holding RightMouse --- plugins/wasd_controls.js | 106 ++++++++++++++++++++++++--------------- 1 file changed, 66 insertions(+), 40 deletions(-) diff --git a/plugins/wasd_controls.js b/plugins/wasd_controls.js index 0604ab4c..c96ee046 100644 --- a/plugins/wasd_controls.js +++ b/plugins/wasd_controls.js @@ -3,6 +3,7 @@ let deletables = []; let old_animate; +let rightMouseDown = false; BBPlugin.register('wasd_controls', { title: 'WASD Controls', @@ -15,41 +16,41 @@ BBPlugin.register('wasd_controls', { variant: 'both', onload() { let navigate_forward = new KeybindItem('navigate_forward', { - name: 'Move Forward', - icon: 'arrow_upward', - category: 'navigate', + name: 'Move Forward', + icon: 'arrow_upward', + category: 'navigate', keybind: new Keybind({key: 'w', ctrl: null}) - }) + }); let navigate_backward = new KeybindItem('navigate_backward', { - name: 'Move Backward', - icon: 'arrow_upward', - category: 'navigate', + name: 'Move Backward', + icon: 'arrow_upward', + category: 'navigate', keybind: new Keybind({key: 's', ctrl: null}) - }) + }); let navigate_left = new KeybindItem('navigate_left', { - name: 'Move Left', - icon: 'arrow_upward', - category: 'navigate', + name: 'Move Left', + icon: 'arrow_upward', + category: 'navigate', keybind: new Keybind({key: 'a', ctrl: null}) - }) + }); let navigate_right = new KeybindItem('navigate_right', { - name: 'Move Right', - icon: 'arrow_upward', - category: 'navigate', + name: 'Move Right', + icon: 'arrow_upward', + category: 'navigate', keybind: new Keybind({key: 'd', ctrl: null}) - }) + }); let navigate_down = new KeybindItem('navigate_down', { - name: 'Move Down', - icon: 'arrow_upward', - category: 'navigate', + name: 'Move Down', + icon: 'arrow_upward', + category: 'navigate', keybind: new Keybind({key: 16, ctrl: null}) - }) + }); let navigate_up = new KeybindItem('navigate_up', { - name: 'Move Up', - icon: 'arrow_upward', - category: 'navigate', + name: 'Move Up', + icon: 'arrow_upward', + category: 'navigate', keybind: new Keybind({key: 32, ctrl: null}) - }) + }); let navigation_keybinds = [navigate_forward, navigate_backward, navigate_left, navigate_right, navigate_down, navigate_up]; deletables.push(...navigation_keybinds); @@ -62,20 +63,26 @@ BBPlugin.register('wasd_controls', { } let wasd_toggle = new Toggle('wasd_movement', { - name: 'WASD Movement', - icon: 'sports_esports', - category: 'navigate', + name: 'WASD Movement', + icon: 'sports_esports', + category: 'navigate', value: false, onChange(value) { setupWASDMovement(Preview.selected, value ? 1 : 16); Preview.all.forEach(preview => { preview.controls.enableZoom = !value; - }) + }); } - }) + }); + function isWASDMovementEnabled() { - return Preview.selected && BarItems.wasd_movement && BarItems.wasd_movement.value; + if (settings.requires_hold_right_mouse.value) { + return Preview.selected && BarItems.wasd_movement && BarItems.wasd_movement.value && rightMouseDown; + } else { + return Preview.selected && BarItems.wasd_movement && BarItems.wasd_movement.value + } } + deletables.push(wasd_toggle); MenuBar.menus.view.addAction('_'); MenuBar.menus.view.addAction(wasd_toggle); @@ -86,14 +93,21 @@ BBPlugin.register('wasd_controls', { type: 'number', value: 100, min: 1 - })) + })); deletables.push(new Setting('wasd_y_level', { name: 'WASD Navigation at Y Level', description: 'Navigate using WASD at consistent Y level rather than on camera plane', category: 'preview', value: true - })) + })); + + deletables.push(new Setting('requires_hold_right_mouse', { + name: 'Only works when holding the right mouse button', + description: 'The WASD Controls neeeds to be enabled for this to work.', + category: 'preview', + value: true + })); let pressed_keys = []; Blockbench.on('press_key', data => { @@ -104,13 +118,25 @@ BBPlugin.register('wasd_controls', { data.capture(); } } - }) + }); + document.addEventListener('keyup', event => { pressed_keys.remove(event.which); - }) + }); - function doWASDMovement() { + document.addEventListener('mousedown', event => { + if (event.button === 2) { // Right mouse button + rightMouseDown = true; + } + }); + + document.addEventListener('mouseup', event => { + if (event.button === 2) { // Right mouse button + rightMouseDown = false; + } + }); + function doWASDMovement() { let movement = new THREE.Vector3(0, 0, 0); let uses_wasd_movement = false; function add(x, y, z) { @@ -149,21 +175,21 @@ BBPlugin.register('wasd_controls', { if (isWASDMovementEnabled() && pressed_keys.length) { doWASDMovement(); } - } + }; }, oninstall() { - MenuBar.menus.view.highlight(BarItems.wasd_movement) + MenuBar.menus.view.highlight(BarItems.wasd_movement); }, onunload() { deletables.forEach(action => { action.delete(); - }) + }); setupWASDMovement(Preview.selected, 16); Preview.all.forEach(preview => { preview.controls.enableZoom = true; - }) + }); window.animate = old_animate; } }); -})() +})(); From ff4129179ca03a3863560f0cfe207d861bfb11ec Mon Sep 17 00:00:00 2001 From: Caio Raphael Date: Sun, 14 Jul 2024 12:59:41 -0300 Subject: [PATCH 2/7] [WASD Controls] Update the metadata I forgot, oops. --- plugins/wasd_controls.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/wasd_controls.js b/plugins/wasd_controls.js index c96ee046..f50b7f77 100644 --- a/plugins/wasd_controls.js +++ b/plugins/wasd_controls.js @@ -11,7 +11,7 @@ BBPlugin.register('wasd_controls', { author: 'JannisX11', description: 'Adds a WASD controlled viewport navigation mode', about: 'The WASD mode can be enabled from the View menu.\nThe keys can be remapped in the keybindings menu.\nThe sensitivity can be changed in the settings under Preview, along with the movement plane.\nHold Control to move faster.', - version: '1.1.0', + version: '1.2.0', min_version: '4.3.0', variant: 'both', onload() { From ead8d22fdf8cc23df3d8f60f3c8291108ecd11a5 Mon Sep 17 00:00:00 2001 From: Caio Raphael Date: Sun, 14 Jul 2024 13:07:14 -0300 Subject: [PATCH 3/7] [WASD Controls] typo ;/ --- plugins/wasd_controls.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/wasd_controls.js b/plugins/wasd_controls.js index f50b7f77..162b9bce 100644 --- a/plugins/wasd_controls.js +++ b/plugins/wasd_controls.js @@ -104,7 +104,7 @@ BBPlugin.register('wasd_controls', { deletables.push(new Setting('requires_hold_right_mouse', { name: 'Only works when holding the right mouse button', - description: 'The WASD Controls neeeds to be enabled for this to work.', + description: 'The WASD Controls needs to be enabled for this to work.', category: 'preview', value: true })); From de9d1a54cda8af8450aea7a1a35f70a5cd2f7e0b Mon Sep 17 00:00:00 2001 From: Caio Raphael Date: Mon, 15 Jul 2024 16:16:38 -0300 Subject: [PATCH 4/7] 3 changes requested -> metadata in plugin.json -> improved name for 'requires_hold_right_mouse' setting -> set the 'requires_hold_right_mouse' to be false by default --- plugins.json | 2 +- plugins/wasd_controls.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins.json b/plugins.json index 9b9c554b..a2739c94 100644 --- a/plugins.json +++ b/plugins.json @@ -631,7 +631,7 @@ "author": "JannisX11", "description": "Adds a WASD controlled viewport navigation mode", "about": "The WASD mode can be enabled from the View menu.\nThe keys can be remapped in the keybindings menu.\nThe sensitivity can be changed in the settings under Preview, along with the movement plane.\nHold Control to move faster.", - "version": "1.1.0", + "version": "1.2.0", "min_version": "4.3.0", "variant": "both" }, diff --git a/plugins/wasd_controls.js b/plugins/wasd_controls.js index 162b9bce..944a6e83 100644 --- a/plugins/wasd_controls.js +++ b/plugins/wasd_controls.js @@ -76,7 +76,7 @@ BBPlugin.register('wasd_controls', { }); function isWASDMovementEnabled() { - if (settings.requires_hold_right_mouse.value) { + if (settings.wasd_requires_hold_right_mouse.value) { return Preview.selected && BarItems.wasd_movement && BarItems.wasd_movement.value && rightMouseDown; } else { return Preview.selected && BarItems.wasd_movement && BarItems.wasd_movement.value @@ -102,11 +102,11 @@ BBPlugin.register('wasd_controls', { value: true })); - deletables.push(new Setting('requires_hold_right_mouse', { + deletables.push(new Setting('wasd_requires_hold_right_mouse', { name: 'Only works when holding the right mouse button', description: 'The WASD Controls needs to be enabled for this to work.', category: 'preview', - value: true + value: false })); let pressed_keys = []; From a83c79ec2737a908aa170f2314418966636d033d Mon Sep 17 00:00:00 2001 From: Caio Raphael Date: Tue, 16 Jul 2024 14:58:41 -0300 Subject: [PATCH 5/7] zoom fix; new buttons to move faster and slower; name fix; --- plugins/wasd_controls.js | 80 ++++++++++++++++++++++++++++++---------- 1 file changed, 60 insertions(+), 20 deletions(-) diff --git a/plugins/wasd_controls.js b/plugins/wasd_controls.js index 944a6e83..0ac339f4 100644 --- a/plugins/wasd_controls.js +++ b/plugins/wasd_controls.js @@ -1,7 +1,5 @@ (function() { - let deletables = []; - let old_animate; let rightMouseDown = false; @@ -23,43 +21,56 @@ BBPlugin.register('wasd_controls', { }); let navigate_backward = new KeybindItem('navigate_backward', { name: 'Move Backward', - icon: 'arrow_upward', + icon: 'arrow_downward', category: 'navigate', keybind: new Keybind({key: 's', ctrl: null}) }); let navigate_left = new KeybindItem('navigate_left', { name: 'Move Left', - icon: 'arrow_upward', + icon: 'arrow_back', category: 'navigate', keybind: new Keybind({key: 'a', ctrl: null}) }); let navigate_right = new KeybindItem('navigate_right', { name: 'Move Right', - icon: 'arrow_upward', + icon: 'arrow_forward', category: 'navigate', keybind: new Keybind({key: 'd', ctrl: null}) }); let navigate_down = new KeybindItem('navigate_down', { name: 'Move Down', - icon: 'arrow_upward', + icon: 'expand_more', category: 'navigate', keybind: new Keybind({key: 16, ctrl: null}) }); let navigate_up = new KeybindItem('navigate_up', { name: 'Move Up', - icon: 'arrow_upward', + icon: 'expand_less', category: 'navigate', keybind: new Keybind({key: 32, ctrl: null}) }); - let navigation_keybinds = [navigate_forward, navigate_backward, navigate_left, navigate_right, navigate_down, navigate_up]; + + let navigate_faster = new KeybindItem('navigate_faster', { + name: 'Move Faster', + icon: 'expand_less', + category: 'navigate', + keybind: new Keybind({key: 16, ctrl: null}) + }); + let navigate_slower = new KeybindItem('navigate_slower', { + name: 'Move Slower', + icon: 'expand_less', + category: 'navigate', + keybind: new Keybind({key: 18, ctrl: null}) + }); + + + let navigation_keybinds = [navigate_forward, navigate_backward, navigate_left, navigate_right, navigate_down, navigate_up, navigate_faster, navigate_slower]; deletables.push(...navigation_keybinds); function setupWASDMovement(preview, length = 1) { let pos = new THREE.Vector3().copy(preview.camera.position); pos.add(preview.camera.getWorldDirection(new THREE.Vector3()).normalize().multiplyScalar(length)); preview.controls.target.copy(pos); - - preview.controls.enable_zoom = false; } let wasd_toggle = new Toggle('wasd_movement', { @@ -69,9 +80,6 @@ BBPlugin.register('wasd_controls', { value: false, onChange(value) { setupWASDMovement(Preview.selected, value ? 1 : 16); - Preview.all.forEach(preview => { - preview.controls.enableZoom = !value; - }); } }); @@ -87,23 +95,41 @@ BBPlugin.register('wasd_controls', { MenuBar.menus.view.addAction('_'); MenuBar.menus.view.addAction(wasd_toggle); - deletables.push(new Setting('wasd_sensitivity', { - name: 'WASD Sensitivity', + deletables.push(new Setting('base_speed', { + name: 'WASD Controls: Base Speed', category: 'preview', type: 'number', - value: 100, + value: 50, min: 1 })); + deletables.push(new Setting('move_faster_mult', { + name: 'WASD Controls: Move Faster Multiplier', + category: 'preview', + type: 'number', + value: 2, + max: 10, + min: 1 + })); + + deletables.push(new Setting('move_slower_mult', { + name: 'WASD Controls: Move Slower Multiplier', + category: 'preview', + type: 'number', + value: 0.5, + max: 1, + min: 0.1 + })); + deletables.push(new Setting('wasd_y_level', { - name: 'WASD Navigation at Y Level', + name: 'WASD Controls: Navigate at Y Level', description: 'Navigate using WASD at consistent Y level rather than on camera plane', category: 'preview', value: true })); deletables.push(new Setting('wasd_requires_hold_right_mouse', { - name: 'Only works when holding the right mouse button', + name: 'WASD Controls: Navigation only works when holding the right mouse button', description: 'The WASD Controls needs to be enabled for this to work.', category: 'preview', value: false @@ -138,6 +164,7 @@ BBPlugin.register('wasd_controls', { function doWASDMovement() { let movement = new THREE.Vector3(0, 0, 0); + let uses_wasd_movement = false; function add(x, y, z) { movement.x += x; @@ -145,6 +172,7 @@ BBPlugin.register('wasd_controls', { movement.z += z; uses_wasd_movement = true; } + if (pressed_keys.includes(navigate_forward.keybind.key)) add(0, 0, -1); if (pressed_keys.includes(navigate_backward.keybind.key)) add(0, 0, 1); if (pressed_keys.includes(navigate_left.keybind.key)) add(-1, 0, 0); @@ -152,8 +180,14 @@ BBPlugin.register('wasd_controls', { if (pressed_keys.includes(navigate_down.keybind.key)) add(0, -1, 0); if (pressed_keys.includes(navigate_up.keybind.key)) add(0, 1, 0); + if (uses_wasd_movement) { setupWASDMovement(Preview.selected); + + let speedMultiplier = 1.0; // Default speed + + if (pressed_keys.includes(navigate_faster.keybind.key)) speedMultiplier *= settings.move_faster_mult.value; + else if (pressed_keys.includes(navigate_slower.keybind.key)) speedMultiplier *= settings.move_slower_mult.value; if (settings.wasd_y_level.value) { let vec = Preview.selected.controls.object.getWorldDirection(new THREE.Vector3()).normalize(); @@ -162,7 +196,9 @@ BBPlugin.register('wasd_controls', { } else { movement.applyEuler(Preview.selected.controls.object.rotation); } - movement.multiplyScalar(Settings.get('wasd_sensitivity') * (Pressing.ctrl || Pressing.overrides.ctrl ? 2.4 : 1) / 100); + + console.log(movement, Settings.get('base_speed'), speedMultiplier, Settings.get('base_speed') * speedMultiplier / 100) + movement.multiplyScalar(Settings.get('base_speed') * speedMultiplier / 100); Preview.selected.camera.position.add(movement); Preview.selected.controls.target.add(movement); } @@ -175,6 +211,11 @@ BBPlugin.register('wasd_controls', { if (isWASDMovementEnabled() && pressed_keys.length) { doWASDMovement(); } + + // Ensure zoom is disabled when moving + Preview.all.forEach(preview => { + preview.controls.enableZoom = !isWASDMovementEnabled(); + }); }; }, oninstall() { @@ -191,5 +232,4 @@ BBPlugin.register('wasd_controls', { window.animate = old_animate; } }); - })(); From 57ca628f31d719a7044a737490f8b2dd7fb3d845 Mon Sep 17 00:00:00 2001 From: Caio Raphael Date: Thu, 18 Jul 2024 01:21:51 -0300 Subject: [PATCH 6/7] properly saves the state of the tool 'WASD Toggle' when restarting the app I don't know if the best idea, but I created a setting to save the tool state. --- plugins/wasd_controls.js | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/plugins/wasd_controls.js b/plugins/wasd_controls.js index 0ac339f4..87ce65f7 100644 --- a/plugins/wasd_controls.js +++ b/plugins/wasd_controls.js @@ -73,16 +73,36 @@ BBPlugin.register('wasd_controls', { preview.controls.target.copy(pos); } + deletables.push(new Setting('wasd_enabled', { + name: 'WASD Controls: Enabled', + description: '_', + category: 'preview', + value: false, + onChange(value) { + BarItems.wasd_movement.value = value + BarItems.wasd_movement.updateEnabledState(); + setupWASDMovement(Preview.selected, value ? 1 : 16); + } + })); + let wasd_toggle = new Toggle('wasd_movement', { name: 'WASD Movement', icon: 'sports_esports', category: 'navigate', value: false, onChange(value) { + settings.wasd_enabled.value = value + Settings.saveLocalStorages(); setupWASDMovement(Preview.selected, value ? 1 : 16); } }); + deletables.push(wasd_toggle); + MenuBar.menus.view.addAction('_'); + MenuBar.menus.view.addAction(wasd_toggle); + BarItems.wasd_movement.value = settings.wasd_enabled.value + BarItems.wasd_movement.updateEnabledState(); + function isWASDMovementEnabled() { if (settings.wasd_requires_hold_right_mouse.value) { return Preview.selected && BarItems.wasd_movement && BarItems.wasd_movement.value && rightMouseDown; @@ -91,12 +111,9 @@ BBPlugin.register('wasd_controls', { } } - deletables.push(wasd_toggle); - MenuBar.menus.view.addAction('_'); - MenuBar.menus.view.addAction(wasd_toggle); - deletables.push(new Setting('base_speed', { name: 'WASD Controls: Base Speed', + description: '-', category: 'preview', type: 'number', value: 50, @@ -105,6 +122,7 @@ BBPlugin.register('wasd_controls', { deletables.push(new Setting('move_faster_mult', { name: 'WASD Controls: Move Faster Multiplier', + description: '-', category: 'preview', type: 'number', value: 2, @@ -114,6 +132,7 @@ BBPlugin.register('wasd_controls', { deletables.push(new Setting('move_slower_mult', { name: 'WASD Controls: Move Slower Multiplier', + description: '-', category: 'preview', type: 'number', value: 0.5, @@ -197,7 +216,6 @@ BBPlugin.register('wasd_controls', { movement.applyEuler(Preview.selected.controls.object.rotation); } - console.log(movement, Settings.get('base_speed'), speedMultiplier, Settings.get('base_speed') * speedMultiplier / 100) movement.multiplyScalar(Settings.get('base_speed') * speedMultiplier / 100); Preview.selected.camera.position.add(movement); Preview.selected.controls.target.add(movement); From b4bcb1ecc2ff3b16b416a533fbfd339c9531c769 Mon Sep 17 00:00:00 2001 From: JannisX11 Date: Sat, 24 Aug 2024 14:44:29 +0200 Subject: [PATCH 7/7] WASD Controls: Small fixes --- plugins.json | 2 +- plugins/wasd_controls.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins.json b/plugins.json index a2739c94..306e27e3 100644 --- a/plugins.json +++ b/plugins.json @@ -628,7 +628,7 @@ "wasd_controls": { "title": "WASD Controls", "icon": "sports_esports", - "author": "JannisX11", + "author": "JannisX11, caioraphael1", "description": "Adds a WASD controlled viewport navigation mode", "about": "The WASD mode can be enabled from the View menu.\nThe keys can be remapped in the keybindings menu.\nThe sensitivity can be changed in the settings under Preview, along with the movement plane.\nHold Control to move faster.", "version": "1.2.0", diff --git a/plugins/wasd_controls.js b/plugins/wasd_controls.js index 87ce65f7..8e5e7f05 100644 --- a/plugins/wasd_controls.js +++ b/plugins/wasd_controls.js @@ -6,7 +6,7 @@ let rightMouseDown = false; BBPlugin.register('wasd_controls', { title: 'WASD Controls', icon: 'sports_esports', - author: 'JannisX11', + author: 'JannisX11, caioraphael1', description: 'Adds a WASD controlled viewport navigation mode', about: 'The WASD mode can be enabled from the View menu.\nThe keys can be remapped in the keybindings menu.\nThe sensitivity can be changed in the settings under Preview, along with the movement plane.\nHold Control to move faster.', version: '1.2.0', @@ -54,7 +54,7 @@ BBPlugin.register('wasd_controls', { name: 'Move Faster', icon: 'expand_less', category: 'navigate', - keybind: new Keybind({key: 16, ctrl: null}) + keybind: new Keybind({key: 17, ctrl: null}) }); let navigate_slower = new KeybindItem('navigate_slower', { name: 'Move Slower',