mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Pass preformatted string when updating sign positions. (#13480)
This forces the strings to be formatted in advance and avoids using global string parameters.pull/13481/head
parent
eaa765d615
commit
8c48f9fc49
|
@ -49,8 +49,7 @@ void Sign::UpdateVirtCoord()
|
||||||
|
|
||||||
if (this->sign.kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeSign(this->index));
|
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, GetString(STR_WHITE_SIGN, this->index));
|
||||||
this->sign.UpdatePosition(pt.x, pt.y - 6 * ZOOM_BASE, STR_WHITE_SIGN);
|
|
||||||
|
|
||||||
_viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeSign(this->index));
|
_viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeSign(this->index));
|
||||||
}
|
}
|
||||||
|
|
|
@ -448,9 +448,7 @@ void Station::UpdateVirtCoord()
|
||||||
|
|
||||||
if (this->sign.kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeStation(this->index));
|
if (this->sign.kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeStation(this->index));
|
||||||
|
|
||||||
SetDParam(0, this->index);
|
this->sign.UpdatePosition(pt.x, pt.y, GetString(STR_VIEWPORT_STATION, this->index, this->facilities), GetString(STR_STATION_NAME, this->index, this->facilities));
|
||||||
SetDParam(1, this->facilities);
|
|
||||||
this->sign.UpdatePosition(pt.x, pt.y, STR_VIEWPORT_STATION, STR_STATION_NAME);
|
|
||||||
|
|
||||||
_viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeStation(this->index));
|
_viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeStation(this->index));
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ TextEffectID AddTextEffect(StringID msg, int center, int y, uint8_t duration, Te
|
||||||
|
|
||||||
/* Make sure we only dirty the new area */
|
/* Make sure we only dirty the new area */
|
||||||
te.width_normal = 0;
|
te.width_normal = 0;
|
||||||
te.UpdatePosition(center, y, msg);
|
te.UpdatePosition(center, y, GetString(te.string_id));
|
||||||
|
|
||||||
return static_cast<TextEffectID>(it - std::begin(_text_effects));
|
return static_cast<TextEffectID>(it - std::begin(_text_effects));
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ void UpdateTextEffect(TextEffectID te_id, StringID msg)
|
||||||
te.string_id = msg;
|
te.string_id = msg;
|
||||||
CopyOutDParam(te.params, 2);
|
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()
|
void UpdateAllTextEffectVirtCoords()
|
||||||
|
@ -80,7 +80,7 @@ void UpdateAllTextEffectVirtCoords()
|
||||||
for (auto &te : _text_effects) {
|
for (auto &te : _text_effects) {
|
||||||
if (te.string_id == INVALID_STRING_ID) continue;
|
if (te.string_id == INVALID_STRING_ID) continue;
|
||||||
CopyInDParam(te.params);
|
CopyInDParam(te.params);
|
||||||
te.UpdatePosition(te.center, te.top, te.string_id);
|
te.UpdatePosition(te.center, te.top, GetString(te.string_id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -412,11 +412,10 @@ void Town::UpdateVirtCoord()
|
||||||
|
|
||||||
if (this->cache.sign.kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeTown(this->index));
|
if (this->cache.sign.kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeTown(this->index));
|
||||||
|
|
||||||
SetDParam(0, this->index);
|
std::string town_string = GetString(STR_TOWN_NAME, this->index);
|
||||||
SetDParam(1, this->cache.population);
|
|
||||||
this->cache.sign.UpdatePosition(pt.x, pt.y - 24 * ZOOM_BASE,
|
this->cache.sign.UpdatePosition(pt.x, pt.y - 24 * ZOOM_BASE,
|
||||||
_settings_client.gui.population_in_label ? STR_VIEWPORT_TOWN_POP : STR_TOWN_NAME,
|
_settings_client.gui.population_in_label ? GetString(STR_VIEWPORT_TOWN_POP, this->index, this->cache.population) : town_string,
|
||||||
STR_TOWN_NAME);
|
town_string);
|
||||||
|
|
||||||
_viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeTown(this->index));
|
_viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeTown(this->index));
|
||||||
|
|
||||||
|
|
|
@ -1515,23 +1515,20 @@ static void ViewportAddKdtreeSigns(DrawPixelInfo *dpi)
|
||||||
* @param center the (preferred) center of the viewport sign
|
* @param center the (preferred) center of the viewport sign
|
||||||
* @param top the new top of the sign
|
* @param top the new top of the sign
|
||||||
* @param str the string to show in 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();
|
if (this->width_normal != 0) this->MarkDirty();
|
||||||
|
|
||||||
this->top = top;
|
this->top = top;
|
||||||
|
|
||||||
std::string name = GetString(str);
|
this->width_normal = WidgetDimensions::scaled.fullbevel.left + Align(GetStringBoundingBox(str).width, 2) + WidgetDimensions::scaled.fullbevel.right;
|
||||||
this->width_normal = WidgetDimensions::scaled.fullbevel.left + Align(GetStringBoundingBox(name).width, 2) + WidgetDimensions::scaled.fullbevel.right;
|
|
||||||
this->center = center;
|
this->center = center;
|
||||||
|
|
||||||
/* zoomed out version */
|
/* zoomed out version */
|
||||||
if (str_small != STR_NULL) {
|
if (str_small.empty()) str_small = str;
|
||||||
name = GetString(str_small);
|
this->width_small = WidgetDimensions::scaled.fullbevel.left + Align(GetStringBoundingBox(str_small, FS_SMALL).width, 2) + WidgetDimensions::scaled.fullbevel.right;
|
||||||
}
|
|
||||||
this->width_small = WidgetDimensions::scaled.fullbevel.left + Align(GetStringBoundingBox(name, FS_SMALL).width, 2) + WidgetDimensions::scaled.fullbevel.right;
|
|
||||||
|
|
||||||
this->MarkDirty();
|
this->MarkDirty();
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ struct ViewportSign {
|
||||||
|
|
||||||
auto operator<=>(const ViewportSign &) const = default;
|
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;
|
void MarkDirty(ZoomLevel maxzoom = ZOOM_LVL_MAX) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ struct TrackedViewportSign : ViewportSign {
|
||||||
* Update the position of the viewport sign.
|
* Update the position of the viewport sign.
|
||||||
* Note that this function hides the base class function.
|
* 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->kdtree_valid = true;
|
||||||
this->ViewportSign::UpdatePosition(center, top, str, str_small);
|
this->ViewportSign::UpdatePosition(center, top, str, str_small);
|
||||||
|
|
|
@ -44,8 +44,7 @@ void Waypoint::UpdateVirtCoord()
|
||||||
Point pt = RemapCoords2(TileX(this->xy) * TILE_SIZE, TileY(this->xy) * TILE_SIZE);
|
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));
|
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, GetString(STR_WAYPOINT_NAME, this->index));
|
||||||
this->sign.UpdatePosition(pt.x, pt.y - 32 * ZOOM_BASE, STR_WAYPOINT_NAME);
|
|
||||||
|
|
||||||
_viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeWaypoint(this->index));
|
_viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeWaypoint(this->index));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue