Fix #10362: NewGRF bridges without speed limits.

For bridges, a max speed of 0xFFFF (i.e. no effective limit)
 is no longer displayed as a limit in the UI.

A max speed of 0 is also considered unlimited, for similarity to the
 roadtype and railtype interface.
This commit is contained in:
Francis Herne
2023-01-16 17:51:34 +00:00
committed by rubidium42
parent 3c80f2d14a
commit 01be423237
4 changed files with 33 additions and 19 deletions

View File

@@ -130,6 +130,23 @@ private:
this->SetWidgetDirty(WID_BBS_BRIDGE_LIST);
}
/**
* Get the StringID to draw in the selection list and set the appropriate DParams.
* @param bridge_data the bridge to get the StringID of.
* @return the StringID.
*/
StringID GetBridgeSelectString(const BuildBridgeData &bridge_data) const
{
SetDParam(0, bridge_data.spec->material);
SetDParam(1, bridge_data.spec->speed);
SetDParam(2, bridge_data.cost);
/* If the bridge has no meaningful speed limit, don't display it. */
if (bridge_data.spec->speed == UINT16_MAX) {
return _game_mode == GM_EDITOR ? STR_SELECT_BRIDGE_INFO_NAME : STR_SELECT_BRIDGE_INFO_NAME_COST;
}
return _game_mode == GM_EDITOR ? STR_SELECT_BRIDGE_INFO_NAME_MAX_SPEED : STR_SELECT_BRIDGE_INFO_NAME_MAX_SPEED_COST;
}
public:
BuildBridgeWindow(WindowDesc *desc, TileIndex start, TileIndex end, TransportType transport_type, byte road_rail_type, GUIBridgeList *bl) : Window(desc),
start_tile(start),
@@ -183,14 +200,9 @@ public:
case WID_BBS_BRIDGE_LIST: {
Dimension sprite_dim = {0, 0}; // Biggest bridge sprite dimension
Dimension text_dim = {0, 0}; // Biggest text dimension
for (int i = 0; i < (int)this->bridges->size(); i++) {
const BridgeSpec *b = this->bridges->at(i).spec;
sprite_dim = maxdim(sprite_dim, GetSpriteSize(b->sprite));
SetDParam(2, this->bridges->at(i).cost);
SetDParam(1, b->speed);
SetDParam(0, b->material);
text_dim = maxdim(text_dim, GetStringBoundingBox(_game_mode == GM_EDITOR ? STR_SELECT_BRIDGE_SCENEDIT_INFO : STR_SELECT_BRIDGE_INFO));
for (const BuildBridgeData &bridge_data : *this->bridges) {
sprite_dim = maxdim(sprite_dim, GetSpriteSize(bridge_data.spec->sprite));
text_dim = maxdim(text_dim, GetStringBoundingBox(GetBridgeSelectString(bridge_data)));
}
sprite_dim.height++; // Sprite is rendered one pixel down in the matrix field.
text_dim.height++; // Allowing the bottom row pixels to be rendered on the edge of the matrix field.
@@ -224,15 +236,10 @@ public:
case WID_BBS_BRIDGE_LIST: {
Rect tr = r.WithHeight(this->resize.step_height).Shrink(WidgetDimensions::scaled.matrix);
for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < (int)this->bridges->size(); i++) {
const BridgeSpec *b = this->bridges->at(i).spec;
SetDParam(2, this->bridges->at(i).cost);
SetDParam(1, b->speed);
SetDParam(0, b->material);
const BuildBridgeData &bridge_data = this->bridges->at(i);
const BridgeSpec *b = bridge_data.spec;
DrawSprite(b->sprite, b->pal, tr.left, tr.bottom - GetSpriteSize(b->sprite).height);
DrawStringMultiLine(tr.Indent(this->bridgetext_offset, false),
_game_mode == GM_EDITOR ? STR_SELECT_BRIDGE_SCENEDIT_INFO : STR_SELECT_BRIDGE_INFO);
DrawStringMultiLine(tr.Indent(this->bridgetext_offset, false), GetBridgeSelectString(bridge_data));
tr = tr.Translate(0, this->resize.step_height);
}
break;