// drawPlayerStats
//---------------------------------------------------------------------------
// Purpose:
//---------------------------------------------------------------------------
void RankView::drawPlayerStats(Surface &dest)
{
    char statBuf[256];

    ObjectiveInterface::updatePlayerObjectiveCounts();

    std::vector<const PlayerState*> states;
    for(size_t i = 0; i < PlayerInterface::getMaxPlayers(); ++i) {
        PlayerState* state = PlayerInterface::getPlayerState(i);
        if(state->getStatus() != _player_state_active)
            continue;
        states.push_back(state);
    }

    switch(gameconfig->gametype) {
    case _gametype_objective:
        std::sort(states.begin(), states.end(), StatesSortByObjectives());
        break;
    case _gametype_timelimit:
    case _gametype_fraglimit:
        std::sort(states.begin(), states.end(), StatesSortByFrags());
        break;
    }

    unsigned int CHAR_YPIX = Surface::getFontHeight();
    unsigned int entryHeight = std::max(CHAR_YPIX, UNIT_FLAGS_SURFACE.getHeight()) + 2;
    iXY offset(2, 40);
    iXY flagOffset(162, 40 + (int(CHAR_YPIX - UNIT_FLAGS_SURFACE.getHeight()))/2);

    for(std::vector<const PlayerState*>::iterator i = states.begin();
            i != states.end(); ++i) {
        const PlayerState* state = *i;

        snprintf(statBuf, sizeof(statBuf),
                 "%-20s%10i%7i%6i%10i", state->getName().substr(0,20).c_str(),
                 state->getKills(), state->getLosses(), state->getTotal(),
                 state->getObjectivesHeld());
        dest.bltString(offset.x, offset.y, statBuf, state->getColor());
        UNIT_FLAGS_SURFACE.setFrame(state->getFlag());
        UNIT_FLAGS_SURFACE.blt( dest, flagOffset.x, flagOffset.y );

        offset.y += entryHeight;
        flagOffset.y += entryHeight;
    }

} // end RankView::drawPlayerStats
示例#2
0
// drawPlayerStats
//---------------------------------------------------------------------------
// Purpose:
//---------------------------------------------------------------------------
void RankView::drawPlayerStats(Surface &dest, unsigned int flagHeight)
{
    char statBuf[256];

    states.clear();
    PlayerID i;
    for( i = 0; i < PlayerInterface::getMaxPlayers(); ++i)
    {
        PlayerState* state = PlayerInterface::getPlayer(i);
        if ( state->isActive() )
        {
            states.push_back(state);
        }
    }

    switch(GameConfig::game_gametype)
    {
        case _gametype_objective:
            std::sort(states.begin(), states.end(), StatesSortByObjectives());
            break;
        case _gametype_timelimit:
        case _gametype_fraglimit:
            std::sort(states.begin(), states.end(), StatesSortByPoints());
            break;
    }

    int cur_line_pos = TABLE_START + ((ENTRY_HEIGHT - Surface::getFontHeight())/2);
    int flag_pos = TABLE_START + (int(ENTRY_HEIGHT - flagHeight))/2;
    Surface * flag = 0;
    int cur_state = 0;
    for(std::vector<const PlayerState*>::iterator i = states.begin();
            i != states.end(); ++i) {
        const PlayerState* state = *i;

        snprintf(statBuf, sizeof(statBuf),
                stats_format, state->getName().substr(0,20).c_str(),
                state->getKills(), state->getLosses(), state->getTotal(),
                state->getObjectivesHeld());
        dest.bltStringShadowed(NAME_START, cur_line_pos, statBuf,
                               (cur_state == selected_line)?Color::yellow:Color::gray224,
                               Color::gray64);
        
        flag = ResourceManager::getFlag(state->getFlag());
        flag->blt( dest, FLAG_START, flag_pos );
        if ( state->getID() != PlayerInterface::getLocalPlayerIndex() )
        {
            // XXX ALLY
            bool meWithHim = PlayerInterface::isSingleAllied(PlayerInterface::getLocalPlayerIndex(), state->getID());
            bool himWithMe = PlayerInterface::isSingleAllied(state->getID(), PlayerInterface::getLocalPlayerIndex());            
            if ( meWithHim && himWithMe )
            {
                allyImage.bltTrans(dest, ALLY_START, flag_pos );
            }
            else if ( meWithHim )
            {
                allyRequestImage.bltTrans(dest, ALLY_START, flag_pos );
            }
            else if ( himWithMe )
            {
                allyOtherImage.bltTrans(dest, ALLY_START, flag_pos );
            }
            else
            {
                noAllyImage.bltTrans(dest, ALLY_START, flag_pos );
            }
        }

        colorImage.bltTransColor(dest, TABLE_HEADER_PIX_LEN+2, flag_pos, state->getColor());

        cur_line_pos += ENTRY_HEIGHT;
        flag_pos += ENTRY_HEIGHT;
        ++cur_state;
    }

} // end RankView::drawPlayerStats
// drawPlayerStats
//---------------------------------------------------------------------------
// Purpose:
//---------------------------------------------------------------------------
void RankView::drawPlayerStats( unsigned int flagHeight)
{
    char statBuf[256];

	states.clear();
	for(size_t i = 0; i < PlayerInterface::getMaxPlayers(); ++i)
	{
        PlayerState* state = PlayerInterface::getPlayer(i);
        if(state->getStatus() != _player_state_active)
        {
			continue;
		}
        states.push_back(state);
    }

    switch(gameconfig->gametype)
	{
        case _gametype_objective:
            std::sort(states.begin(), states.end(), StatesSortByObjectives());
            break;
        case _gametype_timelimit:
        case _gametype_fraglimit:
            std::sort(states.begin(), states.end(), StatesSortByFrags());
            break;
    }

    unsigned int CHAR_YPIX = Surface::getFontHeight();
    unsigned int entryHeight = std::max(CHAR_YPIX, flagHeight) + 2;
    iXY offset( 6*8, 40);
    iXY flagOffset(26, 40 + (int(CHAR_YPIX - flagHeight))/2);
    Surface * flag = 0;

    for(std::vector<const PlayerState*>::iterator i = states.begin();
            i != states.end(); ++i) {
        const PlayerState* state = *i;

        snprintf(statBuf, sizeof(statBuf),
                "%-20s%5i%7i%7i%10i", state->getName().substr(0,20).c_str(),
                state->getKills(), state->getLosses(), state->getTotal(),
                state->getObjectivesHeld());
        drawStringShadowed(offset.x, offset.y, statBuf, Color::white, Color::gray64);
        
        flag = ResourceManager::getFlag(state->getFlag());
        drawImage( *flag, flagOffset.x, flagOffset.y );
		if ( state->getID() != PlayerInterface::getLocalPlayerIndex() )
		{
			bool meWithHim = PlayerInterface::isSingleAllied(PlayerInterface::getLocalPlayerIndex(), state->getID());
			bool himWithMe = PlayerInterface::isSingleAllied(state->getID(), PlayerInterface::getLocalPlayerIndex());
			if ( meWithHim && himWithMe )
			{
				drawImage( allyImage, 4, flagOffset.y );
			}
			else if ( meWithHim )
			{
				drawImage( allyRequestImage, 4, flagOffset.y );
			}
			else if ( himWithMe )
			{
				drawImage( allyOtherImage, 4, flagOffset.y );
			}
			else
			{
				drawImage( noAllyImage, 4, flagOffset.y );
			}
		}
		
        offset.y += entryHeight;
        flagOffset.y += entryHeight;        
    }

} // end RankView::drawPlayerStats