Advertisement
Microstar301

Touch Monitor Chatter v0.5 / cc

Nov 8th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.48 KB | None | 0 0
  1. -- TOUCH MONITOR CHATTER V0.5 for CC: TWEAKED
  2. -- by Voxelat3d
  3.  
  4.  
  5. speaker = peripheral.find("speaker")
  6.  
  7. mon = peripheral.find("monitor")
  8.  
  9. if (mon == nil) then
  10.     error("NO MONITOR FOUND")
  11. elseif not (mon.isColor()) then
  12.     error("NOT AN ADVANCED MONITOR")
  13. end
  14.  
  15. monscale = 1.0
  16. mx,my = mon.getSize()
  17.  
  18. mon.setTextScale(monscale)
  19. mon.clear()
  20. mon.setCursorPos(1,5)
  21. function monprint(strng)
  22.     mon.write(strng)
  23.     px,py = mon.getCursorPos()
  24.     mon.setCursorPos(1,py+1)
  25. end
  26. function drawchatfield()
  27.     mon.setCursorPos(1,math.floor(my/2))
  28.     mon.clearLine()
  29.     mon.setTextColor(colors.black)
  30.     mon.setBackgroundColor(colors.white)
  31.     mon.write("CHAT:")
  32.     mon.setTextColor(colors.white)
  33.     mon.setBackgroundColor(colors.black)
  34.     mon.write(" ")
  35.     mon.setCursorBlink(true)
  36. end
  37. function changescale()
  38.     while true do
  39.         e, k = os.pullEvent("char")
  40.         if (k=="+") then
  41.             if (monscale<4.9) then
  42.                 monscale = monscale + 0.1
  43.             end
  44.            
  45.         elseif (k=="-") then
  46.             if (monscale>0.6) then
  47.                 monscale = monscale - 0.1
  48.             end
  49.         end
  50.         mon.setTextScale(monscale)
  51.         print("monitor text scale: "..monscale)
  52.         mx,my = mon.getSize()
  53.         drawchat()
  54.         osk()
  55.         drawchatfield()
  56.     end
  57. end
  58. print("monitor text scale: "..monscale)
  59.  
  60. cmsg = ""
  61. function osk()
  62.     mon.setCursorPos(1,math.floor(my/2+1))
  63.     monprint("1234567890  BACKSPACE")
  64.     monprint("QWERTYUIOP  ")
  65.     monprint("ASDFGHJKL   ENTER")
  66.     monprint("ZXCVBNM,.   ")
  67.     monprint("-SPACE-     ")
  68. end
  69.  
  70. function oskread()
  71.     while true do
  72.         e,s,ox,oy = os.pullEvent("monitor_touch")
  73.         ty = math.floor(my/2)
  74.         if (ox==1 and oy==(ty+1)) then
  75.             mon.write("1")
  76.             cmsg = cmsg.."1"
  77.         elseif (ox==2 and oy==(ty+1)) then
  78.             mon.write("2")
  79.             cmsg = cmsg.."2"
  80.         elseif (ox==3 and oy==(ty+1)) then
  81.             mon.write("3")
  82.             cmsg = cmsg.."3"
  83.         elseif (ox==4 and oy==(ty+1)) then
  84.             mon.write("4")
  85.             cmsg = cmsg.."4"
  86.         elseif (ox==5 and oy==(ty+1)) then
  87.             mon.write("5")
  88.             cmsg = cmsg.."5"
  89.         elseif (ox==6 and oy==(ty+1)) then
  90.             mon.write("6")
  91.             cmsg = cmsg.."6"
  92.         elseif (ox==7 and oy==(ty+1)) then
  93.             mon.write("7")
  94.             cmsg = cmsg.."7"
  95.         elseif (ox==8 and oy==(ty+1)) then
  96.             mon.write("8")
  97.             cmsg = cmsg.."8"
  98.         elseif (ox==9 and oy==(ty+1)) then
  99.             mon.write("9")
  100.             cmsg = cmsg.."9"
  101.         elseif (ox==10 and oy==(ty+1)) then
  102.             mon.write("0")
  103.             cmsg = cmsg.."0"
  104.         elseif (ox==1 and oy==(ty+2)) then
  105.             mon.write("q")
  106.             cmsg = cmsg.."q"
  107.         elseif (ox==2 and oy==(ty+2)) then
  108.             mon.write("w")
  109.             cmsg = cmsg.."w"
  110.         elseif (ox==3 and oy==(ty+2)) then
  111.             mon.write("e")
  112.             cmsg = cmsg.."e"
  113.         elseif (ox==4 and oy==(ty+2)) then
  114.             mon.write("r")
  115.             cmsg = cmsg.."r"
  116.         elseif (ox==5 and oy==(ty+2)) then
  117.             mon.write("t")
  118.             cmsg = cmsg.."t"
  119.         elseif (ox==6 and oy==(ty+2)) then
  120.             mon.write("y")
  121.             cmsg = cmsg.."y"
  122.         elseif (ox==7 and oy==(ty+2)) then
  123.             mon.write("u")
  124.             cmsg = cmsg.."u"
  125.         elseif (ox==8 and oy==(ty+2)) then
  126.             mon.write("i")
  127.             cmsg = cmsg.."i"
  128.         elseif (ox==9 and oy==(ty+2)) then
  129.             mon.write("o")
  130.             cmsg = cmsg.."o"
  131.         elseif (ox==10 and oy==(ty+2)) then
  132.             mon.write("p")
  133.             cmsg = cmsg.."p"
  134.         elseif (ox==1 and oy==(ty+3)) then
  135.             mon.write("a")
  136.             cmsg = cmsg.."a"
  137.         elseif (ox==2 and oy==(ty+3)) then
  138.             mon.write("s")
  139.             cmsg = cmsg.."s"
  140.         elseif (ox==3 and oy==(ty+3)) then
  141.             mon.write("d")
  142.             cmsg = cmsg.."d"
  143.         elseif (ox==4 and oy==(ty+3)) then
  144.             mon.write("f")
  145.             cmsg = cmsg.."f"
  146.         elseif (ox==5 and oy==(ty+3)) then
  147.             mon.write("g")
  148.             cmsg = cmsg.."g"
  149.         elseif (ox==6 and oy==(ty+3)) then
  150.             mon.write("h")
  151.             cmsg = cmsg.."h"
  152.         elseif (ox==7 and oy==(ty+3)) then
  153.             mon.write("j")
  154.             cmsg = cmsg.."j"
  155.         elseif (ox==8 and oy==(ty+3)) then
  156.             mon.write("k")
  157.             cmsg = cmsg.."k"
  158.         elseif (ox==9 and oy==(ty+3)) then
  159.             mon.write("l")
  160.             cmsg = cmsg.."l"
  161.         elseif (ox==1 and oy==(ty+4)) then
  162.             mon.write("z")
  163.             cmsg = cmsg.."z"
  164.         elseif (ox==2 and oy==(ty+4)) then
  165.             mon.write("x")
  166.             cmsg = cmsg.."x"
  167.         elseif (ox==3 and oy==(ty+4)) then
  168.             mon.write("c")
  169.             cmsg = cmsg.."c"
  170.         elseif (ox==4 and oy==(ty+4)) then
  171.             mon.write("v")
  172.             cmsg = cmsg.."v"
  173.         elseif (ox==5 and oy==(ty+4)) then
  174.             mon.write("b")
  175.             cmsg = cmsg.."b"
  176.         elseif (ox==6 and oy==(ty+4)) then
  177.             mon.write("n")
  178.             cmsg = cmsg.."n"
  179.         elseif (ox==7 and oy==(ty+4)) then
  180.             mon.write("m")
  181.             cmsg = cmsg.."m"
  182.         elseif (ox==8 and oy==(ty+4)) then
  183.             mon.write(",")
  184.             cmsg = cmsg..","
  185.         elseif (ox==9 and oy==(ty+4)) then
  186.             mon.write(".")
  187.             cmsg = cmsg.."."
  188.         elseif (ox<9 and oy==(ty+5)) then
  189.             mon.write(" ")
  190.             cmsg = cmsg.." "
  191.         elseif (ox>12 and ox<18 and oy==(ty+3)) then
  192.             return cmsg
  193.         elseif (ox>12 and ox<22 and oy==(ty+1)) then
  194.             if (cmsg~="") then
  195.                 osx,osy = mon.getCursorPos()
  196.                 mon.setCursorPos(osx-1,osy)
  197.                 mon.write(" ")
  198.                 mon.setCursorPos(osx-1,osy)
  199.                 cmsg=cmsg:sub(1, -2)
  200.             end
  201.         end
  202.     end
  203. end
  204.  
  205. monprint("  #############")
  206. monprint(" #             #")
  207. monprint("#  TOUCH        #")
  208. monprint("#  CHATTER 0.5  #")
  209. monprint("#               #")
  210. monprint(" #               #")
  211. monprint("  #################")
  212. monprint("    by Voxelat3d")
  213. monprint("")
  214. monprint("")
  215. monprint("")
  216. monprint(" Add speaker for notification sound!")
  217. sleep(2)
  218. mon.clear()
  219. mon.setCursorPos(1,1)
  220. msgs = {}
  221. if mx<10 or my<10 then
  222.     error("SCREEN TOO SMALL")
  223. end
  224.  
  225. if not fs.exists("/modemside") then
  226.     monprint("--- REDNET SETUP ---")
  227.     monprint("")
  228.     mon.setCursorPos(1,6)
  229.     monprint(" (top, bottom, right, left, front or back) ")
  230.     mon.setCursorPos(1,3)
  231.     mon.write("Enter side of modem: ")
  232.     modemside = read()
  233.     rednet.open(modemside)
  234.     file = fs.open("/modemside","w")
  235.     file.write(modemside)
  236.     file.close()
  237.     mon.setCursorPos(1,6)
  238.     mon.clearLine()
  239.     monprint("settings written to /modemside")
  240.     monprint("delete file for setup")
  241.     sleep(1)
  242.     os.pullEvent("char")
  243.     mon.clear()
  244. else
  245.     file = fs.open("/modemside","r")
  246.     rednet.open(file.readAll())
  247.     file.close()
  248. end
  249.  
  250. mon.setCursorPos(1,my)
  251. monprint("type exit to quit program")
  252. function drawchat()
  253.     for i=1,(my/2)-1 do
  254.         cx,cy = mon.getCursorPos()
  255.         if (msgs[i]==ni) then
  256.             break
  257.         end
  258.         mon.setCursorPos(1,i)
  259.         mon.clearLine()
  260.         monprint(msgs[i])
  261.         mon.setCursorPos(cx,cy)
  262.     end
  263. end
  264. function addmsg(toadd)
  265.     if (msgs[math.floor(my/2-1)]~=nil) then
  266.         for i=1,math.floor(my/2-1) do
  267.             msgs[i]=msgs[i+1]
  268.         end
  269.         msgs[math.floor(my/2-1)]=toadd      
  270.     else
  271.         for i=1,math.floor(my/2-1) do
  272.             if (msgs[i]==nil) then
  273.                 msgs[i]=toadd
  274.                 break
  275.             end        
  276.         end
  277.     end
  278.     drawchat()
  279. end
  280. function redreceive()
  281.     while true do
  282.         curid,curmsg = rednet.receive()
  283.         addmsg("USER "..tostring(curid).." : "..curmsg)
  284.         if speaker~=nil then
  285.             speaker.playNote("bell",3,16)
  286.             sleep(0.1)
  287.             speaker.playNote("bell",3,13)
  288.         end
  289.     end
  290. end
  291. function send(tosend)
  292.     rednet.broadcast(tosend)
  293. end
  294. function writeui()
  295.     while true do
  296.         osk()
  297.         drawchatfield()
  298.         tosend = oskread()
  299.         if tosend=="quit" or tosend=="QUIT" or tosend=="EXIT" or tosend=="exit" then
  300.             rednet.close(modemside)
  301.             mon.clear()
  302.             break
  303.         end
  304.         if not (tosend=="") then
  305.             addmsg("ME("..os.getComputerID()..") : "..tosend)
  306.             send(tosend)
  307.         end
  308.         cmsg = ""
  309.     end
  310. end
  311.  
  312. parallel.waitForAny(redreceive,writeui,changescale)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement