Advertisement
LSLCNR

Untitled

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