all repos — mgba @ 0bd9ae087e149599e352bbee24c4de23e6247ec5

mGBA Game Boy Advance Emulator

Qt: Start Cheats view
Jeffrey Pfau jeffrey@endrift.com
Sat, 14 Feb 2015 16:38:29 -0800
commit

0bd9ae087e149599e352bbee24c4de23e6247ec5

parent

883a6381d176cf494baa45f09fd186be10c653fb

M src/platform/qt/CMakeLists.txtsrc/platform/qt/CMakeLists.txt

@@ -37,6 +37,8 @@ endif()

set(SOURCE_FILES AudioProcessor.cpp + CheatsModel.cpp + CheatsView.cpp ConfigController.cpp Display.cpp GBAApp.cpp

@@ -60,6 +62,7 @@ VFileDevice.cpp

VideoView.cpp) qt5_wrap_ui(UI_FILES + CheatsView.ui GIFView.ui LoadSaveState.ui LogView.ui
A src/platform/qt/CheatsModel.cpp

@@ -0,0 +1,66 @@

+/* Copyright (c) 2013-2015 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include "CheatsModel.h" + +extern "C" { +#include "gba/cheats.h" +#include "util/vfs.h" +} + +using namespace QGBA; + +CheatsModel::CheatsModel(GBACheatDevice* device, QObject* parent) + : QAbstractItemModel(parent) + , m_device(device) +{ +} + +QVariant CheatsModel::data(const QModelIndex& index, int role) const { + if (!index.isValid()) { + return QVariant(); + } + + int row = index.row(); + const GBACheatSet* cheats = static_cast<const GBACheatSet*>(index.internalPointer()); + switch (role) { + case Qt::DisplayRole: + return cheats->name ? cheats->name : tr("(untitled)"); + case Qt::CheckStateRole: + return Qt::Checked; + default: + return QVariant(); + } +} + +QModelIndex CheatsModel::index(int row, int column, const QModelIndex& parent) const { + return createIndex(row, column, *GBACheatSetsGetPointer(&m_device->cheats, row)); +} + +QModelIndex CheatsModel::parent(const QModelIndex& index) const { + return QModelIndex(); +} + +int CheatsModel::columnCount(const QModelIndex& parent) const { + return 1; +} + +int CheatsModel::rowCount(const QModelIndex& parent) const { + if (parent.isValid()) { + return 0; + } + return GBACheatSetsSize(&m_device->cheats); +} + +void CheatsModel::loadFile(const QString& path) { + VFile* vf = VFileOpen(path.toLocal8Bit().constData(), O_RDONLY); + if (!vf) { + return; + } + beginResetModel(); + GBACheatParseFile(m_device, vf); + endResetModel(); + vf->close(vf); +}
A src/platform/qt/CheatsModel.h

@@ -0,0 +1,37 @@

+/* Copyright (c) 2013-2015 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifndef QGBA_CHEATS_MODEL +#define QGBA_CHEATS_MODEL + +#include <QAbstractItemModel> + +struct GBACheatDevice; + +namespace QGBA { + +class CheatsModel : public QAbstractItemModel { +Q_OBJECT + +public: + CheatsModel(GBACheatDevice* m_device, QObject* parent = nullptr); + + virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; + + virtual QModelIndex index(int row, int column, const QModelIndex& parent) const override; + virtual QModelIndex parent(const QModelIndex& index) const override; + + virtual int columnCount(const QModelIndex& parent = QModelIndex()) const override; + virtual int rowCount(const QModelIndex& parent = QModelIndex()) const override; + + void loadFile(const QString& path); + +private: + GBACheatDevice* m_device; +}; + +} + +#endif
A src/platform/qt/CheatsView.cpp

@@ -0,0 +1,28 @@

+/* Copyright (c) 2013-2015 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include "CheatsView.h" + +#include <QFileDialog> + +using namespace QGBA; + +CheatsView::CheatsView(GBACheatDevice* device, QWidget* parent) + : QWidget(parent) + , m_model(device) +{ + m_ui.setupUi(this); + + m_ui.cheatList->setModel(&m_model); + + connect(m_ui.load, SIGNAL(clicked()), this, SLOT(load())); +} + +void CheatsView::load() { + QString filename = QFileDialog::getOpenFileName(this, tr("Select cheats file")); + if (!filename.isEmpty()) { + m_model.loadFile(filename); + } +}
A src/platform/qt/CheatsView.h

@@ -0,0 +1,35 @@

+/* Copyright (c) 2013-2015 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifndef QGBA_CHEATS_VIEW +#define QGBA_CHEATS_VIEW + +#include <QWidget> + +#include "CheatsModel.h" + +#include "ui_CheatsView.h" + +struct GBACheatDevice; + +namespace QGBA { + +class CheatsView : public QWidget { +Q_OBJECT + +public: + CheatsView(GBACheatDevice* device, QWidget* parent = nullptr); + +private slots: + void load(); + +private: + Ui::CheatsView m_ui; + CheatsModel m_model; +}; + +} + +#endif
A src/platform/qt/CheatsView.ui

@@ -0,0 +1,150 @@

+<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>CheatsView</class> + <widget class="QWidget" name="CheatsView"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>422</width> + <height>389</height> + </rect> + </property> + <property name="windowTitle"> + <string>Cheats</string> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="2" column="1" colspan="2"> + <widget class="QPushButton" name="remove"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Remove</string> + </property> + </widget> + </item> + <item row="0" column="1" colspan="2"> + <widget class="QPushButton" name="addSet"> + <property name="enabled"> + <bool>false</bool> + </property> + <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="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Add GameShark</string> + </property> + </widget> + </item> + <item row="8" column="1" colspan="2"> + <widget class="QPushButton" name="addPAR"> + <property name="enabled"> + <bool>false</bool> + </property> + <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="enabled"> + <bool>false</bool> + </property> + <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="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Add</string> + </property> + </widget> + </item> + <item row="1" column="2"> + <widget class="QPushButton" name="save"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Save</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="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="headerHidden"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="4" column="1" rowspan="2" colspan="2"> + <widget class="QTextEdit" name="codeEntry"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Maximum" vsizetype="Expanding"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="maximumSize"> + <size> + <width>180</width> + <height>16777215</height> + </size> + </property> + </widget> + </item> + </layout> + </widget> + <tabstops> + <tabstop>cheatList</tabstop> + <tabstop>addSet</tabstop> + <tabstop>load</tabstop> + <tabstop>codeEntry</tabstop> + <tabstop>add</tabstop> + <tabstop>addGSA</tabstop> + <tabstop>addPAR</tabstop> + <tabstop>addCB</tabstop> + </tabstops> + <resources/> + <connections/> +</ui>
M src/platform/qt/GameController.cppsrc/platform/qt/GameController.cpp

@@ -46,6 +46,9 @@ m_renderer = new GBAVideoSoftwareRenderer;

GBAVideoSoftwareRendererCreate(m_renderer); m_renderer->outputBuffer = (color_t*) m_drawContext; m_renderer->outputBufferStride = 256; + + GBACheatDeviceCreate(&m_cheatDevice); + m_threadContext.state = THREAD_INITIALIZED; m_threadContext.debugger = 0; m_threadContext.frameskip = 0;

@@ -53,6 +56,7 @@ m_threadContext.bios = 0;

m_threadContext.renderer = &m_renderer->d; m_threadContext.userData = this; m_threadContext.rewindBufferCapacity = 0; + m_threadContext.cheats = &m_cheatDevice; m_threadContext.logLevel = -1; m_lux.p = this;
M src/platform/qt/GameController.hsrc/platform/qt/GameController.h

@@ -13,6 +13,7 @@ #include <QMutex>

#include <QString> extern "C" { +#include "gba/cheats.h" #include "gba/hardware.h" #include "gba/supervisor/thread.h" #ifdef BUILD_SDL

@@ -44,6 +45,7 @@ ~GameController();

const uint32_t* drawContext() const { return m_drawContext; } GBAThread* thread() { return &m_threadContext; } + GBACheatDevice* cheatDevice() { return &m_cheatDevice; } void threadInterrupt(); void threadContinue();

@@ -136,6 +138,7 @@

uint32_t* m_drawContext; GBAThread m_threadContext; GBAVideoSoftwareRenderer* m_renderer; + GBACheatDevice m_cheatDevice; int m_activeKeys; int m_logLevels;
M src/platform/qt/Window.cppsrc/platform/qt/Window.cpp

@@ -14,6 +14,7 @@ #include <QMessageBox>

#include <QMimeData> #include <QStackedLayout> +#include "CheatsView.h" #include "ConfigController.h" #include "GameController.h" #include "GBAKeyEditor.h"

@@ -231,11 +232,19 @@ connect(this, SIGNAL(shutdown()), overrideWindow, SLOT(close()));

overrideWindow->setAttribute(Qt::WA_DeleteOnClose); overrideWindow->show(); } + void Window::openSensorWindow() { SensorView* sensorWindow = new SensorView(m_controller); connect(this, SIGNAL(shutdown()), sensorWindow, SLOT(close())); sensorWindow->setAttribute(Qt::WA_DeleteOnClose); sensorWindow->show(); +} + +void Window::openCheatsWindow() { + CheatsView* cheatsWindow = new CheatsView(m_controller->cheatDevice()); + connect(this, SIGNAL(shutdown()), cheatsWindow, SLOT(close())); + cheatsWindow->setAttribute(Qt::WA_DeleteOnClose); + cheatsWindow->show(); } #ifdef BUILD_SDL

@@ -682,6 +691,10 @@

QAction* sensors = new QAction(tr("Game &Pak sensors..."), toolsMenu); connect(sensors, SIGNAL(triggered()), this, SLOT(openSensorWindow())); addControlledAction(toolsMenu, sensors, "sensorWindow"); + + QAction* cheats = new QAction(tr("&Cheats..."), toolsMenu); + connect(cheats, SIGNAL(triggered()), this, SLOT(openCheatsWindow())); + addControlledAction(toolsMenu, cheats, "cheatsWindow"); #ifdef USE_GDB_STUB QAction* gdbWindow = new QAction(tr("Start &GDB server..."), toolsMenu);
M src/platform/qt/Window.hsrc/platform/qt/Window.h

@@ -69,6 +69,7 @@ void openShortcutWindow();

void openOverrideWindow(); void openSensorWindow(); + void openCheatsWindow(); #ifdef BUILD_SDL void openGamepadWindow();