mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2025-01-18 06:25:37 +00:00
Qt: Add groups to cheat manager
This commit is contained in:
parent
133639122d
commit
1f948b1266
|
@ -1,11 +1,11 @@
|
||||||
#include "cheatcodeeditordialog.h"
|
#include "cheatcodeeditordialog.h"
|
||||||
#include <QtWidgets/QMessageBox>
|
#include <QtWidgets/QMessageBox>
|
||||||
|
|
||||||
CheatCodeEditorDialog::CheatCodeEditorDialog(CheatList* list, CheatCode* code, QWidget* parent)
|
CheatCodeEditorDialog::CheatCodeEditorDialog(const QStringList& group_names, CheatCode* code, QWidget* parent)
|
||||||
: m_code(code), QDialog(parent)
|
: m_code(code), QDialog(parent)
|
||||||
{
|
{
|
||||||
m_ui.setupUi(this);
|
m_ui.setupUi(this);
|
||||||
setupAdditionalUi(list);
|
setupAdditionalUi(group_names);
|
||||||
fillUi();
|
fillUi();
|
||||||
connectUi();
|
connectUi();
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ void CheatCodeEditorDialog::cancelClicked()
|
||||||
done(0);
|
done(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheatCodeEditorDialog::setupAdditionalUi(CheatList* list)
|
void CheatCodeEditorDialog::setupAdditionalUi(const QStringList& group_names)
|
||||||
{
|
{
|
||||||
for (u32 i = 0; i < static_cast<u32>(CheatCode::Type::Count); i++)
|
for (u32 i = 0; i < static_cast<u32>(CheatCode::Type::Count); i++)
|
||||||
{
|
{
|
||||||
|
@ -53,27 +53,28 @@ void CheatCodeEditorDialog::setupAdditionalUi(CheatList* list)
|
||||||
qApp->translate("Cheats", CheatCode::GetActivationDisplayName(static_cast<CheatCode::Activation>(i))));
|
qApp->translate("Cheats", CheatCode::GetActivationDisplayName(static_cast<CheatCode::Activation>(i))));
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto groups = list->GetCodeGroups();
|
if (!group_names.isEmpty())
|
||||||
if (!groups.empty())
|
m_ui.group->addItems(group_names);
|
||||||
{
|
|
||||||
for (const std::string& group_name : groups)
|
|
||||||
m_ui.group->addItem(QString::fromStdString(group_name));
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
m_ui.group->addItem(QStringLiteral("Ungrouped"));
|
m_ui.group->addItem(QStringLiteral("Ungrouped"));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void CheatCodeEditorDialog::fillUi()
|
void CheatCodeEditorDialog::fillUi()
|
||||||
{
|
{
|
||||||
m_ui.description->setText(QString::fromStdString(m_code->description));
|
m_ui.description->setText(QString::fromStdString(m_code->description));
|
||||||
|
|
||||||
int index = m_ui.group->findText(QString::fromStdString(m_code->group));
|
const QString group_qstr(QString::fromStdString(m_code->group));
|
||||||
|
int index = m_ui.group->findText(group_qstr);
|
||||||
if (index >= 0)
|
if (index >= 0)
|
||||||
|
{
|
||||||
m_ui.group->setCurrentIndex(index);
|
m_ui.group->setCurrentIndex(index);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
m_ui.group->setCurrentIndex(0);
|
{
|
||||||
|
index = m_ui.group->count();
|
||||||
|
m_ui.group->addItem(group_qstr);
|
||||||
|
m_ui.group->setCurrentIndex(index);
|
||||||
|
}
|
||||||
|
|
||||||
m_ui.type->setCurrentIndex(static_cast<int>(m_code->type));
|
m_ui.type->setCurrentIndex(static_cast<int>(m_code->type));
|
||||||
m_ui.activation->setCurrentIndex(static_cast<int>(m_code->activation));
|
m_ui.activation->setCurrentIndex(static_cast<int>(m_code->activation));
|
||||||
|
|
|
@ -7,7 +7,7 @@ class CheatCodeEditorDialog : public QDialog
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CheatCodeEditorDialog(CheatList* list, CheatCode* code, QWidget* parent);
|
CheatCodeEditorDialog(const QStringList& group_names, CheatCode* code, QWidget* parent);
|
||||||
~CheatCodeEditorDialog();
|
~CheatCodeEditorDialog();
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
|
@ -15,7 +15,7 @@ private Q_SLOTS:
|
||||||
void cancelClicked();
|
void cancelClicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupAdditionalUi(CheatList* list);
|
void setupAdditionalUi(const QStringList& group_names);
|
||||||
void fillUi();
|
void fillUi();
|
||||||
void connectUi();
|
void connectUi();
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <QtCore/QFileInfo>
|
#include <QtCore/QFileInfo>
|
||||||
#include <QtGui/QColor>
|
#include <QtGui/QColor>
|
||||||
#include <QtWidgets/QFileDialog>
|
#include <QtWidgets/QFileDialog>
|
||||||
|
#include <QtWidgets/QInputDialog>
|
||||||
#include <QtWidgets/QMessageBox>
|
#include <QtWidgets/QMessageBox>
|
||||||
#include <QtWidgets/QTreeWidgetItemIterator>
|
#include <QtWidgets/QTreeWidgetItemIterator>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
@ -165,20 +166,42 @@ QTreeWidgetItem* CheatManagerDialog::getItemForCheatIndex(u32 index) const
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
QTreeWidgetItem* CheatManagerDialog::getItemForCheatGroup(const std::string& group) const
|
QTreeWidgetItem* CheatManagerDialog::getItemForCheatGroup(const QString& group_name) const
|
||||||
{
|
{
|
||||||
const QString group_qstr(QString::fromStdString(group));
|
|
||||||
const int count = m_ui.cheatList->topLevelItemCount();
|
const int count = m_ui.cheatList->topLevelItemCount();
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
QTreeWidgetItem* item = m_ui.cheatList->topLevelItem(i);
|
QTreeWidgetItem* item = m_ui.cheatList->topLevelItem(i);
|
||||||
if (item->text(0) == group_qstr)
|
if (item->text(0) == group_name)
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QTreeWidgetItem* CheatManagerDialog::createItemForCheatGroup(const QString& group_name) const
|
||||||
|
{
|
||||||
|
QTreeWidgetItem* group = new QTreeWidgetItem();
|
||||||
|
group->setFlags(group->flags() | Qt::ItemIsUserCheckable);
|
||||||
|
group->setText(0, group_name);
|
||||||
|
m_ui.cheatList->addTopLevelItem(group);
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList CheatManagerDialog::getCheatGroupNames() const
|
||||||
|
{
|
||||||
|
QStringList group_names;
|
||||||
|
|
||||||
|
const int count = m_ui.cheatList->topLevelItemCount();
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
QTreeWidgetItem* item = m_ui.cheatList->topLevelItem(i);
|
||||||
|
group_names.push_back(item->text(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
return group_names;
|
||||||
|
}
|
||||||
|
|
||||||
static int getCheatIndexFromItem(QTreeWidgetItem* item)
|
static int getCheatIndexFromItem(QTreeWidgetItem* item)
|
||||||
{
|
{
|
||||||
QVariant item_data(item->data(0, Qt::UserRole));
|
QVariant item_data(item->data(0, Qt::UserRole));
|
||||||
|
@ -225,10 +248,7 @@ void CheatManagerDialog::updateCheatList()
|
||||||
const std::vector<std::string> groups = list->GetCodeGroups();
|
const std::vector<std::string> groups = list->GetCodeGroups();
|
||||||
for (const std::string& group_name : groups)
|
for (const std::string& group_name : groups)
|
||||||
{
|
{
|
||||||
QTreeWidgetItem* group = new QTreeWidgetItem();
|
QTreeWidgetItem* group = createItemForCheatGroup(QString::fromStdString(group_name));
|
||||||
group->setFlags(group->flags() | Qt::ItemIsUserCheckable);
|
|
||||||
group->setText(0, QString::fromStdString(group_name));
|
|
||||||
m_ui.cheatList->addTopLevelItem(group);
|
|
||||||
|
|
||||||
const u32 count = list->GetCodeCount();
|
const u32 count = list->GetCodeCount();
|
||||||
bool all_enabled = true;
|
bool all_enabled = true;
|
||||||
|
@ -363,7 +383,17 @@ void CheatManagerDialog::activateCheat(u32 index)
|
||||||
|
|
||||||
void CheatManagerDialog::newCategoryClicked()
|
void CheatManagerDialog::newCategoryClicked()
|
||||||
{
|
{
|
||||||
//
|
QString group_name = QInputDialog::getText(this, tr("Add Group"), tr("Group Name:"));
|
||||||
|
if (group_name.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (getItemForCheatGroup(group_name) != nullptr)
|
||||||
|
{
|
||||||
|
QMessageBox::critical(this, tr("Error"), tr("This group name already exists."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
createItemForCheatGroup(group_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheatManagerDialog::addCodeClicked()
|
void CheatManagerDialog::addCodeClicked()
|
||||||
|
@ -371,15 +401,19 @@ void CheatManagerDialog::addCodeClicked()
|
||||||
CheatList* list = getCheatList();
|
CheatList* list = getCheatList();
|
||||||
|
|
||||||
CheatCode new_code;
|
CheatCode new_code;
|
||||||
CheatCodeEditorDialog editor(list, &new_code, this);
|
new_code.group = "Ungrouped";
|
||||||
|
|
||||||
|
CheatCodeEditorDialog editor(getCheatGroupNames(), &new_code, this);
|
||||||
if (editor.exec() > 0)
|
if (editor.exec() > 0)
|
||||||
{
|
{
|
||||||
QTreeWidgetItem* group_item = getItemForCheatGroup(new_code.group);
|
const QString group_name_qstr(QString::fromStdString(new_code.group));
|
||||||
|
QTreeWidgetItem* group_item = getItemForCheatGroup(group_name_qstr);
|
||||||
if (!group_item)
|
if (!group_item)
|
||||||
group_item = m_ui.cheatList->topLevelItem(0);
|
group_item = createItemForCheatGroup(group_name_qstr);
|
||||||
|
|
||||||
QTreeWidgetItem* item = new QTreeWidgetItem(group_item);
|
QTreeWidgetItem* item = new QTreeWidgetItem(group_item);
|
||||||
fillItemForCheatCode(item, list->GetCodeCount(), new_code);
|
fillItemForCheatCode(item, list->GetCodeCount(), new_code);
|
||||||
|
group_item->setExpanded(true);
|
||||||
|
|
||||||
QtHostInterface::GetInstance()->executeOnEmulationThread(
|
QtHostInterface::GetInstance()->executeOnEmulationThread(
|
||||||
[this, &new_code]() {
|
[this, &new_code]() {
|
||||||
|
@ -401,7 +435,7 @@ void CheatManagerDialog::editCodeClicked()
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CheatCode new_code = list->GetCode(static_cast<u32>(index));
|
CheatCode new_code = list->GetCode(static_cast<u32>(index));
|
||||||
CheatCodeEditorDialog editor(list, &new_code, this);
|
CheatCodeEditorDialog editor(getCheatGroupNames(), &new_code, this);
|
||||||
if (editor.exec() > 0)
|
if (editor.exec() > 0)
|
||||||
{
|
{
|
||||||
QTreeWidgetItem* item = getItemForCheatIndex(static_cast<u32>(index));
|
QTreeWidgetItem* item = getItemForCheatIndex(static_cast<u32>(index));
|
||||||
|
@ -410,10 +444,13 @@ void CheatManagerDialog::editCodeClicked()
|
||||||
if (new_code.group != list->GetCode(static_cast<u32>(index)).group)
|
if (new_code.group != list->GetCode(static_cast<u32>(index)).group)
|
||||||
{
|
{
|
||||||
item = item->parent()->takeChild(item->parent()->indexOfChild(item));
|
item = item->parent()->takeChild(item->parent()->indexOfChild(item));
|
||||||
QTreeWidgetItem* group_item = getItemForCheatGroup(new_code.group);
|
|
||||||
|
const QString group_name_qstr(QString::fromStdString(new_code.group));
|
||||||
|
QTreeWidgetItem* group_item = getItemForCheatGroup(group_name_qstr);
|
||||||
if (!group_item)
|
if (!group_item)
|
||||||
group_item = m_ui.cheatList->topLevelItem(0);
|
group_item = createItemForCheatGroup(group_name_qstr);
|
||||||
group_item->addChild(item);
|
group_item->addChild(item);
|
||||||
|
group_item->setExpanded(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
fillItemForCheatCode(item, static_cast<u32>(index), new_code);
|
fillItemForCheatCode(item, static_cast<u32>(index), new_code);
|
||||||
|
|
|
@ -59,7 +59,9 @@ private:
|
||||||
void fillItemForCheatCode(QTreeWidgetItem* item, u32 index, const CheatCode& code);
|
void fillItemForCheatCode(QTreeWidgetItem* item, u32 index, const CheatCode& code);
|
||||||
|
|
||||||
QTreeWidgetItem* getItemForCheatIndex(u32 index) const;
|
QTreeWidgetItem* getItemForCheatIndex(u32 index) const;
|
||||||
QTreeWidgetItem* getItemForCheatGroup(const std::string& group) const;
|
QTreeWidgetItem* getItemForCheatGroup(const QString& group_name) const;
|
||||||
|
QTreeWidgetItem* createItemForCheatGroup(const QString& group_name) const;
|
||||||
|
QStringList getCheatGroupNames() const;
|
||||||
int getSelectedCheatIndex() const;
|
int getSelectedCheatIndex() const;
|
||||||
int getSelectedResultIndex() const;
|
int getSelectedResultIndex() const;
|
||||||
int getSelectedWatchIndex() const;
|
int getSelectedWatchIndex() const;
|
||||||
|
|
|
@ -28,11 +28,8 @@
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="cheatListNewCategory">
|
<widget class="QPushButton" name="cheatListNewCategory">
|
||||||
<property name="enabled">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&New Category...</string>
|
<string>&Add Group...</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
Loading…
Reference in a new issue