Skip to content

Commit

Permalink
Qt: Add prompt to enable cheats when list is checked
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Nov 3, 2024
1 parent d416ecb commit 8f087ab
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/duckstation-qt/gamecheatsettingswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ void GameCheatSettingsWidget::onCheatListItemChanged(QTreeWidgetItem* item, int
if (current_enabled == current_checked)
return;

if (current_checked)
checkForMasterDisable();

setCheatEnabled(std::move(cheat_name), current_checked, true);
}

Expand Down Expand Up @@ -337,6 +340,33 @@ bool GameCheatSettingsWidget::shouldLoadFromDatabase() const
return m_dialog->getSettingsInterface()->GetBoolValue("Cheats", "LoadCheatsFromDatabase", true);
}

void GameCheatSettingsWidget::checkForMasterDisable()
{
if (m_dialog->getSettingsInterface()->GetBoolValue("Cheats", "EnableCheats", false) || m_master_enable_ignored)
return;

QMessageBox mbox;
mbox.setIcon(QMessageBox::Warning);
mbox.setWindowTitle(tr("Confirm Cheat Enable"));
mbox.setWindowIcon(QtHost::GetAppIcon());
mbox.setTextFormat(Qt::RichText);
mbox.setText(tr("<h3>Cheats are not currently enabled for this game.</h3><p>Enabling this cheat will not have any "
"effect until cheats are enabled for this game. Do you want to do this now?"));

mbox.addButton(QMessageBox::Yes);
mbox.addButton(QMessageBox::No);

QCheckBox* cb = new QCheckBox(&mbox);
cb->setText(tr("Do not show again"));
mbox.setCheckBox(cb);

const int res = mbox.exec();
if (res == QMessageBox::No)
m_master_enable_ignored = cb->isChecked();
else
m_ui.enableCheats->setChecked(true);
}

Cheats::CodeInfo* GameCheatSettingsWidget::getSelectedCode()
{
const QList<QTreeWidgetItem*> selected = m_ui.cheatList->selectedItems();
Expand Down
3 changes: 3 additions & 0 deletions src/duckstation-qt/gamecheatsettingswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ private Q_SLOTS:

private:
bool shouldLoadFromDatabase() const;
void checkForMasterDisable();

Cheats::CodeInfo* getSelectedCode();
QTreeWidgetItem* getTreeWidgetParent(const std::string_view parent);
Expand All @@ -78,6 +79,8 @@ private Q_SLOTS:
UnorderedStringMap<QTreeWidgetItem*> m_parent_map;
Cheats::CodeInfoList m_codes;
std::vector<std::string> m_enabled_codes;

bool m_master_enable_ignored = false;
};

class CheatCodeEditorDialog : public QDialog
Expand Down

0 comments on commit 8f087ab

Please # to comment.