Use StringBuilder for GetString/GetStringWithArgs, as per upstream
Update dependent code as required
This commit is contained in:
@@ -265,7 +265,6 @@ void NetworkTextMessage(NetworkAction action, TextColour colour, bool self_send,
|
||||
{
|
||||
SetDParamStr(0, name);
|
||||
|
||||
char message_src[256];
|
||||
StringID strid;
|
||||
switch (action) {
|
||||
case NETWORK_ACTION_SERVER_MESSAGE:
|
||||
@@ -294,8 +293,7 @@ void NetworkTextMessage(NetworkAction action, TextColour colour, bool self_send,
|
||||
|
||||
case NETWORK_ACTION_GIVE_MONEY: {
|
||||
SetDParam(1, data.auxdata >> 16);
|
||||
GetString(message_src, STR_NETWORK_MESSAGE_MONEY_GIVE_SRC_DESCRIPTION, lastof(message_src));
|
||||
SetDParamStr(0, message_src);
|
||||
SetDParamStr(0, GetString(STR_NETWORK_MESSAGE_MONEY_GIVE_SRC_DESCRIPTION));
|
||||
|
||||
extern byte GetCurrentGrfLangID();
|
||||
byte lang_id = GetCurrentGrfLangID();
|
||||
@@ -317,7 +315,8 @@ void NetworkTextMessage(NetworkAction action, TextColour colour, bool self_send,
|
||||
default: strid = STR_NETWORK_CHAT_ALL; break;
|
||||
}
|
||||
|
||||
char message[1024];
|
||||
std::string message;
|
||||
StringBuilder builder(message);
|
||||
SetDParamStr(1, str);
|
||||
SetDParam(2, data.data);
|
||||
SetDParamStr(3, data_str);
|
||||
@@ -326,12 +325,12 @@ void NetworkTextMessage(NetworkAction action, TextColour colour, bool self_send,
|
||||
* right-to-left characters depending on the context. As the next text might be an user's name, the
|
||||
* user name's characters will influence the direction of the "***" instead of the language setting
|
||||
* of the game. Manually set the direction of the "***" by inserting a text-direction marker. */
|
||||
char *msg_ptr = message + Utf8Encode(message, _current_text_dir == TD_LTR ? CHAR_TD_LRM : CHAR_TD_RLM);
|
||||
GetString(msg_ptr, strid, lastof(message));
|
||||
builder.Utf8Encode(_current_text_dir == TD_LTR ? CHAR_TD_LRM : CHAR_TD_RLM);
|
||||
GetString(builder, strid);
|
||||
|
||||
DEBUG(desync, 1, "msg: %s; %s", debug_date_dumper().HexDate(), message);
|
||||
IConsolePrintF(colour, "%s", message);
|
||||
NetworkAddChatMessage(colour, _settings_client.gui.network_chat_timeout, message);
|
||||
DEBUG(desync, 1, "msg: %s; %s", debug_date_dumper().HexDate(), message.c_str());
|
||||
IConsolePrintF(colour, "%s", message.c_str());
|
||||
NetworkAddChatMessage(colour, _settings_client.gui.network_chat_timeout, message.c_str());
|
||||
}
|
||||
|
||||
/* Calculate the frame-lag of a client */
|
||||
|
@@ -33,10 +33,6 @@
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
/** The draw buffer must be able to contain the chat message, client name and the "[All]" message,
|
||||
* some spaces and possible translations of [All] to other languages. */
|
||||
static_assert((int)DRAW_STRING_BUFFER >= (int)NETWORK_CHAT_LENGTH + NETWORK_NAME_LENGTH + 40);
|
||||
|
||||
/** Spacing between chat lines. */
|
||||
static const uint NETWORK_CHAT_LINE_SPACING = 3;
|
||||
|
||||
|
@@ -745,8 +745,7 @@ public:
|
||||
|
||||
if (!this->selected->dependencies.empty()) {
|
||||
/* List dependencies */
|
||||
char buf[DRAW_STRING_BUFFER] = "";
|
||||
char *p = buf;
|
||||
std::string buf;
|
||||
for (auto &cid : this->selected->dependencies) {
|
||||
/* Try to find the dependency */
|
||||
ConstContentIterator iter = _network_content_client.Begin();
|
||||
@@ -754,22 +753,23 @@ public:
|
||||
const ContentInfo *ci = *iter;
|
||||
if (ci->id != cid) continue;
|
||||
|
||||
p += seprintf(p, lastof(buf), p == buf ? "%s" : ", %s", (*iter)->name.c_str());
|
||||
if (!buf.empty()) buf += ", ";
|
||||
buf += (*iter)->name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
SetDParamStr(0, buf);
|
||||
SetDParamStr(0, std::move(buf));
|
||||
tr.top = DrawStringMultiLine(tr, STR_CONTENT_DETAIL_DEPENDENCIES);
|
||||
}
|
||||
|
||||
if (!this->selected->tags.empty()) {
|
||||
/* List all tags */
|
||||
char buf[DRAW_STRING_BUFFER] = "";
|
||||
char *p = buf;
|
||||
std::string buf;
|
||||
for (auto &tag : this->selected->tags) {
|
||||
p += seprintf(p, lastof(buf), p == buf ? "%s" : ", %s", tag.c_str());
|
||||
if (!buf.empty()) buf += ", ";
|
||||
buf += tag;
|
||||
}
|
||||
SetDParamStr(0, buf);
|
||||
SetDParamStr(0, std::move(buf));
|
||||
tr.top = DrawStringMultiLine(tr, STR_CONTENT_DETAIL_TAGS);
|
||||
}
|
||||
|
||||
@@ -778,15 +778,15 @@ public:
|
||||
ConstContentVector tree;
|
||||
_network_content_client.ReverseLookupTreeDependency(tree, this->selected);
|
||||
|
||||
char buf[DRAW_STRING_BUFFER] = "";
|
||||
char *p = buf;
|
||||
std::string buf;
|
||||
for (const ContentInfo *ci : tree) {
|
||||
if (ci == this->selected || ci->state != ContentInfo::SELECTED) continue;
|
||||
|
||||
p += seprintf(p, lastof(buf), buf == p ? "%s" : ", %s", ci->name.c_str());
|
||||
if (!buf.empty()) buf += ", ";
|
||||
buf += ci->name;
|
||||
}
|
||||
if (p != buf) {
|
||||
SetDParamStr(0, buf);
|
||||
if (!buf.empty()) {
|
||||
SetDParamStr(0, std::move(buf));
|
||||
tr.top = DrawStringMultiLine(tr, STR_CONTENT_DETAIL_SELECTED_BECAUSE_OF);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user