Qt: Enable savestates for GB games

This commit is contained in:
Jeffrey Pfau 2016-05-30 23:24:39 -07:00
parent 5ea104844d
commit 61b4d53150
3 changed files with 7 additions and 64 deletions

View File

@ -43,10 +43,13 @@ LoadSaveState::LoadSaveState(GameController* controller, QWidget* parent)
m_slots[7] = m_ui.state8;
m_slots[8] = m_ui.state9;
unsigned width, height;
controller->thread()->core->desiredVideoDimensions(controller->thread()->core, &width, &height);
int i;
for (i = 0; i < NUM_SLOTS; ++i) {
loadState(i + 1);
m_slots[i]->installEventFilter(this);
m_slots[i]->setMaximumSize(width + 2, height + 2);
connect(m_slots[i], &QAbstractButton::clicked, this, [this, i]() { triggerState(i + 1); });
}
@ -192,9 +195,11 @@ void LoadSaveState::loadState(int slot) {
QDateTime creation/*(QDateTime::fromMSecsSinceEpoch(state->creationUsec / 1000LL))*/; // TODO
QImage stateImage;
unsigned width, height;
thread->core->desiredVideoDimensions(thread->core, &width, &height);
mStateExtdataItem item;
if (mStateExtdataGet(&extdata, EXTDATA_SCREENSHOT, &item) && item.size >= VIDEO_HORIZONTAL_PIXELS * VIDEO_VERTICAL_PIXELS * 4) {
stateImage = QImage((uchar*) item.data, VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS, QImage::Format_ARGB32).rgbSwapped();
if (mStateExtdataGet(&extdata, EXTDATA_SCREENSHOT, &item) && item.size >= width * height * 4) {
stateImage = QImage((uchar*) item.data, width, height, QImage::Format_ARGB32).rgbSwapped();
}
if (!stateImage.isNull()) {

View File

@ -37,12 +37,6 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>242</width>
<height>162</height>
</size>
</property>
<property name="text">
<string>No Save</string>
</property>
@ -65,12 +59,6 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>242</width>
<height>162</height>
</size>
</property>
<property name="text">
<string>No Save</string>
</property>
@ -115,12 +103,6 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>242</width>
<height>162</height>
</size>
</property>
<property name="text">
<string>No Save</string>
</property>
@ -143,12 +125,6 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>242</width>
<height>162</height>
</size>
</property>
<property name="text">
<string>No Save</string>
</property>
@ -171,12 +147,6 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>242</width>
<height>162</height>
</size>
</property>
<property name="text">
<string>No Save</string>
</property>
@ -199,12 +169,6 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>242</width>
<height>162</height>
</size>
</property>
<property name="text">
<string>No Save</string>
</property>
@ -227,12 +191,6 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>242</width>
<height>162</height>
</size>
</property>
<property name="text">
<string>No Save</string>
</property>
@ -255,12 +213,6 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>242</width>
<height>162</height>
</size>
</property>
<property name="text">
<string>No Save</string>
</property>
@ -283,12 +235,6 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>242</width>
<height>162</height>
</size>
</property>
<property name="text">
<string>No Save</string>
</property>

View File

@ -836,7 +836,6 @@ void Window::setupMenu(QMenuBar* menubar) {
connect(loadState, &QAction::triggered, [this]() { this->openStateWindow(LoadSave::LOAD); });
m_gameActions.append(loadState);
m_nonMpActions.append(loadState);
m_gbaActions.append(loadState);
addControlledAction(fileMenu, loadState, "loadState");
QAction* saveState = new QAction(tr("&Save state"), fileMenu);
@ -844,7 +843,6 @@ void Window::setupMenu(QMenuBar* menubar) {
connect(saveState, &QAction::triggered, [this]() { this->openStateWindow(LoadSave::SAVE); });
m_gameActions.append(saveState);
m_nonMpActions.append(saveState);
m_gbaActions.append(saveState);
addControlledAction(fileMenu, saveState, "saveState");
QMenu* quickLoadMenu = fileMenu->addMenu(tr("Quick load"));
@ -856,14 +854,12 @@ void Window::setupMenu(QMenuBar* menubar) {
connect(quickLoad, SIGNAL(triggered()), m_controller, SLOT(loadState()));
m_gameActions.append(quickLoad);
m_nonMpActions.append(quickLoad);
m_gbaActions.append(quickLoad);
addControlledAction(quickLoadMenu, quickLoad, "quickLoad");
QAction* quickSave = new QAction(tr("Save recent"), quickSaveMenu);
connect(quickSave, SIGNAL(triggered()), m_controller, SLOT(saveState()));
m_gameActions.append(quickSave);
m_nonMpActions.append(quickSave);
m_gbaActions.append(quickSave);
addControlledAction(quickSaveMenu, quickSave, "quickSave");
quickLoadMenu->addSeparator();
@ -874,7 +870,6 @@ void Window::setupMenu(QMenuBar* menubar) {
connect(undoLoadState, SIGNAL(triggered()), m_controller, SLOT(loadBackupState()));
m_gameActions.append(undoLoadState);
m_nonMpActions.append(undoLoadState);
m_gbaActions.append(undoLoadState);
addControlledAction(quickLoadMenu, undoLoadState, "undoLoadState");
QAction* undoSaveState = new QAction(tr("Undo save state"), quickSaveMenu);
@ -882,7 +877,6 @@ void Window::setupMenu(QMenuBar* menubar) {
connect(undoSaveState, SIGNAL(triggered()), m_controller, SLOT(saveBackupState()));
m_gameActions.append(undoSaveState);
m_nonMpActions.append(undoSaveState);
m_gbaActions.append(undoSaveState);
addControlledAction(quickSaveMenu, undoSaveState, "undoSaveState");
quickLoadMenu->addSeparator();
@ -895,7 +889,6 @@ void Window::setupMenu(QMenuBar* menubar) {
connect(quickLoad, &QAction::triggered, [this, i]() { m_controller->loadState(i); });
m_gameActions.append(quickLoad);
m_nonMpActions.append(quickLoad);
m_gbaActions.append(quickLoad);
addControlledAction(quickLoadMenu, quickLoad, QString("quickLoad.%1").arg(i));
quickSave = new QAction(tr("State &%1").arg(i), quickSaveMenu);
@ -903,7 +896,6 @@ void Window::setupMenu(QMenuBar* menubar) {
connect(quickSave, &QAction::triggered, [this, i]() { m_controller->saveState(i); });
m_gameActions.append(quickSave);
m_nonMpActions.append(quickSave);
m_gbaActions.append(quickSave);
addControlledAction(quickSaveMenu, quickSave, QString("quickSave.%1").arg(i));
}