147 lines
4.6 KiB
C++
147 lines
4.6 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
||
|
||
#pragma once
|
||
|
||
#include "CoreMinimal.h"
|
||
#include "ConfigCacheIni.h"
|
||
#include "SlateTypes.h"
|
||
#include "Styling/SlateStyle.h"
|
||
|
||
inline FName CloseButtonStyleName("CloseButton");
|
||
inline FName VolumeMeterBar("VolumeMeter");
|
||
inline FName VolumeMeterBarSpace("VolumeMeterSpace");
|
||
inline FName DefaultFontName("DefaultFont");
|
||
inline FName PianoRollBackground("PianoRollBackground");
|
||
inline FName WhiteBrush("WhiteBrush");
|
||
inline FName WhiteKey("WhiteKey");
|
||
inline FName BlackKey("BlackKey");
|
||
|
||
/** */
|
||
class FAronaStyle : public FSlateStyleSet
|
||
{
|
||
public:
|
||
FAronaStyle(const FName& InStyleSetName)
|
||
: FSlateStyleSet(InStyleSetName)
|
||
{
|
||
}
|
||
|
||
static void Initialize();
|
||
|
||
static void Shutdown();
|
||
|
||
/** reloads textures used by slate renderer */
|
||
static void ReloadTextures();
|
||
|
||
/** @return The Slate style set for the Shooter game */
|
||
static const ISlateStyle& Get();
|
||
|
||
virtual const FName& GetStyleSetName() const override;
|
||
|
||
static const FButtonStyle* GetButtonStyle(const FName& PropertyName, const ANSICHAR* Specifier = nullptr);
|
||
static const FSlateBrush* GetSlateBrush(const FName& PropertyName, const ANSICHAR* Specifier = nullptr);
|
||
static FSlateFontInfo GetFontInfo(const FName& PropertyName, const ANSICHAR* Specifier = nullptr);
|
||
|
||
template<typename T>
|
||
static T GetValue(const FName& PropertyName, const ANSICHAR* Specifier = nullptr);
|
||
|
||
FString SkinDir;
|
||
FConfigFile Config;
|
||
private:
|
||
void LoadConfig();
|
||
template<typename T>
|
||
TOptional<T> GetConfigValue(const FName& Key, FName FindSection = FName("Resource"));
|
||
|
||
void AddImageBrush(FName Key);
|
||
void AddFloatValue(FName Key);
|
||
void AddFontInfo(FName Key);
|
||
void AddButtonStyle(FName Key);
|
||
|
||
// static FConfigFile Config;
|
||
static TSharedRef<FAronaStyle> Create();
|
||
static TSharedPtr<FAronaStyle> StyleInstance;
|
||
};
|
||
|
||
template <>
|
||
inline float FAronaStyle::GetValue(const FName& PropertyName, const ANSICHAR* Specifier)
|
||
{
|
||
return StyleInstance->GetFloat(PropertyName, Specifier);
|
||
}
|
||
|
||
template <>
|
||
inline FVector2D FAronaStyle::GetValue(const FName& PropertyName, const ANSICHAR* Specifier)
|
||
{
|
||
return StyleInstance->GetVector(PropertyName, Specifier);
|
||
}
|
||
|
||
template <>
|
||
inline const FLinearColor& FAronaStyle::GetValue(const FName& PropertyName, const ANSICHAR* Specifier)
|
||
{
|
||
return StyleInstance->GetColor(PropertyName, Specifier);
|
||
}
|
||
|
||
template <>
|
||
inline const FSlateColor FAronaStyle::GetValue(const FName& PropertyName, const ANSICHAR* Specifier)
|
||
{
|
||
return StyleInstance->GetSlateColor(PropertyName, Specifier);
|
||
}
|
||
|
||
template <>
|
||
inline const FMargin& FAronaStyle::GetValue(const FName& PropertyName, const ANSICHAR* Specifier)
|
||
{
|
||
return StyleInstance->GetMargin(PropertyName, Specifier);
|
||
}
|
||
|
||
template<>
|
||
inline TOptional<FString> FAronaStyle::GetConfigValue(const FName& Key, FName FindSection)
|
||
{
|
||
TSharedRef<FAronaStyle> Style = StaticCastSharedRef<FAronaStyle>(StyleInstance.ToSharedRef());
|
||
if (!Style->Config.Contains(FindSection.ToString()))
|
||
return TOptional<FString>();
|
||
const FConfigSection* Section = Style->Config.Find(FindSection.ToString());
|
||
if (Section == nullptr)
|
||
return TOptional<FString>();
|
||
const FConfigValue* ConfigValue = Section->Find(Key);
|
||
if (ConfigValue == nullptr)
|
||
return TOptional<FString>();
|
||
return TOptional<FString>(ConfigValue->GetValue());
|
||
}
|
||
|
||
template<>
|
||
inline TOptional<FVector2f> FAronaStyle::GetConfigValue(const FName& Key, FName FindSection)
|
||
{
|
||
TSharedRef<FAronaStyle> Style = StaticCastSharedRef<FAronaStyle>(StyleInstance.ToSharedRef());
|
||
if (!Style->Config.Contains(FindSection.ToString()))
|
||
return TOptional<FVector2f>();
|
||
const FConfigSection* Section = Style->Config.Find(FindSection.ToString());
|
||
if (Section == nullptr)
|
||
return TOptional<FVector2f>();
|
||
const FConfigValue* ConfigValue = Section->Find(Key);
|
||
if (ConfigValue == nullptr)
|
||
return TOptional<FVector2f>();
|
||
FVector2f Value;
|
||
Value.InitFromString(ConfigValue->GetValue());
|
||
return TOptional<FVector2f>(Value);
|
||
}
|
||
|
||
template<>
|
||
inline TOptional<float> FAronaStyle::GetConfigValue(const FName& Key, FName FindSection)
|
||
{
|
||
TSharedRef<FAronaStyle> Style = StaticCastSharedRef<FAronaStyle>(StyleInstance.ToSharedRef());
|
||
if (!Style->Config.Contains(FindSection.ToString()))
|
||
return TOptional<float>();
|
||
const FConfigSection* Section = Style->Config.Find(FindSection.ToString());
|
||
if (Section == nullptr)
|
||
return TOptional<float>();
|
||
const FConfigValue* ConfigValue = Section->Find(Key);
|
||
if (ConfigValue == nullptr)
|
||
return TOptional<float>();
|
||
FString String = ConfigValue->GetValue();
|
||
String = String.Replace(TEXT("x"), TEXT("X"));
|
||
String = String.Replace(TEXT("y"), TEXT("Y"));
|
||
String = String.Replace(TEXT(","), TEXT(""));
|
||
String = String.Replace(TEXT(","), TEXT(""));
|
||
return TOptional<float>(FCString::Atof(*String));
|
||
}
|
||
|
||
|