mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-15 23:20:36 +01:00
Core/Chat: Remove fmt::sprintf from headers
This commit is contained in:
@@ -94,6 +94,8 @@ Channel::Channel(ObjectGuid const& guid, std::string const& name, uint32 team /*
|
||||
}
|
||||
}
|
||||
|
||||
Channel::~Channel() = default;
|
||||
|
||||
void Channel::GetChannelName(std::string& channelName, uint32 channelId, LocaleConstant locale, AreaTableEntry const* zoneEntry)
|
||||
{
|
||||
if (channelId)
|
||||
@@ -104,7 +106,7 @@ void Channel::GetChannelName(std::string& channelName, uint32 channelId, LocaleC
|
||||
if (channelEntry->GetFlags().HasFlag(ChatChannelFlags::LinkedChannel))
|
||||
zoneEntry = ChannelMgr::SpecialLinkedArea;
|
||||
|
||||
channelName = fmt::sprintf(channelEntry->Name[locale], ASSERT_NOTNULL(zoneEntry)->AreaName[locale]);
|
||||
channelName = ChatHandler::PGetParseString(channelEntry->Name[locale], ASSERT_NOTNULL(zoneEntry)->AreaName[locale]);
|
||||
}
|
||||
else
|
||||
channelName = channelEntry->Name[locale];
|
||||
|
||||
@@ -161,6 +161,13 @@ class TC_GAME_API Channel
|
||||
Channel(ObjectGuid const& guid, uint32 channelId, uint32 team = 0, AreaTableEntry const* zoneEntry = nullptr); // built-in channel ctor
|
||||
Channel(ObjectGuid const& guid, std::string const& name, uint32 team = 0, std::string const& banList = ""); // custom player channel ctor
|
||||
|
||||
Channel(Channel const&) = delete;
|
||||
Channel(Channel&&) = delete;
|
||||
Channel& operator=(Channel const&) = delete;
|
||||
Channel& operator=(Channel&&) = delete;
|
||||
|
||||
~Channel();
|
||||
|
||||
static void GetChannelName(std::string& channelName, uint32 channelId, LocaleConstant locale, AreaTableEntry const* zoneEntry);
|
||||
std::string GetName(LocaleConstant locale = DEFAULT_LOCALE) const;
|
||||
|
||||
|
||||
@@ -159,6 +159,11 @@ void ChatHandler::SendSysMessage(uint32 entry)
|
||||
SendSysMessage(GetTrinityString(entry));
|
||||
}
|
||||
|
||||
std::string ChatHandler::StringVPrintf(std::string_view messageFormat, fmt::printf_args messageFormatArgs)
|
||||
{
|
||||
return fmt::vsprintf<char>(messageFormat, messageFormatArgs);
|
||||
}
|
||||
|
||||
bool ChatHandler::_ParseCommands(std::string_view text)
|
||||
{
|
||||
if (Trinity::ChatCommands::TryExecuteCommand(*this, text))
|
||||
|
||||
@@ -54,23 +54,31 @@ class TC_GAME_API ChatHandler
|
||||
void SendSysMessage(uint32 entry);
|
||||
|
||||
template<typename... Args>
|
||||
void PSendSysMessage(const char* fmt, Args&&... args)
|
||||
void PSendSysMessage(char const* fmt, Args&&... args)
|
||||
{
|
||||
SendSysMessage(fmt::sprintf(fmt, std::forward<Args>(args)...));
|
||||
SendSysMessage(StringVPrintf(fmt, fmt::make_printf_args(std::forward<Args>(args)...)));
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void PSendSysMessage(uint32 entry, Args&&... args)
|
||||
{
|
||||
SendSysMessage(PGetParseString(entry, std::forward<Args>(args)...).c_str());
|
||||
SendSysMessage(PGetParseString(entry, std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
static std::string PGetParseString(std::string_view fmt, Args&&... args)
|
||||
{
|
||||
return StringVPrintf(fmt, fmt::make_printf_args(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
std::string PGetParseString(uint32 entry, Args&&... args) const
|
||||
{
|
||||
return fmt::sprintf(GetTrinityString(entry), std::forward<Args>(args)...);
|
||||
return PGetParseString(GetTrinityString(entry), std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
static std::string StringVPrintf(std::string_view messageFormat, fmt::printf_args messageFormatArgs);
|
||||
|
||||
bool _ParseCommands(std::string_view text);
|
||||
virtual bool ParseCommands(std::string_view text);
|
||||
|
||||
|
||||
@@ -28,3 +28,8 @@ char const* Trinity::Impl::ChatCommands::GetTrinityString(ChatHandler const* han
|
||||
{
|
||||
return handler->GetTrinityString(which);
|
||||
}
|
||||
|
||||
std::string Trinity::Impl::ChatCommands::FormatTrinityString(std::string_view messageFormat, fmt::printf_args messageFormatArgs)
|
||||
{
|
||||
return ChatHandler::StringVPrintf(messageFormat, messageFormatArgs);
|
||||
}
|
||||
|
||||
@@ -123,10 +123,11 @@ namespace Trinity::Impl::ChatCommands
|
||||
|
||||
TC_GAME_API void SendErrorMessageToHandler(ChatHandler* handler, std::string_view str);
|
||||
TC_GAME_API char const* GetTrinityString(ChatHandler const* handler, TrinityStrings which);
|
||||
TC_GAME_API std::string FormatTrinityString(std::string_view messageFormat, fmt::printf_args messageFormatArgs);
|
||||
template <typename... Ts>
|
||||
std::string FormatTrinityString(ChatHandler const* handler, TrinityStrings which, Ts&&... args)
|
||||
{
|
||||
return fmt::sprintf(GetTrinityString(handler, which), std::forward<Ts>(args)...);
|
||||
return FormatTrinityString(GetTrinityString(handler, which), fmt::make_printf_args(std::forward<Ts>(args)...));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -267,7 +267,7 @@ public:
|
||||
if (*target->m_playerData->PlayerTitle == titleInfo->MaskID)
|
||||
activeStr = handler->GetTrinityString(LANG_ACTIVE);
|
||||
|
||||
std::string titleName = fmt::sprintf(name, player->GetName());
|
||||
std::string titleName = ChatHandler::PGetParseString(name, player->GetName());
|
||||
|
||||
// send title in "id (idx:idx) - [namedlink locale]" format
|
||||
if (handler->GetSession())
|
||||
|
||||
@@ -1252,7 +1252,7 @@ public:
|
||||
continue;
|
||||
|
||||
LocaleConstant locale = handler->GetSessionDbcLocale();
|
||||
std::string name = (gender == GENDER_MALE ? titleInfo->Name : titleInfo->Name1)[locale];
|
||||
std::string_view name = (gender == GENDER_MALE ? titleInfo->Name : titleInfo->Name1)[locale];
|
||||
|
||||
if (name.empty())
|
||||
continue;
|
||||
@@ -1288,7 +1288,7 @@ public:
|
||||
? handler->GetTrinityString(LANG_ACTIVE)
|
||||
: "";
|
||||
|
||||
std::string titleNameStr = fmt::sprintf(name, targetName);
|
||||
std::string titleNameStr = ChatHandler::PGetParseString(name, targetName);
|
||||
|
||||
// send title in "id (idx:idx) - [namedlink locale]" format
|
||||
if (handler->GetSession())
|
||||
|
||||
@@ -80,7 +80,7 @@ public:
|
||||
}
|
||||
|
||||
std::string tNameLink = handler->GetNameLink(target);
|
||||
std::string titleNameStr = fmt::sprintf(target->GetNativeGender() == GENDER_MALE ? titleInfo->Name[handler->GetSessionDbcLocale()] : titleInfo->Name1[handler->GetSessionDbcLocale()], target->GetName());
|
||||
std::string titleNameStr = ChatHandler::PGetParseString(target->GetNativeGender() == GENDER_MALE ? titleInfo->Name[handler->GetSessionDbcLocale()] : titleInfo->Name1[handler->GetSessionDbcLocale()], target->GetName());
|
||||
|
||||
target->SetTitle(titleInfo);
|
||||
target->SetChosenTitle(titleInfo->MaskID);
|
||||
@@ -113,7 +113,7 @@ public:
|
||||
}
|
||||
|
||||
std::string tNameLink = handler->GetNameLink(target);
|
||||
std::string titleNameStr = fmt::sprintf(target->GetNativeGender() == GENDER_MALE ? titleInfo->Name[handler->GetSessionDbcLocale()] : titleInfo->Name1[handler->GetSessionDbcLocale()], target->GetName());
|
||||
std::string titleNameStr = ChatHandler::PGetParseString(target->GetNativeGender() == GENDER_MALE ? titleInfo->Name[handler->GetSessionDbcLocale()] : titleInfo->Name1[handler->GetSessionDbcLocale()], target->GetName());
|
||||
|
||||
target->SetTitle(titleInfo);
|
||||
handler->PSendSysMessage(LANG_TITLE_ADD_RES, *titleId, titleNameStr.c_str(), tNameLink.c_str());
|
||||
@@ -146,7 +146,7 @@ public:
|
||||
target->SetTitle(titleInfo, true);
|
||||
|
||||
std::string tNameLink = handler->GetNameLink(target);
|
||||
std::string titleNameStr = fmt::sprintf(target->GetNativeGender() == GENDER_MALE ? titleInfo->Name[handler->GetSessionDbcLocale()] : titleInfo->Name1[handler->GetSessionDbcLocale()], target->GetName());
|
||||
std::string titleNameStr = ChatHandler::PGetParseString(target->GetNativeGender() == GENDER_MALE ? titleInfo->Name[handler->GetSessionDbcLocale()] : titleInfo->Name1[handler->GetSessionDbcLocale()], target->GetName());
|
||||
|
||||
handler->PSendSysMessage(LANG_TITLE_REMOVE_RES, *titleId, titleNameStr.c_str(), tNameLink.c_str());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user