Merge pull request #6650 from spycrab/qt_cheatmanager

Qt: Implement Cheats Manager
This commit is contained in:
Anthony
2018-04-19 21:47:54 +01:00
committed by GitHub
14 changed files with 813 additions and 13 deletions
+1
View File
@@ -7,6 +7,7 @@ set(CMAKE_AUTOMOC ON)
add_executable(dolphin-emu-qt2
AboutDialog.cpp
CheatsManager.cpp
FIFOPlayerWindow.cpp
HotkeyScheduler.cpp
Host.cpp
File diff suppressed because it is too large Load Diff
+117
View File
@@ -0,0 +1,117 @@
// Copyright 2018 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <memory>
#include <vector>
#include <QDialog>
#include <QString>
#include "Common/CommonTypes.h"
class ARCodeWidget;
class QComboBox;
class QDialogButtonBox;
class QLineEdit;
class QPushButton;
class QRadioButton;
class QSplitter;
class QTabWidget;
class QTableWidget;
class QTableWidgetItem;
class QLabel;
namespace UICommon
{
class GameFile;
}
namespace Core
{
enum class State;
}
enum class CompareType : int
{
Equal = 0,
NotEqual = 1,
Less = 2,
LessEqual = 3,
More = 4,
MoreEqual = 5
};
enum class DataType : int
{
Byte = 0,
Short = 1,
Int = 2,
Float = 3,
Double = 4,
String = 5
};
struct Result
{
u32 address;
DataType type;
QString name;
bool locked = false;
u32 locked_value;
};
class CheatsManager : public QDialog
{
Q_OBJECT
public:
explicit CheatsManager(QWidget* parent = nullptr);
private:
QWidget* CreateCheatSearch();
void CreateWidgets();
void ConnectWidgets();
void OnStateChanged(Core::State state);
size_t GetTypeSize() const;
bool MatchesSearch(u32 addr) const;
void Reset();
void NewSearch();
void NextSearch();
void Update();
void GenerateARCode();
void OnWatchContextMenu();
void OnMatchContextMenu();
void OnWatchItemChanged(QTableWidgetItem* item);
std::vector<Result> m_results;
std::vector<Result> m_watch;
std::shared_ptr<const UICommon::GameFile> m_game_file;
QDialogButtonBox* m_button_box;
QTabWidget* m_tab_widget = nullptr;
QWidget* m_cheat_search;
ARCodeWidget* m_ar_code = nullptr;
QLabel* m_result_label;
QTableWidget* m_match_table;
QTableWidget* m_watch_table;
QSplitter* m_option_splitter;
QSplitter* m_table_splitter;
QComboBox* m_match_length;
QComboBox* m_match_operation;
QLineEdit* m_match_value;
QPushButton* m_match_new;
QPushButton* m_match_next;
QPushButton* m_match_refresh;
QPushButton* m_match_reset;
QRadioButton* m_match_decimal;
QRadioButton* m_match_hexadecimal;
QRadioButton* m_match_octal;
bool m_updating = false;
};
+16 -3
View File
@@ -18,8 +18,9 @@
#include "DolphinQt2/Config/CheatWarningWidget.h"
#include "UICommon/GameFile.h"
ARCodeWidget::ARCodeWidget(const UICommon::GameFile& game)
: m_game(game), m_game_id(game.GetGameID()), m_game_revision(game.GetRevision())
ARCodeWidget::ARCodeWidget(const UICommon::GameFile& game, bool restart_required)
: m_game(game), m_game_id(game.GetGameID()), m_game_revision(game.GetRevision()),
m_restart_required(restart_required)
{
CreateWidgets();
ConnectWidgets();
@@ -39,7 +40,7 @@ ARCodeWidget::ARCodeWidget(const UICommon::GameFile& game)
void ARCodeWidget::CreateWidgets()
{
m_warning = new CheatWarningWidget(m_game_id);
m_warning = new CheatWarningWidget(m_game_id, m_restart_required);
m_code_list = new QListWidget;
m_code_add = new QPushButton(tr("&Add New Code..."));
m_code_edit = new QPushButton(tr("&Edit Code..."));
@@ -75,6 +76,10 @@ void ARCodeWidget::ConnectWidgets()
void ARCodeWidget::OnItemChanged(QListWidgetItem* item)
{
m_ar_codes[m_code_list->row(item)].active = (item->checkState() == Qt::Checked);
if (!m_restart_required)
ActionReplay::ApplyCodes(m_ar_codes);
SaveCodes();
}
@@ -119,6 +124,14 @@ void ARCodeWidget::SaveCodes()
game_ini_local.Save(File::GetUserPath(D_GAMESETTINGS_IDX) + m_game_id + ".ini");
}
void ARCodeWidget::AddCode(ActionReplay::ARCode code)
{
m_ar_codes.push_back(std::move(code));
UpdateList();
SaveCodes();
}
void ARCodeWidget::OnCodeAddPressed()
{
ActionReplay::ARCode ar;
+4 -1
View File
@@ -27,7 +27,9 @@ class ARCodeWidget : public QWidget
{
Q_OBJECT
public:
explicit ARCodeWidget(const UICommon::GameFile& game);
explicit ARCodeWidget(const UICommon::GameFile& game, bool restart_required = true);
void AddCode(ActionReplay::ARCode code);
signals:
void OpenGeneralSettings();
@@ -56,4 +58,5 @@ private:
QPushButton* m_code_remove;
std::vector<ActionReplay::ARCode> m_ar_codes;
bool m_restart_required;
};
@@ -14,14 +14,15 @@
#include "Core/Core.h"
#include "DolphinQt2/Settings.h"
CheatWarningWidget::CheatWarningWidget(const std::string& game_id) : m_game_id(game_id)
CheatWarningWidget::CheatWarningWidget(const std::string& game_id, bool restart_required)
: m_game_id(game_id), m_restart_required(restart_required)
{
CreateWidgets();
ConnectWidgets();
connect(&Settings::Instance(), &Settings::EnableCheatsChanged,
connect(&Settings::Instance(), &Settings::EnableCheatsChanged, this,
[this] { Update(Core::IsRunning()); });
connect(&Settings::Instance(), &Settings::EmulationStateChanged,
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this,
[this](Core::State state) { Update(state == Core::State::Running); });
Update(Core::IsRunning());
@@ -58,7 +59,7 @@ void CheatWarningWidget::Update(bool running)
bool hide_widget = true;
bool hide_config_button = true;
if (running && SConfig::GetInstance().GetGameID() == m_game_id)
if (running && SConfig::GetInstance().GetGameID() == m_game_id && m_restart_required)
{
hide_widget = false;
m_text->setText(tr("Changing cheats will only take effect when the game is restarted."));
@@ -15,7 +15,7 @@ class CheatWarningWidget : public QWidget
{
Q_OBJECT
public:
explicit CheatWarningWidget(const std::string& game_id);
explicit CheatWarningWidget(const std::string& game_id, bool restart_required);
signals:
void OpenCheatEnableSettings();
@@ -29,4 +29,5 @@ private:
QLabel* m_text;
QPushButton* m_config_button;
const std::string m_game_id;
bool m_restart_required;
};
@@ -22,8 +22,9 @@
#include "DolphinQt2/Config/CheatWarningWidget.h"
#include "UICommon/GameFile.h"
GeckoCodeWidget::GeckoCodeWidget(const UICommon::GameFile& game)
: m_game(game), m_game_id(game.GetGameID()), m_game_revision(game.GetRevision())
GeckoCodeWidget::GeckoCodeWidget(const UICommon::GameFile& game, bool restart_required)
: m_game(game), m_game_id(game.GetGameID()), m_game_revision(game.GetRevision()),
m_restart_required(restart_required)
{
CreateWidgets();
ConnectWidgets();
@@ -42,7 +43,7 @@ GeckoCodeWidget::GeckoCodeWidget(const UICommon::GameFile& game)
void GeckoCodeWidget::CreateWidgets()
{
m_warning = new CheatWarningWidget(m_game_id);
m_warning = new CheatWarningWidget(m_game_id, m_restart_required);
m_code_list = new QListWidget;
m_name_label = new QLabel;
m_creator_label = new QLabel;
@@ -155,6 +156,9 @@ void GeckoCodeWidget::OnItemChanged(QListWidgetItem* item)
{
m_gecko_codes[m_code_list->row(item)].enabled = (item->checkState() == Qt::Checked);
if (!m_restart_required)
Gecko::SetActiveCodes(m_gecko_codes);
SaveCodes();
}
@@ -28,7 +28,7 @@ class GeckoCodeWidget : public QWidget
{
Q_OBJECT
public:
explicit GeckoCodeWidget(const UICommon::GameFile& game);
explicit GeckoCodeWidget(const UICommon::GameFile& game, bool restart_required = true);
signals:
void OpenGeneralSettings();
@@ -62,4 +62,5 @@ private:
QPushButton* m_remove_code;
QPushButton* m_download_codes;
std::vector<Gecko::GeckoCode> m_gecko_codes;
bool m_restart_required;
};
@@ -60,6 +60,7 @@
<!--NOTE: When adding moc'd files, you must list outputs in the ClCompile ItemGroup too!-->
<ItemGroup>
<QtMoc Include="AboutDialog.h" />
<QtMoc Include="CheatsManager.h" />
<QtMoc Include="Config\CheatCodeEditor.h" />
<QtMoc Include="Config\ARCodeWidget.h" />
<QtMoc Include="Config\CheatWarningWidget.h" />
@@ -141,6 +142,7 @@
<ClCompile Include="$(QtMocOutPrefix)AudioPane.cpp" />
<ClCompile Include="$(QtMocOutPrefix)AdvancedWidget.cpp" />
<ClCompile Include="$(QtMocOutPrefix)BreakpointWidget.cpp" />
<ClCompile Include="$(QtMocOutPrefix)CheatsManager.cpp" />
<ClCompile Include="$(QtMocOutPrefix)CheatWarningWidget.cpp" />
<ClCompile Include="$(QtMocOutPrefix)CodeViewWidget.cpp" />
<ClCompile Include="$(QtMocOutPrefix)CodeWidget.cpp" />
@@ -205,6 +207,7 @@
<ClCompile Include="$(QtMocOutPrefix)USBDeviceAddToWhitelistDialog.cpp" />
<ClCompile Include="$(QtMocOutPrefix)Updater.cpp" />
<ClCompile Include="AboutDialog.cpp" />
<ClCompile Include="CheatsManager.cpp" />
<ClCompile Include="Config\CheatCodeEditor.cpp" />
<ClCompile Include="Config\ARCodeWidget.cpp" />
<ClCompile Include="Config\CheatWarningWidget.cpp" />
+8
View File
@@ -46,6 +46,7 @@
#include "DiscIO/NANDImporter.h"
#include "DolphinQt2/AboutDialog.h"
#include "DolphinQt2/CheatsManager.h"
#include "DolphinQt2/Config/ControllersWindow.h"
#include "DolphinQt2/Config/Graphics/GraphicsWindow.h"
#include "DolphinQt2/Config/LogConfigWidget.h"
@@ -204,6 +205,7 @@ void MainWindow::CreateComponents()
m_watch_widget = new WatchWidget(this);
m_breakpoint_widget = new BreakpointWidget(this);
m_code_widget = new CodeWidget(this);
m_cheats_manager = new CheatsManager(this);
connect(m_watch_widget, &WatchWidget::RequestMemoryBreakpoint,
[this](u32 addr) { m_breakpoint_widget->AddAddressMBP(addr); });
@@ -275,6 +277,7 @@ void MainWindow::ConnectMenuBar()
// Tools
connect(m_menu_bar, &MenuBar::ShowMemcardManager, this, &MainWindow::ShowMemcardManager);
connect(m_menu_bar, &MenuBar::ShowCheatsManager, this, &MainWindow::ShowCheatsManager);
connect(m_menu_bar, &MenuBar::BootGameCubeIPL, this, &MainWindow::OnBootGameCubeIPL);
connect(m_menu_bar, &MenuBar::ImportNANDBackup, this, &MainWindow::OnImportNANDBackup);
connect(m_menu_bar, &MenuBar::PerformOnlineUpdate, this, &MainWindow::PerformOnlineUpdate);
@@ -1233,6 +1236,11 @@ void MainWindow::ShowMemcardManager()
manager.exec();
}
void MainWindow::ShowCheatsManager()
{
m_cheats_manager->show();
}
void MainWindow::OnUpdateProgressDialog(QString title, int progress, int total)
{
if (!m_progress_dialog)
+3
View File
@@ -22,6 +22,7 @@ class QProgressDialog;
class BreakpointWidget;
struct BootParameters;
class CheatsManager;
class CodeWidget;
class ControllersWindow;
class DragEnterEvent;
@@ -121,6 +122,7 @@ private:
void ShowNetPlaySetupDialog();
void ShowFIFOPlayer();
void ShowMemcardManager();
void ShowCheatsManager();
void NetPlayInit();
bool NetPlayJoin();
@@ -188,4 +190,5 @@ private:
FIFOPlayerWindow* m_fifo_window;
RegisterWidget* m_register_widget;
WatchWidget* m_watch_widget;
CheatsManager* m_cheats_manager;
};
+10
View File
@@ -99,6 +99,9 @@ void MenuBar::OnEmulationStateChanged(Core::State state)
m_recording_stop->setEnabled(false);
m_recording_play->setEnabled(!running);
// Tools
m_show_cheat_manager->setEnabled(Settings::Instance().GetCheatsEnabled());
// Symbols
m_symbols->setEnabled(running);
@@ -167,6 +170,13 @@ void MenuBar::AddToolsMenu()
AddAction(tools_menu, tr("&Memory Card Manager (GC)"), this,
[this] { emit ShowMemcardManager(); });
m_show_cheat_manager =
AddAction(tools_menu, tr("&Cheats Manager"), this, [this] { emit ShowCheatsManager(); });
connect(&Settings::Instance(), &Settings::EnableCheatsChanged, [this](bool enabled) {
m_show_cheat_manager->setEnabled(Core::GetState() != Core::State::Uninitialized && enabled);
});
tools_menu->addSeparator();
AddAction(tools_menu, tr("Import Wii Save..."), this, &MenuBar::ImportWiiSave);
+2
View File
@@ -73,6 +73,7 @@ signals:
void BootGameCubeIPL(DiscIO::Region region);
void ShowFIFOPlayer();
void ShowAboutDialog();
void ShowCheatsManager();
void ConnectWiiRemote(int id);
// Options
@@ -157,6 +158,7 @@ private:
QMenu* m_backup_menu;
// Tools
QAction* m_show_cheat_manager;
QAction* m_wad_install_action;
QMenu* m_perform_online_update_menu;
QAction* m_perform_online_update_for_current_region;