Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- side = "top"
- pSide = "top"
- mon = peripheral.wrap(side)
- w, h = mon.getSize()
- project = {}
- mainMenu = {"Rules", "View projects"}
- yourProjects = {}
- names = {}
- nameList = {}
- screen = 0
- deleteYes = false
- deleteNo = false
- goBack = false
- backToMainMenu = false
- selectedName = false
- player = peripheral.wrap(pSide)
- screen = 0
- sec = 0
- rules = {[1] = "- No griefing -", [2] = "- No stealing -", [3] = "- No cheating in any way -", [4] = "- PvP only on agreement -", [5] = "- Be friendly and respectful -", [6] = "- Have fun -", [7] = "- Don't break the rules -"}
- for i = 1, 100 do
- names[i] = {}
- end
- function checkFile(path) -- check if file exists
- if not fs.exists(path) then
- file = fs.open(path, "w")
- file.close()
- end
- end
- function writeFile(fileName, tableName) -- overwrites an old file
- file = fs.open(fileName, "w")
- file.write(textutils.serialize(tableName))
- file.close()
- end
- function loadProjects(load) -- Load filed called projects
- checkFile(load)
- file = fs.open(load, "r")
- readFile = file.readLine()
- if readFile ~= nil then
- project = textutils.unserialize(readFile)
- end
- file.close()
- end
- function loadNames(load) -- load file called names
- checkFile(load)
- file = fs.open(load, "r")
- readFile = file.readLine()
- if readFile ~= nil then
- names = textutils.unserialize(readFile)
- end
- file.close()
- end
- function loadRules(load) -- load file called rules
- checkFile(load)
- file = fs.open(load, "r")
- readFile = file.readLine()
- if readFile ~= nil then
- rules = textutils.unserialize(readFile)
- end
- file.close()
- end
- function getInputProject() -- read user input and inserts it to the project table
- term.setCursorPos(w/2, h-2)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- input = read()
- table.insert(project, input)
- end
- function getInputName(projectName) -- read user input and inserts it to table in names table.
- term.setCursorPos(w/2, h-2)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- input = read()
- i = projectName
- table.insert(names[i], input)
- end
- function drawImage(image, x, y)
- myImage = paintutils.loadImage(image)
- paintutils.drawImage(myImage, x, y)
- end
- function viewProjects() -- displays stored projects
- term.clear()
- mWrite("<--", 1, h, colors.black, colors.white)
- x = 1
- y = 1
- mWrite("New project", (w-11)/2, h, colors.black, colors.white)
- if table.getn(project) > 0 then
- for i = 1, #project do
- drawImage("button", x, y)
- cY = y +2
- cX = x+1
- y = y + 4
- mWrite(project[i], cX, cY, colors.lime)
- mWrite("[X]", w-2, 1, colors.black, colors.red)
- if y >= h - 4 then y = 1 x = x+12 end
- end
- else
- mWrite("There are currently no projects", (w-31)/2, h/2, colors.white)
- end
- end
- function startMenu() -- displays start menu
- term.clear()
- drawImage("header", 1, 1)
- mWrite("Build Board", (w-11)/2, 2, colors.lightGray)
- x = (w/8)+2
- y = h/2
- cY = y+1
- cX = x +5
- for i = 1, #mainMenu do
- drawImage("main", x, y)
- mWrite(mainMenu[i], cX, cY, colors.white)
- cX = cX + 16
- x = x+20
- end
- end
- function rulesDisplay()
- term.clear()
- -- mWrite("Add rule", (w-8)/2, h, colors.lightBlue, colors.white)
- y = ((h-(#rules*2))/2)+2
- drawImage("rulesScreen", 1,1)
- mWrite("<--", 1, h, colors.lightBlue, colors.white)
- for i = 1, #rules do
- x = (w-#rules[i])/2
- mWrite(rules[i], x, y, colors.white)
- y= y+2
- end
- rulesTouch()
- end
- function drawBoard() -- decides which menu to draw
- term.clear()
- startMenu()
- if screen == 0 then
- event, param1, posx, posy = os.pullEvent()
- if event == "monitor_touch" and posx > 27 and posx < 44 and posy > (h/2)-1 and posy < (h/2)+3 then screen = 1
- elseif event == "monitor_touch" and posx > 7 and posx < 24 and posy > (h/2)-1 and posy < (h/2)+3 then screen = -1
- elseif event == "timer" then
- sec = sec+1
- if sec == 30 then shell.run("startup") end
- -- timer = os.startTimer(1)
- end
- end
- if screen == 0 then
- startMenu()
- --touch()
- elseif screen == 1 then
- sec = 0
- viewProjects()
- inputProject()
- elseif screen == -1 then
- sec = 0
- rulesDisplay()
- end
- end
- function mWrite(message, cX, cY, background, text) -- writes message on cX and cY with background as background color
- mon.setBackgroundColor(background)
- if text == nil then mon.setTextColor(colors.black)
- else mon.setTextColor(text) end
- mon.setCursorPos(cX, cY)
- mon.write(message)
- mon.setBackgroundColor(colors.black)
- end
- function rulesTouch() -- Toggle between menues
- event, param1, x, y = os.pullEvent()
- if event == "monitor_touch" and x < 4 and y == h then screen = screen +1
- if screen == 2 then screen = 0 end
- -- elseif event == "monitor_touch" and x > (w-8)/2 and x < ((w-8)/2)+8 and y == h then
- -- newRule = read()
- -- table.insert(rules, newRule)
- -- writeFile("rules", rules)
- end
- end
- function inputProject() -- add a project to the list
- event, param1, x, y = os.pullEvent()
- if event == "monitor_touch" and x > (w-13)/2 and x < (w+11)/2 and y == h then
- getInputProject()
- writeFile("projects", project)
- elseif event == "monitor_touch" and x > w-3 and y == 1 then selectDeleteProject()
- elseif event == "monitor_touch" and x < 4 and y == h then screen = screen +1
- if screen == 2 then screen = 0 end
- else clickProject()
- end
- end
- function clickProject() -- determines which project is clicked
- if event == "monitor_touch" and x > 1 and x < 13 and y > 1 and y < 5 and table.getn(project) > 0 then enterProject(1)
- elseif event == "monitor_touch" and x > 1 and x < 13 and y > 5 and y <9 and table.getn(project) > 1 then enterProject(2)
- elseif event == "monitor_touch" and x > 1 and x < 13 and y > 9 and y < 13 and table.getn(project) > 2 then enterProject(3)
- elseif event == "monitor_touch" and x > 1 and x < 13 and y > 13 and y < 17 and table.getn(project) > 3 then enterProject(4)
- elseif event == "monitor_touch" and x > 13 and x < 25 and y > 1 and y < 5 and table.getn(project) > 4 then enterProject(5)
- elseif event == "monitor_touch" and x > 13 and x < 25 and y > 5 and y <9 and table.getn(project) > 5 then enterProject(6)
- elseif event == "monitor_touch" and x > 13 and x < 25 and y > 9 and y < 13 and table.getn(project) > 6 then enterProject(7)
- elseif event == "monitor_touch" and x > 13 and x < 25 and y > 13 and y < 17 and table.getn(project) > 7 then enterProject(8)
- elseif event == "monitor_touch" and x > 25 and x < 37 and y > 1 and y < 5 and table.getn(project) > 8 then enterProject(9)
- elseif event == "monitor_touch" and x > 25 and x < 37 and y > 5 and y < 9 and table.getn(project) > 9 then enterProject(10)
- elseif event == "monitor_touch" and x > 25 and x < 37 and y > 9 and y < 13 and table.getn(project) > 10 then enterProject(11)
- elseif event == "monitor_touch" and x > 25 and x < 37 and y > 13 and y < 17 and table.getn(project) > 11 then enterProject(12)
- elseif event == "monitor_touch" and x > 37 and x < 49 and y > 1 and y < 5 and table.getn(project) > 12 then enterProject(13)
- elseif event == "monitor_touch" and x > 37 and x < 49 and y > 5 and y < 9 and table.getn(project) > 13 then enterProject(14)
- elseif event == "monitor_touch" and x > 37 and x < 49 and y > 9 and y < 13 and table.getn(project) > 14 then enterProject(15)
- elseif event == "monitor_touch" and x > 37 and x < 49 and y > 13 and y < 17 and table.getn(project) > 15 then enterProject(16)
- elseif event == "monitor_touch" and y == h and x < 4 then screen = screen +1
- if screen == 2 then screen = 1 end
- end
- end
- function enterProject(projectName) -- see who is working on clicked project
- currProject = projectName
- while true do
- term.clear()
- mWrite("<--", 1, h, colors.black, colors.white)
- drawImage("header", 1,1)
- mWrite(project[projectName], (w-#project[projectName])/2, 2, colors.lightGray)
- mWrite("Add name", (w-8)/2, h, colors.black, colors.white)
- mWrite("[X]", w-2, 1, colors.lightGray, colors.red)
- x = 1
- y = 5
- if names[projectName] ~= nil then
- if table.getn(names[projectName]) > 0 then
- for i = 1, #names[projectName] do
- drawImage("button", x, y)
- cY = y +2
- cX = x+1
- y = y + 4
- mWrite(names[projectName][i], cX, cY, colors.lime)
- if y >= h - 4 then y = 5 x = x+12 end
- end
- else
- mWrite("No one is working on this project", (w-33)/2, h/2, colors.white)
- end
- end
- inputName(projectName)
- if backToMain == true then
- backToMain = false
- break
- end
- end
- end
- function selectDeleteName(projectName) -- select a name for delete
- currProject = projectName
- while true do
- term.clear()
- mWrite("<--", 1, h, colors.black, colors.white)
- drawImage("header", 1,1)
- mWrite(project[projectName], (w-#project[projectName])/2, 2, colors.lightGray)
- x = 1
- y = 5
- if names[projectName] ~= nil then
- if table.getn(names[projectName]) > 0 then
- for i = 1, #names[projectName] do
- drawImage("buttonGray", x, y)
- cY = y +2
- cX = x+1
- y = y + 4
- mWrite(names[projectName][i], cX, cY, colors.lightGray)
- if y >= h - 4 then y = 5 x = x+12 end
- end
- else
- mWrite("No one is working on this project", (w-33)/2, h/2, colors.white)
- end
- end
- activeProject = projectName
- clickName(projectName)
- if selectedName ~= false then
- deleteName(selectedName, projectName)
- selectedName = false
- end
- if goBack == true then
- goBack = false
- break
- end
- end
- end
- function tableCounter(projectName)
- number = 0
- for k, v in pairs(names[projectName]) do
- number = number +1
- end
- return tonumber(number)
- end
- function clickName(projectName)
- event, param1, x, y = os.pullEvent("monitor_touch")
- if event == "monitor_touch" then notInUse = 1 end
- event, param1, x, y = os.pullEvent("monitor_touch")
- if x > 1 and x < 13 and y > 5 and y < 9 then selectedName = 1
- elseif x > 1 and x < 13 and y > 9 and y <13 then selectedName = 2
- elseif x > 1 and x < 13 and y > 13 and y < 17 then selectedName = 3
- elseif x > 13 and x < 25 and y > 5 and y < 9 then selectedName = 4
- elseif x > 13 and x < 25 and y > 9 and y <13 then selectedName = 5
- elseif x > 13 and x < 25 and y > 13 and y < 17 then selectedName = 6
- elseif x > 25 and x < 37 and y > 5 and y < 9 then selectedName = 7
- elseif x > 25 and x < 37 and y > 9 and y < 13 then selectedName = 8
- elseif x > 25 and x < 37 and y > 13 and y < 17 then selectedName = 9
- elseif x > 37 and x < 49 and y > 5 and y < 9 then selectedName = 10
- elseif x > 37 and x < 49 and y > 9 and y < 13 then selectedName = 11
- elseif x > 37 and x < 49 and y > 13 and y < 17 then selectedName = 12
- elseif y == h and x < 4 then goBack = true
- end
- end
- function deleteName(selectedName, projectName)
- currProject = projectName
- selectedName = selectedName
- term.clear()
- drawImage("yes", (w/4), h/2)
- drawImage("no", (w/4)*3, h/2)
- mWrite("Yes", (w/4)+1, (h/2)+1, colors.white)
- mWrite("No", (w/4)*3+1, (h/2)+1, colors.white)
- event, param1, x, y = os.pullEvent("monitor_touch")
- if x > (w/4)-1 and x < (w/4)+5 and y > (h/2)-1 and y < (h/2) +3 then deleteYes = true
- elseif x > (w/4)*3-1 and x < (w/4)*3+5 and y > (h/2)-1 and y < (h/2) +3 then deleteNo = true
- end
- if deleteNo == true then goBack = true deleteNo = false
- elseif deleteYes == true then table.remove(names[projectName], selectedName)
- goBack = true
- deleteYes = false
- writeFile("names", names)
- end
- end
- function inputName(projectName) -- add a name to a project
- currProject = projectName
- event, param1, x, y = os.pullEvent("monitor_touch")
- if event == "monitor_touch" and x > (w-11)/2 and x < (w+11)/2 and y == h then
- getInputName(projectName)
- writeFile("names", names)
- elseif event == "monitor_touch" and x > w-3 and y == 1 then selectDeleteName(projectName)
- elseif event == "monitor_touch" and x < 4 and y > h-2 then
- screen = screen +1
- backToMain = true
- if screen == 2 then screen = 1 end
- end
- end
- function selectDeleteProject() -- select a project for delete
- while true do
- term.clear()
- x = 1
- y = 1
- if table.getn(project) > 0 then
- for i = 1, #project do
- drawImage("buttonGray", x, y)
- cY = y +2
- cX = x+1
- y = y + 4
- mWrite(project[i], cX, cY, colors.lightGray)
- if y >= h - 4 then y = 1 x = x+12 end
- end
- else
- mWrite("There are currently no projects", (w-31)/2, h/2, colors.white)
- end
- pickProject()
- if goBack == true then
- goBack = false
- break
- end
- end
- end
- function pickProject() -- registers which project you want to delete
- event, param1, x, y = os.pullEvent("monitor_touch")
- if event == "monitor_touch" then notInUse = 1 end
- event, param1, x, y = os.pullEvent("monitor_touch")
- if x > 1 and x < 13 and y > 1 and y < 5 then deleteProject(1)
- elseif x > 1 and x < 13 and y > 5 and y <9 then deleteProject(2)
- elseif x > 1 and x < 13 and y > 9 and y < 13 then deleteProject(3)
- elseif x > 1 and x < 13 and y > 13 and y < 17 then deleteProject(4)
- elseif x > 13 and x < 25 and y > 1 and y < 5 then deleteProject(5)
- elseif x > 13 and x < 25 and y > 5 and y <9 then deleteProject(6)
- elseif x > 13 and x < 25 and y > 9 and y < 13 then deleteProject(7)
- elseif x > 13 and x < 25 and y > 13 and y < 17 then deleteProject(8)
- elseif x > 25 and x < 37 and y > 1 and y < 5 then deleteProject(9)
- elseif x > 25 and x < 37 and y > 5 and y < 9 then deleteProject(10)
- elseif x > 25 and x < 37 and y > 9 and y < 13 then deleteProject(11)
- elseif x > 25 and x < 37 and y > 13 and y < 17 then deleteProject(12)
- elseif x > 37 and x < 49 and y > 1 and y < 5 then deleteProject(13)
- elseif x > 37 and x < 49 and y > 5 and y < 9 then deleteProject(14)
- elseif x > 37 and x < 49 and y > 9 and y < 13 then deleteProject(15)
- elseif x > 37 and x < 49 and y > 13 and y < 17 then deleteProject(16)
- elseif event == "monitor_touch" and y == h and x < 4 then goBack = true
- if screen == 2 then screen = 1 end
- end
- end
- function deleteProject(selectedProject) -- deletes selected project
- term.clear()
- drawImage("yes", (w/4), h/2)
- drawImage("no", (w/4)*3, h/2)
- mWrite("Yes", (w/4)+1, (h/2)+1, colors.white)
- mWrite("No", (w/4)*3+1, (h/2)+1, colors.white)
- event, param1, x, y = os.pullEvent("monitor_touch")
- if x > (w/4)-1 and x < (w/4)+5 and y > (h/2)-1 and y < (h/2) +3 then deleteYes = true
- elseif x > (w/4)*3-1 and x < (w/4)*3+5 and y > (h/2)-1 and y < (h/2) +3 then deleteNo = true
- end
- if deleteNo == true then goBack = true deleteNo = false
- elseif deleteYes == true then table.remove(project, selectedProject)
- goBack = true
- deleteYes = false
- writeFile("projects", project)
- end
- end
- ---------- LOOP -------------
- term.redirect(mon)
- while true do
- timer = os.startTimer(1)
- loadProjects("projects")
- loadNames("names")
- -- loadRules("rules")
- drawBoard()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement