Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function c() return term.clear() end
- function sc(...) return term.setBackgroundColor(...) end
- function stc(...) return term.setTextColor(...) end
- function sp(...) return term.setCursorPos(...) end
- -- Vars
- local w,h = term.getSize()
- local state = "idle"
- local barcolor = colors.blue
- local options = {"Start", "Reboot", "Shutdown", "Logout", "---", "Run", "Paint", "Edit Code"}
- local running = true
- local extra_menu_width = 2
- local background = "Images/background"
- -- Password lock
- if not fs.exists("/".. shell.dir().. "/Pass/runp") then
- if not http then
- error("HTTP Must be enabled.")
- end
- shell.run("pastebin get ApZBXSmg /".. shell.dir() .."/Pass/runp")
- end
- if not fs.exists("passes") then
- file = fs.open("passes", "w")
- file.close()
- end
- shell.run("/".. shell.dir().. "/Pass/runp")
- -- Graphical Functions
- function drawBar(color)
- sp(1,h + 1)
- sc(color)
- print(string.rep(" ", w))
- sp(1,h)
- stc(colors.lightBlue)
- print(" Start ")
- end
- function findLongest(array)
- longest = 0
- for i = 1, #options do
- if #options[i] > longest then
- longest = #options[i]
- end
- end
- return longest
- end
- function drawStage()
- if state == "menu" or state == "games" then
- longest = findLongest(options) + extra_menu_width
- sc(colors.lightBlue)
- stc(colors.blue)
- sp(1, h - #options)
- for i = 1, #options do
- if i == 1 then
- sc(colors.blue)
- stc(colors.lightBlue)
- end
- print(string.rep(" ", longest))
- sc(colors.lightBlue)
- stc(colors.blue)
- end
- sp(1, h - #options)
- for i = 1, #options do
- if i == 1 then
- sc(colors.blue)
- stc(colors.lightBlue)
- end
- if i ~= 1 then
- print(" ".. options[i])
- else
- print(string.rep(" ", (longest / 2) - (#options[i] / 2)).. options[i])
- end
- sc(colors.lightBlue)
- stc(colors.blue)
- end
- end
- end
- function calculateOption(y) -- Here trying to calculate it
- start = h - #options
- opt = y - start
- return opt
- end
- function popup(text)
- -- FIRST LINE
- sp((w / 2) - (#text / 2) - 1, h / 2 - 1)
- sc(colors.blue)
- print(string.rep(" ", #text + 2))
- -- MIDDLE LINE
- sc(colors.blue)
- sp((w / 2) - (#text / 2) - 1, h / 2)
- write(" ")
- sc(colors.lightBlue)
- write(text)
- sc(colors.blue)
- print(" ")
- -- LAST LINE
- sc(colors.blue)
- sp((w / 2) - (#text / 2) - 1, h / 2 + 1)
- print(string.rep(" ", #text + 2))
- -- Wait for click
- event = os.pullEvent("mouse_click")
- end
- function inputPopup(text)
- sp((w / 2) - (#text / 2) - 1, h / 2 - 1)
- sc(colors.blue)
- print(string.rep(" ", #text + 2))
- sc(colors.blue)
- sp((w / 2) - (#text / 2) - 1, h / 2)
- write(" ")
- sc(colors.lightBlue)
- write(text)
- sc(colors.blue)
- print(" ")
- sc(colors.blue)
- sp((w / 2) - (#text / 2) - 1, h / 2 + 1)
- write(" ")
- sc(colors.lightBlue)
- write(string.rep(" ", #text))
- sc(colors.blue)
- print(" ")
- sp((w / 2) - (#text / 2) - 1, h / 2 + 2)
- sc(colors.blue)
- print(string.rep(" ", #text + 2))
- sp((w / 2) - (#text / 2) + 1, h / 2 + 1)
- sc(colors.lightBlue)
- stc(colors.blue)
- input = read()
- return input
- end
- function callMenuFunction(option)
- if option == 1 then -- Reboot
- os.reboot()
- end
- if option == 2 then -- Shutdown
- os.shutdown()
- end
- if option == 3 then -- Logout
- if not fs.exists("/".. shell.dir() .."/passes") then
- popup("Something went wrong, rebooting.")
- -- This would occur if the user deletes the
- -- Password program while in the OS
- os.reboot()
- end
- file = fs.open("/".. shell.dir() .."/passes", "r")
- redline = file.readLine()
- file.close()
- if redline == "" or redline == nil then
- popup("You have no password, Also no logout.")
- return
- end
- shell.run("/".. shell.dir().. "/Pass/runp")
- end
- if option == 5 then -- Open
- sc(colors.white)
- stc(colors.black)
- c()
- comm = inputPopup("Command: ")
- sp(1,1)
- sc(colors.black)
- stc(colors.white)
- c()
- shell.run(comm)
- stc(colors.red)
- print("Press any key..")
- event = os.pullEvent("key")
- end
- if option == 6 then
- sc(colors.white)
- stc(colors.black)
- c()
- comm = inputPopup("File Name: ")
- shell.run("paint ".. comm)
- end
- if option == 7 then
- shell.run("edit run")
- shell.run("run")
- error("Exited after editing")
- end
- end
- -- Main Loop
- h = h - 1
- while running do
- stc(colors.orange)
- sc(colors.white)
- c()
- drawBar(barcolor)
- drawStage()
- local event, button, x, y = os.pullEvent("mouse_click")
- if state == "idle" then
- if x < (#" Start ") and y == h then
- state = "menu"
- end
- end
- if state == "menu" then
- if x < ((findLongest(options) + 1) + extra_menu_width) and y > ((h - 1) - #options) then
- callMenuFunction(calculateOption(y))
- else
- state = "idle"
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement