Merge commit '73bed054b87399484e39f6972d30f91a404daba8'

This commit is contained in:
2024-04-03 19:37:54 +01:00
1355 changed files with 153171 additions and 81528 deletions
+55 -63
View File
@@ -46,7 +46,7 @@
*/
/** Nested widget definition for train depots. */
static const NWidgetPart _nested_train_depot_widgets[] = {
static constexpr NWidgetPart _nested_train_depot_widgets[] = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_D_SHOW_RENAME), // rename button
@@ -85,43 +85,42 @@ static const NWidgetPart _nested_train_depot_widgets[] = {
EndContainer(),
};
static WindowDesc _train_depot_desc(
static WindowDesc _train_depot_desc(__FILE__, __LINE__,
WDP_AUTO, "depot_train", 362, 123,
WC_VEHICLE_DEPOT, WC_NONE,
0,
_nested_train_depot_widgets, lengthof(_nested_train_depot_widgets)
std::begin(_nested_train_depot_widgets), std::end(_nested_train_depot_widgets)
);
static WindowDesc _road_depot_desc(
static WindowDesc _road_depot_desc(__FILE__, __LINE__,
WDP_AUTO, "depot_roadveh", 316, 97,
WC_VEHICLE_DEPOT, WC_NONE,
0,
_nested_train_depot_widgets, lengthof(_nested_train_depot_widgets)
std::begin(_nested_train_depot_widgets), std::end(_nested_train_depot_widgets)
);
static WindowDesc _ship_depot_desc(
static WindowDesc _ship_depot_desc(__FILE__, __LINE__,
WDP_AUTO, "depot_ship", 306, 99,
WC_VEHICLE_DEPOT, WC_NONE,
0,
_nested_train_depot_widgets, lengthof(_nested_train_depot_widgets)
std::begin(_nested_train_depot_widgets), std::end(_nested_train_depot_widgets)
);
static WindowDesc _aircraft_depot_desc(
static WindowDesc _aircraft_depot_desc(__FILE__, __LINE__,
WDP_AUTO, "depot_aircraft", 332, 99,
WC_VEHICLE_DEPOT, WC_NONE,
0,
_nested_train_depot_widgets, lengthof(_nested_train_depot_widgets)
std::begin(_nested_train_depot_widgets), std::end(_nested_train_depot_widgets)
);
extern void DepotSortList(VehicleList *list);
/**
* This is the Callback method after the cloning attempt of a vehicle
* @param cmd unused
* @param result the result of the cloning command
* @param veh_id cloned vehicle ID
*/
void CcCloneVehicle(Commands cmd, const CommandCost &result, VehicleID veh_id)
void CcCloneVehicle(Commands, const CommandCost &result, VehicleID veh_id)
{
if (result.Failed()) return;
@@ -259,7 +258,7 @@ struct DepotWindow : Window {
VehicleID vehicle_over; ///< Rail vehicle over which another one is dragged, \c INVALID_VEHICLE if none.
VehicleType type;
bool generate_list;
int hovered_widget; ///< Index of the widget being hovered during drag/drop. -1 if no drag is in progress.
WidgetID hovered_widget; ///< Index of the widget being hovered during drag/drop. -1 if no drag is in progress.
VehicleList vehicle_list;
VehicleList wagon_list;
uint unitnumber_digits;
@@ -295,7 +294,7 @@ struct DepotWindow : Window {
OrderBackup::Reset();
}
void Close() override
void Close([[maybe_unused]] int data = 0) override
{
CloseWindowById(WC_BUILD_VEHICLE, this->window_number);
CloseWindowById(GetWindowClassForVehicleType(this->type), VehicleListIdentifier(VL_DEPOT_LIST, this->type, this->owner, this->GetDepotIndex()).Pack(), false);
@@ -331,7 +330,7 @@ struct DepotWindow : Window {
SetDParam(0, CeilDiv(u->gcache.cached_total_length * 10, TILE_SIZE));
SetDParam(1, 1);
Rect count = text.WithWidth(this->count_width - WidgetDimensions::scaled.hsep_normal, !rtl);
DrawString(count.left, count.right, count.bottom - FONT_HEIGHT_SMALL + 1, STR_TINY_BLACK_DECIMAL, TC_FROMSTRING, SA_RIGHT); // Draw the counter
DrawString(count.left, count.right, count.bottom - GetCharacterHeight(FS_SMALL) + 1, STR_JUST_DECIMAL, TC_BLACK, SA_RIGHT, false, FS_SMALL); // Draw the counter
break;
}
@@ -349,22 +348,22 @@ struct DepotWindow : Window {
} else {
/* Arrange unitnumber and flag vertically */
diff_x = 0;
diff_y = WidgetDimensions::scaled.matrix.top + FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.vsep_normal;
diff_y = WidgetDimensions::scaled.matrix.top + GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal;
}
text = text.WithWidth(this->header_width - WidgetDimensions::scaled.hsep_normal, rtl).WithHeight(FONT_HEIGHT_NORMAL).Indent(diff_x, rtl);
text = text.WithWidth(this->header_width - WidgetDimensions::scaled.hsep_normal, rtl).WithHeight(GetCharacterHeight(FS_NORMAL)).Indent(diff_x, rtl);
if (free_wagon) {
DrawString(text, STR_DEPOT_NO_ENGINE);
} else {
Rect flag = r.WithWidth(this->flag_size.width, rtl).WithHeight(this->flag_size.height).Translate(0, diff_y);
DrawSpriteIgnorePadding((v->vehstatus & VS_STOPPED) ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, PAL_NONE, flag, false, SA_CENTER);
DrawSpriteIgnorePadding((v->vehstatus & VS_STOPPED) ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, PAL_NONE, flag, SA_CENTER);
SetDParam(0, v->unitnumber);
DrawString(text, (uint16)(v->max_age - DAYS_IN_LEAP_YEAR) >= v->age ? STR_BLACK_COMMA : STR_RED_COMMA);
DrawString(text, STR_JUST_COMMA, (v->max_age - CalendarTime::DAYS_IN_LEAP_YEAR) >= v->age ? TC_BLACK : TC_RED);
}
}
void DrawWidget(const Rect &r, int widget) const override
void DrawWidget(const Rect &r, WidgetID widget) const override
{
if (widget != WID_D_MATRIX) return;
@@ -399,7 +398,7 @@ struct DepotWindow : Window {
}
}
uint16 rows_in_display = wid->current_y / wid->resize_y;
uint16_t rows_in_display = wid->current_y / wid->resize_y;
uint num = this->vscroll->GetPosition() * this->num_columns;
uint maxval = static_cast<uint>(std::min<size_t>(this->vehicle_list.size(), num + (rows_in_display * this->num_columns)));
@@ -422,7 +421,7 @@ struct DepotWindow : Window {
}
}
void SetStringParameters(int widget) const override
void SetStringParameters(WidgetID widget) const override
{
if (widget != WID_D_CAPTION) return;
@@ -445,6 +444,8 @@ struct DepotWindow : Window {
DepotGUIAction GetVehicleFromDepotWndPt(int x, int y, const Vehicle **veh, GetDepotVehiclePtData *d) const
{
const NWidgetCore *matrix_widget = this->GetWidget<NWidgetCore>(WID_D_MATRIX);
/* Make X relative to widget. Y is left alone for GetScrolledRowFromWidget(). */
x -= matrix_widget->pos_x;
/* In case of RTL the widgets are swapped as a whole */
if (_current_text_dir == TD_RTL) x = matrix_widget->current_x - x;
@@ -456,14 +457,12 @@ struct DepotWindow : Window {
xm = x % this->resize.step_width;
if (xt >= this->num_columns) return MODE_ERROR;
}
ym = y % this->resize.step_height;
ym = (y - matrix_widget->pos_y) % this->resize.step_height;
uint row = y / this->resize.step_height;
if (row >= this->vscroll->GetCapacity()) return MODE_ERROR;
int row = this->vscroll->GetScrolledRowFromWidget(y, this, WID_D_MATRIX);
uint pos = (row * this->num_columns) + xt;
uint pos = ((row + this->vscroll->GetPosition()) * this->num_columns) + xt;
if (this->vehicle_list.size() + this->wagon_list.size() <= pos) {
if (row == INT_MAX || this->vehicle_list.size() + this->wagon_list.size() <= pos) {
/* Clicking on 'line' / 'block' without a vehicle */
if (this->type == VEH_TRAIN) {
/* End the dragging */
@@ -498,7 +497,7 @@ struct DepotWindow : Window {
switch (this->type) {
case VEH_TRAIN:
if (wagon) return MODE_ERROR;
FALLTHROUGH;
[[fallthrough]];
case VEH_ROAD:
if (xm <= this->flag_size.width) return MODE_START_STOP;
@@ -506,7 +505,7 @@ struct DepotWindow : Window {
case VEH_SHIP:
case VEH_AIRCRAFT:
if (xm <= this->flag_size.width && ym >= (uint)(FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.vsep_normal)) return MODE_START_STOP;
if (xm <= this->flag_size.width && ym >= (uint)(GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal)) return MODE_START_STOP;
break;
default: NOT_REACHED();
@@ -654,7 +653,7 @@ struct DepotWindow : Window {
this->flag_size = maxdim(GetScaledSpriteSize(SPR_FLAG_VEH_STOPPED), GetScaledSpriteSize(SPR_FLAG_VEH_RUNNING));
}
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, 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_D_MATRIX: {
@@ -663,13 +662,13 @@ struct DepotWindow : Window {
if (this->type == VEH_TRAIN) {
SetDParamMaxValue(0, 1000, 0, FS_SMALL);
SetDParam(1, 1);
this->count_width = GetStringBoundingBox(STR_TINY_BLACK_DECIMAL).width + WidgetDimensions::scaled.hsep_normal;
this->count_width = GetStringBoundingBox(STR_JUST_DECIMAL, FS_SMALL).width + WidgetDimensions::scaled.hsep_normal;
} else {
this->count_width = 0;
}
SetDParamMaxDigits(0, this->unitnumber_digits);
Dimension unumber = GetStringBoundingBox(STR_BLACK_COMMA);
Dimension unumber = GetStringBoundingBox(STR_JUST_COMMA);
if (this->type == VEH_TRAIN || this->type == VEH_ROAD) {
min_height = std::max<uint>(unumber.height, this->flag_size.height);
@@ -703,7 +702,7 @@ struct DepotWindow : Window {
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
void OnInvalidateData(int data = 0, bool gui_scope = true) override
void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
{
this->generate_list = true;
}
@@ -736,7 +735,7 @@ struct DepotWindow : Window {
max_width = std::max(max_width, width);
}
/* Always have 1 empty row, so people can change the setting of the train */
this->vscroll->SetCount((uint)this->vehicle_list.size() + (uint)this->wagon_list.size() + 1);
this->vscroll->SetCount(this->vehicle_list.size() + this->wagon_list.size() + 1);
/* Always make it longer than the longest train, so you can attach vehicles at the end, and also see the next vertical tile separator line */
this->hscroll->SetCount(max_width + ScaleSpriteTrad(2 * VEHICLEINFO_FULL_VEHICLE_WIDTH + 1));
} else {
@@ -754,20 +753,17 @@ struct DepotWindow : Window {
WID_D_BUILD,
WID_D_CLONE,
WID_D_RENAME,
WID_D_AUTOREPLACE,
WIDGET_LIST_END);
WID_D_AUTOREPLACE);
this->DrawWidgets();
}
void OnClick(Point pt, int widget, int click_count) override
void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
{
switch (widget) {
case WID_D_MATRIX: { // List
NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_D_MATRIX);
this->DepotClick(pt.x - nwi->pos_x, pt.y - nwi->pos_y);
case WID_D_MATRIX: // List
this->DepotClick(pt.x, pt.y);
break;
}
case WID_D_BUILD: // Build vehicle
ResetObjectToPlace();
@@ -813,7 +809,7 @@ struct DepotWindow : Window {
case WID_D_SELL_ALL:
/* Only open the confirmation window if there are anything to sell */
if (this->vehicle_list.size() != 0 || this->wagon_list.size() != 0) {
if (!this->vehicle_list.empty() || !this->wagon_list.empty()) {
SetDParam(0, this->type);
SetDParam(1, this->GetDepotIndex());
ShowQuery(
@@ -844,20 +840,19 @@ struct DepotWindow : Window {
Command<CMD_RENAME_DEPOT>::Post(STR_ERROR_CAN_T_RENAME_DEPOT, this->GetDepotIndex(), str);
}
bool OnRightClick(Point pt, int widget) override
bool OnRightClick([[maybe_unused]] Point pt, WidgetID widget) override
{
if (widget != WID_D_MATRIX) return false;
GetDepotVehiclePtData gdvp = { nullptr, nullptr };
const Vehicle *v = nullptr;
NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_D_MATRIX);
DepotGUIAction mode = this->GetVehicleFromDepotWndPt(pt.x - nwi->pos_x, pt.y - nwi->pos_y, &v, &gdvp);
DepotGUIAction mode = this->GetVehicleFromDepotWndPt(pt.x, pt.y, &v, &gdvp);
if (this->type == VEH_TRAIN) v = gdvp.wagon;
if (v == nullptr || mode != MODE_DRAG_VEHICLE) return false;
CargoArray capacity, loaded;
CargoArray capacity{}, loaded{};
/* Display info for single (articulated) vehicle, or for whole chain starting with selected vehicle */
bool whole_chain = (this->type == VEH_TRAIN && _ctrl_pressed);
@@ -877,25 +872,24 @@ struct DepotWindow : Window {
}
/* Build tooltipstring */
static char details[1024];
details[0] = '\0';
char *pos = details;
static std::string details;
details.clear();
for (CargoID cargo_type = 0; cargo_type < NUM_CARGO; cargo_type++) {
for (const CargoSpec *cs : _sorted_cargo_specs) {
CargoID cargo_type = cs->Index();
if (capacity[cargo_type] == 0) continue;
SetDParam(0, cargo_type); // {CARGO} #1
SetDParam(1, loaded[cargo_type]); // {CARGO} #2
SetDParam(2, cargo_type); // {SHORTCARGO} #1
SetDParam(3, capacity[cargo_type]); // {SHORTCARGO} #2
pos = GetString(pos, STR_DEPOT_VEHICLE_TOOLTIP_CARGO, lastof(details));
details += GetString(STR_DEPOT_VEHICLE_TOOLTIP_CARGO);
}
/* Show tooltip window */
uint64 args[2];
args[0] = (whole_chain ? num : v->engine_type);
args[1] = (uint64)(size_t)details;
GuiShowTooltips(this, whole_chain ? STR_DEPOT_VEHICLE_TOOLTIP_CHAIN : STR_DEPOT_VEHICLE_TOOLTIP, 2, args, TCC_RIGHT_CLICK);
SetDParam(0, whole_chain ? num : v->engine_type);
SetDParamStr(1, details);
GuiShowTooltips(this, whole_chain ? STR_DEPOT_VEHICLE_TOOLTIP_CHAIN : STR_DEPOT_VEHICLE_TOOLTIP, TCC_RIGHT_CLICK, 2);
return true;
}
@@ -981,7 +975,7 @@ struct DepotWindow : Window {
}
}
void OnMouseDrag(Point pt, int widget) override
void OnMouseDrag(Point pt, WidgetID widget) override
{
if (this->sel == INVALID_VEHICLE) return;
if (widget != this->hovered_widget) {
@@ -1006,11 +1000,10 @@ struct DepotWindow : Window {
return;
}
NWidgetBase *matrix = this->GetWidget<NWidgetBase>(widget);
const Vehicle *v = nullptr;
GetDepotVehiclePtData gdvp = {nullptr, nullptr};
if (this->GetVehicleFromDepotWndPt(pt.x - matrix->pos_x, pt.y - matrix->pos_y, &v, &gdvp) != MODE_DRAG_VEHICLE) return;
if (this->GetVehicleFromDepotWndPt(pt.x, pt.y, &v, &gdvp) != MODE_DRAG_VEHICLE) return;
VehicleID new_vehicle_over = INVALID_VEHICLE;
if (gdvp.head != nullptr) {
@@ -1033,7 +1026,7 @@ struct DepotWindow : Window {
this->SetWidgetDirty(widget);
}
void OnDragDrop(Point pt, int widget) override
void OnDragDrop(Point pt, WidgetID widget) override
{
switch (widget) {
case WID_D_MATRIX: {
@@ -1043,11 +1036,10 @@ struct DepotWindow : Window {
this->sel = INVALID_VEHICLE;
this->SetDirty();
NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_D_MATRIX);
if (this->type == VEH_TRAIN) {
GetDepotVehiclePtData gdvp = { nullptr, nullptr };
if (this->GetVehicleFromDepotWndPt(pt.x - nwi->pos_x, pt.y - nwi->pos_y, &v, &gdvp) == MODE_DRAG_VEHICLE && sel != INVALID_VEHICLE) {
if (this->GetVehicleFromDepotWndPt(pt.x, pt.y, &v, &gdvp) == MODE_DRAG_VEHICLE && sel != INVALID_VEHICLE) {
if (gdvp.wagon != nullptr && gdvp.wagon->index == sel && _ctrl_pressed) {
Command<CMD_REVERSE_TRAIN_DIRECTION>::Post(STR_ERROR_CAN_T_REVERSE_DIRECTION_RAIL_VEHICLE, Vehicle::Get(sel)->tile, Vehicle::Get(sel)->index, true);
} else if (gdvp.wagon == nullptr || gdvp.wagon->index != sel) {
@@ -1057,7 +1049,7 @@ struct DepotWindow : Window {
ShowVehicleViewWindow(gdvp.head);
}
}
} else if (this->GetVehicleFromDepotWndPt(pt.x - nwi->pos_x, pt.y - nwi->pos_y, &v, nullptr) == MODE_DRAG_VEHICLE && v != nullptr && sel == v->index) {
} else if (this->GetVehicleFromDepotWndPt(pt.x, pt.y, &v, nullptr) == MODE_DRAG_VEHICLE && v != nullptr && sel == v->index) {
ShowVehicleViewWindow(v);
}
break;
@@ -1126,7 +1118,7 @@ struct DepotWindow : Window {
* In the case of airports, this is the station ID.
* @return Depot or station ID of this window.
*/
inline uint16 GetDepotIndex() const
inline uint16_t GetDepotIndex() const
{
return (this->type == VEH_AIRCRAFT) ? ::GetStationIndex(this->window_number) : ::GetDepotIndex(this->window_number);
}