Exemplo n.º 1
0
void ClientModeDODNormal::RadioMessage( const char *pszSoundName, const char *pszSubtitle, const char *pszSender /* = NULL */, int iSenderIndex /* = 0 */ )
{
	C_DODPlayer *pLocalPlayer = C_DODPlayer::GetLocalDODPlayer();
	if ( !pLocalPlayer )
	{
		return;
	}

	int color = ( pLocalPlayer->GetTeamNumber() == TEAM_ALLIES ) ? DOD_COLOR_ALLIES : DOD_COLOR_AXIS;

	// stop the last played radio message
	if ( Q_strlen( m_szLastRadioSound ) > 0 )
	{
		C_DODPlayer *pLocalPlayer = C_DODPlayer::GetLocalDODPlayer();
		if ( pLocalPlayer )
		{
			pLocalPlayer->StopSound( m_szLastRadioSound );
		}
	}

	Q_strncpy( m_szLastRadioSound, pszSoundName, sizeof(m_szLastRadioSound) );

	// Play the radio alert
	char szCmd[128];
	Q_snprintf( szCmd, sizeof(szCmd), "playgamesound %s", pszSoundName );

	engine->ClientCmd( szCmd );

	// Print a message to chat
	wchar_t wszPrint[128];
	char szPrint[128];

	g_pVGuiLocalize->ConstructString( wszPrint, sizeof(wszPrint), g_pVGuiLocalize->Find(pszSubtitle), 0 );
	g_pVGuiLocalize->ConvertUnicodeToANSI( wszPrint, szPrint, sizeof(szPrint) );

	CBaseHudChat *hudChat = (CBaseHudChat *)GET_HUDELEMENT( CHudChat );

	if ( !hudChat )
		return;
	
	wchar_t *pwLoc = g_pVGuiLocalize->Find( "#dod_radio_prefix" );
	char szPrefix[16];
	g_pVGuiLocalize->ConvertUnicodeToANSI( pwLoc, szPrefix, sizeof(szPrefix) );

	pwLoc = g_pVGuiLocalize->Find( pszSubtitle );
	char szSuffix[512];
	g_pVGuiLocalize->ConvertUnicodeToANSI( pwLoc, szSuffix, sizeof(szSuffix) );

	if ( pszSender )
	{
		hudChat->ChatPrintf( iSenderIndex, CHAT_FILTER_NONE, "%c%s %s %c: %s", COLOR_PLAYERNAME, szPrefix, g_PR->GetPlayerName( iSenderIndex ), COLOR_NORMAL, szSuffix );
	}
	else
	{
		hudChat->Printf( CHAT_FILTER_NONE, "%c%s %c: %s", color, szPrefix, COLOR_NORMAL, szSuffix );
	}
}
Exemplo n.º 2
0
void CHudChatFilterButton::DoClick( void )
{
	BaseClass::DoClick();

	CBaseHudChat *pChat = dynamic_cast < CBaseHudChat * > (GetParent() );

	if ( pChat )
	{
		pChat->GetChatInput()->RequestFocus();

		if ( pChat->GetChatFilterPanel() )
		{
			if ( pChat->GetChatFilterPanel()->IsVisible() )
			{
				pChat->GetChatFilterPanel()->SetVisible( false );
			}
			else
			{
				pChat->GetChatFilterPanel()->SetVisible( true );
				pChat->GetChatFilterPanel()->MakePopup();
				pChat->GetChatFilterPanel()->SetMouseInputEnabled( true );
			}
		}
	}
}
Exemplo n.º 3
0
//-----------------------------------------------------------------------------
// Purpose: Inserts colored text into the RichText control at the given alpha
//-----------------------------------------------------------------------------
void CBaseHudChatLine::Colorize( int alpha )
{
	// clear out text
	SetText( "" );

	CBaseHudChat *pChat = dynamic_cast<CBaseHudChat*>(GetParent() );

	if ( pChat && pChat->GetChatHistory() )
	{	
		pChat->GetChatHistory()->InsertString( "\n" );
	}

	wchar_t wText[4096];
	Color color;
	for ( int i=0; i<m_textRanges.Count(); ++i )
	{
		wchar_t * start = m_text + m_textRanges[i].start;
		int len = m_textRanges[i].end - m_textRanges[i].start + 1;
		if ( len > 1 )
		{
			wcsncpy( wText, start, len );
			wText[len-1] = 0;
			color = m_textRanges[i].color;
			color[3] = alpha;
			InsertColorChange( color );
			InsertString( wText );

			CBaseHudChat *pChat = dynamic_cast<CBaseHudChat*>(GetParent() );

			if ( pChat && pChat->GetChatHistory() )
			{	
				pChat->GetChatHistory()->InsertColorChange( color );
				pChat->GetChatHistory()->InsertString( wText );
				pChat->GetChatHistory()->InsertFade( hud_saytext_time.GetFloat(), CHAT_HISTORY_IDLE_FADE_TIME );

				if ( i == m_textRanges.Count()-1 )
				{
					pChat->GetChatHistory()->InsertFade( -1, -1 );
				}
			}

		}
	}

	InvalidateLayout( true );
}
Exemplo n.º 4
0
void ChatEchoPanel::OnThink()
{
	CBaseHudChat *pHUDChat = (CBaseHudChat *)GET_HUDELEMENT( CHudChat );
	if (!pHUDChat)
		return;

	// ASWTODO - Unprotect all the hud chat stuff so this code below works - or figure out a better way of showing the chat during the various frames

	// copying the chat input line
	CBaseHudChatInputLine *pChatInput = pHUDChat->GetChatInput();
	if ( pChatInput)
	{
		vgui::TextEntry *pTextEntry = dynamic_cast<vgui::TextEntry*>(pChatInput->GetInputPanel());
		vgui::Label *pPrompt = pChatInput->GetPrompt();
		if (pTextEntry)
		{
			wchar_t buffer[256];
			pTextEntry->GetText(buffer, sizeof(buffer));
			bool bInputVisible = (pChatInput->IsVisible() && pTextEntry->IsVisible()
						&& pChatInput->GetAlpha() > 200  && pTextEntry->GetAlpha() > 200);
			//if (Q_strcmp(buffer, m_InputBuffer))
			{				
				pTextEntry->GetText(m_InputBuffer, sizeof(m_InputBuffer));
				if (bInputVisible)
				{
					// grab our prompt (or use a default)
					wchar_t prompt[64];
					if (pPrompt)
						pPrompt->GetText(prompt, sizeof(prompt));
					else
					{
						char promptbuffer[8];
						Q_snprintf(promptbuffer, sizeof(promptbuffer), "Say: ");
						g_pVGuiLocalize->ConvertANSIToUnicode(promptbuffer, prompt, sizeof( prompt ));
					}

					// copy x chars around the cursor into our echo
					const int max_copy_chars = 54;
					int line_length = wcslen(m_InputBuffer);
					int cursor_pos = 0;
					if (pTextEntry)
						cursor_pos = pTextEntry->GetTextCursorPos();
					int copy_start = MAX((cursor_pos + 20) - max_copy_chars, 0);
					int copy_end = copy_start + max_copy_chars;
					if (copy_end > line_length)
					{
						int diff = copy_end - line_length;
						copy_start = MAX(copy_start - diff, 0);
						copy_end = MIN(copy_start + max_copy_chars, line_length);
					}

					// copy the prompt over
					int prompt_len = wcslen(prompt);
					int iCopyCursor = 0;
					for (int i=0;i<prompt_len;i++)
					{
						buffer[iCopyCursor] = prompt[i];
						iCopyCursor++;
					}

					buffer[iCopyCursor] = L' ';
					iCopyCursor++;
					bool bAddedCursor = false;

					// check for drawing the cursor at the start
					if (cursor_pos == 0)
					{
						bAddedCursor |= AddCursorToBuffer(buffer, iCopyCursor, (cursor_pos == copy_end));  // if cursor is also at the end, we can flash it						
					}

					// now copy the section of our input line, insert the cursor in the right place
					for (int i=copy_start;i<copy_end;i++)
					{
						if (iCopyCursor >= 253)	// make sure we don't go over out limit for safety (never should though)
							iCopyCursor = 253;
						buffer[iCopyCursor] = m_InputBuffer[i];
						iCopyCursor++;
						if (i == (cursor_pos-1))
						{
							bAddedCursor |= AddCursorToBuffer(buffer, iCopyCursor, (cursor_pos == copy_end));  // if cursor is at the end, we can flash it
						}
					}

					// make sure we've added the cursor
					if (!bAddedCursor)
						AddCursorToBuffer(buffer, iCopyCursor, true);
					
					//if (copy_start == copy_end)
					//{
						//if (fabs(gpGlobals->curtime - integer_time) < 0.25f ||
								//(fabs(gpGlobals->curtime - integer_time) > 0.5f
								//&& fabs(gpGlobals->curtime - integer_time) < 0.75f)) 
						//{
							//buffer[iCopyCursor] = L'|';
							//iCopyCursor++;
						//}
					//}
					buffer[iCopyCursor] = L'\0';
					
					//if 
						//Q_snprintf(buffer, sizeof(buffer), "%s %s", prompt, m_InputBuffer);
					//else
						//Q_snprintf(buffer, sizeof(buffer), "%s %s|", prompt, m_InputBuffer);
					
					m_pChatInputLine->SetText(buffer);
					m_pChatInputLine->SetVisible(true);
				}
				else
				{
					m_pChatInputLine->SetText(m_InputBuffer);					
				}
			}			
			if (m_pChatInputLine->IsVisible() != bInputVisible)
				m_pChatInputLine->SetVisible(bInputVisible);
		}
		else
		{
			if (m_pChatInputLine->IsVisible())
				m_pChatInputLine->SetVisible(false);
		}
	}	
	/*
	// copying the chat history
	if ( pHUDChat->GetChatHistory() )
	{
		CHudChatHistory *pHistory = pHUDChat->GetChatHistory();
						
		//pHistory->GetText(0, m_InputBuffer, sizeof(m_InputBuffer) * sizeof(wchar_t));
		pHistory->GetEndOfText(ASW_CHAT_ECHO_HISTORY_WCHARS-1, m_InputBuffer, ASW_CHAT_ECHO_HISTORY_WCHARS);
		if (m_pChatHistory)
		{
			if (pHistory->IsVisible())
			{
				m_pChatHistory->SetText(m_InputBuffer);
				m_pChatHistory->SetVisible(true);

				m_pChatHistory->SetPaintBorderEnabled( false );
				m_pChatHistory->GotoTextEnd();
				m_pChatHistory->SetMouseInputEnabled( false );
			}
			else
			{
				m_pChatHistory->SetVisible(false);			
			}
		}
	}
	*/
}
Exemplo n.º 5
0
//-----------------------------------------------------------------------------
// Purpose: Parses a line of text for color markup and inserts it via Colorize()
//-----------------------------------------------------------------------------
void CBaseHudChatLine::InsertAndColorizeText( wchar_t *buf, int clientIndex )
{
	if ( m_text )
	{
		delete[] m_text;
		m_text = NULL;
	}
	m_textRanges.RemoveAll();

	m_text = CloneWString( buf );

	CBaseHudChat *pChat = dynamic_cast<CBaseHudChat*>(GetParent() );

	if ( pChat == NULL )
		return;

	wchar_t *txt = m_text;
	int lineLen = wcslen( m_text );
	if ( m_text[0] == COLOR_PLAYERNAME || m_text[0] == COLOR_LOCATION || m_text[0] == COLOR_NORMAL || m_text[0] == COLOR_ACHIEVEMENT )
	{
		while ( txt && *txt )
		{
			TextRange range;

			switch ( *txt )
			{
			case COLOR_PLAYERNAME:
			case COLOR_LOCATION:
			case COLOR_ACHIEVEMENT:
			case COLOR_NORMAL:
				{
					// save this start
					range.start = (txt-m_text) + 1;
					range.color = pChat->GetTextColorForClient( (TextColor)(*txt), clientIndex );
					range.end = lineLen;

					int count = m_textRanges.Count();
					if ( count )
					{
						m_textRanges[count-1].end = range.start - 1;
					}

					m_textRanges.AddToTail( range );
				}
				++txt;
				break;

			default:
				++txt;
			}
		}
	}

	if ( !m_textRanges.Count() && m_iNameLength > 0 && m_text[0] == COLOR_USEOLDCOLORS )
	{
		TextRange range;
		range.start = 0;
		range.end = m_iNameStart;
		range.color = pChat->GetTextColorForClient( COLOR_NORMAL, clientIndex );
		m_textRanges.AddToTail( range );

		range.start = m_iNameStart;
		range.end = m_iNameStart + m_iNameLength;
		range.color = pChat->GetTextColorForClient( COLOR_PLAYERNAME, clientIndex );
		m_textRanges.AddToTail( range );

		range.start = range.end;
		range.end = wcslen( m_text );
		range.color = pChat->GetTextColorForClient( COLOR_NORMAL, clientIndex );
		m_textRanges.AddToTail( range );
	}

	if ( !m_textRanges.Count() )
	{
		TextRange range;
		range.start = 0;
		range.end = wcslen( m_text );
		range.color = pChat->GetTextColorForClient( COLOR_NORMAL, clientIndex );
		m_textRanges.AddToTail( range );
	}

	for ( int i=0; i<m_textRanges.Count(); ++i )
	{
		wchar_t * start = m_text + m_textRanges[i].start;
		if ( *start > 0 && *start < COLOR_MAX )
		{
			m_textRanges[i].start += 1;
		}
	}

	Colorize();
}
Exemplo n.º 6
0
void ClientModeDODNormal::FireGameEvent( IGameEvent * event)
{
	const char *eventname = event->GetName();

	if ( !eventname || !eventname[0] )
		return;

	if ( Q_strcmp( "dod_round_start", eventname ) == 0 )
	{
		// Just tell engine to clear decals
		engine->ClientCmd( "r_cleardecals\n" );

		// recreate all client side physics props
		// check for physenv, because we sometimes crash on changelevel
		// if we get this message before fully connecting
		if ( physenv )
		{
            C_PhysPropClientside::RecreateAll();
		}
	}
	else if( Q_strcmp( "dod_broadcast_audio", eventname ) == 0 )
	{
		CLocalPlayerFilter filter;
		const char *pszSoundName = event->GetString("sound");
		C_BaseEntity::EmitSound( filter, SOUND_FROM_LOCAL_PLAYER, pszSoundName );
	}
	else if ( Q_strcmp( "dod_bomb_planted", eventname ) == 0 )
	{
		int defendingTeam = event->GetInt( "team" );

		C_DODPlayer *pLocalPlayer = C_DODPlayer::GetLocalDODPlayer();

		if ( !pLocalPlayer )
			return;

		const char *pszSound = "";
		const char *pszMessage = "";

		int localTeam = pLocalPlayer->GetTeamNumber();

		const char *pPlanterName = NULL;

		int iPlanterIndex = 0;

		if ( defendingTeam == localTeam )
		{
			// play defend sound
			switch( localTeam )
			{
			case TEAM_ALLIES:
				{
					pszSound = "Voice.US_C4EnemyPlanted";
					pszMessage = "#dod_bomb_us_enemy_planted";
				}
				break;
			case TEAM_AXIS:
				{
					pszSound = "Voice.German_C4EnemyPlanted";
					pszMessage = "#dod_bomb_ger_enemy_planted";
				}
				break;
			default:
				break;
			}
		}
		else
		{
			// play planting sound
			switch( localTeam )
			{
			case TEAM_ALLIES:
				{
					pszSound = "Voice.US_C4TeamPlanted";
					pszMessage = "#dod_bomb_us_team_planted";
				}
				break;
			case TEAM_AXIS:
				{
					pszSound = "Voice.German_C4TeamPlanted";
					pszMessage = "#dod_bomb_ger_team_planted";
				}
				break;
			default:
				break;
			}

			// Only show the planter name if its a team plant, not enemy plant
			iPlanterIndex = engine->GetPlayerForUserID( event->GetInt("userid") );
			pPlanterName = g_PR->GetPlayerName( iPlanterIndex );
		}		

		RadioMessage( pszSound, pszMessage, pPlanterName, iPlanterIndex );
	}
	else if ( Q_strcmp( "dod_bomb_defused", eventname ) == 0 )
	{
		int defusingTeam = event->GetInt( "team" );

		C_DODPlayer *pLocalPlayer = C_DODPlayer::GetLocalDODPlayer();

		if ( !pLocalPlayer )
			return;

		const char *pszSound = "";
		const char *pszMessage = "";

		int localTeam = pLocalPlayer->GetTeamNumber();

		if ( defusingTeam == localTeam )
		{
			// play defused sound
			switch( localTeam )
			{
			case TEAM_ALLIES:
				{
					pszSound = "Voice.US_C4Defused";
					pszMessage = "#dod_bomb_us_defused";
				}
				break;
			case TEAM_AXIS:
				{
					pszSound = "Voice.German_C4Defused";
					pszMessage = "#dod_bomb_ger_defused";
				}
				break;
			default:
				break;
			}

			int iDefuser = engine->GetPlayerForUserID( event->GetInt("userid") );
			const char *pDefuserName = g_PR->GetPlayerName( iDefuser );

			RadioMessage( pszSound, pszMessage, pDefuserName, iDefuser );
		}
	}
	else if ( Q_strcmp( "player_team", eventname ) == 0 )
	{
		C_BasePlayer *pPlayer = USERID2PLAYER( event->GetInt("userid") );

		if ( !pPlayer )
			return;

		bool bDisconnected = event->GetBool("disconnect");

		if ( bDisconnected )
			return;

		int team = event->GetInt( "team" );

		if ( pPlayer->IsLocalPlayer() )
		{
			// that's me
			pPlayer->TeamChange( team );
		}

		CBaseHudChat *hudChat = (CBaseHudChat *)GET_HUDELEMENT( CHudChat );

		if ( !hudChat )
			return;

		char *pTemplate = NULL;

		if ( team == TEAM_ALLIES )
		{
			pTemplate = "#game_joined_allies";
		}
		else if ( team == TEAM_AXIS )
		{
			pTemplate = "#game_joined_axis";
		}
		else
		{
			pTemplate = "#game_joined_spectators";
		} 

		wchar_t szPlayerName[MAX_PLAYER_NAME_LENGTH];
		g_pVGuiLocalize->ConvertANSIToUnicode( pPlayer->GetPlayerName(), szPlayerName, sizeof(szPlayerName) );

		wchar_t wszPrint[128];
		char szPrint[128];

		g_pVGuiLocalize->ConstructString( wszPrint, sizeof(wszPrint), g_pVGuiLocalize->Find(pTemplate), 1, szPlayerName );
		g_pVGuiLocalize->ConvertUnicodeToANSI( wszPrint, szPrint, sizeof(szPrint) );

		hudChat->Printf( CHAT_FILTER_TEAMCHANGE, "%s",szPrint );
	}
	else if ( Q_strcmp( "dod_timer_flash", eventname ) == 0 )
	{
		C_DODPlayer *pLocalPlayer = C_DODPlayer::GetLocalDODPlayer();

		if ( !pLocalPlayer )
			return;

		const char *pszSound = "";
		const char *pszMessage = "";

		int localTeam = pLocalPlayer->GetTeamNumber();

		int iTimeRemaining = event->GetInt( "time_remaining", 0 );

		switch( iTimeRemaining )
		{
		case 60:
			switch( localTeam )
			{
			case TEAM_ALLIES:
				{
					pszSound = "Voice.US_OneMinute";
					pszMessage = "#dod_time_remaining_us_1_min";
				}
				break;
			case TEAM_AXIS:
				{
					pszSound = "Voice.German_OneMinute";
					pszMessage = "#dod_time_remaining_ger_1_min";
				}
				break;
			default:
				break;
			}
			break;
		case 120:
			switch( localTeam )
			{
			case TEAM_ALLIES:
				{
					pszSound = "Voice.US_TwoMinute";
					pszMessage = "#dod_time_remaining_us_2_min";
				}
				break;
			case TEAM_AXIS:
				{
					pszSound = "Voice.German_TwoMinute";
					pszMessage = "#dod_time_remaining_ger_2_min";
				}
				break;
			default:
				break;
			}
			break;
		default:
			break;
		}

		RadioMessage( pszSound, pszMessage );
	}
	else
		BaseClass::FireGameEvent( event );
}