View difference between Paste ID: TXcLTSsV and REfxrLkG
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+
    {"Stargate Controller", "psg"},
19-
print("Current Time: " .. textutils.formatTime(os.time(), true))
19+
    {"To-Do List", "todo"},
20-
lineBreak()
20+
    {"Update", "Update"},
21-
print("Select a program to run:")
21+
    {"Exit", nil} -- nil indicates exit
22-
print("1. Bastion")
22+
}
23-
print("2. Automatic Bastion")
23+
24-
print("3. GPS")
24+
local function drawMenu()
25-
print("4. Artillery Controller")
25+
    clearScreen()
26-
print("5. Teleport Controller")
26+
    print("Welcome to Monopoly OS by Monopoly Co.")
27-
print("6. Stargate Controller")
27+
    lineBreak()
28-
print("7. To-Do List")
28+
    print("Current Time: " .. textutils.formatTime(os.time(), true))
29-
print("8. Update")
29+
    lineBreak()
30-
print("9. Exit")
30+
    print("Select a program to run:")
31-
lineBreak()
31+
    for i, item in ipairs(menuItems) do
32
        print(i .. ". " .. item[1])
33-
local choice = read()
33+
34
    lineBreak()
35-
if choice == "1" then
35+
36-
  shell.run("Bastion")
36+
37-
elseif choice == "2" then
37+
local function getClickedItem(y)
38-
  shell.run("RBastion")
38+
    -- Menu starts on line 6
39-
elseif choice == "3" then
39+
    local index = y - 6
40-
  shell.run("GPS")
40+
    if index >= 1 and index <= #menuItems then
41-
elseif choice == "4" then
41+
        return index
42-
  shell.run("ArtilleryControl")
42+
43-
elseif choice == "5" then
43+
    return nil
44-
  shell.run("Teleport")
44+
45-
elseif choice == "6" then
45+
46-
  shell.run("psg")
46+
-- Main execution
47-
elseif choice == "7" then
47+
drawMenu()
48-
  shell.run("todo")
48+
49-
elseif choice == "8" then
49+
while true do
50-
  shell.run("Update")
50+
    local event, button, x, y = os.pullEvent()
51
52
    if event == "mouse_click" then
53
        local choice = getClickedItem(y)
54
        if choice then
55
            local entry = menuItems[choice]
56
            if entry[2] == nil then
57
                break -- Exit
58
            else
59
                shell.run(entry[2])
60
                drawMenu()
61
            end
62
        end
63
    elseif event == "char" then
64
        local num = tonumber(button)
65
        if num and menuItems[num] then
66
            local entry = menuItems[num]
67
            if entry[2] == nil then
68
                break
69
            else
70
                shell.run(entry[2])
71
                drawMenu()
72
            end
73
        end
74
    end
75
end