SHOW:
|
|
- or go back to the newest paste.
1 | os.loadAPI("f") -- a monitor API made by myself, it makes my life easier | |
2 | os.loadAPI("getInput") -- search_bar | |
3 | local p = peripheral.find("draconic_chest") -- can change for "chest" instead of "draconic_chest" | |
4 | local m = peripheral.find("monitor") -- running on a monitor | |
5 | m.setTextScale(1) | |
6 | local list_items,items = {},{} | |
7 | local a,b,c = 1,1,1 | |
8 | local selected = 0 | |
9 | local side = "west" -- 2nd chest direction from 1st chest | |
10 | local chestSize = p.getInventorySize() | |
11 | local w,h = m.getSize() | |
12 | ||
13 | local bg = window.create(m,1,1,w,h) | |
14 | local list = window.create(m,1,2,w*3/5-1,chestSize) | |
15 | local up_bar = window.create(m,1,1,w,1) | |
16 | local down_bar = window.create(m,1,h,w,h) | |
17 | local scroll_bar = window.create(m,w*(3/5),2,1,h-1) | |
18 | local bg2 = window.create(m,w*(3/5)+1,2,w,h-1) | |
19 | ||
20 | function reset() | |
21 | bg.setBackgroundColor(colors.black) | |
22 | bg.clear() | |
23 | list.setBackgroundColor(colors.black) | |
24 | list.clear() | |
25 | up_bar.setBackgroundColor(colors.lightGray) | |
26 | up_bar.clear() | |
27 | down_bar.setBackgroundColor(colors.lightGray) | |
28 | down_bar.clear() | |
29 | scroll_bar.setBackgroundColor(colors.lightGray) | |
30 | scroll_bar.clear() | |
31 | bg2.setBackgroundColor(colors.gray) | |
32 | bg2.clear() | |
33 | f.centerText(up_bar,1,"selectionner une destination","black") | |
34 | f.cprint(down_bar,1,1,"dernier tp : ","black") | |
35 | f.cprint(down_bar,13,1,last_dest,"blue","lightGray") | |
36 | f.cprint(scroll_bar,1,1,"^","black","gray") | |
37 | f.cprint(scroll_bar,1,h-2,"v","black","gray") | |
38 | - | l,m = bg2.getSize() |
38 | + | l,q = bg2.getSize() |
39 | - | print(l," ",m) |
39 | + | print(l," ",q) |
40 | - | xb1,yb1,x2b1,y2b1 = f.drawBox(bg2,2,m/2-1,l-2,m/2+1,"lightGray") |
40 | + | xb1,yb1,x2b1,y2b1 = f.drawBox(bg2,2,q/2-1,l-2,q/2+1,"lightGray") |
41 | end | |
42 | ||
43 | function pulse() | |
44 | redstone.setAnalogOutput("right",15) | |
45 | sleep(0.5) | |
46 | redstone.setAnalogOutput("right",0) | |
47 | local last_dest = "none" | |
48 | end | |
49 | ||
50 | function getItems() | |
51 | b = 1 | |
52 | items = {} | |
53 | if chestSize ~= nil then | |
54 | for a=1,chestSize do | |
55 | list_items[a] = p.getStackInSlot(a) | |
56 | if list_items[a] ~= nil and list_items[a].name == "teleporterMKI" then | |
57 | items[b] = {} | |
58 | items[b][1] = a | |
59 | items[b][2] = list_items[a].display_name | |
60 | b = b + 1 | |
61 | end | |
62 | end | |
63 | end | |
64 | table.sort(items, function(a, b) return a[2] < b[2] end) | |
65 | table.insert(items,1,{1,">>> retour au Spawn <<<","spawn"}) | |
66 | if display == nil then display = items end | |
67 | end | |
68 | ||
69 | function list_display() | |
70 | for c=1,#display do | |
71 | if c == selected then | |
72 | f.drawLine(list,1,c,w,"gray") | |
73 | f.centerTextRight(list,c,"ouvrir","white") | |
74 | else | |
75 | list.setBackgroundColor(colors.black) | |
76 | end | |
77 | if display[c][3] == nil then | |
78 | f.cprint(list,1,c,display[c][2],"blue") | |
79 | elseif display[c][3] == "spawn" then | |
80 | f.centerText(list,c,display[c][2],"cyan") | |
81 | end | |
82 | end | |
83 | end | |
84 | ||
85 | function scroll(direction) | |
86 | local x,y = list.getPosition() | |
87 | if direction == "up" and y <=1 then | |
88 | list.reposition(1,y+2) | |
89 | elseif direction == "down" and y+#items > h-1 then | |
90 | list.reposition(1,y-2) | |
91 | end | |
92 | end | |
93 | ||
94 | function search() | |
95 | bg2.setCursorPos(1,1) | |
96 | word = getInput.read(bg2,30) | |
97 | display = {} | |
98 | for i,v in pairs(items) do | |
99 | if string.find(v[2],word) ~= nil then | |
100 | table.insert(display,v) | |
101 | end | |
102 | end | |
103 | end | |
104 | ||
105 | pulse() | |
106 | ||
107 | while true do | |
108 | reset() | |
109 | getItems() | |
110 | list_display() | |
111 | down_bar.redraw() | |
112 | up_bar.redraw() | |
113 | x,y = list.getPosition() | |
114 | j,k = scroll_bar.getPosition() | |
115 | event,p1,p2,p3,p4,p5 = os.pullEvent() | |
116 | if event == "monitor_touch" then | |
117 | if p3-y+1 == selected and display[selected] ~= nil and p2 < j-1 then | |
118 | up_bar.clear() | |
119 | f.centerText(up_bar,1,"ouverture...","black") | |
120 | pulse() | |
121 | p.pushItem(side,display[selected][1]) | |
122 | last_dest = display[selected][2] | |
123 | getItems() | |
124 | close = os.startTimer(3) | |
125 | elseif p3 > 1 and p2 < j-1 then | |
126 | selected = p3-y+1 | |
127 | elseif p3 == 2 and p2 == j then | |
128 | scroll("up") | |
129 | elseif p3 == h-1 and p2 == j then | |
130 | scroll("down") | |
131 | else | |
132 | search() | |
133 | end | |
134 | end | |
135 | if event == "timer" and p1 == close then | |
136 | pulse() | |
137 | end | |
138 | end |