# HG changeset patch # User Adam Kaminski # Date 1621970603 14400 # Tue May 25 15:23:23 2021 -0400 # Node ID a5267639d1578dcc61d429636f3ba1e0702156f3 # Parent b381a6ce87908451bdca16cc5ef18093078b12b4 Cleaned up SCOREBOARD_RenderInVoteClassic and SCOREBOARD_RenderInVote, also changed some of the strings so they're not all capitalized. diff -r b381a6ce8790 -r a5267639d157 src/scoreboard.cpp --- a/src/scoreboard.cpp Tue May 25 14:34:00 2021 -0400 +++ b/src/scoreboard.cpp Tue May 25 15:23:23 2021 -0400 @@ -659,119 +659,72 @@ // void SCOREBOARD_RenderInVoteClassic( void ) { - char szString[128]; - ULONG ulCurYPos = 0; - ULONG ulIdx; - ULONG ulNumYes; - ULONG ulNumNo; - ULONG *pulPlayersWhoVotedYes; - ULONG *pulPlayersWhoVotedNo; - - // Start with the "VOTE NOW!" title. - ulCurYPos = 16; - - // Render the title. - sprintf( szString, "VOTE NOW!" ); - screen->DrawText( BigFont, gameinfo.gametype == GAME_Doom ? CR_RED : CR_UNTRANSLATED, - 160 - ( BigFont->StringWidth( szString ) / 2 ), - ulCurYPos, - szString, - DTA_Clean, true, TAG_DONE ); - - // Render who called the vote. - ulCurYPos += 24; - sprintf( szString, "Vote called by: %s", players[CALLVOTE_GetVoteCaller( )].userinfo.GetName() ); - screen->DrawText( SmallFont, CR_UNTRANSLATED, - 160 - ( SmallFont->StringWidth( szString ) / 2 ), - ulCurYPos, - szString, - DTA_Clean, true, TAG_DONE ); - - // Render the command being voted on. - ulCurYPos += 16; - sprintf( szString, "%s", CALLVOTE_GetVoteMessage( )); - screen->DrawText( SmallFont, CR_WHITE, - 160 - ( SmallFont->StringWidth( szString ) / 2 ), - ulCurYPos, - szString, - DTA_Clean, true, TAG_DONE ); - - // Render the reason for the vote being voted on. - if ( strlen( CALLVOTE_GetReason( )) > 0 ) - { - ulCurYPos += 16; - sprintf( szString, "Reason: %s", CALLVOTE_GetReason( )); - screen->DrawText( SmallFont, CR_ORANGE, - 160 - ( SmallFont->StringWidth( szString ) / 2 ), - ulCurYPos, - szString, - DTA_Clean, true, TAG_DONE ); - } - - // Render how much time is left to vote. - ulCurYPos += 16; - sprintf( szString, "Vote ends in: %d", static_cast (( CALLVOTE_GetCountdownTicks( ) + TICRATE ) / TICRATE) ); - screen->DrawText( SmallFont, CR_RED, - 160 - ( SmallFont->StringWidth( szString ) / 2 ), - ulCurYPos, - szString, - DTA_Clean, true, TAG_DONE ); - - pulPlayersWhoVotedYes = CALLVOTE_GetPlayersWhoVotedYes( ); - pulPlayersWhoVotedNo = CALLVOTE_GetPlayersWhoVotedNo( ); - ulNumYes = 0; - ulNumNo = 0; - - // Count how many players voted for what. - for ( ulIdx = 0; ulIdx < ( MAXPLAYERS / 2 ) + 1; ulIdx++ ) - { - if ( pulPlayersWhoVotedYes[ulIdx] != MAXPLAYERS && SERVER_IsValidClient( pulPlayersWhoVotedYes[ulIdx] )) - ulNumYes++; - - if ( pulPlayersWhoVotedNo[ulIdx] != MAXPLAYERS && SERVER_IsValidClient( pulPlayersWhoVotedNo[ulIdx] )) - ulNumNo++; - } - - // Display how many have voted for "Yes" and "No". - ulCurYPos += 16; - sprintf( szString, "YES: %d", static_cast (ulNumYes) ); - screen->DrawText( SmallFont, CR_UNTRANSLATED, - 32, - ulCurYPos, - szString, - DTA_Clean, true, TAG_DONE ); - - sprintf( szString, "NO: %d", static_cast (ulNumNo) ); - screen->DrawText( SmallFont, CR_UNTRANSLATED, - 320 - 32 - SmallFont->StringWidth( szString ), - ulCurYPos, - szString, - DTA_Clean, true, TAG_DONE ); - - // Show all the players who have voted, and what they voted for. - ulCurYPos += 8; - for ( ulIdx = 0; ulIdx < MAX( ulNumYes, ulNumNo ); ulIdx++ ) - { - ulCurYPos += 8; - if ( pulPlayersWhoVotedYes[ulIdx] != MAXPLAYERS && SERVER_IsValidClient( pulPlayersWhoVotedYes[ulIdx] )) - { - sprintf( szString, "%s", players[pulPlayersWhoVotedYes[ulIdx]].userinfo.GetName() ); - screen->DrawText( SmallFont, CR_UNTRANSLATED, - 32, - ulCurYPos, - szString, - DTA_Clean, true, TAG_DONE ); - } - - if ( pulPlayersWhoVotedNo[ulIdx] != MAXPLAYERS && SERVER_IsValidClient( pulPlayersWhoVotedNo[ulIdx] )) - { - sprintf( szString, "%s", players[pulPlayersWhoVotedNo[ulIdx]].userinfo.GetName() ); - screen->DrawText( SmallFont, CR_UNTRANSLATED, - 320 - 32 - SmallFont->StringWidth( szString ), - ulCurYPos, - szString, - DTA_Clean, true, TAG_DONE ); - } + ULONG ulNumYes = CALLVOTE_CountPlayersWhoVotedYes( ); + ULONG ulNumNo = CALLVOTE_CountPlayersWhoVotedNo( ); + ULONG *pulPlayersWhoVotedYes = CALLVOTE_GetPlayersWhoVotedYes( ); + ULONG *pulPlayersWhoVotedNo = CALLVOTE_GetPlayersWhoVotedNo( ); + ULONG ulMaxYesOrNoVoters = ( MAXPLAYERS / 2 ) + 1; + FString text; + + // Start with the "VOTE NOW!" title. + ULONG ulCurYPos = 16; + HUD_DrawTextCleanCentered( BigFont, gameinfo.gametype == GAME_Doom ? CR_RED : CR_UNTRANSLATED, ulCurYPos, "VOTE NOW!" ); + + // Render who called the vote. + ulCurYPos += 24; + text.Format( "Vote called by: %s", players[CALLVOTE_GetVoteCaller( )].userinfo.GetName( )); + HUD_DrawTextCleanCentered( SmallFont, CR_UNTRANSLATED, ulCurYPos, text ); + + // Render the command being voted on. + ulCurYPos += 16; + HUD_DrawTextCleanCentered( SmallFont, CR_WHITE, ulCurYPos, CALLVOTE_GetVoteMessage( )); + + // Render the reason for the vote being voted on. + if ( strlen( CALLVOTE_GetReason( )) > 0 ) + { + ulCurYPos += 16; + text.Format( "Reason: %s", CALLVOTE_GetReason( )); + HUD_DrawTextCleanCentered( SmallFont, CR_ORANGE, ulCurYPos, text ); + } + + // Render how much time is left to vote. + ulCurYPos += 16; + text.Format( "Vote ends in: %d", static_cast(( CALLVOTE_GetCountdownTicks( ) + TICRATE ) / TICRATE )); + HUD_DrawTextCleanCentered( SmallFont, CR_RED, ulCurYPos, text ); + + // Display how many have voted for "Yes" and "No". + ulCurYPos += 16; + text.Format( "Yes: %d", static_cast( ulNumYes )); + HUD_DrawTextClean( SmallFont, CR_RED, 32, ulCurYPos, text ); + + text.Format( "No: %d", static_cast( ulNumNo )); + HUD_DrawTextClean( SmallFont, CR_RED, 320 - 32 - SmallFont->StringWidth( text ), ulCurYPos, text ); + + ulCurYPos += 8; + ULONG ulOldCurYPos = ulCurYPos; + + // [AK] Show a list of all the players who voted yes. + for ( ULONG ulIdx = 0; ulIdx < ulMaxYesOrNoVoters; ulIdx++ ) + { + if ( pulPlayersWhoVotedYes[ulIdx] != MAXPLAYERS ) + { + ulCurYPos += 8; + text.Format( "%s", players[ulIdx].userinfo.GetName( )); + HUD_DrawTextClean( SmallFont, CR_UNTRANSLATED, 32, ulCurYPos, text ); + } + } + + ulCurYPos = ulOldCurYPos; + + // [AK] Next, show another list with all the players who voted no. + for ( ULONG ulIdx = 0; ulIdx < ulMaxYesOrNoVoters; ulIdx++ ) + { + if ( pulPlayersWhoVotedNo[ulIdx] != MAXPLAYERS ) + { + ulCurYPos += 8; + text.Format( "%s", players[ulIdx].userinfo.GetName( )); + HUD_DrawTextClean( SmallFont, CR_UNTRANSLATED, 320 - 32 - SmallFont->StringWidth( text ), ulCurYPos, text ); + } } } @@ -781,157 +734,66 @@ // void SCOREBOARD_RenderInVote( void ) { - char szString[128]; - char szKeyYes[16]; - char szKeyNo[16]; - ULONG ulCurYPos = 0; - ULONG ulIdx; - ULONG ulNumYes = 0; - ULONG ulNumNo = 0; - ULONG *pulPlayersWhoVotedYes; - ULONG *pulPlayersWhoVotedNo; - bool bWeVotedYes = false; - bool bWeVotedNo = false; + ULONG ulNumYes = CALLVOTE_CountPlayersWhoVotedYes( ); + ULONG ulNumNo = CALLVOTE_CountPlayersWhoVotedNo( ); + ULONG *pulPlayersWhoVotedYes = CALLVOTE_GetPlayersWhoVotedYes( ); + ULONG *pulPlayersWhoVotedNo = CALLVOTE_GetPlayersWhoVotedNo( ); + bool bWeVotedYes = false; + bool bWeVotedNo = false; + FString text; - // Get how many players voted for what. - pulPlayersWhoVotedYes = CALLVOTE_GetPlayersWhoVotedYes( ); - pulPlayersWhoVotedNo = CALLVOTE_GetPlayersWhoVotedNo( ); - for ( ulIdx = 0; ulIdx < ( MAXPLAYERS / 2 ) + 1; ulIdx++ ) + // [AK] Check if we either voted yes or no. + for ( ULONG ulIdx = 0; ulIdx < ( MAXPLAYERS / 2 ) + 1; ulIdx++ ) { - if ( pulPlayersWhoVotedYes[ulIdx] != MAXPLAYERS && SERVER_IsValidClient( pulPlayersWhoVotedYes[ulIdx] )) + if ( pulPlayersWhoVotedYes[ulIdx] == static_cast( consoleplayer )) { - ulNumYes++; - if( static_cast (pulPlayersWhoVotedYes[ulIdx]) == consoleplayer ) - bWeVotedYes = true; + bWeVotedYes = true; + break; } - - if ( pulPlayersWhoVotedNo[ulIdx] != MAXPLAYERS && SERVER_IsValidClient( pulPlayersWhoVotedNo[ulIdx] )) + else if ( pulPlayersWhoVotedNo[ulIdx] == static_cast( consoleplayer )) { - ulNumNo++; - if( static_cast (pulPlayersWhoVotedNo[ulIdx]) == consoleplayer) - bWeVotedNo = true; + bWeVotedNo = true; + break; } } - // Start at the top of the screen - ulCurYPos = 8; - // Render the title and time left. - sprintf( szString, "VOTE NOW! ( %d )", static_cast (( CALLVOTE_GetCountdownTicks( ) + TICRATE ) / TICRATE) ); + ULONG ulCurYPos = 8; + text.Format( "VOTE NOW! ( %d )", static_cast(( CALLVOTE_GetCountdownTicks( ) + TICRATE ) / TICRATE )); + HUD_DrawTextCentered( BigFont, gameinfo.gametype == GAME_Doom ? CR_RED : CR_UNTRANSLATED, ulCurYPos, text, g_bScale ); - if(g_bScale) - { - screen->DrawText( BigFont, gameinfo.gametype == GAME_Doom ? CR_RED : CR_UNTRANSLATED, - (LONG)(160 * g_fXScale) - (BigFont->StringWidth( szString ) / 2), - ulCurYPos, szString, - DTA_VirtualWidth, g_ValWidth.Int, - DTA_VirtualHeight, g_ValHeight.Int, - TAG_DONE ); - } - else - { - screen->DrawText( BigFont, gameinfo.gametype == GAME_Doom ? CR_RED : CR_UNTRANSLATED, - SCREENWIDTH/2 - ( BigFont->StringWidth( szString ) / 2 ), - ulCurYPos, - szString, - DTA_Clean, g_bScale, TAG_DONE ); - } // Render the command being voted on. ulCurYPos += 14; - sprintf( szString, "%s", CALLVOTE_GetVoteMessage( )); - if(g_bScale) - { - screen->DrawText( SmallFont, CR_WHITE, - (LONG)(160 * g_fXScale) - ( SmallFont->StringWidth( szString ) / 2 ), - ulCurYPos, szString, - DTA_VirtualWidth, g_ValWidth.Int, - DTA_VirtualHeight, g_ValHeight.Int, - TAG_DONE ); - } - else - { - screen->DrawText( SmallFont, CR_WHITE, - SCREENWIDTH/2 - ( SmallFont->StringWidth( szString ) / 2 ), - ulCurYPos, - szString, - DTA_Clean, g_bScale, TAG_DONE ); - } + HUD_DrawTextCentered( SmallFont, CR_WHITE, ulCurYPos, CALLVOTE_GetVoteMessage( ), g_bScale ); ulCurYPos += 4; - // Render the reason of the vote being voted on. - if ( strlen( CALLVOTE_GetReason( )) > 0 ) - { - ulCurYPos += 8; - sprintf( szString, "Reason: %s", CALLVOTE_GetReason( )); - if ( g_bScale ) - { - screen->DrawText( SmallFont, CR_ORANGE, - (LONG)(160 * g_fXScale) - ( SmallFont->StringWidth( szString ) / 2 ), - ulCurYPos, szString, - DTA_VirtualWidth, g_ValWidth.Int, - DTA_VirtualHeight, g_ValHeight.Int, - TAG_DONE ); - } - else - { - screen->DrawText( SmallFont, CR_ORANGE, - SCREENWIDTH/2 - ( SmallFont->StringWidth( szString ) / 2 ), - ulCurYPos, - szString, - DTA_Clean, g_bScale, TAG_DONE ); - } + // Render the reason of the vote being voted on. + if ( strlen( CALLVOTE_GetReason( )) > 0 ) + { + ulCurYPos += 8; + text.Format( "Reason: %s", CALLVOTE_GetReason( )); + HUD_DrawTextCentered( SmallFont, CR_ORANGE, ulCurYPos, text, g_bScale ); } // Render the number of votes. ulCurYPos += 8; - sprintf( szString, "\\c%sYes: %d, \\c%sNo: %d", bWeVotedYes ? "k" : "s", static_cast (ulNumYes), bWeVotedNo ? "k" : "s", static_cast (ulNumNo) ); - V_ColorizeString( szString ); - if(g_bScale) - { - screen->DrawText( SmallFont, CR_DARKBROWN, - (LONG)(160 * g_fXScale) - ( SmallFont->StringWidth( szString ) / 2 ), - ulCurYPos, szString, - DTA_VirtualWidth, g_ValWidth.Int, - DTA_VirtualHeight, g_ValHeight.Int, - TAG_DONE ); - } - else - { - screen->DrawText( SmallFont, CR_DARKBROWN, - SCREENWIDTH/2 - ( SmallFont->StringWidth( szString ) / 2 ), - ulCurYPos, - szString, - DTA_Clean, g_bScale, TAG_DONE ); - } - if( !bWeVotedYes && !bWeVotedNo ) - { - // Render the explanation of keys. - ulCurYPos += 8; + text.Format( "%sYes: %d" TEXTCOLOR_NORMAL ", %sNo: %d", bWeVotedYes ? TEXTCOLOR_YELLOW : "", static_cast( ulNumYes ), + bWeVotedNo ? TEXTCOLOR_YELLOW : "", static_cast( ulNumNo )); + HUD_DrawTextCentered( SmallFont, CR_DARKBROWN, ulCurYPos, text, g_bScale ); - static char vote_yes[] = "vote_yes"; - static char vote_no[] = "vote no"; - C_FindBind( vote_yes, szKeyYes ); - C_FindBind( vote_no, szKeyNo ); - sprintf( szString, "%s | %s", szKeyYes, szKeyNo); - if(g_bScale) - { - screen->DrawText( SmallFont, CR_BLACK, - (LONG)(160 * g_fXScale) - ( SmallFont->StringWidth( szString ) / 2 ), - ulCurYPos, szString, - DTA_VirtualWidth, g_ValWidth.Int, - DTA_VirtualHeight, g_ValHeight.Int, - TAG_DONE ); - } - else - { - screen->DrawText( SmallFont, CR_BLACK, - SCREENWIDTH/2 - ( SmallFont->StringWidth( szString ) / 2 ), - ulCurYPos, - szString, - DTA_Clean, g_bScale, TAG_DONE ); - } + // Render the explanation of keys. + if (( bWeVotedYes == false ) && ( bWeVotedNo == false )) + { + char keyVoteYes[16]; + C_FindBind( "vote_yes", keyVoteYes ); + char keyVoteNo[16]; + C_FindBind( "vote_no", keyVoteNo ); + + ulCurYPos += 8; + text.Format( "%s | %s", keyVoteYes, keyVoteNo ); + HUD_DrawTextCentered( SmallFont, CR_BLACK, ulCurYPos, text, g_bScale ); } }