Advertisement
LSLCNR

Untitled

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