Skip to content

Commit

Permalink
Added custom details panel code
Browse files Browse the repository at this point in the history
  • Loading branch information
orfeasel committed Nov 5, 2018
1 parent a985af3 commit 65673f5
Show file tree
Hide file tree
Showing 17 changed files with 319 additions and 0 deletions.
Binary file added CustomDetailsPanel/BP_FancyCube.uasset
Binary file not shown.
20 changes: 20 additions & 0 deletions CustomDetailsPanel/BlogpostModule/BlogpostModule.Build.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using UnrealBuildTool;

public class BlogpostModule : ModuleRules
{
public BlogpostModule(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;

//Public module names that this module uses.
//In case you would like to add various classes that you're going to use in your game
//you should add the core,coreuobject and engine dependencies.
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine","PropertyEditor","Slate","SlateCore"});

//The path for the header files
PublicIncludePaths.AddRange(new string[] {"BlogpostModule/Public"});

//The path for the source files
PrivateIncludePaths.AddRange(new string[] {"BlogpostModule/Private"});
}
}
26 changes: 26 additions & 0 deletions CustomDetailsPanel/BlogpostModule/Private/BlogpostModule.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "BlogpostModule.h"
#include "FancyCube.h"
#include "CustomDetailsPanel.h"
#include "PropertyEditorModule.h"

DEFINE_LOG_CATEGORY(BlogpostModule);

#define LOCTEXT_NAMESPACE "FBlogpostModule"

void FBlogpostModule::StartupModule()
{
UE_LOG(BlogpostModule, Warning, TEXT("BlogpostModule module has started!"));
//Get the property module
FPropertyEditorModule& PropertyModule = FModuleManager::LoadModuleChecked<FPropertyEditorModule>("PropertyEditor");
//Register the custom details panel we have created
PropertyModule.RegisterCustomClassLayout(AFancyCube::StaticClass()->GetFName(), FOnGetDetailCustomizationInstance::CreateStatic(&FCustomDetailsPanel::MakeInstance));
}

void FBlogpostModule::ShutdownModule()
{
UE_LOG(BlogpostModule, Warning, TEXT("BlogpostModule module has shut down"));
}

#undef LOCTEXT_NAMESPACE

IMPLEMENT_MODULE(FBlogpostModule,BlogpostModule)
66 changes: 66 additions & 0 deletions CustomDetailsPanel/BlogpostModule/Private/CustomDetailsPanel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Fill out your copyright notice in the Description page of Project Settings.

#include "CustomDetailsPanel.h"
#include "IDetailsView.h"
#include "DetailLayoutBuilder.h"
#include "DetailWidgetRow.h"
#include "DetailCategoryBuilder.h"
#include "Widgets/SNullWidget.h"
#include "Widgets/Text/STextBlock.h"
#include "Widgets/Input/SButton.h"
#include "Widgets/SBoxPanel.h"
#include "Text.h"
#include "FancyCube.h"
#include "UObject/Class.h"


TSharedRef<IDetailCustomization> FCustomDetailsPanel::MakeInstance()
{
return MakeShareable(new FCustomDetailsPanel);
}

void FCustomDetailsPanel::CustomizeDetails(IDetailLayoutBuilder& DetailBuilder)
{
//Edits a category. If it doesn't exist it creates a new one
IDetailCategoryBuilder& CustomCategory = DetailBuilder.EditCategory("CustomCategory");

//Store the currently selected objects from the viewport to the SelectedObjects array.
DetailBuilder.GetObjectsBeingCustomized(SelectedObjects);

//Adding a custom row
CustomCategory.AddCustomRow(FText::FromString("Outline Color Changing Category"))
.ValueContent()
.VAlign(VAlign_Center) // set vertical alignment to center
.MaxDesiredWidth(250)
[ //With this operator we declare a new slate object inside our widget row
//In this case the slate object is a button
SNew(SButton)
.VAlign(VAlign_Center)
.OnClicked(this, &FCustomDetailsPanel::ClickedOnButton) //Binding the OnClick function we want to execute when this object is clicked
.Content()
[ //We create a new slate object inside our button. In this case a text block with the content of "Change Color"
//If you ever coded a UMG button with a text on top of it you will notice that the process is quite the same
//Meaning, you first declare a button which has various events and properties and then you place a Text Block widget
//inside the button's widget to display text
SNew(STextBlock).Text(FText::FromString("Change Color!"))
]
];

}

FReply FCustomDetailsPanel::ClickedOnButton()
{
if (GEngine)
{
for (const TWeakObjectPtr<UObject>& Object : SelectedObjects)
{
AFancyCube* FancyCube = Cast<AFancyCube>(Object.Get());
if (FancyCube)
{
FancyCube->AssignColor(FLinearColor::MakeRandomColor());
}
}
GLog->Log("fancy cubes got a nice random color!");
}
return FReply::Handled();
}
37 changes: 37 additions & 0 deletions CustomDetailsPanel/BlogpostModule/Private/FancyCube.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Fill out your copyright notice in the Description page of Project Settings.

#include "FancyCube.h"


// Sets default values
AFancyCube::AFancyCube()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
CubeSM = CreateDefaultSubobject<UStaticMeshComponent>("CubeSM");
}

void AFancyCube::AssignColor(FLinearColor NewColor)
{
if (CubeSM)
{
UMaterialInstanceDynamic* MID = CubeSM->CreateAndSetMaterialInstanceDynamic(0);
MID->SetVectorParameterValue("BaseColor", NewColor);
}

}

// Called when the game starts or when spawned
void AFancyCube::BeginPlay()
{
Super::BeginPlay();

}

// Called every frame
void AFancyCube::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);

}

16 changes: 16 additions & 0 deletions CustomDetailsPanel/BlogpostModule/Public/BlogpostModule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include "ModuleManager.h"

DECLARE_LOG_CATEGORY_EXTERN(BlogpostModule, All, All);

class FBlogpostModule : public IModuleInterface
{
public:

/* This will get called when the editor loads the module */
virtual void StartupModule() override;

/* This will get called when the editor unloads the module */
virtual void ShutdownModule() override;
};
28 changes: 28 additions & 0 deletions CustomDetailsPanel/BlogpostModule/Public/CustomDetailsPanel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Input/Reply.h"
#include "IDetailCustomization.h"

class FCustomDetailsPanel : public IDetailCustomization
{

private:

/* Contains references to all selected objects inside in the viewport */
TArray<TWeakObjectPtr<UObject>> SelectedObjects;

public:

/* Makes a new instance of this detail layout class for a specific detail view requesting it */
static TSharedRef<IDetailCustomization> MakeInstance();

/* IDetalCustomization interface */
virtual void CustomizeDetails(IDetailLayoutBuilder& DetailBuilder) override;

/* The code that fires when we click the "ChangeColor" button */
FReply ClickedOnButton();

};
33 changes: 33 additions & 0 deletions CustomDetailsPanel/BlogpostModule/Public/FancyCube.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "FancyCube.generated.h"

UCLASS()
class BLOGPOSTMODULE_API AFancyCube : public AActor
{
GENERATED_BODY()

public:
// Sets default values for this actor's properties
AFancyCube();

void AssignColor(FLinearColor NewColor);

protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;

UPROPERTY(VisibleAnywhere)
UStaticMeshComponent* CubeSM;

public:
// Called every frame
virtual void Tick(float DeltaTime) override;



};
14 changes: 14 additions & 0 deletions CustomDetailsPanel/FancyDetailsPanel.Target.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Fill out your copyright notice in the Description page of Project Settings.

using UnrealBuildTool;
using System.Collections.Generic;

public class FancyDetailsPanelTarget : TargetRules
{
public FancyDetailsPanelTarget(TargetInfo Target) : base(Target)
{
Type = TargetType.Game;

ExtraModuleNames.AddRange( new string[] { "FancyDetailsPanel" } );
}
}
23 changes: 23 additions & 0 deletions CustomDetailsPanel/FancyDetailsPanel/FancyDetailsPanel.Build.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Fill out your copyright notice in the Description page of Project Settings.

using UnrealBuildTool;

public class FancyDetailsPanel : ModuleRules
{
public FancyDetailsPanel(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;

PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore","BlogpostModule" });

PrivateDependencyModuleNames.AddRange(new string[] { });

// Uncomment if you are using Slate UI
// PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });

// Uncomment if you are using online features
// PrivateDependencyModuleNames.Add("OnlineSubsystem");

// To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true
}
}
6 changes: 6 additions & 0 deletions CustomDetailsPanel/FancyDetailsPanel/FancyDetailsPanel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Fill out your copyright notice in the Description page of Project Settings.

#include "FancyDetailsPanel.h"
#include "Modules/ModuleManager.h"

IMPLEMENT_PRIMARY_GAME_MODULE( FDefaultGameModuleImpl, FancyDetailsPanel, "FancyDetailsPanel" );
6 changes: 6 additions & 0 deletions CustomDetailsPanel/FancyDetailsPanel/FancyDetailsPanel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Fill out your copyright notice in the Description page of Project Settings.

#include "FancyDetailsPanelGameModeBase.h"




Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/GameModeBase.h"
#include "FancyDetailsPanelGameModeBase.generated.h"

/**
*
*/
UCLASS()
class FANCYDETAILSPANEL_API AFancyDetailsPanelGameModeBase : public AGameModeBase
{
GENERATED_BODY()




};
14 changes: 14 additions & 0 deletions CustomDetailsPanel/FancyDetailsPanelEditor.Target.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Fill out your copyright notice in the Description page of Project Settings.

using UnrealBuildTool;
using System.Collections.Generic;

public class FancyDetailsPanelEditorTarget : TargetRules
{
public FancyDetailsPanelEditorTarget(TargetInfo Target) : base(Target)
{
Type = TargetType.Editor;

ExtraModuleNames.AddRange( new string[] { "FancyDetailsPanel" } );
}
}
Binary file added CustomDetailsPanel/M_Cube.uasset
Binary file not shown.
3 changes: 3 additions & 0 deletions CustomDetailsPanel/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# File picker tutorial

Read the full tutorial here: https://wp.me/p6hvtS-s3

0 comments on commit 65673f5

Please sign in to comment.