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,36 +95,38 @@ term.setCursorPos(1, 1)
|
||||||
term.setTextColor(textColor)
|
term.setTextColor(textColor)
|
||||||
end
|
end
|
||||||
|
|
||||||
function clickListen()
|
term.setBackgroundColor(backgroundColor) -- Setting the background color
|
||||||
local event, button, x, y = os.pullEvent("mouse_up")
|
renderPlayButton() -- Rendering the play button
|
||||||
if button == 1 and x >= centerWidth - 4 and y >= centerHeight - 4 and x <= centerWidth + 4 and y <= centerHeight + 2 then
|
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
|
if playing == true then
|
||||||
stopDisc()
|
stopDisc()
|
||||||
else
|
else
|
||||||
playDisc()
|
playDisc()
|
||||||
end
|
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()
|
ejectDisc()
|
||||||
end
|
end
|
||||||
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
|
||||||
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
|
if playing == true then
|
||||||
stopDisc()
|
stopDisc()
|
||||||
else
|
else
|
||||||
playDisc()
|
playDisc()
|
||||||
end
|
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()
|
ejectDisc()
|
||||||
end
|
end
|
||||||
end
|
elseif event == "key_up" then
|
||||||
|
local name = keys.getName(eventData[2]) or "unknown key"
|
||||||
function keyEvent()
|
|
||||||
local event, key = os.pullEvent("key_up")
|
|
||||||
local name = keys.getName(key) or "unknown key"
|
|
||||||
|
|
||||||
if name == "space" then
|
if name == "space" then
|
||||||
if playing == true then
|
if playing == true then
|
||||||
stopDisc()
|
stopDisc()
|
||||||
|
@ -134,16 +136,5 @@ function keyEvent()
|
||||||
elseif name == "q" then
|
elseif name == "q" then
|
||||||
os.exit()
|
os.exit()
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue