Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Refactorization of folder coloring #4211

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[/Script/OpenPype.OpenPypeSettings]
FolderColor=(R=91,G=197,B=220,A=255)
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public OpenPype(ReadOnlyTargetRules Target) : base(Target)
"Engine",
"Slate",
"SlateCore",
"AssetTools"
// ... add private dependencies that you statically link with here ...
}
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#include "OpenPype.h"

#include "ISettingsContainer.h"
#include "ISettingsModule.h"
#include "ISettingsSection.h"
#include "LevelEditor.h"
#include "OpenPypePythonBridge.h"
#include "OpenPypeSettings.h"
#include "OpenPypeStyle.h"


Expand All @@ -11,13 +16,12 @@ static const FName OpenPypeTabName("OpenPype");
// This function is triggered when the plugin is staring up
void FOpenPypeModule::StartupModule()
{

FOpenPypeStyle::Initialize();
FOpenPypeStyle::SetIcon("Logo", "openpype40");

// Create the Extender that will add content to the menu
FLevelEditorModule& LevelEditorModule = FModuleManager::LoadModuleChecked<FLevelEditorModule>("LevelEditor");

TSharedPtr<FExtender> MenuExtender = MakeShareable(new FExtender());
TSharedPtr<FExtender> ToolbarExtender = MakeShareable(new FExtender());

Expand All @@ -37,6 +41,7 @@ void FOpenPypeModule::StartupModule()
LevelEditorModule.GetMenuExtensibilityManager()->AddExtender(MenuExtender);
LevelEditorModule.GetToolBarExtensibilityManager()->AddExtender(ToolbarExtender);

RegisterSettings();
}

void FOpenPypeModule::ShutdownModule()
Expand Down Expand Up @@ -64,7 +69,6 @@ void FOpenPypeModule::AddMenuEntry(FMenuBuilder& MenuBuilder)
FSlateIcon(FOpenPypeStyle::GetStyleSetName(), "OpenPype.Logo"),
FUIAction(FExecuteAction::CreateRaw(this, &FOpenPypeModule::MenuDialog))
);

}
MenuBuilder.EndSection();
}
Expand All @@ -89,13 +93,58 @@ void FOpenPypeModule::AddToobarEntry(FToolBarBuilder& ToolbarBuilder)
ToolbarBuilder.EndSection();
}

void FOpenPypeModule::RegisterSettings()
{
ISettingsModule& SettingsModule = FModuleManager::LoadModuleChecked<ISettingsModule>("Settings");

// Create the new category
// TODO: After the movement of the plugin from the game to editor, it might be necessary to move this!
ISettingsContainerPtr SettingsContainer = SettingsModule.GetContainer("Project");

UOpenPypeSettings* Settings = GetMutableDefault<UOpenPypeSettings>();

// Register the settings
ISettingsSectionPtr SettingsSection = SettingsModule.RegisterSettings("Project", "OpenPype", "General",
LOCTEXT("RuntimeGeneralSettingsName",
"General"),
LOCTEXT("RuntimeGeneralSettingsDescription",
"Base configuration for Open Pype Module"),
Settings
);

// Register the save handler to your settings, you might want to use it to
// validate those or just act to settings changes.
if (SettingsSection.IsValid())
{
SettingsSection->OnModified().BindRaw(this, &FOpenPypeModule::HandleSettingsSaved);
}
}

bool FOpenPypeModule::HandleSettingsSaved()
{
UOpenPypeSettings* Settings = GetMutableDefault<UOpenPypeSettings>();
bool ResaveSettings = false;

// You can put any validation code in here and resave the settings in case an invalid
// value has been entered

if (ResaveSettings)
{
Settings->SaveConfig();
}

return true;
}


void FOpenPypeModule::MenuPopup() {
void FOpenPypeModule::MenuPopup()
{
UOpenPypePythonBridge* bridge = UOpenPypePythonBridge::Get();
bridge->RunInPython_Popup();
}

void FOpenPypeModule::MenuDialog() {
void FOpenPypeModule::MenuDialog()
{
UOpenPypePythonBridge* bridge = UOpenPypePythonBridge::Get();
bridge->RunInPython_Dialog();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "OpenPypeLib.h"

#include "AssetViewUtils.h"
#include "Misc/Paths.h"
#include "Misc/ConfigCacheIni.h"
#include "UObject/UnrealType.h"
Expand All @@ -10,21 +12,23 @@
* @warning This color will appear only after Editor restart. Is there a better way?
*/

void UOpenPypeLib::CSetFolderColor(FString FolderPath, FLinearColor FolderColor, bool bForceAdd)
bool UOpenPypeLib::SetFolderColor(const FString& FolderPath, const FLinearColor& FolderColor, const bool& bForceAdd)
{
auto SaveColorInternal = [](FString InPath, FLinearColor InFolderColor)
if (AssetViewUtils::DoesFolderExist(FolderPath))
{
// Saves the color of the folder to the config
if (FPaths::FileExists(GEditorPerProjectIni))
{
GConfig->SetString(TEXT("PathColor"), *InPath, *InFolderColor.ToString(), GEditorPerProjectIni);
}
const TSharedPtr<FLinearColor> LinearColor = MakeShared<FLinearColor>(FolderColor);

};

SaveColorInternal(FolderPath, FolderColor);
AssetViewUtils::SaveColor(FolderPath, LinearColor, true);
UE_LOG(LogAssetData, Display, TEXT("A color {%s} has been set to folder \"%s\""), *LinearColor->ToString(),
*FolderPath)
return true;
}

UE_LOG(LogAssetData, Display, TEXT("Setting a color {%s} to folder \"%s\" has failed! Directory doesn't exist!"),
*FolderColor.ToString(), *FolderPath)
return false;
}

/**
* Returns all poperties on given object
* @param cls - class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "OpenPypePublishInstance.h"
#include "AssetRegistryModule.h"
#include "NotificationManager.h"
#include "OpenPypeLib.h"
#include "OpenPypeSettings.h"
#include "SNotificationList.h"

//Moves all the invalid pointers to the end to prepare them for the shrinking
Expand Down Expand Up @@ -36,6 +38,11 @@ UOpenPypePublishInstance::UOpenPypePublishInstance(const FObjectInitializer& Obj
AssetRegistryModule.Get().OnAssetAdded().AddUObject(this, &UOpenPypePublishInstance::OnAssetCreated);
AssetRegistryModule.Get().OnAssetRemoved().AddUObject(this, &UOpenPypePublishInstance::OnAssetRemoved);
AssetRegistryModule.Get().OnAssetUpdated().AddUObject(this, &UOpenPypePublishInstance::OnAssetUpdated);

#ifdef WITH_EDITOR
ColorOpenPypeDirs();
#endif

}

void UOpenPypePublishInstance::OnAssetCreated(const FAssetData& InAssetData)
Expand All @@ -58,7 +65,7 @@ void UOpenPypePublishInstance::OnAssetCreated(const FAssetData& InAssetData)
if (AssetDataInternal.Emplace(Asset).IsValidId())
{
UE_LOG(LogTemp, Log, TEXT("Added an Asset to PublishInstance - Publish Instance: %s, Asset %s"),
*this->GetName(), *Asset->GetName());
*this->GetName(), *Asset->GetName());
}
}
}
Expand Down Expand Up @@ -96,6 +103,48 @@ bool UOpenPypePublishInstance::IsUnderSameDir(const UObject* InAsset) const

#ifdef WITH_EDITOR

void UOpenPypePublishInstance::ColorOpenPypeDirs()
{
FString PathName = this->GetPathName();

//Check whether the path contains the defined OpenPype folder
if (!PathName.Contains(TEXT("OpenPype"))) return;

//Get the base path for open pype
FString PathLeft, PathRight;
PathName.Split(FString("OpenPype"), &PathLeft, &PathRight);

if (PathLeft.IsEmpty() || PathRight.IsEmpty())
{
UE_LOG(LogAssetData, Error, TEXT("Failed to retrieve the base OpenPype directory!"))
return;
}

PathName.RemoveFromEnd(PathRight, ESearchCase::CaseSensitive);

//Get the current settings
const UOpenPypeSettings* Settings = GetMutableDefault<UOpenPypeSettings>();

//Color the base folder
UOpenPypeLib::SetFolderColor(PathName, Settings->GetFolderFColor(), false);

//Get Sub paths, iterate through them and color them according to the folder color in UOpenPypeSettings
const FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>(
"AssetRegistry");

TArray<FString> PathList;

AssetRegistryModule.Get().GetSubPaths(PathName, PathList, true);

if (PathList.Num() > 0)
{
for (const FString& Path : PathList)
{
UOpenPypeLib::SetFolderColor(Path, Settings->GetFolderFColor(), false);
}
}
}

void UOpenPypePublishInstance::SendNotification(const FString& Text) const
{
FNotificationInfo Info{FText::FromString(Text)};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Fill out your copyright notice in the Description page of Project Settings.

#include "OpenPypeSettings.h"

#include "IPluginManager.h"
#include "UObjectGlobals.h"

/**
* Mainly is used for initializing default values if the DefaultOpenPypeSettings.ini file does not exist in the saved config
*/
UOpenPypeSettings::UOpenPypeSettings(const FObjectInitializer& ObjectInitializer)
{

const FString ConfigFilePath = OPENPYPE_SETTINGS_FILEPATH;

// This has to be probably in the future set using the UE Reflection system
FColor Color;
GConfig->GetColor(TEXT("/Script/OpenPype.OpenPypeSettings"), TEXT("FolderColor"), Color, ConfigFilePath);

FolderColor = Color;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ class FOpenPypeModule : public IModuleInterface
virtual void ShutdownModule() override;

private:
void RegisterSettings();
bool HandleSettingsSaved();

void AddMenuEntry(FMenuBuilder& MenuBuilder);
void AddToobarEntry(FToolBarBuilder& ToolbarBuilder);
void MenuPopup();
void MenuDialog();

};
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@


UCLASS(Blueprintable)
class OPENPYPE_API UOpenPypeLib : public UObject
class OPENPYPE_API UOpenPypeLib : public UBlueprintFunctionLibrary
{

GENERATED_BODY()

public:
UFUNCTION(BlueprintCallable, Category = Python)
static void CSetFolderColor(FString FolderPath, FLinearColor FolderColor, bool bForceAdd);
static bool SetFolderColor(const FString& FolderPath, const FLinearColor& FolderColor,const bool& bForceAdd);

UFUNCTION(BlueprintCallable, Category = Python)
static TArray<FString> GetAllProperties(UClass* cls);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ UCLASS(Blueprintable)
class OPENPYPE_API UOpenPypePublishInstance : public UPrimaryDataAsset
{
GENERATED_UCLASS_BODY()

public:

/**
/**
* Retrieves all the assets which are monitored by the Publish Instance (Monitors assets in the directory which is
* placed in)
Expand Down Expand Up @@ -58,8 +56,10 @@ class OPENPYPE_API UOpenPypePublishInstance : public UPrimaryDataAsset
UFUNCTION(BlueprintCallable, BlueprintPure)
TSet<UObject*> GetAllAssets() const
{
const TSet<TSoftObjectPtr<UObject>>& IteratedSet = bAddExternalAssets ? AssetDataInternal.Union(AssetDataExternal) : AssetDataInternal;

const TSet<TSoftObjectPtr<UObject>>& IteratedSet = bAddExternalAssets
? AssetDataInternal.Union(AssetDataExternal)
: AssetDataInternal;

//Create a new TSet only with raw pointers.
TSet<UObject*> ResultSet;

Expand All @@ -69,12 +69,10 @@ class OPENPYPE_API UOpenPypePublishInstance : public UPrimaryDataAsset
return ResultSet;
}


private:

UPROPERTY(VisibleAnywhere, Category="Assets")
TSet<TSoftObjectPtr<UObject>> AssetDataInternal;

/**
* This property allows exposing the array to include other assets from any other directory than what it's currently
* monitoring. NOTE: that these assets have to be added manually! They are not automatically registered or added!
Expand All @@ -93,11 +91,11 @@ class OPENPYPE_API UOpenPypePublishInstance : public UPrimaryDataAsset
bool IsUnderSameDir(const UObject* InAsset) const;

#ifdef WITH_EDITOR

void ColorOpenPypeDirs();

void SendNotification(const FString& Text) const;
virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;

#endif

};

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

#pragma once

#include "CoreMinimal.h"
#include "Object.h"
#include "OpenPypeSettings.generated.h"

#define OPENPYPE_SETTINGS_FILEPATH IPluginManager::Get().FindPlugin("OpenPype")->GetBaseDir() / TEXT("Config") / TEXT("DefaultOpenPypeSettings.ini")

UCLASS(Config=OpenPypeSettings, DefaultConfig)
class OPENPYPE_API UOpenPypeSettings : public UObject
{
GENERATED_UCLASS_BODY()

UFUNCTION(BlueprintCallable, BlueprintPure, Category = Settings)
FColor GetFolderFColor() const
{
return FolderColor;
}

UFUNCTION(BlueprintCallable, BlueprintPure, Category = Settings)
FLinearColor GetFolderFLinearColor() const
{
return FLinearColor(FolderColor);
}

protected:

UPROPERTY(config, EditAnywhere, Category = Folders)
FColor FolderColor = FColor(25,45,223);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[/Script/OpenPype.OpenPypeSettings]
FolderColor=(R=91,G=197,B=220,A=255)
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public OpenPype(ReadOnlyTargetRules Target) : base(Target)
"Engine",
"Slate",
"SlateCore",
"AssetTools"
// ... add private dependencies that you statically link with here ...
}
);
Expand Down
Loading