Enable button toggle for keyboard in the modifier button
This commit is contained in:
parent
9d010be483
commit
1f228c51ca
|
@ -12,20 +12,37 @@ namespace InputCommon {
|
||||||
|
|
||||||
class KeyButton final : public Input::ButtonDevice {
|
class KeyButton final : public Input::ButtonDevice {
|
||||||
public:
|
public:
|
||||||
explicit KeyButton(std::shared_ptr<KeyButtonList> key_button_list_)
|
explicit KeyButton(std::shared_ptr<KeyButtonList> key_button_list_, bool toggle_)
|
||||||
: key_button_list(std::move(key_button_list_)) {}
|
: key_button_list(std::move(key_button_list_)), toggle(toggle_) {}
|
||||||
|
|
||||||
~KeyButton() override;
|
~KeyButton() override;
|
||||||
|
|
||||||
bool GetStatus() const override {
|
bool GetStatus() const override {
|
||||||
|
if (toggle) {
|
||||||
|
return toggled_status.load();
|
||||||
|
}
|
||||||
return status.load();
|
return status.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ToggleButton() {
|
||||||
|
if (!lock) {
|
||||||
|
lock = true;
|
||||||
|
toggled_status.store(!toggled_status.load());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UnlockButton() {
|
||||||
|
lock = false;
|
||||||
|
}
|
||||||
|
|
||||||
friend class KeyButtonList;
|
friend class KeyButtonList;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<KeyButtonList> key_button_list;
|
std::shared_ptr<KeyButtonList> key_button_list;
|
||||||
std::atomic<bool> status{false};
|
std::atomic<bool> status{false};
|
||||||
|
std::atomic<bool> toggled_status{false};
|
||||||
|
bool lock = {};
|
||||||
|
const bool toggle;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct KeyButtonPair {
|
struct KeyButtonPair {
|
||||||
|
@ -51,6 +68,11 @@ public:
|
||||||
for (const KeyButtonPair& pair : list) {
|
for (const KeyButtonPair& pair : list) {
|
||||||
if (pair.key_code == key_code) {
|
if (pair.key_code == key_code) {
|
||||||
pair.key_button->status.store(pressed);
|
pair.key_button->status.store(pressed);
|
||||||
|
if (pressed) {
|
||||||
|
pair.key_button->ToggleButton();
|
||||||
|
} else {
|
||||||
|
pair.key_button->UnlockButton();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,7 +97,8 @@ KeyButton::~KeyButton() {
|
||||||
|
|
||||||
std::unique_ptr<Input::ButtonDevice> Keyboard::Create(const Common::ParamPackage& params) {
|
std::unique_ptr<Input::ButtonDevice> Keyboard::Create(const Common::ParamPackage& params) {
|
||||||
const int key_code = params.Get("code", 0);
|
const int key_code = params.Get("code", 0);
|
||||||
std::unique_ptr<KeyButton> button = std::make_unique<KeyButton>(key_button_list);
|
const bool toggle = params.Get("toggle", false);
|
||||||
|
std::unique_ptr<KeyButton> button = std::make_unique<KeyButton>(key_button_list, toggle);
|
||||||
key_button_list->AddKeyButton(key_code, button.get());
|
key_button_list->AddKeyButton(key_code, button.get());
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
|
@ -376,11 +376,15 @@ void GRenderWindow::closeEvent(QCloseEvent* event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GRenderWindow::keyPressEvent(QKeyEvent* event) {
|
void GRenderWindow::keyPressEvent(QKeyEvent* event) {
|
||||||
|
if (!event->isAutoRepeat()) {
|
||||||
input_subsystem->GetKeyboard()->PressKey(event->key());
|
input_subsystem->GetKeyboard()->PressKey(event->key());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GRenderWindow::keyReleaseEvent(QKeyEvent* event) {
|
void GRenderWindow::keyReleaseEvent(QKeyEvent* event) {
|
||||||
|
if (!event->isAutoRepeat()) {
|
||||||
input_subsystem->GetKeyboard()->ReleaseKey(event->key());
|
input_subsystem->GetKeyboard()->ReleaseKey(event->key());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GRenderWindow::mousePressEvent(QMouseEvent* event) {
|
void GRenderWindow::mousePressEvent(QMouseEvent* event) {
|
||||||
|
|
|
@ -104,7 +104,9 @@ QString ButtonToText(const Common::ParamPackage& param) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (param.Get("engine", "") == "keyboard") {
|
if (param.Get("engine", "") == "keyboard") {
|
||||||
return GetKeyName(param.Get("code", 0));
|
const QString button_str = GetKeyName(param.Get("code", 0));
|
||||||
|
const QString toggle = QString::fromStdString(param.Get("toggle", false) ? "~" : "");
|
||||||
|
return QObject::tr("%1%2").arg(toggle, button_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (param.Get("engine", "") == "gcpad") {
|
if (param.Get("engine", "") == "gcpad") {
|
||||||
|
@ -412,6 +414,15 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
|
||||||
analogs_param[analog_id].Set("modifier", "");
|
analogs_param[analog_id].Set("modifier", "");
|
||||||
analog_map_modifier_button[analog_id]->setText(tr("[not set]"));
|
analog_map_modifier_button[analog_id]->setText(tr("[not set]"));
|
||||||
});
|
});
|
||||||
|
context_menu.addAction(tr("Toggle button"), [&] {
|
||||||
|
Common::ParamPackage modifier_param =
|
||||||
|
Common::ParamPackage{analogs_param[analog_id].Get("modifier", "")};
|
||||||
|
const bool toggle_value = !modifier_param.Get("toggle", false);
|
||||||
|
modifier_param.Set("toggle", toggle_value);
|
||||||
|
analogs_param[analog_id].Set("modifier", modifier_param.Serialize());
|
||||||
|
analog_map_modifier_button[analog_id]->setText(
|
||||||
|
ButtonToText(modifier_param));
|
||||||
|
});
|
||||||
context_menu.exec(
|
context_menu.exec(
|
||||||
analog_map_modifier_button[analog_id]->mapToGlobal(menu_location));
|
analog_map_modifier_button[analog_id]->mapToGlobal(menu_location));
|
||||||
});
|
});
|
||||||
|
|
Reference in New Issue