mirror of https://github.com/mgba-emu/mgba.git
Qt: Clean up cheats dialog
This commit is contained in:
parent
8ea9747021
commit
f1ec80889d
1
CHANGES
1
CHANGES
|
@ -22,6 +22,7 @@ Other fixes:
|
|||
Misc:
|
||||
- Core: Suspend runloop when a core crashes
|
||||
- Qt: Rearrange menus some
|
||||
- Qt: Clean up cheats dialog
|
||||
- Util: Improve speed of UPS patch loading
|
||||
|
||||
0.9.1: (2021-04-18)
|
||||
|
|
|
@ -8,8 +8,10 @@
|
|||
#include "GBAApp.h"
|
||||
#include "CoreController.h"
|
||||
|
||||
#include <QBoxLayout>
|
||||
#include <QButtonGroup>
|
||||
#include <QClipboard>
|
||||
#include <QPushButton>
|
||||
#include <QRadioButton>
|
||||
|
||||
#include <mgba/core/cheats.h>
|
||||
#ifdef M_CORE_GBA
|
||||
|
@ -30,58 +32,30 @@ CheatsView::CheatsView(std::shared_ptr<CoreController> controller, QWidget* pare
|
|||
|
||||
m_ui.cheatList->installEventFilter(this);
|
||||
m_ui.cheatList->setModel(&m_model);
|
||||
m_ui.codeEntry->setFont(GBAApp::app()->monospaceFont());
|
||||
|
||||
connect(m_ui.load, &QPushButton::clicked, this, &CheatsView::load);
|
||||
connect(m_ui.save, &QPushButton::clicked, this, &CheatsView::save);
|
||||
connect(m_ui.addSet, &QPushButton::clicked, this, &CheatsView::addSet);
|
||||
connect(m_ui.remove, &QPushButton::clicked, this, &CheatsView::removeSet);
|
||||
connect(m_ui.load, &QAbstractButton::clicked, this, &CheatsView::load);
|
||||
connect(m_ui.save, &QAbstractButton::clicked, this, &CheatsView::save);
|
||||
connect(m_ui.addSet, &QAbstractButton::clicked, this, &CheatsView::addSet);
|
||||
connect(m_ui.remove, &QAbstractButton::clicked, this, &CheatsView::removeSet);
|
||||
connect(m_ui.add, &QAbstractButton::clicked, this, &CheatsView::enterCheat);
|
||||
connect(controller.get(), &CoreController::stopping, this, &CheatsView::close);
|
||||
connect(controller.get(), &CoreController::stateLoaded, &m_model, &CheatsModel::invalidated);
|
||||
|
||||
QPushButton* add;
|
||||
switch (controller->platform()) {
|
||||
#ifdef M_CORE_GBA
|
||||
case mPLATFORM_GBA:
|
||||
connect(m_ui.add, &QPushButton::clicked, [this]() {
|
||||
enterCheat(GBA_CHEAT_AUTODETECT);
|
||||
});
|
||||
|
||||
add = new QPushButton(tr("Add GameShark"));
|
||||
m_ui.gridLayout->addWidget(add, m_ui.gridLayout->rowCount(), 2, 1, 2);
|
||||
connect(add, &QPushButton::clicked, [this]() {
|
||||
enterCheat(GBA_CHEAT_GAMESHARK);
|
||||
});
|
||||
|
||||
add = new QPushButton(tr("Add Pro Action Replay"));
|
||||
m_ui.gridLayout->addWidget(add, m_ui.gridLayout->rowCount(), 2, 1, 2);
|
||||
connect(add, &QPushButton::clicked, [this]() {
|
||||
enterCheat(GBA_CHEAT_PRO_ACTION_REPLAY);
|
||||
});
|
||||
|
||||
add = new QPushButton(tr("Add CodeBreaker"));
|
||||
m_ui.gridLayout->addWidget(add, m_ui.gridLayout->rowCount(), 2, 1, 2);
|
||||
connect(add, &QPushButton::clicked, [this]() {
|
||||
enterCheat(GBA_CHEAT_CODEBREAKER);
|
||||
});
|
||||
registerCodeType(tr("Autodetect (recommended)"), GBA_CHEAT_AUTODETECT);
|
||||
registerCodeType(tr("GameShark"), GBA_CHEAT_GAMESHARK);
|
||||
registerCodeType(tr("Action Replay MAX"), GBA_CHEAT_PRO_ACTION_REPLAY);
|
||||
registerCodeType(tr("CodeBreaker"), GBA_CHEAT_CODEBREAKER);
|
||||
break;
|
||||
#endif
|
||||
#ifdef M_CORE_GB
|
||||
case mPLATFORM_GB:
|
||||
connect(m_ui.add, &QPushButton::clicked, [this]() {
|
||||
enterCheat(GB_CHEAT_AUTODETECT);
|
||||
});
|
||||
|
||||
add = new QPushButton(tr("Add GameShark"));
|
||||
m_ui.gridLayout->addWidget(add, m_ui.gridLayout->rowCount(), 2, 1, 2);
|
||||
connect(add, &QPushButton::clicked, [this]() {
|
||||
enterCheat(GB_CHEAT_GAMESHARK);
|
||||
});
|
||||
|
||||
add = new QPushButton(tr("Add GameGenie"));
|
||||
m_ui.gridLayout->addWidget(add, m_ui.gridLayout->rowCount(), 2, 1, 2);
|
||||
connect(add, &QPushButton::clicked, [this]() {
|
||||
enterCheat(GB_CHEAT_GAME_GENIE);
|
||||
});
|
||||
registerCodeType(tr("Autodetect (recommended)"), GB_CHEAT_AUTODETECT);
|
||||
registerCodeType(tr("GameShark"), GB_CHEAT_GAMESHARK);
|
||||
registerCodeType(tr("Game Genie"), GB_CHEAT_GAME_GENIE);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
|
@ -127,6 +101,7 @@ void CheatsView::addSet() {
|
|||
mCheatSet* set = m_controller->cheatDevice()->createSet(m_controller->cheatDevice(), nullptr);
|
||||
m_model.addSet(set);
|
||||
m_ui.cheatList->selectionModel()->select(m_model.index(m_model.rowCount() - 1, 0, QModelIndex()), QItemSelectionModel::ClearAndSelect);
|
||||
enterCheat();
|
||||
}
|
||||
|
||||
void CheatsView::removeSet() {
|
||||
|
@ -140,7 +115,21 @@ void CheatsView::removeSet() {
|
|||
}
|
||||
}
|
||||
|
||||
void CheatsView::enterCheat(int codeType) {
|
||||
void CheatsView::registerCodeType(const QString& label, int type) {
|
||||
QRadioButton* add = new QRadioButton(label);
|
||||
m_ui.typeLayout->addWidget(add);
|
||||
connect(add, &QAbstractButton::clicked, [this, type]() {
|
||||
m_codeType = type;
|
||||
});
|
||||
if (!m_typeGroup) {
|
||||
m_typeGroup = new QButtonGroup(this);
|
||||
m_codeType = type;
|
||||
add->setChecked(true);
|
||||
}
|
||||
m_typeGroup->addButton(add);
|
||||
}
|
||||
|
||||
void CheatsView::enterCheat() {
|
||||
mCheatSet* set = nullptr;
|
||||
QModelIndexList selection = m_ui.cheatList->selectionModel()->selectedIndexes();
|
||||
QModelIndex index;
|
||||
|
@ -163,7 +152,7 @@ void CheatsView::enterCheat(int codeType) {
|
|||
QStringList cheats = m_ui.codeEntry->toPlainText().split('\n', QString::SkipEmptyParts);
|
||||
for (const QString& string : cheats) {
|
||||
m_model.beginAppendRow(index);
|
||||
mCheatAddLine(set, string.toUtf8().constData(), codeType);
|
||||
mCheatAddLine(set, string.toUtf8().constData(), m_codeType);
|
||||
m_model.endAppendRow();
|
||||
}
|
||||
if (set->refresh) {
|
||||
|
|
|
@ -33,13 +33,17 @@ private slots:
|
|||
void save();
|
||||
void addSet();
|
||||
void removeSet();
|
||||
void enterCheat();
|
||||
|
||||
private:
|
||||
void enterCheat(int codeType);
|
||||
void registerCodeType(const QString& label, int type);
|
||||
|
||||
Ui::CheatsView m_ui;
|
||||
std::shared_ptr<CoreController> m_controller;
|
||||
CheatsModel m_model;
|
||||
QButtonGroup* m_typeGroup = nullptr;
|
||||
|
||||
int m_codeType = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -6,60 +6,18 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>629</width>
|
||||
<height>428</height>
|
||||
<width>520</width>
|
||||
<height>455</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Cheats</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout" columnstretch="3,0,0,0">
|
||||
<item row="2" column="2" colspan="2">
|
||||
<widget class="QPushButton" name="remove">
|
||||
<property name="text">
|
||||
<string>Remove</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="2" colspan="2">
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="3">
|
||||
<widget class="QPushButton" name="save">
|
||||
<property name="text">
|
||||
<string>Save</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QPushButton" name="load">
|
||||
<property name="text">
|
||||
<string>Load</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2" colspan="2">
|
||||
<widget class="QPushButton" name="addSet">
|
||||
<property name="text">
|
||||
<string>Add New Set</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="2" colspan="2">
|
||||
<widget class="QPushButton" name="add">
|
||||
<property name="text">
|
||||
<string>Add</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" rowspan="7" colspan="2">
|
||||
<layout class="QGridLayout" name="gridLayout" rowstretch="0,0,0,0,1,0,0" columnstretch="4,0,0">
|
||||
<item row="0" column="0" rowspan="7">
|
||||
<widget class="QTreeView" name="cheatList">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
|
@ -75,18 +33,51 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="2" rowspan="2" colspan="2">
|
||||
<item row="0" column="1" colspan="2">
|
||||
<widget class="QPushButton" name="addSet">
|
||||
<property name="text">
|
||||
<string>Add New Code</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QPushButton" name="load">
|
||||
<property name="text">
|
||||
<string>Load</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QPushButton" name="save">
|
||||
<property name="text">
|
||||
<string>Save</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1" colspan="2">
|
||||
<widget class="QPushButton" name="remove">
|
||||
<property name="text">
|
||||
<string>Remove</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1" colspan="2">
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1" colspan="2">
|
||||
<widget class="QPlainTextEdit" name="codeEntry">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Expanding">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
||||
<horstretch>1</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Courier New</family>
|
||||
</font>
|
||||
<property name="tabChangesFocus">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="lineWrapMode">
|
||||
<enum>QPlainTextEdit::NoWrap</enum>
|
||||
|
@ -96,6 +87,21 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1" colspan="2">
|
||||
<widget class="QPushButton" name="add">
|
||||
<property name="text">
|
||||
<string>Add Lines</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1" colspan="2">
|
||||
<widget class="QGroupBox" name="typeBox">
|
||||
<property name="title">
|
||||
<string>Code type</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="typeLayout"/>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
|
|
Loading…
Reference in New Issue