From f2d8311c90609c30823c69db8ee51a9eb085e8c4 Mon Sep 17 00:00:00 2001 From: Arnaud Jamin Date: Sat, 21 Oct 2023 00:31:14 -0400 Subject: [PATCH] CogWindow: Add shortcuts text for some menu items --- .../Private/CogEngineWindow_DebugSettings.cpp | 94 ++++++++++++------- .../Private/CogEngineWindow_LogCategories.cpp | 31 ++++-- .../Private/CogEngineWindow_Selection.cpp | 21 ++++- .../Public/CogEngineWindow_Selection.h | 4 +- .../CogImgui/Private/CogImguiInputHelper.cpp | 87 +++++++++++++++-- .../CogImgui/Public/CogImguiInputHelper.h | 10 +- .../CogWindow/Private/CogWindowManager.cpp | 75 ++++++++++----- .../CogWindow/Public/CogWindowManager.h | 11 +++ TODO.txt | 2 - 9 files changed, 253 insertions(+), 82 deletions(-) diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_DebugSettings.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_DebugSettings.cpp index 2d339f8..f414d25 100644 --- a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_DebugSettings.cpp +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_DebugSettings.cpp @@ -76,8 +76,6 @@ void UCogEngineWindow_DebugSettings::PreSaveConfig() GradientColorIntensity = FCogDebugSettings::GradientColorIntensity; GradientColorSpeed = FCogDebugSettings::GradientColorSpeed; TextSize = FCogDebugSettings::TextSize; - - bIsFilteringBySelection = FCogDebugSettings::GetIsFilteringBySelection(); } //-------------------------------------------------------------------------------------------------------------------------- @@ -101,79 +99,109 @@ void UCogEngineWindow_DebugSettings::RenderContent() ImGui::EndMenuBar(); } + bIsFilteringBySelection = FCogDebugSettings::GetIsFilteringBySelection(); if (ImGui::Checkbox("Filter by selection", &bIsFilteringBySelection)) { FCogDebugSettings::SetIsFilteringBySelection(GetWorld(), bIsFilteringBySelection); } - - ImGui::SameLine(); - FCogWindowWidgets::HelpMarker("If checked, only show the debug of the currently selected actor. Otherwise show the debug of all actors."); + if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) + { + ImGui::SetTooltip("If checked, only show the debug of the currently selected actor. Otherwise show the debug of all actors."); + } ImGui::Checkbox("Persistent", &FCogDebugSettings::Persistent); - ImGui::SameLine(); - FCogWindowWidgets::HelpMarker("Make debug draw always persist"); + if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) + { + ImGui::SetTooltip("Make debug draw always persist"); + } ImGui::Checkbox("Text Shadow", &FCogDebugSettings::TextShadow); - ImGui::SameLine(); - FCogWindowWidgets::HelpMarker("Show a shadow below debug text."); + if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) + { + ImGui::SetTooltip("Show a shadow below debug text."); + } FCogWindowWidgets::SetNextItemToShortWidth(); ImGui::Checkbox("Fade 2D", &FCogDebugSettings::Fade2D); - ImGui::SameLine(); - FCogWindowWidgets::HelpMarker("Does the 2D debug is fading out."); + if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) + { + ImGui::SetTooltip("Does the 2D debug is fading out."); + } FCogWindowWidgets::SetNextItemToShortWidth(); ImGui::DragFloat("Duration", &FCogDebugSettings::Duration, 0.01f, 0.0f, 100.0f, "%.1f"); - ImGui::SameLine(); - FCogWindowWidgets::HelpMarker("The duration of debug elements."); + if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) + { + ImGui::SetTooltip("The duration of debug elements."); + } FCogWindowWidgets::SetNextItemToShortWidth(); ImGui::DragFloat("Thickness", &FCogDebugSettings::Thickness, 0.05f, 0.0f, 5.0f, "%.1f"); - ImGui::SameLine(); - FCogWindowWidgets::HelpMarker("The thickness of debug lines."); + if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) + { + ImGui::SetTooltip("The thickness of debug lines."); + } FCogWindowWidgets::SetNextItemToShortWidth(); ImGui::DragFloat("Server Thickness", &FCogDebugSettings::ServerThickness, 0.05f, 0.0f, 5.0f, "%.1f"); - ImGui::SameLine(); - FCogWindowWidgets::HelpMarker("The thickness the server debug lines."); + if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) + { + ImGui::SetTooltip("The thickness the server debug lines."); + } FCogWindowWidgets::SetNextItemToShortWidth(); ImGui::DragFloat("Server Color Mult", &FCogDebugSettings::ServerColorMultiplier, 0.01f, 0.0f, 1.0f, "%.1f"); - ImGui::SameLine(); - FCogWindowWidgets::HelpMarker("The color multiplier applied to the server debug lines."); + if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) + { + ImGui::SetTooltip("The color multiplier applied to the server debug lines."); + } FCogWindowWidgets::SetNextItemToShortWidth(); ImGui::DragInt("Depth Priority", &FCogDebugSettings::DepthPriority, 0.1f, 0, 100); - ImGui::SameLine(); - FCogWindowWidgets::HelpMarker("The depth priority of debug elements."); + if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) + { + ImGui::SetTooltip("The depth priority of debug elements."); + } FCogWindowWidgets::SetNextItemToShortWidth(); ImGui::DragInt("Segments", &FCogDebugSettings::Segments, 0.1f, 4, 20.0f); - ImGui::SameLine(); - FCogWindowWidgets::HelpMarker("The number of segments used for circular shapes."); + if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) + { + ImGui::SetTooltip("The number of segments used for circular shapes."); + } FCogWindowWidgets::SetNextItemToShortWidth(); ImGui::DragFloat("Axes Scale", &FCogDebugSettings::AxesScale, 0.1f, 0, 10.0f, "%.1f"); - ImGui::SameLine(); - FCogWindowWidgets::HelpMarker("The scaling debug axis."); + if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) + { + ImGui::SetTooltip("The scaling debug axis."); + } FCogWindowWidgets::SetNextItemToShortWidth(); ImGui::DragFloat("Arrow Size", &FCogDebugSettings::ArrowSize, 1.0f, 0.0f, 200.0f, "%.0f"); - ImGui::SameLine(); - FCogWindowWidgets::HelpMarker("The size of debug arrows."); + if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) + { + ImGui::SetTooltip("The size of debug arrows."); + } FCogWindowWidgets::SetNextItemToShortWidth(); ImGui::DragFloat("Gradient Intensity", &FCogDebugSettings::GradientColorIntensity, 0.01f, 0.0f, 1.0f, "%.2f"); - ImGui::SameLine(); - FCogWindowWidgets::HelpMarker("How much the debug elements color should be changed by a gradient color over time."); + if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) + { + ImGui::SetTooltip("How much the debug elements color should be changed by a gradient color over time."); + } FCogWindowWidgets::SetNextItemToShortWidth(); ImGui::DragFloat("Gradient Speed", &FCogDebugSettings::GradientColorSpeed, 0.1f, 0.0f, 10.0f, "%.1f"); - ImGui::SameLine(); - FCogWindowWidgets::HelpMarker("The speed of the gradient color change."); + if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) + { + ImGui::SetTooltip("The speed of the gradient color change."); + } FCogWindowWidgets::SetNextItemToShortWidth(); ImGui::DragFloat("Text Size", &FCogDebugSettings::TextSize, 0.1f, 0.1f, 5.0f, "%.1f"); - ImGui::SameLine(); - FCogWindowWidgets::HelpMarker("The size of the debug texts."); + if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) + { + ImGui::SetTooltip("The size of the debug texts."); + } } diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_LogCategories.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_LogCategories.cpp index 76e364a..55b01a5 100644 --- a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_LogCategories.cpp +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_LogCategories.cpp @@ -49,21 +49,38 @@ void UCogEngineWindow_LogCategories::RenderContent() { if (ImGui::BeginMenu("Options")) { + if (ImGui::MenuItem("Deactivate All")) + { + FCogDebugLog::DeactivateAllLogCateories(*World); + } + if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) + { + ImGui::SetTooltip("Deactivate all log categories. If connected to a server, also deactivate all its log categories."); + } + + ImGui::Separator(); + ImGui::Checkbox("Show detailed verbosity", &bShowAllVerbosity); - ImGui::SameLine(); - FCogWindowWidgets::HelpMarker("Show the verbosity level of each log category."); + if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) + { + ImGui::SetTooltip("Show the verbosity level of each log category."); + } ImGui::EndMenu(); } - if (ImGui::MenuItem("Reset")) + bool bIsFilteringBySelection = FCogDebugSettings::GetIsFilteringBySelection(); + ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 2); + FCogWindowWidgets::PushStyleCompact(); + if (ImGui::Checkbox("Filter", &bIsFilteringBySelection)) { - FCogDebugLog::DeactivateAllLogCateories(*World); + FCogDebugSettings::SetIsFilteringBySelection(GetWorld(), bIsFilteringBySelection); } + FCogWindowWidgets::PopStyleCompact(); - if (ImGui::IsItemHovered()) + if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) { - ImGui::SetTooltip("Deactivate all the log categories"); + ImGui::SetTooltip("If checked, only show the debug of the currently selected actor. Otherwise show the debug of all actors."); } if (ImGui::MenuItem("Flush")) @@ -73,7 +90,7 @@ void UCogEngineWindow_LogCategories::RenderContent() GEngine->ClearOnScreenDebugMessages(); } - if (ImGui::IsItemHovered()) + if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) { ImGui::SetTooltip("Clear all the debug drawn on screen"); } diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Selection.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Selection.cpp index 912ad27..a9a67a3 100644 --- a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Selection.cpp +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Selection.cpp @@ -4,6 +4,7 @@ #include "CogDebugSettings.h" #include "CogEngineReplicator.h" #include "CogImguiModule.h" +#include "CogImguiInputHelper.h" #include "CogWindowManager.h" #include "CogWindowWidgets.h" #include "EngineUtils.h" @@ -12,6 +13,8 @@ #include "imgui.h" #include "Kismet/GameplayStatics.h" +FString UCogEngineWindow_Selection::ToggleSelectionModeCommand = TEXT("Cog.ToggleSelectionMode"); + //-------------------------------------------------------------------------------------------------------------------------- void UCogEngineWindow_Selection::RenderHelp() { @@ -30,7 +33,7 @@ UCogEngineWindow_Selection::UCogEngineWindow_Selection() ActorClasses = { AActor::StaticClass(), ACharacter::StaticClass() }; ConsoleCommands.Add(IConsoleManager::Get().RegisterConsoleCommand( - TEXT("Cog.ToggleSelectionMode"), + *ToggleSelectionModeCommand, TEXT("Toggle the actor selection mode"), FConsoleCommandWithArgsDelegate::CreateLambda([this](const TArray& Args) { ToggleSelectionMode(); }), ECVF_Cheat)); @@ -198,6 +201,7 @@ void UCogEngineWindow_Selection::RenderContent() ActivateSelectionMode(); HackWaitInputRelease(); } + RenderPickButtonTooltip(); ImGui::EndMenuBar(); } @@ -592,10 +596,7 @@ void UCogEngineWindow_Selection::RenderMainMenuWidget(bool Draw, float& Width) ActivateSelectionMode(); HackWaitInputRelease(); } - if (ImGui::IsItemHovered()) - { - ImGui::SetTooltip("Enter picking mode to select an actor on screen."); - } + RenderPickButtonTooltip(); ImGui::PopStyleColor(1); ImGui::PopStyleVar(2); @@ -654,3 +655,13 @@ void UCogEngineWindow_Selection::SetGlobalSelection(AActor* Value) const { FCogDebugSettings::SetSelection(GetWorld(), Value); } + +//-------------------------------------------------------------------------------------------------------------------------- +void UCogEngineWindow_Selection::RenderPickButtonTooltip() +{ + if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) + { + const FString Shortcut = FCogImguiInputHelper::CommandToString(*GetWorld(), ToggleSelectionModeCommand); + ImGui::SetTooltip("Enter picking mode to pick an actor on screen. %s", TCHAR_TO_ANSI(*Shortcut)); + } +} \ No newline at end of file diff --git a/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_Selection.h b/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_Selection.h index 7725b05..6ab4345 100644 --- a/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_Selection.h +++ b/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_Selection.h @@ -14,6 +14,8 @@ class COGENGINE_API UCogEngineWindow_Selection : public UCogWindow public: + static FString ToggleSelectionModeCommand; + UCogEngineWindow_Selection(); bool GetIsSelecting() const { return bSelectionModeActive; } @@ -58,7 +60,7 @@ protected: virtual void SetGlobalSelection(AActor* Value) const; -private: + virtual void RenderPickButtonTooltip(); TSubclassOf GetSelectedActorClass() const; diff --git a/Plugins/Cog/Source/CogImgui/Private/CogImguiInputHelper.cpp b/Plugins/Cog/Source/CogImgui/Private/CogImguiInputHelper.cpp index 00595a8..7ffb767 100644 --- a/Plugins/Cog/Source/CogImgui/Private/CogImguiInputHelper.cpp +++ b/Plugins/Cog/Source/CogImgui/Private/CogImguiInputHelper.cpp @@ -17,7 +17,7 @@ TMap FCogImguiInputHelper::KeyMap; //-------------------------------------------------------------------------------------------------------------------------- -APlayerController* FCogImguiInputHelper::GetFirstLocalPlayerController(UWorld& World) +APlayerController* FCogImguiInputHelper::GetFirstLocalPlayerController(const UWorld& World) { for (FConstPlayerControllerIterator Iterator = World.GetPlayerControllerIterator(); Iterator; ++Iterator) { @@ -31,6 +31,19 @@ APlayerController* FCogImguiInputHelper::GetFirstLocalPlayerController(UWorld& W return nullptr; } +//-------------------------------------------------------------------------------------------------------------------------- +UPlayerInput* FCogImguiInputHelper::GetPlayerInput(const UWorld& World) +{ + APlayerController* PlayerController = GetFirstLocalPlayerController(World); + if (PlayerController == nullptr) + { + return nullptr; + } + + UPlayerInput* PlayerInput = PlayerController->PlayerInput; + return PlayerInput; +} + //-------------------------------------------------------------------------------------------------------------------------- bool FCogImguiInputHelper::IsKeyEventHandled(UWorld* World, const FKeyEvent& KeyEvent) { @@ -205,13 +218,7 @@ bool FCogImguiInputHelper::IsKeyBoundToCommand(UWorld* World, const FKeyEvent& K return false; } - APlayerController* Controller = GetFirstLocalPlayerController(*World); - if (Controller == nullptr) - { - return false; - } - - UPlayerInput* PlayerInput = Controller->PlayerInput; + const UPlayerInput* PlayerInput = GetPlayerInput(*World); if (PlayerInput == nullptr) { return false; @@ -441,3 +448,67 @@ void FCogImguiInputHelper::InitializeKeyMap() //KeyMap.Add(EKeys::RightParantheses, ImGuiKey_None; //KeyMap.Add(EKeys::Quote, ImGuiKey_None; } + +//-------------------------------------------------------------------------------------------------------------------------- +FString FCogImguiInputHelper::CommandToString(const UWorld& World, const FString& Command) +{ + const UPlayerInput* PlayerInput = GetPlayerInput(World); + if (PlayerInput == nullptr) + { + return FString(); + } + + const FKeyBind* Result = PlayerInput->DebugExecBindings.FindByPredicate([&](const FKeyBind& KeyBind) { return KeyBind.Command == Command; }); + if (Result == nullptr) + { + return FString(); + } + + return KeyBindToString(*Result); +} + +//-------------------------------------------------------------------------------------------------------------------------- +FString FCogImguiInputHelper::CommandToString(const UPlayerInput* PlayerInput, const FString& Command) +{ + if (PlayerInput == nullptr) + { + return FString(); + } + + const FKeyBind* Result = PlayerInput->DebugExecBindings.FindByPredicate([&](const FKeyBind& KeyBind) { return KeyBind.Command == Command; }); + if (Result == nullptr) + { + return FString(); + } + + return KeyBindToString(*Result); +} + +//-------------------------------------------------------------------------------------------------------------------------- +FString FCogImguiInputHelper::KeyBindToString(const FKeyBind& KeyBind) +{ + FString Result; + if (KeyBind.Alt) + { + Result = Result.Append("Alt "); + } + + if (KeyBind.Shift) + { + Result = Result.Append("Shift "); + } + + if (KeyBind.Control) + { + Result = Result.Append("Ctrl "); + } + + if (KeyBind.Cmd) + { + Result = Result.Append("Cmd "); + } + + Result = Result.Printf(TEXT("[%s]"), *KeyBind.Key.ToString()); + + return Result; +} diff --git a/Plugins/Cog/Source/CogImgui/Public/CogImguiInputHelper.h b/Plugins/Cog/Source/CogImgui/Public/CogImguiInputHelper.h index fedbf3c..332838a 100644 --- a/Plugins/Cog/Source/CogImgui/Public/CogImguiInputHelper.h +++ b/Plugins/Cog/Source/CogImgui/Public/CogImguiInputHelper.h @@ -12,7 +12,9 @@ class COGIMGUI_API FCogImguiInputHelper { public: - static APlayerController* GetFirstLocalPlayerController(UWorld& World); + static APlayerController* GetFirstLocalPlayerController(const UWorld& World); + + static UPlayerInput* GetPlayerInput(const UWorld& World); static bool IsKeyEventHandled(UWorld* World, const FKeyEvent& KeyEvent); @@ -42,6 +44,12 @@ public: static EMouseCursor::Type ToSlateMouseCursor(ImGuiMouseCursor MouseCursor); + static FString CommandToString(const UWorld& World, const FString& Command); + + static FString CommandToString(const UPlayerInput* PlayerInput, const FString& Command); + + static FString KeyBindToString(const FKeyBind& KeyBind); + template* = nullptr> static ImWchar CastInputChar(T Char) { diff --git a/Plugins/Cog/Source/CogWindow/Private/CogWindowManager.cpp b/Plugins/Cog/Source/CogWindow/Private/CogWindowManager.cpp index 548e3ff..034b86e 100644 --- a/Plugins/Cog/Source/CogWindow/Private/CogWindowManager.cpp +++ b/Plugins/Cog/Source/CogWindow/Private/CogWindowManager.cpp @@ -11,6 +11,11 @@ #include "HAL/IConsoleManager.h" #include "imgui_internal.h" +FString UCogWindowManager::ToggleInputCommand = TEXT("Cog.ToggleInput"); +FString UCogWindowManager::LoadLayoutCommand = TEXT("Cog.LoadLayout"); +FString UCogWindowManager::SaveLayoutCommand = TEXT("Cog.SaveLayout"); +FString UCogWindowManager::ResetLayoutCommand = TEXT("Cog.ResetLayout"); + //-------------------------------------------------------------------------------------------------------------------------- UCogWindowManager::UCogWindowManager() { @@ -54,19 +59,25 @@ void UCogWindowManager::InitializeInternal() SettingsWindow = CreateWindow("Window.Settings", false); ConsoleCommands.Add(IConsoleManager::Get().RegisterConsoleCommand( - TEXT("Cog.ToggleInput"), + *ToggleInputCommand, TEXT("Toggle the input focus between the Game and ImGui"), FConsoleCommandWithArgsDelegate::CreateLambda([](const TArray& Args) { FCogImguiModule::Get().ToggleEnableInput(); }), ECVF_Cheat)); ConsoleCommands.Add(IConsoleManager::Get().RegisterConsoleCommand( - TEXT("Cog.LoadLayout"), + *ResetLayoutCommand, + TEXT("Reset the layout."), + FConsoleCommandWithArgsDelegate::CreateLambda([this](const TArray& Args) { if (Args.Num() > 0) { ResetLayout(); }}), + ECVF_Cheat)); + + ConsoleCommands.Add(IConsoleManager::Get().RegisterConsoleCommand( + *LoadLayoutCommand, TEXT("Load the layout. Cog.LoadLayout "), FConsoleCommandWithArgsDelegate::CreateLambda([this](const TArray& Args) { if (Args.Num() > 0) { LoadLayout(FCString::Atoi(*Args[0])); }}), ECVF_Cheat)); ConsoleCommands.Add(IConsoleManager::Get().RegisterConsoleCommand( - TEXT("Cog.SaveLayout"), + *SaveLayoutCommand, TEXT("Save the layout. Cog.SaveLayout "), FConsoleCommandWithArgsDelegate::CreateLambda([this](const TArray& Args) { if (Args.Num() > 0) { SaveLayout(FCString::Atoi(*Args[0])); }}), ECVF_Cheat)); @@ -295,6 +306,8 @@ UCogWindowManager::FMenu* UCogWindowManager::AddMenu(const FString& Name) //-------------------------------------------------------------------------------------------------------------------------- void UCogWindowManager::RenderMainMenu() { + const UPlayerInput* PlayerInput = FCogImguiInputHelper::GetPlayerInput(*GetWorld()); + if (ImGui::BeginMainMenuBar()) { for (UCogWindowManager::FMenu& Menu : MainMenu.SubMenus) @@ -304,6 +317,13 @@ void UCogWindowManager::RenderMainMenu() if (ImGui::BeginMenu("Window")) { + if (ImGui::MenuItem("Toggle Input", TCHAR_TO_ANSI(*FCogImguiInputHelper::CommandToString(PlayerInput, ToggleInputCommand)))) + { + FCogImguiModule::Get().ToggleEnableInput(); + } + ImGui::Separator(); + + if (ImGui::MenuItem("Close All Windows")) { CloseAllWindows(); @@ -318,10 +338,7 @@ void UCogWindowManager::RenderMainMenu() { for (int32 i = 1; i <= 4; ++i) { - if (ImGui::MenuItem(TCHAR_TO_ANSI(*FString::Printf(TEXT("Load Layout %d"), i)))) - { - LoadLayout(i); - } + RenderLoadLayoutMenuItem(PlayerInput, i); } ImGui::EndMenu(); @@ -331,10 +348,7 @@ void UCogWindowManager::RenderMainMenu() { for (int32 i = 1; i <= 4; ++i) { - if (ImGui::MenuItem(TCHAR_TO_ANSI(*FString::Printf(TEXT("Save Layout %d"), i)))) - { - SaveLayout(i); - } + RenderSaveLayoutMenuItem(PlayerInput, i); } ImGui::EndMenu(); @@ -390,6 +404,28 @@ void UCogWindowManager::RenderMainMenu() } } +//-------------------------------------------------------------------------------------------------------------------------- +void UCogWindowManager::RenderLoadLayoutMenuItem(const UPlayerInput* PlayerInput, int LayoutIndex) +{ + FString Command = FString::Printf(TEXT("%s %d"), *LoadLayoutCommand, LayoutIndex); + FString Shortcut = FCogImguiInputHelper::CommandToString(PlayerInput, Command); + if (ImGui::MenuItem(TCHAR_TO_ANSI(*FString::Printf(TEXT("Load Layout %d"), LayoutIndex)), TCHAR_TO_ANSI(*Shortcut))) + { + LoadLayout(LayoutIndex); + } +} + +//-------------------------------------------------------------------------------------------------------------------------- +void UCogWindowManager::RenderSaveLayoutMenuItem(const UPlayerInput* PlayerInput, int LayoutIndex) +{ + FString Command = FString::Printf(TEXT("%s %d"), *SaveLayoutCommand, LayoutIndex); + FString Shortcut = FCogImguiInputHelper::CommandToString(PlayerInput, Command); + if (ImGui::MenuItem(TCHAR_TO_ANSI(*FString::Printf(TEXT("Save Layout %d"), LayoutIndex)), TCHAR_TO_ANSI(*Shortcut))) + { + SaveLayout(LayoutIndex); + } +} + //-------------------------------------------------------------------------------------------------------------------------- void UCogWindowManager::RenderOptionMenu(UCogWindowManager::FMenu& Menu) { @@ -535,23 +571,12 @@ void UCogWindowManager::ResetAllWindowsConfig() //-------------------------------------------------------------------------------------------------------------------------- bool UCogWindowManager::RegisterDefaultCommands() { - UWorld* World = GetWorld(); - if (World == nullptr) + if (GetWorld() == nullptr) { return false; } - APlayerController* PlayerController = FCogImguiInputHelper::GetFirstLocalPlayerController(*World); - if (PlayerController == nullptr) - { - return false; - } - - UPlayerInput* PlayerInput = PlayerController->PlayerInput; - if (PlayerInput == nullptr) - { - return false; - } + UPlayerInput* PlayerInput = FCogImguiInputHelper::GetPlayerInput(*GetWorld()); AddCommand(PlayerInput, "Cog.ToggleInput", EKeys::Tab); AddCommand(PlayerInput, "Cog.LoadLayout 1", EKeys::F1); @@ -609,4 +634,4 @@ void UCogWindowManager::SortCommands(UPlayerInput* PlayerInput) { 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 fe4ad14..5576cd5 100644 --- a/Plugins/Cog/Source/CogWindow/Public/CogWindowManager.h +++ b/Plugins/Cog/Source/CogWindow/Public/CogWindowManager.h @@ -9,6 +9,7 @@ class IConsoleObject; class SCogImguiWidget; class UCogWindow; class UCogWindow_Settings; +class UPlayerInput; class UWorld; struct ImGuiSettingsHandler; struct ImGuiTextBuffer; @@ -19,6 +20,12 @@ class COGWINDOW_API UCogWindowManager : public UObject GENERATED_BODY() public: + + static FString ToggleInputCommand; + static FString LoadLayoutCommand; + static FString SaveLayoutCommand; + static FString ResetLayoutCommand; + UCogWindowManager(); virtual void PostInitProperties() override; @@ -106,6 +113,10 @@ protected: virtual void RenderMenuItem(UCogWindow& Window, const char* MenuItemName); + virtual void RenderLoadLayoutMenuItem(const UPlayerInput* PlayerInput, int LayoutIndex); + + virtual void RenderSaveLayoutMenuItem(const UPlayerInput* PlayerInput, int LayoutIndex); + static void SettingsHandler_ClearAll(ImGuiContext* ctx, ImGuiSettingsHandler*); static void SettingsHandler_ApplyAll(ImGuiContext* ctx, ImGuiSettingsHandler*); diff --git a/TODO.txt b/TODO.txt index 1064627..bb6046b 100644 --- a/TODO.txt +++ b/TODO.txt @@ -14,6 +14,4 @@ - CogSample: Add a custom window in sample (changing the character faction) - CogSample: Create more abilities -- CogSample: Add area of effects in the level -- CogPackage: in package mode the Gameplay Cues are not visible.