Core: Cleanup locale handling.

It also fixes the recent problem of strange strings.

--HG--
branch : trunk
This commit is contained in:
linencloth
2010-09-17 07:04:29 +02:00
parent 5de48a67c6
commit d8a854d6e0
19 changed files with 39 additions and 45 deletions
+10 -16
View File
@@ -7640,31 +7640,25 @@ PetNameInvalidReason ObjectMgr::CheckPetName(const std::string& name)
return PET_NAME_SUCCESS;
}
int ObjectMgr::GetIndexForLocale(LocaleConstant loc)
LocaleConstant ObjectMgr::GetIndexForLocale(LocaleConstant loc)
{
if (loc == LOCALE_enUS)
return -1;
for (size_t i=0; i < m_LocalForIndex.size(); ++i)
if (m_LocalForIndex[i] == loc)
return i;
return loc;
return -1;
return DEFAULT_LOCALE;
}
LocaleConstant ObjectMgr::GetLocaleForIndex(int i)
{
if (i < 0 || i >= int(m_LocalForIndex.size()))
return LOCALE_enUS;
return DEFAULT_LOCALE;
return m_LocalForIndex[i];
}
int ObjectMgr::GetOrNewIndexForLocale(LocaleConstant loc)
{
if (loc == LOCALE_enUS)
return -1;
for (size_t i = 0; i < m_LocalForIndex.size(); ++i)
if (m_LocalForIndex[i] == loc)
return i;
@@ -7815,8 +7809,7 @@ bool ObjectMgr::LoadTrinityStrings(char const* table, int32 min_value, int32 max
data.Content.resize(1);
++count;
data.Default = fields[1].GetCppString();
for (uint8 i = 1; i < MAX_LOCALE; ++i)
for (uint8 i = 0; i < MAX_LOCALE; ++i)
{
std::string str = fields[i + 1].GetCppString();
AddLocaleString(str, LocaleConstant(i), data.Content);
@@ -7832,13 +7825,14 @@ bool ObjectMgr::LoadTrinityStrings(char const* table, int32 min_value, int32 max
return true;
}
const char *ObjectMgr::GetTrinityString(int32 entry, int locale_idx) const
const char *ObjectMgr::GetTrinityString(int32 entry, LocaleConstant locale_idx) const
{
if (TrinityStringLocale const *msl = GetTrinityStringLocale(entry))
{
std::string s = msl->Default;
GetLocaleString(msl->Content, locale_idx, s);
return s.c_str();
if (msl->Content.size() > size_t(locale_idx) && !msl->Content[locale_idx].empty())
return msl->Content[locale_idx].c_str();
return msl->Content[DEFAULT_LOCALE].c_str();
}
if (entry > 0)
+4 -5
View File
@@ -174,7 +174,6 @@ typedef UNORDERED_MAP<uint64/*(instance,guid) pair*/,time_t> RespawnTimes;
struct TrinityStringLocale
{
std::string Default;
StringVector Content;
};
@@ -864,9 +863,9 @@ class ObjectMgr
if (itr == mTrinityStringLocaleMap.end()) return NULL;
return &itr->second;
}
const char *GetTrinityString(int32 entry, int locale_idx) const;
const char *GetTrinityString(int32 entry, LocaleConstant locale_idx) const;
const char *GetTrinityStringForDBCLocale(int32 entry) const { return GetTrinityString(entry,DBCLocaleIndex); }
int32 GetDBCLocaleIndex() const { return DBCLocaleIndex; }
LocaleConstant GetDBCLocaleIndex() const { return DBCLocaleIndex; }
void SetDBCLocaleIndex(uint32 lang) { DBCLocaleIndex = GetIndexForLocale(LocaleConstant(lang)); }
void AddCorpseCellData(uint32 mapid, uint32 cellid, uint32 player_guid, uint32 instance);
@@ -906,7 +905,7 @@ class ObjectMgr
static bool CheckDeclinedNames(std::wstring mainpart, DeclinedName const& names);
int GetIndexForLocale(LocaleConstant loc);
LocaleConstant GetIndexForLocale(LocaleConstant loc);
LocaleConstant GetLocaleForIndex(int i);
GameTele const* GetGameTele(uint32 id) const
@@ -1080,7 +1079,7 @@ class ObjectMgr
typedef std::vector<LocaleConstant> LocalForIndex;
LocalForIndex m_LocalForIndex;
int DBCLocaleIndex;
LocaleConstant DBCLocaleIndex;
private:
void LoadScripts(ScriptsType type);