Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- maxx, maxy = term.getSize()
- function setTitle(title,reverse)
- if reverse then
- term.setBackgroundColour(colours.white)
- term.setTextColour(colours.black)
- term.clearLine()
- term.setCursorPos(1,1)
- print(title)
- term.setBackgroundColour(colours.black)
- term.setTextColour(colours.white)
- elseif not reverse then
- term.setBackgroundColour(colours.black)
- term.setTextColour(colours.white)
- term.clearLine()
- term.setCursorPos(1,1)
- print(title)
- term.setBackgroundColour(colours.white)
- term.setTextColour(colours.black)
- end
- end
- function reverseBW(bool)
- if bool then
- term.setTextColour(colours.white)
- term.setBackgroundColour(colours.black)
- elseif bool == false then
- term.setTextColour(colours.black)
- term.setBackgroundColour(colours.white)
- end
- end
- function createMenu(title,mainTab,modifiers) -- Title is the title and contents is a table containing names of options
- function sortTab(largeTab)
- local lts = #largeTab
- local pages = {}
- if lts > maxx-1 then
- table.insert(pages, largeTab)
- return pages, false
- else
- repeat
- local sTab = {}
- local n = 1
- local oldn = 0
- repeat
- table.insert(sTab, largeTab[n])
- n = n + 1
- until n == maxx-2+oldn or largeTab[n] == nil
- table.insert(pages,sTab)
- oldn = oldn + n
- until largeTab[n] == nil
- return pages, true
- end
- end
- function drawMenu()
- term.clear()
- local num = 1
- repeat
- term.setCursorPos(1,1)
- reverseBW(false)
- term.clearLine()
- print(title)
- reverseBW(true)
- term.setCursorPos(1,num+2)
- if num == selected then
- reverseBW(false)
- term.clearLine()
- print(contents[page][num])
- reverseBW(true)
- else
- print(contents[page][num])
- end
- num = num + 1
- until contents[page][num] == nil
- end
- contents = sortTab(mainTab)
- selected = 1
- page = 1
- drawMenu()
- repeat
- event, param1 = os.pullEvent()
- if keys.getName(param1) == "up" then
- selected = selected - 1
- elseif keys.getName(param1) == "down" then
- selected = selected + 1
- elseif keys.getName(param1) == "left" then
- page = page - 1
- elseif keys.getName(param1) == "right" then
- page = page + 1
- end
- if selected > #contents[page] then
- selected = 1
- elseif selected < 1 then
- selected = #contents[page]
- elseif page > #contents then
- page = 1
- elseif selected < 1 then
- page = #contents
- end
- local n2 = 1
- repeat
- if modifiers[n2] == keys.getName(param1) then press = true end
- n2 = n2 + 1
- until modifiers[n2] == nil
- drawMenu()
- until press == true
- return contents[selected], param1
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement