Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- TOUCH MONITOR CHATTER V0.5 for CC: TWEAKED
- -- by Voxelat3d
- speaker = peripheral.find("speaker")
- mon = peripheral.find("monitor")
- if (mon == nil) then
- error("NO MONITOR FOUND")
- elseif not (mon.isColor()) then
- error("NOT AN ADVANCED MONITOR")
- end
- monscale = 1.0
- mx,my = mon.getSize()
- mon.setTextScale(monscale)
- mon.clear()
- mon.setCursorPos(1,5)
- function monprint(strng)
- mon.write(strng)
- px,py = mon.getCursorPos()
- mon.setCursorPos(1,py+1)
- end
- function drawchatfield()
- mon.setCursorPos(1,math.floor(my/2))
- mon.clearLine()
- mon.setTextColor(colors.black)
- mon.setBackgroundColor(colors.white)
- mon.write("CHAT:")
- mon.setTextColor(colors.white)
- mon.setBackgroundColor(colors.black)
- mon.write(" ")
- mon.setCursorBlink(true)
- end
- function changescale()
- while true do
- e, k = os.pullEvent("char")
- if (k=="+") then
- if (monscale<4.9) then
- monscale = monscale + 0.1
- end
- elseif (k=="-") then
- if (monscale>0.6) then
- monscale = monscale - 0.1
- end
- end
- mon.setTextScale(monscale)
- print("monitor text scale: "..monscale)
- mx,my = mon.getSize()
- drawchat()
- osk()
- drawchatfield()
- end
- end
- print("monitor text scale: "..monscale)
- cmsg = ""
- function osk()
- mon.setCursorPos(1,math.floor(my/2+1))
- monprint("1234567890 BACKSPACE")
- monprint("QWERTYUIOP ")
- monprint("ASDFGHJKL ENTER")
- monprint("ZXCVBNM,. ")
- monprint("-SPACE- ")
- end
- function oskread()
- while true do
- e,s,ox,oy = os.pullEvent("monitor_touch")
- ty = math.floor(my/2)
- if (ox==1 and oy==(ty+1)) then
- mon.write("1")
- cmsg = cmsg.."1"
- elseif (ox==2 and oy==(ty+1)) then
- mon.write("2")
- cmsg = cmsg.."2"
- elseif (ox==3 and oy==(ty+1)) then
- mon.write("3")
- cmsg = cmsg.."3"
- elseif (ox==4 and oy==(ty+1)) then
- mon.write("4")
- cmsg = cmsg.."4"
- elseif (ox==5 and oy==(ty+1)) then
- mon.write("5")
- cmsg = cmsg.."5"
- elseif (ox==6 and oy==(ty+1)) then
- mon.write("6")
- cmsg = cmsg.."6"
- elseif (ox==7 and oy==(ty+1)) then
- mon.write("7")
- cmsg = cmsg.."7"
- elseif (ox==8 and oy==(ty+1)) then
- mon.write("8")
- cmsg = cmsg.."8"
- elseif (ox==9 and oy==(ty+1)) then
- mon.write("9")
- cmsg = cmsg.."9"
- elseif (ox==10 and oy==(ty+1)) then
- mon.write("0")
- cmsg = cmsg.."0"
- elseif (ox==1 and oy==(ty+2)) then
- mon.write("q")
- cmsg = cmsg.."q"
- elseif (ox==2 and oy==(ty+2)) then
- mon.write("w")
- cmsg = cmsg.."w"
- elseif (ox==3 and oy==(ty+2)) then
- mon.write("e")
- cmsg = cmsg.."e"
- elseif (ox==4 and oy==(ty+2)) then
- mon.write("r")
- cmsg = cmsg.."r"
- elseif (ox==5 and oy==(ty+2)) then
- mon.write("t")
- cmsg = cmsg.."t"
- elseif (ox==6 and oy==(ty+2)) then
- mon.write("y")
- cmsg = cmsg.."y"
- elseif (ox==7 and oy==(ty+2)) then
- mon.write("u")
- cmsg = cmsg.."u"
- elseif (ox==8 and oy==(ty+2)) then
- mon.write("i")
- cmsg = cmsg.."i"
- elseif (ox==9 and oy==(ty+2)) then
- mon.write("o")
- cmsg = cmsg.."o"
- elseif (ox==10 and oy==(ty+2)) then
- mon.write("p")
- cmsg = cmsg.."p"
- elseif (ox==1 and oy==(ty+3)) then
- mon.write("a")
- cmsg = cmsg.."a"
- elseif (ox==2 and oy==(ty+3)) then
- mon.write("s")
- cmsg = cmsg.."s"
- elseif (ox==3 and oy==(ty+3)) then
- mon.write("d")
- cmsg = cmsg.."d"
- elseif (ox==4 and oy==(ty+3)) then
- mon.write("f")
- cmsg = cmsg.."f"
- elseif (ox==5 and oy==(ty+3)) then
- mon.write("g")
- cmsg = cmsg.."g"
- elseif (ox==6 and oy==(ty+3)) then
- mon.write("h")
- cmsg = cmsg.."h"
- elseif (ox==7 and oy==(ty+3)) then
- mon.write("j")
- cmsg = cmsg.."j"
- elseif (ox==8 and oy==(ty+3)) then
- mon.write("k")
- cmsg = cmsg.."k"
- elseif (ox==9 and oy==(ty+3)) then
- mon.write("l")
- cmsg = cmsg.."l"
- elseif (ox==1 and oy==(ty+4)) then
- mon.write("z")
- cmsg = cmsg.."z"
- elseif (ox==2 and oy==(ty+4)) then
- mon.write("x")
- cmsg = cmsg.."x"
- elseif (ox==3 and oy==(ty+4)) then
- mon.write("c")
- cmsg = cmsg.."c"
- elseif (ox==4 and oy==(ty+4)) then
- mon.write("v")
- cmsg = cmsg.."v"
- elseif (ox==5 and oy==(ty+4)) then
- mon.write("b")
- cmsg = cmsg.."b"
- elseif (ox==6 and oy==(ty+4)) then
- mon.write("n")
- cmsg = cmsg.."n"
- elseif (ox==7 and oy==(ty+4)) then
- mon.write("m")
- cmsg = cmsg.."m"
- elseif (ox==8 and oy==(ty+4)) then
- mon.write(",")
- cmsg = cmsg..","
- elseif (ox==9 and oy==(ty+4)) then
- mon.write(".")
- cmsg = cmsg.."."
- elseif (ox<9 and oy==(ty+5)) then
- mon.write(" ")
- cmsg = cmsg.." "
- elseif (ox>12 and ox<18 and oy==(ty+3)) then
- return cmsg
- elseif (ox>12 and ox<22 and oy==(ty+1)) then
- if (cmsg~="") then
- osx,osy = mon.getCursorPos()
- mon.setCursorPos(osx-1,osy)
- mon.write(" ")
- mon.setCursorPos(osx-1,osy)
- cmsg=cmsg:sub(1, -2)
- end
- end
- end
- end
- monprint(" #############")
- monprint(" # #")
- monprint("# TOUCH #")
- monprint("# CHATTER 0.5 #")
- monprint("# #")
- monprint(" # #")
- monprint(" #################")
- monprint(" by Voxelat3d")
- monprint("")
- monprint("")
- monprint("")
- monprint(" Add speaker for notification sound!")
- sleep(2)
- mon.clear()
- mon.setCursorPos(1,1)
- msgs = {}
- if mx<10 or my<10 then
- error("SCREEN TOO SMALL")
- end
- if not fs.exists("/modemside") then
- monprint("--- REDNET SETUP ---")
- monprint("")
- mon.setCursorPos(1,6)
- monprint(" (top, bottom, right, left, front or back) ")
- mon.setCursorPos(1,3)
- mon.write("Enter side of modem: ")
- modemside = read()
- rednet.open(modemside)
- file = fs.open("/modemside","w")
- file.write(modemside)
- file.close()
- mon.setCursorPos(1,6)
- mon.clearLine()
- monprint("settings written to /modemside")
- monprint("delete file for setup")
- sleep(1)
- os.pullEvent("char")
- mon.clear()
- else
- file = fs.open("/modemside","r")
- rednet.open(file.readAll())
- file.close()
- end
- mon.setCursorPos(1,my)
- monprint("type exit to quit program")
- function drawchat()
- for i=1,(my/2)-1 do
- cx,cy = mon.getCursorPos()
- if (msgs[i]==ni) then
- break
- end
- mon.setCursorPos(1,i)
- mon.clearLine()
- monprint(msgs[i])
- mon.setCursorPos(cx,cy)
- end
- end
- function addmsg(toadd)
- if (msgs[math.floor(my/2-1)]~=nil) then
- for i=1,math.floor(my/2-1) do
- msgs[i]=msgs[i+1]
- end
- msgs[math.floor(my/2-1)]=toadd
- else
- for i=1,math.floor(my/2-1) do
- if (msgs[i]==nil) then
- msgs[i]=toadd
- break
- end
- end
- end
- drawchat()
- end
- function redreceive()
- while true do
- curid,curmsg = rednet.receive()
- addmsg("USER "..tostring(curid).." : "..curmsg)
- if speaker~=nil then
- speaker.playNote("bell",3,16)
- sleep(0.1)
- speaker.playNote("bell",3,13)
- end
- end
- end
- function send(tosend)
- rednet.broadcast(tosend)
- end
- function writeui()
- while true do
- osk()
- drawchatfield()
- tosend = oskread()
- if tosend=="quit" or tosend=="QUIT" or tosend=="EXIT" or tosend=="exit" then
- rednet.close(modemside)
- mon.clear()
- break
- end
- if not (tosend=="") then
- addmsg("ME("..os.getComputerID()..") : "..tosend)
- send(tosend)
- end
- cmsg = ""
- end
- end
- parallel.waitForAny(redreceive,writeui,changescale)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement