Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Basic Functions
- local user = "guest"
- local select = 1
- local menustate = "admin"
- w,h = term.getSize()
- function printCentred(str , h)
- term.setCursorPos(w/2 - #str/2, h)
- term.write(str)
- end
- function printRight(str , h)
- term.setCursorPos(w - #str, h)
- term.write(str)
- end
- function printLeft(str , h)
- term.setCursorPos(1, h)
- term.write(str)
- end
- --Menu state--
- local mopt = {
- ["admin"] = {
- options = {
- {display= "Pink",
- link = "admin",
- ftype = "menu",
- colour = colours.pink} ,
- {display= "Apple",
- link = "test",
- ftype = "menu",
- colour = colours.green} ,
- {display = "Cake",
- link = "quit",
- ftype = "special",
- colour = colours.red}
- }
- },
- ["test"] = {
- options = {
- {display="Yellow",
- link = "",
- ftype = "text",
- colour = colours.yellow} ,
- {display="Orange",
- link = "admin",
- ftype = "menu",
- colour = colours.orange} ,
- {display="Red",
- link = "",
- ftype = "text",
- colour = colours.red} ,
- {display="Magenta",
- link = "",
- ftype = "text",
- colour = colours.magenta} ,
- {display = "Quit",
- link = "quit",
- ftype = "special",
- colour = colours.red}
- }
- }
- }
- --Scrolling List--
- fitem = 1
- rsel = 1
- selpos = 5
- function drawList(items)
- a = h-6 a = a/2
- if #items > a then l = a
- else l = #items end
- j = 4
- for i = fitem, l+fitem-1 do
- term.setTextColour(items[i].colour)
- printCentred(items[i].display, j)
- j = j +2
- end
- term.setTextColour(colours.white)
- local selpos = rsel*2 + 3
- printCentred("---------", selpos)
- end
- function checkSel(items)
- a = h -6 a= a/2
- if rsel > a -1 and select<#items then
- rsel = rsel -1
- fitem = fitem+1
- print("SD")
- elseif rsel == 1 and select > 1 then
- rsel = rsel +1
- fitem = fitem -1
- print("SU")
- end
- end
- function changeMenu()
- menustate = mopt[menustate].options[select].link
- end
- function plainText()
- end
- local typelist = {
- ["menu"] = changeMenu(),
- ["text"] = plainText(),
- ["special"] = ""
- }
- --Menus
- function drawHeader()
- term.setTextColour(colours.white)
- printCentred("KYLEOS - TEST 0.1", 1)
- printLeft(string.rep("-",w),2)
- printLeft(string.rep("-",w),h-1)
- printLeft(menustate,h)
- printRight("made by kylergs",h)
- end
- --Users--
- local users = {
- ["guest"]={default = "main", pass=""},
- ["member"]={default = "member", pass="password"},
- ["admin"]={default = "admin", pass="admin"},
- ["op"]={default = "main", pass=""},
- ["kylergs"] = {default = "main", pass = "kyle"}
- }
- function drawLogon()
- printCentred("Please LogOn to your user", 5)
- printCentred("Username: ",8)
- printCentred("Password: ",10)
- end
- function drawLog(acc)
- term.clear()
- if acc then
- drawHeader()
- printCentred("Logon Accepted", 6)
- printCentred("Logging on to - "..user, 8)
- printCentred(" Press any Key to continue... ", 11)
- menustate = users[user].default
- else
- drawHeader()
- printCentred("Logon Denied", 6)
- printCentred("Reseting to guest",8)
- printCentred("Press any Key to continue", 11)
- user = "guest"
- menustate = "main"
- end
- end
- function logon()
- skip = true
- select = 1
- local usr = ""
- local pass = ""
- term.clear()
- drawHeader()
- drawLogon()
- term.setCursorPos(w/2+5,8)
- usr = read()
- term.setCursorPos(w/2+5,10)
- inpass = read()
- flag = flase
- if users[usr] then
- if users[usr].pass == inpass then
- user = usr
- drawLog(true)
- else
- drawLog(false)
- end
- else
- drawLog(false)
- end
- end
- --Run
- function runMain()
- while true do
- term.clear()
- drawHeader()
- sleep(0.1)
- mms = mopt[menustate]
- tftype = mms.options[select].ftype
- if not skip then drawList(mms.options) end
- print(tftype)
- local id, key = os.pullEvent("key")
- if not skip then
- if key == 200 and select > 1 then select = select-1 rsel=rsel-1 checkSel(mms.options)
- elseif key == 208 and select < #mms.options then select = select + 1 rsel = rsel +1 checkSel(mms.options)
- elseif key == 28 then
- if mms.options[select].link == "quit" then break end
- typelist[tftype]()
- end
- else skip = false
- end
- end
- end
- runMain()
- term.clear()
- term.setCursorPos(1,1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement