From 203ecb534d65287a16cb1565ab69ee10a02ab0bf Mon Sep 17 00:00:00 2001 From: Techjar Date: Mon, 29 Oct 2018 17:00:37 -0400 Subject: [PATCH] NetPlay: Fix saving host game selection --- Source/Core/Core/Config/NetplaySettings.cpp | 2 -- .../Core/DolphinQt/NetPlay/NetPlayDialog.cpp | 1 + .../DolphinQt/NetPlay/NetPlaySetupDialog.cpp | 23 +++++++++++-------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Source/Core/Core/Config/NetplaySettings.cpp b/Source/Core/Core/Config/NetplaySettings.cpp index a4235ad03e..5bebda50c8 100644 --- a/Source/Core/Core/Config/NetplaySettings.cpp +++ b/Source/Core/Core/Config/NetplaySettings.cpp @@ -29,8 +29,6 @@ const ConfigInfo NETPLAY_LISTEN_PORT{{System::Main, "NetPlay", "ListenPort" DEFAULT_LISTEN_PORT}; const ConfigInfo NETPLAY_NICKNAME{{System::Main, "NetPlay", "Nickname"}, "Player"}; -const ConfigInfo NETPLAY_SELECTED_HOST_GAME{ - {System::Main, "NetPlay", "SelectedHostGame"}, ""}; const ConfigInfo NETPLAY_USE_UPNP{{System::Main, "NetPlay", "UseUPNP"}, false}; const ConfigInfo NETPLAY_ENABLE_QOS{{System::Main, "NetPlay", "EnableQoS"}, true}; diff --git a/Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp b/Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp index dc6b847b61..1e47f80bb6 100644 --- a/Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp +++ b/Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp @@ -314,6 +314,7 @@ void NetPlayDialog::ConnectWidgets() { auto unique_id = gld.GetSelectedUniqueID(); Settings::Instance().GetNetPlayServer()->ChangeGame(unique_id.toStdString()); + Settings::GetQSettings().setValue(QStringLiteral("netplay/hostgame"), unique_id); } }); diff --git a/Source/Core/DolphinQt/NetPlay/NetPlaySetupDialog.cpp b/Source/Core/DolphinQt/NetPlay/NetPlaySetupDialog.cpp index 6f7818e2b0..25f44ba4db 100644 --- a/Source/Core/DolphinQt/NetPlay/NetPlaySetupDialog.cpp +++ b/Source/Core/DolphinQt/NetPlay/NetPlaySetupDialog.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -51,13 +52,6 @@ NetPlaySetupDialog::NetPlaySetupDialog(QWidget* parent) OnConnectionTypeChanged(m_connection_type->currentIndex()); - int selected_game = Settings::GetQSettings().value(QStringLiteral("netplay/hostgame"), 0).toInt(); - - if (selected_game >= m_host_games->count()) - selected_game = 0; - - m_host_games->setCurrentItem(m_host_games->item(selected_game)); - ConnectWidgets(); } @@ -161,8 +155,9 @@ void NetPlaySetupDialog::ConnectWidgets() connect(m_host_port_box, static_cast(&QSpinBox::valueChanged), this, &NetPlaySetupDialog::SaveSettings); connect(m_host_games, static_cast(&QListWidget::currentRowChanged), - [](int index) { - Settings::GetQSettings().setValue(QStringLiteral("netplay/hostgame"), index); + [this](int index) { + Settings::GetQSettings().setValue(QStringLiteral("netplay/hostgame"), + m_host_games->item(index)->text()); }); connect(m_host_games, &QListWidget::itemDoubleClicked, this, &NetPlaySetupDialog::accept); @@ -251,6 +246,8 @@ void NetPlaySetupDialog::accept() void NetPlaySetupDialog::PopulateGameList() { + QSignalBlocker blocker(m_host_games); + m_host_games->clear(); for (int i = 0; i < m_game_list_model->rowCount(QModelIndex()); i++) { @@ -263,6 +260,14 @@ void NetPlaySetupDialog::PopulateGameList() } m_host_games->sortItems(); + + QString selected_game = Settings::GetQSettings() + .value(QStringLiteral("netplay/hostgame"), QStringLiteral("")) + .toString(); + auto find_list = m_host_games->findItems(selected_game, Qt::MatchFlag::MatchExactly); + + if (find_list.count() > 0) + m_host_games->setCurrentItem(find_list[0]); } void NetPlaySetupDialog::ResetTraversalHost()