diff --git a/src/signs.cpp b/src/signs.cpp index 453c55841b..e8e85364b9 100644 --- a/src/signs.cpp +++ b/src/signs.cpp @@ -49,8 +49,7 @@ void Sign::UpdateVirtCoord() if (this->sign.kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeSign(this->index)); - SetDParam(0, this->index); - this->sign.UpdatePosition(pt.x, pt.y - 6 * ZOOM_BASE, STR_WHITE_SIGN); + this->sign.UpdatePosition(pt.x, pt.y - 6 * ZOOM_BASE, GetString(STR_WHITE_SIGN, this->index)); _viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeSign(this->index)); } diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index d1f7b1b031..088a397a2c 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -448,9 +448,7 @@ void Station::UpdateVirtCoord() if (this->sign.kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeStation(this->index)); - SetDParam(0, this->index); - SetDParam(1, this->facilities); - this->sign.UpdatePosition(pt.x, pt.y, STR_VIEWPORT_STATION, STR_STATION_NAME); + this->sign.UpdatePosition(pt.x, pt.y, GetString(STR_VIEWPORT_STATION, this->index, this->facilities), GetString(STR_STATION_NAME, this->index, this->facilities)); _viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeStation(this->index)); diff --git a/src/texteff.cpp b/src/texteff.cpp index 213d3adfba..c9a03d9b04 100644 --- a/src/texteff.cpp +++ b/src/texteff.cpp @@ -59,7 +59,7 @@ TextEffectID AddTextEffect(StringID msg, int center, int y, uint8_t duration, Te /* Make sure we only dirty the new area */ te.width_normal = 0; - te.UpdatePosition(center, y, msg); + te.UpdatePosition(center, y, GetString(te.string_id)); return static_cast(it - std::begin(_text_effects)); } @@ -72,7 +72,7 @@ void UpdateTextEffect(TextEffectID te_id, StringID msg) te.string_id = msg; CopyOutDParam(te.params, 2); - te.UpdatePosition(te.center, te.top, te.string_id); + te.UpdatePosition(te.center, te.top, GetString(te.string_id)); } void UpdateAllTextEffectVirtCoords() @@ -80,7 +80,7 @@ void UpdateAllTextEffectVirtCoords() for (auto &te : _text_effects) { if (te.string_id == INVALID_STRING_ID) continue; CopyInDParam(te.params); - te.UpdatePosition(te.center, te.top, te.string_id); + te.UpdatePosition(te.center, te.top, GetString(te.string_id)); } } diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index eba5392022..5127286271 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -412,11 +412,10 @@ void Town::UpdateVirtCoord() if (this->cache.sign.kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeTown(this->index)); - SetDParam(0, this->index); - SetDParam(1, this->cache.population); + std::string town_string = GetString(STR_TOWN_NAME, this->index); this->cache.sign.UpdatePosition(pt.x, pt.y - 24 * ZOOM_BASE, - _settings_client.gui.population_in_label ? STR_VIEWPORT_TOWN_POP : STR_TOWN_NAME, - STR_TOWN_NAME); + _settings_client.gui.population_in_label ? GetString(STR_VIEWPORT_TOWN_POP, this->index, this->cache.population) : town_string, + town_string); _viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeTown(this->index)); diff --git a/src/viewport.cpp b/src/viewport.cpp index 246e50fe8f..d0010c2bf0 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -1515,23 +1515,20 @@ static void ViewportAddKdtreeSigns(DrawPixelInfo *dpi) * @param center the (preferred) center of the viewport sign * @param top the new top of the sign * @param str the string to show in the sign - * @param str_small the string to show when zoomed out. STR_NULL means same as \a str + * @param str_small the string to show when zoomed out. If the string is emtpy then the \a str is used. */ -void ViewportSign::UpdatePosition(int center, int top, StringID str, StringID str_small) +void ViewportSign::UpdatePosition(int center, int top, std::string_view str, std::string_view str_small) { if (this->width_normal != 0) this->MarkDirty(); this->top = top; - std::string name = GetString(str); - this->width_normal = WidgetDimensions::scaled.fullbevel.left + Align(GetStringBoundingBox(name).width, 2) + WidgetDimensions::scaled.fullbevel.right; + this->width_normal = WidgetDimensions::scaled.fullbevel.left + Align(GetStringBoundingBox(str).width, 2) + WidgetDimensions::scaled.fullbevel.right; this->center = center; /* zoomed out version */ - if (str_small != STR_NULL) { - name = GetString(str_small); - } - this->width_small = WidgetDimensions::scaled.fullbevel.left + Align(GetStringBoundingBox(name, FS_SMALL).width, 2) + WidgetDimensions::scaled.fullbevel.right; + if (str_small.empty()) str_small = str; + this->width_small = WidgetDimensions::scaled.fullbevel.left + Align(GetStringBoundingBox(str_small, FS_SMALL).width, 2) + WidgetDimensions::scaled.fullbevel.right; this->MarkDirty(); } diff --git a/src/viewport_type.h b/src/viewport_type.h index f90556cdab..a57352d7f8 100644 --- a/src/viewport_type.h +++ b/src/viewport_type.h @@ -54,7 +54,7 @@ struct ViewportSign { auto operator<=>(const ViewportSign &) const = default; - void UpdatePosition(int center, int top, StringID str, StringID str_small = STR_NULL); + void UpdatePosition(int center, int top, std::string_view str, std::string_view str_small = {}); void MarkDirty(ZoomLevel maxzoom = ZOOM_LVL_MAX) const; }; @@ -68,7 +68,7 @@ struct TrackedViewportSign : ViewportSign { * Update the position of the viewport sign. * Note that this function hides the base class function. */ - void UpdatePosition(int center, int top, StringID str, StringID str_small = STR_NULL) + void UpdatePosition(int center, int top, std::string_view str, std::string_view str_small = {}) { this->kdtree_valid = true; this->ViewportSign::UpdatePosition(center, top, str, str_small); diff --git a/src/waypoint_cmd.cpp b/src/waypoint_cmd.cpp index a479561d12..e216a89caf 100644 --- a/src/waypoint_cmd.cpp +++ b/src/waypoint_cmd.cpp @@ -44,8 +44,7 @@ void Waypoint::UpdateVirtCoord() Point pt = RemapCoords2(TileX(this->xy) * TILE_SIZE, TileY(this->xy) * TILE_SIZE); if (this->sign.kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeWaypoint(this->index)); - SetDParam(0, this->index); - this->sign.UpdatePosition(pt.x, pt.y - 32 * ZOOM_BASE, STR_WAYPOINT_NAME); + this->sign.UpdatePosition(pt.x, pt.y - 32 * ZOOM_BASE, GetString(STR_WAYPOINT_NAME, this->index)); _viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeWaypoint(this->index));