Alexr360

Welcome Screen V2

May 2nd, 2025 (edited)
470
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.     {"Stargate Controller", "psg"},
  19.     {"To-Do List", "todo"},
  20.     {"Update", "Update"},
  21.     {"Exit", nil} -- nil indicates exit
  22. }
  23.  
  24. local function drawMenu()
  25.     clearScreen()
  26.     print("Welcome to Monopoly OS by Monopoly Co.")
  27.     lineBreak()
  28.     print("Current Time: " .. textutils.formatTime(os.time(), true))
  29.     lineBreak()
  30.     print("Select a program to run:")
  31.     for i, item in ipairs(menuItems) do
  32.         print(i .. ". " .. item[1])
  33.     end
  34.     lineBreak()
  35. end
  36.  
  37. local function getClickedItem(y)
  38.     -- Menu starts on line 6
  39.     local index = y - 6
  40.     if index >= 1 and index <= #menuItems then
  41.         return index
  42.     end
  43.     return nil
  44. end
  45.  
  46. -- Main execution
  47. drawMenu()
  48.  
  49. while true do
  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
Advertisement
Add Comment
Please, Sign In to add comment