KingXenoth

Computercraft screen maker

Mar 23rd, 2025 (edited)
573
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 30.53 KB | Gaming | 0 0
  1. -------------------------------------
  2. -- "Ultimate" (could be better) Screen Maker
  3. -------------------------------------
  4.  
  5. -- Load settings early
  6. settings.load()
  7.  
  8. -----------------------------------------------------
  9. -- Default Global Variables
  10. -----------------------------------------------------
  11. textSize                 = 1
  12. textStartX, textStartY   = 1, 1
  13. currentText             = {}
  14. scrollSpeed             = 0.1
  15. pauseTime               = 1
  16.  
  17. currentTextColorNum      = colors.white
  18. currentTextColor         = "f"
  19. currentBackgroundNum     = colors.black
  20. currentBackgroundColor   = "0"
  21.  
  22. marqueeBackgroundNum     = colors.black
  23. marqueeBackgroundColor   = "0"
  24.  
  25. startupMarquee          = false
  26. startupClock            = false
  27. startupStarryNight      = false
  28.  
  29. starryNightColor        = colors.yellow
  30. starryNightBGColor      = colors.black
  31.  
  32. -----------------------------------------------------
  33. -- Color Maps
  34. -----------------------------------------------------
  35. local colorHexMap = {
  36.   black      = "f",
  37.   darkblue   = "6",
  38.   darkgreen  = "4",
  39.   darkaqua   = "3",
  40.   darkred    = "1",
  41.   darkpurple = "2",
  42.   gold       = "e",
  43.   gray       = "8",
  44.   lightgray  = "7",
  45.   blue       = "b",
  46.   green      = "d",
  47.   aqua       = "9",
  48.   red        = "5",
  49.   magenta    = "a",
  50.   yellow     = "c",
  51.   white      = "0"
  52. }
  53.  
  54. local hexToColor = {
  55.   ["f"] = colors.white,
  56.   ["6"] = colors.gold,
  57.   ["4"] = colors.darkPurple,
  58.   ["3"] = colors.cyan,
  59.   ["1"] = colors.yellow,
  60.   ["2"] = colors.darkGreen,
  61.   ["e"] = colors.pink,
  62.   ["8"] = colors.lightGray,
  63.   ["7"] = colors.gray,
  64.   ["b"] = colors.cyan,
  65.   ["d"] = colors.magenta,
  66.   ["9"] = colors.blue,
  67.   ["5"] = colors.brown,
  68.   ["a"] = colors.green,
  69.   ["c"] = colors.red,
  70.   ["0"] = colors.black
  71. }
  72.  
  73. -----------------------------------------------------
  74. -- Reset the Monitor's Palette (with safe fallbacks)
  75. -----------------------------------------------------
  76. local mon = peripheral.wrap("back")
  77. if mon then
  78.   local palette = {
  79.     {colors.black,      0x000000},
  80.     {colors.darkBlue,   0x0000AA},
  81.     {colors.darkGreen,  0x00AA00},
  82.     {colors.cyan,       0x00AAAA},
  83.     {colors.darkRed,    0xAA0000},
  84.     {colors.darkPurple, 0xAA00AA},
  85.     {colors.orange,     0xFFAA00},
  86.     {colors.gray,       0xAAAAAA},
  87.     {colors.lightGray,  0x555555},
  88.     {colors.blue,       0x5555FF},
  89.     {colors.green,      0x55FF55},
  90.     {colors.cyan,       0x55FFFF},
  91.     {colors.red,        0xFF5555},
  92.     {colors.magenta,    0xFF55FF},
  93.     {colors.yellow,     0xFFFF55},
  94.     {colors.white,      0xFFFFFF},
  95.   }
  96.   for _, col in ipairs(palette) do
  97.     if col[1] then
  98.       mon.setPaletteColor(col[1], col[2])
  99.     end
  100.   end
  101. end
  102.  
  103. -----------------------------------------------------
  104. -- Helper Functions
  105. -----------------------------------------------------
  106. local function wrapSub(str, start, len)
  107.   if not str or str == "" then return "" end
  108.   local total = #str
  109.   local res = ""
  110.   for i = 0, len - 1 do
  111.     local idx = ((start + i - 1) % total) + 1
  112.     res = res .. str:sub(idx, idx)
  113.   end
  114.   return res
  115. end
  116.  
  117. local function redrawText(mon)
  118.   local w, h = mon.getSize()
  119.   mon.clear()
  120.   for i = 1, h do
  121.     local line = currentText[i] or ""
  122.     local textColors, bgColors
  123.  
  124.     if line == "" then
  125.       line = string.rep(" ", w)
  126.       textColors = string.rep(currentBackgroundColor, w)
  127.       bgColors   = string.rep(currentBackgroundColor, w)
  128.     else
  129.       if #line < w then
  130.         line = line .. string.rep(" ", w - #line)
  131.       else
  132.         line = string.sub(line, 1, w)
  133.       end
  134.       textColors = string.rep(currentTextColor, w)
  135.       bgColors   = string.rep(currentBackgroundColor, w)
  136.     end
  137.  
  138.     mon.setCursorPos(textStartX, textStartY + i - 1)
  139.     mon.blit(line, textColors, bgColors)
  140.   end
  141. end
  142.  
  143. -----------------------------------------------------
  144. -- Settings Persistence
  145. -----------------------------------------------------
  146. function loadSettingsCustom()
  147.   local ts = settings.get("textSize")
  148.   if ts then textSize = ts end
  149.  
  150.   local tx = settings.get("textStartX")
  151.   local ty = settings.get("textStartY")
  152.   if tx and ty then
  153.     textStartX, textStartY = tx, ty
  154.   end
  155.  
  156.   local ss = settings.get("scrollSpeed")
  157.   if ss then scrollSpeed = ss end
  158.  
  159.   local pt = settings.get("pauseTime")
  160.   if pt then pauseTime = pt end
  161.  
  162.   local txtColNum = settings.get("currentTextColorNum")
  163.   if txtColNum then currentTextColorNum = txtColNum end
  164.  
  165.   local txtCol = settings.get("currentTextColor")
  166.   if txtCol then currentTextColor = txtCol end
  167.  
  168.   local bgNum = settings.get("currentBackgroundNum")
  169.   if bgNum then currentBackgroundNum = bgNum end
  170.  
  171.   local bgCol = settings.get("currentBackgroundColor")
  172.   if bgCol then currentBackgroundColor = bgCol end
  173.  
  174.   local mbgNum = settings.get("marqueeBackgroundNum")
  175.   if mbgNum then marqueeBackgroundNum = mbgNum end
  176.  
  177.   local mbgCol = settings.get("marqueeBackgroundColor")
  178.   if mbgCol then marqueeBackgroundColor = mbgCol end
  179.  
  180.   local sm = settings.get("startupMarquee")
  181.   if sm ~= nil then startupMarquee = sm end
  182.  
  183.   local sc = settings.get("startupClock")
  184.   if sc ~= nil then startupClock = sc end
  185.  
  186.   local ssn = settings.get("startupStarryNight")
  187.   if ssn ~= nil then startupStarryNight = ssn end
  188.  
  189.   local savedText = settings.get("currentText")
  190.   if savedText then
  191.     if type(savedText) == "string" then
  192.       currentText = textutils.unserialize(savedText)
  193.     elseif type(savedText) == "table" then
  194.       currentText = savedText
  195.     end
  196.   end
  197. end
  198.  
  199. function saveSettingsCustom()
  200.   settings.set("textSize", textSize)
  201.   settings.set("textStartX", textStartX)
  202.   settings.set("textStartY", textStartY)
  203.   settings.set("scrollSpeed", scrollSpeed)
  204.   settings.set("pauseTime", pauseTime)
  205.   settings.set("currentTextColorNum", currentTextColorNum)
  206.   settings.set("currentTextColor", currentTextColor)
  207.   settings.set("currentBackgroundNum", currentBackgroundNum)
  208.   settings.set("currentBackgroundColor", currentBackgroundColor)
  209.   settings.set("marqueeBackgroundNum", marqueeBackgroundNum)
  210.   settings.set("marqueeBackgroundColor", marqueeBackgroundColor)
  211.   settings.set("startupMarquee", startupMarquee)
  212.   settings.set("startupClock", startupClock)
  213.   settings.set("startupStarryNight", startupStarryNight)
  214.   settings.set("currentText", textutils.serialize(currentText))
  215.   settings.save()
  216. end
  217.  
  218. -----------------------------------------------------
  219. -- Apply Settings on Startup
  220. -----------------------------------------------------
  221. function applySettings()
  222.   local mon = peripheral.wrap("back")
  223.   if mon then
  224.     mon.setTextScale(textSize)
  225.     mon.setBackgroundColor(currentBackgroundNum)
  226.     mon.clear()
  227.     mon.setCursorPos(textStartX, textStartY)
  228.     redrawText(mon)
  229.   end
  230. end
  231.  
  232. -----------------------------------------------------
  233. -- Marquee Mode
  234. -----------------------------------------------------
  235. function marqueeText()
  236.   local mon = peripheral.wrap("back")
  237.   if not mon then
  238.     print("No monitor found at the back.")
  239.     return
  240.   end
  241.  
  242.   mon.setTextScale(textSize)
  243.   mon.setBackgroundColor(marqueeBackgroundNum)
  244.   mon.clear()
  245.   local w, h = mon.getSize()
  246.  
  247.   if #currentText == 0 then
  248.     currentText = {"Marquee Text"}
  249.   end
  250.  
  251.   local static = {}
  252.   local pattern = {}
  253.   local textColorPattern = {}
  254.   local bgPattern = {}
  255.   local scrollOffsets = {}
  256.   local refIndex = nil
  257.  
  258.   for i, line in ipairs(currentText) do
  259.     scrollOffsets[i] = 0
  260.     if line == "" then
  261.       static[i]           = nil
  262.       pattern[i]          = nil
  263.       textColorPattern[i] = nil
  264.       bgPattern[i]        = nil
  265.     else
  266.       local truncated = (#line <= w) and (line .. string.rep(" ", w - #line)) or string.sub(line, 1, w)
  267.       static[i]           = truncated
  268.       pattern[i]          = truncated .. " "
  269.       textColorPattern[i] = string.rep(currentTextColor, w + 1)
  270.       bgPattern[i]        = string.rep(marqueeBackgroundColor, w + 1)
  271.       if not refIndex then
  272.         refIndex = i
  273.       end
  274.     end
  275.   end
  276.  
  277.   local original = refIndex and static[refIndex] or nil
  278.   local pausedThisCycle = false
  279.  
  280.   print("Entering marquee mode on monitor. (Press any key in the terminal to exit.)")
  281.   local running = true
  282.   while running do
  283.     mon.setBackgroundColor(marqueeBackgroundNum)
  284.     mon.clear()
  285.  
  286.     for i, line in ipairs(currentText) do
  287.       mon.setCursorPos(textStartX, textStartY + i - 1)
  288.       if line == "" then
  289.         local blank = string.rep(" ", w)
  290.         mon.blit(blank, string.rep(marqueeBackgroundColor, w), string.rep(marqueeBackgroundColor, w))
  291.       else
  292.         local cyc = #pattern[i]
  293.         local off = scrollOffsets[i] % cyc
  294.         local visible = wrapSub(pattern[i], off + 1, w)
  295.         local visTC   = wrapSub(textColorPattern[i], off + 1, w)
  296.         local visBG   = wrapSub(bgPattern[i], off + 1, w)
  297.  
  298.         mon.blit(visible, visTC, visBG)
  299.         scrollOffsets[i] = scrollOffsets[i] + 1
  300.       end
  301.     end
  302.  
  303.     -- Pause if we've returned to the original alignment
  304.     if original and refIndex then
  305.       local cyc   = #pattern[refIndex]
  306.       local off   = (scrollOffsets[refIndex] - 1) % cyc
  307.       local firstVisible = wrapSub(pattern[refIndex], off + 1, w)
  308.       if firstVisible == original then
  309.         if not pausedThisCycle then
  310.           sleep(pauseTime)
  311.           pausedThisCycle = true
  312.         end
  313.       else
  314.         pausedThisCycle = false
  315.       end
  316.     end
  317.  
  318.     local timerID = os.startTimer(scrollSpeed)
  319.     local event, param = os.pullEvent()
  320.     if event == "key" then
  321.       running = false
  322.     elseif event == "timer" and param == timerID then
  323.       -- continue
  324.     end
  325.   end
  326.  
  327.   -- Restore static text
  328.   redrawText(mon)
  329.   print("Exited marquee mode on monitor.")
  330. end
  331.  
  332. -----------------------------------------------------
  333. -- Terminal Starry Night (runs in parallel)
  334. -----------------------------------------------------
  335. function terminalStarryNight()
  336.   term.clear()
  337.   local w, h = term.getSize()
  338.  
  339.   for y = 1, h - 1 do
  340.     term.setCursorPos(1, y)
  341.     local line = ""
  342.     for x = 1, w do
  343.       if math.random() < 0.1 then
  344.         line = line .. "*"
  345.       else
  346.         line = line .. " "
  347.       end
  348.     end
  349.     term.write(line)
  350.   end
  351.  
  352.   local exitMsg = "Press any key to exit"
  353.   term.setCursorPos(math.floor((w - #exitMsg) / 2), h)
  354.   term.setTextColor(colors.yellow)
  355.   term.write(exitMsg)
  356.   term.setTextColor(colors.white)
  357.  
  358.   os.pullEvent("key")
  359.   term.clear()
  360. end
  361.  
  362. -----------------------------------------------------
  363. -- Monitor Starry Night
  364. -----------------------------------------------------
  365. function extrasStarryNight()
  366.   local mon = peripheral.wrap("back")
  367.   if not mon then
  368.     print("No monitor found.")
  369.     return
  370.   end
  371.   mon.setTextScale(textSize)
  372.   local w, h = mon.getSize()
  373.  
  374.   print("Entering monitor Starry Night. (Press any key to exit.)")
  375.   local running = true
  376.   while running do
  377.     mon.setBackgroundColor(starryNightBGColor)
  378.     mon.clear()
  379.     for y = 1, h do
  380.       mon.setCursorPos(1, y)
  381.       local line = ""
  382.       for x = 1, w do
  383.         if math.random() < 0.1 then
  384.           mon.setTextColor(starryNightColor)
  385.           line = line .. "*"
  386.         else
  387.           line = line .. " "
  388.         end
  389.       end
  390.       mon.write(line)
  391.     end
  392.     local timerID = os.startTimer(0.5)
  393.     local event, param = os.pullEvent()
  394.     if event == "key" then
  395.       running = false
  396.     elseif event == "timer" and param == timerID then
  397.       -- Continue
  398.     end
  399.   end
  400.   mon.clear()
  401.   print("Exited monitor Starry Night.")
  402. end
  403.  
  404. -----------------------------------------------------
  405. -- Monitor Clock
  406. -----------------------------------------------------
  407. function clockMonitor()
  408.   local mon = peripheral.wrap("back")
  409.   if not mon then
  410.     print("No monitor found.")
  411.     return
  412.   end
  413.   mon.setTextScale(textSize)
  414.   local w, h = mon.getSize()
  415.   local running = true
  416.  
  417.   while running do
  418.     mon.clear()
  419.     local currentTime = os.date("%H:%M:%S")
  420.     local dateStr     = os.date("%A, %B %d, %Y")
  421.  
  422.     local timeX       = math.floor((w - #currentTime) / 2) + 1
  423.     local dateX       = math.floor((w - #dateStr) / 2) + 1
  424.     local timeY       = math.floor(h / 2) - 1
  425.     local dateY       = timeY + 2
  426.  
  427.     mon.setBackgroundColor(currentBackgroundNum)
  428.     mon.clear()
  429.  
  430.     mon.setCursorPos(timeX, timeY)
  431.     mon.setTextColor(colors.white)
  432.     mon.write(currentTime)
  433.  
  434.     mon.setCursorPos(dateX, dateY)
  435.     mon.setTextColor(colors.lightGray)
  436.     mon.write(dateStr)
  437.  
  438.     local timerID = os.startTimer(1)
  439.     local event, param = os.pullEvent()
  440.     if event == "key" then
  441.       running = false
  442.     elseif event == "timer" and param == timerID then
  443.       -- Update clock
  444.     end
  445.   end
  446.   mon.clear()
  447.   print("Exited Clock mode.")
  448. end
  449.  
  450. -----------------------------------------------------
  451. -- Cute Screen
  452. -----------------------------------------------------
  453. function showCuteScreen()
  454.   term.clear()
  455.   term.setCursorPos(1,1)
  456.   local termWidth, termHeight = term.getSize()
  457.   local art = {
  458.     "(\\_/)",
  459.     "( •_•)",
  460.     '(")_(")'
  461.   }
  462.   local startY = math.floor((termHeight - #art) / 2)
  463.   for i, line in ipairs(art) do
  464.     local startX = math.floor((termWidth - #line) / 2)
  465.     term.setCursorPos(startX, startY + i)
  466.     term.setTextColor(colors.magenta)
  467.     print(line)
  468.   end
  469.   term.setTextColor(colors.yellow)
  470.   local msg = "Welcome to Ultimate Screen Maker!"
  471.   term.setCursorPos(math.floor((termWidth - #msg) / 2), startY + #art + 2)
  472.   print(msg)
  473.   term.setTextColor(colors.white)
  474.   sleep(2)
  475.   term.clear()
  476. end
  477.  
  478. -----------------------------------------------------
  479. -- Single Helper to Render a Centered Menu
  480. -----------------------------------------------------
  481. local function drawCenteredMenu(title, options, selectedIndex)
  482.   -- Clear the whole terminal first.
  483.   term.clear()
  484.   term.setCursorPos(1, 1)
  485.   local termWidth, termHeight = term.getSize()
  486.  
  487.   -----------------------------------
  488.   -- 1) Top border + Title (Line 1)
  489.   -----------------------------------
  490.   -- Build a line that has "==== title ====" with padding on each side
  491.   -- so it is centered. We can just do something simpler: border + space + title + space + border (don't ask) Prob a better way to do this had issues?????
  492.   local fullTitle = string.rep("=", math.floor((termWidth - #title - 2) / 2))
  493.     .. " " .. title .. " "
  494.     .. string.rep("=", math.ceil((termWidth - #title - 2) / 2))
  495.  
  496.   -- Print that line (clamped to termWidth just in case)
  497.   term.setCursorPos(1, 1)
  498.   term.setTextColor(colors.lightBlue)
  499.   if #fullTitle > termWidth then
  500.     fullTitle = fullTitle:sub(1, termWidth)
  501.   end
  502.   print(fullTitle)
  503.  
  504.   -----------------------------------
  505.   -- 2) Second border (Line 2)
  506.   -----------------------------------
  507.   term.setCursorPos(1, 2)
  508.   term.setTextColor(colors.lightBlue)
  509.   print(string.rep("=", termWidth))
  510.  
  511.   -----------------------------------
  512.   -- 3) Menu Items, starting at line 3
  513.   -----------------------------------
  514.   local startLine = 3
  515.   for i, opt in ipairs(options) do
  516.     -- If we’re about to exceed terminal height - 1, we’ll stop printing items
  517.     -- so we can leave at least one line for instructions at the bottom.
  518.     if startLine > termHeight - 1 then
  519.       break
  520.     end
  521.  
  522.     term.setCursorPos(1, startLine)
  523.  
  524.     -- Center the text: we add " > " and " < " around selected item
  525.     local text = (i == selectedIndex) and (" > " .. opt .. " < ") or ("   " .. opt .. "   ")
  526.     local lineX = math.floor((termWidth - #text) / 2)
  527.     if lineX < 1 then lineX = 1 end
  528.  
  529.     term.setCursorPos(lineX, startLine)
  530.  
  531.     -- Color it red if it's “Back” or “Exit,” otherwise use yellow if selected, white if not
  532.     if i == selectedIndex then
  533.       term.setTextColor(colors.yellow)
  534.     else
  535.       if string.find(string.lower(opt), "back") or string.find(string.lower(opt), "exit") then
  536.         term.setTextColor(colors.red)
  537.       else
  538.         term.setTextColor(colors.white)
  539.       end
  540.     end
  541.     print(text)
  542.  
  543.     startLine = startLine + 1
  544.   end
  545.  
  546.   -----------------------------------
  547.   -- 4) Footer / Instructions (Last line or near-last line)
  548.   -----------------------------------
  549.   if startLine <= termHeight then
  550.     -- Print a thin separator
  551.     term.setCursorPos(1, startLine)
  552.     term.setTextColor(colors.white)
  553.     print(string.rep("-", termWidth))
  554.     startLine = startLine + 1
  555.   end
  556.  
  557.   if startLine <= termHeight then
  558.     term.setCursorPos(1, startLine)
  559.     term.setTextColor(colors.white)
  560.     print("Use arrow keys to navigate, Enter to select.")
  561.   end
  562. end
  563.  
  564.  
  565. -----------------------------------------------------
  566. -- Setting Changer Functions
  567. -----------------------------------------------------
  568. function changeText()
  569.   print("Enter the new text you want to display (type 'END' on a new line to finish):")
  570.   local lines = {}
  571.   while true do
  572.     local line = read()
  573.     if line == "END" then break end
  574.     table.insert(lines, line)
  575.   end
  576.   currentText = lines
  577.   local mon = peripheral.wrap("back")
  578.   if mon then
  579.     redrawText(mon)
  580.   end
  581.   saveSettingsCustom()
  582. end
  583. -- I had some probmlems with colors here so I had to remap them to be the right color idk why it does this kinda lost?????? HMMMMMMM
  584. function changeColor()
  585.   local availableColors = {
  586.     {name = "Black",     value = "black"},
  587.     {name = "Pink",      value = "darkblue"},
  588.     {name = "Yellow",    value = "darkgreen"},
  589.     {name = "Dark Aqua", value = "darkaqua"},
  590.     {name = "Orange",    value = "darkred"},
  591.     {name = "Purple",    value = "darkpurple"},
  592.     {name = "Red",       value = "gold"},
  593.     {name = "Gray",      value = "gray"},
  594.     {name = "Light Gray",value = "lightgray"},
  595.     {name = "Blue",      value = "blue"},
  596.     {name = "Green",     value = "green"},
  597.     {name = "Aqua",      value = "aqua"},
  598.     {name = "Lime",      value = "red"},
  599.     {name = "Magenta",   value = "magenta"},
  600.     {name = "Brown",     value = "yellow"},
  601.     {name = "White",     value = "white"},
  602.     {name = "Back",      value = "Back"}
  603.   }
  604.  
  605.   local selected = 1
  606.  
  607.   local function buildOptions()
  608.     local list = {}
  609.     for _, col in ipairs(availableColors) do
  610.       table.insert(list, col.name)
  611.     end
  612.     return list
  613.   end
  614.  
  615.   while true do
  616.     local options = buildOptions()
  617.     drawCenteredMenu("Choose a Cute Text Color", options, selected)
  618.     local e, key = os.pullEvent("key")
  619.     if key == keys.up then
  620.       selected = (selected <= 1) and #availableColors or (selected - 1)
  621.     elseif key == keys.down then
  622.       selected = (selected >= #availableColors) and 1 or (selected + 1)
  623.     elseif key == keys.enter then
  624.       local chosen = availableColors[selected]
  625.       if chosen.value == "Back" then
  626.         break
  627.       else
  628.         local mon = peripheral.wrap("back")
  629.         if not mon then
  630.           print("No monitor found at the back.")
  631.           return
  632.         end
  633.         local newColor = colors[chosen.value] or colors.white
  634.         mon.setTextColor(newColor)
  635.         currentTextColorNum = newColor
  636.         currentTextColor    = colorHexMap[chosen.value] or currentTextColor
  637.  
  638.         redrawText(mon)
  639.         print("Text color updated to " .. chosen.name)
  640.         sleep(1)
  641.       end
  642.     end
  643.   end
  644.   term.clear()
  645.   term.setCursorPos(1,1)
  646.   saveSettingsCustom()
  647. end
  648. -- Don't ask :(
  649. function changeBackgroundColor()
  650.   local availableColors = {
  651.     {name = "Black",     value = "black"},
  652.     {name = "Pink",      value = "darkblue"},
  653.     {name = "Yellow",    value = "darkgreen"},
  654.     {name = "Dark Aqua", value = "darkaqua"},
  655.     {name = "Orange",    value = "darkred"},
  656.     {name = "Purple",    value = "darkpurple"},
  657.     {name = "Red",       value = "gold"},
  658.     {name = "Gray",      value = "gray"},
  659.     {name = "Light Gray",value = "lightgray"},
  660.     {name = "Blue",      value = "blue"},
  661.     {name = "Green",     value = "green"},
  662.     {name = "Aqua",      value = "aqua"},
  663.     {name = "Lime",      value = "red"},
  664.     {name = "Magenta",   value = "magenta"},
  665.     {name = "Brown",     value = "yellow"},
  666.     {name = "White",     value = "white"},
  667.     {name = "Back",      value = "Back"}
  668.   }
  669.  
  670.   local selected = 1
  671.  
  672.   local function buildOptions()
  673.     local list = {}
  674.     for _, col in ipairs(availableColors) do
  675.       table.insert(list, col.name)
  676.     end
  677.     return list
  678.   end
  679.  
  680.   while true do
  681.     local options = buildOptions()
  682.     drawCenteredMenu("Pick a Cute Background Color", options, selected)
  683.     local e, key = os.pullEvent("key")
  684.     if key == keys.up then
  685.       selected = (selected <= 1) and #availableColors or (selected - 1)
  686.     elseif key == keys.down then
  687.       selected = (selected >= #availableColors) and 1 or (selected + 1)
  688.     elseif key == keys.enter then
  689.       local chosen = availableColors[selected]
  690.       if chosen.value == "Back" then
  691.         break
  692.       else
  693.         local mon = peripheral.wrap("back")
  694.         if not mon then
  695.           print("No monitor found at the back.")
  696.           return
  697.         end
  698.         local newBg = colors[chosen.value] or colors.black
  699.         mon.setBackgroundColor(newBg)
  700.         currentBackgroundNum   = newBg
  701.         currentBackgroundColor = colorHexMap[chosen.value] or currentBackgroundColor
  702.  
  703.         -- Also update marquee background to match
  704.         marqueeBackgroundNum   = newBg
  705.         marqueeBackgroundColor = colorHexMap[chosen.value] or marqueeBackgroundColor
  706.  
  707.         redrawText(mon)
  708.         print("Static & Marquee background color updated to " .. chosen.name)
  709.         sleep(1)
  710.       end
  711.     end
  712.   end
  713.   term.clear()
  714.   term.setCursorPos(1,1)
  715.   saveSettingsCustom()
  716. end
  717.  
  718. function changePosition()
  719.   print("Enter the new position (X, Y) on the monitor (e.g., 2,3):")
  720.   local input = read()
  721.   local x, y = input:match("(%d+),%s*(%d+)")
  722.   x, y = tonumber(x), tonumber(y)
  723.   if not x or not y then
  724.     print("Invalid input.")
  725.     return
  726.   end
  727.   local sw, sh = term.getSize()
  728.   if x < 1 or x > sw or y < 1 or y > sh then
  729.     print("Position out of bounds.")
  730.     return
  731.   end
  732.   textStartX, textStartY = x, y
  733.   local mon = peripheral.wrap("back")
  734.   if mon then
  735.     redrawText(mon)
  736.   end
  737.   print("Position updated.")
  738.   saveSettingsCustom()
  739. end
  740.  
  741. function changeSize()
  742.   print("Enter the new text size (1 to 5):")
  743.   local size = tonumber(read())
  744.   if size and size >= 1 and size <= 5 then
  745.     textSize = size
  746.     local mon = peripheral.wrap("back")
  747.     if mon then
  748.       mon.setTextScale(textSize)
  749.       redrawText(mon)
  750.     end
  751.     print("Text size updated to " .. textSize)
  752.     saveSettingsCustom()
  753.   else
  754.     print("Invalid size.")
  755.   end
  756. end
  757.  
  758. function changeScrollSpeed()
  759.   print("Enter the new scroll speed in seconds (e.g., 0.1):")
  760.   local newSpeed = tonumber(read())
  761.   if newSpeed and newSpeed > 0 then
  762.     scrollSpeed = newSpeed
  763.     print("Scroll speed updated to " .. scrollSpeed .. " seconds.")
  764.     saveSettingsCustom()
  765.   else
  766.     print("Invalid scroll speed.")
  767.   end
  768. end
  769.  
  770. function changePauseTime()
  771.   print("Enter the new pause time in seconds (e.g., 1):")
  772.   local newPause = tonumber(read())
  773.   if newPause and newPause >= 0 then
  774.     pauseTime = newPause
  775.     print("Pause time updated to " .. pauseTime .. " seconds.")
  776.     saveSettingsCustom()
  777.   else
  778.     print("Invalid pause time.")
  779.   end
  780. end
  781.  
  782. function toggleStartupMarquee()
  783.   startupMarquee = not startupMarquee
  784.   print("Startup Marquee Mode " .. (startupMarquee and "enabled." or "disabled."))
  785.   saveSettingsCustom()
  786. end
  787.  
  788. function toggleStartupClock()
  789.   startupClock = not startupClock
  790.   print("Startup Clock Mode " .. (startupClock and "enabled." or "disabled."))
  791.   saveSettingsCustom()
  792. end
  793.  
  794. function toggleStartupStarryNight()
  795.   startupStarryNight = not startupStarryNight
  796.   print("Startup Starry Night " .. (startupStarryNight and "enabled." or "disabled."))
  797.   saveSettingsCustom()
  798. end
  799.  
  800. -----------------------------------------------------
  801. -- Starry Night Color Options
  802. -----------------------------------------------------
  803. function extrasStarryNightColorOptions()
  804.   local availableColors = {
  805.     {name = "Black",      value = "black"},
  806.     {name = "Dark Blue",  value = "darkblue"},
  807.     {name = "Dark Green", value = "darkgreen"},
  808.     {name = "Dark Aqua",  value = "darkaqua"},
  809.     {name = "Dark Red",   value = "darkred"},
  810.     {name = "Dark Purple",value = "darkpurple"},
  811.     {name = "Gold",       value = "gold"},
  812.     {name = "Gray",       value = "gray"},
  813.     {name = "Light Gray", value = "lightgray"},
  814.     {name = "Blue",       value = "blue"},
  815.     {name = "Green",      value = "green"},
  816.     {name = "Aqua",       value = "aqua"},
  817.     {name = "Red",        value = "red"},
  818.     {name = "Magenta",    value = "magenta"},
  819.     {name = "Yellow",     value = "yellow"},
  820.     {name = "White",      value = "white"},
  821.     {name = "Back",       value = "Back"}
  822.   }
  823.   local selected = 1
  824.  
  825.   local function buildOptions()
  826.     local list = {}
  827.     for i, col in ipairs(availableColors) do
  828.       list[#list+1] = col.name
  829.     end
  830.     return list
  831.   end
  832.  
  833.   while true do
  834.     local options = buildOptions()
  835.     drawCenteredMenu("Starry Night Color Options", options, selected)
  836.     local event, key = os.pullEvent("key")
  837.     if key == keys.up then
  838.       selected = (selected <= 1) and #availableColors or (selected - 1)
  839.     elseif key == keys.down then
  840.       selected = (selected >= #availableColors) and 1 or (selected + 1)
  841.     elseif key == keys.enter then
  842.       local chosen = availableColors[selected]
  843.       if chosen.value == "Back" then
  844.         break
  845.       else
  846.         starryNightColor = colors[chosen.value] or colors.yellow
  847.         print("Starry Night star color updated to " .. chosen.name)
  848.         sleep(1)
  849.       end
  850.     end
  851.   end
  852.   term.clear()
  853.   term.setCursorPos(1,1)
  854. end
  855.  
  856. -----------------------------------------------------
  857. -- Text Changer Menu
  858. -----------------------------------------------------
  859. function textChangerMenu()
  860.   local selected = 1
  861.  
  862.   local function getTextChangerOptions()
  863.     return {
  864.       "Change Text",
  865.       "Change Color",
  866.       "Change Background Color",
  867.       "Change Position",
  868.       "Change Size",
  869.       "Set Scroll Speed",
  870.       "Set Pause Time",
  871.       "Marquee Mode",
  872.       "Toggle Startup Marquee [" .. (startupMarquee and "ON" or "OFF") .. "]",
  873.       "Back"
  874.     }
  875.   end
  876.  
  877.   while true do
  878.     local options = getTextChangerOptions()
  879.     drawCenteredMenu("Text Changer", options, selected)
  880.     local event, key = os.pullEvent("key")
  881.     if key == keys.up then
  882.       selected = (selected <= 1) and #options or (selected - 1)
  883.     elseif key == keys.down then
  884.       selected = (selected >= #options) and 1 or (selected + 1)
  885.     elseif key == keys.enter then
  886.       local choice = options[selected]
  887.       if choice == "Change Text" then
  888.         changeText()
  889.       elseif choice == "Change Color" then
  890.         changeColor()
  891.       elseif choice == "Change Background Color" then
  892.         changeBackgroundColor()
  893.       elseif choice == "Change Position" then
  894.         changePosition()
  895.       elseif choice == "Change Size" then
  896.         changeSize()
  897.       elseif choice == "Set Scroll Speed" then
  898.         changeScrollSpeed()
  899.       elseif choice == "Set Pause Time" then
  900.         changePauseTime()
  901.       elseif choice == "Marquee Mode" then
  902.         parallel.waitForAny(marqueeText, terminalStarryNight)
  903.         showCuteScreen()
  904.       elseif choice:find("Toggle Startup Marquee") then
  905.         toggleStartupMarquee()
  906.       elseif choice == "Back" then
  907.         return
  908.       end
  909.     end
  910.   end
  911. end
  912.  
  913. -----------------------------------------------------
  914. -- Extras Menu
  915. -----------------------------------------------------
  916. function extrasMenu()
  917.   local selected = 1
  918.  
  919.   local function getExtrasOptions()
  920.     return {
  921.       "Starry Night",
  922.       "Starry Night Color Options",
  923.       "Clock",
  924.       "Toggle Startup Starry Night [" .. (startupStarryNight and "ON" or "OFF") .. "]",
  925.       "Toggle Startup Clock [" .. (startupClock and "ON" or "OFF") .. "]",
  926.       "Back"
  927.     }
  928.   end
  929.  
  930.   while true do
  931.     local options = getExtrasOptions()
  932.     drawCenteredMenu("Extras", options, selected)
  933.     local event, key = os.pullEvent("key")
  934.     if key == keys.up then
  935.       selected = (selected <= 1) and #options or (selected - 1)
  936.     elseif key == keys.down then
  937.       selected = (selected >= #options) and 1 or (selected + 1)
  938.     elseif key == keys.enter then
  939.       local choice = options[selected]
  940.       if choice == "Starry Night" then
  941.         extrasStarryNight()
  942.       elseif choice == "Starry Night Color Options" then
  943.         extrasStarryNightColorOptions()
  944.       elseif choice == "Clock" then
  945.         clockMonitor()
  946.       elseif choice:find("Toggle Startup Starry Night") then
  947.         toggleStartupStarryNight()
  948.       elseif choice:find("Toggle Startup Clock") then
  949.         toggleStartupClock()
  950.       elseif choice == "Back" then
  951.         return
  952.       end
  953.     end
  954.   end
  955. end
  956.  
  957. -----------------------------------------------------
  958. -- Main Menu
  959. -----------------------------------------------------
  960. function displayMainMenu()
  961.   local selected = 1
  962.   local menuOptions = {
  963.     "Text Changer",
  964.     "P2",
  965.     "P1",
  966.     "Extras",
  967.     "Exit"
  968.   }
  969. -- I had planned some fun diplay features that I never got to. (left the code in)
  970.   while true do
  971.     drawCenteredMenu("Ultimate Screen Maker", menuOptions, selected)
  972.     local event, key = os.pullEvent("key")
  973.     if key == keys.up then
  974.       selected = (selected <= 1) and #menuOptions or (selected - 1)
  975.     elseif key == keys.down then
  976.       selected = (selected >= #menuOptions) and 1 or (selected + 1)
  977.     elseif key == keys.enter then
  978.       local choice = menuOptions[selected]
  979.       if choice == "Text Changer" then
  980.         textChangerMenu()
  981.       elseif choice == "P2" then
  982.         print("Placeholder 1 not implemented.")
  983.         sleep(1)
  984.       elseif choice == "P1" then
  985.         print("Placeholder 2 not implemented.")
  986.         sleep(1)
  987.       elseif choice == "Extras" then
  988.         extrasMenu()
  989.       elseif choice == "Exit" then
  990.         term.clear()
  991.         term.setCursorPos(1,1)
  992.         term.setTextColor(colors.red)
  993.         print("Exiting program.")
  994.         term.setTextColor(colors.white)
  995.         break
  996.       end
  997.     end
  998.   end
  999. end
  1000.  
  1001. -----------------------------------------------------
  1002. -- Main Program
  1003. -----------------------------------------------------
  1004. function main()
  1005.   loadSettingsCustom()  -- load from 'settings'
  1006.   applySettings()       -- update the monitor with saved settings
  1007.  
  1008.   -- Auto-start toggles:
  1009.   if startupMarquee then
  1010.     parallel.waitForAny(marqueeText, terminalStarryNight)
  1011.     showCuteScreen()
  1012.   end
  1013.  
  1014.   if startupStarryNight then
  1015.     extrasStarryNight()
  1016.     showCuteScreen()
  1017.   end
  1018.  
  1019.   if startupClock then
  1020.     clockMonitor()
  1021.     showCuteScreen()
  1022.   end
  1023.  
  1024.   -- Main Menu
  1025.   displayMainMenu()
  1026. end
  1027.  
  1028. main()
  1029.  
Advertisement
Add Comment
Please, Sign In to add comment