Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Hilfsfunktionen
- if not fs.exists("startup") then
- local f = fs.open("startup", "w")
- f.writeLine('shell.run("Screen-Conf")')
- f.close()
- end
- local function clear()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.lightBlue)
- term.clear()
- term.setCursorPos(1, 1)
- end
- local function waitEnter()
- term.setTextColor(colors.gray)
- print("\nDrücke [Enter], um fortzufahren...")
- term.setTextColor(colors.lightBlue)
- read()
- end
- local function listScreens()
- if not fs.exists("screens") then fs.makeDir("screens") end
- local files = fs.list("screens")
- local screens = {}
- for _, f in ipairs(files) do
- if not fs.isDir("screens/" .. f) then
- table.insert(screens, f)
- end
- end
- return screens
- end
- local function displayScreen(filename)
- local path = "screens/" .. filename
- local file = fs.open(path, "r")
- if not file then return false, "Datei konnte nicht geöffnet werden." end
- local header = file.readLine()
- local side, scaleStr, bgColorStr = header:match("([^,]+),([^,]+),([^,]+)")
- local scale = tonumber(scaleStr)
- local bgColor = tonumber(bgColorStr)
- if not (side and scale and bgColor) then
- file.close()
- return false, "Ungültiger Header in Datei."
- end
- local monitor = peripheral.wrap(side)
- if not monitor then
- file.close()
- return false, "Monitor auf Seite '" .. side .. "' nicht gefunden."
- end
- monitor.setTextScale(scale)
- monitor.setBackgroundColor(bgColor)
- monitor.clear()
- while true do
- local line = file.readLine()
- if not line then break end
- local x, y, textColor, charBgColor, char = line:match("([^,]+),([^,]+),([^,]+),([^,]+),(.+)")
- x = tonumber(x)
- y = tonumber(y)
- textColor = tonumber(textColor)
- charBgColor = tonumber(charBgColor)
- if x and y and textColor and charBgColor and char then
- monitor.setCursorPos(x, y)
- monitor.setTextColor(textColor)
- monitor.setBackgroundColor(charBgColor)
- monitor.write(char)
- end
- end
- file.close()
- return true
- end
- -- [3] Auto-Start Bildschirmanzeige
- local function autoStartScreen()
- if not fs.exists("auto_start") then return end
- local file = fs.open("auto_start", "r")
- local screenFile = file.readLine()
- file.close()
- if not screenFile or screenFile == "" then return end
- local success, err = displayScreen(screenFile)
- if not success then
- term.setTextColor(colors.red)
- print("Auto-Start Fehler: " .. err)
- term.setTextColor(colors.lightBlue)
- sleep(2)
- end
- end
- autoStartScreen()
- -- [1] Gespeicherten Bildschirm anschauen
- local function promptScreenStart()
- clear()
- print("Gespeicherte Screens:\n")
- local screens = listScreens()
- for i, s in ipairs(screens) do
- print(i .. ") " .. s)
- end
- io.write("\nNummer eingeben zum Starten: ")
- local n = tonumber(read())
- if not (n and screens[n]) then
- term.setTextColor(colors.red)
- print("Ungültige Eingabe.")
- term.setTextColor(colors.lightBlue)
- waitEnter()
- return
- end
- local success, err = displayScreen(screens[n])
- if not success then
- term.setTextColor(colors.red)
- print(err)
- term.setTextColor(colors.lightBlue)
- waitEnter()
- return
- end
- end
- -- [2] Neuen Bildschirm Konfigurieren
- local function screenConfig()
- 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.")
- end
- -- [3] Auto-Start Bildschirm festlegen
- local function promptAutoStart()
- clear()
- print("Auto-Start Bildschirm festlegen:\n")
- local screens = listScreens()
- for i, s in ipairs(screens) do
- print(i .. ") " .. s)
- end
- io.write("\nNummer eingeben: ")
- local n = tonumber(read())
- if n and screens[n] then
- local file = fs.open("auto_start", "w")
- file.write(screens[n])
- file.close()
- term.setTextColor(colors.green)
- print("\nGespeichert! Beim nächsten Start wird dieser Bildschirm automatisch angezeigt.")
- term.setTextColor(colors.lightBlue)
- else
- term.setTextColor(colors.red)
- print("Ungültige Eingabe.")
- term.setTextColor(colors.lightBlue)
- end
- waitEnter()
- end
- -- [4] Gespeicherten Bildschirm löschen
- local function deleteScreen()
- clear()
- print("Screen löschen:\n")
- local screens = listScreens()
- for i, s in ipairs(screens) do
- print(i .. ") " .. s)
- end
- io.write("\nNummer eingeben: ")
- local n = tonumber(read())
- if n and screens[n] then
- fs.delete("screens/" .. screens[n])
- term.setTextColor(colors.green)
- print("\nBildschirm gelöscht.")
- term.setTextColor(colors.lightBlue)
- else
- term.setTextColor(colors.red)
- print("Ungültige Eingabe.")
- term.setTextColor(colors.lightBlue)
- end
- waitEnter()
- end
- -- [5] Hauptmenü
- local function main()
- while true do
- clear()
- print([[
- Willkommen im Bildschirm - Konfigurator
- Du kannst ohne Programmierkenntnisse folgendes tun:
- 1) Gespeicherten Bildschirm anschauen
- 2) Neuen Bildschirm konfigurieren
- 3) Auto-Start für Bildschirm festlegen
- 4) Gespeicherten Bildschirm löschen
- 5) Beenden
- ]])
- io.write("Bitte Zahl eingeben und [Enter] drücken: ")
- local input = read()
- if input == "1" then promptScreenStart() -- [1]
- elseif input == "2" then screenConfig() -- [2]
- elseif input == "3" then promptAutoStart() -- [3]
- elseif input == "4" then deleteScreen() -- [4]
- elseif input == "5" then -- [5]
- print("Beende Menü...")
- sleep(1)
- break
- else
- term.setTextColor(colors.red)
- print("Ungültige Eingabe.")
- term.setTextColor(colors.lightBlue)
- waitEnter()
- end
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement