jaklsfjlsak

激光扫描发射器 水平跳船 投屏 v4

Apr 21st, 2025 (edited)
576
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Laser‑Guided Warp System (“ztc”) with H/I prompts on two bottom lines
  2.  
  3. -- 1) Wrap terminal + any attached monitors
  4. local screens = {}
  5.  
  6. -- Terminal wrapper
  7. table.insert(screens, {
  8.   clear              = function() term.clear(); term.setCursorPos(1,1) end,
  9.   getSize            = function() return term.getSize() end,
  10.   setTextColor       = term.setTextColor,
  11.   setBackgroundColor = term.setBackgroundColor,
  12.   setCursorPos       = term.setCursorPos,
  13.   write              = term.write,
  14. })
  15.  
  16. -- Monitor wrappers
  17. for _, side in ipairs(peripheral.getNames()) do
  18.   if peripheral.getType(side) == "monitor" then
  19.     local m = peripheral.wrap(side)
  20.     table.insert(screens, {
  21.       clear              = function() m.clear(); m.setCursorPos(1,1) end,
  22.       getSize            = function() return m.getSize() end,
  23.       setTextColor       = function(c) m.setTextColor(c) end,
  24.       setBackgroundColor = function(c) m.setBackgroundColor(c) end,
  25.       setCursorPos       = function(x,y) m.setCursorPos(x,y) end,
  26.       write              = function(txt) m.write(txt) end,
  27.       monitor            = m,
  28.     })
  29.   end
  30. end
  31.  
  32. -- 2) Auto‑scale monitors so at least 6 lines will fit
  33. for _, s in ipairs(screens) do
  34.   if s.monitor then
  35.     local best = 0.5
  36.     for _, scale in ipairs({1, 0.5}) do
  37.       s.monitor.setTextScale(scale)
  38.       local w,h = s.getSize()
  39.       if w >= 40 and h >= 6 then
  40.         best = scale
  41.         break
  42.       end
  43.     end
  44.     s.monitor.setTextScale(best)
  45.   end
  46. end
  47.  
  48. -- 3) Helpers
  49. local function forAll(fn) for _,s in ipairs(screens) do fn(s) end end
  50.  
  51. -- Clear every screen to lightGray
  52. local function clearAll()
  53.   forAll(function(s)
  54.     s.setTextColor(colors.black)
  55.     s.setBackgroundColor(colors.lightGray)
  56.     s.clear()
  57.   end)
  58. end
  59.  
  60. -- 4) Static texts
  61. local titleText     = "Laser Guided Warp System"
  62. local subtitleText  = "Emit Scanning Laser to Warp"
  63. local offsetText    = "Mining Laser Offset ( I ): "
  64. local promptH       = "Press H for Main Menu"
  65. local promptI       = "Press I to Toggle Laser Miner Offset"
  66.  
  67. -- Draw title, subtitle, and offset‑state line
  68. local function drawStatic()
  69.   forAll(function(s)
  70.     local w,_ = s.getSize()
  71.     -- Title (line 1): white on black
  72.     local xT = math.floor((w - #titleText)/2) + 1
  73.     s.setTextColor(colors.white)
  74.     s.setBackgroundColor(colors.black)
  75.     s.setCursorPos(xT,1)
  76.     s.write(titleText)
  77.  
  78.     -- Subtitle (line 3): black on lightGray
  79.     local xS = math.floor((w - #subtitleText)/2) + 1
  80.     s.setTextColor(colors.black)
  81.     s.setBackgroundColor(colors.lightGray)
  82.     s.setCursorPos(xS,3)
  83.     s.write(subtitleText)
  84.  
  85.     -- Offset‑state (line 4)
  86.     local fullOffset = offsetText.."OFF"
  87.     local xO = math.floor((w - #fullOffset)/2) + 1
  88.     s.setTextColor(colors.black)
  89.     s.setBackgroundColor(colors.lightGray)
  90.     s.setCursorPos(1,4)
  91.     s.write(string.rep(" ", w))
  92.     s.setCursorPos(xO,4)
  93.     s.write(offsetText)
  94.     s.setTextColor(colors.white)
  95.     s.setBackgroundColor(colors.red)
  96.     s.write("OFF")
  97.   end)
  98. end
  99.  
  100. -- Draw prompts on the bottom two rows
  101. local function drawPrompt()
  102.   forAll(function(s)
  103.     local w,h = s.getSize()
  104.     -- line h-1: H prompt
  105.     s.setTextColor(colors.white)
  106.     s.setBackgroundColor(colors.blue)
  107.     s.setCursorPos(1,h-1)
  108.     s.write(string.rep(" ", w))
  109.     local xH = math.floor((w - #promptH)/2) + 1
  110.     s.setCursorPos(xH,h-1)
  111.     s.write(promptH)
  112.     -- line h: I prompt
  113.     s.setBackgroundColor(colors.blue)
  114.     s.setCursorPos(1,h)
  115.     s.write(string.rep(" ", w))
  116.     local xI = math.floor((w - #promptI)/2) + 1
  117.     s.setCursorPos(xI,h)
  118.     s.write(promptI)
  119.   end)
  120. end
  121.  
  122. -- 5) Set up warpdriveLaserCamera peripherals
  123. rednet.open("top")
  124. local cams = peripheral.getNames()
  125. for i=#cams,1,-1 do
  126.   if peripheral.getType(cams[i]) ~= "warpdriveLaserCamera" then
  127.     table.remove(cams,i)
  128.   else
  129.     peripheral.wrap(cams[i]).beamFrequency(1420)
  130.   end
  131. end
  132.  
  133. -- 6) Initial draw (blank coords)
  134. clearAll()
  135. drawStatic()
  136. drawPrompt()
  137.  
  138. -- 7) Coords line, accepts nil → blanks before first scan
  139. local function updateCoords(x,y,z)
  140.   local sx = x and tostring(x) or "    "
  141.   local sy = y and tostring(y) or "    "
  142.   local sz = z and tostring(z) or "    "
  143.   local coordLine = string.format("Target: X:%s   Y:%s   Z:%s", sx, sy, sz)
  144.   forAll(function(s)
  145.     local w,_ = s.getSize()
  146.     s.setTextColor(colors.black)
  147.     s.setBackgroundColor(colors.lightGray)
  148.     s.setCursorPos(1,5)
  149.     s.write(string.rep(" ", w))
  150.     local cx = math.floor((w - #coordLine)/2) + 1
  151.     s.setCursorPos(cx,5)
  152.     s.write(coordLine)
  153.   end)
  154. end
  155.  
  156. -- draw initial blanks
  157. updateCoords(nil,nil,nil)
  158.  
  159. -- 8) Main loop: scan + key handling
  160. while true do
  161.   local ev,a,b,c,d = os.pullEventRaw()
  162.   if ev == "laserScanning" then
  163.     local tx = tonumber(b)
  164.     local ty = tonumber(c)
  165.     local tz = tonumber(d)
  166.     updateCoords(tx,ty,tz)
  167.     local data = { x = tx, y = ty, z = tz }
  168.     rednet.broadcast(data, "HorizontalJumpBroadcast")
  169.  
  170.   elseif ev == "key" then
  171.     if a == keys.h then
  172.       os.reboot()
  173.     elseif a == keys.i then
  174.       shell.run("ztc")
  175.       -- after running ztc, re‑draw UI
  176.       clearAll()
  177.       drawStatic()
  178.       updateCoords(tx,ty,tz)
  179.       drawPrompt()
  180.     end
  181.   end
  182. end
  183.  
Advertisement
Add Comment
Please, Sign In to add comment