Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("f") -- a monitor API made by myself, it makes my life easier
- os.loadAPI("getInput") -- search_bar
- local p = peripheral.find("draconic_chest") -- can change for "chest" instead of "draconic_chest"
- local m = peripheral.find("monitor") -- running on a monitor
- m.setTextScale(0.5)
- local list_items,items = {},{}
- local a,b,c = 1,1,1
- local selected = 0
- local side = "west" -- 2nd chest direction from 1st chest
- local chestSize = p.getInventorySize()
- local w,h = m.getSize()
- local bg = window.create(m,1,1,w,h)
- local list = window.create(m,1,2,w*3/5-1,chestSize)
- local up_bar = window.create(m,1,1,w,1)
- local down_bar = window.create(m,1,h,w,h)
- local scroll_bar = window.create(m,w*(3/5),2,1,h-1)
- local bg2 = window.create(m,w*(3/5)+1,2,w,h-1)
- function reset()
- bg.setBackgroundColor(colors.black)
- bg.clear()
- list.setBackgroundColor(colors.black)
- list.clear()
- up_bar.setBackgroundColor(colors.lightGray)
- up_bar.clear()
- down_bar.setBackgroundColor(colors.lightGray)
- down_bar.clear()
- scroll_bar.setBackgroundColor(colors.lightGray)
- scroll_bar.clear()
- bg2.setBackgroundColor(colors.gray)
- bg2.clear()
- f.centerText(up_bar,1,"selectionner une destination","black")
- f.print(down_bar,"dernier tp : ","black")
- f.cprint(down_bar,13,1,last_dest,"blue","lightGray")
- f.cprint(scroll_bar,1,1,"^","black","gray")
- f.cprint(scroll_bar,1,h-2,"v","black","gray")
- end
- function pulse()
- redstone.setAnalogOutput("right",15)
- sleep(0.5)
- redstone.setAnalogOutput("right",0)
- local last_dest = "none"
- end
- function getItems()
- b = 1
- items = {}
- if chestSize ~= nil then
- for a=1,chestSize do
- list_items[a] = p.getStackInSlot(a)
- if list_items[a] ~= nil and list_items[a].name == "teleporterMKI" then
- items[b] = {}
- items[b][1] = a
- items[b][2] = list_items[a].display_name
- b = b + 1
- end
- end
- end
- table.sort(items, function(a, b) return a[2] < b[2] end)
- table.insert(items,1,{1,">>> retour au Spawn <<<","spawn"})
- end
- function list_display()
- for c=1,#items do
- if c == selected then
- f.drawLine(list,1,c,w,"gray")
- f.centerTextRight(list,c,"ouvrir","white")
- else
- list.setBackgroundColor(colors.black)
- end
- if items[c][3] == nil then
- f.cprint(list,1,c,items[c][2],"blue","black")
- elseif items[c][3] == "spawn" then
- f.centerText(list,c,items[c][2],"cyan")
- end
- end
- end
- function scroll(direction)
- local x,y = list.getPosition()
- if direction == "up" and y <=1 then
- list.reposition(1,y+2)
- elseif direction == "down" and y+#items > h-1 then
- list.reposition(1,y-2)
- end
- end
- pulse()
- while true do
- reset()
- getItems()
- list_display()
- down_bar.redraw()
- up_bar.redraw()
- x,y = list.getPosition()
- j,k = scroll_bar.getPosition()
- event,p1,p2,p3,p4,p5 = os.pullEvent()
- if event == "monitor_touch" then
- if p3-y+1 == selected and items[selected] ~= nil and p2 < j-1 then
- up_bar.clear()
- f.centerText(up_bar,1,"ouverture...","black")
- pulse()
- p.pushItem(side,items[selected][1])
- last_dest = items[selected][2]
- getItems()
- close = os.startTimer(3)
- elseif p3 > 1 and p2 < j-1 then
- selected = p3-y+1
- elseif p3 == 2 and p2 == j then
- scroll("up")
- elseif p3 == h-1 and p2 == j then
- scroll("down")
- end
- end
- if event == "timer" and p1 == close then
- pulse()
- end
- bg2.setCursorPos(1,1)
- search, ev10, p10 = getInput.read(bg2,30)
- bg2.setCursorPos(1,2)
- print(search)
- display = {}
- for i,v in pairs(items) do
- if string.find(v[2],search) ~= nil then
- table.insert(display,v)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement