Advertisement
jig487

listGUI

Mar 14th, 2024
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. local rgui --recursive gui
  2.  
  3. --##Key grabber##
  4. --local evt, key = os.pullEvent("key")
  5.  
  6. local titleColor = colors.pink
  7. local menuColor = colors.purple
  8. local textColor = colors.white
  9. local highlightColor = colors.pink
  10.  
  11. local menuColors = {
  12. title = titleColor,
  13. menu = menuColor,
  14. text = textColor,
  15. highlight = highlightColor
  16. }
  17.  
  18. --Args: menu = array of strings, colorList = array of named colors
  19. --returns: int = cursor, string = name of menu item chosen, bool = true: user chose this option / false: user wants to exit menu
  20. local function openMenu(menu,colorList)
  21. local col = term.getTextColor()
  22. local cursor = 1
  23. term.clear()
  24. while true do
  25. term.setCursorPos(1,1)
  26. for i = 1, #menu do
  27. if cursor == i then
  28. term.setTextColor(colorList.highlight)
  29. print("{"..i.."} "..menu[i])
  30. else
  31. term.setTextColor(colorList.text)
  32. print("["..i.."] "..menu[i])
  33. end
  34. end
  35.  
  36. local evt, key = os.pullEvent("key")
  37. key = keys.getName(key)
  38. if key == "up" and cursor > 1 then
  39. cursor = cursor - 1
  40. elseif key == "down" and cursor < #menu then
  41. cursor = cursor + 1
  42. --elseif key == "left" then
  43. --elseif key == "right" then
  44. elseif key == "enter" then
  45. term.setTextColor(col)
  46. return cursor, menu[cursor], true
  47. elseif key == "backspace" then
  48. term.setTextColor(col)
  49. return cursor, false
  50. end
  51. end
  52. end
  53.  
  54. local menu = {"Quarry Miner", "Strip Miner","1","2","3","4","5"}
  55. while true do
  56. local cursor,item,val = openMenu(menu,menuColors)
  57. term.clear()
  58. print(cursor,item,val)
  59. print("Press 'enter' to continue")
  60. read()
  61. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement