๐ŸŒž Victory Plugin ~ 's Extra Blueprint Nodes for UE5, No C++ Required!

:heart: 's UE5 Color Picker For You :heart:

Dear UE Community,

Iโ€™ve integrated my implementation of the UE Editor Color Picker into the UE5 version of Victory Plugin!

:zap: :star2: :rose:This Color Picker, The UE Color Picker Itself, Will Indeed Work In Packaged Games :rose: :star2: :zap:

Many Thanks To :sparkling_heart: Nick Darnell :sparkling_heart:, for it was he who exposed the UE Color Picker Slate class (Runtime/AppFramework) so we could use it in :rose:packaged games! :rose:

My role was to create the UMG Class wrapper of the Slate Code so that the Color Picker can be accessed from the :rose: UMG Designer :rose:, as you can see in the video below!

@M1te Your UMG Color Picker Gift is Ready at the Download link in original post, enjoy!


UE5 C++ Code


.h

/*
	By  for You
	
	You are welcome to use this code anywhere as long as you include this notice.
*/

#pragma once

//UE5 Color Picker
//		Requires module in build.cs
//			APPFRAMEWORK 
#include "Runtime/AppFramework/Public/Widgets/Colors/SColorPicker.h"

class SJoyColorPicker
	: public SColorPicker
{ 
	typedef SColorPicker Super;
	
public: //! <~~~~~
	FORCEINLINE void SetColorRGB(const FLinearColor& NewColor)
	{
		//This is protected in SColorPicker 
		//		so can't call it from UMG component
		SetNewTargetColorRGB( NewColor, true ); //Force Update
	}
	
//Animation
public:
 
	FLinearColor InstantColor;
	bool Animation_SkipToFinalForOneTick = false; 
	virtual void Tick( const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime ) override
	{ 
		//Skip to final, then resume normal animation behavior
		if(Animation_SkipToFinalForOneTick)
		{  
			Animation_SkipToFinalForOneTick = false;  
			Super::Tick(AllottedGeometry, InCurrentTime, 10000); //<~~~ because all the required vars like CurrentTime are private :)
			SetColorRGB(InstantColor);
			return;
			//~~~~
		}
		
		//Animate normally!
		Super::Tick(AllottedGeometry, InCurrentTime, InDeltaTime);
	}
};
#pragma once

#include "CoreMinimal.h"
#include "UObject/ObjectMacros.h"
#include "Styling/SlateColor.h"
#include "Styling/SlateTypes.h"
#include "Widgets/SWidget.h"
#include "Components/Widget.h"

#include "RamaColorPicker.generated.h"

class SJoyColorPicker;

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnJoyColorChangedEvent, const FLinearColor&, NewColor);

/**
 *  Color Picker For You! โ™ฅ 
 */
UCLASS()
class VICTORYBPLIBRARY_API URamaColorPicker : public UWidget
{
	GENERATED_UCLASS_BODY()
	
public:

	/** The currently Chosen Color for this Color Picker! โ™ฅ */
	UPROPERTY(BlueprintReadWrite, EditAnywhere, Category=" Color Picker",meta=(Keywords="getcolor"))
	FLinearColor JoyColor = FLinearColor::Red;
	
	/** Called whenever the color is changed programmatically or interactively by the user */
	UPROPERTY(BlueprintAssignable, Category=" Color Picker", meta=(DisplayName="OnColorChanged ( Color Picker)"))
	FOnJoyColorChangedEvent OnColorChanged;
	
	/**
	 * Directly sets the current color, for saving user preferences of chosen color, or loading existing color of an in-game clicked actor!
	 * @param InColor The color to assign to the widget
	 */
	UFUNCTION(BlueprintCallable, Category = " Color Picker",meta=(Keywords="setcolor"))
	void SetJoyColor(FLinearColor NewColor, bool SkipAnimation=false);
	
public:
	void ColorUpdated(FLinearColor NewValue);

#if WITH_EDITOR
public:
	
	// UWidget interface
	//virtual const FSlateBrush* GetEditorIcon() override;
	virtual const FText GetPaletteCategory() override;
	// End UWidget interface
	
	// UObject interface
	virtual void PostEditChangeProperty(struct FPropertyChangedEvent& PropertyChangedEvent) override;
	// End of UObject interface
	
#endif

public:
	
	//~ Begin UWidget Interface
	virtual void SynchronizeProperties() override;
	//~ End UWidget Interface
	
protected:
	//~ Begin UWidget Interface
	virtual TSharedRef<SWidget> RebuildWidget() override;
	// End of UWidget
	
	// UVisual interface
	virtual void ReleaseSlateResources(bool bReleaseChildren) override;
	// End of UVisual interface
	
protected:
	TSharedPtr<SJoyColorPicker> MySlateColorPicker;
	
};

#include "RamaColorPicker.h"

#include "UObject/ConstructorHelpers.h"
#include "Widgets/DeclarativeSyntaxSupport.h"
#include "SJoyColorPicker.h"

#define LOCTEXT_NAMESPACE "UMG"

URamaColorPicker::URamaColorPicker(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
	, JoyColor(FLinearColor::Red)
{}

#if WITH_EDITOR
/*
const FSlateBrush* UJoyColorWheel::GetEditorIcon()
{
	return FUMGStyle::Get().GetBrush("Widget.Image");
}
*/ 
 
const FText URamaColorPicker::GetPaletteCategory()
{
	return LOCTEXT("Victory Plugin", "Victory Plugin");
}

void URamaColorPicker::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
{
	Super::PostEditChangeProperty(PropertyChangedEvent);

	FName PropertyName = (PropertyChangedEvent.Property != NULL) ? PropertyChangedEvent.Property->GetFName() : NAME_None;
  
	//Update Picker to JoyColor property change!
	if (PropertyName == TEXT("JoyColor"))
	{  
		SetJoyColor(JoyColor,true);
	}	
} 
#endif

void URamaColorPicker::SetJoyColor(FLinearColor NewColor, bool SkipAnimation)
{
	if(!MySlateColorPicker.IsValid()) 
	{
		return;
	}
	
	//Skip Anim?
	if(SkipAnimation)
	{
		MySlateColorPicker->InstantColor = NewColor; 
		MySlateColorPicker->Animation_SkipToFinalForOneTick = true;		//See SJoyColorPicker.h
	}
	else
	{
		//Set!
		MySlateColorPicker->SetColorRGB(NewColor);
	}
}

void URamaColorPicker::ColorUpdated(FLinearColor NewValue)
{
	JoyColor = NewValue; 
	 
	if(OnColorChanged.IsBound())
	{
		OnColorChanged.Broadcast(JoyColor);
	}
} 

TSharedRef<SWidget> URamaColorPicker::RebuildWidget()
{
	MySlateColorPicker = SNew( SJoyColorPicker )
		.TargetColorAttribute( JoyColor )
		.OnColorCommitted( FOnLinearColorValueChanged::CreateUObject( this, &URamaColorPicker::ColorUpdated) );
	
	return MySlateColorPicker.ToSharedRef();
}

//Release
void URamaColorPicker::ReleaseSlateResources(bool bReleaseChildren)
{
	Super::ReleaseSlateResources(bReleaseChildren);

	if(MySlateColorPicker.IsValid()) 
	{
		MySlateColorPicker.Reset();
	}
}

void URamaColorPicker::SynchronizeProperties()
{
	Super::SynchronizeProperties();
	 
	SetJoyColor(JoyColor,true);
}


/////////////////////////////////////////////////////

#undef LOCTEXT_NAMESPACE
1 Like