Guest User

Untitled

a guest
Jan 20th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.99 KB | None | 0 0
  1. rednet.open("right")
  2.  
  3.  
  4. function activateFloor(id)
  5. rednet.send(id, "on")
  6. end
  7.  
  8.  
  9. mymenu={{},{},{},{},{},{},{},{},{},{}}
  10. mymenu[1][1]={'0 Ground',{activateFloor,0}}
  11. mymenu[2][1]={'-1 Inventory',{activateFloor,0}}
  12. mymenu[3][1]={'-2 Sorting',{activateFloor,0}}
  13. mymenu[4][1]={'-3 Forestry',{activateFloor,0}}
  14. mymenu[5][1]={'-4 Railcraft',{activateFloor,0}}
  15. mymenu[6][1]={'-5 Empty',{activateFloor,0}}
  16. mymenu[7][1]={'-6 Empty',{activateFloor,0}}
  17. mymenu[8][1]={'-7 Fuel Prod.',{activateFloor,0}}
  18. mymenu[9][1]={'-8 Engines',{activateFloor,0}}
  19. mymenu[10][1]={'-9 Basement',{activateFloor,0}}
  20.  
  21. mymenu[1][2]={'1 Empty',{activateFloor,0}}
  22. mymenu[2][2]={'2 Empty',{activateFloor,0}}
  23. mymenu[3][2]={'3 Trees',{activateFloor,0}}
  24. mymenu[4][2]={'5 Rubber Trees',{activateFloor,0}}
  25. mymenu[5][2]={'7 Cactus',{activateFloor,0}}
  26. mymenu[6][2]={'8 Sugarcane',{activateFloor,0}}
  27. mymenu[7][2]={'9 Empty',{activateFloor,0}}
  28. mymenu[8][2]={'10 Empty',{activateFloor,0}}
  29. mymenu[9][2]={'11 Empty',{activateFloor,0}}
  30. mymenu[10][2]={'12 Garden',{activateFloor,0}}
  31.  
  32.  
  33. mymenu[1][3]={'18 Empty',{activateFloor,0}}
  34. mymenu[2][3]={'19 Empty',{activateFloor,0}}
  35. mymenu[3][3]={'30 Roof',{activateFloor,0}}
  36. --menu.generate(mymenu,15,2,2,30,12)
  37.  
  38. input=mymenu
  39. dist=15
  40. offsetx=2
  41. offsety=2
  42. limx=30
  43. limy=12
  44. --[Required functions]
  45. local function pullfirst(input)
  46. local first=input[1]
  47. local temp={}
  48. for k,v in pairs(input) do
  49. if k~=1 then
  50. temp[#temp+1]=v
  51. end
  52. end
  53. return first,temp
  54. end
  55.  
  56. local function cleararea(...)
  57. local pos={term.getCursorPos()}
  58. local args={...}
  59. for y=args[2], args[2]+args[4]-2 do
  60. term.setCursorPos(args[1],y)
  61. write(string.rep(' ',args[3]-args[1]+1))
  62. end
  63. term.setCursorPos(pos[1],pos[2])
  64. end
  65.  
  66. --[Gathering initial information and declaring variables]
  67. local scrolledx=0
  68. local scrolledy=0
  69. local selectedx=1
  70. local selectedy=1
  71. local lastx=0
  72. dist=dist or 10
  73. local columnmaxlen={}
  74. local maxlen=0
  75. for b,y in pairs(input) do
  76. for a,x in pairs(y) do
  77. if columnmaxlen[a] or 0<string.len(x[1]) then
  78. columnmaxlen[a]=string.len(x[1])
  79. end
  80. end
  81. end
  82. for a,b in pairs(columnmaxlen) do
  83. if string.len(b)>maxlen then
  84. maxlen=string.len(b)
  85. end
  86. end
  87.  
  88. while true do
  89. --[Render the menu]
  90. cleararea(offsetx,offsety,limx,limy)
  91. lastx=0
  92. for b,y in pairs(input) do
  93. for a,x in pairs(y) do
  94. currentlen=dist*(a-scrolledx-1)+columnmaxlen[a]
  95.  
  96. if b>scrolledy and b<=limy-offsety+scrolledy+1 and a>scrolledx and currentlen<limx-offsetx+1 then
  97. lastx=(lastx<=a and a) or lastx
  98. if a==selectedx and b==selectedy then
  99. term.setCursorPos(offsetx+a*dist-scrolledx*dist-dist,offsety+b-1-scrolledy)
  100. write((delim1 or '>')..x[1]..(delim2 or delim1 or '<'))
  101. else
  102. term.setCursorPos(offsetx+1+a*dist-scrolledx*dist-dist,offsety+b-1-scrolledy)
  103. write(x[1])
  104. end
  105. end
  106. end
  107. end
  108. print('')
  109.  
  110. --[Detect keypresses for interface and adjust variables accordingly]
  111. while true do
  112. local event,key=os.pullEvent('key')
  113. if key==203 and selectedx>1 then
  114. selectedx=selectedx-1
  115. if selectedx<=scrolledx then
  116. scrolledx=scrolledx-1
  117. end
  118. break
  119. elseif key==205 and selectedx<#input[selectedy] then
  120. selectedx=selectedx+1
  121. if selectedx>lastx then
  122. scrolledx=scrolledx+1
  123. end
  124. break
  125. elseif key==200 and selectedy>1 then
  126. selectedy=selectedy-1
  127. if selectedy<=scrolledy then
  128. scrolledy=scrolledy-1
  129. end
  130. break
  131. elseif key==208 and selectedy<#input then
  132. selectedy=selectedy+1
  133. if selectedy>limy-offsety+scrolledy+1 then
  134. scrolledy=scrolledy+1
  135. end
  136. break
  137. elseif key==28 then
  138. local cmd={pullfirst(input[selectedy][selectedx][2])}
  139. return cmd[1](unpack(cmd[2]))
  140. end
  141.  
  142. local event, rn_id, rn_msg = os.pullEvent('rednet_message')
  143. if message == "on" then
  144. rs.setOutput("left",true)
  145. elseif message =="off" then
  146. rs.setOutput("left",false)
  147. end
  148.  
  149.  
  150. end
  151. if selectedx>#input[selectedy] then
  152. selectedx=#input[selectedy]
  153. end
  154. end
  155. end
Add Comment
Please, Sign In to add comment