Advertisement
9551

Untitled

Jun 25th, 2021
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 15.50 KB | None | 0 0
  1. local b = require("button")
  2. local s = require("strings")
  3. local m = peripheral.find("monitor")
  4. local r = peripheral.find("BigReactors-Reactor")
  5. local c = peripheral.find("minecraft:chest")
  6. local ins = {peripheral.find("bigreactors:tileentityreactoraccessport")}
  7. local rin = ins[1]
  8. local rout = ins[2]
  9. local arg = ...
  10. local updatespeed = 1 --*higher speeds look better but buttons are less responsive #default = 1
  11. local bootime = 2
  12. local theme = {
  13.     ["dblack"] = colors.black,
  14.     ["dwhite"] = colors.white,
  15.     ["dcyan"] = colors.cyan,
  16.     ["dgray"] = colors.gray,
  17.     ["dred"] = colors.red,
  18.     ["dgreen"] = colors.green,
  19.     ["dblue"] = colors.blue,
  20.     ["fred"] = "red",
  21.     ["fcyan"] = "cyan",
  22.     ["fblack"] = "black",
  23.     ["fgray"] = "gray",
  24.     ["fwhite"] = "white",
  25.     ["fgreen"] = "green",
  26.     ["fblue"] = "blue",
  27.     ["borange"] = "1",
  28.     ["bgray"] = "7",
  29.     ["bwhite"] = "e",
  30.     ["bred"] = "r",
  31.     ["bblack"] = "f"
  32. }
  33. if arg ~= nil then
  34.     print("entered configuration mode press enter to exit")
  35.     print("to skip peripheral just write skip\n")
  36.     print("peripherals list:")
  37.     textutils.pagedTabulate(peripheral.getNames())
  38.     print("")
  39.     print("enter your monitor")
  40.     local ins = read()
  41.     if ins ~= "skip" then
  42.         m = peripheral.wrap(ins)
  43.     end
  44.     local function cancel()
  45.         if ins == "" then
  46.             error("canceled", 0)
  47.         end
  48.     end
  49.     cancel()
  50.     print("enter your reactor")
  51.     local ins = read()
  52.     if ins ~= "skip" then
  53.         r = peripheral.wrap(ins)
  54.     end
  55.     print("enter your chest")
  56.     local ins = read()
  57.     if ins ~= "skip" then
  58.         c = peripheral.wrap(ins)
  59.     end
  60.     print("enter your input reactor port")
  61.     local ins = read()
  62.     if ins ~= "skip" then
  63.         rin = peripheral.wrap(ins)
  64.     end
  65.     print("enter your output reactor port")
  66.     local ins = read()
  67.     if ins ~= "skip" then
  68.         rout = peripheral.wrap(ins)
  69.     end
  70. end
  71. ----*peripheral check(--------
  72. if not m then
  73.     local otc = term.getBackgroundColor()
  74.     term.setBackgroundColor(theme["dblack"])
  75.     error("you dont have a monitor attached !", 0)
  76.     term.setBackgroundColor(otc)
  77. end
  78. m.setBackgroundColor(theme["dcyan"])
  79. if not r then
  80.     m.setCursorPos(2, 5)
  81.     m.setTextColor(theme["dwhite"])
  82.     m.setBackgroundColor(theme["dblack"])
  83.     m.clear()
  84.     m.setTextScale(2)
  85.     m.write("you dont have a reactor attached !")
  86.     error("no detected reactor !", 0)
  87. end
  88. if not c then
  89.     m.setCursorPos(2, 5)
  90.     m.setTextColor(theme["dwhite"])
  91.     m.setBackgroundColor(theme["dblack"])
  92.     m.clear()
  93.     m.setTextScale(1)
  94.     m.write("you dont have a chest attached !")
  95.     error("no chest detected !", 0)
  96. end
  97. if not rin then
  98.     m.setCursorPos(2, 5)
  99.     m.setTextColor(theme["dwhite"])
  100.     m.setBackgroundColor(theme["dblack"])
  101.     m.clear()
  102.     m.setTextScale(1)
  103.     m.write("no input/output port detected !")
  104.     error("no ports detected !", 0)
  105. end
  106. if (not rout) and rin then
  107.     m.setCursorPos(2, 5)
  108.     m.setTextColor(theme["dwhite"])
  109.     m.setBackgroundColor(theme["dblack"])
  110.     m.clear()
  111.     m.setTextScale(1)
  112.     m.write("no or 1 input/output port detected !")
  113.     error("no or 1 port detected !", 0)
  114. end
  115. ----*peripheral check)--------
  116. local mname = peripheral.getName(m)
  117. m.setTextScale(0.5)
  118. m.clear()
  119. m.setBackgroundColor(theme["dcyan"])
  120. m.setTextColor(theme["dcyan"])
  121. b.frame(mname, 3, 19, 97, 18, theme["fwhite"], theme["fcyan"], false)
  122. b.frame(mname, 30, 20, 40, 5, theme["fwhite"], theme["fred"], true)
  123. m.setCursorPos(42, 20)
  124. m.blit("reakt by 9551", string.rep(theme["borange"], 13), string.rep(theme["bgray"], 13))
  125. m.setCursorPos(37, 21)
  126. m.setBackgroundColor(theme["dred"])
  127. m.setTextColor(theme["dblack"])
  128. m.blit("reactor control program", string.rep(theme["borange"], 23), string.rep(theme["bgray"], 23))
  129. m.setCursorPos(38, 28)
  130. m.write("default peripherals used \25")
  131. m.setCursorPos(36, 29)
  132. m.write("reactor: " .. peripheral.getName(r))
  133. m.setCursorPos(36, 30)
  134. m.write("monitor: " .. peripheral.getName(m))
  135. m.setCursorPos(36, 31)
  136. m.write("chest: " .. peripheral.getName(c))
  137. m.setCursorPos(36, 32)
  138. m.write("r. in: " .. peripheral.getName(rin))
  139. m.setCursorPos(36, 33)
  140. m.write("r. out: " .. peripheral.getName(rout))
  141. local function topline()
  142.     b.frame(mname, 5, 6, 70, 1, theme["fblack"], theme["fblack"])
  143.     m.setTextColor(theme["dblack"])
  144.     m.setCursorPos(6, 6)
  145.     m.write("main")
  146.     m.setCursorPos(11, 6)
  147.     m.write("fuels")
  148.     m.setCursorPos(17, 6)
  149.     m.write("chest")
  150.     m.setCursorPos(23, 6)
  151.     m.write("rod control")
  152.     m.setCursorPos(35, 6)
  153.     m.write("energy control")
  154.     m.setCursorPos(50, 6)
  155.     m.write("energy info")
  156.     m.setCursorPos(62, 6)
  157.     m.write("settings")
  158. end
  159. local function setcol(x, text)
  160.     local oldcol = m.getBackgroundColor()
  161.     m.setBackgroundColor(theme["dgray"])
  162.     m.setCursorPos(x + 1, 6)
  163.     m.write(text)
  164.     m.setBackgroundColor(oldcol)
  165. end
  166. local function maincard(x, text)
  167.     topline()
  168.     local oldcol = m.getBackgroundColor()
  169.     m.setBackgroundColor(theme["dcyan"])
  170.     b.frame(mname, 5, 22, 70, 14, theme["fblack"], theme["fgray"], true)
  171.     m.setBackgroundColor(theme["dgray"])
  172.     b.frame(mname, x + 2, 8, #text - 1, 1, theme["fgray"], theme["fgray"])
  173.     setcol(x, text)
  174.     m.setBackgroundColor(oldcol)
  175. end
  176. local function menuButtons(click)
  177.     local oci = m.getBackgroundColor()
  178.     local ocii = m.getTextColor()
  179.     m.setBackgroundColor(theme["dblack"])
  180.     m.setTextColor(theme["dred"])
  181.     m.setCursorPos(81, 6)
  182.     m.write("TABS \25")
  183.     m.setBackgroundColor(oci)
  184.     m.setTextColor(ocii)
  185.     b.menu(mname, click, 1, 81, 7, theme["fblack"], theme["fred"], "main", "main", true, 5)
  186.     b.menu(mname, click, 2, 81, 8, theme["fblack"], theme["fred"], "fuels", "fuels", true, 10)
  187.     b.menu(mname, click, 3, 81, 9, theme["fblack"], theme["fred"], "chest", "chest", true, 16)
  188.     b.menu(mname, click, 4, 81, 10, theme["fblack"], theme["fred"], "rod control", "rod control", true, 22)
  189.     b.menu(mname, click, 5, 81, 11, theme["fblack"], theme["fred"], "energy control", "energy control", true, 34)
  190.     b.menu(mname, click, 6, 81, 12, theme["fblack"], theme["fred"], "energy info", "energy info", true, 49)
  191.  
  192.     --------------*settings menu--------------
  193.     m.setBackgroundColor(theme["dblack"])
  194.     b.menu(mname, click, 7, 81, 25, theme["fwhite"], theme["fgreen"], "peripherals", "peripherals", true, 61)
  195.     b.menu(mname, click, 8, 81, 26, theme["fwhite"], theme["fgreen"], "reactor set.", "reactor set.", true, 61)
  196.     --*---------------------------------------
  197.     m.setTextColor(theme["dwhite"])
  198.     if b.button(mname, click, 81, 14, ">shutdown<") then
  199.         m.setBackgroundColor(theme["dblack"])
  200.         m.setTextColor(theme["dwhite"])
  201.         m.clear()
  202.         m.setCursorPos(70, 14)
  203.         m.write("shutting down.")
  204.         sleep(bootime / 3)
  205.         m.setCursorPos(70, 14)
  206.         m.write("shutting down..")
  207.         sleep(bootime / 3)
  208.         m.setCursorPos(70, 14)
  209.         m.write("shutting down...")
  210.         sleep(bootime / 3)
  211.         m.clear()
  212.         os.shutdown()
  213.     end
  214.     m.setBackgroundColor(theme["dcyan"])
  215.     local out = b.menudata()
  216.     if (type(out[2]) == "number") and (out[1]) then
  217.         maincard(out[2], out[1])
  218.     end
  219. end
  220. sleep(bootime)
  221.  
  222. local function basemenu()
  223.     m.setBackgroundColor(theme["dcyan"])
  224.     b.frame(mname, 3, 20, 97, 18, theme["fblack"], theme["fcyan"], true)
  225.     b.frame(mname, 80, 20, 15, 15, theme["fblack"], theme["fcyan"], true)
  226.     b.frame(mname, 80, 20, 16, 15, theme["fwhite"], theme["fcyan"], true)
  227.     b.frame(mname, 81, 18, 14, 5, theme["fred"], theme["fblack"], false)
  228.     m.setCursorPos(81, 13)
  229.     m.blit("system", string.rep(theme["bred"], 6), string.rep(theme["bwhite"], 6))
  230.  
  231.     b.frame(mname, 81, 29, 14, 5, theme["fred"], theme["fblack"], false)
  232.     m.setCursorPos(81, 24)
  233.     m.blit("settings", string.rep(theme["bred"], 8), string.rep(theme["bwhite"], 8))
  234. end
  235. basemenu()
  236. topline()
  237. --*-----------------main programs----------------
  238. local function mmain(click)
  239.     b.frame(mname, 30, 20, 10, 5, theme["fblack"], theme["fgray"], true)
  240. end
  241. local function mpers(click)
  242.     local function selection(ins)
  243.         while true do
  244.             local click = b.timetouch(updatespeed, mname)
  245.             m.setBackgroundColor(theme["dgray"])
  246.             b.frame(mname, 8, 22, 63, 12, theme["fblack"], theme["fblue"], false)
  247.             m.setBackgroundColor(theme["dred"])
  248.             m.setCursorPos(22, 10)
  249.             m.write("what kind of peripheral is this ?")
  250.             m.setCursorPos(20, 11)
  251.             m.write(ins)
  252.             if b.button(mname, click, 35, 21, "|BACK|") then
  253.                 break
  254.             end
  255.             m.setBackgroundColor(theme["dgreen"])
  256.             if b.button(mname, click, 28, 15, "monitor") then
  257.                 m.setBackgroundColor(theme["dblack"])
  258.                 m.clear()
  259.                 m.setBackgroundColor(theme["dcyan"])
  260.                 m = peripheral.wrap(ins)
  261.                 m.setTextScale(0.5)
  262.                 mname = ins
  263.                 menuButtons(click)
  264.                 basemenu()
  265.                 topline()
  266.                 break
  267.             end
  268.             if b.button(mname, click, 36, 15, "reactor") then
  269.                 r = peripheral.wrap(ins)
  270.                 break
  271.             end
  272.             if b.button(mname, click, 40, 17, "r. input <") then
  273.                 rin = peripheral.wrap(ins)
  274.                 break
  275.             end
  276.             if b.button(mname, click, 28, 17, "r. output >") then
  277.                 rout = peripheral.wrap(rout)
  278.                 break
  279.             end
  280.             if b.button(mname, click, 44, 15, "chest") then
  281.                 c = peripheral.wrap(ins)
  282.                 break
  283.             end
  284.         end
  285.     end
  286.     m.setBackgroundColor(theme["dgray"])
  287.     b.frame(mname, 8, 22, 30, 12, theme["fblack"], theme["fgreen"], false)
  288.     b.frame(mname, 41, 22, 30, 12, theme["fblack"], theme["fred"], false)
  289.     m.setBackgroundColor(theme["dgreen"])
  290.     b.frame(mname, 10, 14, 26, 2, theme["fblack"], theme["fblue"], false)
  291.     m.setCursorPos(10, 12)
  292.     m.blit("monitor :", string.rep(theme["bred"], 9), string.rep(theme["bblack"], 9))
  293.     b.frame(mname, 10, 19, 26, 2, theme["fblack"], theme["fblue"], false)
  294.     m.setCursorPos(10, 17)
  295.     m.blit("reactor :", string.rep(theme["bred"], 9), string.rep(theme["bblack"], 9))
  296.     b.frame(mname, 10, 24, 26, 2, theme["fblack"], theme["fblue"], false)
  297.     m.setCursorPos(10, 22)
  298.     m.blit("chest :", string.rep(theme["bred"], 7), string.rep(theme["bblack"], 7))
  299.     b.frame(mname, 10, 30, 26, 3, theme["fblack"], theme["fblue"], false)
  300.     m.setCursorPos(10, 27)
  301.     m.blit("input/output :", string.rep(theme["bred"], 14), string.rep(theme["bblack"], 14))
  302.  
  303.     m.setCursorPos(8, 10)
  304.     m.blit("active :", string.rep(theme["bred"], 8), string.rep(theme["bblack"], 8))
  305.     m.setCursorPos(41, 10)
  306.     m.blit("all found :", string.rep(theme["bred"], 11), string.rep(theme["bblack"], 11))
  307.     m.setBackgroundColor(theme["dblue"])
  308.     m.setCursorPos(11, 14)
  309.     m.write(peripheral.getName(m))
  310.     m.setCursorPos(11, 19)
  311.     m.write(peripheral.getName(r))
  312.     m.setCursorPos(11, 24)
  313.     m.write(peripheral.getName(c))
  314.     m.setCursorPos(11, 29)
  315.     m.write("I: " .. string.sub(peripheral.getName(rin), 23))
  316.     m.setCursorPos(11, 31)
  317.     m.write("O: " .. string.sub(peripheral.getName(rout), 23))
  318.     local pers = peripheral.getNames()
  319.     local sc = 11
  320.     m.setTextColor(theme["dblack"])
  321.     m.setBackgroundColor(theme["dred"])
  322.     for i = 1, #pers do
  323.         if peripheral.getType(pers[i]) == "bigreactors:tileentityreactoraccessport" then
  324.             pers[i] = string.sub(pers[i], 23)
  325.         end
  326.         if b.button(mname, click, 42, sc + i, pers[i]) then
  327.             if s.ensure_width(pers[i], 18) == "reactoraccessport_" then
  328.                 pers[i] = "bigreactors:tileentityreactoraccessport_" .. string.sub(pers[i], 19)
  329.             end
  330.             selection(pers[i])
  331.         end
  332.     end
  333. end
  334. local function mfuel(click)
  335.     b.frame(mname, 30, 20, 10, 5, theme["fblack"], theme["fgray"], true)
  336. end
  337. local function mchest(click)
  338.     b.frame(mname, 30, 20, 10, 5, theme["fblack"], theme["fgray"], true)
  339. end
  340. local function mrod(click)
  341.     b.frame(mname, 30, 20, 10, 5, theme["fblack"], theme["fgray"], true)
  342. end
  343. local function menergyc(click)
  344.     b.frame(mname, 30, 20, 10, 5, theme["fblack"], theme["fgray"], true)
  345. end
  346. local function menergyi(click)
  347.     b.frame(mname, 30, 20, 10, 5, theme["fblack"], theme["fgray"], true)
  348. end
  349. local function mreactor(click)
  350.     b.frame(mname, 30, 20, 10, 5, theme["fblack"], theme["fgray"], true)
  351. end
  352. --*----------------------------------------------
  353. local function peripheralsmenu()
  354.     local oc = m.getBackgroundColor()
  355.     repeat
  356.         local ins = b.menudata()
  357.         local click = b.timetouch(updatespeed, mname)
  358.         menuButtons(click)
  359.         mpers(click)
  360.     until ins ~= "peripherals"
  361.     m.setBackgroundColor(oc)
  362. end
  363. local function main()
  364.     local oc = m.getBackgroundColor()
  365.     repeat
  366.         local ins = b.menudata()
  367.         local click = b.timetouch(updatespeed, mname)
  368.         menuButtons(click)
  369.         mmain(click)
  370.     until ins ~= "main"
  371.     m.setBackgroundColor(oc)
  372. end
  373. local function fuels()
  374.     local oc = m.getBackgroundColor()
  375.     repeat
  376.         local ins = b.menudata()
  377.         local click = b.timetouch(updatespeed, mname)
  378.         menuButtons(click)
  379.         mfuel(click)
  380.     until ins ~= "fuels"
  381.     m.setBackgroundColor(oc)
  382. end
  383. local function chest()
  384.     local oc = m.getBackgroundColor()
  385.     repeat
  386.         local ins = b.menudata()
  387.         local click = b.timetouch(updatespeed, mname)
  388.         menuButtons(click)
  389.         mchest(click)
  390.     until ins ~= "chest"
  391.     m.setBackgroundColor(oc)
  392. end
  393. local function rodcontrol()
  394.     local oc = m.getBackgroundColor()
  395.     repeat
  396.         local ins = b.menudata()
  397.         local click = b.timetouch(updatespeed, mname)
  398.         menuButtons(click)
  399.         mrod(click)
  400.     until ins ~= "rod control"
  401.     m.setBackgroundColor(oc)
  402. end
  403. local function energyc()
  404.     local oc = m.getBackgroundColor()
  405.     repeat
  406.         local ins = b.menudata()
  407.         local click = b.timetouch(updatespeed, mname)
  408.         menuButtons(click)
  409.         menergyc(click)
  410.     until ins ~= "energy control"
  411.     m.setBackgroundColor(oc)
  412. end
  413. local function energyinf()
  414.     local oc = m.getBackgroundColor()
  415.     repeat
  416.         local ins = b.menudata()
  417.         local click = b.timetouch(updatespeed, mname)
  418.         menuButtons(click)
  419.         menergyi(click)
  420.     until ins ~= "energy info"
  421.     m.setBackgroundColor(oc)
  422. end
  423. local function reactorsettings()
  424.     local oc = m.getBackgroundColor()
  425.     repeat
  426.         local ins = b.menudata()
  427.         local click = b.timetouch(updatespeed, mname)
  428.         menuButtons(click)
  429.         mreactor(click)
  430.     until ins ~= "reactor set."
  431.     m.setBackgroundColor(oc)
  432. end
  433.  
  434. menuButtons({"monitor_touch", mname, 83, 7})
  435. while true do
  436.     local menuout = b.menudata()
  437.     if menuout[1] == "peripherals" then
  438.         peripheralsmenu()
  439.     end
  440.     if menuout[1] == "main" then
  441.         main()
  442.     end
  443.     if menuout[1] == "fuels" then
  444.         fuels()
  445.     end
  446.     if menuout[1] == "chest" then
  447.         chest()
  448.     end
  449.     if menuout[1] == "rod control" then
  450.         rodcontrol()
  451.     end
  452.     if menuout[1] == "energy control" then
  453.         energyc()
  454.     end
  455.     if menuout[1] == "energy info" then
  456.         energyinf()
  457.     end
  458.     if menuout[1] == "reactor set." then
  459.         reactorsettings()
  460.     end
  461. end
  462.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement