Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mon = peripheral.find("monitor")
- modem = peripheral.find("modem")
- ids = {0,1,2, 9}
- data = {}
- for i=1, 6 do
- data[i] = 0
- end
- rednet.open("left")
- selected = 1
- num_turtles = table.getn(ids)
- function draw_text(x, y, text, text_color, bg_color)
- mon.setBackgroundColor(bg_color)
- mon.setTextColor(text_color)
- mon.setCursorPos(x,y)
- mon.write(text)
- end
- function draw_line(x, y, length, color)
- if length < 0 then
- length = 0
- end
- mon.setBackgroundColor(color)
- mon.setCursorPos(x,y)
- mon.write(string.rep(" ", length))
- end
- function progress_bar(x, y, length, minVal, maxVal, bar_color, bg_color)
- draw_line(x, y, length, bg_color) --backgoround bar
- local barSize = math.floor((minVal/maxVal) * length)
- draw_line(x, y, barSize, bar_color) --progress so far
- end
- function clear()
- --term.clear()
- --term.setCursorPos(1,1)
- mon.setBackgroundColor(colors.black)
- mon.clear()
- mon.setCursorPos(1,1)
- end
- function baseGUI(label, fuel, posX, posY, posZ, status)
- draw_text(2, 2, "<--", colors.white, colors.gray)
- draw_text(25, 2, "-->", colors.white, colors.gray)
- draw_text((13 - string.len(label) / 2), 2, label, colors.green, colors.white)
- draw_text(4, 6, "Status: " .. status, colors.blue, colors.white)
- draw_text(4, 8, "Fuel level: " .. ((fuel / 20000) * 100) .. "%", colors.orange, colors.white)
- progress_bar(4, 10, 19, fuel, 20000, colors.green, colors.red) draw_text(4, 12, "X: " .. posX, colors.black, colors.orange)
- draw_text(4, 14, "Y: " .. posY, colors.black, colors.orange)
- draw_text(4, 16, "Z: " .. posZ, colors.black, colors.orange)
- draw_text( 5, 2, ids[selected], colors.red, colors.gray)
- end
- function draw()
- while(true) do
- baseGUI(data[1], data[2], data[3], data[4], data[5], data[6])
- sleep(0.0001)
- clear()
- end
- end
- function ping()
- while(true) do
- rednet.send(ids[selected], "send", "ping")
- sleep(0.01)
- end
- end
- function update()
- while true do
- local sender, message, protocol = rednet.receive("miners")
- if(sender == ids[selected]) then
- local k = 1
- for token in string.gmatch(message, "[^%s]+") do
- if(token == null) then
- data[k] = 0
- else
- data[k] = token
- end
- k = k + 1
- end
- end
- sleep(0.0001)
- end
- end
- function buttons()
- while true do
- event, side, xPos, yPos = os.pullEvent("monitor_touch")
- if(yPos == 2) then
- if(xPos >=2 and xPos <= 4) then
- selected = selected - 1
- if(selected < 1) then
- selected = num_turtles
- end
- else if(xPos >= 25 and xPos <= 27) then
- selected = selected + 1
- if(selected > num_turtles) then
- selected = 1
- end
- end
- end
- end
- sleep(0.01)
- end
- end
- function failsafe()
- while true do
- rednet.broadcast(" ", "failsafe")
- sleep(2)
- end
- end
- parallel.waitForAll(update, buttons, failsafe, ping, draw)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement