SHOW:
|
|
- or go back to the newest paste.
1 | - | -- KekApi (1.2) |
1 | + | -- KekApi (1.2.1) |
2 | ||
3 | ||
4 | function centerText (text) | |
5 | local w, h = term.getSize() | |
6 | term.setCursorPos(math.floor(w / 2 - text:len() / 2 + .5), math.floor(h / 2 + .5)) | |
7 | write(text) | |
8 | end | |
9 | ||
10 | function centerPrint (text) | |
11 | local textLen = string.len(text) | |
12 | local screenW,_ = term.getSize() | |
13 | local xCoords = tonumber(math.ceil((screenW / 2) - (textLen / 2))) | |
14 | local _,termY = term.getCursorPos() | |
15 | term.setCursorPos(xCoords,termY) | |
16 | print(text) | |
17 | return xCoords | |
18 | end | |
19 | ||
20 | function writeLine () | |
21 | term.write("--------------------------------------------------") | |
22 | end | |
23 | ||
24 | function slowCenterPrint (text, time) | |
25 | local textLen = string.len(text) | |
26 | local screenW,_ = term.getSize() | |
27 | local xCoords = tonumber(math.ceil((screenW / 2) - (textLen / 2))) -- Da Ba Dee xD | |
28 | local _,termY = term.getCursorPos() | |
29 | term.setCursorPos(xCoords,termY) | |
30 | textutils.slowWrite(text, time) | |
31 | return xCoords | |
32 | end | |
33 | ||
34 | - | function drawMenu (tab1, x, y) |
34 | + | function drawMenu(tab, t,d) |
35 | - | if y == nil or x == nil then |
35 | + | wybor = 1 |
36 | - | printError("podaj x i y dla menu!") |
36 | + | back = term.getBackgroundColor() |
37 | - | end |
37 | + | w,h = term.getSize() |
38 | - | a = 0 |
38 | + | scr = 0 |
39 | - | colorOld = term.getBackgroundColor() |
39 | + | |
40 | - | wbr = 1 |
40 | + | c,v = term.getSize() |
41 | if #tab > 10 then | |
42 | - | w,h = term.getSize() |
42 | + | tabL = 10 |
43 | - | if #tab1 < 10 then |
43 | + | else |
44 | - | for i = 1, #tab1 do |
44 | + | tabL = #tab |
45 | - | term.setCursorPos(x,y + i - 1) |
45 | + | |
46 | - | if i == wbr then |
46 | + | a = 0 |
47 | - | term.setBackgroundColor(colors.gray) |
47 | + | for i=1,tabL do |
48 | - | else |
48 | + | a = a + 1 |
49 | - | term.setBackgroundColor(colorOld) |
49 | + | if t == nil and d == nil then |
50 | - | end |
50 | + | term.setCursorPos(1, a + math.floor(h / 2 - .5) - #tab / 2 + .5) |
51 | - | term.write(tab1[i]) |
51 | + | else |
52 | term.setCursorPos(t, d + a - 1) | |
53 | - | elseif #tab1 > 10 or #tab1 == 10 then |
53 | + | |
54 | - | for i = 1, 10 do |
54 | + | term.clearLine() |
55 | - | if i == wbr then |
55 | + | if a+scr == wybor then |
56 | - | term.setBackgroundColor(colors.gray) |
56 | + | term.setBackgroundColor(colors.lightGray) |
57 | - | else |
57 | + | else |
58 | - | term.setBackgroundColor(colorOld) |
58 | + | term.setBackgroundColor(back) |
59 | - | end |
59 | + | |
60 | - | if wbr == 9 or wbr > 9 then |
60 | + | if t == nil and d == nil then |
61 | - | i = wbr |
61 | + | centerPrint(" ".. tab[i+scr].. " ") |
62 | - | i = i - 1 |
62 | + | else write(" ".. tostring(tab[i+scr]).. " ") end |
63 | - | end |
63 | + | term.setBackgroundColor(back) |
64 | - | term.setCursorPos(x,y + i - 1) |
64 | + | |
65 | - | term.clearLine() |
65 | + | |
66 | - | term.write(tab1[i]) |
66 | + | if key == keys.up and wybor>1 then |
67 | - | end |
67 | + | if wybor > 10 then |
68 | scr = scr - 1 | |
69 | end | |
70 | - | if key == keys.down and wbr < #tab1 then |
70 | + | wybor = wybor - 1 |
71 | - | wbr = wbr + 1 |
71 | + | elseif key == keys.down and wybor<#tab then |
72 | wybor = wybor + 1 | |
73 | - | if key == keys.up and wbr > 1 then |
73 | + | if wybor > 10 then |
74 | - | wbr = wbr - 1 |
74 | + | scr = scr + 1 |
75 | end | |
76 | - | if key == keys.enter then |
76 | + | elseif key == keys.enter then |
77 | - | break |
77 | + | term.clear() |
78 | return wybor | |
79 | - | end |
79 | + | |
80 | - | term.setBackgroundColor(colorOld) |
80 | + | end |
81 | - | return wbr |
81 | + |