Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("c")
- os.loadAPI("p")
- local fields = {}
- fields = {{15,10,23,10,nil,""},
- {9,13,33,17,nil,""},
- {35,13,43,14," save",""},
- {35,16,43,17," clear",""}
- }
- -- convenience functions: because we can!
- local function drawFields()
- local xalt,yalt = term.getCursorPos()
- term.setBackgroundColor(colors.gray)
- for f = 1,#fields do
- for fLines = 0,fields[f][4]-fields[f][2] do
- c.xwrite(string.rep(" ",fields[f][3]-fields[f][1]),fields[f][1],fields[f][2]+fLines)
- end
- if fields[f][6] ~= ""
- then c.writefit(fields[f][6],fields[f][1],fields[f][2],fields[f][3])
- end
- if fields[f][5] ~= nil
- then c.xwrite(fields[f][5],fields[f][1],fields[f][4])
- end
- end
- term.setBackgroundColor(colors.black)
- term.setCursorPos(xalt,yalt)
- end
- local function clearScreen()
- term.clear()
- drawFields()
- p.sign(34,3)
- c.xwrite("NEWS-BOARD",9,5)
- c.xwrite("Name:",9,10)
- c.xwrite("New Message:",9,12)
- term.setCursorPos(fields[1][1],fields[1][2])
- end
- local function isField(x,y)
- local returnField = -1
- for i=1,#fields do
- if x>=fields[i][1] and x<=fields[i][3] and y>=fields[i][2] and y<= fields[i][4]
- then returnField = i end
- end
- return returnField
- end
- local function incID()
- local file = fs.open("archive/lastid.inf","r")
- local messageID = tonumber(file.readLine()) +1
- file.close()
- file = fs.open("archive/lastid.inf","w")
- file.writeLine(messageID)
- file.close()
- return messageID
- end
- local function saveToFile()
- local saveFile = fs.open("archive/"..incID()..".msg","w")
- local today = ""
- -- today = http.get("http://www.timeapi.org/cet/now?format=%25c").readAll()
- local firstLine = fields[1][6]..today
- saveFile.writeLine(firstLine)
- saveFile.writeLine(fields[2][6])
- saveFile.close()
- end
- local function onClick(x,y)
- if isField(x,y) == 1 or isField(x,y) == 2
- then term.setCursorPos(fields[isField(x,y)][1],fields[isField(x,y)][2])
- end
- if isField(x,y) == 3 and string.len(fields[1][6]) >= 3 and string.len(fields[2][6]) >=5
- then term.clear() --- ditte wech, wenn animiert
- saveToFile()
- print("saved")--- Animation hier!
- sleep(2)
- fields[1][6] = ""
- fields[2][6] = ""
- clearScreen()
- shell.run("output")
- elseif isField(x,y) == 4
- then
- --Todo clearAll Variables,counters etc.
- fields[1][6] = ""
- fields[2][6] = ""
- clearScreen()
- end
- end
- local function getAction()
- local event,p1,p2,p3,p4,p5 = os.pullEvent()
- if event == "mouse_click"
- then onClick(p2,p3)
- elseif event == "char"
- then if isField(term.getCursorPos()) == 1 and string.len(fields[1][6])<8
- then fields[1][6] = fields[1][6]..p1
- drawFields()
- -- term.setCursorPos(fields[1][1],fields[1][2])
- -- c.xwrite(fields[1][6],fields[1][1],fields[1][2])
- end
- if isField(term.getCursorPos()) == 2 and string.len(fields[2][6])<115
- then fields[2][6] = fields[2][6]..p1
- drawFields()
- -- c.writefit(fields[2][6],fields[2][1],fields[2][2],fields[2][3])
- end
- elseif event == "key"
- then if p1 == 14 and isField(term.getCursorPos()) == 1 and string.len(fields[1][6])>=1
- then fields[1][6] = string.sub(fields[1][6],1,string.len(fields[1][6])-1)
- drawFields()
- end
- if p1 == 14 and isField(term.getCursorPos()) == 2 and string.len(fields[2][6])>=1
- then fields[2][6] = string.sub(fields[2][6],1,string.len(fields[2][6])-1)
- drawFields()
- end
- if p1 == 15
- then
- if isField(term.getCursorPos()) == 1
- then term.setCursorPos(fields[2][1],fields[2][2])
- else term.setCursorPos(fields[1][1],fields[1][2])
- end
- end
- end
- end
- --Program
- clearScreen()
- while true do
- term.setCursorBlink(true)
- getAction()
- --sleep(0.5)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement