// 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 static T GetValue(const FName& PropertyName, const ANSICHAR* Specifier = nullptr); FString SkinDir; FConfigFile Config; private: void LoadConfig(); template TOptional 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 Create(); static TSharedPtr 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 FAronaStyle::GetConfigValue(const FName& Key, FName FindSection) { TSharedRef Style = StaticCastSharedRef(StyleInstance.ToSharedRef()); if (!Style->Config.Contains(FindSection.ToString())) return TOptional(); const FConfigSection* Section = Style->Config.Find(FindSection.ToString()); if (Section == nullptr) return TOptional(); const FConfigValue* ConfigValue = Section->Find(Key); if (ConfigValue == nullptr) return TOptional(); return TOptional(ConfigValue->GetValue()); } template<> inline TOptional FAronaStyle::GetConfigValue(const FName& Key, FName FindSection) { TSharedRef Style = StaticCastSharedRef(StyleInstance.ToSharedRef()); if (!Style->Config.Contains(FindSection.ToString())) return TOptional(); const FConfigSection* Section = Style->Config.Find(FindSection.ToString()); if (Section == nullptr) return TOptional(); const FConfigValue* ConfigValue = Section->Find(Key); if (ConfigValue == nullptr) return TOptional(); FVector2f Value; Value.InitFromString(ConfigValue->GetValue()); return TOptional(Value); } template<> inline TOptional FAronaStyle::GetConfigValue(const FName& Key, FName FindSection) { TSharedRef Style = StaticCastSharedRef(StyleInstance.ToSharedRef()); if (!Style->Config.Contains(FindSection.ToString())) return TOptional(); const FConfigSection* Section = Style->Config.Find(FindSection.ToString()); if (Section == nullptr) return TOptional(); const FConfigValue* ConfigValue = Section->Find(Key); if (ConfigValue == nullptr) return TOptional(); 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(FCString::Atof(*String)); }