diff options
author | HeartWell <heartwell@list.ru> | 2016-11-05 22:43:11 +0300 |
---|---|---|
committer | Shin <borzifrancesco@gmail.com> | 2016-11-05 20:43:11 +0100 |
commit | c8cc99be37314eb5d86d176bacced6a96c020256 (patch) | |
tree | 6c86fbb29f6d5aac0e178d16ebc0acb027801beb /src | |
parent | f54f7ce7dc5ec748c1e38710e140fba4b1157330 (diff) |
Core/Object: Localization objects. (#226)
Diffstat (limited to 'src')
-rw-r--r-- | src/game/Entities/GameObject/GameObject.cpp | 10 | ||||
-rw-r--r-- | src/game/Globals/ObjectMgr.cpp | 26 | ||||
-rw-r--r-- | src/game/Globals/ObjectMgr.h | 6 | ||||
-rw-r--r-- | src/game/Handlers/QueryHandler.cpp | 22 | ||||
-rw-r--r-- | src/scripts/Commands/cs_lookup.cpp | 28 |
5 files changed, 76 insertions, 16 deletions
diff --git a/src/game/Entities/GameObject/GameObject.cpp b/src/game/Entities/GameObject/GameObject.cpp index b6931c5f70..58a476e5f1 100644 --- a/src/game/Entities/GameObject/GameObject.cpp +++ b/src/game/Entities/GameObject/GameObject.cpp @@ -1903,7 +1903,15 @@ void GameObject::EventInform(uint32 eventId) // overwrite WorldObject function for proper name localization std::string const& GameObject::GetNameForLocaleIdx(LocaleConstant loc_idx) const -{ +{ + if (loc_idx != DEFAULT_LOCALE) + { + uint8 uloc_idx = uint8(loc_idx); + if (GameObjectLocale const* cl = sObjectMgr->GetGameObjectLocale(GetEntry())) + if (cl->Name.size() > uloc_idx && !cl->Name[uloc_idx].empty()) + return cl->Name[uloc_idx]; + } + return GetName(); } diff --git a/src/game/Globals/ObjectMgr.cpp b/src/game/Globals/ObjectMgr.cpp index 085be3cca5..cc44f916aa 100644 --- a/src/game/Globals/ObjectMgr.cpp +++ b/src/game/Globals/ObjectMgr.cpp @@ -6439,13 +6439,10 @@ void ObjectMgr::LoadGameObjectLocales() { uint32 oldMSTime = getMSTime(); - _gameObjectLocaleStore.clear(); // need for reload case - - QueryResult result = WorldDatabase.Query("SELECT entry, " - "name_loc1, name_loc2, name_loc3, name_loc4, name_loc5, name_loc6, name_loc7, name_loc8, " - "castbarcaption_loc1, castbarcaption_loc2, castbarcaption_loc3, castbarcaption_loc4, " - "castbarcaption_loc5, castbarcaption_loc6, castbarcaption_loc7, castbarcaption_loc8 FROM locales_gameobject"); + _gameObjectLocaleStore.clear(); // need for reload case + // 0 1 2 3 + QueryResult result = WorldDatabase.Query("SELECT entry, locale, name, castBarCaption FROM gameobject_template_locale"); if (!result) return; @@ -6453,15 +6450,20 @@ void ObjectMgr::LoadGameObjectLocales() { Field* fields = result->Fetch(); - uint32 entry = fields[0].GetUInt32(); + uint32 id = fields[0].GetUInt32(); + std::string localeName = fields[1].GetString(); - GameObjectLocale& data = _gameObjectLocaleStore[entry]; + std::string name = fields[2].GetString(); + std::string castBarCaption = fields[3].GetString(); - for (uint8 i = 1; i < TOTAL_LOCALES; ++i) - AddLocaleString(fields[i].GetString(), LocaleConstant(i), data.Name); + GameObjectLocale& data = _gameObjectLocaleStore[id]; + LocaleConstant locale = GetLocaleByName(localeName); + if (locale == LOCALE_enUS) + continue; + + AddLocaleString(name, locale, data.Name); + AddLocaleString(castBarCaption, locale, data.CastBarCaption); - for (uint8 i = 1; i < TOTAL_LOCALES; ++i) - AddLocaleString(fields[i + (TOTAL_LOCALES - 1)].GetString(), LocaleConstant(i), data.CastBarCaption); } while (result->NextRow()); sLog->outString(">> Loaded %lu gameobject locale strings in %u ms", (unsigned long)_gameObjectLocaleStore.size(), GetMSTimeDiffToNow(oldMSTime)); diff --git a/src/game/Globals/ObjectMgr.h b/src/game/Globals/ObjectMgr.h index d8eb716210..aa3ea649fc 100644 --- a/src/game/Globals/ObjectMgr.h +++ b/src/game/Globals/ObjectMgr.h @@ -1056,6 +1056,12 @@ class ObjectMgr if (itr == _creatureLocaleStore.end()) return NULL; return &itr->second; } + GameObjectLocale const* GetGameObjectLocale(uint32 entry) const + { + GameObjectLocaleContainer::const_iterator itr = _gameObjectLocaleStore.find(entry); + if (itr == _gameObjectLocaleStore.end()) return NULL; + return &itr->second; + } ItemLocale const* GetItemLocale(uint32 entry) const { ItemLocaleContainer::const_iterator itr = _itemLocaleStore.find(entry); diff --git a/src/game/Handlers/QueryHandler.cpp b/src/game/Handlers/QueryHandler.cpp index 50ffc4597d..d1495fe034 100644 --- a/src/game/Handlers/QueryHandler.cpp +++ b/src/game/Handlers/QueryHandler.cpp @@ -148,15 +148,31 @@ void WorldSession::HandleGameObjectQueryOpcode(WorldPacket & recvData) const GameObjectTemplate* info = sObjectMgr->GetGameObjectTemplate(entry); if (info) { + std::string Name; + std::string IconName; + std::string CastBarCaption; + + Name = info->name; + IconName = info->IconName; + CastBarCaption = info->castBarCaption; + + LocaleConstant localeConstant = GetSessionDbLocaleIndex(); + if (localeConstant >= LOCALE_enUS) + if (GameObjectLocale const* gameObjectLocale = sObjectMgr->GetGameObjectLocale(entry)) + { + ObjectMgr::GetLocaleString(gameObjectLocale->Name, localeConstant, Name); + ObjectMgr::GetLocaleString(gameObjectLocale->CastBarCaption, localeConstant, CastBarCaption); + } + ;//sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: CMSG_GAMEOBJECT_QUERY '%s' - Entry: %u. ", info->name.c_str(), entry); WorldPacket data (SMSG_GAMEOBJECT_QUERY_RESPONSE, 150); data << uint32(entry); data << uint32(info->type); data << uint32(info->displayId); - data << info->name; + data << Name; data << uint8(0) << uint8(0) << uint8(0); // name2, name3, name4 - data << info->IconName; // 2.0.3, string. Icon name to use instead of default icon for go's (ex: "Attack" makes sword) - data << info->castBarCaption; // 2.0.3, string. Text will appear in Cast Bar when using GO (ex: "Collecting") + data << IconName; // 2.0.3, string. Icon name to use instead of default icon for go's (ex: "Attack" makes sword) + data << CastBarCaption; // 2.0.3, string. Text will appear in Cast Bar when using GO (ex: "Collecting") data << info->unk1; // 2.0.3, string data.append(info->raw.data, MAX_GAMEOBJECT_DATA); data << float(info->size); // go size diff --git a/src/scripts/Commands/cs_lookup.cpp b/src/scripts/Commands/cs_lookup.cpp index fda4b5e7c6..d81ce581da 100644 --- a/src/scripts/Commands/cs_lookup.cpp +++ b/src/scripts/Commands/cs_lookup.cpp @@ -551,6 +551,34 @@ public: GameObjectTemplateContainer const* gotc = sObjectMgr->GetGameObjectTemplates(); for (GameObjectTemplateContainer::const_iterator itr = gotc->begin(); itr != gotc->end(); ++itr) { + uint8 localeIndex = handler->GetSessionDbLocaleIndex(); + if (GameObjectLocale const* objectLocalte = sObjectMgr->GetGameObjectLocale(itr->second.entry)) + { + if (objectLocalte->Name.size() > localeIndex && !objectLocalte->Name[localeIndex].empty()) + { + std::string name = objectLocalte->Name[localeIndex]; + + if (Utf8FitTo(name, wNamePart)) + { + if (maxResults && count++ == maxResults) + { + handler->PSendSysMessage(LANG_COMMAND_LOOKUP_MAX_RESULTS, maxResults); + return true; + } + + if (handler->GetSession()) + handler->PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, itr->second.entry, itr->second.entry, name.c_str()); + else + handler->PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, itr->second.entry, name.c_str()); + + if (!found) + found = true; + + continue; + } + } + } + std::string name = itr->second.name; if (name.empty()) continue; |