Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Utility functions
- local function lineBreak()
- local width = term.getSize()
- print(string.rep("-", width))
- end
- local function clearScreen()
- term.clear()
- term.setCursorPos(1, 1)
- end
- -- Menu entries: {Display Name, Program Name}
- local menuItems = {
- {"Bastion", "Bastion"},
- {"Automatic Bastion", "RBastion"},
- {"GPS", "GPS"},
- {"Artillery Controller", "ArtilleryControl"},
- {"Teleport Controller", "Teleport"},
- {"Stargate Controller", "psg"},
- {"To-Do List", "todo"},
- {"Update", "Update"},
- {"Exit", nil} -- nil indicates exit
- }
- local function drawMenu()
- clearScreen()
- print("Welcome to Monopoly OS by Monopoly Co.")
- lineBreak()
- print("Current Time: " .. textutils.formatTime(os.time(), true))
- lineBreak()
- print("Select a program to run:")
- for i, item in ipairs(menuItems) do
- print(i .. ". " .. item[1])
- end
- lineBreak()
- end
- local function getClickedItem(y)
- -- Menu starts on line 6
- local index = y - 6
- if index >= 1 and index <= #menuItems then
- return index
- end
- return nil
- end
- -- Main execution
- drawMenu()
- while true do
- local event, button, x, y = os.pullEvent()
- if event == "mouse_click" then
- local choice = getClickedItem(y)
- if choice then
- local entry = menuItems[choice]
- if entry[2] == nil then
- break -- Exit
- else
- shell.run(entry[2])
- drawMenu()
- end
- end
- elseif event == "char" then
- local num = tonumber(button)
- if num and menuItems[num] then
- local entry = menuItems[num]
- if entry[2] == nil then
- break
- else
- shell.run(entry[2])
- drawMenu()
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement