class LevelBarsController extends inkLogicController
{
	protected editable var m_bar0 : inkWidgetRef;
	protected editable var m_bar1 : inkWidgetRef;
	protected editable var m_bar2 : inkWidgetRef;
	protected editable var m_bar3 : inkWidgetRef;
	protected editable var m_bar4 : inkWidgetRef;
	protected var m_bars : inkWidgetRef[ 5 ];

	protected event OnInitialize()
	{
		m_bars[ 0 ] = m_bar0;
		m_bars[ 1 ] = m_bar1;
		m_bars[ 2 ] = m_bar2;
		m_bars[ 3 ] = m_bar3;
		m_bars[ 4 ] = m_bar4;
	}

	public function Update( quality : CName, optional qualityToCompare : CName )
	{
		if( IsNameValid( qualityToCompare ) )
		{
			Update( UIItemsHelper.QualityNameToInt( quality ), UIItemsHelper.QualityNameToInt( qualityToCompare ) );
		}
		else
		{
			Update( UIItemsHelper.QualityNameToInt( quality ) );
		}
	}

	public function Update( quality : Int32 )
	{
		Update( quality, -1 );
	}

	public function GetBarWidget( index : Int32 ) : inkWidgetRef
	{
		if( index < m_bars.Size() )
		{
			return m_bars[ index ];
		}
		return m_bars[ 4 ];
	}

	public function Update( quality : Int32, qualityToCompare : Int32 )
	{
		var i : Int32;
		for( i = 0; i < m_bars.Size(); i += 1 )
		{
			if( i <= quality )
			{
				inkWidgetRef.SetState( m_bars[ i ], UIItemsHelper.QualityIntToName( quality ) );
			}
			else
			{
				inkWidgetRef.SetState( m_bars[ i ], 'Empty' );
			}
			if( qualityToCompare > -1 )
			{
				if( quality > qualityToCompare )
				{
					if( ( i > qualityToCompare ) && ( i <= quality ) )
					{
						inkWidgetRef.SetState( m_bars[ i ], 'Better' );
					}
				}
				if( quality < qualityToCompare )
				{
					if( ( i > quality ) && ( i <= qualityToCompare ) )
					{
						inkWidgetRef.SetState( m_bars[ i ], 'Worse' );
					}
				}
			}
		}
	}

}

