mirror of
https://github.com/kevinporetti/UnrealImGui.git
synced 2025-01-18 08:20:32 +00:00
Replaced console variables in FImGuiModuleProperties with plain variables. Added console commands to toggle states of those properties.
This commit is contained in:
parent
e00c1ff9e3
commit
70db3c7b20
@ -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 this is an input mode switch event then handle it here and consume.
|
||||||
if (IsToggleInputEvent(KeyEvent))
|
if (IsToggleInputEvent(KeyEvent))
|
||||||
{
|
{
|
||||||
FImGuiModuleProperties::Get().ToggleInput(ECVF_SetByConsole);
|
FImGuiModuleProperties::Get().ToggleInput();
|
||||||
return FImGuiInputResponse().RequestConsume();
|
return FImGuiInputResponse().RequestConsume();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,13 +13,25 @@ namespace CommandNames
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
const TCHAR* ToggleInput = TEXT("ImGui.ToggleInput");
|
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()
|
FImGuiModuleCommands::FImGuiModuleCommands()
|
||||||
: ToggleInputCommand(CommandNames::ToggleInput,
|
: ToggleInputCommand(CommandNames::ToggleInput,
|
||||||
TEXT("Switch ImGui input mode."),
|
TEXT("Toggle ImGui input mode."),
|
||||||
FConsoleCommandDelegate::CreateRaw(this, &FImGuiModuleCommands::ToggleInput))
|
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
|
// Delegate initializer to support settings loaded after this object creation (in stand-alone builds) and potential
|
||||||
// reloading of settings.
|
// reloading of settings.
|
||||||
@ -70,5 +82,20 @@ void FImGuiModuleCommands::UpdateToggleInputKeyBinding()
|
|||||||
|
|
||||||
void FImGuiModuleCommands::ToggleInput()
|
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();
|
||||||
}
|
}
|
||||||
|
@ -14,13 +14,11 @@ class FImGuiModuleCommands
|
|||||||
FImGuiModuleCommands();
|
FImGuiModuleCommands();
|
||||||
~FImGuiModuleCommands();
|
~FImGuiModuleCommands();
|
||||||
|
|
||||||
// Disable copy semantics.
|
FImGuiModuleCommands(const FImGuiModuleCommands&) = delete;
|
||||||
FImGuiModuleCommands(const FImGuiModuleCommands&) = default;
|
FImGuiModuleCommands& operator=(const FImGuiModuleCommands&) = delete;
|
||||||
FImGuiModuleCommands& operator=(const FImGuiModuleCommands&) = default;
|
|
||||||
|
|
||||||
// Disable move semantics.
|
FImGuiModuleCommands(FImGuiModuleCommands&&) = delete;
|
||||||
FImGuiModuleCommands(FImGuiModuleCommands&&) = default;
|
FImGuiModuleCommands& operator=(FImGuiModuleCommands&&) = delete;
|
||||||
FImGuiModuleCommands& operator=(FImGuiModuleCommands&&) = default;
|
|
||||||
|
|
||||||
void InitializeSettings();
|
void InitializeSettings();
|
||||||
|
|
||||||
@ -30,6 +28,12 @@ class FImGuiModuleCommands
|
|||||||
void UpdateToggleInputKeyBinding();
|
void UpdateToggleInputKeyBinding();
|
||||||
|
|
||||||
void ToggleInput();
|
void ToggleInput();
|
||||||
|
void ToggleKeyboardNavigation();
|
||||||
|
void ToggleGamepadNavigation();
|
||||||
|
void ToggleDemo();
|
||||||
|
|
||||||
FAutoConsoleCommand ToggleInputCommand;
|
FAutoConsoleCommand ToggleInputCommand;
|
||||||
|
FAutoConsoleCommand ToggleKeyboardNavigationCommand;
|
||||||
|
FAutoConsoleCommand ToggleGamepadNavigationCommand;
|
||||||
|
FAutoConsoleCommand ToggleDemoCommand;
|
||||||
};
|
};
|
||||||
|
@ -10,64 +10,3 @@ FImGuiModuleProperties& FImGuiModuleProperties::Get()
|
|||||||
static FImGuiModuleProperties Instance;
|
static FImGuiModuleProperties Instance;
|
||||||
return 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);
|
|
||||||
}
|
|
||||||
|
@ -14,44 +14,56 @@ public:
|
|||||||
// Get the instance of the ImGui properties.
|
// Get the instance of the ImGui properties.
|
||||||
static FImGuiModuleProperties& Get();
|
static FImGuiModuleProperties& Get();
|
||||||
|
|
||||||
// Check whether input is enabled.
|
// Check whether ImGui input is enabled.
|
||||||
bool IsInputEnabled() const;
|
bool IsInputEnabled() const { return bInputEnabled; }
|
||||||
|
|
||||||
// Set whether input should be enabled.
|
// Enable or disable ImGui input.
|
||||||
void SetInputEnabled(bool bEnabled, EConsoleVariableFlags SetBy = ECVF_SetByCode);
|
void SetInputEnabled(bool bEnabled) { bInputEnabled = bEnabled; }
|
||||||
|
|
||||||
// Toggle input state.
|
// Toggle ImGui input.
|
||||||
void ToggleInput(EConsoleVariableFlags SetBy = ECVF_SetByCode);
|
void ToggleInput() { SetInputEnabled(!IsInputEnabled()); }
|
||||||
|
|
||||||
// Check whether keyboard navigation is enabled.
|
// 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.
|
// Check whether gamepad navigation is enabled.
|
||||||
bool IsGamepadNavigationEnabled() const;
|
bool IsGamepadNavigationEnabled() const { return bGamepadNavigationEnabled; }
|
||||||
|
|
||||||
// Check whether demo should be visible.
|
// Enable or disable gamepad navigation.
|
||||||
bool ShowDemo() const;
|
void SetGamepadNavigationEnabled(bool bEnabled) { bGamepadNavigationEnabled = bEnabled; }
|
||||||
|
|
||||||
// Set whether demo should be visible.
|
// Toggle gamepad navigation.
|
||||||
void SetShowDemo(bool bEnabled, EConsoleVariableFlags SetBy = ECVF_SetByCode);
|
void ToggleGamepadNavigation() { SetGamepadNavigationEnabled(!IsGamepadNavigationEnabled()); }
|
||||||
|
|
||||||
// Toggle demo visibility.
|
// Check whether ImGui demo is visible.
|
||||||
void ToggleDemo(EConsoleVariableFlags SetBy = ECVF_SetByCode);
|
bool ShowDemo() const { return bShowDemo; }
|
||||||
|
|
||||||
|
// Show or hide ImGui demo.
|
||||||
|
void SetShowDemo(bool bShow) { bShowDemo = bShow; }
|
||||||
|
|
||||||
|
// Toggle ImGui demo.
|
||||||
|
void ToggleDemo() { SetShowDemo(!ShowDemo()); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
FImGuiModuleProperties();
|
FImGuiModuleProperties() = default;
|
||||||
|
|
||||||
// Disable copy and move semantics.
|
|
||||||
FImGuiModuleProperties(const FImGuiModuleProperties&) = delete;
|
FImGuiModuleProperties(const FImGuiModuleProperties&) = delete;
|
||||||
FImGuiModuleProperties& operator=(const FImGuiModuleProperties&) = delete;
|
FImGuiModuleProperties& operator=(const FImGuiModuleProperties&) = delete;
|
||||||
|
|
||||||
FImGuiModuleProperties(FImGuiModuleProperties&&) = delete;
|
FImGuiModuleProperties(FImGuiModuleProperties&&) = delete;
|
||||||
FImGuiModuleProperties& operator=(FImGuiModuleProperties&&) = delete;
|
FImGuiModuleProperties& operator=(FImGuiModuleProperties&&) = delete;
|
||||||
|
|
||||||
TAutoConsoleVariable<int32> InputEnabledVariable;
|
bool bInputEnabled = false;
|
||||||
|
|
||||||
TAutoConsoleVariable<int32> InputNavigationVariable;
|
bool bKeyboardNavigationEnabled = false;
|
||||||
|
bool bGamepadNavigationEnabled = false;
|
||||||
|
|
||||||
TAutoConsoleVariable<int32> ShowDemoVariable;
|
bool bShowDemo = false;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user