class PerksSkillsLevelsContainerController extends inkLogicController
{
	protected editable var m_topRowItemsContainer : inkCompoundRef;
	protected editable var m_bottomRowItemsContainer : inkCompoundRef;
	protected editable var m_levelBar : inkWidgetRef;
	protected editable var m_levelBarSpacer : inkWidgetRef;
	protected editable var m_label : inkTextRef;
	protected var m_proficiencyDisplayData : ProficiencyDisplayData;

	public function Setup( proficiencyDisplayData : ProficiencyDisplayData )
	{
		m_proficiencyDisplayData = proficiencyDisplayData;
		inkTextRef.SetText( m_label, m_proficiencyDisplayData.m_localizedName );
		UpdateLevelsIndicators();
		UpdateLevelBar();
	}

	public function UpdateLevelsIndicators()
	{
		var i : Int32;
		var widget : weak< inkWidget >;
		inkCompoundRef.RemoveAllChildren( m_topRowItemsContainer );
		inkCompoundRef.RemoveAllChildren( m_bottomRowItemsContainer );
		for( i = 0; i < m_proficiencyDisplayData.m_areas.Size(); i += 1 )
		{
			if( i < 5 )
			{
				widget = SpawnFromLocal( inkCompoundRef.Get( m_topRowItemsContainer ), 'SkillPerkLevelPreview' );
			}
			else
			{
				widget = SpawnFromLocal( inkCompoundRef.Get( m_bottomRowItemsContainer ), 'SkillPerkLevelPreview' );
			}
			( ( PerksSkillsLevelDisplayController )( widget.GetController() ) ).Setup( m_proficiencyDisplayData.m_areas[ i ] );
		}
	}

	public function UpdateLevelBar()
	{
		var percentage : Float;
		if( m_proficiencyDisplayData.m_level == m_proficiencyDisplayData.m_maxLevel )
		{
			percentage = 100.0;
		}
		else
		{
			percentage = ( ( ( Float )( m_proficiencyDisplayData.m_expPoints ) ) / ( ( Float )( m_proficiencyDisplayData.m_maxExpPoints ) ) ) * 100.0;
		}
		inkWidgetRef.SetSizeCoefficient( m_levelBar, percentage );
		inkWidgetRef.SetSizeCoefficient( m_levelBarSpacer, 100.0 - percentage );
	}

}

class PerksSkillsLevelDisplayController extends inkLogicController
{
	protected editable var m_tint : inkWidgetRef;

	public function Setup( data : AreaDisplayData )
	{
		var i, boughtSum, maxedSum, boughtMax : Int32;
		var perk : PerkDisplayData;
		var state : CName;
		for( i = 0; i < data.m_perks.Size(); i += 1 )
		{
			perk = data.m_perks[ i ];
			if( perk.m_level == perk.m_maxLevel )
			{
				maxedSum += 1;
			}
			boughtSum += perk.m_level;
			boughtMax += ( perk.m_maxLevel - 1 );
		}
		if( maxedSum > 0 )
		{
			state = 'Maxed';
			inkWidgetRef.SetOpacity( m_tint, ( ( Float )( maxedSum ) ) / ( ( Float )( data.m_perks.Size() ) ) );
		}
		else if( boughtSum > 0 )
		{
			state = 'Bought';
			inkWidgetRef.SetOpacity( m_tint, ( ( Float )( boughtSum ) ) / ( ( Float )( boughtMax ) ) );
		}
		else
		{
			inkWidgetRef.SetOpacity( m_tint, 0.0 );
		}
		inkWidgetRef.SetState( m_tint, state );
	}

}

