// Project Lab - NHTV IGAD
//////////////////////////////////////////
// Author: Yoshi van Belkom - 130118
//////////////////////////////////////////

#include "SkillTreeEditorPrivatePCH.h"
#include "SkillTreeDetailsCustomization.h"
#include "PhysicsEngine/BodySetup.h"
#include "Editor/Documentation/Public/IDocumentation.h"
#include "PropertyRestriction.h"
#include "PropertyCustomizationHelpers.h"
#include "SkillTreeObject.h"
#include "SkillObject.h"

#define LOCTEXT_NAMESPACE "SkillTreeEditor"

/////////////////////////////////////////////////////
// FSkillTreeDetailsCustomization

// Makes a new instance of this detail layout class for a specific detail view requesting it.
TSharedRef<IDetailCustomization> FSkillTreeDetailsCustomization::MakeInstance()
{
	return MakeInstanceForSkillTreeEditor( );
}

// Makes a new instance of this detail layout class for a specific detail view requesting it.
TSharedRef<IDetailCustomization> FSkillTreeDetailsCustomization::MakeInstanceForSkillTreeEditor( )
{
	return MakeShareable( new FSkillTreeDetailsCustomization( ) );
}

FSkillTreeDetailsCustomization::FSkillTreeDetailsCustomization( )
{
}

FDetailWidgetRow& FSkillTreeDetailsCustomization::GenerateWarningRow( IDetailCategoryBuilder& a_warningCategory, bool a_experimental, const FText& a_warningText, const FText& a_tooltip, const FString& a_excerptLink, const FString& a_excerptName )
{
	const FText searchString = a_warningText;
	const FSlateBrush* warningIcon = FEditorStyle::GetBrush( a_experimental ? "PropertyEditor.ExperimentalClass" : "PropertyEditor.EarlyAccessClass" );

	FDetailWidgetRow& warningRow = a_warningCategory.AddCustomRow( searchString )
		.WholeRowContent()
		[
			SNew( SHorizontalBox )
			.ToolTip( IDocumentation::Get()->CreateToolTip( a_tooltip, nullptr, a_excerptLink, a_excerptName ) )
			.Visibility( EVisibility::Visible )

			+ SHorizontalBox::Slot()
			.VAlign( VAlign_Center )
			.AutoWidth()
			.Padding( 4.0f, 0.0f, 0.0f, 0.0f )
			[SNew( SImage )
			.Image( warningIcon )
			]

			+ SHorizontalBox::Slot()
				.VAlign( VAlign_Center )
				.AutoWidth()
				.Padding( 4.0f, 0.0f, 0.0f, 0.0f )
				[
					SNew( STextBlock )
					.Text( a_warningText )
					.Font( IDetailLayoutBuilder::GetDetailFont() )
				]
		];

	return warningRow;
}

void FSkillTreeDetailsCustomization::CustomizeDetails( IDetailLayoutBuilder& a_detailLayout )
{
	IDetailCategoryBuilder& skillTreeCategory = a_detailLayout.EditCategory( "SkillTree", FText::GetEmpty(), ECategoryPriority::Important );
	BuildSkillTreeSection( skillTreeCategory, a_detailLayout );
}

// Makes sure Skill Tree properties are near the top.
void FSkillTreeDetailsCustomization::BuildSkillTreeSection( IDetailCategoryBuilder& a_skillTreeCategory, IDetailLayoutBuilder& a_detailLayout )
{
	a_skillTreeCategory.AddProperty( GET_MEMBER_NAME_CHECKED( USkillTreeObject, skills ) );
}

/////////////////////////////////////////////////////
// FSkillDetailsCustomization

// Makes a new instance of this detail layout class for a specific detail view requesting it.
TSharedRef<IDetailCustomization> FSkillDetailsCustomization::MakeInstance()
{
	return MakeInstanceForSkillTreeEditor( );
}

// Makes a new instance of this detail layout class for a specific detail view requesting it.
TSharedRef<IDetailCustomization> FSkillDetailsCustomization::MakeInstanceForSkillTreeEditor( )
{
	return MakeShareable( new FSkillDetailsCustomization( ) );
}

FSkillDetailsCustomization::FSkillDetailsCustomization( )
{
}

FDetailWidgetRow& FSkillDetailsCustomization::GenerateWarningRow( IDetailCategoryBuilder& a_warningCategory, bool a_experimental, const FText& a_warningText, const FText& a_tooltip, const FString& a_excerptLink, const FString& a_excerptName )
{
	const FText searchString = a_warningText;
	const FSlateBrush* warningIcon = FEditorStyle::GetBrush( a_experimental ? "PropertyEditor.ExperimentalClass" : "PropertyEditor.EarlyAccessClass" );

	FDetailWidgetRow& warningRow = a_warningCategory.AddCustomRow( searchString )
		.WholeRowContent()
		[
			SNew( SHorizontalBox )
			.ToolTip( IDocumentation::Get()->CreateToolTip( a_tooltip, nullptr, a_excerptLink, a_excerptName ) )
			.Visibility( EVisibility::Visible )

			+ SHorizontalBox::Slot()
			.VAlign( VAlign_Center )
			.AutoWidth()
			.Padding( 4.0f, 0.0f, 0.0f, 0.0f )
			[SNew( SImage )
			.Image( warningIcon )
			]

			+ SHorizontalBox::Slot()
				.VAlign( VAlign_Center )
				.AutoWidth()
				.Padding( 4.0f, 0.0f, 0.0f, 0.0f )
				[
					SNew( STextBlock )
					.Text( a_warningText )
					.Font( IDetailLayoutBuilder::GetDetailFont() )
				]
		];

	return warningRow;
}

void FSkillDetailsCustomization::CustomizeDetails( IDetailLayoutBuilder& a_detailLayout )
{
	IDetailCategoryBuilder& skillCategory = a_detailLayout.EditCategory( "Skill", FText::GetEmpty(), ECategoryPriority::Important );
	BuildSkillSection( skillCategory, a_detailLayout );
}

// Makes sure Skill properties are near the top.
void FSkillDetailsCustomization::BuildSkillSection( IDetailCategoryBuilder& a_skillCategory, IDetailLayoutBuilder& a_detailLayout )
{
	a_skillCategory.AddProperty( GET_MEMBER_NAME_CHECKED( USkillObject, hexMap ) );
}

#undef LOCTEXT_NAMESPACE
