QuickMuffin8782-Alt

CraftOS Themed Minimenu with sounds

Sep 18th, 2020
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local function minimenu( ... )
  2.     local function playSound(name, vol, pitch)
  3.         if peripheral.find("speaker") then
  4.             peripheral.find("speaker").playSound(name, vol, pitch)
  5.         end
  6.     end
  7.     local tArgs = { ... }
  8.     local tSelections = {}
  9.     local _, y = term.getSize()
  10.     local n = 1
  11.     for i, str in ipairs( tArgs ) do
  12.         tSelections[ i ] = { str = str }
  13.         tSelections[ i ][ "x1" ] = n
  14.         tSelections[ i ][ "x2" ] = n + #str + 1
  15.         n = n + 2 + #str
  16.     end
  17.     for k, v in ipairs( tSelections ) do
  18.         term.setCursorPos( v["x1"], y )
  19.         term.write( ' ' .. v.str )
  20.     end
  21.     local slc = 1
  22.     local last = 1
  23.     while true do
  24.         term.setBackgroundColor( colors.black )
  25.         term.setTextColor( colors.white )
  26.         term.setCursorPos( tSelections[ last ]["x1"], y )
  27.         term.write( ' ' )
  28.         term.setCursorPos( tSelections[ last ]["x2"], y )
  29.         term.write( ' ' )
  30.         term.setCursorPos( tSelections[ slc ]["x1"], y )
  31.         term.setTextColor( term.isColor() and colors.cyan or colors.gray )
  32.         term.setBackgroundColor( term.isColor() and colors.black or colors.black )
  33.         term.write( "[" )
  34.         term.setCursorPos( tSelections[ slc ]["x2"], y )
  35.         term.write( "]" )
  36.         while true do
  37.             local event, key = os.pullEvent( "key" )
  38.             if key == 203 and tSelections[ slc - 1 ] then
  39.                 last = slc
  40.                 slc = slc - 1
  41.                 playSound("block.note_block.hat", 0.5, 1)
  42.                 break
  43.             elseif key == 205 and tSelections[ slc + 1 ] then
  44.                 last = slc
  45.                 slc = slc + 1
  46.                 playSound("block.note_block.hat", 0.5, 1)
  47.                 break
  48.             elseif key == 28 then
  49.                 playSound("ui.button.click", 1, 1)
  50.                 return tSelections[ slc ].str
  51.             end
  52.         end
  53.     end
  54. end
Add Comment
Please, Sign In to add comment