Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Basic Functions --
- local user = "guest"
- local select = 1
- local rsel = 1
- local fitem = 1
- local mSel = 1
- local l = 1
- local menustate = "admin"
- w,h = term.getSize()
- function isInteger(nIn)
- if math.floor(nIn) == nIn then return true
- else return false end
- end
- 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
- function returnFileAsTable(aFile) --This function and the two bellow it are credit of Challenge.Accepted on the ComputerCraft Forums
- f= fs.open(aFile,"r")
- aTable = {}
- aLine = f.readLine()
- while aLine ~= nil do
- table.insert(aTable, aLine)
- aLine = f.readLine()
- end
- return aTable
- end
- function seperateString(aString, sep)
- p = string.find(aString, sep)
- return string.sub(aString, 1, p-1), string.sub(aString, p+1)
- end
- function iterateTable(aTable)
- local keyTable = {}
- local definitionTable = {}
- for i=1, #aTable do
- key, def = seperateString(aTable[i], ":")
- table.insert(keyTable, key)
- table.insert(definitionTable, def)
- end
- return keyTable, definitionTable
- end
- -- Menus --
- function drawHeader()
- term.setTextColour(colours.white)
- printCentred("KYLEOS - TEST 1.0", 1)
- printLeft(string.rep("-",w),2)
- printLeft(string.rep("-",w),h-1)
- printLeft(menustate.." : "..user,h)
- printRight("made by kylergs",h)
- end
- -- Menu state --
- local path = "GUI/GUImopt"
- fs.makeDir(path)
- local mopt = {}
- local tAllValues = {}
- local i3
- local menus = fs.list(path)
- if #menus ~= 0 then
- for i = 1,#menus do
- mopt[menus[i]] = {}
- tAllValues = returnFileAsTable(path.."/"..menus[i])
- mopt[menus[i]].options = {}
- i3 = 1
- for i2 = 1,#tAllValues,5 do
- table.insert(mopt[menus[i]].options, {})
- mopt[menus[i]].options[i3].display = tAllValues[i2]
- mopt[menus[i]].options[i3].link = tAllValues[i2+1]
- mopt[menus[i]].options[i3].ftype = tAllValues[i2+2]
- mopt[menus[i]].options[i3].colour = colours[tAllValues[i2+3]]
- i3 = i3+1
- end
- end
- else
- term.clear()
- drawHeader()
- printCentred("No Menu's Configued", 8)
- printCentred("Closing Interface", 9)
- printCentred("Press Any Key to Continue", 10)
- os.pullEvent("key")
- sleep(0.1)
- term.clear()
- term.setCursorPos(1,1)
- error()
- end
- if not mopt[menustate] then
- menustate = menus[1]
- end
- local hist = {}
- -- Scrolling List --
- fitem = 1
- rsel = 1
- function drawList(items)
- a = h-5 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(items[select].colour)
- local selpos = rsel*2 + 2
- printCentred("[ "..items[select].display.." ]", selpos)
- end
- function checkSel(items)
- a = h -5 a= a/2
- if rsel > a -1 and select<#items then
- rsel = rsel -1
- fitem = fitem+1
- elseif rsel == 1 and select > 1 then
- rsel = rsel +1
- fitem = fitem -1
- end
- end
- -- User Area for added functions (Suggested) --
- -- Special Programs --
- function logon()
- 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"}
- }
- os.loadAPI("GUI/logonapi")
- user = logonapi.logon(users,user)
- os.unloadAPI("GUI/logonapi")
- end
- tsPrograms = {
- ["logon"] = logon
- }
- -- Type Specific Functions --
- function changeMenu()
- menustate = mopt[menustate].options[select].link
- select = 1; rsel = 1; fitem = 1
- table.insert(hist, menustate)
- end
- function plainText()
- end
- function special()
- local link = mopt[menustate].options[select].link
- if link == "quit" then term.clear(); term.setCursorPos(1,1); error();
- elseif link == "back" and #hist > 1 then table.remove(hist); menustate = hist[#hist];
- select = 1; rsel = 1; fitem = 1;
- end
- end
- function runExternal()
- shell.run(mopt[menustate].options[select].link)
- end
- function specialFunction()
- x = mopt[menustate].options[select].link
- tsPrograms[x]()
- end
- local typelist = {
- ["menu"] = {func = changeMenu};
- ["text"] = {func = plainText};
- ["special"] = {func = special};
- ["program"] = {func = runExternal};
- ["sfunc"] = {func = specialFunction};
- }
- -- Run --
- function runMain()
- while true do
- term.clear()
- drawHeader()
- mms = mopt[menustate]
- drawList(mms.options)
- do id, key, param2, param3 = os.pullEvent(); repeat until id == "key" or id =="mouse_click" or id == "mouse_scroll" end
- if id == "key" 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
- typelist[mms.options[select].ftype].func()
- end
- elseif id =="mouse_click" then
- mSel = param3/2 -1
- if isInteger(mSel) and key == 1 and mSel <= l then select = mSel+fitem -1; rsel=mSel;
- typelist[mms.options[select].ftype].func()
- end
- elseif id =="mouse_scroll" then
- if key == -1 and fitem > 1 then fitem = fitem-1 ; select=select-1 ; checkSel(mms.options)
- elseif key == -1 and fitem == 1 and select > 1 then select = select - 1 ; rsel = rsel -1 ;
- elseif key == 1 and fitem +l -1< #mms.options then select = select + 1 ; fitem = fitem+1 ; checkSel(mms.options) ;
- elseif key == 1 and fitem +l-1 >= #mms.options and select < #mms.options then select = select + 1 ; rsel = rsel +1
- end
- end
- end
- end
- runMain()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement