Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- ajustable grid -- concept test
- by big SHiny Toys
- ]]--
- local ver = "0.1aplha"
- local function test(...)
- term.setCursorPos(1,1)
- print(...)
- local event,number = os.pullEvent()
- if event == "key" and number == 14 then
- error()
- end
- end
- --[[
- {"type","player","other","y/n","number",},
- {"random type","Offline","I dont know what",true,7},
- {"random type","Offline","I dont know what",true,7},
- {"random type","Offline","I dont know what",true,7},
- {"random type","Offline","I dont know what",true,7},
- {"random type","Offline","I dont know what",true,7},
- {"random type","Offline","I dont know what",true,7},
- {"random type","Offline","I dont know what",true,7},
- {"random type","Offline","I dont know what",true,7},
- {"random type","Offline","I dont know what",true,7},
- ]]--
- local testGrid = {
- posX = 2,
- posY = 2,
- width = 50,
- hight = 16,
- selOffX = 0,
- selOffY = 0,
- colWidth = {6,12,10,},
- data = {}
- }
- local function getperpheralData()
- local tree = {}
- local data = {}
- print("Welcome to netSearch")
- for k,v in pairs(rs.getSides()) do
- if peripheral.getType(v) == "modem" and not peripheral.call(v,"isWireless") then
- tree[v] = {["type"] = "side",["status"] = "closed",["sub"] = {},}
- end
- end
- print("Found "..#tree.." wired access points.")
- for k,v in pairs(tree) do
- print(type(k),k," ",type(v))
- local devices = peripheral.call(k,"getNamesRemote")
- for a,b in pairs(devices) do
- print(type(a),tostring(a)," ",type(b),tostring(b))
- tree[k].sub[b] = peripheral.call(k,"getTypeRemote",b)
- end
- end
- term.clear()
- term.setCursorPos(1,1)
- table.insert(data,{"Side","Name","Type"})
- for k,v in pairs(tree) do
- print("--- Side "..k.."---")
- for j,l in pairs(v.sub) do
- table.insert(data,{k,j,l})
- end
- end
- return data
- end
- local function drawGrid(grid)
- local sBlank = ""
- for k,v in pairs(grid.colWidth) do
- sBlank = sBlank..string.rep(" ",v-1).."|"
- end
- for i = grid.posY,grid.hight+grid.posY do
- term.setCursorPos(grid.posX,i)
- local sel = i - grid.posY + 1 + grid.selOffY
- if grid.data[sel] then
- if sel == 1 then
- term.setBackgroundColor(colors.gray)
- else
- term.setBackgroundColor(colors.black)
- end
- for k,v in pairs(grid.data[sel]) do
- term.write(string.sub(tostring(v)..string.rep(" ",grid.colWidth[k] - 1),1,grid.colWidth[k] - 1).."|")
- end
- else
- term.write(sBlank)
- end
- end
- end
- local function manipulateGrid(grid)
- local lastEvent = nil
- local lastBlock = nil
- while true do
- term.clear()
- drawGrid(grid)
- local event = {os.pullEvent()}
- if event[1] == "mouse_click" then
- if event[2] == 1 then -- left button
- if event[4] == grid.posY - grid.selOffY then -- X line
- local total = grid.posX - 1
- for i = 1,#grid.colWidth do
- total = total + grid.colWidth[i]
- if event[3] == total then
- lastBlock = i
- end
- end
- end
- end
- elseif event[1] == "mouse_drag" then
- if event[2] == 1 then -- left button
- if event[4] == grid.posY - grid.selOffY and lastBlock then -- X line
- local nTest = event[3] - lastEvent[3]
- if nTest == 1 or nTest == -1 then
- grid.colWidth[lastBlock] = grid.colWidth[lastBlock] + nTest
- else
- lastBlock = nil
- end
- if lastBlock and grid.colWidth[lastBlock] < 1 then
- grid.colWidth[lastBlock] = 1
- lastBlock = nil
- end
- else
- lastBlock = nil
- end
- end
- elseif event[1] == "mouse_scroll" then
- grid.selOffY = grid.selOffY + event[2]
- elseif event[1] == "key" then
- if event[2] == 14 then
- return
- elseif event[2] == 200 then -- up
- grid.posY = grid.posY - 1
- elseif event[2] == 208 then -- down
- grid.posY = grid.posY + 1
- elseif event[2] == 203 then -- left
- grid.posX = grid.posX - 1
- elseif event[2] == 205 then -- right
- grid.posX = grid.posX + 1
- end
- elseif event[1] == "peripheral" or event[1] == "peripheral_detach" then
- grid.data = getperpheralData()
- end
- lastEvent = event
- end
- end
- testGrid.data = getperpheralData()
- manipulateGrid(testGrid)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement