mirror of https://github.com/mgba-emu/mgba.git
Qt: Clear cheats when the game ends
This commit is contained in:
parent
297551a5be
commit
dc5fb14fa1
|
@ -108,4 +108,9 @@ void CheatsModel::addSet(GBACheatSet* set) {
|
|||
beginInsertRows(QModelIndex(), GBACheatSetsSize(&m_device->cheats), GBACheatSetsSize(&m_device->cheats) + 1);
|
||||
*GBACheatSetsAppend(&m_device->cheats) = set;
|
||||
endInsertRows();
|
||||
}
|
||||
}
|
||||
|
||||
void CheatsModel::invalidated() {
|
||||
beginResetModel();
|
||||
endResetModel();
|
||||
}
|
||||
|
|
|
@ -34,6 +34,9 @@ public:
|
|||
void loadFile(const QString& path);
|
||||
void addSet(GBACheatSet* set);
|
||||
|
||||
public slots:
|
||||
void invalidated();
|
||||
|
||||
private:
|
||||
GBACheatDevice* m_device;
|
||||
};
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
#include "CheatsView.h"
|
||||
|
||||
#include "GameController.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
|
||||
extern "C" {
|
||||
|
@ -13,9 +15,9 @@ extern "C" {
|
|||
|
||||
using namespace QGBA;
|
||||
|
||||
CheatsView::CheatsView(GBACheatDevice* device, QWidget* parent)
|
||||
CheatsView::CheatsView(GameController* controller, QWidget* parent)
|
||||
: QWidget(parent)
|
||||
, m_model(device)
|
||||
, m_model(controller->cheatDevice())
|
||||
{
|
||||
m_ui.setupUi(this);
|
||||
|
||||
|
@ -23,6 +25,7 @@ CheatsView::CheatsView(GBACheatDevice* device, QWidget* parent)
|
|||
|
||||
connect(m_ui.load, SIGNAL(clicked()), this, SLOT(load()));
|
||||
connect(m_ui.addSet, SIGNAL(clicked()), this, SLOT(addSet()));
|
||||
connect(controller, SIGNAL(gameStopped(GBAThread*)), &m_model, SLOT(invalidated()));
|
||||
|
||||
connect(m_ui.add, &QPushButton::clicked, [this]() {
|
||||
enterCheat(GBACheatAddLine);
|
||||
|
|
|
@ -18,11 +18,13 @@ struct GBACheatDevice;
|
|||
|
||||
namespace QGBA {
|
||||
|
||||
class GameController;
|
||||
|
||||
class CheatsView : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CheatsView(GBACheatDevice* device, QWidget* parent = nullptr);
|
||||
CheatsView(GameController* controller, QWidget* parent = nullptr);
|
||||
|
||||
private slots:
|
||||
void load();
|
||||
|
|
|
@ -141,6 +141,7 @@ GameController::~GameController() {
|
|||
m_audioThread->wait();
|
||||
disconnect();
|
||||
closeGame();
|
||||
GBACheatDeviceDestroy(&m_cheatDevice);
|
||||
delete m_renderer;
|
||||
delete[] m_drawContext;
|
||||
}
|
||||
|
@ -276,6 +277,13 @@ void GameController::closeGame() {
|
|||
|
||||
m_patch = QString();
|
||||
|
||||
for (size_t i = 0; i < GBACheatSetsSize(&m_cheatDevice.cheats); ++i) {
|
||||
GBACheatSet* set = *GBACheatSetsGetPointer(&m_cheatDevice.cheats, i);
|
||||
GBACheatSetDeinit(set);
|
||||
delete set;
|
||||
}
|
||||
GBACheatSetsClear(&m_cheatDevice.cheats);
|
||||
|
||||
m_gameOpen = false;
|
||||
emit gameStopped(&m_threadContext);
|
||||
}
|
||||
|
|
|
@ -241,7 +241,7 @@ void Window::openSensorWindow() {
|
|||
}
|
||||
|
||||
void Window::openCheatsWindow() {
|
||||
CheatsView* cheatsWindow = new CheatsView(m_controller->cheatDevice());
|
||||
CheatsView* cheatsWindow = new CheatsView(m_controller);
|
||||
connect(this, SIGNAL(shutdown()), cheatsWindow, SLOT(close()));
|
||||
cheatsWindow->setAttribute(Qt::WA_DeleteOnClose);
|
||||
cheatsWindow->show();
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
void NAME ## Deinit(struct NAME* vector); \
|
||||
TYPE* NAME ## GetPointer(struct NAME* vector, size_t location); \
|
||||
TYPE* NAME ## Append(struct NAME* vector); \
|
||||
void NAME ## Clear(struct NAME* vector); \
|
||||
void NAME ## Resize(struct NAME* vector, ssize_t change); \
|
||||
void NAME ## Shift(struct NAME* vector, size_t location, size_t difference); \
|
||||
void NAME ## Unshift(struct NAME* vector, size_t location, size_t difference); \
|
||||
|
@ -51,6 +52,9 @@
|
|||
} \
|
||||
vector->size += change; \
|
||||
} \
|
||||
void NAME ## Clear(struct NAME* vector) { \
|
||||
vector->size = 0; \
|
||||
} \
|
||||
void NAME ## EnsureCapacity(struct NAME* vector, size_t capacity) { \
|
||||
if (capacity <= vector->capacity) { \
|
||||
return; \
|
||||
|
|
Loading…
Reference in New Issue