add source-sdk-2013

This commit is contained in:
nillerusr
2022-03-01 23:00:42 +03:00
parent 88b8830e8b
commit edc8d6c584
3288 changed files with 3731 additions and 1062455 deletions
+190 -298
View File
@@ -4,8 +4,6 @@
#include "cbase.h"
#include "inputsystem/iinputsystem.h"
#include "input.h"
#include "hud.h"
#include "hudelement.h"
#include "hud_macros.h"
@@ -61,24 +59,25 @@ public:
{
g_pVGuiLocalize->ConvertANSIToUnicode( pPlayerName, m_wszPlayerName, sizeof(m_wszPlayerName) );
SetLifetime( 7 );
SetText( "#GameUI_Vote_Notification_Text" );
SetText( "#Vote_notification_text" );
AddStringToken( "initiator", m_wszPlayerName );
}
virtual EType NotificationType() { return eType_AcceptDecline; }
virtual bool CanBeTriggered()
{
return true;
}
virtual void Trigger()
{
CTFGenericConfirmDialog *pDialog = ShowConfirmDialog( "#GameUI_Vote_Notification_Title",
"#GameUI_Vote_Notification_Text",
"#GameUI_Vote_Notification_View",
"#cancel", &ConfirmShowVoteSetup );
CTFGenericConfirmDialog *pDialog = ShowConfirmDialog( "#Vote_notification_title", "#Vote_notification_text", "#Vote_notification_view", "#cancel", &ConfirmShowVoteSetup );
pDialog->SetContext( this );
pDialog->AddStringToken( "initiator", m_wszPlayerName );
// so we aren't deleted
SetIsInUse( true );
}
virtual bool CanBeAcceptedOrDeclined()
{
return true;
}
virtual void Accept()
{
ConfirmShowVoteSetup( true, this );
@@ -96,7 +95,7 @@ public:
CHudVote *pHudVote = GET_HUDELEMENT( CHudVote );
if ( pHudVote )
{
pHudVote->ShowVoteUI( true );
pHudVote->ShowVoteUI();
}
}
pNotification->SetIsInUse( false );
@@ -291,76 +290,6 @@ void CVoteSetupDialog::ApplySettings(KeyValues *inResourceData)
m_HeaderFGColor = pScheme->GetColor( pszColor, Color( 255, 255, 255, 255 ) );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CVoteSetupDialog::InitializeIssueList( void )
{
m_pComboBox->RemoveAll();
m_pComboBox->SetVisible( false );
SetDialogVariable( "combo_label", "" );
for ( int index = 0; index < m_VoteIssues.Count(); index++ )
{
if ( !m_VoteIssues[index].szName || !m_VoteIssues[index].szName[0] )
continue;
bool bActive = m_VoteIssues[index].bIsActive;
char szIssueLocalized[k_MAX_VOTE_NAME_LENGTH] = { 0 };
g_pVGuiLocalize->ConvertUnicodeToANSI( g_pVGuiLocalize->Find( m_VoteIssues[index].szNameString ), szIssueLocalized, sizeof( szIssueLocalized ) );
if ( !bActive )
{
char szDisabled[k_MAX_VOTE_NAME_LENGTH] = { 0 };
g_pVGuiLocalize->ConvertUnicodeToANSI( g_pVGuiLocalize->Find( "#GameUI_Vote_Disabled" ), szDisabled, sizeof( szDisabled ) );
V_strcat_safe( szIssueLocalized, szDisabled );
}
KeyValues *pKeyValues = new KeyValues( "Issue" );
pKeyValues->SetString( "Issue", szIssueLocalized );
pKeyValues->SetString( "IssueRaw", m_VoteIssues[index].szName );
pKeyValues->SetBool( "Active", m_VoteIssues[index].bIsActive );
int iId = m_pVoteSetupList->AddItem( 0, pKeyValues );
pKeyValues->deleteThis();
// Setup the list entry style
if ( m_hIssueFont != INVALID_FONT )
{
m_pVoteSetupList->SetItemFont( iId, m_hIssueFont );
Color colFG = bActive ? m_IssueFGColor : m_IssueFGColorDisabled;
m_pVoteSetupList->SetItemFgColor( iId, colFG );
}
}
// Select the first item by default
if ( m_pVoteSetupList->GetItemCount() > 0 )
{
m_pVoteSetupList->SetSelectedItem( 0 );
}
else
{
// No active issues
char szIssueLocalized[k_MAX_VOTE_NAME_LENGTH] = { 0 };
g_pVGuiLocalize->ConvertUnicodeToANSI( g_pVGuiLocalize->Find( "#GameUI_Vote_System_Disabled" ), szIssueLocalized, sizeof( szIssueLocalized ) );
KeyValues *pKeyValues = new KeyValues( "Issue" );
pKeyValues->SetString( "Issue", szIssueLocalized );
pKeyValues->SetString( "IssueRaw", "Disabled" );
pKeyValues->SetBool( "Active", false );
int iId = m_pVoteSetupList->AddItem( 0, pKeyValues );
pKeyValues->deleteThis();
if ( m_hIssueFont != INVALID_FONT )
{
m_pVoteSetupList->SetItemFont( iId, m_hIssueFont );
m_pVoteSetupList->SetItemFgColor( iId, m_IssueFGColor );
}
}
UpdateCurrentMap();
}
//-----------------------------------------------------------------------------
// Purpose: Keep track of the current map
//-----------------------------------------------------------------------------
@@ -373,7 +302,7 @@ void CVoteSetupDialog::UpdateCurrentMap( void )
//-----------------------------------------------------------------------------
// Purpose: Feeds Issues from the server to this Dialog
//-----------------------------------------------------------------------------
void CVoteSetupDialog::AddVoteIssues( CUtlVector< VoteIssue_t > &m_VoteSetupIssues )
void CVoteSetupDialog::AddVoteIssues( CUtlStringList &m_VoteSetupIssues )
{
m_VoteIssues.RemoveAll();
for ( int index = 0; index < m_VoteSetupIssues.Count(); index++ )
@@ -456,7 +385,36 @@ void CVoteSetupDialog::Activate()
m_pVoteParameterList->SetSectionFgColor( 1, m_HeaderFGColor );
}
InitializeIssueList();
// Populate the Issue list
for ( int index = 0; index < m_VoteIssues.Count(); index++ )
{
const char *pszIssue = m_VoteIssues[index];
if ( !pszIssue || !pszIssue[0] )
continue;
KeyValues *pKeyValues = new KeyValues( "Issue" );
pKeyValues->SetString( "Issue", pszIssue );
int iId = m_pVoteSetupList->AddItem( 0, pKeyValues );
pKeyValues->deleteThis();
// Setup the list entry style
if ( m_hIssueFont != INVALID_FONT )
{
m_pVoteSetupList->SetItemFont( iId, m_hIssueFont );
bool bDisabled = V_stristr( pszIssue, "(Disabled on Server)" ); // driller: need to localize
Color colFG = bDisabled ? m_IssueFGColorDisabled : m_IssueFGColor;
m_pVoteSetupList->SetItemFgColor( iId, colFG );
}
}
// Select the first item by default
if ( m_pVoteSetupList->GetItemCount() > 0 )
{
m_pVoteSetupList->SetSelectedItem( 0 );
}
UpdateCurrentMap();
}
//-----------------------------------------------------------------------------
@@ -474,15 +432,15 @@ void CVoteSetupDialog::OnClose()
void CVoteSetupDialog::OnCommand(const char *command)
{
// We should have enough data to issue a CallVote command
if ( !V_stricmp( command, "CallVote" ) )
if ( V_stricmp( command, "CallVote" ) == 0 )
{
int iSelectedItem = m_pVoteSetupList->GetSelectedItem();
if ( iSelectedItem >= 0 )
{
char szVoteCommand[k_MAX_VOTE_NAME_LENGTH];
char szVoteCommand[128];
KeyValues *pIssueKeyValues = m_pVoteSetupList->GetItemData( iSelectedItem );
const char *szIssueRaw = pIssueKeyValues->GetString( "IssueRaw" );
if ( !V_stricmp( "ChangeLevel", szIssueRaw ) || !V_stricmp( "NextLevel", szIssueRaw ) )
const char *szIssue = pIssueKeyValues->GetString( "Issue" );
if ( V_stricmp( "changelevel", szIssue ) == 0 || V_stricmp( "nextlevel", szIssue ) == 0 )
{
int nSelectedParam = m_pVoteParameterList->GetSelectedItem();
if ( nSelectedParam >= 0 )
@@ -496,13 +454,13 @@ void CVoteSetupDialog::OnCommand(const char *command)
{
// Which Map?
const char *szMapName = pParameterKeyValues->GetString( "Name" );
Q_snprintf( szVoteCommand, sizeof( szVoteCommand ), "callvote %s %s\n;", szIssueRaw, szMapName );
Q_snprintf( szVoteCommand, sizeof( szVoteCommand ), "callvote %s %s\n;", szIssue, szMapName );
engine->ClientCmd( szVoteCommand );
}
}
}
}
else if ( !V_stricmp( "Kick", szIssueRaw ) )
else if ( V_stricmp( "kick", szIssue ) == 0 )
{
// Get selected Player
int iSelectedParam = m_pVoteParameterList->GetSelectedItem();
@@ -518,7 +476,7 @@ void CVoteSetupDialog::OnCommand(const char *command)
if ( engine->GetPlayerInfo( playerIndex, &playerInfo ) )
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex( playerIndex );
Q_snprintf( szVoteCommand, sizeof( szVoteCommand ), "callvote %s \"%d %s\"\n;", szIssueRaw, pPlayer->GetUserID(), pReasonString );
Q_snprintf( szVoteCommand, sizeof( szVoteCommand ), "callvote %s \"%d %s\"\n;", szIssue, pPlayer->GetUserID(), pReasonString );
engine->ClientCmd( szVoteCommand );
#ifdef TF_CLIENT_DLL
CSteamID steamID;
@@ -537,7 +495,7 @@ void CVoteSetupDialog::OnCommand(const char *command)
}
}
#ifdef TF_CLIENT_DLL
else if ( !V_stricmp( "ChangeMission", szIssueRaw ) )
else if ( V_stricmp( "ChangeMission", szIssue ) == 0 )
{
int nSelectedParam = m_pVoteParameterList->GetSelectedItem();
if ( nSelectedParam >= 0 )
@@ -551,7 +509,7 @@ void CVoteSetupDialog::OnCommand(const char *command)
{
// Which Pop File?
const char *szPopFile = pParameterKeyValues->GetString( "Name" );
Q_snprintf( szVoteCommand, sizeof( szVoteCommand ), "callvote %s %s\n;", szIssueRaw, szPopFile );
Q_snprintf( szVoteCommand, sizeof( szVoteCommand ), "callvote %s %s\n;", szIssue, szPopFile );
engine->ClientCmd( szVoteCommand );
}
}
@@ -561,7 +519,7 @@ void CVoteSetupDialog::OnCommand(const char *command)
else
{
// Non-parameter vote. i.e. callvote scrambleteams
Q_snprintf( szVoteCommand, sizeof(szVoteCommand), "callvote %s\n;", szIssueRaw );
Q_snprintf( szVoteCommand, sizeof(szVoteCommand), "callvote %s\n;", szIssue );
engine->ClientCmd( szVoteCommand );
}
@@ -593,23 +551,22 @@ void CVoteSetupDialog::OnItemSelected( vgui::Panel *panel )
if ( !pIssueKeyValues )
return;
CHudVote *pHudVote = GET_HUDELEMENT( CHudVote );
if ( !pHudVote )
return;
// We're rebuilding, so clear state
m_bVoteButtonEnabled = false;
m_pVoteParameterList->ClearSelection();
m_pVoteParameterList->RemoveAll();
const char *pszIssueRaw = pIssueKeyValues->GetString( "IssueRaw" );
bool bActive = pIssueKeyValues->GetBool( "Active" );
if ( !pHudVote->IsVoteSystemActive() || !bActive )
const char *szName = pIssueKeyValues->GetString( "Issue" );
if ( V_stricmp( "Voting disabled on this Server", szName ) == 0 )
{
m_bVoteButtonEnabled = false;
}
else if ( V_stristr( szName, "(Disabled on Server)" ) ) // driller: need to localize
{
m_bVoteButtonEnabled = false;
}
// CHANGELEVEL / NEXTLEVEL
else if ( !V_stricmp( "ChangeLevel", pszIssueRaw ) || !V_stricmp( "NextLevel", pszIssueRaw ) )
else if ( V_stricmp( "changelevel", szName ) == 0 || V_stricmp( "nextlevel", szName ) == 0 )
{
// Feed the mapcycle to the parameters list
for ( int index = 0; index < m_VoteIssuesMapCycle.Count(); index++ )
@@ -641,7 +598,7 @@ void CVoteSetupDialog::OnItemSelected( vgui::Panel *panel )
}
}
// KICK
else if ( !V_stricmp( "Kick", pszIssueRaw ) )
else if ( V_stricmp( "kick", szName ) == 0 )
{
// Feed the player list to the parameters list
int nMaxClients = engine->GetMaxClients();
@@ -699,7 +656,7 @@ void CVoteSetupDialog::OnItemSelected( vgui::Panel *panel )
}
#ifdef TF_CLIENT_DLL
// CHANGE POP FILE
else if ( !V_stricmp( "ChangeMission", pszIssueRaw ) )
else if ( V_stricmp( "ChangeMission", szName ) == 0 )
{
// Feed the popfiles to the parameters list
for ( int index = 0; index < m_VoteIssuesPopFiles.Count(); index++ )
@@ -785,8 +742,8 @@ void CVoteSetupDialog::RefreshIssueParameters()
if ( iSelectedItem >= 0 )
{
KeyValues *pIssueKeyValues = m_pVoteSetupList->GetItemData( iSelectedItem );
const char *pszIssueRaw = pIssueKeyValues->GetString( "IssueRaw" );
if ( !V_stricmp( "Kick", pszIssueRaw ) )
const char *szName = pIssueKeyValues->GetString( "Issue" );
if ( V_stricmp( "kick", szName ) == 0 )
{
if ( m_pVoteParameterList->GetItemCount() > 0 )
{
@@ -829,10 +786,10 @@ void CVoteSetupDialog::RefreshIssueParameters()
m_pVoteParameterList->InvalidateItem( index );
}
m_pVoteParameterList->SetImageList( m_pImageList, false );
}
}
m_pVoteParameterList->SetImageList( m_pImageList, false );
}
}
@@ -842,9 +799,9 @@ void CVoteSetupDialog::RefreshIssueParameters()
void CVoteSetupDialog::ResetData()
{
m_bVoteButtonEnabled = false;
m_pVoteSetupList->RemoveAll();
m_pVoteParameterList->RemoveAll();
m_pComboBox->RemoveAll();
m_pVoteSetupList->DeleteAllItems();
m_pVoteParameterList->DeleteAllItems();
m_pComboBox->DeleteAllItems();
}
//-----------------------------------------------------------------------------
@@ -876,8 +833,6 @@ CHudVote::CHudVote( const char *pElementName ) : CHudElement( pElementName ), Ba
m_nVoteOptionCount[index] = 0;
}
m_pVoteActive = new EditablePanel( this, "VoteActive" );
m_pVoteActiveIssueLabel = new vgui::Label( m_pVoteActive, "Issue", "" );
m_pVoteActiveTargetAvatar = new CAvatarImagePanel( m_pVoteActive, "TargetAvatarImage" );
m_voteBar = new VoteBarPanel( m_pVoteActive, "VoteBar" );
m_pVoteFailed = new EditablePanel( this, "VoteFailed" );
m_pVotePassed = new EditablePanel( this, "VotePassed" );
@@ -897,8 +852,6 @@ void CHudVote::ApplySchemeSettings( vgui::IScheme *pScheme )
SetProportional( true );
LoadControlSettings( "Resource/UI/VoteHud.res" );
m_pVoteActiveIssueLabel->GetPos( m_nVoteActiveIssueLabelX, m_nVoteActiveIssueLabelY );
}
//-----------------------------------------------------------------------------
@@ -910,7 +863,7 @@ void CHudVote::Init( void )
ListenForGameEvent( "vote_options" );
ListenForGameEvent( "vote_cast" );
m_bVotingActive = false;
SetVoteActive( false );
m_flVoteResultCycleTime = -1;
m_flHideTime = -1;
m_bIsYesNoVote = true;
@@ -918,8 +871,6 @@ void CHudVote::Init( void )
m_nVoteChoicesCount = 2; // Yes/No is the default
m_bShowVoteActivePanel = false;
m_iVoteCallerIdx = -1;
m_bVoteSystemActive = false;
m_nVoteTeamIndex = 0;
HOOK_HUD_MESSAGE( CHudVote, CallVoteFailed );
HOOK_HUD_MESSAGE( CHudVote, VoteStart );
@@ -933,12 +884,10 @@ void CHudVote::Init( void )
//-----------------------------------------------------------------------------
void CHudVote::LevelInit( void )
{
m_bVotingActive = false;
SetVoteActive( false );
m_flVoteResultCycleTime = -1;
m_flHideTime = -1;
m_flPostVotedHideTime = -1;
m_bPlayerVoted = false;
m_bShowVoteActivePanel = false;
}
//-----------------------------------------------------------------------------
@@ -952,7 +901,7 @@ int CHudVote::KeyInput( int down, ButtonCode_t keynum, const char *pszCurrentBin
if ( !down )
return 1;
if ( !m_bVotingActive )
if ( !m_bVoteActive )
return 1;
if ( m_bPlayerVoted )
@@ -1030,19 +979,15 @@ void CHudVote::MsgFunc_CallVoteFailed( bf_read &msg )
m_pCallVoteFailed->SetVisible( true );
m_pVoteSetupDialog->SetVisible( false );
m_flHideTime = gpGlobals->curtime + 4.f;
m_flHideTime = gpGlobals->curtime + 4.0;
char szTime[k_MAX_VOTE_NAME_LENGTH];
wchar_t wszTime[k_MAX_VOTE_NAME_LENGTH];
bool bMinutes = ( nTime > 65 );
if ( bMinutes )
{
nTime /= 60;
}
char szTime[256];
wchar_t wszTime[256];
Q_snprintf( szTime, sizeof ( szTime), "%i", nTime );
g_pVGuiLocalize->ConvertANSIToUnicode( szTime, wszTime, sizeof( wszTime ) );
wchar_t wszHeaderString[k_MAX_VOTE_NAME_LENGTH];
wchar_t wszHeaderString[512];
wchar_t *pwszHeaderString;
switch( nReason )
{
@@ -1055,12 +1000,10 @@ void CHudVote::MsgFunc_CallVoteFailed( bf_read &msg )
break;
case VOTE_FAILED_RATE_EXCEEDED:
{
const char *pszTimeString = ( bMinutes ) ? ( ( nTime < 2 ) ? "#GameUI_vote_failed_vote_spam_min" : "#GameUI_vote_failed_vote_spam_mins" ) : "#GameUI_vote_failed_vote_spam";
g_pVGuiLocalize->ConstructString_safe( wszHeaderString, g_pVGuiLocalize->Find( pszTimeString ), 1, wszTime );
m_pCallVoteFailed->SetDialogVariable( "FailedReason", wszHeaderString );
g_pVGuiLocalize->ConstructString( wszHeaderString, sizeof(wszHeaderString), g_pVGuiLocalize->Find( "#GameUI_vote_failed_vote_spam" ), 1, wszTime );
pwszHeaderString = wszHeaderString;
m_pCallVoteFailed->SetDialogVariable( "FailedReason", pwszHeaderString );
break;
}
case VOTE_FAILED_ISSUE_DISABLED:
m_pCallVoteFailed->SetControlString( "FailedReason", "#GameUI_vote_failed_disabled_issue" );
@@ -1078,13 +1021,11 @@ void CHudVote::MsgFunc_CallVoteFailed( bf_read &msg )
m_pCallVoteFailed->SetControlString( "FailedReason", "#GameUI_vote_failed_map_name_required" );
break;
case VOTE_FAILED_ON_COOLDOWN:
{
const char *pszTimeString = ( bMinutes ) ? ( ( nTime < 2 ) ? "#GameUI_vote_failed_recently_min" : "#GameUI_vote_failed_recently_mins" ) : "#GameUI_vote_failed_recently";
g_pVGuiLocalize->ConstructString_safe( wszHeaderString, g_pVGuiLocalize->Find( pszTimeString ), 1, wszTime );
m_pCallVoteFailed->SetDialogVariable( "FailedReason", wszHeaderString );
case VOTE_FAILED_FAILED_RECENTLY:
g_pVGuiLocalize->ConstructString( wszHeaderString, sizeof(wszHeaderString), g_pVGuiLocalize->Find( "#GameUI_vote_failed_recently" ), 1, wszTime );
pwszHeaderString = wszHeaderString;
m_pCallVoteFailed->SetDialogVariable( "FailedReason", pwszHeaderString );
break;
}
case VOTE_FAILED_TEAM_CANT_CALL:
m_pCallVoteFailed->SetControlString( "FailedReason", "#GameUI_vote_failed_team_cant_call" );
@@ -1111,12 +1052,10 @@ void CHudVote::MsgFunc_CallVoteFailed( bf_read &msg )
break;
case VOTE_FAILED_CANNOT_KICK_FOR_TIME:
{
const char *pszTimeString = ( bMinutes ) ? ( ( nTime < 2 ) ? "#GameUI_vote_failed_cannot_kick_min" : "#GameUI_vote_failed_cannot_kick_mins" ) : "#GameUI_vote_failed_cannot_kick";
g_pVGuiLocalize->ConstructString_safe( wszHeaderString, g_pVGuiLocalize->Find( pszTimeString ), 1, wszTime );
m_pCallVoteFailed->SetDialogVariable( "FailedReason", wszHeaderString );
g_pVGuiLocalize->ConstructString( wszHeaderString, sizeof(wszHeaderString), g_pVGuiLocalize->Find( "#GameUI_vote_failed_cannot_kick_for_time" ), 1, wszTime );
pwszHeaderString = wszHeaderString;
m_pCallVoteFailed->SetDialogVariable( "FailedReason", pwszHeaderString );
break;
}
case VOTE_FAILED_CANNOT_KICK_DURING_ROUND:
m_pCallVoteFailed->SetControlString( "FailedReason", "#GameUI_vote_failed_round_active" );
@@ -1125,18 +1064,6 @@ void CHudVote::MsgFunc_CallVoteFailed( bf_read &msg )
case VOTE_FAILED_MODIFICATION_ALREADY_ACTIVE:
m_pCallVoteFailed->SetControlString( "FailedReason", "#GameUI_vote_failed_event_already_active" );
break;
case VOTE_FAILED_VOTE_IN_PROGRESS:
m_pCallVoteFailed->SetControlString( "FailedReason", "#GameUI_vote_failed_vote_in_progress" );
break;
case VOTE_FAILED_KICK_LIMIT_REACHED:
m_pCallVoteFailed->SetControlString( "FailedReason", "#GameUI_vote_failed_kick_limit" );
break;
case VOTE_FAILED_KICK_DENIED_BY_GC:
m_pCallVoteFailed->SetControlString( "FailedReason", "#GameUI_vote_failed_kick_limit_gc" );
break;
}
}
@@ -1148,14 +1075,14 @@ void CHudVote::MsgFunc_VoteFailed( bf_read &msg )
if ( IsPlayingDemo() )
return;
m_nVoteTeamIndex = msg.ReadByte();
int iTeam = msg.ReadByte();
vote_create_failed_t nReason = (vote_create_failed_t)msg.ReadByte();
// Visibility of this error is handled by OnThink()
m_bVotingActive = false;
SetVoteActive( false );
m_bVotePassed = false;
m_flVoteResultCycleTime = gpGlobals->curtime + 2.f;
m_flHideTime = gpGlobals->curtime + 5.f;
m_flVoteResultCycleTime = gpGlobals->curtime + 2;
m_flHideTime = gpGlobals->curtime + 5;
switch ( nReason )
{
@@ -1172,10 +1099,11 @@ void CHudVote::MsgFunc_VoteFailed( bf_read &msg )
break;
}
// driller: this event has no listeners - will eventually hook into stats
IGameEvent *event = gameeventmanager->CreateEvent( "vote_failed" );
if ( event )
{
event->SetInt( "team", m_nVoteTeamIndex );
event->SetInt( "team", iTeam );
gameeventmanager->FireEventClientSide( event );
}
@@ -1183,11 +1111,7 @@ void CHudVote::MsgFunc_VoteFailed( bf_read &msg )
if ( !pLocalPlayer )
return;
bool bShowToPlayer = ( !m_nVoteTeamIndex || pLocalPlayer->GetTeamNumber() == m_nVoteTeamIndex );
if ( bShowToPlayer )
{
pLocalPlayer->EmitSound("Vote.Failed");
}
pLocalPlayer->EmitSound("Vote.Failed");
}
//-----------------------------------------------------------------------------
@@ -1203,8 +1127,9 @@ void CHudVote::MsgFunc_VoteStart( bf_read &msg )
return;
// Is this a team-only vote?
m_nVoteTeamIndex = msg.ReadByte();
if ( m_nVoteTeamIndex >= FIRST_GAME_TEAM && m_nVoteTeamIndex != pLocalPlayer->GetTeamNumber() )
int iTeam = msg.ReadByte();
uint8 invalidTeam = (uint8)TEAM_INVALID;
if ( iTeam != invalidTeam && iTeam != pLocalPlayer->GetTeamNumber() )
return;
// Entity calling the vote
@@ -1232,18 +1157,18 @@ void CHudVote::MsgFunc_VoteStart( bf_read &msg )
}
// DisplayString
char szIssue[k_MAX_VOTE_NAME_LENGTH] = { 0 };
char szIssue[256];
szIssue[0] = 0;
msg.ReadString( szIssue, sizeof(szIssue) );
// DetailString
char szParam1[k_MAX_VOTE_NAME_LENGTH] = { 0 };
char szParam1[256];
szParam1[0] = 0;
msg.ReadString( szParam1, sizeof(szParam1) );
m_bIsYesNoVote = msg.ReadByte();
int iTargetEntIndex = msg.ReadByte();
m_flVoteResultCycleTime = -1.f;
m_bVotingActive = true;
SetVoteActive( true );
m_pVoteFailed->SetVisible( false );
m_pVotePassed->SetVisible( false );
m_pCallVoteFailed->SetVisible( false );
@@ -1273,23 +1198,25 @@ void CHudVote::MsgFunc_VoteStart( bf_read &msg )
// Display vote caller's name
wchar_t wszCallerName[MAX_PLAYER_NAME_LENGTH];
wchar_t wszHeaderString[k_MAX_VOTE_NAME_LENGTH];
wchar_t wszHeaderString[512];
wchar_t *pwszHeaderString;
// Player
g_pVGuiLocalize->ConvertANSIToUnicode( pszCallerName, wszCallerName, sizeof( wszCallerName ) );
// String
g_pVGuiLocalize->ConstructString_safe( wszHeaderString, g_pVGuiLocalize->Find( "#GameUI_vote_header" ), 1, wszCallerName );
g_pVGuiLocalize->ConstructString( wszHeaderString, sizeof(wszHeaderString), g_pVGuiLocalize->Find( "#GameUI_vote_header" ), 1, wszCallerName );
pwszHeaderString = wszHeaderString;
// Final
m_pVoteActive->SetDialogVariable( "header", wszHeaderString );
m_pVoteActive->SetDialogVariable( "header", pwszHeaderString );
// Display the Issue
wchar_t *pwcParam;
wchar_t wcParam[k_MAX_VOTE_NAME_LENGTH];
wchar_t wcParam[128];
wchar_t *pwcIssue;
wchar_t wcIssue[k_MAX_VOTE_NAME_LENGTH];
wchar_t wcIssue[512];
if ( Q_strlen( szParam1 ) > 0 )
{
@@ -1305,7 +1232,7 @@ void CHudVote::MsgFunc_VoteStart( bf_read &msg )
pwcParam = wcParam;
}
g_pVGuiLocalize->ConstructString_safe( wcIssue, g_pVGuiLocalize->Find( szIssue ), 1, pwcParam );
g_pVGuiLocalize->ConstructString( wcIssue, sizeof(wcIssue), g_pVGuiLocalize->Find( szIssue ), 1, pwcParam );
pwcIssue = wcIssue;
}
else
@@ -1319,19 +1246,19 @@ void CHudVote::MsgFunc_VoteStart( bf_read &msg )
if ( m_bIsYesNoVote )
{
// YES / NO UI
wchar_t wzFinal[k_MAX_VOTE_NAME_LENGTH] = L"";
wchar_t *pszText = g_pVGuiLocalize->Find( ::input->IsSteamControllerActive() ? "#GameUI_vote_yes_sc_instruction" : "#GameUI_vote_yes_pc_instruction" );
wchar_t wzFinal[512] = L"";
wchar_t *pszText = g_pVGuiLocalize->Find( "#GameUI_vote_yes_pc_instruction" );
if ( pszText )
{
UTIL_ReplaceKeyBindings( pszText, 0, wzFinal, sizeof( wzFinal ), GAME_ACTION_SET_FPSCONTROLS );
UTIL_ReplaceKeyBindings( pszText, 0, wzFinal, sizeof( wzFinal ) );
if ( m_pVoteActive )
m_pVoteActive->SetControlString( "LabelOption1", wzFinal );
}
pszText = g_pVGuiLocalize->Find( ::input->IsSteamControllerActive() ? "#GameUI_vote_no_sc_instruction" : "#GameUI_vote_no_pc_instruction" );
pszText = g_pVGuiLocalize->Find( "#GameUI_vote_no_pc_instruction" );
if ( pszText )
{
UTIL_ReplaceKeyBindings( pszText, 0, wzFinal, sizeof( wzFinal ), GAME_ACTION_SET_FPSCONTROLS );
UTIL_ReplaceKeyBindings( pszText, 0, wzFinal, sizeof( wzFinal ) );
if ( m_pVoteActive )
m_pVoteActive->SetControlString( "LabelOption2", wzFinal );
}
@@ -1361,7 +1288,7 @@ void CHudVote::MsgFunc_VoteStart( bf_read &msg )
// Construct Option name
const char *pszChoiceName = m_VoteSetupChoices[iIndex];
char szOptionName[k_MAX_VOTE_NAME_LENGTH];
char szOptionName[256];
Q_snprintf( szOptionName, sizeof( szOptionName ), "F%i. ", iIndex + 1 );
Q_strncat( szOptionName, pszChoiceName, sizeof( szOptionName ), COPY_ALL_CHARACTERS );
@@ -1382,28 +1309,12 @@ void CHudVote::MsgFunc_VoteStart( bf_read &msg )
}
}
// Is the target a player?
int nTargetLabelX = m_nVoteActiveIssueLabelX;
C_BasePlayer *pTargetPlayer = NULL;
if ( iTargetEntIndex )
{
pTargetPlayer = UTIL_PlayerByIndex( iTargetEntIndex );
if ( pTargetPlayer )
{
m_pVoteActiveTargetAvatar->SetPlayer( pTargetPlayer );
m_pVoteActiveTargetAvatar->SetShouldDrawFriendIcon( false );
nTargetLabelX += ( m_pVoteActiveTargetAvatar->GetWide() + XRES( 3 ) );
}
}
m_pVoteActiveIssueLabel->SetPos( nTargetLabelX, m_nVoteActiveIssueLabelY );
m_pVoteActiveTargetAvatar->SetVisible( pTargetPlayer ? true : false );
IGameEvent *event = gameeventmanager->CreateEvent( "vote_started" );
if ( event )
{
event->SetString( "issue", szIssue );
event->SetString( "param1", szParam1 );
event->SetInt( "team", m_nVoteTeamIndex );
event->SetInt( "team", iTeam );
event->SetInt( "initiator", m_iVoteCallerIdx );
gameeventmanager->FireEventClientSide( event );
}
@@ -1415,10 +1326,10 @@ void CHudVote::MsgFunc_VoteStart( bf_read &msg )
}
else
{
m_bShowVoteActivePanel = true;
ShowVoteUI();
}
#else
m_bShowVoteActivePanel = true;
ShowVoteUI();
#endif // TF_CLIENT_DLL
}
@@ -1430,24 +1341,24 @@ void CHudVote::MsgFunc_VotePass( bf_read &msg )
if ( IsPlayingDemo() )
return;
m_nVoteTeamIndex = msg.ReadByte();
int iTeam = msg.ReadByte();
// Passed string
char szResult[k_MAX_VOTE_NAME_LENGTH];
char szResult[256];
szResult[0] = 0;
msg.ReadString( szResult, sizeof(szResult) );
// Detail string
char szParam1[k_MAX_VOTE_NAME_LENGTH];
char szParam1[256];
szParam1[0] = 0;
msg.ReadString( szParam1, sizeof(szParam1) );
// Localize
wchar_t *pwcParam;
wchar_t wcParam[k_MAX_VOTE_NAME_LENGTH];
wchar_t wcParam[128];
wchar_t *pwcIssue;
wchar_t wcIssue[k_MAX_VOTE_NAME_LENGTH];
wchar_t wcIssue[512];
if ( Q_strlen( szParam1 ) > 0 )
{
@@ -1462,7 +1373,7 @@ void CHudVote::MsgFunc_VotePass( bf_read &msg )
pwcParam = wcParam;
}
g_pVGuiLocalize->ConstructString_safe( wcIssue, g_pVGuiLocalize->Find( szResult ), 1, pwcParam );
g_pVGuiLocalize->ConstructString( wcIssue, sizeof(wcIssue), g_pVGuiLocalize->Find( szResult ), 1, pwcParam );
pwcIssue = wcIssue;
}
else
@@ -1473,10 +1384,10 @@ void CHudVote::MsgFunc_VotePass( bf_read &msg )
m_pVotePassed->SetDialogVariable( "passedresult", pwcIssue );
m_bVotingActive = false;
SetVoteActive( false );
m_bVotePassed = true;
m_flVoteResultCycleTime = gpGlobals->curtime + 2.f;
m_flHideTime = gpGlobals->curtime + 5.f;
m_flVoteResultCycleTime = gpGlobals->curtime + 2;
m_flHideTime = gpGlobals->curtime + 5;
// driller: this event has no listeners - will eventually hook into stats
IGameEvent *event = gameeventmanager->CreateEvent( "vote_passed" );
@@ -1484,7 +1395,7 @@ void CHudVote::MsgFunc_VotePass( bf_read &msg )
{
event->SetString( "details", szResult );
event->SetString( "param1", szParam1 );
event->SetInt( "team", m_nVoteTeamIndex );
event->SetInt( "team", iTeam );
gameeventmanager->FireEventClientSide( event );
}
@@ -1517,45 +1428,21 @@ void CHudVote::MsgFunc_VoteSetup( bf_read &msg )
int nIssueCount = msg.ReadByte();
if ( nIssueCount )
{
for ( int i = 0; i < nIssueCount; i++ )
for ( int index = 0; index < nIssueCount; index++ )
{
char szIssue[k_MAX_VOTE_NAME_LENGTH];
char szIssueString[k_MAX_VOTE_NAME_LENGTH];
msg.ReadString( szIssue, sizeof( szIssue ) );
msg.ReadString( szIssueString, sizeof( szIssueString ) );
bool bIsActive = (bool)msg.ReadByte();
m_bVoteSystemActive |= bIsActive;
bool bAdd = true;
FOR_EACH_VEC( m_VoteSetupIssues, j )
char szIssue[256];
msg.ReadString( szIssue, sizeof(szIssue) );
if ( !m_VoteSetupIssues.HasElement( szIssue ) )
{
if ( !V_strcmp( szIssue, m_VoteSetupIssues[j].szName ) )
{
bAdd = false;
break;
}
}
if ( bAdd )
{
// When empty, assume that we just pre-pend #Vote_ to szIssue (reduces msg size)
if ( !szIssueString[0] )
{
V_sprintf_safe( szIssueString, "#Vote_%s", szIssue );
}
VoteIssue_t issue;
V_strcpy_safe( issue.szName, szIssue );
V_strcpy_safe( issue.szNameString, szIssueString );
issue.bIsActive = bIsActive;
// Send it over to the listpanel
m_VoteSetupIssues.AddToTail( issue );
m_VoteSetupIssues.CopyAndAddToTail( szIssue );
}
}
}
else
{
m_VoteSetupIssues.CopyAndAddToTail( "Voting disabled on this Server" );
}
m_pVoteSetupDialog->AddVoteIssues( m_VoteSetupIssues );
// Load up the list of Vote Issue Parameters
@@ -1745,51 +1632,50 @@ void CHudVote::FireGameEvent( IGameEvent *event )
//-----------------------------------------------------------------------------
void CHudVote::OnThink()
{
C_BasePlayer *pLocalPlayer = C_BasePlayer::GetLocalPlayer();
if ( pLocalPlayer )
// We delay hiding the menu after we cast a vote
if ( m_bPlayerVoted && m_flPostVotedHideTime > 0 && m_flPostVotedHideTime < gpGlobals->curtime )
{
bool bShowToPlayer = ( !m_nVoteTeamIndex || pLocalPlayer->GetTeamNumber() == m_nVoteTeamIndex );
m_pVoteActive->SetVisible( false );
m_bShowVoteActivePanel = false;
m_flPostVotedHideTime = -1;
}
// We delay hiding the menu after we cast a vote
if ( m_bPlayerVoted && m_flPostVotedHideTime > 0 && gpGlobals->curtime > m_flPostVotedHideTime )
if ( m_flVoteResultCycleTime > 0 && m_flVoteResultCycleTime < gpGlobals->curtime )
{
m_pVoteActive->SetVisible( false );
m_pVoteFailed->SetVisible( !m_bVotePassed );
m_pVotePassed->SetVisible( m_bVotePassed );
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( m_pVoteActive, "HideVoteBackgrounds" );
m_flVoteResultCycleTime = -1;
m_bPlayerVoted = false;
m_bVoteActive = false;
m_bShowVoteActivePanel = false;
m_iVoteCallerIdx = -1;
}
if ( m_bVoteActive )
{
// driller: Need to rewrite this to handle all vote types (Yes/No and General)
if ( m_bIsYesNoVote && m_pVoteActive )
{
m_pVoteActive->SetVisible( false );
m_bShowVoteActivePanel = false;
m_flPostVotedHideTime = -1;
char szYesCount[512] = "";
Q_snprintf( szYesCount, 512, "%d", m_nVoteOptionCount[0] );
char szNoCount[512] = "";
Q_snprintf( szNoCount, 512, "%d", m_nVoteOptionCount[1] );
m_pVoteActive->SetControlString( "Option1CountLabel", szYesCount );
m_pVoteActive->SetControlString( "Option2CountLabel", szNoCount );
}
if ( m_flVoteResultCycleTime > 0 && gpGlobals->curtime > m_flVoteResultCycleTime )
if ( !m_pVoteActive->IsVisible() && m_bShowVoteActivePanel )
{
m_pVoteActive->SetVisible( false );
m_pVoteFailed->SetVisible( !m_bVotePassed && bShowToPlayer );
m_pVotePassed->SetVisible( m_bVotePassed && bShowToPlayer );
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( m_pVoteActive, "HideVoteBackgrounds" );
m_pVoteActive->SetVisible( true );
m_flVoteResultCycleTime = -1;
m_bPlayerVoted = false;
m_bVotingActive = false;
m_bShowVoteActivePanel = false;
m_iVoteCallerIdx = -1;
}
if ( m_bVotingActive && m_bShowVoteActivePanel )
{
// driller: Need to rewrite this to handle all vote types (Yes/No and General)
if ( m_bIsYesNoVote && m_pVoteActive )
C_BasePlayer *pLocalPlayer = C_BasePlayer::GetLocalPlayer();
if ( pLocalPlayer )
{
char szYesCount[k_MAX_VOTE_NAME_LENGTH] = "";
Q_snprintf( szYesCount, sizeof( szYesCount ), "%d", m_nVoteOptionCount[0] );
char szNoCount[k_MAX_VOTE_NAME_LENGTH] = "";
Q_snprintf( szNoCount, sizeof( szNoCount ), "%d", m_nVoteOptionCount[1] );
m_pVoteActive->SetControlString( "Option1CountLabel", szYesCount );
m_pVoteActive->SetControlString( "Option2CountLabel", szNoCount );
}
if ( !m_pVoteActive->IsVisible() && bShowToPlayer )
{
m_pVoteActive->SetVisible( true );
pLocalPlayer->EmitSound("Vote.Created");
}
}
@@ -1803,7 +1689,7 @@ void CHudVote::OnThink()
//-----------------------------------------------------------------------------
bool CHudVote::ShouldDraw( void )
{
return ( m_bVotingActive || gpGlobals->curtime < m_flHideTime );
return ( m_bVoteActive || m_flHideTime > gpGlobals->curtime );
}
//-----------------------------------------------------------------------------
@@ -1814,6 +1700,22 @@ bool CHudVote::IsPlayingDemo() const
return engine->IsPlayingDemo();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHudVote::SetVoteActive( bool bActive )
{
m_bVoteActive = bActive;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHudVote::ShowVoteUI( void )
{
m_bShowVoteActivePanel = true;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
@@ -1822,13 +1724,3 @@ bool CHudVote::IsVoteUIActive( void )
return m_bShowVoteActivePanel;
}
bool CHudVote::IsShowingVoteSetupDialog()
{
return m_pVoteSetupDialog && m_pVoteSetupDialog->IsEnabled() && m_pVoteSetupDialog->IsVisible();
}
bool CHudVote::IsShowingVotingUI()
{
return m_pVoteActive && m_pVoteActive->IsEnabled() && m_pVoteActive->IsVisible();
}