import class ServerInfo extends IScriptable
{
	import var number : Int32;
	import var kind : String;
	import var hostname : String;
	import var address : String;
	import var worldDescription : String;
}

class ServerInfoController extends ListItemController
{
	private var m_settingsListCtrl : weak< ListController >;
	var m_number : weak< inkText >;
	editable var m_numberPath : CName;
	private var m_kind : weak< inkText >;
	editable var m_kindPath : CName;
	private var m_hostname : weak< inkText >;
	editable var m_hostnamePath : CName;
	private var m_address : weak< inkText >;
	editable var m_addressPath : CName;
	private var m_worldDescription : weak< inkText >;
	editable var m_worldDescriptionPath : CName;
	private var m_background : weak< inkImage >;
	private var c_selectionColor : Color;
	private var c_initialColor : HDRColor;
	private var c_markColor : HDRColor;
	private var m_marked : Bool;
	default m_marked = false;

	protected event OnInitialize()
	{
		super.OnInitialize();
		c_selectionColor = Color( 220, 20, 60, 1 );
		c_markColor = HDRColor( 0.0, 1.0, 0.0, 1.0 );
		RegisterToCallback( 'OnSelected', this, 'OnSelected' );
		RegisterToCallback( 'OnDeselected', this, 'OnDeselected' );
		m_number = ( ( inkText )( GetWidget( m_numberPath ) ) );
		m_kind = ( ( inkText )( GetWidget( m_kindPath ) ) );
		m_hostname = ( ( inkText )( GetWidget( m_hostnamePath ) ) );
		m_address = ( ( inkText )( GetWidget( m_addressPath ) ) );
		m_worldDescription = ( ( inkText )( GetWidget( m_worldDescriptionPath ) ) );
		m_background = ( ( inkImage )( GetWidget( 'Background' ) ) );
		c_initialColor = m_background.GetTintColor();
		RegisterToCallback( 'OnHoverOver', this, 'OnHoverOver' );
		RegisterToCallback( 'OnHoverOut', this, 'OnHoverOut' );
		RegisterToCallback( 'OnRelease', this, 'OnRelease' );
	}

	protected event OnDataChanged( data : IScriptable )
	{
		var serverInfo : ServerInfo;
		serverInfo = ( ( ServerInfo )( data ) );
		m_number.SetText( ( ( String )( serverInfo.number + 1 ) ) );
		m_kind.SetText( serverInfo.kind );
		m_hostname.SetText( serverInfo.hostname );
		m_address.SetText( serverInfo.address );
		m_worldDescription.SetText( serverInfo.worldDescription );
	}

	public function SetMarked( value : Bool )
	{
		m_marked = value;
		m_background.SetTintColor( ( ( m_marked ) ? ( c_markColor ) : ( c_initialColor ) ) );
	}

	public function IsMarked() : Bool
	{
		return m_marked;
	}

	protected event OnSelected( parent : weak< ListItemController > ) {}

	protected event OnDeselected( parent : weak< ListItemController > ) {}

	protected event OnRelease( e : inkPointerEvent )
	{
		SetMarked( true );
	}

	protected event OnHoverOver( e : inkPointerEvent )
	{
		if( !( m_marked ) )
		{
			m_background.SetTintColor( c_selectionColor );
		}
	}

	protected event OnHoverOut( e : inkPointerEvent )
	{
		if( !( m_marked ) )
		{
			m_background.SetTintColor( c_initialColor );
		}
	}

}

