fixed mose click bouncing issue for overlay buttons

This commit is contained in:
StevenPhang22 2022-11-28 22:11:49 -05:00
parent 5b0c9a0a56
commit a40c02ab3c
2 changed files with 16 additions and 4 deletions

View File

@ -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