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 (IsToggleInputEvent(KeyEvent))
|
||||
{
|
||||
FImGuiModuleProperties::Get().ToggleInput(ECVF_SetByConsole);
|
||||
FImGuiModuleProperties::Get().ToggleInput();
|
||||
return FImGuiInputResponse().RequestConsume();
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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<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