Change the event listening thing
This commit is contained in:
parent
26339c5a38
commit
42d99a0a26
|
@ -79,7 +79,7 @@ end
|
||||||
|
|
||||||
function renderStopButton() -- Renders the Stop button
|
function renderStopButton() -- Renders the Stop button
|
||||||
paintutils.drawFilledBox(centerWidth - 4, centerHeight - 4, centerWidth + 4, centerHeight + 2, accentColor)
|
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
|
end
|
||||||
|
|
||||||
function renderEjectButton() -- Renders the Eject button
|
function renderEjectButton() -- Renders the Eject button
|
||||||
|
@ -95,55 +95,46 @@ term.setCursorPos(1, 1)
|
||||||
term.setTextColor(textColor)
|
term.setTextColor(textColor)
|
||||||
end
|
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
|
term.setBackgroundColor(backgroundColor) -- Setting the background color
|
||||||
renderPlayButton() -- Rendering the play button
|
renderPlayButton() -- Rendering the play button
|
||||||
renderEjectButton() -- Rendering the eject button
|
renderEjectButton() -- Rendering the eject button
|
||||||
status = defaultStatus --Setting the
|
status = defaultStatus --Setting the
|
||||||
term.clear()
|
term.clear()
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
term.write(status)
|
local eventData = {os.pullEvent()}
|
||||||
clickListen()
|
local event = eventData[1]
|
||||||
touchListen()
|
|
||||||
keyListen()
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue