Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local sbc= term.setBackgroundColor
- local stc= term.setTextColor
- local scp= term.setCursorPos
- local w,h= term.getSize()
- local ref = {}
- ref[1] = 2^15
- for i = 1, 15 do
- ref[2^i] = 2^(15-i)
- end
- local function lnwrite(txt)
- local x,y = term.getCursorPos()
- local ln = 0
- for line in txt:gmatch("[^\n]+") do
- scp(x,y+ln)
- write(line)
- ln = ln + 1
- end
- end
- local function invert(col)
- return ref[col]
- end
- local chatrooms = {
- offs = 0,
- rooms = {},
- len = 25,
- lanprotocol = "novachat",
- drawroomcol = function(self,room,bc,tc)
- if(room-self.offs <= 3)then
- local sx = (w/2) + self.len/2
- local sy = 4
- local siy = ( sy*(room-self.offs ) )+(room-self.offs)-1
- --if(eiy > mh)then eiy = eiy - mh end
- paintutils.drawFilledBox((sx) - (self.len-2), siy,(sx/2) + (self.len+9)/2,siy+3,bc)
- scp((sx) - (self.len-3),siy)
- stc(tc)
- write("[" .. room .. "] " .. self.rooms[room].n)
- scp((sx) - (self.len-3),siy+1)
- lnwrite(self.rooms[room].motd)
- scp((sx) - (self.len-3),siy+3)
- write("Server Address: " .. self.rooms[room].ip)
- end
- end,
- draw = function(self)
- term.current().setVisible(false)
- sbc(colors.lightGray)
- term.clear()
- local sx = (w/2) + self.len/2
- local sy = 4
- local mh = h-2
- paintutils.drawBox(((w/2) - self.len/2)+1, 3, ((w/2) + self.len/2)+1,h,colors.black)
- paintutils.drawFilledBox((w/2) - self.len/2, 2, (w/2) + self.len/2,h-1,colors.white)
- paintutils.drawLine((w/2) - self.len/2,2,(w/2) + self.len/2,2,colors.blue)
- stc(colors.white)
- scp((w/2) - self.len/2,2)
- write(" Chat rooms available: " .. #self.rooms)
- if(#self.rooms > 0)then
- for i = 1+self.offs, 3+self.offs do
- local siy = ( sy*(i-self.offs ) )+(i-self.offs)-1
- --if(eiy > mh)then eiy = eiy - mh end
- paintutils.drawFilledBox((sx) - (self.len-2), siy,(sx/2) + (self.len+9)/2,siy+3,self.rooms[i].bc)
- scp((sx) - (self.len-3),siy)
- stc(self.rooms[i].tc)
- write("[" .. i .. "] " .. self.rooms[i].n)
- scp((sx) - (self.len-3),siy+1)
- lnwrite(self.rooms[i].motd)
- scp((sx) - (self.len-3),siy+3)
- write("Server Address: " .. self.rooms[i].ip)
- end
- end
- term.current().setVisible(true)
- end,
- update = function(self,e)
- local b = e[2]
- if(e[1] == "mouse_click")then
- local x,y = e[3], e[4]
- local sx = (w/2) + self.len/2
- local sy = 4
- if(x >= (sx) - (self.len-2) and x <= (sx/2) + self.len+9 and y >= sy and y <= h-2)then
- for i = 1+self.offs, 3+self.offs do
- local sy = ( sy*(i-self.offs ) )+(i-self.offs)-1
- if(y >= sy and y <= sy+3 )then
- -- Clicked on i
- self:drawroomcol(i,invert(self.rooms[i].bc),invert(self.rooms[i].tc))
- sleep(0.2)
- self:drawroomcol(i,self.rooms[i].bc,self.rooms[i].tc)
- end
- end
- end
- end
- if(e[1] == "mouse_scroll")then
- if(b == -1 and self.offs > 0)then
- self.offs = self.offs - 1
- self:draw()
- end
- if(b == 1 and (self.offs+3) < #self.rooms)then
- self.offs = self.offs + 1
- self:draw()
- end
- end
- end,
- add = function(self,name,hostip,mes,textc,backc)
- if(#mes > 22 and not mes:find("\n"))then
- for i = 1, math.floor(#mes/22) do
- mes = mes:sub(1+(22*(i-1)),22*i) .. "\n" .. mes:sub(1+(22*(i)),#mes)
- end
- end
- self.rooms[#self.rooms+1] = {n=name,ip=hostip,motd=mes,tc=textc,bc=backc}
- end,
- remove = function(self,name)
- end,
- }
- chatrooms:add("Switchroom",1,"Offical swithcraft\nChat room!.", colors.white,colors.gray)
- chatrooms:add("Test2",156,"Daily message. ", colors.gray,colors.lightGray)
- chatrooms:add("Test3",156,"Daily message. ", colors.white,colors.blue)
- chatrooms:add("Test4",156,"Daily message. ", colors.orange,colors.red)
- chatrooms:draw()
- while true do
- ev = {os.pullEvent()}
- chatrooms:update(ev)
- end
- print(invert(colors.gray))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement