Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Alle Funktionen
- -- design_fillMon(letter, bColor)
- -- design_redrawMonitor(buttons, bColor, hColor, tColor)
- -- design_dateiMenu(dateiOpen, tColor, hColor, bColor)
- -- design_drawButtons(buttons)
- -- object_checkIfClicked(objectX, objectY, clickedX, clickedY)
- -- prog_numberToColor(colorPos)
- -- prog_setButtonName()
- -- prog_setButtonBColor()
- -- prog_setButtonTColor()
- -- prog_closeMenus(buttons, bColor)
- -- prog_getMidOButton(buttonFX, buttonFY, buttonSX, buttonSY, text)
- -- prog_setProgName()
- -- prog_compileObjects(buttons, progName)
- -- Tables
- colorTable = {
- colors.white,
- colors.orange,
- colors.magenta,
- colors.lightBlue,
- colors.yellow,
- colors.lime,
- colors.pink,
- colors.gray,
- colors.lightGray,
- colors.cyan,
- colors.purple,
- colors.blue,
- colors.brown,
- colors.green,
- colors.red,
- colors.black
- };
- -- Funktionen
- function design_fillMon(letter, bColor)
- for row = 2,19 do
- for column = 1,51 do
- term.setTextColor(colors.lightGray);
- term.setBackgroundColor(bColor);
- term.setCursorPos(column, row);
- term.write(letter);
- end
- end
- end
- function design_redrawMonitor(buttons, bColor, hColor, tColor)
- term.clear();
- local mainWindow = paintutils.loadImage(".mainWindow");
- paintutils.drawImage(mainWindow, 1, 1);
- design_fillMon("X", bColor);
- term.setCursorPos(1,1);
- term.setBackgroundColor(hColor);
- term.setTextColor(tColor);
- term.write(" ");
- term.setCursorPos(1,1);
- term.write("Datei Bearbeiten ?");
- design_drawButtons(buttons);
- end
- function design_dateiMenu(dateiOpen, tColor, hColor, bColor)
- if (not dateiOpen) then
- term.setTextColor(tColor);
- term.setBackgroundColor(hColor);
- term.setCursorPos(1,2);
- term.write("Neu ");
- term.setCursorPos(1,3);
- term.write("Speichern");
- return true;
- else
- term.setBackgroundColor(bColor);
- term.setTextColor(colors.lightGray);
- term.setCursorPos(1,2);
- term.write("XXXXXXXXX");
- term.setCursorPos(1,3);
- term.write("XXXXXXXXX");
- term.setCursorPos(1,4);
- term.write("XXXXXXXXX");
- term.setTextColor(tColor);
- return false;
- end
- end
- function design_drawButtons(buttons)
- buttonAttributes = 8;
- curTableNumber = 1;
- if (#buttons == 0) then
- return;
- end
- for i = 1, (#buttons / buttonAttributes) do
- local buttonText = buttons[curTableNumber];
- local bColor = buttons[curTableNumber + 1];
- local tColor = buttons[curTableNumber + 2];
- local fXPos = buttons[curTableNumber + 3];
- local fYPos = buttons[curTableNumber + 4];
- local sXPos = buttons[curTableNumber + 5];
- local sYPos = buttons[curTableNumber + 6];
- local code = buttons[curTableNumber + 7];
- for yPos = fYPos, sYPos do
- for xPos = fXPos, sXPos do
- term.setBackgroundColor(bColor)
- term.setCursorPos(xPos, yPos);
- term.write(" ");
- end
- end
- x, y = prog_getMidOButton(fXPos, fYPos, sXPos, sYPos, buttonText);
- term.setTextColor(tColor);
- term.setCursorPos(x, y);
- term.write(buttonText);
- curTableNumber = curTableNumber + 8;
- end
- end
- function object_checkIfClicked(objectX, objectY, clickedX, clickedY)
- local objectX_a = objectX[1];
- local objectX_b = objectX[2];
- local objectY_a = objectY[1];
- local objectY_b = objectY[2];
- if (clickedX >= objectX_a and clickedX <= objectX_b) then
- if (clickedY >= objectY_a and clickedY <= objectY_b) then
- return true;
- else
- return false;
- end
- else
- return false;
- end
- end
- function prog_numberToColor(colorPos)
- return colorTable[colorPos];
- end
- function prog_setButtonName(buttonFX, buttonSX)
- maxTextChars = buttonSX - buttonFX
- term.setBackgroundColor(colors.gray);
- term.setTextColor(colors.white);
- term.setCursorPos(14,7);
- term.write(" ");
- term.setCursorPos(14,8);
- term.write(" ");
- term.setCursorPos(14,9);
- term.write(" Button Text: ");
- term.setCursorPos(14,10);
- term.write(" ");
- term.setCursorPos(14,11);
- term.write(" ");
- term.setCursorPos(14,12);
- term.write(" ");
- term.setCursorPos(18,8)
- term.write("Maximal " .. tostring(maxTextChars) .. " Zeichen");
- term.setCursorPos(14,10);
- text = read();
- if (text:len() > maxTextChars) then
- prog_setButtonName(buttonFX, buttonSX);
- end
- return text;
- end
- function prog_setButtonBColor()
- local chooseColorX = {17,32};
- local chooseColorY = {10,10};
- term.setBackgroundColor(colors.gray);
- term.setTextColor(colors.white);
- term.setCursorPos(17,7);
- term.write(" ");
- term.setCursorPos(17,8);
- term.write(" ");
- term.setCursorPos(17,9);
- term.write(" Hintergrund: ");
- term.setCursorPos(17,10);
- for i = 1,16 do
- term.setBackgroundColor(colorTable[i]);
- term.write(" ");
- end
- term.setBackgroundColor(colors.gray);
- term.setCursorPos(17,11);
- term.write(" ");
- term.setCursorPos(17,12);
- term.write(" ");
- event, side, x, y = os.pullEvent("mouse_click");
- if (object_checkIfClicked(chooseColorX, chooseColorY, x, y)) then
- clickedColor = x - 16;
- else
- prog_setButtonBColor();
- end
- return colorTable[clickedColor];
- end
- function prog_setButtonTColor()
- local chooseColorX = {17,32};
- local chooseColorY = {10,10};
- term.setBackgroundColor(colors.gray);
- term.setTextColor(colors.white);
- term.setCursorPos(17,7);
- term.write(" ");
- term.setCursorPos(17,8);
- term.write(" ");
- term.setCursorPos(17,9);
- term.write(" Text: ");
- term.setCursorPos(17,10);
- for i = 1,16 do
- term.setBackgroundColor(colorTable[i]);
- term.write(" ");
- end
- term.setBackgroundColor(colors.gray);
- term.setCursorPos(17,11);
- term.write(" ");
- term.setCursorPos(17,12);
- term.write(" ");
- event, side, x, y = os.pullEvent("mouse_click");
- if (object_checkIfClicked(chooseColorX, chooseColorY, x, y)) then
- clickedColor = x - 16;
- else
- prog_setButtonBColor();
- end
- return colorTable[clickedColor];
- end
- function prog_closeMenus(buttons, bColor)
- design_fillMon("X", bColor);
- design_drawButtons(buttons);
- return false, false;
- end
- function prog_getMidOButton(buttonFX, buttonFY, buttonSX, buttonSY, text)
- local buttonSizeX = buttonSX - buttonFX;
- local buttonSizeY = buttonSY - buttonFY;
- if (buttonSizeY % 2) then
- buttonSizeY = buttonSizeY - 1;
- end
- local y = buttonFY + math.ceil(buttonSizeY / 2);
- local x = buttonFX + math.ceil((buttonSizeX / 2) - (text:len() / 2));
- return x, y;
- end
- function prog_setProgName()
- term.setBackgroundColor(colors.gray);
- term.setTextColor(colors.white);
- term.setCursorPos(14,7);
- term.write(" ");
- term.setCursorPos(14,8);
- term.write(" ");
- term.setCursorPos(14,9);
- term.write(" Programmname: ");
- term.setCursorPos(14,10);
- term.write(" ");
- term.setCursorPos(14,11);
- term.write(" ");
- term.setCursorPos(14,12);
- term.write(" ");
- term.setCursorPos(15,10);
- progName = read();
- if (text == "") then
- prog_setProgName()
- end
- return progName;
- end
- function prog_compileObjects(buttons, progName)
- buttonAttributes = 8;
- curTableNumber = 1;
- if (#buttons == 0) then
- return;
- end
- file = fs.open(progName, "w");
- file.writeLine("-- Variablen");
- file.writeLine("");
- file.writeLine("background = colors.black;");
- file.writeLine("textcolor = colors.white;");
- file.writeLine("")
- file.writeLine("-- Design");
- file.writeLine("");
- file.writeLine("term.setBackgroundColor(background);");
- file.writeLine("term.setTextColor(textcolor);");
- file.writeLine("term.clear();");
- file.writeLine("term.setCursorPos(1,1);");
- file.writeLine("");
- for i = 1, (#buttons / buttonAttributes) do
- local buttonText = buttons[curTableNumber];
- local bColor = buttons[curTableNumber + 1];
- local tColor = buttons[curTableNumber + 2];
- local fXPos = buttons[curTableNumber + 3];
- local fYPos = buttons[curTableNumber + 4];
- local sXPos = buttons[curTableNumber + 5];
- local sYPos = buttons[curTableNumber + 6];
- local code = buttons[curTableNumber + 7];
- x, y = prog_getMidOButton(fXPos, fYPos, sXPos, sYPos, buttonText);
- file.writeLine("for yPos = " .. fYPos .. ", " .. sYPos .. " do");
- file.writeLine("");
- file.writeLine(" for xPos = " .. fXPos .. ", " .. sXPos .. " do");
- file.writeLine("");
- file.writeLine(" term.setBackgroundColor(" .. bColor .. ");");
- file.writeLine(" term.setCursorPos(xPos, yPos);");
- file.writeLine(" term.write(\" \");");
- file.writeLine("");
- file.writeLine(" end");
- file.writeLine("");
- file.writeLine("end");
- file.writeLine("");
- file.writeLine("term.setTextColor(" .. tColor .. ");");
- file.writeLine("term.setCursorPos(" .. x .. ", " .. y .. ");");
- file.writeLine("term.write(\"" .. buttonText .. "\");");
- file.writeLine("")
- curTableNumber = curTableNumber + 8;
- end
- file.writeLine("-- Programmtechnisch");
- file.writeLine("");
- file.writeLine("term.setCursorPos(1,1);");
- file.writeLine("term.setBackgroundColor(colors.black);");
- file.writeLine("term.setTextColor(colors.white);");
- file.writeLine("");
- file.writeLine("while true do");
- file.writeLine("");
- file.writeLine("event, side, x, y = os.pullEvent(\"mouse_click\");");
- file.writeLine("")
- curTableNumber = 1;
- curButton = 1;
- for i = 1, (#buttons / buttonAttributes) do
- local buttonText = buttons[curTableNumber];
- local bColor = buttons[curTableNumber + 1];
- local tColor = buttons[curTableNumber + 2];
- local fXPos = buttons[curTableNumber + 3];
- local fYPos = buttons[curTableNumber + 4];
- local sXPos = buttons[curTableNumber + 5];
- local sYPos = buttons[curTableNumber + 6];
- local code = buttons[curTableNumber + 7];
- if (curButton == 1) then
- file.writeLine("if (x >= " .. fXPos .. " and x <= " .. sXPos .. " and y >= " .. fYPos .. " and y <= " .. sYPos .. ") then");
- file.writeLine("");
- else
- file.writeLine("elseif (x >= " .. fXPos .. " and x <= " .. sXPos .. " and y >= " .. fYPos .. " and y <= " .. sYPos .. ") then");
- file.writeLine("");
- end
- file.writeLine(code);
- file.writeLine("");
- curTableNumber = curTableNumber + 8;
- curButton = curButton + 1;
- end
- file.writeLine("end");
- file.writeLine("");
- file.writeLine("end");
- file.close();
- end
Advertisement
Add Comment
Please, Sign In to add comment