Advertisement
Impshial

Crew Roster

Aug 2nd, 2021 (edited)
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.44 KB | None | 0 0
  1. -- Declare variables
  2. local line
  3. local monX
  4. local monY
  5. local headerTextColor
  6. local headerBGColor
  7. local headerText
  8. local centerPOS
  9. local altColorSwitch
  10. local altColor1
  11. local altColor2
  12. local rankHeaderPos
  13. local nameHeaderPos
  14. local rankTitle
  15. local nameTitle
  16.  
  17. -- This is the table that stores the full roster
  18. local crewRoster = {}
  19.  
  20.  
  21. -- Set variables
  22. altColorSwitch = 1
  23. altColor1 = colors.black
  24. altColor2 = colors.gray
  25. headerBGColor = colors.blue
  26. headerTextColor = colors.white
  27. headerText = "Crew Roster"
  28. rankTitle = "Rank"
  29. nameTitle = "Name"
  30.  
  31.  
  32.  
  33.  
  34. -- Write startup message to Terminal
  35. term.clear()
  36.  
  37. -- Check to see if the API file exists
  38. if fs.exists("ImpAPI") == false then
  39.     term.setCursorPos(1,1)
  40.     term.setTextColor(colors.red)
  41.     term.write("Missing API File! Attempting to download...")
  42.     term.setTextColor(colors.white)
  43.     shell.run("pastebin get pwBMKNCb ImpAPI")   -- Go out and download it
  44.     sInput = nil
  45.     term.setCursorPos(1,5)
  46.     term.setTextColor(colors.green)
  47.     term.write("API Loaded.")
  48.     term.setCursorPos(1,7)
  49.     term.setTextColor(colors.white)
  50.     term.write("Press enter to continue...")
  51.     while true do
  52.        sInput = read()
  53.        if sInput ~= nil or sInput ~= "" then
  54.              break
  55.              
  56.        end
  57.     end
  58. end
  59.  
  60. -- load the API
  61. os.loadAPI("ImpAPI")
  62.  
  63. term.clear()
  64.  
  65. -- Find the monitor
  66. mon=ImpAPI.monitorSearch()
  67.  
  68. if mon then     -- Found it
  69.     ImpAPI.CTWrite(1,6,"Monitor Found!",colors.green)
  70.     ImpAPI.CTWrite(1,8,"System Running",colors.orange)
  71.  
  72. else            -- No monitor Present
  73.     ImpAPI.CTWrite(1,6,"Monitor Not Found!",colors.red)
  74.     ImpAPI.CTWrite(1,8,"Please Attach a Monitor",colors.red)
  75.     term.setCursorPos(1,9)
  76.     return
  77. end
  78.  
  79. function RCWrite(col, row, monitor, text, color)
  80.     color = color or colors.white
  81.     monitor.setCursorPos(col,row)
  82.     monitor.setTextColor(color)
  83.     monitor.write(text)
  84. end
  85.  
  86. -- Prepare to write to the monitor
  87. mon.clear()
  88.  
  89. -- Big or small?
  90. mon.setTextScale(1.0)
  91.  
  92. mainLoop = 1
  93.  
  94.  
  95. -- Loop so it always shows (CTRL+R to restart program, CTRL+T to stop program)
  96. while mainLoop > 0 do  
  97.  
  98.     -- Get the monitor's size
  99.     monX, monY = mon.getSize() 
  100.    
  101.     mon.clear()
  102.    
  103.    
  104.     line = 2
  105.    
  106.    
  107.    
  108.     -- Write out header
  109.     ImpAPI.draw_line(1, 1, monX, headerBGColor, mon)
  110.  
  111.     -- Get center of screen for header text
  112.     centerPos = math.floor((monX - #headerText) / 2) + 1
  113.  
  114.     -- Print headerText
  115.     RCWrite(centerPos, 1, mon, headerText, colors.white)
  116.  
  117.     -- Clear out the table
  118.     crewRoster = {}
  119.    
  120.  
  121.     -- Do this line for each member
  122.     -- Just change the Rank and Name values
  123.     table.insert(crewRoster, { ["Rank"] = "Rank 1", ["Name"] = "Name 1", ["RankColor"] = colors.lime, ["NameColor"] = colors.lightBlue})
  124.     table.insert(crewRoster, { ["Rank"] = "Rank 2", ["Name"] = "Name 2", ["RankColor"] = colors.red, ["NameColor"] = colors.green})
  125.     table.insert(crewRoster, { ["Rank"] = "Rank 3", ["Name"] = "Name 3", ["RankColor"] = colors.pink, ["NameColor"] = colors.blue})
  126.     table.insert(crewRoster, { ["Rank"] = "Rank 4", ["Name"] = "Name 4", ["RankColor"] = colors.lightGray, ["NameColor"] = colors.orange})
  127.     table.insert(crewRoster, { ["Rank"] = "Rank 5", ["Name"] = "Name 5", ["RankColor"] = colors.gray, ["NameColor"] = colors.white})
  128.     table.insert(crewRoster, { ["Rank"] = "Rank 6", ["Name"] = "Name 6", ["RankColor"] = colors.cyan, ["NameColor"] = colors.yellow})
  129.  
  130.     -- Redefine center for columns 
  131.     centerPos = (monX / 2) + 1
  132.    
  133.     rankHeaderPos = math.floor(((monX / 2) - #rankTitle) / 2)
  134.     nameHeaderPos = math.floor(((monX / 2) - #nameTitle) / 2) + (monX / 2)
  135.  
  136.     line = 2
  137.  
  138.     -- Write column headers
  139.     ImpAPI.draw_line(1, 2, monX, colors.black, mon)
  140.     RCWrite(rankHeaderPos, 2, mon, "Rank", colors.orange)
  141.     RCWrite(nameHeaderPos, 2, mon, "Name", colors.orange)
  142.  
  143.     -- Write top divider
  144.     ImpAPI.draw_line(1, 3, monX, colors.black, mon)
  145.     RCWrite(1, 3, mon, "--------------------------------------------------------------------------------------", colors.gray)
  146.     -- This is the main loop where the crew is printed
  147.  
  148.     line = 4
  149.        
  150.     for i = 1,#crewRoster do
  151.         --ImpAPI.draw_line(1, line, monX, colors.black, mon)
  152.         RCWrite(2, line, mon, crewRoster[i].Rank, crewRoster[i].RankColor)
  153.         RCWrite(centerPos, line, mon, crewRoster[i].Name, crewRoster[i].NameColor)
  154.        
  155.         -- Draw dotted line from Rank to Name
  156.         for d = #crewRoster[i].Rank + 2, centerPos - 1 do
  157.             RCWrite(d, line, mon, ".", colors.gray)
  158.         end
  159.         line = line + 1
  160.     end
  161.    
  162.     -- Loop timer
  163.     sleep(.50)
  164.    
  165.  end
  166.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement