Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Schritt 1: Eingaben für Monitor
- term.setCursorPos(1, 1)
- term.setTextColor(colors.lightBlue)
- term.setBackgroundColor(colors.black)
- term.clear()
- print("Du stehst vor dem Computer, auf welcher Seite")
- print("des Computers befindet sich der Monitor")
- print("Schreibe: left, right, back, front, top, bottom")
- print(" ")
- local side = read()
- term.setCursorPos(1, 7)
- print("Textgrösse wählen: (von 1 in 0.5er Schritten bis 5) ")
- local scaleInput = read()
- local scale = tonumber(scaleInput)
- if not scale or scale < 0.5 or scale > 5 then
- scale = 1.0
- end
- -- Schritt 2: Hintergrundfarbe wählen
- term.setCursorPos(1, 10)
- print("Hintergrundfarbe des Bildschirms wählen:")
- local MonbgColors = {
- colors.white, colors.orange, colors.magenta, colors.lightBlue,
- colors.yellow, colors.lime, colors.pink, colors.gray,
- colors.black, colors.brown, colors.red, colors.green,
- colors.blue, colors.purple, colors.cyan, colors.lightGray
- }
- for i, color in ipairs(MonbgColors) do
- term.setBackgroundColor(color)
- term.setCursorPos((i - 1) * 2 + 1, 11)
- term.write(" ")
- end
- term.setBackgroundColor(colors.black)
- term.setCursorPos(1, 13)
- write("Klicke eine Farbe an...")
- local currentMonBgColor = colors.black
- while true do
- local event, button, x, y = os.pullEvent()
- if event == "mouse_click" and y == 11 then
- for i, color in ipairs(MonbgColors) do
- local startX = (i - 1) * 2 + 1
- if x >= startX and x <= startX + 1 then
- currentMonBgColor = color
- break
- end
- end
- if currentMonBgColor then break end
- end
- end
- -- Monitor initialisieren
- local mon = peripheral.wrap(side)
- mon.setTextScale(scale)
- mon.setBackgroundColor(currentMonBgColor)
- mon.clear()
- local width, height = mon.getSize()
- -- Hilfstexte
- term.setCursorPos(1, 1)
- term.setTextColor(colors.lightBlue)
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1,12)
- term.write("Mit den Pfeiltasten kannst du auf dem Monitor an")
- term.setCursorPos(1,13)
- term.write("die Stelle navigieren an der dein Text stehen soll.")
- term.setCursorPos(1,14)
- term.write("Schreibe via Tastatureingabe den Text direkt ")
- term.setCursorPos(1,15)
- term.write("an die gewünschte Stelle, du kannst für jeden")
- term.setCursorPos(1,16)
- term.write("Buchstaben Text- und Hintergrundfarbe festlegen.")
- term.setCursorPos(1,18)
- term.write("[Enter] drücken um zu speichern oder beenden")
- -- Farben
- local textColors = MonbgColors
- local bgColors = MonbgColors
- local currentTextColor = colors.white
- local currentBgColor = colors.black
- -- Ordner vorbereiten
- if not fs.exists("screens") then
- fs.makeDir("screens")
- end
- -- Speichern
- local function saveScreen(name, content)
- local f = fs.open("screens/" .. name .. ".txt", "w")
- if not f then
- print("Fehler beim Speichern.")
- return
- end
- f.writeLine(table.concat({side, scale, currentMonBgColor}, ","))
- for _, data in ipairs(content) do
- f.writeLine(table.concat({
- data.x,
- data.y,
- data.textColor,
- data.bgColor,
- data.char
- }, ","))
- end
- f.close()
- print("Gespeichert als: " .. name)
- end
- -- Cursor-Logik
- local x, y = 1, 1
- local cursorVisible = true
- local timerID = os.startTimer(0.5)
- local content = {}
- local function clamp(val, min, max)
- if val < min then return min end
- if val > max then return max end
- return val
- end
- local function drawCursor()
- mon.setCursorPos(x, y)
- local oldChar = " "
- for i = #content, 1, -1 do
- local c = content[i]
- if c.x == x and c.y == y then
- oldChar = c.char
- mon.setTextColor(c.textColor)
- mon.setBackgroundColor(c.bgColor)
- break
- end
- end
- if cursorVisible then
- mon.setTextColor(currentTextColor)
- mon.setBackgroundColor(currentMonBgColor)
- mon.write("_")
- else
- mon.write(oldChar)
- end
- mon.setCursorPos(x, y)
- end
- local function drawColorBoxes()
- term.setCursorPos(1, 1)
- term.setTextColor(colors.lightBlue)
- term.setBackgroundColor(colors.black)
- print("Schrift - Farbe:")
- for i, color in ipairs(textColors) do
- term.setBackgroundColor(color)
- term.setCursorPos(i * 2 - 1, 2)
- term.write(" ")
- end
- term.setCursorPos(1, 4)
- term.setTextColor(colors.lightBlue)
- term.setBackgroundColor(colors.black)
- print("Schrift - Hintergrundfarbe:")
- for i, color in ipairs(bgColors) do
- term.setBackgroundColor(color)
- term.setCursorPos(i * 2 - 1, 5)
- term.write(" ")
- end
- end
- local function checkColorClick(mx, my)
- if my == 2 then
- for i = 1, #textColors do
- if mx >= i * 2 - 1 and mx <= i * 2 then
- currentTextColor = textColors[i]
- end
- end
- elseif my == 5 then
- for i = 1, #bgColors do
- if mx >= i * 2 - 1 and mx <= i * 2 then
- currentBgColor = bgColors[i]
- end
- end
- end
- end
- -- Startanzeige
- drawColorBoxes()
- drawCursor()
- -- Eingabeschleife
- while true do
- local event, p1, p2, p3 = os.pullEvent()
- if event == "char" then
- local char = p1
- mon.setCursorPos(x, y)
- mon.setTextColor(currentTextColor)
- mon.setBackgroundColor(currentBgColor)
- mon.write(char)
- table.insert(content, {
- x = x, y = y,
- textColor = currentTextColor,
- bgColor = currentBgColor,
- char = char
- })
- x = clamp(x + 1, 1, width)
- drawCursor()
- elseif event == "key" then
- local key = p1
- cursorVisible = false
- drawCursor()
- if key == keys.enter then
- term.setCursorPos(1, 8)
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- term.clearLine()
- write("Speichern? (j/n): ")
- local ans = read()
- if ans == "j" then
- term.clearLine()
- write("Speichername: ")
- local name = read()
- saveScreen(name, content)
- end
- break
- elseif key == keys.left then
- x = clamp(x - 1, 1, width)
- elseif key == keys.right then
- x = clamp(x + 1, 1, width)
- elseif key == keys.up then
- y = clamp(y - 1, 1, height)
- elseif key == keys.down then
- y = clamp(y + 1, 1, height)
- elseif key == keys.backspace then
- if x > 1 then
- x = x - 1
- elseif y > 1 then
- y = y - 1
- x = width
- end
- for i = #content, 1, -1 do
- local c = content[i]
- if c.x == x and c.y == y then
- table.remove(content, i)
- break
- end
- end
- mon.setCursorPos(x, y)
- mon.setTextColor(currentTextColor)
- mon.setBackgroundColor(currentBgColor)
- mon.write(" ")
- elseif key == keys.delete then
- for i = #content, 1, -1 do
- local c = content[i]
- if c.x == x and c.y == y then
- table.remove(content, i)
- break
- end
- end
- mon.setCursorPos(x, y)
- mon.setTextColor(currentTextColor)
- mon.setBackgroundColor(currentBgColor)
- mon.write(" ")
- end
- cursorVisible = true
- drawCursor()
- elseif event == "mouse_click" then
- local btn, mx, my = p1, p2, p3
- checkColorClick(mx, my)
- elseif event == "timer" and p1 == timerID then
- cursorVisible = not cursorVisible
- drawCursor()
- timerID = os.startTimer(0.5)
- end
- end
- cursorVisible = false
- drawCursor()
- mon.setCursorPos(1, height)
- mon.write("Programm beendet.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement