Merge pull request #2403 from JosJuice/short-titles

DolphinQt: Use short GC game titles in grid view
This commit is contained in:
Matthew Parlane 2015-06-08 20:15:29 +10:00
commit 5a0daef7f0
15 changed files with 98 additions and 109 deletions

View File

@ -85,7 +85,7 @@ public:
virtual std::string GetMakerID() const = 0;
virtual u16 GetRevision() const = 0;
virtual std::string GetInternalName() const = 0;
virtual std::map<ELanguage, std::string> GetNames() const = 0;
virtual std::map<ELanguage, std::string> GetNames(bool prefer_long) const = 0;
virtual std::map<ELanguage, std::string> GetDescriptions() const { return std::map<ELanguage, std::string>(); }
virtual std::string GetCompany() const { return std::string(); }
virtual std::vector<u32> GetBanner(int* width, int* height) const;

View File

@ -191,7 +191,7 @@ std::string CVolumeDirectory::GetInternalName() const
return "";
}
std::map<IVolume::ELanguage, std::string> CVolumeDirectory::GetNames() const
std::map<IVolume::ELanguage, std::string> CVolumeDirectory::GetNames(bool prefer_long) const
{
std::map<IVolume::ELanguage, std::string> names;
std::string name = GetInternalName();

View File

@ -41,7 +41,7 @@ public:
u16 GetRevision() const override { return 0; }
std::string GetInternalName() const override;
std::map<IVolume::ELanguage, std::string> GetNames() const override;
std::map<IVolume::ELanguage, std::string> GetNames(bool prefer_long) const override;
void SetName(const std::string&);
u32 GetFSTSize() const override;

View File

@ -105,91 +105,14 @@ std::string CVolumeGC::GetInternalName() const
return "";
}
std::map<IVolume::ELanguage, std::string> CVolumeGC::GetNames() const
std::map<IVolume::ELanguage, std::string> CVolumeGC::GetNames(bool prefer_long) const
{
std::map<IVolume::ELanguage, std::string> names;
if (!LoadBannerFile())
return names;
u32 name_count = 0;
IVolume::ELanguage language;
bool is_japanese = GetCountry() == IVolume::ECountry::COUNTRY_JAPAN;
switch (m_banner_file_type)
{
case BANNER_BNR1:
name_count = 1;
language = is_japanese ? IVolume::ELanguage::LANGUAGE_JAPANESE : IVolume::ELanguage::LANGUAGE_ENGLISH;
break;
case BANNER_BNR2:
name_count = 6;
language = IVolume::ELanguage::LANGUAGE_ENGLISH;
break;
case BANNER_INVALID:
case BANNER_NOT_LOADED:
break;
}
auto const banner = reinterpret_cast<const GCBanner*>(m_banner_file.data());
for (u32 i = 0; i < name_count; ++i)
{
auto& comment = banner->comment[i];
std::string name = DecodeString(comment.longTitle);
if (name.empty())
name = DecodeString(comment.shortTitle);
if (!name.empty())
names[(IVolume::ELanguage)(language + i)] = name;
}
return names;
return ReadMultiLanguageStrings(false, prefer_long);
}
std::map<IVolume::ELanguage, std::string> CVolumeGC::GetDescriptions() const
{
std::map<IVolume::ELanguage, std::string> descriptions;
if (!LoadBannerFile())
return descriptions;
u32 desc_count = 0;
IVolume::ELanguage language;
bool is_japanese = GetCountry() == IVolume::ECountry::COUNTRY_JAPAN;
switch (m_banner_file_type)
{
case BANNER_BNR1:
desc_count = 1;
language = is_japanese ? IVolume::ELanguage::LANGUAGE_JAPANESE : IVolume::ELanguage::LANGUAGE_ENGLISH;
break;
case BANNER_BNR2:
language = IVolume::ELanguage::LANGUAGE_ENGLISH;
desc_count = 6;
break;
case BANNER_INVALID:
case BANNER_NOT_LOADED:
break;
}
auto banner = reinterpret_cast<const GCBanner*>(m_banner_file.data());
for (u32 i = 0; i < desc_count; ++i)
{
auto& data = banner->comment[i].comment;
std::string description = DecodeString(data);
if (!description.empty())
descriptions[(IVolume::ELanguage)(language + i)] = description;
}
return descriptions;
return ReadMultiLanguageStrings(true);
}
std::string CVolumeGC::GetCompany() const
@ -277,14 +200,17 @@ IVolume::EPlatform CVolumeGC::GetVolumeType() const
return GAMECUBE_DISC;
}
// Returns true if the loaded banner file is valid,
// regardless of whether it was loaded by the current call
bool CVolumeGC::LoadBannerFile() const
{
// The methods GetNames, GetDescriptions, GetCompany and GetBanner
// all need to access the opening.bnr file. These four methods are
// typically called after each other, so we store the file in RAM
// to avoid reading it from the disc several times. However,
// The methods ReadMultiLanguageStrings, GetCompany and GetBanner
// need to access the opening.bnr file. These methods are
// usually called one after another. The file is cached in
// RAM to avoid reading it from the disc several times, but
// if none of these methods are called, the file is never loaded.
// If opening.bnr has been loaded already, return immediately
if (m_banner_file_type != BANNER_NOT_LOADED)
return m_banner_file_type != BANNER_INVALID;
@ -319,4 +245,60 @@ bool CVolumeGC::LoadBannerFile() const
return m_banner_file_type != BANNER_INVALID;
}
std::map<IVolume::ELanguage, std::string> CVolumeGC::ReadMultiLanguageStrings(bool description, bool prefer_long) const
{
std::map<ELanguage, std::string> strings;
if (!LoadBannerFile())
return strings;
u32 number_of_languages = 0;
ELanguage start_language;
bool is_japanese = GetCountry() == ECountry::COUNTRY_JAPAN;
switch (m_banner_file_type)
{
case BANNER_BNR1: // NTSC
number_of_languages = 1;
start_language = is_japanese ? ELanguage::LANGUAGE_JAPANESE : ELanguage::LANGUAGE_ENGLISH;
break;
case BANNER_BNR2: // PAL
number_of_languages = 6;
start_language = ELanguage::LANGUAGE_ENGLISH;
break;
// Shouldn't happen
case BANNER_INVALID:
case BANNER_NOT_LOADED:
break;
}
auto const banner = reinterpret_cast<const GCBanner*>(m_banner_file.data());
for (u32 i = 0; i < number_of_languages; ++i)
{
GCBannerComment comment = banner->comment[i];
std::string string;
if (description)
{
string = DecodeString(comment.comment);
}
else // Title
{
if (prefer_long)
string = DecodeString(comment.longTitle);
if (string.empty())
string = DecodeString(comment.shortTitle);
}
if (!string.empty())
strings[(ELanguage)(start_language + i)] = string;
}
return strings;
}
} // namespace

