Merge pull request #12966 from Dentomologist/cheatsmanager_create_code_widgets_only_once
CheatsManager: Create Action Replay and Gecko code widgets only once
This commit is contained in:
commit
2c15d7af7f
|
@ -36,8 +36,6 @@ CheatsManager::CheatsManager(Core::System& system, QWidget* parent)
|
||||||
CreateWidgets();
|
CreateWidgets();
|
||||||
ConnectWidgets();
|
ConnectWidgets();
|
||||||
|
|
||||||
RefreshCodeTabs(Core::GetState(m_system), true);
|
|
||||||
|
|
||||||
auto& settings = Settings::GetQSettings();
|
auto& settings = Settings::GetQSettings();
|
||||||
restoreGeometry(settings.value(QStringLiteral("cheatsmanager/geometry")).toByteArray());
|
restoreGeometry(settings.value(QStringLiteral("cheatsmanager/geometry")).toByteArray());
|
||||||
}
|
}
|
||||||
|
@ -50,7 +48,7 @@ CheatsManager::~CheatsManager()
|
||||||
|
|
||||||
void CheatsManager::OnStateChanged(Core::State state)
|
void CheatsManager::OnStateChanged(Core::State state)
|
||||||
{
|
{
|
||||||
RefreshCodeTabs(state, false);
|
RefreshCodeTabs(state);
|
||||||
if (state == Core::State::Paused)
|
if (state == Core::State::Paused)
|
||||||
UpdateAllCheatSearchWidgetCurrentValues();
|
UpdateAllCheatSearchWidgetCurrentValues();
|
||||||
}
|
}
|
||||||
|
@ -99,9 +97,9 @@ void CheatsManager::showEvent(QShowEvent* event)
|
||||||
RegisterAfterFrameEventCallback();
|
RegisterAfterFrameEventCallback();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheatsManager::RefreshCodeTabs(Core::State state, bool force)
|
void CheatsManager::RefreshCodeTabs(Core::State state)
|
||||||
{
|
{
|
||||||
if (!force && (state == Core::State::Starting || state == Core::State::Stopping))
|
if (state == Core::State::Starting || state == Core::State::Stopping)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const auto& game_id =
|
const auto& game_id =
|
||||||
|
@ -109,47 +107,15 @@ void CheatsManager::RefreshCodeTabs(Core::State state, bool force)
|
||||||
const auto& game_tdb_id = SConfig::GetInstance().GetGameTDBID();
|
const auto& game_tdb_id = SConfig::GetInstance().GetGameTDBID();
|
||||||
const u16 revision = SConfig::GetInstance().GetRevision();
|
const u16 revision = SConfig::GetInstance().GetRevision();
|
||||||
|
|
||||||
if (!force && m_game_id == game_id && m_game_tdb_id == game_tdb_id && m_revision == revision)
|
if (m_game_id == game_id && m_game_tdb_id == game_tdb_id && m_revision == revision)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_game_id = game_id;
|
m_game_id = game_id;
|
||||||
m_game_tdb_id = game_tdb_id;
|
m_game_tdb_id = game_tdb_id;
|
||||||
m_revision = revision;
|
m_revision = revision;
|
||||||
|
|
||||||
if (m_ar_code)
|
m_ar_code->ChangeGame(m_game_id, m_revision);
|
||||||
{
|
m_gecko_code->ChangeGame(m_game_id, m_game_tdb_id, m_revision);
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_gecko_code)
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
connect(m_ar_code, &ARCodeWidget::OpenGeneralSettings, this, &CheatsManager::OpenGeneralSettings);
|
|
||||||
connect(m_gecko_code, &GeckoCodeWidget::OpenGeneralSettings, this,
|
|
||||||
&CheatsManager::OpenGeneralSettings);
|
|
||||||
#ifdef USE_RETRO_ACHIEVEMENTS
|
|
||||||
connect(m_ar_code, &ARCodeWidget::OpenAchievementSettings, this,
|
|
||||||
&CheatsManager::OpenAchievementSettings);
|
|
||||||
connect(m_gecko_code, &GeckoCodeWidget::OpenAchievementSettings, this,
|
|
||||||
&CheatsManager::OpenAchievementSettings);
|
|
||||||
#endif // USE_RETRO_ACHIEVEMENTS
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheatsManager::CreateWidgets()
|
void CheatsManager::CreateWidgets()
|
||||||
|
@ -157,9 +123,19 @@ void CheatsManager::CreateWidgets()
|
||||||
m_tab_widget = new PartiallyClosableTabWidget;
|
m_tab_widget = new PartiallyClosableTabWidget;
|
||||||
m_button_box = new QDialogButtonBox(QDialogButtonBox::Close);
|
m_button_box = new QDialogButtonBox(QDialogButtonBox::Close);
|
||||||
|
|
||||||
|
int tab_index;
|
||||||
|
|
||||||
|
m_ar_code = new ARCodeWidget(m_game_id, m_revision, false);
|
||||||
|
tab_index = m_tab_widget->addTab(m_ar_code, tr("AR Code"));
|
||||||
|
m_tab_widget->setTabUnclosable(tab_index);
|
||||||
|
|
||||||
|
m_gecko_code = new GeckoCodeWidget(m_game_id, m_game_tdb_id, m_revision, false);
|
||||||
|
tab_index = m_tab_widget->addTab(m_gecko_code, tr("Gecko Codes"));
|
||||||
|
m_tab_widget->setTabUnclosable(tab_index);
|
||||||
|
|
||||||
m_cheat_search_new = new CheatSearchFactoryWidget();
|
m_cheat_search_new = new CheatSearchFactoryWidget();
|
||||||
m_tab_widget->addTab(m_cheat_search_new, tr("Start New Cheat Search"));
|
tab_index = m_tab_widget->addTab(m_cheat_search_new, tr("Start New Cheat Search"));
|
||||||
m_tab_widget->setTabUnclosable(0);
|
m_tab_widget->setTabUnclosable(tab_index);
|
||||||
|
|
||||||
auto* layout = new QVBoxLayout;
|
auto* layout = new QVBoxLayout;
|
||||||
layout->addWidget(m_tab_widget);
|
layout->addWidget(m_tab_widget);
|
||||||
|
@ -172,14 +148,9 @@ void CheatsManager::OnNewSessionCreated(const Cheats::CheatSearchSessionBase& se
|
||||||
{
|
{
|
||||||
auto* w = new CheatSearchWidget(m_system, session.Clone());
|
auto* w = new CheatSearchWidget(m_system, session.Clone());
|
||||||
const int tab_index = m_tab_widget->addTab(w, tr("Cheat Search"));
|
const int tab_index = m_tab_widget->addTab(w, tr("Cheat Search"));
|
||||||
w->connect(w, &CheatSearchWidget::ActionReplayCodeGenerated, this,
|
connect(w, &CheatSearchWidget::ActionReplayCodeGenerated, m_ar_code, &ARCodeWidget::AddCode);
|
||||||
[this](const ActionReplay::ARCode& ar_code) {
|
connect(w, &CheatSearchWidget::ShowMemory, this, &CheatsManager::ShowMemory);
|
||||||
if (m_ar_code)
|
connect(w, &CheatSearchWidget::RequestWatch, this, &CheatsManager::RequestWatch);
|
||||||
m_ar_code->AddCode(ar_code);
|
|
||||||
});
|
|
||||||
w->connect(w, &CheatSearchWidget::ShowMemory, [this](u32 address) { emit ShowMemory(address); });
|
|
||||||
w->connect(w, &CheatSearchWidget::RequestWatch,
|
|
||||||
[this](QString name, u32 address) { emit RequestWatch(name, address); });
|
|
||||||
m_tab_widget->setCurrentIndex(tab_index);
|
m_tab_widget->setCurrentIndex(tab_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,4 +167,13 @@ void CheatsManager::ConnectWidgets()
|
||||||
connect(m_cheat_search_new, &CheatSearchFactoryWidget::NewSessionCreated, this,
|
connect(m_cheat_search_new, &CheatSearchFactoryWidget::NewSessionCreated, this,
|
||||||
&CheatsManager::OnNewSessionCreated);
|
&CheatsManager::OnNewSessionCreated);
|
||||||
connect(m_tab_widget, &QTabWidget::tabCloseRequested, this, &CheatsManager::OnTabCloseRequested);
|
connect(m_tab_widget, &QTabWidget::tabCloseRequested, this, &CheatsManager::OnTabCloseRequested);
|
||||||
|
connect(m_ar_code, &ARCodeWidget::OpenGeneralSettings, this, &CheatsManager::OpenGeneralSettings);
|
||||||
|
connect(m_gecko_code, &GeckoCodeWidget::OpenGeneralSettings, this,
|
||||||
|
&CheatsManager::OpenGeneralSettings);
|
||||||
|
#ifdef USE_RETRO_ACHIEVEMENTS
|
||||||
|
connect(m_ar_code, &ARCodeWidget::OpenAchievementSettings, this,
|
||||||
|
&CheatsManager::OpenAchievementSettings);
|
||||||
|
connect(m_gecko_code, &GeckoCodeWidget::OpenAchievementSettings, this,
|
||||||
|
&CheatsManager::OpenAchievementSettings);
|
||||||
|
#endif // USE_RETRO_ACHIEVEMENTS
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ private:
|
||||||
void OnNewSessionCreated(const Cheats::CheatSearchSessionBase& session);
|
void OnNewSessionCreated(const Cheats::CheatSearchSessionBase& session);
|
||||||
void OnTabCloseRequested(int index);
|
void OnTabCloseRequested(int index);
|
||||||
|
|
||||||
void RefreshCodeTabs(Core::State state, bool force);
|
void RefreshCodeTabs(Core::State state);
|
||||||
void UpdateAllCheatSearchWidgetCurrentValues();
|
void UpdateAllCheatSearchWidgetCurrentValues();
|
||||||
|
|
||||||
std::string m_game_id;
|
std::string m_game_id;
|
||||||
|
|
|
@ -35,25 +35,27 @@ ARCodeWidget::ARCodeWidget(std::string game_id, u16 game_revision, bool restart_
|
||||||
CreateWidgets();
|
CreateWidgets();
|
||||||
ConnectWidgets();
|
ConnectWidgets();
|
||||||
|
|
||||||
if (!m_game_id.empty())
|
LoadCodes();
|
||||||
{
|
|
||||||
Common::IniFile game_ini_local;
|
|
||||||
|
|
||||||
// We don't use LoadLocalGameIni() here because user cheat codes that are installed via the UI
|
|
||||||
// will always be stored in GS/${GAMEID}.ini
|
|
||||||
game_ini_local.Load(File::GetUserPath(D_GAMESETTINGS_IDX) + m_game_id + ".ini");
|
|
||||||
|
|
||||||
const Common::IniFile game_ini_default =
|
|
||||||
SConfig::LoadDefaultGameIni(m_game_id, m_game_revision);
|
|
||||||
m_ar_codes = ActionReplay::LoadCodes(game_ini_default, game_ini_local);
|
|
||||||
}
|
|
||||||
|
|
||||||
UpdateList();
|
|
||||||
OnSelectionChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ARCodeWidget::~ARCodeWidget() = default;
|
ARCodeWidget::~ARCodeWidget() = default;
|
||||||
|
|
||||||
|
void ARCodeWidget::ChangeGame(std::string game_id, const u16 game_revision)
|
||||||
|
{
|
||||||
|
m_game_id = std::move(game_id);
|
||||||
|
m_game_revision = game_revision;
|
||||||
|
m_restart_required = false;
|
||||||
|
|
||||||
|
m_ar_codes.clear();
|
||||||
|
|
||||||
|
// If a CheatCodeEditor is open, it's now trying to add or edit a code in the previous game's code
|
||||||
|
// list which is no longer loaded. Letting the user save the code wouldn't make sense, so close
|
||||||
|
// the dialog instead.
|
||||||
|
m_cheat_code_editor->reject();
|
||||||
|
|
||||||
|
LoadCodes();
|
||||||
|
}
|
||||||
|
|
||||||
void ARCodeWidget::CreateWidgets()
|
void ARCodeWidget::CreateWidgets()
|
||||||
{
|
{
|
||||||
m_warning = new CheatWarningWidget(m_game_id, m_restart_required, this);
|
m_warning = new CheatWarningWidget(m_game_id, m_restart_required, this);
|
||||||
|
@ -65,10 +67,7 @@ void ARCodeWidget::CreateWidgets()
|
||||||
m_code_edit = new NonDefaultQPushButton(tr("&Edit Code..."));
|
m_code_edit = new NonDefaultQPushButton(tr("&Edit Code..."));
|
||||||
m_code_remove = new NonDefaultQPushButton(tr("&Remove Code"));
|
m_code_remove = new NonDefaultQPushButton(tr("&Remove Code"));
|
||||||
|
|
||||||
m_code_list->setEnabled(!m_game_id.empty());
|
m_cheat_code_editor = new CheatCodeEditor(this);
|
||||||
m_code_add->setEnabled(!m_game_id.empty());
|
|
||||||
m_code_edit->setEnabled(!m_game_id.empty());
|
|
||||||
m_code_remove->setEnabled(!m_game_id.empty());
|
|
||||||
|
|
||||||
m_code_list->setContextMenuPolicy(Qt::CustomContextMenu);
|
m_code_list->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
|
|
||||||
|
@ -179,14 +178,18 @@ void ARCodeWidget::OnListReordered()
|
||||||
|
|
||||||
void ARCodeWidget::OnSelectionChanged()
|
void ARCodeWidget::OnSelectionChanged()
|
||||||
{
|
{
|
||||||
auto items = m_code_list->selectedItems();
|
const QList<QListWidgetItem*> items = m_code_list->selectedItems();
|
||||||
|
const bool empty = items.empty();
|
||||||
|
|
||||||
if (items.empty())
|
m_code_edit->setDisabled(empty);
|
||||||
|
m_code_remove->setDisabled(empty);
|
||||||
|
|
||||||
|
if (empty)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const auto* selected = items[0];
|
const QListWidgetItem* const selected = items[0];
|
||||||
|
|
||||||
bool user_defined = m_ar_codes[m_code_list->row(selected)].user_defined;
|
const bool user_defined = m_ar_codes[m_code_list->row(selected)].user_defined;
|
||||||
|
|
||||||
m_code_remove->setEnabled(user_defined);
|
m_code_remove->setEnabled(user_defined);
|
||||||
m_code_edit->setText(user_defined ? tr("&Edit Code...") : tr("Clone and &Edit Code..."));
|
m_code_edit->setText(user_defined ? tr("&Edit Code...") : tr("Clone and &Edit Code..."));
|
||||||
|
@ -214,6 +217,29 @@ void ARCodeWidget::UpdateList()
|
||||||
m_code_list->setDragDropMode(QAbstractItemView::InternalMove);
|
m_code_list->setDragDropMode(QAbstractItemView::InternalMove);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ARCodeWidget::LoadCodes()
|
||||||
|
{
|
||||||
|
if (!m_game_id.empty())
|
||||||
|
{
|
||||||
|
Common::IniFile game_ini_local;
|
||||||
|
|
||||||
|
// We don't use LoadLocalGameIni() here because user cheat codes that are installed via the UI
|
||||||
|
// will always be stored in GS/${GAMEID}.ini
|
||||||
|
game_ini_local.Load(File::GetUserPath(D_GAMESETTINGS_IDX) + m_game_id + ".ini");
|
||||||
|
|
||||||
|
const Common::IniFile game_ini_default =
|
||||||
|
SConfig::LoadDefaultGameIni(m_game_id, m_game_revision);
|
||||||
|
m_ar_codes = ActionReplay::LoadCodes(game_ini_default, game_ini_local);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_code_list->setEnabled(!m_game_id.empty());
|
||||||
|
m_code_add->setEnabled(!m_game_id.empty());
|
||||||
|
m_code_edit->setEnabled(false);
|
||||||
|
m_code_remove->setEnabled(false);
|
||||||
|
|
||||||
|
UpdateList();
|
||||||
|
}
|
||||||
|
|
||||||
void ARCodeWidget::SaveCodes()
|
void ARCodeWidget::SaveCodes()
|
||||||
{
|
{
|
||||||
if (m_game_id.empty())
|
if (m_game_id.empty())
|
||||||
|
@ -241,10 +267,9 @@ void ARCodeWidget::OnCodeAddClicked()
|
||||||
ActionReplay::ARCode ar;
|
ActionReplay::ARCode ar;
|
||||||
ar.enabled = true;
|
ar.enabled = true;
|
||||||
|
|
||||||
CheatCodeEditor ed(this);
|
m_cheat_code_editor->SetARCode(&ar);
|
||||||
ed.SetARCode(&ar);
|
SetQWidgetWindowDecorations(m_cheat_code_editor);
|
||||||
SetQWidgetWindowDecorations(&ed);
|
if (m_cheat_code_editor->exec() == QDialog::Rejected)
|
||||||
if (ed.exec() == QDialog::Rejected)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_ar_codes.push_back(std::move(ar));
|
m_ar_codes.push_back(std::move(ar));
|
||||||
|
@ -261,23 +286,19 @@ void ARCodeWidget::OnCodeEditClicked()
|
||||||
|
|
||||||
const auto* const selected = items[0];
|
const auto* const selected = items[0];
|
||||||
auto& current_ar = m_ar_codes[m_code_list->row(selected)];
|
auto& current_ar = m_ar_codes[m_code_list->row(selected)];
|
||||||
|
SetQWidgetWindowDecorations(m_cheat_code_editor);
|
||||||
|
|
||||||
CheatCodeEditor ed(this);
|
|
||||||
if (current_ar.user_defined)
|
if (current_ar.user_defined)
|
||||||
{
|
{
|
||||||
ed.SetARCode(¤t_ar);
|
m_cheat_code_editor->SetARCode(¤t_ar);
|
||||||
|
if (m_cheat_code_editor->exec() == QDialog::Rejected)
|
||||||
SetQWidgetWindowDecorations(&ed);
|
|
||||||
if (ed.exec() == QDialog::Rejected)
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ActionReplay::ARCode ar = current_ar;
|
ActionReplay::ARCode ar = current_ar;
|
||||||
ed.SetARCode(&ar);
|
m_cheat_code_editor->SetARCode(&ar);
|
||||||
|
if (m_cheat_code_editor->exec() == QDialog::Rejected)
|
||||||
SetQWidgetWindowDecorations(&ed);
|
|
||||||
if (ed.exec() == QDialog::Rejected)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_ar_codes.push_back(std::move(ar));
|
m_ar_codes.push_back(std::move(ar));
|
||||||
|
|
|
@ -15,6 +15,7 @@ namespace ActionReplay
|
||||||
struct ARCode;
|
struct ARCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class CheatCodeEditor;
|
||||||
class CheatWarningWidget;
|
class CheatWarningWidget;
|
||||||
#ifdef USE_RETRO_ACHIEVEMENTS
|
#ifdef USE_RETRO_ACHIEVEMENTS
|
||||||
class HardcoreWarningWidget;
|
class HardcoreWarningWidget;
|
||||||
|
@ -31,6 +32,7 @@ public:
|
||||||
explicit ARCodeWidget(std::string game_id, u16 game_revision, bool restart_required = true);
|
explicit ARCodeWidget(std::string game_id, u16 game_revision, bool restart_required = true);
|
||||||
~ARCodeWidget() override;
|
~ARCodeWidget() override;
|
||||||
|
|
||||||
|
void ChangeGame(std::string game_id, u16 game_revision);
|
||||||
void AddCode(ActionReplay::ARCode code);
|
void AddCode(ActionReplay::ARCode code);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
@ -47,6 +49,7 @@ private:
|
||||||
void CreateWidgets();
|
void CreateWidgets();
|
||||||
void ConnectWidgets();
|
void ConnectWidgets();
|
||||||
void UpdateList();
|
void UpdateList();
|
||||||
|
void LoadCodes();
|
||||||
void SaveCodes();
|
void SaveCodes();
|
||||||
void SortAlphabetically();
|
void SortAlphabetically();
|
||||||
void SortEnabledCodesFirst();
|
void SortEnabledCodesFirst();
|
||||||
|
@ -70,6 +73,8 @@ private:
|
||||||
QPushButton* m_code_edit;
|
QPushButton* m_code_edit;
|
||||||
QPushButton* m_code_remove;
|
QPushButton* m_code_remove;
|
||||||
|
|
||||||
|
CheatCodeEditor* m_cheat_code_editor;
|
||||||
|
|
||||||
std::vector<ActionReplay::ARCode> m_ar_codes;
|
std::vector<ActionReplay::ARCode> m_ar_codes;
|
||||||
bool m_restart_required;
|
bool m_restart_required;
|
||||||
};
|
};
|
||||||
|
|
|
@ -42,20 +42,30 @@ GeckoCodeWidget::GeckoCodeWidget(std::string game_id, std::string gametdb_id, u1
|
||||||
CreateWidgets();
|
CreateWidgets();
|
||||||
ConnectWidgets();
|
ConnectWidgets();
|
||||||
|
|
||||||
if (!m_game_id.empty())
|
LoadCodes();
|
||||||
{
|
}
|
||||||
Common::IniFile game_ini_local;
|
|
||||||
|
|
||||||
// We don't use LoadLocalGameIni() here because user cheat codes that are installed via the UI
|
void GeckoCodeWidget::ChangeGame(std::string game_id, std::string gametdb_id,
|
||||||
// will always be stored in GS/${GAMEID}.ini
|
const u16 game_revision)
|
||||||
game_ini_local.Load(File::GetUserPath(D_GAMESETTINGS_IDX) + m_game_id + ".ini");
|
{
|
||||||
|
m_game_id = std::move(game_id);
|
||||||
|
m_gametdb_id = std::move(gametdb_id);
|
||||||
|
m_game_revision = game_revision;
|
||||||
|
m_restart_required = false;
|
||||||
|
|
||||||
const Common::IniFile game_ini_default =
|
m_gecko_codes.clear();
|
||||||
SConfig::LoadDefaultGameIni(m_game_id, m_game_revision);
|
m_code_list->clear();
|
||||||
m_gecko_codes = Gecko::LoadCodes(game_ini_default, game_ini_local);
|
m_name_label->clear();
|
||||||
}
|
m_creator_label->clear();
|
||||||
|
m_code_description->clear();
|
||||||
|
m_code_view->clear();
|
||||||
|
|
||||||
UpdateList();
|
// If a CheatCodeEditor is open, it's now trying to add or edit a code in the previous game's code
|
||||||
|
// list which is no longer loaded. Letting the user save the code wouldn't make sense, so close
|
||||||
|
// the dialog instead.
|
||||||
|
m_cheat_code_editor->reject();
|
||||||
|
|
||||||
|
LoadCodes();
|
||||||
}
|
}
|
||||||
|
|
||||||
GeckoCodeWidget::~GeckoCodeWidget() = default;
|
GeckoCodeWidget::~GeckoCodeWidget() = default;
|
||||||
|
@ -91,19 +101,10 @@ void GeckoCodeWidget::CreateWidgets()
|
||||||
m_remove_code = new NonDefaultQPushButton(tr("&Remove Code"));
|
m_remove_code = new NonDefaultQPushButton(tr("&Remove Code"));
|
||||||
m_download_codes = new NonDefaultQPushButton(tr("Download Codes"));
|
m_download_codes = new NonDefaultQPushButton(tr("Download Codes"));
|
||||||
|
|
||||||
|
m_cheat_code_editor = new CheatCodeEditor(this);
|
||||||
|
|
||||||
m_download_codes->setToolTip(tr("Download Codes from the WiiRD Database"));
|
m_download_codes->setToolTip(tr("Download Codes from the WiiRD Database"));
|
||||||
|
|
||||||
m_code_list->setEnabled(!m_game_id.empty());
|
|
||||||
m_name_label->setEnabled(!m_game_id.empty());
|
|
||||||
m_creator_label->setEnabled(!m_game_id.empty());
|
|
||||||
m_code_description->setEnabled(!m_game_id.empty());
|
|
||||||
m_code_view->setEnabled(!m_game_id.empty());
|
|
||||||
|
|
||||||
m_add_code->setEnabled(!m_game_id.empty());
|
|
||||||
m_edit_code->setEnabled(false);
|
|
||||||
m_remove_code->setEnabled(false);
|
|
||||||
m_download_codes->setEnabled(!m_game_id.empty());
|
|
||||||
|
|
||||||
auto* layout = new QVBoxLayout;
|
auto* layout = new QVBoxLayout;
|
||||||
|
|
||||||
layout->addWidget(m_warning);
|
layout->addWidget(m_warning);
|
||||||
|
@ -166,17 +167,16 @@ void GeckoCodeWidget::ConnectWidgets()
|
||||||
|
|
||||||
void GeckoCodeWidget::OnSelectionChanged()
|
void GeckoCodeWidget::OnSelectionChanged()
|
||||||
{
|
{
|
||||||
auto items = m_code_list->selectedItems();
|
const QList<QListWidgetItem*> items = m_code_list->selectedItems();
|
||||||
|
|
||||||
const bool empty = items.empty();
|
const bool empty = items.empty();
|
||||||
|
|
||||||
m_edit_code->setEnabled(!empty);
|
m_edit_code->setDisabled(empty);
|
||||||
m_remove_code->setEnabled(!empty);
|
m_remove_code->setDisabled(empty);
|
||||||
|
|
||||||
if (items.empty())
|
if (empty)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto selected = items[0];
|
const QListWidgetItem* const selected = items[0];
|
||||||
|
|
||||||
const int index = selected->data(Qt::UserRole).toInt();
|
const int index = selected->data(Qt::UserRole).toInt();
|
||||||
|
|
||||||
|
@ -212,10 +212,9 @@ void GeckoCodeWidget::AddCode()
|
||||||
Gecko::GeckoCode code;
|
Gecko::GeckoCode code;
|
||||||
code.enabled = true;
|
code.enabled = true;
|
||||||
|
|
||||||
CheatCodeEditor ed(this);
|
m_cheat_code_editor->SetGeckoCode(&code);
|
||||||
ed.SetGeckoCode(&code);
|
SetQWidgetWindowDecorations(m_cheat_code_editor);
|
||||||
SetQWidgetWindowDecorations(&ed);
|
if (m_cheat_code_editor->exec() == QDialog::Rejected)
|
||||||
if (ed.exec() == QDialog::Rejected)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_gecko_codes.push_back(std::move(code));
|
m_gecko_codes.push_back(std::move(code));
|
||||||
|
@ -231,10 +230,9 @@ void GeckoCodeWidget::EditCode()
|
||||||
|
|
||||||
const int index = item->data(Qt::UserRole).toInt();
|
const int index = item->data(Qt::UserRole).toInt();
|
||||||
|
|
||||||
CheatCodeEditor ed(this);
|
m_cheat_code_editor->SetGeckoCode(&m_gecko_codes[index]);
|
||||||
ed.SetGeckoCode(&m_gecko_codes[index]);
|
SetQWidgetWindowDecorations(m_cheat_code_editor);
|
||||||
SetQWidgetWindowDecorations(&ed);
|
if (m_cheat_code_editor->exec() == QDialog::Rejected)
|
||||||
if (ed.exec() == QDialog::Rejected)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SaveCodes();
|
SaveCodes();
|
||||||
|
@ -254,6 +252,35 @@ void GeckoCodeWidget::RemoveCode()
|
||||||
SaveCodes();
|
SaveCodes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GeckoCodeWidget::LoadCodes()
|
||||||
|
{
|
||||||
|
if (!m_game_id.empty())
|
||||||
|
{
|
||||||
|
Common::IniFile game_ini_local;
|
||||||
|
|
||||||
|
// We don't use LoadLocalGameIni() here because user cheat codes that are installed via the UI
|
||||||
|
// will always be stored in GS/${GAMEID}.ini
|
||||||
|
game_ini_local.Load(File::GetUserPath(D_GAMESETTINGS_IDX) + m_game_id + ".ini");
|
||||||
|
|
||||||
|
const Common::IniFile game_ini_default =
|
||||||
|
SConfig::LoadDefaultGameIni(m_game_id, m_game_revision);
|
||||||
|
m_gecko_codes = Gecko::LoadCodes(game_ini_default, game_ini_local);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_code_list->setEnabled(!m_game_id.empty());
|
||||||
|
m_name_label->setEnabled(!m_game_id.empty());
|
||||||
|
m_creator_label->setEnabled(!m_game_id.empty());
|
||||||
|
m_code_description->setEnabled(!m_game_id.empty());
|
||||||
|
m_code_view->setEnabled(!m_game_id.empty());
|
||||||
|
|
||||||
|
m_add_code->setEnabled(!m_game_id.empty());
|
||||||
|
m_edit_code->setEnabled(false);
|
||||||
|
m_remove_code->setEnabled(false);
|
||||||
|
m_download_codes->setEnabled(!m_game_id.empty());
|
||||||
|
|
||||||
|
UpdateList();
|
||||||
|
}
|
||||||
|
|
||||||
void GeckoCodeWidget::SaveCodes()
|
void GeckoCodeWidget::SaveCodes()
|
||||||
{
|
{
|
||||||
if (m_game_id.empty())
|
if (m_game_id.empty())
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
|
|
||||||
|
class CheatCodeEditor;
|
||||||
class CheatWarningWidget;
|
class CheatWarningWidget;
|
||||||
#ifdef USE_RETRO_ACHIEVEMENTS
|
#ifdef USE_RETRO_ACHIEVEMENTS
|
||||||
class HardcoreWarningWidget;
|
class HardcoreWarningWidget;
|
||||||
|
@ -33,6 +34,8 @@ public:
|
||||||
bool restart_required = true);
|
bool restart_required = true);
|
||||||
~GeckoCodeWidget() override;
|
~GeckoCodeWidget() override;
|
||||||
|
|
||||||
|
void ChangeGame(std::string game_id, std::string gametdb_id, u16 game_revision);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void OpenGeneralSettings();
|
void OpenGeneralSettings();
|
||||||
#ifdef USE_RETRO_ACHIEVEMENTS
|
#ifdef USE_RETRO_ACHIEVEMENTS
|
||||||
|
@ -52,6 +55,7 @@ private:
|
||||||
void EditCode();
|
void EditCode();
|
||||||
void RemoveCode();
|
void RemoveCode();
|
||||||
void DownloadCodes();
|
void DownloadCodes();
|
||||||
|
void LoadCodes();
|
||||||
void SaveCodes();
|
void SaveCodes();
|
||||||
void SortAlphabetically();
|
void SortAlphabetically();
|
||||||
void SortEnabledCodesFirst();
|
void SortEnabledCodesFirst();
|
||||||
|
@ -74,6 +78,7 @@ private:
|
||||||
QPushButton* m_edit_code;
|
QPushButton* m_edit_code;
|
||||||
QPushButton* m_remove_code;
|
QPushButton* m_remove_code;
|
||||||
QPushButton* m_download_codes;
|
QPushButton* m_download_codes;
|
||||||
|
CheatCodeEditor* m_cheat_code_editor;
|
||||||
std::vector<Gecko::GeckoCode> m_gecko_codes;
|
std::vector<Gecko::GeckoCode> m_gecko_codes;
|
||||||
bool m_restart_required;
|
bool m_restart_required;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue