Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jun 3rd, 2011  |  syntax: None  |  size: 11.90 KB  |  views: 52  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. surface.CreateFont( "ChatFont", 32, 1600, true, false, "GiantChatFont" );
  2. datastream.Hook( "TiramisuAddToChat", function( handler, id, encoded, decoded )
  3.     if !decoded.font then
  4.         decoded.font = CAKE.ChatFont
  5.     end
  6.     if decoded.channel == "IC" then
  7.         CAKE.Chatbox:AddLine(  "<color=135,209,255,255><font=" .. decoded.font .. ">" .. decoded.text .. "</font></color>", decoded.channel )
  8.     else
  9.         CAKE.Chatbox:AddLine(  "<font=" .. decoded.font .. ">" .. decoded.text .. "</font>", decoded.channel )
  10.     end
  11.  
  12.     for i = 0, decoded.text:len() / 255 do
  13.         MsgN(string.sub( decoded.text, i * 255 + 1, i * 255 + 255 ) )
  14.     end
  15. end)
  16.  
  17. --Same as above, it is only being sent as a different datastream for it to print properly on console (IE, so that the </color> part is not printed)
  18. datastream.Hook( "TiramisuAddToOOC", function( handler, id, encoded, decoded )
  19.    
  20.     local color = decoded.color
  21.     local playername = decoded.name
  22.     local text = decoded.text
  23.  
  24.     CAKE.Chatbox:AddLine(  "<font=" .. CAKE.ChatFont .. "><color=white>[OOC]</color><color=" .. tostring( color.r ) .. "," .. tostring( color.g ) .. "," .. tostring( color.b ) .. ">".. playername .. "</color><color=white>:" .. text .. "</color></font>", "OOC" )
  25.  
  26.     text = "[OOC]" .. playername .. ": " .. text
  27.  
  28.     for i = 0, text:len() / 255 do
  29.         MsgN(string.sub( text, i * 255 + 1, i * 255 + 255 ) )
  30.     end
  31. end)
  32.  
  33. local matBlurScreen = Material( "pp/blurscreen" )
  34. local PANEL = {}
  35.  
  36. /*---------------------------------------------------------
  37.  
  38. ---------------------------------------------------------*/
  39. function PANEL:Init()
  40.  
  41.         self:SetFocusTopLevel( true )
  42.  
  43.         self.Channels = {}
  44.         self.Color = CAKE.BaseColor
  45.         self:ShowCloseButton( false )
  46.         self:SetTitle( "" )
  47.        
  48.         self.Height = math.Round(( ScrH() / 3 ) / 10 ) * 10
  49.         self.Width = self.Height * 2
  50.         self.Alpha = 0
  51.         self.Lines = {}
  52.         self:SetSize( self.Width, self.Height )
  53.         self:SetPos( 20, ScrH() - self.Height - 60 )
  54.         self.Open = false
  55.  
  56.         // This turns off the engine drawing
  57.         self:SetPaintBackgroundEnabled( false )
  58.         self:SetPaintBorderEnabled( false )
  59.        
  60.         self.PropertySheet = vgui.Create( "DPropertySheet", self )
  61.         self.PropertySheet:SetSize( self.Width - 5 , self.Height - 30 )
  62.         self.PropertySheet:SetPos( 3, 3 )
  63.         self.PropertySheet:SetShowIcons( false )
  64.         self.PropertySheet.Paint = function()
  65.         end
  66.         self:AddChannel( "All", "All Messages" )
  67.         self:AddChannel( "IC", "In Character" )
  68.         self:AddChannel( "OOC", "Out Of Character" )
  69.  
  70.         self.TextEntry = vgui.Create( "DTextEntry", self )
  71.         self.TextEntry:SetSize( self.Width - 13, 25 )
  72.         self.TextEntry:SetPos( 5, self.Height - 30 )
  73.         self.TextEntry.Paint = function()
  74.            
  75.             if self.Open then
  76.                 draw.RoundedBox( 2, 2, 2, self.TextEntry:GetWide(), self.TextEntry:GetTall(), Color( 50, 50, 50, self.Alpha ) )
  77.                 self.TextEntry:DrawTextEntryText( Color( 200, 200, 200, 240 ), self.TextEntry.m_colHighlight, self.TextEntry.m_colCursor )
  78.             end
  79.  
  80.         end
  81.         self.TextEntry.OnEnter = function()
  82.             if self.TextEntry:GetValue() != "" then
  83.                 if ( string.sub(self.TextEntry:GetValue(), 1, 1 ) == "@" ) then
  84.                     local exp = string.Explode( " ", self.TextEntry:GetValue()) or {}
  85.                     local command = exp[1] or self.TextEntry:GetValue()
  86.                     table.remove( exp, 1 )
  87.                     RunConsoleCommand(string.sub( command, 2, string.len(command) ), unpack(exp) )
  88.                 elseif ( string.sub( self.TextEntry:GetValue(), 1, 1 ) == "!" ) then
  89.                     local exp = string.Explode( " ", self.TextEntry:GetValue()) or {}
  90.                     local command = exp[1] or self.TextEntry:GetValue()
  91.                     table.remove( exp, 1 )
  92.                     RunConsoleCommand("rp_" .. string.sub( command, 2, string.len(command) ), unpack(exp) )
  93.                 else
  94.                     if self.TextEntry:GetValue():len() > 600 then
  95.                         datastream.StreamToServer( "TiramisuChatHandling", { ["text"] = string.sub( string.Replace(self.TextEntry:GetValue(), "\"", "'"), 1, 600 ) } )
  96.                     else
  97.                         datastream.StreamToServer( "TiramisuChatHandling", { ["text"] = string.Replace(self.TextEntry:GetValue(), "\"", "'") } )
  98.                     end
  99.                 end
  100.                 self.TextEntry:Clear()
  101.                 self:Close()
  102.             else
  103.                 self.TextEntry:Clear()
  104.                 self:Close()
  105.             end
  106.         end
  107.         self.TextEntry.Clear = function()
  108.             self.TextEntry:SetValue("")
  109.             self.TextEntry:SetCaretPos( 0 )
  110.         end
  111.  
  112. end
  113.  
  114. --Adds a tab to the chatbox. Can be done while the chatbox is open.
  115. function PANEL:AddChannel( name, description )
  116.  
  117.     if !self.Channels[ name ] then
  118.         local panel = vgui.Create( "DPanelList" )
  119.         panel:EnableVerticalScrollbar(true)
  120.         panel.Paint = function()
  121.             draw.RoundedBox( 4, 0, 0, panel:GetWide(), panel:GetTall(), Color( 50, 50, 50, self.Alpha ) )
  122.             if panel.VBar and panel.VBar.Enabled then
  123.                 panel.VBar:SetVisible( self.Open )
  124.             end
  125.         end
  126.         self.Channels[ name ] = panel
  127.         self.PropertySheet:AddSheet( name, panel, "", false, false, description or name )
  128.         self.PropertySheet:InvalidateLayout( true, true )
  129.         for _,item in pairs( self.PropertySheet.Items ) do
  130.             item.Tab.Paint = function()
  131.                 if ( item.Tab:GetPropertySheet():GetActiveTab() == item.Tab ) then
  132.                     draw.RoundedBox( 2, 0, 0, item.Tab:GetWide() - 8, item.Tab:GetTall(), Color( 40, 40, 40, self.Alpha ) )
  133.                     item.Tab:SetTextColor( Color( 170, 170, 170, self.Alpha ) )
  134.                 else
  135.                     draw.RoundedBox( 2, 1, 1, item.Tab:GetWide() - 9, item.Tab:GetTall() - 1, Color( 90, 90, 90, self.Alpha ))
  136.                     item.Tab:SetTextColor( Color( 170, 170, 170, self.Alpha ) )
  137.                 end
  138.             end
  139.                     if ( item.Tab.Image ) then
  140.                         item.Tab.Image:SetVisible( false )
  141.                         end
  142.         end
  143.     end
  144.  
  145. end
  146.  
  147. --Adds a line to a particular channel. If no channel is specified it simply becomes global.
  148. function PANEL:AddLine( text, channel )
  149.  
  150.     local label = MarkupLabel( text, self.Width - 25 )
  151.     local number = #self.Lines + 1
  152.     self.Lines[ number ] = {}
  153.     self.Lines[ number ][ "panel" ] = label
  154.     self.Lines[ number ][ "timestamp" ] = CurTime()
  155.     self.Channels[ "All" ]:AddItem( label )
  156.  
  157.     if channel then
  158.         self:AddChannel( channel )
  159.         label = MarkupLabel( text, self.Width - 25 )
  160.         local number = #self.Lines + 1
  161.         self.Lines[ number ] = {}
  162.         self.Lines[ number ][ "panel" ] = label
  163.         self.Lines[ number ][ "timestamp" ] = CurTime()
  164.         self.Channels[ channel ]:AddItem( label )
  165.     end
  166.  
  167.     timer.Simple( 0.1, function()
  168.         if channel then
  169.                 if self.Channels[ channel ] and self.Channels[ channel ].VBar then
  170.                 self.Channels[ channel ].VBar:SetScroll( 999999 )
  171.             end
  172.         end
  173.         if self.Channels[ "All" ].VBar then
  174.             self.Channels[ "All" ].VBar:SetScroll( 999999 )
  175.         end
  176.     end)
  177. end
  178.  
  179.  
  180. /*---------------------------------------------------------
  181.  
  182. ---------------------------------------------------------*/
  183. --Doesn't actually close the chatbox, simply hides it.
  184. function PANEL:Close()
  185.  
  186.     self.Open = false
  187.     self:SetKeyboardInputEnabled(false)
  188.     self:SetMouseInputEnabled(false)
  189.     gui.EnableScreenClicker( false )
  190.     LocalPlayer( ):ConCommand( "rp_closedchat" )
  191.  
  192. end
  193.  
  194. /*---------------------------------------------------------
  195.  
  196. ---------------------------------------------------------*/
  197. function PANEL:OpenChat()
  198.  
  199.     if !self.Open then
  200.         self.Open = true
  201.         self:SetKeyboardInputEnabled(true)
  202.         self:SetMouseInputEnabled(true)
  203.         self:MakePopup()
  204.         self.TextEntry:RequestFocus()
  205.         gui.EnableScreenClicker( true )
  206.         LocalPlayer( ):ConCommand( "rp_openedchat" )
  207.     end
  208. end
  209.  
  210.  
  211. /*---------------------------------------------------------
  212.  
  213. ---------------------------------------------------------*/
  214. --Calculations to determine which lines fade out.
  215. local linetbl = {}
  216. function PANEL:Think()
  217.     if self.Lines and !self.Open then
  218.         for k, v in pairs( self.Lines ) do
  219.             if v[ "timestamp" ] + 10 < CurTime() then
  220.                 v[ "panel" ]:SetAlpha( Lerp( 0.05, v[ "panel" ]:GetAlpha() , 0 ) )
  221.             end
  222.         end
  223.     else
  224.         for k, v in pairs( self.Lines ) do
  225.             v[ "panel" ]:SetAlpha( 255 )
  226.         end
  227.     end
  228.     if self.Open and input.IsKeyDown(KEY_ESCAPE) then
  229.         self:Close()
  230.     end
  231. end
  232.  
  233. local x, y
  234. local lastpos
  235. local color
  236.  
  237. --Handles the whole drawing part.
  238. function PANEL:Paint()
  239.  
  240.     if !self.Alpha then
  241.         self.Alpha = 0
  242.     else
  243.         if !self.Open then
  244.             self.Alpha = Lerp( 0.2, self.Alpha, 0 )
  245.         else
  246.              self.Alpha = Lerp( 0.2, self.Alpha, 150 )
  247.         end
  248.     end
  249.  
  250.     x, y = self:ScreenToLocal( 0, 0 )
  251.     lastpos = 0
  252.     color = self.Color or CAKE.BaseColor or Color( 100, 100, 115, 150 )
  253.        
  254.     // Background
  255.     surface.SetMaterial( matBlurScreen )
  256.     surface.SetDrawColor( 255, 255, 255, self.Alpha or 0 )
  257.        
  258.     matBlurScreen:SetMaterialFloat( "$blur", self.Alpha or 0 / 50 )
  259.     render.UpdateScreenEffectTexture()
  260.        
  261.     surface.DrawTexturedRect( x, y, ScrW(), ScrH() )
  262.  
  263.     if ( self.m_bBackgroundBlur ) then
  264.         Derma_DrawBackgroundBlur( self, self.m_fCreateTime )
  265.     end
  266.        
  267.     surface.SetDrawColor( color.r, color.g, color.b, self.Alpha or 0 )
  268.     surface.DrawRect( x, y, ScrW(), ScrH() )
  269.  
  270.     surface.SetDrawColor( 50, 50, 50, math.Clamp( self.Alpha or 0 - 50, 0, 255 ) )
  271.  
  272.     for i = 1, self:GetWide() / 5 * 2  do
  273.         surface.DrawLine( ( i * 5 ), 0, 0, ( i * 5 ) )
  274.     end
  275.  
  276.     // Pretentious line bullshit :P
  277.     x = math.floor( self:GetWide() / 5 )
  278.     y = math.floor( self:GetTall() / 5 )
  279.  
  280.     // and some gradient shit for additional overkill
  281.  
  282.     for i = 1, ( y + 5 ) do
  283.         surface.SetDrawColor( math.Clamp( color.r - 50, 0, 255 ), math.Clamp( color.g - 50,0, 255 ), math.Clamp( color.b - 50, 0, 255 ), Lerp( i / ( ( y + 5 ) ), 0 , self.Alpha or 0 ) )
  284.         surface.DrawRect( 0, ( i * 5 ) , self:GetWide(), 5 )
  285.     end
  286.  
  287.     // Border
  288.     surface.SetDrawColor( math.Clamp( color.r - 50, 0, 255 ), math.Clamp( color.g - 50,0, 255 ), math.Clamp( color.b - 50, 0, 255 ), self.Alpha or 0 )
  289.     surface.DrawOutlinedRect( 0, 0, self:GetWide(), self:GetTall() )
  290.        
  291.     return true
  292. end
  293.  
  294. function PANEL:PerformLayout()
  295. end
  296.  
  297. function PANEL:IsActive()
  298.  
  299.         if ( self:HasFocus() ) then return true end
  300.         if ( vgui.FocusedHasParent( self ) ) then return true end
  301.        
  302.         return false
  303.  
  304. end
  305. /*---------------------------------------------------------
  306.  
  307. ---------------------------------------------------------*/
  308. function PANEL:OnMousePressed()
  309.  
  310.     self:OpenChat()
  311.  
  312. end
  313.  
  314. vgui.Register( "TiramisuChatBox", PANEL, "DFrame")
  315.  
  316. function chat.AddText(...) --Overriding default chat text entry
  317. end
  318.  
  319.  
  320. hook.Add("PlayerBindPress", "TiramisuChatOverride", function(ply, bind, pressed)
  321.     if string.find( bind, "messagemode" ) or string.find( bind, "messagemode2" ) then
  322.         CAKE.Chatbox:OpenChat()
  323.         return true
  324.     end
  325. end)
  326.  
  327. usermessage.Hook( "TiramisuInitChat", function( um )
  328.     gamemode.Call( "StartChat" )
  329.     gamemode.Call( "FinishChat" )
  330.     if !CAKE.ChatBox then
  331.         CAKE.Chatbox = vgui.Create( "TiramisuChatBox" )
  332.         CAKE.Chatbox:Init()
  333.     end
  334. end)
clone this paste RAW Paste Data