From 038b8cd1e6c24ea9be25c9bcfe7e7abbe87847bb Mon Sep 17 00:00:00 2001 From: Vitaly Date: Fri, 22 Sep 2023 23:09:23 +0300 Subject: [PATCH] add a way to go back in ui with gamepad & notification impr --- src/controls.ts | 21 ++++++++++++++++++--- src/menus/notification.js | 2 +- src/utils.ts | 4 +--- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/controls.ts b/src/controls.ts index 7e02b88f..7b7017fa 100644 --- a/src/controls.ts +++ b/src/controls.ts @@ -30,6 +30,10 @@ export const contro = new ControMax({ chat: [['KeyT', 'Enter'], null], command: ['Slash', null], }, + ui: { + back: [null/* 'Escape' */, 'B'], + click: [null, 'A'], + } // waila: { // showLookingBlockRecipe: ['Numpad3'], // showLookingBlockUsages: ['Numpad4'] @@ -117,9 +121,20 @@ subscribe(activeModalStack, () => { } }) +const uiCommand = (command: Command) => { + if (command === 'ui.back') { + hideCurrentModal() + } else if (command === 'ui.click') { + // todo cursor + } +} + const onTriggerOrReleased = (command: Command, pressed: boolean) => { // always allow release! - if (pressed && !isGameActive(true)) return + if (pressed && !isGameActive(true)) { + uiCommand(command) + return + } if (stringStartsWith(command, 'general')) { // handle general commands switch (command) { @@ -308,8 +323,8 @@ addEventListener('mousedown', (e) => { if (e.button === 1) { const block = bot.blockAtCursor(/* 6 */5) if (!block) return - const Item = require('prismarine-item')(bot.version); - const item = new Item(block.type, 1, 0); + const Item = require('prismarine-item')(bot.version) + const item = new Item(block.type, 1, 0) bot.creative.setInventorySlot(bot.inventory.hotbarStart + bot.quickBarSlot, item) bot.updateHeldItem() } diff --git a/src/menus/notification.js b/src/menus/notification.js index ff58ba8d..fb42ade0 100644 --- a/src/menus/notification.js +++ b/src/menus/notification.js @@ -15,7 +15,7 @@ const initialNotification = { export const notification = proxy(initialNotification) export const showNotification = (/** @type {Partial} */newNotification) => { - Object.assign(notification, newNotification, initialNotification) + Object.assign(notification, { show: true, ...newNotification }, initialNotification) } window.notification = notification diff --git a/src/utils.ts b/src/utils.ts index dc9ec6c9..dda422fb 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -38,8 +38,6 @@ export const pointerLock = { } const displayBrowserProblem = () => { notification.show = true - // todo use notification stack - notification.autoHide = true notification.message = navigator['keyboard'] ? 'Browser Limitation: Click on screen, enable Auto Fullscreen or F11' : 'Browser Limitation: Click on screen or use fullscreen in Chrome' } if (!(document.fullscreenElement && navigator['keyboard']) && this.justHitEscape) { @@ -70,7 +68,7 @@ window.getScreenRefreshRate = getScreenRefreshRate /** * Allows to obtain the estimated Hz of the primary monitor in the system. */ -export function getScreenRefreshRate() { +export function getScreenRefreshRate(): Promise { let requestId = null let callbackTriggered = false let resolve