class CodexListItemController extends ListItemController
{
	protected editable var m_doMarkNew : Bool;
	protected editable var m_stateMapperRef : inkWidgetRef;
	protected var m_stateMapper : weak< ListItemStateMapper >;

	protected event OnInitialize()
	{
		RegisterToCallback( 'OnDataChanged', this, 'OnDataChanged' );
		m_stateMapper = ( ( ListItemStateMapper )( inkWidgetRef.GetControllerByType( m_stateMapperRef, 'ListItemStateMapper' ) ) );
	}

	protected event OnDataChanged( value : IScriptable )
	{
		var data : JournalRepresentationData;
		data = ( ( JournalRepresentationData )( value ) );
		if( m_doMarkNew )
		{
			m_stateMapper.SetNew( data.IsNew );
		}
		super.OnDataChanged( value );
		data.Reference = GetRootWidget();
	}

	protected event OnToggledOn( target : weak< ListItemController > )
	{
		RemoveNew();
	}

	protected function RemoveNew()
	{
		m_stateMapper.SetNew( false );
	}

}

class CodexImageButton extends CodexListItemController
{
	protected editable var m_image : inkImageRef;
	protected editable var m_border : inkImageRef;
	protected editable var m_translateOnSelect : inkWidgetRef;
	protected editable var m_selectTranslationX : Float;

	protected event OnInitialize()
	{
		m_stateMapper = ( ( ListItemStateMapper )( inkWidgetRef.GetControllerByType( m_stateMapperRef, 'ListItemStateMapper' ) ) );
		inkImageRef.SetVisible( m_border, IsToggled() );
		RegisterToCallback( 'OnToggledOn', this, 'OnToggledOn' );
		RegisterToCallback( 'OnToggledOff', this, 'OnToggledOff' );
		RegisterToCallback( 'OnSelected', this, 'OnSelected' );
		RegisterToCallback( 'OnDeselected', this, 'OnDeselected' );
	}

	protected event OnToggledOn( target : weak< ListItemController > )
	{
		RemoveNew();
		inkImageRef.SetVisible( m_border, true );
		if( inkWidgetRef.IsValid( m_translateOnSelect ) )
		{
			inkWidgetRef.SetTranslation( m_translateOnSelect, m_selectTranslationX, 0.0 );
		}
	}

	protected event OnToggledOff( target : weak< ListItemController > )
	{
		inkImageRef.SetVisible( m_border, false );
		if( inkWidgetRef.IsValid( m_translateOnSelect ) )
		{
			inkWidgetRef.SetTranslation( m_translateOnSelect, 0.0, 0.0 );
		}
	}

	protected event OnDataChanged( value : IScriptable )
	{
		var image : CName;
		var data : weak< JournalRepresentationData >;
		var journalData : weak< JournalCodexCategory >;
		super.OnDataChanged( value );
		data = ( ( JournalRepresentationData )( value ) );
		journalData = ( ( JournalCodexCategory )( data.Data ) );
		if( journalData )
		{
			inkTextRef.SetVisible( m_labelPathRef, false );
			image = StringToName( journalData.GetCategoryName() );
		}
		else if( data.OnscreenData )
		{
			inkTextRef.SetVisible( m_labelPathRef, false );
			image = data.OnscreenData.GetTag();
		}
		else
		{
			inkTextRef.SetVisible( m_labelPathRef, true );
			image = '';
		}
		if( inkImageRef.IsValid( m_image ) )
		{
			if( IsNameValid( image ) )
			{
				inkImageRef.SetVisible( m_image, true );
				inkImageRef.SetTexturePart( m_image, image );
			}
			else
			{
				inkImageRef.SetVisible( m_image, false );
			}
		}
	}

	protected virtual function ExtractImage( data : JournalRepresentationData ) : CName
	{
		return '';
	}

}

