Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local w,h = term.getSize()
- local select = 1
- --Some draw functions to get us started
- local function printCentered(str, ypos)
- term.setCursorPos(w/2 - #str/2, ypos)
- term.write(str)
- end
- local function printRight(str, ypos)
- term.setCursorPos(w - #str, ypos)
- term.write(str)
- end
- --Add the menus here
- function drawMain()
- printCentered("Picture 1", 8)
- printCentered("Picture 2", 12)
- printCentered("Quit", h-2)
- local ypos = 9
- if select == 2 then ypos = 13
- elseif select == 3 then ypos = h-1 end
- printCentered("---------", ypos)
- end
- function drawPicOne()
- local rookList = {
- "|'-'-'| ",
- " \\ / ",
- " | | ",
- " | | ",
- " | | ",
- " | | ",
- " |___| ",
- " /_____\\ ",
- "(_______)"
- }
- for i=1,#rookList do
- printCentered(rookList[i], 3 + i)
- end
- printCentered("Picture 2", h-4)
- printCentered("Back", h-1)
- local ypos = h-3;
- if select == 2 then ypos = h end
- printCentered("---------", ypos)
- end
- function drawPicTwo()
- local bishopList = {
- " _<> ",
- " /\\\\ \\",
- " \\ \\) /",
- " \\__/ ",
- " (____) ",
- " | | ",
- " | | ",
- " | | ",
- " |__| ",
- " /____\\ ",
- "(______)"
- }
- for i=1,#bishopList do
- printCentered(bishopList[i], 2 + i)
- end
- printCentered("Picture 1", h-4)
- printCentered("Back", h-1)
- local ypos = h-3;
- if select == 2 then ypos = h end
- printCentered("---------", ypos)
- end
- function drawHeader()
- printCentered("PICTURE VIEWER", 1)
- printCentered(string.rep("-", w), 2)
- printRight("by nitrofingers", h)
- end
- --Menu state
- local menustate = "main"
- local mopt = {
- ["main"] = {
- options = {"pic1", "pic2", "quit"},
- draw = drawMain
- },
- ["pic1"] = {
- options = {"pic2", "main"},
- draw = drawPicOne
- },
- ["pic2"] = {
- options = {"pic1", "main"},
- draw = drawPicTwo
- }
- }
- --Run Function
- function runMenu()
- while true do
- term.clear()
- drawHeader()
- mopt[menustate].draw()
- local id, key = os.pullEvent("key")
- --UP = 200, DOWN = 208, ENTER = 28
- if key == 200 and select > 1 then select = select-1
- elseif key == 208 and select < #mopt[menustate].options then select = select+1
- elseif key == 28 then
- if mopt[menustate].options[select] == "quit" then break end
- menustate = mopt[menustate].options[select]
- end
- end
- end
- runMenu()
- term.clear()
- term.setCursorPos(1,1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement