citra-qt: Add base support for hotkey reconfiguration + UI (whole of PR citra-emu/citra#3786)
* Adds a new Hotkeys tab in the Controls group. * Right click to reconfigure. * See the original PR for more details & screenshots.
This commit is contained in:
parent
95a57a2fe3
commit
5fa25fcf13
22 changed files with 559 additions and 306 deletions
|
@ -276,6 +276,30 @@ void ConfigureInput::ApplyProfile() {
|
|||
Settings::values.current_input_profile_index = ui->profile->currentIndex();
|
||||
}
|
||||
|
||||
void ConfigureInput::EmitInputKeysChanged() {
|
||||
emit InputKeysChanged(GetUsedKeyboardKeys());
|
||||
}
|
||||
|
||||
void ConfigureInput::OnHotkeysChanged(QList<QKeySequence> new_key_list) {
|
||||
hotkey_list = new_key_list;
|
||||
}
|
||||
|
||||
QList<QKeySequence> ConfigureInput::GetUsedKeyboardKeys() {
|
||||
QList<QKeySequence> list;
|
||||
for (int button = 0; button < Settings::NativeButton::NumButtons; button++) {
|
||||
auto button_param = buttons_param[button];
|
||||
|
||||
if (button_param.Get("engine", "") == "keyboard") {
|
||||
list << QKeySequence(button_param.Get("code", 0));
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(adityaruplaha): Add home button to list when we finally emulate it
|
||||
// Button ID of home button is 14: Reffered from citra_qt/configuration/config.cpp
|
||||
list.removeOne(list.indexOf(QKeySequence(buttons_param[14].Get("code", 0))));
|
||||
return list;
|
||||
}
|
||||
|
||||
void ConfigureInput::loadConfiguration() {
|
||||
std::transform(Settings::values.current_input_profile.buttons.begin(),
|
||||
Settings::values.current_input_profile.buttons.end(), buttons_param.begin(),
|
||||
|
@ -332,11 +356,14 @@ void ConfigureInput::updateButtonLabels() {
|
|||
}
|
||||
analog_map_stick[analog_id]->setText(tr("Set Analog Stick"));
|
||||
}
|
||||
|
||||
EmitInputKeysChanged();
|
||||
}
|
||||
|
||||
void ConfigureInput::handleClick(QPushButton* button,
|
||||
std::function<void(const Common::ParamPackage&)> new_input_setter,
|
||||
InputCommon::Polling::DeviceType type) {
|
||||
previous_key_code = QKeySequence(button->text())[0];
|
||||
button->setText(tr("[press key]"));
|
||||
button->setFocus();
|
||||
|
||||
|
@ -378,16 +405,26 @@ void ConfigureInput::keyPressEvent(QKeyEvent* event) {
|
|||
if (!input_setter || !event)
|
||||
return;
|
||||
|
||||
if (event->key() != Qt::Key_Escape) {
|
||||
if (event->key() != Qt::Key_Escape && event->key() != previous_key_code) {
|
||||
if (want_keyboard_keys) {
|
||||
// Check if key is already bound
|
||||
if (hotkey_list.contains(QKeySequence(event->key())) ||
|
||||
GetUsedKeyboardKeys().contains(QKeySequence(event->key()))) {
|
||||
setPollingResult({}, true);
|
||||
QMessageBox::critical(this, tr("Error!"),
|
||||
tr("You're using a key that's already bound."));
|
||||
return;
|
||||
}
|
||||
setPollingResult(Common::ParamPackage{InputCommon::GenerateKeyboardParam(event->key())},
|
||||
false);
|
||||
} else {
|
||||
// Escape key wasn't pressed and we don't want any keyboard keys, so don't stop polling
|
||||
// Escape key wasn't pressed and we don't want any keyboard keys, so don't stop
|
||||
// polling
|
||||
return;
|
||||
}
|
||||
}
|
||||
setPollingResult({}, true);
|
||||
previous_key_code = 0;
|
||||
}
|
||||
|
||||
void ConfigureInput::retranslateUi() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue