Advertisement
Arc13

music (OC)

Jul 6th, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.25 KB | None | 0 0
  1. local component = require("component")
  2. local term = require("term")
  3. local event = require("event")
  4. local colors = require("colors")
  5. local gpu = component.gpu
  6.  
  7. if not component.isAvailable("jukebox") then
  8.   error("No jukebox detected !")
  9. end
  10.  
  11. local jukebox = component.jukebox
  12.  
  13. local sError = ""
  14. local bTerminated = false
  15.  
  16. local nOldMonX, nOldMonY = gpu.getResolution()
  17. gpu.setResolution(80, 25)
  18. local nMonX, nMonY = gpu.getResolution()
  19.  
  20. term.clear()
  21.  
  22. gpu.setBackground(0x4C4C4C)
  23. gpu.fill(1, 1, nMonX, 1, " ")
  24.  
  25. term.setCursor(1, 1)
  26. term.write("music by arc13")
  27.  
  28. gpu.setBackground(0xCC4C4C)
  29. gpu.fill(nMonX - 4, 1, nMonX, 1, " ")
  30. term.setCursor(nMonX - 2, 1)
  31. term.write("X")
  32.  
  33. gpu.setBackground(0x999999)
  34. gpu.fill(1, 2, nMonX, nMonY, " ")
  35.  
  36. gpu.setBackground(0x3366CC)
  37. gpu.fill(1, nMonY, nMonX, nMonY, " ")
  38. term.setCursor(1, nMonY)
  39. term.write("["..os.date().."] No notifications !")
  40.  
  41. gpu.setBackground(0x57A64E)
  42. gpu.fill(1, 10, nMonX / 3, nMonY / 2, " ")
  43.  
  44. gpu.setBackground(0xCC4C4C)
  45. gpu.fill(nMonX / 3 + nMonX / 3, 10, nMonX, nMonY / 2, " ")
  46.  
  47. gpu.setBackground(0xFFFFFF)
  48. gpu.fill(10, 12, 1, nMonY / 2 - 4, " ")
  49. gpu.set(11, 12, " ")
  50. gpu.set(12, 13, " ")
  51. gpu.set(13, 14, " ")
  52. gpu.set(14, 15, " ")
  53. gpu.set(11, 12 + nMonY / 2 - 5, " ")
  54. gpu.set(12, 12 + nMonY / 2 - 6, " ")
  55. gpu.set(13, 12 + nMonY / 2 - 7, " ")
  56. gpu.set(14, 12 + nMonY / 2 - 8, " ")
  57.  
  58. gpu.fill(nMonX - 10, 12, 2, nMonY / 2 - 4, " ")
  59. gpu.fill(nMonX - 16, 12, 2, nMonY / 2 - 4, " ")
  60.  
  61. term.setCursor(1, 2)
  62. gpu.setBackground(0x4C4C4C)
  63.  
  64. local function toast(sText, bDefault)
  65.   if sText then
  66.     term.setCursor(1, nMonY)
  67.     gpu.setBackground(0x3366CC)
  68.     term.clearLine()
  69.    
  70.     if bDefault then
  71.       term.write(sText)
  72.     else
  73.       term.write("["..os.date().."] "..sText)
  74.     end
  75.   end
  76. end
  77.  
  78. local function touchHandler(_, _, nMouseX, nMouseY)
  79.   if nMouseX >= nMonX - 4 and nMouseY == 1 then
  80.     bTerminated = true
  81.   elseif nMouseX >= 1 and nMouseX <= nMonX / 3 and nMouseY >= 10 and nMouseY <= 10 + nMonY / 2 - 1 then
  82.     toast("Music played !")
  83.     jukebox.play()
  84.   elseif nMouseX >= nMonX / 3 + nMonX / 3 and nMouseX <= nMonX and nMouseY >= 10 and nMouseY <= 10 + nMonY / 2 - 1 then
  85.     toast("Music stopped !")
  86.     jukebox.stop()
  87.   end
  88. end
  89.  
  90. local function keyHandler(_, _, nChar, nCode)
  91.   if nChar == 112 and nCode == 25 then
  92.     toast("Music played !")
  93.     jukebox.play()
  94.   elseif nChar == 115 and nCode == 31 then
  95.     toast("Music stopped !")
  96.     jukebox.stop()
  97.   end
  98. end
  99.  
  100. local function removeHandler(_, sType)
  101.  if sType == "jukebox" then
  102.     bTerminated = true
  103.     sError = "Jukebox has been removed !"
  104.   end
  105. end
  106.  
  107. event.listen("touch", touchHandler)
  108. event.listen("key_up", keyHandler)
  109. event.listen("component_unavailable", removeHandler)
  110.  
  111. while bTerminated == false do
  112.   term.setCursor(1, 3)
  113.   gpu.setBackground(0x999999)
  114.   term.clearLine()
  115.  
  116.   _, sThing = jukebox.getRecord()
  117.   term.write(sThing)
  118.  
  119.   os.sleep(1)
  120. end
  121.  
  122. gpu.setResolution(nOldMonX, nOldMonY)
  123.  
  124. event.ignore("touch", touchHandler)
  125. event.ignore("key_up", keyHandler)
  126. event.ignore("component_unavailable", removeHandler)
  127.  
  128. gpu.setBackground(0x000000)
  129. term.clear()
  130.  
  131. if sError ~= "" then
  132.   gpu.setForeground(0xCC4C4C)
  133.   term.write(sError)
  134.   gpu.setForeground(0xFFFFFF)
  135. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement