mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-01 08:19:51 -05:00
Add the ability to configure the Console key through the openspace.cfg (closes #2573)
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#ifndef __OPENSPACE_CORE___CONFIGURATION___H__
|
||||
#define __OPENSPACE_CORE___CONFIGURATION___H__
|
||||
|
||||
#include <openspace/util/keys.h>
|
||||
#include <ghoul/lua/luastate.h>
|
||||
#include <ghoul/misc/dictionary.h>
|
||||
#include <filesystem>
|
||||
@@ -91,6 +92,8 @@ struct Configuration {
|
||||
bool isLoggingOpenGLCalls = false;
|
||||
bool isPrintingEvents = false;
|
||||
|
||||
Key consoleKey = Key::GraveAccent;
|
||||
|
||||
float shutdownCountdown = 0.f;
|
||||
|
||||
bool shouldUseScreenshotDate = false;
|
||||
|
||||
@@ -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<std::string> _commandsHistory;
|
||||
size_t _activeCommand = 0;
|
||||
|
||||
@@ -237,6 +237,7 @@ LoadingScreen = {
|
||||
CheckOpenGLState = false
|
||||
LogEachOpenGLCall = false
|
||||
PrintEvents = false
|
||||
ConsoleKey = "GRAVEACCENT"
|
||||
|
||||
ShutdownCountdown = 3
|
||||
ScreenshotUseDate = true
|
||||
|
||||
@@ -254,6 +254,10 @@ namespace {
|
||||
// the OpenSpaceEngine with the same name
|
||||
std::optional<bool> 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<std::string> 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);
|
||||
|
||||
@@ -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:");
|
||||
|
||||
@@ -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<unsigned int>(CommandInputButton)) {
|
||||
if (codepoint == static_cast<unsigned int>(_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));
|
||||
|
||||
Reference in New Issue
Block a user