Merge pull request #7534 from Techjar/fix-netplay-gamelist-saving

NetPlay: Fix saving host game selection
This commit is contained in:
Pierre Bourdon 2018-11-09 04:28:55 +01:00 committed by GitHub
commit 162e34ad22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 11 deletions

View File

@ -29,8 +29,6 @@ const ConfigInfo<u16> NETPLAY_LISTEN_PORT{{System::Main, "NetPlay", "ListenPort"
DEFAULT_LISTEN_PORT}; DEFAULT_LISTEN_PORT};
const ConfigInfo<std::string> NETPLAY_NICKNAME{{System::Main, "NetPlay", "Nickname"}, "Player"}; const ConfigInfo<std::string> NETPLAY_NICKNAME{{System::Main, "NetPlay", "Nickname"}, "Player"};
const ConfigInfo<std::string> NETPLAY_SELECTED_HOST_GAME{
{System::Main, "NetPlay", "SelectedHostGame"}, ""};
const ConfigInfo<bool> NETPLAY_USE_UPNP{{System::Main, "NetPlay", "UseUPNP"}, false}; const ConfigInfo<bool> NETPLAY_USE_UPNP{{System::Main, "NetPlay", "UseUPNP"}, false};
const ConfigInfo<bool> NETPLAY_ENABLE_QOS{{System::Main, "NetPlay", "EnableQoS"}, true}; const ConfigInfo<bool> NETPLAY_ENABLE_QOS{{System::Main, "NetPlay", "EnableQoS"}, true};

View File

@ -314,6 +314,7 @@ void NetPlayDialog::ConnectWidgets()
{ {
auto unique_id = gld.GetSelectedUniqueID(); auto unique_id = gld.GetSelectedUniqueID();
Settings::Instance().GetNetPlayServer()->ChangeGame(unique_id.toStdString()); Settings::Instance().GetNetPlayServer()->ChangeGame(unique_id.toStdString());
Settings::GetQSettings().setValue(QStringLiteral("netplay/hostgame"), unique_id);
} }
}); });

View File

@ -13,6 +13,7 @@
#include <QListWidget> #include <QListWidget>
#include <QMessageBox> #include <QMessageBox>
#include <QPushButton> #include <QPushButton>
#include <QSignalBlocker>
#include <QSpinBox> #include <QSpinBox>
#include <QTabWidget> #include <QTabWidget>
@ -51,13 +52,6 @@ NetPlaySetupDialog::NetPlaySetupDialog(QWidget* parent)
OnConnectionTypeChanged(m_connection_type->currentIndex()); 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(); ConnectWidgets();
} }
@ -161,8 +155,9 @@ void NetPlaySetupDialog::ConnectWidgets()
connect(m_host_port_box, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, connect(m_host_port_box, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
&NetPlaySetupDialog::SaveSettings); &NetPlaySetupDialog::SaveSettings);
connect(m_host_games, static_cast<void (QListWidget::*)(int)>(&QListWidget::currentRowChanged), connect(m_host_games, static_cast<void (QListWidget::*)(int)>(&QListWidget::currentRowChanged),
[](int index) { [this](int index) {
Settings::GetQSettings().setValue(QStringLiteral("netplay/hostgame"), index); Settings::GetQSettings().setValue(QStringLiteral("netplay/hostgame"),
m_host_games->item(index)->text());
}); });
connect(m_host_games, &QListWidget::itemDoubleClicked, this, &NetPlaySetupDialog::accept); connect(m_host_games, &QListWidget::itemDoubleClicked, this, &NetPlaySetupDialog::accept);
@ -251,6 +246,8 @@ void NetPlaySetupDialog::accept()
void NetPlaySetupDialog::PopulateGameList() void NetPlaySetupDialog::PopulateGameList()
{ {
QSignalBlocker blocker(m_host_games);
m_host_games->clear(); m_host_games->clear();
for (int i = 0; i < m_game_list_model->rowCount(QModelIndex()); i++) for (int i = 0; i < m_game_list_model->rowCount(QModelIndex()); i++)
{ {
@ -263,6 +260,14 @@ void NetPlaySetupDialog::PopulateGameList()
} }
m_host_games->sortItems(); 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() void NetPlaySetupDialog::ResetTraversalHost()