Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("GUIElements")
- local args = {...}
- --Name, Text, BlinkText, FirstColor, SecondColor, FirstTextColor, SecondTextColor, PosX, PosY, Blink
- local StatusPoint = GUIElements.CreateBlinkPoint("SP", "Undefined", nil, colors.green, colors.white, nil, nil, 2, 1)
- local InfoPoint = GUIElements.CreateBlinkPoint("IP", "Commands: 'p', 's', 'b'.", ">", colors.green, colors.white, nil, nil, 2, 3)
- local FuelPoint = GUIElements.CreateBlinkPoint("FP", "Fuel: " .. 0, ">", colors.green, colors.white, nil, nil, 2, 6)
- local ConnectPoint = GUIElements.CreateBlinkPoint("CP", "No modem", ">", colors.red, colors.white, nil, nil, 2, 8)
- --Define variable
- local serveraddress = nil
- local running = true
- local status = "paused"
- local isConnect = 0 -- '-1' - no modem; '0' - connect; '1' - connected.
- local fuel = 0
- local statcolor = {}
- statcolor["mining"] = colors.green
- statcolor["paused"] = colors.yellow
- statcolor["no_fuel"] = colors.red
- statcolor["undefined"] = colors.gray
- --Utils
- local function Exit()
- running = false
- GUIElements.DestroyBlinkPoint(StatusPoint.name)
- GUIElements.DestroyBlinkPoint(InfoPoint.name)
- GUIElements.DestroyBlinkPoint(FuelPoint.name)
- GUIElements.DestroyBlinkPoint(ConnectPoint.name)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.setCursorPos(1, 1)
- term.clear()
- end
- --message status fuel ... end
- local function ParseMessage(msg)
- local _msg = msg
- local strings = {}
- while _msg ~= "end" do
- local si = string.find(_msg, "%s")
- table.insert(strings, string.sub(_msg, 1, si-1))
- _msg = string.sub(_msg, si+1, -1)
- end
- if strings[1] == "packet" then
- status = strings[2]
- fuel = strings[3]
- end
- end
- --Program
- local function GUI()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.gray)
- term.clear()
- while running do
- StatusPoint.text = status
- StatusPoint.fcolor = statcolor[status]
- FuelPoint.text = "Fuel: " .. fuel
- GUIElements.DrawPoints()
- os.sleep(1)
- end
- end
- local function ncGUI()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- StatusPoint.fcolor = colors.white
- InfoPoint.fcolor = colors.white
- FuelPoint.fcolor = colors.white
- ConnectPoint.fcolor = colors.white
- StatusPoint.scolor = colors.black
- InfoPoint.scolor = colors.black
- FuelPoint.scolor = colors.black
- ConnectPoint.scolor = colors.black
- StatusPoint.ftcolor = colors.white
- InfoPoint.ftcolor = colors.white
- FuelPoint.ftcolor = colors.white
- ConnectPoint.ftcolor = colors.white
- StatusPoint.stcolor = colors.black
- InfoPoint.stcolor = colors.black
- FuelPoint.stcolor = colors.black
- ConnectPoint.stcolor = colors.black
- while running do
- StatusPoint.text = status
- FuelPoint.text = "Fuel: " .. fuel
- GUIElements.DrawPoints()
- os.sleep(1)
- end
- end
- local function UserControl()
- while running do
- local event, par1, par2, par3 = os.pullEvent()
- if (event == "char") then
- if par1 == "p" then
- rednet.send(address, "paused", "TurtleControl1")
- elseif par1 == "s" then
- rednet.send(address, "stop", "TurtleControl1")
- Exit()
- end
- elseif (event == "rednet_message" and par1 == address and par3 == "TurtleControl1") then
- ParseMessage(par2)
- if status == "stop" then Exit() end
- end
- end
- end
- local sModemSide = nil
- for n, sSide in ipairs(rs.getSides()) do
- if peripheral.getType(sSide) == "modem" and peripheral.call(sSide, "isWireless") then
- sModemSide = sSide
- break
- end
- end
- if not sModemSide then Exit() end
- if args[1] and type(args[1] + 0) == "number" then
- address = args[1] + 0
- else Exit() end
- if sModemSide and address then
- rednet.open(sModemSide)
- isConnect = 0
- end
- if term.isColor() then
- parallel.waitForAll(GUI, UserControl)
- else
- parallel.waitForAll(ncGUI, UserControl)
- end
- rednet.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement