LSLCNR

Untitled

Nov 12th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. local sg = peripheral.wrap("right")
  2.  
  3. local favAddresses = {
  4. {
  5. title = "",
  6. address = ""
  7. }
  8. }
  9.  
  10. local event, p1, p2, p3 = nil
  11. local screenSelection = 0
  12. local screen = nil
  13.  
  14. function resetScreen()
  15. term.setBackgroundColor(colors.gray)
  16. term.setTextColor(colors.black)
  17. term.clear()
  18. term.setCursorPos(1, 1)
  19. end
  20.  
  21. function Print(text, x, y)
  22. term.setCursorPos(x, y)
  23. term.write(text)
  24. end
  25.  
  26. function drawScreen(screenSettings)
  27. resetScreen()
  28.  
  29. term.setBackgroundColor(colors.white)
  30. for i = 1, 3, 1 do
  31. term.setCursorPos(1, i)
  32. term.clearLine()
  33. end
  34. Print(screenSettings["title"], getCenterX(screenSettings["title"]), 2)
  35. term.setBackgroundColor(colors.gray)
  36.  
  37. --For each option of a screen
  38. local line = getCenterY() - math.floor(tablelength(screenSettings["options"]) / 2)
  39. local curSel = 0
  40. for k, v in ipairs(screenSettings["options"]) do
  41. local label = v["option"]
  42. if curSel == screenSelection then
  43. label = "[" + v["option"] + "]"
  44. end
  45. Print(label, getCenterX(label), line)
  46. line = line + 1
  47. curSel = curSel + 1
  48. end
  49. end
  50.  
  51. function getCenterX(text)
  52. local x,_ = term.getSize()
  53. return math.floor((x / 2) - (string.len(text) / 2))
  54. end
  55.  
  56. function getCenterY()
  57. local _,y = term.getSize()
  58. return math.floor(y / 2)
  59. end
  60.  
  61. function tablelength(T)
  62. local count = 0
  63. for _ in pairs(T) do count = count + 1 end
  64. return count
  65. end
  66.  
  67. function startup()
  68. screenSelection = 0
  69. screen = {
  70. title = "Stargate Control Program",
  71. options = {
  72. {
  73. option = "Dial Favorite",
  74. func = dialFavoriteScreen
  75. },
  76. {
  77. option = "Dial Manually",
  78. func = dialFavoriteScreen
  79. },
  80. {
  81. option = "Exit",
  82. func = exitProgram
  83. }
  84. }
  85. }
  86. end
  87.  
  88. function dialFavoriteScreen()
  89.  
  90. end
  91.  
  92. function exitProgram()
  93. computer.reboot()
  94. end
  95.  
  96. function awaitEvent()
  97. event, p1, p2, p3 = os.pullEvent()
  98. end
  99.  
  100. function isSelectionChanged()
  101. if event == "key" then
  102. if p1 == keys.up then
  103.  
  104. end
  105. end
  106. end
  107.  
  108. startup()
  109.  
  110. while true do
  111. awaitEvent()
  112. drawScreen(screen)
  113. end
Advertisement
Add Comment
Please, Sign In to add comment