Qt: Update window title/save states from running title

This commit is contained in:
Connor McLaughlin
2020-01-24 14:50:46 +10:00
parent 82b4229f1b
commit 20b60e0f01
9 changed files with 102 additions and 33 deletions

View File

@@ -42,7 +42,6 @@ void MainWindow::onEmulationStarted()
{
m_emulation_running = true;
updateEmulationActions(false, true);
populateLoadSaveStateMenus(QString());
}
void MainWindow::onEmulationStopped()
@@ -121,6 +120,15 @@ void MainWindow::onPerformanceCountersUpdated(float speed, float fps, float vps,
QStringLiteral("%1ms average, %2ms worst").arg(average_frame_time, 0, 'f', 2).arg(worst_frame_time, 0, 'f', 2));
}
void MainWindow::onRunningGameChanged(QString filename, QString game_code, QString game_title)
{
populateLoadSaveStateMenus(game_code);
if (game_title.isEmpty())
setWindowTitle(tr("DuckStation"));
else
setWindowTitle(game_title);
}
void MainWindow::onStartDiscActionTriggered()
{
QString filename =
@@ -288,10 +296,11 @@ void MainWindow::connectSignals()
connect(m_host_interface, &QtHostInterface::emulationStopped, this, &MainWindow::onEmulationStopped);
connect(m_host_interface, &QtHostInterface::emulationPaused, this, &MainWindow::onEmulationPaused);
connect(m_host_interface, &QtHostInterface::toggleFullscreenRequested, this, &MainWindow::toggleFullscreen);
connect(m_host_interface, &QtHostInterface::performanceCountersUpdated, this,
&MainWindow::onPerformanceCountersUpdated);
connect(m_host_interface, &QtHostInterface::recreateDisplayWidgetRequested, this, &MainWindow::recreateDisplayWidget,
Qt::BlockingQueuedConnection);
connect(m_host_interface, &QtHostInterface::performanceCountersUpdated, this,
&MainWindow::onPerformanceCountersUpdated);
connect(m_host_interface, &QtHostInterface::runningGameChanged, this, &MainWindow::onRunningGameChanged);
connect(m_game_list_widget, &GameListWidget::bootEntryRequested, [this](const GameListEntry* entry) {
// if we're not running, boot the system, otherwise swap discs
@@ -370,23 +379,18 @@ void MainWindow::populateLoadSaveStateMenus(QString game_code)
{
// TODO: Do we want to test for the existance of these on disk here?
load_menu->addAction(tr("Global Save %1 (2020-01-01 00:01:02)").arg(i + 1));
if (m_emulation_running)
save_menu->addAction(tr("Global Save %1").arg(i + 1));
save_menu->addAction(tr("Global Save %1").arg(i + 1));
}
if (!game_code.isEmpty())
{
load_menu->addSeparator();
if (m_emulation_running)
save_menu->addSeparator();
save_menu->addSeparator();
for (int i = 0; i < NUM_SAVE_STATE_SLOTS; i++)
{
load_menu->addAction(tr("Game Save %1 (2020-01-01 00:01:02)").arg(i + 1));
if (m_emulation_running)
save_menu->addAction(tr("Game Save %1").arg(i + 1));
save_menu->addAction(tr("Game Save %1").arg(i + 1));
}
}
}

View File

@@ -9,7 +9,6 @@
class QLabel;
class GameList;
class GameListWidget;
class QtHostInterface;
@@ -30,6 +29,7 @@ private Q_SLOTS:
void recreateDisplayWidget(bool create_device_context);
void onPerformanceCountersUpdated(float speed, float fps, float vps, float average_frame_time,
float worst_frame_time);
void onRunningGameChanged(QString filename, QString game_code, QString game_title);
void onStartDiscActionTriggered();
void onChangeDiscFromFileActionTriggered();
@@ -55,7 +55,6 @@ private:
QtHostInterface* m_host_interface = nullptr;
std::unique_ptr<GameList> m_game_list;
GameListWidget* m_game_list_widget = nullptr;
QWidget* m_display_widget = nullptr;

View File

@@ -162,6 +162,7 @@ void QtHostInterface::createGameList()
void QtHostInterface::refreshGameList(bool invalidate_cache /* = false */, bool invalidate_database /* = false */)
{
std::lock_guard<std::mutex> lock(m_qsettings_mutex);
QtSettingsInterface si(m_qsettings);
m_game_list->SetPathsFromSettings(si);
m_game_list->Refresh(invalidate_cache, invalidate_database);
@@ -243,6 +244,13 @@ void QtHostInterface::OnPerformanceCountersUpdated()
emit performanceCountersUpdated(m_speed, m_fps, m_vps, m_average_frame_time, m_worst_frame_time);
}
void QtHostInterface::OnRunningGameChanged(const char* path, const char* game_code, const char* game_title)
{
HostInterface::OnRunningGameChanged(path, game_code, game_title);
emit runningGameChanged(QString::fromUtf8(path), QString::fromUtf8(game_code), QString::fromUtf8(game_title));
}
void QtHostInterface::updateInputMap()
{
if (!isOnWorkerThread())
@@ -390,6 +398,7 @@ void QtHostInterface::powerOffSystem()
m_audio_stream->PauseOutput(true);
m_display_window->destroyDeviceContext();
emit runningGameChanged(QString(), QString(), QString());
emit emulationStopped();
}
@@ -437,6 +446,7 @@ void QtHostInterface::doBootSystem(QString initial_filename, QString initial_sav
std::string initial_filename_str = initial_filename.toStdString();
std::string initial_save_state_filename_str = initial_save_state_filename.toStdString();
std::lock_guard<std::mutex> lock(m_qsettings_mutex);
if (!CreateSystem() ||
!BootSystem(initial_filename_str.empty() ? nullptr : initial_filename_str.c_str(),
initial_save_state_filename_str.empty() ? nullptr : initial_save_state_filename_str.c_str()))
@@ -501,6 +511,7 @@ void QtHostInterface::switchGPURenderer()
{
if (!m_display_window->initializeDeviceContext(m_settings.gpu_use_debug_device))
{
emit runningGameChanged(QString(), QString(), QString());
emit emulationStopped();
return;
}

View File

@@ -70,6 +70,7 @@ Q_SIGNALS:
void toggleFullscreenRequested();
void recreateDisplayWidgetRequested(bool create_device_context);
void performanceCountersUpdated(float speed, float fps, float vps, float avg_frame_time, float worst_frame_time);
void runningGameChanged(QString filename, QString game_code, QString game_title);
public Q_SLOTS:
void applySettings();
@@ -87,6 +88,7 @@ private Q_SLOTS:
protected:
void OnPerformanceCountersUpdated() override;
void OnRunningGameChanged(const char* path, const char* game_code, const char* game_title) override;
private:
using InputButtonHandler = std::function<void(bool)>;
@@ -126,8 +128,6 @@ private:
QSettings m_qsettings;
std::mutex m_qsettings_mutex;
std::unique_ptr<GameList> m_game_list;
QtDisplayWindow* m_display_window = nullptr;
QThread* m_original_thread = nullptr;
Thread* m_worker_thread = nullptr;