Add Keyboard localization option

User can choose QWERTY or AZERTY keyboard input
This commit is contained in:
Intemporel
2022-02-12 21:49:02 +01:00
parent e8281f400c
commit 4d6a79fc0d
4 changed files with 100 additions and 10 deletions

View File

@@ -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, 6>{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, 6>{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;

View File

@@ -132,6 +132,9 @@ private:
bool _camera_moved_since_last_draw = true;
std::array<Qt::Key, 6> _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};

View File

@@ -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();
}
}
}
}

View File

@@ -995,6 +995,9 @@
<layout class="QVBoxLayout" name="verticalLayout_32">
<item>
<layout class="QVBoxLayout" name="verticalLayout_33">
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_57">
<item>
@@ -1198,6 +1201,72 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_9">
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_8">
<property name="minimumSize">
<size>
<width>134</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Keyboard locale</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="_keyboard_locale">
<property name="minimumSize">
<size>
<width>80</width>
<height>0</height>
</size>
</property>
<item>
<property name="text">
<string>QWERTY</string>
</property>
</item>
<item>
<property name="text">
<string>AZERTY</string>
</property>
</item>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
</layout>