Skip to content

Commit

Permalink
RMG: save and restore selected server in netplay dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosalie241 committed Jan 24, 2025
1 parent 881e0c9 commit 5fd9b78
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ CreateNetplaySessionDialog::~CreateNetplaySessionDialog(void)
{
CoreSettingsSetValue(SettingsID::Netplay_Nickname, nickname.toStdString());
}

QString server = this->serverComboBox->currentText();
if (!server.isEmpty())
{
CoreSettingsSetValue(SettingsID::Netplay_SelectedServer, server.toStdString());
}
}

QJsonObject CreateNetplaySessionDialog::GetSessionJson(void)
Expand Down Expand Up @@ -182,6 +188,8 @@ void CreateNetplaySessionDialog::on_broadcastSocket_readyRead()
this->serverComboBox->addItem(servers.at(i), json.value(servers.at(i)).toString());
}
}

NetplayCommon::RestoreSelectedServer(this->serverComboBox);
}

void CreateNetplaySessionDialog::on_networkAccessManager_Finished(QNetworkReply* reply)
Expand All @@ -203,6 +211,8 @@ void CreateNetplaySessionDialog::on_networkAccessManager_Finished(QNetworkReply*
}

reply->deleteLater();

NetplayCommon::RestoreSelectedServer(this->serverComboBox);
}

void CreateNetplaySessionDialog::on_serverComboBox_currentIndexChanged(int index)
Expand Down
15 changes: 15 additions & 0 deletions Source/RMG/UserInterface/Dialog/Netplay/NetplayCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,18 @@ QList<QString> NetplayCommon::GetPluginNames(QString md5QString)

return pluginNames;
}

void NetplayCommon::RestoreSelectedServer(QComboBox* comboBox)
{
QString server = QString::fromStdString(CoreSettingsGetStringValue(SettingsID::Netplay_SelectedServer));
if (server.isEmpty())
{
return;
}

int index = comboBox->findText(server);
if (index >= 0)
{
comboBox->setCurrentIndex(index);
}
}
3 changes: 3 additions & 0 deletions Source/RMG/UserInterface/Dialog/Netplay/NetplayCommon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define NETPLAYCOMMON_HPP

#include <QJsonObject>
#include <QComboBox>
#include <QString>

namespace NetplayCommon
Expand All @@ -24,6 +25,8 @@ namespace NetplayCommon

// Retrieves RSP and GFX plugin names
QList<QString> GetPluginNames(QString md5QString);

void RestoreSelectedServer(QComboBox* comboBox);
}

#endif // NETPLAYCOMMON_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ NetplaySessionBrowserDialog::~NetplaySessionBrowserDialog(void)
{
CoreSettingsSetValue(SettingsID::Netplay_Nickname, nickname.toStdString());
}

QString server = this->serverComboBox->currentText();
if (!server.isEmpty())
{
CoreSettingsSetValue(SettingsID::Netplay_SelectedServer, server.toStdString());
}
}

QJsonObject NetplaySessionBrowserDialog::GetSessionJson(void)
Expand Down Expand Up @@ -255,6 +261,8 @@ void NetplaySessionBrowserDialog::on_broadcastSocket_readyRead(void)
this->serverComboBox->addItem(servers.at(i), json.value(servers.at(i)).toString());
}
}

NetplayCommon::RestoreSelectedServer(this->serverComboBox);
}

void NetplaySessionBrowserDialog::on_networkAccessManager_Finished(QNetworkReply* reply)
Expand All @@ -277,6 +285,8 @@ void NetplaySessionBrowserDialog::on_networkAccessManager_Finished(QNetworkReply
}

reply->deleteLater();

NetplayCommon::RestoreSelectedServer(this->serverComboBox);
}

void NetplaySessionBrowserDialog::on_serverComboBox_currentIndexChanged(int index)
Expand Down

0 comments on commit 5fd9b78

Please sign in to comment.