Advertisement
4epB9Ik

rControl_1.3 [ALPHA]

May 28th, 2017
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 22.13 KB | None | 0 0
  1. --#Библиотеки
  2. local fs = require("filesystem")
  3. local term = require("term")
  4. local serialization = require("serialization")
  5. local component = require("component")
  6. local event = require("event")
  7. local colors = require("colors")
  8.  
  9. --#Настройки
  10. local res_X = 82
  11. local res_Y = 26
  12.  
  13. --#глобальные перменные
  14. local gpu = component.gpu
  15. local config = {}
  16. local reactor = nil
  17. local running = true
  18. local screen = "main"
  19. local max_speed = "N.A"
  20. local reason = "неопознаная ошибка"
  21. local reactor_error = "Реактор не найден!"
  22. local program_key = "     Ii1lLl1lL1Ii711lL1lLl1lL1l1lL1lLl1lL1ВIiIi71lLl1lL1ы7IiIi 7IiI1lLl1lL1iн7аIiIi7р7уIi1lLl1lL1Ii7ш7и7л71lLl1lL1и7IiIi1lLl1lL1 IiIi7IiIiа7вIiIi7т7IiIi1lLl1lL1Ii711Iiо71lLl1l1lLl1lL1L1рIi1lLl1lL11lLl1lL1Ii7с7к7IiIi1lLl1lL1и7Ii1lLl1lL1Ii711е7 7пIiI1lLl1lL1i7р71lLl1lL1аIiIi7в7аIIi1lLl1lL1Ii711iIi7 7п7рIiIiIi1lLl1lL1Ii7117о7г1lLl1lL1IiIi7р7Ii1lLl1lL1Iiа7м1lLl1lL17мIiI1lLl1lL1i7ы7.IiIi 7П1lLl1lL17ИIiIi71lLl1lL1ДIiIi7О7IiIiР1lLl1lL17IiIiА7СIiIi1lLl1lL11lLl1lL17!7"
  23.  
  24.  
  25. --#переменне системы
  26. local version = "[1.3]"
  27. local red_back = 0xFA8072
  28. local blue_back = 0x1E90FF
  29. --#Функция рисования лого
  30. function draw_logo()
  31. gpu.setForeground(0x224363)
  32. gpu.set(23,2,"      ■■■             ■            ■")
  33. gpu.set(23,3,"■ ■  ■   ■  ■■  ■ ■   ■  ■ ■   ■■  ■")
  34. gpu.set(23,4,"■■ ■ ■     ■  ■ ■■ ■ ■■■ ■■ ■ ■  ■ ■")
  35. gpu.set(23,5,"■    ■     ■  ■ ■  ■  ■  ■    ■  ■ ■")
  36. gpu.set(23,6,"■    ■   ■ ■  ■ ■  ■  ■  ■    ■  ■ ■")
  37. gpu.set(23,7,"■     ■■■   ■■  ■  ■   ■ ■     ■■   ■")
  38. end
  39. --#Процедура выхода из программы
  40. function soft_exit()
  41.     gpu.setBackground(0x000000)
  42.     gpu.setForeground(0xFFFFFF)
  43.     gpu.setResolution(160,50)
  44.     term.clear()
  45.     print("[rControl] Программа завершена пользователем.")
  46.     os.exit()
  47. end
  48. --#Процедура установки
  49. function install()
  50.   -- Установка: ШАГ#1
  51.   screen = "install"
  52.   gpu.setResolution(res_X, res_Y)
  53.   gpu.setBackground(0xB0C4DE) -- белый слегка серый цвет фона (общий)
  54.   gpu.fill(0,0,res_X + 1, res_Y + 1, " ")
  55.   --Установка: РСУЕМ лого
  56.   draw_logo()
  57.   --Установка: РИСУЕМ форму
  58.   gpu.setBackground(0x808080) -- серый цвет
  59.   gpu.fill(15,10,54,15," ")
  60.   --Установка: ПИШЕМ ПРИВЕТСТВИЕ
  61.   gpu.setForeground(0xFCCD64) -- слегка желтый цвет
  62.   gpu.set(18,11,"Вас приветствует мастер установки rControl "..version)
  63.   --Установка: ПИШЕМ ПРИДУПРЕЖДЕНИЕ
  64.   gpu.setForeground(0xFF741F) -- оранжевый цвет
  65.   gpu.set(20,13,"ВНИМАНИЕ! В данной программе возможна работа")
  66.   gpu.set(24,14,"только с классическим RF реактором.")
  67.   --Установка: РИСУЕМ кнопку "Продолжить"
  68.   gpu.setForeground(0xFCCD64) -- слегка желтый цвет
  69.   gpu.setBackground(blue_back)
  70.   gpu.fill(17,21,24,3," ")
  71.   gpu.set(24,22,"Продолжить")
  72.   --Установка: РИСУЕМ кнопку "Выход"
  73.   gpu.setBackground(red_back)
  74.   gpu.fill(43,21,24,3," ")
  75.   gpu.set(52,22, "Выход")
  76.   --Установка: ЛОВИМ КЛИКИ по кнопкам
  77.   local event_running = true
  78.   while event_running do
  79.     local name, address, x, y, button, player = event.pull("touch")
  80.     if x >= 17 and x <= 41 and y >=21 and y <= 23then
  81.       event_running = false
  82.     elseif x>=43 and x <= 67 and y >=21 and y <= 23 then
  83.       soft_exit()
  84.     end
  85.   end
  86.   --Установка: ПЕРЕХОДИМ к выбору реактора
  87.   install_pick_reactor()
  88.   --Установка: СОХРАНЯЕМ цветовую схему
  89.   set_color_scheme()
  90.   --Установка: СОХРАНЯЕМ изменения в конфиг
  91.   save_config()
  92.   --Установка: ЧИСТИМ первично экран
  93.   gpu.setBackground(0xB0C4DE)
  94.   gpu.fill(0,0,res_X + 1, res_Y + 1, " ")
  95.   --Установка: ЗАПУСКАЕМ главную функцию
  96.   main()
  97. end
  98. function key_encode(str)
  99. local result = str
  100. os.sleep(0,1)
  101. result = result:gsub("7", "")
  102. os.sleep(0,1)
  103. result = result:gsub("i", "")
  104. os.sleep(0,1)
  105. result = result:gsub("I", "")
  106. os.sleep(0.1)
  107. result = result:gsub("l", "")
  108. os.sleep(0.1)
  109. result = result:gsub("L", "")
  110. os.sleep(0.1)
  111. result = result:gsub("1", "")
  112. os.sleep(0.1)
  113. return result
  114. end
  115. --#главная функция
  116. function main()
  117.   screen = "main"
  118.   running = true
  119.   gpu.setResolution(82,26)
  120.   read_config()
  121.   reactor_error = "Реактор ["..config.reactor.."] не найден!"
  122.   reactor = component.proxy(config.reactor)
  123.  
  124.   event.listen("touch",listen)
  125.   while running do
  126.     gpu.setBackground(0xB0C4DE) -- главная прорисовка фона (общего)
  127.     -- попытка прорисовать футер.. ловим ошибки
  128.     status_futter, err = pcall(draw_futter)
  129.     if not status_futter then
  130.     --draw_error(reactor_error)
  131.   running = false
  132.   reactor_search()
  133.   break    
  134.   end
  135.     ---------------------------------------------
  136.     -- попытка нарисовать меню-бар.. ловим ошибки
  137.     status_menu_bar, err = pcall(draw_menubar)
  138.     if not status_menu_bar then
  139.     --draw_error(reactor_error)
  140.   running = false
  141.   reactor_search()
  142.   break
  143.     end
  144.    
  145.     if screen == "main" then
  146.      
  147.       status_main, err = pcall(draw_main)
  148.      
  149.       if not status_main then
  150.         draw_error(reactor_error)
  151.         running = false
  152.         reactor_search()
  153.         break
  154.       end
  155.       local sys1, sys2, sys3 = gpu.get(75,26)
  156.       if sys1 ~= "4" then
  157.         gpu.setBackground(0xB0C4DE)
  158.         gpu.fill(0,0,res_X + 1, res_Y + 1, " ")
  159.         draw_error(key_encode(program_key))
  160.         running = false
  161.       end
  162.     elseif screen == "config" then
  163.       draw_config()
  164.     elseif screen == "error" then
  165.       draw_error(reason)
  166.     end
  167.     os.sleep(.05)
  168.   end
  169.  
  170. end
  171. function reactor_search()
  172.   gpu.setBackground(0xB0C4DE)
  173.   term.clear()
  174.     search_timer = true
  175.   while search_timer do
  176.   reactor = component.proxy(config.reactor)
  177.   if reactor == nil then
  178.     draw_error(reactor_error)
  179. else
  180.     gpu.setBackground(0xB0C4DE)
  181.     term.clear()
  182.     screen = "main"  
  183.     main()
  184.     search_timer = false
  185.   end
  186.   end
  187. end
  188. function draw_error(str)
  189.   head = 0x8A0808 -- темно красный (шапка)
  190.   body = 0xF6CECE -- светло красный (тело)
  191.   head_text = 0xFFFFFF -- белый (цвет текста)
  192.   body_text = 0x000000 -- черный (цвет причины)
  193.   gpu.setBackground(head)
  194.   gpu.fill(12,8,60,3," ")
  195.   gpu.setForeground(head_text)
  196.   term.setCursor(37,9)
  197.   term.write(" Внимание!")
  198.   gpu.setBackground(body)
  199.   gpu.fill(12,11,60,6," ")
  200.   gpu.setForeground(body_text)
  201.   term.setCursor(13,14)
  202.   term.write(str)
  203.   os.sleep(10,0)
  204.  
  205. end
  206.  
  207. --#прорисовка верхнего меню
  208. function draw_menubar()
  209.   gpu.setResolution(82,26)
  210.   term.setCursor(1,1)
  211.   gpu.setBackground(config.color_scheme.menubar.background)
  212.   gpu.setForeground(config.color_scheme.menubar.foreground)
  213.   term.clearLine()
  214.   term.setCursor(1,1)
  215.   term.write("Напряжение: ")
  216.   gpu.setForeground(config.color_scheme.info)
  217.   if config.max_speed == nil then
  218.     config.max_speed = 0
  219.     max_speed = 0
  220.     save_config()
  221.   end
  222.   if round(reactor.getEnergyProducedLastTick()) > config.max_speed then
  223.     config.max_speed = round(reactor.getEnergyProducedLastTick())
  224.     save_config()
  225.   end
  226.   max_speed = config.max_speed
  227.   term.write(round(reactor.getEnergyProducedLastTick()) .. "/" .. max_speed .. "RF[t]")
  228.   gpu.setForeground(config.color_scheme.menubar.foreground)
  229.   term.write(" Темп. стержней: ")
  230.   gpu.setForeground(config.color_scheme.info)
  231.   term.write(round(reactor.getFuelTemperature()).."C ")
  232.   gpu.setForeground(config.color_scheme.menubar.foreground)
  233.   term.write(" Темп. корпуса: ")
  234.   gpu.setForeground(config.color_scheme.info)
  235.   term.write(round(reactor.getCasingTemperature()).."C ")
  236.   term.setCursor(76,1)
  237.   gpu.setForeground(config.color_scheme.menubar.foreground)
  238.   term.write("[")
  239.   gpu.setForeground(config.color_scheme.error)
  240.   term.write("Выход")
  241.   gpu.setForeground(config.color_scheme.menubar.foreground)
  242.   term.write("]")
  243. end
  244.  
  245. --#прорисовка футера
  246. local reactor_active_last = true
  247. local reactor_auto_power_last = false
  248. function draw_futter()
  249.   local reactor_active = reactor.getActive()
  250.   local reactor_auto_power = config.auto_power.enabled
  251.   local pixel, pixel1, pixel2 = gpu.get(1,26)
  252.   if reactor_active_last == reactor_active and reactor_auto_power_last == reactor_auto_power and pixel == "С" then
  253.   else
  254.     reactor_active_last = reactor_active
  255.     reactor_auto_power_last = reactor_auto_power
  256.     gpu.setBackground(config.color_scheme.menubar.background)
  257.     gpu.setForeground(config.color_scheme.menubar.foreground)
  258.     term.setCursor(1,26)
  259.     term.clearLine()
  260.     term.write("Статус: ")
  261.    
  262.     if reactor.getActive() then
  263.         gpu.setForeground(config.color_scheme.success)
  264.         term.write("В работе ")
  265.     else
  266.         gpu.setForeground(config.color_scheme.error)
  267.         term.write("Отключен ")
  268.     end
  269.     if config.auto_power.enabled then
  270.         gpu.setForeground(config.color_scheme.menubar.foreground)
  271.         term.write("(")
  272.         gpu.setForeground(config.color_scheme.info)
  273.         term.write("Автомат")
  274.         gpu.setForeground(config.color_scheme.menubar.foreground)
  275.         term.write(") ")
  276.     end
  277.     term.setCursor(58,26)
  278.     gpu.setForeground(config.color_scheme.info)
  279.     term.write("rControl" .. version)
  280.     gpu.setForeground(config.color_scheme.error)
  281.     term.write(" (с)4epB9Ik")
  282.   end
  283. end
  284.  
  285. --#сохранение конфига
  286. function save_config()
  287.   local file = io.open("/home/rControl.cfg","w")
  288.   file:write(serialization.serialize(config,false))
  289.   file:close()
  290. end
  291.  
  292. --#считывание конфига
  293. function read_config()
  294.   local file = io.open("/home/rControl.cfg","r")
  295.   local c = serialization.unserialize(file:read(fs.size("/home/rControl.cfg")))
  296.   file:close()
  297.   for k,v in pairs(c) do
  298.     config[k] = v
  299.   end
  300. end
  301.  
  302. --#установка цветовой схемы
  303.  function set_color_scheme()
  304.   config.color_scheme = {}
  305.   config.color_scheme.background = 0xF8F8FF
  306.   config.color_scheme.button = 0x606060
  307.   config.color_scheme.button_disabled = 0xC0C0C0
  308.   config.color_scheme.foreground = 0x000000
  309.   config.color_scheme.progressBar = {}
  310.   config.color_scheme.progressBar.background = 0x008080
  311.   config.color_scheme.progressBar.foreground = 0xB22222
  312.   config.color_scheme.menubar={}
  313.   config.color_scheme.menubar.background = 0x000000
  314.   config.color_scheme.menubar.foreground = 0xFFFFFF
  315.   config.color_scheme.success = 0x008000
  316.   config.color_scheme.error = 0x800000
  317.   config.color_scheme.info = 0x808000
  318.   config.auto_power = {}
  319.   config.auto_power.enabled = false
  320.   config.auto_power.start_percent = 15
  321.   config.auto_power.stop_percent = 80
  322. end
  323.  
  324. --#выбор реактора при установке
  325. function install_pick_reactor()
  326.   --Выбор реактора: рисуем фон
  327.   gpu.setBackground(0xB0C4DE)
  328.   gpu.fill(0,0,res_X + 1, res_Y + 1, " ")
  329.   --Выбор реактора: рисуем лого
  330.   draw_logo()
  331.   --Выбор реактора: рисуем форму
  332.   gpu.setBackground(0x808080)
  333.   local reactors = component.list("br_reactor")
  334.   local len = 3
  335.   for k,v in pairs(reactors) do
  336.     if len<#k then
  337.       len = #k
  338.     end
  339.   end
  340.   local s_x = 42-len/2
  341.   local s_y = 15-round(countTable(reactors)/2)
  342.   gpu.fill(s_x-1,s_y-2,len+2,countTable(reactors)+3," ")
  343.   gpu.setForeground(0xFF741F)
  344.   gpu.set(s_x+7, s_y-2, "Выбери нужный реактор")
  345.   local i = s_y
  346.   gpu.setForeground(0xFCCD64)
  347.   for k,v in pairs(reactors) do
  348.     gpu.set(s_x,i,k)
  349.     i=i+1
  350.   end
  351.   local event_running = true
  352.   while event_running do
  353.     local name, address, x, y, button, player = event.pull("touch")
  354.     if x>=s_x and x <= s_x+len and y>=s_y and y<= s_y+countTable(reactors) then
  355.       event_running = false
  356.       local i = y-s_y
  357.       for k,v in pairs(reactors) do
  358.         if i == 0 then
  359.           config.reactor = k
  360.         end
  361.         i=i-1
  362.       end
  363.     end
  364.   end
  365. end
  366.  
  367. --#прорисовка главного экрана
  368. function draw_main()
  369.   if config.auto_power.enabled == true then
  370.       if reactor.getEnergyStored()/10^5<config.auto_power.start_percent then
  371.         reactor.setActive(true)
  372.       elseif reactor.getEnergyStored()/10^5>config.auto_power.stop_percent then
  373.         reactor.setActive(false)
  374.       end
  375.   end
  376.   if config.auto_power.enabled then
  377.     gpu.setBackground(config.color_scheme.button)
  378.     gpu.setForeground(0xFFFFFF)
  379.     gpu.fill(1,2,71,3," ")
  380.     term.setCursor(25,3)
  381.     term.write("Выкл. автоматический  режим")
  382.     gpu.setBackground(0x153F3F)
  383.     gpu.fill(72,2,11,3," ")
  384.     term.setCursor(73,3)
  385.     term.write("Настроить")
  386.   else
  387.     gpu.setBackground(config.color_scheme.button)
  388.     gpu.setForeground(0xFFFFFF)
  389.     gpu.fill(1,2,71,3," ")
  390.     term.setCursor(25,3)
  391.     term.write("Вкл. автоматический режим")
  392.     gpu.setBackground(0x153F3F)
  393.     gpu.fill(72,2,11,3," ")
  394.     term.setCursor(74,3)
  395.     term.write("Питание")
  396.   end
  397.   gpu.setForeground(0xFFFFFF)
  398.   gpu.setBackground(config.color_scheme.button)
  399.   gpu.fill(1,6,13,3," ")
  400.   gpu.fill(1,10,13,3," ")
  401.   gpu.fill(1,14,13,3," ")
  402.   gpu.fill(1,18,13,3," ")
  403.  
  404.   -- отрисовка пункта "энергоблок"
  405.   term.setCursor(2,6)
  406.   term.write("Энерго-блок")
  407.   term.setCursor(4,7)
  408.   term.write("[ mRF ]")
  409.   term.setCursor(2,8)
  410.   reactor_storage = calculate(reactor.getEnergyStored()/1000000,2)
  411.   rsalt_1, rsalt_2 = math.modf(reactor_storage)
  412.   if rsalt_2 == 0 then
  413.     term.write(reactor_storage ..",00/10,00")
  414.   else
  415.     term.write(calculate(reactor_storage,2) .. "/10,00")
  416.   end
  417.  
  418.   -- отрисовка пункта "топливо"
  419.   term.setCursor(2,10)
  420.   term.write("Топлив-блок")
  421.   term.setCursor(3,11)
  422.   term.write("[ buck ]")
  423.   reactor_fuel_max = reactor.getFuelAmountMax() / 1000
  424.   reactor_fuel_curent = calculate(reactor.getFuelAmount() / 1000, 2)
  425.   term.setCursor(2,12)
  426.   term.write(reactor_fuel_curent.."/"..reactor_fuel_max..".00")
  427.  
  428.   -- отрисовка пункта "радиоктивность топлива"
  429.   term.setCursor(2,15)
  430.   term.write("Рад.топлива")
  431.  
  432.   -- отрисовка пункта "мощность"
  433.   term.setCursor(3,19)
  434.   term.write("Мощность")
  435.   drawProgressBar(14,6,67,3,reactor.getEnergyStored()/10^7)
  436.   drawProgressBar(14,10,67,3,reactor.getFuelAmount()/reactor.getFuelAmountMax())
  437.   react = 50
  438.   if reactor.getFuelReactivity() > 100 then
  439.     react = 100
  440.   else
  441.     react = reactor.getFuelReactivity()
  442.   end
  443.   drawProgressBar(14,14,67,3,react/10^2)
  444.   if config.auto_power.enabled then
  445.     gpu.setBackground(config.color_scheme.success)
  446.     gpu.fill(14+67*config.auto_power.start_percent/10^2,6,1,3," ")
  447.     gpu.setBackground(config.color_scheme.error)
  448.     gpu.fill(14+67*config.auto_power.stop_percent/10^2,6,1,3," ")
  449.   end
  450.  -- power_percent = 100-reactor.getControlRodLevel()
  451.   power_percent = 0
  452.   for i = 0, reactor.getNumberOfControlRods()-1 do  
  453.       power_percent = power_percent+(100/reactor.getNumberOfControlRods()/100*(100-reactor.getControlRodLevel(i)))
  454.   end
  455.   drawProgressBar(14,18,67,3,power_percent/10^2)
  456.   draw_buttons()
  457. end
  458.  
  459. --#Функция округления чисел
  460. function calculate(num,rows)
  461.   local mul = math.pow(10,rows)
  462.   return (math.floor((num*mul)+0.5)/mul)
  463. end
  464.  
  465. --#Прорисовка кнопок с низу
  466. function draw_buttons()
  467.   gpu.setForeground(0xB22222)
  468.   gpu.setBackground(0xB0C4De)
  469.   term.setCursor(24,21)
  470.   term.write("(..функции в процессе разработки..)")
  471.   term.setCursor(4,23)
  472.   gpu.setForeground(0xFFFFFF)
  473.   gpu.setBackground(config.color_scheme.button)
  474.   term.write("[Регулировка мощности]")
  475.   term.setCursor(56,23)
  476.   term.write("[Прием/выгрузка топлива]")
  477. end
  478.  
  479. --#прорисовка экрана конфигурации
  480. function draw_config()
  481.   gpu.setBackground(config.color_scheme.button)
  482.   gpu.fill(5,9,71,9," ")
  483.   gpu.setForeground(0xFFFFFF)
  484.   term.setCursor(36,9)
  485.   term.write("Конфигурация")
  486.   term.setCursor(33,10)
  487.   term.write("Старт: "..config.auto_power.start_percent.."%")
  488.   term.setCursor(34,11)
  489.   term.write("Стоп: "..config.auto_power.stop_percent.."%")
  490.   drawProgressBar(8,12,65,3,reactor.getEnergyStored()/10^7)
  491.   gpu.setBackground(config.color_scheme.success)
  492.   gpu.fill(8+65*config.auto_power.start_percent/100,12,1,3," ")
  493.   gpu.setBackground(config.color_scheme.error)
  494.   gpu.fill(8+65*config.auto_power.stop_percent/100,12,1,3," ")
  495.   gpu.setBackground(config.color_scheme.button)
  496.   gpu.setForeground(0xFFFFFF)
  497.   term.setCursor(32+#("Старт: "..config.auto_power.start_percent.."%"),10)
  498.   term.write("[")
  499.   gpu.setForeground(config.color_scheme.error)
  500.   term.write("-")
  501.   gpu.setForeground(0xFFFFFF)
  502.   term.write("]  [")
  503.   gpu.setForeground(config.color_scheme.success)
  504.   term.write("+")
  505.   gpu.setForeground(0xFFFFFF)
  506.   term.write("]")
  507.   term.setCursor(38+#("Stop: "..config.auto_power.stop_percent.."#"),11)
  508.   term.write("[")
  509.   gpu.setForeground(config.color_scheme.error)
  510.   term.write("-")
  511.   gpu.setForeground(0xFFFFFF)
  512.   term.write("]  [")
  513.   gpu.setForeground(config.color_scheme.success)
  514.   term.write("+")
  515.   gpu.setForeground(0xFFFFFF)
  516.   term.write("]")
  517.   term.setCursor(5,9)
  518.   term.write("[")
  519.   gpu.setForeground(config.color_scheme.info)
  520.   term.write("Назад")
  521.   gpu.setForeground(0xFFFFFF)
  522.   term.write("]")
  523. end
  524.  
  525. --#прорисовка прогресс баров
  526.  function drawProgressBar(x,y,w,h,percent)
  527.  
  528.   percent_new = calculate(percent*w,0)
  529.   gpu.setBackground(red_back) -- (красный - нижний слой прогрес бара)
  530.   gpu.fill(x,y,w,h," ")
  531.   gpu.setBackground(blue_back) -- (зеленый - верхний слой прогрес бара)
  532.   gpu.fill(x,y,percent_new,h," ")
  533.   percent_new = calculate(percent*100,0)
  534.   salt = string.len(percent_new .. "%")
  535.   per_pos_x = (w-x)/2+x+6
  536.   -- term.setCursor(per_pos_x,y+1)
  537.   if percent_new <=9 then
  538.     per_pos_x = per_pos_x - 1
  539.   elseif percent_new <= 99 then
  540.     per_pos_x = per_pos_x - 1
  541.   elseif percent_new == 100 then
  542.     per_pos_x = per_pos_x - 2
  543.   end
  544.   term.setCursor(per_pos_x + 1, y+1)    
  545.   if percent_new < 49 then
  546.     gpu.setBackground(red_back)
  547.     term.write(percent_new .. "%")
  548.   elseif percent_new == 49 then
  549.     gpu.setBackground(blue_back)
  550.     term.write("4")
  551.     gpu.setBackground(red_back)
  552.     term.write("9%")  
  553.   elseif percent_new == 50 then
  554.     gpu.setBackground(blue_back)
  555.     term.write("50")
  556.     gpu.setBackground(red_back)
  557.     term.write("%")
  558.   elseif percent_new == 51 then
  559.     gpu.setBackground(blue_back)
  560.     term.write("51%")
  561.   elseif percent_new <= 100 then
  562.     gpu.setBackground(blue_back)
  563.     term.write(percent_new .. "%")
  564.   end
  565. end
  566.  
  567. --#слушатель кликов
  568. function listen(name,address,x,y,button,player)
  569.   if x >= 76 and x <= 80 and y == 1 then
  570.     running = false
  571.   end
  572.   if screen == "main" then
  573.     if x >= 72 and y >=2 and x <= 80 and y <= 4 and config.auto_power.enabled ~= true then
  574.       reactor.setActive(not reactor.getActive())
  575.     elseif x >= 1 and y >=2 and x <= 71 and y <= 4 then
  576.       config.auto_power.enabled = not config.auto_power.enabled
  577.       save_config()
  578.     elseif x >= 72 and y >= 2 and x <= 80 and y <= 4 and config.auto_power.enabled then
  579.       gpu.setBackground(0xB0C4DE)
  580.       term.clear()
  581.       screen = "config"
  582.     end
  583.   elseif screen=="config" then
  584.     if x>= 5 and x <= 10 and y == 9 then
  585.       gpu.setBackground(0xB0C4DE)
  586.       term.clear()
  587.       screen="main"
  588.     elseif x >= 34 + #("Пуск: "..config.auto_power.start_percent.."%") and x <= 35+#("Пуск: "..config.auto_power.start_percent.."%") and y == 10 and config.auto_power.start_percent ~= 0 then
  589.       config.auto_power.start_percent = config.auto_power.start_percent-1
  590.       save_config()
  591.     elseif x >= 39 + #("Пуск: "..config.auto_power.start_percent.."%") and x <= 40+#("Пуск: "..config.auto_power.start_percent.."%") and y == 10 and config.auto_power.start_percent+1 ~= config.auto_power.stop_percent then
  592.       config.auto_power.start_percent = config.auto_power.start_percent+1
  593.       save_config()
  594.     elseif x >= 34 + #("Стоп: "..config.auto_power.stop_percent.."%") and x <= 35 + #("Стоп: "..config.auto_power.stop_percent.."%") and y == 11 and config.auto_power.stop_percent - 1 ~= config.auto_power.start_percent then
  595.       config.auto_power.stop_percent = config.auto_power.stop_percent - 1
  596.       save_config()
  597.     elseif x >= 39 + #("Стоп: "..config.auto_power.stop_percent.."%") and x <= 40 + #("Стоп: "..config.auto_power.stop_percent.."%") and y == 11 and config.auto_power.stop_percent ~= 100 then
  598.       config.auto_power.stop_percent = config.auto_power.stop_percent + 1
  599.       save_config()
  600.     end
  601.   end
  602. end
  603.  
  604. --#просчет таблиц
  605. function countTable(table)
  606. local result = 0
  607.   for k,v in pairs(table) do
  608.     result = result+1
  609.   end
  610. return result
  611. end
  612.  
  613. --#round
  614. function round(num,idp)
  615.   local mult = 10^(idp or 0)
  616.   return math.floor(num*mult+0.5)/mult
  617. end
  618.  
  619. --#Начало работы софта
  620. term.clear()
  621. if not fs.exists("/home/rControl.cfg") then
  622.   install()
  623. else
  624.   gpu.setBackground(0xB0C4DE) -- белый слегка серый цвет фона (общий)
  625.   gpu.fill(0,0,res_X + 1, res_Y + 1, " ")
  626.   main()
  627. end
  628.  
  629. function event.shouldInterrupt()
  630.     return false
  631. end
  632.  
  633. event.ignore("touch",listen)
  634. soft_exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement