Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local version = "1.12" --(31/05 2020)
- os.loadAPI("/portal/f") -- a monitor API made by myself, it makes my life easier
- os.loadAPI("/portal/lib/API") -- search_bar
- --local img = paintutils.loadImage("/portal/lib/Charm")
- local p = peripheral.find("diamond") -- can change for "chest" instead of "draconic_chest"
- local m = peripheral.find("monitor") -- running on a monitor
- local q = peripheral.find("peripheral")
- m.setTextScale(1)
- local side,rside = "north","left" -- IMPORTANT
- local list_items,items,stq = {},{},{}
- local a,b,c = 1,1,1
- local selected,last_dest = 0,"aucun"
- 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*0.6+1,2,w*0.4+1,h-1)
- local pbg2 = {bg2.getPosition()} sbg2 = {bg2.getSize()}
- local button1 = window.create(bg2,2,3,sbg2[1]-2,3)
- local pb1 = {button1.getPosition()} sb1 = {button1.getSize()}
- local VIP = {"TheBaslez","SesameChocolat","Jaguar","LeChikito","jungleis26","Ertupop","Veine","annelaure1912","Gaetann18",
- "GohuSan","boucherreb","Ciliste"}
- local GUIDES = {"zorinova","DaikiKaminari","maxou684"}
- 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()
- button1.setBackgroundColor(colors.red) button1.clear()
- f.centerText(up_bar,1,"selectionner une destination","black","lightGray")
- f.cprint(down_bar,1,1,"dernier tp : ","black")
- f.centerTextRight(down_bar,1,"v"..version,"black","lightGray")
- f.cprint(down_bar,14,1,last_dest,"blue","lightGray")
- f.cprint(scroll_bar,1,1,"^","black","gray")
- f.cprint(scroll_bar,1,h-2,"v","black","gray")
- f.cprint(bg2,2,1,"Status: ","white","gray")
- f.cprint(bg2,2,7,"Rechercher:","white","gray")
- f.centerText(button1,2,"fermer","black","red")
- f.drawLine(bg2,2,9,sbg2[1]-2.4,"lightGray")
- if q ~= nil then
- local stq = q.getAllStacks()
- if stq[1] ~= nil then f.cprint(bg2,9,1,"on","green","gray")
- else f.cprint(bg2,9,1,"off","yellow","gray") end
- end
- --term.redirect(bg2) paintutils.drawImage(img,sbg2[1]/2-3,11)
- if word ~= nil then f.cprint(bg2,2,9,word,"gray","lightGray") end
- f.cprint(bg2,2,11,"Double-cliquer sur","white","gray")
- f.cprint(bg2,2,12," un nom pour se","white","gray")
- f.cprint(bg2,2,13," teleporter.","white","gray")
- f.cprint(bg2,2,14,"Taper dans le","white","gray")
- f.cprint(bg2,2,15," computer une ","white","gray")
- f.cprint(bg2,2,16," recherche.","white","gray")
- end
- function pulse()
- rs.setAnalogOutput(rside,15)
- sleep(0.5)
- rs.setAnalogOutput(rside,0)
- 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] = API.normalize(list_items[a].display_name)
- if API.check(VIP,items[b][2]) == true then items[b][3] = "VIP" end
- if API.check(GUIDES,items[b][2]) == true then items[b][3] = "guide" end
- b = b + 1
- end
- end
- end
- table.sort(items, function(a, b) return a[2] < b[2] end)
- if display == nil then display = items end
- end
- function list_display()
- for c=1,#display do
- if c == selected then
- f.drawLine(list,1,c,w,"red")
- f.centerTextRight(list,c,"ouvrir","white")
- else
- list.setBackgroundColor(colors.black)
- end
- if display[c][3] == nil then
- f.cprint(list,1,c,display[c][2],"gray")
- elseif display[c][3] == "spawn" then
- f.centerText(list,c,display[c][2],"lightBlue")
- elseif display[c][3] == "VIP" then
- f.cprint(list,1,c,display[c][2],"orange")
- elseif display[c][3] == "guide" then
- f.cprint(list,1,c,display[c][2],"lime")
- 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
- function search(entry)
- bg2.setCursorPos(2,9)
- word = API.read(bg2,30,"lightGray",entry)
- display = {}
- for i,v in pairs(items) do
- if string.find(v[2],word) ~= nil then
- table.insert(display,v)
- end
- 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()
- local event = {os.pullEvent()}
- if event[1] == "monitor_touch" then
- if event[4]-y+1 == selected and display[selected] ~= nil and event[3] < j-1 then
- up_bar.clear()
- f.centerText(up_bar,1,"ouverture...","black")
- pulse()
- sleep(0.5)
- p.pushItem(side,display[selected][1])
- last_dest = display[selected][2]
- getItems()
- elseif event[4] > 1 and event[3] < j-1 then
- selected = event[4]-y+1
- elseif event[4] == 2 and event[3] == j then
- scroll("up")
- elseif event[4] == h-1 and event[3] == j then
- scroll("down")
- elseif f.itrv(event[3],pbg2[1],pbg2[1]+sbg2[1]) and f.itrv(event[4],pbg2[2],pbg2[2]+sbg2[2]) then
- xc = event[3]-pbg2[1]+1 yc = event[4]-pbg2[2]+1
- if f.itrv(xc,pb1[1],pb1[1]+sb1[1]) and f.itrv(yc,pb1[2],pb1[2]+sb1[2]-1) then
- up_bar.clear()
- f.centerText(up_bar,1,"fermeture...","black")
- pulse()
- sleep(0.4)
- elseif f.itrv(xc,2,sbg2[1]) and f.itrv(yc,6,9) then
- search()
- end
- end
- end
- if event[1] == "char" then search(event[2]) end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement