Added pointer capture menu item

This commit is contained in:
Michael Green 2024-03-02 23:54:35 +11:00
parent e4f7b2a9be
commit c5c84751f0
2 changed files with 30 additions and 11 deletions

View file

@ -22,6 +22,7 @@ class EJS_GameManager {
saveSaveFiles: this.Module.cwrap('cmd_savefiles', '', []), saveSaveFiles: this.Module.cwrap('cmd_savefiles', '', []),
supportsStates: this.Module.cwrap('supports_states', 'number', []), supportsStates: this.Module.cwrap('supports_states', 'number', []),
loadSaveFiles: this.Module.cwrap('refresh_save_files', 'null', []), loadSaveFiles: this.Module.cwrap('refresh_save_files', 'null', []),
togglePointerCapture: this.Module.cwrap('toggle_capturepointer', 'null', ['number']),
toggleFastForward: this.Module.cwrap('toggle_fastforward', 'null', ['number']), toggleFastForward: this.Module.cwrap('toggle_fastforward', 'null', ['number']),
setFastForwardRatio: this.Module.cwrap('set_ff_ratio', 'null', ['number']), setFastForwardRatio: this.Module.cwrap('set_ff_ratio', 'null', ['number']),
toggleRewind: this.Module.cwrap('toggle_rewind', 'null', ['number']), toggleRewind: this.Module.cwrap('toggle_rewind', 'null', ['number']),
@ -351,6 +352,9 @@ class EJS_GameManager {
this.clearEJSResetTimer(); this.clearEJSResetTimer();
this.functions.loadSaveFiles(); this.functions.loadSaveFiles();
} }
togglePointerCapture(active) {
this.functions.togglePointerCapture(active);
}
setFastForwardRatio(ratio) { setFastForwardRatio(ratio) {
this.functions.setFastForwardRatio(ratio); this.functions.setFastForwardRatio(ratio);
} }

View file

@ -277,6 +277,11 @@ class EmulatorJS {
this.settingsLanguage = window.EJS_settingsLanguage || false; this.settingsLanguage = window.EJS_settingsLanguage || false;
this.config = config; this.config = config;
this.currentPopup = null; this.currentPopup = null;
if (window.EJS_CapturePointer !== undefined) {
this.isPointerCapture = window.EJS_CapturePointer;
} else {
this.isPointerCapture = false;
}
this.isFastForward = false; this.isFastForward = false;
this.isSlowMotion = false; this.isSlowMotion = false;
this.rewindEnabled = this.loadRewindEnabled(); this.rewindEnabled = this.loadRewindEnabled();
@ -1703,13 +1708,10 @@ class EmulatorJS {
} }
this.gameManager.toggleMainLoop(this.paused ? 0 : 1); this.gameManager.toggleMainLoop(this.paused ? 0 : 1);
//I now realize its not easy to pause it while the cursor is locked, just in case I guess if (this.canvas.exitPointerLock) {
if (this.getCore(true) === "nds") { this.canvas.exitPointerLock();
if (this.canvas.exitPointerLock) { } else if (this.canvas.mozExitPointerLock) {
this.canvas.exitPointerLock(); this.canvas.mozExitPointerLock();
} else if (this.canvas.mozExitPointerLock) {
this.canvas.mozExitPointerLock();
}
} }
} }
this.play = (dontUpdate) => { this.play = (dontUpdate) => {
@ -1905,10 +1907,12 @@ class EmulatorJS {
this.addEventListener(this.canvas, "click", (e) => { this.addEventListener(this.canvas, "click", (e) => {
if (e.pointerType === "touch") return; if (e.pointerType === "touch") return;
if (!this.paused) { if (!this.paused) {
if (this.canvas.requestPointerLock) { if (this.isPointerCapture === true) {
this.canvas.requestPointerLock(); if (this.canvas.requestPointerLock) {
} else if (this.canvas.mozRequestPointerLock) { this.canvas.requestPointerLock();
this.canvas.mozRequestPointerLock(); } else if (this.canvas.mozRequestPointerLock) {
this.canvas.mozRequestPointerLock();
}
} }
this.menu.close(); this.menu.close();
} }
@ -3902,6 +3906,12 @@ class EmulatorJS {
if (this.rewindEnabled) { if (this.rewindEnabled) {
this.gameManager.setRewindGranularity(parseInt(value)); this.gameManager.setRewindGranularity(parseInt(value));
} }
} else if (option === "capturepointer") {
if (value === "enabled") {
this.isPointerCapture = true;
} else {
this.isPointerCapture = false;
}
} }
this.gameManager.setVariable(option, value); this.gameManager.setVariable(option, value);
this.saveSettings(); this.saveSettings();
@ -4078,6 +4088,11 @@ class EmulatorJS {
}, 'disabled'); }, 'disabled');
} }
addToMenu(this.localization('Capture Pointer'), 'capturepointer', {
'enabled': this.localization("Enabled"),
'disabled': this.localization("Disabled")
}, "disabled");
addToMenu(this.localization('FPS'), 'fps', { addToMenu(this.localization('FPS'), 'fps', {
'show': this.localization("show"), 'show': this.localization("show"),
'hide': this.localization("hide") 'hide': this.localization("hide")