Advertisement
ravneravn

organiser + screensaver

May 23rd, 2013
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.91 KB | None | 0 0
  1.  
  2.  
  3. side = "top"
  4. pSide = "top"
  5. mon = peripheral.wrap(side)
  6. w, h = mon.getSize()
  7. project = {}
  8. mainMenu = {"Rules", "View projects"}
  9. yourProjects = {}
  10. names = {}
  11. nameList = {}
  12. screen = 0
  13. deleteYes = false
  14. deleteNo = false
  15. goBack = false
  16. backToMainMenu = false
  17. selectedName = false
  18. player = peripheral.wrap(pSide)
  19. screen = 0
  20. sec = 0
  21. rules = {[1] = "- No griefing -", [2] = "- No stealing -", [3] = "- No cheating in any way -", [4] = "- PvP only on agreement -", [5] = "- Be friendly and respectful -", [6] = "- Have fun -", [7] = "- Don't break the rules -"}
  22. for i = 1, 100 do
  23. names[i] = {}
  24. end
  25.  
  26.  
  27.  
  28. function checkFile(path) -- check if file exists
  29. if not fs.exists(path) then
  30. file = fs.open(path, "w")
  31. file.close()
  32. end
  33. end
  34.  
  35.  
  36. function writeFile(fileName, tableName) -- overwrites an old file
  37. file = fs.open(fileName, "w")
  38. file.write(textutils.serialize(tableName))
  39. file.close()
  40. end
  41.  
  42.  
  43. function loadProjects(load) -- Load filed called projects
  44. checkFile(load)
  45. file = fs.open(load, "r")
  46. readFile = file.readLine()
  47. if readFile ~= nil then
  48. project = textutils.unserialize(readFile)
  49. end
  50. file.close()
  51. end
  52.  
  53. function loadNames(load) -- load file called names
  54. checkFile(load)
  55. file = fs.open(load, "r")
  56. readFile = file.readLine()
  57. if readFile ~= nil then
  58. names = textutils.unserialize(readFile)
  59. end
  60. file.close()
  61. end
  62.  
  63. function loadRules(load) -- load file called rules
  64. checkFile(load)
  65. file = fs.open(load, "r")
  66. readFile = file.readLine()
  67. if readFile ~= nil then
  68. rules = textutils.unserialize(readFile)
  69. end
  70. file.close()
  71. end
  72.  
  73.  
  74.  
  75.  
  76.  
  77. function getInputProject() -- read user input and inserts it to the project table
  78. term.setCursorPos(w/2, h-2)
  79. term.setBackgroundColor(colors.black)
  80. term.setTextColor(colors.white)
  81. input = read()
  82. table.insert(project, input)
  83. end
  84.  
  85.  
  86. function getInputName(projectName) -- read user input and inserts it to table in names table.
  87. term.setCursorPos(w/2, h-2)
  88. term.setBackgroundColor(colors.black)
  89. term.setTextColor(colors.white)
  90. input = read()
  91. i = projectName
  92. table.insert(names[i], input)
  93. end
  94.  
  95. function drawImage(image, x, y)
  96. myImage = paintutils.loadImage(image)
  97. paintutils.drawImage(myImage, x, y)
  98. end
  99.  
  100.  
  101.  
  102. function viewProjects() -- displays stored projects
  103. term.clear()
  104. mWrite("<--", 1, h, colors.black, colors.white)
  105. x = 1
  106. y = 1
  107. mWrite("New project", (w-11)/2, h, colors.black, colors.white)
  108. if table.getn(project) > 0 then
  109. for i = 1, #project do
  110. drawImage("button", x, y)
  111. cY = y +2
  112. cX = x+1
  113. y = y + 4
  114. mWrite(project[i], cX, cY, colors.lime)
  115. mWrite("[X]", w-2, 1, colors.black, colors.red)
  116. if y >= h - 4 then y = 1 x = x+12 end
  117. end
  118. else
  119. mWrite("There are currently no projects", (w-31)/2, h/2, colors.white)
  120. end
  121. end
  122.  
  123.  
  124. function startMenu() -- displays start menu
  125. term.clear()
  126. drawImage("header", 1, 1)
  127. mWrite("Build Board", (w-11)/2, 2, colors.lightGray)
  128. x = (w/8)+2
  129. y = h/2
  130. cY = y+1
  131. cX = x +5
  132. for i = 1, #mainMenu do
  133. drawImage("main", x, y)
  134. mWrite(mainMenu[i], cX, cY, colors.white)
  135. cX = cX + 16
  136. x = x+20
  137. end
  138. end
  139.  
  140.  
  141. function rulesDisplay()
  142. term.clear()
  143. -- mWrite("Add rule", (w-8)/2, h, colors.lightBlue, colors.white)
  144. y = ((h-(#rules*2))/2)+2
  145. drawImage("rulesScreen", 1,1)
  146. mWrite("<--", 1, h, colors.lightBlue, colors.white)
  147. for i = 1, #rules do
  148. x = (w-#rules[i])/2
  149. mWrite(rules[i], x, y, colors.white)
  150. y= y+2
  151. end
  152. rulesTouch()
  153. end
  154.  
  155.  
  156.  
  157. function drawBoard() -- decides which menu to draw
  158. term.clear()
  159. startMenu()
  160. if screen == 0 then
  161. event, param1, posx, posy = os.pullEvent()
  162. if event == "monitor_touch" and posx > 27 and posx < 44 and posy > (h/2)-1 and posy < (h/2)+3 then screen = 1
  163. elseif event == "monitor_touch" and posx > 7 and posx < 24 and posy > (h/2)-1 and posy < (h/2)+3 then screen = -1
  164. elseif event == "timer" then
  165. sec = sec+1
  166. if sec == 30 then shell.run("startup") end
  167. -- timer = os.startTimer(1)
  168. end
  169. end
  170. if screen == 0 then
  171. startMenu()
  172. --touch()
  173. elseif screen == 1 then
  174. sec = 0
  175. viewProjects()
  176. inputProject()
  177. elseif screen == -1 then
  178. sec = 0
  179. rulesDisplay()
  180. end
  181. end
  182.  
  183.  
  184.  
  185. function mWrite(message, cX, cY, background, text) -- writes message on cX and cY with background as background color
  186. mon.setBackgroundColor(background)
  187. if text == nil then mon.setTextColor(colors.black)
  188. else mon.setTextColor(text) end
  189. mon.setCursorPos(cX, cY)
  190. mon.write(message)
  191. mon.setBackgroundColor(colors.black)
  192. end
  193.  
  194.  
  195. function rulesTouch() -- Toggle between menues
  196. event, param1, x, y = os.pullEvent()
  197. if event == "monitor_touch" and x < 4 and y == h then screen = screen +1
  198. if screen == 2 then screen = 0 end
  199. -- elseif event == "monitor_touch" and x > (w-8)/2 and x < ((w-8)/2)+8 and y == h then
  200. -- newRule = read()
  201. -- table.insert(rules, newRule)
  202. -- writeFile("rules", rules)
  203. end
  204. end
  205.  
  206.  
  207. function inputProject() -- add a project to the list
  208. event, param1, x, y = os.pullEvent()
  209. if event == "monitor_touch" and x > (w-13)/2 and x < (w+11)/2 and y == h then
  210. getInputProject()
  211. writeFile("projects", project)
  212. elseif event == "monitor_touch" and x > w-3 and y == 1 then selectDeleteProject()
  213. elseif event == "monitor_touch" and x < 4 and y == h then screen = screen +1
  214. if screen == 2 then screen = 0 end
  215. else clickProject()
  216. end
  217. end
  218.  
  219.  
  220.  
  221. function clickProject() -- determines which project is clicked
  222. if event == "monitor_touch" and x > 1 and x < 13 and y > 1 and y < 5 and table.getn(project) > 0 then enterProject(1)
  223. elseif event == "monitor_touch" and x > 1 and x < 13 and y > 5 and y <9 and table.getn(project) > 1 then enterProject(2)
  224. elseif event == "monitor_touch" and x > 1 and x < 13 and y > 9 and y < 13 and table.getn(project) > 2 then enterProject(3)
  225. elseif event == "monitor_touch" and x > 1 and x < 13 and y > 13 and y < 17 and table.getn(project) > 3 then enterProject(4)
  226.  
  227. elseif event == "monitor_touch" and x > 13 and x < 25 and y > 1 and y < 5 and table.getn(project) > 4 then enterProject(5)
  228. elseif event == "monitor_touch" and x > 13 and x < 25 and y > 5 and y <9 and table.getn(project) > 5 then enterProject(6)
  229. elseif event == "monitor_touch" and x > 13 and x < 25 and y > 9 and y < 13 and table.getn(project) > 6 then enterProject(7)
  230. elseif event == "monitor_touch" and x > 13 and x < 25 and y > 13 and y < 17 and table.getn(project) > 7 then enterProject(8)
  231.  
  232. elseif event == "monitor_touch" and x > 25 and x < 37 and y > 1 and y < 5 and table.getn(project) > 8 then enterProject(9)
  233. elseif event == "monitor_touch" and x > 25 and x < 37 and y > 5 and y < 9 and table.getn(project) > 9 then enterProject(10)
  234. elseif event == "monitor_touch" and x > 25 and x < 37 and y > 9 and y < 13 and table.getn(project) > 10 then enterProject(11)
  235. elseif event == "monitor_touch" and x > 25 and x < 37 and y > 13 and y < 17 and table.getn(project) > 11 then enterProject(12)
  236.  
  237. elseif event == "monitor_touch" and x > 37 and x < 49 and y > 1 and y < 5 and table.getn(project) > 12 then enterProject(13)
  238. elseif event == "monitor_touch" and x > 37 and x < 49 and y > 5 and y < 9 and table.getn(project) > 13 then enterProject(14)
  239. elseif event == "monitor_touch" and x > 37 and x < 49 and y > 9 and y < 13 and table.getn(project) > 14 then enterProject(15)
  240. elseif event == "monitor_touch" and x > 37 and x < 49 and y > 13 and y < 17 and table.getn(project) > 15 then enterProject(16)
  241.  
  242. elseif event == "monitor_touch" and y == h and x < 4 then screen = screen +1
  243. if screen == 2 then screen = 1 end
  244. end
  245. end
  246.  
  247.  
  248.  
  249.  
  250. function enterProject(projectName) -- see who is working on clicked project
  251. currProject = projectName
  252. while true do
  253. term.clear()
  254. mWrite("<--", 1, h, colors.black, colors.white)
  255. drawImage("header", 1,1)
  256. mWrite(project[projectName], (w-#project[projectName])/2, 2, colors.lightGray)
  257. mWrite("Add name", (w-8)/2, h, colors.black, colors.white)
  258. mWrite("[X]", w-2, 1, colors.lightGray, colors.red)
  259. x = 1
  260. y = 5
  261. if names[projectName] ~= nil then
  262. if table.getn(names[projectName]) > 0 then
  263. for i = 1, #names[projectName] do
  264. drawImage("button", x, y)
  265. cY = y +2
  266. cX = x+1
  267. y = y + 4
  268. mWrite(names[projectName][i], cX, cY, colors.lime)
  269. if y >= h - 4 then y = 5 x = x+12 end
  270. end
  271. else
  272. mWrite("No one is working on this project", (w-33)/2, h/2, colors.white)
  273. end
  274. end
  275. inputName(projectName)
  276. if backToMain == true then
  277. backToMain = false
  278. break
  279. end
  280. end
  281. end
  282.  
  283.  
  284. function selectDeleteName(projectName) -- select a name for delete
  285. currProject = projectName
  286. while true do
  287. term.clear()
  288. mWrite("<--", 1, h, colors.black, colors.white)
  289. drawImage("header", 1,1)
  290. mWrite(project[projectName], (w-#project[projectName])/2, 2, colors.lightGray)
  291. x = 1
  292. y = 5
  293. if names[projectName] ~= nil then
  294. if table.getn(names[projectName]) > 0 then
  295. for i = 1, #names[projectName] do
  296. drawImage("buttonGray", x, y)
  297. cY = y +2
  298. cX = x+1
  299. y = y + 4
  300. mWrite(names[projectName][i], cX, cY, colors.lightGray)
  301. if y >= h - 4 then y = 5 x = x+12 end
  302. end
  303. else
  304. mWrite("No one is working on this project", (w-33)/2, h/2, colors.white)
  305. end
  306. end
  307. activeProject = projectName
  308. clickName(projectName)
  309. if selectedName ~= false then
  310. deleteName(selectedName, projectName)
  311. selectedName = false
  312. end
  313. if goBack == true then
  314. goBack = false
  315. break
  316. end
  317. end
  318. end
  319.  
  320.  
  321.  
  322. function tableCounter(projectName)
  323. number = 0
  324. for k, v in pairs(names[projectName]) do
  325. number = number +1
  326. end
  327. return tonumber(number)
  328. end
  329.  
  330. function clickName(projectName)
  331. event, param1, x, y = os.pullEvent("monitor_touch")
  332. if event == "monitor_touch" then notInUse = 1 end
  333. event, param1, x, y = os.pullEvent("monitor_touch")
  334. if x > 1 and x < 13 and y > 5 and y < 9 then selectedName = 1
  335. elseif x > 1 and x < 13 and y > 9 and y <13 then selectedName = 2
  336. elseif x > 1 and x < 13 and y > 13 and y < 17 then selectedName = 3
  337.  
  338. elseif x > 13 and x < 25 and y > 5 and y < 9 then selectedName = 4
  339. elseif x > 13 and x < 25 and y > 9 and y <13 then selectedName = 5
  340. elseif x > 13 and x < 25 and y > 13 and y < 17 then selectedName = 6
  341.  
  342. elseif x > 25 and x < 37 and y > 5 and y < 9 then selectedName = 7
  343. elseif x > 25 and x < 37 and y > 9 and y < 13 then selectedName = 8
  344. elseif x > 25 and x < 37 and y > 13 and y < 17 then selectedName = 9
  345.  
  346. elseif x > 37 and x < 49 and y > 5 and y < 9 then selectedName = 10
  347. elseif x > 37 and x < 49 and y > 9 and y < 13 then selectedName = 11
  348. elseif x > 37 and x < 49 and y > 13 and y < 17 then selectedName = 12
  349.  
  350. elseif y == h and x < 4 then goBack = true
  351. end
  352. end
  353.  
  354.  
  355. function deleteName(selectedName, projectName)
  356. currProject = projectName
  357. selectedName = selectedName
  358. term.clear()
  359. drawImage("yes", (w/4), h/2)
  360. drawImage("no", (w/4)*3, h/2)
  361. mWrite("Yes", (w/4)+1, (h/2)+1, colors.white)
  362. mWrite("No", (w/4)*3+1, (h/2)+1, colors.white)
  363.  
  364. event, param1, x, y = os.pullEvent("monitor_touch")
  365. if x > (w/4)-1 and x < (w/4)+5 and y > (h/2)-1 and y < (h/2) +3 then deleteYes = true
  366. elseif x > (w/4)*3-1 and x < (w/4)*3+5 and y > (h/2)-1 and y < (h/2) +3 then deleteNo = true
  367. end
  368.  
  369. if deleteNo == true then goBack = true deleteNo = false
  370. elseif deleteYes == true then table.remove(names[projectName], selectedName)
  371. goBack = true
  372. deleteYes = false
  373. writeFile("names", names)
  374. end
  375. end
  376.  
  377.  
  378.  
  379. function inputName(projectName) -- add a name to a project
  380. currProject = projectName
  381. event, param1, x, y = os.pullEvent("monitor_touch")
  382. if event == "monitor_touch" and x > (w-11)/2 and x < (w+11)/2 and y == h then
  383. getInputName(projectName)
  384. writeFile("names", names)
  385. elseif event == "monitor_touch" and x > w-3 and y == 1 then selectDeleteName(projectName)
  386. elseif event == "monitor_touch" and x < 4 and y > h-2 then
  387. screen = screen +1
  388. backToMain = true
  389. if screen == 2 then screen = 1 end
  390. end
  391. end
  392.  
  393.  
  394.  
  395. function selectDeleteProject() -- select a project for delete
  396. while true do
  397. term.clear()
  398. x = 1
  399. y = 1
  400. if table.getn(project) > 0 then
  401. for i = 1, #project do
  402. drawImage("buttonGray", x, y)
  403. cY = y +2
  404. cX = x+1
  405. y = y + 4
  406. mWrite(project[i], cX, cY, colors.lightGray)
  407. if y >= h - 4 then y = 1 x = x+12 end
  408. end
  409. else
  410. mWrite("There are currently no projects", (w-31)/2, h/2, colors.white)
  411. end
  412. pickProject()
  413. if goBack == true then
  414. goBack = false
  415. break
  416. end
  417. end
  418. end
  419.  
  420.  
  421.  
  422.  
  423.  
  424.  
  425.  
  426.  
  427. function pickProject() -- registers which project you want to delete
  428. event, param1, x, y = os.pullEvent("monitor_touch")
  429. if event == "monitor_touch" then notInUse = 1 end
  430. event, param1, x, y = os.pullEvent("monitor_touch")
  431. if x > 1 and x < 13 and y > 1 and y < 5 then deleteProject(1)
  432. elseif x > 1 and x < 13 and y > 5 and y <9 then deleteProject(2)
  433. elseif x > 1 and x < 13 and y > 9 and y < 13 then deleteProject(3)
  434. elseif x > 1 and x < 13 and y > 13 and y < 17 then deleteProject(4)
  435.  
  436. elseif x > 13 and x < 25 and y > 1 and y < 5 then deleteProject(5)
  437. elseif x > 13 and x < 25 and y > 5 and y <9 then deleteProject(6)
  438. elseif x > 13 and x < 25 and y > 9 and y < 13 then deleteProject(7)
  439. elseif x > 13 and x < 25 and y > 13 and y < 17 then deleteProject(8)
  440.  
  441. elseif x > 25 and x < 37 and y > 1 and y < 5 then deleteProject(9)
  442. elseif x > 25 and x < 37 and y > 5 and y < 9 then deleteProject(10)
  443. elseif x > 25 and x < 37 and y > 9 and y < 13 then deleteProject(11)
  444. elseif x > 25 and x < 37 and y > 13 and y < 17 then deleteProject(12)
  445.  
  446. elseif x > 37 and x < 49 and y > 1 and y < 5 then deleteProject(13)
  447. elseif x > 37 and x < 49 and y > 5 and y < 9 then deleteProject(14)
  448. elseif x > 37 and x < 49 and y > 9 and y < 13 then deleteProject(15)
  449. elseif x > 37 and x < 49 and y > 13 and y < 17 then deleteProject(16)
  450.  
  451. elseif event == "monitor_touch" and y == h and x < 4 then goBack = true
  452. if screen == 2 then screen = 1 end
  453. end
  454. end
  455.  
  456.  
  457. function deleteProject(selectedProject) -- deletes selected project
  458. term.clear()
  459. drawImage("yes", (w/4), h/2)
  460. drawImage("no", (w/4)*3, h/2)
  461. mWrite("Yes", (w/4)+1, (h/2)+1, colors.white)
  462. mWrite("No", (w/4)*3+1, (h/2)+1, colors.white)
  463.  
  464. event, param1, x, y = os.pullEvent("monitor_touch")
  465. if x > (w/4)-1 and x < (w/4)+5 and y > (h/2)-1 and y < (h/2) +3 then deleteYes = true
  466. elseif x > (w/4)*3-1 and x < (w/4)*3+5 and y > (h/2)-1 and y < (h/2) +3 then deleteNo = true
  467. end
  468.  
  469. if deleteNo == true then goBack = true deleteNo = false
  470. elseif deleteYes == true then table.remove(project, selectedProject)
  471. goBack = true
  472. deleteYes = false
  473. writeFile("projects", project)
  474. end
  475. end
  476.  
  477.  
  478.  
  479. ---------- LOOP -------------
  480. term.redirect(mon)
  481. while true do
  482. timer = os.startTimer(1)
  483. loadProjects("projects")
  484. loadNames("names")
  485. -- loadRules("rules")
  486. drawBoard()
  487. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement