From 588a5e2beb5c1d042c8da673371ce975332d02f9 Mon Sep 17 00:00:00 2001 From: Ethan O'Brien Date: Mon, 5 Aug 2024 23:06:37 -0500 Subject: [PATCH] Minor fixes with exit menu --- data/src/emulator.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/data/src/emulator.js b/data/src/emulator.js index d9d241f..98c4e0f 100644 --- a/data/src/emulator.js +++ b/data/src/emulator.js @@ -1517,13 +1517,6 @@ class EmulatorJS { timeout = setTimeout(hide, 3000); this.elements.menu.classList.remove("ejs_menu_bar_hidden"); }) - this.addEventListener(this.elements.menu, 'touchstart touchend', (e) => { - if (!this.started) return; - if (this.isPopupOpen()) return; - clearTimeout(timeout); - timeout = setTimeout(hide, 3000); - this.elements.menu.classList.remove("ejs_menu_bar_hidden"); - }) this.menu = { close: () => { clearTimeout(timeout); @@ -1532,7 +1525,7 @@ class EmulatorJS { open: (force) => { if (!this.started && force !== true) return; clearTimeout(timeout); - timeout = setTimeout(hide, 3000); + if (force !== true) timeout = setTimeout(hide, 3000); this.elements.menu.classList.remove("ejs_menu_bar_hidden"); }, toggle: () => { @@ -1798,10 +1791,11 @@ class EmulatorJS { this.elements.menu.appendChild(volumeSettings); const contextMenuButton = addButton("Context Menu", '', () => { - if (this.elements.contextmenu.style.display == "none") { + if (this.elements.contextmenu.style.display === "none") { this.elements.contextmenu.style.display = "block"; this.elements.contextmenu.style.left = (getComputedStyle(this.elements.parent).width.split("px")[0]/2 - getComputedStyle(this.elements.contextmenu).width.split("px")[0]/2)+"px"; this.elements.contextmenu.style.top = (getComputedStyle(this.elements.parent).height.split("px")[0]/2 - getComputedStyle(this.elements.contextmenu).height.split("px")[0]/2)+"px"; + setTimeout(this.menu.close.bind(this), 20); } else { this.elements.contextmenu.style.display = "none"; } @@ -1912,7 +1906,10 @@ class EmulatorJS { } } + let exitMenuIsOpen = false; const exitEmulation = addButton("Exit EmulatorJS", '', async () => { + if (exitMenuIsOpen) return; + exitMenuIsOpen = true; const popups = this.createSubPopup(); this.game.appendChild(popups[0]); popups[1].classList.add("ejs_cheat_parent"); @@ -1929,6 +1926,7 @@ class EmulatorJS { header.appendChild(close); popup.appendChild(header); this.addEventListener(close, "click", (e) => { + exitMenuIsOpen = false popups[0].remove(); }) popup.appendChild(this.createElement("br")); @@ -1952,6 +1950,7 @@ class EmulatorJS { this.addEventListener(closeButton, "click", (e) => { popups[0].remove(); + exitMenuIsOpen = false }) this.addEventListener(submit, "click", (e) => { @@ -1959,7 +1958,7 @@ class EmulatorJS { const body = this.createPopup("EmulatorJS has exited", {}); this.callEvent("exit"); }) - + setTimeout(this.menu.close.bind(this), 20); }); @@ -1995,7 +1994,8 @@ class EmulatorJS { cacheManager: [cache], saveSavFiles: [saveSavFiles], loadSavFiles: [loadSavFiles], - netplay: [netplay] + netplay: [netplay], + exit: [exitEmulation] } @@ -2026,6 +2026,7 @@ class EmulatorJS { if (this.config.buttonOpts.netplay === false) netplay.style.display = "none"; if (this.config.buttonOpts.diskButton === false) diskButton[0].style.display = "none"; if (this.config.buttonOpts.volumeSlider === false) volumeSlider.style.display = "none"; + if (this.config.buttonOpts.exitEmulation === false) exitEmulation.style.display = "none"; } this.menu.failedToStart = () => { @@ -2053,6 +2054,7 @@ class EmulatorJS { netplay.style.display = "none"; diskButton[0].style.display = "none"; volumeSlider.style.display = "none"; + exitEmulation.style.display = "none"; this.elements.menu.style.opacity = ""; this.menu.open(true);