Advertisement
MarkFergus

/portal/launch

Mar 26th, 2021
870
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local version = "1.13" --(31/07/2020)
  2. os.loadAPI("/lib/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("draconic_chest") -- can change from "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 = "west","east" -- IMPORTANT
  10. local list_items,items,stq = {},{},{}
  11. local a,b,c,volume = 1,1,1,100
  12. local selected,last_dest = 0,"aucun"
  13. local chestSize = p.getInventorySize()
  14. local w,h = m.getSize()
  15.  
  16. local VIP = {"TheBaslez","SesameChocolat","Jaguar","LeChikito","jungleis26","Ertupop","Veine","annelaure1912","Gaetann18",
  17. "GohuSan","boucherreb","Ciliste"}
  18. local GUIDES = {"zorinova","DaikiKaminari","maxou684"}
  19.  
  20. function vn(arg) return arg ~= nil end
  21.  
  22. function setWindows()
  23.     bg = f.addWin(m,1,1,w,h) bg.reset = {bg_color="black"}
  24.     list = f.addWin(m,1,2,w*3/5-1,chestSize) list.reset = {bg_color="black"}
  25.     up_bar = f.addWin(m,1,1,w,1) up_bar.reset = {bg_color="lightGray",printText = function()
  26.         f.centerText(up_bar,1,"selectionner une destination","black","lightGray") end}
  27.     down_bar = f.addWin(m,1,h,w,h) down_bar.reset = {bg_color="lightGray",printText = function()
  28.         f.centerTextRight(down_bar,1,"v"..version,"black","lightGray") end}
  29.     scroll_bar = f.addWin(m,w*(3/5),2,1,h-1) scroll_bar.reset = {bg_color="lightGray",printText = function()
  30.         f.cprint(scroll_bar,1,1,"^","black","gray")
  31.         f.cprint(scroll_bar,1,h-2,"v","black","gray") end}
  32.     bg2 = f.addWin(m,w*0.6+1,2,w*0.4+1,h-1) bg2.reset = {bg_color="gray",printText = function()
  33.         f.cprint(bg2,2,1,"Status: ","white","gray")
  34.         f.cprint(bg2,2,7,"Rechercher:","white","gray")
  35.         f.drawLine(bg2,2,9,bg2.size[1]-2.4,"lightGray")
  36.         f.cprint(bg2,2,11,"Taper dans le","white","gray")
  37.         f.cprint(bg2,2,12," computer une ","white","gray")
  38.         f.cprint(bg2,2,13," recherche.","white","gray")
  39.         f.cprint(bg2,2,14,"Double-cliquer sur","white","gray")
  40.         f.cprint(bg2,2,15," un nom pour se","white","gray")
  41.         f.cprint(bg2,2,16," teleporter.","white","gray") end}
  42.     b1 = f.addWin(bg2,2,3,bg2.size[1]-2,3) b1.reset = {bg_color="red",printText = function()
  43.         f.centerText(b1,2,"fermer","black","red") end}
  44.     b2 = f.addWin(bg2,2,18,bg2.size[1]-2,3) b2.reset = {bg_color="red",printText = function()
  45.         f.centerText(b2,2,"quitter le module","black","red") end}
  46.  b3 = f.addWin(bg2,bg2.size[1]-1,9,1,1) b3.reset = {bg_color="white",printText = function()
  47.   f.cprint(b3,1,1,"x","lightGray","white") end}
  48. end
  49.  
  50. function reset()
  51.     bg.apply("reset") bg2.apply("reset") list.apply("reset")
  52.     up_bar.apply("reset") down_bar.apply("reset") scroll_bar.apply("reset")
  53.     b1.apply("reset") b2.apply("reset") b3.apply("reset")
  54.     if vn(q) then
  55.         local stq = q.getAllStacks()
  56.         if stq[1] ~= nil then f.cprint(bg2,10,1,"ouvert","green","gray")
  57.         else f.cprint(bg2,10,1,"en veille","yellow","gray") end
  58.     end
  59.     if word ~= nil then f.cprint(bg2,2,9,word,"gray","lightGray") end
  60. end
  61.  
  62. function pulse()
  63.     stq = q.getAllStacks()
  64.     if stq[1] ~= nil then
  65.         shell.run("/lib/soundAPI","mystcraft:linking.link-disarm",volume,"1","false")
  66.         q.pushItem(rside,1)
  67.     end
  68. end
  69.  
  70. function getItems()
  71.     local b = 1
  72.     items = {}
  73.     if chestSize ~= nil then
  74.         for a=1,chestSize do
  75.             list_items[a] = p.getStackInSlot(a)
  76.             if list_items[a] ~= nil and list_items[a].name == "teleporterMKI" then
  77.                 items[b] = {}
  78.                 items[b][1] = a
  79.                 items[b][2] = API.normalize(list_items[a].display_name)
  80.                 if API.check(VIP,items[b][2]) then items[b][3] = "orange"
  81.                 elseif API.check(GUIDES,items[b][2]) then items[b][3] = "lime"
  82.                 else items[b][3] = "gray" end
  83.                 b = b + 1
  84.             end
  85.         end
  86.     end
  87.     table.sort(items, function(a, b) return a[2] < b[2] end)
  88.     if display == nil then display = items end
  89. end
  90.  
  91. function list_display()
  92.   for c=1,#display do
  93.     if c == selected then
  94.       f.drawLine(list,1,c,w,"red")
  95.       f.centerTextRight(list,c,"ouvrir","white")
  96.     else
  97.       list.setBackgroundColor(colors.black)
  98.     end
  99.     f.cprint(list,1,c,display[c][2],display[c][3])
  100.   end
  101. end
  102.  
  103. function scroll(direction)
  104.   local x,y = list.getPosition()
  105.   if direction == "up" and y <=1 then
  106.     list.reposition(1,y+2)
  107.   elseif direction == "down" and y+#items > h-1 then
  108.     list.reposition(1,y-2)
  109.   end
  110. end
  111.  
  112. function search(entry)
  113.     bg2.setCursorPos(2,9)
  114.     word = API.read(bg2,30,"lightGray",entry)
  115.     display = {}
  116.     for i,v in pairs(items) do
  117.         if string.find(v[2],word) ~= nil then
  118.             table.insert(display,v)
  119.         end
  120.     end
  121. end
  122.  
  123. setWindows() reset()
  124. pulse()
  125. shell.run("/lib/soundAPI","mystcraft:linking.link-following",volume,"1","false")
  126. shell.run("/door","open")
  127.  
  128. while true do
  129.     reset()
  130.     getItems()
  131.     list_display()
  132.     down_bar.redraw()
  133.     up_bar.redraw()
  134.     x,y = list.getPosition()
  135.     j,k = scroll_bar.getPosition()
  136.     local e = {os.pullEvent()}
  137.     if e[1] == "monitor_touch" then
  138.         if e[4]-y+1 == selected and display[selected] ~= nil and e[3] < j-1 then
  139.             up_bar.clear()
  140.             f.centerText(up_bar,1,"ouverture...","black")
  141.             pulse()
  142.             sleep(0.5)
  143.             p.pushItem(side,display[selected][1])
  144.             shell.run("/lib/soundAPI","mystcraft:linking.link-fissure",volume,"1","false")
  145.             last_dest = display[selected][2]
  146.             getItems()
  147.         elseif e[4] > 1 and e[3] < j-1 then
  148.             selected = e[4]-y+1
  149.         elseif e[4] == 2 and e[3] == j then
  150.             scroll("up")
  151.         elseif e[4] == h-1 and e[3] == j then
  152.             scroll("down")
  153.         elseif bg2.isClicked(e[3],e[4]) then
  154.             xc = e[3]-bg2.pos[1]+1 yc = e[4]-bg2.pos[2]+1
  155.             if b1.isClicked(xc,yc) then
  156.                 up_bar.clear()
  157.                 f.centerText(up_bar,1,"fermeture...","black")
  158.                 pulse()
  159.                 sleep(0.4)
  160.             elseif f.itrv(xc,2,bg2.size[1]-3) and f.itrv(yc,6,9) then
  161.                 search()
  162.             elseif b2.isClicked(xc,yc) then
  163.                 pulse()
  164.                 shell.run("/door","close")
  165.                 m.clear()
  166.                 break
  167.             elseif b3.isClicked(xc,yc) then
  168.     word = ""
  169.    end
  170.         end
  171.     end
  172.     if e[1] == "char" then search(e[2]) end
  173. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement