Marlingaming

CCTweaked CCSPS 2.0.0 - App Writer

Feb 21st, 2022 (edited)
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | None | 0 0
  1. local OpenedPath = "n"
  2. local StoredFiles = {}
  3. local StartFile = "n"
  4. local ProgramImage = "n"
  5. local Line = 1
  6. local Lines = {}
  7. local tArg = {...}
  8. local options = {}
  9.  
  10. local FilePath = ""
  11. local w, h = term.getSize()
  12.  
  13. local function Clear()
  14. term.clear()
  15. term.setCursorPos(1,1)
  16. end
  17.  
  18. function OpenFile()
  19. Lines = {}
  20.  
  21. Line = 1
  22.  
  23. local file = fs.open(FilePath,"r")
  24. repeat
  25. local Contents = file.readLine()
  26. if Contents ~= nil then Lines[#Lines + 1] = Contents end
  27. until Contents == nil
  28. file.close()
  29.  
  30. Lines[#Lines + 1] = "=NewLine="
  31.  
  32. Lines[#Lines + 1] = "=exit="
  33. end
  34.  
  35. function SaveFile()
  36. local file = fs.open(FilePath,"w")
  37. for i = 1, #Lines do
  38. file.writeLine(Lines[i])
  39. end
  40. file.close()
  41. Lines = {}
  42. Line = 1
  43. end
  44.  
  45. function FindFile(name)
  46. FilePath = fs.combine(OpenedPath,name)
  47. end
  48.  
  49. function CUI(m,y) --declare function
  50. n=1
  51. local l = #m
  52. while true do
  53. term.setCursorPos(1,y)
  54. for i=1, #m, 1 do --traverse the table of options
  55. if i==n then term.clearLine() print(i, " >",m[i]) else term.clearLine() print(i, " ", m[i]) end --print them
  56. end
  57. a, b= os.pullEvent("key") --wait for keypress
  58. if b==keys.w and n>1 then n=n-1 end
  59. if b==keys.s and n<l then n=n+1 end
  60. if b==keys.enter then break end
  61. end
  62. return n --return the value
  63. end
  64.  
  65. function TextMenu_Base()
  66. Clear()
  67. options = Lines
  68. local n = CUI(options,1)
  69. if options[n] == "=exit=" then
  70. Lines[#Lines] = nil
  71. Lines[#Lines] = nil
  72. SaveFile()
  73. if tArg[1] == "direct" then
  74.  
  75. else
  76. FileMenu()
  77. end
  78. elseif options[n] == "=NewLine=" then
  79. Lines[n] = "empty"
  80. Lines[#Lines] = "=NewLine="
  81. Lines[#Lines + 1] = "=exit="
  82. TextMenu_Base()
  83. else
  84. Line = n
  85. TextMenu_Line()
  86. end
  87. end
  88.  
  89. function TextMenu_Line()
  90. Clear()
  91. print("line ",Line," :",Lines[Line])
  92. term.setCursorPos(1,3)
  93. local input = Lines[Line]
  94. while true do
  95. local event = {os.pullEvent("key")}
  96. if event[2] == keys.enter then break end
  97. input = read()
  98. end
  99. Lines[Line] = input
  100. TextMenu_Base()
  101. end
  102.  
  103. function FileMenu()
  104. Clear()
  105. options = nil
  106. if OpenedPath == "n" then
  107. options = AllowedPaths
  108. else
  109. options = fs.list(OpenedPath)
  110. options[#fs.list(OpenedPath) + 1] = "return"
  111. end
  112. local n = CUI(options,2)
  113. if options[n] == "exit" then
  114.  
  115. elseif options[n] == "return" then
  116. OpenedPath = "n"
  117. FileMenu()
  118. elseif OpenedPath == "n" then
  119. OpenedPath = options[n]
  120. FileMenu()
  121. else
  122. FindFile(options[n])
  123. OpenFile()
  124. TextMenu_Base()
  125. end
  126. end
  127.  
  128. function ProjectDisplay()
  129. print("[return]")
  130. print("//Options//")
  131. print("<StartFile>",StartFile)
  132. print("<Image>",ProgramImage)
  133. end
  134.  
  135. function Menu()
  136. term.setBackgroundColor(colors.black)
  137. Clear()
  138. print("////Developer////")
  139. print("[Proj][Tools][File][Help]")
  140. print("|Files|")
  141. if StartFile ~= "n" then
  142. term.setCursorPos(9,3)
  143. term.write("[run]")
  144. end
  145. term.setCursorPos(1,4)
  146. for i = 1, #StoredFiles do
  147. print(string.sub(StoredFiles[i],1,7))
  148. end
  149. local n = 0
  150. while true do
  151. local a, b, c, d = os.pullEvent("mouse_click")
  152. if d == 2 then
  153. if c < 7 then n = 1 end
  154. if c < 15 then n = 2 end
  155. if c < 22 then n = 3 end
  156. if c < 26 then n = 4 end
  157. else
  158. if d == 3 and c > 8 and c < 14 and StartFile ~= "n" then n = 5 end
  159. if d > 3 and c < 8 then n = (d - 3) + 10 end
  160. end
  161. if n > 0 then break end
  162. end
  163. if n == 1 then
  164.  
  165. elseif n == 2 then
  166.  
  167. elseif n == 3 then
  168.  
  169. elseif n == 4 then
  170.  
  171. elseif n == 5 then
  172. shell.run(StartFile)
  173. paintutils.DrawBox(1,1,w,h,colors.blue)
  174. term.setTextColor(white)
  175. term.setCursorPos((w/2) - 2, h /2)
  176. term.write("done")
  177. os.sleep(3)
  178. Menu()
  179. elseif n == 6 then
  180.  
  181. elseif n == 7 then
  182.  
  183. else
  184.  
  185. end
  186. end
  187.  
  188. Menu()
Add Comment
Please, Sign In to add comment