Advertisement
9551

ButtonH-MENU/PANEL API by 9551Dev

May 22nd, 2021 (edited)
1,834
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 50.99 KB | None | 0 0
  1. --------------------ButtonH----------------------------
  2. ----------------------MENU/PANEL API-------------------
  3. --------------------by 9551 DEV------------------------
  4. ---Copyright (c) 2021-2022 9551------------9551#0001---
  5. ---using this code in your project is fine!------------
  6. ---as long as you dont claim you made it---------------
  7. ---im cool with it, feel free to include---------------
  8. ---in your projects!   discord: 9551#0001--------------
  9. ---you dont have to but giving credits is nice :)------
  10. -------------------------------------------------------
  11. -------------------------------------------------------
  12. --*!   pastebin get LTDZZZEJ button
  13.  
  14. --*functions usages
  15. --*API(ins, cord1, cord2, length, height)
  16. --*timetouch(timeout,monitor [,ignore])
  17. --*button(monitor, ins, cord1, cord2, text)
  18. --*counter(monitor, ins, cc, cord1, cord2, cv, max, min, col)
  19. --*fill(monitor, pos1, pos2, length, height)
  20. --*switch(monitor, cc, ins, pos1, pos2, col1, col2, col3, text)
  21. --*switchn(monitor, cc, ins, pos1, pos2, col1, col2, col3, text, text2)
  22. --*bundle(side, color, state)
  23. --*signal(side, ins, col)
  24. --*sliderVer/Hor(monitor, ins, cc, pos1, pos2, length, color1, textCol)
  25. --*menu(monitor, ins, cc, x, y, textcol, switchcol, text, returns1, more, returns2)  (returns menuout)
  26. --*bar(monitor, pos1, pos2, length, height, ins, max, color1, color2, color3, printval, hor, text, format, rect, thicc)
  27. --*render(monitor,text,x,y,textcol,backCol)
  28. --*menudata()
  29. --*frame(monitor, pos1, pos2, length, height, color3, color1, thicc)
  30. --*boxAPI(ins,x,y,xp,yp,text)
  31. --*boxButton(mon,ins,x,y,bcol,tcol,txt,xp,yp)
  32. --*db allows you to get stored data from all functions that use stored data!
  33. --*how to use db:  in your function for example switch you do   b.switch("db",<data>) data is the storing position you want to get data of. you can also use "setdb" to set data b.switch("setdb",buttonID,value)
  34. --*if you are using terminal version instead of mon put in 1-3 to select left or right click (3 for mouse wheel middle)
  35. --*put values at end of switch function (x,y) to add padding for your switches
  36. local e = {}
  37. local t = {}
  38. local a = require("cc.expect").expect
  39. function e.fill(o, i, n, s, h)
  40.     a(1, o, "string")
  41.     a(2, i, "number")
  42.     a(3, n, "number")
  43.     a(4, s, "number")
  44.     a(5, h, "number")
  45.     local r = peripheral.wrap(o)
  46.     for d = 0, h - 1 do
  47.         r.setCursorPos(i, n + d)
  48.         r.write(string.rep(" ", s))
  49.     end
  50. end
  51. function e.API(l, u, c, f, w)
  52.     a(1, l, "table")
  53.     a(2, u, "number")
  54.     a(3, c, "number")
  55.     a(4, f, "number")
  56.     a(5, w, "number")
  57.     if l == true then
  58.         l = {os.pullEvent("monitor_touch")}
  59.     end
  60.     if l[3] >= u and l[3] <= u + f - 1 then
  61.         return l[4] >= c and l[4] <= c + w - 1
  62.     end
  63. end
  64. function e.boxAPI(y, p, v, b, g, k)
  65.     a(1, y, "table")
  66.     a(2, p, "number")
  67.     a(3, v, "number")
  68.     a(4, b, "number")
  69.     a(5, g, "number")
  70.     a(6, k, "string")
  71.     local q = p - b + 1
  72.     local j = v - g
  73.     local x = #k - 2
  74.     local z = false
  75.     if b >= 1 then
  76.         b = b - 1
  77.         z = true
  78.     end
  79.     if b > 0 or z then
  80.         x = #k + b * 2
  81.         q = q - 1
  82.     end
  83.     local E = g * 2 + 1
  84.     return e.API(y, q - 1, j, x + 2, E), {q, j, x, E}
  85. end
  86. function e.boxButton(T, A, O, I, N, S, H, R, D)
  87.     a(1, T, "string")
  88.     a(2, A, "table")
  89.     a(3, O, "number")
  90.     a(4, I, "number")
  91.     a(5, N, "string")
  92.     a(6, S, "string")
  93.     a(7, H, "string", "number", "nil")
  94.     a(8, R, "number", "nil")
  95.     a(9, D, "number", "nil")
  96.     if not R then
  97.         R = 0
  98.     end
  99.     if not D then
  100.         D = 0
  101.     end
  102.     if not H then
  103.         H = ""
  104.     end
  105.     local H = tostring(H)
  106.     if A[2] == T then
  107.         if A ~= nil then
  108.             local L = peripheral.wrap(T)
  109.             local U, C = L.getTextColor(), L.getBackgroundColor()
  110.             L.setBackgroundColor(colors[N])
  111.             L.setTextColor(colors[S])
  112.             local M, F = e.boxAPI(A, O, I, R or 1, D or 1, H)
  113.             e.fill(T, F[1] - 1, F[2], F[3] + 2, F[4])
  114.             local W, Y, P, V = F[1], F[2], F[3] + F[1], F[4] + F[2]
  115.             L.setCursorPos(math.floor(W + (P - W) / 2 - H:len() / 2 + 0.5), math.floor(Y + (V - Y) / 2))
  116.             L.write(H)
  117.             L.setBackgroundColor(C)
  118.             L.setTextColor(U)
  119.             return M
  120.         end
  121.     end
  122. end
  123. function e.touch()
  124.     local B = {os.pullEvent("monitor_touch")}
  125.     return B
  126. end
  127. function e.timetouch(G, K)
  128.     a(1, G, "number", "nil")
  129.     a(2, K, "string")
  130.     local Q
  131.     if G then
  132.         Q = os.startTimer(G)
  133.     end
  134.     while true do
  135.         local J
  136.         if G then J = {os.pullEvent()} end
  137.         if not G then J = {os.pullEvent("monitor_touch")} end
  138.         if J[1] == "timer" and J[2] == Q then
  139.             return {"timeout", K, 1000, 1000}
  140.         elseif J[1] == "monitor_touch" and J[2] == K then
  141.             return {J[1], J[2], J[3], J[4]}
  142.         end
  143.     end
  144. end
  145. function e.button(X, Z, et, tt, at)
  146.     a(1, X, "string")
  147.     a(2, Z, "table")
  148.     a(3, et, "number")
  149.     a(4, tt, "number")
  150.     a(5, at, "string")
  151.     if Z[2] == X then
  152.         if Z ~= nil then
  153.             local ot = peripheral.wrap(X)
  154.             local it = e.API(Z, et, tt, #at, 1)
  155.             ot.setCursorPos(et, tt)
  156.             ot.write(at)
  157.             return it
  158.         end
  159.     end
  160. end
  161. function e.counter(nt, st, ht, rt, dt, lt, ut, ct, mt)
  162.     if nt == "db" then
  163.         if data == nil then
  164.             return nil
  165.         else
  166.             return data[st]
  167.         end
  168.     end
  169.     if nt == "setdb" then
  170.         if data == nil then
  171.             return "no data to edit"
  172.         else
  173.             data[st] = ht
  174.             return "value changed too " .. type(ht)
  175.         end
  176.     end
  177.     a(1, nt, "string")
  178.     a(2, st, "table")
  179.     a(3, ht, "number")
  180.     a(4, rt, "number")
  181.     a(5, dt, "number")
  182.     a(6, lt, "number")
  183.     a(7, ut, "number")
  184.     a(8, ct, "number")
  185.     a(9, mt, "string")
  186.     if st[2] == nt then
  187.         if st ~= nil then
  188.             local ft = peripheral.wrap(nt)
  189.             if data == nil then
  190.                 data = {}
  191.                 for wt = 0, 1000 do
  192.                     data[wt] = 0
  193.                 end
  194.             end
  195.             ft.setCursorPos(rt, dt)
  196.             ft.write("\24" .. " " .. data[ht])
  197.             ft.setCursorPos(rt, dt + 1)
  198.             ft.write("\25")
  199.             if e.API(st, rt, dt, 1, 1) == true then
  200.                 if data[ht] < ut then
  201.                     data[ht] = data[ht] + lt
  202.                     ft.setCursorPos(rt, dt)
  203.                     ft.setTextColor(colors.green)
  204.                     ft.write("\24" .. " " .. data[ht] .. " ")
  205.                     ft.setCursorPos(rt, dt + 1)
  206.                     ft.setTextColor(colors.red)
  207.                     ft.write("\25")
  208.                     ft.setTextColor(colors[mt])
  209.                     return data[ht]
  210.                 end
  211.             end
  212.         end
  213.         if e.API(st, rt, dt + 1, 1, 1) == true then
  214.             if data[ht] > ct then
  215.                 data[ht] = data[ht] - lt
  216.                 m.setCursorPos(rt, dt)
  217.                 m.setTextColor(colors.green)
  218.                 m.write("\24" .. " " .. data[ht] .. " ")
  219.                 m.setCursorPos(rt, dt + 1)
  220.                 m.setTextColor(colors.red)
  221.                 m.write("\25")
  222.                 m.setTextColor(colors[mt])
  223.                 return data[ht]
  224.             end
  225.         end
  226.     end
  227. end
  228. function e.switch(yt, pt, vt, bt, gt, kt, qt, jt, xt, zt, Et)
  229.     if yt == "db" then
  230.         if data1 == nil then
  231.             return nil
  232.         else
  233.             return data1[pt]
  234.         end
  235.     end
  236.     if yt == "setdb" then
  237.         if data1 == nil then
  238.             return "no data to edit"
  239.         else
  240.             data1[pt] = vt
  241.             return "value changed too " .. type(vt)
  242.         end
  243.     end
  244.     a(1, yt, "string")
  245.     a(2, pt, "number")
  246.     a(3, vt, "table")
  247.     a(4, bt, "number")
  248.     a(5, gt, "number")
  249.     a(6, kt, "string")
  250.     a(7, qt, "string")
  251.     a(8, jt, "string")
  252.     a(9, xt, "string")
  253.     a(10, zt, "number", "nil")
  254.     a(11, Et, "number", "nil")
  255.     if vt[2] == yt then
  256.         if vt ~= nil then
  257.             local _ = #xt
  258.             peripheral.wrap(yt)
  259.             if data1 == nil then
  260.                 data1 = {}
  261.                 for Ot = 0, 1000 do
  262.                     data1[Ot] = false
  263.                 end
  264.             end
  265.             local function It()
  266.                 data1[pt] = not data1[pt]
  267.             end
  268.             local Nt
  269.             if not data1[pt] then
  270.                 Nt = kt
  271.             else
  272.                 Nt = qt
  273.             end
  274.             if e.boxButton(yt, vt, bt, gt, Nt, jt, xt, zt, Et) then
  275.                 It()
  276.             end
  277.             return data1[pt]
  278.         end
  279.     end
  280. end
  281. function e.switchn(St, Ht, Rt, Dt, Lt, Ut, Ct, Mt, Ft, Wt, Yt, Pt)
  282.     if St == "db" then
  283.         if data2 == nil then
  284.             return nil
  285.         else
  286.             return data2[Ht]
  287.         end
  288.     end
  289.     if St == "setdb" then
  290.         if data2 == nil then
  291.             return "no data to edit"
  292.         else
  293.             data2[Ht] = Rt
  294.             return "value changed too " .. type(Rt)
  295.         end
  296.     end
  297.     a(1, St, "string")
  298.     a(2, Ht, "number")
  299.     a(3, Rt, "table")
  300.     a(4, Dt, "number")
  301.     a(5, Lt, "number")
  302.     a(6, Ut, "string")
  303.     a(7, Ct, "string")
  304.     a(8, Mt, "string")
  305.     a(9, Ft, "string")
  306.     a(10, Wt, "string")
  307.     a(11, Yt, "number", "nil")
  308.     a(12, Pt, "number", "nil")
  309.     if Rt[2] == St then
  310.         if Rt ~= nil then
  311.             peripheral.wrap(St)
  312.             if data2 == nil then
  313.                 data2 = {}
  314.                 for Bt = 0, 1000 do
  315.                     data2[Bt] = false
  316.                 end
  317.             end
  318.             local function Gt()
  319.                 data2[Ht] = not data2[Ht]
  320.             end
  321.             local Kt
  322.             local Qt
  323.             if not data2[Ht] then
  324.                 Kt = Ut
  325.                 Qt = Ft
  326.             else
  327.                 Kt = Ct
  328.                 Qt = Wt
  329.             end
  330.             if e.boxButton(St, Rt, Dt, Lt, Kt, Mt, Qt, Yt, Pt) then
  331.                 Gt()
  332.             end
  333.             return data2[Ht]
  334.         end
  335.     end
  336. end
  337. function e.bundle(Jt, Xt, Zt)
  338.     a(1, Jt, "string")
  339.     a(2, Xt, "number")
  340.     a(3, Zt, "boolean")
  341.     if Zt == true then
  342.         rs.setBundledOutput(Jt, colors.combine(rs.getBundledOutput(Jt), Xt))
  343.     elseif Zt == false then
  344.         rs.setBundledOutput(Jt, colors.subtract(rs.getBundledOutput(Jt), Xt))
  345.     end
  346. end
  347. function e.signal(ea, ta, aa, oa)
  348.     a(1, ea, "string")
  349.     a(2, ta, "boolean", "string")
  350.     a(3, aa, "number","string")
  351.     a(4, oa, "boolean")
  352.     if ta == "clear" then
  353.         rs.setBundledOutput(ea, 0)
  354.     else
  355.         if oa == true then
  356.             if ta == "on" then
  357.                 ta = true
  358.             end
  359.             if ta == "nil" then
  360.                 ta = false
  361.             end
  362.         end
  363.         if ta ~= nil then
  364.             if type(aa) == "number" then
  365.                 if ta == true then
  366.                     e.bundle(ea, aa, true)
  367.                 elseif ta == false then
  368.                     e.bundle(ea, aa, false)
  369.                 end
  370.             elseif type(aa) == "string" then
  371.                 if ta == true then
  372.                     e.bundle(ea, colors[aa], true)
  373.                 elseif ta == false then
  374.                     e.bundle(ea, colors[aa], false)
  375.                 end
  376.             end
  377.         end
  378.     end
  379. end
  380. function e.sliderHor(ia, na, sa, ha, ra, da, la, ua)
  381.     if ia == "db" then
  382.         if data3 == nil then
  383.             return nil
  384.         else
  385.             return data3[na]
  386.         end
  387.     end
  388.     if ia == "setdb" then
  389.         if data3 == nil then
  390.             return "no data to edit"
  391.         else
  392.             data3[na] = sa
  393.             return "value changed too " .. type(sa)
  394.         end
  395.     end
  396.     a(1, ia, "string")
  397.     a(2, na, "table")
  398.     a(3, sa, "number")
  399.     a(4, ha, "number")
  400.     a(5, ra, "number")
  401.     a(6, da, "number")
  402.     a(7, la, "string")
  403.     a(8, ua, "string")
  404.     if na[2] == ia then
  405.         if na ~= nil then
  406.             m = peripheral.wrap(ia)
  407.             local ca = m.getBackgroundColor()
  408.             local ma = m.getTextColor()
  409.             m.setBackgroundColor(colors[la])
  410.             m.setTextColor(colors[ua])
  411.             m.setCursorPos(ha, ra)
  412.             for fa = 0, da do
  413.                 m.write("-")
  414.                 m.setCursorPos(ha + fa, ra)
  415.             end
  416.             if data3 == nil then
  417.                 data3 = {}
  418.                 for wa = 0, 10000 do
  419.                     data3[wa] = 0
  420.                 end
  421.             end
  422.             local ya = na[3]
  423.             if na[4] == ra and na[3] >= ha and na[3] <= ha + da - 1 then
  424.                 m.setCursorPos(ya, ra)
  425.                 data3[sa] = ya
  426.                 m.write("|")
  427.             else
  428.                 m.setCursorPos(data3[sa], ra)
  429.                 m.write("|")
  430.             end
  431.             m.setBackgroundColor(ca)
  432.             m.setTextColor(ma)
  433.             if data3[sa] - ha >= 0 then
  434.                 return data3[sa] - ha
  435.             elseif data3[sa] - ha < 0 then
  436.                 return 0
  437.             end
  438.         end
  439.     end
  440. end
  441. function e.sliderVer(pa, va, ba, ga, ka, qa, ja, xa)
  442.     if pa == "db" then
  443.         if data10 == nil then
  444.             return nil
  445.         else
  446.             return data10[va]
  447.         end
  448.     end
  449.     if pa == "setdb" then
  450.         if data10 == nil then
  451.             return "no data to edit"
  452.         else
  453.             data10[va] = ba
  454.             return "value changed too " .. type(ba)
  455.         end
  456.     end
  457.     a(1, pa, "string")
  458.     a(2, va, "table")
  459.     a(3, ba, "number")
  460.     a(4, ga, "number")
  461.     a(5, ka, "number")
  462.     a(6, qa, "number")
  463.     a(7, ja, "string")
  464.     a(8, xa, "string")
  465.     if va[2] == pa then
  466.         if va ~= nil then
  467.             m = peripheral.wrap(pa)
  468.             local za = m.getBackgroundColor()
  469.             local Ea = m.getTextColor()
  470.             m.setBackgroundColor(colors[ja])
  471.             m.setTextColor(colors[xa])
  472.             m.setCursorPos(ga, ka)
  473.             for Ta = 0, qa do
  474.                 m.write("\124")
  475.                 m.setCursorPos(ga, ka - Ta)
  476.             end
  477.             if data10 == nil then
  478.                 data10 = {}
  479.                 for Aa = 0, 10000 do
  480.                     data10[Aa] = 0
  481.                 end
  482.             end
  483.             local Oa = va[4]
  484.             if va[3] == ga and va[4] <= ka and va[4] >= ka - qa + 1 then
  485.                 m.setCursorPos(ga, Oa)
  486.                 data10[ba] = Oa
  487.                 m.write("\xad")
  488.             else
  489.                 m.setCursorPos(ga, data10[ba])
  490.                 m.write("\xad")
  491.             end
  492.             m.setBackgroundColor(za)
  493.             m.setTextColor(Ea)
  494.             if data10[ba] - ga >= 0 then
  495.                 return data10[ba] - ga
  496.             elseif data10[ba] - ga < 0 then
  497.                 return 0
  498.             end
  499.         end
  500.     end
  501. end
  502. function e.render(Ia, Na, Sa, Ha, Ra, Da)
  503.     a(1, Ia, "string")
  504.     a(2, Na, "string")
  505.     a(3, Sa, "number")
  506.     a(4, Ha, "number")
  507.     a(5, Ra, "string")
  508.     a(6, Da, "string", "number")
  509.     local La = peripheral.wrap(Ia)
  510.     local Ua = La.getBackgroundColor()
  511.     local Ca = La.getTextColor()
  512.     local Ma = {La.getCursorPos()}
  513.     La.setTextColor(colors[Ra])
  514.     if type(Da) == "string" then
  515.         La.setBackgroundColor(colors[Da])
  516.     elseif type(Da) == "number" then
  517.         La.setBackgroundColor(Da)
  518.     end
  519.     La.setCursorPos(Sa, Ha)
  520.     La.write(Na)
  521.     La.setBackgroundColor(Ua)
  522.     La.setTextColor(Ca)
  523.     La.setCursorPos(Ma[1], Ma[2])
  524. end
  525. function e.menu(Fa, Wa, Ya, Pa, Va, Ba, Ga, Ka, Qa, Ja, Xa)
  526.     a(1, Fa, "string")
  527.     a(2, Wa, "table")
  528.     a(3, Ya, "number")
  529.     a(4, Pa, "number")
  530.     a(5, Va, "number")
  531.     a(6, Ba, "string")
  532.     a(7, Ga, "string")
  533.     a(8, Ka, "string")
  534.     a(9, Qa, "string", "number", "boolean", "nil")
  535.     a(10, Ja, "boolean", "nil")
  536.     a(11, Xa, "string", "number", "boolean", "nil")
  537.     if Wa[2] == Fa then
  538.         if thisIsUseless == nil then
  539.             for Za = 0, 1000 do
  540.                 thisIsUseless = {}
  541.                 thisIsUseless[Za] = false
  542.             end
  543.         end
  544.         local eo = peripheral.wrap(Fa)
  545.         if not thisIsUseless[Ya] then
  546.             local tcol = eo.getBackgroundColor()
  547.             e.render(Fa, Ka, Pa, Va, Ba, tcol)
  548.         end
  549.         if Wa ~= nil then
  550.             local to = eo.getTextColor()
  551.             local ao = eo.getBackgroundColor()
  552.             local oo = #Ka
  553.             if Wa[1] ~= "timeout" then
  554.                 if data4 == nil then
  555.                     data4 = {}
  556.                     for io = 0, 1000 do
  557.                         data4[io] = false
  558.                     end
  559.                 end
  560.                 if data5 == nil then
  561.                     data5 = {}
  562.                     for no = 0, 1000 do
  563.                         data5[no] = false
  564.                     end
  565.                 end
  566.                 if data6 == nil then
  567.                     data6 = {}
  568.                     for so = 0, 1000 do
  569.                         data6[so] = false
  570.                     end
  571.                 end
  572.                 if e.API(Wa, Pa, Va, oo, 1) == true then
  573.                     data4[Ya] = Ka
  574.                     data5[Ya] = Pa
  575.                     data6[Ya] = Va
  576.                     local function ho()
  577.                         for ro = 1, 500 do
  578.                             if data4[ro] ~= false then
  579.                                 eo.setBackgroundColor(ao)
  580.                                 eo.setCursorPos(data5[ro], data6[ro])
  581.                                 eo.setTextColor(colors[Ba])
  582.                                 eo.write(data4[ro])
  583.                             end
  584.                         end
  585.                     end
  586.                     ho()
  587.                     eo.setCursorPos(data5[Ya], data6[Ya])
  588.                     eo.setBackgroundColor(colors[Ga])
  589.                     eo.setTextColor(colors[Ba])
  590.                     eo.write(Ka)
  591.                     eo.setTextColor(to)
  592.                     eo.setBackgroundColor(ao)
  593.                     menuout = Ka
  594.                     if Qa == nil then
  595.                         return menuout
  596.                     else
  597.                         if Ja == nil or Ja == false then
  598.                             menuout = Qa
  599.                             return menuout
  600.                         else
  601.                             menuout = {Qa, Xa}
  602.                             if menuout == nil then
  603.                                 return 0
  604.                             end
  605.                             return menuout
  606.                         end
  607.                     end
  608.                 end
  609.             end
  610.         end
  611.     end
  612.     thisIsUseless[Ya] = true
  613.     if Ja == true then
  614.         if menuout == nil then
  615.             menuout = {Qa, "nil"}
  616.         end
  617.     end
  618. end
  619. function e.menudata(...)
  620.     local re = {}
  621.     local re = table.pack(...)
  622.     local ty = type(menuout)
  623.     if ty == "string" or ty == "number" or ty == "function"  then
  624.         return menuout
  625.     elseif ty == "table" then
  626.         for k,v in pairs(menuout) do
  627.             if menuout[k] == "nil" then
  628.                 menuout[k] = re[k]
  629.             end
  630.         end
  631.         return table.unpack(menuout)
  632.     end
  633. end
  634. function e.bar(lo, uo, co, mo, fo, wo, yo, po, vo, bo, go, ko, qo, jo, xo, zo)
  635.     a(1, lo, "string")
  636.     a(2, uo, "number")
  637.     a(3, co, "number")
  638.     a(4, mo, "number")
  639.     a(5, fo, "number")
  640.     a(6, wo, "number")
  641.     a(7, yo, "number")
  642.     a(8, po, "string")
  643.     a(9, vo, "string")
  644.     a(10, bo, "string")
  645.     a(11, go, "boolean")
  646.     a(12, ko, "boolean")
  647.     a(13, qo, "string")
  648.     a(14, jo, "boolean")
  649.     a(15, xo, "boolean")
  650.     a(16, zo, "boolean")
  651.     if wo == nil or wo < 0 then
  652.         wo = 0
  653.     end
  654.     if jo == nil then
  655.     end
  656.     if wo ~= nil then
  657.         local Eo = peripheral.wrap(lo)
  658.         oldcol = Eo.getBackgroundColor()
  659.         oldcol1 = Eo.getTextColor()
  660.         Eo.setTextColor(colors[bo])
  661.         local function To()
  662.             Eo.setBackgroundColor(colors[po])
  663.             e.fill(lo, uo - 1, co - fo, mo, fo * 2)
  664.             Eo.setBackgroundColor(oldcol)
  665.             xm = Eo.getBackgroundColor()
  666.             xb = Eo.getTextColor()
  667.             Eo.setTextColor(xm)
  668.             Eo.setBackgroundColor(xb)
  669.             Eo.setCursorPos(uo - 1, co - fo)
  670.             if zo then
  671.                 Eo.setBackgroundColor(colors[bo])
  672.             end
  673.             if zo then
  674.                 Eo.write(string.rep("\x83", mo + 1))
  675.                 Eo.setTextColor(xb)
  676.                 Eo.setBackgroundColor(xm)
  677.             else
  678.                 Eo.write("\159" .. string.rep("\143", mo - 1))
  679.                 Eo.setTextColor(xb)
  680.                 Eo.setBackgroundColor(xm)
  681.                 Eo.write("\144")
  682.             end
  683.             if zo then
  684.                 Eo.setBackgroundColor(colors[bo])
  685.             end
  686.             Eo.setCursorPos(uo - 1, co + fo)
  687.             if zo then
  688.                 Eo.write(string.rep("\x8c", mo + 1))
  689.             else
  690.                 Eo.write("\130" .. string.rep("\131", mo - 1) .. "\129")
  691.             end
  692.             for Ao = 0, fo * 2 - 2 do
  693.                 if not zo then
  694.                     Eo.setTextColor(xm)
  695.                     Eo.setBackgroundColor(xb)
  696.                 end
  697.                 Eo.setCursorPos(uo - 1, co + Ao - fo + 1)
  698.                 if zo then
  699.                     Eo.setBackgroundColor(colors[bo])
  700.                 end
  701.                 Eo.write("\x95")
  702.                 Eo.setCursorPos(uo - 2 + (mo + 1), co + Ao - fo + 1)
  703.                 if not zo then
  704.                     Eo.setTextColor(xb)
  705.                     Eo.setBackgroundColor(xm)
  706.                 end
  707.                 Eo.write("\x95")
  708.             end
  709.         end
  710.         if xo ~= false then
  711.             To()
  712.         else
  713.             e.fill(lo, uo - 1, co - fo, mo, fo * 2)
  714.         end
  715.         local Oo = wo / yo * mo
  716.         local Io = wo / yo * fo
  717.         local No = math.ceil(Io)
  718.         local So = No * 2 - 2
  719.         local Ho = co + fo
  720.         Eo.setBackgroundColor(colors[vo])
  721.         if ko == false or ko == nil then
  722.             e.fill(lo, uo, co - fo + 1, Oo - 1, fo * 2 - 1)
  723.         else
  724.             e.fill(lo, uo, Ho - 1 - So, mo - 1, So + 1)
  725.         end
  726.         if go == true then
  727.             Eo.setCursorPos(uo, co)
  728.             Eo.setTextColor(colors[bo])
  729.             if ko == true then
  730.                 if jo then
  731.                     if wo >= yo / 2 then
  732.                         Eo.setBackgroundColor(colors[vo])
  733.                     else
  734.                         Eo.setBackgroundColor(colors[po])
  735.                     end
  736.                 else
  737.                     if wo >= yo / 2 - yo / fo then
  738.                         Eo.setBackgroundColor(colors[vo])
  739.                     else
  740.                         Eo.setBackgroundColor(colors[po])
  741.                     end
  742.                 end
  743.             elseif ko == false then
  744.                 Eo.setCursorPos(uo, co)
  745.                 Eo.setTextColor(colors[bo])
  746.                 if ko == true then
  747.                     if wo >= 1 then
  748.                         Eo.setBackgroundColor(colors[vo])
  749.                     else
  750.                         Eo.setBackgroundColor(colors[po])
  751.                     end
  752.                 end
  753.             end
  754.             if jo then
  755.                 Eo.write(wo .. "/" .. yo)
  756.                 Eo.setCursorPos(uo, co + 1)
  757.                 Eo.write(qo)
  758.             else
  759.                 Eo.write(wo .. "/" .. yo .. " " .. qo)
  760.             end
  761.             Eo.setBackgroundColor(oldcol)
  762.             Eo.setTextColor(oldcol1)
  763.         end
  764.         Eo.setTextColor(oldcol1)
  765.         Eo.setBackgroundColor(oldcol)
  766.     end
  767. end
  768. function e.frame(Ro, Do, Lo, Uo, Co, Mo, Fo, Wo)
  769.     a(1, Ro, "string")
  770.     a(2, Do, "number")
  771.     a(3, Lo, "number")
  772.     a(4, Uo, "number")
  773.     a(5, Co, "number")
  774.     a(6, Mo, "string")
  775.     a(7, Fo, "string")
  776.     a(8, Wo, "boolean", "nil")
  777.     local Yo = peripheral.wrap(Ro)
  778.     local Po = Yo.getBackgroundColor()
  779.     local Vo = Yo.getTextColor()
  780.     Yo.setBackgroundColor(colors[Fo])
  781.     e.fill(Ro, Do - 1, Lo - Co, Uo, Co * 2)
  782.     Yo.setBackgroundColor(Po)
  783.     xm = Yo.getBackgroundColor()
  784.     xb = Yo.getTextColor()
  785.     Yo.setTextColor(xm)
  786.     Yo.setBackgroundColor(xb)
  787.     Yo.setCursorPos(Do - 1, Lo - Co)
  788.     if Wo then
  789.         Yo.setBackgroundColor(colors[Mo])
  790.         Yo.setTextColor(Po)
  791.         Yo.write(string.rep("\x83", Uo + 1))
  792.         Yo.setTextColor(xb)
  793.         Yo.setBackgroundColor(xm)
  794.     else
  795.         Yo.setTextColor(Po)
  796.         Yo.setBackgroundColor(colors[Mo])
  797.         Yo.write("\159" .. string.rep("\143", Uo - 1))
  798.         Yo.setTextColor(colors[Mo])
  799.         Yo.setBackgroundColor(Po)
  800.         Yo.write("\144")
  801.     end
  802.     Yo.setCursorPos(Do - 1, Lo + Co)
  803.     if Wo then
  804.         Yo.setBackgroundColor(Po)
  805.         Yo.setTextColor(colors[Mo])
  806.         Yo.write(string.rep("\x8f", Uo + 1))
  807.         Yo.setBackgroundColor(colors[Fo])
  808.         Yo.setTextColor(colors[Mo])
  809.     else
  810.         Yo.write("\130" .. string.rep("\131", Uo - 1) .. "\129")
  811.     end
  812.     for Bo = 0, Co * 2 - 2 do
  813.         if not Wo then
  814.             Yo.setTextColor(xm)
  815.             Yo.setBackgroundColor(xb)
  816.         end
  817.         Yo.setCursorPos(Do - 1, Lo + Bo - Co + 1)
  818.         if Wo then
  819.             Yo.setBackgroundColor(colors[Mo])
  820.         end
  821.         Yo.setBackgroundColor(colors[Mo])
  822.         Yo.write("\x95")
  823.         Yo.setCursorPos(Do - 2 + (Uo + 1), Lo + Bo - Co + 1)
  824.         if not Wo then
  825.             Yo.setTextColor(xb)
  826.             Yo.setBackgroundColor(xm)
  827.         end
  828.         Yo.setTextColor(colors[Mo])
  829.         Yo.write("\x95")
  830.     end
  831.     Yo.setBackgroundColor(Po)
  832.     Yo.setTextColor(Vo)
  833. end
  834. function t.fill(Go, Ko, Qo, Jo, chars)
  835.     local char
  836.     if _9551_buttonH_doFillCharCustom  then
  837.         char = _9551_buttonH_doFillCharCustom      
  838.         _9551_buttonH_doFillCharCustom =  nil
  839.     else
  840.         char = " "
  841.     end
  842.     if not chars then
  843.         a(1, Go, "number")
  844.         a(2, Ko, "number")
  845.         a(3, Qo, "number")
  846.         a(4, Jo, "number")
  847.         for Xo = 0, Jo - 1 do
  848.             term.setCursorPos(Go, Ko + Xo)
  849.             term.write(string.rep(char, Qo))
  850.         end
  851.     else
  852.         _9551_buttonH_doFillCharCustom = chars
  853.     end
  854. end
  855. function t.API(Zo, ei, ti, ai, oi)
  856.     a(1, Zo, "table")
  857.     a(2, ei, "number")
  858.     a(3, ti, "number")
  859.     a(4, ai, "number")
  860.     a(5, oi, "number")
  861.     if Zo == true then
  862.         Zo = {os.pullEvent("mouse_click")}
  863.     end
  864.     if Zo[3] >= ei and Zo[3] <= ei + ai - 1 then
  865.         return Zo[4] >= ti and Zo[4] <= ti + oi - 1
  866.     end
  867. end
  868. function t.boxAPI(ii, ni, si, hi, ri, di)
  869.     a(1, ii, "table")
  870.     a(2, ni, "number")
  871.     a(3, si, "number")
  872.     a(4, hi, "number")
  873.     a(5, ri, "number")
  874.     a(6, di, "string")
  875.     local li = ni - hi + 1
  876.     local ui = si - ri
  877.     local ci = #di - 2
  878.     local mi = false
  879.     if hi >= 1 then
  880.         hi = hi - 1
  881.         mi = true
  882.     end
  883.     if hi > 0 or mi then
  884.         ci = #di + hi * 2
  885.         li = li - 1
  886.     end
  887.     local fi = ri * 2 + 1
  888.     return t.API(ii, li - 1, ui, ci + 2, fi), {li, ui, ci, fi}
  889. end
  890. function t.boxButton(wi, yi, pi, vi, bi, gi, ki, qi, ji)
  891.     a(1, wi, "number")
  892.     a(2, yi, "table")
  893.     a(3, pi, "number")
  894.     a(4, vi, "number")
  895.     a(5, bi, "string")
  896.     a(6, gi, "string")
  897.     a(7, ki, "string", "number", "nil")
  898.     a(8, qi, "number", "nil")
  899.     a(9, ji, "number", "nil")
  900.     if not qi then
  901.         qi = 0
  902.     end
  903.     if not ji then
  904.         ji = 0
  905.     end
  906.     if not ki then
  907.         ki = ""
  908.     end
  909.     local ki = tostring(ki)
  910.     if yi[2] == wi or yi[2] == "tout" then
  911.         if yi ~= nil then
  912.             local xi, zi = term.getTextColor(), term.getBackgroundColor()
  913.             term.setBackgroundColor(colors[bi])
  914.             term.setTextColor(colors[gi])
  915.             local Ei, Ti = t.boxAPI(yi, pi, vi, qi or 1, ji or 1, ki)
  916.             t.fill(Ti[1] - 1, Ti[2], Ti[3] + 2, Ti[4])
  917.             local Ai, Oi, Ii, Ni = Ti[1], Ti[2], Ti[3] + Ti[1], Ti[4] + Ti[2]
  918.             term.setCursorPos(math.floor(Ai + (Ii - Ai) / 2 - ki:len() / 2 + 0.5), math.floor(Oi + (Ni - Oi) / 2))
  919.             term.write(ki)
  920.             term.setBackgroundColor(zi)
  921.             term.setTextColor(xi)
  922.             return Ei
  923.         end
  924.     end
  925. end
  926. function t.touch()
  927.     local Si = {os.pullEvent("mouse_click")}
  928.     return Si
  929. end
  930. function t.timetouch(Hi,iG,drag)
  931.     a(1, Hi, "number", "nil")
  932.     local Ri
  933.     if Hi then
  934.         Ri = os.startTimer(Hi)
  935.     end
  936.     if drag then
  937.         while true do
  938.             local Di
  939.             if Hi then Di = {os.pullEvent()} end
  940.             if not Hi then Di = {os.pullEvent("mouse_click")} end
  941.             if not iG then
  942.                 if Di[1] == "timer" and Di[2] == Ri then
  943.                     return {"timeout", "tout", 1000, 1000}
  944.                 elseif (Di[1] == "mouse_click" or Di[1] == "mouse_drag") then
  945.                     return {Di[1], Di[2], Di[3], Di[4]}
  946.                 end
  947.             elseif iG then
  948.                 if Di[1] == "timer" and Di[2] == Ri then
  949.                     return {"timeout", "tout", 1000, 1000}
  950.                 elseif (Di[1] == "mouse_click" or Di[1] == "mouse_drag") and not iG[Di[2]] then
  951.                     return {Di[1], Di[2], Di[3], Di[4]}
  952.                 end
  953.             end
  954.         end
  955.     else
  956.         while true do
  957.             local Di
  958.             if Hi then Di = {os.pullEvent()} end
  959.             if not Hi then Di = {os.pullEvent("mouse_click")} end
  960.             if not iG then
  961.                 if Di[1] == "timer" and Di[2] == Ri then
  962.                     return {"timeout", "tout", 1000, 1000}
  963.                 elseif (Di[1] == "mouse_click") then
  964.                     return {Di[1], Di[2], Di[3], Di[4]}
  965.                 end
  966.             elseif iG then
  967.                 if Di[1] == "timer" and Di[2] == Ri then
  968.                     return {"timeout", "tout", 1000, 1000}
  969.                 elseif (Di[1] == "mouse_click") and not iG[Di[2]] then
  970.                     return {Di[1], Di[2], Di[3], Di[4]}
  971.                 end
  972.             end
  973.         end
  974.     end
  975. end
  976. function t.button(Li, Ui, Ci, Mi, Fi,addX)
  977.     local term = win or term
  978.     a(1, Li, "number")
  979.     a(2, Ui, "table")
  980.     a(3, Ci, "number")
  981.     a(4, Mi, "number")
  982.     a(5, Fi, "string")
  983.     if Ui[2] == Li or Ui[2] == "tout" then
  984.         if Ui ~= nil then
  985.             local Wi = t.API(Ui, Ci+(addX or 0), Mi, #Fi, 1)
  986.             term.setCursorPos(Ci, Mi)
  987.             term.write(Fi)
  988.             return Wi
  989.         end
  990.     end
  991. end
  992. function t.counter(Yi, Pi, Vi, Bi, Gi, Ki, Qi, Ji, Xi)
  993.     if Yi == "db" then
  994.         if data == nil then
  995.             return nil
  996.         else
  997.             return data[Pi]
  998.         end
  999.     end
  1000.     if Yi == "setdb" then
  1001.         if data == nil then
  1002.             return "no data to edit"
  1003.         else
  1004.             data[Pi] = Vi
  1005.             return "value changed too " .. type(Vi)
  1006.         end
  1007.     end
  1008.     a(1, Yi, "number")
  1009.     a(2, Pi, "table")
  1010.     a(3, Vi, "number")
  1011.     a(4, Bi, "number")
  1012.     a(5, Gi, "number")
  1013.     a(6, Ki, "number")
  1014.     a(7, Qi, "number")
  1015.     a(8, Ji, "number")
  1016.     a(9, Xi, "string")
  1017.     if Pi[2] == Yi or Pi[2] == "tout" then
  1018.         if Pi ~= nil then
  1019.             if data == nil then
  1020.                 data = {}
  1021.                 for Zi = 0, 1000 do
  1022.                     data[Zi] = 0
  1023.                 end
  1024.             end
  1025.             term.setCursorPos(Bi, Gi)
  1026.             term.write("\24" .. " " .. data[Vi])
  1027.             term.setCursorPos(Bi, Gi + 1)
  1028.             term.write("\25")
  1029.             if t.API(Pi, Bi, Gi, 1, 1) == true then
  1030.                 if data[Vi] < Qi then
  1031.                     data[Vi] = data[Vi] + Ki
  1032.                     term.setCursorPos(Bi, Gi)
  1033.                     term.setTextColor(colors.green)
  1034.                     term.write("\24" .. " " .. data[Vi] .. " ")
  1035.                     term.setCursorPos(Bi, Gi + 1)
  1036.                     term.setTextColor(colors.red)
  1037.                     term.write("\25")
  1038.                     term.setTextColor(colors[Xi])
  1039.                     return data[Vi]
  1040.                 end
  1041.             end
  1042.         end
  1043.         if t.API(Pi, Bi, Gi + 1, 1, 1) == true then
  1044.             if data[Vi] > Ji then
  1045.                 data[Vi] = data[Vi] - Ki
  1046.                 term.setCursorPos(Bi, Gi)
  1047.                 term.setTextColor(colors.green)
  1048.                 term.write("\24" .. " " .. data[Vi] .. " ")
  1049.                 term.setCursorPos(Bi, Gi + 1)
  1050.                 term.setTextColor(colors.red)
  1051.                 term.write("\25")
  1052.                 term.setTextColor(colors[Xi])
  1053.                 return data[Vi]
  1054.             end
  1055.         end
  1056.     end
  1057. end
  1058. function t.switch(en, tn, an, on, nn, sn, hn, rn, dn, ln, un)
  1059.     if en == "db" then
  1060.         if data1 == nil then
  1061.             return nil
  1062.         else
  1063.             return data1[tn]
  1064.         end
  1065.     end
  1066.     if en == "setdb" then
  1067.         if data1 == nil then
  1068.             return "no data to edit"
  1069.         else
  1070.             data1[tn] = an
  1071.             return "value changed too " .. type(an)
  1072.         end
  1073.     end
  1074.     a(1, en, "number")
  1075.     a(2, tn, "number")
  1076.     a(3, an, "table")
  1077.     a(4, on, "number")
  1078.     a(5, nn, "number")
  1079.     a(6, sn, "string")
  1080.     a(7, hn, "string")
  1081.     a(8, rn, "string")
  1082.     a(9, dn, "string")
  1083.     a(10, ln, "number", "nil")
  1084.     a(11, un, "number", "nil")
  1085.     local fn
  1086.     if an[2] == en or an[2] == "tout" then
  1087.         if an ~= nil then
  1088.             if data1 == nil then
  1089.                 data1 = {}
  1090.                 for cn = 0, 1000 do
  1091.                     data1[cn] = false
  1092.                 end
  1093.             end
  1094.             local function mn()
  1095.                 data1[tn] = not data1[tn]
  1096.             end
  1097.             if not data1[tn] then
  1098.                 fn = sn
  1099.             else
  1100.                 fn = hn
  1101.             end
  1102.             if t.boxButton(en, an, on, nn, fn, rn, dn, ln, un) then
  1103.                 mn()
  1104.             end
  1105.             return data1[tn]
  1106.         end
  1107.     elseif an and data1 ~= nil and fn then
  1108.         t.boxButton(en, an, on, nn, fn, rn, dn, ln, un)
  1109.     end
  1110. end
  1111. function t.switchn(wn, yn, pn, vn, bn, gn, kn, qn, jn, xn, zn, En)
  1112.     if wn == "db" then
  1113.         if data2 == nil then
  1114.             return nil
  1115.         else
  1116.             return data2[yn]
  1117.         end
  1118.     end
  1119.     if wn == "setdb" then
  1120.         if data2 == nil then
  1121.             return "no data to edit"
  1122.         else
  1123.             data2[yn] = pn
  1124.             return "value changed too " .. type(pn)
  1125.         end
  1126.     end
  1127.     a(1, wn, "number")
  1128.     a(2, yn, "number")
  1129.     a(3, pn, "table")
  1130.     a(4, vn, "number")
  1131.     a(5, bn, "number")
  1132.     a(6, gn, "string")
  1133.     a(7, kn, "string")
  1134.     a(8, qn, "string")
  1135.     a(9, jn, "string")
  1136.     a(10, xn, "string")
  1137.     a(11, zn, "number", "nil")
  1138.     a(12, En, "number", "nil")
  1139.     local On
  1140.     local In
  1141.     if pn[2] == wn or pn[2] == "tout" then
  1142.         if pn ~= nil then
  1143.             if data2 == nil then
  1144.                 data2 = {}
  1145.                 for Tn = 0, 1000 do
  1146.                     data2[Tn] = false
  1147.                 end
  1148.             end
  1149.             local function An()
  1150.                 data2[yn] = not data2[yn]
  1151.             end
  1152.             if not data2[yn] then
  1153.                 On = gn
  1154.                 In = jn
  1155.             else
  1156.                 On = kn
  1157.                 In = xn
  1158.             end
  1159.             if t.boxButton(wn, pn, vn, bn, On, qn, In, zn, En) then
  1160.                 An()
  1161.             end
  1162.         end
  1163.     elseif pn and data2 ~= nil and On and In then
  1164.         t.boxButton(wn, pn, vn, bn, On, qn, In, zn, En)
  1165.     end
  1166. end
  1167. function t.bundle(Nn, Sn, Hn)
  1168.     a(1, Nn, "string")
  1169.     a(2, Sn, "number")
  1170.     a(3, Hn, "boolean")
  1171.     if type(Nn) == "string" and type(Sn) == "number" and type(Hn) == "boolean" then
  1172.         if Hn == true then
  1173.             rs.setBundledOutput(Nn, colors.combine(rs.getBundledOutput(Nn), Sn))
  1174.         elseif Hn == false then
  1175.             rs.setBundledOutput(Nn, colors.subtract(rs.getBundledOutput(Nn), Sn))
  1176.         end
  1177.     else
  1178.         error("please use like this:\nbundle(side:string,colors.(color),state:boolean)")
  1179.     end
  1180. end
  1181. function t.signal(ea, ta, aa, oa)
  1182.     a(1, ea, "string")
  1183.     a(2, ta, "boolean", "string")
  1184.     a(3, aa, "number","string")
  1185.     a(4, oa, "boolean")
  1186.     if ta == "clear" then
  1187.         rs.setBundledOutput(ea, 0)
  1188.     else
  1189.         if oa == true then
  1190.             if ta == "on" then
  1191.                 ta = true
  1192.             end
  1193.             if ta == "nil" then
  1194.                 ta = false
  1195.             end
  1196.         end
  1197.         if ta ~= nil then
  1198.             if type(aa) == "number" then
  1199.                 if ta == true then
  1200.                     t.bundle(ea, aa, true)
  1201.                 elseif ta == false then
  1202.                     t.bundle(ea, aa, false)
  1203.                 end
  1204.             elseif type(aa) == "string" then
  1205.                 if ta == true then
  1206.                     t.bundle(ea, colors[aa], true)
  1207.                 elseif ta == false then
  1208.                     t.bundle(ea, colors[aa], false)
  1209.                 end
  1210.             end
  1211.         end
  1212.     end
  1213. end
  1214. function t.sliderHor(Cn, Mn, Fn, Wn, Yn, Pn, Vn, Bn)
  1215.     if Cn == "db" then
  1216.         if data3 == nil then
  1217.             return nil
  1218.         else
  1219.             return data3[Mn]
  1220.         end
  1221.     end
  1222.     if Cn == "setdb" then
  1223.         if data3 == nil then
  1224.             return "no data to edit"
  1225.         else
  1226.             data3[Mn] = Fn
  1227.             return "value changed too " .. type(Fn)
  1228.         end
  1229.     end
  1230.     a(1, Cn, "number")
  1231.     a(2, Mn, "table")
  1232.     a(3, Fn, "number")
  1233.     a(4, Wn, "number")
  1234.     a(5, Yn, "number")
  1235.     a(6, Pn, "number")
  1236.     a(7, Vn, "string")
  1237.     a(8, Bn, "string")
  1238.     if Mn[2] == Cn or Mn[2] == "tout" then
  1239.         if Mn ~= nil then
  1240.             local Gn = term.getBackgroundColor()
  1241.             local Kn = term.getTextColor()
  1242.             term.setBackgroundColor(colors[Vn])
  1243.             term.setTextColor(colors[Bn])
  1244.             term.setCursorPos(Wn, Yn)
  1245.             for Qn = 0, Pn do
  1246.                 term.write("-")
  1247.                 term.setCursorPos(Wn + Qn, Yn)
  1248.             end
  1249.             if data3 == nil then
  1250.                 data3 = {}
  1251.                 for Jn = 0, 10000 do
  1252.                     data3[Jn] = 0
  1253.                 end
  1254.             end
  1255.             local Xn = Mn[3]
  1256.             if Mn[4] == Yn and Mn[3] >= Wn and Mn[3] <= Wn + Pn - 1 then
  1257.                 term.setCursorPos(Xn, Yn)
  1258.                 data3[Fn] = Xn
  1259.                 term.write("|")
  1260.             else
  1261.                 term.setCursorPos(data3[Fn], Yn)
  1262.                 term.write("|")
  1263.             end
  1264.             term.setBackgroundColor(Gn)
  1265.             term.setTextColor(Kn)
  1266.             if data3[Fn] - Wn >= 0 then
  1267.                 return data3[Fn] - Wn
  1268.             elseif data3[Fn] - Wn < 0 then
  1269.                 return 0
  1270.             end
  1271.         end
  1272.     end
  1273. end
  1274. function t.sliderVer(Zn, es, ts, as, is, ns, ss, hs)
  1275.     if Zn == "db" then
  1276.         if data10 == nil then
  1277.             return nil
  1278.         else
  1279.             return data10[es]
  1280.         end
  1281.     end
  1282.     if Zn == "setdb" then
  1283.         if data10 == nil then
  1284.             return "no data to edit"
  1285.         else
  1286.             data10[es] = ts
  1287.             return "value changed too " .. type(ts)
  1288.         end
  1289.     end
  1290.     a(1, Zn, "number")
  1291.     a(2, es, "table")
  1292.     a(3, ts, "number")
  1293.     a(4, as, "number")
  1294.     a(5, is, "number")
  1295.     a(6, ns, "number")
  1296.     a(7, ss, "string")
  1297.     a(8, hs, "string")
  1298.     if es[2] == Zn or es[2] == "tout" then
  1299.         if es ~= nil then
  1300.             local ds = term.getBackgroundColor()
  1301.             local ls = term.getTextColor()
  1302.             term.setBackgroundColor(colors[ss])
  1303.             term.setTextColor(colors[hs])
  1304.             term.setCursorPos(as, is)
  1305.             for us = 0, ns do
  1306.                 term.write("\124")
  1307.                 term.setCursorPos(as, is - us)
  1308.             end
  1309.             if data10 == nil then
  1310.                 data10 = {}
  1311.                 for cs = 0, 10000 do
  1312.                     data10[cs] = 0
  1313.                 end
  1314.             end
  1315.             local ms = es[4]
  1316.             if es[3] == as and es[4] <= is and es[4] >= is - ns + 1 then
  1317.                 term.setCursorPos(as, ms)
  1318.                 data10[ts] = ms
  1319.                 term.write("\xad")
  1320.             else
  1321.                 term.setCursorPos(as, data10[ts])
  1322.                 term.write("\xad")
  1323.             end
  1324.             term.setBackgroundColor(ds)
  1325.             term.setTextColor(ls)
  1326.             if data10[ts] - as >= 0 then
  1327.                 return data10[ts] - as
  1328.             elseif data10[ts] - as < 0 then
  1329.                 return 0
  1330.             end
  1331.         end
  1332.     end
  1333. end
  1334. function t.render(fs, ws, ys, ps, vs)
  1335.     a(1, fs, "string")
  1336.     a(2, ws, "number")
  1337.     a(3, ys, "number")
  1338.     a(4, ps, "string")
  1339.     a(5, vs, "string", "number")
  1340.     local bs = term.getBackgroundColor()
  1341.     local gs = term.getTextColor()
  1342.     local ks = {term.getCursorPos()}
  1343.     term.setTextColor(colors[ps])
  1344.     if type(vs) == "string" then
  1345.         term.setBackgroundColor(colors[vs])
  1346.     elseif type(vs) == "number" then
  1347.         term.setBackgroundColor(vs)
  1348.     end
  1349.     term.setCursorPos(ws, ys)
  1350.     term.write(fs)
  1351.     term.setBackgroundColor(bs)
  1352.     term.setTextColor(gs)
  1353.     term.setCursorPos(ks[1], ks[2])
  1354. end
  1355. function t.menu(qs, js, xs, zs, Es, Ts, As, Os, Is, Ns, Ss)
  1356.     a(1, qs, "number")
  1357.     a(2, js, "table")
  1358.     a(3, xs, "number")
  1359.     a(4, zs, "number")
  1360.     a(5, Es, "number")
  1361.     a(6, Ts, "string")
  1362.     a(7, As, "string")
  1363.     a(8, Os, "string")
  1364.     a(9, Is, "string", "number", "boolean", "nil")
  1365.     a(10, Ns, "boolean", "nil")
  1366.     a(11, Ss, "string", "number", "boolean", "nil")
  1367.     if js[2] == qs or js[2] == "tout" then
  1368.         if thisIsUseless == nil then
  1369.             for Hs = 0, 1000 do
  1370.                 thisIsUseless = {}
  1371.                 thisIsUseless[Hs] = false
  1372.             end
  1373.         end
  1374.         if not thisIsUseless[xs] then
  1375.             local tcol = term.getBackgroundColor()
  1376.             t.render(Os, zs, Es, Ts, tcol)
  1377.         end
  1378.         if js ~= nil then
  1379.             local Rs = term.getTextColor()
  1380.             local Ds = term.getBackgroundColor()
  1381.             local Ls = #Os
  1382.             if js[1] ~= "timeout" then
  1383.                 if data4 == nil then
  1384.                     data4 = {}
  1385.                     for Us = 0, 1000 do
  1386.                         data4[Us] = false
  1387.                     end
  1388.                 end
  1389.                 if data5 == nil then
  1390.                     data5 = {}
  1391.                     for Cs = 0, 1000 do
  1392.                         data5[Cs] = false
  1393.                     end
  1394.                 end
  1395.                 if data6 == nil then
  1396.                     data6 = {}
  1397.                     for Ms = 0, 1000 do
  1398.                         data6[Ms] = false
  1399.                     end
  1400.                 end
  1401.                 if t.API(js, zs, Es, Ls, 1) == true then
  1402.                     data4[xs] = Os
  1403.                     data5[xs] = zs
  1404.                     data6[xs] = Es
  1405.                     local function Fs()
  1406.                         for Ws = 1, 500 do
  1407.                             if data4[Ws] ~= false then
  1408.                                 term.setBackgroundColor(Ds)
  1409.                                 term.setCursorPos(data5[Ws], data6[Ws])
  1410.                                 term.setTextColor(colors[Ts])
  1411.                                 term.write(data4[Ws])
  1412.                             end
  1413.                         end
  1414.                     end
  1415.                     Fs()
  1416.                     term.setCursorPos(data5[xs], data6[xs])
  1417.                     term.setBackgroundColor(colors[As])
  1418.                     term.setTextColor(colors[Ts])
  1419.                     term.write(Os)
  1420.                     term.setTextColor(Rs)
  1421.                     term.setBackgroundColor(Ds)
  1422.                     menuout = Os
  1423.                     if Is == nil then
  1424.                         return menuout
  1425.                     else
  1426.                         if Ns == nil or Ns == false then
  1427.                             menuout = Is
  1428.                             return menuout
  1429.                         else
  1430.                             menuout = {Is, Ss}
  1431.                             if menuout == nil then
  1432.                                 return 0
  1433.                             end
  1434.                             return menuout
  1435.                         end
  1436.                     end
  1437.                 end
  1438.             end
  1439.         end
  1440.     end
  1441.     thisIsUseless[xs] = true
  1442.     if Ns == true then
  1443.         if menuout == nil then
  1444.             menuout = {Is, "nil"}
  1445.         end
  1446.     end
  1447. end
  1448. function t.menudata(...)
  1449.     local re = {}
  1450.     local re = table.pack(...)
  1451.     local ty = type(menuout)
  1452.     if ty == "string" or ty == "number" or ty == "function"  then
  1453.         return menuout
  1454.     elseif ty == "table" then
  1455.         for k,v in pairs(menuout) do
  1456.             if menuout[k] == "nil" then
  1457.                 menuout[k] = re[k]
  1458.             end
  1459.         end
  1460.         return table.unpack(menuout)
  1461.     end
  1462. end
  1463. function t.bar(Ys, Ps, Vs, Bs, Gs, Ks, Qs, Js, Xs, Zs, eh, th, ah, oh, ih)
  1464.     a(1, Ys, "number")
  1465.     a(2, Ps, "number")
  1466.     a(3, Vs, "number")
  1467.     a(4, Bs, "number")
  1468.     a(5, Gs, "number")
  1469.     a(6, Ks, "number")
  1470.     a(7, Qs, "string")
  1471.     a(8, Js, "string")
  1472.     a(9, Xs, "string")
  1473.     a(10, Zs, "boolean")
  1474.     a(11, eh, "boolean")
  1475.     a(12, th, "string")
  1476.     a(13, ah, "boolean")
  1477.     a(14, oh, "boolean")
  1478.     a(15, ih, "boolean")
  1479.     if Gs == nil or Gs < 0 then
  1480.         Gs = 0
  1481.     end
  1482.     if ah == nil then
  1483.     end
  1484.     if Gs ~= nil then
  1485.         oldcol = term.getBackgroundColor()
  1486.         oldcol1 = term.getTextColor()
  1487.         term.setTextColor(colors[Xs])
  1488.         local function nh()
  1489.             term.setBackgroundColor(colors[Qs])
  1490.             t.fill(Ys - 1, Ps - Bs, Vs, Bs * 2)
  1491.             term.setBackgroundColor(oldcol)
  1492.             xm = term.getBackgroundColor()
  1493.             xb = term.getTextColor()
  1494.             term.setTextColor(xm)
  1495.             term.setBackgroundColor(xb)
  1496.             term.setCursorPos(Ys - 1, Ps - Bs)
  1497.             if ih then
  1498.                 term.setBackgroundColor(colors[Xs])
  1499.             end
  1500.             if ih then
  1501.                 term.write(string.rep("\x83", Vs + 1))
  1502.                 term.setTextColor(xb)
  1503.                 term.setBackgroundColor(xm)
  1504.             else
  1505.                 term.write("\159" .. string.rep("\143", Vs - 1))
  1506.                 term.setTextColor(xb)
  1507.                 term.setBackgroundColor(xm)
  1508.                 term.write("\144")
  1509.             end
  1510.             if ih then
  1511.                 term.setBackgroundColor(colors[Xs])
  1512.             end
  1513.             term.setCursorPos(Ys - 1, Ps + Bs)
  1514.             if ih then
  1515.                 term.write(string.rep("\x8c", Vs + 1))
  1516.             else
  1517.                 term.write("\130" .. string.rep("\131", Vs - 1) .. "\129")
  1518.             end
  1519.             for sh = 0, Bs * 2 - 2 do
  1520.                 if not ih then
  1521.                     term.setTextColor(xm)
  1522.                     term.setBackgroundColor(xb)
  1523.                 end
  1524.                 term.setCursorPos(Ys - 1, Ps + sh - Bs + 1)
  1525.                 if ih then
  1526.                     term.setBackgroundColor(colors[Xs])
  1527.                 end
  1528.                 term.write("\x95")
  1529.                 term.setCursorPos(Ys - 2 + (Vs + 1), Ps + sh - Bs + 1)
  1530.                 if not ih then
  1531.                     term.setTextColor(xb)
  1532.                     term.setBackgroundColor(xm)
  1533.                 end
  1534.                 term.write("\x95")
  1535.             end
  1536.         end
  1537.         if oh ~= false then
  1538.             nh()
  1539.         else
  1540.             t.fill(Ys - 1, Ps - Bs, Vs, Bs * 2)
  1541.         end
  1542.         local hh = Gs / Ks * Vs
  1543.         local rh = Gs / Ks * Bs
  1544.         local dh = math.ceil(rh)
  1545.         local lh = dh * 2 - 2
  1546.         local uh = Ps + Bs
  1547.         term.setBackgroundColor(colors[Js])
  1548.         if eh == false or eh == nil then
  1549.             t.fill(Ys, Ps - Bs + 1, hh - 1, Bs * 2 - 1)
  1550.         else
  1551.             t.fill(Ys, uh - 1 - lh, Vs - 1, lh + 1)
  1552.         end
  1553.         if Zs == true then
  1554.             term.setCursorPos(Ys, Ps)
  1555.             term.setTextColor(colors[Xs])
  1556.             if eh == true then
  1557.                 if ah then
  1558.                     if Gs >= Ks / 2 then
  1559.                         term.setBackgroundColor(colors[Js])
  1560.                     else
  1561.                         term.setBackgroundColor(colors[Qs])
  1562.                     end
  1563.                 else
  1564.                     if Gs >= Ks / 2 - Ks / Bs then
  1565.                         term.setBackgroundColor(colors[Js])
  1566.                     else
  1567.                         term.setBackgroundColor(colors[Qs])
  1568.                     end
  1569.                 end
  1570.             elseif eh == false then
  1571.                 term.setCursorPos(Ys, Ps)
  1572.                 term.setTextColor(colors[Xs])
  1573.                 if eh == true then
  1574.                     if Gs >= 1 then
  1575.                         term.setBackgroundColor(colors[Js])
  1576.                     else
  1577.                         term.setBackgroundColor(colors[Qs])
  1578.                     end
  1579.                 end
  1580.             end
  1581.             if ah then
  1582.                 term.write(Gs .. "/" .. Ks)
  1583.                 term.setCursorPos(Ys, Ps + 1)
  1584.                 term.write(th)
  1585.             else
  1586.                 term.write(Gs .. "/" .. Ks .. " " .. th)
  1587.             end
  1588.             term.setBackgroundColor(oldcol)
  1589.             term.setTextColor(oldcol1)
  1590.         end
  1591.         term.setTextColor(oldcol1)
  1592.         term.setBackgroundColor(oldcol)
  1593.     end
  1594. end
  1595. function t.frame(ch, mh, fh, wh, yh, ph, vh)
  1596.     a(1, ch, "number")
  1597.     a(2, mh, "number")
  1598.     a(3, fh, "number")
  1599.     a(4, wh, "number")
  1600.     a(5, yh, "string")
  1601.     a(6, ph, "string")
  1602.     a(7, vh, "boolean", "nil")
  1603.     local bh = term.getBackgroundColor()
  1604.     local gh = term.getTextColor()
  1605.     term.setBackgroundColor(colors[ph])
  1606.     t.fill(ch - 1, mh - wh, fh, wh * 2)
  1607.     term.setBackgroundColor(bh)
  1608.     xm = term.getBackgroundColor()
  1609.     xb = term.getTextColor()
  1610.     term.setTextColor(xm)
  1611.     term.setBackgroundColor(xb)
  1612.     term.setCursorPos(ch - 1, mh - wh)
  1613.     if vh then
  1614.         term.setBackgroundColor(colors[yh])
  1615.         term.setTextColor(bh)
  1616.         term.write(string.rep("\x83", fh + 1))
  1617.         term.setTextColor(xb)
  1618.         term.setBackgroundColor(xm)
  1619.     else
  1620.         term.setTextColor(bh)
  1621.         term.setBackgroundColor(colors[yh])
  1622.         term.write("\159" .. string.rep("\143", fh - 1))
  1623.         term.setTextColor(colors[yh])
  1624.         term.setBackgroundColor(bh)
  1625.         term.write("\144")
  1626.     end
  1627.     term.setCursorPos(ch - 1, mh + wh)
  1628.     if vh then
  1629.         term.setBackgroundColor(bh)
  1630.         term.setTextColor(colors[yh])
  1631.         term.write(string.rep("\x8f", fh + 1))
  1632.         term.setBackgroundColor(colors[ph])
  1633.         term.setTextColor(colors[yh])
  1634.     else
  1635.         term.write("\130" .. string.rep("\131", fh - 1) .. "\129")
  1636.     end
  1637.     for kh = 0, wh * 2 - 2 do
  1638.         if not vh then
  1639.             term.setTextColor(xm)
  1640.             term.setBackgroundColor(xb)
  1641.         end
  1642.         term.setCursorPos(ch - 1, mh + kh - wh + 1)
  1643.         if vh then
  1644.             term.setBackgroundColor(colors[yh])
  1645.         end
  1646.         term.setBackgroundColor(colors[yh])
  1647.         term.write("\x95")
  1648.         term.setCursorPos(ch - 2 + (fh + 1), mh + kh - wh + 1)
  1649.         if not vh then
  1650.             term.setTextColor(xb)
  1651.             term.setBackgroundColor(xm)
  1652.         end
  1653.         term.setTextColor(colors[yh])
  1654.         term.write("\x95")
  1655.     end
  1656.     term.setBackgroundColor(bh)
  1657.     term.setTextColor(gh)
  1658. end
  1659. return {monitor = e, terminal = t}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement