diff --git a/Source/HarmonyLink/Private/Objects/HarmonyLinkGraphics.cpp b/Source/HarmonyLink/Private/Objects/HarmonyLinkGraphics.cpp index 47b090d..bd6b1b5 100644 --- a/Source/HarmonyLink/Private/Objects/HarmonyLinkGraphics.cpp +++ b/Source/HarmonyLink/Private/Objects/HarmonyLinkGraphics.cpp @@ -13,17 +13,20 @@ TMap> UHarmonyLinkGraphics::DefaultSettings = { "Battery", { { TEXT("r.ReflectionMethod"), FHLConfigValue(0) }, { TEXT("r.DynamicGlobalIlluminationMethod"), FHLConfigValue(2) }, - { TEXT("r.Shadow.Virtual.Enable"), FHLConfigValue(0) } + { TEXT("r.Shadow.Virtual.Enable"), FHLConfigValue(0) }, + { TEXT("r.ScreenPercentage"), FHLConfigValue(50) }, }}, { "Charging", { { TEXT("r.ReflectionMethod"), FHLConfigValue(2) }, { TEXT("r.DynamicGlobalIlluminationMethod"), FHLConfigValue(2) }, - { TEXT("r.Shadow.Virtual.Enable"), FHLConfigValue(1) } + { TEXT("r.Shadow.Virtual.Enable"), FHLConfigValue(1) }, + { TEXT("r.ScreenPercentage"), FHLConfigValue(100) }, }}, - { "Docked", { + { "Docked", { { TEXT("r.ReflectionMethod"), FHLConfigValue(2) }, { TEXT("r.DynamicGlobalIlluminationMethod"), FHLConfigValue(2) }, - { TEXT("r.Shadow.Virtual.Enable"), FHLConfigValue(1) } + { TEXT("r.Shadow.Virtual.Enable"), FHLConfigValue(1) }, + { TEXT("r.ScreenPercentage"), FHLConfigValue(100) }, }} }; @@ -144,15 +147,6 @@ void UHarmonyLinkGraphics::SaveConfig() const GConfig->Flush(false, Filename); } -void UHarmonyLinkGraphics::ApplySettings(const bool bCheckForCommandLineOverrides) -{ - { - FGlobalComponentRecreateRenderStateContext Context; - //ApplyResolutionSettings(bCheckForCommandLineOverrides); - //ApplyNonResolutionSettings(); - } -} - UHarmonyLinkGraphics* UHarmonyLinkGraphics::GetSettings() @@ -170,7 +164,10 @@ UHarmonyLinkGraphics* UHarmonyLinkGraphics::GetSettings() const FBattery BatteryStatus = UHarmonyLinkLibrary::GetBatteryStatus(); - if (BatteryStatus.HasBattery) + // Enabled for development testing + // At some point I need to implement the ability to fake and emulate these settings to make it easier to test + // BUG: Remove this before release! + if (!BatteryStatus.HasBattery) { Instance->ApplyProfile(EProfile::BATTERY); } @@ -262,9 +259,76 @@ void UHarmonyLinkGraphics::LoadDefaults() } } -void UHarmonyLinkGraphics::ApplyProfile(EProfile Profile) +bool UHarmonyLinkGraphics::ApplyProfile(const EProfile Profile) { + // Find the profile name associated with the given EProfile + const FName* ProfileName = ProfileNames.Find(Profile); + if (!ProfileName) + { + UE_LOG(LogHarmonyLink, Warning, TEXT("Profile not found.")); + return false; + } + + UE_LOG(LogHarmonyLink, Log, TEXT("Applying profile %s."), *ProfileName->ToString()); + + // Find the settings associated with the profile + FSettingsProfile* SettingsProfile = Profiles.Find(Profile); + + if (!SettingsProfile) + { + UE_LOG(LogHarmonyLink, Warning, TEXT("No settings found for profile %s."), *ProfileName->ToString()); + return false; + } + + { + FGlobalComponentRecreateRenderStateContext Context; + + // Example of applying settings (actual application depends on your implementation) + for (const TPair& Setting : SettingsProfile->Settings) + { + // Example of logging each setting being applied + UE_LOG(LogHarmonyLink, Log, TEXT("Applying setting: %s = %s"), + *Setting.Key.ToString(), *Setting.Value.ToString()); + + ApplySetting(Setting); + } + } + + return true; +} + +void UHarmonyLinkGraphics::ApplySetting(const TPair& Setting) +{ + // Apply the setting based on the key (CVar) + IConsoleManager& ConsoleManager = IConsoleManager::Get(); + IConsoleVariable* CVar = ConsoleManager.FindConsoleVariable(*Setting.Key.ToString()); + + if (CVar) + { + switch (Setting.Value.GetType()) + { + case EConfigValueType::Bool: + CVar->Set(Setting.Value.GetValue(), ECVF_SetByGameSetting); + break; + + case EConfigValueType::Float: + CVar->Set(Setting.Value.GetValue(), ECVF_SetByGameSetting); + break; + + case EConfigValueType::Int: + CVar->Set(Setting.Value.GetValue(), ECVF_SetByGameSetting); + break; + + default: + UE_LOG(LogHarmonyLink, Warning, TEXT("Unsupported value type for setting: %s"), *Setting.Key.ToString()); + break; + } + } + else + { + UE_LOG(LogHarmonyLink, Warning, TEXT("Console variable not found: %s"), *Setting.Key.ToString()); + } } void UHarmonyLinkGraphics::DebugPrintProfiles() const diff --git a/Source/HarmonyLink/Public/Objects/HarmonyLinkGraphics.h b/Source/HarmonyLink/Public/Objects/HarmonyLinkGraphics.h index eb4845f..64f5913 100644 --- a/Source/HarmonyLink/Public/Objects/HarmonyLinkGraphics.h +++ b/Source/HarmonyLink/Public/Objects/HarmonyLinkGraphics.h @@ -26,9 +26,6 @@ public: UFUNCTION(BlueprintCallable, Category="HarmonyLink Settings") void SaveConfig() const; - UFUNCTION(BlueprintCallable, Category="HarmonyLink Settings", meta=(bCheckForCommandLineOverrides=true)) - void ApplySettings(bool bCheckForCommandLineOverrides = true); - /** Returns the game local machine settings (resolution, windowing mode, scalability settings, etc...) */ UFUNCTION(BlueprintCallable, Category="HarmonyLink Settings") static UHarmonyLinkGraphics* GetSettings(); @@ -41,10 +38,12 @@ private: bool LoadSection(const FConfigFile& ConfigFile, const TPair Profile); void SaveSection(FSettingsProfile& SettingsProfile, const bool bFlush = false) const; void LoadDefaults(); - void ApplyProfile(EProfile Profile); + bool ApplyProfile(EProfile Profile); static void ResetInstance(); + static void ApplySetting(const TPair& Setting); + // Debugging void DebugPrintProfiles() const; static void PrintDebugSection(FSettingsProfile& SettingsProfile); diff --git a/Source/HarmonyLink/Public/Structs/HLConfigValue.h b/Source/HarmonyLink/Public/Structs/HLConfigValue.h index daf99d2..98711ec 100644 --- a/Source/HarmonyLink/Public/Structs/HLConfigValue.h +++ b/Source/HarmonyLink/Public/Structs/HLConfigValue.h @@ -45,7 +45,24 @@ public: FHLConfigValue(bool Value) : Type(EConfigValueType::Bool), IntValue(0), FloatValue(0.0f), BoolValue(Value), StringValue(TEXT("")) {} FHLConfigValue(const FString& Value) : Type(EConfigValueType::String), IntValue(0), FloatValue(0.0f), BoolValue(false), StringValue(Value) {} - + + FString ToString() const + { + switch (Type) + { + case EConfigValueType::Int: + return FString::Printf(TEXT("Int: %d"), IntValue); + case EConfigValueType::Float: + return FString::Printf(TEXT("Float: %f"), FloatValue); + case EConfigValueType::Bool: + return BoolValue ? TEXT("Bool: true") : TEXT("Bool: false"); + case EConfigValueType::String: + return FString::Printf(TEXT("String: %s"), *StringValue); + default: + return TEXT("Unknown Type"); + } + } + EConfigValueType GetType() const { return Type;