Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local controlId = 6
- os.loadAPI("buttonLib.lua")
- local inspectData
- local inventoryData
- local lastResponse = ""
- local buttons
- local buildSide = "forward"
- local markDraw = false
- local function draw()
- term.setBackgroundColor(colours.black)
- term.clear()
- term.setBackgroundColor(colours.green)
- term.setTextColor(colours.black)
- for i, object in ipairs(buttons) do
- buttonLib.draw(object)
- end
- term.setBackgroundColor(colors.white);
- term.setTextColor(colors.black);
- if buildSide == "forward" then
- term.setCursorPos(18, 13)
- term.write("---")
- elseif buildSide == "up" then
- term.setCursorPos(18, 12)
- term.write("^^^")
- elseif buildSide == "down" then
- term.setCursorPos(18, 14)
- term.write("vvv")
- end
- term.setBackgroundColor(colours.black)
- term.setTextColor(colors.white)
- if inspectData then
- if inspectData.top then
- term.setCursorPos(26-string.len(inspectData.top.name),1)
- term.write(inspectData.top.name)
- end
- if inspectData.forward then
- term.setCursorPos(26-string.len(inspectData.forward.name),5)
- term.write(inspectData.forward.name)
- end
- if inspectData.bottom then
- term.setCursorPos(26-string.len(inspectData.bottom.name),9)
- term.write(inspectData.bottom.name)
- end
- end
- if inventoryData then
- if inventoryData.slots[inventoryData.current] then
- term.setCursorPos(3,18)
- term.write(inventoryData.slots[inventoryData.current].name)
- end
- term.setCursorPos(1, 1)
- term.write("Fuel: " .. inventoryData.fuel)
- local count = inventoryData.slots.length
- local yOffset
- for i=1,16,1 do
- local xOffset = ((i-1) % 4) * 3
- if (i-1) % 4 == 0 then
- yOffset = ((i-1) / 4) * 2
- end
- term.setCursorPos(3 + xOffset, 11 + yOffset)
- if i == inventoryData.current then
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- end
- if inventoryData.slots[i] then
- term.write(inventoryData.slots[i].count)
- else
- term.write(0)
- end
- if i == inventoryData.current then
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- end
- end
- end
- term.setCursorPos(1, 19)
- term.setTextColor(colors.white)
- print("> " .. tostring(lastResponse))
- end
- local function click(x,y,n)
- if not n == 1 then
- return
- end
- for i, object in ipairs(buttons) do
- if buttonLib.inBounds(object,x, y) then
- if object.action then
- object.action()
- end
- end
- end
- end
- local function send(msg)
- rednet.send(controlId, msg)
- end
- local function key(keyCode)
- if keyCode == keys.a then
- send("left")
- elseif keyCode == keys.d then
- send("right")
- elseif keyCode == keys.w then
- send("forward")
- elseif keyCode == keys.s then
- send("back")
- elseif keyCode == keys.space then
- send("up")
- elseif keyCode == keys.leftShift then
- send("down")
- elseif keyCode == keys.one then
- buildSide = "down"
- lastResponse = "Build Dir: Down"
- markDraw = true
- elseif keyCode == keys.two then
- buildSide = "forward"
- lastResponse = "Build Dir: Forward"
- markDraw = true
- elseif keyCode == keys.three then
- buildSide = "up"
- lastResponse = "Build Dir: Up"
- markDraw = true
- elseif keyCode == keys.down then
- if buildSide == "forward" then
- buildSide = "down"
- elseif buildSide == "up" then
- buildSide = "forward"
- end
- lastResponse = "Build Dir: " .. buildSide
- markDraw = true
- elseif keyCode == keys.up then
- if buildSide == "forward" then
- buildSide = "up"
- elseif buildSide == "down" then
- buildSide = "forward"
- end
- lastResponse = "Build Dir: " .. buildSide
- markDraw = true
- elseif keyCode == keys.left then
- if buildSide == "forward" then
- send("dig")
- elseif buildSide == "up" then
- send("digUp")
- elseif buildSide == "down" then
- send("digDown")
- end
- elseif keyCode == keys.right then
- if buildSide == "forward" then
- send("place")
- elseif buildSide == "up" then
- send("placeUp")
- elseif buildSide == "down" then
- send("placeDown")
- end
- elseif keyCode == keys.q then
- if inventoryData then
- if inventoryData.current > 1 then
- send("select " .. inventoryData.current - 1)
- end
- else
- send("select 1")
- end
- elseif keyCode == keys.e then
- if inventoryData then
- if inventoryData.current < 16 then
- send("select " .. inventoryData.current + 1)
- end
- else
- send("select 1")
- end
- end
- end
- local function net(id, msgBundle)
- if not id == controlId then
- return
- end
- for i, object in ipairs(msgBundle) do
- local message = object;
- local type = message.type
- local data = message.message
- if type == "inventory" then
- inventoryData = data
- markDraw = true
- elseif type == "inspect" then
- inspectData = data
- markDraw = true
- else
- lastResponse = data
- markDraw = true
- end
- end
- end
- buttons = {
- buttonLib.new(2, 2, 4, 3, "Up",
- function()
- send("up")
- end
- ),
- buttonLib.new(7, 2, 4, 3, "FW",
- function()
- send("forward")
- end
- ),
- buttonLib.new(12, 2, 4, 3, "DW",
- function()
- send("down")
- end
- ),
- buttonLib.new(2, 6, 4, 3, "LF",
- function()
- send("left")
- end
- ),
- buttonLib.new(7, 6, 4, 3, "BK",
- function()
- send("back")
- end
- ),
- buttonLib.new(12, 6, 4, 3, "RT",
- function()
- send("right")
- end
- ),
- buttonLib.new(17, 2, 4, 3, "DU",
- function()
- send("digUp")
- end
- ),
- buttonLib.new(17, 6, 4, 3, "DG",
- function()
- send("dig")
- end
- ),
- buttonLib.new(17, 10, 4, 3, "DD",
- function()
- send("digDown")
- end
- ),
- buttonLib.new(22, 2, 4, 3, "PU",
- function()
- send("placeUp")
- end
- ),
- buttonLib.new(22, 6, 4, 3, "PL",
- function()
- send("place")
- end
- ),
- buttonLib.new(22, 10, 4, 3, "PD",
- function()
- send("placeDown")
- end
- ),
- buttonLib.new(3, 10, 2, 1, "01",
- function()
- send("select 1")
- end
- ),
- buttonLib.new(6, 10, 2, 1, "02",
- function()
- send("select 2")
- end
- ),
- buttonLib.new(9, 10, 2, 1, "03",
- function()
- send("select 3")
- end
- ),
- buttonLib.new(12, 10, 2, 1, "04",
- function()
- send("select 4")
- end
- ),
- buttonLib.new(3, 12, 2, 1, "05",
- function()
- send("select 5")
- end
- ),
- buttonLib.new(6, 12, 2, 1, "06",
- function()
- send("select 6")
- end
- ),
- buttonLib.new(9, 12, 2, 1, "07",
- function()
- send("select 7")
- end
- ),
- buttonLib.new(12, 12, 2, 1, "08",
- function()
- send("select 8")
- end
- ),
- buttonLib.new(3, 14, 2, 1, "09",
- function()
- send("select 9")
- end
- ),
- buttonLib.new(6, 14, 2, 1, "10",
- function()
- send("select 10")
- end
- ),
- buttonLib.new(9, 14, 2, 1, "11",
- function()
- send("select 11")
- end
- ),
- buttonLib.new(12, 14, 2, 1, "12",
- function()
- send("select 12")
- end
- ),
- buttonLib.new(3, 16, 2, 1, "13",
- function()
- send("select 13")
- end
- ),
- buttonLib.new(6, 16, 2, 1, "14",
- function()
- send("select 14")
- end
- ),
- buttonLib.new(9, 16, 2, 1, "15",
- function()
- send("select 15")
- end
- ),
- buttonLib.new(12, 16, 2, 1, "16",
- function()
- send("select 16")
- end
- ),
- buttonLib.new(18, 12, 3, 1, "^",
- function()
- buildSide = "up"
- end
- ),
- buttonLib.new(18, 13, 3, 1, "-",
- function()
- buildSide = "forward"
- end
- ),
- buttonLib.new(18, 14, 3, 1, "v",
- function()
- buildSide = "down"
- end
- ),
- }
- rednet.close("back")
- rednet.open("back")
- markDraw = true
- send("inventory")
- while true do
- local event, n, x, y = os.pullEvent()
- if event == "mouse_click" then
- click(x,y,n)
- elseif event == "key" then
- key(n)
- elseif event == "rednet_message" then
- net(n,x)
- end
- if markDraw then
- markDraw = false
- draw()
- end
- end
Add Comment
Please, Sign In to add comment