summaryrefslogtreecommitdiff
path: root/Source/Core/DolphinWX/ISOFile.cpp
diff options
context:
space:
mode:
authorJosJuice <josjuice@gmail.com>2015-04-09 17:44:53 +0200
committerJosJuice <josjuice@gmail.com>2015-04-23 08:14:39 +0200
commit235ecfbed71986f0be2ecf469a10e1105dcb3c96 (patch)
tree36427d6c1bedd2b695fc3bd68a66743d8c26e33f /Source/Core/DolphinWX/ISOFile.cpp
parent87a63713f4f7c583545f23b75ed8395913c8e600 (diff)
Return GetNames languages, to avoid hardcoded language lists in callers
This makes the code cleaner and also leads to some user-visible changes: The wx game properties will no longer let the user select WAD languages that don't have any names. The Qt game list will now display names using the languages set in the configuration instead of always using English for PAL GC games and Japanese for WADs. If a WAD doesn't have a name in the user's preferred language, English is now selected as a fallback before Japanese.
Diffstat (limited to 'Source/Core/DolphinWX/ISOFile.cpp')
-rw-r--r--Source/Core/DolphinWX/ISOFile.cpp96
1 files changed, 55 insertions, 41 deletions
diff --git a/Source/Core/DolphinWX/ISOFile.cpp b/Source/Core/DolphinWX/ISOFile.cpp
index db1c141de6..5190849435 100644
--- a/Source/Core/DolphinWX/ISOFile.cpp
+++ b/Source/Core/DolphinWX/ISOFile.cpp
@@ -7,6 +7,7 @@
#include <cstring>
#include <memory>
#include <string>
+#include <utility>
#include <vector>
#include <wx/app.h>
#include <wx/bitmap.h>
@@ -37,11 +38,33 @@
#include "DolphinWX/ISOFile.h"
#include "DolphinWX/WxUtils.h"
-static const u32 CACHE_REVISION = 0x122;
+static const u32 CACHE_REVISION = 0x123;
#define DVD_BANNER_WIDTH 96
#define DVD_BANNER_HEIGHT 32
+static std::string GetLanguageString(IVolume::ELanguage language, std::map<IVolume::ELanguage, std::string> strings)
+{
+ auto end = strings.end();
+ auto it = strings.find(language);
+ if (it != end)
+ return it->second;
+
+ // English tends to be a good fallback when the requested language isn't available
+ if (language != IVolume::ELanguage::LANGUAGE_ENGLISH)
+ {
+ it = strings.find(IVolume::ELanguage::LANGUAGE_ENGLISH);
+ if (it != end)
+ return it->second;
+ }
+
+ // If English isn't available either, just pick something
+ if (!strings.empty())
+ return strings.cbegin()->second;
+
+ return "";
+}
+
GameListItem::GameListItem(const std::string& _rFileName)
: m_FileName(_rFileName)
, m_emu_state(0)
@@ -202,63 +225,37 @@ std::string GameListItem::CreateCacheFilename()
std::string GameListItem::GetCompany() const
{
- if (m_company.empty())
- return "N/A";
- else
- return m_company;
+ return m_company;
}
-// (-1 = Japanese, 0 = English, etc)?
-std::string GameListItem::GetDescription(int _index) const
+std::string GameListItem::GetDescription(IVolume::ELanguage language) const
{
- const u32 index = _index;
-
- if (index < m_descriptions.size())
- return m_descriptions[index];
-
- if (!m_descriptions.empty())
- return m_descriptions[0];
-
- return "";
+ return GetLanguageString(language, m_descriptions);
}
-// (-1 = Japanese, 0 = English, etc)?
-std::string GameListItem::GetVolumeName(int _index) const
+std::string GameListItem::GetDescription() const
{
- u32 const index = _index;
-
- if (index < m_volume_names.size() && !m_volume_names[index].empty())
- return m_volume_names[index];
-
- if (!m_volume_names.empty())
- return m_volume_names[0];
-
- return "";
+ return GetDescription(SConfig::GetInstance().m_LocalCoreStartupParameter.GetCurrentLanguage(m_Platform != GAMECUBE_DISC));
}
-// (-1 = Japanese, 0 = English, etc)?
-std::string GameListItem::GetBannerName(int _index) const
+std::string GameListItem::GetVolumeName(IVolume::ELanguage language) const
{
- u32 const index = _index;
-
- if (index < m_banner_names.size() && !m_banner_names[index].empty())
- return m_banner_names[index];
-
- if (!m_banner_names.empty())
- return m_banner_names[0];
+ return GetLanguageString(language, m_volume_names);
+}
- return "";
+std::string GameListItem::GetBannerName(IVolume::ELanguage language) const
+{
+ return GetLanguageString(language, m_banner_names);
}
-// (-1 = Japanese, 0 = English, etc)?
-std::string GameListItem::GetName(int _index) const
+std::string GameListItem::GetName(IVolume::ELanguage language) const
{
// Prefer name from banner, fallback to name from volume, fallback to filename
- std::string name = GetBannerName(_index);
+ std::string name = GetBannerName(language);
if (name.empty())
- name = GetVolumeName(_index);
+ name = GetVolumeName(language);
if (name.empty())
{
@@ -269,6 +266,23 @@ std::string GameListItem::GetName(int _index) const
return name;
}
+std::string GameListItem::GetName() const
+{
+ return GetName(SConfig::GetInstance().m_LocalCoreStartupParameter.GetCurrentLanguage(m_Platform != GAMECUBE_DISC));
+}
+
+std::vector<IVolume::ELanguage> GameListItem::GetLanguages() const
+{
+ std::map<IVolume::ELanguage, std::string> language_strings = m_banner_names;
+ if (m_volume_names.size() > m_banner_names.size())
+ language_strings = m_volume_names;
+
+ std::vector<IVolume::ELanguage> languages;
+ for (std::pair<IVolume::ELanguage, std::string> language_string : language_strings)
+ languages.emplace_back(language_string.first);
+ return languages;
+}
+
const std::string GameListItem::GetWiiFSPath() const
{
DiscIO::IVolume *iso = DiscIO::CreateVolumeFromFilename(m_FileName);