Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local width, height = term.getSize()
- print("width: ", width, "\n", "height: ", height)
- sleep(1)
- local selectedMenu = 1
- local selectedItem = 1
- local running = true
- function clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- function choice1()
- clear()
- print("valasztott menu: 1")
- print("key: ", key)
- print("menu", menu)
- print("selectedItem: ", selectedItem)
- event, key = os.pullEvent("key")
- end
- function choice15()
- selectedItem = 1
- selectedMenu = 2
- end
- function choice22()
- selectedItem = 1
- selectedMenu = 1
- end
- function Exit()
- running = false
- end
- local mainMenu1 = {
- [1] = { text = "menu1", handler = choice1 },
- [2] = { text = "menu2", handler = choice2 },
- [3] = { text = "menu3", handler = choice3 },
- [4] = { text = "menu4", handler = choice4 },
- [5] = { text = "menu5", handler = choice5 },
- [6] = { text = "menu6", handler = choice6 },
- [7] = { text = "menu7", handler = choice7 },
- [8] = { text = "menu8", handler = choice8 },
- [9] = { text = "menu9", handler = choice9 },
- [10] = { text = "menu10", handler = choice10 },
- [11] = { text = "menu11", handler = choice11 },
- [12] = { text = "menu12", handler = choice12 },
- [13] = { text = "menu13", handler = choice13 },
- [14] = { text = "menu14", handler = choice14 },
- [15] = { text = "menu15", handler = choice14 },
- [16] = { text = "menu16", handler = choice14 },
- [17] = { text = "menu17", handler = choice14 },
- [18] = { text = "menu18", handler = choice14 },
- [19] = { text = "tovab2", handler = choice15 },
- [20] = { text = "Exit20", handler = Exit }
- }
- local mainMenu2 = {
- [1] = { text = "menu1", handler = choice21 },
- [2] = { text = "tovabb1", handler = choice22 },
- [3] = { text = "Exit20", handler = Exit }
- }
- function printMenu( menu )
- for i=1,#menu do
- if i < height then
- if i == selectedItem then
- term.setCursorPos(1, (i))
- print(">> "..menu[i].text .. " <<")
- else
- term.setCursorPos(1, (i))
- print(" "..menu[i].text)
- end
- elseif i > height - 1 then
- if i == selectedItem then
- term.setCursorPos(10, (i-18))
- print(">> "..menu[i].text .. " <<")
- else
- term.setCursorPos(10, (i-18))
- print(" "..menu[i].text)
- end
- end
- end
- end
- function onKeyPressed( key, menu )
- term.setCursorPos(35,18)
- print("keypressed: ", key)
- sleep(.01)
- if key == 28 then
- onItemSelected(menu)
- elseif key == 200 then
- if selectedItem > 1 then
- selectedItem = selectedItem - 1
- end
- elseif key == 208 then
- if selectedItem < #menu then
- selectedItem = selectedItem + 1
- end
- elseif key == 203 then
- if selectedItem > 18 then
- selectedItem = selectedItem - 18
- end
- elseif key == 205 then
- vissza = selectedItem
- if selectedItem < #menu then
- selectedItem = selectedItem + 18
- if selectedItem > #menu then
- selectedItem = vissza
- end
- end
- end
- end
- function onItemSelected( menu )
- menu[selectedItem].handler()
- end
- function main()
- while running do
- if selectedMenu == 1 then
- term.clear()
- term.setCursorPos(1,1)
- printMenu(mainMenu1)
- event, key = os.pullEvent("key")
- onKeyPressed(key,mainMenu1)
- elseif selectedMenu == 2 then
- term.clear()
- term.setCursorPos(1,1)
- printMenu(mainMenu2)
- event, key = os.pullEvent("key")
- onKeyPressed(key,mainMenu2)
- end
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement