Marlingaming

CC Tweaked CCSPS 20 - Tab Manager

Feb 18th, 2022 (edited)
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. local tArg = {...}
  2. local w, h = term.getSize()
  3. local Title
  4. local Background = colors.white
  5. local Pages = {}
  6. local SelectedPage = 1
  7.  
  8. function LoadPage()
  9. paintutils.drawFilledBox(1,2,w, h -1, colors.white)
  10. term.setTextColor(colors.black)
  11. term.setCursorPos(1,1)
  12. term.setBackgroundColor(colors.lightGray)
  13. term.write(Title)
  14. term.setBackgroundColor(Background)
  15. for i = 1, #Pages[SelectedPage] do
  16. if Pages[SelectedPage][i][2] == "text" then
  17. term.setCursorPos(1,i + 1)
  18. term.clearLine()
  19. term.write(Pages[SelectedPage][i][1])
  20. elseif Pages[SelectedPage][i][2] == "button" then
  21. term.setCursorPos(1,i + 1)
  22. term.clearLine()
  23. paintutils.drawBox(1,i + 1, string.len(Pages[SelectedPage][i][1]), i + 1, colors.lightBlue)
  24. term.setBackgroundColor(Background)
  25. term.write(Pages[SelectedPage][i][1])
  26. end
  27. end
  28. Interaction()
  29. end
  30.  
  31. function Interaction()
  32. local n = 0
  33. while true do
  34. local a, b, c, d = os.pullEvent("mouse_click")
  35. if d > 1 and d < h then
  36. for i = 1, #Pages[SelectedPage] do
  37. if d == i and Pages[SelectedPage][i][2] == "button" then n = i end
  38. end
  39. else
  40. n = 100
  41. end
  42. if n > 0 then break end
  43. end
  44. if n == 100 then
  45.  
  46. else
  47. if string.find(Pages[SelectedPage][n][3],"page_") then
  48. SelectedPage = string.sub(Pages[SelectedPage][n][3], string.find(Pages[SelectedPage][n][3],"page_") + 1,string.len(Pages[SelectedPage][n][3]))
  49. LoadPage()
  50. else
  51. shell.run(Pages[SelectedPage][n][3])
  52. LoadPage()
  53. end
  54. end
  55. end
  56.  
  57. local i = 1
  58. local File = fs.open(tArg[1],"r")
  59. local content = "n"
  60. repeat
  61. content = File.readLine()
  62. print(content)
  63. if string.find(content,"<") then
  64. if string.find(content,"<newPage>") then Pages[#Pages + 1] = {} i = 1 end
  65. if string.find(content,"<title:") then Title = string.sub(content,8,(string.len(content) - 1)) end
  66. if string.find(content,"<text:") then Pages[#Pages][i] = {string.sub(content,7,(string.len(content) - 1)),"text"} i = i + 1 end
  67. if string.find(content,"<button:") then Pages[#Pages][i] = {string.sub(content,9,string.len("<button:")),"button",string.sub(content,string.len(content) - string.sub(content,9,string.len("<button:")), -1)} i = i + 1 end
  68. end
  69. until content == "<end>"
  70. File.close()
  71. LoadPage()
  72.  
Add Comment
Please, Sign In to add comment