Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Objects (members)
- local menu = {
- currentMenu = 1;
- items = {};
- [1] = {
- menuText = "Is this computer a client or server?";
- pos = 1;
- backColor = colors.black;
- textColor = colors.red;
- items = {};
- };
- [2] = {
- menuText = "Which side is the modem attached to?";
- pos = 1;
- backColor = colors.black;
- textColor = colors.red;
- items = {};
- };
- [3] = {
- menuText = "Main menu";
- pos = 1;
- backColor = colors.black;
- textColor = colors.red;
- items = {};
- };
- [4] = {
- menuText = "Signed in as Jyzarc";
- pos = 1;
- backColor = colors.black;
- textColor = colors.red;
- items = {};
- };
- }
- local program = {
- eventData = {};
- name = shell.getRunningProgram();
- }
- local account = {
- loggedIn = false;
- }
- local writer = {
- running = true;
- text = "";
- param = {};
- }
- function program.exit()
- error()
- end
- function program.uninstall()
- --Clear screen
- term.clear()
- --Set cursor pos to top left
- term.setCursorPos(1,1)
- print("Are you sure you would like to uninstall?")
- program.input = read()
- --If player answer is yes, then uninstall program
- if program.input == "yes"
- or program.input == "YES"
- or program.input == "y"
- or program.input == "Y"
- or program.input == "true"
- or program.input == "TRUE" then
- --Deletes current program file
- fs.delete(program.name)
- print("Program uninstalled")
- --Waits for key press
- os.pullEvent("key")
- --Exits program
- program.exit()
- end
- end
- --Reinstalls/updates the currently running program
- function program.reinstall()
- if http then
- --Deletes current program file
- fs.delete(program.name)
- --Runs built it pastebin program (too lazy to write my own function)
- shell.run("pastebin get "..program.pastebinCode.." "..program.name)
- print("Program reinstalled, press any key to continue")
- --Waits for key press
- os.pullEvent("key")
- --Exits program gracefully
- program.exit()
- else
- print("Http not enabled")
- --Waits for key press
- os.pullEvent("key")
- end
- end
- function program.edit()
- --Opens file to be edited
- shell.run("edit "..program.name)
- --Exits program
- program.exit()
- end
- function account.login()
- term.clear()
- term.setCursorPos(1,1)
- term.write("Username: ")
- program.input = io.read()
- term.write("Password: ")
- program.input = io.read()
- end
- function program.startup()
- end
- function writer.updateScreen()
- term.setCursorBlink(true)
- term.clear()
- term.setCursorPos(1,1)
- write(writer.text)
- end
- function writer.run()
- while writer.running do
- writer.updateScreen()
- program.eventData[1],program.eventData[2],program.eventData[3],program.eventData[4] = os.pullEvent()
- if program.eventData[1] == "char" then
- writer.text = writer.text..program.eventData[2]
- elseif program.eventData[1] == "key" then
- if program.eventData[2] == 28 then
- writer.text = writer.text.."\n"
- elseif program.eventData[2] == 14 then
- writer.text = string.sub(writer.text,1,string.len(writer.text)-1)
- end
- end
- end
- end
- menu[1].items = {
- [1] = { text = "client", color = colors.white, handler = read };
- [2] = { text = "server", color = colors.white, handler = read };
- }
- menu[2].items = {
- [1] = { text = "top", color = colors.white, handler = read };
- [2] = { text = "bottom", color = colors.white, handler = read };
- [3] = { text = "left", color = colors.white, handler = read };
- [4] = { text = "right", color = colors.white, handler = read };
- [5] = { text = "front", color = colors.white, handler = read };
- [6] = { text = "back", color = colors.white, handler = read };
- }
- menu[3].items = {
- [1] = { text = "login", color = colors.white, handler = read };
- [2] = { text = "create account", color = colors.white, handler = read };
- [3] = { text = "exit", color = colors.white, handler = program.exit};
- [4] = { text = "reinstall", color = colors.white, handler = program.reinstall };
- [5] = { text = "uninstall", color = colors.white, handler = program.uninstall };
- }
- menu[4].items = {
- [1] = { text = "Inbox", color = colors.white, handler = read };
- [2] = { text = "archive", color = colors.white, handler = read };
- [3] = { text = "compose", color = colors.white, handler = read };
- [4] = { text = "uninstall", color = colors.white, handler = read };
- }
- function menu.print()
- if term.isColor() then
- term.setBackgroundColor(menu[menu.currentMenu].backColor)
- else
- term.setBackgroundColor(colors.black)
- end
- term.clear()
- term.setCursorPos(1,1)
- if term.isColor() then
- term.setTextColor(menu[menu.currentMenu].textColor)
- else
- term.setTextColor(colors.white)
- end
- print(menu[menu.currentMenu].text)
- menu.x,menu.y = term.getSize()
- menu.x = (menu.x/2)
- menu.y = (menu.y/2) - (#menu.items/2)
- for i = 1,#menu.items do
- if term.isColor() then
- term.setTextColor(menu.items[i].color)
- else
- term.setTextColor(colors.white)
- end
- term.setCursorPos(menu.x-(string.len(menu.items[i].text)/2),menu.y+(i))
- menu.items[i].xPos1,menu.items[i].yPos = term.getCursorPos()
- if menu[menu.currentMenu].pos == i then
- print("<"..menu.items[i].text..">")
- else
- print(" "..menu.items[i].text)
- end
- menu.items[i].xPos2 = menu.items[i].xPos1 + string.len(menu.items[i].text)
- end
- end
- function menu.run()
- menu.items[menu[menu.currentMenu].pos].handler()
- end
- function menu.checkClick(x,y)
- for i = 1,#menu.items do
- if x >= menu.items[i].xPos1
- and x <= menu.items[i].xPos2
- and y == menu.items[i].yPos then
- return i
- end
- end
- end
- while true do
- menu.items = menu[menu.currentMenu].items
- menu.print(menu.pos)
- program.eventData[1],program.eventData[2],program.eventData[3],program.eventData[4] = os.pullEvent()
- if program.eventData[1] == "key" then
- if program.eventData[2] == 208
- or program.eventData[2] == 205 then
- menu[menu.currentMenu].pos = menu[menu.currentMenu].pos + 1
- elseif program.eventData[2] == 200
- or program.eventData[2] == 203 then
- menu[menu.currentMenu].pos = menu[menu.currentMenu].pos - 1
- elseif program.eventData[2] == 28 then
- menu.run()
- end
- elseif program.eventData[1] == "mouse_scroll" then
- menu[menu.currentMenu].pos = menu[menu.currentMenu].pos + program.eventData[2]
- elseif program.eventData[1] == "mouse_click" then
- if program.eventData[2] == 1 then
- menu.temp = menu.checkClick(program.eventData[3],program.eventData[4])
- if menu.temp ~= nil then
- menu[menu.currentMenu].pos = menu.temp
- menu.run()
- end
- end
- end
- if menu[menu.currentMenu].pos > #menu.items then
- menu[menu.currentMenu].pos = 1
- elseif menu[menu.currentMenu].pos < 1 then
- menu[menu.currentMenu].pos = #menu.items
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment