void CNB_Mission_Summary::OnThink()
{
	BaseClass::OnThink();

	if ( !ASWGameResource() )
		return;

	int nSkillLevel = ASWGameRules()->GetSkillLevel();
	const wchar_t *pDifficulty = NULL;
	switch( nSkillLevel )
	{
		case 1: pDifficulty = g_pVGuiLocalize->Find( "#asw_difficulty_easy" ); break;
		default:
		case 2: pDifficulty = g_pVGuiLocalize->Find( "#asw_difficulty_normal" ); break;
		case 3: pDifficulty = g_pVGuiLocalize->Find( "#asw_difficulty_hard" ); break;
		case 4: pDifficulty = g_pVGuiLocalize->Find( "#asw_difficulty_insane" ); break;
		case 5: pDifficulty = g_pVGuiLocalize->Find( "#asw_difficulty_imba" ); break;
	}
	if ( !pDifficulty )
	{
		pDifficulty = L"";
	}

	if ( CAlienSwarm::IsOnslaught() )
	{
		wchar_t wszText[ 128 ];
		_snwprintf( wszText, sizeof( wszText ), L"%s %s", pDifficulty, g_pVGuiLocalize->FindSafe( "#nb_onslaught_title" ) );
		m_pDifficultyLabel->SetText( wszText );
	}
	else
	{
		m_pDifficultyLabel->SetText( pDifficulty );
	}

	CASWHudMinimap *pMap = GET_HUDELEMENT( CASWHudMinimap );
	if ( pMap )
	{
		m_pMissionLabel->SetText(pMap->m_szMissionTitle);
	}

	// compose objectives list
	wchar_t wszObjectivesBuffer[ 1024 ];
	wchar_t wszBuffer[ 1024 ];

	wszObjectivesBuffer[ 0 ] = 0;

	int nObjectives = 0;
	for ( int i = 0 ; i < ASW_MAX_OBJECTIVES; i++ )
	{
		C_ASW_Objective* pObjective = ASWGameResource()->GetObjective(i);
		if ( pObjective && !pObjective->IsObjectiveHidden() && !pObjective->IsObjectiveDummy() )
		{
			if ( nObjectives == 0 )
			{
				_snwprintf( wszObjectivesBuffer, sizeof( wszObjectivesBuffer ), L"- %s", pObjective->GetObjectiveTitle() );
			}
			else
			{
				_snwprintf( wszBuffer, sizeof( wszBuffer ), L"%s\n- %s", wszObjectivesBuffer, pObjective->GetObjectiveTitle() );
				_snwprintf( wszObjectivesBuffer , sizeof( wszObjectivesBuffer ), L"%s", wszBuffer );
			}
			nObjectives++;
		}
	}
	m_pObjectivesLabel->SetText( wszObjectivesBuffer );

	int nLabelWidth = YRES( 168 );
	m_pObjectivesLabel->SetSize( nLabelWidth, 400 );
	m_pObjectivesLabel->GetTextImage()->SetDrawWidth( nLabelWidth );
	m_pObjectivesLabel->InvalidateLayout( true );
	int texwide, texttall;	
	m_pObjectivesLabel->GetTextImage()->ResizeImageToContentMaxWidth( nLabelWidth );
	m_pObjectivesLabel->SetWrap( true );
	m_pObjectivesLabel->GetTextImage()->GetContentSize( texwide, texttall );	
	//m_pObjectivesLabel->SetSize( texwide, texttall );
	m_pObjectivesLabel->InvalidateLayout( true );
	m_pObjectivesLabel->GetTextImage()->GetContentSize( texwide, texttall );
	m_pObjectivesLabel->InvalidateLayout( true );
}
void CASWHudObjective::UpdateObjectiveList()
{
    C_ASW_Game_Resource* pGameResource = ASWGameResource();
    if (!pGameResource)
        return;
    int iCurrent = 0;
    bool bNeedsLayout = false;
    for (int i=0; i<ASW_MAX_OBJECTIVES; i++)
    {
        C_ASW_Objective* pObjective = pGameResource->GetObjective(i);
        bool bUpdatedTitle = false;
        if (pObjective && !pObjective->IsObjectiveDummy() && !pObjective->IsObjectiveHidden())
        {
            if (m_hObjectives[iCurrent].Get() != pObjective || pObjective->NeedsTitleUpdate()
                    || m_bObjectiveTitleEmpty[iCurrent])
            {
                if (m_hObjectives[iCurrent].Get() != pObjective)
                {
                    m_bObjectiveComplete[iCurrent] = pObjective->IsObjectiveComplete();
                    if (pObjective->GetObjectiveIconName()[0] != '\0')
                    {
                        m_pObjectiveIcon[iCurrent]->SetImage(pObjective->GetObjectiveIconName());
                        //Msg("Set objective icon %d to %s\n", iCurrent, pObjective->GetObjectiveIconName());
                    }
                    if (pObjective->IsObjectiveComplete())
                        m_pTickBox[iCurrent]->SetImage("swarm/HUD/TickBoxTicked");
                    else
                        m_pTickBox[iCurrent]->SetImage("swarm/HUD/TickBoxEmpty");
                    m_hObjectives[iCurrent] = pObjective;
                }
                // set the content for this objective
                const wchar_t *pTitle = pObjective->GetObjectiveTitle();
                bUpdatedTitle = true;
                m_bObjectiveTitleEmpty[iCurrent] = (pTitle[0] == '\0');
                m_pObjectiveLabel[iCurrent]->SetText(pTitle);
                if (m_bPlayMissionCompleteSequence && m_hObjectiveComplete.Get() == pObjective)
                {
                    m_pObjectiveGlowLabel->SetText(pTitle);
                    //Msg("A) Set glow label to %s\n", pTitle);
                }

                // make sure they're visible
                if (!m_pObjectiveLabel[iCurrent]->IsVisible())
                    m_pObjectiveLabel[iCurrent]->SetVisible(true);
                if (pObjective->GetObjectiveIconName()[0] != '\0' && !m_pObjectiveIcon[iCurrent]->IsVisible())
                {
                    //Msg("setting objective icon %d visible\n", iCurrent);
                    m_pObjectiveIcon[iCurrent]->SetVisible(true);
                }
                else
                {
                    m_pObjectiveIcon[iCurrent]->SetVisible(false);
                }
                if (!m_pTickBox[iCurrent]->IsVisible())
                    m_pTickBox[iCurrent]->SetVisible(true);

                bNeedsLayout = true;
            }

            // already have this objective in our list, but check if it's become complete
            if (m_bObjectiveComplete[iCurrent] != pObjective->IsObjectiveComplete())
            {
                //Msg("Objective %d is now complete!\n", iCurrent);
                m_bObjectiveComplete[iCurrent] = pObjective->IsObjectiveComplete();
                if (pObjective->IsObjectiveComplete())
                    m_pTickBox[iCurrent]->SetImage("swarm/HUD/TickBoxTicked");
                else
                    m_pTickBox[iCurrent]->SetImage("swarm/HUD/TickBoxEmpty");
                if (ASWGameRules() && ASWGameRules()->GetGameState() == ASW_GS_INGAME)//  && !ASWGameRules()->IsTutorialMap()
                {
                    m_iObjectiveCompleteSequencePos = iCurrent;
                    m_hObjectiveComplete = pObjective;
                    m_bPlayMissionCompleteSequence = true;
                    m_iNumLetters = 0;
                    GetAnimationController()->RunAnimationCommand(m_pCompleteLabel, "Alpha", 255, 0, 0.1f, AnimationController::INTERPOLATOR_LINEAR);
                    GetAnimationController()->RunAnimationCommand(m_pCompleteLabelBD, "Alpha", 255, 0, 0.1f, AnimationController::INTERPOLATOR_LINEAR);
                    GetAnimationController()->RunAnimationCommand(m_pObjectiveGlowLabel, "Alpha", 255, 0, 0.1f, AnimationController::INTERPOLATOR_LINEAR);
                    const wchar_t *pTitle = pObjective->GetObjectiveTitle();
                    m_pObjectiveGlowLabel->SetText(pTitle);
                    //Msg("1) Set glow label to %s\n", pTitle);
                }
            }
            if ( m_hObjectiveComplete.Get() != NULL && m_hObjectiveComplete.Get() == pObjective )
            {
                if ( iCurrent != m_iObjectiveCompleteSequencePos )
                {
                    m_iObjectiveCompleteSequencePos = iCurrent;
                    bNeedsLayout = true;
                }
            }
            iCurrent++;
        }
    }
    if ( m_iNumObjectivesListed != iCurrent)
    {
        m_iNumObjectivesListed = iCurrent;
        bNeedsLayout = true;
    }

    for (int i=iCurrent; i<ASW_MAX_OBJECTIVES; i++)
    {
        //Msg("Clearing objective slot %d\n", i);
        m_hObjectives[i] = NULL;
        if (m_pObjectiveLabel[i]->IsVisible())
            m_pObjectiveLabel[i]->SetVisible(false);
        if (m_pObjectiveIcon[i]->IsVisible())
            m_pObjectiveIcon[i]->SetVisible(false);
        if (m_pTickBox[i]->IsVisible())
            m_pTickBox[i]->SetVisible(false);
    }
    if ( IsSpectating() != m_bLastSpectating )
    {
        bNeedsLayout = true;
    }

    if ( bNeedsLayout )
    {
        LayoutObjectives();
    }
}