mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-09 15:41:15 +00:00
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:
parent
3c80f2d14a
commit
01be423237
@ -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;
|
||||
|
@ -2698,8 +2698,10 @@ STR_BUILD_SIGNAL_DRAG_SIGNALS_DENSITY_INCREASE_TOOLTIP :{BLACK}Increase
|
||||
STR_SELECT_RAIL_BRIDGE_CAPTION :{WHITE}Select Rail Bridge
|
||||
STR_SELECT_ROAD_BRIDGE_CAPTION :{WHITE}Select Road Bridge
|
||||
STR_SELECT_BRIDGE_SELECTION_TOOLTIP :{BLACK}Bridge selection - click on your preferred bridge to build it
|
||||
STR_SELECT_BRIDGE_INFO :{GOLD}{STRING},{} {VELOCITY} {WHITE}{CURRENCY_LONG}
|
||||
STR_SELECT_BRIDGE_SCENEDIT_INFO :{GOLD}{STRING},{} {VELOCITY}
|
||||
STR_SELECT_BRIDGE_INFO_NAME :{GOLD}{STRING}
|
||||
STR_SELECT_BRIDGE_INFO_NAME_MAX_SPEED :{GOLD}{STRING},{} {VELOCITY}
|
||||
STR_SELECT_BRIDGE_INFO_NAME_COST :{GOLD}{0:STRING},{} {WHITE}{2:CURRENCY_LONG}
|
||||
STR_SELECT_BRIDGE_INFO_NAME_MAX_SPEED_COST :{GOLD}{STRING},{} {VELOCITY} {WHITE}{CURRENCY_LONG}
|
||||
STR_BRIDGE_NAME_SUSPENSION_STEEL :Suspension, Steel
|
||||
STR_BRIDGE_NAME_GIRDER_STEEL :Girder, Steel
|
||||
STR_BRIDGE_NAME_CANTILEVER_STEEL :Cantilever, Steel
|
||||
|
@ -2190,7 +2190,7 @@ static ChangeInfoResult BridgeChangeInfo(uint brid, int numinfo, int prop, ByteR
|
||||
|
||||
case 0x0A: // Maximum length
|
||||
bridge->max_length = buf->ReadByte();
|
||||
if (bridge->max_length > 16) bridge->max_length = 0xFFFF;
|
||||
if (bridge->max_length > 16) bridge->max_length = UINT16_MAX;
|
||||
break;
|
||||
|
||||
case 0x0B: // Cost factor
|
||||
@ -2199,6 +2199,7 @@ static ChangeInfoResult BridgeChangeInfo(uint brid, int numinfo, int prop, ByteR
|
||||
|
||||
case 0x0C: // Maximum speed
|
||||
bridge->speed = buf->ReadWord();
|
||||
if (bridge->speed == 0) bridge->speed = UINT16_MAX;
|
||||
break;
|
||||
|
||||
case 0x0D: { // Bridge sprite tables
|
||||
|
@ -1757,12 +1757,16 @@ static void GetTileDesc_TunnelBridge(TileIndex tile, TileDesc *td)
|
||||
|
||||
if (!IsTunnel(tile)) {
|
||||
uint16 spd = GetBridgeSpec(GetBridgeType(tile))->speed;
|
||||
/* rail speed special-cases 0 as unlimited, hides display of limit etc. */
|
||||
if (spd == UINT16_MAX) spd = 0;
|
||||
if (td->rail_speed == 0 || spd < td->rail_speed) {
|
||||
td->rail_speed = spd;
|
||||
}
|
||||
}
|
||||
} else if (tt == TRANSPORT_ROAD && !IsTunnel(tile)) {
|
||||
uint16 spd = GetBridgeSpec(GetBridgeType(tile))->speed;
|
||||
/* road speed special-cases 0 as unlimited, hides display of limit etc. */
|
||||
if (spd == UINT16_MAX) spd = 0;
|
||||
if (road_rt != INVALID_ROADTYPE && (td->road_speed == 0 || spd < td->road_speed)) td->road_speed = spd;
|
||||
if (tram_rt != INVALID_ROADTYPE && (td->tram_speed == 0 || spd < td->tram_speed)) td->tram_speed = spd;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user