View difference between Paste ID: TqV0Mi9L and bvBCaWg4
SHOW: | | - or go back to the newest paste.
1-
os.loadAPI("f") -- a monitor API made by myself, it makes my life easier
1+
local version = "1.13" --(01/09 2020)
2-
os.loadAPI("getInput") -- search_bar
2+
os.loadAPI("/lib/f") -- a monitor API made by myself, it makes my life easier
3
os.loadAPI("/lib/getInput") -- search bar read() function
4
os.loadAPI("/portal/API") -- custom API to help run the program
5
local p = peripheral.find("draconic_chest") -- can change for "chest" instead of "draconic_chest"
6
local m = peripheral.find("monitor") -- running on a monitor
7-
local side,rside = "north","top" -- IMPORTANT
7+
8
m.setTextScale(1)
9
local side,rside = "east","left" -- IMPORTANT
10-
local selected,last_dest = 0,"none"
10+
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 img = paintutils.loadImage("/Charm")
23+
24-
--local switch1 = window.create(bg2,
24+
25-
print("[",os.time(),"] ",os.day())
25+
26
local VIP = {"TheBaslez","SesameChocolat","Jaguar","LeChikito","jungleis26","Ertupop","Veine","annelaure1912","Gaetann18",
27
"GohuSan","boucherreb","Ciliste"}
28-
  bg.setBackgroundColor(colors.black)
28+
local GUIDES = {"zorinova","DaikiKaminari","maxou684"}
29-
  bg.clear()
29+
30-
  list.setBackgroundColor(colors.black)
30+
31-
  list.clear()
31+
  bg.setBackgroundColor(colors.black) bg.clear()
32-
  up_bar.setBackgroundColor(colors.lightGray)
32+
  list.setBackgroundColor(colors.black) list.clear()
33-
  up_bar.clear()
33+
  up_bar.setBackgroundColor(colors.lightGray) up_bar.clear()
34-
  down_bar.setBackgroundColor(colors.lightGray)
34+
  down_bar.setBackgroundColor(colors.lightGray) down_bar.clear()
35-
  down_bar.clear()
35+
  scroll_bar.setBackgroundColor(colors.lightGray) scroll_bar.clear()
36-
  scroll_bar.setBackgroundColor(colors.lightGray)
36+
  bg2.setBackgroundColor(colors.gray) bg2.clear()
37-
  scroll_bar.clear()
37+
  button1.setBackgroundColor(colors.red) button1.clear()
38-
  bg2.setBackgroundColor(colors.gray)
38+
  f.centerText(up_bar,1,"selectionner une destination","black","lightGray")
39-
  bg2.clear()
39+
40-
  button1.setBackgroundColor(colors.red)
40+
  f.centerTextRight(down_bar,1,"v"..version,"black","lightGray")
41-
  button1.clear()
41+
42-
  f.centerText(up_bar,1,"selectionner une destination","black")
42+
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-
  f.centerText(button1,2,"fermer","black")
49+
50
    if stq[1] ~= nil then f.cprint(bg2,10,1,"ouvert","green","gray")
51
    else f.cprint(bg2,10,1,"en veille","yellow","gray") end
52
  end
53
  if word ~= nil then f.cprint(bg2,2,9,word,"gray","lightGray") end
54
  f.cprint(bg2,2,11,"Double-cliquer sur","white","gray")
55
  f.cprint(bg2,2,12," un nom pour se","white","gray")
56-
  term.redirect(bg2)
56+
  f.cprint(bg2,2,13," teleporter.","white","gray")
57-
  paintutils.drawImage(img,sbg2[1]/2-3,11)
57+
  f.cprint(bg2,2,14,"Taper dans le","white","gray")
58
  f.cprint(bg2,2,15," computer une ","white","gray")
59
  f.cprint(bg2,2,16," recherche.","white","gray")
60
end
61-
  redstone.setAnalogOutput(rside,15)
61+
62-
  sleep(0.3)
62+
63-
  redstone.setAnalogOutput(rside,0)
63+
  rs.setAnalogOutput(rside,15)
64
  sleep(0.5)
65
  rs.setAnalogOutput(rside,0)
66
end
67
68
function getItems()
69
  b = 1
70
  items = {}
71
  if chestSize ~= nil then
72
    for a=1,chestSize do
73
      list_items[a] = p.getStackInSlot(a)
74
      if list_items[a] ~= nil and list_items[a].name == "teleporterMKI" then
75-
        items[b][2] = list_items[a].display_name
75+
76
        items[b][1] = a
77
        items[b][2] = API.normalize(list_items[a].display_name)
78
        if API.check(VIP,items[b][2]) == true then items[b][3] = "VIP" end
79
        if API.check(GUIDES,items[b][2]) == true then items[b][3] = "guide" end
80
        b = b + 1
81
      end
82
    end
83
  end
84
  table.sort(items, function(a, b) return a[2] < b[2] end)
85
  table.insert(items,1,{1,">>> retour au Spawn <<<","spawn"})
86
  if display == nil then display = items end
87
end
88-
      f.drawLine(list,1,c,w,"gray")
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-
      f.cprint(list,1,c,display[c][2],"blue")
94+
95
      list.setBackgroundColor(colors.black)
96-
      f.centerText(list,c,display[c][2],"cyan")
96+
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-
function search()
110+
111
  if direction == "up" and y <=1 then
112-
  word = getInput.read(bg2,30)
112+
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 = getInput.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-
      close = os.startTimer(3)
141+
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-
      xc = event[3]-pbg2[1] yc = event[4]-pbg2[2]
149+
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 event[1] == "timer" and event[2] == close then
157+
158-
    pulse()
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