Qt: Start Cheats view

This commit is contained in:
Jeffrey Pfau 2015-02-14 16:38:29 -08:00
parent 883a6381d1
commit 0bd9ae087e
10 changed files with 340 additions and 0 deletions

View File

@ -37,6 +37,8 @@ endif()
set(SOURCE_FILES
AudioProcessor.cpp
CheatsModel.cpp
CheatsView.cpp
ConfigController.cpp
Display.cpp
GBAApp.cpp
@ -60,6 +62,7 @@ set(SOURCE_FILES
VideoView.cpp)
qt5_wrap_ui(UI_FILES
CheatsView.ui
GIFView.ui
LoadSaveState.ui
LogView.ui

View File

@ -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);
}

View File

@ -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

View File

@ -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);
}
}

View File

@ -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

View File

@ -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>

View File

@ -46,6 +46,9 @@ GameController::GameController(QObject* parent)
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 @@ GameController::GameController(QObject* parent)
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;

View File

@ -13,6 +13,7 @@
#include <QString>
extern "C" {
#include "gba/cheats.h"
#include "gba/hardware.h"
#include "gba/supervisor/thread.h"
#ifdef BUILD_SDL
@ -44,6 +45,7 @@ public:
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 @@ private:
uint32_t* m_drawContext;
GBAThread m_threadContext;
GBAVideoSoftwareRenderer* m_renderer;
GBACheatDevice m_cheatDevice;
int m_activeKeys;
int m_logLevels;

View File

@ -14,6 +14,7 @@
#include <QMimeData>
#include <QStackedLayout>
#include "CheatsView.h"
#include "ConfigController.h"
#include "GameController.h"
#include "GBAKeyEditor.h"
@ -231,6 +232,7 @@ void Window::openOverrideWindow() {
overrideWindow->setAttribute(Qt::WA_DeleteOnClose);
overrideWindow->show();
}
void Window::openSensorWindow() {
SensorView* sensorWindow = new SensorView(m_controller);
connect(this, SIGNAL(shutdown()), sensorWindow, SLOT(close()));
@ -238,6 +240,13 @@ void Window::openSensorWindow() {
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
void Window::openGamepadWindow() {
GBAKeyEditor* keyEditor = new GBAKeyEditor(&m_inputController, SDL_BINDING_BUTTON);
@ -683,6 +692,10 @@ void Window::setupMenu(QMenuBar* menubar) {
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);
connect(gdbWindow, SIGNAL(triggered()), this, SLOT(gdbOpen()));

View File

@ -69,6 +69,7 @@ public slots:
void openOverrideWindow();
void openSensorWindow();
void openCheatsWindow();
#ifdef BUILD_SDL
void openGamepadWindow();