From 8580e159fefc774a0b847a82158cce385c4f2c0f Mon Sep 17 00:00:00 2001 From: spycrab Date: Sat, 26 Aug 2017 20:54:37 +0200 Subject: [PATCH 1/4] Qt/SettingsWindow: Add SelectGeneralPane method --- Source/Core/DolphinQt2/Config/SettingsWindow.cpp | 7 ++++++- Source/Core/DolphinQt2/Config/SettingsWindow.h | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Source/Core/DolphinQt2/Config/SettingsWindow.cpp b/Source/Core/DolphinQt2/Config/SettingsWindow.cpp index 0ac1fe5cc6..36eedb9d69 100644 --- a/Source/Core/DolphinQt2/Config/SettingsWindow.cpp +++ b/Source/Core/DolphinQt2/Config/SettingsWindow.cpp @@ -38,7 +38,7 @@ SettingsWindow::SettingsWindow(QWidget* parent) : QDialog(parent) m_tabs = new ListTabWidget(); layout->addWidget(m_tabs); - AddTab(m_tabs, tr("General"), new GeneralPane(), "config"); + m_general_pane_index = AddTab(m_tabs, tr("General"), new GeneralPane(), "config"); AddTab(m_tabs, tr("Interface"), new InterfacePane(), "browse"); m_audio_pane_index = AddTab(m_tabs, tr("Audio"), new AudioPane(), "play"); AddTab(m_tabs, tr("Paths"), new PathPane(), "browse"); @@ -55,3 +55,8 @@ void SettingsWindow::SelectAudioPane() { m_tabs->setCurrentIndex(m_audio_pane_index); } + +void SettingsWindow::SelectGeneralPane() +{ + m_tabs->setCurrentIndex(m_general_pane_index); +} diff --git a/Source/Core/DolphinQt2/Config/SettingsWindow.h b/Source/Core/DolphinQt2/Config/SettingsWindow.h index f61b41bfe6..50efd2ad8f 100644 --- a/Source/Core/DolphinQt2/Config/SettingsWindow.h +++ b/Source/Core/DolphinQt2/Config/SettingsWindow.h @@ -13,9 +13,11 @@ class SettingsWindow final : public QDialog Q_OBJECT public: explicit SettingsWindow(QWidget* parent = nullptr); + void SelectGeneralPane(); void SelectAudioPane(); private: ListTabWidget* m_tabs; int m_audio_pane_index = -1; + int m_general_pane_index = -1; }; From 8687f6aae7928d4fc2268c1c0251f051503612af Mon Sep 17 00:00:00 2001 From: spycrab Date: Sat, 26 Aug 2017 20:55:16 +0200 Subject: [PATCH 2/4] Qt: Implement CheatWarningWidget --- .../DolphinQt2/Config/CheatWarningWidget.cpp | 79 +++++++++++++++++++ .../DolphinQt2/Config/CheatWarningWidget.h | 37 +++++++++ 2 files changed, 116 insertions(+) create mode 100644 Source/Core/DolphinQt2/Config/CheatWarningWidget.cpp create mode 100644 Source/Core/DolphinQt2/Config/CheatWarningWidget.h diff --git a/Source/Core/DolphinQt2/Config/CheatWarningWidget.cpp b/Source/Core/DolphinQt2/Config/CheatWarningWidget.cpp new file mode 100644 index 0000000000..c47bb93bd4 --- /dev/null +++ b/Source/Core/DolphinQt2/Config/CheatWarningWidget.cpp @@ -0,0 +1,79 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "DolphinQt2/Config/CheatWarningWidget.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "Core/ConfigManager.h" +#include "Core/Core.h" + +CheatWarningWidget::CheatWarningWidget(const std::string& game_id) : m_game_id(game_id) +{ + CreateWidgets(); + ConnectWidgets(); + + setHidden(true); + + connect(this, &CheatWarningWidget::CheatEnableToggled, this, + &CheatWarningWidget::CheatEnableToggled); + connect(this, &CheatWarningWidget::EmulationStarted, this, + &CheatWarningWidget::CheatEnableToggled); + connect(this, &CheatWarningWidget::EmulationStopped, this, + &CheatWarningWidget::CheatEnableToggled); +} + +void CheatWarningWidget::CreateWidgets() +{ + auto* icon = new QLabel; + + QPixmap warning_icon = style()->standardIcon(QStyle::SP_MessageBoxWarning).pixmap(24, 24); + + icon->setPixmap(warning_icon); + + m_text = new QLabel(); + m_config_button = new QPushButton(tr("Configure Dolphin")); + + m_config_button->setHidden(true); + + auto* layout = new QHBoxLayout; + + layout->addWidget(icon); + layout->addWidget(m_text); + layout->addWidget(m_config_button); + + setLayout(layout); +} + +void CheatWarningWidget::Update() +{ + bool cheats_enabled = SConfig::GetInstance().bEnableCheats; + + bool hide = true; + + if (Core::IsRunning() && SConfig::GetInstance().GetGameID() == m_game_id) + { + hide = false; + m_text->setText(tr("Changing cheats will only take effect when the game is restarted.")); + } + + if (!cheats_enabled) + { + hide = false; + m_text->setText(tr("Dolphin's cheat system is currently disabled.")); + } + + m_config_button->setHidden(hide); +} + +void CheatWarningWidget::ConnectWidgets() +{ + connect(m_config_button, &QPushButton::pressed, [this] { emit OpenCheatEnableSettings(); }); +} diff --git a/Source/Core/DolphinQt2/Config/CheatWarningWidget.h b/Source/Core/DolphinQt2/Config/CheatWarningWidget.h new file mode 100644 index 0000000000..77f8506824 --- /dev/null +++ b/Source/Core/DolphinQt2/Config/CheatWarningWidget.h @@ -0,0 +1,37 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include + +#include + +class QLabel; +class QPushButton; +class QTimer; + +class CheatWarningWidget : public QWidget +{ + Q_OBJECT +public: + explicit CheatWarningWidget(const std::string& game_id); + +signals: + void OpenCheatEnableSettings(); + void CheatEnableToggled(); + void EmulationStarted(); + void EmulationStopped(); + +private: + const std::string& m_game_id; + + void CreateWidgets(); + void ConnectWidgets(); + + void Update(); + + QLabel* m_text; + QPushButton* m_config_button; +}; From 5aecd61ede39efab8adfe228615da76176cfaaa5 Mon Sep 17 00:00:00 2001 From: spycrab Date: Wed, 30 Aug 2017 21:00:59 +0200 Subject: [PATCH 3/4] Qt/Settings: Implement cheat settings --- .../DolphinQt2/Config/CheatWarningWidget.cpp | 45 ++++++++++--------- .../DolphinQt2/Config/CheatWarningWidget.h | 7 +-- Source/Core/DolphinQt2/Settings.cpp | 14 ++++++ Source/Core/DolphinQt2/Settings.h | 5 +++ .../Core/DolphinQt2/Settings/GeneralPane.cpp | 4 +- 5 files changed, 47 insertions(+), 28 deletions(-) diff --git a/Source/Core/DolphinQt2/Config/CheatWarningWidget.cpp b/Source/Core/DolphinQt2/Config/CheatWarningWidget.cpp index c47bb93bd4..b365e3048b 100644 --- a/Source/Core/DolphinQt2/Config/CheatWarningWidget.cpp +++ b/Source/Core/DolphinQt2/Config/CheatWarningWidget.cpp @@ -6,35 +6,34 @@ #include #include -#include #include #include #include -#include #include "Core/ConfigManager.h" #include "Core/Core.h" +#include "DolphinQt2/Settings.h" CheatWarningWidget::CheatWarningWidget(const std::string& game_id) : m_game_id(game_id) { CreateWidgets(); ConnectWidgets(); - setHidden(true); + connect(&Settings::Instance(), &Settings::EnableCheatsChanged, + [this] { Update(Core::IsRunning()); }); + connect(this, &CheatWarningWidget::EmulationStarted, [this] { Update(true); }); + connect(this, &CheatWarningWidget::EmulationStopped, [this] { Update(false); }); - connect(this, &CheatWarningWidget::CheatEnableToggled, this, - &CheatWarningWidget::CheatEnableToggled); - connect(this, &CheatWarningWidget::EmulationStarted, this, - &CheatWarningWidget::CheatEnableToggled); - connect(this, &CheatWarningWidget::EmulationStopped, this, - &CheatWarningWidget::CheatEnableToggled); + Update(Core::IsRunning()); } void CheatWarningWidget::CreateWidgets() { auto* icon = new QLabel; - QPixmap warning_icon = style()->standardIcon(QStyle::SP_MessageBoxWarning).pixmap(24, 24); + const auto size = 1.5 * QFontMetrics(font()).height(); + + QPixmap warning_icon = style()->standardIcon(QStyle::SP_MessageBoxWarning).pixmap(size, size); icon->setPixmap(warning_icon); @@ -46,34 +45,38 @@ void CheatWarningWidget::CreateWidgets() auto* layout = new QHBoxLayout; layout->addWidget(icon); - layout->addWidget(m_text); + layout->addWidget(m_text, 1); layout->addWidget(m_config_button); + layout->setContentsMargins(0, 0, 0, 0); + setLayout(layout); } -void CheatWarningWidget::Update() +void CheatWarningWidget::Update(bool running) { - bool cheats_enabled = SConfig::GetInstance().bEnableCheats; + bool hide_widget = true; + bool hide_config_button = true; - bool hide = true; - - if (Core::IsRunning() && SConfig::GetInstance().GetGameID() == m_game_id) + if (running && SConfig::GetInstance().GetGameID() == m_game_id) { - hide = false; + hide_widget = false; m_text->setText(tr("Changing cheats will only take effect when the game is restarted.")); } - if (!cheats_enabled) + if (!Settings::Instance().GetCheatsEnabled()) { - hide = false; + hide_widget = false; + hide_config_button = false; m_text->setText(tr("Dolphin's cheat system is currently disabled.")); } - m_config_button->setHidden(hide); + setHidden(hide_widget); + m_config_button->setHidden(hide_config_button); } void CheatWarningWidget::ConnectWidgets() { - connect(m_config_button, &QPushButton::pressed, [this] { emit OpenCheatEnableSettings(); }); + connect(m_config_button, &QPushButton::pressed, this, + &CheatWarningWidget::OpenCheatEnableSettings); } diff --git a/Source/Core/DolphinQt2/Config/CheatWarningWidget.h b/Source/Core/DolphinQt2/Config/CheatWarningWidget.h index 77f8506824..15b3334620 100644 --- a/Source/Core/DolphinQt2/Config/CheatWarningWidget.h +++ b/Source/Core/DolphinQt2/Config/CheatWarningWidget.h @@ -10,7 +10,6 @@ class QLabel; class QPushButton; -class QTimer; class CheatWarningWidget : public QWidget { @@ -20,18 +19,16 @@ public: signals: void OpenCheatEnableSettings(); - void CheatEnableToggled(); void EmulationStarted(); void EmulationStopped(); private: - const std::string& m_game_id; - void CreateWidgets(); void ConnectWidgets(); - void Update(); + void Update(bool running); QLabel* m_text; QPushButton* m_config_button; + const std::string m_game_id; }; diff --git a/Source/Core/DolphinQt2/Settings.cpp b/Source/Core/DolphinQt2/Settings.cpp index fbc283c267..7e5a16c6e8 100644 --- a/Source/Core/DolphinQt2/Settings.cpp +++ b/Source/Core/DolphinQt2/Settings.cpp @@ -203,3 +203,17 @@ void Settings::ResetNetPlayServer(NetPlayServer* server) { m_server.reset(server); } + +bool Settings::GetCheatsEnabled() const +{ + return SConfig::GetInstance().bEnableCheats; +} + +void Settings::SetCheatsEnabled(bool enabled) +{ + if (SConfig::GetInstance().bEnableCheats != enabled) + { + SConfig::GetInstance().bEnableCheats = enabled; + emit EnableCheatsChanged(enabled); + } +} diff --git a/Source/Core/DolphinQt2/Settings.h b/Source/Core/DolphinQt2/Settings.h index 4de0b88be6..42964ec0fd 100644 --- a/Source/Core/DolphinQt2/Settings.h +++ b/Source/Core/DolphinQt2/Settings.h @@ -77,6 +77,10 @@ public: NetPlayServer* GetNetPlayServer(); void ResetNetPlayServer(NetPlayServer* server = nullptr); + // Cheats + bool GetCheatsEnabled() const; + void SetCheatsEnabled(bool enabled); + // Other GameListModel* GetGameListModel() const; @@ -90,6 +94,7 @@ signals: void NANDRefresh(); void LogVisibilityChanged(bool visible); void LogConfigVisibilityChanged(bool visible); + void EnableCheatsChanged(bool enabled); private: std::unique_ptr m_client; diff --git a/Source/Core/DolphinQt2/Settings/GeneralPane.cpp b/Source/Core/DolphinQt2/Settings/GeneralPane.cpp index 9e092f4668..a89ecfe65d 100644 --- a/Source/Core/DolphinQt2/Settings/GeneralPane.cpp +++ b/Source/Core/DolphinQt2/Settings/GeneralPane.cpp @@ -145,7 +145,7 @@ void GeneralPane::LoadConfig() m_checkbox_enable_analytics->setChecked(SConfig::GetInstance().m_analytics_enabled); #endif m_checkbox_dualcore->setChecked(SConfig::GetInstance().bCPUThread); - m_checkbox_cheats->setChecked(SConfig::GetInstance().bEnableCheats); + m_checkbox_cheats->setChecked(Settings::Instance().GetCheatsEnabled()); int selection = qRound(SConfig::GetInstance().m_EmulationSpeed * 10); if (selection < m_combobox_speedlimit->count()) m_combobox_speedlimit->setCurrentIndex(selection); @@ -177,7 +177,7 @@ void GeneralPane::OnSaveConfig() SConfig::GetInstance().m_analytics_enabled = m_checkbox_enable_analytics->isChecked(); #endif SConfig::GetInstance().bCPUThread = m_checkbox_dualcore->isChecked(); - SConfig::GetInstance().bEnableCheats = m_checkbox_cheats->isChecked(); + Settings::Instance().SetCheatsEnabled(m_checkbox_cheats->isChecked()); SConfig::GetInstance().m_EmulationSpeed = m_combobox_speedlimit->currentIndex() * 0.1f; int engine_value = 0; if (m_radio_interpreter->isChecked()) From f90e81b9db0f6e6359b135057ca7b2d11cef0293 Mon Sep 17 00:00:00 2001 From: spycrab Date: Sun, 10 Sep 2017 19:10:45 +0200 Subject: [PATCH 4/4] Qt/Properties: Implement "Gecko codes" tab --- Source/Core/DolphinQt2/CMakeLists.txt | 2 + .../DolphinQt2/Config/CheatWarningWidget.cpp | 8 +- .../DolphinQt2/Config/CheatWarningWidget.h | 2 - .../DolphinQt2/Config/GeckoCodeWidget.cpp | 207 ++++++++++++++++++ .../Core/DolphinQt2/Config/GeckoCodeWidget.h | 54 +++++ .../DolphinQt2/Config/PropertiesDialog.cpp | 8 + .../Core/DolphinQt2/Config/PropertiesDialog.h | 3 + Source/Core/DolphinQt2/DolphinQt2.vcxproj | 12 +- Source/Core/DolphinQt2/GameList/GameList.cpp | 3 + Source/Core/DolphinQt2/GameList/GameList.h | 1 + Source/Core/DolphinQt2/MainWindow.cpp | 8 + Source/Core/DolphinQt2/MainWindow.h | 1 + 12 files changed, 302 insertions(+), 7 deletions(-) create mode 100644 Source/Core/DolphinQt2/Config/GeckoCodeWidget.cpp create mode 100644 Source/Core/DolphinQt2/Config/GeckoCodeWidget.h diff --git a/Source/Core/DolphinQt2/CMakeLists.txt b/Source/Core/DolphinQt2/CMakeLists.txt index 73fd776468..dae253410a 100644 --- a/Source/Core/DolphinQt2/CMakeLists.txt +++ b/Source/Core/DolphinQt2/CMakeLists.txt @@ -31,8 +31,10 @@ set(SRCS Translation.cpp WiiUpdate.cpp WiiUpdate.h + Config/CheatWarningWidget.cpp Config/ControllersWindow.cpp Config/FilesystemWidget.cpp + Config/GeckoCodeWidget.cpp Config/Graphics/AdvancedWidget.cpp Config/Graphics/EnhancementsWidget.cpp Config/Graphics/GeneralWidget.cpp diff --git a/Source/Core/DolphinQt2/Config/CheatWarningWidget.cpp b/Source/Core/DolphinQt2/Config/CheatWarningWidget.cpp index b365e3048b..85acbfc9bb 100644 --- a/Source/Core/DolphinQt2/Config/CheatWarningWidget.cpp +++ b/Source/Core/DolphinQt2/Config/CheatWarningWidget.cpp @@ -10,6 +10,8 @@ #include #include +#include + #include "Core/ConfigManager.h" #include "Core/Core.h" #include "DolphinQt2/Settings.h" @@ -21,8 +23,10 @@ CheatWarningWidget::CheatWarningWidget(const std::string& game_id) : m_game_id(g connect(&Settings::Instance(), &Settings::EnableCheatsChanged, [this] { Update(Core::IsRunning()); }); - connect(this, &CheatWarningWidget::EmulationStarted, [this] { Update(true); }); - connect(this, &CheatWarningWidget::EmulationStopped, [this] { Update(false); }); + connect(&Settings::Instance(), &Settings::EmulationStateChanged, [this](Core::State state) { + std::cout << (state == Core::State::Running) << std::endl; + Update(state == Core::State::Running); + }); Update(Core::IsRunning()); } diff --git a/Source/Core/DolphinQt2/Config/CheatWarningWidget.h b/Source/Core/DolphinQt2/Config/CheatWarningWidget.h index 15b3334620..25e93e3b26 100644 --- a/Source/Core/DolphinQt2/Config/CheatWarningWidget.h +++ b/Source/Core/DolphinQt2/Config/CheatWarningWidget.h @@ -19,8 +19,6 @@ public: signals: void OpenCheatEnableSettings(); - void EmulationStarted(); - void EmulationStopped(); private: void CreateWidgets(); diff --git a/Source/Core/DolphinQt2/Config/GeckoCodeWidget.cpp b/Source/Core/DolphinQt2/Config/GeckoCodeWidget.cpp new file mode 100644 index 0000000000..ddb31b138b --- /dev/null +++ b/Source/Core/DolphinQt2/Config/GeckoCodeWidget.cpp @@ -0,0 +1,207 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "DolphinQt2/Config/GeckoCodeWidget.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "Common/FileUtil.h" +#include "Common/IniFile.h" +#include "Core/ConfigManager.h" +#include "Core/GeckoCodeConfig.h" +#include "DolphinQt2/Config/CheatWarningWidget.h" +#include "DolphinQt2/GameList/GameFile.h" + +GeckoCodeWidget::GeckoCodeWidget(const GameFile& game) + : m_game(game), m_game_id(game.GetGameID().toStdString()), m_game_revision(game.GetRevision()) +{ + CreateWidgets(); + ConnectWidgets(); + + IniFile game_ini_local; + + // We don't use LoadLocalGameIni() here because user cheat codes that are installed via the UI + // will always be stored in GS/${GAMEID}.ini + game_ini_local.Load(File::GetUserPath(D_GAMESETTINGS_IDX) + m_game_id + ".ini"); + + IniFile game_ini_default = SConfig::GetInstance().LoadDefaultGameIni(m_game_id, m_game_revision); + m_gecko_codes = Gecko::LoadCodes(game_ini_default, game_ini_local); + + UpdateList(); +} + +void GeckoCodeWidget::CreateWidgets() +{ + m_warning = new CheatWarningWidget(m_game_id); + m_code_list = new QListWidget; + m_name_label = new QLabel; + m_creator_label = new QLabel; + + QFont monospace(QFontDatabase::systemFont(QFontDatabase::FixedFont).family()); + + const auto line_height = QFontMetrics(font()).lineSpacing(); + + m_code_description = new QTextEdit; + m_code_description->setFont(monospace); + m_code_description->setReadOnly(true); + m_code_description->setFixedHeight(line_height * 5); + + m_code_view = new QTextEdit; + m_code_view->setFont(monospace); + m_code_view->setReadOnly(true); + m_code_view->setFixedHeight(line_height * 10); + + m_download_codes = new QPushButton(tr("Download Codes (WiiRD Database)")); + m_download_codes->setEnabled(!m_game_id.empty()); + m_download_codes->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + + auto* layout = new QVBoxLayout; + + layout->addWidget(m_warning); + layout->addWidget(m_code_list); + + auto* info_layout = new QFormLayout; + + info_layout->addRow(tr("Name:"), m_name_label); + info_layout->addRow(tr("Creator:"), m_creator_label); + info_layout->addRow(tr("Description:"), static_cast(nullptr)); + + info_layout->setFormAlignment(Qt::AlignLeft | Qt::AlignTop); + + for (QLabel* label : {m_name_label, m_creator_label}) + { + label->setTextInteractionFlags(Qt::TextSelectableByMouse); + label->setCursor(Qt::IBeamCursor); + } + + layout->addLayout(info_layout); + layout->addWidget(m_code_description); + layout->addWidget(m_code_view); + layout->addWidget(m_download_codes, 0, Qt::AlignRight); + + setLayout(layout); +} + +void GeckoCodeWidget::ConnectWidgets() +{ + connect(m_code_list, &QListWidget::itemSelectionChanged, this, + &GeckoCodeWidget::OnSelectionChanged); + connect(m_code_list, &QListWidget::itemChanged, this, &GeckoCodeWidget::OnItemChanged); + + connect(m_download_codes, &QPushButton::pressed, this, &GeckoCodeWidget::DownloadCodes); + + connect(m_warning, &CheatWarningWidget::OpenCheatEnableSettings, this, + &GeckoCodeWidget::OpenGeneralSettings); +} + +void GeckoCodeWidget::OnSelectionChanged() +{ + auto items = m_code_list->selectedItems(); + + if (items.empty()) + return; + + auto selected = items[0]; + + const auto& code = m_gecko_codes[m_code_list->row(selected)]; + + m_name_label->setText(QString::fromStdString(code.name)); + m_creator_label->setText(QString::fromStdString(code.creator)); + + m_code_description->clear(); + + if (code.notes.empty()) + m_code_description->append(tr("N/A")); + + for (const auto& line : code.notes) + m_code_description->append(QString::fromStdString(line)); + + m_code_view->clear(); + + for (const auto& c : code.codes) + m_code_view->append(QStringLiteral("%1 %2") + .arg(c.address, 8, 16, QLatin1Char('0')) + .arg(c.data, 8, 16, QLatin1Char('0'))); +} + +void GeckoCodeWidget::OnItemChanged(QListWidgetItem* item) +{ + m_gecko_codes[m_code_list->row(item)].enabled = (item->checkState() == Qt::Checked); + + SaveCodes(); +} + +void GeckoCodeWidget::SaveCodes() +{ + IniFile game_ini_local; + game_ini_local.Load(File::GetUserPath(D_GAMESETTINGS_IDX) + m_game_id + ".ini"); + Gecko::SaveCodes(game_ini_local, m_gecko_codes); + + game_ini_local.Save(File::GetUserPath(D_GAMESETTINGS_IDX) + m_game_id + ".ini"); +} + +void GeckoCodeWidget::UpdateList() +{ + m_code_list->clear(); + + for (size_t i = 0; i < m_gecko_codes.size(); i++) + { + const auto& code = m_gecko_codes[i]; + + auto* item = new QListWidgetItem(QString::fromStdString(code.name) + .replace(QStringLiteral("<"), QStringLiteral("<")) + .replace(QStringLiteral(">"), QStringLiteral(">"))); + + item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable); + item->setCheckState(code.enabled ? Qt::Checked : Qt::Unchecked); + + m_code_list->addItem(item); + } +} + +void GeckoCodeWidget::DownloadCodes() +{ + bool success; + + std::vector codes = Gecko::DownloadCodes(m_game_id, &success); + + if (!success) + { + QMessageBox::critical(this, tr("Error"), tr("Failed to download codes.")); + return; + } + + if (codes.empty()) + { + QMessageBox::critical(this, tr("Error"), tr("File contained no codes.")); + return; + } + + size_t added_count = 0; + + for (const auto& code : codes) + { + auto it = std::find(m_gecko_codes.begin(), m_gecko_codes.end(), code); + + if (it == m_gecko_codes.end()) + { + m_gecko_codes.push_back(code); + added_count++; + } + } + + UpdateList(); + SaveCodes(); + + QMessageBox::information(this, tr("Download complete"), + tr("Downloaded %1 codes. (added %2)") + .arg(QString::number(codes.size()), QString::number(added_count))); +} diff --git a/Source/Core/DolphinQt2/Config/GeckoCodeWidget.h b/Source/Core/DolphinQt2/Config/GeckoCodeWidget.h new file mode 100644 index 0000000000..877090b367 --- /dev/null +++ b/Source/Core/DolphinQt2/Config/GeckoCodeWidget.h @@ -0,0 +1,54 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include + +#include +#include + +#include "Common/CommonTypes.h" +#include "Core/GeckoCode.h" + +class CheatWarningWidget; +class GameFile; +class QLabel; +class QListWidget; +class QListWidgetItem; +class QTextEdit; +class QPushButton; + +class GeckoCodeWidget : public QWidget +{ + Q_OBJECT +public: + explicit GeckoCodeWidget(const GameFile& game); + +signals: + void OpenGeneralSettings(); + +private: + void OnSelectionChanged(); + void OnItemChanged(QListWidgetItem* item); + + void CreateWidgets(); + void ConnectWidgets(); + void UpdateList(); + void DownloadCodes(); + void SaveCodes(); + + const GameFile& m_game; + std::string m_game_id; + u8 m_game_revision; + + CheatWarningWidget* m_warning; + QListWidget* m_code_list; + QLabel* m_name_label; + QLabel* m_creator_label; + QTextEdit* m_code_description; + QTextEdit* m_code_view; + QPushButton* m_download_codes; + std::vector m_gecko_codes; +}; diff --git a/Source/Core/DolphinQt2/Config/PropertiesDialog.cpp b/Source/Core/DolphinQt2/Config/PropertiesDialog.cpp index 3ab91deff8..d8c464f07c 100644 --- a/Source/Core/DolphinQt2/Config/PropertiesDialog.cpp +++ b/Source/Core/DolphinQt2/Config/PropertiesDialog.cpp @@ -7,6 +7,7 @@ #include #include "DolphinQt2/Config/FilesystemWidget.h" +#include "DolphinQt2/Config/GeckoCodeWidget.h" #include "DolphinQt2/Config/InfoWidget.h" #include "DolphinQt2/Config/PropertiesDialog.h" @@ -18,7 +19,14 @@ PropertiesDialog::PropertiesDialog(QWidget* parent, const GameFile& game) : QDia QTabWidget* tab_widget = new QTabWidget(this); InfoWidget* info = new InfoWidget(game); + + GeckoCodeWidget* gecko = new GeckoCodeWidget(game); + + connect(gecko, &GeckoCodeWidget::OpenGeneralSettings, this, + &PropertiesDialog::OpenGeneralSettings); + tab_widget->addTab(info, tr("Info")); + tab_widget->addTab(gecko, tr("Gecko Codes")); if (DiscIO::IsDisc(game.GetPlatformID())) { diff --git a/Source/Core/DolphinQt2/Config/PropertiesDialog.h b/Source/Core/DolphinQt2/Config/PropertiesDialog.h index f640f4e536..85f1ef64f5 100644 --- a/Source/Core/DolphinQt2/Config/PropertiesDialog.h +++ b/Source/Core/DolphinQt2/Config/PropertiesDialog.h @@ -13,4 +13,7 @@ class PropertiesDialog final : public QDialog Q_OBJECT public: explicit PropertiesDialog(QWidget* parent, const GameFile& game); + +signals: + void OpenGeneralSettings(); }; diff --git a/Source/Core/DolphinQt2/DolphinQt2.vcxproj b/Source/Core/DolphinQt2/DolphinQt2.vcxproj index be07c59b2a..bfd4dcb868 100644 --- a/Source/Core/DolphinQt2/DolphinQt2.vcxproj +++ b/Source/Core/DolphinQt2/DolphinQt2.vcxproj @@ -60,8 +60,10 @@ + + @@ -111,14 +113,16 @@ - + + + @@ -154,8 +158,10 @@ + + @@ -226,8 +232,8 @@ - - + + diff --git a/Source/Core/DolphinQt2/GameList/GameList.cpp b/Source/Core/DolphinQt2/GameList/GameList.cpp index df4e9d161c..7588bd12b4 100644 --- a/Source/Core/DolphinQt2/GameList/GameList.cpp +++ b/Source/Core/DolphinQt2/GameList/GameList.cpp @@ -239,6 +239,9 @@ void GameList::ShowContextMenu(const QPoint&) void GameList::OpenProperties() { PropertiesDialog* properties = new PropertiesDialog(this, *GetSelectedGame()); + + connect(properties, &PropertiesDialog::OpenGeneralSettings, this, &GameList::OpenGeneralSettings); + properties->show(); } diff --git a/Source/Core/DolphinQt2/GameList/GameList.h b/Source/Core/DolphinQt2/GameList/GameList.h index 75103a42fd..fb564cde92 100644 --- a/Source/Core/DolphinQt2/GameList/GameList.h +++ b/Source/Core/DolphinQt2/GameList/GameList.h @@ -31,6 +31,7 @@ signals: void GameSelected(); void NetPlayHost(const QString& game_id); void SelectionChanged(QSharedPointer game_file); + void OpenGeneralSettings(); private: void ShowContextMenu(const QPoint&); diff --git a/Source/Core/DolphinQt2/MainWindow.cpp b/Source/Core/DolphinQt2/MainWindow.cpp index a55b5b94b2..bfa3aff851 100644 --- a/Source/Core/DolphinQt2/MainWindow.cpp +++ b/Source/Core/DolphinQt2/MainWindow.cpp @@ -279,6 +279,8 @@ void MainWindow::ConnectGameList() { connect(m_game_list, &GameList::GameSelected, this, &MainWindow::Play); connect(m_game_list, &GameList::NetPlayHost, this, &MainWindow::NetPlayHost); + + connect(m_game_list, &GameList::OpenGeneralSettings, this, &MainWindow::ShowGeneralWindow); } void MainWindow::ConnectRenderWidget() @@ -551,6 +553,12 @@ void MainWindow::ShowAudioWindow() ShowSettingsWindow(); } +void MainWindow::ShowGeneralWindow() +{ + m_settings_window->SelectGeneralPane(); + ShowSettingsWindow(); +} + void MainWindow::ShowAboutDialog() { AboutDialog* about = new AboutDialog(this); diff --git a/Source/Core/DolphinQt2/MainWindow.h b/Source/Core/DolphinQt2/MainWindow.h index 84a2f04de6..93d5431334 100644 --- a/Source/Core/DolphinQt2/MainWindow.h +++ b/Source/Core/DolphinQt2/MainWindow.h @@ -91,6 +91,7 @@ private: void HideRenderWidget(); void ShowSettingsWindow(); + void ShowGeneralWindow(); void ShowAudioWindow(); void ShowControllersWindow(); void ShowGraphicsWindow();