9551

Untitled

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