From 70db3c7b2057e09c7becf903f4e1bdc5e19a7f62 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sun, 25 Nov 2018 19:11:48 +0000 Subject: [PATCH] Replaced console variables in FImGuiModuleProperties with plain variables. Added console commands to toggle states of those properties. --- Source/ImGui/Private/ImGuiInputHandler.cpp | 2 +- Source/ImGui/Private/ImGuiModuleCommands.cpp | 31 +++++++++- Source/ImGui/Private/ImGuiModuleCommands.h | 16 +++-- .../ImGui/Private/ImGuiModuleProperties.cpp | 61 ------------------- Source/ImGui/Private/ImGuiModuleProperties.h | 50 +++++++++------ 5 files changed, 71 insertions(+), 89 deletions(-) diff --git a/Source/ImGui/Private/ImGuiInputHandler.cpp b/Source/ImGui/Private/ImGuiInputHandler.cpp index 62f1ed0..3c703d9 100644 --- a/Source/ImGui/Private/ImGuiInputHandler.cpp +++ b/Source/ImGui/Private/ImGuiInputHandler.cpp @@ -26,7 +26,7 @@ FImGuiInputResponse UImGuiInputHandler::OnKeyDown(const FKeyEvent& KeyEvent) // If this is an input mode switch event then handle it here and consume. if (IsToggleInputEvent(KeyEvent)) { - FImGuiModuleProperties::Get().ToggleInput(ECVF_SetByConsole); + FImGuiModuleProperties::Get().ToggleInput(); return FImGuiInputResponse().RequestConsume(); } diff --git a/Source/ImGui/Private/ImGuiModuleCommands.cpp b/Source/ImGui/Private/ImGuiModuleCommands.cpp index 85101a2..78fe3e4 100644 --- a/Source/ImGui/Private/ImGuiModuleCommands.cpp +++ b/Source/ImGui/Private/ImGuiModuleCommands.cpp @@ -13,13 +13,25 @@ namespace CommandNames namespace { const TCHAR* ToggleInput = TEXT("ImGui.ToggleInput"); + const TCHAR* ToggleKeyboardNavigation = TEXT("ImGui.ToggleKeyboardNavigation"); + const TCHAR* ToggleGamepadNavigation = TEXT("ImGui.ToggleGamepadNavigation"); + const TCHAR* ToggleDemo = TEXT("ImGui.ToggleDemo"); } } FImGuiModuleCommands::FImGuiModuleCommands() : ToggleInputCommand(CommandNames::ToggleInput, - TEXT("Switch ImGui input mode."), + TEXT("Toggle ImGui input mode."), FConsoleCommandDelegate::CreateRaw(this, &FImGuiModuleCommands::ToggleInput)) + , ToggleKeyboardNavigationCommand(CommandNames::ToggleKeyboardNavigation, + TEXT("Toggle ImGui keyboard navigation."), + FConsoleCommandDelegate::CreateRaw(this, &FImGuiModuleCommands::ToggleKeyboardNavigation)) + , ToggleGamepadNavigationCommand(CommandNames::ToggleGamepadNavigation, + TEXT("Toggle ImGui gamepad navigation."), + FConsoleCommandDelegate::CreateRaw(this, &FImGuiModuleCommands::ToggleGamepadNavigation)) + , ToggleDemoCommand(CommandNames::ToggleDemo, + TEXT("Toggle ImGui demo."), + FConsoleCommandDelegate::CreateRaw(this, &FImGuiModuleCommands::ToggleDemo)) { // Delegate initializer to support settings loaded after this object creation (in stand-alone builds) and potential // reloading of settings. @@ -70,5 +82,20 @@ void FImGuiModuleCommands::UpdateToggleInputKeyBinding() void FImGuiModuleCommands::ToggleInput() { - FImGuiModuleProperties::Get().ToggleInput(ECVF_SetByConsole); + FImGuiModuleProperties::Get().ToggleInput(); +} + +void FImGuiModuleCommands::ToggleKeyboardNavigation() +{ + FImGuiModuleProperties::Get().ToggleKeyboardNavigation(); +} + +void FImGuiModuleCommands::ToggleGamepadNavigation() +{ + FImGuiModuleProperties::Get().ToggleGamepadNavigation(); +} + +void FImGuiModuleCommands::ToggleDemo() +{ + FImGuiModuleProperties::Get().ToggleDemo(); } diff --git a/Source/ImGui/Private/ImGuiModuleCommands.h b/Source/ImGui/Private/ImGuiModuleCommands.h index b6077dc..6039250 100644 --- a/Source/ImGui/Private/ImGuiModuleCommands.h +++ b/Source/ImGui/Private/ImGuiModuleCommands.h @@ -14,13 +14,11 @@ class FImGuiModuleCommands FImGuiModuleCommands(); ~FImGuiModuleCommands(); - // Disable copy semantics. - FImGuiModuleCommands(const FImGuiModuleCommands&) = default; - FImGuiModuleCommands& operator=(const FImGuiModuleCommands&) = default; + FImGuiModuleCommands(const FImGuiModuleCommands&) = delete; + FImGuiModuleCommands& operator=(const FImGuiModuleCommands&) = delete; - // Disable move semantics. - FImGuiModuleCommands(FImGuiModuleCommands&&) = default; - FImGuiModuleCommands& operator=(FImGuiModuleCommands&&) = default; + FImGuiModuleCommands(FImGuiModuleCommands&&) = delete; + FImGuiModuleCommands& operator=(FImGuiModuleCommands&&) = delete; void InitializeSettings(); @@ -30,6 +28,12 @@ class FImGuiModuleCommands void UpdateToggleInputKeyBinding(); void ToggleInput(); + void ToggleKeyboardNavigation(); + void ToggleGamepadNavigation(); + void ToggleDemo(); FAutoConsoleCommand ToggleInputCommand; + FAutoConsoleCommand ToggleKeyboardNavigationCommand; + FAutoConsoleCommand ToggleGamepadNavigationCommand; + FAutoConsoleCommand ToggleDemoCommand; }; diff --git a/Source/ImGui/Private/ImGuiModuleProperties.cpp b/Source/ImGui/Private/ImGuiModuleProperties.cpp index 65fb730..cd21447 100644 --- a/Source/ImGui/Private/ImGuiModuleProperties.cpp +++ b/Source/ImGui/Private/ImGuiModuleProperties.cpp @@ -10,64 +10,3 @@ FImGuiModuleProperties& FImGuiModuleProperties::Get() static FImGuiModuleProperties Instance; return Instance; } - -FImGuiModuleProperties::FImGuiModuleProperties() - : InputEnabledVariable(TEXT("ImGui.InputEnabled"), 0, - TEXT("Enable or disable ImGui input mode.\n") - TEXT("0: disabled (default)\n") - TEXT("1: enabled, input is routed to ImGui and with a few exceptions is consumed"), - ECVF_Default) - , InputNavigationVariable(TEXT("ImGui.InputNavigation"), 0, - TEXT("EXPERIMENTAL Set ImGui navigation mode.\n") - TEXT("0: navigation is disabled\n") - TEXT("1: keyboard navigation\n") - TEXT("2: gamepad navigation (gamepad input is consumed)\n") - TEXT("3: keyboard and gamepad navigation (gamepad input is consumed)"), - ECVF_Default) - , ShowDemoVariable(TEXT("ImGui.ShowDemo"), 0, - TEXT("Show ImGui demo.\n") - TEXT("0: disabled (default)\n") - TEXT("1: enabled."), - ECVF_Default) -{ -} - -bool FImGuiModuleProperties::IsInputEnabled() const -{ - return InputEnabledVariable->GetInt() > 0; -} - -void FImGuiModuleProperties::SetInputEnabled(bool bEnabled, EConsoleVariableFlags SetBy) -{ - InputEnabledVariable->Set(bEnabled ? 1 : 0, SetBy); -} - -void FImGuiModuleProperties::ToggleInput(EConsoleVariableFlags SetBy) -{ - SetInputEnabled(!IsInputEnabled(), SetBy); -} - -bool FImGuiModuleProperties::IsKeyboardNavigationEnabled() const -{ - return (InputNavigationVariable->GetInt() & 1) != 0; -} - -bool FImGuiModuleProperties::IsGamepadNavigationEnabled() const -{ - return (InputNavigationVariable->GetInt() & 2) != 0; -} - -bool FImGuiModuleProperties::ShowDemo() const -{ - return ShowDemoVariable->GetInt() > 0; -} - -void FImGuiModuleProperties::SetShowDemo(bool bEnabled, EConsoleVariableFlags SetBy) -{ - ShowDemoVariable->Set(bEnabled ? 1 : 0, SetBy); -} - -void FImGuiModuleProperties::ToggleDemo(EConsoleVariableFlags SetBy) -{ - SetShowDemo(!ShowDemo(), SetBy); -} diff --git a/Source/ImGui/Private/ImGuiModuleProperties.h b/Source/ImGui/Private/ImGuiModuleProperties.h index b91ef11..b133c5d 100644 --- a/Source/ImGui/Private/ImGuiModuleProperties.h +++ b/Source/ImGui/Private/ImGuiModuleProperties.h @@ -14,44 +14,56 @@ public: // Get the instance of the ImGui properties. static FImGuiModuleProperties& Get(); - // Check whether input is enabled. - bool IsInputEnabled() const; + // Check whether ImGui input is enabled. + bool IsInputEnabled() const { return bInputEnabled; } - // Set whether input should be enabled. - void SetInputEnabled(bool bEnabled, EConsoleVariableFlags SetBy = ECVF_SetByCode); + // Enable or disable ImGui input. + void SetInputEnabled(bool bEnabled) { bInputEnabled = bEnabled; } - // Toggle input state. - void ToggleInput(EConsoleVariableFlags SetBy = ECVF_SetByCode); + // Toggle ImGui input. + void ToggleInput() { SetInputEnabled(!IsInputEnabled()); } // Check whether keyboard navigation is enabled. - bool IsKeyboardNavigationEnabled() const; + bool IsKeyboardNavigationEnabled() const { return bKeyboardNavigationEnabled; } + + // Enable or disable keyboard navigation. + void SetKeyboardNavigationEnabled(bool bEnabled) { bKeyboardNavigationEnabled = bEnabled; } + + // Toggle keyboard navigation. + void ToggleKeyboardNavigation() { SetKeyboardNavigationEnabled(!IsKeyboardNavigationEnabled()); } // Check whether gamepad navigation is enabled. - bool IsGamepadNavigationEnabled() const; + bool IsGamepadNavigationEnabled() const { return bGamepadNavigationEnabled; } - // Check whether demo should be visible. - bool ShowDemo() const; + // Enable or disable gamepad navigation. + void SetGamepadNavigationEnabled(bool bEnabled) { bGamepadNavigationEnabled = bEnabled; } - // Set whether demo should be visible. - void SetShowDemo(bool bEnabled, EConsoleVariableFlags SetBy = ECVF_SetByCode); + // Toggle gamepad navigation. + void ToggleGamepadNavigation() { SetGamepadNavigationEnabled(!IsGamepadNavigationEnabled()); } - // Toggle demo visibility. - void ToggleDemo(EConsoleVariableFlags SetBy = ECVF_SetByCode); + // Check whether ImGui demo is visible. + bool ShowDemo() const { return bShowDemo; } + + // Show or hide ImGui demo. + void SetShowDemo(bool bShow) { bShowDemo = bShow; } + + // Toggle ImGui demo. + void ToggleDemo() { SetShowDemo(!ShowDemo()); } private: - FImGuiModuleProperties(); + FImGuiModuleProperties() = default; - // Disable copy and move semantics. FImGuiModuleProperties(const FImGuiModuleProperties&) = delete; FImGuiModuleProperties& operator=(const FImGuiModuleProperties&) = delete; FImGuiModuleProperties(FImGuiModuleProperties&&) = delete; FImGuiModuleProperties& operator=(FImGuiModuleProperties&&) = delete; - TAutoConsoleVariable InputEnabledVariable; + bool bInputEnabled = false; - TAutoConsoleVariable InputNavigationVariable; + bool bKeyboardNavigationEnabled = false; + bool bGamepadNavigationEnabled = false; - TAutoConsoleVariable ShowDemoVariable; + bool bShowDemo = false; };