enum CustomButtonType
{
	UnlockAllVehicles = 0,
	ShowAllPoiMappins = 1,
	DiscoverAllPoiMappins = 2,
}

class BuildButtonItemController extends inkButtonDpadSupportedController
{
	private var m_associatedBuild : gamedataBuildType;

	protected event OnInitialize()
	{
		super.OnInitialize();
	}

	public function SetButtonDetails( const argText : ref< String >, type : gamedataBuildType )
	{
		var currListText : weak< inkText >;
		m_rootWidget = ( ( inkCanvas )( GetRootWidget() ) );
		currListText = ( ( inkText )( m_rootWidget.GetWidget( 'textLabel' ) ) );
		currListText.SetText( argText );
		m_associatedBuild = type;
	}

	public function GetAssociatedBuild() : gamedataBuildType
	{
		return m_associatedBuild;
	}

}

class buildsWidgetGameController extends inkGameController
{
	private var m_horizontalPanelsList : array< weak< inkHorizontalPanel > >;

	protected event OnInitialize()
	{
		var i, j : Int32;
		var amountOfLists : Int32;
		var tempList : weak< inkHorizontalPanel >;
		var verticalPanel : weak< inkVerticalPanel >;
		var devBuildList : array< array< gamedataBuildType > >;
		devBuildList = GetProperDevBuildList();
		verticalPanel = ( ( inkVerticalPanel )( GetWidget( 'SubCanvas\VerticalPanel' ) ) );
		amountOfLists = devBuildList.Size() + 1;
		for( i = 0; i < amountOfLists; i += 1 )
		{
			tempList = ( ( inkHorizontalPanel )( SpawnFromLocal( verticalPanel, 'BuildsList' ) ) );
			m_horizontalPanelsList.PushBack( tempList );
		}
		for( i = 0; i < devBuildList.Size(); i += 1 )
		{
			for( j = 0; j < devBuildList[ i ].Size(); j += 1 )
			{
				CreateBuildButton( i, devBuildList[ i ][ j ] );
			}
		}
		CreateCustomButton( amountOfLists - 1, CustomButtonType.UnlockAllVehicles );
		CreateCustomButton( amountOfLists - 1, CustomButtonType.ShowAllPoiMappins );
		CreateCustomButton( amountOfLists - 1, CustomButtonType.DiscoverAllPoiMappins );
		SetCursorOverWidget( m_horizontalPanelsList[ 0 ].GetWidget( 0 ) );
	}

	private function GetProperDevBuildList() : array< array< gamedataBuildType > >
	{
		var arrayOfDevBuilds : array< array< gamedataBuildType > >;
		var devBuilds : array< gamedataBuildType >;
		devBuilds.Clear();
		devBuilds.PushBack( gamedataBuildType.Normal_20_Ranged );
		devBuilds.PushBack( gamedataBuildType.Normal_20_Netrunner );
		devBuilds.PushBack( gamedataBuildType.Normal_20_Melee );
		arrayOfDevBuilds.PushBack( devBuilds );
		devBuilds.Clear();
		devBuilds.PushBack( gamedataBuildType.Hard_20_Body );
		devBuilds.PushBack( gamedataBuildType.Hard_20_Reflex );
		devBuilds.PushBack( gamedataBuildType.Hard_20_Intelligence );
		arrayOfDevBuilds.PushBack( devBuilds );
		devBuilds.Clear();
		devBuilds.PushBack( gamedataBuildType.Hard_30_BodyTech );
		devBuilds.PushBack( gamedataBuildType.Hard_30_Reflex );
		devBuilds.PushBack( gamedataBuildType.Hard_30_IntBody );
		arrayOfDevBuilds.PushBack( devBuilds );
		devBuilds.Clear();
		devBuilds.PushBack( gamedataBuildType.VHard_50_IntRef );
		devBuilds.PushBack( gamedataBuildType.VHard_50_RefBody );
		devBuilds.PushBack( gamedataBuildType.VHard_50_TechCool );
		devBuilds.PushBack( gamedataBuildType.VHard_50_CoolRef );
		devBuilds.PushBack( gamedataBuildType.VHard_50_BodyCool );
		devBuilds.PushBack( gamedataBuildType.VHard_50_IntTech );
		devBuilds.PushBack( gamedataBuildType.VHard_50_RefTech );
		arrayOfDevBuilds.PushBack( devBuilds );
		devBuilds.Clear();
		devBuilds.PushBack( gamedataBuildType.EP1_Standalone_Street_MA_StartingBuild );
		devBuilds.PushBack( gamedataBuildType.EP1_Standalone_Street_WA_StartingBuild );
		devBuilds.PushBack( gamedataBuildType.EP1_Standalone_Corpo_MA_StartingBuild );
		devBuilds.PushBack( gamedataBuildType.EP1_Standalone_Corpo_WA_StartingBuild );
		devBuilds.PushBack( gamedataBuildType.EP1_Standalone_Nomad_MA_StartingBuild );
		devBuilds.PushBack( gamedataBuildType.EP1_Standalone_Nomad_WA_StartingBuild );
		arrayOfDevBuilds.PushBack( devBuilds );
		devBuilds.Clear();
		devBuilds.PushBack( gamedataBuildType.Story_5 );
		arrayOfDevBuilds.PushBack( devBuilds );
		devBuilds.Clear();
		devBuilds.PushBack( gamedataBuildType.Weak_10 );
		devBuilds.PushBack( gamedataBuildType.Weak_20_Cool );
		devBuilds.PushBack( gamedataBuildType.Weak_30 );
		arrayOfDevBuilds.PushBack( devBuilds );
		devBuilds.Clear();
		devBuilds.PushBack( gamedataBuildType.Avg_10_Int_Netrunner );
		arrayOfDevBuilds.PushBack( devBuilds );
		devBuilds.Clear();
		devBuilds.PushBack( gamedataBuildType.Str_5_Tank );
		devBuilds.PushBack( gamedataBuildType.Str_10_Tank );
		devBuilds.PushBack( gamedataBuildType.Str_30_Cool_Assassin );
		arrayOfDevBuilds.PushBack( devBuilds );
		return arrayOfDevBuilds;
	}

	private function CreateBuildButton( rowIdx : Int32, type : gamedataBuildType )
	{
		var currButton : weak< inkCanvas >;
		var currLogic : weak< BuildButtonItemController >;
		var buildString : String;
		if( rowIdx >= m_horizontalPanelsList.Size() )
		{
			return;
		}
		currButton = ( ( inkCanvas )( SpawnFromLocal( m_horizontalPanelsList[ rowIdx ], 'BuildButton' ) ) );
		currButton.RegisterToCallback( 'OnRelease', this, 'OnBuildsMenuSelectBuild' );
		currButton.RegisterToCallback( 'OnEnter', this, 'OnBuildMenuEnter' );
		currButton.RegisterToCallback( 'OnLeave', this, 'OnBuildMenuExit' );
		currLogic = ( ( BuildButtonItemController )( currButton.GetController() ) );
		buildString = EnumValueToString( "gamedataBuildType", ( ( Int32 )( type ) ) );
		currLogic.SetButtonDetails( buildString, type );
		SetTooltip( type );
	}

	private function CreateCustomButton( rowIdx : Int32, type : CustomButtonType )
	{
		var currButton : weak< inkCanvas >;
		var currLogic : weak< BuildButtonItemController >;
		if( rowIdx >= m_horizontalPanelsList.Size() )
		{
			return;
		}
		currButton = ( ( inkCanvas )( SpawnFromLocal( m_horizontalPanelsList[ rowIdx ], 'BuildButton' ) ) );
		switch( type )
		{
			case CustomButtonType.UnlockAllVehicles:
				currButton.RegisterToCallback( 'OnRelease', this, 'OnClickedCutonButton_UnlockAllVehicles' );
			currLogic = ( ( BuildButtonItemController )( currButton.GetController() ) );
			currLogic.SetButtonDetails( "Unlock all vehicles", gamedataBuildType.Invalid );
			break;
			case CustomButtonType.ShowAllPoiMappins:
				currButton.RegisterToCallback( 'OnRelease', this, 'OnClickedCutonButton_ShowAllPoiMappins' );
			currLogic = ( ( BuildButtonItemController )( currButton.GetController() ) );
			currLogic.SetButtonDetails( "Show all POIs", gamedataBuildType.Invalid );
			break;
			case CustomButtonType.DiscoverAllPoiMappins:
				currButton.RegisterToCallback( 'OnRelease', this, 'OnClickedCutonButton_DiscoverAllPoiMappins' );
			currLogic = ( ( BuildButtonItemController )( currButton.GetController() ) );
			currLogic.SetButtonDetails( "Discover POIs", gamedataBuildType.Invalid );
			break;
		}
	}

	public function OnClickedCutonButton_UnlockAllVehicles( e : inkPointerEvent )
	{
		var vehicleSystem : VehicleSystem;
		if( e.IsAction( 'click' ) )
		{
			DebugGiveHotkeys( ( ( GameObject )( GetOwnerEntity() ) ).GetGame() );
			vehicleSystem = GameInstance.GetVehicleSystem( ( ( GameObject )( GetOwnerEntity() ) ).GetGame() );
			if( vehicleSystem )
			{
				vehicleSystem.EnableAllPlayerVehicles();
			}
		}
	}

	public function OnClickedCutonButton_ShowAllPoiMappins( e : inkPointerEvent )
	{
		var journalManager : JournalManager;
		if( e.IsAction( 'click' ) )
		{
			journalManager = GameInstance.GetJournalManager( ( ( GameObject )( GetOwnerEntity() ) ).GetGame() );
			if( journalManager )
			{
				journalManager.DebugShowAllPoiMappins();
			}
		}
	}

	public function OnClickedCutonButton_DiscoverAllPoiMappins( e : inkPointerEvent )
	{
		var mappinSystem : MappinSystem;
		if( e.IsAction( 'click' ) )
		{
			mappinSystem = GameInstance.GetMappinSystem( ( ( GameObject )( GetOwnerEntity() ) ).GetGame() );
			if( mappinSystem )
			{
				mappinSystem.DebugDiscoverAllPoiMappins();
			}
		}
	}

	public function OnBuildsMenuSelectBuild( e : inkPointerEvent )
	{
		var PDS : PlayerDevelopmentSystem;
		var request : SetProgressionBuild;
		var button : weak< inkCanvas >;
		var controller : weak< BuildButtonItemController >;
		var player : PlayerPuppet;
		player = GetPlayer( ( ( GameObject )( GetOwnerEntity() ) ).GetGame() );
		if( e.IsAction( 'click' ) )
		{
			DebugGiveHotkeys( player.GetGame() );
			PDS = ( ( PlayerDevelopmentSystem )( GameInstance.GetScriptableSystemsContainer( ( ( GameObject )( GetOwnerEntity() ) ).GetGame() ).Get( 'PlayerDevelopmentSystem' ) ) );
			if( PDS.GetIsProgressionBuildSetCompleted( player ) )
			{
				button = ( ( inkCanvas )( e.GetCurrentTarget() ) );
				controller = ( ( BuildButtonItemController )( button.GetController() ) );
				request = new SetProgressionBuild;
				request.m_isDebug = true;
				request.Set( player, controller.GetAssociatedBuild() );
				PDS.QueueRequest( request );
				PDS.SetIsProgressionBuildSetCompleted( player, false );
			}
		}
	}

	private function SetTooltip( type : gamedataBuildType )
	{
		var tooltipWidgetText : weak< inkText >;
		var tooltipWidgetText2 : weak< inkText >;
		var build : weak< ProgressionBuild_Record >;
		var startingProficiencies : array< weak< BuildProficiency_Record > >;
		var startingPerks : array< weak< BuildPerk_Record > >;
		var startingAttributes : array< weak< BuildAttribute_Record > >;
		var startingItems : array< weak< InventoryItem_Record > >;
		var startingEquipment : array< weak< BuildEquipment_Record > >;
		var startingCyberware : array< weak< BuildCyberware_Record > >;
		var startingPrograms : array< weak< BuildProgram_Record > >;
		var craftBook : weak< Craftable_Record >;
		var tooltip : String;
		var i : Int32;
		var craftingRecipes : array< weak< Item_Record > >;
		tooltip = "";
		tooltipWidgetText = ( ( inkText )( GetWidget( 'SubCanvas\tooltip\text_wrapper\tooltipText' ) ) );
		tooltipWidgetText2 = ( ( inkText )( GetWidget( 'SubCanvas\tooltip\text_wrapper\tooltipText2' ) ) );
		tooltipWidgetText.SetLetterCase( textLetterCase.UpperCase );
		tooltipWidgetText2.SetLetterCase( textLetterCase.UpperCase );
		build = TweakDBInterface.GetProgressionBuildRecord( TDBID.Create( "ProgressionBuilds." + EnumValueToString( "gamedataBuildType", ( ( Int32 )( type ) ) ) ) );
		tooltip = ( tooltip + EnumValueToString( "gamedataBuildType", ( ( Int32 )( type ) ) ) ) + "\n\n";
		build.StartingProficiencies( startingProficiencies );
		build.StartingPerks( startingPerks );
		build.StartingAttributes( startingAttributes );
		build.StartingItems( startingItems );
		build.StartingEquipment( startingEquipment );
		build.StartingCyberware( startingCyberware );
		build.StartingPrograms( startingPrograms );
		craftBook = build.CraftBook();
		craftBook.CraftableItem( craftingRecipes );
		tooltip = tooltip + "CHARACTER:\n";
		for( i = 0; i < startingProficiencies.Size(); i += 1 )
		{
			if( startingProficiencies[ i ].Proficiency().DisplayName() == "Level" )
			{
				tooltip = ( ( ( tooltip + startingProficiencies[ i ].Proficiency().DisplayName() ) + " " ) + startingProficiencies[ i ].Level() ) + "\n";
			}
		}
		tooltip = tooltip + "\n";
		tooltip = tooltip + "ATTRIBUTES:\n";
		for( i = 0; i < startingAttributes.Size(); i += 1 )
		{
			tooltip = ( ( ( tooltip + EnumValueToString( "gamedataStatType", ( ( Int64 )( startingAttributes[ i ].Attribute().StatType() ) ) ) ) + " " ) + startingAttributes[ i ].Level() ) + "\n";
		}
		tooltip = tooltip + "\n";
		tooltip = tooltip + "SKILLS:\n";
		for( i = 0; i < startingProficiencies.Size(); i += 1 )
		{
			if( startingProficiencies[ i ].Proficiency().DisplayName() != "Level" )
			{
				tooltip = ( ( ( tooltip + startingProficiencies[ i ].Proficiency().DisplayName() ) + " " ) + startingProficiencies[ i ].Level() ) + "\n";
			}
		}
		tooltip = tooltip + "\n";
		tooltip = tooltip + "CRAFTING BLUEPRINTS:\n";
		for( i = 0; i < craftingRecipes.Size(); i += 1 )
		{
			tooltip = ( tooltip + NameToString( craftingRecipes[ i ].DisplayName() ) ) + "\n";
		}
		tooltip = tooltip + "\n";
		tooltipWidgetText.SetText( tooltip );
		tooltip = "";
		tooltip = tooltip + "CYBERWARE:\n";
		for( i = 0; i < startingCyberware.Size(); i += 1 )
		{
			tooltip = ( tooltip + NameToString( startingCyberware[ i ].Cyberware().DisplayName() ) ) + "\n";
		}
		tooltip = tooltip + "\n";
		tooltip = tooltip + "PROGRAMS:\n";
		for( i = 0; i < startingPrograms.Size(); i += 1 )
		{
			tooltip = ( tooltip + NameToString( startingPrograms[ i ].Program().DisplayName() ) ) + "\n";
		}
		tooltip = tooltip + "\n";
		tooltip = tooltip + "INVENTORY:\n";
		for( i = 0; i < startingEquipment.Size(); i += 1 )
		{
			tooltip = ( tooltip + NameToString( startingEquipment[ i ].Equipment().DisplayName() ) ) + "\n";
		}
		for( i = 0; i < startingItems.Size(); i += 1 )
		{
			if( startingItems[ i ].Quantity() > 1 )
			{
				tooltip = ( ( ( tooltip + NameToString( startingItems[ i ].Item().DisplayName() ) ) + " (" ) + startingItems[ i ].Quantity() ) + ")\n";
			}
			else
			{
				tooltip = ( tooltip + NameToString( startingItems[ i ].Item().DisplayName() ) ) + "\n";
			}
		}
		tooltip = tooltip + "\n";
		tooltipWidgetText2.SetText( tooltip );
	}

	private function ShowTooltip( val : Bool )
	{
		var tooltipWidget : weak< inkCanvas >;
		tooltipWidget = ( ( inkCanvas )( GetWidget( 'SubCanvas\tooltip' ) ) );
		tooltipWidget.SetVisible( val );
	}

	public function OnBuildMenuEnter( e : inkPointerEvent )
	{
		var button : weak< inkWidget >;
		var controller : weak< BuildButtonItemController >;
		button = ( ( inkWidget )( e.GetCurrentTarget() ) );
		controller = ( ( BuildButtonItemController )( button.GetController() ) );
		SetTooltip( controller.GetAssociatedBuild() );
		ShowTooltip( true );
	}

	public function OnBuildMenuExit( e : inkPointerEvent )
	{
		ShowTooltip( false );
	}

}

