moo3oo3oo3

Jukebox (CC:Restitched 1.16)

Jun 16th, 2021
1,416
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Config
  2. local monitor = peripheral.wrap("back")
  3. local speaker = peripheral.wrap("right")
  4. local buttonWidth = 19
  5. -- Do not edit past this point unless you know what you are doing!
  6.  
  7. if pocket then
  8.     print("Running on pocket computer")
  9.     monitor = term
  10.     speaker = peripheral.wrap("back")
  11. else
  12.     monitor.setTextScale(.5)
  13. end
  14.  
  15.  
  16. local width, height = monitor.getSize()
  17. local numColumns = math.floor(width / buttonWidth)
  18.  
  19. if numColumns == 0 then
  20.     error("Screen is too narrow! Monitor must be at least 2 blocks wide!")
  21. end
  22.  
  23. local numRows = math.floor(height / 2)
  24.  
  25. local buttons = {}
  26. local pages = {}
  27. local currentPage = 1
  28. local discs =
  29. {
  30.     [1] = { [1] = "13", [2] = "minecraft:music_disc.13"},
  31.     [2] = { [1] = "cat", [2] = "minecraft:music_disc.cat"},
  32.     [3] = { [1] = "blocks", [2] = "minecraft:music_disc.blocks"},
  33.     [4] = { [1] = "chirp", [2] = "minecraft:music_disc.chirp"},
  34.     [5] = { [1] = "far", [2] = "minecraft:music_disc.far"},
  35.     [6] = { [1] = "mall", [2] = "minecraft:music_disc.mall"},
  36.     [7] = { [1] = "mellohi", [2] = "minecraft:music_disc.mellohi"},
  37.     [8] = { [1] = "stal", [2] = "minecraft:music_disc.stal"},
  38.     [9] = { [1] = "strad", [2] = "minecraft:music_disc.strad"},
  39.     [10] = { [1] = "ward", [2] = "minecraft:music_disc.ward"},
  40.     [11] = { [1] = "11", [2] = "minecraft:music_disc.11"},
  41.     [12] = { [1] = "wait", [2] = "minecraft:music_disc.wait"},
  42.     [13] = { [1] = "Pigstep", [2] = "minecraft:music_disc.pigstep"},
  43.     [14] = { [1] = "Luminous Plantation", [2] = "cinderscapes:music_disc.luminous_plantation"},
  44.     [15] = { [1] = "Chilling In Hell", [2] = "cinderscapes:music_disc.chilling_in_hell"},
  45.     [16] = { [1] = "Strange And Alien", [2] = "betterend:betterend.record.strange_and_alien"},
  46.     [17] = { [1] = "Grasping At Stars", [2] = "betterend:betterend.record.grasping_at_stars"},
  47.     [18] = { [1] = "Endseeker", [2] = "betterend:betterend.record.endseeker"},
  48.     [19] = { [1] = "Eo Dracona", [2] = "betterend:betterend.record.eo_dracona"},
  49.     [20] = { [1] = "Button Mushrooms", [2] = "biomemakeover:button_mushrooms"},
  50.     [21] = { [1] = "Ghost Town", [2] = "biomemakeover:ghost_town"},
  51.     [22] = { [1] = "Swamp Jives", [2] = "biomemakeover:swamp_jives"},
  52.     [23] = { [1] = "Red Rose", [2] = "biomemakeover:red_rose"}
  53. }
  54.  
  55.  
  56. function reset()
  57.     monitor.setBackgroundColor(colors.black)
  58.     monitor.setTextColor(colors.white)
  59.    
  60.     if not pocket then
  61.         monitor.setTextScale(.5)
  62.     end
  63.    
  64.     monitor.clear()
  65. end
  66.  
  67.  
  68. function drawButton(posX, posY, width, text, internalMsg, backgroundColor, textColor)
  69.     local bgColor = (backgroundColor == nil) and colors.red or backgroundColor
  70.     local txtColor = (textColor == nil) and colors.white or textColor
  71.     local txtLen = string.len(text)
  72.    
  73.     monitor.setBackgroundColor(bgColor)
  74.     monitor.setTextColor(txtColor)
  75.     monitor.setCursorPos(posX, posY)
  76.     monitor.write( string.rep(" ", width) )
  77.     monitor.setCursorPos( posX + math.floor( (width - txtLen) / 2 ), posY)
  78.     monitor.write(text)
  79.    
  80.     table.insert(buttons, {posX, posY, width, internalMsg})
  81. end
  82.  
  83.  
  84. function generatePages()
  85.     local maxButtons = numColumns * numRows
  86.    
  87.     local i = 1
  88.     local page = {}
  89.     for _, disc in ipairs(discs) do
  90.        
  91.         table.insert(page, disc)
  92.        
  93.         if i == maxButtons or next(discs, _) == nil then
  94.             table.insert(pages, page)
  95.             i = 1
  96.             page = {}
  97.         end
  98.        
  99.         i = i + 1
  100.     end
  101.    
  102. end
  103.  
  104.  
  105. function buildPage()
  106.     reset()
  107.     buttons = {}
  108.     for i, disc in ipairs(pages[currentPage]) do
  109.         local colNum = (i-1) % numColumns
  110.         local x = 2 + colNum * buttonWidth + colNum
  111.         local y = 1 + math.floor( (i-1) / numColumns) * 2
  112.        
  113.         drawButton(x, y, buttonWidth, disc[1], disc[2])
  114.        
  115.         if pages[currentPage + 1] ~= nil then
  116.             monitor.setCursorPos(width - 2, height - 1)
  117.             drawButton(width - 2, height - 1, 2, "->", "nextPage")
  118.         end
  119.         if pages[currentPage - 1] ~= nil then
  120.             monitor.setCursorPos(width - 5, height - 1)
  121.             drawButton(width - 5, height - 1, 2, "<-", "previousPage")
  122.         end
  123.     end
  124. end
  125.  
  126. reset()
  127. generatePages()
  128. buildPage()
  129. while true do
  130.    
  131.     local listen = "monitor_touch"
  132.     if pocket then listen = "mouse_click" end;
  133.    
  134.     local event, side, x, y = os .pullEvent(listen)
  135.    
  136.     for index, bttn in pairs(buttons) do
  137.         if y == bttn[2] and x >= bttn[1] and x <= bttn[1] + bttn[3] then
  138.             local internalMsg = bttn[4]
  139.            
  140.             if internalMsg == "nextPage" then
  141.                 currentPage = currentPage + 1
  142.                 buildPage()
  143.                 break
  144.             elseif internalMsg == "previousPage" then
  145.                 currentPage = currentPage - 1
  146.                 buildPage()
  147.                 break
  148.             end
  149.            
  150.             if not pocket then
  151.                 print("Now playing: "..internalMsg)
  152.             end
  153.            
  154.             speaker.playSound(internalMsg)
  155.             break
  156.         end
  157.     end
  158.    
  159. end
RAW Paste Data