Advertisement
Guest User

A.R.C.S.

a guest
Jul 22nd, 2016
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.02 KB | None | 0 0
  1. `mon = peripheral.wrap("monitor_0")
  2. local rea = peripheral.wrap("right")
  3. monX, monY = mon.getSize()
  4.  
  5. --Clear Function
  6. function clear()
  7.         mon.setBackgroundColor(colors.black)
  8.         mon.clear()
  9.         mon.setCursorPos(1,1)
  10. end
  11.  
  12. --Draw Line Function
  13. function drawLine(x,y, length, size, color_bar)
  14.         for yPos = y, y+size-1 do
  15.                 mon.setBackgroundColor(color_bar)
  16.                 mon.setCursorPos(x, yPos)
  17.                 mon.write(string.rep(" ", length))
  18.         end
  19. end
  20.  
  21. --Progress Bar Function
  22. function drawProg(x, y, length, size, minVal, maxVal, color_bar, color_bg)
  23.         drawLine(x, y, length, size, color_bg)
  24.         local barSize = math.floor((minVal/maxVal)*length)
  25.         drawLine(x, y, barSize, size, color_bar)
  26. end
  27.  
  28. --Function for Centering Titles
  29. function centerText(title, y, per, value, maxValue)
  30.         mon.setBackgroundColor(colors.black)
  31.         mon.setTextColor(colors.white)
  32.         local txtX, txtY = mon.getSize()
  33.         if per == true then
  34.                 mon.setCursorPos((txtX+string.len(title))/2-(string.len(title)), y)
  35.                 mon.write(title..':'..math.floor((value/maxValue)*100).."%")
  36.         else
  37.                 mon.setCursorPos((txtX+string.len(title))/2-(string.len(title)-1), y)
  38.                 mon.write(title)
  39.         end
  40. end
  41.  
  42. local button={}
  43.  
  44. function clearTable()
  45.         button = {}
  46.         mon.clear()
  47. end
  48.  
  49. function setTable(name, func, xmin, xmax, ymin, ymax)
  50.         button[name] = {}
  51.         button[name]["func"] = func
  52.         button[name]["active"] = false
  53.         button[name]["xmin"] = xmin
  54.         button[name]["ymin"] = ymin
  55.         button[name]["xmax"] = xmax
  56.         buttob[name]["ymax"] = ymax
  57. end
  58.  
  59. function fill(text, color, bData)
  60.         mon.setBackgroundColor(color)
  61.         local yspot = math.floor((bData["ymin"] + bData['ymax']) /2)
  62.         local xspot = math.floor(((bData["xmin"] + bData['xmax']) - string.len(text))/2)+1
  63.         for j = bData["ymin"], bData['ymax'] do
  64.                 mon.setCursorPos(bData["xmin"], j)
  65.                 if j == yspot then
  66.                         for k = 0, bData["xmax"] - bData['xmin'] - string.len(text) +1 do
  67.                                 if k == xspot then
  68.                                         mon.write(text)
  69.                                 else
  70.                                         mon.write(" ")
  71.                                 end
  72.                         end
  73.                 else
  74.                         for i = bData["xmin"], bData['xmax'] do
  75.                                 mon.write(" ")
  76.                         end
  77.                 end
  78.         end
  79.         mon.setBackgroundColor(colors.black)
  80. end
  81. function screen()
  82.         local currColor
  83.         for name, data in pairs(button) do
  84.                 local on = data["active"]
  85.                 if on == true then
  86.                         currColor = colors.lime
  87.                 else
  88.                         currColor = colors.red
  89.                 end
  90.                 fill(name, currColor, data)
  91.         end
  92. end
  93. function toggleButton(name)
  94.         button[name]["active"] = not button[name]['active']
  95.         screen()
  96. end
  97.  
  98.  
  99. function flash(name)
  100.         toggleButton(name)
  101.         screen()
  102.         sleep(0.15)
  103.         toggleButton(name)
  104.         screen()
  105. end
  106.  
  107. function checkxy(x, y)
  108.         for name, data in pairs(button) do
  109.                 if y>=data["ymin"] and y <= data['ymax'] then
  110.                         if x>=data["xmin"] and x <= data['xmax'] then
  111.                                 data["func"]()
  112.                                 return true
  113.                         end
  114.                 end
  115.         end
  116.         return false
  117. end
  118.  
  119. function fillTable()
  120.         --Control Rod 1
  121.         button.setTable("-10", R11, 2, 4, 9, 9)
  122.         button.setTable("-5", R12, 6, 7, 9, 9)
  123.         button.setTable("-1", R13, 8, 9, 9, 9)
  124.         button.setTable("+1", R14, 76, 77, 9, 9)
  125.         button.setTable("+5", R15, 79, 80, 9, 9)
  126.         button.setTable("+10", R16, 82, 83, 9, 9)
  127.         --Control Rod 2
  128.         button.setTable("-10", R21, 2, 4, 11, 11)
  129.         button.setTable("-5", R22, 6, 7, 11, 11)
  130.         button.setTable("-1", R23, 8, 9, 11, 11)
  131.         button.setTable("+1", R24, 76, 77, 11, 11)
  132.         button.setTable("+5", R25, 79, 80, 11, 11)
  133.         button.setTable("+10", R26, 82, 83, 11, 11)
  134.        
  135.         --Control Rod 3
  136.         button.setTable("-10", R31, 2, 4, 13, 13)
  137.         button.setTable("-5", R32, 6, 7, 13, 13)
  138.         button.setTable("-1", R33, 8, 9, 13, 13)
  139.         button.setTable("+1", R34, 76, 77, 13, 13)
  140.         button.setTable("+5", R35, 79, 80, 13, 13)
  141.         button.setTable("+10", R36, 82, 83, 13, 13)
  142.        
  143.         --Control Rod 4
  144.         button.setTable("-10", R41, 2, 4, 15, 15)
  145.         button.setTable("-5", R42, 6, 7, 15, 15)
  146.         button.setTable("-1", R43, 8, 9, 15, 15)
  147.         button.setTable("+1", R44, 76, 77, 15, 15)
  148.         button.setTable("+5", R45, 79, 80, 15, 15)
  149.         button.setTable("+10", R46, 82, 83, 15, 15)
  150.        
  151.         --Control Rod 5
  152.         button.setTable("-10", R51, 2, 4, 17, 17)
  153.         button.setTable("-5", R52, 6, 7, 17, 17)
  154.         button.setTable("-1", R53, 8, 9, 17, 17)
  155.         button.setTable("+1", R54, 76, 77, 17, 17)
  156.         button.setTable("+5", R55, 79, 80, 17, 17)
  157.         button.setTable("+10", R56, 82, 83, 17, 17)
  158.         --Additional buttons
  159.         button.setTable("On/Off", OnOff, 1, 6, 1, 1)
  160.         button.setTable("X", stopProgram, 84,84, 1, 1)
  161. end
  162.  
  163. function getClick()
  164.         event, side, x, y = os.pullEvent("monitor_touch")
  165.         checkxy(x, y)
  166. end
  167. --Button Functions
  168.   --Control Rod 1
  169. function R11()
  170.         rea.setControlRodLevel(1, rea.getControlRodLevel(1)-10)
  171. end
  172. function R12()
  173.         rea.setControlRodLevel(1, rea.getControlRodLevel(1)-5)
  174. end
  175. function R13()
  176.         rea.setControlRodLevel(1, rea.getControlRodLevel(1)-1)
  177. end
  178. function R14()
  179.         rea.setControlRodLevel(1, rea.getControlRodLevel(1)+10)
  180. end
  181. function R15()
  182.         rea.setControlRodLevel(1, rea.getControlRodLevel(1)+5)
  183. end
  184. function R16()
  185.         rea.setControlRodLevel(1, rea.getControlRodLevel(1)+1)
  186. end
  187.   --Control Rod 2
  188. function R21()
  189.         rea.setControlRodLevel(2, rea.getControlRodLevel(2)-10)
  190. end
  191. function R22()
  192.         rea.setControlRodLevel(2, rea.getControlRodLevel(2)-5)
  193. end
  194. function R23()
  195.         rea.setControlRodLevel(2, rea.getControlRodLevel(2)-1)
  196. end
  197. function R24()
  198.         rea.setControlRodLevel(2, rea.getControlRodLevel(2)+1)
  199. end
  200. function R25()
  201.         rea.setControlRodLevel(2, rea.getControlRodLevel(2)+5)
  202. end
  203. function R26()
  204.         rea.setControlRodLevel(2, rea.getControlRodLevel(2)+10)
  205. end
  206.   --Control Rod 3
  207. function R31()
  208.         rea.setControlRodLevel(3, rea.getControlRodLevel(3)-10)
  209. end
  210. function R32()
  211.         rea.setControlRodLevel(3, rea.getControlRodLevel(3)-5)
  212. end
  213. function R33()
  214.         rea.setControlRodLevel(3, rea.getControlRodLevel(3)-1)
  215. end
  216. function R34()
  217.         rea.setControlRodLevel(3, rea.getControlRodLevel(3)+1)
  218. end
  219. function R35()
  220.         rea.setControlRodLevel(3, rea.getControlRodLevel(3)+5)
  221. end
  222. function R36()
  223.         rea.setControlRodLevel(3, rea.getControlRodLevel(3)+10)
  224. end
  225.   --Control Rod 4
  226. function R41()
  227.         rea.setControlRodLevel(4, rea.getControlRodLevel(4)-10)
  228. end
  229. function R42()
  230.         rea.setControlRodLevel(4, rea.getControlRodLevel(4)-5)
  231. end
  232. function R43()
  233.         rea.setControlRodLevel(4, rea.getControlRodLevel(4)-1)
  234. end
  235. function R44()
  236.         rea.setControlRodLevel(4, rea.getControlRodLevel(4)+1)
  237. end
  238. function R45()
  239.         rea.setControlRodLevel(4, rea.getControlRodLevel(4)+5)
  240. end
  241. function R46()
  242.         rea.setControlRodLevel(4, rea.getControlRodLevel(4)+10)
  243. end
  244.   --Control Rod 5
  245. function R51()
  246.         rea.setControlRodLevel(5, rea.getControlRodLevel(5)-10)
  247. end
  248. function R52()
  249.         rea.setControlRodLevel(5, rea.getControlRodLevel(5)-5)
  250. end
  251. function R53()
  252.         rea.setControlRodLevel(5, rea.getControlRodLevel(5)-1)
  253. end
  254. function R54()
  255.         rea.setControlRodLevel(5, rea.getControlRodLevel(5)+1)
  256. end
  257. function R55()
  258.         rea.setControlRodLevel(5, rea.getControlRodLevel(5)+5)
  259. end
  260. function R56()
  261.         rea.setControlRodLevel(5, rea.getControlRodLevel(5)+10)
  262. end
  263.   --Other buttons
  264. function OnOff()
  265.         if rea.getActive == true then
  266.                 rea.setActive(false)
  267.         else
  268.                 rea.setActive(true)
  269.         end
  270. end
  271.  
  272. function stopProgram()
  273.   SD = true
  274. end
  275.  
  276. --Progress bar updates and control rod control
  277. local SD = false
  278. while SD == false do
  279.   clear()
  280.    
  281.   --Main Title
  282.     centerText("A.R.C.S.", 1, false, 0, 0)
  283.          
  284.   --Power Bar
  285.     centerText('energy Stored', 4, true, rea.getEnergyStored(), 10000000)
  286.     drawProg(12, 5, 60, 1, rea.getEnergyStored(), 10000000, colors.green, colors.red)
  287.          
  288.   --Stored Fuel
  289.     centerText('Fuel Stored', 6, true, rea.getFuelAmount(), rea.getFuelAmountMax())
  290.     drawProg(12, 7, 60, 1, rea.getFuelAmount(), rea.getFuelAmountMax(), colors.green, colors.red)
  291.          
  292.   --Control Rod 1
  293.     centerText('Control Rod 1 Insertion', 8, true, rea.getControlRodLevel(0), 100)
  294.     drawProg(12, 9, 60, 1, rea.getControlRodLevel(0), 100, colors.green, colors.red)
  295.          
  296.   --Control Rod 2
  297.     centerText('Control Rod 2 Insertion', 10, true, rea.getControlRodLevel(1), 100)
  298.     drawProg(12, 11, 60, 1, rea.getControlRodLevel(1), 100, colors.green, colors.red)
  299.          
  300.   --Control Rod 3
  301.     centerText('Control Rod 3 Insertion', 12, true, rea.getControlRodLevel(2), 100)
  302.     drawProg(12, 13, 60, 1, rea.getControlRodLevel(2), 100, colors.green, colors.red)
  303.          
  304.   --Control Rod 4
  305.     centerText('Control Rod 4 Insertion', 14, true, rea.getControlRodLevel(3), 100)
  306.     drawProg(12, 15, 60, 1, rea.getControlRodLevel(3), 100, colors.green, colors.red)
  307.      
  308.   --Control Rod 5
  309.     centerText('Control Rod 5 Insertion', 16, true, rea.getControlRodLevel(4), 100)
  310.     drawProg(12, 17, 60, 1, rea.getControlRodLevel(4), 100, colors.green, colors.red)
  311.          
  312.   --Other Things
  313.     getClick()
  314.     sleep(0.1)
  315. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement