Hikooshi

Press

Feb 4th, 2022 (edited)
344
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 37.67 KB | None | 0 0
  1. --pastebin get FL9yB7Zm press
  2. local component = require("component")
  3. local gpu = component.gpu
  4. local transposer = component.transposer
  5. local event = require("event")
  6. local unicode = require("unicode")
  7. local term = require("term")
  8. local serialization = require("serialization")
  9. local keyboard = require("keyboard")
  10. local thread = require("thread")
  11.  
  12.  
  13.  
  14. local queue = {}
  15. --local pSides = {gear=2, wire=3, plate=4, rod=5}
  16. local areas = {}
  17. local molds = {plate="Пластина", rod="Стержень x2", wire="Провод x2", gear="Шестеренка", empty=""}
  18. local uChar = unicode.char(9600)
  19. local dChar = unicode.char(9604)
  20. local fChar = unicode.char(9608)
  21. local selectedSideForMold
  22. local lSide
  23. local wSide
  24. local wMold
  25. local wSize
  26. local wDiv
  27. local mat
  28. local maxNmb
  29. local curNmb
  30. local workBtn
  31. local queueWork = false
  32. local qStop = false
  33. local delay = 1 ----------------
  34. "█▄ ","██▀","▀  ",mono=true},
  35. step = {"█▄ █","██▀█","▀  ▀",mono=true},
  36. pause = {"██ ██","██ ██","▀▀ ▀▀",mono=true},
  37. stop = {"█████","█████","▀▀▀▀▀",mono=true}}
  38. --[[for i = 1, #txts.gear do
  39.   for l = 1, #txts.gear[i] do
  40.     if txts.gear[i][l] > 0 then
  41.     txts.gear[i][l] = 0xFFFFFF
  42.     end
  43.   end
  44. end]]
  45. local buttons = {north={x=46,y=2,width=16,height=8,text={{"N",1,1}},side=2,active=true,cFore=0xFFFF00,cBack=0x444444},
  46.                  south={x=46,y=18,width=16,height=8,text={{"S",1,1}},side=3,active=true,cFore=0xFFFF00,cBack=0x444444},
  47.                  west={x=30,y=10,width=16,height=8,text={{"W",1,1}},side=4,active=true,cFore=0xFFFF00,cBack=0x444444},
  48.                  east={x=62,y=10,width=16,height=8,text={{"E",1,1}},side=5,active=true,cFore=0xFFFF00,cBack=0x444444},
  49.                  start={x=48,y=11,width=3,height=3,text={},active=true,txt=txts.start,enabled=false,cFore=0x00FF00,cEnFore=0xFF00FF,cBack=0x000000},
  50.                  pause={x=48,y=15,width=5,height=3,text={},active=true,txt=txts.pause,enabled=false,cFore=0x00FF00,cEnFore=0xFF00FF,cBack=0x000000},
  51.                  stop={x=55,y=15,width=5,height=3,text={},active=true,txt=txts.stop,enabled=false,cFore=0x00FF00,cEnFore=0xFF00FF,cBack=0x000000},
  52.                  step={x=55,y=11,width=4,height=3,text={},active=true,txt=txts.step,enabled=false,cFore=0x00FF00,cEnFore=0xFA00FA,cBack=0x000000},
  53.                  materials={x=9,y=3,width=11,height=3,text={{"Материалы",1,1}},thin=true,active=true,cFore=0xFFFF00,cBack=0x444444},
  54.                  add={x=28,y=2,width=4,height=1,text={{"-->",0,0}},active=false,cFore=0xFFFF00,cBack=0x444444},
  55.                  cancel={x=32,y=23,width=8,height=1,text={{"Отмена",1,0}},active=false,cFore=0xFFFF00,cBack=0x444444},
  56.                  plt={x=38,y=2,width=5,height=1,text={{"Нет",1,0}},plt=false,active=false,cFore=0xFFFF00,cBack=0x444444},
  57.                  hplt={x=38,y=3,width=5,height=1,text={{"Нет",1,0}},hplt=false,active=false,cFore=0xFFFF00,cBack=0x444444},
  58.                  p={x=23,y=2,width=3,height=1,text={{"+",1,0}},active=true,mltp=1,cFore=0xFFFF00,cBack=0x444444},
  59.                  m={x=17,y=2,width=3,height=1,text={{"-",1,0}},active=true,mltp=-1,cFore=0xFFFF00,cBack=0x444444},
  60.                  fwd={x=29,y=23,width=2,height=1,text={{"->",0,0}},active=true,mltp=1,cFore=0xFFFF00,cBack=0x444444},
  61.                  bkd={x=14,y=23,width=2,height=1,text={{"<-",0,0}},active=true,mltp=-1,cFore=0xFFFF00,cBack=0x444444},
  62.                  exit={x=78,y=1,width=3,height=1,text={{"X",1,0}},active=true,cFore=0x444444,cBack=0xFF0000},
  63.                  moldP={x=1,y=2,ydef=2,width=12,height=1,text={{"Пластина",1,0}},mold="plate",div=1,active=false,cFore=0xFFFF00,cBack=0x000000},
  64.                  moldR={x=1,y=1,ydef=1,width=12,height=1,text={{"Стержень",1,0}},mold="rod",div=0.5,active=false,cFore=0xFFFF00,cBack=0x000000},
  65.                  moldW={x=1,y=3,ydef=3,width=12,height=1,text={{"Провод",1,0}},mold="wire",div=0.5,active=false,cFore=0xFFFF00,cBack=0x000000},
  66.                  moldG={x=1,y=4,ydef=4,width=12,height=1,text={{"Шестеренка",1,0}},mold="gear",div=4,active=false,cFore=0xFFFF00,cBack=0x000000},
  67.                  moldE={x=1,y=5,ydef=5,width=12,height=1,text={{"Пусто",1,0}},mold="empty",active=false,cFore=0xFFFF00,cBack=0x000000}}
  68. local lists = {queue = {x=17, y=23, width=11, height=1, length=0, content={}, lType="btn", limit=160, top=true, posF = 1, sb={0x0000FA, false, length=0, shift=0, q=0, work=false}, hor=true, spacer=2, cFore = 0xFAFA00, cbBack=0x00FA00, cEnBack=0x0000FA, cBack = 0x000000},
  69.                materials = {x=4, y=6, width=20, height=11, length=0, content={}, lType="btn", limit=40, top=true, posF = 1, sb={0x0000FA, true,length=0,shift=0,q=0,work=false}, spacer=1, cFore=0xFAFA00, cbBack=0x444444, cEnBack=0x0000FA, cBack = 0x222222}}
  70. local labels = {queue={x=3,y=23,text="Очередь",cFore=0xFFFF00},
  71.                 detail={x=5,y=18,text="Деталь",cFore=0xFFFF00},
  72.                 material={x=3,y=20,text="Материал",cFore=0xFFFF00},
  73.                 count={x=3,y=2,text="Количество",cFore=0xFFFF00},
  74.                 plt={x=27,y=2,text="Обшивка",cFore=0xFFFF00},
  75.                 hplt={x=27,y=3,text="Тяжелая",cFore=0xFFFF00},
  76.                 nmb={x=20,y=2,width=3,text="  0",o=0,cFore=0xFFFF00},
  77.                 d={x=14,y=18,text="",cFore=0xFFFF00},
  78.                 m={x=14,y=20,text="",cFore=0xFFFF00}}
  79. local startLabels = {labels.queue, labels.detail, labels.material, labels.count, labels.nmb}
  80.  
  81. for i = 0, 1 do
  82.   if transposer.getInventoryName(i) and transposer.getInventorySize(i) > 1 then mainInv = i slots = transposer.getInventorySize(i) break end
  83. end
  84.  
  85. function add(list, data, obj)
  86.  
  87. local wList = lists[list]
  88. local cPos, shift, spsr = 1, wList.width, wList.spacer
  89. local totalLines = #wList.content
  90. local count
  91. --if data then
  92. --[[if totalLines + count > wList.limit then
  93.   for i = 1, count do
  94.   table.remove(wList.content, 1)
  95.   end
  96. end]]
  97. local x, y, w, h, l = wList.x, wList.y, wList.width, wList.height, wList.length
  98. if data then
  99. local lData
  100. local lsData
  101.         if totalLines > 0 and spsr then
  102.         l = l + spsr
  103.         end
  104.   if type(data) == "table" then
  105.     lData = data[1]
  106.     lsData = data[2]
  107.   elseif type(data) == "string" then
  108.     lData = data
  109.   end
  110. l=l+1
  111.         local mStr = lData:match("(.+)"..fChar) or lData
  112.         local aStr = lData:match(fChar.."(.+)")
  113.         local words = {}
  114.         local tempContent = {}
  115.         tempContent.s = l
  116.           for word in mStr:gmatch("%S+") do table.insert(words, word) end
  117.             if not wList.hor then
  118.             local tStr = words[1]
  119.               for i = 2, #words do
  120.                 if unicode.wlen(tStr.." "..words[i]) <= w then
  121.                     tStr = tStr .. " " .. words[i]
  122.                 else
  123.                     tempContent[l]=tStr
  124.                     l = l + 1
  125.                     tStr = ""
  126.                 end
  127.               end
  128.                   if tStr ~= "" then
  129.                     tempContent[l] = tStr
  130.                     l = l + 1
  131.                   end
  132.             else
  133.               local wl = unicode.wlen(mStr)
  134.                 for i = 1, wl-1 do
  135.                     tempContent[l]=unicode.sub(mStr, i, i)
  136.                     l = l + 1
  137.                 end
  138.               tempContent[l]=unicode.sub(mStr, wl, wl)
  139.             end
  140.                   if aStr then
  141.                     if not wList.hor then
  142.                         tempContent[l]=aStr
  143.                     --l = l + 1
  144.                     else
  145.                       local awl = unicode.wlen(aStr)
  146.                         for i = 1, awl-1 do
  147.                             tempContent[l]=unicode.sub(aStr, i, i)
  148.                             l = l + 1
  149.                         end
  150.                       tempContent[l]=unicode.sub(aStr, awl, awl)
  151.                     end
  152.                   end
  153.                     tempContent.enabled = false
  154.                     tempContent.f = l
  155.                 if lsData then
  156.                   for k,v in pairs(lsData) do
  157.                     tempContent[k] = v
  158.                   end
  159.                 end
  160.               table.insert(wList.content, tempContent)
  161. --totalLines = #wList.content
  162. --        if totalLines > l and wList.top == false then
  163. --        wList.posF = totalLines - l + 1
  164. --        end
  165. wList.length = l
  166. end
  167. if wList.sb then
  168. local length = 0
  169. local q = 0
  170. local hw = wList.hor and w or h
  171.   if l > hw then
  172.     length = math.floor(hw/l*hw)
  173.     length = length > 0 and length or 1
  174.     q = (hw - 1 - length)/(l - 1 - hw)
  175.     q = q > 0 and q or 1
  176.     wList.sb.q = q
  177. --  wList.sb.thumbPosition = math.ceil(math.abs(q*wlist.posF-realLength))
  178.     wList.sb.work = true
  179.   else
  180.     length = wList.hor and w or h
  181.     q = 0
  182.   end
  183.     wList.sb.q = q
  184.     local s = wList.hor and dChar or " "
  185.     wList.sb.thumb = string.rep(s, length)
  186. end
  187.  
  188. end
  189.  
  190. function drawList(list)
  191.  
  192. gpu.setForeground(list.cFore)
  193. gpu.setBackground(list.cBack)
  194. local cCount = #list.content
  195. local l = list.length
  196. local x, y, w, h = list.x, list.y, list.width, list.height
  197. local len, xsb, ysb, sbw, sbh
  198. local posF = list.posF
  199.   if not list.hor then
  200.     len = h
  201.     xsb = x+w
  202.     ysb = y
  203.     sbw = 1
  204.     sbh = h
  205.   else
  206.     len = 1
  207.     xsb = x
  208.     ysb = y+1
  209.     sbw = w
  210.     sbh = 1
  211.   end
  212.     gpu.fill(x, y, w, h, " ")
  213.     local shiftF = -1
  214.     local hw = list.hor and w or h
  215.     local fLine = l > hw and hw or l
  216.       if not list.top and l < h then
  217.         shiftF = h - l - 1
  218.       end
  219.         if cCount > 0 then
  220.         local drawContent = {}
  221.           for i = 1, cCount do
  222.             --for k,v in pairs(list.content[i]) do
  223.               if posF + fLine > list.content[i].s and posF <= list.content[i].f then
  224.                 table.insert(drawContent, list.content[i])
  225.               end
  226.             --end
  227.           end
  228.             for i = 1, #drawContent do
  229.               local color = drawContent[i].enabled and list.cEnBack or list.cbBack
  230.               gpu.setBackground(color)
  231.                 for i1 = posF, posF+fLine-1 do
  232.                   if drawContent[i][i1] then
  233.                     if not list.hor then
  234.                         gpu.fill(x, y+i1-posF, w, 1, " ")
  235.                         gpu.set(x, y+i1-posF, drawContent[i][i1])
  236.                     else
  237.                         gpu.set(x+i1-posF, y, drawContent[i][i1])
  238.                     end
  239.                   end
  240.                 end
  241.             end
  242.         end
  243.           if list.sb then
  244.             local n = list.hor and w or h
  245.             local s = list.hor and dChar or " "
  246.             if #list.content == 0 then list.sb.thumb = string.rep(s, n) list.sb.q = 0 end
  247.             gpu.setForeground(0x000000)
  248.             gpu.setBackground(0x000044)
  249.             gpu.fill(xsb, ysb, sbw, sbh, s)
  250.             gpu.setBackground(list.sb[1])
  251.             local thumbPosition = math.ceil(list.sb.q*(list.posF-1))
  252.             local xsb1, ysb1
  253.                 if not list.hor then
  254.                     xsb1 = xsb
  255.                     ysb1 = ysb + thumbPosition
  256.                 else
  257.                     xsb1 = xsb + thumbPosition
  258.                     ysb1 = ysb
  259.                 end
  260.             gpu.set(xsb1, ysb1, list.sb.thumb, list.sb[2])
  261.           end
  262. gpu.setForeground(0xFFFFFF)
  263. gpu.setBackground(0x000000)
  264.  
  265. end
  266.  
  267. function reCurNmb(add)
  268.     curNmb = 0
  269.     labels.nmb.text = "  0"
  270.     drawLabel(labels.nmb)
  271.     if add then
  272.         sltSide(_, true)
  273.         drawList(lists.materials)
  274.         buttons.add.active=false
  275.         gpu.setBackground(0x000000)
  276.         gpu.set(28, 2, "    ")
  277.     end
  278. end
  279.  
  280. function drawButton(btn)
  281.     local x,y = btn.x, btn.y
  282.     local w,h = btn.width, btn.height
  283.         if btn.txt then
  284.             local txt = btn.txt
  285.                 if not txt.mono then
  286.                     for i = 1, h do
  287.                         for l = 1, w*2, 2 do
  288.                             gpu.setForeground(btn.txt[i][l])
  289.                             gpu.setBackground(btn.txt[i][l+1])
  290.                             gpu.set(x+math.floor(l/2), y+i-1, uChar)
  291.                         end
  292.                     end
  293.                 else
  294.                     local color = btn.enabled and btn.cEnFore or btn.cFore
  295.                     gpu.setForeground(color)
  296.                     gpu.setBackground(btn.cBack)
  297.                     for i = 1, #txt do
  298.                         gpu.set(btn.x, btn.y+i-1, txt[i])
  299.                     end
  300.                 end
  301.         else
  302.             --gpu.setForeground(btn.cFore)
  303.             gpu.setBackground(btn.cBack)
  304.             if btn.thin then
  305.                 gpu.setForeground(0x000000)
  306.                 gpu.fill(x,y,w,1,uChar)
  307.                 gpu.fill(x,y+1,w,h-2," ")
  308.                 gpu.fill(x,y+h-1,w,1,dChar)
  309.             else
  310.                 gpu.fill(x, y, w, h, " ")
  311.             end  
  312.         end
  313.     gpu.setForeground(btn.cFore)
  314.     local text = btn.text
  315.     if #text > 0 then
  316.         for i = 1, #text do
  317.             gpu.set(x+text[i][2], y+text[i][3], text[i][1])
  318.         end
  319.     end
  320. end
  321.  
  322. function drawLabel(lbl)
  323.     local width = lbl.width or unicode.wlen(lbl.text)+2
  324.     local o = lbl.o or 1
  325.     gpu.setBackground(0x444444)
  326.     gpu.setForeground(lbl.cFore)
  327.     gpu.fill(lbl.x, lbl.y, width, 1, " ")
  328.     gpu.set(lbl.x+o, lbl.y, lbl.text)
  329. end
  330.                                         -------------------------------------------------------
  331. term.clear()
  332. gpu.setResolution(80, 25)
  333. workBtn = buttons.stop
  334. buttons.stop.enabled = true
  335. local settings = io.open("settings", "r")
  336. if settings then
  337. local lines = {}
  338.   for line in settings:lines() do table.insert(lines, line) end
  339.     for k,v in pairs(lines) do
  340.       if v:match("columns") then columns = tonumber(v:match("%d+")) break end
  341.     end
  342. settings:close()
  343. end
  344.  
  345. drawList(lists.queue)
  346. drawList(lists.materials)
  347.  
  348. function getMaterials()
  349.     if #lists.queue.content == 0 then
  350.         local materials = {}
  351.         local stacks = transposer.getAllStacks(mainInv)
  352.         for i = 1, slots do transposer.transferItem(mainInv, mainInv, _, i) end
  353.         for i = 1, slots do
  354.             if stacks[i].name ~= "minecraft:air" then
  355.                 local name = stacks[i].label
  356.                 local size = stacks[i].size
  357.                 if materials[name] then
  358.                     materials[name] = materials[name] + size
  359.                 else
  360.                     materials[name] = size
  361.                 end
  362.             end
  363.         end
  364.         lists.materials.content={}
  365.         lists.materials.length=0
  366.         lists.materials.posF=1
  367.         for k,v in pairs(materials) do
  368.             add("materials", {k..fChar..tostring(v), {mat=k, size=v}})
  369.         end
  370.         drawList(lists.materials)
  371.     end
  372. end
  373.  
  374. buttons.materials.func = getMaterials
  375.  
  376. buttons.exit.func = function()
  377.     gpu.setResolution(160, 50)
  378.     gpu.setForeground(0xFFFFFF)
  379.     gpu.setBackground(0x000000)
  380.     term.clear()
  381.     os.exit()
  382. end
  383.  
  384. function plusMinus(btn, shift, control)
  385.     if wMold and mat then
  386.         curNmb = curNmb + btn.mltp*(shift and 2 or 1)*(control and 4 or 1)
  387.         if curNmb < 0 then
  388.             curNmb = 0
  389.         elseif curNmb > maxNmb then
  390.             curNmb = maxNmb
  391.         end
  392.         if curNmb > 0 then
  393.             if not buttons.add.active then
  394.                 buttons.add.active=true
  395.                 drawButton(buttons.add)
  396.             end
  397.         else
  398.             if buttons.add.active then
  399.                 buttons.add.active = false
  400.                 gpu.setBackground(0x000000)
  401.                 gpu.set(28, 2, "     ")
  402.             end
  403.         end
  404.         local tNmb = tostring(curNmb)
  405.         local length = string.len(tNmb)
  406.         labels.nmb.text = string.rep(" ", 3-length)..tNmb
  407.         drawLabel(labels.nmb)
  408.     end
  409. end
  410.  
  411. buttons.p.func = plusMinus
  412. buttons.m.func = plusMinus
  413.  
  414. lists.materials.func = function(l)
  415.     for i = 1, #l.content do
  416.         if l.content[i].enabled then
  417.             mat = l.content[i].mat
  418.             wSize = l.content[i].size
  419.             break
  420.         end
  421.     end
  422.     if wDiv then
  423.         maxNmb = math.floor(wSize/wDiv)
  424.     end
  425.     reCurNmb()
  426. end
  427.  
  428. for k,v in pairs(buttons) do
  429.   if v.active then
  430.   drawButton(v)
  431.   end
  432. end
  433.  
  434. for i = 1, #startLabels do
  435. drawLabel(startLabels[i])
  436. end
  437.  
  438. function setSideForMold(btn)
  439.     if btn.side then
  440.         if not selectedSideForMold then
  441.             btn.active=false
  442.             selectedSideForMold = btn
  443.         else
  444.             selectedSideForMold.active=true
  445.             drawButton(selectedSideForMold)
  446.             btn.active=false
  447.             selectedSideForMold = btn
  448.             for k,v in pairs(buttons) do
  449.                 if v.ydef then
  450.                     v.x=1
  451.                     v.y=v.ydef
  452.                     v.active=false
  453.                 end
  454.             end
  455.         end
  456.         for k,v in pairs(buttons) do
  457.             if v.ydef then
  458.                 v.active=true
  459.                 v.x=selectedSideForMold.x+2
  460.                 v.y=v.y+selectedSideForMold.y+1
  461.                 drawButton(v)
  462.             end
  463.         end
  464.     end
  465. end
  466.  
  467. buttons.north.rFunc = setSideForMold
  468. buttons.south.rFunc = setSideForMold
  469. buttons.west.rFunc = setSideForMold
  470. buttons.east.rFunc = setSideForMold
  471.  
  472. function sltSide(btn, cancel)
  473.     if cancel and lSide or lSide and lSide ~= btn and btn.mold then
  474.         local lx, ly, lw, lh, lmold = lSide.x, lSide.y, lSide.width, lSide.height, lSide.mold
  475.         for i = 1, 16 do
  476.             gpu.setForeground(txts[lmold][1][i*2-1])
  477.             gpu.setBackground(txts[lmold][1][i*2])
  478.             gpu.set(lx+i-1, ly, uChar)
  479.             gpu.setForeground(txts[lmold][8][i*2-1])
  480.             gpu.setBackground(txts[lmold][8][i*2])
  481.             gpu.set(lx+i-1, ly+lh-1, uChar)
  482.         end
  483.         for i = 1, 8 do
  484.             gpu.setForeground(txts[lmold][i][1])
  485.             gpu.setBackground(txts[lmold][i][2])
  486.             gpu.set(lx, ly+i-1, uChar)
  487.             gpu.setForeground(txts[lmold][i][31])
  488.             gpu.setBackground(txts[lmold][i][32])
  489.             gpu.set(lx+lw-1, ly+i-1, uChar)
  490.         end
  491.         wMold = false
  492.     end
  493.     if btn and btn.mold then
  494.         lSide = btn
  495.         wSide = btn.side
  496.         wMold = btn.mold
  497.         gpu.setForeground(0x00FF00)
  498.         local x, y = btn.x, btn.y
  499.         local w, h = btn.width, btn.height
  500.         for i = 1, 16 do
  501.             gpu.setBackground(txts[wMold][1][i*2])
  502.             gpu.set(x+i-1, y, uChar)
  503.             gpu.setBackground(txts[wMold][8][i*2-1])
  504.             gpu.set(x+i-1, y+h-1, dChar)
  505.         end
  506.         gpu.fill(x, y, 1, 8, fChar)
  507.         gpu.fill(x+w-1, y, 1, 8, fChar)
  508.         wDiv = btn.div
  509.         if wSize then
  510.             maxNmb = math.floor(wSize/wDiv)
  511.         end
  512.         reCurNmb()
  513.     end
  514. end
  515.  
  516. buttons.north.func = sltSide
  517. buttons.south.func = sltSide
  518. buttons.west.func = sltSide
  519. buttons.east.func = sltSide
  520.  
  521. function selectMold(btn)
  522.     if btn.mold ~= "empty" then
  523.         selectedSideForMold.mold = btn.mold
  524.         selectedSideForMold.txt = txts[btn.mold]
  525.         selectedSideForMold.div = btn.div
  526.         selectedSideForMold.text[1][1] = ""
  527.     end
  528.     for k,v in pairs(buttons) do
  529.         if v.ydef then
  530.             v.x=1
  531.             v.y=v.ydef
  532.             v.active=false
  533.         end
  534.     end
  535.     --selectedSideForMold.active = true
  536.     drawButton(selectedSideForMold)
  537.     selectedSideForMold.active=true
  538.     selectedSideForMold = nil
  539. end
  540.  
  541. for k,v in pairs(buttons) do
  542.   if v.ydef then
  543.   v.func = selectMold
  544.   end
  545. end
  546.  
  547. buttons.add.func = function()
  548.     local cn = curNmb
  549.     if wDiv < 1 then cn = math.ceil(curNmb * wDiv) end
  550.         for i = 1, cn do
  551.             add("queue", {"  ", {mat=mat, count=math.ceil(wDiv), side=wSide, mold=wMold}})
  552.         end
  553.         local lc = lists.materials.content
  554.         for i = 1, #lc do
  555.             if lc[i].enabled then
  556.                 lc[i].size = lc[i].size - math.ceil(curNmb*wDiv)
  557.                 lc[i][lc[i].f] = tostring(lc[i].size)
  558.                 lc[i].enabled = false
  559.                 mat = false
  560.                 break
  561.             end
  562.         end
  563.     reCurNmb(true)
  564.     drawList(lists.queue)
  565. end
  566.  
  567. lists.queue.func = function(l)
  568.     reQueueInfo()
  569.     local chunk
  570.     for i = 1, #l.content do
  571.         if l.content[i].enabled then
  572.             chunk = l.content[i]
  573.             break
  574.         end
  575.     end
  576.     if chunk then
  577.         labels.d.text = molds[chunk.mold]
  578.         labels.m.text = chunk.mat
  579.         drawLabel(labels.d)
  580.         drawLabel(labels.m)
  581.         buttons.cancel.active = true
  582.         drawButton(buttons.cancel)
  583.     end
  584. end
  585.  
  586. function start()
  587.     local c = lists.queue.content
  588.     local st = 1
  589.     local mats = transposer.getAllStacks(mainInv).getAll()
  590.     local lastSide
  591.     local nwk = {}
  592.     workBtn.enabled = false
  593.     drawButton(workBtn)
  594.     buttons.start.enabled = true
  595.     workBtn = buttons.start
  596.     drawButton(workBtn)
  597.     queueWork = true
  598.     local slotNmb
  599.     while st <= #c and queueWork do
  600. --  local slot = transposer.getStackInSlot(c[st].side, 1)
  601.         for i1 = #mats, 1, -1 do
  602.             if mats[i1].label == c[st].mat and mats[i1].size >= c[st].count then
  603.                 slotNmb = i1
  604.             break
  605.         end
  606.     end
  607.         if transposer.getSlotStackSize(c[st].side, 1) == 0 then
  608.           --if c[st].side == lastSide then
  609.           os.sleep(delay)
  610.           --else
  611.           --lastSide = c[st].side
  612.           --end
  613.           local stck = transposer.transferItem(mainInv, c[st].side, c[st].count, slotNmb)
  614.             if stck == 0 then
  615.             table.insert(nwk, c[st])
  616.             end
  617.           --if c[st].count == 0 then
  618.           --table.remove(c, 1)
  619.           st = st + 1
  620.           --end
  621.         end
  622.   end
  623.     for i = 1, st-1 do table.remove(c, 1) end
  624.       if #c == 0 then qStop = true end
  625.       if qStop then
  626.       queueStop(nwk) qStop = false
  627.       else
  628.         local lst = lists.queue
  629.         if #c > 0 then
  630.         lst.length = #c*2 + (#c-1)*2
  631.         local diff = c[#c].f - lst.length
  632.           for i = 1, #c do
  633.           local data = {}
  634.             for i1 = c[i].s, c[i].f do
  635.             table.insert(data, c[i][i1])
  636.             c[i][i1] = nil
  637.             end
  638.               c[i].s = c[i].s - diff
  639.               c[i].f = c[i].f - diff
  640.                 for i2 = 1, #data do
  641.                 c[i][c[i].s-1+i2] = data[i2]
  642.                 end
  643.           end
  644.         else
  645.         c = {}
  646.         lst.length = 0
  647.         end
  648.         lst.posF = 1
  649.         add("queue")
  650.         drawList(lists.queue)
  651.       end
  652. reQueueInfo(true)
  653. end
  654.  
  655. buttons.start.func = function(btn)
  656.  
  657. thread.create(start)
  658. end
  659.  
  660. function queueStop(nwk)
  661.     local c = lists.queue.content
  662.     local m = lists.materials.content
  663.     if #c > 0 then
  664.         for i = 1, #c do
  665.             for i1 = 1, #m do
  666.                 if m[i1].mat == c[i].mat then
  667.                     m[i1].size = m[i1].size + c[i].count
  668.                     break
  669.                 end
  670.             end
  671.         end
  672.     end
  673.         if #nwk > 0 then
  674.             for i = 1, #nwk do
  675.                 for i1 = 1, #m do
  676.                     if m[i1].mat == nwk[i].mat then
  677.                         m[i1].size = m[i1].size + nwk[i].count
  678.                         break
  679.                     end
  680.                 end
  681.             end
  682.         end
  683.           for i = 1, #m do
  684.             m[i][m[i].f] = tostring(m[i].size)
  685.           end
  686.     drawList(lists.materials)
  687.     lists.queue.length = 0
  688.     lists.queue.content = {}
  689.     lists.queue.posF = 1
  690.     drawList(lists.queue)
  691.     workBtn.enabled = false
  692.     drawButton(workBtn)
  693.     workBtn = buttons.stop
  694.     workBtn.enabled = true
  695.     drawButton(workBtn)
  696. end
  697.  
  698. buttons.stop.func = function()
  699.     if queueWork then
  700.         queueWork = false
  701.         qStop = true
  702.     else
  703.         queueStop()
  704.     end
  705. --[[local c = lists.queue.content
  706.     if #c > 0 then
  707.         for i = 1, #c do
  708.             for i1 = 1, #lists.materials.content do
  709.                 if lists.materials.content[i1].mat == c[i].mat then
  710.                     lists.materials.content[i1].size = lists.materials.content[i1].size + c[i].count
  711.                     break
  712.                 end
  713.             end
  714.     end
  715.       for i = 1, #lists.materials.content do
  716.         lists.materials.content[i][lists.materials.content[i].f] = tostring(lists.materials.content[i].size)
  717.       end
  718.     end
  719.     drawList(lists.materials)
  720.     lists.queue.length = 0
  721.     lists.queue.content = {}
  722.     lists.queue.posF = 1
  723.     drawList(lists.queue)]]
  724.     workBtn.enabled = false
  725.     drawButton(workBtn)
  726.     buttons.stop.enabled = true
  727.     workBtn = buttons.stop
  728.     drawButton(workBtn)
  729.     reQueueInfo(true)
  730. end
  731.  
  732. buttons.pause.func = function()
  733.     if queueWork then
  734.         queueWork = false
  735.         workBtn.enabled = false
  736.         drawButton(workBtn)
  737.         workBtn = buttons.pause
  738.         workBtn.enabled = true
  739.         drawButton(workBtn)
  740.     end
  741. end
  742.  
  743. buttons.step.func = function(btn)
  744.   if queueWork == false then
  745.       if btn ~= workBtn then
  746.       workBtn.enabled = false
  747.       drawButton(workBtn)
  748.       workBtn = buttons.step
  749.       workBtn.enabled = true
  750.       drawButton(workBtn)
  751.       end
  752.   local c = lists.queue.content
  753.   local slots = transposer.getAllStacks(mainInv).getAll()
  754.   local s
  755.   local cnt
  756.   local mat
  757.   local nmb
  758.   local last = false
  759.   local pos = lists.queue.posF
  760.     for i = 1, #c do
  761.       if c[i].enabled then
  762.       s = c[i].side
  763.       cnt = c[i].count
  764.       mat = c[i].mat
  765.       nmb = i
  766.         if i == #c then last = true end
  767.       break
  768.       end
  769.     end
  770.           if s then
  771.                   for i = #slots, 1, -1 do
  772.                     if slots[i].label == mat and slots[i].size >= cnt then
  773.                       cnt = cnt - transposer.transferItem(mainInv, s, cnt, i)
  774.                       table.remove(c, nmb)
  775.                       break
  776.                     end
  777.                   end
  778. --          lists.queue.length = lists.queue.length - 4
  779. --                if not last then
  780. --                  for i = nmb, #c do
  781. --                  local data = {}
  782. --                    for i1 = c[i].s, c[i].f do
  783. --                    table.insert(data, c[i][i1])
  784. --                    c[i][i1] = nil
  785. --                    end
  786. --                      c[i].s = c[i].s - 4
  787. --                      c[i].f = c[i].f - 4
  788. --                        for i2 = 1, #data do
  789. --                        c[i][i2+c[i].s-1] = data[i2]
  790. --                        end
  791. --                  end
  792. --                end
  793. --                pos = pos - 4
  794. --                  if pos < 1 then pos = 1 end
  795. --                lists.queue.posF = pos
  796. --                add("queue")
  797. --                drawList(lists.queue)
  798.                   updList(nmb, c, pos, last, cnt, mat)
  799.           end
  800.   reQueueInfo(true)
  801.   end
  802. end
  803.  
  804. function updList(nmb, c, pos, last, cnt, mat)
  805.     lists.queue.length = lists.queue.length - 4
  806.     local m = lists.materials.content
  807.     local nm
  808.     for i = 1, #m do
  809.         if m[i].mat == mat then
  810.             m[i].size = m[i].size + cnt
  811.             nm = i
  812.             break
  813.         end
  814.     end
  815.     m[nm][m[nm].f] = tostring(m[nm].size)
  816.     if not last then
  817.         for i = nmb, #c do
  818.             local data = {}
  819.             for i1 = c[i].s, c[i].f do
  820.                 table.insert(data, c[i][i1])
  821.                 c[i][i1] = nil
  822.             end
  823.         c[i].s = c[i].s - 4
  824.         c[i].f = c[i].f - 4
  825.             for i2 = 1, #data do
  826.                 c[i][i2+c[i].s-1] = data[i2]
  827.             end
  828.         end
  829.     end
  830.     pos = pos - 4
  831.     if pos < 1 then pos = 1 end
  832.     lists.queue.posF = pos
  833.     add("queue")
  834.     drawList(lists.queue)
  835.     drawList(lists.materials)
  836. end
  837.  
  838. buttons.cancel.func = function()
  839.     local c = lists.queue.content
  840.     local pos = lists.queue.posF
  841.     local nmb
  842.     local last = false
  843.     local cnt
  844.     local mat
  845.     for i = 1, #c do
  846.         if c[i].enabled then
  847.             nmb = i
  848.             cnt = c[i].count
  849.             mat = c[i].mat
  850.         if nmb == #c then last = true end
  851.             break
  852.         end
  853.     end
  854.     table.remove(c, nmb)
  855.     updList(nmb, c, pos, last, cnt, mat)
  856.     reQueueInfo(true)
  857. end
  858.  
  859. function fwdBkd(btn)
  860.     local list = lists.queue
  861.     local pos = list.posF
  862.     if list.length > list.width then
  863.         pos = pos + 4*btn.mltp
  864.         if pos <= 0 then
  865.             pos = 1
  866.         elseif pos+list.width-1 > list.length then
  867.             pos  = list.length - list.width + 1
  868.         end
  869.         list.posF = pos
  870.         drawList(lists.queue)
  871.     end
  872. end
  873.  
  874. buttons.bkd.func = fwdBkd
  875. buttons.fwd.func = fwdBkd
  876.  
  877. function reQueueInfo(cancel)
  878.     gpu.setBackground(0x000000)
  879.     local d = labels.d
  880.     local m = labels.m
  881.     gpu.fill(d.x, d.y, 13, 1, " ")
  882.     gpu.fill(m.x, m.y, 22, 1, " ")
  883.     if cancel then
  884.         buttons.cancel.active = false
  885.         gpu.fill(buttons.cancel.x, buttons.cancel.y, 8, 1, " ")
  886.     end
  887. end
  888.  
  889. function interface()
  890.     while true do
  891.         local event,_,x,y,mb = event.pull()
  892.         if event == "touch" then
  893.             local list
  894.             for k,v in pairs(lists) do
  895.                 if x >= v.x and x < v.x+v.width and y >= v.y and y < v.y+v.height then
  896.                     list = v
  897.                     break
  898.                 end
  899.             end
  900.             if list then
  901.                 local curListPos
  902.                 if not list.hor then
  903.                     curListPos = y-list.y+list.posF
  904.                 else
  905.                     curListPos = x-list.x+list.posF
  906.                 end
  907.                 for k,v in pairs(list.content) do
  908.                     if curListPos >= v.s and curListPos <= v.f then
  909.                         for i = 1, #list.content do list.content[i].enabled = false end
  910.                             v.enabled = true
  911.                             drawList(list)
  912.                             break
  913.                         end
  914.                     end
  915.                     if list.func then list.func(list) end
  916.             else
  917.                 for k,v in pairs(buttons) do
  918.                     if v.active then
  919.                         if x >= v.x and x < v.x+v.width and y >= v.y and y < v.y+v.height then
  920.                             if mb == 0 and v.func then
  921.                                 v.func(v, keyboard.isShiftDown(), keyboard.isControlDown())
  922.                                 break
  923.                             elseif mb == 1 and v.rFunc then
  924.                                 v.rFunc(v)
  925.                                 break
  926.                             end
  927.                         end
  928.                     end
  929.                 end
  930.             end
  931.         elseif event == "scroll" then
  932.             for k,v in pairs(lists) do
  933.                 if x >= v.x and x < v.x+v.width and y >= v.y and y < v.y+v.height then
  934.                     local pos = v.posF
  935.                     pos = pos - mb
  936.                     local hw = v.hor and v.width or v.height
  937.                     if pos >= 1 and pos + hw-1 <= v.length then
  938.                         v.posF = pos
  939.                         drawList(v)
  940.                     end
  941.                 end
  942.             end
  943.         end
  944.     end
  945. end
  946.  
  947. local main = thread.create(interface)
  948.  
  949. thread.waitForAll({main})
  950. os.exit(0)
Comments
Add Comment
Please, Sign In to add comment