Allow translations and custom names in GameFile::GetNetPlayName

There is no longer any major reason for why this function would
need to return the same result for all players.
This commit is contained in:
JosJuice 2020-06-10 18:49:22 +02:00
parent a41166bb37
commit 5cad82137d
10 changed files with 25 additions and 13 deletions

View File

@ -743,6 +743,11 @@ GameList::FindSecondDisc(const UICommon::GameFile& game) const
return m_model->FindSecondDisc(game); return m_model->FindSecondDisc(game);
} }
std::string GameList::GetNetPlayName(const UICommon::GameFile& game) const
{
return m_model->GetNetPlayName(game);
}
void GameList::SetViewColumn(int col, bool view) void GameList::SetViewColumn(int col, bool view)
{ {
m_list->setColumnHidden(col, !view); m_list->setColumnHidden(col, !view);

View File

@ -32,6 +32,7 @@ public:
bool HasMultipleSelected() const; bool HasMultipleSelected() const;
std::shared_ptr<const UICommon::GameFile> FindGame(const std::string& path) const; std::shared_ptr<const UICommon::GameFile> FindGame(const std::string& path) const;
std::shared_ptr<const UICommon::GameFile> FindSecondDisc(const UICommon::GameFile& game) const; std::shared_ptr<const UICommon::GameFile> FindSecondDisc(const UICommon::GameFile& game) const;
std::string GetNetPlayName(const UICommon::GameFile& game) const;
void SetListView() { SetPreferredView(true); } void SetListView() { SetPreferredView(true); }
void SetGridView() { SetPreferredView(false); } void SetGridView() { SetPreferredView(false); }

View File

@ -313,6 +313,11 @@ std::shared_ptr<const UICommon::GameFile> GameListModel::GetGameFile(int index)
return m_games[index]; return m_games[index];
} }
std::string GameListModel::GetNetPlayName(const UICommon::GameFile& game) const
{
return game.GetNetPlayName(m_title_database);
}
void GameListModel::AddGame(const std::shared_ptr<const UICommon::GameFile>& game) void GameListModel::AddGame(const std::shared_ptr<const UICommon::GameFile>& game)
{ {
beginInsertRows(QModelIndex(), m_games.size(), m_games.size()); beginInsertRows(QModelIndex(), m_games.size(), m_games.size());

View File

@ -37,6 +37,7 @@ public:
int columnCount(const QModelIndex& parent) const override; int columnCount(const QModelIndex& parent) const override;
std::shared_ptr<const UICommon::GameFile> GetGameFile(int index) const; std::shared_ptr<const UICommon::GameFile> GetGameFile(int index) const;
std::string GetNetPlayName(const UICommon::GameFile& game) const;
bool ShouldDisplayGameListItem(int index) const; bool ShouldDisplayGameListItem(int index) const;
void SetSearchTerm(const QString& term); void SetSearchTerm(const QString& term);

View File

@ -1420,7 +1420,7 @@ bool MainWindow::NetPlayHost(const UICommon::GameFile& game)
} }
Settings::Instance().GetNetPlayServer()->ChangeGame(game.GetSyncIdentifier(), Settings::Instance().GetNetPlayServer()->ChangeGame(game.GetSyncIdentifier(),
game.GetNetPlayName()); m_game_list->GetNetPlayName(game));
// Join our local server // Join our local server
return NetPlayJoin(); return NetPlayJoin();

View File

@ -55,7 +55,8 @@ void GameListDialog::PopulateGameList()
{ {
std::shared_ptr<const UICommon::GameFile> game = game_list_model->GetGameFile(i); std::shared_ptr<const UICommon::GameFile> game = game_list_model->GetGameFile(i);
auto* item = new QListWidgetItem(QString::fromStdString(game->GetNetPlayName())); auto* item =
new QListWidgetItem(QString::fromStdString(game_list_model->GetNetPlayName(*game)));
item->setData(Qt::UserRole, QVariant::fromValue(std::move(game))); item->setData(Qt::UserRole, QVariant::fromValue(std::move(game)));
m_game_list->addItem(item); m_game_list->addItem(item);
} }

View File

@ -325,9 +325,12 @@ void NetPlayDialog::ConnectWidgets()
GameListDialog gld(this); GameListDialog gld(this);
if (gld.exec() == QDialog::Accepted) if (gld.exec() == QDialog::Accepted)
{ {
Settings& settings = Settings::Instance();
const UICommon::GameFile& game = gld.GetSelectedGame(); const UICommon::GameFile& game = gld.GetSelectedGame();
const std::string netplay_name = game.GetNetPlayName(); const std::string netplay_name = settings.GetGameListModel()->GetNetPlayName(game);
Settings::Instance().GetNetPlayServer()->ChangeGame(game.GetSyncIdentifier(), netplay_name);
settings.GetNetPlayServer()->ChangeGame(game.GetSyncIdentifier(), netplay_name);
Settings::GetQSettings().setValue(QStringLiteral("netplay/hostgame"), Settings::GetQSettings().setValue(QStringLiteral("netplay/hostgame"),
QString::fromStdString(netplay_name)); QString::fromStdString(netplay_name));
} }

View File

@ -363,7 +363,8 @@ void NetPlaySetupDialog::PopulateGameList()
{ {
std::shared_ptr<const UICommon::GameFile> game = m_game_list_model->GetGameFile(i); std::shared_ptr<const UICommon::GameFile> game = m_game_list_model->GetGameFile(i);
auto* item = new QListWidgetItem(QString::fromStdString(game->GetNetPlayName())); auto* item =
new QListWidgetItem(QString::fromStdString(m_game_list_model->GetNetPlayName(*game)));
item->setData(Qt::UserRole, QVariant::fromValue(std::move(game))); item->setData(Qt::UserRole, QVariant::fromValue(std::move(game)));
m_host_games->addItem(item); m_host_games->addItem(item);
} }

View File

@ -535,7 +535,7 @@ std::vector<DiscIO::Language> GameFile::GetLanguages() const
return languages; return languages;
} }
std::string GameFile::GetNetPlayName() const std::string GameFile::GetNetPlayName(const Core::TitleDatabase& title_database) const
{ {
std::vector<std::string> info; std::vector<std::string> info;
if (!GetGameID().empty()) if (!GetGameID().empty())
@ -543,12 +543,7 @@ std::string GameFile::GetNetPlayName() const
if (GetRevision() != 0) if (GetRevision() != 0)
info.push_back("Revision " + std::to_string(GetRevision())); info.push_back("Revision " + std::to_string(GetRevision()));
std::string name = GetLongName(DiscIO::Language::English); const std::string name = GetName(title_database);
if (name.empty())
{
// Use the file name as a fallback. Not necessarily consistent, but it's the best we have
name = m_file_name;
}
int disc_number = GetDiscNumber() + 1; int disc_number = GetDiscNumber() + 1;

View File

@ -82,7 +82,7 @@ public:
u16 GetRevision() const { return m_revision; } u16 GetRevision() const { return m_revision; }
// 0 is the first disc, 1 is the second disc // 0 is the first disc, 1 is the second disc
u8 GetDiscNumber() const { return m_disc_number; } u8 GetDiscNumber() const { return m_disc_number; }
std::string GetNetPlayName() const; std::string GetNetPlayName(const Core::TitleDatabase& title_database) const;
// This function is slow // This function is slow
std::array<u8, 20> GetSyncHash() const; std::array<u8, 20> GetSyncHash() const;