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.
This commit is contained in:
Sebastian 2018-11-24 21:16:25 +00:00
parent c5f3759664
commit e00c1ff9e3
5 changed files with 55 additions and 25 deletions

View File

@ -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

View File

@ -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);
}
}

View File

@ -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))
{

View File

@ -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

View File

@ -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).