Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rednet.open("back")
- controller = 0
- function checkInArray(x,a)
- for i,v in ipairs(a) do
- if v == x then
- return v
- end
- end
- return nil
- end
- local function findClickArea(x,y,w,h)
- xs = {}
- ys = {}
- i = 0
- while i < w do
- table.insert(xs, x + i)
- i = i + 1
- end
- i = 0
- while i < h do
- table.insert(ys, y + i)
- i = i + 1
- end
- return {xs, ys}
- end
- function drawBox(x,y,w,h,color)
- if color ~= nil then
- term.setBackgroundColor(color)
- end
- i = 0
- while i < w do
- i2 = 0
- while i2 < h do
- term.setCursorPos(x + i, y + i2)
- term.write(" ")
- i2 = i2 + 1
- end
- i = i + 1
- end
- end
- function checkClickArea(x,y,a)
- area = {}
- area = a
- xFound = false
- yFound = false
- if checkInArray(x,area[1]) == nil then
- return false
- end
- if checkInArray(y,area[2]) == nil then
- return false
- end
- return true
- end
- function drawArray(a,startY,fixedW)
- if a == nil then
- error("The array is nil")
- end
- tab = {}
- tab = a
- pages = 1
- curPage = 1
- bPoint = 1
- if fixedW == nil then
- w,h = term.getSize()
- else
- _,h = term.getSize()
- w = fixedW
- end
- if tab[1] ~= nil then
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- x = 3
- if startY == nil then
- y = 3
- else
- y = startY
- end
- areas = {}
- items = {}
- for i,v in ipairs(tab) do
- if v == ".DS_Store" then
- table.remove(tab, i)
- end
- end
- for i,v in ipairs(tab) do
- if x + string.len(v) + 2 > w then
- x = 3
- y = y + 2
- end
- drawBox(x,y,string.len(v) + 2, 1, colors.white)
- term.setCursorPos(x + 1, y)
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.write(v)
- table.insert(areas, findClickArea(x,y,string.len(v) + 2, 1))
- if x > w-2 then
- x = 3
- y = y + 4
- else
- x = x + string.len(v) + 3
- end
- end
- for i,v in ipairs(tab) do
- table.insert(items, {v, areas[i]})
- end
- term.setTextColor(colors.white)
- while true do
- e,p1,p2,p3 = os.pullEvent()
- if e == "mouse_click" and p1 == 1 then
- for i,v in ipairs(items) do
- if checkClickArea(p2,p3,v[2]) then
- return v[1]
- end
- end
- return
- end
- end
- end
- term.setBackgroundColor(colors.black)
- end
- function clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- term.setBackgroundColor(colors.lightGray)
- clear()
- term.write("PASSWORD: ")
- password = read()
- while true do
- message = {"getTypes",password}
- message = textutils.serialize(message)
- rednet.send(controller,message)
- id,msg,d = rednet.receive(1)
- if msg == nil then
- print("PASSCODE IS PROBABLY WRONG")
- break
- end
- allTypes = textutils.unserialize(msg)
- term.setBackgroundColor(colors.lightGray)
- clear()
- table.insert(allTypes,"EXIT")
- print("ALL TYPES")
- while true do
- choiceType = drawArray(allTypes)
- if choiceType ~= nil then
- break
- end
- end
- if choiceType == "EXIT" then
- term.setBackgroundColor(colors.black)
- clear()
- break
- end
- while true do
- term.setBackgroundColor(colors.lightGray)
- clear()
- device = ""
- command = ""
- params = {}
- message = {"getAllOfType", password, choiceType}
- message = textutils.serialize(message)
- rednet.send(controller,message)
- id,msg,d = rednet.receive()
- term.setBackgroundColor(colors.lightGray)
- clear()
- deviceList = textutils.unserialize(msg)
- table.insert(deviceList,"BACK")
- print("TYPE: "..choiceType)
- while true do
- device = drawArray(deviceList)
- if device ~= nil then
- break
- end
- end
- if device == "BACK" then
- term.setBackgroundColor(colors.lightGray)
- clear()
- break
- else
- message = {"getDeviceSpecs",password,device}
- message = textutils.serialize(message)
- rednet.send(controller,message)
- id,msg,d = rednet.receive()
- deviceSpecs = textutils.unserialize(msg)
- table.insert(deviceSpecs[2], "PARAMS ON/OFF")
- table.insert(deviceSpecs[2],"BACK")
- paramsExist = false
- while true do
- term.setBackgroundColor(colors.lightGray)
- clear()
- print("DEVICE: "..device)
- print("TYPE: "..deviceSpecs[1])
- print("PARAMS: "..textutils.serialize(paramsExist))
- while true do
- command = drawArray(deviceSpecs[2],5)
- if command ~= nil then
- break
- end
- end
- if command ~= "BACK" then
- if command == "PARAMS ON/OFF" then
- paramsExist = not paramsExist
- else
- while true do
- if paramsExist then
- term.setBackgroundColor(colors.lightGray)
- clear()
- print("TYPE IN ARGUMENTS, TYPE SEND TO SEND, TYPE EXIT TO LEAVE (PRESS ENTER AFTER EACH ARGUMENT)")
- print()
- param = read()
- if string.upper(param) == "EXIT" then
- break
- elseif string.upper(param) == "SEND" then
- fullMessage = {"sendCommand",password,device,command,params}
- fullMessage = textutils.serialize(fullMessage)
- print(fullMessage)
- rednet.send(controller,fullMessage)
- params = {}
- break
- else
- table.insert(params, param)
- end
- else
- fullMessage = {"sendCommand", password, device, command, {" "}}
- fullMessage = textutils.serialize(fullMessage)
- rednet.send(controller, fullMessage)
- break
- end
- end
- end
- else
- break
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement