forked from orfeasel/UE4-Cpp-Tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
319 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
26
CustomDetailsPanel/BlogpostModule/Private/BlogpostModule.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
66
CustomDetailsPanel/BlogpostModule/Private/CustomDetailsPanel.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
28
CustomDetailsPanel/BlogpostModule/Public/CustomDetailsPanel.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
|
||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
23
CustomDetailsPanel/FancyDetailsPanel/FancyDetailsPanel.Build.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
7 changes: 7 additions & 0 deletions
7
CustomDetailsPanel/FancyDetailsPanel/FancyDetailsPanelGameModeBase.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
||
|
||
|
||
|
20 changes: 20 additions & 0 deletions
20
CustomDetailsPanel/FancyDetailsPanel/FancyDetailsPanelGameModeBase.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|
||
|
||
|
||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |