From e00c1ff9e3493576271fb610deb6cb603e871b97 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sat, 24 Nov 2018 21:16:25 +0000 Subject: [PATCH] Renamed SwitchInputMode to ToggleInput command and interface to provide a better consistency with the engine and between module functions. Note that this commit contains a minor breaking change for custom implementations of UImGuiInputHandler. - Changed "ImGui.SwitchInputMode" command name to "ImGui.ToggleInput". - Changed SwitchInputModeKey property in settings to ToggleInput. - Added temporary mechanism protecting from losing data by moving it from SwitchInputModeKey to ToggleInput and removing deprecated entry from the default config file. - Renamed UImGuiInputHandler protected function from IsSwitchInputModeEvent to IsToggleInputEvent, so custom implementations of that class may require update. --- Source/ImGui/Private/ImGuiInputHandler.cpp | 8 +++--- Source/ImGui/Private/ImGuiModuleCommands.cpp | 12 ++++---- Source/ImGui/Private/ImGuiSettings.cpp | 30 ++++++++++++++++++-- Source/ImGui/Private/ImGuiSettings.h | 22 ++++++++------ Source/ImGui/Public/ImGuiInputHandler.h | 8 +++--- 5 files changed, 55 insertions(+), 25 deletions(-) diff --git a/Source/ImGui/Private/ImGuiInputHandler.cpp b/Source/ImGui/Private/ImGuiInputHandler.cpp index 00a5217..62f1ed0 100644 --- a/Source/ImGui/Private/ImGuiInputHandler.cpp +++ b/Source/ImGui/Private/ImGuiInputHandler.cpp @@ -24,7 +24,7 @@ DEFINE_LOG_CATEGORY(LogImGuiInputHandler); FImGuiInputResponse UImGuiInputHandler::OnKeyDown(const FKeyEvent& KeyEvent) { // If this is an input mode switch event then handle it here and consume. - if (IsSwitchInputModeEvent(KeyEvent)) + if (IsToggleInputEvent(KeyEvent)) { FImGuiModuleProperties::Get().ToggleInput(ECVF_SetByConsole); return FImGuiInputResponse().RequestConsume(); @@ -89,11 +89,11 @@ namespace } } -bool UImGuiInputHandler::IsSwitchInputModeEvent(const FKeyEvent& KeyEvent) const +bool UImGuiInputHandler::IsToggleInputEvent(const FKeyEvent& KeyEvent) const { return GImGuiSettings - && (KeyEvent.GetKey() == GImGuiSettings->GetSwitchInputModeKey().Key) - && AreModifiersMatching(GImGuiSettings->GetSwitchInputModeKey(), KeyEvent); + && (KeyEvent.GetKey() == GImGuiSettings->GetToggleInputKey().Key) + && AreModifiersMatching(GImGuiSettings->GetToggleInputKey(), KeyEvent); } bool UImGuiInputHandler::HasImGuiActiveItem() const diff --git a/Source/ImGui/Private/ImGuiModuleCommands.cpp b/Source/ImGui/Private/ImGuiModuleCommands.cpp index f8e2db6..85101a2 100644 --- a/Source/ImGui/Private/ImGuiModuleCommands.cpp +++ b/Source/ImGui/Private/ImGuiModuleCommands.cpp @@ -12,12 +12,12 @@ namespace CommandNames { namespace { - const TCHAR* SwitchInputMode = TEXT("ImGui.SwitchInputMode"); + const TCHAR* ToggleInput = TEXT("ImGui.ToggleInput"); } } FImGuiModuleCommands::FImGuiModuleCommands() - : ToggleInputCommand(CommandNames::SwitchInputMode, + : ToggleInputCommand(CommandNames::ToggleInput, TEXT("Switch ImGui input mode."), FConsoleCommandDelegate::CreateRaw(this, &FImGuiModuleCommands::ToggleInput)) { @@ -46,9 +46,9 @@ void FImGuiModuleCommands::InitializeSettings() void FImGuiModuleCommands::RegisterSettingsDelegates() { - if (GImGuiSettings && !GImGuiSettings->OnSwitchInputModeKeyChanged.IsBoundToObject(this)) + if (GImGuiSettings && !GImGuiSettings->OnToggleInputKeyChanged.IsBoundToObject(this)) { - GImGuiSettings->OnSwitchInputModeKeyChanged.AddRaw(this, &FImGuiModuleCommands::UpdateToggleInputKeyBinding); + GImGuiSettings->OnToggleInputKeyChanged.AddRaw(this, &FImGuiModuleCommands::UpdateToggleInputKeyBinding); } } @@ -56,7 +56,7 @@ void FImGuiModuleCommands::UnregisterSettingsDelegates() { if (GImGuiSettings) { - GImGuiSettings->OnSwitchInputModeKeyChanged.RemoveAll(this); + GImGuiSettings->OnToggleInputKeyChanged.RemoveAll(this); } } @@ -64,7 +64,7 @@ void FImGuiModuleCommands::UpdateToggleInputKeyBinding() { if (GImGuiSettings) { - DebugExecBindings::UpdatePlayerInputs(GImGuiSettings->GetSwitchInputModeKey(), CommandNames::SwitchInputMode); + DebugExecBindings::UpdatePlayerInputs(GImGuiSettings->GetToggleInputKey(), CommandNames::ToggleInput); } } diff --git a/Source/ImGui/Private/ImGuiSettings.cpp b/Source/ImGui/Private/ImGuiSettings.cpp index 34bb40a..f17d449 100644 --- a/Source/ImGui/Private/ImGuiSettings.cpp +++ b/Source/ImGui/Private/ImGuiSettings.cpp @@ -32,6 +32,32 @@ void UImGuiSettings::PostInitProperties() { Super::PostInitProperties(); + if (SwitchInputModeKey_DEPRECATED.Key.IsValid() && !ToggleInput.Key.IsValid()) + { + const FString ConfigFileName = GetDefaultConfigFilename(); + + // Move value to the new property. + ToggleInput = MoveTemp(SwitchInputModeKey_DEPRECATED); + + // Remove from configuration file entry for obsolete property. + if (FConfigFile* ConfigFile = GConfig->Find(ConfigFileName, false)) + { + if (FConfigSection* Section = ConfigFile->Find(TEXT("/Script/ImGui.ImGuiSettings"))) + { + if (Section->Remove(TEXT("SwitchInputModeKey"))) + { + ConfigFile->Dirty = true; + GConfig->Flush(false, ConfigFileName); + } + } + } + + // Add to configuration file entry for new property. + UpdateSinglePropertyInConfigFile( + UImGuiSettings::StaticClass()->FindPropertyByName(GET_MEMBER_NAME_CHECKED(UImGuiSettings, ToggleInput)), + ConfigFileName); + } + if (IsTemplate()) { GImGuiSettings = this; @@ -74,9 +100,9 @@ void UImGuiSettings::OnPropertyChanged(class UObject* ObjectBeingModified, struc { OnImGuiInputHandlerClassChanged.Broadcast(); } - else if (UpdatedPropertyName == GET_MEMBER_NAME_CHECKED(UImGuiSettings, SwitchInputModeKey)) + else if (UpdatedPropertyName == GET_MEMBER_NAME_CHECKED(UImGuiSettings, ToggleInput)) { - OnSwitchInputModeKeyChanged.Broadcast(); + OnToggleInputKeyChanged.Broadcast(); } else if (UpdatedPropertyName == GET_MEMBER_NAME_CHECKED(UImGuiSettings, bUseSoftwareCursor)) { diff --git a/Source/ImGui/Private/ImGuiSettings.h b/Source/ImGui/Private/ImGuiSettings.h index ad3137c..560138c 100644 --- a/Source/ImGui/Private/ImGuiSettings.h +++ b/Source/ImGui/Private/ImGuiSettings.h @@ -59,19 +59,19 @@ public: // Path to custom implementation of ImGui Input Handler. const FStringClassReference& GetImGuiInputHandlerClass() const { return ImGuiInputHandlerClass; } - // Get mapping for 'ImGui.SwitchInputMode' command. - const FImGuiKeyInfo& GetSwitchInputModeKey() const { return SwitchInputModeKey; } + // Get the shortcut key info for 'ImGui.ToggleInput' command. + const FImGuiKeyInfo& GetToggleInputKey() const { return ToggleInput; } // Check whether ImGui should draw its own software cursor. bool UseSoftwareCursor() const { return bUseSoftwareCursor; } - // Delegate raised when ImGuiInputHandlerClass property has changed. + // Delegate raised when ImGuiInputHandlerClass is changed. FSimpleMulticastDelegate OnImGuiInputHandlerClassChanged; - // Delegate raised when SwitchInputModeKey property has changed. - FSimpleMulticastDelegate OnSwitchInputModeKeyChanged; + // Delegate raised when ToggleInput key is changed. + FSimpleMulticastDelegate OnToggleInputKeyChanged; - // Delegate raised when SoftwareCursorEnabled property has changed. + // Delegate raised when SoftwareCursorEnabled property is changed. FSimpleMulticastDelegate OnSoftwareCursorChanged; virtual void PostInitProperties() override; @@ -84,13 +84,17 @@ protected: UPROPERTY(EditAnywhere, config, Category = "Extensions", meta = (MetaClass = "ImGuiInputHandler")) FStringClassReference ImGuiInputHandlerClass; - // Define a custom key binding to 'ImGui.SwitchInputMode' command. Binding is only set if key is valid. + // Define a shortcut key to 'ImGui.ToggleInput' command. Binding is only set if the key field is valid. // Note that modifier key properties can be set to one of the three values: undetermined means that state of the given - // modifier is not tested, checked means that it needs to be pressed and unchecked means that it cannot be pressed. + // modifier is not important, checked means that it needs to be pressed and unchecked means that it cannot be pressed. // // This binding is using Player Input's DebugExecBindings which only works in non-shipment builds. UPROPERTY(EditAnywhere, config, Category = "Keyboard Shortcuts") - FImGuiKeyInfo SwitchInputModeKey; + FImGuiKeyInfo ToggleInput; + + // Deprecated name for ToggleInput. Kept temporarily to automatically move old configuration. + UPROPERTY(config) + FImGuiKeyInfo SwitchInputModeKey_DEPRECATED; // If true, then in input mode ImGui will draw its own cursor in place of the hardware one. // When disabled (default) there is a noticeable difference between cursor position seen by ImGui and position on diff --git a/Source/ImGui/Public/ImGuiInputHandler.h b/Source/ImGui/Public/ImGuiInputHandler.h index 0b6a817..1727d66 100644 --- a/Source/ImGui/Public/ImGuiInputHandler.h +++ b/Source/ImGui/Public/ImGuiInputHandler.h @@ -1,4 +1,4 @@ -// Copyright 1998-2018 Epic Games, Inc. All Rights Reserved. +// Distributed under the MIT License (MIT) (see accompanying LICENSE file) #pragma once @@ -174,12 +174,12 @@ protected: #endif /** - * Checks whether this key event can switch ImGui input mode (as defined in settings). + * Checks whether this key event can toggle ImGui input (as defined in settings). * * @param KeyEvent - Key event to test. - * @returns True, if this key is bound to 'ImGui.SwitchInputMode' command that switches ImGui input mode. + * @returns True, if this key is bound to 'ImGui.ToggleInput' command that switches ImGui input mode. */ - bool IsSwitchInputModeEvent(const FKeyEvent& KeyEvent) const; + bool IsToggleInputEvent(const FKeyEvent& KeyEvent) const; /** * Checks whether corresponding ImGui context has an active item (holding cursor focus).