Leon_Lejon

CC OS 2 music

Jan 1st, 2025 (edited)
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local w,h = term.getSize()
  2.  
  3. --Center Text
  4.  
  5. function printCentered (y,s)
  6.     local x = math.floor((w - string.len(s)) /2)
  7.     term.setCursorPos(x,y)
  8.     term.clearLine()
  9.     term.write(s)
  10. end
  11.  
  12. --Drawmenu
  13.  
  14. local nOption = 1
  15.  
  16. local function drawMenu()
  17.     term.setBackgroundColor(colors.cyan)
  18.     term.clear()
  19.     term.setCursorPos(1,1)
  20.     local logo = paintutils.loadImage("os/.logo")
  21.     paintutils.drawImage(logo, 1, 1)
  22.     term.setBackgroundColor(colors.cyan)
  23.    
  24.     term.setCursorPos(w-11,1)
  25.     if nOption == 1 then
  26.         term.write("Play Disc")
  27.     elseif nOption == 2 then
  28.         term.write("Stop Disc")
  29.     elseif nOption == 3 then
  30.         term.write("Eject Disc")
  31.     elseif nOption == 4 then
  32.         term.write("Exit")
  33.     else
  34.         end
  35. end    
  36.  
  37. --GUI
  38.  
  39. term.clear()
  40. local function drawFrontend()
  41.     printCentered(math.floor(h/2) -3, "")
  42.     printCentered(math.floor(h/2) -2, "START")
  43.     printCentered(math.floor(h/2) -1, "")
  44.     printCentered(math.floor(h/2) + 0, (nOption == 1 and "[ Play Disc ]") or "Play Disc")
  45.     printCentered(math.floor(h/2) + 1, (nOption == 2 and "[ Stop Disc ]") or "Stop Disc")
  46.     printCentered(math.floor(h/2) + 2, (nOption == 3 and "[ Eject Disc ]") or "Eject Disc")
  47.     printCentered(math.floor(h/2) + 3, (nOption == 4 and "[ Exit ]") or "Exit")
  48. end
  49.  
  50. --Display
  51.  
  52. drawMenu()
  53. drawFrontend()
  54.  
  55. while true do
  56.     local e,p = os.pullEvent()
  57.         if e == "key" then
  58.             local key = p
  59.             if key == keys.up or key == 200 then
  60.            
  61.                 if nOption > 1 then
  62.                     nOption = nOption -1
  63.                     drawMenu()
  64.                     drawFrontend()
  65.                 end
  66.             elseif key == keys.down or key == 208 then
  67.                 if nOption < 5 then
  68.                     nOption = nOption +1
  69.                     drawMenu()
  70.                     drawFrontend()
  71.                 end
  72.         elseif key == keys.enter then
  73.             break
  74. end
  75. end
  76. end
  77.  
  78. term.clear()
  79.  
  80. --Conditions
  81. if nOption == 1 then
  82.     a = disk.hasAudio("left")
  83.     b = disk.hasAudio("right")
  84.     c = disk.hasAudio("top")
  85.     d = disk.hasAudio("bottom")
  86.     if a == true then
  87.         disk.playAudio("left")
  88.     elseif b == true then
  89.         disk.playAudio("right")
  90.     elseif c == true then
  91.         disk.playAudio("top")
  92.     elseif d == true then
  93.         disk.playAudio("bottom")
  94.     end    
  95.     shell.run("Music")
  96. elseif nOption == 2 then
  97.     a = disk.hasAudio("left")
  98.     b = disk.hasAudio("right")
  99.     c = disk.hasAudio("top")
  100.     d = disk.hasAudio("bottom")
  101.     if a == true then
  102.         disk.stopAudio("left")
  103.     elseif b == true then
  104.         disk.stopAudio("right")
  105.     elseif c == true then
  106.         disk.stopAudio("top")
  107.     elseif d == true then
  108.         disk.stopAduio("bottom")
  109.     end
  110.     shell.run("Music")
  111. elseif nOption == 3 then
  112.     a = disk.hasAudio("left")
  113.     b = disk.hasAudio("right")
  114.     c = disk.hasAudio("top")
  115.     d = disk.hasAudio("bottom")
  116.     if a == true then
  117.         disk.eject("left")
  118.     elseif b == true then
  119.         disk.eject("right")
  120.     elseif c == true then
  121.         disk.eject("top")
  122.     elseif d == true then
  123.         disk.eject("bottom")
  124.     end    
  125.     shell.run("Music")
  126. else
  127.     shell.run("os/.functions")
  128. end
Advertisement
Add Comment
Please, Sign In to add comment