Qt: Clean up cheats

This commit is contained in:
Jeffrey Pfau 2016-09-05 10:01:12 -07:00
parent 69244f053a
commit 5b710a59fa
3 changed files with 104 additions and 86 deletions

View File

@ -11,7 +11,7 @@
#include "core/cheats.h"
#include "util/vector.h"
enum GBACheatType {
enum GBCheatType {
GB_CHEAT_AUTODETECT,
GB_CHEAT_GAMESHARK,
GB_CHEAT_GAME_GENIE,

View File

@ -9,12 +9,16 @@
#include "GameController.h"
#include <QClipboard>
#include <QPushButton>
extern "C" {
#include "core/cheats.h"
#ifdef M_CORE_GBA
#include "gba/cheats.h"
#endif
#ifdef M_CORE_GB
#include "gb/cheats.h"
#endif
}
using namespace QGBA;
@ -33,24 +37,63 @@ CheatsView::CheatsView(GameController* controller, QWidget* parent)
connect(m_ui.save, SIGNAL(clicked()), this, SLOT(save()));
connect(m_ui.addSet, SIGNAL(clicked()), this, SLOT(addSet()));
connect(m_ui.remove, SIGNAL(clicked()), this, SLOT(removeSet()));
connect(controller, SIGNAL(gameStopped(mCoreThread*)), &m_model, SLOT(invalidated()));
connect(controller, SIGNAL(gameStopped(mCoreThread*)), this, SLOT(close()));
connect(controller, SIGNAL(stateLoaded(mCoreThread*)), &m_model, SLOT(invalidated()));
connect(m_ui.add, &QPushButton::clicked, [this]() {
enterCheat(GBA_CHEAT_AUTODETECT);
});
QPushButton* add;
switch (controller->platform()) {
#ifdef M_CORE_GBA
case PLATFORM_GBA:
connect(m_ui.add, &QPushButton::clicked, [this]() {
enterCheat(GBA_CHEAT_AUTODETECT);
});
connect(m_ui.addGSA, &QPushButton::clicked, [this]() {
enterCheat(GBA_CHEAT_GAMESHARK);
});
add = new QPushButton("Add GameShark");
m_ui.gridLayout->addWidget(add, m_ui.gridLayout->rowCount(), 2, 1, 2);
connect(add, &QPushButton::clicked, [this]() {
enterCheat(GBA_CHEAT_GAMESHARK);
});
connect(m_ui.addPAR, &QPushButton::clicked, [this]() {
enterCheat(GBA_CHEAT_PRO_ACTION_REPLAY);
});
add = new QPushButton("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);
});
connect(m_ui.addCB, &QPushButton::clicked, [this]() {
enterCheat(GBA_CHEAT_CODEBREAKER);
});
add = new QPushButton("Add CodeBreaker");
m_ui.gridLayout->addWidget(add, m_ui.gridLayout->rowCount(), 2, 1, 2);
connect(add, &QPushButton::clicked, [this]() {
enterCheat(GBA_CHEAT_CODEBREAKER);
});
break;
#endif
#ifdef M_CORE_GB
case PLATFORM_GB:
connect(m_ui.add, &QPushButton::clicked, [this]() {
enterCheat(GB_CHEAT_AUTODETECT);
});
add = new QPushButton("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("Add GameGenie");
m_ui.gridLayout->addWidget(add, m_ui.gridLayout->rowCount(), 2, 1, 2);
connect(add, &QPushButton::clicked, [this]() {
enterCheat(GB_CHEAT_GAME_GENIE);
});
break;
#endif
default:
break;
}
// Stretch the cheat list back into place
int index = m_ui.gridLayout->indexOf(m_ui.cheatList);
m_ui.gridLayout->takeAt(index);
m_ui.gridLayout->addWidget(m_ui.cheatList, 0, 0, -1, 1);
}
bool CheatsView::eventFilter(QObject* object, QEvent* event) {

View File

@ -14,89 +14,35 @@
<string>Cheats</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="1" colspan="2">
<item row="2" column="2" colspan="2">
<widget class="QPushButton" name="remove">
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QPushButton" name="addSet">
<property name="text">
<string>Add New Set</string>
</property>
</widget>
</item>
<item row="7" column="1" colspan="2">
<widget class="QPushButton" name="addGSA">
<property name="text">
<string>Add GameShark</string>
</property>
</widget>
</item>
<item row="8" column="1" colspan="2">
<widget class="QPushButton" name="addPAR">
<property name="text">
<string>Add Pro Action Replay</string>
</property>
</widget>
</item>
<item row="9" column="1" colspan="2">
<widget class="QPushButton" name="addCB">
<property name="text">
<string>Add CodeBreaker</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="6" column="1" colspan="2">
<widget class="QPushButton" name="add">
<property name="text">
<string>Add</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="3" column="1" colspan="2">
<item row="3" column="2" colspan="2">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="0" column="0" rowspan="10">
<widget class="QTreeView" name="cheatList">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="defaultDropAction">
<enum>Qt::MoveAction</enum>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="headerHidden">
<bool>true</bool>
<item row="1" column="3">
<widget class="QPushButton" name="save">
<property name="text">
<string>Save</string>
</property>
</widget>
</item>
<item row="4" column="1" rowspan="2" colspan="2">
<item row="1" column="2">
<widget class="QPushButton" name="load">
<property name="text">
<string>Load</string>
</property>
</widget>
</item>
<item row="4" column="2" rowspan="2" colspan="2">
<widget class="QPlainTextEdit" name="codeEntry">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Expanding">
@ -117,19 +63,48 @@
</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">
<widget class="QTreeView" name="cheatList">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="defaultDropAction">
<enum>Qt::MoveAction</enum>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="headerHidden">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>cheatList</tabstop>
<tabstop>addSet</tabstop>
<tabstop>load</tabstop>
<tabstop>save</tabstop>
<tabstop>remove</tabstop>
<tabstop>codeEntry</tabstop>
<tabstop>add</tabstop>
<tabstop>addGSA</tabstop>
<tabstop>addPAR</tabstop>
<tabstop>addCB</tabstop>
</tabstops>
<resources/>
<connections/>