diff --git a/src/citra_qt/configuration/config.cpp b/src/citra_qt/configuration/config.cpp index 744f6422f..968821a6a 100644 --- a/src/citra_qt/configuration/config.cpp +++ b/src/citra_qt/configuration/config.cpp @@ -8,7 +8,6 @@ #include #include #include "citra_qt/configuration/config.h" -#include "citra_qt/uisettings.h" #include "common/file_util.h" #include "core/frontend/mic.h" #include "core/hle/service/service.h" @@ -56,31 +55,32 @@ const std::array, Settings::NativeAnalog::NumAnalogs> Config: // This must be in alphabetical order according to action name as it must have the same order as // UISetting::values.shortcuts, which is alphabetically ordered. // clang-format off -const std::array default_hotkeys{ - {{QStringLiteral("Advance Frame"), QStringLiteral("Main Window"), {QStringLiteral("\\"), Qt::ApplicationShortcut}}, - {QStringLiteral("Capture Screenshot"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+P"), Qt::ApplicationShortcut}}, - {QStringLiteral("Continue/Pause Emulation"), QStringLiteral("Main Window"), {QStringLiteral("F4"), Qt::WindowShortcut}}, - {QStringLiteral("Decrease Speed Limit"), QStringLiteral("Main Window"), {QStringLiteral("-"), Qt::ApplicationShortcut}}, +const std::array Config::default_hotkeys {{ + {QStringLiteral("Advance Frame"), QStringLiteral("Main Window"), {QStringLiteral(""), Qt::ApplicationShortcut}}, + {QStringLiteral("Capture Screenshot"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+P"), Qt::WidgetWithChildrenShortcut}}, + {QStringLiteral("Continue/Pause Emulation"), QStringLiteral("Main Window"), {QStringLiteral("F4"), Qt::WindowShortcut}}, + {QStringLiteral("Decrease Speed Limit"), QStringLiteral("Main Window"), {QStringLiteral("-"), Qt::ApplicationShortcut}}, {QStringLiteral("Exit Citra"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+Q"), Qt::WindowShortcut}}, - {QStringLiteral("Exit Fullscreen"), QStringLiteral("Main Window"), {QStringLiteral("Esc"), Qt::WindowShortcut}}, - {QStringLiteral("Fullscreen"), QStringLiteral("Main Window"), {QStringLiteral("F11"), Qt::WindowShortcut}}, - {QStringLiteral("Increase Speed Limit"), QStringLiteral("Main Window"), {QStringLiteral("+"), Qt::ApplicationShortcut}}, - {QStringLiteral("Load Amiibo"), QStringLiteral("Main Window"), {QStringLiteral("F2"), Qt::ApplicationShortcut}}, - {QStringLiteral("Load File"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+O"), Qt::WindowShortcut}}, + {QStringLiteral("Exit Fullscreen"), QStringLiteral("Main Window"), {QStringLiteral("Esc"), Qt::WindowShortcut}}, + {QStringLiteral("Fullscreen"), QStringLiteral("Main Window"), {QStringLiteral("F11"), Qt::WindowShortcut}}, + {QStringLiteral("Increase Speed Limit"), QStringLiteral("Main Window"), {QStringLiteral("+"), Qt::ApplicationShortcut}}, + {QStringLiteral("Load Amiibo"), QStringLiteral("Main Window"), {QStringLiteral("F2"), Qt::WidgetWithChildrenShortcut}}, + {QStringLiteral("Load File"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+O"), Qt::WidgetWithChildrenShortcut}}, {QStringLiteral("Load from Newest Slot"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+V"), Qt::WindowShortcut}}, {QStringLiteral("Mute Audio"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+M"), Qt::WindowShortcut}}, - {QStringLiteral("Remove Amiibo"), QStringLiteral("Main Window"), {QStringLiteral("F3"), Qt::ApplicationShortcut}}, - {QStringLiteral("Restart Emulation"), QStringLiteral("Main Window"), {QStringLiteral("F6"), Qt::WindowShortcut}}, - {QStringLiteral("Rotate Screens Upright"), QStringLiteral("Main Window"), {QStringLiteral("F8"), Qt::WindowShortcut}}, + {QStringLiteral("Remove Amiibo"), QStringLiteral("Main Window"), {QStringLiteral("F3"), Qt::ApplicationShortcut}}, + {QStringLiteral("Restart Emulation"), QStringLiteral("Main Window"), {QStringLiteral("F6"), Qt::WindowShortcut}}, + {QStringLiteral("Rotate Screens Upright"), QStringLiteral("Main Window"), {QStringLiteral("F8"), Qt::WindowShortcut}}, {QStringLiteral("Save to Oldest Slot"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+C"), Qt::WindowShortcut}}, - {QStringLiteral("Stop Emulation"), QStringLiteral("Main Window"), {QStringLiteral("F5"), Qt::WindowShortcut}}, - {QStringLiteral("Swap Screens"), QStringLiteral("Main Window"), {QStringLiteral("F9"), Qt::WindowShortcut}}, - {QStringLiteral("Toggle Alternate Speed"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+Z"), Qt::ApplicationShortcut}}, + {QStringLiteral("Stop Emulation"), QStringLiteral("Main Window"), {QStringLiteral("F5"), Qt::WindowShortcut}}, + {QStringLiteral("Swap Screens"), QStringLiteral("Main Window"), {QStringLiteral("F9"), Qt::WindowShortcut}}, + {QStringLiteral("Toggle Per-Game Speed"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+Z"), Qt::ApplicationShortcut}}, {QStringLiteral("Toggle Filter Bar"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+F"), Qt::WindowShortcut}}, {QStringLiteral("Toggle Frame Advancing"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+A"), Qt::ApplicationShortcut}}, - {QStringLiteral("Toggle Screen Layout"), QStringLiteral("Main Window"), {QStringLiteral("F10"), Qt::WindowShortcut}}, + {QStringLiteral("Toggle Screen Layout"), QStringLiteral("Main Window"), {QStringLiteral("F10"), Qt::WindowShortcut}}, {QStringLiteral("Toggle Status Bar"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+S"), Qt::WindowShortcut}}, - {QStringLiteral("Toggle Texture Dumping"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+D"), Qt::ApplicationShortcut}}}}; + {QStringLiteral("Toggle Texture Dumping"), QStringLiteral("Main Window"), {QStringLiteral(""), Qt::ApplicationShortcut}}, + }}; // clang-format on void Config::Initialize(const std::string& config_name) { @@ -632,14 +632,16 @@ void Config::ReadShortcutValues() { qt_config->beginGroup(QStringLiteral("Shortcuts")); for (const auto& [name, group, shortcut] : default_hotkeys) { - auto [keyseq, context] = shortcut; qt_config->beginGroup(group); qt_config->beginGroup(name); + // No longer using ReadSetting for shortcut.second as it innacurately returns a value of 1 + // for WidgetWithChildrenShortcut which is a value of 3. Needed to fix shortcuts the open + // a file dialog in windowed mode UISettings::values.shortcuts.push_back( {name, group, - {ReadSetting(QStringLiteral("KeySeq"), keyseq).toString(), - ReadSetting(QStringLiteral("Context"), context).toInt()}}); + {ReadSetting(QStringLiteral("KeySeq"), shortcut.keyseq).toString(), + shortcut.context}}); qt_config->endGroup(); qt_config->endGroup(); } @@ -1110,12 +1112,13 @@ void Config::SaveShortcutValues() { // Lengths of UISettings::values.shortcuts & default_hotkeys are same. // However, their ordering must also be the same. for (std::size_t i = 0; i < default_hotkeys.size(); i++) { - auto [name, group, shortcut] = UISettings::values.shortcuts[i]; + const auto& [name, group, shortcut] = UISettings::values.shortcuts[i]; + const auto& default_hotkey = default_hotkeys[i].shortcut; + qt_config->beginGroup(group); qt_config->beginGroup(name); - WriteSetting(QStringLiteral("KeySeq"), shortcut.first, default_hotkeys[i].shortcut.first); - WriteSetting(QStringLiteral("Context"), shortcut.second, - default_hotkeys[i].shortcut.second); + WriteSetting(QStringLiteral("KeySeq"), shortcut.keyseq, default_hotkey.keyseq); + WriteSetting(QStringLiteral("Context"), shortcut.context, default_hotkey.context); qt_config->endGroup(); qt_config->endGroup(); } diff --git a/src/citra_qt/configuration/config.h b/src/citra_qt/configuration/config.h index 8a8659de4..7f1855d72 100644 --- a/src/citra_qt/configuration/config.h +++ b/src/citra_qt/configuration/config.h @@ -8,6 +8,7 @@ #include #include #include +#include "citra_qt/uisettings.h" #include "common/settings.h" class QSettings; @@ -25,6 +26,7 @@ public: static const std::array default_buttons; static const std::array, Settings::NativeAnalog::NumAnalogs> default_analogs; + static const std::array default_hotkeys; private: void Initialize(const std::string& config_name); diff --git a/src/citra_qt/configuration/configure_hotkeys.cpp b/src/citra_qt/configuration/configure_hotkeys.cpp index 287e7baa4..e4015aa25 100644 --- a/src/citra_qt/configuration/configure_hotkeys.cpp +++ b/src/citra_qt/configuration/configure_hotkeys.cpp @@ -2,31 +2,40 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include #include #include +#include "citra_qt/configuration/config.h" #include "citra_qt/configuration/configure_hotkeys.h" #include "citra_qt/hotkeys.h" #include "citra_qt/util/sequence_dialog/sequence_dialog.h" #include "common/settings.h" #include "ui_configure_hotkeys.h" +constexpr int name_column = 0; +constexpr int hotkey_column = 1; + ConfigureHotkeys::ConfigureHotkeys(QWidget* parent) : QWidget(parent), ui(std::make_unique()) { ui->setupUi(this); setFocusPolicy(Qt::ClickFocus); model = new QStandardItemModel(this); - model->setColumnCount(3); - model->setHorizontalHeaderLabels({tr("Action"), tr("Hotkey"), tr("Context")}); + model->setColumnCount(2); + model->setHorizontalHeaderLabels({tr("Action"), tr("Hotkey")}); connect(ui->hotkey_list, &QTreeView::doubleClicked, this, &ConfigureHotkeys::Configure); + connect(ui->hotkey_list, &QTreeView::customContextMenuRequested, this, + &ConfigureHotkeys::PopupContextMenu); + ui->hotkey_list->setContextMenuPolicy(Qt::CustomContextMenu); ui->hotkey_list->setModel(model); - // TODO(Kloen): Make context configurable as well (hiding the column for now) - ui->hotkey_list->hideColumn(2); + ui->hotkey_list->setColumnWidth(0, 250); + ui->hotkey_list->resizeColumnToContents(hotkey_column); - ui->hotkey_list->setColumnWidth(0, 200); - ui->hotkey_list->resizeColumnToContents(1); + connect(ui->button_restore_defaults, &QPushButton::clicked, this, + &ConfigureHotkeys::RestoreDefaults); + connect(ui->button_clear_all, &QPushButton::clicked, this, &ConfigureHotkeys::ClearAll); } ConfigureHotkeys::~ConfigureHotkeys() = default; @@ -55,9 +64,11 @@ void ConfigureHotkeys::Populate(const HotkeyRegistry& registry) { QStandardItem* action = new QStandardItem(hotkey.first); QStandardItem* keyseq = new QStandardItem(hotkey.second.keyseq.toString(QKeySequence::NativeText)); + QStandardItem* controller_keyseq = new QStandardItem(hotkey.second.controller_keyseq); action->setEditable(false); keyseq->setEditable(false); - parent_item->appendRow({action, keyseq}); + controller_keyseq->setEditable(false); + parent_item->appendRow({action, keyseq, controller_keyseq}); } model->appendRow(parent_item); } @@ -74,8 +85,9 @@ void ConfigureHotkeys::Configure(QModelIndex index) { return; } - index = index.sibling(index.row(), 1); - auto* const model = ui->hotkey_list->model(); + // Swap to the hotkey column + index = index.sibling(index.row(), hotkey_column); + const auto previous_key = model->data(index); SequenceDialog hotkey_dialog{this}; @@ -85,26 +97,50 @@ void ConfigureHotkeys::Configure(QModelIndex index) { if (return_code == QDialog::Rejected || key_sequence.isEmpty()) { return; } + const auto [key_sequence_used, used_action] = IsUsedKey(key_sequence); - if (IsUsedKey(key_sequence) && key_sequence != QKeySequence(previous_key.toString())) { - QMessageBox::warning(this, tr("Conflicting Key Sequence"), - tr("The entered key sequence is already assigned to another hotkey.")); + if (key_sequence_used && key_sequence != QKeySequence(previous_key.toString())) { + QMessageBox::warning( + this, tr("Conflicting Key Sequence"), + tr("The entered key sequence is already assigned to: %1").arg(used_action)); } else { model->setData(index, key_sequence.toString(QKeySequence::NativeText)); EmitHotkeysChanged(); } } -bool ConfigureHotkeys::IsUsedKey(QKeySequence key_sequence) const { - return input_keys_list.contains(key_sequence) || GetUsedKeyList().contains(key_sequence); +std::pair ConfigureHotkeys::IsUsedKey(QKeySequence key_sequence) const { + if (key_sequence == QKeySequence::fromString(QStringLiteral(""), QKeySequence::NativeText)) { + return std::make_pair(false, QString()); + } + + if (input_keys_list.contains(key_sequence)) { + return std::make_pair(true, tr("A 3ds button")); + } + + for (int r = 0; r < model->rowCount(); ++r) { + const QStandardItem* const parent = model->item(r, 0); + + for (int r2 = 0; r2 < parent->rowCount(); ++r2) { + const QStandardItem* const key_seq_item = parent->child(r2, hotkey_column); + const auto key_seq_str = key_seq_item->text(); + const auto key_seq = QKeySequence::fromString(key_seq_str, QKeySequence::NativeText); + + if (key_sequence == key_seq) { + return std::make_pair(true, parent->child(r2, 0)->text()); + } + } + } + + return std::make_pair(false, QString()); } void ConfigureHotkeys::ApplyConfiguration(HotkeyRegistry& registry) { for (int key_id = 0; key_id < model->rowCount(); key_id++) { QStandardItem* parent = model->item(key_id, 0); for (int key_column_id = 0; key_column_id < parent->rowCount(); key_column_id++) { - QStandardItem* action = parent->child(key_column_id, 0); - QStandardItem* keyseq = parent->child(key_column_id, 1); + const QStandardItem* action = parent->child(key_column_id, name_column); + const QStandardItem* keyseq = parent->child(key_column_id, hotkey_column); for (auto& [group, sub_actions] : registry.hotkey_groups) { if (group != parent->text()) continue; @@ -120,6 +156,61 @@ void ConfigureHotkeys::ApplyConfiguration(HotkeyRegistry& registry) { registry.SaveHotkeys(); } +void ConfigureHotkeys::RestoreDefaults() { + for (int r = 0; r < model->rowCount(); ++r) { + const QStandardItem* parent = model->item(r, 0); + + for (int r2 = 0; r2 < parent->rowCount(); ++r2) { + model->item(r, 0) + ->child(r2, hotkey_column) + ->setText(Config::default_hotkeys[r2].shortcut.keyseq); + } + } +} + +void ConfigureHotkeys::ClearAll() { + for (int r = 0; r < model->rowCount(); ++r) { + const QStandardItem* parent = model->item(r, 0); + + for (int r2 = 0; r2 < parent->rowCount(); ++r2) { + model->item(r, 0)->child(r2, hotkey_column)->setText(QString{}); + } + } +} + +void ConfigureHotkeys::PopupContextMenu(const QPoint& menu_location) { + const auto index = ui->hotkey_list->indexAt(menu_location); + if (!index.parent().isValid()) { + return; + } + + QMenu context_menu; + QAction* restore_default = context_menu.addAction(tr("Restore Default")); + QAction* clear = context_menu.addAction(tr("Clear")); + + const auto hotkey_index = index.sibling(index.row(), hotkey_column); + connect(restore_default, &QAction::triggered, + [this, hotkey_index] { RestoreHotkey(hotkey_index); }); + connect(clear, &QAction::triggered, + [this, hotkey_index] { model->setData(hotkey_index, QString{}); }); + + context_menu.exec(ui->hotkey_list->viewport()->mapToGlobal(menu_location)); +} + +void ConfigureHotkeys::RestoreHotkey(QModelIndex index) { + const QKeySequence& default_key_sequence = QKeySequence::fromString( + Config::default_hotkeys[index.row()].shortcut.keyseq, QKeySequence::NativeText); + const auto [key_sequence_used, used_action] = IsUsedKey(default_key_sequence); + + if (key_sequence_used && default_key_sequence != QKeySequence(model->data(index).toString())) { + QMessageBox::warning( + this, tr("Conflicting Key Sequence"), + tr("The default key sequence is already assigned to: %1").arg(used_action)); + } else { + model->setData(index, default_key_sequence.toString(QKeySequence::NativeText)); + } +} + void ConfigureHotkeys::RetranslateUI() { ui->retranslateUi(this); } diff --git a/src/citra_qt/configuration/configure_hotkeys.h b/src/citra_qt/configuration/configure_hotkeys.h index ad4c468ec..99d159217 100644 --- a/src/citra_qt/configuration/configure_hotkeys.h +++ b/src/citra_qt/configuration/configure_hotkeys.h @@ -19,7 +19,7 @@ class ConfigureHotkeys : public QWidget { public: explicit ConfigureHotkeys(QWidget* parent = nullptr); - ~ConfigureHotkeys(); + ~ConfigureHotkeys() override; void ApplyConfiguration(HotkeyRegistry& registry); void RetranslateUI(); @@ -41,10 +41,13 @@ signals: private: void Configure(QModelIndex index); - bool IsUsedKey(QKeySequence key_sequence) const; + std::pair IsUsedKey(QKeySequence key_sequence) const; QList GetUsedKeyList() const; - std::unique_ptr ui; + void RestoreDefaults(); + void ClearAll(); + void PopupContextMenu(const QPoint& menu_location); + void RestoreHotkey(QModelIndex index); /** * List of keyboard keys currently registered to any of the 3DS inputs. @@ -53,5 +56,7 @@ private: */ QList input_keys_list; + std::unique_ptr ui; + QStandardItemModel* model; }; diff --git a/src/citra_qt/configuration/configure_hotkeys.ui b/src/citra_qt/configuration/configure_hotkeys.ui index 56a2e53fa..0c4850eed 100644 --- a/src/citra_qt/configuration/configure_hotkeys.ui +++ b/src/citra_qt/configuration/configure_hotkeys.ui @@ -15,7 +15,7 @@ - + @@ -23,6 +23,37 @@ + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Clear All + + + + + + + Restore Defaults + + + + + + + diff --git a/src/citra_qt/configuration/configure_input.cpp b/src/citra_qt/configuration/configure_input.cpp index 6c40b9ebf..62be40208 100644 --- a/src/citra_qt/configuration/configure_input.cpp +++ b/src/citra_qt/configuration/configure_input.cpp @@ -395,9 +395,6 @@ ConfigureInput::ConfigureInput(QWidget* parent) }); LoadConfiguration(); - - // TODO(wwylele): enable this when we actually emulate it - ui->buttonHome->setEnabled(false); } ConfigureInput::~ConfigureInput() = default; diff --git a/src/citra_qt/hotkeys.cpp b/src/citra_qt/hotkeys.cpp index 591ac8163..0e5368517 100644 --- a/src/citra_qt/hotkeys.cpp +++ b/src/citra_qt/hotkeys.cpp @@ -17,8 +17,8 @@ void HotkeyRegistry::SaveHotkeys() { for (const auto& hotkey : group.second) { UISettings::values.shortcuts.push_back( {hotkey.first, group.first, - UISettings::ContextualShortcut(hotkey.second.keyseq.toString(), - hotkey.second.context)}); + UISettings::ContextualShortcut( + {hotkey.second.keyseq.toString(), hotkey.second.context})}); } } } @@ -28,9 +28,10 @@ void HotkeyRegistry::LoadHotkeys() { // beginGroup() for (auto shortcut : UISettings::values.shortcuts) { Hotkey& hk = hotkey_groups[shortcut.group][shortcut.name]; - if (!shortcut.shortcut.first.isEmpty()) { - hk.keyseq = QKeySequence::fromString(shortcut.shortcut.first, QKeySequence::NativeText); - hk.context = static_cast(shortcut.shortcut.second); + if (!shortcut.shortcut.keyseq.isEmpty()) { + hk.keyseq = + QKeySequence::fromString(shortcut.shortcut.keyseq, QKeySequence::NativeText); + hk.context = static_cast(shortcut.shortcut.context); } if (hk.shortcut) { hk.shortcut->disconnect(); @@ -42,8 +43,9 @@ void HotkeyRegistry::LoadHotkeys() { QShortcut* HotkeyRegistry::GetHotkey(const QString& group, const QString& action, QWidget* widget) { Hotkey& hk = hotkey_groups[group][action]; - if (!hk.shortcut) + if (!hk.shortcut) { hk.shortcut = new QShortcut(hk.keyseq, widget, nullptr, nullptr, hk.context); + } return hk.shortcut; } diff --git a/src/citra_qt/hotkeys.h b/src/citra_qt/hotkeys.h index 248fadaf3..6a377f511 100644 --- a/src/citra_qt/hotkeys.h +++ b/src/citra_qt/hotkeys.h @@ -68,6 +68,7 @@ public: private: struct Hotkey { QKeySequence keyseq; + QString controller_keyseq; QShortcut* shortcut = nullptr; Qt::ShortcutContext context = Qt::WindowShortcut; }; diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index 44515db4a..b35337f3f 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -473,62 +473,37 @@ void GMainWindow::InitializeHotkeys() { hotkey_registry.LoadHotkeys(); const QString main_window = QStringLiteral("Main Window"); - const QString load_file = QStringLiteral("Load File"); - const QString exit_citra = QStringLiteral("Exit Citra"); - const QString stop_emulation = QStringLiteral("Stop Emulation"); - const QString toggle_filter_bar = QStringLiteral("Toggle Filter Bar"); - const QString toggle_status_bar = QStringLiteral("Toggle Status Bar"); const QString fullscreen = QStringLiteral("Fullscreen"); const QString toggle_screen_layout = QStringLiteral("Toggle Screen Layout"); const QString swap_screens = QStringLiteral("Swap Screens"); const QString rotate_screens = QStringLiteral("Rotate Screens Upright"); - ui->action_Show_Filter_Bar->setShortcut( - hotkey_registry.GetKeySequence(main_window, toggle_filter_bar)); - ui->action_Show_Filter_Bar->setShortcutContext( - hotkey_registry.GetShortcutContext(main_window, toggle_filter_bar)); + const auto link_action_shortcut = [&](QAction* action, const QString& action_name) { + 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)); + action->setAutoRepeat(false); + this->addAction(action); + }; - ui->action_Show_Status_Bar->setShortcut( - hotkey_registry.GetKeySequence(main_window, toggle_status_bar)); - ui->action_Show_Status_Bar->setShortcutContext( - hotkey_registry.GetShortcutContext(main_window, toggle_status_bar)); - - connect(hotkey_registry.GetHotkey(main_window, load_file, this), &QShortcut::activated, - ui->action_Load_File, &QAction::trigger); - - connect(hotkey_registry.GetHotkey(main_window, stop_emulation, this), &QShortcut::activated, - ui->action_Stop, &QAction::trigger); - - connect(hotkey_registry.GetHotkey(main_window, exit_citra, this), &QShortcut::activated, - ui->action_Exit, &QAction::trigger); - - connect( - hotkey_registry.GetHotkey(main_window, QStringLiteral("Continue/Pause Emulation"), this), - &QShortcut::activated, this, [&] { - if (emulation_running) { - if (emu_thread->IsRunning()) { - OnPauseGame(); - } else { - OnStartGame(); - } - } - }); - connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("Restart Emulation"), this), - &QShortcut::activated, this, [this] { - if (!Core::System::GetInstance().IsPoweredOn()) - return; - BootGame(QString(game_path)); - }); - connect(hotkey_registry.GetHotkey(main_window, swap_screens, render_window), - &QShortcut::activated, ui->action_Screen_Layout_Swap_Screens, &QAction::trigger); - connect(hotkey_registry.GetHotkey(main_window, rotate_screens, render_window), - &QShortcut::activated, ui->action_Screen_Layout_Upright_Screens, &QAction::trigger); - connect(hotkey_registry.GetHotkey(main_window, toggle_screen_layout, render_window), - &QShortcut::activated, this, &GMainWindow::ToggleScreenLayout); - connect(hotkey_registry.GetHotkey(main_window, fullscreen, render_window), - &QShortcut::activated, ui->action_Fullscreen, &QAction::trigger); - connect(hotkey_registry.GetHotkey(main_window, fullscreen, render_window), - &QShortcut::activatedAmbiguously, ui->action_Fullscreen, &QAction::trigger); + link_action_shortcut(ui->action_Load_File, QStringLiteral("Load File")); + link_action_shortcut(ui->action_Load_Amiibo, QStringLiteral("Load Amiibo")); + link_action_shortcut(ui->action_Remove_Amiibo, QStringLiteral("Remove Amiibo")); + link_action_shortcut(ui->action_Exit, QStringLiteral("Exit Citra")); + link_action_shortcut(ui->action_Restart, QStringLiteral("Restart Emulation")); + link_action_shortcut(ui->action_Pause, QStringLiteral("Continue/Pause Emulation")); + link_action_shortcut(ui->action_Stop, QStringLiteral("Stop Emulation")); + link_action_shortcut(ui->action_Show_Filter_Bar, QStringLiteral("Toggle Filter Bar")); + link_action_shortcut(ui->action_Show_Status_Bar, QStringLiteral("Toggle Status Bar")); + link_action_shortcut(ui->action_Fullscreen, fullscreen); + link_action_shortcut(ui->action_Capture_Screenshot, QStringLiteral("Capture Screenshot")); + link_action_shortcut(ui->action_Screen_Layout_Swap_Screens, swap_screens); + link_action_shortcut(ui->action_Screen_Layout_Upright_Screens, rotate_screens); + link_action_shortcut(ui->action_Enable_Frame_Advancing, + QStringLiteral("Toggle Frame Advancing")); + link_action_shortcut(ui->action_Advance_Frame, QStringLiteral("Advance Frame")); + link_action_shortcut(ui->action_Load_from_Newest_Slot, QStringLiteral("Load from Newest Slot")); + link_action_shortcut(ui->action_Save_to_Oldest_Slot, QStringLiteral("Save to Oldest Slot")); const auto add_secondary_window_hotkey = [this](QKeySequence hotkey, const char* slot) { // This action will fire specifically when secondary_window is in focus @@ -553,77 +528,53 @@ void GMainWindow::InitializeHotkeys() { const auto rotate_screen_hotkey = hotkey_registry.GetKeySequence(main_window, rotate_screens); add_secondary_window_hotkey(rotate_screen_hotkey, SLOT(TriggerRotateScreens())); - connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("Exit Fullscreen"), this), - &QShortcut::activated, this, [&] { - if (emulation_running) { - ui->action_Fullscreen->setChecked(false); - ToggleFullscreen(); - } - }); - connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("Toggle Alternate Speed"), this), - &QShortcut::activated, this, [&] { - Settings::values.frame_limit.SetGlobal(!Settings::values.frame_limit.UsingGlobal()); - UpdateStatusBar(); - }); - connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("Toggle Texture Dumping"), this), - &QShortcut::activated, this, - [&] { Settings::values.dump_textures = !Settings::values.dump_textures; }); + const auto connect_shortcut = [&](const QString& action_name, const auto& function) { + const auto* hotkey = hotkey_registry.GetHotkey(main_window, action_name, this); + connect(hotkey, &QShortcut::activated, this, function); + }; + + connect(hotkey_registry.GetHotkey(main_window, toggle_screen_layout, render_window), + &QShortcut::activated, this, &GMainWindow::ToggleScreenLayout); + + connect_shortcut(QStringLiteral("Exit Fullscreen"), [&] { + if (emulation_running) { + ui->action_Fullscreen->setChecked(false); + ToggleFullscreen(); + } + }); + connect_shortcut(QStringLiteral("Toggle Per-Game Speed"), [&] { + Settings::values.frame_limit.SetGlobal(!Settings::values.frame_limit.UsingGlobal()); + UpdateStatusBar(); + }); + connect_shortcut(QStringLiteral("Toggle Texture Dumping"), + [&] { Settings::values.dump_textures = !Settings::values.dump_textures; }); // We use "static" here in order to avoid capturing by lambda due to a MSVC bug, which makes // the variable hold a garbage value after this function exits static constexpr u16 SPEED_LIMIT_STEP = 5; - connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("Increase Speed Limit"), this), - &QShortcut::activated, this, [&] { - if (Settings::values.frame_limit.GetValue() == 0) { - return; - } - if (Settings::values.frame_limit.GetValue() < 995 - SPEED_LIMIT_STEP) { - Settings::values.frame_limit.SetValue(Settings::values.frame_limit.GetValue() + - SPEED_LIMIT_STEP); - } else { - Settings::values.frame_limit = 0; - } - UpdateStatusBar(); - }); - connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("Decrease Speed Limit"), this), - &QShortcut::activated, this, [&] { - if (Settings::values.frame_limit.GetValue() == 0) { - Settings::values.frame_limit = 995; - } else if (Settings::values.frame_limit.GetValue() > SPEED_LIMIT_STEP) { - Settings::values.frame_limit.SetValue(Settings::values.frame_limit.GetValue() - - SPEED_LIMIT_STEP); - UpdateStatusBar(); - } - UpdateStatusBar(); - }); - connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("Toggle Frame Advancing"), this), - &QShortcut::activated, ui->action_Enable_Frame_Advancing, &QAction::trigger); - connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("Advance Frame"), this), - &QShortcut::activated, ui->action_Advance_Frame, &QAction::trigger); - connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("Load Amiibo"), this), - &QShortcut::activated, this, [&] { - if (ui->action_Load_Amiibo->isEnabled()) { - OnLoadAmiibo(); - } - }); - connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("Remove Amiibo"), this), - &QShortcut::activated, this, [&] { - if (ui->action_Remove_Amiibo->isEnabled()) { - OnRemoveAmiibo(); - } - }); - connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("Capture Screenshot"), this), - &QShortcut::activated, this, [&] { - if (ui->action_Capture_Screenshot->isEnabled()) { - OnCaptureScreenshot(); - } - }); - connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("Load from Newest Slot"), this), - &QShortcut::activated, ui->action_Load_from_Newest_Slot, &QAction::trigger); - connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("Save to Oldest Slot"), this), - &QShortcut::activated, ui->action_Save_to_Oldest_Slot, &QAction::trigger); - connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("Mute Audio"), this), - &QShortcut::activated, this, - [] { Settings::values.audio_muted = !Settings::values.audio_muted; }); + connect_shortcut(QStringLiteral("Increase Speed Limit"), [&] { + if (Settings::values.frame_limit.GetValue() == 0) { + return; + } + if (Settings::values.frame_limit.GetValue() < 995 - SPEED_LIMIT_STEP) { + Settings::values.frame_limit.SetValue(Settings::values.frame_limit.GetValue() + + SPEED_LIMIT_STEP); + } else { + Settings::values.frame_limit = 0; + } + UpdateStatusBar(); + }); + connect_shortcut(QStringLiteral("Decrease Speed Limit"), [&] { + if (Settings::values.frame_limit.GetValue() == 0) { + Settings::values.frame_limit = 995; + } else if (Settings::values.frame_limit.GetValue() > SPEED_LIMIT_STEP) { + Settings::values.frame_limit.SetValue(Settings::values.frame_limit.GetValue() - + SPEED_LIMIT_STEP); + UpdateStatusBar(); + } + UpdateStatusBar(); + }); + connect_shortcut(QStringLiteral("Mute Audio"), + [] { Settings::values.audio_muted = !Settings::values.audio_muted; }); } void GMainWindow::ShowUpdaterWidgets() { @@ -686,7 +637,8 @@ void GMainWindow::OnAppFocusStateChanged(Qt::ApplicationState state) { (state & (Qt::ApplicationHidden | Qt::ApplicationInactive))) { auto_paused = true; OnPauseGame(); - } else if (ui->action_Start->isEnabled() && auto_paused && state == Qt::ApplicationActive) { + } else if (emulation_running && !emu_thread->IsRunning() && auto_paused && + state == Qt::ApplicationActive) { auto_paused = false; OnStartGame(); } @@ -728,32 +680,34 @@ void GMainWindow::ConnectWidgetEvents() { } void GMainWindow::ConnectMenuEvents() { + const auto connect_menu = [&](QAction* action, const auto& event_fn) { + connect(action, &QAction::triggered, this, event_fn); + // Add actions to this window so that hiding menus in fullscreen won't disable them + addAction(action); + // Add actions to the render window so that they work outside of single window mode + render_window->addAction(action); + }; + // File - connect(ui->action_Load_File, &QAction::triggered, this, &GMainWindow::OnMenuLoadFile); - connect(ui->action_Install_CIA, &QAction::triggered, this, &GMainWindow::OnMenuInstallCIA); - connect(ui->action_Exit, &QAction::triggered, this, &QMainWindow::close); - connect(ui->action_Load_Amiibo, &QAction::triggered, this, &GMainWindow::OnLoadAmiibo); - connect(ui->action_Remove_Amiibo, &QAction::triggered, this, &GMainWindow::OnRemoveAmiibo); + connect_menu(ui->action_Load_File, &GMainWindow::OnMenuLoadFile); + connect_menu(ui->action_Install_CIA, &GMainWindow::OnMenuInstallCIA); + connect_menu(ui->action_Exit, &QMainWindow::close); + connect_menu(ui->action_Load_Amiibo, &GMainWindow::OnLoadAmiibo); + connect_menu(ui->action_Remove_Amiibo, &GMainWindow::OnRemoveAmiibo); // Emulation - connect(ui->action_Start, &QAction::triggered, this, &GMainWindow::OnStartGame); - connect(ui->action_Pause, &QAction::triggered, this, &GMainWindow::OnPauseGame); - connect(ui->action_Stop, &QAction::triggered, this, &GMainWindow::OnStopGame); - connect(ui->action_Restart, &QAction::triggered, this, - [this] { BootGame(QString(game_path)); }); - connect(ui->action_Report_Compatibility, &QAction::triggered, this, - &GMainWindow::OnMenuReportCompatibility); - connect(ui->action_Configure, &QAction::triggered, this, &GMainWindow::OnConfigure); - connect(ui->action_Configure_Current_Game, &QAction::triggered, this, - &GMainWindow::OnConfigurePerGame); - connect(ui->action_Cheats, &QAction::triggered, this, &GMainWindow::OnCheats); + connect_menu(ui->action_Pause, &GMainWindow::OnPauseContinueGame); + connect_menu(ui->action_Stop, &GMainWindow::OnStopGame); + connect_menu(ui->action_Restart, [this] { BootGame(QString(game_path)); }); + connect_menu(ui->action_Report_Compatibility, &GMainWindow::OnMenuReportCompatibility); + connect_menu(ui->action_Configure, &GMainWindow::OnConfigure); + connect_menu(ui->action_Configure_Current_Game, &GMainWindow::OnConfigurePerGame); + connect_menu(ui->action_Cheats, &GMainWindow::OnCheats); // View - connect(ui->action_Single_Window_Mode, &QAction::triggered, this, - &GMainWindow::ToggleWindowMode); - connect(ui->action_Display_Dock_Widget_Headers, &QAction::triggered, this, - &GMainWindow::OnDisplayTitleBars); - connect(ui->action_Show_Filter_Bar, &QAction::triggered, this, &GMainWindow::OnToggleFilterBar); + connect_menu(ui->action_Single_Window_Mode, &GMainWindow::ToggleWindowMode); + connect_menu(ui->action_Display_Dock_Widget_Headers, &GMainWindow::OnDisplayTitleBars); + connect_menu(ui->action_Show_Filter_Bar, &GMainWindow::OnToggleFilterBar); connect(ui->action_Show_Status_Bar, &QAction::triggered, statusBar(), &QStatusBar::setVisible); // Multiplayer @@ -768,64 +722,41 @@ void GMainWindow::ConnectMenuEvents() { connect(ui->action_Show_Room, &QAction::triggered, multiplayer_state, &MultiplayerState::OnOpenNetworkRoom); - ui->action_Fullscreen->setShortcut( - hotkey_registry - .GetHotkey(QStringLiteral("Main Window"), QStringLiteral("Fullscreen"), this) - ->key()); - ui->action_Screen_Layout_Swap_Screens->setShortcut( - hotkey_registry - .GetHotkey(QStringLiteral("Main Window"), QStringLiteral("Swap Screens"), this) - ->key()); - ui->action_Screen_Layout_Swap_Screens->setShortcutContext(Qt::WidgetWithChildrenShortcut); - ui->action_Screen_Layout_Upright_Screens->setShortcut( - hotkey_registry - .GetHotkey(QStringLiteral("Main Window"), QStringLiteral("Rotate Screens Upright"), - this) - ->key()); - ui->action_Screen_Layout_Upright_Screens->setShortcutContext(Qt::WidgetWithChildrenShortcut); - connect(ui->action_Fullscreen, &QAction::triggered, this, &GMainWindow::ToggleFullscreen); - connect(ui->action_Screen_Layout_Default, &QAction::triggered, this, - &GMainWindow::ChangeScreenLayout); - connect(ui->action_Screen_Layout_Single_Screen, &QAction::triggered, this, - &GMainWindow::ChangeScreenLayout); - connect(ui->action_Screen_Layout_Large_Screen, &QAction::triggered, this, - &GMainWindow::ChangeScreenLayout); - connect(ui->action_Screen_Layout_Side_by_Side, &QAction::triggered, this, - &GMainWindow::ChangeScreenLayout); - connect(ui->action_Screen_Layout_Separate_Windows, &QAction::triggered, this, - &GMainWindow::ChangeScreenLayout); - connect(ui->action_Screen_Layout_Swap_Screens, &QAction::triggered, this, - &GMainWindow::OnSwapScreens); - connect(ui->action_Screen_Layout_Upright_Screens, &QAction::triggered, this, - &GMainWindow::OnRotateScreens); + connect_menu(ui->action_Fullscreen, &GMainWindow::ToggleFullscreen); + connect_menu(ui->action_Screen_Layout_Default, &GMainWindow::ChangeScreenLayout); + connect_menu(ui->action_Screen_Layout_Single_Screen, &GMainWindow::ChangeScreenLayout); + connect_menu(ui->action_Screen_Layout_Large_Screen, &GMainWindow::ChangeScreenLayout); + connect_menu(ui->action_Screen_Layout_Side_by_Side, &GMainWindow::ChangeScreenLayout); + connect_menu(ui->action_Screen_Layout_Separate_Windows, &GMainWindow::ChangeScreenLayout); + connect_menu(ui->action_Screen_Layout_Swap_Screens, &GMainWindow::OnSwapScreens); + connect_menu(ui->action_Screen_Layout_Upright_Screens, &GMainWindow::OnRotateScreens); // Movie - connect(ui->action_Record_Movie, &QAction::triggered, this, &GMainWindow::OnRecordMovie); - connect(ui->action_Play_Movie, &QAction::triggered, this, &GMainWindow::OnPlayMovie); - connect(ui->action_Close_Movie, &QAction::triggered, this, &GMainWindow::OnCloseMovie); - connect(ui->action_Save_Movie, &QAction::triggered, this, &GMainWindow::OnSaveMovie); - connect(ui->action_Movie_Read_Only_Mode, &QAction::toggled, this, - [](bool checked) { Core::Movie::GetInstance().SetReadOnly(checked); }); - connect(ui->action_Enable_Frame_Advancing, &QAction::triggered, this, [this] { + connect_menu(ui->action_Record_Movie, &GMainWindow::OnRecordMovie); + connect_menu(ui->action_Play_Movie, &GMainWindow::OnPlayMovie); + connect_menu(ui->action_Close_Movie, &GMainWindow::OnCloseMovie); + connect_menu(ui->action_Save_Movie, &GMainWindow::OnSaveMovie); + connect_menu(ui->action_Movie_Read_Only_Mode, + [](bool checked) { Core::Movie::GetInstance().SetReadOnly(checked); }); + connect_menu(ui->action_Enable_Frame_Advancing, [this] { if (emulation_running) { Core::System::GetInstance().frame_limiter.SetFrameAdvancing( ui->action_Enable_Frame_Advancing->isChecked()); ui->action_Advance_Frame->setEnabled(ui->action_Enable_Frame_Advancing->isChecked()); } }); - connect(ui->action_Advance_Frame, &QAction::triggered, this, [this] { - if (emulation_running) { + connect_menu(ui->action_Advance_Frame, [this] { + auto& system = Core::System::GetInstance(); + if (emulation_running && system.frame_limiter.IsFrameAdvancing()) { ui->action_Enable_Frame_Advancing->setChecked(true); ui->action_Advance_Frame->setEnabled(true); - Core::System::GetInstance().frame_limiter.SetFrameAdvancing(true); - Core::System::GetInstance().frame_limiter.AdvanceFrame(); + system.frame_limiter.AdvanceFrame(); } }); - connect(ui->action_Capture_Screenshot, &QAction::triggered, this, - &GMainWindow::OnCaptureScreenshot); + connect_menu(ui->action_Capture_Screenshot, &GMainWindow::OnCaptureScreenshot); #ifdef ENABLE_FFMPEG_VIDEO_DUMPER - connect(ui->action_Dump_Video, &QAction::triggered, [this] { + connect_menu(ui->action_Dump_Video, [this] { if (ui->action_Dump_Video->isChecked()) { OnStartVideoDumping(); } else { @@ -837,16 +768,41 @@ void GMainWindow::ConnectMenuEvents() { #endif // Help - connect(ui->action_Open_Citra_Folder, &QAction::triggered, this, - &GMainWindow::OnOpenCitraFolder); - connect(ui->action_FAQ, &QAction::triggered, []() { + connect_menu(ui->action_Open_Citra_Folder, &GMainWindow::OnOpenCitraFolder); + connect_menu(ui->action_FAQ, []() { QDesktopServices::openUrl(QUrl(QStringLiteral("https://citra-emu.org/wiki/faq/"))); }); - connect(ui->action_About, &QAction::triggered, this, &GMainWindow::OnMenuAboutCitra); - connect(ui->action_Check_For_Updates, &QAction::triggered, this, - &GMainWindow::OnCheckForUpdates); - connect(ui->action_Open_Maintenance_Tool, &QAction::triggered, this, - &GMainWindow::OnOpenUpdater); + connect_menu(ui->action_About, &GMainWindow::OnMenuAboutCitra); + connect_menu(ui->action_Check_For_Updates, &GMainWindow::OnCheckForUpdates); + connect_menu(ui->action_Open_Maintenance_Tool, &GMainWindow::OnOpenUpdater); +} + +void GMainWindow::UpdateMenuState() { + const bool is_paused = emu_thread == nullptr || !emu_thread->IsRunning(); + + const std::array running_actions{ + ui->action_Stop, + ui->action_Restart, + ui->action_Configure_Current_Game, + ui->action_Report_Compatibility, + ui->action_Load_Amiibo, + ui->action_Remove_Amiibo, + ui->action_Pause, + ui->action_Cheats, + ui->action_Advance_Frame, + }; + + for (QAction* action : running_actions) { + action->setEnabled(emulation_running); + } + + ui->action_Capture_Screenshot->setEnabled(emulation_running && !is_paused); + + if (emulation_running && is_paused) { + ui->action_Pause->setText(tr("&Continue")); + } else { + ui->action_Pause->setText(tr("&Pause")); + } } void GMainWindow::OnDisplayTitleBars(bool show) { @@ -1247,27 +1203,16 @@ void GMainWindow::ShutdownGame() { disconnect(render_window, &GRenderWindow::Closed, this, &GMainWindow::OnStopGame); disconnect(secondary_window, &GRenderWindow::Closed, this, &GMainWindow::OnStopGame); - // Update the GUI - ui->action_Start->setEnabled(false); - ui->action_Start->setText(tr("Start")); - ui->action_Pause->setEnabled(false); - ui->action_Stop->setEnabled(false); - ui->action_Restart->setEnabled(false); - ui->action_Cheats->setEnabled(false); - ui->action_Configure_Current_Game->setEnabled(false); - ui->action_Load_Amiibo->setEnabled(false); - ui->action_Remove_Amiibo->setEnabled(false); - ui->action_Report_Compatibility->setEnabled(false); - ui->action_Advance_Frame->setEnabled(false); - ui->action_Capture_Screenshot->setEnabled(false); render_window->hide(); secondary_window->hide(); loading_screen->hide(); loading_screen->Clear(); - if (game_list->IsEmpty()) + + if (game_list->IsEmpty()) { game_list_placeholder->show(); - else + } else { game_list->show(); + } game_list->SetFilterFocus(); setMouseTracking(false); @@ -1293,6 +1238,9 @@ void GMainWindow::ShutdownGame() { game_path.clear(); + // Update the GUI + UpdateMenuState(); + // When closing the game, destroy the GLWindow to clear the context after the game is closed render_window->ReleaseRenderTarget(); secondary_window->ReleaseRenderTarget(); @@ -1595,9 +1543,12 @@ void GMainWindow::OnMenuInstallCIA() { QStringList filepaths = QFileDialog::getOpenFileNames( this, tr("Load Files"), UISettings::values.roms_path, tr("3DS Installation File (*.CIA*)") + QStringLiteral(";;") + tr("All Files (*.*)")); - if (filepaths.isEmpty()) - return; + if (filepaths.isEmpty()) { + return; + } + + UISettings::values.roms_path = QFileInfo(filepaths[0]).path(); InstallCIA(filepaths); } @@ -1692,34 +1643,40 @@ void GMainWindow::OnStartGame() { qRegisterMetaType("std::string"); connect(emu_thread.get(), &EmuThread::ErrorThrown, this, &GMainWindow::OnCoreError); - ui->action_Start->setEnabled(false); - ui->action_Start->setText(tr("Continue")); - - ui->action_Pause->setEnabled(true); - ui->action_Stop->setEnabled(true); - ui->action_Restart->setEnabled(true); - ui->action_Cheats->setEnabled(true); - ui->action_Configure_Current_Game->setEnabled(true); - ui->action_Load_Amiibo->setEnabled(true); - ui->action_Report_Compatibility->setEnabled(true); - ui->action_Capture_Screenshot->setEnabled(true); + UpdateMenuState(); discord_rpc->Update(); UpdateSaveStates(); } +void GMainWindow::OnRestartGame() { + Core::System& system = Core::System::GetInstance(); + if (!system.IsPoweredOn()) { + return; + } + // Make a copy since BootGame edits game_path + BootGame(QString(game_path)); +} + void GMainWindow::OnPauseGame() { emu_thread->SetRunning(false); Camera::QtMultimediaCameraHandler::StopCameras(); - ui->action_Start->setEnabled(true); - ui->action_Pause->setEnabled(false); - ui->action_Stop->setEnabled(true); - ui->action_Capture_Screenshot->setEnabled(false); + UpdateMenuState(); AllowOSSleep(); } +void GMainWindow::OnPauseContinueGame() { + if (emulation_running) { + if (emu_thread->IsRunning()) { + OnPauseGame(); + } else { + OnStartGame(); + } + } +} + void GMainWindow::OnStopGame() { ShutdownGame(); Settings::RestoreGlobalState(false); @@ -1951,6 +1908,10 @@ void GMainWindow::OnConfigure() { } void GMainWindow::OnLoadAmiibo() { + if (emu_thread == nullptr || !emu_thread->IsRunning()) { + return; + } + const QString extensions{QStringLiteral("*.bin")}; const QString file_filter = tr("Amiibo File (%1);; All Files (*.*)").arg(extensions); const QString filename = QFileDialog::getOpenFileName(this, tr("Load Amiibo"), {}, file_filter); @@ -2105,6 +2066,10 @@ void GMainWindow::OnSaveMovie() { } void GMainWindow::OnCaptureScreenshot() { + if (emu_thread == nullptr || !emu_thread->IsRunning()) { + return; + } + OnPauseGame(); std::string path = UISettings::values.screenshot_path.GetValue(); if (!FileUtil::IsDirectory(path)) { @@ -2509,9 +2474,6 @@ void GMainWindow::OnLanguageChanged(const QString& locale) { ui->retranslateUi(this); RetranslateStatusBar(); UpdateWindowTitle(); - - if (emulation_running) - ui->action_Start->setText(tr("Continue")); } void GMainWindow::OnConfigurePerGame() { diff --git a/src/citra_qt/main.h b/src/citra_qt/main.h index 03689cc5f..4b3fa0d36 100644 --- a/src/citra_qt/main.h +++ b/src/citra_qt/main.h @@ -119,6 +119,7 @@ private: void ConnectWidgetEvents(); void ConnectMenuEvents(); + void UpdateMenuState(); void PreventOSSleep(); void AllowOSSleep(); @@ -169,7 +170,9 @@ private: private slots: void OnStartGame(); + void OnRestartGame(); void OnPauseGame(); + void OnPauseContinueGame(); void OnStopGame(); void OnSaveState(); void OnLoadState(); diff --git a/src/citra_qt/main.ui b/src/citra_qt/main.ui index 172486a04..b3e36a978 100644 --- a/src/citra_qt/main.ui +++ b/src/citra_qt/main.ui @@ -93,7 +93,6 @@ - @@ -215,14 +214,6 @@ E&xit - - - false - - - &Start - - false diff --git a/src/citra_qt/uisettings.h b/src/citra_qt/uisettings.h index 43e84ced8..06cb8e254 100644 --- a/src/citra_qt/uisettings.h +++ b/src/citra_qt/uisettings.h @@ -17,7 +17,10 @@ namespace UISettings { -using ContextualShortcut = std::pair; +struct ContextualShortcut { + QString keyseq; + int context; +}; struct Shortcut { QString name;