Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function drawMenu(tMenu, xpos, ypos, curSel)
- if xpos == true then
- centered = true
- else
- centered = false
- end
- if curSel ~= nil or curSel~= "" then
- sel = 1
- else
- sel = curSel
- end
- tPlaces = {}
- while true do
- for i=1, #tMenu do
- iSel = i-1
- local w, h = term.getSize()
- table.remove(tPlaces, i)
- if i == sel then
- if centered == false then
- term.setCursorPos(xpos, ypos+iSel)
- term.clearLine()
- table.insert(tPlaces, i, term.getCursorPos()+2)
- write("[ "..tMenu[i].." ]")
- else
- term.setCursorPos(w/2-#tMenu[i]/2-2, ypos+iSel)
- term.clearLine()
- table.insert(tPlaces, i, term.getCursorPos()+2)
- write("[ "..tMenu[i].." ]")
- end
- else
- if centered == false then
- term.setCursorPos(xpos, ypos+iSel)
- term.clearLine()
- table.insert(tPlaces, i, term.getCursorPos())
- write(tMenu[i])
- else
- term.setCursorPos(w/2-#tMenu[i]/2, ypos+iSel)
- term.clearLine()
- table.insert(tPlaces, i, term.getCursorPos())
- write(tMenu[i])
- end
- end
- end
- local event, key, x, y = os.pullEvent()
- if event == "key" then
- if key == 200 and sel > 1 and sel <= #tMenu then sel = sel-1
- elseif key == 208 and sel >= 1 and sel < #tMenu then sel = sel+1
- elseif key == 208 and sel == #tMenu then sel = 1
- elseif key == 200 and sel == 1 then sel = #tMenu
- end
- for v = 1, #tMenu do
- if key == 28 and sel == v then
- return tMenu[v], sel
- end
- end
- elseif event == "mouse_click" then
- for s = 1, #tMenu do
- iSel = s-1
- if s == sel then
- if x >= tPlaces[s] and x < tPlaces[s]+#tMenu[s] and y == ypos+iSel then
- return tMenu[s], s
- end
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment