diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CommandBindings.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CommandBindings.cpp index b14f885..4786fa0 100644 --- a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CommandBindings.cpp +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CommandBindings.cpp @@ -54,7 +54,7 @@ void FCogEngineWindow_CommandBindings::RenderContent() "Disable the existing Unreal command shortcuts mapped to same shortcuts Cog is using. Typically, if the F1 shortcut is used to toggle Inputs, the Unreal wireframe command will get disabled." )) { - GetOwner()->DisableConflictingCommands(); + GetOwner()->OnShortcutsDefined(); } for (FKeyBind& KeyBind : PlayerInput->DebugExecBindings) diff --git a/Plugins/Cog/Source/CogImgui/Private/CogImguiInputHelper.cpp b/Plugins/Cog/Source/CogImgui/Private/CogImguiInputHelper.cpp index fc26e4e..341f918 100644 --- a/Plugins/Cog/Source/CogImgui/Private/CogImguiInputHelper.cpp +++ b/Plugins/Cog/Source/CogImgui/Private/CogImguiInputHelper.cpp @@ -1,5 +1,7 @@ #include "CogImguiInputHelper.h" +#include + #include "CogImguiKeyInfo.h" #include "Engine/World.h" #include "Framework/Application/SlateApplication.h" @@ -16,6 +18,9 @@ #include "Kismet2/DebuggerCommands.h" #endif //WITH_EDITOR +//-------------------------------------------------------------------------------------------------------------------------- + TArray FCogImguiInputHelper::CogShortcuts; + //-------------------------------------------------------------------------------------------------------------------------- APlayerController* FCogImguiInputHelper::GetFirstLocalPlayerController(const UWorld& World) { @@ -45,23 +50,35 @@ UPlayerInput* FCogImguiInputHelper::GetPlayerInput(const UWorld& World) } //-------------------------------------------------------------------------------------------------------------------------- -bool FCogImguiInputHelper::IsKeyEventHandled(UWorld* World, const FKeyEvent& KeyEvent) +bool FCogImguiInputHelper::IsTopPriorityKey(UWorld* InWorld, const FKey& InKey) { + FKeyEvent KeyEvent(InKey, FModifierKeysState(), 0, false, 0, 0); + return IsTopPriorityKeyEvent(InWorld, KeyEvent); +} + +//-------------------------------------------------------------------------------------------------------------------------- +bool FCogImguiInputHelper::IsTopPriorityKeyEvent(UWorld* InWorld, const FKeyEvent& InKeyEvent) +{ + //------------------------------------------------------------------------------------------------ + // We want the user to be able to use Cog shortcuts when imgui has the input. + //------------------------------------------------------------------------------------------------ + for (const FCogImGuiKeyInfo& KeyInfo : CogShortcuts) + { + if (IsKeyEventMatchingKeyInfo(InKeyEvent, KeyInfo)) + { return true; } + } + //------------------------------------------------------------------------------------------------ // We want the user to be able to open the console command when imgui has the input. //------------------------------------------------------------------------------------------------ - if (IsConsoleEvent(KeyEvent)) - { - return false; - } + if (IsConsoleEvent(InKeyEvent)) + { return true; } //------------------------------------------------------------------------------------------------ // We want the user to be able to stop its session by pressing Esc, even when imgui has the input //------------------------------------------------------------------------------------------------ - if (IsStopPlaySessionEvent(KeyEvent)) - { - return false; - } + if (IsStopPlaySessionEvent(InKeyEvent)) + { return true; } //------------------------------------------------------------------------------------------------ // If we receive a key modifier, we want to let others systems know about it. @@ -71,22 +88,16 @@ bool FCogImguiInputHelper::IsKeyEventHandled(UWorld* World, const FKeyEvent& Key // and not the Key+Modifier event. // We update ImGui modifier keys in SCogImguiWidget::TickKeyModifiers(). //------------------------------------------------------------------------------------------------ - if (KeyEvent.GetKey().IsModifierKey()) - { - return false; - } + if (InKeyEvent.GetKey().IsModifierKey()) + { return true; } //------------------------------------------------------------------------------------------------ // We want the user to be able to use command bindings, even when imgui has the input. - // We actually use a console command to toggle the input from the game to imgui, and other - // windows command such as LoadLayout. //------------------------------------------------------------------------------------------------ - if (IsKeyBoundToCommand(World, KeyEvent)) - { - return false; - } + if (IsKeyBoundToCommand(InWorld, InKeyEvent)) + { return true; } - return true; + return false; } //-------------------------------------------------------------------------------------------------------------------------- @@ -97,7 +108,7 @@ bool FCogImguiInputHelper::IsCheckBoxStateMatchingValue(ECheckBoxState CheckBoxS } //-------------------------------------------------------------------------------------------------------------------------- -bool FCogImguiInputHelper::IsCheckBoxStateMatchingKeybindModifier(ECheckBoxState InCheckBoxState, bool InRequireModifier, bool InIgnoreModifier) +bool FCogImguiInputHelper::IsCheckBoxStateMatchingKeyBindModifier(ECheckBoxState InCheckBoxState, bool InRequireModifier, bool InIgnoreModifier) { switch (InCheckBoxState) { @@ -109,13 +120,13 @@ bool FCogImguiInputHelper::IsCheckBoxStateMatchingKeybindModifier(ECheckBoxState } //-------------------------------------------------------------------------------------------------------------------------- -bool FCogImguiInputHelper::IsKeyEventMatchingKeyInfo(const FKeyEvent& KeyEvent, const FCogImGuiKeyInfo& KeyInfo) +bool FCogImguiInputHelper::IsKeyEventMatchingKeyInfo(const FKeyEvent& InKeyEvent, const FCogImGuiKeyInfo& InKeyInfo) { - const bool Result = (KeyInfo.Key == KeyEvent.GetKey()) - && IsCheckBoxStateMatchingValue(KeyInfo.Shift, KeyEvent.IsShiftDown()) - && IsCheckBoxStateMatchingValue(KeyInfo.Ctrl, KeyEvent.IsControlDown()) - && IsCheckBoxStateMatchingValue(KeyInfo.Alt, KeyEvent.IsAltDown()) - && IsCheckBoxStateMatchingValue(KeyInfo.Cmd, KeyEvent.IsCommandDown()); + const bool Result = (InKeyInfo.Key == InKeyEvent.GetKey()) + && IsCheckBoxStateMatchingValue(InKeyInfo.Shift, InKeyEvent.IsShiftDown()) + && IsCheckBoxStateMatchingValue(InKeyInfo.Ctrl, InKeyEvent.IsControlDown()) + && IsCheckBoxStateMatchingValue(InKeyInfo.Alt, InKeyEvent.IsAltDown()) + && IsCheckBoxStateMatchingValue(InKeyInfo.Cmd, InKeyEvent.IsCommandDown()); return Result; } @@ -182,10 +193,10 @@ void FCogImguiInputHelper::KeyInfoToKeyBind(const FCogImGuiKeyInfo& KeyInfo, FKe bool FCogImguiInputHelper::IsKeyBindMatchingKeyInfo(const FKeyBind& InKeyBind, const FCogImGuiKeyInfo& InKeyInfo) { const bool Result = (InKeyInfo.Key == InKeyBind.Key) - && IsCheckBoxStateMatchingKeybindModifier(InKeyInfo.Shift, InKeyBind.Shift, InKeyBind.bIgnoreShift) - && IsCheckBoxStateMatchingKeybindModifier(InKeyInfo.Ctrl, InKeyBind.Control, InKeyBind.bIgnoreCtrl) - && IsCheckBoxStateMatchingKeybindModifier(InKeyInfo.Alt, InKeyBind.Alt, InKeyBind.bIgnoreAlt) - && IsCheckBoxStateMatchingKeybindModifier(InKeyInfo.Cmd, InKeyBind.Cmd, InKeyBind.bIgnoreCmd); + && IsCheckBoxStateMatchingKeyBindModifier(InKeyInfo.Shift, InKeyBind.Shift, InKeyBind.bIgnoreShift) + && IsCheckBoxStateMatchingKeyBindModifier(InKeyInfo.Ctrl, InKeyBind.Control, InKeyBind.bIgnoreCtrl) + && IsCheckBoxStateMatchingKeyBindModifier(InKeyInfo.Alt, InKeyBind.Alt, InKeyBind.bIgnoreAlt) + && IsCheckBoxStateMatchingKeyBindModifier(InKeyInfo.Cmd, InKeyBind.Cmd, InKeyBind.bIgnoreCmd); return Result; } @@ -326,33 +337,11 @@ FString FCogImguiInputHelper::CommandToString(const UPlayerInput* PlayerInput, c } //-------------------------------------------------------------------------------------------------------------------------- -FString FCogImguiInputHelper::KeyBindToString(const FKeyBind& KeyBind) +FString FCogImguiInputHelper::KeyBindToString(const FKeyBind& InKeyBind) { - FString Result = "["; - if (KeyBind.Alt) - { - Result += FString("Alt "); - } - - if (KeyBind.Shift) - { - Result += FString("Shift "); - } - - if (KeyBind.Control) - { - Result += FString("Ctrl "); - } - - if (KeyBind.Cmd) - { - Result += FString("Cmd "); - } - - Result += KeyBind.Key.ToString(); - Result += FString("]"); - - return Result; + FCogImGuiKeyInfo KeyInfo; + KeyBindToKeyInfo(InKeyBind, KeyInfo); + return KeyInfoToString(KeyInfo); } //-------------------------------------------------------------------------------------------------------------------------- @@ -471,6 +460,32 @@ bool FCogImguiInputHelper::IsMouseInsideMainViewport() return false; } +//-------------------------------------------------------------------------------------------------------------------------- +void FCogImguiInputHelper::SetShortcuts(const UWorld& World, const TArray& InShortcuts, bool InDisableCommandsConflictingWithShortcuts) +{ + CogShortcuts = InShortcuts; + + if (InDisableCommandsConflictingWithShortcuts == false ) + { return; } + + UPlayerInput* PlayerInput = FCogImguiInputHelper::GetPlayerInput(World); + if (PlayerInput == nullptr) + { return; } + + for (const FCogImGuiKeyInfo& Shortcut : CogShortcuts) + { + for (FKeyBind& KeyBind : PlayerInput->DebugExecBindings) + { + if (IsKeyBindMatchingKeyInfo(KeyBind, Shortcut)) + { + KeyBind.bDisabled = true; + } + } + } + + PlayerInput->SaveConfig(); +} + //-------------------------------------------------------------------------------------------------------------------------- ImGuiKey FCogImguiInputHelper::ToImKey(const FKey& Key) { @@ -615,3 +630,4 @@ ImGuiKey FCogImguiInputHelper::ToImKey(const FKey& Key) const ImGuiKey* Result = LookupMap.Find(Key); return (Result != nullptr) ? *Result : ImGuiKey_None; } + diff --git a/Plugins/Cog/Source/CogImgui/Private/CogImguiWidget.cpp b/Plugins/Cog/Source/CogImgui/Private/CogImguiWidget.cpp index f2377c8..7052de0 100644 --- a/Plugins/Cog/Source/CogImgui/Private/CogImguiWidget.cpp +++ b/Plugins/Cog/Source/CogImgui/Private/CogImguiWidget.cpp @@ -152,7 +152,7 @@ FReply SCogImguiWidget::HandleKeyEvent(const FKeyEvent& KeyEvent, bool Down) return FReply::Unhandled(); } - if (FCogImguiInputHelper::IsKeyEventHandled(Context->GetGameViewport()->GetWorld(), KeyEvent) == false) + if (FCogImguiInputHelper::IsTopPriorityKeyEvent(Context->GetGameViewport()->GetWorld(), KeyEvent)) { return FReply::Unhandled(); } @@ -169,10 +169,10 @@ FReply SCogImguiWidget::HandleKeyEvent(const FKeyEvent& KeyEvent, bool Down) return FReply::Unhandled(); } - if (IO.WantTextInput == false) - { - return FReply::Unhandled(); - } + // if (IO.WantTextInput == false) + // { + // return FReply::Unhandled(); + // } return FReply::Handled(); } diff --git a/Plugins/Cog/Source/CogImgui/Public/CogImguiInputHelper.h b/Plugins/Cog/Source/CogImgui/Public/CogImguiInputHelper.h index dd58c06..f091139 100644 --- a/Plugins/Cog/Source/CogImgui/Public/CogImguiInputHelper.h +++ b/Plugins/Cog/Source/CogImgui/Public/CogImguiInputHelper.h @@ -22,15 +22,17 @@ public: static UPlayerInput* GetPlayerInput(const UWorld& World); - static bool IsKeyEventHandled(UWorld* World, const FKeyEvent& KeyEvent); + static bool IsTopPriorityKey(UWorld* InWorld, const FKey& InKey); + + static bool IsTopPriorityKeyEvent(UWorld* InWorld, const FKeyEvent& InKeyEvent); static bool WasKeyInfoJustPressed(APlayerController& PlayerController, const FCogImGuiKeyInfo& KeyInfo); static bool IsCheckBoxStateMatchingValue(ECheckBoxState CheckBoxState, bool bValue); - static bool IsCheckBoxStateMatchingKeybindModifier(ECheckBoxState InCheckBoxState, bool InRequireModifier, bool InIgnoreModifier); + static bool IsCheckBoxStateMatchingKeyBindModifier(ECheckBoxState InCheckBoxState, bool InRequireModifier, bool InIgnoreModifier); - static bool IsKeyEventMatchingKeyInfo(const FKeyEvent& KeyEvent, const FCogImGuiKeyInfo& InputChord); + static bool IsKeyEventMatchingKeyInfo(const FKeyEvent& InKeyEvent, const FCogImGuiKeyInfo& InKeyInfo); static bool IsKeyBindMatchingKeyInfo(const FKeyBind& InKeyBind, const FCogImGuiKeyInfo& InKeyInfo); @@ -60,7 +62,7 @@ public: static FString CommandToString(const UPlayerInput* PlayerInput, const FString& Command); - static FString KeyBindToString(const FKeyBind& KeyBind); + static FString KeyBindToString(const FKeyBind& InKeyBind); static FString KeyInfoToString(const FCogImGuiKeyInfo& InKeyInfo); @@ -68,9 +70,14 @@ public: static bool IsKeyBoundToCommand(const UPlayerInput* InPlayerInput, const FKeyEvent& KeyEvent); + static void SetShortcuts(const UWorld& World, const TArray& InShortcuts, bool InDisableCommandsConflictingWithShortcuts); + template* = nullptr> static ImWchar CastInputChar(T Char) { return static_cast(Char); } + +private: + static TArray CogShortcuts; }; diff --git a/Plugins/Cog/Source/CogWindow/Private/CogWindowManager.cpp b/Plugins/Cog/Source/CogWindow/Private/CogWindowManager.cpp index 20a51f6..5f4f98a 100644 --- a/Plugins/Cog/Source/CogWindow/Private/CogWindowManager.cpp +++ b/Plugins/Cog/Source/CogWindow/Private/CogWindowManager.cpp @@ -51,10 +51,7 @@ void UCogWindowManager::InitializeInternal() SpaceWindows.Add(AddWindow("Spacing 4", false)); Settings = GetConfig(); - if (Settings->bResolveShortcutsConflicts) - { - DisableConflictingCommands(); - } + OnShortcutsDefined(); LayoutsWindow = AddWindow("Window.Layouts", false); SettingsWindow = AddWindow("Window.Settings", false); @@ -843,10 +840,10 @@ void UCogWindowManager::HandleInputs() if (PlayerInput == nullptr) { return; } - if (ImGui::GetIO().WantTextInput) + if (Settings->bDisableShortcutsWhenImGuiWantTextInput && ImGui::GetIO().WantTextInput) { return; } - if (FCogImguiInputHelper::IsKeyInfoPressed(PlayerInput, Settings->ToggleImguiInputShortcut)) + if (FCogImguiInputHelper::IsKeyInfoPressed(PlayerInput, Settings->ToggleImGuiInputShortcut)) { ToggleInputMode(); } @@ -888,42 +885,15 @@ bool UCogWindowManager::GetActivateSelectionMode() const } //-------------------------------------------------------------------------------------------------------------------------- -void UCogWindowManager::DisableConflictingCommands() const +void UCogWindowManager::OnShortcutsDefined() const { if (GetWorld() == nullptr) { return; } - UPlayerInput* PlayerInput = FCogImguiInputHelper::GetPlayerInput(*GetWorld()); - if (PlayerInput == nullptr) - { return; } - - DisableConflictingCommand(PlayerInput, Settings->ToggleImguiInputShortcut); - DisableConflictingCommand(PlayerInput, Settings->ToggleSelectionShortcut); + TArray Shortcuts = { Settings->ToggleImGuiInputShortcut, Settings->ToggleSelectionShortcut }; + Shortcuts.Append(Settings->LoadLayoutShortcuts); + Shortcuts.Append(Settings->SaveLayoutShortcuts); - for (int32 i = 0; i < Settings->LoadLayoutShortcuts.Num(); ++i) - { - DisableConflictingCommand(PlayerInput, Settings->LoadLayoutShortcuts[i]); - } - - for (int32 i = 0; i < Settings->SaveLayoutShortcuts.Num(); ++i) - { - DisableConflictingCommand(PlayerInput, Settings->SaveLayoutShortcuts[i]); - } - - PlayerInput->SaveConfig(); + FCogImguiInputHelper::SetShortcuts(*GetWorld(), Shortcuts, Settings->bDisableConflictingCommands); } -//-------------------------------------------------------------------------------------------------------------------------- -void UCogWindowManager::DisableConflictingCommand(UPlayerInput* InPlayerInput, const FCogImGuiKeyInfo& InShortcut) -{ - if (InPlayerInput == nullptr) - { return; } - - for (FKeyBind& KeyBind :InPlayerInput->DebugExecBindings) - { - if (FCogImguiInputHelper::IsKeyBindMatchingKeyInfo(KeyBind, InShortcut)) - { - KeyBind.bDisabled = true; - } - } -} diff --git a/Plugins/Cog/Source/CogWindow/Private/CogWindowWidgets.cpp b/Plugins/Cog/Source/CogWindow/Private/CogWindowWidgets.cpp index e7fdac9..7245582 100644 --- a/Plugins/Cog/Source/CogWindow/Private/CogWindowWidgets.cpp +++ b/Plugins/Cog/Source/CogWindow/Private/CogWindowWidgets.cpp @@ -40,6 +40,18 @@ void FCogWindowWidgets::EndTableTooltip() ImGui::PopStyleVar(2); } +//-------------------------------------------------------------------------------------------------------------------------- +void FCogWindowWidgets::ItemTooltipWrappedText(const char* InText) +{ + if (ImGui::BeginItemTooltip()) + { + ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f); + ImGui::TextUnformatted(InText); + ImGui::PopTextWrapPos(); + ImGui::EndTooltip(); + } +} + //-------------------------------------------------------------------------------------------------------------------------- bool FCogWindowWidgets::BeginItemTableTooltip() { diff --git a/Plugins/Cog/Source/CogWindow/Private/CogWindow_Settings.cpp b/Plugins/Cog/Source/CogWindow/Private/CogWindow_Settings.cpp index 7a28d47..b418747 100644 --- a/Plugins/Cog/Source/CogWindow/Private/CogWindow_Settings.cpp +++ b/Plugins/Cog/Source/CogWindow/Private/CogWindow_Settings.cpp @@ -77,8 +77,8 @@ void FCogWindow_Settings::RenderContent() { Context.SetEnableInput(bEnableInput); } - ImGui::SetItemTooltip("Enable ImGui inputs. When enabled the ImGui menu is shown and inputs are forwarded to ImGui."); - FCogWindowWidgets::MenuItemShortcut("EnableInputShortcut", FCogImguiInputHelper::KeyInfoToString(Config->ToggleImguiInputShortcut)); + FCogWindowWidgets::ItemTooltipWrappedText("Enable ImGui inputs. When enabled the ImGui menu is shown and inputs are forwarded to ImGui."); + FCogWindowWidgets::MenuItemShortcut("EnableInputShortcut", FCogImguiInputHelper::KeyInfoToString(Config->ToggleImGuiInputShortcut)); //------------------------------------------------------------------------------------------- bool bShareKeyboard = Context.GetShareKeyboard(); @@ -86,7 +86,7 @@ void FCogWindow_Settings::RenderContent() { Context.SetShareKeyboard(bShareKeyboard); } - ImGui::SetItemTooltip("Forward the keyboard inputs to the game when ImGui does not need them."); + FCogWindowWidgets::ItemTooltipWrappedText("Forward the keyboard inputs to the game when ImGui does not need them."); //------------------------------------------------------------------------------------------- bool bShareMouse = Context.GetShareMouse(); @@ -94,7 +94,7 @@ void FCogWindow_Settings::RenderContent() { Context.SetShareMouse(bShareMouse); } - ImGui::SetItemTooltip("Forward mouse inputs to the game when ImGui does not need them."); + FCogWindowWidgets::ItemTooltipWrappedText("Forward mouse inputs to the game when ImGui does not need them."); //------------------------------------------------------------------------------------------- if (bShareMouse == false) @@ -107,7 +107,7 @@ void FCogWindow_Settings::RenderContent() { Context.SetShareMouseWithGameplay(bShareMouseWithGameplay); } - ImGui::SetItemTooltip("When disabled, mouse inputs are only forwarded to game menus. " + FCogWindowWidgets::ItemTooltipWrappedText("When disabled, mouse inputs are only forwarded to game menus. " "When enabled, mouse inputs are also forwarded to the gameplay. Note that this mode: \n" " - Force the cursor to be visible.\n" " - Prevent the interaction of Cog's transform gizmos.\n" @@ -120,15 +120,21 @@ void FCogWindow_Settings::RenderContent() //------------------------------------------------------------------------------------------- ImGui::CheckboxFlags("Keyboard Navigation", &IO.ConfigFlags, ImGuiConfigFlags_NavEnableKeyboard); - ImGui::SetItemTooltip("Use the keyboard to navigate in ImGui windows with the following keys : Tab, Directional Arrows, Space, Enter."); + FCogWindowWidgets::ItemTooltipWrappedText("Use the keyboard to navigate in ImGui windows with the following keys : Tab, Directional Arrows, Space, Enter."); //------------------------------------------------------------------------------------------- //ImGui::CheckboxFlags("Gamepad Navigation", &IO.ConfigFlags, ImGuiConfigFlags_NavEnableGamepad); - //ImGui::SetItemTooltip("Use the gamepad to navigate in ImGui windows."); + //FCogWindowWidgets::ItemTooltipWrappedText("Use the gamepad to navigate in ImGui windows."); //------------------------------------------------------------------------------------------- - ImGui::Checkbox("Disable Conflicting Commands", &Config->bResolveShortcutsConflicts); - ImGui::SetItemTooltip("Disable the existing Unreal command shortcuts mapped to same shortcuts Cog is using. Typically, if the F1 shortcut is used to toggle Inputs, the Unreal wireframe command will get disabled."); + ImGui::Checkbox("Disable Conflicting Commands", &Config->bDisableConflictingCommands); + FCogWindowWidgets::ItemTooltipWrappedText("Disable the existing Unreal command shortcuts mapped to same shortcuts Cog is using. Typically, if the F1 shortcut is used to toggle Inputs, the Unreal wireframe command will get disabled."); + + //------------------------------------------------------------------------------------------- + ImGui::Checkbox("Disable shortcuts when ImGui want text input", &Config->bDisableShortcutsWhenImGuiWantTextInput); + FCogWindowWidgets::ItemTooltipWrappedText("Disable Cog's shortcuts (ToggleInput, ToggleSelectionMode, LoadLayout, ...) when ImGui want text input." + " This can be required if the shortcuts are mapped by keys generating a text input (letters, or Backspace for example)." + " This is not required if the shortcuts are set to keys such as F1 or F2."); } //------------------------------------------------------------------------------------------- @@ -138,19 +144,19 @@ void FCogWindow_Settings::RenderContent() { FCogImguiHelper::SetFlags(IO.ConfigFlags, ImGuiConfigFlags_ViewportsEnable, Config->bEnableViewports); } - ImGui::SetItemTooltip("Enable moving ImGui windows outside of the main viewport."); + FCogWindowWidgets::ItemTooltipWrappedText("Enable moving ImGui windows outside of the main viewport."); //------------------------------------------------------------------------------------------- ImGui::Checkbox("Compact Mode", &Config->bCompactMode); - ImGui::SetItemTooltip("Enable compact mode."); + FCogWindowWidgets::ItemTooltipWrappedText("Enable compact mode."); //------------------------------------------------------------------------------------------- ImGui::Checkbox("Show Windows In Main Menu", &Config->bShowWindowsInMainMenu); - ImGui::SetItemTooltip("Show the content of the windows when hovering the window menu item."); + FCogWindowWidgets::ItemTooltipWrappedText("Show the content of the windows when hovering the window menu item."); //------------------------------------------------------------------------------------------- ImGui::Checkbox("Show Help", &Config->bShowHelp); - ImGui::SetItemTooltip("Show windows help on the window menu items."); + FCogWindowWidgets::ItemTooltipWrappedText("Show windows help on the window menu items."); //------------------------------------------------------------------------------------------- FCogWindowWidgets::SetNextItemToShortWidth(); @@ -170,7 +176,7 @@ void FCogWindow_Settings::RenderContent() //------------------------------------------------------------------------------------------- if (ImGui::CollapsingHeader("Shortcuts", ImGuiTreeNodeFlags_DefaultOpen)) { - RenderShortcut("Toggle ImGui Input", Config->ToggleImguiInputShortcut); + RenderShortcut("Toggle ImGui Input", Config->ToggleImGuiInputShortcut); RenderShortcut("Toggle Selection", Config->ToggleSelectionShortcut); ImGui::Separator(); @@ -232,9 +238,6 @@ void FCogWindow_Settings::RenderShortcut(const char* Label, FCogImGuiKeyInfo& Ke { if (FCogWindowWidgets::InputKey(Label, KeyInfo)) { - if (Config->bResolveShortcutsConflicts) - { - GetOwner()->DisableConflictingCommands(); - } + GetOwner()->OnShortcutsDefined(); } } diff --git a/Plugins/Cog/Source/CogWindow/Public/CogWindowManager.h b/Plugins/Cog/Source/CogWindow/Public/CogWindowManager.h index b616c84..f5b197d 100644 --- a/Plugins/Cog/Source/CogWindow/Public/CogWindowManager.h +++ b/Plugins/Cog/Source/CogWindow/Public/CogWindowManager.h @@ -79,7 +79,7 @@ public: static void SortCommands(UPlayerInput* PlayerInput); - void DisableConflictingCommands() const; + void OnShortcutsDefined() const; protected: diff --git a/Plugins/Cog/Source/CogWindow/Public/CogWindowWidgets.h b/Plugins/Cog/Source/CogWindow/Public/CogWindowWidgets.h index 408984b..1c234fb 100644 --- a/Plugins/Cog/Source/CogWindow/Public/CogWindowWidgets.h +++ b/Plugins/Cog/Source/CogWindow/Public/CogWindowWidgets.h @@ -27,6 +27,8 @@ public: static void EndTableTooltip(); + static void ItemTooltipWrappedText(const char* InText); + static bool BeginItemTableTooltip(); static void EndItemTableTooltip(); diff --git a/Plugins/Cog/Source/CogWindow/Public/CogWindow_Settings.h b/Plugins/Cog/Source/CogWindow/Public/CogWindow_Settings.h index d20d54f..f2d08b4 100644 --- a/Plugins/Cog/Source/CogWindow/Public/CogWindow_Settings.h +++ b/Plugins/Cog/Source/CogWindow/Public/CogWindow_Settings.h @@ -80,10 +80,13 @@ public: bool bNavEnableKeyboard = false; UPROPERTY(Config) - bool bResolveShortcutsConflicts = true; - + bool bDisableConflictingCommands = true; + UPROPERTY(Config) - FCogImGuiKeyInfo ToggleImguiInputShortcut = FCogImGuiKeyInfo(EKeys::F1); + bool bDisableShortcutsWhenImGuiWantTextInput = false; + + UPROPERTY(Config) + FCogImGuiKeyInfo ToggleImGuiInputShortcut = FCogImGuiKeyInfo(EKeys::F1); UPROPERTY(Config) FCogImGuiKeyInfo ToggleSelectionShortcut = FCogImGuiKeyInfo(EKeys::F5); @@ -114,10 +117,13 @@ public: bShareMouse = false; bShareKeyboard = false; bNavEnableKeyboard = false; + bDisableConflictingCommands = true; + bDisableShortcutsWhenImGuiWantTextInput = false; //bNavEnableGamepad = false; //bNavNoCaptureInput = true; - ToggleImguiInputShortcut = FCogImGuiKeyInfo(EKeys::F1); + + ToggleImGuiInputShortcut = FCogImGuiKeyInfo(EKeys::F1); ToggleSelectionShortcut = FCogImGuiKeyInfo(EKeys::F5); LoadLayoutShortcuts = { FCogImGuiKeyInfo(EKeys::F2), FCogImGuiKeyInfo(EKeys::F3), FCogImGuiKeyInfo(EKeys::F4), FCogImGuiKeyInfo()}; SaveLayoutShortcuts = { FCogImGuiKeyInfo(), FCogImGuiKeyInfo(), FCogImGuiKeyInfo(), FCogImGuiKeyInfo()}; diff --git a/Plugins/CogCommonUI/CogCommonUI.uplugin b/Plugins/CogCommonUI/CogCommonUI.uplugin new file mode 100644 index 0000000..db41d04 --- /dev/null +++ b/Plugins/CogCommonUI/CogCommonUI.uplugin @@ -0,0 +1,34 @@ +{ + "FileVersion": 1, + "Version": 1, + "VersionName": "1.0", + "FriendlyName": "CogCommonUI", + "Description": "", + "Category": "Other", + "CreatedBy": "Arnaud Jamin", + "CreatedByURL": "", + "DocsURL": "", + "MarketplaceURL": "", + "SupportURL": "", + "CanContainContent": false, + "IsBetaVersion": false, + "IsExperimentalVersion": false, + "Installed": false, + "Modules": [ + { + "Name": "CogCommonUI", + "Type": "Runtime", + "LoadingPhase": "Default" + } + ], + "Plugins": [ + { + "Name": "Cog", + "Enabled": true + }, + { + "Name": "CommonUI", + "Enabled": true + } + ] +} \ No newline at end of file diff --git a/Plugins/CogCommonUI/Source/CogCommonUI/CogCommonUI.Build.cs b/Plugins/CogCommonUI/Source/CogCommonUI/CogCommonUI.Build.cs new file mode 100644 index 0000000..9190b4a --- /dev/null +++ b/Plugins/CogCommonUI/Source/CogCommonUI/CogCommonUI.Build.cs @@ -0,0 +1,50 @@ +using UnrealBuildTool; + +public class CogCommonUI : ModuleRules +{ + public CogCommonUI(ReadOnlyTargetRules Target) : base(Target) + { + PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs; + + PublicIncludePaths.AddRange( + new string[] { + } + ); + + + PrivateIncludePaths.AddRange( + new string[] { + } + ); + + + PublicDependencyModuleNames.AddRange( + new string[] + { + "Core", + "CogCommon", + "CogImgui", + "CogDebug", + "CogWindow", + "CommonUI", + "InputCore", + } + ); + + + PrivateDependencyModuleNames.AddRange( + new string[] + { + "CoreUObject", + "Engine", + } + ); + + + DynamicallyLoadedModuleNames.AddRange( + new string[] + { + } + ); + } +} diff --git a/Plugins/CogCommonUI/Source/CogCommonUI/Private/CogCommonUIModule.cpp b/Plugins/CogCommonUI/Source/CogCommonUI/Private/CogCommonUIModule.cpp new file mode 100644 index 0000000..7f03502 --- /dev/null +++ b/Plugins/CogCommonUI/Source/CogCommonUI/Private/CogCommonUIModule.cpp @@ -0,0 +1,17 @@ +#include "CogCommonUIModule.h" + +#define LOCTEXT_NAMESPACE "FCogCommonUIModule" + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogCommonUIModule::StartupModule() +{ +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogCommonUIModule::ShutdownModule() +{ +} + +#undef LOCTEXT_NAMESPACE + +IMPLEMENT_MODULE(FCogCommonUIModule, CogCommonUI) \ No newline at end of file diff --git a/Plugins/CogCommonUI/Source/CogCommonUI/Private/CogCommonUI_ActionRouter.cpp b/Plugins/CogCommonUI/Source/CogCommonUI/Private/CogCommonUI_ActionRouter.cpp new file mode 100644 index 0000000..dfd76e1 --- /dev/null +++ b/Plugins/CogCommonUI/Source/CogCommonUI/Private/CogCommonUI_ActionRouter.cpp @@ -0,0 +1,15 @@ +#include "CogCommonUI_ActionRouter.h" + +#include "CogImguiInputHelper.h" + +ERouteUIInputResult UCogCommonUI_ActionRouter::ProcessInput(FKey Key, EInputEvent InputEvent) const +{ + UWorld* World = GetWorld(); + + if (FCogImguiInputHelper::IsTopPriorityKey(World, Key)) + { + return ERouteUIInputResult::Unhandled; + } + + return UCommonUIActionRouterBase::ProcessInput(Key, InputEvent); +} diff --git a/Plugins/CogCommonUI/Source/CogCommonUI/Public/CogCommonUIModule.h b/Plugins/CogCommonUI/Source/CogCommonUI/Public/CogCommonUIModule.h new file mode 100644 index 0000000..001c5c4 --- /dev/null +++ b/Plugins/CogCommonUI/Source/CogCommonUI/Public/CogCommonUIModule.h @@ -0,0 +1,20 @@ +#pragma once + +#include "CoreMinimal.h" +#include "Modules/ModuleManager.h" + +class COGCOMMONUI_API FCogCommonUIModule : public IModuleInterface +{ +public: + + static inline FCogCommonUIModule& Get() + { + return FModuleManager::LoadModuleChecked("CogCommonUI"); + } + + /** IModuleInterface implementation */ + virtual void StartupModule() override; + virtual void ShutdownModule() override; + +private: +}; diff --git a/Plugins/CogCommonUI/Source/CogCommonUI/Public/CogCommonUI_ActionRouter.h b/Plugins/CogCommonUI/Source/CogCommonUI/Public/CogCommonUI_ActionRouter.h new file mode 100644 index 0000000..e245e2d --- /dev/null +++ b/Plugins/CogCommonUI/Source/CogCommonUI/Public/CogCommonUI_ActionRouter.h @@ -0,0 +1,13 @@ +#pragma once + +#include "CoreMinimal.h" +#include "Input/CommonUIActionRouterBase.h" +#include "CogCommonUI_ActionRouter.generated.h" + +UCLASS() +class COGCOMMONUI_API UCogCommonUI_ActionRouter : public UCommonUIActionRouterBase +{ + GENERATED_BODY() + + virtual ERouteUIInputResult ProcessInput(FKey Key, EInputEvent InputEvent) const override; +};