mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-25 07:09:48 -06:00
Merge pull request #8212 from spycrab/ar_gecko_reorder
ActionReplay & GeckoCode reordering support
This commit is contained in:
@ -5,8 +5,10 @@
|
|||||||
#include "DolphinQt/Config/ARCodeWidget.h"
|
#include "DolphinQt/Config/ARCodeWidget.h"
|
||||||
|
|
||||||
#include <QButtonGroup>
|
#include <QButtonGroup>
|
||||||
|
#include <QCursor>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QListWidget>
|
#include <QListWidget>
|
||||||
|
#include <QMenu>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
@ -49,6 +51,8 @@ void ARCodeWidget::CreateWidgets()
|
|||||||
m_code_edit = new QPushButton(tr("&Edit Code..."));
|
m_code_edit = new QPushButton(tr("&Edit Code..."));
|
||||||
m_code_remove = new QPushButton(tr("&Remove Code"));
|
m_code_remove = new QPushButton(tr("&Remove Code"));
|
||||||
|
|
||||||
|
m_code_list->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
|
|
||||||
auto* button_layout = new QHBoxLayout;
|
auto* button_layout = new QHBoxLayout;
|
||||||
|
|
||||||
button_layout->addWidget(m_code_add);
|
button_layout->addWidget(m_code_add);
|
||||||
@ -68,8 +72,13 @@ void ARCodeWidget::ConnectWidgets()
|
|||||||
{
|
{
|
||||||
connect(m_warning, &CheatWarningWidget::OpenCheatEnableSettings, this,
|
connect(m_warning, &CheatWarningWidget::OpenCheatEnableSettings, this,
|
||||||
&ARCodeWidget::OpenGeneralSettings);
|
&ARCodeWidget::OpenGeneralSettings);
|
||||||
|
|
||||||
connect(m_code_list, &QListWidget::itemChanged, this, &ARCodeWidget::OnItemChanged);
|
connect(m_code_list, &QListWidget::itemChanged, this, &ARCodeWidget::OnItemChanged);
|
||||||
connect(m_code_list, &QListWidget::itemSelectionChanged, this, &ARCodeWidget::OnSelectionChanged);
|
connect(m_code_list, &QListWidget::itemSelectionChanged, this, &ARCodeWidget::OnSelectionChanged);
|
||||||
|
connect(m_code_list->model(), &QAbstractItemModel::rowsMoved, this,
|
||||||
|
&ARCodeWidget::OnListReordered);
|
||||||
|
connect(m_code_list, &QListWidget::customContextMenuRequested, this,
|
||||||
|
&ARCodeWidget::OnContextMenuRequested);
|
||||||
|
|
||||||
connect(m_code_add, &QPushButton::pressed, this, &ARCodeWidget::OnCodeAddPressed);
|
connect(m_code_add, &QPushButton::pressed, this, &ARCodeWidget::OnCodeAddPressed);
|
||||||
connect(m_code_edit, &QPushButton::pressed, this, &ARCodeWidget::OnCodeEditPressed);
|
connect(m_code_edit, &QPushButton::pressed, this, &ARCodeWidget::OnCodeEditPressed);
|
||||||
@ -83,6 +92,40 @@ void ARCodeWidget::OnItemChanged(QListWidgetItem* item)
|
|||||||
if (!m_restart_required)
|
if (!m_restart_required)
|
||||||
ActionReplay::ApplyCodes(m_ar_codes);
|
ActionReplay::ApplyCodes(m_ar_codes);
|
||||||
|
|
||||||
|
UpdateList();
|
||||||
|
SaveCodes();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ARCodeWidget::OnContextMenuRequested()
|
||||||
|
{
|
||||||
|
QMenu menu;
|
||||||
|
|
||||||
|
menu.addAction(tr("Sort Alphabetically"), this, &ARCodeWidget::SortAlphabetically);
|
||||||
|
|
||||||
|
menu.exec(QCursor::pos());
|
||||||
|
}
|
||||||
|
|
||||||
|
void ARCodeWidget::SortAlphabetically()
|
||||||
|
{
|
||||||
|
m_code_list->sortItems();
|
||||||
|
OnListReordered();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ARCodeWidget::OnListReordered()
|
||||||
|
{
|
||||||
|
// Reorder codes based on the indices of table item
|
||||||
|
std::vector<ActionReplay::ARCode> codes;
|
||||||
|
codes.reserve(m_ar_codes.size());
|
||||||
|
|
||||||
|
for (int i = 0; i < m_code_list->count(); i++)
|
||||||
|
{
|
||||||
|
const int index = m_code_list->item(i)->data(Qt::UserRole).toInt();
|
||||||
|
|
||||||
|
codes.push_back(std::move(m_ar_codes[index]));
|
||||||
|
}
|
||||||
|
|
||||||
|
m_ar_codes = std::move(codes);
|
||||||
|
|
||||||
SaveCodes();
|
SaveCodes();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,17 +148,22 @@ void ARCodeWidget::UpdateList()
|
|||||||
{
|
{
|
||||||
m_code_list->clear();
|
m_code_list->clear();
|
||||||
|
|
||||||
for (const auto& ar : m_ar_codes)
|
for (size_t i = 0; i < m_ar_codes.size(); i++)
|
||||||
{
|
{
|
||||||
|
const auto& ar = m_ar_codes[i];
|
||||||
auto* item = new QListWidgetItem(QString::fromStdString(ar.name)
|
auto* item = new QListWidgetItem(QString::fromStdString(ar.name)
|
||||||
.replace(QStringLiteral("<"), QStringLiteral("<"))
|
.replace(QStringLiteral("<"), QStringLiteral("<"))
|
||||||
.replace(QStringLiteral(">"), QStringLiteral(">")));
|
.replace(QStringLiteral(">"), QStringLiteral(">")));
|
||||||
|
|
||||||
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable);
|
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable |
|
||||||
|
Qt::ItemIsDragEnabled);
|
||||||
item->setCheckState(ar.active ? Qt::Checked : Qt::Unchecked);
|
item->setCheckState(ar.active ? Qt::Checked : Qt::Unchecked);
|
||||||
|
item->setData(Qt::UserRole, static_cast<int>(i));
|
||||||
|
|
||||||
m_code_list->addItem(item);
|
m_code_list->addItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_code_list->setDragDropMode(QAbstractItemView::InternalMove);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ARCodeWidget::SaveCodes()
|
void ARCodeWidget::SaveCodes()
|
||||||
|
@ -37,16 +37,20 @@ signals:
|
|||||||
private:
|
private:
|
||||||
void OnSelectionChanged();
|
void OnSelectionChanged();
|
||||||
void OnItemChanged(QListWidgetItem* item);
|
void OnItemChanged(QListWidgetItem* item);
|
||||||
|
void OnContextMenuRequested();
|
||||||
|
|
||||||
void CreateWidgets();
|
void CreateWidgets();
|
||||||
void ConnectWidgets();
|
void ConnectWidgets();
|
||||||
void UpdateList();
|
void UpdateList();
|
||||||
void SaveCodes();
|
void SaveCodes();
|
||||||
|
void SortAlphabetically();
|
||||||
|
|
||||||
void OnCodeAddPressed();
|
void OnCodeAddPressed();
|
||||||
void OnCodeEditPressed();
|
void OnCodeEditPressed();
|
||||||
void OnCodeRemovePressed();
|
void OnCodeRemovePressed();
|
||||||
|
|
||||||
|
void OnListReordered();
|
||||||
|
|
||||||
const UICommon::GameFile& m_game;
|
const UICommon::GameFile& m_game;
|
||||||
std::string m_game_id;
|
std::string m_game_id;
|
||||||
u16 m_game_revision;
|
u16 m_game_revision;
|
||||||
|
@ -4,11 +4,13 @@
|
|||||||
|
|
||||||
#include "DolphinQt/Config/GeckoCodeWidget.h"
|
#include "DolphinQt/Config/GeckoCodeWidget.h"
|
||||||
|
|
||||||
|
#include <QCursor>
|
||||||
#include <QFontDatabase>
|
#include <QFontDatabase>
|
||||||
#include <QFormLayout>
|
#include <QFormLayout>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QListWidget>
|
#include <QListWidget>
|
||||||
|
#include <QMenu>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QTextEdit>
|
#include <QTextEdit>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
@ -51,6 +53,8 @@ void GeckoCodeWidget::CreateWidgets()
|
|||||||
m_name_label = new QLabel;
|
m_name_label = new QLabel;
|
||||||
m_creator_label = new QLabel;
|
m_creator_label = new QLabel;
|
||||||
|
|
||||||
|
m_code_list->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
|
|
||||||
QFont monospace(QFontDatabase::systemFont(QFontDatabase::FixedFont).family());
|
QFont monospace(QFontDatabase::systemFont(QFontDatabase::FixedFont).family());
|
||||||
|
|
||||||
const auto line_height = QFontMetrics(font()).lineSpacing();
|
const auto line_height = QFontMetrics(font()).lineSpacing();
|
||||||
@ -116,12 +120,15 @@ void GeckoCodeWidget::ConnectWidgets()
|
|||||||
connect(m_code_list, &QListWidget::itemSelectionChanged, this,
|
connect(m_code_list, &QListWidget::itemSelectionChanged, this,
|
||||||
&GeckoCodeWidget::OnSelectionChanged);
|
&GeckoCodeWidget::OnSelectionChanged);
|
||||||
connect(m_code_list, &QListWidget::itemChanged, this, &GeckoCodeWidget::OnItemChanged);
|
connect(m_code_list, &QListWidget::itemChanged, this, &GeckoCodeWidget::OnItemChanged);
|
||||||
|
connect(m_code_list->model(), &QAbstractItemModel::rowsMoved, this,
|
||||||
|
&GeckoCodeWidget::OnListReordered);
|
||||||
|
connect(m_code_list, &QListWidget::customContextMenuRequested, this,
|
||||||
|
&GeckoCodeWidget::OnContextMenuRequested);
|
||||||
|
|
||||||
connect(m_add_code, &QPushButton::pressed, this, &GeckoCodeWidget::AddCode);
|
connect(m_add_code, &QPushButton::pressed, this, &GeckoCodeWidget::AddCode);
|
||||||
connect(m_remove_code, &QPushButton::pressed, this, &GeckoCodeWidget::RemoveCode);
|
connect(m_remove_code, &QPushButton::pressed, this, &GeckoCodeWidget::RemoveCode);
|
||||||
connect(m_edit_code, &QPushButton::pressed, this, &GeckoCodeWidget::EditCode);
|
connect(m_edit_code, &QPushButton::pressed, this, &GeckoCodeWidget::EditCode);
|
||||||
connect(m_download_codes, &QPushButton::pressed, this, &GeckoCodeWidget::DownloadCodes);
|
connect(m_download_codes, &QPushButton::pressed, this, &GeckoCodeWidget::DownloadCodes);
|
||||||
|
|
||||||
connect(m_warning, &CheatWarningWidget::OpenCheatEnableSettings, this,
|
connect(m_warning, &CheatWarningWidget::OpenCheatEnableSettings, this,
|
||||||
&GeckoCodeWidget::OpenGeneralSettings);
|
&GeckoCodeWidget::OpenGeneralSettings);
|
||||||
}
|
}
|
||||||
@ -130,8 +137,10 @@ void GeckoCodeWidget::OnSelectionChanged()
|
|||||||
{
|
{
|
||||||
auto items = m_code_list->selectedItems();
|
auto items = m_code_list->selectedItems();
|
||||||
|
|
||||||
m_edit_code->setEnabled(!items.empty());
|
const bool empty = items.empty();
|
||||||
m_remove_code->setEnabled(!items.empty());
|
|
||||||
|
m_edit_code->setEnabled(!empty);
|
||||||
|
m_remove_code->setEnabled(!empty);
|
||||||
|
|
||||||
if (items.empty())
|
if (items.empty())
|
||||||
return;
|
return;
|
||||||
@ -222,11 +231,46 @@ void GeckoCodeWidget::SaveCodes()
|
|||||||
{
|
{
|
||||||
IniFile game_ini_local;
|
IniFile game_ini_local;
|
||||||
game_ini_local.Load(File::GetUserPath(D_GAMESETTINGS_IDX) + m_game_id + ".ini");
|
game_ini_local.Load(File::GetUserPath(D_GAMESETTINGS_IDX) + m_game_id + ".ini");
|
||||||
|
|
||||||
Gecko::SaveCodes(game_ini_local, m_gecko_codes);
|
Gecko::SaveCodes(game_ini_local, m_gecko_codes);
|
||||||
|
|
||||||
game_ini_local.Save(File::GetUserPath(D_GAMESETTINGS_IDX) + m_game_id + ".ini");
|
game_ini_local.Save(File::GetUserPath(D_GAMESETTINGS_IDX) + m_game_id + ".ini");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GeckoCodeWidget::OnContextMenuRequested()
|
||||||
|
{
|
||||||
|
QMenu menu;
|
||||||
|
|
||||||
|
menu.addAction(tr("Sort Alphabetically"), this, &GeckoCodeWidget::SortAlphabetically);
|
||||||
|
|
||||||
|
menu.exec(QCursor::pos());
|
||||||
|
}
|
||||||
|
|
||||||
|
void GeckoCodeWidget::SortAlphabetically()
|
||||||
|
{
|
||||||
|
m_code_list->sortItems();
|
||||||
|
OnListReordered();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GeckoCodeWidget::OnListReordered()
|
||||||
|
{
|
||||||
|
// Reorder codes based on the indices of table item
|
||||||
|
std::vector<Gecko::GeckoCode> codes;
|
||||||
|
codes.reserve(m_gecko_codes.size());
|
||||||
|
|
||||||
|
for (int i = 0; i < m_code_list->count(); i++)
|
||||||
|
{
|
||||||
|
const int index = m_code_list->item(i)->data(Qt::UserRole).toInt();
|
||||||
|
|
||||||
|
codes.push_back(std::move(m_gecko_codes[index]));
|
||||||
|
}
|
||||||
|
|
||||||
|
m_gecko_codes = std::move(codes);
|
||||||
|
|
||||||
|
UpdateList();
|
||||||
|
SaveCodes();
|
||||||
|
}
|
||||||
|
|
||||||
void GeckoCodeWidget::UpdateList()
|
void GeckoCodeWidget::UpdateList()
|
||||||
{
|
{
|
||||||
m_code_list->clear();
|
m_code_list->clear();
|
||||||
@ -239,12 +283,15 @@ void GeckoCodeWidget::UpdateList()
|
|||||||
.replace(QStringLiteral("<"), QStringLiteral("<"))
|
.replace(QStringLiteral("<"), QStringLiteral("<"))
|
||||||
.replace(QStringLiteral(">"), QStringLiteral(">")));
|
.replace(QStringLiteral(">"), QStringLiteral(">")));
|
||||||
|
|
||||||
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable);
|
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable |
|
||||||
|
Qt::ItemIsDragEnabled);
|
||||||
item->setCheckState(code.enabled ? Qt::Checked : Qt::Unchecked);
|
item->setCheckState(code.enabled ? Qt::Checked : Qt::Unchecked);
|
||||||
item->setData(Qt::UserRole, static_cast<int>(i));
|
item->setData(Qt::UserRole, static_cast<int>(i));
|
||||||
|
|
||||||
m_code_list->addItem(item);
|
m_code_list->addItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_code_list->setDragDropMode(QAbstractItemView::InternalMove);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeckoCodeWidget::DownloadCodes()
|
void GeckoCodeWidget::DownloadCodes()
|
||||||
|
@ -36,6 +36,8 @@ signals:
|
|||||||
private:
|
private:
|
||||||
void OnSelectionChanged();
|
void OnSelectionChanged();
|
||||||
void OnItemChanged(QListWidgetItem* item);
|
void OnItemChanged(QListWidgetItem* item);
|
||||||
|
void OnListReordered();
|
||||||
|
void OnContextMenuRequested();
|
||||||
|
|
||||||
void CreateWidgets();
|
void CreateWidgets();
|
||||||
void ConnectWidgets();
|
void ConnectWidgets();
|
||||||
@ -45,6 +47,7 @@ private:
|
|||||||
void RemoveCode();
|
void RemoveCode();
|
||||||
void DownloadCodes();
|
void DownloadCodes();
|
||||||
void SaveCodes();
|
void SaveCodes();
|
||||||
|
void SortAlphabetically();
|
||||||
|
|
||||||
const UICommon::GameFile& m_game;
|
const UICommon::GameFile& m_game;
|
||||||
std::string m_game_id;
|
std::string m_game_id;
|
||||||
|
Reference in New Issue
Block a user