diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CommandBindings.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CommandBindings.cpp index 0abf2d3..33d6523 100644 --- a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CommandBindings.cpp +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CommandBindings.cpp @@ -1,5 +1,6 @@ #include "CogEngineWindow_CommandBindings.h" +#include "CogWindowManager.h" #include "CogWindowWidgets.h" #include "GameFramework/PlayerInput.h" #include "imgui.h" @@ -18,20 +19,6 @@ UCogEngineWindow_CommandBindings::UCogEngineWindow_CommandBindings() { } -//-------------------------------------------------------------------------------------------------------------------------- -void UCogEngineWindow_CommandBindings::PostInitProperties() -{ - Super::PostInitProperties(); - - if (bRegisterDefaultCommands) - { - if (RegisterDefaultCommands()) - { - bRegisterDefaultCommands = false; - } - } -} - //-------------------------------------------------------------------------------------------------------------------------- void UCogEngineWindow_CommandBindings::RenderContent() { @@ -61,7 +48,7 @@ void UCogEngineWindow_CommandBindings::RenderContent() ImGui::SameLine(); if (FCogWindowWidgets::ButtonWithTooltip("Sort", "Sort the array")) { - Sort(PlayerInput); + UCogWindowManager::SortCommands(PlayerInput); PlayerInput->SaveConfig(); } @@ -77,7 +64,7 @@ void UCogEngineWindow_CommandBindings::RenderContent() "[F5] Cog.ToggleSelectionMode\n" )) { - RegisterDefaultCommands(); + Owner->RegisterDefaultCommands(); } for (FKeyBind& KeyBind : PlayerInput->DebugExecBindings) @@ -105,68 +92,3 @@ void UCogEngineWindow_CommandBindings::RenderContent() PlayerInput->SaveConfig(); } } - - -//-------------------------------------------------------------------------------------------------------------------------- -void UCogEngineWindow_CommandBindings::Sort(UPlayerInput* PlayerInput) -{ - PlayerInput->DebugExecBindings.Sort([](const FKeyBind& Key1, const FKeyBind& Key2) - { - return Key1.Command.Compare(Key2.Command) < 0; - }); -} - -//-------------------------------------------------------------------------------------------------------------------------- -bool UCogEngineWindow_CommandBindings::RegisterDefaultCommands() -{ - APlayerController* PlayerController = GetLocalPlayerController(); - if (PlayerController == nullptr) - { - return false; - } - - UPlayerInput* PlayerInput = PlayerController->PlayerInput; - if (PlayerInput == nullptr) - { - return false; - } - - AddCogCommand(PlayerInput, "Cog.ToggleInput", EKeys::Tab); - AddCogCommand(PlayerInput, "Cog.LoadLayout 1", EKeys::F1); - AddCogCommand(PlayerInput, "Cog.LoadLayout 2", EKeys::F2); - AddCogCommand(PlayerInput, "Cog.LoadLayout 3", EKeys::F3); - AddCogCommand(PlayerInput, "Cog.LoadLayout 4", EKeys::F4); - AddCogCommand(PlayerInput, "Cog.ToggleSelectionMode", EKeys::F5); - - Sort(PlayerInput); - PlayerInput->SaveConfig(); - - return true; -} - -//-------------------------------------------------------------------------------------------------------------------------- -void UCogEngineWindow_CommandBindings::AddCogCommand(UPlayerInput* PlayerInput, const FString& Command, const FKey& Key) -{ - for (FKeyBind& KeyBind : PlayerInput->DebugExecBindings) - { - if (KeyBind.Key == Key && KeyBind.Command != Command) - { - KeyBind.Control = true; - KeyBind.bIgnoreCtrl = false; - } - } - - FKeyBind* ExistingKeyBind = PlayerInput->DebugExecBindings.FindByPredicate([Command](const FKeyBind& KeyBind){ return KeyBind.Command == Command; }); - if (ExistingKeyBind == nullptr) - { - ExistingKeyBind = &PlayerInput->DebugExecBindings.AddDefaulted_GetRef(); - } - - FKeyBind CogKeyBind; - CogKeyBind.Command = Command; - CogKeyBind.Control = false; - CogKeyBind.bIgnoreCtrl = true; - CogKeyBind.Key = Key; - - *ExistingKeyBind = CogKeyBind; -} \ No newline at end of file diff --git a/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_CommandBindings.h b/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_CommandBindings.h index 0102def..25a1451 100644 --- a/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_CommandBindings.h +++ b/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_CommandBindings.h @@ -18,20 +18,10 @@ public: protected: - virtual void PostInitProperties() override; - virtual void RenderHelp() override; virtual void RenderContent() override; - virtual bool RegisterDefaultCommands(); - private: - - UPROPERTY(Config) - bool bRegisterDefaultCommands = true; - void Sort(UPlayerInput* PlayerInput); - - void AddCogCommand(UPlayerInput* PlayerInput, const FString& Command, const FKey& Key); }; diff --git a/Plugins/Cog/Source/CogImgui/Private/CogImguiInputHelper.cpp b/Plugins/Cog/Source/CogImgui/Private/CogImguiInputHelper.cpp index 28066db..00595a8 100644 --- a/Plugins/Cog/Source/CogImgui/Private/CogImguiInputHelper.cpp +++ b/Plugins/Cog/Source/CogImgui/Private/CogImguiInputHelper.cpp @@ -5,6 +5,7 @@ #include "GameFramework/GameUserSettings.h" #include "GameFramework/InputSettings.h" #include "GameFramework/PlayerController.h" +#include "GameFramework/PlayerInput.h" #include "imgui_internal.h" #include "InputCoreTypes.h" @@ -227,7 +228,6 @@ bool FCogImguiInputHelper::IsKeyBoundToCommand(UWorld* World, const FKeyEvent& K return false; } - //-------------------------------------------------------------------------------------------------------------------------- bool FCogImguiInputHelper::IsConsoleEvent(const FKeyEvent& KeyEvent) { diff --git a/Plugins/Cog/Source/CogImgui/Public/CogImguiInputHelper.h b/Plugins/Cog/Source/CogImgui/Public/CogImguiInputHelper.h index 44f9793..fedbf3c 100644 --- a/Plugins/Cog/Source/CogImgui/Public/CogImguiInputHelper.h +++ b/Plugins/Cog/Source/CogImgui/Public/CogImguiInputHelper.h @@ -4,6 +4,7 @@ #include "CogImguiInputHelper.h" #include "imgui.h" +class UPlayerInput; struct FCogImGuiKeyInfo; struct FKeyBind; diff --git a/Plugins/Cog/Source/CogWindow/Private/CogWindowManager.cpp b/Plugins/Cog/Source/CogWindow/Private/CogWindowManager.cpp index 3b1ef24..548e3ff 100644 --- a/Plugins/Cog/Source/CogWindow/Private/CogWindowManager.cpp +++ b/Plugins/Cog/Source/CogWindow/Private/CogWindowManager.cpp @@ -2,6 +2,7 @@ #include "CogDebugDrawImGui.h" #include "CogImguiModule.h" +#include "CogImguiInputHelper.h" #include "CogImguiWidget.h" #include "CogWindow_Settings.h" #include "CogWindow_Spacing.h" @@ -15,6 +16,20 @@ UCogWindowManager::UCogWindowManager() { } +//-------------------------------------------------------------------------------------------------------------------------- +void UCogWindowManager::PostInitProperties() +{ + Super::PostInitProperties(); + + if (bRegisterDefaultCommands) + { + if (RegisterDefaultCommands()) + { + bRegisterDefaultCommands = false; + } + } +} + //-------------------------------------------------------------------------------------------------------------------------- void UCogWindowManager::InitializeInternal() { @@ -515,4 +530,83 @@ void UCogWindowManager::ResetAllWindowsConfig() { Window->ResetConfig(); } +} + +//-------------------------------------------------------------------------------------------------------------------------- +bool UCogWindowManager::RegisterDefaultCommands() +{ + UWorld* World = GetWorld(); + if (World == nullptr) + { + return false; + } + + APlayerController* PlayerController = FCogImguiInputHelper::GetFirstLocalPlayerController(*World); + if (PlayerController == nullptr) + { + return false; + } + + UPlayerInput* PlayerInput = PlayerController->PlayerInput; + if (PlayerInput == nullptr) + { + return false; + } + + AddCommand(PlayerInput, "Cog.ToggleInput", EKeys::Tab); + AddCommand(PlayerInput, "Cog.LoadLayout 1", EKeys::F1); + AddCommand(PlayerInput, "Cog.LoadLayout 2", EKeys::F2); + AddCommand(PlayerInput, "Cog.LoadLayout 3", EKeys::F3); + AddCommand(PlayerInput, "Cog.LoadLayout 4", EKeys::F4); + AddCommand(PlayerInput, "Cog.ToggleSelectionMode", EKeys::F5); + + SortCommands(PlayerInput); + PlayerInput->SaveConfig(); + + return true; +} + +//-------------------------------------------------------------------------------------------------------------------------- +void UCogWindowManager::AddCommand(UPlayerInput* PlayerInput, const FString& Command, const FKey& Key) +{ + //--------------------------------------------------- + // Reassign conflicting commands + //--------------------------------------------------- + for (FKeyBind& KeyBind : PlayerInput->DebugExecBindings) + { + if (KeyBind.Key == Key && KeyBind.Command != Command) + { + KeyBind.Control = true; + KeyBind.bIgnoreCtrl = false; + } + } + + //--------------------------------------------------- + // Find or add desired command + //--------------------------------------------------- + FKeyBind* ExistingKeyBind = PlayerInput->DebugExecBindings.FindByPredicate([Command](const FKeyBind& KeyBind) { return KeyBind.Command == Command; }); + if (ExistingKeyBind == nullptr) + { + ExistingKeyBind = &PlayerInput->DebugExecBindings.AddDefaulted_GetRef(); + } + + //--------------------------------------------------- + // Assign the key to the command + //--------------------------------------------------- + FKeyBind CogKeyBind; + CogKeyBind.Command = Command; + CogKeyBind.Control = false; + CogKeyBind.bIgnoreCtrl = true; + CogKeyBind.Key = Key; + + *ExistingKeyBind = CogKeyBind; +} + +//-------------------------------------------------------------------------------------------------------------------------- +void UCogWindowManager::SortCommands(UPlayerInput* PlayerInput) +{ + PlayerInput->DebugExecBindings.Sort([](const FKeyBind& Key1, const FKeyBind& Key2) + { + return Key1.Command.Compare(Key2.Command) < 0; + }); } \ No newline at end of file diff --git a/Plugins/Cog/Source/CogWindow/Public/CogWindowManager.h b/Plugins/Cog/Source/CogWindow/Public/CogWindowManager.h index a3f0edf..fe4ad14 100644 --- a/Plugins/Cog/Source/CogWindow/Public/CogWindowManager.h +++ b/Plugins/Cog/Source/CogWindow/Public/CogWindowManager.h @@ -21,13 +21,15 @@ class COGWINDOW_API UCogWindowManager : public UObject public: UCogWindowManager(); - void Shutdown(); + virtual void PostInitProperties() override; - void SortMainMenu(); + virtual void Shutdown(); - void Render(float DeltaTime); + virtual void SortMainMenu(); - void Tick(float DeltaTime); + virtual void Render(float DeltaTime); + + virtual void Tick(float DeltaTime); template T* CreateWindow(const FString& Name, bool AddToMainMenu = true) @@ -39,41 +41,47 @@ public: return Window; } - void AddWindow(UCogWindow* Window, bool AddToMainMenu = true); + virtual void AddWindow(UCogWindow* Window, bool AddToMainMenu = true); - void AddMainMenuWidget(UCogWindow* Window); + virtual void AddMainMenuWidget(UCogWindow* Window); - UCogWindow* FindWindowByID(ImGuiID ID); + virtual UCogWindow* FindWindowByID(ImGuiID ID); - void CloseAllWindows(); + virtual void CloseAllWindows(); - void ResetLayout(); + virtual void ResetLayout(); - void LoadLayout(int32 LayoutIndex); + virtual void LoadLayout(int32 LayoutIndex); - void SaveLayout(int32 LayoutIndex); + virtual void SaveLayout(int32 LayoutIndex); - bool GetHideAllWindows() const { return bHideAllWindows; } + virtual bool GetHideAllWindows() const { return bHideAllWindows; } - void SetHideAllWindows(bool Value); + virtual void SetHideAllWindows(bool Value); - float GetDPIScale() const { return DPIScale; } + virtual float GetDPIScale() const { return DPIScale; } - void SetDPIScale(float Value); + virtual void SetDPIScale(float Value); - bool GetCompactMode() const { return bCompactMode; } + virtual bool GetCompactMode() const { return bCompactMode; } - void SetCompactMode(bool Value) { bCompactMode = Value; } + virtual void SetCompactMode(bool Value) { bCompactMode = Value; } - bool GetShowHelp() const { return bShowHelp; } + virtual bool GetShowHelp() const { return bShowHelp; } - void SetShowHelp(bool Value) { bShowHelp = Value; } + virtual void SetShowHelp(bool Value) { bShowHelp = Value; } - bool GetPreviewWindowsInMenu() const { return bShowWindowsInMainMenu; } + virtual bool GetPreviewWindowsInMenu() const { return bShowWindowsInMainMenu; } - void SetPreviewWindowsInMenu(bool Value) { bShowWindowsInMainMenu = Value; } + virtual void SetPreviewWindowsInMenu(bool Value) { bShowWindowsInMainMenu = Value; } - void ResetAllWindowsConfig(); + virtual void ResetAllWindowsConfig(); + + virtual bool RegisterDefaultCommands(); + + static void AddCommand(UPlayerInput* PlayerInput, const FString& Command, const FKey& Key); + + static void SortCommands(UPlayerInput* PlayerInput); protected: @@ -86,17 +94,17 @@ protected: TArray SubMenus; }; - void InitializeInternal(); + virtual void InitializeInternal(); - void RefreshDPIScale(); + virtual void RefreshDPIScale(); - void RenderMainMenu(); + virtual void RenderMainMenu(); - FMenu* AddMenu(const FString& Name); + virtual FMenu* AddMenu(const FString& Name); - void RenderOptionMenu(FMenu& Menu); + virtual void RenderOptionMenu(FMenu& Menu); - void RenderMenuItem(UCogWindow& Window, const char* MenuItemName); + virtual void RenderMenuItem(UCogWindow& Window, const char* MenuItemName); static void SettingsHandler_ClearAll(ImGuiContext* ctx, ImGuiSettingsHandler*); @@ -137,6 +145,9 @@ protected: UPROPERTY(Config) bool bShowWindowsInMainMenu = true; + UPROPERTY(Config) + bool bRegisterDefaultCommands = true; + TSharedPtr ImGuiWidget = nullptr; FMenu MainMenu; diff --git a/Source/CogSample/CogSampleExecCalculation_Damage.cpp b/Source/CogSample/CogSampleExecCalculation_Damage.cpp index 5e5eca0..0dd4fc2 100644 --- a/Source/CogSample/CogSampleExecCalculation_Damage.cpp +++ b/Source/CogSample/CogSampleExecCalculation_Damage.cpp @@ -172,6 +172,8 @@ void UCogSampleFunctionLibrary_Damage::ExecuteDamageGameplayCue( GameplayCueParameters.Location = HitResult.Location; GameplayCueParameters.Normal = HitResult.ImpactNormal; + FGameplayTagContainer SpecAssetTags; + EffectSpec.GetAllAssetTags(SpecAssetTags); TArray Tags; SpecAssetTags.GetGameplayTagArray(Tags);