Advertisement
Guest User

scriptgl chathud groove

a guest
Apr 7th, 2013
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.65 KB | None | 0 0
  1. //for simplicity, this is here
  2. $pref::ChatHud::Lines = 5;
  3.  
  4. $vChatHud::Width = "550";
  5. $pref::vChatHud::NoDeathMsgs = true;
  6. $vChatHUD::Lines = 0;
  7. $vChatHud::Scroll = 0;
  8.  
  9. // keybinds for scrolling up or down and resizing
  10.  
  11. function vChatHud::addBindsToMenu() after GameBinds::Init
  12. {
  13.     $GameBinds::CurrentMap = "actionMap.sae";
  14.     $GameBinds::CurrentMapHandle = GameBinds::GetActionMap2( "actionMap.sae" );
  15.     GameBinds::addBindCommand( "vChatHUD scroll UP", "vChatHud::OnScroll(Up);", "" );
  16.     GameBinds::addBindCommand( "vChatHUD scroll DOWN", "vChatHud::OnScroll(Down);", "" );
  17.     GameBinds::addBindCommand( "ChatHud Size + 20", "ChatDisplay::addLine();", "" );
  18. }
  19.  
  20.  
  21. //that's where we get out messages, remember the text, the channel, the name (not just the id, in case the player drops)
  22. //also we have that nifty feature where repeated text will increase the count, repeated messages will just be displayed once
  23. //the taunt sound will still be played, so no worries, just less action in the chat
  24. function vChatHud::DecideMessage( %cl, %msg, %type ) after onClientMessage
  25. {
  26.     if(%msg != "" && !String::Starts(%msg,"~"))
  27.     {
  28.         if($pref::vChatHud::NoFlagMsgs)
  29.             if(!%cl && String::FindSubStr(%msg, " flag") != -1 )
  30.                 return;
  31.        
  32.         if($pref::vChatHud::NoDeathMsgs)
  33.             if(KillTrak::Parse(%msg, "check"))
  34.                 return;
  35.        
  36.         //for less buggyness, only filter server messages, channel 0
  37.         if(%type < 2 )
  38.             for(%i = 0; $Filter[%i] != ""; %i++)
  39.             {
  40.                 if(String::findSubStr(%msg, $Filter[%i]) != -1)
  41.                 {
  42.                     return;
  43.                 }
  44.             }
  45.  
  46.         %clName = Client::getName(%cl);
  47.         %now = GetSimTime();
  48.        
  49.         //spam compare lastline, if it's a repeat, increase the count but don't add a line
  50.         if(%now - $vChatHud::Lines[$vChatHUD::Lines, time] < 2.0)
  51.             if(%clName == $vChatHud::Lines[$vChatHUD::Lines, cl])
  52.                 if(%msg == $vChatHud::Lines[$vChatHUD::Lines, msg])
  53.                     if(%type == $vChatHud::Lines[$vChatHUD::Lines, type])
  54.                     {
  55.                         $vChatHud::Lines[$vChatHUD::Lines, count]++;
  56.                         $vChatHud::Lines[$vChatHUD::Lines, time] = %now;
  57.                         return;
  58.                     }
  59.         //spam compare last line by client, if it's a repeat, increase the count but don't add a line
  60.         if(%now - $vChatHud::Lines[$vChatHud::LastMessage[%clName], time] < 2.0)
  61.             if(%msg == $vChatHud::Lines[$vChatHud::LastMessage[%clName], msg])
  62.                 if(%type == $vChatHud::Lines[$vChatHud::LastMessage[%clName], type])
  63.                 {
  64.                     $vChatHud::Lines[$vChatHud::LastMessage[%clName], count]++;
  65.                     return;
  66.                 }
  67.                    
  68.         $vChatHud::Lines++;
  69.         $vChatHud::Lines[$vChatHUD::Lines, cl]  =  %clName;
  70.         $vChatHud::Lines[$vChatHUD::Lines, msg]  =  %msg;
  71.         $vChatHud::Lines[$vChatHUD::Lines, type] = %type;
  72.         $vChatHud::Lines[$vChatHUD::Lines, count] = 1;
  73.         $vChatHud::Lines[$vChatHUD::Lines, time] = %now;
  74.         $vChatHud::LastMessage[%clName] = $vChatHUD::Lines;
  75.        
  76.     }
  77. }
  78.  
  79. function vChatHud::Render()
  80. {
  81.     if($Scriptgl::CurrentGui != "playGui")
  82.         return;
  83.        
  84.     if(!Control::getVisible("ScriptGL::vChatHud"))
  85.         return;
  86.  
  87. $scriptgl::chathud::show = false;
  88. $scriptgl::chathud::showinput = false;
  89.        
  90.     %pos = control::getposition("ScriptGL::vChatHud");
  91.     %x = getWord(%pos,0);
  92.     %y = getWord(%pos,1);
  93.     %dx = $vChatHud::Width;
  94.     %lineheight = 12;
  95.    
  96.     Control::setExtent("ScriptGL::vChatHud", getWord(Control::getExtent("ScriptGL::vChatHud"),0), -5 +($pref::ChatHud::Lines+1) * %lineheight);
  97.    
  98. // Control::SetVisible("chatdisplayhud", false);
  99.     glDisable($GL_TEXTURE_2D);
  100.     glDisable($GL_SCISSOR_TEST);
  101.     glEnable($GL_ALPHA_TEST);
  102.     glBlendFunc($GL_SRC_ALPHA,$GL_ONE_MINUS_SRC_ALPHA);
  103.     glAlphaFunc($GL_GREATER,$GL_ZERO);
  104.     glColor4ub( 0, 0, 0, 187 );
  105. //  glLoadIdentity();
  106.        
  107.     //background
  108.     glBegin($GL_QUADS);
  109.         glVertex2f(%x,%y);         
  110.         glVertex2f(%x + %dx, %y);
  111.         glVertex2f(%x + %dx, %y - 5 + ($pref::ChatHud::Lines+1) * %lineheight);
  112.         glVertex2f(%x, %y - 5 + ($pref::ChatHud::Lines+1) * %lineheight);
  113.     glEnd();
  114.    
  115.     glSetFont( $pref::Groove::Font, 9, 0, 9 );
  116.    
  117.     glColor4ub( 255, 255, 255, 187 );
  118.     // glEnable($GL_TEXTURE_2D);
  119.     // glDrawTexture("lt.png", $GLEX_SCALED, %x, %y - 28, 0.5, -0.5);
  120.     // glDrawTexture("l.png", $GLEX_SCALED, %x, %y - 28, 0.5, 20);
  121.     // glDrawTexture("t.png", $GLEX_SCALED, %x + 6, %y - 28, 44, -0.5);
  122.     // glDrawTexture("lb.png", $GLEX_SCALED, %x, %y - 2, 0.5, -0.5);
  123.     // glDrawTexture("rt.png", $GLEX_SCALED, %x + 50, %y - 28, 0.5, -0.5);
  124.     // glDrawTexture("r.png", $GLEX_SCALED, %x + 50, %y - 28, 0.5, 20);
  125.     // glDrawTexture("rb.png", $GLEX_SCALED, %x + 50, %y - 2, 0.5, -0.5);
  126.     // glDrawTexture("b.png", $GLEX_SCALED, %x + 6, %y - 2, 44, -0.5);
  127.     vChatHud::renderInputField(%x, %y, %dx, %dy);
  128.    
  129.     //the actual text
  130.     glEnable($GL_SCISSOR_TEST);
  131.     glScissor(%x,0,%dx - 10, 1024);
  132.  
  133.    
  134.     //for each we want displayed
  135.     for(%i = 0; %i < $pref::ChatHud::Lines && %i < $vChatHUD::Lines; %i++)
  136.     {
  137.         //we need to display a scrolled version of the chathud
  138.         if($vChatHud::Scroll > 0)
  139.         {
  140.             //the + 1 is because we want 1 overlapping row
  141.             %displayline = $vChatHUD::Lines - ($vChatHud::Scroll*$pref::ChatHud::Lines) - %i + 1;
  142.             %textslot = %i;
  143.             %textpos[x] = %x + 3;
  144.             %textpos[y] = %y + 5 + ($pref::ChatHud::Lines - %textslot - 1)*%lineheight;
  145.         }
  146.         else
  147.         {
  148.             %displayline = $vChatHUD::Lines-%i;
  149.             %textslot = %i;
  150.             %textpos[x] = %x + 3;
  151.             %textpos[y] = %y + 5 + ($pref::ChatHud::Lines - %textslot - 1)*%lineheight;
  152.         }
  153.         //color desicion for that message
  154.         switch($vChatHud::Lines[%displayline, type])
  155.         {
  156.             case 0:
  157.                 glColor4ub( 255, 255, 255, 255 ); break;                   
  158.             case 1:
  159.                 glColor4ub( 255, 0.0, 0.0, 255 ); break;                   
  160.             case 2:
  161.                 glColor4ub( 222, 166, 0.0, 255 ); break;                   
  162.             case 3:
  163.                 glColor4ub( 0.0, 255, 0.0, 255 ); break;                   
  164.             default:
  165.                 glColor4ub( 255, 255, 0.0, 255 ); break;
  166.         }
  167.        
  168.         //get the message, client and count
  169.         %msg = $vChatHud::Lines[%displayline, msg];
  170.         %cl = $vChatHud::Lines[%displayline, cl];
  171.         %count = $vChatHud::Lines[%displayline, count];
  172.        
  173.         //spam repeat reduction, adding the ammount of times
  174.         if(%count > 1)
  175.             %msg = %msg ~ "("~%count~"x)";
  176.        
  177.         //finally draw the string
  178.         if(%cl != "")
  179.             glDrawString( %textpos[x], %textpos[y], %cl ~": "~ %msg );
  180.         else
  181.             glDrawString( %textpos[x], %textpos[y], %msg );
  182.     }
  183. }
  184.  
  185. //render the area where input text is entered
  186. function vChatHud::RenderInputField(%x,%y,%dx,%dy)
  187. {
  188.     glDisable($GL_TEXTURE_2D);
  189.     glDisable($GL_SCISSOR_TEST);
  190.     glEnable($GL_ALPHA_TEST);
  191.     glBlendFunc($GL_SRC_ALPHA,$GL_ONE_MINUS_SRC_ALPHA);
  192.     glAlphaFunc($GL_GREATER,$GL_ZERO);
  193.     glColor4ub( 0, 0, 0, 160 );
  194.    
  195.     //the entry field
  196.     if($ScriptGL::ChatHUD::InputVisible)
  197.     {
  198.         %playgui_height = getword(Control::getExtent("playgui"),1);
  199.        
  200.         %input = "Say: " ~ ScriptGL::ChatHUD::getInput();
  201.         %lines = 1+floor(getWord(glGetStringDimensions(%input),0) / (%dx - 10));
  202.  
  203.         //check if we have space to render the input field below the chat
  204.         if(%y + 10 - 5 + ($pref::ChatHud::Lines+1+%lines) * 13 < %playgui_height)
  205.         {
  206.             glBegin($GL_QUADS);
  207.                 glVertex2f(%x, %y  + ($pref::ChatHud::Lines) * 15);
  208.                 glVertex2f(%x + %dx, %y  + ($pref::ChatHud::Lines) * 15);
  209.                 glVertex2f(%x + %dx, %y + 10 - 5 + ($pref::ChatHud::Lines+%lines) * 15);
  210.                 glVertex2f(%x, %y + 10 - 5 + ($pref::ChatHud::Lines+%lines) * 15);
  211.             glEnd();
  212.            
  213.             if($pref::msgChannel == 0)
  214.                 glColor4f( 1.0, 1.0, 1.0, 1.0 );
  215.             else
  216.                 glColor4f( 0.0, 1.0, 0.0, 1.0 );
  217.            
  218.             if(getWord(glGetStringDimensions(%input),0) > 550) {
  219.             %motherfuck = String::insert( %input, "\n" , 50 );
  220.             glDrawString( %x + 5, %y + 3  + ($pref::ChatHud::Lines) * 15, %motherfuck );
  221.             }
  222.             else
  223.             glDrawString( %x + 5, %y + 3  + ($pref::ChatHud::Lines) * 15, %input );
  224.         }
  225.         else //render above the chat
  226.         {
  227.             glBegin($GL_QUADS);
  228.                 glVertex2f(%x, %y - 10 - (%lines) * 13);
  229.                 glVertex2f(%x + %dx, %y  - 10 - (%lines) * 13);
  230.                 glVertex2f(%x + %dx, %y - 5);
  231.                 glVertex2f(%x, %y - 5 );
  232.             glEnd();
  233.            
  234.             if($pref::msgChannel == 0)
  235.                 glColor4f( 1.0, 1.0, 1.0, 1.0 );
  236.             else
  237.                 glColor4f( 0.0, 1.0, 0.0, 1.0 );
  238.  
  239.             glDrawString( %x + 5, %y + 3 - 10 - (%lines) * 13, %input );
  240.         }
  241.     }
  242. }
  243. //for some reason several things don't go through onClientMessage() on 1.4
  244. Event::Attach( eventClientJoin,         vChatHud::onClientJoin );
  245. Event::Attach( eventClientDrop,         vChatHud::onClientDrop );
  246. Event::Attach( eventClientChangeTeam,   vChatHud::onClientChangeTeam );
  247.  
  248. function vChatHud::onClientJoin(%cl)
  249. {
  250.     onClientMessage(0,Client::GetName(%cl) ~ " connected to the game.", 0);
  251. }
  252. function vChatHud::onClientDrop(%cl)
  253. {
  254.     onClientMessage(0,Client::GetName(%cl) ~ " dropped.", 0);
  255. }
  256. function vChatHud::onClientChangeTeam(%cl, %team)
  257. {
  258.     if(%team >= 0)
  259.         onClientMessage(0,Client::GetName(%cl) ~ " joined team " ~ $Team::Name[ %team ], 0);
  260. }
  261.  
  262. //we create and empty hud via the interface and keep it's size up to date
  263. //while rendering we get the position via control::getPosition();
  264. //that instantly supports a hudmover
  265. function vChatHud::Create()
  266. {
  267.     if ( $vChatHud::Loaded )
  268.         return;
  269.    
  270.     $vChatHud::Loaded = true;
  271.    
  272.     vhud::create( "ScriptGL::vChatHud", "0% 0%", "0% 0%", vChatHud::Render );
  273.     HUD::New("ScriptGL::vChatHud", 0, 25, $vChatHud::Width, 5+($pref::ChatHud::Lines-%i-1)*13);
  274. }
  275. function vChatHud::OnScroll(%direction)
  276. {
  277.     switch(%direction)
  278.     {
  279.         case "Up":
  280.             $vChatHud::Scroll++;
  281.         break;
  282.        
  283.         case "Down":
  284.             if($vChatHud::Scroll > 0)
  285.                 $vChatHud::Scroll--;
  286.         break;
  287.     }
  288. }
  289.  
  290. /*
  291.     Even when a custom Chathud is used, and the the original one is disabled ($scriptgl::chathud::show == "false")
  292.     we want the default one to be shown during Map changes or in the CommandsView ...
  293.     ("CmdObjectivesGui" and "CommandGui")
  294. */
  295.  
  296. $Scriptgl::ChatHud::dorepatch = false;
  297. function Repatch::onGuiOpen(%gui)
  298. {
  299.     if(%gui == "CmdObjectivesGui" || %gui == "CommandGui")
  300.     {
  301.         //dont show?
  302.         if(!$scriptgl::chathud::show)
  303.         {
  304.             //set to show and remember to disable again
  305.             $scriptgl::chathud::show = true;
  306.             $Scriptgl::ChatHud::dorepatch = true;
  307.         }
  308.     }
  309. }
  310. function Repatch::onGuiClose(%gui)
  311. {
  312.     if(%gui == "CmdObjectivesGui" || %gui == "CommandGui")
  313.     {
  314.         //chathud set to show and we set it to unshow earlier (onGuiOpen)
  315.         if($scriptgl::chathud::show && $Scriptgl::ChatHud::dorepatch)
  316.         {
  317.             //hide it again and forget about repatch
  318.             $scriptgl::chathud::show = false;
  319.             $Scriptgl::ChatHud::dorepatch = false;
  320.         }
  321.     }
  322. }
  323.  
  324. //Key for addline was pressed
  325. function ChatDisplay::addLine()
  326. {
  327.     $pref::ChatHud::Lines = $pref::ChatHud::Lines +20;
  328.     if ($pref::ChatHud::Lines > 46) $pref::ChatHud::Lines = 5;
  329.     postAction(nameToId("SimGui::PlayDelegate"), IDACTION_CHAT_DISP_SIZE, $pref::ChatHud::Lines);
  330. }
  331.  
  332. Event::Attach(eventGuiOpen, Repatch::onGuiOpen);
  333. Event::Attach(eventGuiClose, Repatch::onGuiClose);
  334. Event::Attach(eventChatHudScroll, vChatHud::OnScroll);
  335.  
  336. vChatHud::Create();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement