Game-specific settings (#623)

This commit is contained in:
redphx
2025-01-28 11:28:26 +07:00
parent 91c8172564
commit e3f971845f
79 changed files with 2205 additions and 1426 deletions

View File

@@ -3,15 +3,11 @@ import type { SettingsDialog } from "../settings-dialog";
import { MkbMappingPresetsTable } from "@/utils/local-db/mkb-mapping-presets-table";
import { BxSelectElement } from "@/web-components/bx-select";
import { t } from "@/utils/translation";
import { getPref, setPref } from "@/utils/settings-storages/global-settings-storage";
import { PrefKey } from "@/enums/pref-keys";
import { StreamSettings } from "@/utils/stream-settings";
import { getGlobalPref, getStreamPref, setStreamPref } from "@/utils/pref-utils";
import { GlobalPref, StreamPref } from "@/enums/pref-keys";
import { MkbMappingManagerDialog } from "../profile-manger/mkb-mapping-manager-dialog";
import { KeyboardShortcutsManagerDialog } from "../profile-manger/keyboard-shortcuts-manager-dialog";
import { KeyboardShortcutsTable } from "@/utils/local-db/keyboard-shortcuts-table";
import { SettingElement } from "@/utils/setting-element";
import { STORAGE } from "@/utils/global";
import { EmulatedMkbHandler } from "@/modules/mkb/mkb-handler";
import { BxIcon } from "@/utils/bx-icon";
export class MkbExtraSettings extends HTMLElement {
@@ -44,7 +40,7 @@ export class MkbExtraSettings extends HTMLElement {
}));
$container.append(
...(getPref(PrefKey.MKB_ENABLED) ? [
...(getGlobalPref(GlobalPref.MKB_ENABLED) ? [
createSettingRow(
t('virtual-controller'),
CE('div', {
@@ -63,14 +59,20 @@ export class MkbExtraSettings extends HTMLElement {
}),
}),
),
{ multiLines: true },
{
multiLines: true,
onContextMenu: this.boundOnContextMenu,
pref: StreamPref.MKB_P1_MAPPING_PRESET_ID,
},
),
createSettingRow(
t('virtual-controller-slot'),
SettingElement.fromPref(PrefKey.MKB_P1_SLOT, STORAGE.Global, () => {
EmulatedMkbHandler.getInstance()?.resetXcloudGamepads();
}),
this.settingsManager.getElement(StreamPref.MKB_P1_SLOT),
{
onContextMenu: this.boundOnContextMenu,
pref: StreamPref.MKB_P1_SLOT,
},
),
] : []),
@@ -92,13 +94,20 @@ export class MkbExtraSettings extends HTMLElement {
}),
}),
),
{ multiLines: true },
{
multiLines: true,
onContextMenu: this.boundOnContextMenu,
pref: StreamPref.KEYBOARD_SHORTCUTS_IN_GAME_PRESET_ID,
},
),
);
$container.$mappingPresets = $mappingPresets;
$container.$shortcutsPresets = $shortcutsPresets;
this.settingsManager.setElement(StreamPref.KEYBOARD_SHORTCUTS_IN_GAME_PRESET_ID, $shortcutsPresets);
this.settingsManager.setElement(StreamPref.MKB_P1_MAPPING_PRESET_ID, $mappingPresets);
$container.updateLayout();
// Refresh layout when parent dialog is shown
this.onMountedCallbacks.push(() => {
@@ -111,24 +120,20 @@ export class MkbExtraSettings extends HTMLElement {
private static async updateLayout(this: MkbExtraSettings) {
// Render shortcut presets
const mappingPresets = await MkbMappingPresetsTable.getInstance().getPresets();
renderPresetsList(this.$mappingPresets, mappingPresets, getPref(PrefKey.MKB_P1_MAPPING_PRESET_ID));
renderPresetsList(this.$mappingPresets, mappingPresets, getStreamPref(StreamPref.MKB_P1_MAPPING_PRESET_ID));
// Render shortcut presets
const shortcutsPresets = await KeyboardShortcutsTable.getInstance().getPresets();
renderPresetsList(this.$shortcutsPresets, shortcutsPresets, getPref(PrefKey.KEYBOARD_SHORTCUTS_IN_GAME_PRESET_ID), { addOffValue: true });
renderPresetsList(this.$shortcutsPresets, shortcutsPresets, getStreamPref(StreamPref.KEYBOARD_SHORTCUTS_IN_GAME_PRESET_ID), { addOffValue: true });
}
private static async saveMkbSettings(this: MkbExtraSettings) {
const presetId = parseInt(this.$mappingPresets.value);
setPref(PrefKey.MKB_P1_MAPPING_PRESET_ID, presetId);
StreamSettings.refreshMkbSettings();
setStreamPref(StreamPref.MKB_P1_MAPPING_PRESET_ID, presetId, 'ui');
}
private static async saveShortcutsSettings(this: MkbExtraSettings) {
const presetId = parseInt(this.$shortcutsPresets.value);
setPref(PrefKey.KEYBOARD_SHORTCUTS_IN_GAME_PRESET_ID, presetId);
StreamSettings.refreshKeyboardShortcuts();
setStreamPref(StreamPref.KEYBOARD_SHORTCUTS_IN_GAME_PRESET_ID, presetId, 'ui');
}
}