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) load_state_menu = menu->addMenu(tr("Load State"));
load_state_menu->setEnabled(false);
if (!entry->serial.empty())
{ {
if (ssi.global) std::vector<SaveStateInfo> available_states(System::GetAvailableSaveStates(entry->serial.c_str()));
continue; const QString timestamp_format = QLocale::system().dateTimeFormat(QLocale::ShortFormat);
const bool challenge_mode = Achievements::IsHardcoreModeActive();
const s32 slot = ssi.slot; for (SaveStateInfo& ssi : available_states)
const QDateTime timestamp(QDateTime::fromSecsSinceEpoch(static_cast<qint64>(ssi.timestamp)));
const QString timestamp_str(timestamp.toString(timestamp_format));
QAction* action;
if (slot < 0)
{ {
resume_action->setText(tr("Resume (%1)").arg(timestamp_str)); if (ssi.global)
resume_action->setEnabled(!challenge_mode); continue;
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); 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);
if (has_any_states)
{ {
connect(delete_save_states_action, &QAction::triggered, [parent_window, entry] { const bool has_any_states = resume_action->isEnabled() || load_state_menu->isEnabled();
if (QMessageBox::warning( QAction* delete_save_states_action = menu->addAction(tr("Delete Save States..."));
parent_window, tr("Confirm Save State Deletion"), delete_save_states_action->setEnabled(has_any_states);
tr("Are you sure you want to delete all save states for %1?\n\nThe saves will not be recoverable.") if (has_any_states)
.arg(QString::fromStdString(entry->serial)), {
QMessageBox::Yes, QMessageBox::No) != QMessageBox::Yes) connect(delete_save_states_action, &QAction::triggered, [parent_window, entry] {
{ if (QMessageBox::warning(
return; parent_window, tr("Confirm Save State Deletion"),
} 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)),
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); });