superkh

config API

Jan 20th, 2016
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.27 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw
  2. --Vars-------------------------------------------------------------------
  3. local w,h = term.getSize()
  4. local rng = true
  5. local src = A.RCpath()
  6. local User = A.RUser()
  7. local conf = {}
  8. local cm = 0
  9. local txy = {}
  10. local cT = {}
  11. local xy2 = {0,0}
  12. local t = nil
  13. local ctable = nil
  14. local colorsC = nil
  15. local tbP = {}
  16. local tbl2 = {}
  17. local tbl3 = {}
  18. local xy = {0,0}
  19. --buffers--
  20. local figBuffer = nil
  21. local bImageOps = buf.createBuffer()
  22. ---------------------------------------------------------------------------
  23. local function setT(src,save)
  24.       local file = fs.open(src,"w")
  25.       file.write(textutils.serialize(save))
  26.       file.close()
  27. end
  28. local function getUser()
  29.     src = A.RCpath()
  30.     User = A.RUser()
  31. end
  32. local function dImageOps()
  33.     tbP = { }
  34.     for v,k in ipairs(fs.list("os/images")) do
  35.         if fs.isDir("os/images/"..k) then
  36.             if ("os/images/"..k)=="os/images/icons" then
  37.             else
  38.                 for s,d in ipairs(fs.list("os/images/"..k)) do
  39.                     table.insert(tbP,k.."/"..d)
  40.                 end
  41.             end
  42.         else
  43.             table.insert(tbP,k)
  44.         end
  45.     end
  46.     local x = 7
  47.     local y = 2
  48.     local x2 = w-8
  49.     local y2 = h-1
  50.     buf.drawFilledBox(bImageOps,x+1,y+1,x2-2,y2-1,colors.white)
  51.     buf.drawBox(bImageOps,x,y,x2,y2,colors.gray)
  52.     buf.drawLine(bImageOps,x2-1,y+2,x2-1,y2-2,colors.orange)
  53.     buf.pos(x2-1,y+1)
  54.     buf.bWrite(bImageOps,"^",colors.white,colors.red)
  55.     buf.pos(x2-1,y2-1)
  56.     buf.bWrite(bImageOps,"v",colors.white,colors.red)
  57.     local X = x+2
  58.     local Y = y+1
  59.     buf.bc(colors.white)
  60.     buf.tc(colors.black)
  61.     for v,k in ipairs(tbP) do
  62.         buf.pos(X,Y)
  63.         buf.bWriteL(bImageOps,k)
  64.         local t = {X-1,X+#k,Y,k} -- x1 x2 y (file name) os/images/kyle = kyle
  65.         table.insert(tbl2,t)
  66.         Y=Y+1
  67.     end
  68.     buf.drawBuffer(bImageOps)
  69. end
  70. local function drawOps()
  71.     local w,h = term.getSize()
  72.     txy = {}
  73.     local x = 2
  74.     local y = 3
  75.     local t = {"Background Image:","Background Color:","Meun Color:","Meun Text Color:","Side Meun Color:","Side Meun Text Color:","Config Background Image:","Config Background Color:","Config Text Color:"}
  76.     local tt = {"BCI","BCC","MC","MTC","SMC","SMTC","CBI","CBC","CTC"}
  77.     local curt = 1
  78.     buf.tc(colors.white)
  79.     buf.bc(colors.black)
  80.     for v,k in ipairs(t) do
  81.         buf.pos(x,y)
  82.         buf.bc(conf["CBC"])
  83.         buf.tc(conf["CTC"])
  84.         buf.bWriteLP(figBuffer,k.." ")
  85.         buf.tc(colors.red)
  86.         local type1 = "string"
  87.         local tn = {}
  88.         if type(conf[tt[curt]])=="number" then
  89.             type1="number"
  90.             if (conf[tt[curt]])~=conf["CBC"] then
  91.                 buf.bc(conf[tt[curt]])
  92.                 buf.bWriteLP(figBuffer,"   ")
  93.                 tn = {x+#k+1,x+#k+3,y,type1,tostring(tt[curt])}
  94.             else
  95.                 for g,f in ipairs(colorsC) do
  96.                     if f[1]==conf[tt[curt]] then
  97.                         buf.bc(f[3])
  98.                         buf.tc(f[1])
  99.                         buf.bWriteLP(figBuffer,string.rep(" ",#f[2]+2))
  100.                         buf.pos(x+#k+2,y)
  101.                         buf.bWriteLP(figBuffer,f[2])
  102.                         tn = {x+#k+1,x+#k+7,y,type1,tostring(tt[curt])}
  103.                     end
  104.                 end
  105.             end
  106.         else
  107.             buf.bWriteLP(figBuffer,tostring(conf[tt[curt]]))
  108.             type1="Image"
  109.             tn = {x+#k+1,x+#k+#conf[tt[curt]],y,type1,tostring(tt[curt])}
  110.         end
  111.         buf.bc(conf["CBC"])
  112.         --tn = (x1, x2, y, type ) type = string or color
  113.         table.insert(txy,1,tn)
  114.         curt=curt+1
  115.         y=y+1
  116.     end
  117.     buf.pos(2,h-4)
  118.     buf.tc(conf["CTC"])
  119.     buf.bWriteLP(figBuffer,"UserName:")
  120.     buf.tc(colors.red)
  121.     buf.bWriteLP(figBuffer,tostring(User))
  122.     tn = {11,11+#User-1,h-4,"file",User}
  123.     table.insert(txy,1,tn)
  124.     buf.pos(2,h-2)
  125.     buf.tc(conf["CTC"])
  126.     buf.bWriteLP(figBuffer,"PassWord:")
  127.     buf.tc(colors.red)
  128.     buf.bWriteLP(figBuffer,tostring(conf["PW"]))
  129.     tn = {11,11+#conf["PW"],h-2,"string","PW"}
  130.     table.insert(txy,1,tn)
  131. end
  132. local function dm()
  133.     conf = A.getT(src)
  134.     colorsC = A.getT("os/files/colorsC")
  135.     buf.bc(conf["CBC"])
  136.     A.dfig()
  137.     drawOps()
  138.     buf.copyBuffer(figBuffer,bImageOps)
  139.     buf.drawBuffer(figBuffer)
  140.     A.Time(w-4,h,conf["MC"],conf["MTC"])
  141. end
  142. function main()
  143.     figBuffer = A.RFmeun()
  144.     conf = A.getT(src)
  145.     colorsC = A.getT("os/files/colorsC")
  146.     dm()
  147.     t = os.startTimer(.1)
  148.     while true do
  149.         getUser()
  150.         conf = A.getT(src)
  151.         local arg = { os.pullEvent() }
  152.         if arg[1]=="timer" and arg[2]==t then
  153.             A.Time(w-3,h,conf["MC"],conf["MTC"])
  154.             t = os.startTimer(.1)
  155.         elseif cm==0 then
  156.             if arg[1]=="mouse_click" then
  157.                 if arg[2]==1 then
  158.                     if arg[3]>=2 and arg[3]<=8 and arg[4]==1 then
  159.                         A.dmeun5()
  160.                         cm=1
  161.                     else
  162.                         local ok = false
  163.                         local x = arg[3]
  164.                         local y = arg[4]
  165.                         -- tn = (x1, x2, y, type ) tpye = string or color
  166.                         for v,k in ipairs(txy) do
  167.                             if x>=k[1] and x<=k[2] then
  168.                                 if y==k[3] then
  169.                                     term.setTextColor(colors.white)
  170.                                     ok = true
  171.                                     cT = txy[v]
  172.                                 end
  173.                             end
  174.                         end
  175.                         if ok then
  176.                             cm=2
  177.                         else
  178.                             dm()
  179.                         end
  180.                     end
  181.                 elseif arg[2]==2 then
  182.                     xy = {A.dmeun6(arg[3],arg[4])}
  183.                     cm=5
  184.                 end
  185.             end
  186.         elseif cm==1 then
  187.             if arg[1]=="mouse_click" then
  188.                 if arg[2]==1 then
  189.                     if arg[3]>=2 and arg[3]<=11 then
  190.                         if arg[4]==3 then
  191.                             A.ExitIS(true,true)
  192.                             break
  193.                         elseif arg[4]==4 then
  194.                             os.shutdown()
  195.                         elseif arg[4]==5 then
  196.                             os.reboot()
  197.                         elseif arg[4]==6 then
  198.                             break
  199.                         else
  200.                             dm()
  201.                             cm=0
  202.                         end
  203.                     else
  204.                         dm()
  205.                         cm=0
  206.                     end
  207.                 else
  208.                     dm()
  209.                     cm=0
  210.                 end
  211.             end
  212.         elseif cm==2 then
  213.             if cT[4]=="string" then
  214.                 term.setCursorPos(cT[1],cT[3])
  215.                 term.setBackgroundColor(colors.black)
  216.                 term.setTextColor(colors.green)
  217.                 write(string.rep(" ",cT[2]-cT[1]+1))
  218.                 term.setCursorPos(cT[1],cT[3])
  219.                 local input = read()
  220.                 sleep(.2)
  221.                 if input~=conf[cT[5]] then
  222.                     conf[cT[5]]=input
  223.                 end
  224.                 setT(src,conf)
  225.                 dm()
  226.                 cm=0
  227.             elseif cT[4]=="Image" then
  228.                 dImageOps()
  229.                 t = os.startTimer(.1)
  230.                 cm=4
  231.             elseif cT[4]=="number" then
  232.                 ctable = {}
  233.                 local function color()
  234.                     local t = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768}
  235.                     local x = cT[2]+2
  236.                     local y = cT[3]
  237.                     for v,k in ipairs(t) do
  238.                         term.setBackgroundColor(k)
  239.                         write(" ")
  240.                         local ct = {x,y,k}
  241.                         table.insert(ctable,ct)
  242.                         x=x+1
  243.                     end
  244.                 end
  245.                 term.setCursorPos(cT[2]+2,cT[3])
  246.                 color()
  247.                 cm=3
  248.             elseif cT[4]=="file" then
  249.                 term.setCursorPos(cT[1],cT[3])
  250.                 term.setBackgroundColor(colors.black)
  251.                 term.setTextColor(colors.green)
  252.                 write(string.rep(" ",cT[2]-cT[1]+1))
  253.                 term.setCursorPos(cT[1],cT[3])
  254.                 local input = read()
  255.                 sleep(.2)
  256.                 --tn = {11,11+#User-1,h-4,"file",User}
  257.                 if input~=cT[5] then
  258.                     if input~="" then
  259.                         fs.move("os/users/"..User, "os/users/"..input)
  260.                         A.LoadConf(input)
  261.                         getUser()
  262.                     end
  263.                 end
  264.                 dm()
  265.                 cm=0
  266.             end
  267.             t = os.startTimer(.1)
  268.         elseif cm==3 then
  269.             if arg[1]=="mouse_click" and arg[2]==1 then
  270.                 for v,k in ipairs(ctable) do
  271.                     if arg[3]==k[1] and arg[4]==k[2] then
  272.                         if cT[5]=="CBC" then
  273.                             if k[3]~=conf["CTC"] then
  274.                                 conf[cT[5]]=k[3]
  275.                                 setT(src,conf)
  276.                             end
  277.                         elseif cT[5]=="CTC" then
  278.                             if k[3]~=conf["CBC"] then
  279.                                 conf[cT[5]]=k[3]
  280.                                 setT(src,conf)
  281.                             end
  282.                         else
  283.                             conf[cT[5]]=k[3]
  284.                             setT(src,conf)
  285.                         end
  286.                     end
  287.                 end
  288.                 dm()
  289.                 cm=0
  290.             end
  291.             t = os.startTimer(.1)
  292.             A.reloadMeuns()
  293.         elseif cm==4 then
  294.             if arg[1]=="mouse_click" then
  295.                 if arg[2]==1 then
  296.                     for v,k in ipairs(tbl2) do
  297.                         if arg[3]>=k[1] and arg[3]<=k[2] then
  298.                             if arg[4]==k[3] then
  299.                                 conf[cT[5]]="os/images/"..k[4]
  300.                                 setT(src,conf)
  301.                             end
  302.                         end
  303.                     end
  304.                     dm()
  305.                     cm=0
  306.                     setT(src,conf)
  307.                 elseif arg[2]==2 then
  308.                     for v,k in ipairs(tbl2) do
  309.                         if arg[3]>=k[1] and arg[3]<=k[2] then
  310.                             if arg[4]==k[3] then
  311.                                 tbl3 = {k[4]}
  312.                                 A.dmeun4(k[1]+1,k[3]+1)
  313.                                 cm=6
  314.                                 xy = {k[1]+1,k[3]+1}
  315.                             end
  316.                         end
  317.                     end
  318.                 else
  319.                     dm()
  320.                     cm=0
  321.                 end
  322.             end
  323.         elseif cm==5 then
  324.             if arg[1]=="mouse_click" then
  325.                 if arg[2]==1 then
  326.                     if arg[3]>=xy[1]+1 and arg[3]<=xy[1]+11 then
  327.                         if arg[4]==xy[2]+1 then
  328.                             dm()
  329.                             local input = A.userin(2,3,3)
  330.                             shell.run("paint",input) ---new icon
  331.                             dm()
  332.                             t = os.startTimer(.1)
  333.                             cm=0
  334.                         else
  335.                             dm()
  336.                             cm=0
  337.                         end
  338.                     else
  339.                         dm()
  340.                         cm=0
  341.                     end
  342.                 else
  343.                     dm()
  344.                     cm=0
  345.                 end
  346.             end
  347.         elseif cm==6 then
  348.             if arg[1]=="mouse_click" then
  349.                 if arg[2]==1 then
  350.                     if arg[3]>=xy[1]+1 and arg[3]<=xy[1]+8 then
  351.                         if arg[4]==xy[2]+1 then
  352.                             shell.run("paint","os/images/"..tbl3[1])
  353.                             t = os.startTimer(.1)
  354.                             dm()
  355.                             dImageOps()
  356.                             cm=4
  357.                         elseif arg[4]==xy[2]+2 then
  358.                                 shell.run("delete","os/images/"..tbl3[1])
  359.                                 if conf["BCI"] == "os/images/"..tbl3[1] then
  360.                                     conf["BCI"] = "os/images/default"
  361.                                 elseif conf["CBI"] == "os/images/"..tbl3[1] then
  362.                                     conf["CBI"] = "os/images/default"
  363.                                 end
  364.                                 setT(src,conf)
  365.                             t = os.startTimer(.1)
  366.                             dm()
  367.                             dImageOps()
  368.                             cm=4
  369.                         else
  370.                             dm()
  371.                             dImageOps()
  372.                             t = os.startTimer(.1)
  373.                             cm=4
  374.                         end
  375.                     else
  376.                         dm()
  377.                         dImageOps()
  378.                         t = os.startTimer(.1)
  379.                         cm=4
  380.                     end
  381.                 else
  382.                     dm()
  383.                     dImageOps()
  384.                     t = os.startTimer(.1)
  385.                     cm=4
  386.                 end
  387.             end
  388.         end
  389.     end
  390. end
  391. local ok, err = pcall(main)
  392. if not ok then
  393.     A.Error(err)
  394.     sleep(5)
  395. end
Add Comment
Please, Sign In to add comment