Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diskDrive = peripheral.find("drive")
- if not os.loadAPI("time") then
- shell.run("pastebin get 6nArsPfK time")
- os.loadAPI("time")
- end
- term.setBackgroundColor(colors.lightGray)
- term.clear()
- x, y = term.getSize()
- paintutils.drawLine(1, 1, x, 1, colors.gray)
- term.setCursorPos(1, 1)
- term.write("music by arc13")
- if not diskDrive then
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1, 1)
- error("No disk drive found")
- end
- paintutils.drawPixel(x, 1, colors.red)
- term.setCursorPos(x, 1)
- term.write("X")
- term.setBackgroundColor(colors.lightGray)
- function toast(text, default)
- if text then
- paintutils.drawLine(1, y, x, y, colors.blue)
- term.setCursorPos(1, y)
- term.clearLine()
- if default then
- term.write(text)
- else
- term.write("["..time.getWorldHours()..":"..time.getWorldMinutes().."] "..text)
- end
- term.setBackgroundColor(colors.lightGray)
- end
- end
- function buttonHandler()
- while true do
- event, button, cX, cY = os.pullEvent("mouse_click")
- if cX <= 7 and cY >= y - 5 and cY <= y - 2 and diskDrive.hasAudio() then
- diskDrive.playAudio()
- elseif cX >= x - 6 and cY >= y - 5 and cY <= y - 2 and diskDrive.hasAudio() then
- diskDrive.stopAudio()
- elseif cX == x and cY == 1 then
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1, 1)
- return true
- end
- end
- end
- function toggleButtons(state)
- if state then
- paintutils.drawFilledBox(1, y - 6, 7, y - 2, colors.green)
- term.setCursorPos(3, y - 4)
- term.write("|>")
- paintutils.drawFilledBox(x - 6, y - 6, x, y - 2, colors.red)
- term.setCursorPos(x - 3, y - 4)
- term.write("||")
- else
- paintutils.drawFilledBox(1, y - 6, 7, y - 2, colors.gray)
- term.setCursorPos(3, y - 4)
- term.write("|>")
- paintutils.drawFilledBox(x - 6, y - 6, x, y - 2, colors.gray)
- term.setCursorPos(x - 3, y - 4)
- term.write("||")
- end
- term.setBackgroundColor(colors.lightGray)
- end
- function diskHandler()
- while true do
- event = os.pullEvent()
- if event == "disk" then
- toast("Disk inserted !")
- if diskDrive.hasAudio() then
- toggleButtons(true)
- term.setCursorPos(1, 3)
- term.clearLine()
- term.write(diskDrive.getAudioTitle())
- else
- toggleButtons(false)
- term.setCursorPos(1, 3)
- term.clearLine()
- term.write("Not an audio disk !")
- end
- elseif event == "disk_eject" then
- toast("Disk ejected !")
- toggleButtons(false)
- term.setCursorPos(1, 3)
- term.clearLine()
- term.write("No disk inserted !")
- end
- end
- end
- if diskDrive.isDiskPresent() then
- if diskDrive.hasAudio() then
- toggleButtons(true)
- term.setCursorPos(1, 3)
- term.clearLine()
- term.write(diskDrive.getAudioTitle())
- else
- toggleButtons(false)
- term.setCursorPos(1, 3)
- term.clearLine()
- term.write("Not an audio disk !")
- end
- else
- toggleButtons(false)
- term.setCursorPos(1, 3)
- term.clearLine()
- term.write("No disk inserted !")
- end
- toast("No notifications !", true)
- parallel.waitForAny(diskHandler, buttonHandler)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement