mirror of
https://github.com/kevinporetti/UnrealImGui.git
synced 2025-01-18 08:20:32 +00:00
Introduced input sharing properties:
- Added properties defining whether keyboard or gamepad input should be shared between ImGui and game. - Added interface and commands to dynamically change introduced properties. - Updated ImGui Input Handler to base default input responses on sharing properties.
This commit is contained in:
parent
0c69e6ddfc
commit
f4718e404a
@ -20,6 +20,7 @@
|
||||
|
||||
DEFINE_LOG_CATEGORY(LogImGuiInputHandler);
|
||||
|
||||
static FImGuiInputResponse IgnoreResponse{ false, false };
|
||||
|
||||
FImGuiInputResponse UImGuiInputHandler::OnKeyDown(const FKeyEvent& KeyEvent)
|
||||
{
|
||||
@ -27,13 +28,13 @@ FImGuiInputResponse UImGuiInputHandler::OnKeyDown(const FKeyEvent& KeyEvent)
|
||||
if (IsToggleInputEvent(KeyEvent))
|
||||
{
|
||||
ModuleManager->GetProperties().ToggleInput();
|
||||
return FImGuiInputResponse().RequestConsume();
|
||||
return GetDefaultKeyboardResponse().RequestConsume();
|
||||
}
|
||||
|
||||
// Ignore console events, so we don't block it from opening.
|
||||
if (IsConsoleEvent(KeyEvent))
|
||||
{
|
||||
return FImGuiInputResponse{ false, false };
|
||||
return IgnoreResponse;
|
||||
}
|
||||
|
||||
#if WITH_EDITOR
|
||||
@ -41,11 +42,21 @@ FImGuiInputResponse UImGuiInputHandler::OnKeyDown(const FKeyEvent& KeyEvent)
|
||||
// command, then ignore that event and let the command execute.
|
||||
if (!HasImGuiActiveItem() && IsStopPlaySessionEvent(KeyEvent))
|
||||
{
|
||||
return FImGuiInputResponse{ false, false };
|
||||
return IgnoreResponse;
|
||||
}
|
||||
#endif // WITH_EDITOR
|
||||
|
||||
return DefaultResponse();
|
||||
return GetDefaultKeyboardResponse();
|
||||
}
|
||||
|
||||
FImGuiInputResponse UImGuiInputHandler::GetDefaultKeyboardResponse() const
|
||||
{
|
||||
return FImGuiInputResponse{ true, !ModuleManager->GetProperties().IsKeyboardInputShared() };
|
||||
}
|
||||
|
||||
FImGuiInputResponse UImGuiInputHandler::GetDefaultGamepadResponse() const
|
||||
{
|
||||
return FImGuiInputResponse{ true, !ModuleManager->GetProperties().IsGamepadInputShared() };
|
||||
}
|
||||
|
||||
bool UImGuiInputHandler::IsConsoleEvent(const FKeyEvent& KeyEvent) const
|
||||
|
@ -16,6 +16,8 @@ namespace CommandNames
|
||||
const TCHAR* ToggleInput = TEXT("ImGui.ToggleInput");
|
||||
const TCHAR* ToggleKeyboardNavigation = TEXT("ImGui.ToggleKeyboardNavigation");
|
||||
const TCHAR* ToggleGamepadNavigation = TEXT("ImGui.ToggleGamepadNavigation");
|
||||
const TCHAR* ToggleKeyboardInputSharing = TEXT("ImGui.ToggleKeyboardInputSharing");
|
||||
const TCHAR* ToggleGamepadInputSharing = TEXT("ImGui.ToggleGamepadInputSharing");
|
||||
const TCHAR* ToggleDemo = TEXT("ImGui.ToggleDemo");
|
||||
}
|
||||
}
|
||||
@ -31,6 +33,12 @@ FImGuiModuleCommands::FImGuiModuleCommands(FImGuiModuleManager& InModuleManager)
|
||||
, ToggleGamepadNavigationCommand(CommandNames::ToggleGamepadNavigation,
|
||||
TEXT("Toggle ImGui gamepad navigation."),
|
||||
FConsoleCommandDelegate::CreateRaw(this, &FImGuiModuleCommands::ToggleGamepadNavigation))
|
||||
, ToggleKeyboardInputSharingCommand(CommandNames::ToggleKeyboardInputSharing,
|
||||
TEXT("Toggle ImGui keyboard input sharing."),
|
||||
FConsoleCommandDelegate::CreateRaw(this, &FImGuiModuleCommands::ToggleKeyboardInputSharing))
|
||||
, ToggleGamepadInputSharingCommand(CommandNames::ToggleGamepadInputSharing,
|
||||
TEXT("Toggle ImGui gamepad input sharing."),
|
||||
FConsoleCommandDelegate::CreateRaw(this, &FImGuiModuleCommands::ToggleGamepadInputSharing))
|
||||
, ToggleDemoCommand(CommandNames::ToggleDemo,
|
||||
TEXT("Toggle ImGui demo."),
|
||||
FConsoleCommandDelegate::CreateRaw(this, &FImGuiModuleCommands::ToggleDemo))
|
||||
@ -97,6 +105,16 @@ void FImGuiModuleCommands::ToggleGamepadNavigation()
|
||||
ModuleManager.GetProperties().ToggleGamepadNavigation();
|
||||
}
|
||||
|
||||
void FImGuiModuleCommands::ToggleKeyboardInputSharing()
|
||||
{
|
||||
ModuleManager.GetProperties().ToggleKeyboardInputSharing();
|
||||
}
|
||||
|
||||
void FImGuiModuleCommands::ToggleGamepadInputSharing()
|
||||
{
|
||||
ModuleManager.GetProperties().ToggleGamepadInputSharing();
|
||||
}
|
||||
|
||||
void FImGuiModuleCommands::ToggleDemo()
|
||||
{
|
||||
ModuleManager.GetProperties().ToggleDemo();
|
||||
|
@ -33,6 +33,8 @@ private:
|
||||
void ToggleInput();
|
||||
void ToggleKeyboardNavigation();
|
||||
void ToggleGamepadNavigation();
|
||||
void ToggleKeyboardInputSharing();
|
||||
void ToggleGamepadInputSharing();
|
||||
void ToggleDemo();
|
||||
|
||||
FImGuiModuleManager& ModuleManager;
|
||||
@ -40,5 +42,7 @@ private:
|
||||
FAutoConsoleCommand ToggleInputCommand;
|
||||
FAutoConsoleCommand ToggleKeyboardNavigationCommand;
|
||||
FAutoConsoleCommand ToggleGamepadNavigationCommand;
|
||||
FAutoConsoleCommand ToggleKeyboardInputSharingCommand;
|
||||
FAutoConsoleCommand ToggleGamepadInputSharingCommand;
|
||||
FAutoConsoleCommand ToggleDemoCommand;
|
||||
};
|
||||
|
@ -106,7 +106,7 @@ public:
|
||||
* @returns Response with rules how input should be handled. Default implementation contains requests to process
|
||||
* and consume this event.
|
||||
*/
|
||||
virtual FImGuiInputResponse OnKeyChar(const struct FCharacterEvent& CharacterEvent) { return DefaultResponse(); }
|
||||
virtual FImGuiInputResponse OnKeyChar(const struct FCharacterEvent& CharacterEvent) { return GetDefaultKeyboardResponse(); }
|
||||
|
||||
/**
|
||||
* Called when handling keyboard key down events.
|
||||
@ -125,7 +125,7 @@ public:
|
||||
* @returns Response with rules how input should be handled. Default implementation contains requests to consume
|
||||
* this event.
|
||||
*/
|
||||
virtual FImGuiInputResponse OnKeyUp(const FKeyEvent& KeyEvent) { return DefaultResponse(); }
|
||||
virtual FImGuiInputResponse OnKeyUp(const FKeyEvent& KeyEvent) { return GetDefaultKeyboardResponse(); }
|
||||
|
||||
/**
|
||||
* Called when handling gamepad key down events.
|
||||
@ -133,7 +133,7 @@ public:
|
||||
* @returns Response with rules how input should be handled. Default implementation contains requests to process
|
||||
* and consume this event.
|
||||
*/
|
||||
virtual FImGuiInputResponse OnGamepadKeyDown(const FKeyEvent& GamepadKeyEvent) { return DefaultResponse(); }
|
||||
virtual FImGuiInputResponse OnGamepadKeyDown(const FKeyEvent& GamepadKeyEvent) { return GetDefaultGamepadResponse(); }
|
||||
|
||||
/**
|
||||
* Called when handling gamepad key up events.
|
||||
@ -143,7 +143,7 @@ public:
|
||||
* @returns Response with rules how input should be handled. Default implementation contains requests to consume
|
||||
* this event.
|
||||
*/
|
||||
virtual FImGuiInputResponse OnGamepadKeyUp(const FKeyEvent& GamepadKeyEvent) { return DefaultResponse(); }
|
||||
virtual FImGuiInputResponse OnGamepadKeyUp(const FKeyEvent& GamepadKeyEvent) { return GetDefaultGamepadResponse(); }
|
||||
|
||||
/**
|
||||
* Called when handling gamepad analog events.
|
||||
@ -151,10 +151,24 @@ public:
|
||||
* @returns Response with rules how input should be handled. Default implementation contains requests to process
|
||||
* and consume this event.
|
||||
*/
|
||||
virtual FImGuiInputResponse OnGamepadAxis(const FAnalogInputEvent& GamepadAxisEvent) { return DefaultResponse(); }
|
||||
virtual FImGuiInputResponse OnGamepadAxis(const FAnalogInputEvent& GamepadAxisEvent) { return GetDefaultGamepadResponse(); }
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Get default keyboard response, with consume request based on IsKeyboardInputShared property.
|
||||
*
|
||||
* @returns Default response for keyboard inputs.
|
||||
*/
|
||||
FImGuiInputResponse GetDefaultKeyboardResponse() const;
|
||||
|
||||
/**
|
||||
* Get default gamepad response, with consume request based on IsGamepadInputShared property.
|
||||
*
|
||||
* @returns Default response for gamepad inputs.
|
||||
*/
|
||||
FImGuiInputResponse GetDefaultGamepadResponse() const;
|
||||
|
||||
/**
|
||||
* Checks whether this is a key event that can open console.
|
||||
*
|
||||
@ -192,8 +206,6 @@ private:
|
||||
|
||||
void Initialize(FImGuiModuleManager* InModuleManager, UGameViewportClient* InGameViewport, int32 InContextIndex);
|
||||
|
||||
FORCEINLINE FImGuiInputResponse DefaultResponse() { return FImGuiInputResponse{ true, true }; }
|
||||
|
||||
FImGuiModuleManager* ModuleManager = nullptr;
|
||||
|
||||
TWeakObjectPtr<UGameViewportClient> GameViewport;
|
||||
|
@ -35,6 +35,24 @@ public:
|
||||
/** Toggle gamepad navigation. */
|
||||
void ToggleGamepadNavigation() { SetGamepadNavigationEnabled(!IsGamepadNavigationEnabled()); }
|
||||
|
||||
/** Check whether keyboard input is shared with game. */
|
||||
bool IsKeyboardInputShared() const { return bKeyboardInputShared; }
|
||||
|
||||
/** Set whether keyboard input should be shared with game. */
|
||||
void SetKeyboardInputShared(bool bShared) { bKeyboardInputShared = bShared; }
|
||||
|
||||
/** Toggle whether keyboard input should be shared with game. */
|
||||
void ToggleKeyboardInputSharing() { SetKeyboardInputShared(!IsKeyboardInputShared()); }
|
||||
|
||||
/** Check whether gamepad input is shared with game. */
|
||||
bool IsGamepadInputShared() const { return bGamepadInputShared; }
|
||||
|
||||
/** Set whether gamepad input should be shared with game. */
|
||||
void SetGamepadInputShared(bool bShared) { bGamepadInputShared = bShared; }
|
||||
|
||||
/** Toggle whether gamepad input should be shared with game. */
|
||||
void ToggleGamepadInputSharing() { SetGamepadInputShared(!IsGamepadInputShared()); }
|
||||
|
||||
/** Check whether ImGui demo is visible. */
|
||||
bool ShowDemo() const { return bShowDemo; }
|
||||
|
||||
@ -51,5 +69,8 @@ private:
|
||||
bool bKeyboardNavigationEnabled = false;
|
||||
bool bGamepadNavigationEnabled = false;
|
||||
|
||||
bool bKeyboardInputShared = false;
|
||||
bool bGamepadInputShared = false;
|
||||
|
||||
bool bShowDemo = false;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user