From 164f570aae94206453d90fd054ec32611dc16a51 Mon Sep 17 00:00:00 2001 From: Ted John Date: Sat, 5 Dec 2020 13:55:44 +0000 Subject: [PATCH 1/2] Fix #13517: Bad formatting of dates --- src/openrct2/localisation/Formatting.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/openrct2/localisation/Formatting.cpp b/src/openrct2/localisation/Formatting.cpp index e8486e3308..9b2eb30ef2 100644 --- a/src/openrct2/localisation/Formatting.cpp +++ b/src/openrct2/localisation/Formatting.cpp @@ -19,6 +19,8 @@ namespace OpenRCT2 { + static void FormatMonthYear(std::stringstream& ss, int32_t month, int32_t year); + static std::optional ParseNumericToken(std::string_view s) { if (s.size() >= 3 && s.size() <= 5 && s[0] == '{' && s[s.size() - 1] == '}') @@ -572,7 +574,7 @@ namespace OpenRCT2 { auto month = date_get_month(arg); auto year = date_get_year(arg) + 1; - FormatStringId(ss, STR_DATE_FORMAT_MY, month, year); + FormatMonthYear(ss, month, year); } break; case FormatToken::Month: @@ -792,6 +794,22 @@ namespace OpenRCT2 BuildAnyArgListFromLegacyArgBuffer(fmt, anyArgs, args); return FormatStringAny(buffer, bufferLen, fmt, anyArgs); } + + static void FormatMonthYear(std::stringstream& ss, int32_t month, int32_t year) + { + thread_local std::vector tempArgs; + tempArgs.clear(); + + auto fmt = GetFmtStringById(STR_DATE_FORMAT_MY); + Formatter ft; + ft.Add(month); + ft.Add(year); + const void* legacyArgs = ft.Data(); + BuildAnyArgListFromLegacyArgBuffer(fmt, tempArgs, legacyArgs); + size_t argIndex = 0; + FormatStringAny(ss, fmt, tempArgs, argIndex); + } + } // namespace OpenRCT2 void format_string(utf8* dest, size_t size, rct_string_id format, const void* args) From d6fd4ed64b39769354641555c8c2ceeea7ede43b Mon Sep 17 00:00:00 2001 From: Ted John Date: Sat, 5 Dec 2020 14:14:09 +0000 Subject: [PATCH 2/2] Allow formatting in in-game console --- src/openrct2-ui/interface/InGameConsole.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openrct2-ui/interface/InGameConsole.cpp b/src/openrct2-ui/interface/InGameConsole.cpp index f208313200..62eb26dba9 100644 --- a/src/openrct2-ui/interface/InGameConsole.cpp +++ b/src/openrct2-ui/interface/InGameConsole.cpp @@ -312,7 +312,7 @@ void InGameConsole::Draw(rct_drawpixelinfo* dpi) const { const size_t index = i + _consoleScrollPos; lineBuffer = colourFormatStr + _consoleLines[index]; - gfx_draw_string_no_formatting(dpi, lineBuffer.c_str(), textColour, screenCoords); + gfx_draw_string(dpi, lineBuffer.c_str(), textColour, screenCoords); screenCoords.y += lineHeight; }