View File

@ -29,7 +29,7 @@ public:
std::string GetMakerID() const override;
u16 GetRevision() const override;
virtual std::string GetInternalName() const override;
std::map<ELanguage, std::string> GetNames() const override;
std::map<ELanguage, std::string> GetNames(bool prefer_long) const override;
std::map<ELanguage, std::string> GetDescriptions() const override;
std::string GetCompany() const override;
std::vector<u32> GetBanner(int* width, int* height) const override;
@ -44,6 +44,7 @@ public:
private:
bool LoadBannerFile() const;
std::map<ELanguage, std::string> ReadMultiLanguageStrings(bool description, bool prefer_long = true) const;
static const int GC_BANNER_WIDTH = 96;
static const int GC_BANNER_HEIGHT = 32;

View File

@ -117,7 +117,7 @@ IVolume::EPlatform CVolumeWAD::GetVolumeType() const
return WII_WAD;
}
std::map<IVolume::ELanguage, std::string> CVolumeWAD::GetNames() const
std::map<IVolume::ELanguage, std::string> CVolumeWAD::GetNames(bool prefer_long) const
{
std::vector<u8> name_data(NAMES_TOTAL_BYTES);
if (!Read(m_opening_bnr_offset + 0x9C, NAMES_TOTAL_BYTES, name_data.data()))

View File

@ -32,7 +32,7 @@ public:
std::string GetMakerID() const override;
u16 GetRevision() const override;
std::string GetInternalName() const override { return ""; }
std::map<IVolume::ELanguage, std::string> GetNames() const override;
std::map<IVolume::ELanguage, std::string> GetNames(bool prefer_long) const override;
u32 GetFSTSize() const override { return 0; }
std::string GetApploaderDate() const override { return ""; }

View File

@ -202,7 +202,7 @@ std::string CVolumeWiiCrypted::GetInternalName() const
return "";
}
std::map<IVolume::ELanguage, std::string> CVolumeWiiCrypted::GetNames() const
std::map<IVolume::ELanguage, std::string> CVolumeWiiCrypted::GetNames(bool prefer_long) const
{
std::unique_ptr<IFileSystem> file_system(CreateFileSystem(this));
std::vector<u8> opening_bnr(NAMES_TOTAL_BYTES);

View File

@ -32,7 +32,7 @@ public:
std::string GetMakerID() const override;
u16 GetRevision() const override;
std::string GetInternalName() const override;
std::map<IVolume::ELanguage, std::string> GetNames() const override;
std::map<IVolume::ELanguage, std::string> GetNames(bool prefer_long) const override;
u32 GetFSTSize() const override;
std::string GetApploaderDate() const override;
u8 GetDiscNumber() const override;

View File

@ -25,7 +25,7 @@
#include "DolphinQt/Utils/Resources.h"
#include "DolphinQt/Utils/Utils.h"
static const u32 CACHE_REVISION = 0x009;
static const u32 CACHE_REVISION = 0x00A;
static const u32 DATASTREAM_REVISION = 15; // Introduced in Qt 5.2
static QMap<DiscIO::IVolume::ELanguage, QString> ConvertLocalizedStrings(std::map<DiscIO::IVolume::ELanguage, std::string> strings)
@ -87,7 +87,8 @@ GameFile::GameFile(const QString& fileName)
{
m_platform = volume->GetVolumeType();
m_names = ConvertLocalizedStrings(volume->GetNames());
m_short_names = ConvertLocalizedStrings(volume->GetNames(false));
m_long_names = ConvertLocalizedStrings(volume->GetNames(true));
m_descriptions = ConvertLocalizedStrings(volume->GetDescriptions());
m_company = QString::fromStdString(volume->GetCompany());
@ -165,10 +166,12 @@ bool GameFile::LoadFromCache()
u32 country;
u32 platform;
QMap<u8, QString> names;
QMap<u8, QString> short_names;
QMap<u8, QString> long_names;
QMap<u8, QString> descriptions;
stream >> m_folder_name
>> names
>> short_names
>> long_names
>> descriptions
>> m_company
>> m_unique_id
@ -182,7 +185,8 @@ bool GameFile::LoadFromCache()
>> m_revision;
m_country = (DiscIO::IVolume::ECountry)country;
m_platform = (DiscIO::IVolume::EPlatform)platform;
m_names = CastLocalizedStrings<DiscIO::IVolume::ELanguage>(names);
m_short_names = CastLocalizedStrings<DiscIO::IVolume::ELanguage>(short_names);
m_long_names = CastLocalizedStrings<DiscIO::IVolume::ELanguage>(long_names);
m_descriptions = CastLocalizedStrings<DiscIO::IVolume::ELanguage>(descriptions);
file.close();
return true;
@ -209,7 +213,8 @@ void GameFile::SaveToCache()
stream << CACHE_REVISION;
stream << m_folder_name
<< CastLocalizedStrings<u8>(m_names)
<< CastLocalizedStrings<u8>(m_short_names)
<< CastLocalizedStrings<u8>(m_long_names)
<< CastLocalizedStrings<u8>(m_descriptions)
<< m_company
<< m_unique_id
@ -258,15 +263,15 @@ QString GameFile::GetDescription() const
return GetDescription(SConfig::GetInstance().m_LocalCoreStartupParameter.GetCurrentLanguage(wii));
}
QString GameFile::GetName(DiscIO::IVolume::ELanguage language) const
QString GameFile::GetName(bool prefer_long, DiscIO::IVolume::ELanguage language) const
{
return GetLanguageString(language, m_names);
return GetLanguageString(language, prefer_long ? m_long_names : m_short_names);
}
QString GameFile::GetName() const
QString GameFile::GetName(bool prefer_long) const
{
bool wii = m_platform != DiscIO::IVolume::GAMECUBE_DISC;
QString name = GetName(SConfig::GetInstance().m_LocalCoreStartupParameter.GetCurrentLanguage(wii));
QString name = GetName(prefer_long, SConfig::GetInstance().m_LocalCoreStartupParameter.GetCurrentLanguage(wii));
if (name.isEmpty())
{
// No usable name, return filename (better than nothing)

View File

@ -22,8 +22,8 @@ public:
bool IsValid() const { return m_valid; }
QString GetFileName() { return m_file_name; }
QString GetFolderName() { return m_folder_name; }
QString GetName(DiscIO::IVolume::ELanguage language) const;
QString GetName() const;
QString GetName(bool prefer_long, DiscIO::IVolume::ELanguage language) const;
QString GetName(bool prefer_long) const;
QString GetDescription(DiscIO::IVolume::ELanguage language) const;
QString GetDescription() const;
QString GetCompany() const;
@ -45,7 +45,8 @@ private:
QString m_file_name;
QString m_folder_name;
QMap<DiscIO::IVolume::ELanguage, QString> m_names;
QMap<DiscIO::IVolume::ELanguage, QString> m_short_names;
QMap<DiscIO::IVolume::ELanguage, QString> m_long_names;
QMap<DiscIO::IVolume::ELanguage, QString> m_descriptions;
QString m_company;

View File

@ -76,7 +76,7 @@ void DGameGrid::AddGame(GameFile* gameItem)
QListWidgetItem* i = new QListWidgetItem;
i->setIcon(QIcon(gameItem->GetBitmap()
.scaled(GRID_BANNER_WIDTH, GRID_BANNER_HEIGHT, Qt::KeepAspectRatio, Qt::SmoothTransformation)));
i->setText(gameItem->GetName());
i->setText(gameItem->GetName(false));
if (gameItem->IsCompressed())
i->setTextColor(QColor("#00F"));

View File

@ -110,7 +110,7 @@ void DGameTree::AddGame(GameFile* item)
QTreeWidgetItem* i = new QTreeWidgetItem;
i->setIcon(COL_TYPE, QIcon(Resources::GetPlatformPixmap(item->GetPlatform())));
i->setIcon(COL_BANNER, QIcon(item->GetBitmap()));
i->setText(COL_TITLE, item->GetName());
i->setText(COL_TITLE, item->GetName(true));
i->setText(COL_DESCRIPTION, item->GetDescription());
i->setIcon(COL_REGION, QIcon(Resources::GetRegionPixmap(item->GetCountry())));
i->setText(COL_SIZE, NiceSizeFormat(item->GetFileSize()));

View File

@ -84,7 +84,7 @@ GameListItem::GameListItem(const std::string& _rFileName)
{
m_Platform = pVolume->GetVolumeType();
m_names = pVolume->GetNames();
m_names = pVolume->GetNames(true);
m_descriptions = pVolume->GetDescriptions();
m_company = pVolume->GetCompany();

View File

@ -222,7 +222,7 @@ static std::string GetTitle(std::string filename)
std::unique_ptr<DiscIO::IVolume> pVolume(DiscIO::CreateVolumeFromFilename(filename));
if (pVolume != nullptr) {
std::map <DiscIO::IVolume::ELanguage, std::string> titles = pVolume->GetNames();
std::map <DiscIO::IVolume::ELanguage, std::string> titles = pVolume->GetNames(true);
/*
bool is_wii_title = pVolume->GetVolumeType() != DiscIO::IVolume::GAMECUBE_DISC;