diff --git a/data/language/en-GB.txt b/data/language/en-GB.txt index abbf2ef186..73269b0a62 100644 --- a/data/language/en-GB.txt +++ b/data/language/en-GB.txt @@ -556,7 +556,6 @@ STR_1168 :Options STR_1169 :(None) STR_1170 :{STRING} STR_1171 :{RED}Closed -STR_1172 :{YELLOW}{STRINGID} STR_1173 :Build footpaths and queue lines STR_1174 :Banner sign in the way STR_1175 :Can’t build this on sloped footpath @@ -1113,7 +1112,6 @@ STR_1727 :Construction rights not for sale! STR_1728 :Can’t buy construction rights here… STR_1729 :Land not owned by park! STR_1730 :{RED}Closed -STR_1731 :{WHITE}{STRINGID} - - STR_1732 :Build STR_1733 :Mode STR_1734 :{WINDOW_COLOUR_2}Number of laps: @@ -1154,7 +1152,6 @@ STR_1771 :{POP16}{POP16}{POP16}{POP16}{POP16}{POP16}{POP16}{POP16}{POP16}{COM STR_1773 :Only one on-ride photo section allowed per ride STR_1774 :Only one cable lift hill allowed per ride STR_1777 :Ride music -STR_1778 :{STRINGID} - - STR_1790 :Select uniform colour for this type of staff STR_1791 :{WINDOW_COLOUR_2}Uniform colour: STR_1792 :Responding to {STRINGID} breakdown call @@ -3851,3 +3848,4 @@ STR_7018 :{SPRITE}{MOVE_X}{17}{STRINGID} STR_7019 :{SPRITE}{MOVE_X}{27}{STRINGID} STR_7020 :{MOVE_X}{10}{SPRITE}{NEWLINE_SMALLER}{MOVE_X}{36}{STRINGID} STR_7021 :{MOVE_X}{10}{SPRITE}{NEWLINE_SMALLER}»{MOVE_X}{36}{STRINGID} +STR_7022 :{STRING} - - diff --git a/src/openrct2/drawing/ScrollingText.cpp b/src/openrct2/drawing/ScrollingText.cpp index 8f27f7bcfb..a9bbdce4b4 100644 --- a/src/openrct2/drawing/ScrollingText.cpp +++ b/src/openrct2/drawing/ScrollingText.cpp @@ -9,6 +9,7 @@ #include "ScrollingText.h" +#include "../GameState.h" #include "../SpriteIds.h" #include "../config/Config.h" #include "../core/CodepointView.hpp" @@ -31,8 +32,7 @@ namespace OpenRCT2::Drawing::ScrollingText { struct DrawScrollText { - StringId string_id; - uint8_t string_args[32]; + u8string string; PaletteIndex colour; uint16_t position; uint16_t mode; @@ -42,7 +42,7 @@ namespace OpenRCT2::Drawing::ScrollingText static DrawScrollText _drawScrollTextList[kMaxEntries]; static uint8_t _characterBitmaps[SPR_FONTS_GLYPH_COUNT][8]; - static uint32_t _drawSCrollNextIndex = 0; + static uint32_t _drawScrollNextIndex = 0; static std::mutex _mutex; static void setBitmapForSprite( @@ -117,8 +117,7 @@ namespace OpenRCT2::Drawing::ScrollingText return _characterBitmaps[offset]; } - static int32_t getMatchingOrOldest( - StringId stringId, Formatter& ft, uint16_t scroll, uint16_t scrollingMode, PaletteIndex colour) + static int32_t getMatchingOrOldest(u8string_view string, uint16_t scroll, uint16_t scrollingMode, PaletteIndex colour) { uint32_t oldestId = 0xFFFFFFFF; int32_t scrollIndex = -1; @@ -132,29 +131,16 @@ namespace OpenRCT2::Drawing::ScrollingText } // If exact match return the matching index - if (scrollText->string_id == stringId - && std::memcmp(scrollText->string_args, ft.Buf(), sizeof(scrollText->string_args)) == 0 - && scrollText->colour == colour && scrollText->position == scroll && scrollText->mode == scrollingMode) + if (scrollText->string == string && scrollText->colour == colour && scrollText->position == scroll + && scrollText->mode == scrollingMode) { - scrollText->id = _drawSCrollNextIndex; + scrollText->id = _drawScrollNextIndex; return static_cast(i + SPR_SCROLLING_TEXT_START); } } return scrollIndex; } - static void format(utf8* dst, size_t size, DrawScrollText* scrollText) - { - if (Config::Get().general.upperCaseBanners) - { - FormatStringToUpper(dst, size, scrollText->string_id, scrollText->string_args); - } - else - { - FormatStringLegacy(dst, size, scrollText->string_id, scrollText->string_args); - } - } - extern bool TempForScrollText; consteval int16_t ScrollPos(const int16_t x, const int16_t y) @@ -1428,14 +1414,20 @@ static constexpr const int16_t* kScrollPositions[kMaxModes] = { { for (auto& scrollText : _drawScrollTextList) { - scrollText.string_id = 0; - std::memset(scrollText.string_args, 0, sizeof(scrollText.string_args)); + scrollText.string.clear(); } } - ImageId setup( - PaintSession& session, StringId stringId, Formatter& ft, uint16_t scroll, uint16_t scrollingMode, PaletteIndex colour) + ImageId setup(PaintSession& session, u8string_view string, uint16_t scrollingMode, PaletteIndex colour) { + u8string formattedString = FormatStringID(STR_BANNER_TEXT_FORMAT, string); + if (Config::Get().general.upperCaseBanners) + { + formattedString = String::toUpper(formattedString); + } + auto stringWidth = GfxGetStringWidth(formattedString, FontStyle::tiny); + auto scroll = stringWidth > 0 ? (getGameState().currentTicks / 2) % stringWidth : 0; + std::scoped_lock lock(_mutex); assert(scrollingMode < kMaxModes); @@ -1443,35 +1435,29 @@ static constexpr const int16_t* kScrollPositions[kMaxModes] = { if (session.rt.zoom_level > ZoomLevel{ 0 }) return ImageId(SPR_SCROLLING_TEXT_DEFAULT); - _drawSCrollNextIndex++; - ft.Rewind(); - uint32_t scrollIndex = getMatchingOrOldest(stringId, ft, scroll, scrollingMode, colour); + _drawScrollNextIndex++; + uint32_t scrollIndex = getMatchingOrOldest(formattedString, scroll, scrollingMode, colour); if (scrollIndex >= SPR_SCROLLING_TEXT_START) return ImageId(scrollIndex); // Setup scrolling text auto scrollText = &_drawScrollTextList[scrollIndex]; - scrollText->string_id = stringId; - std::memcpy(scrollText->string_args, ft.Buf(), sizeof(scrollText->string_args)); + scrollText->string = formattedString; scrollText->colour = colour; scrollText->position = scroll; scrollText->mode = scrollingMode; - scrollText->id = _drawSCrollNextIndex; - - // Create the string to draw - utf8 scrollString[256]; - format(scrollString, 256, scrollText); + scrollText->id = _drawScrollNextIndex; const int16_t* scrollingModePositions = kScrollPositions[scrollingMode]; std::fill_n(scrollText->bitmap, 320 * 8, PaletteIndex::transparent); if (LocalisationService_UseTrueTypeFont()) { - setBitmapForTTF(scrollString, scroll, scrollText->bitmap, scrollingModePositions, colour); + setBitmapForTTF(scrollText->string, scroll, scrollText->bitmap, scrollingModePositions, colour); } else { - setBitmapForSprite(scrollString, scroll, scrollText->bitmap, scrollingModePositions, colour); + setBitmapForSprite(scrollText->string, scroll, scrollText->bitmap, scrollingModePositions, colour); } uint32_t imageId = SPR_SCROLLING_TEXT_START + scrollIndex; diff --git a/src/openrct2/drawing/ScrollingText.h b/src/openrct2/drawing/ScrollingText.h index c15944c9bb..803d127da3 100644 --- a/src/openrct2/drawing/ScrollingText.h +++ b/src/openrct2/drawing/ScrollingText.h @@ -9,6 +9,8 @@ #pragma once +#include "../core/StringTypes.h" + #include struct ImageId; @@ -32,9 +34,10 @@ namespace OpenRCT2::Drawing::ScrollingText static auto constexpr kMaxLegacyEntries = 32; static auto constexpr kMaxEntries = 256; constexpr int8_t kMaxModes = 38; + constexpr auto kParkBannerColourPrefix = "{WHITE}"; + constexpr auto kRideBannerColourPrefix = "{YELLOW}"; void initialiseBitmaps(); void invalidate(); - ImageId setup( - PaintSession& session, StringId stringId, Formatter& ft, uint16_t scroll, uint16_t scrollingMode, PaletteIndex colour); + ImageId setup(PaintSession& session, u8string_view string, uint16_t scrollingMode, PaletteIndex colour); } // namespace OpenRCT2::Drawing::ScrollingText diff --git a/src/openrct2/localisation/StringIds.h b/src/openrct2/localisation/StringIds.h index c02f22f875..a66fafdc54 100644 --- a/src/openrct2/localisation/StringIds.h +++ b/src/openrct2/localisation/StringIds.h @@ -187,7 +187,6 @@ enum : StringId STR_CANT_RAISE_WATER_LEVEL_HERE = 1167, STR_STRING = 1170, STR_RIDE_ENTRANCE_CLOSED = 1171, - STR_RIDE_ENTRANCE_NAME = 1172, STR_BANNER_SIGN_IN_THE_WAY = 1174, STR_CANT_BUILD_THIS_ON_SLOPED_FOOTPATH = 1175, STR_CANT_BUILD_FOOTPATH_HERE = 1176, @@ -581,7 +580,7 @@ enum : StringId STR_CANT_BUY_CONSTRUCTION_RIGHTS_HERE = 1728, STR_LAND_NOT_OWNED_BY_PARK = 1729, STR_BANNER_TEXT_CLOSED = 1730, - STR_BANNER_TEXT_FORMAT = 1731, + STR_BANNER_TEXT_FORMAT = 7022, // STR_1737 :{COMMA16} STR_CANT_CHANGE_NUMBER_OF_LAPS = 1738, STR_RACE_WON_BY_GUEST = 1739, @@ -602,7 +601,6 @@ enum : StringId STR_ONLY_ONE_CABLE_LIFT_HILL_PER_RIDE = 1774, // STR_OPTIONS_RIDE_MUSIC_OFF = 1775, // STR_OPTIONS_RIDE_MUSIC_ON = 1776, - STR_SCROLLING_SIGN_TEXT = 1778, // STR_STAFF_OPTION_COSTUME_PANDA = 1779, // STR_STAFF_OPTION_COSTUME_TIGER = 1780, // STR_STAFF_OPTION_COSTUME_ELEPHANT = 1781, diff --git a/src/openrct2/paint/tile_element/Paint.Banner.cpp b/src/openrct2/paint/tile_element/Paint.Banner.cpp index a92a89c38d..0665ff37aa 100644 --- a/src/openrct2/paint/tile_element/Paint.Banner.cpp +++ b/src/openrct2/paint/tile_element/Paint.Banner.cpp @@ -57,22 +57,8 @@ static void PaintBannerScrollingText( return; } - auto ft = Formatter(); - banner.formatTextWithColourTo(ft); - - char text[256]; - if (Config::Get().general.upperCaseBanners) - { - FormatStringToUpper(text, sizeof(text), STR_BANNER_TEXT_FORMAT, ft.Data()); - } - else - { - FormatStringLegacy(text, sizeof(text), STR_BANNER_TEXT_FORMAT, ft.Data()); - } - - auto stringWidth = GfxGetStringWidth(text, FontStyle::tiny); - auto scroll = stringWidth > 0 ? (getGameState().currentTicks / 2) % stringWidth : 0; - auto imageId = ScrollingText::setup(session, STR_BANNER_TEXT_FORMAT, ft, scroll, scrollingMode, PaletteIndex::transparent); + auto bannerText = banner.getTextWithColour(); + auto imageId = ScrollingText::setup(session, bannerText, scrollingMode, PaletteIndex::transparent); PaintAddImageAsChild(session, imageId, { 0, 0, height + 22 }, { bbOffset, { 1, 1, 21 } }); } diff --git a/src/openrct2/paint/tile_element/Paint.Entrance.cpp b/src/openrct2/paint/tile_element/Paint.Entrance.cpp index 22a3790b72..c37f0aa798 100644 --- a/src/openrct2/paint/tile_element/Paint.Entrance.cpp +++ b/src/openrct2/paint/tile_element/Paint.Entrance.cpp @@ -53,36 +53,22 @@ static void PaintRideEntranceExitScrollingText( if (entranceEl.GetEntranceType() == ENTRANCE_TYPE_RIDE_EXIT) return; - auto ride = GetRide(entranceEl.GetRideIndex()); + const auto* ride = GetRide(entranceEl.GetRideIndex()); if (ride == nullptr) return; - auto ft = Formatter(); - ft.Add(STR_RIDE_ENTRANCE_NAME); + u8string bannerText; if (ride->status == RideStatus::open && !(ride->lifecycleFlags & RIDE_LIFECYCLE_BROKEN_DOWN)) { - ride->formatNameTo(ft); + bannerText = ScrollingText::kRideBannerColourPrefix + ride->getName(); } else { - ft.Add(STR_RIDE_ENTRANCE_CLOSED); + bannerText = LanguageGetString(STR_RIDE_ENTRANCE_CLOSED); } - char text[256]; - if (Config::Get().general.upperCaseBanners) - { - FormatStringToUpper(text, sizeof(text), STR_BANNER_TEXT_FORMAT, ft.Data()); - } - else - { - FormatStringLegacy(text, sizeof(text), STR_BANNER_TEXT_FORMAT, ft.Data()); - } - auto stringWidth = GfxGetStringWidth(text, FontStyle::tiny); - auto scroll = stringWidth > 0 ? (getGameState().currentTicks / 2) % stringWidth : 0; - PaintAddImageAsChild( - session, - ScrollingText::setup(session, STR_BANNER_TEXT_FORMAT, ft, scroll, stationObj.ScrollingMode, PaletteIndex::transparent), + session, ScrollingText::setup(session, bannerText, stationObj.ScrollingMode, PaletteIndex::transparent), { 0, 0, height + stationObj.Height }, { { 2, 2, height + stationObj.Height }, { 28, 28, 51 } }); } @@ -235,35 +221,19 @@ static void PaintParkEntranceScrollingText( if (scrollingMode == kScrollingModeNone) return; - auto ft = Formatter(); auto& gameState = getGameState(); + u8string bannerText; if (gameState.park.flags & PARK_FLAGS_PARK_OPEN) { const auto& park = gameState.park; - auto name = park.name.c_str(); - ft.Add(STR_STRING); - ft.Add(name); + bannerText = ScrollingText::kParkBannerColourPrefix + park.name; } else { - ft.Add(STR_BANNER_TEXT_CLOSED); - ft.Add(0); + bannerText = LanguageGetString(STR_BANNER_TEXT_CLOSED); } - char text[256]; - if (Config::Get().general.upperCaseBanners) - { - FormatStringToUpper(text, sizeof(text), STR_BANNER_TEXT_FORMAT, ft.Data()); - } - else - { - FormatStringLegacy(text, sizeof(text), STR_BANNER_TEXT_FORMAT, ft.Data()); - } - - auto stringWidth = GfxGetStringWidth(text, FontStyle::tiny); - auto scroll = stringWidth > 0 ? (gameState.currentTicks / 2) % stringWidth : 0; - auto imageIndex = ScrollingText::setup( - session, STR_BANNER_TEXT_FORMAT, ft, scroll, scrollingMode + direction / 2, PaletteIndex::transparent); + auto imageIndex = ScrollingText::setup(session, bannerText, scrollingMode + direction / 2, PaletteIndex::transparent); auto textHeight = height + entrance.GetTextHeight(); PaintAddImageAsChild(session, imageIndex, { 0, 0, textHeight }, { { 2, 2, textHeight }, { 28, 28, 47 } }); } diff --git a/src/openrct2/paint/tile_element/Paint.LargeScenery.cpp b/src/openrct2/paint/tile_element/Paint.LargeScenery.cpp index 8d5da3f8f4..5e3d22b044 100644 --- a/src/openrct2/paint/tile_element/Paint.LargeScenery.cpp +++ b/src/openrct2/paint/tile_element/Paint.LargeScenery.cpp @@ -319,23 +319,9 @@ static void PaintLargeSceneryScrollingText( if (banner == nullptr) return; - auto ft = Formatter(); - banner->formatTextTo(ft); - - char text[256]; - if (Config::Get().general.upperCaseBanners) - { - FormatStringToUpper(text, sizeof(text), STR_SCROLLING_SIGN_TEXT, ft.Data()); - } - else - { - FormatStringLegacy(text, sizeof(text), STR_SCROLLING_SIGN_TEXT, ft.Data()); - } - + auto bannerText = banner->getText(); auto scrollMode = sceneryEntry.scrolling_mode + ((direction + 1) & 3); - auto stringWidth = GfxGetStringWidth(text, FontStyle::tiny); - auto scroll = stringWidth > 0 ? (getGameState().currentTicks / 2) % stringWidth : 0; - auto imageId = ScrollingText::setup(session, STR_SCROLLING_SIGN_TEXT, ft, scroll, scrollMode, textPaletteIndex); + auto imageId = ScrollingText::setup(session, bannerText, scrollMode, textPaletteIndex); PaintAddImageAsChild(session, imageId, { 0, 0, height + 25 }, { bbOffset, { 1, 1, 21 } }); } diff --git a/src/openrct2/paint/tile_element/Paint.Path.cpp b/src/openrct2/paint/tile_element/Paint.Path.cpp index 8b84534b00..ab6b127700 100644 --- a/src/openrct2/paint/tile_element/Paint.Path.cpp +++ b/src/openrct2/paint/tile_element/Paint.Path.cpp @@ -155,35 +155,19 @@ static void PathPaintQueueBanner( uint16_t scrollingMode = railings.scrollingMode; scrollingMode += direction; - auto ft = Formatter(); - + u8string bannerText; if (ride->status == RideStatus::open && !(ride->lifecycleFlags & RIDE_LIFECYCLE_BROKEN_DOWN)) { - ft.Add(STR_RIDE_ENTRANCE_NAME); - ride->formatNameTo(ft); + bannerText = ScrollingText::kRideBannerColourPrefix + ride->getName(); } else { - ft.Add(STR_RIDE_ENTRANCE_CLOSED); + bannerText = LanguageGetString(STR_RIDE_ENTRANCE_CLOSED); } - utf8 bannerBuffer[512]{}; - if (Config::Get().general.upperCaseBanners) - { - FormatStringToUpper(bannerBuffer, sizeof(bannerBuffer), STR_BANNER_TEXT_FORMAT, ft.Data()); - } - else - { - FormatStringLegacy(bannerBuffer, sizeof(bannerBuffer), STR_BANNER_TEXT_FORMAT, ft.Data()); - } - - uint16_t stringWidth = GfxGetStringWidth(bannerBuffer, FontStyle::tiny); - uint16_t scroll = stringWidth > 0 ? (getGameState().currentTicks / 2) % stringWidth : 0; - PaintAddImageAsChild( - session, - ScrollingText::setup(session, STR_BANNER_TEXT_FORMAT, ft, scroll, scrollingMode, PaletteIndex::transparent), - { 0, 0, height + 7 }, { boundBoxOffsets, { 1, 1, 21 } }); + session, ScrollingText::setup(session, bannerText, scrollingMode, PaletteIndex::transparent), { 0, 0, height + 7 }, + { boundBoxOffsets, { 1, 1, 21 } }); } session.InteractionType = ViewportInteractionItem::footpath; diff --git a/src/openrct2/paint/tile_element/Paint.Wall.cpp b/src/openrct2/paint/tile_element/Paint.Wall.cpp index 732e59e53a..2f6dda1b84 100644 --- a/src/openrct2/paint/tile_element/Paint.Wall.cpp +++ b/src/openrct2/paint/tile_element/Paint.Wall.cpp @@ -176,21 +176,8 @@ static void PaintWallScrollingText( : wallElement.GetSecondaryColour(); auto textPaletteIndex = direction == 0 ? getColourMap(textColour).midDark : getColourMap(textColour).light; - auto ft = Formatter(); - banner->formatTextTo(ft); - char signString[256]; - if (Config::Get().general.upperCaseBanners) - { - FormatStringToUpper(signString, sizeof(signString), STR_SCROLLING_SIGN_TEXT, ft.Data()); - } - else - { - FormatStringLegacy(signString, sizeof(signString), STR_SCROLLING_SIGN_TEXT, ft.Data()); - } - - auto stringWidth = GfxGetStringWidth(signString, FontStyle::tiny); - auto scroll = stringWidth > 0 ? (getGameState().currentTicks / 2) % stringWidth : 0; - auto imageId = ScrollingText::setup(session, STR_SCROLLING_SIGN_TEXT, ft, scroll, scrollingMode, textPaletteIndex); + auto bannerText = banner->getText(); + auto imageId = ScrollingText::setup(session, bannerText, scrollingMode, textPaletteIndex); PaintAddImageAsChild(session, imageId, { 0, 0, height + 8 }, { boundsOffset, { 1, 1, 13 } }); } diff --git a/src/openrct2/world/Banner.cpp b/src/openrct2/world/Banner.cpp index eadb85e220..4f2580b9eb 100644 --- a/src/openrct2/world/Banner.cpp +++ b/src/openrct2/world/Banner.cpp @@ -43,6 +43,13 @@ using namespace OpenRCT2; +std::string Banner::getTextWithColour() const +{ + Formatter ft; + formatTextWithColourTo(ft); + return FormatStringIDLegacy(STR_STRINGID, ft.Data()); +} + std::string Banner::getText() const { Formatter ft; diff --git a/src/openrct2/world/Banner.h b/src/openrct2/world/Banner.h index 2270d28bbd..479bca0360 100644 --- a/src/openrct2/world/Banner.h +++ b/src/openrct2/world/Banner.h @@ -58,6 +58,7 @@ struct Banner return type == kBannerNull; } + std::string getTextWithColour() const; std::string getText() const; void formatTextWithColourTo(OpenRCT2::Formatter&) const; void formatTextTo(OpenRCT2::Formatter&) const;