mirror of
https://github.com/Ed94/Cog.git
synced 2026-06-13 00:01:37 -07:00
Minor refactor
This commit is contained in:
@@ -1541,4 +1541,65 @@ bool FCogWidgets::InputChordProperty(UObject& InConfig, const FProperty& InInput
|
||||
return FCogWidgets::InputChord(Name.Get(), *InputChord);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
bool FCogWidgets::IsConfigContainingInputChords(const UObject& InConfig)
|
||||
{
|
||||
for (TFieldIterator<FProperty> It(InConfig.GetClass()); It; ++It)
|
||||
{
|
||||
if (const FStructProperty* StructProperty = CastField<FStructProperty>(*It))
|
||||
{
|
||||
if (StructProperty->Struct == FInputChord::StaticStruct())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
bool FCogWidgets::AllInputChordsOfConfig(UObject& InConfig, FProperty** InModifiedProperty)
|
||||
{
|
||||
bool HasChanged = false;
|
||||
TArray<FProperty*> Properties;
|
||||
for (TFieldIterator<FProperty> It(InConfig.GetClass()); It; ++It)
|
||||
{
|
||||
if (FStructProperty* StructProperty = CastField<FStructProperty>(*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<FProperty*> Properties;
|
||||
for (TFieldIterator<FProperty> It(InConfig.GetClass()); It; ++It)
|
||||
{
|
||||
if (const FStructProperty* StructProperty = CastField<FStructProperty>(*It))
|
||||
{
|
||||
if (StructProperty->Struct == FInputChord::StaticStruct())
|
||||
{
|
||||
TextInputChordProperty(InConfig, *StructProperty);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -244,32 +244,20 @@ void FCogWindow_Settings::RenderContent()
|
||||
//-------------------------------------------------------------------------------------------
|
||||
if (ImGui::CollapsingHeader("Shortcuts", ImGuiTreeNodeFlags_DefaultOpen))
|
||||
{
|
||||
TArray<TObjectPtr<UCogCommonConfig>>& Configs = GetOwner()->GetConfigs();
|
||||
for (TObjectPtr<UCogCommonConfig> SomeConfig : Configs)
|
||||
for (TObjectPtr SomeConfig : GetOwner()->GetConfigs())
|
||||
{
|
||||
TArray<FProperty*> Properties;
|
||||
for (TFieldIterator<FProperty> It(SomeConfig->GetClass()); It; ++It)
|
||||
{
|
||||
if (FStructProperty* StructProperty = CastField<FStructProperty>(*It))
|
||||
{
|
||||
if (StructProperty->Struct == FInputChord::StaticStruct())
|
||||
{
|
||||
Properties.Add(StructProperty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Properties.Num() > 0)
|
||||
if (SomeConfig == nullptr)
|
||||
{ continue; }
|
||||
|
||||
if (FCogWidgets::IsConfigContainingInputChords(*SomeConfig))
|
||||
{
|
||||
auto ConfigName = StringCast<ANSICHAR>(*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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<typename EnumType>
|
||||
|
||||
@@ -79,6 +79,7 @@ public:
|
||||
|
||||
float GetDpiScale() const;
|
||||
|
||||
|
||||
template<class T>
|
||||
T* GetConfig(bool InResetConfigOnRequest = true) const { return Cast<T>(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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user