Lite: disable navigating using gamepad in Settings dialog

This commit is contained in:
redphx 2025-01-16 06:45:12 +07:00
parent d05a68c470
commit 77e0f2d8ba
2 changed files with 23 additions and 19 deletions

View File

@ -1,3 +1,5 @@
import { isFullVersion } from "@macros/build" with { type: "macro" };
import { GamepadKey } from "@/enums/gamepad"; import { GamepadKey } from "@/enums/gamepad";
import { VIRTUAL_GAMEPAD_ID } from "@/modules/mkb/mkb-handler"; import { VIRTUAL_GAMEPAD_ID } from "@/modules/mkb/mkb-handler";
import { BxEvent } from "@/utils/bx-event"; import { BxEvent } from "@/utils/bx-event";
@ -408,9 +410,6 @@ export class NavigationDialogManager {
BxEventBus.Script.emit('dialog.shown', {}); BxEventBus.Script.emit('dialog.shown', {});
// Stop xCloud's navigation polling
window.BX_EXPOSED.disableGamepadPolling = true;
// Lock scroll bar // Lock scroll bar
document.body.classList.add('bx-no-scroll'); document.body.classList.add('bx-no-scroll');
@ -437,11 +436,18 @@ export class NavigationDialogManager {
this.$container.addEventListener('keydown', this); this.$container.addEventListener('keydown', this);
// Start gamepad polling // Start gamepad polling
if (isFullVersion()) {
this.startGamepadPolling(); this.startGamepadPolling();
} }
}
hide() { hide() {
// Stop gamepad polling
if (isFullVersion()) {
this.clearGamepadHoldingInterval(); this.clearGamepadHoldingInterval();
this.stopGamepadPolling();
}
if (!this.isShowing()) { if (!this.isShowing()) {
return; return;
} }
@ -459,9 +465,6 @@ export class NavigationDialogManager {
// Remove event listeners // Remove event listeners
this.$container.removeEventListener('keydown', this); this.$container.removeEventListener('keydown', this);
// Stop gamepad polling
this.stopGamepadPolling();
// Remove current dialog and everything after it from dialogs stack // Remove current dialog and everything after it from dialogs stack
if (this.dialog) { if (this.dialog) {
const dialogIndex = this.dialogsStack.indexOf(this.dialog); const dialogIndex = this.dialogsStack.indexOf(this.dialog);
@ -473,9 +476,6 @@ export class NavigationDialogManager {
// Unmount dialog // Unmount dialog
this.unmountCurrentDialog(); this.unmountCurrentDialog();
// Enable xCloud's navigation polling
window.BX_EXPOSED.disableGamepadPolling = false;
// Show the last dialog in dialogs stack // Show the last dialog in dialogs stack
if (this.dialogsStack.length) { if (this.dialogsStack.length) {
this.dialogsStack[this.dialogsStack.length - 1].show(); this.dialogsStack[this.dialogsStack.length - 1].show();
@ -639,14 +639,18 @@ export class NavigationDialogManager {
} }
private startGamepadPolling() { private startGamepadPolling() {
this.stopGamepadPolling(); // Stop xCloud's navigation polling
window.BX_EXPOSED.disableGamepadPolling = true;
this.stopGamepadPolling();
this.gamepadPollingIntervalId = window.setInterval(this.pollGamepad, NavigationDialogManager.GAMEPAD_POLLING_INTERVAL); this.gamepadPollingIntervalId = window.setInterval(this.pollGamepad, NavigationDialogManager.GAMEPAD_POLLING_INTERVAL);
} }
private stopGamepadPolling() { private stopGamepadPolling() {
this.gamepadLastStates = []; // Enable xCloud's navigation polling
window.BX_EXPOSED.disableGamepadPolling = false;
this.gamepadLastStates = [];
this.gamepadPollingIntervalId && window.clearInterval(this.gamepadPollingIntervalId); this.gamepadPollingIntervalId && window.clearInterval(this.gamepadPollingIntervalId);
this.gamepadPollingIntervalId = null; this.gamepadPollingIntervalId = null;
} }

View File

@ -579,20 +579,20 @@ export class SettingsDialog extends NavigationDialog {
}], }],
}]; }];
private readonly TAB_MKB_ITEMS: (() => Array<SettingTabSection | false>) = () => [ private readonly TAB_MKB_ITEMS: (() => Array<SettingTabSection | false>) = isFullVersion() ? () => [
isFullVersion() && { {
requiredVariants: 'full', requiredVariants: 'full',
group: 'mkb', group: 'mkb',
label: t('mouse-and-keyboard'), label: t('mouse-and-keyboard'),
helpUrl: 'https://better-xcloud.github.io/mouse-and-keyboard/', helpUrl: 'https://better-xcloud.github.io/mouse-and-keyboard/',
items: [ items: [
isFullVersion() && (($parent: HTMLElement) => { ($parent: HTMLElement) => {
$parent.appendChild(MkbExtraSettings.renderSettings.apply(this)); $parent.appendChild(MkbExtraSettings.renderSettings.apply(this));
}) },
], ],
}, },
isFullVersion() && NativeMkbHandler.isAllowed() && { NativeMkbHandler.isAllowed() && {
requiredVariants: 'full', requiredVariants: 'full',
group: 'native-mkb', group: 'native-mkb',
label: t('native-mkb'), label: t('native-mkb'),
@ -607,7 +607,7 @@ export class SettingsDialog extends NavigationDialog {
NativeMkbHandler.getInstance()?.setHorizontalScrollMultiplier(value / 100); NativeMkbHandler.getInstance()?.setHorizontalScrollMultiplier(value / 100);
}, },
}] : [], }] : [],
}]; }] : () => [];
private readonly TAB_STATS_ITEMS: Array<SettingTabSection | false> = [{ private readonly TAB_STATS_ITEMS: Array<SettingTabSection | false> = [{
group: 'stats', group: 'stats',