SHARE
TWEET

Untitled

a guest Nov 12th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 = 1
  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 = 1
  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 = 1
  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.             if screenSelection == 1 then
  121.                 screenSelection = tablelength(screen["options"])
  122.             else
  123.                 screenSelection = screenSelection - 1
  124.             end
  125.         elseif p1 == keys.down then
  126.             if screenSelection == tablelength(screen["options"]) then
  127.                 screenSelection = 1
  128.             else
  129.                 screenSelection = screenSelection + 1
  130.             end
  131.         end
  132.     end
  133. end
  134.  
  135. startup()
  136.  
  137. while true do
  138.     awaitEvent()
  139.     isSelectionChanged()
  140.     drawScreen(screen)
  141. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top