Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -----BigReactor Control
- -----by jaranvil aka jared314
- -----Edited by Wolfdale276
- -----feel free to use and/or mondify this code
- -----------------------------------------------
- version = 2.2
- term.clear()
- -------------------FORMATTING-------------------------------
- function clear()
- mon.setBackgroundColor(colors.black)
- mon.clear()
- mon.setCursorPos(1,1)
- end
- function draw_text_term(x, y, text, text_color, bg_color)
- term.setTextColor(text_color)
- term.setBackgroundColor(bg_color)
- term.setCursorPos(x,y)
- write(text)
- end
- function draw_text(x, y, text, text_color, bg_color)
- mon.setBackgroundColor(bg_color)
- mon.setTextColor(text_color)
- mon.setCursorPos(x,y)
- mon.write(text)
- end
- function draw_line(x, y, length, color)
- mon.setBackgroundColor(color)
- mon.setCursorPos(x,y)
- mon.write(string.rep(" ", length))
- end
- function draw_line_term(x, y, length, color)
- term.setBackgroundColor(color)
- term.setCursorPos(x,y)
- term.write(string.rep(" ", length))
- end
- function progress_bar(x, y, length, minVal, maxVal, bar_color, bg_color)
- draw_line(x, y, length, bg_color) --backgoround bar
- local barSize = math.floor((minVal/maxVal) * length)
- draw_line(x, y, barSize, bar_color) --progress so far
- end
- function progress_bar_term(x, y, length, minVal, maxVal, bar_color, bg_color)
- draw_line_term(x, y, length, bg_color) --backgoround bar
- local barSize = math.floor((minVal/maxVal) * length)
- draw_line_term(x, y, barSize, bar_color) --progress so far
- end
- function button(x, y, length, text, txt_color, bg_color)
- draw_line(x, y, length, bg_color)
- draw_text((x+2), y, text, txt_color, bg_color)
- end
- function menu_bar()
- draw_line(1, 1, monX, colors.purple)
- draw_text(2, 1, "Power Tools Settings", colors.white, colors.purple)
- draw_line(1, 19, monX, colors.purple)
- draw_text(2, 19, " Reactor Control", colors.white, colors.purple)
- end
- function power_menu()
- draw_line(1, 2, 9, colors.gray)
- draw_line(1, 3, 9, colors.gray)
- draw_line(1, 4, 9, colors.gray)
- if active then
- draw_text(2, 2, "ON", colors.lightGray, colors.gray)
- draw_text(2, 3, "OFF", colors.white, colors.gray)
- else
- draw_text(2, 2, "ON", colors.white, colors.gray)
- draw_text(2, 3, "OFF", colors.lightGray, colors.gray)
- end
- draw_text(2, 4, "Auto", colors.white, colors.gray)
- end
- function tools_menu()
- draw_line(10, 2, 14, colors.gray)
- draw_line(10, 3, 14, colors.gray)
- draw_line(10, 4, 14, colors.gray)
- draw_line(10, 5, 14, colors.gray)
- draw_text(11, 2, "Control Rods", colors.white, colors.gray)
- draw_text(11, 3, "Efficiency", colors.white, colors.gray)
- draw_text(11, 4, "Fuel", colors.white, colors.gray)
- draw_text(11, 5, "Waste", colors.white, colors.gray)
- end
- function settings_menu()
- draw_line(12, 2, 18, colors.gray)
- draw_line(12, 3, 18, colors.gray)
- draw_text(13, 2, "Check for Updates", colors.white, colors.gray)
- draw_text(13, 3, "Reset peripherals", colors.white, colors.gray)
- end
- function popup_screen(y, title, height)
- clear()
- menu_bar()
- draw_line(4, y, 22, colors.purple)
- draw_line(25, y, 1, colors.red)
- for counter = y+1, height+y do
- draw_line(4, counter, 22, colors.white)
- end
- draw_text(25, y, "X", colors.white, colors.red)
- draw_text(5, y, title, colors.white, colors.purple)
- end
- function save_config()
- sw = fs.open("config.txt", "w")
- sw.writeLine(version)
- sw.writeLine(side)
- sw.writeLine(name)
- sw.writeLine(auto_string)
- sw.writeLine(on)
- sw.writeLine(off)
- sw.writeLine(auto_rods)
- sw.writeLine(auto_rf)
- sw.close()
- end
- function load_config()
- sr = fs.open("config.txt", "r")
- version = tonumber(sr.readLine())
- side = sr.readLine()
- name = sr.readLine()
- auto_string = sr.readLine()
- on = tonumber(sr.readLine())
- off = tonumber(sr.readLine())
- auto_rods = sr.readLine()
- auto_rf = tonumber(sr.readLine())
- sr.close()
- end
- --------------------------------------------------
- function homepage()
- clear()
- menu_bar()
- terminal_screen()
- energy_stored = peripheral.getEnergyStored(capacitor_bank)
- ------------STORAGE------------
- draw_text(2, 15, "RF Stored:", colors.yellow, colors.black)
- energy_stored_percent = math.floor((energy_stored/10000000)*100)
- draw_text(13, 15, energy_stored_percent.."% ("..energy_stored.." RF)", colors.white, colors.black)
- end
- sleep(0.5)
- end
- --------------MENU SCREENS--------------
- -----------------------Settings--------------------------------
- function rf_mode()
- wait = read()
- end
- function steam_mode()
- wait = read()
- end
- function install_update(program, pastebin)
- clear()
- draw_line(4, 5, 22, colors.blue)
- for counter = 6, 10 do
- draw_line(4, counter, 22, colors.white)
- end
- draw_text(5, 5, "Updating...", colors.white, colors.blue)
- draw_text(5, 7, "Open computer", colors.black, colors.white)
- draw_text(5, 8, "terminal.", colors.black, colors.white)
- if fs.exists("install") then fs.delete("install") end
- shell.run("pastebin get p4zeq7Ma install")
- shell.run("install")
- end
- function update()
- popup_screen(5, "Updates", 4)
- draw_text(5, 7, "Connecting to", colors.black, colors.white)
- draw_text(5, 8, "pastebin...", colors.black, colors.white)
- sleep(0.5)
- shell.run("pastebin get MkF2QQjH current_version.txt")
- sr = fs.open("current_version.txt", "r")
- current_version = tonumber(sr.readLine())
- sr.close()
- fs.delete("current_version.txt")
- terminal_screen()
- if current_version > version then
- popup_screen(5, "Updates", 7)
- draw_text(5, 7, "Update Available!", colors.black, colors.white)
- draw_text(11, 9, " Intall ", colors.white, colors.black)
- draw_text(11, 11, " Ignore ", colors.white, colors.black)
- local event, side, xPos, yPos = os.pullEvent("monitor_touch")
- --Instatll button
- if yPos == 9 and xPos >= 11 and xPos <= 17 then
- install_update()
- end
- --Exit button
- if yPos == 5 and xPos == 25 then
- call_homepage()
- end
- call_homepage()
- else
- popup_screen(5, "Updates", 5)
- draw_text(5, 7, "You are up to date!", colors.black, colors.white)
- draw_text(11, 9, " Okay ", colors.white, colors.black)
- local event, side, xPos, yPos = os.pullEvent("monitor_touch")
- --Okay button
- if yPos == 9 and xPos >= 11 and xPos <= 17 then
- call_homepage()
- end
- --Exit button
- if yPos == 5 and xPos == 25 then
- call_homepage()
- end
- call_homepage()
- end
- end
- function reset_peripherals()
- clear()
- draw_line(4, 5, 22, colors.blue)
- for counter = 6, 10 do
- draw_line(4, counter, 22, colors.white)
- end
- draw_text(5, 5, "Reset Peripherals", colors.white, colors.blue)
- draw_text(5, 7, "Open computer", colors.black, colors.white)
- draw_text(5, 8, "terminal.", colors.black, colors.white)
- setup_wizard()
- end
- --stop running status screen if monitors was touched
- function stop()
- while true do
- local event, side, xPos, yPos = os.pullEvent("monitor_touch")
- x = xPos
- y = yPos
- stop_function = "monitor_touch"
- return
- end
- end
- function mon_touch()
- --when the monitor is touch on the homepage
- if y == 1 then
- if x < monX/3 then
- power_menu()
- local event, side, xPos, yPos = os.pullEvent("monitor_touch")
- if xPos < 9 then
- if yPos == 2 then
- reactor1.setActive(true)
- timer = 0 --reset anytime the reactor is turned on/off
- call_homepage()
- else if yPos == 3 then
- reactor1.setActive(false)
- timer = 0 --reset anytime the reactor is turned on/off
- call_homepage()
- else if yPos == 4 then
- auto_off()
- else
- call_homepage()
- end
- end
- end
- else
- call_homepage()
- end
- else if x < 20 then
- tools_menu()
- local event, side, xPos, yPos = os.pullEvent("monitor_touch")
- if xPos < 25 and xPos > 10 then
- if yPos == 2 then
- control_rods()
- else if yPos == 3 then
- efficiency()
- else if yPos == 4 then
- fuel()
- else if yPos == 5 then
- waste()
- else
- call_homepage()
- end
- end
- end
- end
- else
- call_homepage()
- end
- else if x < monX then
- settings_menu()
- local event, side, xPos, yPos = os.pullEvent("monitor_touch")
- if xPos > 13 then
- if yPos == 2 then
- update()
- else if yPos == 3 then
- reset_peripherals()
- else
- call_homepage()
- end
- end
- else
- call_homepage()
- end
- end
- end
- end
- else
- call_homepage()
- end
- end
- function terminal_screen()
- term.clear()
- draw_line_term(1, 1, 55, colors.blue)
- draw_text_term(13, 1, "BigReactor Controls", colors.white, colors.blue)
- draw_line_term(1, 19, 55, colors.blue)
- draw_text_term(13, 19, "by jaranvil aka jared314", colors.white, colors.blue)
- draw_text_term(1, 3, "Current program:", colors.white, colors.black)
- draw_text_term(1, 4, "Reactor Control v"..version, colors.blue, colors.black)
- draw_text_term(1, 6, "Installer:", colors.white, colors.black)
- draw_text_term(1, 7, "pastebin.com/p4zeq7Ma", colors.blue, colors.black)
- draw_text_term(1, 9, "Please give me your feedback, suggestions,", colors.white, colors.black)
- draw_text_term(1, 10, "and errors!", colors.white, colors.black)
- draw_text_term(1, 11, "reddit.com/r/br_controls", colors.blue, colors.black)
- end
- --run both homepage() and stop() until one returns
- function call_homepage()
- clear()
- parallel.waitForAny(homepage, stop)
- if stop_function == "terminal_screen" then
- stop_function = "nothing"
- setup_wizard()
- else if stop_function == "monitor_touch" then
- stop_function = "nothing"
- mon_touch()
- end
- end
- end
- --try to wrap peripherals
- --catch any errors
- function test_reactor_connection()
- reactor1 = peripheral.wrap(name) --wrap reactor
- c = reactor1.getConnected()
- if unexpected_condition then error() end
- end
- function test_monitor_connection()
- mon = peripheral.wrap(side) --wrap mon
- monX, monY = mon.getSize() --get mon size ()
- if unexpected_condition then error() end
- end
- --test if the entered monitor and reactor can be wrapped
- function test_configs()
- term.clear()
- draw_line_term(1, 1, 55, colors.blue)
- draw_text_term(10, 1, "BigReactor Controls v"..version, colors.white, colors.blue)
- draw_line_term(1, 19, 55, colors.blue)
- draw_text_term(10, 19, "by jaranvil aka jared314", colors.white, colors.blue)
- draw_text_term(1, 3, "Wrapping peripherals...", colors.blue, colors.black)
- draw_text_term(2, 5, "wrap montior...", colors.white, colors.black)
- sleep(0.1)
- if pcall(test_monitor_connection) then
- draw_text_term(18, 5, "success", colors.lime, colors.black)
- else
- draw_text_term(1, 4, "Error:", colors.red, colors.black)
- draw_text_term(1, 8, "Could not connect to monitor on "..side.." side", colors.red, colors.black)
- draw_text_term(1, 9, "Valid sides are 'left', 'right', 'top', 'bottom' and 'back'", colors.white, colors.black)
- draw_text_term(1, 11, "Press Enter to continue...", colors.gray, colors.black)
- wait = read()
- setup_wizard()
- end
- sleep(0.1)
- draw_text_term(2, 6, "wrap reactor...", colors.white, colors.black)
- sleep(0.1)
- if pcall(test_reactor_connection) then
- draw_text_term(18, 6, "success", colors.lime, colors.black)
- else
- draw_text_term(1, 8, "Error:", colors.red, colors.black)
- draw_text_term(1, 9, "Could not connect to "..name, colors.red, colors.black)
- draw_text_term(1, 10, "Reactor must be connected with networking cable and wired modem", colors.white, colors.black)
- draw_text_term(1, 12, "Press Enter to continue...", colors.gray, colors.black)
- wait = read()
- setup_wizard()
- end
- sleep(0.1)
- draw_text_term(2, 8, "saving settings to file...", colors.white, colors.black)
- save_config()
- sleep(0.1)
- draw_text_term(1, 10, "Setup Complete!", colors.lime, colors.black)
- sleep(1)
- auto = auto_string == "true"
- call_homepage()
- end
- ----------------SETUP-------------------------------
- function setup_wizard()
- term.clear()
- draw_text_term(1, 1, "BigReactor Controls v"..version, colors.lime, colors.black)
- draw_text_term(1, 2, "Peripheral setup wizard", colors.white, colors.black)
- draw_text_term(1, 4, "Step 1:", colors.lime, colors.black)
- draw_text_term(1, 5, "-Place 3x3 advanced monitors next to computer.", colors.white, colors.black)
- draw_text_term(1, 7, "Step 2:", colors.lime, colors.black)
- draw_text_term(1, 8, "-Place a wired modem on this computer and on the ", colors.white, colors.black)
- draw_text_term(1, 9, " computer port of the reactor.", colors.white, colors.black)
- draw_text_term(1, 10, "-connect modems with network cable.", colors.white, colors.black)
- draw_text_term(1, 11, "-right click modems to activate.", colors.white, colors.black)
- draw_text_term(1, 13, "Press Enter when ready...", colors.gray, colors.black)
- wait = read()
- term.clear()
- draw_text_term(1, 1, "Peripheral Setup", colors.lime, colors.black)
- draw_text_term(1, 3, "What side is your monitor on?", colors.yellow, colors.black)
- term.setTextColor(colors.white)
- term.setCursorPos(1,4)
- side = read()
- term.clear()
- draw_text_term(1, 1, "Peripheral Setup", colors.lime, colors.black)
- draw_text_term(1, 3, "What is the reactor's name?", colors.yellow, colors.black)
- draw_text_term(1, 4, "type 'default' for 'BigReactors-Reactor_0'", colors.gray, colors.black)
- term.setTextColor(colors.white)
- term.setCursorPos(1,5)
- name = read()
- w
- if name == "default" then name = "BigReactors-Reactor_0" end
- auto_string = false
- on = 0
- off = 99
- auto_rods = false
- auto_rf = 0
- test_configs()
- end
- function start()
- --if configs exists, load values and test
- if fs.exists("config.txt") then
- load_config()
- test_configs()
- else
- setup_wizard()
- end
- end
- start()
Add Comment
Please, Sign In to add comment