Change the event listening thing

This commit is contained in:
mint 2021-05-07 02:32:24 -04:00
parent 26339c5a38
commit 42d99a0a26
1 changed files with 37 additions and 46 deletions

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,55 +95,46 @@ 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
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
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
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
ejectDisc()
end
end
function keyEvent()
local event, key = os.pullEvent("key_up")
local name = keys.getName(key) or "unknown key"
if name == "space" then
if playing == true then
stopDisc()
else
playDisc()
end
elseif name == "q" then
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()
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 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
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 eventData[4] >= centerWidth - 2 and eventData[5] >= centerHeight + 4 and eventData[4] <= centerWidth + 2 and eventData[5] <= centerHeight + 4 then
ejectDisc()
end
elseif event == "key_up" then
local name = keys.getName(eventData[2]) or "unknown key"
if name == "space" then
if playing == true then
stopDisc()
else
playDisc()
end
elseif name == "q" then
os.exit()
end
end
end