Advertisement
jaklsfjlsak

集成尝试420 投屏 v2

Apr 20th, 2025 (edited)
234
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 content
  31. local titleText      = "Main Menu"
  32. local optionOneText  = "Horizontal Mining System "
  33. local optionOneKey   = "(Press M)"
  34. local optionTwoText  = "Laser Guided Warp System "
  35. local optionTwoKey   = "(Press J)"
  36.  
  37. -- Determine total option lengths
  38. local optionOneTotal = optionOneText .. optionOneKey
  39. local optionTwoTotal = optionTwoText .. optionTwoKey
  40.  
  41. -- Auto-scale monitors so our 5-line layout (lines 1,3,5) fits
  42. for _, s in ipairs(screens) do
  43.   if s.monitor then
  44.     local chosen = 0.5
  45.     for _, scale in ipairs({1, 0.5}) do
  46.       s.monitor.setTextScale(scale)
  47.       local w,h = s.getSize()
  48.       if w >= #optionTwoTotal and h >= 5 then
  49.         chosen = scale
  50.         break
  51.       end
  52.     end
  53.     s.monitor.setTextScale(chosen)
  54.   end
  55. end
  56.  
  57. -- Helper: apply fn to every screen
  58. local function forAll(fn)
  59.   for _, s in ipairs(screens) do fn(s) end
  60. end
  61.  
  62. -- Draw the centered menu:
  63. --   • Title at Y=1 in white-on-black
  64. --   • OptionOne at Y=3: preText black-on-lightGray, key white-on-lime
  65. --   • OptionTwo at Y=5: same styling
  66. local function drawMenu()
  67.   for _, s in ipairs(screens) do
  68.     -- clear to light gray base
  69.     s.setTextColor(colors.black)
  70.     s.setBackgroundColor(colors.lightGray)
  71.     s.clear()
  72.     local w,h = s.getSize()
  73.  
  74.     -- Title (line 1) in white-on-black
  75.     local xT = math.floor((w - #titleText)/2) + 1
  76.     s.setTextColor(colors.white)
  77.     s.setBackgroundColor(colors.black)
  78.     s.setCursorPos(xT, 1)
  79.     s.write(titleText)
  80.  
  81.     -- Option 1 (line 3)
  82.     local x1 = math.floor((w - #optionOneTotal)/2) + 1
  83.     s.setCursorPos(x1, 3)
  84.     -- preText
  85.     s.setTextColor(colors.black)
  86.     s.setBackgroundColor(colors.lightGray)
  87.     s.write(optionOneText)
  88.     -- key portion
  89.     s.setTextColor(colors.white)
  90.     s.setBackgroundColor(colors.lime)
  91.     s.write(optionOneKey)
  92.  
  93.     -- Option 2 (line 5)
  94.     local x2 = math.floor((w - #optionTwoTotal)/2) + 1
  95.     s.setCursorPos(x2, 5)
  96.     s.setTextColor(colors.black)
  97.     s.setBackgroundColor(colors.lightGray)
  98.     s.write(optionTwoText)
  99.     s.setTextColor(colors.white)
  100.     s.setBackgroundColor(colors.lime)
  101.     s.write(optionTwoKey)
  102.   end
  103. end
  104.  
  105. -- Initial draw
  106. drawMenu()
  107.  
  108. -- Reset to default colors & clear (for loading external scripts)
  109. local function resetColors()
  110.   forAll(function(s)
  111.     s.setTextColor(colors.white)
  112.     s.setBackgroundColor(colors.black)
  113.     s.clear()
  114.   end)
  115. end
  116.  
  117. -- Load a pastebin script if missing, then re‑draw the menu
  118. local function loadIfMissing(name,id)
  119.   if not fs.exists(name) then
  120.     resetColors()
  121.     shell.run("pastebin get "..id.." "..name)
  122.     drawMenu()
  123.   end
  124. end
  125.  
  126. loadIfMissing("jzc","rfXW7SiN")
  127. loadIfMissing("ztc","qs4SAcmL")
  128. loadIfMissing("itc","fXLxQmpe")
  129. loadIfMissing("otc","0bWu4YgN")
  130.  
  131. -- Main key loop
  132. while true do
  133.   local _, key = os.pullEvent("key")
  134.   if key == keys.m then
  135.     -- Feedback
  136.     forAll(function(s)
  137.       s.clear()
  138.       s.setTextColor(colors.black)
  139.       s.setBackgroundColor(colors.lightGray)
  140.       s.setCursorPos(1,1)
  141.       s.write("Booting Horizontal Mining System...")
  142.     end)
  143.     resetColors()
  144.     shell.run("jzc")
  145.     drawMenu()
  146.  
  147.   elseif key == keys.j then
  148.     forAll(function(s)
  149.       s.clear()
  150.       s.setTextColor(colors.black)
  151.       s.setBackgroundColor(colors.lightGray)
  152.       s.setCursorPos(1,1)
  153.       s.write("Booting Laser Guided Warp System...")
  154.     end)
  155.     resetColors()
  156.     shell.run("ztc")
  157.     drawMenu()
  158.   end
  159. end
  160.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement