Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions src/game/client/hud_vote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,8 @@ void CHudVote::MsgFunc_CallVoteFailed( bf_read &msg )

vote_create_failed_t nReason = (vote_create_failed_t)msg.ReadByte();
int nTime = msg.ReadShort();
char szCustomText[k_MAX_VOTE_NAME_LENGTH];
msg.ReadString( szCustomText, sizeof(szCustomText) );

// if we're already drawing a vote, do nothing
if ( ShouldDraw() )
Expand Down Expand Up @@ -1231,6 +1233,12 @@ void CHudVote::MsgFunc_CallVoteFailed( bf_read &msg )

wchar_t wszHeaderString[k_MAX_VOTE_NAME_LENGTH];

if ( szCustomText[0] )
{
pFreeVotePanel->m_pCallVoteFailed->SetControlString( "FailedReason", szCustomText );
return;
}

switch( nReason )
{
case VOTE_FAILED_GENERIC:
Expand Down Expand Up @@ -1363,6 +1371,8 @@ void CHudVote::MsgFunc_VoteFailed( bf_read &msg )
pVotePanel->m_nVoteTeamIndex = nVoteTeamIndex;

vote_create_failed_t nReason = (vote_create_failed_t)msg.ReadByte();
char szCustomText[k_MAX_VOTE_NAME_LENGTH];
msg.ReadString( szCustomText, sizeof(szCustomText) );

// Visibility of this error is handled by OnThink()
pVotePanel->m_bVotingActive = false;
Expand All @@ -1371,19 +1381,26 @@ void CHudVote::MsgFunc_VoteFailed( bf_read &msg )
pVotePanel->m_flHideTime = gpGlobals->curtime + 5.f;
pVotePanel->m_nVoteIdx = -1;

switch ( nReason )
if ( szCustomText[0] )
{
case VOTE_FAILED_GENERIC:
pVotePanel->m_pVoteFailed->SetControlString( "FailedReason", "#GameUI_vote_failed" );
break;
pVotePanel->m_pVoteFailed->SetControlString( "FailedReason", szCustomText );
}
else
{
switch ( nReason )
{
case VOTE_FAILED_GENERIC:
pVotePanel->m_pVoteFailed->SetControlString( "FailedReason", "#GameUI_vote_failed" );
break;

case VOTE_FAILED_YES_MUST_EXCEED_NO:
pVotePanel->m_pVoteFailed->SetControlString( "FailedReason", "#GameUI_vote_failed_yesno" );
break;
case VOTE_FAILED_YES_MUST_EXCEED_NO:
pVotePanel->m_pVoteFailed->SetControlString( "FailedReason", "#GameUI_vote_failed_yesno" );
break;

case VOTE_FAILED_QUORUM_FAILURE:
pVotePanel->m_pVoteFailed->SetControlString( "FailedReason", "#GameUI_vote_failed_quorum" );
break;
case VOTE_FAILED_QUORUM_FAILURE:
pVotePanel->m_pVoteFailed->SetControlString( "FailedReason", "#GameUI_vote_failed_quorum" );
break;
}
}

IGameEvent *event = gameeventmanager->CreateEvent( "vote_failed" );
Expand Down
67 changes: 65 additions & 2 deletions src/game/server/vote_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,65 @@ static const int k_nKickWatchListMaxDuration = 300;

static int s_nVoteIdx = 0;

CON_COMMAND_F( test_vote_creation_failed, "Test vote UI", FCVAR_CHEAT )
{
CBasePlayer *pPlayer = UTIL_GetCommandClient();
if ( !pPlayer )
return;

if ( args.ArgC() <= 2 )
{
ClientPrint( pPlayer, HUD_PRINTCONSOLE, "Usage: test_vote_creation_failed <reasonnum> <time> [customtext]\n" );
return;
}

vote_create_failed_t nReason = (vote_create_failed_t)Q_atoi( args[1] );
int nTime = Q_atoi( args[2] );
const char* pszCustomText = nullptr;
if ( args.ArgC() > 3 )
pszCustomText = args[3];

if ( g_voteControllerGlobal )
g_voteControllerGlobal->SendVoteCreationFailedMessage( nReason, pPlayer, nTime, pszCustomText );
}

CON_COMMAND_F( test_vote_pass_failed, "Test vote UI", FCVAR_CHEAT )
{
CBasePlayer* pPlayer = UTIL_GetCommandClient();
if ( !pPlayer )
return;

if ( args.ArgC() <= 1 )
{
ClientPrint( pPlayer, HUD_PRINTCONSOLE, "Usage: test_vote_pass_failed <reasonnum> [customtext]\n" );
return;
}

vote_create_failed_t nReason = (vote_create_failed_t)Q_atoi( args[1] );
const char* pszCustomText = nullptr;
if (args.ArgC() > 2)
pszCustomText = args[2];

if ( g_voteControllerGlobal )
{
bool bCreatedVote = false;
if ( !g_voteControllerGlobal->IsVoteActive() )
{
if ( !g_voteControllerGlobal->CreateVote( DEDICATED_SERVER, "eternaween", "" ) )
{
ClientPrint( pPlayer, HUD_PRINTCONSOLE, "Failed to create test vote.\n" );
return;
}

bCreatedVote = true;
}

g_voteControllerGlobal->SendVoteFailedToPassMessage( nReason, pszCustomText );
if (bCreatedVote)
g_voteControllerGlobal->ResetData();
}
}

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -632,7 +691,7 @@ bool CVoteController::CreateVote( int iEntIndex, const char *pszTypeString, cons
//-----------------------------------------------------------------------------
// Purpose: The vote failed to start - let the caller know why
//-----------------------------------------------------------------------------
void CVoteController::SendVoteCreationFailedMessage( vote_create_failed_t nReason, CBasePlayer *pVoteCaller, int nTime /*= -1*/ )
void CVoteController::SendVoteCreationFailedMessage( vote_create_failed_t nReason, CBasePlayer *pVoteCaller, int nTime /*= -1*/, const char* pszCustomText /*= nullptr*/ )
{
Assert( pVoteCaller );
if ( !pVoteCaller )
Expand All @@ -648,13 +707,15 @@ void CVoteController::SendVoteCreationFailedMessage( vote_create_failed_t nReaso
UserMessageBegin( user, "CallVoteFailed" );
WRITE_BYTE( nReason );
WRITE_SHORT( nTime );
if ( pszCustomText && pszCustomText[0] )
WRITE_STRING( pszCustomText );
MessageEnd();
}

//-----------------------------------------------------------------------------
// Purpose: The vote was called, but failed to pass - let everyone know why
//-----------------------------------------------------------------------------
void CVoteController::SendVoteFailedToPassMessage( vote_create_failed_t nReason )
void CVoteController::SendVoteFailedToPassMessage( vote_create_failed_t nReason, const char* pszCustomText /*= nullptr*/ )
{
Assert( m_potentialIssues[m_iActiveIssueIndex] );

Expand All @@ -667,6 +728,8 @@ void CVoteController::SendVoteFailedToPassMessage( vote_create_failed_t nReason
WRITE_BYTE( m_iOnlyTeamToVote );
WRITE_LONG( m_nVoteIdx );
WRITE_BYTE( nReason );
if ( pszCustomText && pszCustomText[0] )
WRITE_STRING( pszCustomText );
MessageEnd();
}

Expand Down
6 changes: 3 additions & 3 deletions src/game/server/vote_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ class CVoteController : public CBaseEntity
void ListIssues( CBasePlayer *pForWhom );
bool IsValidVoter( CBasePlayer *pWhom );
bool CanTeamCastVote( int iTeam ) const;
void SendVoteCreationFailedMessage( vote_create_failed_t nReason, CBasePlayer *pVoteCaller, int nTime = -1 );
void SendVoteFailedToPassMessage( vote_create_failed_t nReason );
void SendVoteCreationFailedMessage( vote_create_failed_t nReason, CBasePlayer *pVoteCaller, int nTime = -1, const char *pszCustomText = nullptr );
void SendVoteFailedToPassMessage( vote_create_failed_t nReason, const char* pszCustomText = nullptr );
void VoteChoice_Increment( int nVoteChoice );
void VoteChoice_Decrement( int nVoteChoice );
int GetVoteIssueIndexWithHighestCount( void );
Expand All @@ -160,9 +160,9 @@ class CVoteController : public CBaseEntity
bool HasIssue( const char *pszIssue );
bool IsAVoteInProgress( void ) { return ( m_iActiveIssueIndex != INVALID_ISSUE ); }
int GetVoteID() const { return m_nVoteIdx; }
void ResetData(void);

protected:
void ResetData( void );
void VoteControllerThink( void );
void CheckForEarlyVoteClose( void ); // If everyone has voted (and changing votes is not allowed) then end early

Expand Down
2 changes: 1 addition & 1 deletion src/game/shared/tf/tf_usermessages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void RegisterUserMessages()
usermessages->Register( "CallVoteFailed", -1 );
usermessages->Register( "VoteStart", -1 );
usermessages->Register( "VotePass", -1 );
usermessages->Register( "VoteFailed", 6 );
usermessages->Register( "VoteFailed", -1 );
usermessages->Register( "VoteSetup", -1 ); // Initiates client-side voting UI

usermessages->Register( "PlayerBonusPoints", 3 );
Expand Down