Advertisement
MarkFergus

portal_Imhp808

Jun 5th, 2020
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local version = "1.12" --(31/05 2020)
  2. os.loadAPI("/portal/f") -- a monitor API made by myself, it makes my life easier
  3. os.loadAPI("/portal/lib/API") -- search_bar
  4. --local img = paintutils.loadImage("/portal/lib/Charm")
  5. local p = peripheral.find("diamond") -- can change for "chest" instead of "draconic_chest"
  6. local m = peripheral.find("monitor") -- running on a monitor
  7. local q = peripheral.find("peripheral")
  8. m.setTextScale(1)
  9. local side,rside = "north","left" -- IMPORTANT
  10. local list_items,items,stq = {},{},{}
  11. local a,b,c = 1,1,1
  12. local selected,last_dest = 0,"aucun"
  13. local chestSize = p.getInventorySize()
  14. local w,h = m.getSize()
  15.  
  16. local bg = window.create(m,1,1,w,h)
  17. local list = window.create(m,1,2,w*3/5-1,chestSize)
  18. local up_bar = window.create(m,1,1,w,1)
  19. local down_bar = window.create(m,1,h,w,h)
  20. local scroll_bar = window.create(m,w*(3/5),2,1,h-1)
  21. local bg2 = window.create(m,w*0.6+1,2,w*0.4+1,h-1)
  22. local pbg2 = {bg2.getPosition()} sbg2 = {bg2.getSize()}
  23. local button1 = window.create(bg2,2,3,sbg2[1]-2,3)
  24. local pb1 = {button1.getPosition()} sb1 = {button1.getSize()}
  25.  
  26. local VIP = {"TheBaslez","SesameChocolat","Jaguar","LeChikito","jungleis26","Ertupop","Veine","annelaure1912","Gaetann18",
  27. "GohuSan","boucherreb","Ciliste"}
  28. local GUIDES = {"zorinova","DaikiKaminari","maxou684"}
  29.  
  30. function reset()
  31.   bg.setBackgroundColor(colors.black) bg.clear()
  32.   list.setBackgroundColor(colors.black) list.clear()
  33.   up_bar.setBackgroundColor(colors.lightGray) up_bar.clear()
  34.   down_bar.setBackgroundColor(colors.lightGray) down_bar.clear()
  35.   scroll_bar.setBackgroundColor(colors.lightGray) scroll_bar.clear()
  36.   bg2.setBackgroundColor(colors.gray) bg2.clear()
  37.   button1.setBackgroundColor(colors.red) button1.clear()
  38.   f.centerText(up_bar,1,"selectionner une destination","black","lightGray")
  39.   f.cprint(down_bar,1,1,"dernier tp : ","black")
  40.   f.centerTextRight(down_bar,1,"v"..version,"black","lightGray")
  41.   f.cprint(down_bar,14,1,last_dest,"blue","lightGray")
  42.   f.cprint(scroll_bar,1,1,"^","black","gray")
  43.   f.cprint(scroll_bar,1,h-2,"v","black","gray")
  44.   f.cprint(bg2,2,1,"Status: ","white","gray")
  45.   f.cprint(bg2,2,7,"Rechercher:","white","gray")
  46.   f.centerText(button1,2,"fermer","black","red")
  47.   f.drawLine(bg2,2,9,sbg2[1]-2.4,"lightGray")
  48.   if q ~= nil then
  49.     local stq = q.getAllStacks()
  50.     if stq[1] ~= nil then f.cprint(bg2,9,1,"on","green","gray")
  51.     else f.cprint(bg2,9,1,"off","yellow","gray") end
  52.   end
  53.   --term.redirect(bg2) paintutils.drawImage(img,sbg2[1]/2-3,11)
  54.   if word ~= nil then f.cprint(bg2,2,9,word,"gray","lightGray") end
  55.   f.cprint(bg2,2,11,"Double-cliquer sur","white","gray")
  56.   f.cprint(bg2,2,12," un nom pour se","white","gray")
  57.   f.cprint(bg2,2,13," teleporter.","white","gray")
  58.   f.cprint(bg2,2,14,"Taper dans le","white","gray")
  59.   f.cprint(bg2,2,15," computer une ","white","gray")
  60.   f.cprint(bg2,2,16," recherche.","white","gray")
  61. end
  62.  
  63. function pulse()
  64.   rs.setAnalogOutput(rside,15)
  65.   sleep(0.5)
  66.   rs.setAnalogOutput(rside,0)
  67. end
  68.  
  69. function getItems()
  70.   b = 1
  71.   items = {}
  72.   if chestSize ~= nil then
  73.     for a=1,chestSize do
  74.       list_items[a] = p.getStackInSlot(a)
  75.       if list_items[a] ~= nil and list_items[a].name == "teleporterMKI" then
  76.         items[b] = {}
  77.         items[b][1] = a
  78.         items[b][2] = API.normalize(list_items[a].display_name)
  79.         if API.check(VIP,items[b][2]) == true then items[b][3] = "VIP" end
  80.         if API.check(GUIDES,items[b][2]) == true then items[b][3] = "guide" end
  81.         b = b + 1
  82.       end
  83.     end
  84.   end
  85.   table.sort(items, function(a, b) return a[2] < b[2] end)
  86.   if display == nil then display = items end
  87. end
  88.  
  89. function list_display()
  90.   for c=1,#display do
  91.     if c == selected then
  92.       f.drawLine(list,1,c,w,"red")
  93.       f.centerTextRight(list,c,"ouvrir","white")
  94.     else
  95.       list.setBackgroundColor(colors.black)
  96.     end
  97.     if display[c][3] == nil then
  98.       f.cprint(list,1,c,display[c][2],"gray")
  99.     elseif display[c][3] == "spawn" then
  100.       f.centerText(list,c,display[c][2],"lightBlue")
  101.     elseif display[c][3] == "VIP" then
  102.       f.cprint(list,1,c,display[c][2],"orange")
  103.     elseif display[c][3] == "guide" then
  104.       f.cprint(list,1,c,display[c][2],"lime")
  105.     end
  106.   end
  107. end
  108.  
  109. function scroll(direction)
  110.   local x,y = list.getPosition()
  111.   if direction == "up" and y <=1 then
  112.     list.reposition(1,y+2)
  113.   elseif direction == "down" and y+#items > h-1 then
  114.     list.reposition(1,y-2)
  115.   end
  116. end
  117.  
  118. function search(entry)
  119.   bg2.setCursorPos(2,9)
  120.   word = API.read(bg2,30,"lightGray",entry)
  121.   display = {}
  122.   for i,v in pairs(items) do
  123.     if string.find(v[2],word) ~= nil then
  124.       table.insert(display,v)
  125.     end
  126.   end
  127. end
  128.  
  129. pulse()
  130.  
  131. while true do
  132.   reset()
  133.   getItems()
  134.   list_display()
  135.   down_bar.redraw()
  136.   up_bar.redraw()
  137.   x,y = list.getPosition()
  138.   j,k = scroll_bar.getPosition()
  139.   local event = {os.pullEvent()}
  140.   if event[1] == "monitor_touch" then
  141.     if event[4]-y+1 == selected and display[selected] ~= nil and event[3] < j-1 then
  142.       up_bar.clear()
  143.       f.centerText(up_bar,1,"ouverture...","black")
  144.       pulse()
  145.       sleep(0.5)
  146.       p.pushItem(side,display[selected][1])
  147.       last_dest = display[selected][2]
  148.       getItems()
  149.     elseif event[4] > 1 and event[3] < j-1 then
  150.       selected = event[4]-y+1
  151.     elseif event[4] == 2 and event[3] == j then
  152.       scroll("up")
  153.     elseif event[4] == h-1 and event[3] == j then
  154.       scroll("down")
  155.     elseif f.itrv(event[3],pbg2[1],pbg2[1]+sbg2[1]) and f.itrv(event[4],pbg2[2],pbg2[2]+sbg2[2]) then
  156.       xc = event[3]-pbg2[1]+1 yc = event[4]-pbg2[2]+1
  157.       if f.itrv(xc,pb1[1],pb1[1]+sb1[1]) and f.itrv(yc,pb1[2],pb1[2]+sb1[2]-1) then
  158.         up_bar.clear()
  159.         f.centerText(up_bar,1,"fermeture...","black")
  160.         pulse()
  161.         sleep(0.4)
  162.       elseif f.itrv(xc,2,sbg2[1]) and f.itrv(yc,6,9) then
  163.         search()
  164.       end
  165.     end
  166.   end
  167.   if event[1] == "char" then search(event[2]) end
  168. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement