Advertisement
Alexr360

Welcome Screen

May 4th, 2025 (edited)
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Utility functions
  2. local function lineBreak()
  3.     local width = term.getSize()
  4.     print(string.rep("-", width))
  5. end
  6.  
  7. local function clearScreen()
  8.     term.clear()
  9.     term.setCursorPos(1, 1)
  10. end
  11.  
  12. -- Menu entries: {Display Name, Program Name}
  13. local menuItems = {
  14.     {"Bastion", "Bastion"},
  15.     {"Automatic Bastion", "RBastion"},
  16.     {"GPS", "GPS"},
  17.     {"Artillery Controller", "ArtilleryControl"},
  18.     {"Teleport Controller", "Teleport"},
  19.     {"Stargate Controller", "psg"},
  20.     {"To-Do List", "todo"},
  21.     {"Update", "Update"},
  22.     {"Exit", nil} -- nil indicates exit
  23. }
  24.  
  25. local function drawMenu()
  26.     clearScreen()
  27.     print("Welcome to Monopoly OS by Monopoly Co.")
  28.     lineBreak()
  29.     print("Current Time: " .. textutils.formatTime(os.time(), true))
  30.     lineBreak()
  31.     print("Select a program to run:")
  32.     for i, item in ipairs(menuItems) do
  33.         print(i .. ". " .. item[1])
  34.     end
  35.     lineBreak()
  36. end
  37.  
  38. local function getClickedItem(y)
  39.     -- Menu starts on line 6
  40.     local index = y - 6
  41.     if index >= 1 and index <= #menuItems then
  42.         return index
  43.     end
  44.     return nil
  45. end
  46.  
  47. -- Main execution
  48. drawMenu()
  49.  
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement