From 0e2d5e245dbec91e21f0b785335fc2857f80fd8d Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Mon, 3 Apr 2023 10:53:09 +0200 Subject: [PATCH] Add the ability to configure the Console key through the openspace.cfg (closes #2573) --- include/openspace/engine/configuration.h | 3 +++ include/openspace/rendering/luaconsole.h | 4 ++++ openspace.cfg | 1 + src/engine/configuration.cpp | 17 +++++++++++++++++ src/engine/openspaceengine.cpp | 1 + src/rendering/luaconsole.cpp | 10 ++++++---- 6 files changed, 32 insertions(+), 4 deletions(-) diff --git a/include/openspace/engine/configuration.h b/include/openspace/engine/configuration.h index 0fca1bcb60..d63fbc5086 100644 --- a/include/openspace/engine/configuration.h +++ b/include/openspace/engine/configuration.h @@ -25,6 +25,7 @@ #ifndef __OPENSPACE_CORE___CONFIGURATION___H__ #define __OPENSPACE_CORE___CONFIGURATION___H__ +#include #include #include #include @@ -91,6 +92,8 @@ struct Configuration { bool isLoggingOpenGLCalls = false; bool isPrintingEvents = false; + Key consoleKey = Key::GraveAccent; + float shutdownCountdown = 0.f; bool shouldUseScreenshotDate = false; diff --git a/include/openspace/rendering/luaconsole.h b/include/openspace/rendering/luaconsole.h index 88086bc3c0..f7a828fb97 100644 --- a/include/openspace/rendering/luaconsole.h +++ b/include/openspace/rendering/luaconsole.h @@ -58,6 +58,8 @@ public: void render(); float currentHeight() const; + void setCommandInputButton(Key key); + private: void parallelConnectionChanged(const ParallelConnection::Status& status); @@ -71,6 +73,8 @@ private: properties::Vec4Property _historyTextColor; properties::IntProperty _historyLength; + Key _commandInputButton = Key::GraveAccent; + size_t _inputPosition = 0; std::vector _commandsHistory; size_t _activeCommand = 0; diff --git a/openspace.cfg b/openspace.cfg index cec2e9cafa..686c9a106e 100644 --- a/openspace.cfg +++ b/openspace.cfg @@ -237,6 +237,7 @@ LoadingScreen = { CheckOpenGLState = false LogEachOpenGLCall = false PrintEvents = false +ConsoleKey = "GRAVEACCENT" ShutdownCountdown = 3 ScreenshotUseDate = true diff --git a/src/engine/configuration.cpp b/src/engine/configuration.cpp index 9f610d37e1..1712c61b02 100644 --- a/src/engine/configuration.cpp +++ b/src/engine/configuration.cpp @@ -254,6 +254,10 @@ namespace { // the OpenSpaceEngine with the same name std::optional printEvents; + /// Determines which key opens the in-game console. The value passed in must be a + /// valid key (see keys.h for a list) + std::optional consoleKey; + // This value determines whether the initialization of the scene graph should // occur multithreaded, that is, whether multiple scene graph nodes should // initialize in parallel. The only use for this value is to disable it for @@ -352,6 +356,19 @@ void parseLuaState(Configuration& configuration) { c.isCheckingOpenGLState = p.checkOpenGLState.value_or(c.isCheckingOpenGLState); c.isLoggingOpenGLCalls = p.logEachOpenGLCall.value_or(c.isLoggingOpenGLCalls); c.isPrintingEvents = p.printEvents.value_or(c.isPrintingEvents); + + if (p.consoleKey.has_value()) { + KeyWithModifier km = stringToKey(*p.consoleKey); + if (km.modifier != KeyModifier::None) { + throw ghoul::RuntimeError(fmt::format( + "Console key '{}' must be a 'bare' key and cannot contain any modifiers", + *p.consoleKey + )); + } + + c.consoleKey = km.key; + } + c.shutdownCountdown = p.shutdownCountdown.value_or(c.shutdownCountdown); c.shouldUseScreenshotDate = p.screenshotUseDate.value_or(c.shouldUseScreenshotDate); c.onScreenTextScaling = p.onScreenTextScaling.value_or(c.onScreenTextScaling); diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index ca98e7d4fc..824de87119 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -470,6 +470,7 @@ void OpenSpaceEngine::initializeGL() { LTRACE("OpenSpaceEngine::initializeGL::Console::initialize(begin)"); try { global::luaConsole->initialize(); + global::luaConsole->setCommandInputButton(global::configuration->consoleKey); } catch (ghoul::RuntimeError& e) { LERROR("Error initializing Console with error:"); diff --git a/src/rendering/luaconsole.cpp b/src/rendering/luaconsole.cpp index 3c2404ec48..b7d97d74b2 100644 --- a/src/rendering/luaconsole.cpp +++ b/src/rendering/luaconsole.cpp @@ -54,8 +54,6 @@ namespace { constexpr uint64_t CurrentVersion = 0xFEEE'FEEE'0000'0001; - constexpr openspace::Key CommandInputButton = openspace::Key::GraveAccent; - constexpr std::string_view FontName = "Console"; constexpr float EntryFontSize = 14.0f; constexpr float HistoryFontSize = 11.0f; @@ -274,7 +272,7 @@ bool LuaConsole::keyboardCallback(Key key, KeyModifier modifier, KeyAction actio return false; } - if (key == CommandInputButton) { + if (key == _commandInputButton) { // Button left of 1 and above TAB // How to deal with different keyboard languages? ---abock if (_isVisible) { @@ -580,7 +578,7 @@ void LuaConsole::charCallback(unsigned int codepoint, return; } - if (codepoint == static_cast(CommandInputButton)) { + if (codepoint == static_cast(_commandInputButton)) { return; } @@ -832,6 +830,10 @@ float LuaConsole::currentHeight() const { return _currentHeight; } +void LuaConsole::setCommandInputButton(Key key) { + _commandInputButton = key; +} + void LuaConsole::addToCommand(std::string c) { const size_t length = c.length(); _commands.at(_activeCommand).insert(_inputPosition, std::move(c));