class NewsFeedMenuWidgetController extends inkLogicController
{
	[ category = "OBSOLETE - Widget Paths" ]
	protected editable var m_bannersListWidgetPath : CName;
	default m_bannersListWidgetPath = 'banners';
	[ category = "Widget Refs" ]
	protected editable var m_bannersListWidget : inkWidgetRef;
	protected var m_isInitialized : Bool;
	private var m_bannerWidgetsData : array< SBannerWidgetPackage >;
	protected var m_fullBannerWidgetData : SBannerWidgetPackage;

	protected event OnInitialize()
	{
		m_fullBannerWidgetData.widgetTweakDBID = T"DevicesUIDefinitions.FullBannerWidget";
	}

	public virtual function InitializeBanners( gameController : ComputerInkGameController, const widgetsData : ref< array< SBannerWidgetPackage > > )
	{
		var i : Int32;
		var widget : inkWidget;
		HideBannerWidgets();
		for( i = 0; i < widgetsData.Size(); i += 1 )
		{
			widget = GetBannerWidget( widgetsData[ i ], gameController );
			if( widget == NULL )
			{
				widget = CreateBannerWidget( gameController, inkWidgetRef.Get( m_bannersListWidget ), widgetsData[ i ] );
				AddBannerWidget( widget, widgetsData[ i ], gameController );
			}
			InitializeBannerWidget( gameController, widget, widgetsData[ i ] );
		}
		m_isInitialized = true;
	}

	public function CreateBannerWidget( gameController : ComputerInkGameController, parentWidget : weak< inkWidget >, const widgetData : ref< SBannerWidgetPackage > ) : weak< inkWidget >
	{
		var widget : inkWidget;
		var screenDef : ScreenDefinitionPackage;
		screenDef = gameController.GetScreenDefinition();
		widget = gameController.FindWidgetInLibrary( parentWidget, TweakDBInterface.GetWidgetDefinitionRecord( widgetData.widgetTweakDBID ), screenDef.screenDefinition.ComputerScreenType(), screenDef.style, widgetData.libraryID, widgetData.libraryPath );
		if( widget != NULL )
		{
			widget.SetSizeRule( inkESizeRule.Stretch );
		}
		return widget;
	}

	protected function InitializeBannerWidget( gameController : ComputerInkGameController, widget : inkWidget, const widgetData : ref< SBannerWidgetPackage > )
	{
		var controller : ComputerBannerWidgetController;
		controller = ( ( ComputerBannerWidgetController )( widget.GetController() ) );
		if( controller != NULL )
		{
			controller.Initialize( gameController, widgetData );
		}
		widget.SetVisible( true );
	}

	protected function GetBannerWidget( widgetData : SBannerWidgetPackage, gameController : ComputerInkGameController ) : weak< inkWidget >
	{
		var i : Int32;
		var screenDef : ScreenDefinitionPackage;
		screenDef = gameController.GetScreenDefinition();
		widgetData.libraryID = gameController.GetCurrentFullLibraryID( TweakDBInterface.GetWidgetDefinitionRecord( widgetData.widgetTweakDBID ), screenDef.screenDefinition.ComputerScreenType(), screenDef.style );
		for( i = 0; i < m_bannerWidgetsData.Size(); i += 1 )
		{
			if( ( ( ( m_bannerWidgetsData[ i ].ownerID == widgetData.ownerID && m_bannerWidgetsData[ i ].widgetName == widgetData.widgetName ) && ( m_bannerWidgetsData[ i ].widgetTweakDBID == widgetData.widgetTweakDBID ) ) && m_bannerWidgetsData[ i ].libraryPath == widgetData.libraryPath ) && m_bannerWidgetsData[ i ].libraryID == widgetData.libraryID )
			{
				return m_bannerWidgetsData[ i ].widget;
			}
		}
		return NULL;
	}

	protected function AddBannerWidget( widget : inkWidget, widgetData : SBannerWidgetPackage, gameController : ComputerInkGameController ) : weak< inkWidget >
	{
		var screenDef : ScreenDefinitionPackage;
		screenDef = gameController.GetScreenDefinition();
		widgetData.libraryID = gameController.GetCurrentFullLibraryID( TweakDBInterface.GetWidgetDefinitionRecord( widgetData.widgetTweakDBID ), screenDef.screenDefinition.ComputerScreenType(), screenDef.style );
		widgetData.widget = widget;
		m_bannerWidgetsData.PushBack( widgetData );
		return widgetData.widget;
	}

	public function HideBannerWidgets()
	{
		var i : Int32;
		for( i = 0; i < m_bannerWidgetsData.Size(); i += 1 )
		{
			if( m_bannerWidgetsData[ i ].widget != NULL )
			{
				m_bannerWidgetsData[ i ].widget.SetVisible( false );
			}
		}
	}

	public function ShowFullBanner( gameController : ComputerInkGameController, const widgetData : ref< SBannerWidgetPackage > )
	{
		var controller : ComputerFullBannerWidgetController;
		var screenDef : ScreenDefinitionPackage;
		var widgetRecord : WidgetDefinition_Record;
		var libraryID : CName;
		var libraryPath : ResRef;
		SWidgetPackageBase.ResolveWidgetTweakDBData( m_fullBannerWidgetData.widgetTweakDBID, libraryID, libraryPath );
		widgetRecord = TweakDBInterface.GetWidgetDefinitionRecord( m_fullBannerWidgetData.widgetTweakDBID );
		if( ( ( m_fullBannerWidgetData.widget == NULL ) || m_fullBannerWidgetData.libraryID != libraryID ) || m_fullBannerWidgetData.libraryPath != libraryPath )
		{
			if( m_fullBannerWidgetData.widget != NULL )
			{
				( ( inkCompoundWidget )( gameController.GetMainLayoutController().GetMenuContainer() ) ).RemoveChild( m_fullBannerWidgetData.widget );
			}
			screenDef = gameController.GetScreenDefinition();
			m_fullBannerWidgetData.widget = gameController.FindWidgetInLibrary( gameController.GetMainLayoutController().GetMenuContainer(), widgetRecord, screenDef.screenDefinition.ComputerScreenType(), screenDef.style, widgetData.libraryID, widgetData.libraryPath );
			m_fullBannerWidgetData.libraryPath = libraryPath;
			m_fullBannerWidgetData.libraryID = libraryID;
		}
		controller = ( ( ComputerFullBannerWidgetController )( m_fullBannerWidgetData.widget.GetController() ) );
		if( controller )
		{
			inkWidgetRef.SetVisible( m_bannersListWidget, false );
			m_fullBannerWidgetData.widget.SetVisible( true );
			controller.Initialize( gameController, widgetData );
		}
	}

	public function HideFullBanner()
	{
		m_fullBannerWidgetData.widget.SetVisible( false );
		inkWidgetRef.SetVisible( m_bannersListWidget, true );
	}

}

