Streetboy_xD

[Computercraft] ButtonCreator Programm V2.3

Dec 7th, 2015 (edited)
447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.40 KB | None | 0 0
  1. -- APIs
  2.  
  3.  
  4. os.loadAPI("functionsAPI");
  5.  
  6.  
  7. -- Variablen
  8.  
  9. setNewButton    = false;            -- Kann ein neuer Knopf gesetzt werden?
  10. fXPos = 0;                          -- First X Position
  11. sXPos = 0;                          -- Second X Position
  12. fYPos = 0;                          -- First Y Position
  13. sYPos = 0;                          -- Second Y Position
  14.  
  15. dateiOpen       = false;            -- Ist Datei geöffnet?
  16. bearbeitenOpen  = false;            -- Ist Bearbeiten geöffnet?
  17. progName        = "newButtonProg";  -- Programmname
  18. tColor          = colors.white;     -- Text Color
  19. hColor          = colors.gray;      -- Header (Kopfzeile) Color
  20. bColor          = colors.white;     -- Background Color
  21. userBackground  = colors.black;     -- Hintergrund in den Einstellungen
  22. userTextColor   = colors.white;     -- Text Farbe in den Einstellungen
  23. menuBar         = true;             -- Menu Bar ausgeklappt?
  24. invisible       = false;            -- Knöpfe sichtbar?
  25.  
  26. buttonsTable            = {};       -- Button Tabelle
  27.  
  28. -- local Knöpfe Koords
  29.    
  30.    
  31. dateiX = {1, 5};
  32. dateiY = {1, 1};
  33. bearbeitenX = {7, 16};
  34. bearbeitenY = {1, 1};
  35. foldMenuX = {48, 48};
  36. foldMenuY = {1, 1};
  37. neuX = {1, 19};
  38. neuY = {2, 2};
  39. speichernX = {1, 19};
  40. speichernY = {3, 3};
  41. projektSpeichernX = {1,19};
  42. projektSpeichernY = {4,4};
  43. projektLadenX = {1,19};
  44. projektLadenY = {5,5};
  45. undoX = {7, 19};
  46. undoY = {2, 2};
  47. optionsX = {7, 19};
  48. optionsY = {3, 3};
  49. quitX = {51, 51};
  50. quitY = {1, 1};
  51. helpX = {50, 50};
  52. helpY = {1, 1};
  53.  
  54. -- Grafischer Teil
  55.  
  56.  
  57. term.clear();
  58.  
  59. mainWindow = paintutils.loadImage(".mainWindow");
  60. paintutils.drawImage(mainWindow, 1, 1);
  61.  
  62. progName = functionsAPI.prog_setProgName();
  63. functionsAPI.design_fillMon("X", bColor, menuBar);
  64.  
  65. if menuBar then
  66.  
  67.     term.setCursorPos(1,1);
  68.     term.setBackgroundColor(hColor);
  69.     term.setTextColor(tColor)
  70.     term.write("                                                   ");
  71.  
  72.     term.setCursorPos(1,1);
  73.     term.write("Datei Bearbeiten                               ^ ?");
  74.     term.setBackgroundColor(colors.red);
  75.     term.write("X");
  76.     term.setBackgroundColor(bColor);
  77.  
  78. end
  79.    
  80. -- Programmtechnischer Teil
  81.  
  82. while true do
  83.  
  84.     event, side, x, y = os.pullEvent();
  85.    
  86.     if (event == "mouse_click") then
  87.        
  88.         if (functionsAPI.object_checkIfClicked(dateiX, dateiY, x, y) and menuBar) then
  89.        
  90.             if (bearbeitenOpen) then
  91.                 bearbeitenOpen = false;
  92.             end
  93.            
  94.             dateiOpen = functionsAPI.design_dateiMenu(dateiOpen, tColor, hColor, bColor, buttonsTable, menuBar, invisible);
  95.            
  96.             setNewButton = false;
  97.  
  98.         elseif (functionsAPI.object_checkIfClicked(bearbeitenX, bearbeitenY, x, y) and menuBar) then
  99.            
  100.             if (dateiOpen) then
  101.                 dateiOpen = false;
  102.             end
  103.                
  104.             bearbeitenOpen = functionsAPI.design_bearbeitenMenu(bearbeitenOpen, tColor, hColor, bColor, buttonsTable, menuBar, invisible);
  105.            
  106.             setNewButton = false;
  107.  
  108.         elseif (functionsAPI.object_checkIfClicked(foldMenuX, foldMenuY, x, y) and menuBar) then
  109.            
  110.             menuBar = false;
  111.             functionsAPI.design_redrawMonitor(buttonsTable, bColor, hColor, tColor, menuBar, invisible);
  112.            
  113.         elseif (functionsAPI.object_checkIfClicked(neuX, neuY, x, y) and dateiOpen) then
  114.        
  115.             setNewButton    = false;
  116.             fXPos           = 0;
  117.             sXPos           = 0;
  118.             fYPos           = 0;
  119.             sYPos           = 0;
  120.  
  121.             dateiOpen       = false;
  122.             bearbeitenOpen  = false;
  123.             progName        = "";
  124.             progCode        = "";
  125.        
  126.             buttonsTable    = {};
  127.            
  128.             progName = functionsAPI.prog_setProgName();
  129.             dateiOpen,bearbeitenOpen = functionsAPI.prog_closeMenus(buttonsTable, bColor, hColor, tColor, menuBar, invisible);
  130.            
  131.         elseif (functionsAPI.object_checkIfClicked(speichernX, speichernY, x, y) and dateiOpen) then
  132.        
  133.             functionsAPI.prog_compileObjects(buttonsTable, progName, userBackground, userTextColor);
  134.             dateiOpen,bearbeitenOpen = functionsAPI.prog_closeMenus(buttonsTable, bColor, hColor, tColor, menuBar, invisible);
  135.            
  136.             term.setBackgroundColor(colors.gray);
  137.             term.setCursorPos(36,1)
  138.             term.write("Gespeichert");
  139.        
  140.         elseif (functionsAPI.object_checkIfClicked(projektSpeichernX, projektSpeichernY, x, y) and dateiOpen) then
  141.        
  142.             saved = functionsAPI.prog_saveProject(buttonsTable, progName, userBackground, userTextColor);
  143.             dateiOpen,bearbeitenOpen = functionsAPI.prog_closeMenus(buttonsTable, bColor, hColor, tColor, menuBar, invisible);
  144.            
  145.             if saved then
  146.            
  147.                 term.setBackgroundColor(colors.gray);
  148.                 term.setCursorPos(28,1)
  149.                 term.write("Projekt gespeichert");
  150.                
  151.             else
  152.            
  153.                 term.setBackgroundColor(colors.gray);
  154.                 term.setCursorPos(33,1)
  155.                 term.write("Fehlgeschlagen");
  156.            
  157.             end
  158.        
  159.         elseif (functionsAPI.object_checkIfClicked(projektLadenX, projektLadenY, x, y) and dateiOpen) then
  160.        
  161.             choosedProject = "";
  162.        
  163.             choosedProject = functionsAPI.prog_loadProject();
  164.            
  165.             if choosedProject == "" then
  166.            
  167.                 dateiOpen,bearbeitenOpen = functionsAPI.prog_closeMenus(buttonsTable, bColor, hColor, tColor, menuBar, invisible);
  168.            
  169.             else
  170.            
  171.                 file = fs.open(choosedProject, "r");
  172.                 fileCode = textutils.unserialise(file.readAll());
  173.                
  174.                 if (fileCode ~= nil) and (fileCode[1] ~= nil) then
  175.                
  176.                     progName = fileCode[1];
  177.                     userBackground = fileCode[2];
  178.                     userTextColor = fileCode[3];
  179.                     buttonsTable = fileCode[4];
  180.                    
  181.                     dateiOpen,bearbeitenOpen = functionsAPI.prog_closeMenus(buttonsTable, bColor, hColor, tColor, menuBar, invisible);
  182.                    
  183.                     term.setBackgroundColor(colors.gray)
  184.                     term.setCursorPos(32,1);
  185.                     term.write("Projekt geladen");
  186.                    
  187.                 else
  188.                
  189.                     dateiOpen,bearbeitenOpen = functionsAPI.prog_closeMenus(buttonsTable, bColor, hColor, tColor, menuBar, invisible);
  190.                    
  191.                     term.setBackgroundColor(colors.gray);
  192.                     term.setCursorPos(27,1);
  193.                     term.write("Laden fehlgeschlagen");
  194.                    
  195.                 end
  196.                
  197.                 file.close()
  198.            
  199.             end
  200.        
  201.         elseif (functionsAPI.object_checkIfClicked(undoX, undoY, x, y) and bearbeitenOpen) then
  202.        
  203.             functionsAPI.object_undoLastObject(buttonsTable, hColor, tColor, bColor, menuBar, invisible);
  204.             dateiOpen,bearbeitenOpen = functionsAPI.prog_closeMenus(buttonsTable, bColor, hColor, tColor, menuBar, invisible);
  205.            
  206.         elseif (functionsAPI.object_checkIfClicked(optionsX, optionsY, x, y) and bearbeitenOpen) then
  207.  
  208.             userTextColor, userBackground = functionsAPI.prog_changeSettings(buttonsTable, hColor, tColor, bColor, userTextColor, userBackground, menuBar, invisible);
  209.             dateiOpen,bearbeitenOpen = functionsAPI.prog_closeMenus(buttonsTable, bColor, hColor, tColor, menuBar, invisible);
  210.        
  211.         elseif (functionsAPI.object_checkIfClicked(quitX, quitY, x, y) and menuBar) then
  212.        
  213.             term.setBackgroundColor(colors.black);
  214.             term.setTextColor(colors.white);
  215.             term.clear();
  216.             term.setCursorPos(1,1);
  217.             term.write("Danke, fuer das benutzen des ButtonCreators! :-\)");
  218.             term.setCursorPos(1,2);
  219.        
  220.             break;
  221.        
  222.         elseif (functionsAPI.object_checkIfClicked(helpX, helpY, x, y) and menuBar) then
  223.        
  224.             functionsAPI.design_helpMenu(buttonsTable, bColor, hColor, tColor, menuBar);
  225.        
  226.         else
  227.        
  228.             if ((y ~= 1 and menuBar) or (not menuBar)) then
  229.        
  230.                 if (setNewButton == false) then
  231.                
  232.                     dateiOpen,bearbeitenOpen = functionsAPI.prog_closeMenus(buttonsTable, bColor, hColor, tColor, menuBar, invisible);
  233.                
  234.                     fXPos = x;
  235.                     fYPos = y;
  236.                    
  237.                     term.setCursorPos(x,y);
  238.                     term.setTextColor(colors.black);
  239.                     term.setBackgroundColor(bColor);
  240.                     term.write("X");
  241.                     term.setTextColor(tColor);
  242.                    
  243.                     setNewButton = true;
  244.                
  245.                 elseif (setNewButton == true) then
  246.                
  247.                     sXPos           = x;
  248.                     sYPos           = y;
  249.                     tempButtonTable = {};
  250.                     buttonText      = "";
  251.                     buttonColor     = "";
  252.                    
  253.                     term.setCursorPos(x,y);
  254.                     term.setTextColor(colors.black);
  255.                     term.setBackgroundColor(bColor);
  256.                     term.write("X");
  257.                     term.setTextColor(tColor);
  258.                    
  259.                     --if (fXPos ~= sXPos and fYPos ~= sYPos) then
  260.                    
  261.                         if (fXPos > sXPos) then
  262.                        
  263.                             local newFXPos  = sXPos;
  264.                             sXPos           = fXPos;
  265.                             fXPos           = newFXPos;
  266.                            
  267.                         end
  268.                        
  269.                         if (fYPos > sYPos) then
  270.                        
  271.                             local newFYPos  = sYPos;
  272.                             sYPos           = fYPos;
  273.                             fYPos           = newFYPos;
  274.                            
  275.                         end
  276.                        
  277.                         local saved = false
  278.            
  279.                         buttonText, buttonColor, buttonTextColor, saved = functionsAPI.prog_setButtonSettings(fXPos, sXPos);
  280.                        
  281.                         if saved then
  282.                            
  283.                             table.insert(tempButtonTable, 1, buttonText);
  284.                             table.insert(tempButtonTable, 2, buttonColor);
  285.                             table.insert(tempButtonTable, 3, buttonTextColor);
  286.                             functionsAPI.design_redrawMonitor(buttonsTable, bColor, hColor, tColor, menuBar, invisible);
  287.                             shell.run("edit temp.lua");
  288.                            
  289.                             table.insert(tempButtonTable, 4, fXPos);
  290.                             table.insert(tempButtonTable, 5, fYPos);
  291.                             table.insert(tempButtonTable, 6, sXPos);
  292.                             table.insert(tempButtonTable, 7, sYPos);
  293.                            
  294.                             if fs.exists("temp.lua") then
  295.                            
  296.                                 file = fs.open("temp.lua","r");
  297.                                 tempCode = file.readAll();
  298.                                 file.close()
  299.                                
  300.                                 fs.delete("temp.lua");
  301.                            
  302.                                 table.insert(tempButtonTable, 8, tempCode);                            
  303.                                 table.insert(buttonsTable, tempButtonTable[1]);
  304.                                 table.insert(buttonsTable, tempButtonTable[2]);
  305.                                 table.insert(buttonsTable, tempButtonTable[3]);
  306.                                 table.insert(buttonsTable, tempButtonTable[4]);
  307.                                 table.insert(buttonsTable, tempButtonTable[5]);
  308.                                 table.insert(buttonsTable, tempButtonTable[6]);
  309.                                 table.insert(buttonsTable, tempButtonTable[7]);
  310.                                 table.insert(buttonsTable, tempButtonTable[8]);
  311.                                
  312.                             end
  313.                            
  314.                             functionsAPI.design_redrawMonitor(buttonsTable, bColor, hColor, tColor, menuBar, invisible);
  315.                            
  316.                             setNewButton = false;
  317.                            
  318.                         else
  319.                                
  320.                             setNewButton = false;
  321.                             functionsAPI.design_redrawMonitor(buttonsTable, bColor, hColor, tColor, menuBar, invisible);
  322.                            
  323.                         end
  324.                
  325.                     --[[else
  326.                    
  327.                         setNewButton = false;
  328.                         functionsAPI.design_redrawMonitor(buttonsTable, bColor, hColor, tColor, menuBar, invisible);
  329.                
  330.                     end]]--
  331.                    
  332.                 end
  333.                
  334.             end
  335.        
  336.         end
  337.        
  338.     elseif (event == "char") then
  339.    
  340.         if (side == "l") then
  341.        
  342.             if not menuBar then
  343.                 menuBar = true;
  344.             else
  345.                 menuBar = false;
  346.             end
  347.            
  348.             functionsAPI.design_redrawMonitor(buttonsTable, bColor, hColor, tColor, menuBar, invisible);
  349.        
  350.         elseif (side == "k") then
  351.        
  352.             if invisible then
  353.                 invisible = false;
  354.             else
  355.                 invisible = true;
  356.             end
  357.            
  358.             functionsAPI.design_redrawMonitor(buttonsTable, bColor, hColor, tColor, menuBar, invisible);
  359.        
  360.         end
  361.        
  362.     end
  363.    
  364. end
  365.  
  366. -- Scripted by Streetboy_xD
  367. -- Please keep this text in the program.
Add Comment
Please, Sign In to add comment