Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --pastebin get FL9yB7Zm press
- local component = require("component")
- local gpu = component.gpu
- local transposer = component.transposer
- local event = require("event")
- local unicode = require("unicode")
- local term = require("term")
- local serialization = require("serialization")
- local keyboard = require("keyboard")
- local thread = require("thread")
- local queue = {}
- --local pSides = {gear=2, wire=3, plate=4, rod=5}
- local areas = {}
- local molds = {plate="Пластина", rod="Стержень x2", wire="Провод x2", gear="Шестеренка", empty=""}
- local uChar = unicode.char(9600)
- local dChar = unicode.char(9604)
- local fChar = unicode.char(9608)
- local selectedSideForMold
- local lSide
- local wSide
- local wMold
- local wSize
- local wDiv
- local mat
- local maxNmb
- local curNmb
- local workBtn
- local queueWork = false
- local qStop = false
- local delay = 1 ----------------
- "█▄ ","██▀","▀ ",mono=true},
- step = {"█▄ █","██▀█","▀ ▀",mono=true},
- pause = {"██ ██","██ ██","▀▀ ▀▀",mono=true},
- stop = {"█████","█████","▀▀▀▀▀",mono=true}}
- --[[for i = 1, #txts.gear do
- for l = 1, #txts.gear[i] do
- if txts.gear[i][l] > 0 then
- txts.gear[i][l] = 0xFFFFFF
- end
- end
- end]]
- local buttons = {north={x=46,y=2,width=16,height=8,text={{"N",1,1}},side=2,active=true,cFore=0xFFFF00,cBack=0x444444},
- south={x=46,y=18,width=16,height=8,text={{"S",1,1}},side=3,active=true,cFore=0xFFFF00,cBack=0x444444},
- west={x=30,y=10,width=16,height=8,text={{"W",1,1}},side=4,active=true,cFore=0xFFFF00,cBack=0x444444},
- east={x=62,y=10,width=16,height=8,text={{"E",1,1}},side=5,active=true,cFore=0xFFFF00,cBack=0x444444},
- start={x=48,y=11,width=3,height=3,text={},active=true,txt=txts.start,enabled=false,cFore=0x00FF00,cEnFore=0xFF00FF,cBack=0x000000},
- pause={x=48,y=15,width=5,height=3,text={},active=true,txt=txts.pause,enabled=false,cFore=0x00FF00,cEnFore=0xFF00FF,cBack=0x000000},
- stop={x=55,y=15,width=5,height=3,text={},active=true,txt=txts.stop,enabled=false,cFore=0x00FF00,cEnFore=0xFF00FF,cBack=0x000000},
- step={x=55,y=11,width=4,height=3,text={},active=true,txt=txts.step,enabled=false,cFore=0x00FF00,cEnFore=0xFA00FA,cBack=0x000000},
- materials={x=9,y=3,width=11,height=3,text={{"Материалы",1,1}},thin=true,active=true,cFore=0xFFFF00,cBack=0x444444},
- add={x=28,y=2,width=4,height=1,text={{"-->",0,0}},active=false,cFore=0xFFFF00,cBack=0x444444},
- cancel={x=32,y=23,width=8,height=1,text={{"Отмена",1,0}},active=false,cFore=0xFFFF00,cBack=0x444444},
- plt={x=38,y=2,width=5,height=1,text={{"Нет",1,0}},plt=false,active=false,cFore=0xFFFF00,cBack=0x444444},
- hplt={x=38,y=3,width=5,height=1,text={{"Нет",1,0}},hplt=false,active=false,cFore=0xFFFF00,cBack=0x444444},
- p={x=23,y=2,width=3,height=1,text={{"+",1,0}},active=true,mltp=1,cFore=0xFFFF00,cBack=0x444444},
- m={x=17,y=2,width=3,height=1,text={{"-",1,0}},active=true,mltp=-1,cFore=0xFFFF00,cBack=0x444444},
- fwd={x=29,y=23,width=2,height=1,text={{"->",0,0}},active=true,mltp=1,cFore=0xFFFF00,cBack=0x444444},
- bkd={x=14,y=23,width=2,height=1,text={{"<-",0,0}},active=true,mltp=-1,cFore=0xFFFF00,cBack=0x444444},
- exit={x=78,y=1,width=3,height=1,text={{"X",1,0}},active=true,cFore=0x444444,cBack=0xFF0000},
- moldP={x=1,y=2,ydef=2,width=12,height=1,text={{"Пластина",1,0}},mold="plate",div=1,active=false,cFore=0xFFFF00,cBack=0x000000},
- 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},
- 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},
- moldG={x=1,y=4,ydef=4,width=12,height=1,text={{"Шестеренка",1,0}},mold="gear",div=4,active=false,cFore=0xFFFF00,cBack=0x000000},
- moldE={x=1,y=5,ydef=5,width=12,height=1,text={{"Пусто",1,0}},mold="empty",active=false,cFore=0xFFFF00,cBack=0x000000}}
- 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},
- 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}}
- local labels = {queue={x=3,y=23,text="Очередь",cFore=0xFFFF00},
- detail={x=5,y=18,text="Деталь",cFore=0xFFFF00},
- material={x=3,y=20,text="Материал",cFore=0xFFFF00},
- count={x=3,y=2,text="Количество",cFore=0xFFFF00},
- plt={x=27,y=2,text="Обшивка",cFore=0xFFFF00},
- hplt={x=27,y=3,text="Тяжелая",cFore=0xFFFF00},
- nmb={x=20,y=2,width=3,text=" 0",o=0,cFore=0xFFFF00},
- d={x=14,y=18,text="",cFore=0xFFFF00},
- m={x=14,y=20,text="",cFore=0xFFFF00}}
- local startLabels = {labels.queue, labels.detail, labels.material, labels.count, labels.nmb}
- for i = 0, 1 do
- if transposer.getInventoryName(i) and transposer.getInventorySize(i) > 1 then mainInv = i slots = transposer.getInventorySize(i) break end
- end
- function add(list, data, obj)
- local wList = lists[list]
- local cPos, shift, spsr = 1, wList.width, wList.spacer
- local totalLines = #wList.content
- local count
- --if data then
- --[[if totalLines + count > wList.limit then
- for i = 1, count do
- table.remove(wList.content, 1)
- end
- end]]
- local x, y, w, h, l = wList.x, wList.y, wList.width, wList.height, wList.length
- if data then
- local lData
- local lsData
- if totalLines > 0 and spsr then
- l = l + spsr
- end
- if type(data) == "table" then
- lData = data[1]
- lsData = data[2]
- elseif type(data) == "string" then
- lData = data
- end
- l=l+1
- local mStr = lData:match("(.+)"..fChar) or lData
- local aStr = lData:match(fChar.."(.+)")
- local words = {}
- local tempContent = {}
- tempContent.s = l
- for word in mStr:gmatch("%S+") do table.insert(words, word) end
- if not wList.hor then
- local tStr = words[1]
- for i = 2, #words do
- if unicode.wlen(tStr.." "..words[i]) <= w then
- tStr = tStr .. " " .. words[i]
- else
- tempContent[l]=tStr
- l = l + 1
- tStr = ""
- end
- end
- if tStr ~= "" then
- tempContent[l] = tStr
- l = l + 1
- end
- else
- local wl = unicode.wlen(mStr)
- for i = 1, wl-1 do
- tempContent[l]=unicode.sub(mStr, i, i)
- l = l + 1
- end
- tempContent[l]=unicode.sub(mStr, wl, wl)
- end
- if aStr then
- if not wList.hor then
- tempContent[l]=aStr
- --l = l + 1
- else
- local awl = unicode.wlen(aStr)
- for i = 1, awl-1 do
- tempContent[l]=unicode.sub(aStr, i, i)
- l = l + 1
- end
- tempContent[l]=unicode.sub(aStr, awl, awl)
- end
- end
- tempContent.enabled = false
- tempContent.f = l
- if lsData then
- for k,v in pairs(lsData) do
- tempContent[k] = v
- end
- end
- table.insert(wList.content, tempContent)
- --totalLines = #wList.content
- -- if totalLines > l and wList.top == false then
- -- wList.posF = totalLines - l + 1
- -- end
- wList.length = l
- end
- if wList.sb then
- local length = 0
- local q = 0
- local hw = wList.hor and w or h
- if l > hw then
- length = math.floor(hw/l*hw)
- length = length > 0 and length or 1
- q = (hw - 1 - length)/(l - 1 - hw)
- q = q > 0 and q or 1
- wList.sb.q = q
- -- wList.sb.thumbPosition = math.ceil(math.abs(q*wlist.posF-realLength))
- wList.sb.work = true
- else
- length = wList.hor and w or h
- q = 0
- end
- wList.sb.q = q
- local s = wList.hor and dChar or " "
- wList.sb.thumb = string.rep(s, length)
- end
- end
- function drawList(list)
- gpu.setForeground(list.cFore)
- gpu.setBackground(list.cBack)
- local cCount = #list.content
- local l = list.length
- local x, y, w, h = list.x, list.y, list.width, list.height
- local len, xsb, ysb, sbw, sbh
- local posF = list.posF
- if not list.hor then
- len = h
- xsb = x+w
- ysb = y
- sbw = 1
- sbh = h
- else
- len = 1
- xsb = x
- ysb = y+1
- sbw = w
- sbh = 1
- end
- gpu.fill(x, y, w, h, " ")
- local shiftF = -1
- local hw = list.hor and w or h
- local fLine = l > hw and hw or l
- if not list.top and l < h then
- shiftF = h - l - 1
- end
- if cCount > 0 then
- local drawContent = {}
- for i = 1, cCount do
- --for k,v in pairs(list.content[i]) do
- if posF + fLine > list.content[i].s and posF <= list.content[i].f then
- table.insert(drawContent, list.content[i])
- end
- --end
- end
- for i = 1, #drawContent do
- local color = drawContent[i].enabled and list.cEnBack or list.cbBack
- gpu.setBackground(color)
- for i1 = posF, posF+fLine-1 do
- if drawContent[i][i1] then
- if not list.hor then
- gpu.fill(x, y+i1-posF, w, 1, " ")
- gpu.set(x, y+i1-posF, drawContent[i][i1])
- else
- gpu.set(x+i1-posF, y, drawContent[i][i1])
- end
- end
- end
- end
- end
- if list.sb then
- local n = list.hor and w or h
- local s = list.hor and dChar or " "
- if #list.content == 0 then list.sb.thumb = string.rep(s, n) list.sb.q = 0 end
- gpu.setForeground(0x000000)
- gpu.setBackground(0x000044)
- gpu.fill(xsb, ysb, sbw, sbh, s)
- gpu.setBackground(list.sb[1])
- local thumbPosition = math.ceil(list.sb.q*(list.posF-1))
- local xsb1, ysb1
- if not list.hor then
- xsb1 = xsb
- ysb1 = ysb + thumbPosition
- else
- xsb1 = xsb + thumbPosition
- ysb1 = ysb
- end
- gpu.set(xsb1, ysb1, list.sb.thumb, list.sb[2])
- end
- gpu.setForeground(0xFFFFFF)
- gpu.setBackground(0x000000)
- end
- function reCurNmb(add)
- curNmb = 0
- labels.nmb.text = " 0"
- drawLabel(labels.nmb)
- if add then
- sltSide(_, true)
- drawList(lists.materials)
- buttons.add.active=false
- gpu.setBackground(0x000000)
- gpu.set(28, 2, " ")
- end
- end
- function drawButton(btn)
- local x,y = btn.x, btn.y
- local w,h = btn.width, btn.height
- if btn.txt then
- local txt = btn.txt
- if not txt.mono then
- for i = 1, h do
- for l = 1, w*2, 2 do
- gpu.setForeground(btn.txt[i][l])
- gpu.setBackground(btn.txt[i][l+1])
- gpu.set(x+math.floor(l/2), y+i-1, uChar)
- end
- end
- else
- local color = btn.enabled and btn.cEnFore or btn.cFore
- gpu.setForeground(color)
- gpu.setBackground(btn.cBack)
- for i = 1, #txt do
- gpu.set(btn.x, btn.y+i-1, txt[i])
- end
- end
- else
- --gpu.setForeground(btn.cFore)
- gpu.setBackground(btn.cBack)
- if btn.thin then
- gpu.setForeground(0x000000)
- gpu.fill(x,y,w,1,uChar)
- gpu.fill(x,y+1,w,h-2," ")
- gpu.fill(x,y+h-1,w,1,dChar)
- else
- gpu.fill(x, y, w, h, " ")
- end
- end
- gpu.setForeground(btn.cFore)
- local text = btn.text
- if #text > 0 then
- for i = 1, #text do
- gpu.set(x+text[i][2], y+text[i][3], text[i][1])
- end
- end
- end
- function drawLabel(lbl)
- local width = lbl.width or unicode.wlen(lbl.text)+2
- local o = lbl.o or 1
- gpu.setBackground(0x444444)
- gpu.setForeground(lbl.cFore)
- gpu.fill(lbl.x, lbl.y, width, 1, " ")
- gpu.set(lbl.x+o, lbl.y, lbl.text)
- end
- -------------------------------------------------------
- term.clear()
- gpu.setResolution(80, 25)
- workBtn = buttons.stop
- buttons.stop.enabled = true
- local settings = io.open("settings", "r")
- if settings then
- local lines = {}
- for line in settings:lines() do table.insert(lines, line) end
- for k,v in pairs(lines) do
- if v:match("columns") then columns = tonumber(v:match("%d+")) break end
- end
- settings:close()
- end
- drawList(lists.queue)
- drawList(lists.materials)
- function getMaterials()
- if #lists.queue.content == 0 then
- local materials = {}
- local stacks = transposer.getAllStacks(mainInv)
- for i = 1, slots do transposer.transferItem(mainInv, mainInv, _, i) end
- for i = 1, slots do
- if stacks[i].name ~= "minecraft:air" then
- local name = stacks[i].label
- local size = stacks[i].size
- if materials[name] then
- materials[name] = materials[name] + size
- else
- materials[name] = size
- end
- end
- end
- lists.materials.content={}
- lists.materials.length=0
- lists.materials.posF=1
- for k,v in pairs(materials) do
- add("materials", {k..fChar..tostring(v), {mat=k, size=v}})
- end
- drawList(lists.materials)
- end
- end
- buttons.materials.func = getMaterials
- buttons.exit.func = function()
- gpu.setResolution(160, 50)
- gpu.setForeground(0xFFFFFF)
- gpu.setBackground(0x000000)
- term.clear()
- os.exit()
- end
- function plusMinus(btn, shift, control)
- if wMold and mat then
- curNmb = curNmb + btn.mltp*(shift and 2 or 1)*(control and 4 or 1)
- if curNmb < 0 then
- curNmb = 0
- elseif curNmb > maxNmb then
- curNmb = maxNmb
- end
- if curNmb > 0 then
- if not buttons.add.active then
- buttons.add.active=true
- drawButton(buttons.add)
- end
- else
- if buttons.add.active then
- buttons.add.active = false
- gpu.setBackground(0x000000)
- gpu.set(28, 2, " ")
- end
- end
- local tNmb = tostring(curNmb)
- local length = string.len(tNmb)
- labels.nmb.text = string.rep(" ", 3-length)..tNmb
- drawLabel(labels.nmb)
- end
- end
- buttons.p.func = plusMinus
- buttons.m.func = plusMinus
- lists.materials.func = function(l)
- for i = 1, #l.content do
- if l.content[i].enabled then
- mat = l.content[i].mat
- wSize = l.content[i].size
- break
- end
- end
- if wDiv then
- maxNmb = math.floor(wSize/wDiv)
- end
- reCurNmb()
- end
- for k,v in pairs(buttons) do
- if v.active then
- drawButton(v)
- end
- end
- for i = 1, #startLabels do
- drawLabel(startLabels[i])
- end
- function setSideForMold(btn)
- if btn.side then
- if not selectedSideForMold then
- btn.active=false
- selectedSideForMold = btn
- else
- selectedSideForMold.active=true
- drawButton(selectedSideForMold)
- btn.active=false
- selectedSideForMold = btn
- for k,v in pairs(buttons) do
- if v.ydef then
- v.x=1
- v.y=v.ydef
- v.active=false
- end
- end
- end
- for k,v in pairs(buttons) do
- if v.ydef then
- v.active=true
- v.x=selectedSideForMold.x+2
- v.y=v.y+selectedSideForMold.y+1
- drawButton(v)
- end
- end
- end
- end
- buttons.north.rFunc = setSideForMold
- buttons.south.rFunc = setSideForMold
- buttons.west.rFunc = setSideForMold
- buttons.east.rFunc = setSideForMold
- function sltSide(btn, cancel)
- if cancel and lSide or lSide and lSide ~= btn and btn.mold then
- local lx, ly, lw, lh, lmold = lSide.x, lSide.y, lSide.width, lSide.height, lSide.mold
- for i = 1, 16 do
- gpu.setForeground(txts[lmold][1][i*2-1])
- gpu.setBackground(txts[lmold][1][i*2])
- gpu.set(lx+i-1, ly, uChar)
- gpu.setForeground(txts[lmold][8][i*2-1])
- gpu.setBackground(txts[lmold][8][i*2])
- gpu.set(lx+i-1, ly+lh-1, uChar)
- end
- for i = 1, 8 do
- gpu.setForeground(txts[lmold][i][1])
- gpu.setBackground(txts[lmold][i][2])
- gpu.set(lx, ly+i-1, uChar)
- gpu.setForeground(txts[lmold][i][31])
- gpu.setBackground(txts[lmold][i][32])
- gpu.set(lx+lw-1, ly+i-1, uChar)
- end
- wMold = false
- end
- if btn and btn.mold then
- lSide = btn
- wSide = btn.side
- wMold = btn.mold
- gpu.setForeground(0x00FF00)
- local x, y = btn.x, btn.y
- local w, h = btn.width, btn.height
- for i = 1, 16 do
- gpu.setBackground(txts[wMold][1][i*2])
- gpu.set(x+i-1, y, uChar)
- gpu.setBackground(txts[wMold][8][i*2-1])
- gpu.set(x+i-1, y+h-1, dChar)
- end
- gpu.fill(x, y, 1, 8, fChar)
- gpu.fill(x+w-1, y, 1, 8, fChar)
- wDiv = btn.div
- if wSize then
- maxNmb = math.floor(wSize/wDiv)
- end
- reCurNmb()
- end
- end
- buttons.north.func = sltSide
- buttons.south.func = sltSide
- buttons.west.func = sltSide
- buttons.east.func = sltSide
- function selectMold(btn)
- if btn.mold ~= "empty" then
- selectedSideForMold.mold = btn.mold
- selectedSideForMold.txt = txts[btn.mold]
- selectedSideForMold.div = btn.div
- selectedSideForMold.text[1][1] = ""
- end
- for k,v in pairs(buttons) do
- if v.ydef then
- v.x=1
- v.y=v.ydef
- v.active=false
- end
- end
- --selectedSideForMold.active = true
- drawButton(selectedSideForMold)
- selectedSideForMold.active=true
- selectedSideForMold = nil
- end
- for k,v in pairs(buttons) do
- if v.ydef then
- v.func = selectMold
- end
- end
- buttons.add.func = function()
- local cn = curNmb
- if wDiv < 1 then cn = math.ceil(curNmb * wDiv) end
- for i = 1, cn do
- add("queue", {" ", {mat=mat, count=math.ceil(wDiv), side=wSide, mold=wMold}})
- end
- local lc = lists.materials.content
- for i = 1, #lc do
- if lc[i].enabled then
- lc[i].size = lc[i].size - math.ceil(curNmb*wDiv)
- lc[i][lc[i].f] = tostring(lc[i].size)
- lc[i].enabled = false
- mat = false
- break
- end
- end
- reCurNmb(true)
- drawList(lists.queue)
- end
- lists.queue.func = function(l)
- reQueueInfo()
- local chunk
- for i = 1, #l.content do
- if l.content[i].enabled then
- chunk = l.content[i]
- break
- end
- end
- if chunk then
- labels.d.text = molds[chunk.mold]
- labels.m.text = chunk.mat
- drawLabel(labels.d)
- drawLabel(labels.m)
- buttons.cancel.active = true
- drawButton(buttons.cancel)
- end
- end
- function start()
- local c = lists.queue.content
- local st = 1
- local mats = transposer.getAllStacks(mainInv).getAll()
- local lastSide
- local nwk = {}
- workBtn.enabled = false
- drawButton(workBtn)
- buttons.start.enabled = true
- workBtn = buttons.start
- drawButton(workBtn)
- queueWork = true
- local slotNmb
- while st <= #c and queueWork do
- -- local slot = transposer.getStackInSlot(c[st].side, 1)
- for i1 = #mats, 1, -1 do
- if mats[i1].label == c[st].mat and mats[i1].size >= c[st].count then
- slotNmb = i1
- break
- end
- end
- if transposer.getSlotStackSize(c[st].side, 1) == 0 then
- --if c[st].side == lastSide then
- os.sleep(delay)
- --else
- --lastSide = c[st].side
- --end
- local stck = transposer.transferItem(mainInv, c[st].side, c[st].count, slotNmb)
- if stck == 0 then
- table.insert(nwk, c[st])
- end
- --if c[st].count == 0 then
- --table.remove(c, 1)
- st = st + 1
- --end
- end
- end
- for i = 1, st-1 do table.remove(c, 1) end
- if #c == 0 then qStop = true end
- if qStop then
- queueStop(nwk) qStop = false
- else
- local lst = lists.queue
- if #c > 0 then
- lst.length = #c*2 + (#c-1)*2
- local diff = c[#c].f - lst.length
- for i = 1, #c do
- local data = {}
- for i1 = c[i].s, c[i].f do
- table.insert(data, c[i][i1])
- c[i][i1] = nil
- end
- c[i].s = c[i].s - diff
- c[i].f = c[i].f - diff
- for i2 = 1, #data do
- c[i][c[i].s-1+i2] = data[i2]
- end
- end
- else
- c = {}
- lst.length = 0
- end
- lst.posF = 1
- add("queue")
- drawList(lists.queue)
- end
- reQueueInfo(true)
- end
- buttons.start.func = function(btn)
- thread.create(start)
- end
- function queueStop(nwk)
- local c = lists.queue.content
- local m = lists.materials.content
- if #c > 0 then
- for i = 1, #c do
- for i1 = 1, #m do
- if m[i1].mat == c[i].mat then
- m[i1].size = m[i1].size + c[i].count
- break
- end
- end
- end
- end
- if #nwk > 0 then
- for i = 1, #nwk do
- for i1 = 1, #m do
- if m[i1].mat == nwk[i].mat then
- m[i1].size = m[i1].size + nwk[i].count
- break
- end
- end
- end
- end
- for i = 1, #m do
- m[i][m[i].f] = tostring(m[i].size)
- end
- drawList(lists.materials)
- lists.queue.length = 0
- lists.queue.content = {}
- lists.queue.posF = 1
- drawList(lists.queue)
- workBtn.enabled = false
- drawButton(workBtn)
- workBtn = buttons.stop
- workBtn.enabled = true
- drawButton(workBtn)
- end
- buttons.stop.func = function()
- if queueWork then
- queueWork = false
- qStop = true
- else
- queueStop()
- end
- --[[local c = lists.queue.content
- if #c > 0 then
- for i = 1, #c do
- for i1 = 1, #lists.materials.content do
- if lists.materials.content[i1].mat == c[i].mat then
- lists.materials.content[i1].size = lists.materials.content[i1].size + c[i].count
- break
- end
- end
- end
- for i = 1, #lists.materials.content do
- lists.materials.content[i][lists.materials.content[i].f] = tostring(lists.materials.content[i].size)
- end
- end
- drawList(lists.materials)
- lists.queue.length = 0
- lists.queue.content = {}
- lists.queue.posF = 1
- drawList(lists.queue)]]
- workBtn.enabled = false
- drawButton(workBtn)
- buttons.stop.enabled = true
- workBtn = buttons.stop
- drawButton(workBtn)
- reQueueInfo(true)
- end
- buttons.pause.func = function()
- if queueWork then
- queueWork = false
- workBtn.enabled = false
- drawButton(workBtn)
- workBtn = buttons.pause
- workBtn.enabled = true
- drawButton(workBtn)
- end
- end
- buttons.step.func = function(btn)
- if queueWork == false then
- if btn ~= workBtn then
- workBtn.enabled = false
- drawButton(workBtn)
- workBtn = buttons.step
- workBtn.enabled = true
- drawButton(workBtn)
- end
- local c = lists.queue.content
- local slots = transposer.getAllStacks(mainInv).getAll()
- local s
- local cnt
- local mat
- local nmb
- local last = false
- local pos = lists.queue.posF
- for i = 1, #c do
- if c[i].enabled then
- s = c[i].side
- cnt = c[i].count
- mat = c[i].mat
- nmb = i
- if i == #c then last = true end
- break
- end
- end
- if s then
- for i = #slots, 1, -1 do
- if slots[i].label == mat and slots[i].size >= cnt then
- cnt = cnt - transposer.transferItem(mainInv, s, cnt, i)
- table.remove(c, nmb)
- break
- end
- end
- -- lists.queue.length = lists.queue.length - 4
- -- if not last then
- -- for i = nmb, #c do
- -- local data = {}
- -- for i1 = c[i].s, c[i].f do
- -- table.insert(data, c[i][i1])
- -- c[i][i1] = nil
- -- end
- -- c[i].s = c[i].s - 4
- -- c[i].f = c[i].f - 4
- -- for i2 = 1, #data do
- -- c[i][i2+c[i].s-1] = data[i2]
- -- end
- -- end
- -- end
- -- pos = pos - 4
- -- if pos < 1 then pos = 1 end
- -- lists.queue.posF = pos
- -- add("queue")
- -- drawList(lists.queue)
- updList(nmb, c, pos, last, cnt, mat)
- end
- reQueueInfo(true)
- end
- end
- function updList(nmb, c, pos, last, cnt, mat)
- lists.queue.length = lists.queue.length - 4
- local m = lists.materials.content
- local nm
- for i = 1, #m do
- if m[i].mat == mat then
- m[i].size = m[i].size + cnt
- nm = i
- break
- end
- end
- m[nm][m[nm].f] = tostring(m[nm].size)
- if not last then
- for i = nmb, #c do
- local data = {}
- for i1 = c[i].s, c[i].f do
- table.insert(data, c[i][i1])
- c[i][i1] = nil
- end
- c[i].s = c[i].s - 4
- c[i].f = c[i].f - 4
- for i2 = 1, #data do
- c[i][i2+c[i].s-1] = data[i2]
- end
- end
- end
- pos = pos - 4
- if pos < 1 then pos = 1 end
- lists.queue.posF = pos
- add("queue")
- drawList(lists.queue)
- drawList(lists.materials)
- end
- buttons.cancel.func = function()
- local c = lists.queue.content
- local pos = lists.queue.posF
- local nmb
- local last = false
- local cnt
- local mat
- for i = 1, #c do
- if c[i].enabled then
- nmb = i
- cnt = c[i].count
- mat = c[i].mat
- if nmb == #c then last = true end
- break
- end
- end
- table.remove(c, nmb)
- updList(nmb, c, pos, last, cnt, mat)
- reQueueInfo(true)
- end
- function fwdBkd(btn)
- local list = lists.queue
- local pos = list.posF
- if list.length > list.width then
- pos = pos + 4*btn.mltp
- if pos <= 0 then
- pos = 1
- elseif pos+list.width-1 > list.length then
- pos = list.length - list.width + 1
- end
- list.posF = pos
- drawList(lists.queue)
- end
- end
- buttons.bkd.func = fwdBkd
- buttons.fwd.func = fwdBkd
- function reQueueInfo(cancel)
- gpu.setBackground(0x000000)
- local d = labels.d
- local m = labels.m
- gpu.fill(d.x, d.y, 13, 1, " ")
- gpu.fill(m.x, m.y, 22, 1, " ")
- if cancel then
- buttons.cancel.active = false
- gpu.fill(buttons.cancel.x, buttons.cancel.y, 8, 1, " ")
- end
- end
- function interface()
- while true do
- local event,_,x,y,mb = event.pull()
- if event == "touch" then
- local list
- for k,v in pairs(lists) do
- if x >= v.x and x < v.x+v.width and y >= v.y and y < v.y+v.height then
- list = v
- break
- end
- end
- if list then
- local curListPos
- if not list.hor then
- curListPos = y-list.y+list.posF
- else
- curListPos = x-list.x+list.posF
- end
- for k,v in pairs(list.content) do
- if curListPos >= v.s and curListPos <= v.f then
- for i = 1, #list.content do list.content[i].enabled = false end
- v.enabled = true
- drawList(list)
- break
- end
- end
- if list.func then list.func(list) end
- else
- for k,v in pairs(buttons) do
- if v.active then
- if x >= v.x and x < v.x+v.width and y >= v.y and y < v.y+v.height then
- if mb == 0 and v.func then
- v.func(v, keyboard.isShiftDown(), keyboard.isControlDown())
- break
- elseif mb == 1 and v.rFunc then
- v.rFunc(v)
- break
- end
- end
- end
- end
- end
- elseif event == "scroll" then
- for k,v in pairs(lists) do
- if x >= v.x and x < v.x+v.width and y >= v.y and y < v.y+v.height then
- local pos = v.posF
- pos = pos - mb
- local hw = v.hor and v.width or v.height
- if pos >= 1 and pos + hw-1 <= v.length then
- v.posF = pos
- drawList(v)
- end
- end
- end
- end
- end
- end
- local main = thread.create(interface)
- thread.waitForAll({main})
- os.exit(0)