Skip to content

Commit

Permalink
GameFile: Use enums for custom/length parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
JosJuice committed Sep 25, 2019
1 parent 8e86b63 commit 32a014b
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 18 deletions.
6 changes: 4 additions & 2 deletions Source/Android/jni/GameList/GameFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,15 @@ JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getPlatform
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getTitle(JNIEnv* env,
jobject obj)
{
return ToJString(env, GetRef(env, obj)->GetName(true));
return ToJString(env,
GetRef(env, obj)->GetName(UICommon::GameFile::Variant::LongAndPossiblyCustom));
}

JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getDescription(JNIEnv* env,
jobject obj)
{
return ToJString(env, GetRef(env, obj)->GetDescription(true));
return ToJString(
env, GetRef(env, obj)->GetDescription(UICommon::GameFile::Variant::LongAndPossiblyCustom));
}

JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getCompany(JNIEnv* env,
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DolphinQt/Config/InfoWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ QGroupBox* InfoWidget::CreateISODetails()

QLineEdit* country = CreateValueDisplay(DiscIO::GetName(m_game.GetCountry(), true));

const std::string game_maker = m_game.GetMaker(false);
const std::string game_maker = m_game.GetMaker(UICommon::GameFile::Variant::LongAndNotCustom);

QLineEdit* maker =
CreateValueDisplay((game_maker.empty() ? UNKNOWN_NAME.toStdString() : game_maker) + " (" +
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DolphinQt/GameList/GameList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ void GameList::ExportWiiSave()
for (const auto& game : GetSelectedGames())
{
if (!WiiSave::Export(game->GetTitleID(), export_dir.toStdString()))
failed.push_back(game->GetName(true));
failed.push_back(game->GetName(UICommon::GameFile::Variant::LongAndPossiblyCustom));
}

if (!failed.isEmpty())
Expand Down
8 changes: 6 additions & 2 deletions Source/Core/DolphinQt/GameList/GameListModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,17 @@ QVariant GameListModel::data(const QModelIndex& index, int role) const
case COL_DESCRIPTION:
if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole)
{
return QString::fromStdString(game.GetDescription(true))
return QString::fromStdString(
game.GetDescription(UICommon::GameFile::Variant::LongAndPossiblyCustom))
.replace(QLatin1Char('\n'), QLatin1Char(' '));
}
break;
case COL_MAKER:
if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole)
return QString::fromStdString(game.GetMaker(true));
{
return QString::fromStdString(
game.GetMaker(UICommon::GameFile::Variant::LongAndPossiblyCustom));
}
break;
case COL_FILE_NAME:
if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole)
Expand Down
19 changes: 10 additions & 9 deletions Source/Core/UICommon/GameFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,28 +469,29 @@ void GameFile::CustomBannerCommit()
const std::string& GameFile::GetName(const Core::TitleDatabase& title_database) const
{
const std::string& custom_name = title_database.GetTitleName(m_gametdb_id, GetConfigLanguage());
return custom_name.empty() ? GetName(true) : custom_name;
return custom_name.empty() ? GetName(Variant::LongAndPossiblyCustom) : custom_name;
}

const std::string& GameFile::GetName(bool allow_custom_name, bool long_name) const
const std::string& GameFile::GetName(Variant variant) const
{
if (allow_custom_name && !m_custom_name.empty())
if (variant == Variant::LongAndPossiblyCustom && !m_custom_name.empty())
return m_custom_name;

const std::string& name = long_name ? GetLongName() : GetShortName();
const std::string& name = variant == Variant::ShortAndNotCustom ? GetShortName() : GetLongName();
if (!name.empty())
return name;

// No usable name, return filename (better than nothing)
return m_file_name;
}

const std::string& GameFile::GetMaker(bool allow_custom_maker, bool long_maker) const
const std::string& GameFile::GetMaker(Variant variant) const
{
if (allow_custom_maker && !m_custom_maker.empty())
if (variant == Variant::LongAndPossiblyCustom && !m_custom_maker.empty())
return m_custom_maker;

const std::string& maker = long_maker ? GetLongMaker() : GetShortMaker();
const std::string& maker =
variant == Variant::ShortAndNotCustom ? GetShortMaker() : GetLongMaker();
if (!maker.empty())
return maker;

Expand All @@ -500,9 +501,9 @@ const std::string& GameFile::GetMaker(bool allow_custom_maker, bool long_maker)
return EMPTY_STRING;
}

const std::string& GameFile::GetDescription(bool allow_custom_description) const
const std::string& GameFile::GetDescription(Variant variant) const
{
if (allow_custom_description && !m_custom_description.empty())
if (variant == Variant::LongAndPossiblyCustom && !m_custom_description.empty())
return m_custom_description;

return LookupUsingConfigLanguage(m_descriptions);
Expand Down
13 changes: 10 additions & 3 deletions Source/Core/UICommon/GameFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ bool operator!=(const GameBanner& lhs, const GameBanner& rhs);
class GameFile final
{
public:
enum class Variant
{
LongAndPossiblyCustom,
LongAndNotCustom,
ShortAndNotCustom,
};

GameFile();
explicit GameFile(std::string path);
~GameFile();
Expand All @@ -52,8 +59,8 @@ class GameFile final
const std::string& GetFilePath() const { return m_file_path; }
const std::string& GetFileName() const { return m_file_name; }
const std::string& GetName(const Core::TitleDatabase& title_database) const;
const std::string& GetName(bool allow_custom_name, bool long_name = true) const;
const std::string& GetMaker(bool allow_custom_maker, bool long_maker = true) const;
const std::string& GetName(Variant variant) const;
const std::string& GetMaker(Variant variant) const;
const std::string& GetShortName(DiscIO::Language l) const { return Lookup(l, m_short_names); }
const std::string& GetShortName() const { return LookupUsingConfigLanguage(m_short_names); }
const std::string& GetLongName(DiscIO::Language l) const { return Lookup(l, m_long_names); }
Expand All @@ -63,7 +70,7 @@ class GameFile final
const std::string& GetLongMaker(DiscIO::Language l) const { return Lookup(l, m_long_makers); }
const std::string& GetLongMaker() const { return LookupUsingConfigLanguage(m_long_makers); }
const std::string& GetDescription(DiscIO::Language l) const { return Lookup(l, m_descriptions); }
const std::string& GetDescription(bool allow_custom_description) const;
const std::string& GetDescription(Variant variant) const;
std::vector<DiscIO::Language> GetLanguages() const;
const std::string& GetInternalName() const { return m_internal_name; }
const std::string& GetGameID() const { return m_game_id; }
Expand Down

0 comments on commit 32a014b

Please sign in to comment.