Advertisement
Good_Pudge

Reactor Control [OC]

Aug 19th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.69 KB | None | 0 0
  1. --Подключаем нужные модули--
  2. local com = require("component")
  3. local gpu = com.gpu
  4. local term = require("term")
  5. local kb = require("keyboard")
  6. local color = require("colors")
  7. local br = com.br_reactor
  8. local comp = require("computer")
  9. local fs = require("filesystem")
  10.  
  11.  
  12. --Сохранение старых настроек--
  13. local OldB = gpu.getBackground()
  14. local OldF = gpu.getForeground()
  15. local OldW,OldH = gpu.getResolution()
  16.  
  17. --Объявление функций--
  18.  
  19. --"Текстовая коробка"--
  20. function textBox(x,y,text,colorF,colorB)
  21.   if colorB ~= nil then
  22.     gpu.setBackground(colorB,true)
  23.   end
  24.  
  25.   if colorF ~= nil then
  26.     gpu.setForeground(colorF,true)
  27.   end
  28.  
  29.   gpu.set(x,y,tostring(text))
  30. end
  31.  
  32. --Индикация температуры обшивки--
  33. function checkCT(CT,Y)
  34.   if CT < 1000 then
  35.     gpu.setBackground(color.gray,true)
  36.     gpu.fill(26,Y,4,1," ")
  37.     textBox(26,Y,CT,color.green)
  38.   elseif CT > 1000 and CT < 1500 then
  39.     gpu.setBackground(color.gray,true)
  40.     gpu.fill(26,Y,4,1," ")
  41.     textBox(26,Y,CT,color.yellow)
  42.   elseif CT > 1500 then
  43.     gpu.setBackground(color.gray,true)
  44.     gpu.fill(26,Y,4,1," ")
  45.     textBox(26,Y,CT,color.red)
  46.   end
  47. end
  48.  
  49. --Индикация температуры стержней--
  50. function checkFT(FT,Y)
  51.     if FT < 1500 then
  52.         gpu.setBackground(color.gray,true)
  53.         gpu.fill(27,Y,4,1," ")
  54.         textBox(27,Y,FT,color.green)
  55.     elseif FT < 2000 then
  56.         gpu.setBackground(color.gray,true)
  57.         gpu.fill(27,Y,4,1," ")
  58.         textBox(27,Y,FT,color.yellow)
  59.     elseif FT > 2000 then
  60.         gpu.setBackground(color.gray,true)
  61.         gpu.fill(27,Y,4,1," ")
  62.         textBox(27,Y,FT,color.red)
  63.     end
  64. end
  65.  
  66. --Отрисовка линии отображения--
  67. function drawLoadLine(x,y,weight,heidht,Value,colorB)
  68.     gpu.setBackground(color.silver,true)
  69.     gpu.fill(x,y,weight,heidht," ")
  70.    
  71.     gpu.setBackground(colorB,true)
  72.     gpu.fill(x,y,weight/10*Value,heidht," ")
  73. end
  74.  
  75. --Индикация статуса реактора--
  76. function checkOnOff()
  77.   if br.getActive() then
  78.     gpu.setBackground(color.green,true)
  79.     gpu.setForeground(color.blue,true)
  80.     gpu.set(5,24," ON ")
  81.     gpu.setBackground(color.gray,true)
  82.     gpu.setForeground(color.blue,true)
  83.     gpu.set(9,24," OFF ")
  84.   else
  85.     gpu.setBackground(color.red,true)
  86.     gpu.setForeground(color.blue,true)
  87.     gpu.set(9,24," OFF ")
  88.     gpu.setBackground(color.gray,true)
  89.     gpu.setForeground(color.blue,true)
  90.     gpu.set(5,24," ON ")
  91.   end
  92. end
  93.  
  94. --Ограничение линни отображения--
  95. function borderLoadLine(maxT,FT,CT)
  96.   if FT > maxT then
  97.     gpu.setBackground(color.gray,true)
  98.     gpu.fill(75,18,5,1," ")
  99.   end
  100.  
  101.   if CT > maxT then
  102.     gpu.setBackground(color.gray,true)
  103.     gpu.fill(75,18,5,1," ")
  104.   end
  105. end
  106.  
  107. function checkEnergy(x,y,ES)
  108.     SES = string.len(ES)
  109.     gpu.setBackground(color.gray,true)
  110.     gpu.setForeground(color.blue,true)
  111.     gpu.fill(x/2-(SES+2)/2,y,10,1," ")
  112.     gpu.set(x/2-(SES+2)/2,y,tostring(ES).."RF")
  113. end
  114.  
  115. function clearLine(Y,colorB)
  116.     if colorB ~= nil then
  117.         gpu.setBackground(colorB,true)
  118.     end
  119.  
  120.     term.setCursor(1,Y)
  121.     term.clearLine()
  122. end
  123.  
  124. --Установка новых настроек--
  125. gpu.setResolution(80,25)
  126. gpu.setBackground(color.gray,true)
  127. gpu.setForeground(color.blue,true)
  128. term.clear()
  129.  
  130. --Программа выбора реактора--
  131. gpu.setBackground(color.blue,true)
  132. gpu.fill(1,2,80,1," ")
  133. textBox(32.5,2,"Reactor Control",color.gray)
  134. textBox(29.5,4,"Выберите тип реактора",color.blue,color.gray)
  135. textBox(29,11,"Энергетический реактор",color.gray,color.blue)
  136. textBox(32.5,13,"Паровой реактор",color.gray,color.blue)
  137. textBox(70,24,"Выйти")
  138.  
  139. while true do
  140.     local type,_,sX,sY,_ = comp.pullSignal(0.1)
  141.    
  142.     if type == "touch" then
  143.         if sX >= 29 and sX <= 51 then
  144.             if sY >= 11 and sY <= 12 then
  145.                
  146.                 clearLine(4)
  147.                 clearLine(11,color.gray)
  148.                 clearLine(13)
  149.                
  150.                 goto EnergyReactor
  151.             end
  152.         end
  153.        
  154.         if sX >= 32 and sX <= 48 then
  155.             if sY >= 13 and sY <= 14 then
  156.                 goto SteamReactor
  157.             end
  158.         end
  159.     end
  160. end
  161.  
  162.  
  163. --Программа энергетического реактора--
  164. ::EnergyReactor::
  165. textBox(32,4,"Общая информация",color.blue,color.gray)
  166.  
  167. clearLine(6,color.blue)
  168. textBox(5,15,"Температура стержней: ",nil,color.gray)
  169. textBox(5,18,"Температура обшивки: ")
  170. textBox(5,24," ON ")
  171. textBox(9,24," OFF ")
  172.  
  173. while true do
  174.   local FT = math.floor(br.getFuelTemperature())
  175.   local CT = math.floor(br.getCasingTemperature())
  176.   local ES = math.floor(br.getEnergyStored())
  177.  
  178.   local type,_,sX,sY,_ = comp.pullSignal(0.1)
  179.  
  180.  
  181.   checkOnOff()
  182.   checkFT(FT,15)
  183.   drawLoadLine(5,16,70,1,FT/200,color.blue)
  184.  
  185.   checkCT(CT,18)
  186.   drawLoadLine(5,19,70,1,CT/200,color.blue)
  187.  
  188.   checkEnergy(40,24,ES)
  189.   drawLoadLine(5,22,70,1,ES/1000000,color.red)
  190.  
  191.  
  192.  
  193.   borderLoadLine(2000,FT,CT)
  194.  
  195.   --Реализация кнопок--
  196.   if type == "touch" then
  197.     --Кнопка выйти--
  198.     if sX >= 70 and sX <= 75 then
  199.         if sY >= 24 and sY <= 25 then
  200.             goto Exit
  201.         end
  202.     end
  203.    
  204.     --Кнопка вкл.--
  205.     if sX >= 5 and sX <= 9 then
  206.         if sY >= 24 and sY <= 25 then
  207.             br.setActive(true)
  208.         end
  209.     end
  210.    
  211.     --Кнопка выкл.--
  212.     if sX >= 9 and sX <= 14 then
  213.         if sY >= 24 and sY <= 25 then
  214.             br.setActive(false)
  215.         end
  216.     end
  217.   end
  218. end
  219.  
  220. --Программа парового реактора--
  221. ::SteamReactor::
  222. textBox(32,4,"Общая информация")
  223. textBox(5,6,"Температура стержней: ",color.blue,color.gray)
  224. textBox(5,8,"Температура обшивки: ")
  225. textBox(5,10,"Количество пара: ")
  226. textBox(5,24," ON ")
  227. textBox(9,24," OFF ")
  228.  
  229. while true do
  230.     local FT = math.floor(br.getFuelTemperature())
  231.     local CT = math.floor(br.getCasingTemperature())
  232.     local HF = br.getHotFluidAmount()
  233.  
  234.     local type,_,sX,sY,_ = comp.pullSignal(0.1)
  235.    
  236.     checkOnOff()
  237.     checkCT(CT,8)
  238.     checkFT(FT,8)
  239.    
  240.     drawLoadLine(5,22,70,1,HF/400,color.blue)
  241.     drawLoadLine(5,20,70,1,CT/200,color.blue)
  242.    
  243.     borderLoadLine(4000,FT,CT)
  244.    
  245.     --Реализация кнопок--
  246.     if type == "touch" then
  247.         --Кнопка выйти--
  248.         if sX >= 70 and sX <= 75 then
  249.             if sY >= 24 and sY <= 25 then
  250.                 goto Exit
  251.             end
  252.         end
  253.    
  254.         --Кнопка вкл.--
  255.         if sX >= 5 and sX <= 9 then
  256.             if sY >= 24 and sY <= 25 then
  257.                 br.setActive(true)
  258.             end
  259.         end
  260.    
  261.         --Кнопка выкл.--
  262.         if sX >= 9 and sX <= 14 then
  263.             if sY >= 24 and sY <= 25 then
  264.                 br.setActive(false)
  265.             end
  266.         end
  267.     end
  268. end
  269.    
  270. --Возвращение предыдущих настроек--
  271. ::Exit::
  272. gpu.setBackground(OldB)
  273. gpu.setForeground(OldF)
  274. gpu.setResolution(OldW,OldH)
  275. term.clear()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement