Streetboy_xD

[Computercraft] ButtonCreator Funktionen V2.3

Dec 7th, 2015
466
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.78 KB | None | 0 0
  1. -- Alle Funktionen
  2.  
  3. -- design_fillMon(letter, bColor)
  4. -- design_redrawMonitor(buttons, bColor, hColor, tColor, menuBar, invisible)
  5. -- design_dateiMenu(dateiOpen, tColor, hColor, bColor)
  6. -- design_bearbeitenMenu(bearbeitenOpen, tColor, hColor, bColor)
  7. -- design_helpMenu(buttons, bColor, hColor, tColor, menuBar)
  8. -- design_drawButtons(buttons)
  9. -- object_checkIfClicked(objectX, objectY, clickedX, clickedY)
  10. -- object_undoLastObject(buttons, hColor, tColor, bColor)
  11. -- prog_numberToColor(colorPos)
  12. -- prog_setButtonSettings(buttonFX, buttonSX)
  13. -- prog_changeSettings(buttons, hColor, tColor, bColor, clickedTColor, clickedBColor, menuBar)
  14. -- prog_closeMenus(buttons, bColor, hColor, tColor, menuBar, invisible)
  15. -- prog_getMidOButton(buttonFX, buttonFY, buttonSX, buttonSY, text)
  16. -- prog_setProgName()
  17. -- prog_saveProject(buttons, progName, backgroundC, textC)
  18. -- prog_loadProject()
  19. -- prog_compileObjects(buttons, progName)
  20.  
  21. -- Tables
  22.  
  23. colorTable = {
  24. colors.white,
  25. colors.orange,
  26. colors.magenta,
  27. colors.lightBlue,
  28. colors.yellow,
  29. colors.lime,
  30. colors.pink,
  31. colors.gray,
  32. colors.lightGray,
  33. colors.cyan,
  34. colors.purple,
  35. colors.blue,
  36. colors.brown,
  37. colors.green,
  38. colors.red,
  39. colors.black
  40. };
  41.  
  42. -- Funktionen
  43.  
  44. function design_fillMon(letter, bColor, menuBar)
  45.  
  46. if menuBar then
  47.  
  48. start = 2;
  49.  
  50. else
  51.  
  52. start = 1;
  53.  
  54. end
  55.  
  56. for row = start,19 do
  57. for column = 1,51 do
  58. term.setTextColor(colors.lightGray);
  59. term.setBackgroundColor(bColor);
  60. term.setCursorPos(column, row);
  61. term.write(letter);
  62. end
  63. end
  64.  
  65. if not menuBar then
  66.  
  67. term.setCursorPos(26,1)
  68. term.write("L")
  69.  
  70. end
  71.  
  72. end
  73.  
  74. function design_redrawMonitor(buttons, bColor, hColor, tColor, menuBar, invisible)
  75.  
  76. term.clear();
  77.  
  78. local mainWindow = paintutils.loadImage(".mainWindow");
  79. paintutils.drawImage(mainWindow, 1, 1);
  80. design_fillMon("X", bColor, menuBar);
  81.  
  82. if not invisible then
  83.  
  84. design_drawButtons(buttons);
  85.  
  86. end
  87.  
  88. if menuBar then
  89.  
  90. term.setCursorPos(1,1);
  91. term.setBackgroundColor(hColor);
  92. term.setTextColor(tColor);
  93. term.write(" ");
  94.  
  95. term.setCursorPos(1,1);
  96. term.write("Datei Bearbeiten ^ ?");
  97. term.setBackgroundColor(colors.red);
  98. term.write("X");
  99. term.setBackgroundColor(bColor);
  100.  
  101. end
  102.  
  103. end
  104.  
  105. function design_dateiMenu(dateiOpen, tColor, hColor, bColor, buttons, menuBar, invisible)
  106.  
  107. if (not dateiOpen) then
  108.  
  109. design_redrawMonitor(buttons, bColor, hColor, tColor, menuBar, invisible);
  110.  
  111. term.setTextColor(tColor);
  112. term.setBackgroundColor(hColor);
  113. term.setCursorPos(1,2);
  114. term.write(" Neu ");
  115. term.setCursorPos(1,3);
  116. term.write(" Speichern ");
  117. term.setCursorPos(1,4);
  118. term.write(" Projekt speichern ");
  119. term.setCursorPos(1,5);
  120. term.write(" Projekt laden ");
  121.  
  122. return true;
  123.  
  124. else
  125.  
  126. design_redrawMonitor(buttons, bColor, hColor, tColor, menuBar, invisible);
  127.  
  128. return false;
  129.  
  130. end
  131.  
  132. end
  133.  
  134. function design_bearbeitenMenu(bearbeitenOpen, tColor, hColor, bColor, buttons, menuBar, invisible)
  135.  
  136. if (not bearbeitenOpen) then
  137.  
  138. design_redrawMonitor(buttons, bColor, hColor, tColor, menuBar, invisible);
  139.  
  140. term.setTextColor(tColor);
  141. term.setBackgroundColor(hColor);
  142. term.setCursorPos(7,2);
  143. term.write(" Rueckgaengig ");
  144. term.setCursorPos(7,3);
  145. term.write(" Einstellungen ");
  146.  
  147. return true;
  148.  
  149. else
  150.  
  151. design_redrawMonitor(buttons, bColor, hColor, tColor, menuBar, invisible);
  152.  
  153. return false;
  154.  
  155. end
  156.  
  157. end
  158.  
  159. function design_helpMenu(buttons, bColor, hColor, tColor, menuBar, invisible)
  160.  
  161. term.setBackgroundColor(colors.gray);
  162. term.setTextColor(colors.white);
  163. term.setCursorPos(11,4);
  164. term.write(" ");
  165. term.setBackgroundColor(colors.red);
  166. term.write("X");
  167. term.setBackgroundColor(colors.gray);
  168. term.setCursorPos(11,5);
  169. term.write(" Indem man 2x auf die ");
  170. term.setCursorPos(11,6);
  171. term.write(" Editierungszone klickt ");
  172. term.setCursorPos(11,7);
  173. term.write(" erstellt man einen Button. ");
  174. term.setCursorPos(11,8);
  175. term.write(" Unter Bearbeiten findet ");
  176. term.setCursorPos(11,9);
  177. term.write(" man ein Einstellungsmenue ");
  178. term.setCursorPos(11,10);
  179. term.write(" mit dem man die Farbe des ");
  180. term.setCursorPos(11,11);
  181. term.write(" spaeteren Programmes ");
  182. term.setCursorPos(11,12);
  183. term.write(" und dessen Textfarbe ");
  184. term.setCursorPos(11,13);
  185. term.write(" festlegen kann. ");
  186. term.setCursorPos(11,14);
  187. term.write(" L - Menu Bar aus/einklappen ");
  188. term.setCursorPos(11,15);
  189. term.write(" K - Buttons un/sichtbar ");
  190. term.setCursorPos(11,16);
  191. term.write(" ");
  192.  
  193. local waitForExit = true;
  194.  
  195. while (waitForExit) do
  196.  
  197. event, side, x, y = os.pullEvent("mouse_click");
  198.  
  199. if (x == 39 and y == 4) then
  200.  
  201. design_redrawMonitor(buttons, bColor, hColor, tColor, menuBar, invisible);
  202.  
  203. waitForExit = false;
  204.  
  205. end
  206.  
  207. end
  208.  
  209. end
  210.  
  211. function design_drawButtons(buttons)
  212.  
  213. buttonAttributes = 8;
  214. curTableNumber = 1;
  215.  
  216. if (#buttons == 0) then
  217.  
  218. return;
  219.  
  220. end
  221.  
  222. for i = 1, (#buttons / buttonAttributes) do
  223.  
  224. local buttonText = buttons[curTableNumber];
  225. local bColor = buttons[curTableNumber + 1];
  226. local tColor = buttons[curTableNumber + 2];
  227. local fXPos = buttons[curTableNumber + 3];
  228. local fYPos = buttons[curTableNumber + 4];
  229. local sXPos = buttons[curTableNumber + 5];
  230. local sYPos = buttons[curTableNumber + 6];
  231. local code = buttons[curTableNumber + 7];
  232.  
  233. for yPos = fYPos, sYPos do
  234.  
  235. for xPos = fXPos, sXPos do
  236.  
  237. term.setBackgroundColor(bColor)
  238. term.setCursorPos(xPos, yPos);
  239. term.write(" ");
  240.  
  241. end
  242.  
  243. end
  244.  
  245. x, y = prog_getMidOButton(fXPos, fYPos, sXPos, sYPos, buttonText);
  246. term.setTextColor(tColor);
  247. term.setCursorPos(x, y);
  248. term.write(buttonText);
  249.  
  250. curTableNumber = curTableNumber + 8;
  251.  
  252. end
  253.  
  254. end
  255.  
  256. function object_checkIfClicked(objectX, objectY, clickedX, clickedY)
  257.  
  258. local objectX_a = objectX[1];
  259. local objectX_b = objectX[2];
  260. local objectY_a = objectY[1];
  261. local objectY_b = objectY[2];
  262.  
  263. if (clickedX >= objectX_a and clickedX <= objectX_b) then
  264.  
  265. if (clickedY >= objectY_a and clickedY <= objectY_b) then
  266.  
  267. return true;
  268.  
  269. else
  270.  
  271. return false;
  272.  
  273. end
  274.  
  275. else
  276.  
  277. return false;
  278.  
  279. end
  280.  
  281. end
  282.  
  283. function object_undoLastObject(buttons, hColor, tColor, bColor, menuBar, invisible)
  284.  
  285. tableLength = #buttons;
  286.  
  287. for i = 1,8 do
  288.  
  289. table.remove(buttons, #buttons);
  290.  
  291. end
  292.  
  293. design_redrawMonitor(buttons, bColor, hColor, tColor, menuBar, invisible);
  294.  
  295. end
  296.  
  297. function prog_numberToColor(colorPos)
  298.  
  299. return colorTable[colorPos];
  300.  
  301. end
  302.  
  303. function prog_setButtonSettings(buttonFX, buttonSX)
  304.  
  305. backgroundC = colors.yellow;
  306. textC = colors.black;
  307. text = "";
  308. textSelected = false;
  309. settings = true;
  310. saved = false;
  311.  
  312. maxTextChars = buttonSX - buttonFX + 1;
  313.  
  314. term.setTextColor(colors.white);
  315. term.setBackgroundColor(colors.black);
  316. term.setCursorPos(1,1);
  317.  
  318. w, h = term.getSize();
  319.  
  320. for i = 5,15 do
  321.  
  322. for j = 5, w - 4 do
  323.  
  324. term.setBackgroundColor(colorTable[8]);
  325. term.setCursorPos(j, i);
  326. term.write(" ");
  327.  
  328. end
  329.  
  330. end
  331.  
  332. term.setBackgroundColor(colors.lightGray);
  333. term.setCursorPos(15,5);
  334. term.write(" Button Einstellungen ");
  335. term.setBackgroundColor(colors.gray);
  336. term.setCursorPos(33,9);
  337. term.write("Hintergrund");
  338. term.setCursorPos(33,12);
  339. term.write("Text Farbe");
  340. term.setCursorPos(14,8);
  341. term.write("Text");
  342. term.setCursorPos(8,9);
  343. term.write("maximal "..maxTextChars.." Zeichen");
  344. term.setBackgroundColor(colors.lightGray);
  345. term.setCursorPos(7,10);
  346. term.write(" ");
  347. term.setCursorPos(7,13);
  348. term.write(" OK ");
  349. term.setBackgroundColor(colors.gray);
  350. term.setCursorPos(47, 5);
  351. term.setBackgroundColor(colors.red);
  352. term.write("X");
  353. term.setBackgroundColor(colors.gray);
  354.  
  355. for i = 1, #colorTable do
  356.  
  357. term.setBackgroundColor(colorTable[i]);
  358. term.setCursorPos(i + 30, 10);
  359. term.write(" ");
  360.  
  361. term.setBackgroundColor(colorTable[i]);
  362. term.setCursorPos(i + 30, 13);
  363. term.write(" ");
  364.  
  365. end
  366.  
  367. while settings do
  368.  
  369. for i,v in pairs(colorTable) do
  370.  
  371. if backgroundC == v then
  372.  
  373. term.setBackgroundColor(colors.gray);
  374. term.setTextColor(colors.yellow);
  375. term.setCursorPos(i + 30, 11);
  376. term.write("^");
  377.  
  378. end
  379.  
  380. if textC == v then
  381.  
  382. term.setBackgroundColor(colors.gray);
  383. term.setTextColor(colors.yellow);
  384. term.setCursorPos(i + 30, 14);
  385. term.write("^");
  386.  
  387. end
  388.  
  389. end
  390.  
  391. if (textSelected) then
  392. term.setCursorPos(7 + string.len(text), 10);
  393. term.setCursorBlink(true);
  394. else
  395. term.setCursorBlink(false);
  396. end
  397.  
  398. event, side, x, y = os.pullEvent()
  399.  
  400. if event == "mouse_click" then
  401.  
  402. if x > 30 and x <= 46 and y == 10 then
  403.  
  404. term.setBackgroundColor(colors.gray);
  405. term.setCursorPos(31,11);
  406. term.write(" ");
  407. term.setCursorPos(31,14);
  408. term.write(" ");
  409.  
  410. backgroundC = colorTable[x - 30];
  411.  
  412. textSelected = false;
  413.  
  414. elseif x > 30 and x <= 46 and y == 13 then
  415.  
  416. term.setBackgroundColor(colors.gray);
  417. term.setCursorPos(31,11);
  418. term.write(" ");
  419. term.setCursorPos(31,14);
  420. term.write(" ");
  421.  
  422. textC = colorTable[x - 30];
  423.  
  424. textSelected = false;
  425.  
  426. elseif x >= 7 and x <= 26 and y == 10 then
  427.  
  428. textSelected = true;
  429.  
  430. elseif x >= 7 and x <= 11 and y == 13 then
  431.  
  432. settings = false;
  433. saved = true;
  434.  
  435. elseif x == 47 and y == 5 then
  436.  
  437. settings = false;
  438.  
  439. else
  440.  
  441. textSelected = false;
  442.  
  443. end
  444.  
  445. elseif event == "char" and textSelected then
  446.  
  447. if string.len(text) < maxTextChars then
  448.  
  449. text = text..side;
  450.  
  451. term.setBackgroundColor(colors.lightGray);
  452. term.setCursorPos(7,10);
  453. term.write(" ");
  454. term.setCursorPos(7,10);
  455. term.write(text);
  456. term.setCursorPos(7,11);
  457. term.setBackgroundColor(colors.gray);
  458. term.write(" ");
  459.  
  460. else
  461.  
  462. term.setCursorPos(7,11);
  463. term.setTextColor(colors.red);
  464. term.write("!Textlaenge erreicht");
  465.  
  466. end
  467.  
  468. elseif event == "key" and textSelected then
  469.  
  470. if side == 14 then
  471.  
  472. text = string.sub(text, 1, string.len(text) - 1);
  473.  
  474. term.setBackgroundColor(colors.lightGray);
  475. term.setCursorPos(7,10);
  476. term.write(" ");
  477. term.setCursorPos(7,10);
  478. term.write(text);
  479. term.setCursorPos(7,11);
  480. term.setBackgroundColor(colors.gray);
  481. term.write(" ");
  482.  
  483. end
  484.  
  485. end
  486.  
  487. end
  488.  
  489. return text,backgroundC,textC,saved;
  490.  
  491. end
  492.  
  493. function prog_changeSettings(buttons, hColor, tColor, bColor, clickedTColor, clickedBColor, menuBar, invisible)
  494.  
  495. local chooseTColorX = {17,32};
  496. local chooseTColorY = {12,12};
  497. local chooseBColorX = {17,32};
  498. local chooseBColorY = {9,9};
  499. local exitX = {33,33};
  500. local exitY = {7,7};
  501.  
  502. term.setBackgroundColor(colors.gray);
  503. term.setTextColor(colors.white);
  504. term.setCursorPos(16,7);
  505. term.write(" ");
  506. term.setBackgroundColor(colors.red);
  507. term.write("X");
  508. term.setBackgroundColor(colors.gray);
  509. term.setCursorPos(16,8);
  510. term.write(" Hintergrund: ");
  511. term.setCursorPos(16,9)
  512. term.write(" ");
  513. term.setCursorPos(17,9);
  514.  
  515. for i = 1,16 do
  516.  
  517. term.setBackgroundColor(colorTable[i]);
  518. term.write(" ");
  519.  
  520. end
  521.  
  522. term.setBackgroundColor(colors.gray);
  523. term.setCursorPos(16,10);
  524. term.write(" ");
  525. term.setCursorPos(16,11);
  526. term.write(" Text: ");
  527. term.setCursorPos(16,12)
  528. term.write(" ");
  529. term.setCursorPos(17,12);
  530.  
  531. for i = 1,16 do
  532.  
  533. term.setBackgroundColor(colorTable[i]);
  534. term.write(" ");
  535.  
  536. end
  537.  
  538. term.setBackgroundColor(colors.gray);
  539. term.setCursorPos(16,13);
  540. term.write(" ");
  541.  
  542. for k, v in pairs(colorTable) do
  543.  
  544. if (v == clickedTColor) then
  545.  
  546. term.setTextColor(colors.yellow);
  547. term.setCursorPos(16 + k, 13);
  548. term.write("^");
  549.  
  550. end
  551.  
  552. if (v == clickedBColor) then
  553.  
  554. term.setTextColor(colors.yellow);
  555. term.setCursorPos(16 + k, 10);
  556. term.write("^");
  557.  
  558. end
  559.  
  560. end
  561.  
  562. local waitForExit = true;
  563.  
  564. while (waitForExit) do
  565.  
  566. event, side, x, y = os.pullEvent("mouse_click");
  567.  
  568. if (object_checkIfClicked(chooseTColorX, chooseTColorY, x, y)) then
  569.  
  570. clickedTColor = colorTable[x - 16];
  571.  
  572. for k, v in pairs(colorTable) do
  573.  
  574. if (v == clickedTColor) then
  575.  
  576. term.setCursorPos(17,13);
  577. term.write(" ");
  578. term.setTextColor(colors.yellow);
  579. term.setCursorPos(16 + k, 13);
  580. term.write("^");
  581.  
  582. end
  583.  
  584. if (v == clickedBColor) then
  585.  
  586. term.setCursorPos(17,10);
  587. term.write(" ");
  588. term.setTextColor(colors.yellow);
  589. term.setCursorPos(16 + k, 10);
  590. term.write("^");
  591.  
  592. end
  593.  
  594. end
  595.  
  596. elseif (object_checkIfClicked(chooseBColorX, chooseBColorY, x, y)) then
  597.  
  598. clickedBColor = colorTable[x - 16];
  599.  
  600. for k, v in pairs(colorTable) do
  601.  
  602. if (v == clickedTColor) then
  603.  
  604. term.setCursorPos(17,13);
  605. term.write(" ");
  606. term.setTextColor(colors.yellow);
  607. term.setCursorPos(16 + k, 13);
  608. term.write("^");
  609.  
  610. end
  611.  
  612. if (v == clickedBColor) then
  613.  
  614. term.setCursorPos(17,10);
  615. term.write(" ");
  616. term.setTextColor(colors.yellow);
  617. term.setCursorPos(16 + k, 10);
  618. term.write("^");
  619.  
  620. end
  621.  
  622. end
  623.  
  624. elseif (object_checkIfClicked(exitX, exitY, x, y)) then
  625.  
  626. waitForExit = false;
  627.  
  628. end
  629.  
  630. end
  631.  
  632. design_redrawMonitor(buttons, bColor, hColor, tColor, menuBar, invisible);
  633.  
  634. return clickedTColor, clickedBColor;
  635.  
  636. end
  637.  
  638. function prog_closeMenus(buttons, bColor, hColor, tColor, menuBar, invisible)
  639.  
  640. design_fillMon("X", bColor, menuBar);
  641.  
  642. if not invisible then
  643.  
  644. design_drawButtons(buttons);
  645.  
  646. end
  647.  
  648. if menuBar then
  649.  
  650. term.setCursorPos(1,1);
  651. term.setBackgroundColor(hColor);
  652. term.setTextColor(tColor);
  653. term.write(" ");
  654.  
  655. term.setCursorPos(1,1);
  656. term.write("Datei Bearbeiten ^ ?");
  657. term.setBackgroundColor(colors.red);
  658. term.write("X");
  659. term.setBackgroundColor(bColor);
  660.  
  661. end
  662.  
  663. return false, false;
  664.  
  665. end
  666.  
  667. function prog_getMidOButton(buttonFX, buttonFY, buttonSX, buttonSY, text)
  668.  
  669. local buttonSizeX = buttonSX - buttonFX;
  670. local buttonSizeY = buttonSY - buttonFY;
  671.  
  672. if (buttonSizeY % 2) then
  673.  
  674. buttonSizeY = buttonSizeY - 1;
  675.  
  676. end
  677.  
  678. local y = buttonFY + math.ceil(buttonSizeY / 2);
  679. local x = buttonFX + math.ceil((buttonSizeX / 2) - (text:len() / 2));
  680.  
  681. return x, y;
  682.  
  683. end
  684.  
  685. function prog_setProgName()
  686.  
  687. term.setBackgroundColor(colors.gray);
  688. term.setTextColor(colors.white);
  689. term.setCursorPos(14,7);
  690. term.write(" ");
  691. term.setCursorPos(14,8);
  692. term.write(" ");
  693. term.setCursorPos(14,9);
  694. term.write(" Programmname: ");
  695. term.setCursorPos(14,10);
  696. term.write(" ");
  697. term.setCursorPos(14,11);
  698. term.write(" ");
  699. term.setCursorPos(14,12);
  700. term.write(" ");
  701.  
  702. term.setCursorPos(15,10);
  703. progName = read();
  704.  
  705. if (text == "") then
  706.  
  707. prog_setProgName();
  708.  
  709. end
  710.  
  711. return progName;
  712.  
  713. end
  714.  
  715. function prog_saveProject(buttons, progName, backgroundC, textC)
  716.  
  717. saved = false;
  718.  
  719. term.setBackgroundColor(colors.gray);
  720. term.setTextColor(colors.white);
  721. term.setCursorPos(14,7);
  722. term.write(" ");
  723. term.setCursorPos(14,8);
  724. term.write(" ");
  725. term.setCursorPos(14,9);
  726. term.write(" Programmname: ");
  727. term.setCursorPos(14,10);
  728. term.write(" ");
  729. term.setCursorPos(14,11);
  730. term.write(" ");
  731. term.setCursorPos(14,12);
  732. term.write(" ");
  733.  
  734. term.setCursorPos(15,10);
  735. projectName = read();
  736.  
  737. if (projectName ~= "") then
  738.  
  739. projectTable = {};
  740. table.insert(projectTable, 1, progName);
  741. table.insert(projectTable, 2, backgroundC);
  742. table.insert(projectTable, 3, textC);
  743. table.insert(projectTable, 4, buttons);
  744.  
  745. file = fs.open(projectName, "w");
  746.  
  747. file.write(textutils.serialise(projectTable));
  748. file.close();
  749.  
  750. saved = true;
  751.  
  752. end
  753.  
  754. return saved;
  755.  
  756. end
  757.  
  758. function prog_loadProject()
  759.  
  760. progs = fs.list("/");
  761. visibleProgs = {};
  762. choosedProject = "";
  763.  
  764. visibleS = 1;
  765. scrollBarY = 7;
  766. scrollBarX = 15;
  767. scrollBarMaxLen = 20;
  768. loading = true;
  769.  
  770. for i = scrollBarY - 1, scrollBarY + 5 do
  771.  
  772. for j = scrollBarX - 1, scrollBarX + scrollBarMaxLen do
  773.  
  774. term.setBackgroundColor(colors.gray);
  775. term.setCursorPos(j,i);
  776. term.write(" ");
  777.  
  778. end
  779.  
  780. end
  781.  
  782. term.setCursorPos(scrollBarX, scrollBarY - 1);
  783. term.write("Laden:");
  784. term.setBackgroundColor(colors.red);
  785. term.setCursorPos(scrollBarX + scrollBarMaxLen, scrollBarY - 1);
  786. term.write("X");
  787.  
  788. while loading do
  789.  
  790. for i,v in pairs(progs) do
  791.  
  792. visibleProgs = {};
  793.  
  794. for i = visibleS, visibleS + 4 do
  795.  
  796. curProg = progs[i];
  797.  
  798. if string.len(curProg) > scrollBarMaxLen then
  799.  
  800. curProg = string.sub(curProg, 1, scrollBarMaxLen);
  801.  
  802. end
  803.  
  804. table.insert(visibleProgs, curProg);
  805.  
  806. end
  807.  
  808. for i = scrollBarY, scrollBarY + 4 do
  809.  
  810. for j = 0, scrollBarMaxLen - 1 do
  811.  
  812. term.setCursorPos(scrollBarX + j, i);
  813. term.write(" ");
  814.  
  815. end
  816.  
  817. end
  818.  
  819. term.setBackgroundColor(colors.lightGray);
  820. term.setCursorPos(scrollBarX - 1, scrollBarY - 1);
  821. term.write("");
  822. term.setTextColor(colors.gray)
  823. term.setCursorPos(scrollBarX,scrollBarY);
  824. term.write(visibleProgs[1]);
  825. term.setCursorPos(scrollBarX,scrollBarY + 1);
  826. term.write(visibleProgs[2]);
  827. term.setCursorPos(scrollBarX,scrollBarY + 2);
  828. term.write(visibleProgs[3]);
  829. term.setCursorPos(scrollBarX,scrollBarY + 3);
  830. term.write(visibleProgs[4]);
  831. term.setCursorPos(scrollBarX,scrollBarY + 4);
  832. term.write(visibleProgs[5]);
  833.  
  834. end
  835.  
  836. event, side, x, y = os.pullEvent()
  837.  
  838. if event == "mouse_click" then
  839.  
  840. if x >= scrollBarX and x <= 50 and y >= scrollBarY and y <= scrollBarY + 4 then
  841.  
  842. -- Clicked program: progs[(y - scrollBarY) + visibleS]
  843. -- Ausgewähltes Programm: progs[(y - scrollBarY) + visibleS]
  844.  
  845. term.setTextColor(colors.white);
  846. term.setCursorPos(1,15);
  847. term.write(" ");
  848. term.setCursorPos(1,15);
  849. term.write(progs[(y - scrollBarY) + visibleS]);
  850.  
  851. loading = false;
  852. choosedProject = progs[(y - scrollBarY) + visibleS];
  853.  
  854. elseif x == scrollBarX + scrollBarMaxLen and y == scrollBarY - 1 then
  855.  
  856. loading = false;
  857.  
  858. end
  859.  
  860. elseif event == "mouse_scroll" then
  861.  
  862. if side == -1 then
  863.  
  864. if visibleS > 1 then
  865. visibleS = visibleS - 1;
  866. end
  867.  
  868. elseif side == 1 then
  869.  
  870. if visibleS < (#progs - 4) then
  871.  
  872. visibleS = visibleS + 1;
  873.  
  874. end
  875.  
  876. end
  877.  
  878. end
  879.  
  880. end
  881.  
  882. return choosedProject;
  883.  
  884. end
  885.  
  886. function prog_tableReverse(tableName)
  887.  
  888. newTable = {};
  889. currentIndex = #tableName;
  890. counter = 1;
  891.  
  892. for i = 1, #tableName / 8 do
  893.  
  894. table.insert(newTable, counter, tableName[currentIndex - 7]);
  895. table.insert(newTable, counter + 1, tableName[currentIndex - 6]);
  896. table.insert(newTable, counter + 2, tableName[currentIndex - 5]);
  897. table.insert(newTable, counter + 3, tableName[currentIndex - 4]);
  898. table.insert(newTable, counter + 4, tableName[currentIndex - 3]);
  899. table.insert(newTable, counter + 5, tableName[currentIndex - 2]);
  900. table.insert(newTable, counter + 6, tableName[currentIndex - 1]);
  901. table.insert(newTable, counter + 7, tableName[currentIndex]);
  902.  
  903. counter = counter + 8;
  904. currentIndex = currentIndex - 8;
  905.  
  906. end
  907.  
  908. return newTable;
  909.  
  910. end
  911.  
  912. function prog_compileObjects(buttons, progName, backgroundC, textC)
  913.  
  914. buttonAttributes = 8;
  915. curTableNumber = 1;
  916.  
  917. if (#buttons == 0) then
  918.  
  919. return;
  920.  
  921. end
  922.  
  923. file = fs.open(progName, "w");
  924.  
  925. file.writeLine("-- Variablen");
  926. file.writeLine("");
  927. file.writeLine("background = " .. backgroundC .. ";");
  928. file.writeLine("textcolor = " .. textC .. ";");
  929. file.writeLine("")
  930. file.writeLine("-- Design");
  931. file.writeLine("");
  932. file.writeLine("term.setBackgroundColor(background);");
  933. file.writeLine("term.setTextColor(textcolor);");
  934. file.writeLine("term.clear();");
  935. file.writeLine("term.setCursorPos(1,1);");
  936. file.writeLine("");
  937.  
  938. for i = 1, (#buttons / buttonAttributes) do
  939.  
  940. local buttonText = buttons[curTableNumber];
  941. local bColor = buttons[curTableNumber + 1];
  942. local tColor = buttons[curTableNumber + 2];
  943. local fXPos = buttons[curTableNumber + 3];
  944. local fYPos = buttons[curTableNumber + 4];
  945. local sXPos = buttons[curTableNumber + 5];
  946. local sYPos = buttons[curTableNumber + 6];
  947. local code = buttons[curTableNumber + 7];
  948.  
  949. x, y = prog_getMidOButton(fXPos, fYPos, sXPos, sYPos, buttonText);
  950.  
  951. file.writeLine("for yPos = " .. fYPos .. ", " .. sYPos .. " do");
  952. file.writeLine("");
  953. file.writeLine(" for xPos = " .. fXPos .. ", " .. sXPos .. " do");
  954. file.writeLine("");
  955. file.writeLine(" term.setBackgroundColor(" .. bColor .. ");");
  956. file.writeLine(" term.setCursorPos(xPos, yPos);");
  957. file.writeLine(" term.write(\" \");");
  958. file.writeLine("");
  959. file.writeLine(" end");
  960. file.writeLine("");
  961. file.writeLine("end");
  962. file.writeLine("");
  963. file.writeLine("term.setTextColor(" .. tColor .. ");");
  964. file.writeLine("term.setCursorPos(" .. x .. ", " .. y .. ");");
  965. file.writeLine("term.write(\"" .. buttonText .. "\");");
  966. file.writeLine("")
  967.  
  968. curTableNumber = curTableNumber + 8;
  969.  
  970. end
  971.  
  972. buttons = prog_tableReverse(buttons)
  973.  
  974. file.writeLine("-- Programmtechnisch");
  975. file.writeLine("");
  976. file.writeLine("term.setCursorPos(1,1);");
  977. file.writeLine("term.setBackgroundColor(colors.black);");
  978. file.writeLine("term.setTextColor(colors.white);");
  979. file.writeLine("");
  980. file.writeLine("while true do");
  981. file.writeLine("");
  982. file.writeLine("event, side, x, y = os.pullEvent(\"mouse_click\");");
  983. file.writeLine("")
  984.  
  985. curTableNumber = 1;
  986. curButton = 1;
  987.  
  988. for i = 1, (#buttons / buttonAttributes) do
  989.  
  990. local buttonText = buttons[curTableNumber];
  991. local bColor = buttons[curTableNumber + 1];
  992. local tColor = buttons[curTableNumber + 2];
  993. local fXPos = buttons[curTableNumber + 3];
  994. local fYPos = buttons[curTableNumber + 4];
  995. local sXPos = buttons[curTableNumber + 5];
  996. local sYPos = buttons[curTableNumber + 6];
  997. local code = buttons[curTableNumber + 7];
  998.  
  999. if (curButton == 1) then
  1000. file.writeLine("if (x >= " .. fXPos .. " and x <= " .. sXPos .. " and y >= " .. fYPos .. " and y <= " .. sYPos .. ") then");
  1001. file.writeLine("");
  1002. else
  1003. file.writeLine("elseif (x >= " .. fXPos .. " and x <= " .. sXPos .. " and y >= " .. fYPos .. " and y <= " .. sYPos .. ") then");
  1004. file.writeLine("");
  1005. end
  1006.  
  1007. file.writeLine("-- Programmcode von X: \{".. fXPos ..",".. sXPos .."\} Y: \{".. fYPos ..",".. sYPos .."\} Text: ".. buttonText);
  1008. file.writeLine("");
  1009. file.writeLine(code);
  1010. file.writeLine("");
  1011.  
  1012. curTableNumber = curTableNumber + 8;
  1013. curButton = curButton + 1;
  1014.  
  1015. end
  1016.  
  1017. file.writeLine("end");
  1018. file.writeLine("");
  1019. file.writeLine("end");
  1020. file.writeLine("");
  1021. file.writeLine("-- File created by ButtonCreator-V2.2");
  1022. file.close();
  1023.  
  1024. end
  1025.  
  1026. -- Scripted by Streetboy_xD
  1027. -- Please keep this text in the program.
Advertisement
Add Comment
Please, Sign In to add comment