Advertisement
Guest User

Untitled

a guest
Mar 10th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.22 KB | None | 0 0
  1. --Basic Functions
  2.  
  3. local user = "guest"
  4. local select = 1
  5. local menustate = "admin"
  6. w,h = term.getSize()
  7.  
  8. function printCentred(str , h)
  9.   term.setCursorPos(w/2 - #str/2, h)
  10.   term.write(str)
  11. end
  12. function printRight(str , h)
  13.   term.setCursorPos(w - #str, h)
  14.   term.write(str)
  15. end
  16. function printLeft(str , h)
  17.   term.setCursorPos(1, h)
  18.   term.write(str)
  19. end
  20.  
  21.  
  22. --Menu state--
  23. local mopt = {
  24.   ["admin"] = {
  25.   options = {
  26.   {display= "Pink",
  27.    link = "admin",
  28.    ftype = "menu",
  29.    colour = colours.pink} ,
  30.   {display= "Apple",
  31.    link = "test",
  32.    ftype = "menu",
  33.    colour = colours.green} ,
  34.   {display = "Cake",
  35.    link = "quit",
  36.    ftype = "special",
  37.    colour = colours.red}
  38.         }
  39.     }, 
  40.   ["test"] = {
  41.   options = {
  42.   {display="Yellow",
  43.    link = "",
  44.    ftype = "text",
  45.    colour = colours.yellow} ,
  46.   {display="Orange",
  47.    link = "admin",
  48.    ftype = "menu",
  49.    colour = colours.orange} ,
  50.   {display="Red",
  51.    link = "",
  52.    ftype = "text",
  53.    colour = colours.red} ,
  54.   {display="Magenta",
  55.    link = "",
  56.    ftype = "text",
  57.    colour = colours.magenta} ,
  58.   {display = "Quit",
  59.    link = "quit",
  60.    ftype = "special",
  61.    colour = colours.red}
  62.         }
  63.     }
  64.    
  65. }
  66.  
  67. --Scrolling List--
  68.  
  69. fitem = 1
  70. rsel = 1
  71. selpos = 5
  72.  
  73. function drawList(items)
  74.   a = h-6  a = a/2
  75.   if #items > a then l = a
  76.   else l = #items end
  77.   j = 4
  78.   for i = fitem, l+fitem-1 do
  79.    term.setTextColour(items[i].colour)
  80.    printCentred(items[i].display, j)
  81.    j = j +2
  82.   end
  83.  
  84.   term.setTextColour(colours.white)
  85.   local selpos = rsel*2 + 3
  86.   printCentred("---------", selpos)
  87.    
  88. end
  89. function checkSel(items)
  90.  
  91.  a = h -6  a= a/2
  92.  
  93.  if rsel > a -1 and select<#items then
  94.   rsel = rsel -1
  95.   fitem = fitem+1
  96.   print("SD")
  97.  elseif rsel == 1 and select > 1 then
  98.   rsel = rsel +1
  99.   fitem = fitem -1
  100.   print("SU")
  101.  end
  102. end
  103.  
  104. function changeMenu()
  105. menustate = mopt[menustate].options[select].link
  106. end
  107. function plainText()
  108. end
  109.  
  110. local typelist = {
  111. ["menu"] = changeMenu(),
  112. ["text"] = plainText(),
  113. ["special"] = ""
  114. }
  115.  
  116. --Menus
  117.  
  118. function drawHeader()
  119.   term.setTextColour(colours.white)
  120.   printCentred("KYLEOS - TEST 0.1", 1)
  121.   printLeft(string.rep("-",w),2)
  122.   printLeft(string.rep("-",w),h-1)
  123.   printLeft(menustate,h)
  124.   printRight("made by kylergs",h)
  125. end
  126.  
  127.  
  128. --Users--
  129.  
  130. local users = {
  131.   ["guest"]={default = "main", pass=""},
  132.   ["member"]={default = "member", pass="password"},
  133.   ["admin"]={default = "admin", pass="admin"},
  134.   ["op"]={default = "main", pass=""},
  135.   ["kylergs"] = {default = "main", pass = "kyle"}
  136. }
  137.  
  138. function drawLogon()
  139.   printCentred("Please LogOn to your user", 5)
  140.   printCentred("Username: ",8)
  141.   printCentred("Password: ",10)
  142. end
  143.  
  144. function drawLog(acc)
  145.   term.clear()
  146.   if acc then
  147.     drawHeader()
  148.     printCentred("Logon Accepted", 6)
  149.     printCentred("Logging on to - "..user, 8)
  150.     printCentred(" Press any Key to continue...  ", 11)
  151.     menustate = users[user].default
  152.   else
  153.     drawHeader()
  154.     printCentred("Logon Denied", 6)
  155.     printCentred("Reseting to guest",8)
  156.     printCentred("Press any Key to continue", 11)
  157.     user = "guest"
  158.     menustate = "main"
  159.   end
  160. end
  161.  
  162. function logon()
  163.   skip = true
  164.   select = 1
  165.   local usr = ""
  166.   local pass = ""
  167.   term.clear()
  168.   drawHeader()
  169.   drawLogon()
  170.   term.setCursorPos(w/2+5,8)
  171.   usr = read()  
  172.   term.setCursorPos(w/2+5,10)
  173.   inpass = read()
  174.   flag = flase
  175.   if users[usr] then
  176.     if users[usr].pass == inpass then
  177.       user = usr
  178.       drawLog(true)
  179.     else
  180.       drawLog(false)
  181.     end
  182.   else
  183.     drawLog(false)
  184.   end
  185. end
  186.  
  187. --Run
  188.  
  189. function runMain()
  190.  while true do
  191.   term.clear()
  192.   drawHeader()
  193.   sleep(0.1)
  194.   mms = mopt[menustate]
  195.  tftype = mms.options[select].ftype
  196.   if not skip then drawList(mms.options) end
  197.   print(tftype)
  198.  
  199.   local id, key = os.pullEvent("key")
  200.   if not skip then
  201.  
  202.    if key == 200 and select > 1 then select = select-1 rsel=rsel-1 checkSel(mms.options)
  203.    elseif key == 208 and select < #mms.options then select = select + 1 rsel = rsel +1 checkSel(mms.options)  
  204.    elseif key == 28 then
  205.     if mms.options[select].link == "quit" then break end    
  206.     typelist[tftype]()
  207.    end
  208.   else skip = false
  209.  end
  210.  end
  211. end
  212.  
  213. runMain()
  214.  
  215. term.clear()
  216. term.setCursorPos(1,1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement