Пример #1
0
SidePanel::~SidePanel()
{
	Team *myTeam = g_app->GetWorld()->GetTeam( g_app->GetWorld()->m_myTeamId );
	
	// Put back any ships currently being placed, so they don't end up in limbo
	if( myTeam->m_fleets.ValidIndex( m_currentFleetId ) &&
	    !myTeam->m_fleets[ m_currentFleetId ]->m_active )
	{
		Fleet *fleet = myTeam->GetFleet( m_currentFleetId );
		
		while ( fleet->m_memberType.Size() > 0 )
		{
			myTeam->m_unitsAvailable[ fleet->m_memberType[0] ]++;
			myTeam->m_unitCredits += g_app->GetWorld()->GetUnitValue( fleet->m_memberType[0] );
			fleet->m_memberType.RemoveData(0);
		}
		
		myTeam->m_fleets.RemoveData( m_currentFleetId );
		delete fleet;
	}
	
    SaveProperties( "WindowUnitCreation" );
}
Пример #2
0
void SidePanel::Render( bool hasFocus )
{
    int currentSelectionId = g_app->GetMapRenderer()->GetCurrentSelectionId();
    if( currentSelectionId == -1 )
    {
        if( m_mode != ModeUnitPlacement &&
            m_mode != ModeFleetPlacement )
        {
            ChangeMode( ModeUnitPlacement );
            m_currentFleetId = -1;
        }
    }
    Team *myTeam = g_app->GetWorld()->GetMyTeam();

    if( m_mode == ModeUnitPlacement )
    {
        PanelModeButton *button = (PanelModeButton *)GetButton("FleetMode");
        //if( !button->m_disabled )
        {
            int shipsRemaining = 0;
            if( myTeam )
            {
                shipsRemaining += myTeam->m_unitsAvailable[WorldObject::TypeBattleShip];
                shipsRemaining += myTeam->m_unitsAvailable[WorldObject::TypeCarrier];
                shipsRemaining += myTeam->m_unitsAvailable[WorldObject::TypeSub];

                bool unplacedFleets = false;
                bool outOfCredits = myTeam->m_unitCredits <= 0;
                if( !g_app->GetGame()->GetOptionValue("VariableUnitCounts") ) outOfCredits = false;

                if( myTeam->m_fleets.Size() > 0 &&
                    myTeam->GetFleet( myTeam->m_fleets.Size() - 1 )->m_active == false )
                {
                    unplacedFleets = true;
                }
                if( (shipsRemaining <= 0 ||
                    myTeam->m_unitCredits <= 0 )&&
                    !unplacedFleets )
                {
                    button->m_disabled = true;
                }
                else
                {
                    button->m_disabled = false;
                }
            }
        }
    }

    int w = m_w;
    m_w = 100;
    FadingWindow::Render( hasFocus, true );    
    m_w = w;
        
    char text[128];
    switch(m_mode)
    {
        case ModeUnitPlacement:     sprintf(text, LANGUAGEPHRASE("dialog_placeunit"));   break;
        case ModeFleetPlacement:    sprintf(text, LANGUAGEPHRASE("dialog_createfleet"));  break;
    }
    g_renderer->TextCentreSimple(m_x+50, m_y+10, White, m_fontsize, text );

    if( m_mode == ModeFleetPlacement )
    {
        if( m_currentFleetId != -1 )
        {
            int x = 0;
            int y = 0;
            int yMod = 0;
            
            Team *myTeam = g_app->GetWorld()->GetTeam( g_app->GetWorld()->m_myTeamId );
            if( myTeam && myTeam->m_fleets.ValidIndex(m_currentFleetId) )
            {
                if( m_mode == ModeFleetPlacement )
                {
                    x = m_x + 120;
                    y = m_y + 20;
                    yMod = 50;

                    for( int i = 0; i < 6; ++i )
                    {
                        g_renderer->RectFill( x, y, 40, 40, Colour(90,90,170,200) );
                        g_renderer->Rect(x, y, 40, 40, White );
                        y += yMod;
                    }
                    y = m_y+20;
                }
                else
                {
                    x = m_x + 10;
                    y = m_y + 40;
                    yMod = 60;
                }

                for( int i = 0; i < myTeam->m_fleets[ m_currentFleetId ]->m_memberType.Size(); ++i )
                {
                    int type = myTeam->m_fleets[ m_currentFleetId ]->m_memberType[i];
                    Image *bmpImage	= g_resource->GetImage( g_app->GetMapRenderer()->m_imageFiles[type] );
                    g_renderer->SetBlendMode( Renderer::BlendModeAdditive );
                    g_renderer->Blit( bmpImage, x+3, y, 35, 35, myTeam->GetTeamColour() );
                    g_renderer->SetBlendMode( Renderer::BlendModeNormal );
                    y += yMod;
                }
            }
        }
    }
    int variableTeamUnits = g_app->GetGame()->GetOptionValue("VariableUnitCounts");
    if( myTeam )
    {
        if( variableTeamUnits == 1 )
        {
            Colour col = Colour(255,255,0,255);
            char msg[128];
            sprintf( msg, LANGUAGEPHRASE("dialog_credits_1") );
            LPREPLACEINTEGERFLAG( 'C', myTeam->m_unitCredits, msg );
            g_renderer->TextCentreSimple( m_x+50, m_y+m_h-28, col, m_fontsize, msg );

            sprintf( msg, LANGUAGEPHRASE("dialog_credits_2"));
            g_renderer->TextCentreSimple( m_x+50, m_y+m_h-15, col, m_fontsize, msg );
        }

        int totalUnits = 0;
        for( int i = 0; i < WorldObject::NumObjectTypes; ++i )
        {
            totalUnits += myTeam->m_unitsAvailable[i];
        }

        if( totalUnits == 0 &&
            m_previousUnitCount > 0 &&
            m_currentFleetId == -1 &&
            !g_app->GetTutorial() )
        {
            EclRemoveWindow("Side Panel" );
            return;
        }
        m_previousUnitCount = totalUnits;
    }
}