SHOW:
|
|
- or go back to the newest paste.
1 | - | -- Print a line of dashes for aesthetics |
1 | + | -- Utility functions |
2 | local function lineBreak() | |
3 | - | local width, height = term.getSize() |
3 | + | local width = term.getSize() |
4 | - | for i = 1, width do |
4 | + | print(string.rep("-", width)) |
5 | - | io.write("-") |
5 | + | |
6 | ||
7 | - | io.write("\n") |
7 | + | |
8 | term.clear() | |
9 | - | -- Function to clear the screen |
9 | + | |
10 | end | |
11 | ||
12 | -- Menu entries: {Display Name, Program Name} | |
13 | local menuItems = { | |
14 | {"Bastion", "Bastion"}, | |
15 | - | clearScreen() |
15 | + | {"Automatic Bastion", "RBastion"}, |
16 | - | -- Print the welcome message |
16 | + | {"GPS", "GPS"}, |
17 | - | print("Welcome to Monopoly OS by Monopoly Co.") |
17 | + | {"Artillery Controller", "ArtilleryControl"}, |
18 | - | lineBreak() |
18 | + | {"Teleport Controller", "Teleport"}, |
19 | - | print("Current Time: " .. textutils.formatTime(os.time(), true)) |
19 | + | {"Stargate Controller", "psg"}, |
20 | - | lineBreak() |
20 | + | {"To-Do List", "todo"}, |
21 | - | print("Select a program to run:") |
21 | + | {"Update", "Update"}, |
22 | - | print("1. Bastion") |
22 | + | {"Exit", nil} -- nil indicates exit |
23 | - | print("2. Automatic Bastion") |
23 | + | } |
24 | - | print("3. GPS") |
24 | + | |
25 | - | print("4. Artillery Controller") |
25 | + | local function drawMenu() |
26 | - | print("5. Teleport Controller") |
26 | + | clearScreen() |
27 | - | print("6. Stargate Controller") |
27 | + | print("Welcome to Monopoly OS by Monopoly Co.") |
28 | - | print("7. To-Do List") |
28 | + | lineBreak() |
29 | - | print("8. Update") |
29 | + | print("Current Time: " .. textutils.formatTime(os.time(), true)) |
30 | - | print("9. Exit") |
30 | + | lineBreak() |
31 | - | lineBreak() |
31 | + | print("Select a program to run:") |
32 | for i, item in ipairs(menuItems) do | |
33 | - | local choice = read() |
33 | + | print(i .. ". " .. item[1]) |
34 | end | |
35 | - | if choice == "1" then |
35 | + | lineBreak() |
36 | - | shell.run("Bastion") |
36 | + | |
37 | - | elseif choice == "2" then |
37 | + | |
38 | - | shell.run("RBastion") |
38 | + | local function getClickedItem(y) |
39 | - | elseif choice == "3" then |
39 | + | -- Menu starts on line 6 |
40 | - | shell.run("GPS") |
40 | + | local index = y - 6 |
41 | - | elseif choice == "4" then |
41 | + | if index >= 1 and index <= #menuItems then |
42 | - | shell.run("ArtilleryControl") |
42 | + | return index |
43 | - | elseif choice == "5" then |
43 | + | |
44 | - | shell.run("Teleport") |
44 | + | return nil |
45 | - | elseif choice == "6" then |
45 | + | |
46 | - | shell.run("psg") |
46 | + | |
47 | - | elseif choice == "7" then |
47 | + | -- Main execution |
48 | - | shell.run("todo") |
48 | + | drawMenu() |
49 | - | elseif choice == "8" then |
49 | + | |
50 | - | shell.run("Update") |
50 | + | while true do |
51 | local event, button, x, y = os.pullEvent() | |
52 | ||
53 | if event == "mouse_click" then | |
54 | local choice = getClickedItem(y) | |
55 | if choice then | |
56 | local entry = menuItems[choice] | |
57 | if entry[2] == nil then | |
58 | break -- Exit | |
59 | else | |
60 | shell.run(entry[2]) | |
61 | drawMenu() | |
62 | end | |
63 | end | |
64 | elseif event == "char" then | |
65 | local num = tonumber(button) | |
66 | if num and menuItems[num] then | |
67 | local entry = menuItems[num] | |
68 | if entry[2] == nil then | |
69 | break | |
70 | else | |
71 | shell.run(entry[2]) | |
72 | drawMenu() | |
73 | end | |
74 | end | |
75 | end | |
76 | end |