Marlingaming

CC Tweaked Main Program Menu (button Version)

Jan 5th, 2022 (edited)
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.63 KB | None | 0 0
  1. --this acts as main script CSP
  2. local w, h = term.getSize()
  3. local IntPrograms = {"os/os_Programs/os_AccountPgScript", "os/os_Programs/os_BankingApp","os/os_Programs/os_SettingsMenu", "os.reboot"}
  4. local ProgramNames = {"AccountPage","Banking","Settings","Reboot"}
  5. local Menu_Buttons = {}
  6.  
  7. local function Clear()
  8. term.clear()
  9. term.setCursorPos(1,1)
  10. end
  11.  
  12. local function CenterText(y,text)
  13.     local x = math.floor((w - string.len(text)) /2)
  14.     term.setCursorPos(x,y)
  15.     term.clearLine()
  16.     term.write(text)
  17. end
  18.  
  19.  
  20. local function MenuDrawer()
  21. Clear()
  22. term.setBackgroundColor(colors.cyan)
  23. paintutils.drawFilledBox(1,1,w,3,colors.gray)
  24. paintutils.drawFilledBox(1,1,3,3,colors.white)
  25. CenterText(1,"===Main=Menu===")
  26. CenterText(3,"Applications")
  27. term.setBackgroundColor(colors.cyan)
  28. CreateButton(3,3,"System","reboot")
  29. end
  30.  
  31. local function ManagePanels(Panel)
  32. print(Panel)
  33. end
  34.  
  35. local function CreateButton(x,y,Cat,Action)
  36. Menu_Buttons[#Menu_Buttons+1] = {x,y,Cat,Action}
  37. paintutils(x-2,y-2,x+2,y+2,colors.red)
  38. end
  39.  
  40. local function CheckButton(i)
  41. if Menu_Buttons[i][3] == "Script" then shell.run(Menu_Buttons[i][4]) end
  42. if Menu_Buttons[i][3] == "System" and Menu_Buttons[i,4] == "reboot" then os.reboot() end
  43. if Menu_Buttons[i][3] == "Panel" then ManagePanels(Menu_Buttons[i,4]) end
  44. end
  45.  
  46. function UserInteraction()
  47. local event
  48. while true do
  49.     event = {os.pullEvent("mouse_click")}
  50.     for i = 1, #Menu_Buttons do
  51.         if event[3] >= Menu_Buttons[i,1]-2 and event[3] <= Menu_Buttons[i,1]+2 and event[4] >= MenuButtons[i,2]-2 and event[4] <= Menu_Buttons[i,2]+2 then CheckButton(i) end
  52.     end
  53. end
  54. end
  55.  
  56. Clear()
  57. MenuDrawer()
  58. UserInteraction()
Add Comment
Please, Sign In to add comment