Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Mini-Map Guided Ship Jump UI + Chat-Driven Broadcaster
- -- 1) Wrap terminal + any attached monitors
- local screens = {}
- -- Terminal
- table.insert(screens, {
- clear = function() term.clear(); term.setCursorPos(1,1) end,
- getSize = function() return term.getSize() end,
- setTextColor = term.setTextColor,
- setBackgroundColor = term.setBackgroundColor,
- setCursorPos = term.setCursorPos,
- write = term.write,
- })
- -- Monitors
- for _, side in ipairs(peripheral.getNames()) do
- if peripheral.getType(side) == "monitor" then
- local m = peripheral.wrap(side)
- table.insert(screens, {
- clear = function() m.clear(); m.setCursorPos(1,1) end,
- getSize = function() return m.getSize() end,
- setTextColor = function(c) m.setTextColor(c) end,
- setBackgroundColor = function(c) m.setBackgroundColor(c) end,
- setCursorPos = function(x,y) m.setCursorPos(x,y) end,
- write = function(txt) m.write(txt) end,
- monitor = m,
- })
- end
- end
- -- 2) Auto-scale monitors so at least 7 lines will fit (like your warp-system UI)
- for _, s in ipairs(screens) do
- if s.monitor then
- local best = 0.5
- for _, scale in ipairs({1, 0.5}) do
- s.monitor.setTextScale(scale)
- local w,h = s.getSize()
- if w >= 40 and h >= 7 then
- best = scale
- break
- end
- end
- s.monitor.setTextScale(best)
- end
- end
- -- 3) Helpers
- local function forAll(fn) for _,s in ipairs(screens) do fn(s) end end
- local function clearAll()
- forAll(function(s)
- s.setTextColor(colors.black)
- s.setBackgroundColor(colors.lightGray)
- s.clear()
- end)
- end
- -- 4) UI Text
- local titleText = "Mini Map Guided Ship Jump"
- local statusText = "Mining Laser Offset (O): "
- local indicator = "ON"
- local promptO = "Press O to Toggle Offset"
- local promptH = "Press H to Return to Main Menu"
- -- track last coords for redraw
- local lastX, lastY, lastZ = nil, nil, nil
- -- 5) Draw static UI (title, status, prompts)
- local function drawUI()
- forAll(function(s)
- local w,h = s.getSize()
- -- title (line 1)
- local xT = math.floor((w - #titleText)/2) + 1
- s.setTextColor(colors.white); s.setBackgroundColor(colors.black)
- s.setCursorPos(xT,1); s.write(titleText)
- -- status (line 4)
- local full = statusText..indicator
- local xS = math.floor((w - #full)/2) + 1
- s.setTextColor(colors.black); s.setBackgroundColor(colors.lightGray)
- s.setCursorPos(1,4); s.write(string.rep(" ", w))
- s.setCursorPos(xS,4); s.write(statusText)
- s.setTextColor(colors.white); s.setBackgroundColor(colors.lime)
- s.write(indicator)
- -- prompt O (line h-1)
- s.setTextColor(colors.white); s.setBackgroundColor(colors.blue)
- s.setCursorPos(1,h-1); s.write(string.rep(" ", w))
- local xO2 = math.floor((w - #promptO)/2) + 1
- s.setCursorPos(xO2,h-1); s.write(promptO)
- -- prompt H (line h)
- s.setCursorPos(1,h); s.write(string.rep(" ", w))
- local xH2 = math.floor((w - #promptH)/2) + 1
- s.setCursorPos(xH2,h); s.write(promptH)
- end)
- end
- -- 6) Coords line renderer (now on line 6, leaving line 5 blank)
- local function updateCoords(x,y,z)
- lastX, lastY, lastZ = x,y,z
- local sx = x and tostring(x) or " "
- local sy = y and tostring(y) or " "
- local sz = z and tostring(z) or " "
- local coordLine = string.format("Target: X:%s Y:%s Z:%s", sx, sy, sz)
- forAll(function(s)
- local w,_ = s.getSize()
- s.setTextColor(colors.black); s.setBackgroundColor(colors.lightGray)
- s.setCursorPos(1,6); s.write(string.rep(" ", w))
- local cx = math.floor((w - #coordLine)/2) + 1
- s.setCursorPos(cx,6); s.write(coordLine)
- end)
- end
- -- 7) Initial draw
- clearAll()
- drawUI()
- updateCoords(nil,nil,nil)
- -- 8) Chat-listener coroutine
- local chat = peripheral.find("warpdriveVirtualAssistant")
- assert(chat, "warpdriveVirtualAssistant not found!")
- chat.name("[name")
- local function chatListener()
- while true do
- sleep(0.08)
- local ok, CMD = chat.pullLastCommand()
- if ok then
- local txt = string.lower(CMD or "")
- local x_val,y_val,z_val = txt:match(".*x:(%-?%d+),%s*y:(%-?%d+),%s*z:(%-?%d+)")
- if x_val and y_val and z_val then
- local x,y,z = tonumber(x_val), tonumber(y_val), tonumber(z_val)
- print(("Broadcasting coordinates → x:%d, y:%d, z:%d"):format(x,y,z))
- rednet.broadcast({ x=x, y=y, z=z }, "ONJMcoordBroadcast")
- updateCoords(x,y,z)
- else
- print("No valid coords in command:", CMD)
- end
- end
- end
- end
- -- 9) UI-handler coroutine
- local function uiHandler()
- while true do
- local ev, key = os.pullEventRaw("key")
- if key == keys.o then
- shell.run("minoffj")
- clearAll(); drawUI(); updateCoords(lastX,lastY,lastZ)
- elseif key == keys.h then
- os.reboot()
- end
- end
- end
- -- 10) Open Rednet on every modem
- for _, side in ipairs(peripheral.getNames()) do
- if peripheral.getType(side) == "modem" then
- rednet.open(side)
- end
- end
- -- 11) Run both loops in parallel
- parallel.waitForAll(chatListener, uiHandler)
Advertisement
Add Comment
Please, Sign In to add comment