Advertisement
jaklsfjlsak

集成尝试420 投屏

Apr 20th, 2025 (edited)
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Wrap the terminal and any attached CC:Tweaked monitors as “screens”
  2. local screens = {}
  3.  
  4. -- Terminal wrapper
  5. table.insert(screens, {
  6.   clear              = function() term.clear() term.setCursorPos(1,1) end,
  7.   getSize            = function() return term.getSize() end,
  8.   setTextColor       = term.setTextColor,
  9.   setBackgroundColor = term.setBackgroundColor,
  10.   setCursorPos       = term.setCursorPos,
  11.   write              = term.write,
  12. })
  13.  
  14. -- Monitor wrappers
  15. for _, side in ipairs(peripheral.getNames()) do
  16.   if peripheral.getType(side) == "monitor" then
  17.     local m = peripheral.wrap(side)
  18.     table.insert(screens, {
  19.       clear              = function() m.clear() m.setCursorPos(1,1) end,
  20.       getSize            = function() return m.getSize() end,
  21.       setTextColor       = function(c) m.setTextColor(c) end,
  22.       setBackgroundColor = function(c) m.setBackgroundColor(c) end,
  23.       setCursorPos       = function(x,y) m.setCursorPos(x,y) end,
  24.       write              = function(txt) m.write(txt) end,
  25.       monitor            = m,
  26.     })
  27.   end
  28. end
  29.  
  30. -- Menu lines
  31. local titleText = "Main Menu"
  32. local optionOne = "Horizontal Mining System (Press M)"
  33. local optionTwo = "Laser Guided Warp System (Press J)"
  34.  
  35. -- Auto-scale monitors so our 5‐line layout (lines 1,3,5) always fits
  36. for _, s in ipairs(screens) do
  37.   if s.monitor then
  38.     local chosen = 0.5
  39.     for _, scale in ipairs({1, 0.5}) do
  40.       s.monitor.setTextScale(scale)
  41.       local w,h = s.getSize()
  42.       if w >= #optionTwo and h >= 5 then
  43.         chosen = scale
  44.         break
  45.       end
  46.     end
  47.     s.monitor.setTextScale(chosen)
  48.   end
  49. end
  50.  
  51. -- Helper: apply fn to every screen
  52. local function forAll(fn)
  53.   for _, s in ipairs(screens) do fn(s) end
  54. end
  55.  
  56. -- Draw the centered menu:
  57. --   • Title at Y=1 in white-on-blue
  58. --   • OptionOne at Y=3 in black-on-lightGray
  59. --   • OptionTwo at Y=5 in black-on-lightGray
  60. local function drawMenu()
  61.   for _, s in ipairs(screens) do
  62.     -- Clear to light gray base
  63.     s.setTextColor(colors.black)
  64.     s.setBackgroundColor(colors.lightGray)
  65.     s.clear()
  66.     local w,h = s.getSize()
  67.  
  68.     -- Title (line 1) in white-on-blue
  69.     local xT = math.floor((w - #titleText)/2) + 1
  70.     s.setTextColor(colors.white)
  71.     s.setBackgroundColor(colors.blue)
  72.     s.setCursorPos(xT, 1)
  73.     s.write(titleText)
  74.  
  75.     -- Option 1 (line 3) in black-on-lightGray
  76.     local x1 = math.floor((w - #optionOne)/2) + 1
  77.     s.setTextColor(colors.black)
  78.     s.setBackgroundColor(colors.lightGray)
  79.     s.setCursorPos(x1, 3)
  80.     s.write(optionOne)
  81.  
  82.     -- Option 2 (line 5) in black-on-lightGray
  83.     local x2 = math.floor((w - #optionTwo)/2) + 1
  84.     s.setCursorPos(x2, 5)
  85.     s.write(optionTwo)
  86.   end
  87. end
  88.  
  89. -- Initial draw
  90. drawMenu()
  91.  
  92. -- Reset to default colors & clear (for loading external scripts)
  93. local function resetColors()
  94.   forAll(function(s)
  95.     s.setTextColor(colors.white)
  96.     s.setBackgroundColor(colors.black)
  97.     s.clear()
  98.   end)
  99. end
  100.  
  101. -- Load a pastebin script if missing, then re‑draw the menu
  102. local function loadIfMissing(name,id)
  103.   if not fs.exists(name) then
  104.     resetColors()
  105.     shell.run("pastebin get "..id.." "..name)
  106.     drawMenu()
  107.   end
  108. end
  109.  
  110. loadIfMissing("jzc","rfXW7SiN")
  111. loadIfMissing("ztc","S9SW0zHJ")
  112.  
  113. -- Main key loop
  114. while true do
  115.   local _, key = os.pullEvent("key")
  116.   if key == keys.m then
  117.     -- Feedback
  118.     forAll(function(s)
  119.       s.clear()
  120.       s.setTextColor(colors.black)
  121.       s.setBackgroundColor(colors.lightGray)
  122.       s.setCursorPos(1,1)
  123.       s.write("Booting Horizontal Mining System...")
  124.     end)
  125.     resetColors()
  126.     shell.run("jzc")
  127.     drawMenu()
  128.  
  129.   elseif key == keys.j then
  130.     forAll(function(s)
  131.       s.clear()
  132.       s.setTextColor(colors.black)
  133.       s.setBackgroundColor(colors.lightGray)
  134.       s.setCursorPos(1,1)
  135.       s.write("Booting Laser Guided Warp System...")
  136.     end)
  137.     resetColors()
  138.     shell.run("ztc")
  139.     drawMenu()
  140.   end
  141. end
  142.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement