Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
#include "gfx_func.h"
|
||||
#include "tunnelbridge.h"
|
||||
#include "sortlist_type.h"
|
||||
#include "widgets/dropdown_func.h"
|
||||
#include "dropdown_func.h"
|
||||
#include "core/geometry_func.hpp"
|
||||
#include "tunnelbridge_map.h"
|
||||
#include "road_gui.h"
|
||||
@@ -57,7 +57,7 @@ typedef GUIList<BuildBridgeData> GUIBridgeList; ///< List of bridges, used in #B
|
||||
* @param tile_start start tile
|
||||
* @param transport_type transport type.
|
||||
*/
|
||||
void CcBuildBridge(Commands, const CommandCost &result, TileIndex end_tile, TileIndex tile_start, TransportType transport_type, BridgeType, byte)
|
||||
void CcBuildBridge(Commands, const CommandCost &result, TileIndex end_tile, TileIndex tile_start, TransportType transport_type, BridgeType, uint8_t)
|
||||
{
|
||||
if (result.Failed()) return;
|
||||
if (_settings_client.sound.confirm) SndPlayTileFx(SND_27_CONSTRUCTION_BRIDGE, end_tile);
|
||||
@@ -80,14 +80,18 @@ private:
|
||||
static Listing last_sorting; ///< Last setting of the sort.
|
||||
|
||||
/* Constants for sorting the bridges */
|
||||
static const StringID sorter_names[];
|
||||
static GUIBridgeList::SortFunction * const sorter_funcs[];
|
||||
static inline const StringID sorter_names[] = {
|
||||
STR_SORT_BY_NUMBER,
|
||||
STR_SORT_BY_COST,
|
||||
STR_SORT_BY_MAX_SPEED,
|
||||
};
|
||||
static const std::initializer_list<GUIBridgeList::SortFunction * const> sorter_funcs;
|
||||
|
||||
/* Internal variables */
|
||||
TileIndex start_tile;
|
||||
TileIndex end_tile;
|
||||
TransportType transport_type;
|
||||
byte road_rail_type;
|
||||
uint8_t road_rail_type;
|
||||
GUIBridgeList bridges;
|
||||
int icon_width; ///< Scaled width of the the bridge icon sprite.
|
||||
Scrollbar *vscroll;
|
||||
@@ -127,7 +131,7 @@ private:
|
||||
this->bridges.Sort();
|
||||
|
||||
/* Display the current sort variant */
|
||||
this->GetWidget<NWidgetCore>(WID_BBS_DROPDOWN_CRITERIA)->widget_data = this->sorter_names[this->bridges.SortType()];
|
||||
this->GetWidget<NWidgetCore>(WID_BBS_DROPDOWN_CRITERIA)->widget_data = BuildBridgeWindow::sorter_names[this->bridges.SortType()];
|
||||
|
||||
/* Set the modified widgets dirty */
|
||||
this->SetWidgetDirty(WID_BBS_DROPDOWN_CRITERIA);
|
||||
@@ -152,7 +156,7 @@ private:
|
||||
}
|
||||
|
||||
public:
|
||||
BuildBridgeWindow(WindowDesc *desc, TileIndex start, TileIndex end, TransportType transport_type, byte road_rail_type, GUIBridgeList &&bl) : Window(desc),
|
||||
BuildBridgeWindow(WindowDesc &desc, TileIndex start, TileIndex end, TransportType transport_type, uint8_t road_rail_type, GUIBridgeList &&bl) : Window(desc),
|
||||
start_tile(start),
|
||||
end_tile(end),
|
||||
transport_type(transport_type),
|
||||
@@ -166,8 +170,8 @@ public:
|
||||
this->FinishInitNested(transport_type); // Initializes 'this->icon_width'.
|
||||
|
||||
this->parent = FindWindowById(WC_BUILD_TOOLBAR, transport_type);
|
||||
this->bridges.SetListing(this->last_sorting);
|
||||
this->bridges.SetSortFuncs(this->sorter_funcs);
|
||||
this->bridges.SetListing(BuildBridgeWindow::last_sorting);
|
||||
this->bridges.SetSortFuncs(BuildBridgeWindow::sorter_funcs);
|
||||
this->bridges.NeedResort();
|
||||
this->SortBridgeList();
|
||||
|
||||
@@ -176,27 +180,24 @@ public:
|
||||
|
||||
~BuildBridgeWindow()
|
||||
{
|
||||
this->last_sorting = this->bridges.GetListing();
|
||||
BuildBridgeWindow::last_sorting = this->bridges.GetListing();
|
||||
}
|
||||
|
||||
void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
|
||||
void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
|
||||
{
|
||||
switch (widget) {
|
||||
case WID_BBS_DROPDOWN_ORDER: {
|
||||
Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
|
||||
d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
|
||||
d.height += padding.height;
|
||||
*size = maxdim(*size, d);
|
||||
size = maxdim(size, d);
|
||||
break;
|
||||
}
|
||||
case WID_BBS_DROPDOWN_CRITERIA: {
|
||||
Dimension d = {0, 0};
|
||||
for (const StringID *str = this->sorter_names; *str != INVALID_STRING_ID; str++) {
|
||||
d = maxdim(d, GetStringBoundingBox(*str));
|
||||
}
|
||||
Dimension d = GetStringListBoundingBox(BuildBridgeWindow::sorter_names);
|
||||
d.width += padding.width;
|
||||
d.height += padding.height;
|
||||
*size = maxdim(*size, d);
|
||||
size = maxdim(size, d);
|
||||
break;
|
||||
}
|
||||
case WID_BBS_BRIDGE_LIST: {
|
||||
@@ -206,11 +207,11 @@ public:
|
||||
sprite_dim = maxdim(sprite_dim, GetScaledSpriteSize(bridge_data.spec->sprite));
|
||||
text_dim = maxdim(text_dim, GetStringBoundingBox(GetBridgeSelectString(bridge_data)));
|
||||
}
|
||||
resize->height = std::max(sprite_dim.height, text_dim.height) + padding.height; // Max of both sizes + account for matrix edges.
|
||||
resize.height = std::max(sprite_dim.height, text_dim.height) + padding.height; // Max of both sizes + account for matrix edges.
|
||||
|
||||
this->icon_width = sprite_dim.width; // Width of bridge icon.
|
||||
size->width = this->icon_width + WidgetDimensions::scaled.hsep_normal + text_dim.width + padding.width;
|
||||
size->height = 4 * resize->height; // Smallest bridge gui is 4 entries high in the matrix.
|
||||
size.width = this->icon_width + WidgetDimensions::scaled.hsep_normal + text_dim.width + padding.width;
|
||||
size.height = 4 * resize.height; // Smallest bridge gui is 4 entries high in the matrix.
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -236,11 +237,11 @@ public:
|
||||
case WID_BBS_BRIDGE_LIST: {
|
||||
Rect tr = r.WithHeight(this->resize.step_height).Shrink(WidgetDimensions::scaled.matrix);
|
||||
bool rtl = _current_text_dir == TD_RTL;
|
||||
for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < (int)this->bridges.size(); i++) {
|
||||
const BuildBridgeData &bridge_data = this->bridges.at(i);
|
||||
const BridgeSpec *b = bridge_data.spec;
|
||||
auto [first, last] = this->vscroll->GetVisibleRangeIterators(this->bridges);
|
||||
for (auto it = first; it != last; ++it) {
|
||||
const BridgeSpec *b = it->spec;
|
||||
DrawSpriteIgnorePadding(b->sprite, b->pal, tr.WithWidth(this->icon_width, rtl), SA_HOR_CENTER | SA_BOTTOM);
|
||||
DrawStringMultiLine(tr.Indent(this->icon_width + WidgetDimensions::scaled.hsep_normal, rtl), GetBridgeSelectString(bridge_data));
|
||||
DrawStringMultiLine(tr.Indent(this->icon_width + WidgetDimensions::scaled.hsep_normal, rtl), GetBridgeSelectString(*it));
|
||||
tr = tr.Translate(0, this->resize.step_height);
|
||||
}
|
||||
break;
|
||||
@@ -279,7 +280,7 @@ public:
|
||||
break;
|
||||
|
||||
case WID_BBS_DROPDOWN_CRITERIA:
|
||||
ShowDropDownMenu(this, this->sorter_names, this->bridges.SortType(), WID_BBS_DROPDOWN_CRITERIA, 0, 0);
|
||||
ShowDropDownMenu(this, BuildBridgeWindow::sorter_names, this->bridges.SortType(), WID_BBS_DROPDOWN_CRITERIA, 0, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -303,20 +304,12 @@ public:
|
||||
Listing BuildBridgeWindow::last_sorting = {true, 2};
|
||||
|
||||
/** Available bridge sorting functions. */
|
||||
GUIBridgeList::SortFunction * const BuildBridgeWindow::sorter_funcs[] = {
|
||||
const std::initializer_list<GUIBridgeList::SortFunction * const> BuildBridgeWindow::sorter_funcs = {
|
||||
&BridgeIndexSorter,
|
||||
&BridgePriceSorter,
|
||||
&BridgeSpeedSorter
|
||||
};
|
||||
|
||||
/** Names of the sorting functions. */
|
||||
const StringID BuildBridgeWindow::sorter_names[] = {
|
||||
STR_SORT_BY_NUMBER,
|
||||
STR_SORT_BY_COST,
|
||||
STR_SORT_BY_MAX_SPEED,
|
||||
INVALID_STRING_ID
|
||||
};
|
||||
|
||||
/** Widgets of the bridge gui. */
|
||||
static constexpr NWidgetPart _nested_build_bridge_widgets[] = {
|
||||
/* Header */
|
||||
@@ -346,11 +339,11 @@ static constexpr NWidgetPart _nested_build_bridge_widgets[] = {
|
||||
};
|
||||
|
||||
/** Window definition for the rail bridge selection window. */
|
||||
static WindowDesc _build_bridge_desc(__FILE__, __LINE__,
|
||||
static WindowDesc _build_bridge_desc(
|
||||
WDP_AUTO, "build_bridge", 200, 114,
|
||||
WC_BUILD_BRIDGE, WC_BUILD_TOOLBAR,
|
||||
WDF_CONSTRUCTION,
|
||||
std::begin(_nested_build_bridge_widgets), std::end(_nested_build_bridge_widgets)
|
||||
_nested_build_bridge_widgets
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -363,7 +356,7 @@ static WindowDesc _build_bridge_desc(__FILE__, __LINE__,
|
||||
* @param transport_type The transport type
|
||||
* @param road_rail_type The road/rail type
|
||||
*/
|
||||
void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transport_type, byte road_rail_type)
|
||||
void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transport_type, uint8_t road_rail_type)
|
||||
{
|
||||
CloseWindowByClass(WC_BUILD_BRIDGE);
|
||||
|
||||
@@ -447,7 +440,7 @@ void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transpo
|
||||
}
|
||||
|
||||
if (!bl.empty()) {
|
||||
new BuildBridgeWindow(&_build_bridge_desc, start, end, transport_type, road_rail_type, std::move(bl));
|
||||
new BuildBridgeWindow(_build_bridge_desc, start, end, transport_type, road_rail_type, std::move(bl));
|
||||
} else {
|
||||
ShowErrorMessage(STR_ERROR_CAN_T_BUILD_BRIDGE_HERE, errmsg, WL_INFO, TileX(end) * TILE_SIZE, TileY(end) * TILE_SIZE);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user