dolphin/Source/Core/DolphinQt/CheatsManager.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

123 lines
3.6 KiB
C++
Raw Normal View History

2018-03-26 02:17:47 +00:00
// Copyright 2018 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
2018-03-26 02:17:47 +00:00
2018-07-06 22:40:15 +00:00
#include "DolphinQt/CheatsManager.h"
2018-03-26 02:17:47 +00:00
2021-08-22 05:13:00 +00:00
#include <functional>
2018-03-26 02:17:47 +00:00
#include <QDialogButtonBox>
#include <QVBoxLayout>
#include "Core/ActionReplay.h"
2021-08-22 05:13:00 +00:00
#include "Core/CheatSearch.h"
2018-03-26 02:17:47 +00:00
#include "Core/ConfigManager.h"
#include "Core/Core.h"
2018-05-28 01:48:04 +00:00
2018-03-26 02:17:47 +00:00
#include "UICommon/GameFile.h"
2021-08-22 05:13:00 +00:00
#include "DolphinQt/CheatSearchFactoryWidget.h"
#include "DolphinQt/CheatSearchWidget.h"
2018-07-06 22:40:15 +00:00
#include "DolphinQt/Config/ARCodeWidget.h"
#include "DolphinQt/Config/GeckoCodeWidget.h"
#include "DolphinQt/Settings.h"
2021-08-22 05:13:00 +00:00
#include "QtUtils/PartiallyClosableTabWidget.h"
CheatsManager::CheatsManager(QWidget* parent) : QDialog(parent)
2018-03-26 02:17:47 +00:00
{
setWindowTitle(tr("Cheats Manager"));
2018-05-05 00:29:16 +00:00
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
2018-03-26 02:17:47 +00:00
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this,
&CheatsManager::OnStateChanged);
OnStateChanged(Core::GetState());
CreateWidgets();
ConnectWidgets();
}
CheatsManager::~CheatsManager() = default;
2018-03-26 02:17:47 +00:00
void CheatsManager::OnStateChanged(Core::State state)
{
if (state != Core::State::Running && state != Core::State::Paused)
return;
const auto& game_id = SConfig::GetInstance().GetGameID();
const auto& game_tdb_id = SConfig::GetInstance().GetGameTDBID();
2021-08-22 05:13:00 +00:00
const u16 revision = SConfig::GetInstance().GetRevision();
if (m_game_id == game_id && m_game_tdb_id == game_tdb_id && m_revision == revision)
return;
m_game_id = game_id;
m_game_tdb_id = game_tdb_id;
m_revision = revision;
2021-08-22 05:13:00 +00:00
if (m_ar_code)
2018-03-26 02:17:47 +00:00
{
2021-08-22 05:13:00 +00:00
const int tab_index = m_tab_widget->indexOf(m_ar_code);
if (tab_index != -1)
m_tab_widget->removeTab(tab_index);
m_ar_code->deleteLater();
m_ar_code = nullptr;
}
2018-03-26 02:17:47 +00:00
2021-08-22 05:13:00 +00:00
if (m_gecko_code)
{
2021-08-22 05:13:00 +00:00
const int tab_index = m_tab_widget->indexOf(m_gecko_code);
if (tab_index != -1)
m_tab_widget->removeTab(tab_index);
m_gecko_code->deleteLater();
m_gecko_code = nullptr;
2018-03-26 02:17:47 +00:00
}
2021-08-22 05:13:00 +00:00
m_ar_code = new ARCodeWidget(m_game_id, m_revision, false);
m_gecko_code = new GeckoCodeWidget(m_game_id, m_game_tdb_id, m_revision, false);
m_tab_widget->insertTab(0, m_ar_code, tr("AR Code"));
m_tab_widget->insertTab(1, m_gecko_code, tr("Gecko Codes"));
m_tab_widget->setTabUnclosable(0);
m_tab_widget->setTabUnclosable(1);
2018-03-26 02:17:47 +00:00
}
void CheatsManager::CreateWidgets()
{
2021-08-22 05:13:00 +00:00
m_tab_widget = new PartiallyClosableTabWidget;
2018-03-26 02:17:47 +00:00
m_button_box = new QDialogButtonBox(QDialogButtonBox::Close);
2021-08-22 05:13:00 +00:00
m_cheat_search_new = new CheatSearchFactoryWidget();
m_tab_widget->addTab(m_cheat_search_new, tr("Start New Cheat Search"));
m_tab_widget->setTabUnclosable(0);
2018-03-26 02:17:47 +00:00
auto* layout = new QVBoxLayout;
layout->addWidget(m_tab_widget);
layout->addWidget(m_button_box);
setLayout(layout);
}
2021-08-22 05:13:00 +00:00
void CheatsManager::OnNewSessionCreated(const Cheats::CheatSearchSessionBase& session)
2018-03-26 02:17:47 +00:00
{
2021-08-22 05:13:00 +00:00
auto* w = new CheatSearchWidget(session.Clone());
const int tab_index = m_tab_widget->addTab(w, tr("Cheat Search"));
w->connect(w, &CheatSearchWidget::ActionReplayCodeGenerated, this,
[this](const ActionReplay::ARCode& ar_code) {
if (m_ar_code)
m_ar_code->AddCode(ar_code);
});
m_tab_widget->setCurrentIndex(tab_index);
2018-03-26 02:17:47 +00:00
}
2021-08-22 05:13:00 +00:00
void CheatsManager::OnTabCloseRequested(int index)
2018-03-26 02:17:47 +00:00
{
2021-08-22 05:13:00 +00:00
m_tab_widget->removeTab(index);
2018-03-26 02:17:47 +00:00
}
2021-08-22 05:13:00 +00:00
void CheatsManager::ConnectWidgets()
2018-03-26 02:17:47 +00:00
{
2021-08-22 05:13:00 +00:00
connect(m_button_box, &QDialogButtonBox::rejected, this, &QDialog::reject);
connect(m_cheat_search_new, &CheatSearchFactoryWidget::NewSessionCreated, this,
&CheatsManager::OnNewSessionCreated);
connect(m_tab_widget, &QTabWidget::tabCloseRequested, this, &CheatsManager::OnTabCloseRequested);
2018-03-26 02:17:47 +00:00
}