From 232d24109df7af9449c0604523ce4568e78aa52d Mon Sep 17 00:00:00 2001 From: Dentomologist Date: Tue, 30 Jul 2024 19:44:10 -0700 Subject: Extract ARCodeWidget/GeckoCodeWidget code loading to functions --- Source/Core/DolphinQt/Config/ARCodeWidget.cpp | 45 +++++++++++++++------------ 1 file changed, 25 insertions(+), 20 deletions(-) (limited to 'Source/Core/DolphinQt/Config/ARCodeWidget.cpp') diff --git a/Source/Core/DolphinQt/Config/ARCodeWidget.cpp b/Source/Core/DolphinQt/Config/ARCodeWidget.cpp index f42a33317b..82a5dce74b 100644 --- a/Source/Core/DolphinQt/Config/ARCodeWidget.cpp +++ b/Source/Core/DolphinQt/Config/ARCodeWidget.cpp @@ -35,21 +35,7 @@ ARCodeWidget::ARCodeWidget(std::string game_id, u16 game_revision, bool restart_ CreateWidgets(); ConnectWidgets(); - 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); - } - - UpdateList(); - OnSelectionChanged(); + LoadCodes(); } ARCodeWidget::~ARCodeWidget() = default; @@ -65,11 +51,6 @@ void ARCodeWidget::CreateWidgets() m_code_edit = new NonDefaultQPushButton(tr("&Edit Code...")); m_code_remove = new NonDefaultQPushButton(tr("&Remove Code")); - 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); - m_code_list->setContextMenuPolicy(Qt::CustomContextMenu); auto* button_layout = new QHBoxLayout; @@ -218,6 +199,30 @@ void ARCodeWidget::UpdateList() 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(); + OnSelectionChanged(); +} + void ARCodeWidget::SaveCodes() { if (m_game_id.empty()) -- cgit v1.2.3