Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Find File and Rename
- local sFile = "Server_Rules"
- if fs.exists(sFile) then
- shell.run("rename",sFile, "startup")
- os.reboot()
- end
- local serverName = nil
- -- Determine where monitor is.
- monitorSide = nil
- if peripheral.isPresent("left") and peripheral.getType("left")=="monitor" then
- monitorSide = "left"
- elseif peripheral.isPresent("right") and peripheral.getType("right")=="monitor" then
- monitorSide = "right"
- elseif peripheral.isPresent("top") and peripheral.getType("top")=="monitor" then
- monitorSide = "top"
- elseif peripheral.isPresent("back") and peripheral.getType("back")=="monitor" then
- monitorSide = "back"
- elseif peripheral.isPresent("bottom") and peripheral.getType("bottom")=="monitor" then
- monitorSide = "bottom"
- end
- if monitorSide ~= nil then
- monitor = peripheral.wrap(monitorSide)
- print("Monitor found on "..monitorSide)
- monitor.setTextScale(.7)
- else
- monitor = nil
- end
- -- Peripheral Wraps
- todo = monitor
- --Check for Monitors
- if not todo then
- error("No Monitor Found",0)
- end
- -- Text Scale
- todo.setTextScale(.5)
- -- Define Tables
- todoData = {}
- -- make directory
- if fs.exists("data") == false then
- fs.makeDir("data")
- end
- if fs.exists("data/todo") == false then
- file = fs.open("data/todo","w")
- file.close()
- end
- -- check for ServerName
- local sPath = "serverName"
- if fs.exists(sPath) == false then
- print("What is the name of your server")
- sResponse = read()
- local file = fs.open( sPath, "w" )
- file.write( sResponse )
- file.close()
- os.reboot()
- else
- file = fs.open(sPath, "r")
- serverName = file.readLine()
- end
- -- Check for Advanced Computer Monitors
- if not term.isColor() then
- error("This Program Must be Run on an Advanced Computer",0)
- end
- if not todo.isColor() then
- error("you must Have Color Monitors",0)
- end
- -- Check Monitor Size
- w,h = todo.getSize()
- if w~= 36 or h ~= 38 then
- error("Monitor is not the Correct Size,\n3 High and 2 Wide is Correct Size.",0)
- end
- term.clear()
- term.setCursorPos(1,1)
- print( "Downloaded as "..sFile )
- sleep(1)
- -- Text Functions
- function center(mon,text,line,colour)
- w,h = todo.getSize()
- if mon == "todo" then
- todo.setCursorPos((w-string.len(text))/2+1,line)
- todo.setTextColor(colour)
- todo.write(text)
- todo.setTextColor(colors.white)
- end
- end
- function wr(mon,x,y,text,colour)
- if mon == "todo" then
- todo.setCursorPos(x,y)
- todo.setTextColor(colour)
- todo.write(text)
- todo.setTextColor(colors.white)
- end
- end
- -- table functions
- function tableW(name,text)
- if name == "todo" then
- table.insert(todoData, text)
- end
- end
- --File Functions
- function getData()
- local file = fs.open("data/todo","r")
- local i = 1
- while true do
- todoData[i] = file.readLine()
- if todoData[i] == nil then
- break
- else
- i = i + 1
- end
- end
- file.close()
- end
- function saveData()
- local file = fs.open("data/todo","w")
- for i = 1, #todoData do
- file.writeLine(todoData[i])
- end
- file.close()
- end
- -- Monitors
- function todoMon()
- todo.clear()
- local nameServer = serverName .. " Rules"
- center("todo",nameServer,1,colors.red)
- posx = 1
- posy = 3
- for i=1, #todoData do
- wr("todo",posx,posy,tostring(i),colors.lime)
- posx = posx + 2
- wr("todo",posx,posy,todoData[i],colors.white)
- posx = posx - 2
- posy = posy + 2
- end
- end
- -- Table functions
- function clear(name)
- if name == "todo" then
- for i=1, #todoData do
- table.remove(todoData)
- end
- end
- end
- -- GUI Things
- -- Main Menu
- local menu_options = {
- [1] = {text="List", color = colors.lightBlue},
- [2] = {text=serverName, color = colors.lightBlue}
- }
- -- List Menu
- local todo_options = {
- [1] = {text="Add", color = colors.lime},
- [2] = {text="Delete", color = colors.magenta}
- }
- -- Find Terminal X Y
- local termX, termY = term.getSize()
- -- Draw Main Menu
- function mainMenuDraw(selected)
- local yPos = termY/2 - #menu_options/2
- for index, data in pairs(menu_options) do
- menu_options[index].bounds = {
- x1 = termX/2 - (#data.text+4)/2,
- x2 = termX/2 + (#data.text+4)/2,
- y = yPos
- }
- term.setTextColor(data.color)
- term.setCursorPos(data.bounds.x1, data.bounds.y)
- local text =
- index==selected and "[ "..data.text.." ]" or
- " "..data.text.." "
- term.write(text)
- yPos = yPos + 2
- end
- end
- -- Draw ToDo Menu
- function todoMenuDraw(selected)
- local yPos = termY/2 - #todo_options/2
- for index, data in pairs(todo_options) do
- todo_options[index].bounds = {
- x = termX/2 - (#data.text+4)/2,
- y = yPos
- }
- term.setTextColor(data.color)
- term.setCursorPos(data.bounds.x,data.bounds.y)
- local text =
- index == selected and "[ "..data.text.." ]" or
- " "..data.text.." "
- term.write(text)
- yPos = yPos + 2
- end
- end
- -- Check click Position
- function checkClick(x,y)
- for index, data in pairs(menu_options) do
- if x >= data.bounds.x1 and x <= data.bounds.x2 and y == data.bounds.y then
- return index
- end
- end
- return false
- end
- --Display Main Menu
- function mainMenu()
- todoMon()
- term.clear()
- term.setCursorPos(termX/2-14,1)
- term.setTextColor(colors.magenta)
- term.write(serverName)
- local selector = 1
- while true do
- mainMenuDraw(selector)
- local e = {os.pullEvent()}
- if e[1] == "key" then
- if e[2] == keys.down then
- selector = selector < #menu_options and selector+1 or 1
- elseif e[2] == keys.up then
- selector = selector > 1 and selector-1 or #menu_options
- elseif e[2] == keys.enter then
- break
- end
- end
- end
- term.clear()
- if selector == 1 then
- todoMenu()
- end
- end
- -- Display Menu 2
- function todoMenu()
- todoMon()
- term.clear()
- term.setCursorPos(termX/2-5,1)
- term.setTextColor(colors.magenta)
- term.write("Rules")
- term.setCursorPos(termX/2-19 ,2)
- term.setTextColor(colors.green)
- term.write("Press Backspace to Go Back to the Main Menu")
- local selector = 1
- while true do
- todoMenuDraw(selector)
- local e = {os.pullEvent()}
- if e[1] == "key" then
- if e[2] == keys.down then
- selector = selector < #todo_options and selector+1 or 1
- elseif e[2] == keys.up then
- slector = selector > 1 and selector-1 or #todo_options
- elseif e[2] == keys.backspace then
- mainMenu()
- elseif e[2] == keys.enter then
- break
- end
- end
- end
- term.clear()
- term.setCursorPos(1,1)
- if selector == 1 then
- addTaskMenu()
- elseif selector == 2 then
- deleteTaskMenu()
- end
- end
- --Add Task Menu
- function addTaskMenu()
- term.clear()
- term.setCursorPos(termX/2-13 ,1)
- term.setTextColor(colors.white)
- term.write("Type Task Then Press Enter")
- term.setCursorPos(2,3)
- term.setTextColor(colors.lime)
- term.write("> ")
- term.setTextColor(colors.white)
- local task = read()
- if string.len(task) > 32 then
- term.clear()
- term.setCursorPos(termX/2-10,1)
- term.setTextColor(colors.red)
- term.write("Error: Task too long!")
- sleep(2)
- todoMenu()
- elseif #todoData == 18 then
- term.clear()
- term.setCursorPos(termX/2-11,1)
- term.setTextColor(colors.red)
- term.write("Error: ToDo List Full!")
- sleep(2)
- todoMenu()
- else
- tableW("todo", task)
- saveData()
- todoMenu()
- end
- end
- -- Delete Task Menu
- function deleteTaskMenu()
- term.clear()
- term.setCursorPos(termX/2-14 ,1)
- term.setTextColor(colors.white)
- term.write("Type Number of Task To Delete")
- term.setCursorPos(termX/2-11 ,2)
- term.write("Or Type 'all' to clear")
- term.setCursorPos(2,3)
- term.setTextColor(colors.lime)
- term.write("> ")
- term.setTextColor(colors.white)
- number = read()
- if number == "all" then
- clear("todo")
- elseif tonumber(number) == nil then
- term.clear()
- term.setCursorPos(termX/2-10 ,1)
- term.setTextColor(colors.red)
- term.write("Error: Not A Number!")
- sleep(2)
- else
- table.remove(todoData, number)
- end
- saveData()
- todoMenu()
- end
- getData()
- mainMenu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement