Qt: Fix up override view

This commit is contained in:
Vicki Pfau 2017-10-13 18:40:49 -07:00
parent 22807c6274
commit b920758dc1
5 changed files with 26 additions and 1 deletions

View File

@ -209,6 +209,10 @@ bool CoreController::isPaused() {
return mCoreThreadIsPaused(&m_threadContext); return mCoreThreadIsPaused(&m_threadContext);
} }
bool CoreController::hasStarted() {
return mCoreThreadHasStarted(&m_threadContext);
}
mPlatform CoreController::platform() const { mPlatform CoreController::platform() const {
return m_threadContext.core->platform(m_threadContext.core); return m_threadContext.core->platform(m_threadContext.core);
} }

View File

@ -61,6 +61,7 @@ public:
color_t* drawContext(); color_t* drawContext();
bool isPaused(); bool isPaused();
bool hasStarted();
mPlatform platform() const; mPlatform platform() const;
QSize screenDimensions() const; QSize screenDimensions() const;

View File

@ -93,13 +93,16 @@ OverrideView::OverrideView(ConfigController* config, QWidget* parent)
connect(m_ui.buttonBox, &QDialogButtonBox::accepted, this, &OverrideView::saveOverride); connect(m_ui.buttonBox, &QDialogButtonBox::accepted, this, &OverrideView::saveOverride);
connect(m_ui.buttonBox, &QDialogButtonBox::rejected, this, &QWidget::close); connect(m_ui.buttonBox, &QDialogButtonBox::rejected, this, &QWidget::close);
m_recheck.setInterval(200);
connect(&m_recheck, &QTimer::timeout, this, &OverrideView::recheck);
} }
void OverrideView::setController(std::shared_ptr<CoreController> controller) { void OverrideView::setController(std::shared_ptr<CoreController> controller) {
m_controller = controller; m_controller = controller;
connect(controller.get(), &CoreController::started, this, &OverrideView::gameStarted); connect(controller.get(), &CoreController::started, this, &OverrideView::gameStarted);
connect(controller.get(), &CoreController::stopping, this, &OverrideView::gameStopped); connect(controller.get(), &CoreController::stopping, this, &OverrideView::gameStopped);
updateOverrides(); recheck();
} }
void OverrideView::saveOverride() { void OverrideView::saveOverride() {
@ -115,6 +118,17 @@ void OverrideView::saveOverride() {
m_config->saveOverride(*override); m_config->saveOverride(*override);
} }
void OverrideView::recheck() {
if (!m_controller) {
return;
}
if (m_controller->hasStarted()) {
gameStarted();
} else {
updateOverrides();
}
}
void OverrideView::updateOverrides() { void OverrideView::updateOverrides() {
if (!m_controller) { if (!m_controller) {
return; return;
@ -190,6 +204,7 @@ void OverrideView::gameStarted() {
mCoreThread* thread = m_controller->thread(); mCoreThread* thread = m_controller->thread();
m_ui.tabWidget->setEnabled(false); m_ui.tabWidget->setEnabled(false);
m_recheck.start();
switch (thread->core->platform(thread->core)) { switch (thread->core->platform(thread->core)) {
#ifdef M_CORE_GBA #ifdef M_CORE_GBA
@ -242,6 +257,7 @@ void OverrideView::gameStarted() {
} }
void OverrideView::gameStopped() { void OverrideView::gameStopped() {
m_recheck.stop();
m_controller.reset(); m_controller.reset();
m_ui.tabWidget->setEnabled(true); m_ui.tabWidget->setEnabled(true);
m_ui.savetype->setCurrentIndex(0); m_ui.savetype->setCurrentIndex(0);

View File

@ -6,6 +6,7 @@
#pragma once #pragma once
#include <QDialog> #include <QDialog>
#include <QTimer>
#include <memory> #include <memory>
@ -36,6 +37,7 @@ public:
public slots: public slots:
void saveOverride(); void saveOverride();
void recheck();
private slots: private slots:
void updateOverrides(); void updateOverrides();
@ -48,6 +50,7 @@ private:
std::shared_ptr<CoreController> m_controller; std::shared_ptr<CoreController> m_controller;
ConfigController* m_config; ConfigController* m_config;
bool m_savePending = false; bool m_savePending = false;
QTimer m_recheck;
#ifdef M_CORE_GB #ifdef M_CORE_GB
uint32_t m_gbColors[12]{}; uint32_t m_gbColors[12]{};

View File

@ -1442,6 +1442,7 @@ void Window::setupMenu(QMenuBar* menubar) {
connect(this, &Window::shutdown, m_overrideView.get(), &QWidget::close); connect(this, &Window::shutdown, m_overrideView.get(), &QWidget::close);
} }
m_overrideView->show(); m_overrideView->show();
m_overrideView->recheck();
}); });
addControlledAction(toolsMenu, overrides, "overrideWindow"); addControlledAction(toolsMenu, overrides, "overrideWindow");