Guest User

Untitled

a guest
Jan 22nd, 2015
469
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.59 KB | None | 0 0
  1. --basic helper functions
  2.  
  3. if fs.exists("GoldSlideDir") == false then
  4. fs.makeDir("GoldSlideDir")
  5. end
  6.  
  7. function clear(display)
  8. if display == nil then
  9. term.clear()
  10. term.setCursorPos(1,1)
  11. else
  12. screen = {}
  13. screen = display
  14. screen.clear()
  15. screen.setCursorPos(1,1)
  16. end
  17. end
  18.  
  19. color = {
  20. 1,
  21. 2,
  22. 8,
  23. 16,
  24. 256,
  25. 2048,
  26. 4096,
  27. 8192,
  28. 32768,
  29. 16384
  30. }
  31.  
  32.  
  33. --click areas
  34. menuBarBack = {
  35. {2,3,4,5,6,7},
  36. {1}
  37. }
  38.  
  39. menuBarAdd = {
  40. {9,10,11,12,13},
  41. {1}
  42. }
  43.  
  44. menuBarBGColor = {
  45. {15,16,17,18,19,20,21,22,23,24},
  46. {1}
  47. }
  48.  
  49. menuBarNewSlide = {
  50. {26,27,28,29,30,31,32,33,34,35,36},
  51. {1}
  52. }
  53.  
  54. boxChangeWidth = {
  55. {51},
  56. {1}
  57. }
  58.  
  59. boxChangeHeight = {
  60. {51},
  61. {2}
  62. }
  63.  
  64. boxDelete = {
  65. {51},
  66. {3}
  67. }
  68.  
  69. addBarBox = {
  70. {2,3,4,5,6,7,8},
  71. {2}
  72. }
  73.  
  74. addBarText = {
  75. {10,11,12,13,14,15,16,17},
  76. {2}
  77. }
  78.  
  79. menuNew = {
  80. {10,11,12,13,14,15,16,17,18,19,20,21,22},
  81. {13,14,15}
  82. }
  83.  
  84. menuOpen = {
  85. {10,11,12,13,14,15,16,17,18,19,20,21,22,23},
  86. {17,18,19}
  87. }
  88.  
  89. menuDelete = {
  90. {25,26,27,28,29,30,31,33,34,35,36,37,38,39,40},
  91. {13,14,15}
  92. }
  93.  
  94. menuShow = {
  95. {25,26,27,28,29,30,31,32,33,34,35,36,37,38},
  96. {17,18,19}
  97. }
  98.  
  99. function checkClickArea(x,y,a)
  100. area = {}
  101. area = a
  102.  
  103. xFound = false
  104. yFound = false
  105.  
  106. for i,v in ipairs(area[1]) do
  107. if v == x then
  108. xFound = true
  109. end
  110. end
  111.  
  112. for i,v in ipairs(area[2]) do
  113. if v == y then
  114. yFound = true
  115. end
  116. end
  117.  
  118. if xFound and yFound then
  119. return true
  120. else
  121. return false
  122. end
  123. end
  124.  
  125. function split(str, pattern)
  126. local t = { }
  127. local fpat = "(.-)" .. pattern
  128. local last_end = 1
  129. local s, e, cap = str:find(fpat, 1)
  130. while s do
  131. if s ~= 1 or cap ~= "" then
  132. table.insert(t,cap)
  133. end
  134. last_end = e+1
  135. s, e, cap = str:find(fpat, last_end)
  136. end
  137. if last_end <= #str then
  138. cap = str:sub(last_end)
  139. table.insert(t, cap)
  140. end
  141. return t
  142. end
  143.  
  144. function aPrint(x,y,text,display)
  145. if display == nil then
  146. screen = term
  147. else
  148. screen = {}
  149. screen = display
  150. end
  151.  
  152. nText = split(text, "/n")
  153.  
  154. y = y - 1
  155.  
  156. for i,v in ipairs(nText) do
  157. screen.setCursorPos(x, y + i)
  158. screen.write(v)
  159. end
  160. end
  161.  
  162. --element functions
  163.  
  164. function drawBox(x,y,w,h,color,display)
  165.  
  166. if display == nil then
  167. screen = term
  168. else
  169. screen = {}
  170. screen = display
  171. end
  172.  
  173. screen.setBackgroundColor(color)
  174. i = 0
  175. while i < w do
  176. i2 = 0
  177. while i2 < h do
  178. screen.setCursorPos(x + i, y + i2)
  179. screen.write(" ")
  180. i2 = i2 + 1
  181. end
  182. i = i + 1
  183. end
  184.  
  185. screen.setBackgroundColor(colors.black)
  186. end
  187.  
  188. function findClickArea(x,y,w,h)
  189. xs = {}
  190. ys = {}
  191.  
  192. i = 0
  193. while i < w do
  194. table.insert(xs, x + i)
  195. i = i + 1
  196. end
  197.  
  198. i = 0
  199. while i < h do
  200. table.insert(ys, y + i)
  201. i = i + 1
  202. end
  203.  
  204. return {xs, ys}
  205. end
  206.  
  207. function drawText(x,y,text, bColor, tColor, display)
  208. if display == nil then
  209. screen = term
  210. else
  211. screen = {}
  212. screen = display
  213. end
  214.  
  215. screen.setBackgroundColor(bColor)
  216. screen.setTextColor(tColor)
  217.  
  218. aPrint(x,y,text,screen)
  219. screen.setBackgroundColor(colors.black)
  220. screen.setTextColor(colors.white)
  221. end
  222.  
  223. function findClickAreaTextBox(x,y,text)
  224. ys = {y}
  225. xs = {}
  226.  
  227. maxLen = 0
  228.  
  229. i = 0
  230. while i < string.len(text) do
  231. table.insert(xs, x + i)
  232. i = i + 1
  233. end
  234.  
  235. return {xs, ys}
  236. end
  237.  
  238. function textClickArea(x,y,element)
  239. text = element[4][1]
  240. xPos = element[2][1]
  241. yPos = element[2][2] - 1
  242.  
  243. array = {}
  244.  
  245. nText = split(text, "/n")
  246.  
  247. found = false
  248.  
  249. for i,v in ipairs(nText) do
  250. table.insert(array, findClickAreaTextBox(xPos,yPos + i,v))
  251. end
  252.  
  253. for i,v in ipairs(array) do
  254. if checkClickArea(x,y,v) then
  255. found = true
  256. end
  257. end
  258.  
  259. return found
  260. end
  261.  
  262. --Drawing functions
  263. function drawMenuBar(display)
  264. if display == nil then
  265. screen = term
  266. else
  267. screen = {}
  268. screen = display
  269. end
  270.  
  271. screen.setBackgroundColor(colors.yellow)
  272. screen.setTextColor(colors.black)
  273. screen.setCursorPos(1,1)
  274. screen.write("| Back | Add | BG Color | New Slide |")
  275. screen.setTextColor(colors.white)
  276. screen.setBackgroundColor(colors.black)
  277. end
  278.  
  279. function drawColorPicker(display)
  280.  
  281. if display == nil then
  282. screen = term
  283. else
  284. screen = {}
  285. screen = display
  286. end
  287.  
  288. for i,v in ipairs(color) do
  289. screen.setCursorPos(50,i)
  290. screen.setBackgroundColor(v)
  291. screen.write(".")
  292. end
  293. end
  294.  
  295. function drawElementButtons(element, picker, display)
  296. if display == nil then
  297. screen = term
  298. else
  299. screen = {}
  300. screen = display
  301. end
  302.  
  303. screen.setBackgroundColor(colors.yellow)
  304. screen.setCursorPos(51,1)
  305. screen.write("X")
  306. if element == "box" then
  307. screen.setCursorPos(51,2)
  308. screen.write("C")
  309. elseif element == "textBox" then
  310. screen.setCursorPos(51,2)
  311. screen.setBackgroundColor(colors.yellow)
  312. screen.write("C")
  313. screen.setCursorPos(51,3)
  314. screen.write("T")
  315. end
  316. screen.setTextColor(colors.white)
  317. screen.setBackgroundColor(colors.black)
  318. end
  319.  
  320. function drawFrame(num,element, display)
  321. if display == nil then
  322. screen = term
  323. else
  324. screen = {}
  325. screen = display
  326. end
  327.  
  328. drawMenuBar(screen)
  329. if element ~= nil then
  330. drawElementButtons(element, screen)
  331. end
  332. screen.setCursorPos(1,19)
  333. screen.write(num)
  334. end
  335.  
  336. function drawAddType(display)
  337. if display == nil then
  338. screen = term
  339. else
  340. screen = {}
  341. screen = display
  342. end
  343.  
  344. screen.setCursorPos(1,2)
  345. screen.write("| Box | Text |")
  346. end
  347.  
  348. --draw main menu
  349. function drawMain()
  350. term.setBackgroundColor(colors.blue)
  351. clear()
  352. --"G"
  353. drawBox(15,3,7,1,colors.yellow)
  354. drawBox(15,4,1,7,colors.yellow)
  355. drawBox(15,11,10,1,colors.yellow)
  356. drawBox(25,8,1,4,colors.yellow)
  357. drawBox(20,8,6,1,colors.yellow)
  358. --"S"
  359. drawBox(27,3,7,1,colors.yellow)
  360. drawBox(27,4,1,3,colors.yellow)
  361. drawBox(27,7,7,1,colors.yellow)
  362. drawBox(33,8,1,4,colors.yellow)
  363. drawBox(27,11,7,1,colors.yellow)
  364. --"New Project"
  365. drawBox(10,13,13,3,colors.red)
  366. term.setBackgroundColor(colors.red)
  367. term.setTextColor(colors.black)
  368. term.setCursorPos(11,14)
  369. term.write("New Project")
  370. --"Open Project"
  371. drawBox(10,17,14,3,colors.red)
  372. term.setBackgroundColor(colors.red)
  373. term.setTextColor(colors.black)
  374. term.setCursorPos(11,18)
  375. term.write("Open Project")
  376. --"Delete Project"
  377. drawBox(25,13,16,3,colors.red)
  378. term.setBackgroundColor(colors.red)
  379. term.setTextColor(colors.black)
  380. term.setCursorPos(26,14)
  381. term.write("Delete Project")
  382. --"Show Project"
  383. drawBox(25,17,14,3,colors.red)
  384. term.setBackgroundColor(colors.red)
  385. term.setTextColor(colors.black)
  386. term.setCursorPos(26,18)
  387. term.write("Show Project")
  388. end
  389.  
  390. --draw slide functions
  391.  
  392. function drawSlideInitial(project, slide, display)
  393. if display == nil then
  394. screen = term
  395. else
  396. screen = {}
  397. screen = display
  398. end
  399.  
  400. allElementsOnScreen = {}
  401.  
  402. clear(screen)
  403.  
  404. slideFolder = "GoldSlideDir/"..project.."/slide-"..slide.."/"
  405.  
  406. shell.run(slideFolder.."id")
  407. shell.run(slideFolder.."bgcolor")
  408.  
  409. screen.setBackgroundColor(bgColor)
  410. clear(screen)
  411.  
  412. elementsFolder = slideFolder.."elements/"
  413.  
  414. allElements = fs.list(elementsFolder)
  415.  
  416. for i,v in ipairs(allElements) do
  417. if v == ".DS_Store" then
  418. table.remove(allElements, i)
  419. end
  420. end
  421.  
  422. for i,v in ipairs(allElements) do
  423.  
  424. file = fs.open(elementsFolder..v.."/element", "r")
  425. nElement = file.readAll()
  426. file.close()
  427.  
  428. file = fs.open(elementsFolder..v.."/pos","r")
  429. nPos = file.readAll()
  430. file.close()
  431. nPos = textutils.unserialize(nPos)
  432.  
  433.  
  434. file = fs.open(elementsFolder..v.."/params","r") --sets param variable
  435. nParams = file.readAll()
  436. file.close()
  437. print(nParams)
  438. nParams = textutils.unserialize(nParams)
  439.  
  440. area = {}
  441.  
  442. --element config
  443. --{element, pos, area, params}
  444.  
  445. --handling the type of element
  446.  
  447. if nElement == "box" then
  448. drawBox(nPos[1],nPos[2],nParams[1],nParams[2],nParams[3],screen)
  449. area = findClickArea(nPos[1],nPos[2],nParams[1],nParams[2])
  450. table.insert(allElementsOnScreen, {nElement, nPos, area, nParams})
  451. elseif nElement == "textBox" then
  452. drawText(nPos[1],nPos[2],nParams[1],nParams[2],nParams[3],screen)
  453. area = findClickAreaTextBox(nPos[1], nPos[2], nParams[1])
  454. table.insert(allElementsOnScreen, {nElement, nPos, area, nParams})
  455. elseif nElement == "picture" then
  456. picture = paintutils.loadImage(elementsFolder..v.."/"..params[1])
  457. paintutils.drawImage(picture, pos[1], pos[2])
  458. end
  459. end
  460. return allElementsOnScreen
  461. end
  462.  
  463. function drawSlide(elem, project, slide, display)
  464. if display == nil then
  465. screen = term
  466. else
  467. screen = {}
  468. screen = display
  469. end
  470.  
  471. elements = {}
  472. elements = elem
  473.  
  474. clear(screen)
  475.  
  476. slideFolder = "GoldSlideDir/"..project.."/slide-"..slide.."/"
  477.  
  478. shell.run(slideFolder.."id")
  479. shell.run(slideFolder.."bgcolor")
  480.  
  481. screen.setBackgroundColor(bgColor)
  482. clear(screen)
  483.  
  484. elementsFolder = slideFolder.."elements/"
  485.  
  486. for i,v in ipairs(elements) do
  487. element = elements[i][1] --sets element variable
  488. pos = elements[i][2] --sets pos variable
  489. params = elements[i][4] --sets param variable
  490.  
  491.  
  492. --element config
  493. --{element, pos, area, params}
  494.  
  495. --handling the type of element
  496.  
  497. if element == "box" then
  498. drawBox(pos[1],pos[2],params[1],params[2],params[3], screen)
  499. elseif element == "textBox" then
  500. drawText(pos[1],pos[2],params[1],params[2],params[3], screen)
  501. elseif element == "picture" then
  502. picture = paintutils.loadImage(elementsFolder..v.."/"..params[1])
  503. paintutils.drawImage(picture, pos[1], pos[2])
  504. end
  505.  
  506. end
  507. end
  508.  
  509. --save function
  510. function save(elem, project, slide)
  511. elements = {}
  512. elements = elem
  513.  
  514. elementsFolder = "GoldSlideDir/"..project.."/slide-"..slide.."/elements/"
  515.  
  516. allElements = fs.list(elementsFolder)
  517.  
  518. for i,v in ipairs(allElements) do
  519. fs.delete(elementsFolder..v)
  520. end
  521.  
  522. for i,v in ipairs(elements) do
  523. fs.makeDir(elementsFolder.."element-"..i)
  524.  
  525.  
  526. file = fs.open(elementsFolder.."element-"..i.."/element", "w")
  527. file.write(v[1])
  528. file.close()
  529.  
  530. file = fs.open(elementsFolder.."element-"..i.."/pos", "w")
  531. file.write('{'..v[2][1]..','..v[2][2]..'}')
  532. file.close()
  533.  
  534. if v[1] == "box" then
  535. file = fs.open(elementsFolder.."element-"..i.."/params", "w")
  536. file.write('{')
  537. file.write(v[4][1]..",")
  538. file.write(v[4][2]..",")
  539. file.write(v[4][3])
  540. file.write("}")
  541. file.close()
  542. elseif v[1] == "textBox" then
  543. file = fs.open(elementsFolder.."element-"..i.."/params", "w")
  544. file.write('{"')
  545. file.write(v[4][1]..'",')
  546. file.write(v[4][2]..",")
  547. file.write(v[4][3])
  548. file.write("}")
  549. file.close()
  550. end
  551.  
  552. end
  553. end
  554.  
  555. --create new
  556. function createNewSlide(projectName,nSlideNum)
  557. path = "GoldSlideDir/"..projectName.."/slide-"..nSlideNum.."/"
  558.  
  559. file = fs.open(path.."id", "w")
  560. file.write("slideId = "..nSlideNum)
  561. file.close()
  562.  
  563. file = fs.open(path.."bgcolor", "w")
  564. file.write("bgColor = colors.black")
  565. file.close()
  566.  
  567. path = path.."elements/element-0/"
  568.  
  569. file = fs.open(path.."element", "w")
  570. file.close()
  571.  
  572. file = fs.open(path.."pos", "w")
  573. file.close()
  574.  
  575. file = fs.open(path.."params", "w")
  576. file.close()
  577. end
  578.  
  579. function newProject(name)
  580. fs.makeDir("GoldSlideDir/"..name.."/")
  581. createNewSlide(name, 1)
  582. end
  583.  
  584. --flow control
  585.  
  586. project = "project-1"
  587.  
  588.  
  589. function editSlide(projectName)
  590. allSlides = fs.list("GoldSlideDir/"..projectName)
  591.  
  592. for i,v in ipairs(allSlides) do
  593. if v == ".DS_Store" then
  594. table.remove(allSlides, i)
  595. end
  596. end
  597.  
  598. clickID = 0
  599. elements = drawSlideInitial(projectName,1)
  600.  
  601. slideCur = 1
  602. slideMin = 1
  603. slideMax = table.getn(allSlides)
  604.  
  605. while true do
  606. allSlides = fs.list("GoldSlideDir/"..projectName)
  607.  
  608. for i,v in ipairs(allSlides) do
  609. if v == ".DS_Store" then
  610. table.remove(allSlides, i)
  611. end
  612. end
  613.  
  614. slideMax = table.getn(allSlides)
  615.  
  616. drawSlide(elements, projectName, slideCur, screen)
  617.  
  618. if clickID ~= 0 then
  619. drawFrame(slideCur, elements[clickID][1], screen)
  620. else
  621. drawFrame(slideCur,screen)
  622. end
  623.  
  624. e,p1,p2,p3 = os.pullEvent()
  625.  
  626. save(elements, projectName, slideCur)
  627.  
  628. if e == "mouse_click" and p1 == 1 or p1 == 2 then
  629.  
  630. drag = false
  631.  
  632. for i = #elements,1,-1 do
  633. if elements[i][1] == "textBox" and textClickArea(p2,p3,elements[i]) then
  634. clickID = i
  635. newClick = true
  636. elseif elements[i][1] ~= "textBox" and checkClickArea(p2,p3,elements[i][3]) then
  637. clickID = i
  638. newClick = true
  639. areaX = elements[i][3][1]
  640. areaY = elements[i][3][2]
  641.  
  642. if p2 == areaX[#areaX] and p3 == areaY[#areaY] and elements[i][1] == "box" then
  643. drag = true
  644. end
  645. break
  646. end
  647. end
  648.  
  649. if p1 == 2 and clickID ~= 0 and elements[clickID][1] == "textBox" then
  650. term.setCursorBlink(true)
  651. newLine = false
  652. while true do
  653. text = elements[clickID][4][1]
  654. y = elements[clickID][2][2]
  655. x = elements[clickID][2][1]
  656. lines = split(text, "/n")
  657. nLines = #lines - 1
  658. if lines[#lines] == nil then
  659. xDis = 0
  660. else
  661. xDis = string.len(lines[#lines])
  662. end
  663.  
  664.  
  665. if newLine then
  666. term.setCursorPos(x, nLines + y + 1)
  667. else
  668. term.setCursorPos(x + xDis, nLines + y)
  669. end
  670. event, param1, param2, param3 = os.pullEvent()
  671.  
  672. if event == "char" then
  673. text = text..param1
  674. elements[clickID][4][1] = text
  675. newLine = false
  676. elseif event == "key" then
  677. if param1 == 28 then
  678. text = text.."/n"
  679. term.setCursorPos(x, nLines + y + 1)
  680. elements[clickID][4][1] = text
  681. newLine = true
  682. elseif param1 == 14 then
  683. if string.sub(text,-2) == "/n" then
  684. temp = string.reverse(text)
  685. temp = string.sub(temp, 3)
  686. temp = string.reverse(temp)
  687. else
  688. temp = string.reverse(text)
  689. temp = string.sub(temp, 2)
  690. temp = string.reverse(temp)
  691. end
  692.  
  693. text = temp
  694. elements[clickID][4][1] = text
  695. end
  696. elseif event == "mouse_click" then
  697. term.setCursorBlink(false)
  698. break
  699. end
  700.  
  701. drawSlide(elements, projectName, slideCur)
  702. drawFrame(slideCur)
  703. end
  704.  
  705. elseif newClick then
  706. newClick = false
  707. elseif p1 == 1 and clickID ~= 0 and p2 == 51 and p3 == 1 then
  708. table.remove(elements, clickID)
  709. clickID = 0
  710. elseif p1 ==1 and clickID ~= 0 and p2 == 51 and p3 == 2 then
  711. drawColorPicker()
  712. event, param1, param2, param3 = os.pullEvent()
  713. if event == "mouse_click" and param1 == 1 and param2 == 50 and param3 <= table.getn(color) then
  714. if elements[clickID][1] == "box" then
  715. elements[clickID][4][3] = color[param3]
  716. elseif elements[clickID][1] == "textBox" then
  717. elements[clickID][4][2] = color[param3]
  718. end
  719. end
  720. elseif p1 == 1 and clickID ~= 0 and p2 == 51 and p3 == 3 and elements[clickID][1] == "textBox" then
  721. drawColorPicker()
  722. event, param1, param2, param3 = os.pullEvent()
  723. if event == "mouse_click" and param1 == 1 and param2 == 50 and param3 <= table.getn(color) then
  724. if elements[clickID][1] == "textBox" then
  725. elements[clickID][4][3] = color[param3]
  726. end
  727. end
  728. elseif checkClickArea(p2,p3,menuBarAdd) then
  729. drawAddType()
  730.  
  731. e1, p11, p21, p31 = os.pullEvent()
  732.  
  733. if e1 == "mouse_click" and p11 == 1 then
  734. if checkClickArea(p21, p31, addBarBox) then
  735. table.insert(elements, {"box" , {4,4} , findClickArea(4,4,2,2), {2,2,colors.orange}})
  736. elseif checkClickArea(p21,p31, addBarText) then
  737. table.insert(elements, {"textBox", {4,4}, findClickAreaTextBox(4,4,"text"), {"text", colors.white, colors.black}})
  738. end
  739. end
  740. elseif checkClickArea(p2,p3,menuBarBack) then
  741. clear()
  742. break
  743. elseif checkClickArea(p2,p3,menuBarBGColor) then
  744. drawColorPicker()
  745. event, param1, param2, param3 = os.pullEvent()
  746. if event == "mouse_click" and param1 == 1 and param2 == 50 and param3 <= table.getn(color) then
  747. term.setBackgroundColor(colors.blue)
  748. file = fs.open("GoldSlideDir/"..projectName.."/slide-"..slideCur.."/bgcolor", "w")
  749. file.write("bgColor = "..color[param3])
  750. file.close()
  751. end
  752. elseif checkClickArea(p2,p3,menuBarNewSlide) then
  753. createNewSlide(projectName, #allSlides + 1)
  754. slideCur = #allSlides + 1
  755. else
  756. if clickID ~= 0 then
  757. clickID = 0
  758. end
  759. end
  760. elseif e == "mouse_drag" and p1 == 1 then
  761. if clickID ~= 0 and drag == false then
  762. elements[clickID][2][1] = p2
  763. elements[clickID][2][2] = p3
  764.  
  765. e = elements[clickID]
  766.  
  767. if e[1] == "box" then
  768. elements[clickID][3] = findClickArea(e[2][1], e[2][2], e[4][1], e[4][2])
  769. elseif e[1] == "textBox" then
  770. elements[clickID][3] = findClickAreaTextBox(e[2][1], e[2][2], e[4][1])
  771. end
  772. elseif clickID ~= 0 and drag == true then
  773. area = elements[clickID][3]
  774. params = elements[clickID][4]
  775.  
  776. xDis = p2 - area[1][#area[1]]
  777. yDis = p3 - area[2][#area[2]]
  778.  
  779. elements[clickID][4][1] = math.abs(params[1] + xDis)
  780. elements[clickID][4][2] = math.abs(params[2] + yDis)
  781.  
  782. w = elements[clickID][4][1]
  783. h = elements[clickID][4][2]
  784. position = elements[clickID][2]
  785.  
  786. elements[clickID][3] = findClickArea(position[1], position[2], w, h)
  787. end
  788. elseif e == "key" then
  789. if p1 == 205 then
  790. if slideCur < #allSlides then
  791. slideCur = slideCur + 1
  792. end
  793. elseif p1 == 203 then
  794. if slideCur > 1 then
  795. slideCur = slideCur - 1
  796. end
  797. end
  798. clickID = 0
  799.  
  800. elements = drawSlideInitial(projectName, slideCur)
  801. end
  802. end
  803. end
  804.  
  805. function drawProjects(allProjects)
  806. tab = {}
  807. tab = allProjects
  808.  
  809. if tab[1] ~= nil then
  810.  
  811. term.setBackgroundColor(colors.blue)
  812. term.setTextColor(colors.black)
  813. clear()
  814. print("Select an Option")
  815.  
  816. x = 3
  817. y = 3
  818.  
  819. areas = {}
  820. projects = {}
  821.  
  822. for i,v in ipairs(tab) do
  823. if v == ".DS_Store" then
  824. table.remove(tab, i)
  825. end
  826. end
  827.  
  828. for i,v in ipairs(tab) do
  829. if x + string.len(v) + 2 > 49 then
  830. x = 3
  831. y = y + 4
  832. end
  833.  
  834. drawBox(x,y,string.len(v) + 2, 3, colors.red)
  835. term.setCursorPos(x + 1, y + 1)
  836. term.setBackgroundColor(colors.red)
  837. term.setTextColor(colors.white)
  838. term.write(v)
  839.  
  840. table.insert(areas, findClickArea(x,y,string.len(v) + 2, 3))
  841.  
  842. if x > 49 then
  843. x = 3
  844. y = y + 4
  845. else
  846. x = x + string.len(v) + 3
  847. end
  848.  
  849. end
  850.  
  851. for i,v in ipairs(tab) do
  852. table.insert(projects, {v, areas[i]})
  853. end
  854.  
  855. return projects
  856. else
  857.  
  858. return "NOPE"
  859.  
  860. end
  861. end
  862.  
  863. function findMonitors()
  864. mons = {}
  865.  
  866. for i,v in ipairs(rs.getSides()) do
  867. if peripheral.getType(v) == "monitor" then
  868. table.insert(mons, v)
  869. end
  870. end
  871.  
  872. return mons
  873. end
  874.  
  875. function slideShow(project, display)
  876. screen1 = {}
  877. screen2 = {}
  878. screen1 = display
  879. screen2 = term
  880.  
  881. slideCur = 1
  882.  
  883. allSlides = fs.list("GoldSlideDir/"..project.."/")
  884. for i,v in ipairs(allSlides) do
  885. if v == ".DS_Store" then
  886. table.remove(allSlides, i)
  887. end
  888. end
  889.  
  890. slideMin = 1
  891. slideMax = #allSlides
  892.  
  893. elements = drawSlideInitial(project, slideCur, screen1)
  894. elements = drawSlideInitial(project, slideCur, screen2)
  895.  
  896. screen.setCursorBlink(false)
  897.  
  898. while true do
  899. clear()
  900.  
  901. drawSlide(elements, project, slideCur, screen1)
  902. drawSlide(elements, project, slideCur, screen2)
  903.  
  904. e,p1 = os.pullEvent()
  905.  
  906. if e == "key" then
  907. if p1 == 203 then
  908. if slideCur > 1 then
  909. slideCur = slideCur - 1
  910. end
  911. elseif p1 == 205 then
  912. if slideCur < slideMax then
  913. slideCur = slideCur + 1
  914. end
  915. elseif p1 == 14 then
  916. break
  917. end
  918. end
  919.  
  920. elements = drawSlideInitial(project, slideCur, screen1)
  921. elements = drawSlideInitial(project, slideCur, screen2)
  922. end
  923. end
  924.  
  925.  
  926.  
  927. while true do
  928. drawMain()
  929. term.setCursorPos(51,1)
  930. term.setBackgroundColor(colors.red)
  931. term.setTextColor(colors.white)
  932. term.write("X")
  933. term.setCursorPos(51,2)
  934. term.setBackgroundColor(colors.yellow)
  935. term.write("i")
  936.  
  937. event, parameter1, parameter2, parameter3 = os.pullEvent()
  938. term.setBackgroundColor(colors.black)
  939. if event == "mouse_click" and parameter1 == 1 then
  940. if checkClickArea(parameter2, parameter3, menuNew) then
  941. term.setBackgroundColor(colors.black)
  942. clear()
  943. print("This part will be better later, I just wanted to add something here temporarily")
  944. term.write("Enter project name: ")
  945. name = read()
  946. newProject(name)
  947. elseif checkClickArea(parameter2, parameter3, menuOpen) then
  948. allProjects = fs.list("GoldSlideDir/")
  949. objects = drawProjects(allProjects)
  950.  
  951. if objects ~= "NOPE" then
  952. e, p1, p2, p3 = os.pullEvent()
  953. if e == "mouse_click" and p1 == 1 then
  954. for i,v in ipairs(objects) do
  955. if checkClickArea(p2,p3,v[2]) then
  956. editSlide(v[1])
  957. end
  958. end
  959. end
  960. end
  961. elseif checkClickArea(parameter2, parameter3, menuShow) then
  962. allProjects = fs.list("GoldSlideDir/")
  963. objects = drawProjects(allProjects)
  964.  
  965. if objects ~= "NOPE" then
  966. e, p1, p2, p3 = os.pullEvent()
  967. if e == "mouse_click" and p1 == 1 then
  968. for i,v in ipairs(objects) do
  969. if checkClickArea(p2,p3,v[2]) then
  970. peripherals = findMonitors()
  971. objects2 = drawProjects(peripherals)
  972.  
  973. term.setBackgroundColor(colors.black)
  974. if objects2 ~= "NOPE" then
  975. e2, param1, param2, param3 = os.pullEvent()
  976. if e2 == "mouse_click" and param1 == 1 then
  977. for o,k in ipairs(objects2) do
  978. if checkClickArea(param2,param3,k[2]) then
  979. slideShow(v[1], peripheral.wrap(k[1]))
  980. end
  981. end
  982. end
  983. end
  984. end
  985. end
  986. end
  987. end
  988. elseif checkClickArea(parameter2, parameter3, menuDelete) then
  989. allProjects = fs.list("GoldSlideDir/")
  990. objects = drawProjects(allProjects)
  991.  
  992. if objects ~= "NOPE" then
  993. e, p1, p2, p3 = os.pullEvent()
  994. if e == "mouse_click" and p1 == 1 then
  995. for i,v in ipairs(objects) do
  996. if checkClickArea(p2,p3,v[2]) then
  997. fs.delete("GoldSlideDir/"..v[1])
  998. end
  999. end
  1000. end
  1001. end
  1002. elseif parameter2 == 51 and parameter3 == 1 then
  1003. term.setBackgroundColor(colors.black)
  1004. clear()
  1005. break
  1006. elseif parameter2 == 51 and parameter3 == 2 then
  1007. term.setBackgroundColor(colors.blue)
  1008. term.setTextColor(colors.black)
  1009. clear()
  1010.  
  1011. print("Thankyou for downloading GoldSlide!")
  1012. print()
  1013. print("To create a project, click new project. Then click open project and select the new project to edit it")
  1014. print()
  1015. print("Keyboard controls to present a slideshow")
  1016. print("----------------------------------------")
  1017. print("Left arrow key - back a slide")
  1018. print()
  1019. print("Right arrow key - forward a slide")
  1020. print()
  1021. print("Backspace - back to main menu")
  1022. print()
  1023. print()
  1024. print()
  1025. print("Press enter")
  1026. read()
  1027.  
  1028. end
  1029. end
  1030. end
Advertisement
Add Comment
Please, Sign In to add comment