Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function monitor()
- for _,b in pairs (rs.getSides()) do
- if peripheral.getType(b) == "monitor" then
- return peripheral.wrap(b)
- end
- end
- end
- local mon = monitor()
- local w, h = mon.getSize()
- local selectedItem = 1
- local run = true
- rs.setOutput("bottom", false)
- function megjegyzes(kiiras)
- hossz = string.len(kiiras)
- mon.clear()
- mon.setCursorPos(w/2-(hossz/2), h/2)
- mon.write(kiiras)
- sleep(3)
- end
- function menu1()
- megjegyzes("menu1")
- end
- function menu2()
- megjegyzes("menu2")
- end
- function exiting()
- megjegyzes("kilepes a programbol")
- mon.clear()
- run = false
- end
- mainmenu = {
- [1] = {text = "choice1", handler = menu1},
- [2] = {text = "choice2", handler = menu2},
- [3] = {text = "exit", handler = exiting}
- }
- function printmenu( menu )
- term.clear()
- mon.clear()
- for i=1,#menu do
- hossz = string.len(menu[i].text)
- if i == selectedItem then
- term.setCursorPos(w/2-(hossz/2)-4, h/2-(#menu/2)-1+i)
- term.write(">> " .. menu[i].text .. " <<")
- mon.setCursorPos(w/2-(hossz/2)-4, h/2-(#menu/2)-1+i)
- mon.write(">> " .. menu[i].text .. " <<")
- else
- term.setCursorPos(w/2-(hossz/2)-4, h/2-(#menu/2)-1+i)
- term.write(" " .. menu[i].text)
- mon.setCursorPos(w/2-(hossz/2)-4, h/2-(#menu/2)-1+i)
- mon.write(" " .. menu[i].text)
- end
- end
- end
- function onKeyPressed( key, menu )
- if key == 28 then
- menu[selectedItem].handler()
- elseif key == 200 then
- if selectedItem > 1 then
- selectedItem = selectedItem - 1
- end
- elseif key == 208 then
- if selectedItem < #menu then
- selectedItem = selectedItem + 1
- end
- else
- megjegyzes("nem definialt gomb")
- end
- end
- while run do
- local timer = os.startTimer(2)
- printmenu(mainmenu)
- local event, par1 = os.pullEventRaw()
- if event == "key" then
- onKeyPressed(par1, mainmenu)
- elseif event == "redstone" then
- if rs.testBundledInput ("front", colors.white) then
- onKeyPressed(200, mainmenu)
- elseif rs.testBundledInput ("front", colors.orange) then
- onKeyPressed(28, mainmenu)
- elseif rs.testBundledInput ("front", colors.magenta) then
- onKeyPressed(208, mainmenu)
- end
- elseif event == "terminate" then
- megjegyzes("Ne kivancsiskodj, nem szep dolog lopni.")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement