Qt: Add Set Cover Image/Edit Memory Cards for merged disc sets

This commit is contained in:
Stenzek 2024-05-21 13:54:19 +10:00
parent 08125262bb
commit f9b58c4077
No known key found for this signature in database

View file

@ -767,42 +767,48 @@ void MainWindow::destroySubWindows()
void MainWindow::populateGameListContextMenu(const GameList::Entry* entry, QWidget* parent_window, QMenu* menu) void MainWindow::populateGameListContextMenu(const GameList::Entry* entry, QWidget* parent_window, QMenu* menu)
{ {
QAction* resume_action = menu->addAction(tr("Resume")); QAction* resume_action = nullptr;
resume_action->setEnabled(false); QMenu* load_state_menu = nullptr;
QMenu* load_state_menu = menu->addMenu(tr("Load State")); if (!entry->IsDiscSet())
load_state_menu->setEnabled(false);
if (!entry->serial.empty())
{ {
std::vector<SaveStateInfo> available_states(System::GetAvailableSaveStates(entry->serial.c_str())); resume_action = menu->addAction(tr("Resume"));
const QString timestamp_format = QLocale::system().dateTimeFormat(QLocale::ShortFormat); resume_action->setEnabled(false);
const bool challenge_mode = Achievements::IsHardcoreModeActive();
for (SaveStateInfo& ssi : available_states)
{
if (ssi.global)
continue;
const s32 slot = ssi.slot; load_state_menu = menu->addMenu(tr("Load State"));
const QDateTime timestamp(QDateTime::fromSecsSinceEpoch(static_cast<qint64>(ssi.timestamp))); load_state_menu->setEnabled(false);
const QString timestamp_str(timestamp.toString(timestamp_format));
QAction* action; if (!entry->serial.empty())
if (slot < 0) {
{ std::vector<SaveStateInfo> available_states(System::GetAvailableSaveStates(entry->serial.c_str()));
resume_action->setText(tr("Resume (%1)").arg(timestamp_str)); const QString timestamp_format = QLocale::system().dateTimeFormat(QLocale::ShortFormat);
resume_action->setEnabled(!challenge_mode); const bool challenge_mode = Achievements::IsHardcoreModeActive();
action = resume_action; for (SaveStateInfo& ssi : available_states)
}
else
{ {
load_state_menu->setEnabled(true); if (ssi.global)
action = load_state_menu->addAction(tr("Game Save %1 (%2)").arg(slot).arg(timestamp_str)); continue;
}
action->setDisabled(challenge_mode); const s32 slot = ssi.slot;
connect(action, &QAction::triggered, const QDateTime timestamp(QDateTime::fromSecsSinceEpoch(static_cast<qint64>(ssi.timestamp)));
[this, entry, path = std::move(ssi.path)]() { startFile(entry->path, std::move(path), std::nullopt); }); const QString timestamp_str(timestamp.toString(timestamp_format));
QAction* action;
if (slot < 0)
{
resume_action->setText(tr("Resume (%1)").arg(timestamp_str));
resume_action->setEnabled(!challenge_mode);
action = resume_action;
}
else
{
load_state_menu->setEnabled(true);
action = load_state_menu->addAction(tr("Game Save %1 (%2)").arg(slot).arg(timestamp_str));
}
action->setDisabled(challenge_mode);
connect(action, &QAction::triggered,
[this, entry, path = std::move(ssi.path)]() { startFile(entry->path, std::move(path), std::nullopt); });
}
} }
} }
@ -815,23 +821,26 @@ void MainWindow::populateGameListContextMenu(const GameList::Entry* entry, QWidg
g_main_window->openMemoryCardEditor(paths[0], paths[1]); g_main_window->openMemoryCardEditor(paths[0], paths[1]);
}); });
const bool has_any_states = resume_action->isEnabled() || load_state_menu->isEnabled(); if (!entry->IsDiscSet())
QAction* delete_save_states_action = menu->addAction(tr("Delete Save States...")); {
delete_save_states_action->setEnabled(has_any_states); const bool has_any_states = resume_action->isEnabled() || load_state_menu->isEnabled();
if (has_any_states) QAction* delete_save_states_action = menu->addAction(tr("Delete Save States..."));
{ delete_save_states_action->setEnabled(has_any_states);
connect(delete_save_states_action, &QAction::triggered, [parent_window, entry] { if (has_any_states)
if (QMessageBox::warning( {
parent_window, tr("Confirm Save State Deletion"), connect(delete_save_states_action, &QAction::triggered, [parent_window, entry] {
tr("Are you sure you want to delete all save states for %1?\n\nThe saves will not be recoverable.") if (QMessageBox::warning(
.arg(QString::fromStdString(entry->serial)), parent_window, tr("Confirm Save State Deletion"),
QMessageBox::Yes, QMessageBox::No) != QMessageBox::Yes) tr("Are you sure you want to delete all save states for %1?\n\nThe saves will not be recoverable.")
{ .arg(QString::fromStdString(entry->serial)),
return; QMessageBox::Yes, QMessageBox::No) != QMessageBox::Yes)
} {
return;
}
System::DeleteSaveStates(entry->serial.c_str(), true); System::DeleteSaveStates(entry->serial.c_str(), true);
}); });
}
} }
} }
@ -1511,12 +1520,21 @@ void MainWindow::onGameListEntryContextMenuRequested(const QPoint& point)
SettingsWindow::openGamePropertiesDialog(first_disc->path, first_disc->serial, first_disc->region); SettingsWindow::openGamePropertiesDialog(first_disc->path, first_disc->serial, first_disc->region);
}); });
connect(menu.addAction(tr("Set Cover Image...")), &QAction::triggered,
[this, entry]() { setGameListEntryCoverImage(entry); });
menu.addSeparator();
populateGameListContextMenu(entry, this, &menu);
menu.addSeparator(); menu.addSeparator();
connect(menu.addAction(tr("Select Disc")), &QAction::triggered, this, &MainWindow::onGameListEntryActivated); connect(menu.addAction(tr("Select Disc")), &QAction::triggered, this, &MainWindow::onGameListEntryActivated);
} }
} }
menu.addSeparator();
connect(menu.addAction(tr("Add Search Directory...")), &QAction::triggered, connect(menu.addAction(tr("Add Search Directory...")), &QAction::triggered,
[this]() { getSettingsDialog()->getGameListSettingsWidget()->addSearchDirectory(this); }); [this]() { getSettingsDialog()->getGameListSettingsWidget()->addSearchDirectory(this); });