Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local receiverID = 1 -- Make a better system that this, maybe develop an API like system?
- local TardisData = {
- Name = "",
- Artron = 100,
- MaxArtron = 1000,
- Progress = 0,
- LastPing = 0,
- DoorState = "OPEN",
- IsRefueling = false,
- Location = {
- x = -1000000,
- y = 0,
- z = 0,
- dimension = "minecraft:overworld",
- direction = 1
- },
- Destination = {
- x = 0,
- y = 0,
- z = 0,
- dimension = "minecraft:overworld",
- direction = 1
- }
- }
- local Buttons = {}
- local TextFields = {}
- local WindowWidth, WindowHeight = term.getSize()
- local BackColor = colors.lightGray
- --WindowWidth, WindowHeight = 26, 20 --Debug ONLY
- local function directionToText(direction)
- if (direction == 1) then
- return "NORTH"
- elseif (direction == 2) then
- return "EAST"
- elseif (direction == 3) then
- return "SOUTH"
- elseif (direction == 4) then
- return "WEST"
- end
- end
- local function buttonAction(name, button)
- if (name == "go") then
- rednet.send(receiverID, "Go")
- elseif (name == "refuel") then
- rednet.send(receiverID, "Refuel")
- elseif (name == "dimension") then
- if (button == 1) then
- rednet.send(receiverID, "NextDimension")
- else
- rednet.send(receiverID, "PreviousDimension")
- end
- elseif (name == "door") then
- rednet.send(receiverID, "Door")
- elseif (name == "direction") then
- rednet.send(receiverID, "turn")
- end
- end
- local function getTardisData()
- rednet.send(receiverID, "GetData")
- local ID,Msg = rednet.receive(nil, 1)
- if (ID == receiverID) then
- TardisData = textutils.unserialiseJSON(Msg)
- -- Bid fields
- TextFields[1].text = TardisData.Destination.x
- TextFields[2].text = TardisData.Destination.y
- TextFields[3].text = TardisData.Destination.z
- -- Bind buttons
- Buttons[2].text = TardisData.Destination.dimension
- Buttons[3].text = TardisData.DoorState
- if (TardisData.DoorState == "CLOSED") then
- Buttons[3].color = colors.red
- else
- Buttons[3].color = colors.green
- end
- if (TardisData.Destination.direction == 1) then
- Buttons[5].text = "\24"
- elseif (TardisData.Destination.direction == 2) then
- Buttons[5].text = "\26"
- elseif (TardisData.Destination.direction == 3) then
- Buttons[5].text = "\25"
- elseif (TardisData.Destination.direction == 4) then
- Buttons[5].text = "\27"
- end
- end
- end
- local function load()
- peripheral.find("modem", rednet.open)
- table.insert(TextFields, {name="x", isSelected=false, x=3, y=3, w=8, h=1, text=tostring(TardisData.Destination.x)}) --1
- table.insert(TextFields, {name="y", isSelected=false, x=3, y=5, w=8, h=1, text=tostring(TardisData.Destination.y)}) --2
- table.insert(TextFields, {name="z", isSelected=false, x=3, y=7, w=8, h=1, text=tostring(TardisData.Destination.z)}) --3
- table.insert(Buttons, {name="go", x=2, y=WindowHeight-1, w=4, h=1, color=colors.green, text="Go"}) --1
- table.insert(Buttons, {name="dimension", x=3, y=9, w=WindowWidth-3, h=1, color=colors.orange, text=TardisData.Destination.dimension}) --2
- table.insert(Buttons, {name="door", x=3, y=12, w=6, h=1, color=colors.green, text=TardisData.DoorState}) --3
- table.insert(Buttons, {name="refuel", x=10, y=12, w=7, h=1, color=colors.red, text="Refuel"}) --4
- table.insert(Buttons, {name="direction", x=18, y=12, w=1, h=1, color=colors.orange, text="\24"}) --5
- table.insert(Buttons, {name="alarm", x=3, y=14, w=5, h=1, color=colors.red, text="Alarm"}) --6
- table.insert(Buttons, {name="break", x=9, y=14, w=5, h=1, color=colors.red, text="Break"}) --6
- getTardisData() -- This has to happen after so the values can be propperly assigned to the controls
- end
- local function update()
- while (true) do
- getTardisData()
- TardisData.LastPing = TardisData.LastPing + 1
- --TardisData.Progress = TardisData.Progress + 5 --Debug ONLY
- sleep(0.1)
- end
- end
- local function draw()
- while (true) do
- --term.setBackgroundColor(BackColor)
- term.setTextColor(colors.black)
- term.clear()
- -- Background
- paintutils.drawFilledBox(1,1, WindowWidth, WindowHeight, BackColor)
- -- buttons container
- paintutils.drawFilledBox(2, 11, WindowWidth-1, WindowHeight-3, colors.gray)
- -- Ping thingy
- if (TardisData.LastPing == nil or TardisData.LastPing >= 3) then
- TardisData.LastPing = 3 -- Just in case the program crashes for too long a number...
- paintutils.drawPixel(1,1, colors.red)
- term.setCursorPos(1, 1)
- term.write("NO SIGNAL")
- end
- paintutils.drawPixel(1,2, BackColor) -- Just so text background isn't red
- --Artron
- local artronString = "AU: " .. TardisData.Artron .. "/" .. TardisData.MaxArtron
- term.setCursorPos(WindowWidth - #artronString, 1)
- term.write(artronString)
- -- Destination stuff
- term.setCursorPos(1, 3)
- term.write("X:")
- term.setCursorPos(1, 5)
- term.write("Y:")
- term.setCursorPos(1, 7)
- term.write("Z:")
- term.setCursorPos(1, 9)
- term.write("D:")
- -- Location stuff
- term.setCursorPos(14, 3)
- term.write(TardisData.Location.x)
- term.setCursorPos(14, 5)
- term.write(TardisData.Location.y)
- term.setCursorPos(14, 7)
- term.write(TardisData.Location.z)
- -- Progress bar
- local barX = 9
- local maxX = (WindowWidth-barX-1)*(TardisData.Progress/100)
- for ix=1, (WindowWidth-barX-1) do
- paintutils.drawPixel(barX + ix, WindowHeight-1, BackColor)
- term.setCursorPos(barX + ix, WindowHeight-1)
- if (maxX <= ix) then
- term.write("\127")
- else
- paintutils.drawPixel(barX + ix, WindowHeight-1, colors.black)
- --term.write("\143")
- end
- end
- -- Buttons
- term.setTextColor(colors.white)
- for i,b in ipairs(Buttons) do
- paintutils.drawBox(b.x, b.y, b.x-1+b.w, b.y-1+b.h, b.color)
- term.setCursorPos(b.x, b.y)
- term.write(b.text)
- end
- -- TextFields
- term.setTextColor(colors.white)
- for i,b in ipairs(TextFields) do
- paintutils.drawBox(b.x, b.y, b.x-1+b.w, b.y-1+b.h, colors.black)
- term.setCursorPos(b.x, b.y)
- if (b.isSelected) then
- term.write(b.text .. "_")
- else
- term.write(b.text)
- end
- end
- sleep(0.1)
- end
- end
- local function onClick()
- while true do
- local event, button, x, y = os.pullEvent("mouse_click")
- -- Buttons
- for i,b in ipairs(Buttons) do
- if ((x >= b.x and x <= b.x-1+b.w) and (y >= b.y and y <= b.y-1+b.h)) then
- buttonAction(b.name, button)
- end
- end
- -- TextFields
- for i,b in ipairs(TextFields) do
- if ((x >= b.x and x <= b.x-1+b.w) and (y >= b.y and y <= b.y-1+b.h)) then
- for _,t in ipairs(TextFields) do
- t.isSelected = false
- end
- b.isSelected = true
- end
- end
- end
- end
- local function onKey()
- while (true) do
- local event, key, is_held = os.pullEvent("key")
- local keyString = keys.getName(key)
- if (keyString == "one") then
- keyString = "1"
- elseif (keyString == "two") then
- keyString = "2"
- elseif (keyString == "three") then
- keyString = "3"
- elseif (keyString == "four") then
- keyString = "4"
- elseif (keyString == "five") then
- keyString = "5"
- elseif (keyString == "six") then
- keyString = "6"
- elseif (keyString == "seven") then
- keyString = "7"
- elseif (keyString == "eight") then
- keyString = "8"
- elseif (keyString == "nine") then
- keyString = "9"
- elseif (keyString == "zero") then
- keyString = "0"
- elseif (keyString == "backspace" or keyString == "enter" or keyString == "slash") then
- keyString = keyString
- else
- goto continue
- end
- for i,b in ipairs(TextFields) do
- if (b.isSelected) then
- if (keyString == "backspace") then
- b.text = b.text:sub(1, -2)
- if (#b.text <= 0) then
- b.text = "0"
- end
- elseif (keyString == "enter") then
- b.isSelected = false
- elseif (keyString == "slash") then
- b.text = "-" .. b.text
- else
- if (b.text == "0") then
- b.text = keyString
- else
- b.text = b.text .. keyString
- end
- end
- -- send new target coords
- rednet.send(receiverID, "SetDestination " .. TextFields[1].text .. " " .. TextFields[2].text .. " " .. TextFields[3].text)
- break
- end
- end
- ::continue::
- end
- end
- load()
- parallel.waitForAny(update, draw, onClick, onKey)
Advertisement
Add Comment
Please, Sign In to add comment