Advertisement
Redxone

[CC] AES Chat WIP

Jul 1st, 2016
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.76 KB | None | 0 0
  1. local sbc= term.setBackgroundColor
  2. local stc= term.setTextColor
  3. local scp= term.setCursorPos
  4. local w,h= term.getSize()
  5. local ref = {}
  6. ref[1] = 2^15
  7. for i = 1, 15 do
  8.     ref[2^i] = 2^(15-i)
  9. end
  10. local function lnwrite(txt)
  11.     local x,y = term.getCursorPos()
  12.     local ln = 0
  13.     for line in txt:gmatch("[^\n]+") do
  14.         scp(x,y+ln)
  15.         write(line)
  16.         ln = ln + 1
  17.     end
  18. end
  19. local function invert(col)
  20.     return ref[col]
  21. end
  22. local chatrooms = {
  23.     offs = 0,
  24.     rooms = {},
  25.     len = 25,
  26.     lanprotocol = "novachat",
  27.     drawroomcol = function(self,room,bc,tc)
  28.         if(room-self.offs <= 3)then
  29.             local sx = (w/2) + self.len/2
  30.             local sy = 4
  31.             local siy = ( sy*(room-self.offs ) )+(room-self.offs)-1
  32.             --if(eiy > mh)then eiy = eiy - mh end
  33.             paintutils.drawFilledBox((sx) - (self.len-2), siy,(sx/2) + (self.len+9)/2,siy+3,bc)
  34.             scp((sx) - (self.len-3),siy)
  35.             stc(tc)
  36.             write("[" .. room .. "] " .. self.rooms[room].n)
  37.             scp((sx) - (self.len-3),siy+1)
  38.             lnwrite(self.rooms[room].motd)
  39.             scp((sx) - (self.len-3),siy+3)
  40.             write("Server Address: " .. self.rooms[room].ip)
  41.         end
  42.     end,
  43.     draw = function(self)
  44.             term.current().setVisible(false)
  45.             sbc(colors.lightGray)
  46.             term.clear()
  47.             local sx = (w/2) + self.len/2
  48.             local sy = 4
  49.             local mh = h-2
  50.             paintutils.drawBox(((w/2) - self.len/2)+1, 3, ((w/2) + self.len/2)+1,h,colors.black)
  51.             paintutils.drawFilledBox((w/2) - self.len/2, 2, (w/2) + self.len/2,h-1,colors.white)
  52.             paintutils.drawLine((w/2) - self.len/2,2,(w/2) + self.len/2,2,colors.blue)
  53.             stc(colors.white)
  54.             scp((w/2) - self.len/2,2)
  55.             write(" Chat rooms available: " .. #self.rooms)
  56.             if(#self.rooms > 0)then
  57.                 for i = 1+self.offs, 3+self.offs do
  58.                     local siy = ( sy*(i-self.offs ) )+(i-self.offs)-1
  59.                     --if(eiy > mh)then eiy = eiy - mh end
  60.                     paintutils.drawFilledBox((sx) - (self.len-2), siy,(sx/2) + (self.len+9)/2,siy+3,self.rooms[i].bc)
  61.                     scp((sx) - (self.len-3),siy)
  62.                     stc(self.rooms[i].tc)
  63.                     write("[" .. i .. "] " .. self.rooms[i].n)
  64.                     scp((sx) - (self.len-3),siy+1)
  65.                     lnwrite(self.rooms[i].motd)
  66.                     scp((sx) - (self.len-3),siy+3)
  67.                     write("Server Address: " .. self.rooms[i].ip)
  68.                 end
  69.             end
  70.         term.current().setVisible(true)
  71.     end,
  72.     update = function(self,e)
  73.         local b = e[2]
  74.         if(e[1] == "mouse_click")then
  75.             local x,y = e[3], e[4]
  76.             local sx = (w/2) + self.len/2
  77.             local sy = 4
  78.             if(x >= (sx) - (self.len-2) and x <= (sx/2) + self.len+9 and y >= sy and y <= h-2)then
  79.                 for i = 1+self.offs, 3+self.offs do
  80.                     local sy = ( sy*(i-self.offs ) )+(i-self.offs)-1
  81.                     if(y >= sy  and y <= sy+3 )then
  82.                         -- Clicked on i
  83.                         self:drawroomcol(i,invert(self.rooms[i].bc),invert(self.rooms[i].tc))
  84.                         sleep(0.2)
  85.                         self:drawroomcol(i,self.rooms[i].bc,self.rooms[i].tc)
  86.                     end
  87.                 end
  88.             end
  89.         end
  90.         if(e[1] == "mouse_scroll")then
  91.             if(b == -1 and self.offs > 0)then
  92.                 self.offs = self.offs - 1
  93.                 self:draw()
  94.             end
  95.             if(b == 1 and (self.offs+3) < #self.rooms)then
  96.                 self.offs = self.offs + 1
  97.                 self:draw()
  98.             end
  99.         end
  100.     end,
  101.     add = function(self,name,hostip,mes,textc,backc)
  102.         if(#mes > 22 and not mes:find("\n"))then
  103.             for i = 1, math.floor(#mes/22) do
  104.                 mes = mes:sub(1+(22*(i-1)),22*i) .. "\n" .. mes:sub(1+(22*(i)),#mes)
  105.             end
  106.         end
  107.         self.rooms[#self.rooms+1] = {n=name,ip=hostip,motd=mes,tc=textc,bc=backc}
  108.     end,
  109.     remove = function(self,name)
  110.  
  111.     end,
  112.  
  113. }
  114. chatrooms:add("Switchroom",1,"Offical swithcraft\nChat room!.", colors.white,colors.gray)
  115. chatrooms:add("Test2",156,"Daily message. ", colors.gray,colors.lightGray)
  116. chatrooms:add("Test3",156,"Daily message. ", colors.white,colors.blue)
  117. chatrooms:add("Test4",156,"Daily message. ", colors.orange,colors.red)
  118. chatrooms:draw()
  119.  
  120. while true do
  121.     ev = {os.pullEvent()}
  122.     chatrooms:update(ev)
  123. end
  124. print(invert(colors.gray))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement