Snaxiiii

Programms

Feb 13th, 2025 (edited)
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.85 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw
  2.  
  3. local w, h = term.getSize()
  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. local nOption = 1
  13.  
  14. local function drawMenu()
  15.     term.clear()
  16.     term.setCursorPos(1, 1)
  17.     term.write("V: 0.1")
  18.     term.setCursorPos(1, 2)
  19.  
  20.     term.setCursorPos(w - 11, 1)
  21.     local options = { "Miner", "Lumber", "Stats", "Menu" }
  22.     term.write(options[nOption] or "")
  23. end
  24.  
  25. local function drawFrontend()
  26.     printCentered(math.floor(h / 2) - 3, "")
  27.     printCentered(math.floor(h / 2) - 2, "Programms")
  28.     printCentered(math.floor(h / 2) - 1, "")
  29.     printCentered(math.floor(h / 2) + 0, (nOption == 1 and "[ Miner  ]") or "Miner")
  30.     printCentered(math.floor(h / 2) + 1, (nOption == 2 and "[ Lumber ]") or "Lumber")
  31.     printCentered(math.floor(h / 2) + 2, (nOption == 3 and "[ Stats ]") or "Stats")
  32.     printCentered(math.floor(h / 2) + 3, (nOption == 4 and "[ Menu ]") or "Menu")
  33.     printCentered(math.floor(h / 2) + 4, "")
  34. end
  35.  
  36. -- Display
  37. drawMenu()
  38. drawFrontend()
  39.  
  40. while true do
  41.     local event, key = os.pullEvent("key")
  42.  
  43.     if key == keys.z or key == keys.up then -- "Z" instead of "W" for QWERTZ
  44.         if nOption > 1 then
  45.             nOption = nOption - 1
  46.             drawMenu()
  47.             drawFrontend()
  48.         end
  49.     elseif key == keys.s or key == keys.down then
  50.         if nOption < 4 then
  51.             nOption = nOption + 1
  52.             drawMenu()
  53.             drawFrontend()
  54.         end
  55.     elseif key == keys.enter then
  56.         break
  57.     end
  58. end
  59.  
  60. term.clear()
  61.  
  62. -- Conditions for selection
  63. if nOption == 1 then
  64.     shell.run("miner")
  65. elseif nOption == 2 then
  66.     shell.run("lumber")
  67. elseif nOption == 3 then
  68.     shell.run("stats")
  69. elseif nOption == 4 then
  70.     shell.run("menu2")
  71. end
  72.  
Advertisement
Add Comment
Please, Sign In to add comment