Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rednet.open("right")
- function activateFloor(id)
- rednet.send(id, "on")
- end
- mymenu={{},{},{},{},{},{},{},{},{},{}}
- mymenu[1][1]={'0 Ground',{activateFloor,0}}
- mymenu[2][1]={'-1 Inventory',{activateFloor,0}}
- mymenu[3][1]={'-2 Sorting',{activateFloor,0}}
- mymenu[4][1]={'-3 Forestry',{activateFloor,0}}
- mymenu[5][1]={'-4 Railcraft',{activateFloor,0}}
- mymenu[6][1]={'-5 Empty',{activateFloor,0}}
- mymenu[7][1]={'-6 Empty',{activateFloor,0}}
- mymenu[8][1]={'-7 Fuel Prod.',{activateFloor,0}}
- mymenu[9][1]={'-8 Engines',{activateFloor,0}}
- mymenu[10][1]={'-9 Basement',{activateFloor,0}}
- mymenu[1][2]={'1 Empty',{activateFloor,0}}
- mymenu[2][2]={'2 Empty',{activateFloor,0}}
- mymenu[3][2]={'3 Trees',{activateFloor,0}}
- mymenu[4][2]={'5 Rubber Trees',{activateFloor,0}}
- mymenu[5][2]={'7 Cactus',{activateFloor,0}}
- mymenu[6][2]={'8 Sugarcane',{activateFloor,0}}
- mymenu[7][2]={'9 Empty',{activateFloor,0}}
- mymenu[8][2]={'10 Empty',{activateFloor,0}}
- mymenu[9][2]={'11 Empty',{activateFloor,0}}
- mymenu[10][2]={'12 Garden',{activateFloor,0}}
- mymenu[1][3]={'18 Empty',{activateFloor,0}}
- mymenu[2][3]={'19 Empty',{activateFloor,0}}
- mymenu[3][3]={'30 Roof',{activateFloor,0}}
- --menu.generate(mymenu,15,2,2,30,12)
- input=mymenu
- dist=15
- offsetx=2
- offsety=2
- limx=30
- limy=12
- --[Required functions]
- local function pullfirst(input)
- local first=input[1]
- local temp={}
- for k,v in pairs(input) do
- if k~=1 then
- temp[#temp+1]=v
- end
- end
- return first,temp
- end
- local function cleararea(...)
- local pos={term.getCursorPos()}
- local args={...}
- for y=args[2], args[2]+args[4]-2 do
- term.setCursorPos(args[1],y)
- write(string.rep(' ',args[3]-args[1]+1))
- end
- term.setCursorPos(pos[1],pos[2])
- end
- --[Gathering initial information and declaring variables]
- local scrolledx=0
- local scrolledy=0
- local selectedx=1
- local selectedy=1
- local lastx=0
- dist=dist or 10
- local columnmaxlen={}
- local maxlen=0
- for b,y in pairs(input) do
- for a,x in pairs(y) do
- if columnmaxlen[a] or 0<string.len(x[1]) then
- columnmaxlen[a]=string.len(x[1])
- end
- end
- end
- for a,b in pairs(columnmaxlen) do
- if string.len(b)>maxlen then
- maxlen=string.len(b)
- end
- end
- while true do
- --[Render the menu]
- cleararea(offsetx,offsety,limx,limy)
- lastx=0
- for b,y in pairs(input) do
- for a,x in pairs(y) do
- currentlen=dist*(a-scrolledx-1)+columnmaxlen[a]
- if b>scrolledy and b<=limy-offsety+scrolledy+1 and a>scrolledx and currentlen<limx-offsetx+1 then
- lastx=(lastx<=a and a) or lastx
- if a==selectedx and b==selectedy then
- term.setCursorPos(offsetx+a*dist-scrolledx*dist-dist,offsety+b-1-scrolledy)
- write((delim1 or '>')..x[1]..(delim2 or delim1 or '<'))
- else
- term.setCursorPos(offsetx+1+a*dist-scrolledx*dist-dist,offsety+b-1-scrolledy)
- write(x[1])
- end
- end
- end
- end
- print('')
- --[Detect keypresses for interface and adjust variables accordingly]
- while true do
- local event,key=os.pullEvent('key')
- if key==203 and selectedx>1 then
- selectedx=selectedx-1
- if selectedx<=scrolledx then
- scrolledx=scrolledx-1
- end
- break
- elseif key==205 and selectedx<#input[selectedy] then
- selectedx=selectedx+1
- if selectedx>lastx then
- scrolledx=scrolledx+1
- end
- break
- elseif key==200 and selectedy>1 then
- selectedy=selectedy-1
- if selectedy<=scrolledy then
- scrolledy=scrolledy-1
- end
- break
- elseif key==208 and selectedy<#input then
- selectedy=selectedy+1
- if selectedy>limy-offsety+scrolledy+1 then
- scrolledy=scrolledy+1
- end
- break
- elseif key==28 then
- local cmd={pullfirst(input[selectedy][selectedx][2])}
- return cmd[1](unpack(cmd[2]))
- end
- local event, rn_id, rn_msg = os.pullEvent('rednet_message')
- if event then
- print("message received")
- print(rn_msg)
- if rn_msg == "on" then
- rs.setOutput("left",true)
- elseif rn_msg =="off" then
- rs.setOutput("left",false)
- end
- end
- end
- if selectedx>#input[selectedy] then
- selectedx=#input[selectedy]
- end
- end
Add Comment
Please, Sign In to add comment