Allow fully customisable controller hotkeys

This commit is contained in:
grimkor 2023-04-28 17:42:18 +01:00
parent 9bf19b04f6
commit ceb65c259a
4 changed files with 56 additions and 32 deletions

View file

@ -1163,7 +1163,8 @@ void GMainWindow::InitializeRecentFileMenuActions() {
UpdateRecentFiles();
}
void GMainWindow::LinkActionShortcut(QAction* action, const QString& action_name) {
void GMainWindow::LinkActionShortcut(QAction* action, const QString& action_name,
const bool tas_allowed) {
static const QString main_window = QStringLiteral("Main Window");
action->setShortcut(hotkey_registry.GetKeySequence(main_window, action_name));
action->setShortcutContext(hotkey_registry.GetShortcutContext(main_window, action_name));
@ -1175,7 +1176,14 @@ void GMainWindow::LinkActionShortcut(QAction* action, const QString& action_name
const auto* controller_hotkey =
hotkey_registry.GetControllerHotkey(main_window, action_name, controller);
connect(
controller_hotkey, &ControllerShortcut::Activated, this, [action] { action->trigger(); },
controller_hotkey, &ControllerShortcut::Activated, this,
[action, tas_allowed, this] {
auto [tas_status, current_tas_frame, total_tas_frames] =
input_subsystem->GetTas()->GetStatus();
if (tas_allowed || tas_status == InputCommon::TasInput::TasState::Stopped) {
action->trigger();
}
},
Qt::QueuedConnection);
}
@ -1192,9 +1200,9 @@ void GMainWindow::InitializeHotkeys() {
LinkActionShortcut(ui->action_Show_Status_Bar, QStringLiteral("Toggle Status Bar"));
LinkActionShortcut(ui->action_Fullscreen, QStringLiteral("Fullscreen"));
LinkActionShortcut(ui->action_Capture_Screenshot, QStringLiteral("Capture Screenshot"));
LinkActionShortcut(ui->action_TAS_Start, QStringLiteral("TAS Start/Stop"));
LinkActionShortcut(ui->action_TAS_Record, QStringLiteral("TAS Record"));
LinkActionShortcut(ui->action_TAS_Reset, QStringLiteral("TAS Reset"));
LinkActionShortcut(ui->action_TAS_Start, QStringLiteral("TAS Start/Stop"), true);
LinkActionShortcut(ui->action_TAS_Record, QStringLiteral("TAS Record"), true);
LinkActionShortcut(ui->action_TAS_Reset, QStringLiteral("TAS Reset"), true);
static const QString main_window = QStringLiteral("Main Window");
const auto connect_shortcut = [&]<typename Fn>(const QString& action_name, const Fn& function) {