diff --git a/Plugins/Cog/Source/Cog/Private/CogWidgets.cpp b/Plugins/Cog/Source/Cog/Private/CogWidgets.cpp index 233bbac..58431b5 100644 --- a/Plugins/Cog/Source/Cog/Private/CogWidgets.cpp +++ b/Plugins/Cog/Source/Cog/Private/CogWidgets.cpp @@ -1541,4 +1541,65 @@ bool FCogWidgets::InputChordProperty(UObject& InConfig, const FProperty& InInput return FCogWidgets::InputChord(Name.Get(), *InputChord); } - \ No newline at end of file + +//-------------------------------------------------------------------------------------------------------------------------- +bool FCogWidgets::IsConfigContainingInputChords(const UObject& InConfig) +{ + for (TFieldIterator It(InConfig.GetClass()); It; ++It) + { + if (const FStructProperty* StructProperty = CastField(*It)) + { + if (StructProperty->Struct == FInputChord::StaticStruct()) + { + return true; + } + } + } + + return false; +} + +//-------------------------------------------------------------------------------------------------------------------------- +bool FCogWidgets::AllInputChordsOfConfig(UObject& InConfig, FProperty** InModifiedProperty) +{ + bool HasChanged = false; + TArray Properties; + for (TFieldIterator It(InConfig.GetClass()); It; ++It) + { + if (FStructProperty* StructProperty = CastField(*It)) + { + if (StructProperty->Struct == FInputChord::StaticStruct()) + { + if (FCogWidgets::InputChordProperty(InConfig, *StructProperty)) + { + HasChanged = true; + if (InModifiedProperty != nullptr) + { + *InModifiedProperty = StructProperty; + } + } + } + } + } + + return HasChanged; +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogWidgets::TextOfAllInputChordsOfConfig(UObject& InConfig) +{ + TArray Properties; + for (TFieldIterator It(InConfig.GetClass()); It; ++It) + { + if (const FStructProperty* StructProperty = CastField(*It)) + { + if (StructProperty->Struct == FInputChord::StaticStruct()) + { + TextInputChordProperty(InConfig, *StructProperty); + } + } + } +} + + + diff --git a/Plugins/Cog/Source/Cog/Private/CogWindow.cpp b/Plugins/Cog/Source/Cog/Private/CogWindow.cpp index 774a3bf..7ffe71f 100644 --- a/Plugins/Cog/Source/Cog/Private/CogWindow.cpp +++ b/Plugins/Cog/Source/Cog/Private/CogWindow.cpp @@ -3,6 +3,7 @@ #include "CogDebug.h" #include "CogWindow_Settings.h" #include "CogSubsystem.h" +#include "CogWidgets.h" #include "Engine/World.h" #include "imgui_internal.h" #include "GameFramework/Pawn.h" @@ -254,3 +255,13 @@ float FCogWindow::GetDpiScale() const { return GetOwner()->GetContext().GetDpiScale(); } + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogWindow::RenderConfigShortcuts(UCogCommonConfig& InConfig) const +{ + FProperty* InModifiedProperty = nullptr; + if (FCogWidgets::AllInputChordsOfConfig(InConfig, &InModifiedProperty)) + { + GetOwner()->RebindShortcut(InConfig, *InModifiedProperty); + } +} \ No newline at end of file diff --git a/Plugins/Cog/Source/Cog/Private/CogWindow_Settings.cpp b/Plugins/Cog/Source/Cog/Private/CogWindow_Settings.cpp index 03ce0f9..3940697 100644 --- a/Plugins/Cog/Source/Cog/Private/CogWindow_Settings.cpp +++ b/Plugins/Cog/Source/Cog/Private/CogWindow_Settings.cpp @@ -244,32 +244,20 @@ void FCogWindow_Settings::RenderContent() //------------------------------------------------------------------------------------------- if (ImGui::CollapsingHeader("Shortcuts", ImGuiTreeNodeFlags_DefaultOpen)) { - TArray>& Configs = GetOwner()->GetConfigs(); - for (TObjectPtr SomeConfig : Configs) + for (TObjectPtr SomeConfig : GetOwner()->GetConfigs()) { - TArray Properties; - for (TFieldIterator It(SomeConfig->GetClass()); It; ++It) - { - if (FStructProperty* StructProperty = CastField(*It)) - { - if (StructProperty->Struct == FInputChord::StaticStruct()) - { - Properties.Add(StructProperty); - } - } - } - - if (Properties.Num() > 0) + if (SomeConfig == nullptr) + { continue; } + + if (FCogWidgets::IsConfigContainingInputChords(*SomeConfig)) { auto ConfigName = StringCast(*FCogWidgets::FormatConfigName(SomeConfig->GetClass()->GetName())); ImGui::SeparatorText(ConfigName.Get()); - for (const FProperty* Property : Properties) + FProperty* InModifiedProperty = nullptr; + if (FCogWidgets::AllInputChordsOfConfig(*SomeConfig, &InModifiedProperty)) { - if (FCogWidgets::InputChordProperty(*SomeConfig, *Property)) - { - GetOwner()->RebindShortcut(*SomeConfig, *Property); - } + GetOwner()->RebindShortcut(*SomeConfig, *InModifiedProperty); } } } diff --git a/Plugins/Cog/Source/Cog/Public/CogWidgets.h b/Plugins/Cog/Source/Cog/Public/CogWidgets.h index 2c2b09d..507dd1f 100644 --- a/Plugins/Cog/Source/Cog/Public/CogWidgets.h +++ b/Plugins/Cog/Source/Cog/Public/CogWidgets.h @@ -188,6 +188,12 @@ public: static void TextInputChordProperty(UObject& InConfig, const FProperty& InInputChordProperty); static bool InputChordProperty(UObject& InConfig, const FProperty& InInputChordProperty); + + static bool IsConfigContainingInputChords(const UObject& InConfig); + + static bool AllInputChordsOfConfig(UObject& InConfig, FProperty** InModifiedProperty = nullptr); + + static void TextOfAllInputChordsOfConfig(UObject& InConfig); }; template diff --git a/Plugins/Cog/Source/Cog/Public/CogWindow.h b/Plugins/Cog/Source/Cog/Public/CogWindow.h index a3b1e02..e844aea 100644 --- a/Plugins/Cog/Source/Cog/Public/CogWindow.h +++ b/Plugins/Cog/Source/Cog/Public/CogWindow.h @@ -79,6 +79,7 @@ public: float GetDpiScale() const; + template T* GetConfig(bool InResetConfigOnRequest = true) const { return Cast(GetConfig(T::StaticClass(), InResetConfigOnRequest)); } @@ -117,7 +118,9 @@ protected: virtual void OnSelectionChanged(AActor* OldSelection, AActor* NewSelection) {} virtual bool IsWindowRenderedInMainMenu(); - + + virtual void RenderConfigShortcuts(UCogCommonConfig& InConfig) const; + APawn* GetLocalPlayerPawn() const; APlayerController* GetLocalPlayerController() const; diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_TimeScale.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_TimeScale.cpp index 2ec735f..4fa9ac8 100644 --- a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_TimeScale.cpp +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_TimeScale.cpp @@ -54,21 +54,21 @@ void FCogEngineWindow_TimeScale::RenderContent() //-------------------------------------------------------------------------------------------------------------------------- void FCogEngineWindow_TimeScale::RenderContextMenu() { + UCogEngineWindowConfig_TimeScale* ConfigPtr = Config.Get(); + if (IsWindowRenderedInMainMenu() == false) { - ImGui::Checkbox("Inline", &Config->Inline); + ImGui::Checkbox("Inline", &ConfigPtr->Inline); } - FCogImguiHelper::ColorEdit4("Time Scale Modified Color", Config->TimeScaleModifiedColor, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + FCogImguiHelper::ColorEdit4("Time Scale Modified Color", ConfigPtr->TimeScaleModifiedColor, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); ImGui::SetItemTooltip("Color of the current time scale, in widget mode, when the time scale in not 1."); - FCogWidgets::FloatArray("Time Scales", Config->TimeScales, 10, ImVec2(0, ImGui::GetFontSize() * 10)); + FCogWidgets::FloatArray("Time Scales", ConfigPtr->TimeScales, 10, ImVec2(0, ImGui::GetFontSize() * 10)); if (ImGui::CollapsingHeader("Shortcuts", ImGuiTreeNodeFlags_DefaultOpen)) { - FCogWidgets::InputChord("Speed Up", Config->Shortcut_FasterTimeScale); - FCogWidgets::InputChord("Speed Down", Config->Shortcut_SlowerTimeScale); - FCogWidgets::InputChord("Reset Time", Config->Shortcut_ResetTimeScale); + RenderConfigShortcuts(*ConfigPtr); } ImGui::Separator(); @@ -134,10 +134,7 @@ void FCogEngineWindow_TimeScale::RenderMainMenuWidget() ImGui::Text("Time Scale: x%g", TimeDilation); ImGui::Spacing(); ImGui::Separator(); - FCogWidgets::TextInputChordProperty(Config.Get(), &UCogEngineWindowConfig_TimeScale::Shortcut_FasterTimeScale); - FCogWidgets::TextInputChordProperty(Config.Get(), &UCogEngineWindowConfig_TimeScale::Shortcut_SlowerTimeScale); - FCogWidgets::TextInputChordProperty(Config.Get(), &UCogEngineWindowConfig_TimeScale::Shortcut_ResetTimeScale); - FCogWidgets::TextInputChordProperty(Config.Get(), &UCogEngineWindowConfig_TimeScale::Shortcut_ZeroTimeScale); + FCogWidgets::TextOfAllInputChordsOfConfig(*Config.Get()); ImGui::EndTooltip(); } }