Merge pull request #8212 from spycrab/ar_gecko_reorder
ActionReplay & GeckoCode reordering support
This commit is contained in:
commit
5262f39026
|
@ -5,8 +5,10 @@
|
|||
#include "DolphinQt/Config/ARCodeWidget.h"
|
||||
|
||||
#include <QButtonGroup>
|
||||
#include <QCursor>
|
||||
#include <QHBoxLayout>
|
||||
#include <QListWidget>
|
||||
#include <QMenu>
|
||||
#include <QPushButton>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
|
@ -49,6 +51,8 @@ void ARCodeWidget::CreateWidgets()
|
|||
m_code_edit = new QPushButton(tr("&Edit Code..."));
|
||||
m_code_remove = new QPushButton(tr("&Remove Code"));
|
||||
|
||||
m_code_list->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
|
||||
auto* button_layout = new QHBoxLayout;
|
||||
|
||||
button_layout->addWidget(m_code_add);
|
||||
|
@ -68,8 +72,13 @@ void ARCodeWidget::ConnectWidgets()
|
|||
{
|
||||
connect(m_warning, &CheatWarningWidget::OpenCheatEnableSettings, this,
|
||||
&ARCodeWidget::OpenGeneralSettings);
|
||||
|
||||
connect(m_code_list, &QListWidget::itemChanged, this, &ARCodeWidget::OnItemChanged);
|
||||
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_edit, &QPushButton::pressed, this, &ARCodeWidget::OnCodeEditPressed);
|
||||
|
@ -83,6 +92,40 @@ void ARCodeWidget::OnItemChanged(QListWidgetItem* item)
|
|||
if (!m_restart_required)
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -105,17 +148,22 @@ void ARCodeWidget::UpdateList()
|
|||
{
|
||||
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)
|
||||
.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->setData(Qt::UserRole, static_cast<int>(i));
|
||||
|
||||
m_code_list->addItem(item);
|
||||
}
|
||||
|
||||
m_code_list->setDragDropMode(QAbstractItemView::InternalMove);
|
||||
}
|
||||
|
||||
void ARCodeWidget::SaveCodes()
|
||||
|
|
|
@ -37,16 +37,20 @@ signals:
|
|||
private:
|
||||
void OnSelectionChanged();
|
||||
void OnItemChanged(QListWidgetItem* item);
|
||||
void OnContextMenuRequested();
|
||||
|
||||
void CreateWidgets();
|
||||
void ConnectWidgets();
|
||||
void UpdateList();
|
||||
void SaveCodes();
|
||||
void SortAlphabetically();
|
||||
|
||||
void OnCodeAddPressed();
|
||||
void OnCodeEditPressed();
|
||||
void OnCodeRemovePressed();
|
||||
|
||||
void OnListReordered();
|
||||
|
||||
const UICommon::GameFile& m_game;
|
||||
std::string m_game_id;
|
||||
u16 m_game_revision;
|
||||
|
|
|
@ -4,11 +4,13 @@
|
|||
|
||||
#include "DolphinQt/Config/GeckoCodeWidget.h"
|
||||
|
||||
#include <QCursor>
|
||||
#include <QFontDatabase>
|
||||
#include <QFormLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QListWidget>
|
||||
#include <QMenu>
|
||||
#include <QPushButton>
|
||||
#include <QTextEdit>
|
||||
#include <QVBoxLayout>
|
||||
|
@ -51,6 +53,8 @@ void GeckoCodeWidget::CreateWidgets()
|
|||
m_name_label = new QLabel;
|
||||
m_creator_label = new QLabel;
|
||||
|
||||
m_code_list->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
|
||||
QFont monospace(QFontDatabase::systemFont(QFontDatabase::FixedFont).family());
|
||||
|
||||
const auto line_height = QFontMetrics(font()).lineSpacing();
|
||||
|
@ -116,12 +120,15 @@ void GeckoCodeWidget::ConnectWidgets()
|
|||
connect(m_code_list, &QListWidget::itemSelectionChanged, this,
|
||||
&GeckoCodeWidget::OnSelectionChanged);
|
||||
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_remove_code, &QPushButton::pressed, this, &GeckoCodeWidget::RemoveCode);
|
||||
connect(m_edit_code, &QPushButton::pressed, this, &GeckoCodeWidget::EditCode);
|
||||
connect(m_download_codes, &QPushButton::pressed, this, &GeckoCodeWidget::DownloadCodes);
|
||||
|
||||
connect(m_warning, &CheatWarningWidget::OpenCheatEnableSettings, this,
|
||||
&GeckoCodeWidget::OpenGeneralSettings);
|
||||
}
|
||||
|
@ -130,8 +137,10 @@ void GeckoCodeWidget::OnSelectionChanged()
|
|||
{
|
||||
auto items = m_code_list->selectedItems();
|
||||
|
||||
m_edit_code->setEnabled(!items.empty());
|
||||
m_remove_code->setEnabled(!items.empty());
|
||||
const bool empty = items.empty();
|
||||
|
||||
m_edit_code->setEnabled(!empty);
|
||||
m_remove_code->setEnabled(!empty);
|
||||
|
||||
if (items.empty())
|
||||
return;
|
||||
|
@ -222,11 +231,46 @@ 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::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()
|
||||
{
|
||||
m_code_list->clear();
|
||||
|
@ -239,12 +283,15 @@ void GeckoCodeWidget::UpdateList()
|
|||
.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->setData(Qt::UserRole, static_cast<int>(i));
|
||||
|
||||
m_code_list->addItem(item);
|
||||
}
|
||||
|
||||
m_code_list->setDragDropMode(QAbstractItemView::InternalMove);
|
||||
}
|
||||
|
||||
void GeckoCodeWidget::DownloadCodes()
|
||||
|
|
|
@ -36,6 +36,8 @@ signals:
|
|||
private:
|
||||
void OnSelectionChanged();
|
||||
void OnItemChanged(QListWidgetItem* item);
|
||||
void OnListReordered();
|
||||
void OnContextMenuRequested();
|
||||
|
||||
void CreateWidgets();
|
||||
void ConnectWidgets();
|
||||
|
@ -45,6 +47,7 @@ private:
|
|||
void RemoveCode();
|
||||
void DownloadCodes();
|
||||
void SaveCodes();
|
||||
void SortAlphabetically();
|
||||
|
||||
const UICommon::GameFile& m_game;
|
||||
std::string m_game_id;
|
||||
|
|
Loading…
Reference in New Issue