Change the event listening thing

This commit is contained in:
Lux Aliaga 2021-05-07 02:32:24 -04:00
parent 26339c5a38
commit 42d99a0a26

View file

@ -79,7 +79,7 @@ end
function renderStopButton() -- Renders the Stop button
paintutils.drawFilledBox(centerWidth - 4, centerHeight - 4, centerWidth + 4, centerHeight + 2, accentColor)
paintutils.drawFilledBox(centerWidth - 2, centerHeight - 3, centerWidth + 1, centerHeight + 1, buttonColor)
paintutils.drawFilledBox(centerWidth - 2, centerHeight - 3, centerWidth + 2, centerHeight + 1, buttonColor)
end
function renderEjectButton() -- Renders the Eject button
@ -95,36 +95,38 @@ term.setCursorPos(1, 1)
term.setTextColor(textColor)
end
function clickListen()
local event, button, x, y = os.pullEvent("mouse_up")
if button == 1 and x >= centerWidth - 4 and y >= centerHeight - 4 and x <= centerWidth + 4 and y <= centerHeight + 2 then
term.setBackgroundColor(backgroundColor) -- Setting the background color
renderPlayButton() -- Rendering the play button
renderEjectButton() -- Rendering the eject button
status = defaultStatus --Setting the
term.clear()
while true do
local eventData = {os.pullEvent()}
local event = eventData[1]
if event == "mouse_up" then
if eventData[2] == 1 and x >= eventData[3] - 4 and eventData[4] >= centerHeight - 4 and eventData[3] <= centerWidth + 4 and eventData[4] <= centerHeight + 2 then
if playing == true then
stopDisc()
else
playDisc()
end
elseif button == 1 and x >= centerWidth - 2 and y >= centerHeight + 4 and x <= centerWidth + 2 and y <= centerHeight + 4 then
elseif eventData[2] == 1 and eventData[3] >= centerWidth - 2 and eventData[4] >= centerHeight + 4 and eventData[3] <= centerWidth + 2 and eventData[4] <= centerHeight + 4 then
ejectDisc()
end
end
function touchEvent()
local event, side, x, y = os.pullEvent("monitor_touch")
if x >= centerWidth - 4 and y >= centerHeight - 4 and x <= centerWidth + 4 and y <= centerHeight + 2 then
elseif event == "monitor_touch" then
if eventData[4] >= centerWidth - 4 and eventData[5] >= centerHeight - 4 and eventData[4] <= centerWidth + 4 and eventData[5] <= centerHeight + 2 then
if playing == true then
stopDisc()
else
playDisc()
end
elseif x >= centerWidth - 2 and y >= centerHeight + 4 and x <= centerWidth + 2 and y <= centerHeight + 4 then
elseif eventData[4] >= centerWidth - 2 and eventData[5] >= centerHeight + 4 and eventData[4] <= centerWidth + 2 and eventData[5] <= centerHeight + 4 then
ejectDisc()
end
end
function keyEvent()
local event, key = os.pullEvent("key_up")
local name = keys.getName(key) or "unknown key"
elseif event == "key_up" then
local name = keys.getName(eventData[2]) or "unknown key"
if name == "space" then
if playing == true then
stopDisc()
@ -135,15 +137,4 @@ function keyEvent()
os.exit()
end
end
term.setBackgroundColor(backgroundColor) -- Setting the background color
renderPlayButton() -- Rendering the play button
renderEjectButton() -- Rendering the eject button
status = defaultStatus --Setting the
term.clear()
while true do
term.write(status)
clickListen()
touchListen()
keyListen()
end