From 5b0c9a0a568257309d2bb0d1eb14fe61ff3a5df4 Mon Sep 17 00:00:00 2001 From: StevenPhang22 Date: Mon, 28 Nov 2022 21:26:24 -0500 Subject: [PATCH 1/2] added buttons for switch disk and eject/insert --- output/luaScripts/emugator/emugators_demo.lua | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/output/luaScripts/emugator/emugators_demo.lua b/output/luaScripts/emugator/emugators_demo.lua index d699e9c3..888438e9 100644 --- a/output/luaScripts/emugator/emugators_demo.lua +++ b/output/luaScripts/emugator/emugators_demo.lua @@ -2,6 +2,8 @@ local cart = {x1=50, y1=50, x2=100, y2=100} local console = {x1=150, y1=50, x2=200, y2=100} local unloadButton = {x1 = 220, y1 = 220, x2 = 250, y2 = 230} + local ejectInsertButton = {x1 = 5, y1 = 220, x2 = 64, y2 = 230} + local switchButton = {x1 = 180, y1 = 220, x2 = 210, y2 = 230} local isDrag = false --local gd = require("gd") @@ -37,13 +39,23 @@ while(true) do gui.rect(unloadButton.x1, unloadButton.y1, unloadButton.x2, unloadButton.y2, "blue", "white") gui.text(unloadButton.x1+2, unloadButton.y1+2, "Unload") + gui.rect(switchButton.x1, switchButton.y1, switchButton.x2, switchButton.y2, "blue", "white") + gui.text(switchButton.x1+2, switchButton.y1+2, "Switch") + + gui.rect(ejectInsertButton.x1, ejectInsertButton.y1, ejectInsertButton.x2, ejectInsertButton.y2, "blue", "white") + gui.text(ejectInsertButton.x1+2, ejectInsertButton.y1+2, "Eject/Insert") + if ((inpt.xmouse > unloadButton.x1) and (inpt.xmouse < unloadButton.x2) and (inpt.ymouse > unloadButton.y1) and (inpt.ymouse < unloadButton.y2) and inpt.leftclick) then emu.closeRom() emugator.yieldwithflag() + elseif ((inpt.xmouse > switchButton.x1) and (inpt.xmouse < switchButton.x2) and (inpt.ymouse > switchButton.y1) and (inpt.ymouse < switchButton.y2) and inpt.leftclick) then + emu.switchDisk() + emu.frameadvance() + elseif ((inpt.xmouse > ejectInsertButton.x1) and (inpt.xmouse < ejectInsertButton.x2) and (inpt.ymouse > ejectInsertButton.y1) and (inpt.ymouse < ejectInsertButton.y2) and inpt.leftclick) then + emu.insertOrEjectDisk() + emu.frameadvance() else emu.frameadvance() end end - - --emu.frameadvance() end \ No newline at end of file From a40c02ab3c8e8ebc8189f239d018f7407417e468 Mon Sep 17 00:00:00 2001 From: StevenPhang22 Date: Mon, 28 Nov 2022 22:11:49 -0500 Subject: [PATCH 2/2] fixed mose click bouncing issue for overlay buttons --- ...apan) (v1.0).fds => LegendOfZelda2_JP.fds} | Bin output/luaScripts/emugator/emugators_demo.lua | 20 ++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) rename output/luaScripts/emugator/{Link no Bouken - The Legend of Zelda 2 (Japan) (v1.0).fds => LegendOfZelda2_JP.fds} (100%) diff --git a/output/luaScripts/emugator/Link no Bouken - The Legend of Zelda 2 (Japan) (v1.0).fds b/output/luaScripts/emugator/LegendOfZelda2_JP.fds similarity index 100% rename from output/luaScripts/emugator/Link no Bouken - The Legend of Zelda 2 (Japan) (v1.0).fds rename to output/luaScripts/emugator/LegendOfZelda2_JP.fds diff --git a/output/luaScripts/emugator/emugators_demo.lua b/output/luaScripts/emugator/emugators_demo.lua index 888438e9..ff1ffd55 100644 --- a/output/luaScripts/emugator/emugators_demo.lua +++ b/output/luaScripts/emugator/emugators_demo.lua @@ -5,6 +5,7 @@ local ejectInsertButton = {x1 = 5, y1 = 220, x2 = 64, y2 = 230} local switchButton = {x1 = 180, y1 = 220, x2 = 210, y2 = 230} local isDrag = false + local wasClicked = false --local gd = require("gd") while(true) do @@ -14,21 +15,22 @@ while(true) do local inpt = input.read() if(emu.emulating() == false) then + wasClicked = false if (inpt.leftclick == nil) then if ((inpt.xmouse > console.x1) and (inpt.xmouse < console.x2) and (inpt.ymouse > console.y1) and (inpt.ymouse < console.y2) and isDrag) then - emu.loadrom("superMario.nes") + emu.loadrom("LegendOfZelda2_JP.fds") end isDrag = false end if isDrag then gui.rect(inpt.xmouse, inpt.ymouse, inpt.xmouse+50, inpt.ymouse+50, "red", "white") - gui.text(inpt.xmouse + 12, inpt.ymouse+12, "Super\nMario\nBros.") + gui.text(inpt.xmouse + 12, inpt.ymouse+12, "Legend\nOf\nZelda") elseif ((inpt.xmouse > cart.x1) and (inpt.xmouse < cart.x2) and (inpt.ymouse > cart.y1) and (inpt.ymouse < cart.y2) and inpt.leftclick) then isDrag = true else gui.rect(cart.x1, cart.y1, cart.x2, cart.y2, "gray", "white") - gui.text(cart.x1 + 12, cart.y1 + 12, "Super\nMario\nBros.") + gui.text(cart.x1 + 12, cart.y1 + 12, "Legend\nof\nZelda\n2") end gui.rect(console.x1, console.y1, console.x2, console.y2, "blue", "white") @@ -46,15 +48,25 @@ while(true) do gui.text(ejectInsertButton.x1+2, ejectInsertButton.y1+2, "Eject/Insert") if ((inpt.xmouse > unloadButton.x1) and (inpt.xmouse < unloadButton.x2) and (inpt.ymouse > unloadButton.y1) and (inpt.ymouse < unloadButton.y2) and inpt.leftclick) then - emu.closeRom() + if (wasClicked == false) then + emu.closeRom() + end + wasClicked = true emugator.yieldwithflag() elseif ((inpt.xmouse > switchButton.x1) and (inpt.xmouse < switchButton.x2) and (inpt.ymouse > switchButton.y1) and (inpt.ymouse < switchButton.y2) and inpt.leftclick) then + if (wasClicked == false) then emu.switchDisk() + end + wasClicked = true emu.frameadvance() elseif ((inpt.xmouse > ejectInsertButton.x1) and (inpt.xmouse < ejectInsertButton.x2) and (inpt.ymouse > ejectInsertButton.y1) and (inpt.ymouse < ejectInsertButton.y2) and inpt.leftclick) then + if (wasClicked == false) then emu.insertOrEjectDisk() + end + wasClicked = true emu.frameadvance() else + wasClicked = false emu.frameadvance() end end