From 4d6a79fc0d8bf5bdd7b0657f479b153b630600d9 Mon Sep 17 00:00:00 2001 From: Intemporel Date: Sat, 12 Feb 2022 21:49:02 +0100 Subject: [PATCH] Add Keyboard localization option User can choose QWERTY or AZERTY keyboard input --- src/noggit/MapView.cpp | 34 ++++++--- src/noggit/MapView.h | 3 + .../windows/settingsPanel/SettingsPanel.cpp | 4 +- .../ui/windows/settingsPanel/SettingsPanel.ui | 69 +++++++++++++++++++ 4 files changed, 100 insertions(+), 10 deletions(-) diff --git a/src/noggit/MapView.cpp b/src/noggit/MapView.cpp index 362dee2d..ea33965c 100644 --- a/src/noggit/MapView.cpp +++ b/src/noggit/MapView.cpp @@ -4303,13 +4303,14 @@ void MapView::keyPressEvent (QKeyEvent *event) if (event->key() == Qt::Key_Space) _mod_space_down = true; + checkInputsSettings(); // movement - if (event->key() == Qt::Key_W) + if (event->key() == _inputs[0]) { moving = 1.0f; } - if (event->key() == Qt::Key_S) + if (event->key() == _inputs[1]) { moving = -1.0f; } @@ -4332,20 +4333,20 @@ void MapView::keyPressEvent (QKeyEvent *event) turn = -0.75f; } - if (event->key() == Qt::Key_D) + if (event->key() == _inputs[2]) { strafing = 1.0f; } - if (event->key() == Qt::Key_A) + if (event->key() == _inputs[3]) { strafing = -1.0f; } - if (event->key() == Qt::Key_Q) + if (event->key() == _inputs[4]) { updown = 1.0f; } - if (event->key() == Qt::Key_E) + if (event->key() == _inputs[5]) { updown = -1.0f; } @@ -4459,8 +4460,10 @@ void MapView::keyReleaseEvent (QKeyEvent* event) if (event->key() == Qt::Key_Space) _mod_space_down = false; + checkInputsSettings(); + // movement - if (event->key() == Qt::Key_W || event->key() == Qt::Key_S) + if (event->key() == _inputs[0] || event->key() == _inputs[1]) { moving = 0.0f; } @@ -4475,12 +4478,12 @@ void MapView::keyReleaseEvent (QKeyEvent* event) turn = 0.0f; } - if (event->key() == Qt::Key_D || event->key() == Qt::Key_A) + if (event->key() == _inputs[2] || event->key() == _inputs[3]) { strafing = 0.0f; } - if (event->key() == Qt::Key_Q || event->key() == Qt::Key_E) + if (event->key() == _inputs[4] || event->key() == _inputs[5]) { updown = 0.0f; } @@ -4518,6 +4521,19 @@ void MapView::keyReleaseEvent (QKeyEvent* event) } +void MapView::checkInputsSettings() +{ + QString _locale = _settings->value("keyboard_locale", "QWERTY").toString(); + + // default is QWERTY + _inputs = std::array{Qt::Key_W, Qt::Key_S, Qt::Key_D, Qt::Key_A, Qt::Key_Q, Qt::Key_E}; + + if (_locale == "AZERTY") + { + _inputs = std::array{Qt::Key_Z, Qt::Key_S, Qt::Key_D, Qt::Key_Q, Qt::Key_A, Qt::Key_E}; + } +} + void MapView::focusOutEvent (QFocusEvent*) { _mod_alt_down = false; diff --git a/src/noggit/MapView.h b/src/noggit/MapView.h index f7d79322..9c125817 100644 --- a/src/noggit/MapView.h +++ b/src/noggit/MapView.h @@ -132,6 +132,9 @@ private: bool _camera_moved_since_last_draw = true; + std::array _inputs = {Qt::Key_W, Qt::Key_S, Qt::Key_D, Qt::Key_A, Qt::Key_Q, Qt::Key_E}; + void checkInputsSettings(); + public: Noggit::BoolToggleProperty _draw_contour = {false}; Noggit::BoolToggleProperty _draw_mfbo = {false}; diff --git a/src/noggit/ui/windows/settingsPanel/SettingsPanel.cpp b/src/noggit/ui/windows/settingsPanel/SettingsPanel.cpp index 17e46745..3cf2dcaf 100644 --- a/src/noggit/ui/windows/settingsPanel/SettingsPanel.cpp +++ b/src/noggit/ui/windows/settingsPanel/SettingsPanel.cpp @@ -225,6 +225,7 @@ namespace Noggit ui->_nativeMenubar->setChecked(_settings->value("nativeMenubar", true).toBool()); ui->_additional_file_loading_log->setChecked( _settings->value("additional_file_loading_log", false).toBool()); + ui->_keyboard_locale->setCurrentText(_settings->value("keyboard_locale", "QWERTY").toString()); ui->_theme->setCurrentText(_settings->value("theme", "Dark").toString()); ui->assetBrowserBgCol->setColor(_settings->value("assetBrowser/background_color", @@ -284,6 +285,7 @@ namespace Noggit _settings->setValue("unload_interval", ui->_adt_unload_check_interval->value()); _settings->setValue("uid_startup_check", ui->_uid_cb->isChecked()); _settings->setValue("additional_file_loading_log", ui->_additional_file_loading_log->isChecked()); + _settings->setValue("keyboard_locale", ui->_keyboard_locale->currentText()); _settings->setValue("systemWindowFrame", ui->_systemWindowFrame->isChecked()); _settings->setValue("nativeMenubar", ui->_nativeMenubar->isChecked()); @@ -313,4 +315,4 @@ namespace Noggit emit saved(); } } -} \ No newline at end of file +} diff --git a/src/noggit/ui/windows/settingsPanel/SettingsPanel.ui b/src/noggit/ui/windows/settingsPanel/SettingsPanel.ui index 1a9f9648..cc4f8b89 100644 --- a/src/noggit/ui/windows/settingsPanel/SettingsPanel.ui +++ b/src/noggit/ui/windows/settingsPanel/SettingsPanel.ui @@ -995,6 +995,9 @@ + + 0 + @@ -1198,6 +1201,72 @@ + + + + 0 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 134 + 0 + + + + Keyboard locale + + + + + + + + 80 + 0 + + + + + QWERTY + + + + + AZERTY + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + +