From 29eedee3ec4ab177a37c31ef5ba86960accd5f6a Mon Sep 17 00:00:00 2001 From: Sergey Stepanov Date: Fri, 15 Mar 2024 14:38:30 +0300 Subject: [PATCH] Fix keybindings for options --- web/index.html | 8 ++++---- web/js/controller.js | 6 +----- web/js/event/event.js | 1 - web/js/gui/gui.js | 3 ++- web/js/settings/settings.js | 31 +++++++++++++++++++------------ 5 files changed, 26 insertions(+), 23 deletions(-) diff --git a/web/index.html b/web/index.html index 068279c6a..8ca2df5f4 100644 --- a/web/index.html +++ b/web/index.html @@ -104,12 +104,12 @@ - + - + - + @@ -122,7 +122,7 @@ - + diff --git a/web/js/controller.js b/web/js/controller.js index e85733a07..3b7d7dc5b 100644 --- a/web/js/controller.js +++ b/web/js/controller.js @@ -303,8 +303,7 @@ name: 'settings', keyRelease: key => { if (key === KEY.SETTINGS) { - const isSettingsOpened = settings.ui.toggle(); - if (!isSettingsOpened) setState(lastState); + !settings.ui.toggle() && setState(lastState) } }, menuReady: showMenuScreen @@ -452,9 +451,6 @@ event.sub(KEY_PRESSED, onKeyPress); event.sub(KEY_RELEASED, onKeyRelease); event.sub(SETTINGS_CHANGED, () => message.show('Settings have been updated')); - event.sub(SETTINGS_CLOSED, () => { - state.keyRelease(KEY.SETTINGS); - }); event.sub(AXIS_CHANGED, onAxisChanged); event.sub(CONTROLLER_UPDATED, data => webrtc.input(data)); // recording diff --git a/web/js/event/event.js b/web/js/event/event.js index 3c412d202..301e731b6 100644 --- a/web/js/event/event.js +++ b/web/js/event/event.js @@ -97,7 +97,6 @@ const STATS_TOGGLE = 'statsToggle'; const HELP_OVERLAY_TOGGLED = 'helpOverlayToggled'; const SETTINGS_CHANGED = 'settingsChanged'; -const SETTINGS_CLOSED = 'settingsClosed'; const RECORDING_TOGGLED = 'recordingToggle' const RECORDING_STATUS_CHANGED = 'recordingStatusChanged' diff --git a/web/js/gui/gui.js b/web/js/gui/gui.js index b58ca0a3b..95b4ee13a 100644 --- a/web/js/gui/gui.js +++ b/web/js/gui/gui.js @@ -131,7 +131,7 @@ const gui = (() => { _title.innerText = state.loading ? `${state.title}...` : state.title; } - function toggle(show) { + function toggle(show = true) { state.shown = show; // hack not transparent jpeg corners :_; @@ -142,6 +142,7 @@ const gui = (() => { onToggle && onToggle(state.shown, _root) state.shown ? gui.show(_root) : gui.hide(_root) + return state.shown; } return { diff --git a/web/js/settings/settings.js b/web/js/settings/settings.js index 09e1cb7f0..5fed80af1 100644 --- a/web/js/settings/settings.js +++ b/web/js/settings/settings.js @@ -244,6 +244,13 @@ const settings = (() => { provider.remove(key, subKey); } + + const _render = () => { + _renderer.data = panel.contentEl; + _renderer.render() + } + + const panel = gui.panel(document.getElementById('settings'), '> OPTIONS', 'settings', null, [ {caption: 'Export', handler: () => _export(), title: 'Save',}, {caption: 'Import', handler: () => _fileReader.read(onFileLoad), title: 'Load',}, @@ -259,25 +266,25 @@ const settings = (() => { }, {} ], - (state) => { - if (state) return; + (show) => { + if (show) { + _render(); + return; + } - event.pub(SETTINGS_CLOSED); // to make sure it's disabled, but it's a tad verbose event.pub(KEYBOARD_TOGGLE_FILTER_MODE, {mode: true}); }) panel.toggle(false); - const _render = () => { - _renderer.data = panel.contentEl; - _renderer.render() - } - - const toggle = () => { - panel.toggle(true); - _render() - } + const toggle = (() => { + let x = false; + return () => { + x = !x; + panel.toggle(x); + } + })(); function _getType(value) { if (value === undefined) return option.undefined