Update to 14.0-beta1

This commit is contained in:
dP
2024-02-04 02:18:17 +05:30
parent 79037e2c65
commit 33ef333b57
1325 changed files with 138465 additions and 70987 deletions

View File

@@ -51,18 +51,19 @@ StringID GetEngineCategoryName(EngineID engine)
}
}
static const NWidgetPart _nested_engine_preview_widgets[] = {
static constexpr NWidgetPart _nested_engine_preview_widgets[] = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE),
NWidget(WWT_CAPTION, COLOUR_LIGHT_BLUE), SetDataTip(STR_ENGINE_PREVIEW_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE),
NWidget(WWT_EMPTY, INVALID_COLOUR, WID_EP_QUESTION), SetMinimalSize(300, 0), SetPadding(8, 8, 8, 8), SetFill(1, 0),
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(85, 10, 85),
NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_EP_NO), SetDataTip(STR_QUIT_NO, STR_NULL), SetFill(1, 0),
NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_EP_YES), SetDataTip(STR_QUIT_YES, STR_NULL), SetFill(1, 0),
NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_wide, 0), SetPadding(WidgetDimensions::unscaled.modalpopup),
NWidget(WWT_EMPTY, INVALID_COLOUR, WID_EP_QUESTION), SetMinimalSize(300, 0), SetFill(1, 0),
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(85, WidgetDimensions::unscaled.hsep_wide, 85),
NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_EP_NO), SetDataTip(STR_QUIT_NO, STR_NULL), SetFill(1, 0),
NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_EP_YES), SetDataTip(STR_QUIT_YES, STR_NULL), SetFill(1, 0),
EndContainer(),
EndContainer(),
NWidget(NWID_SPACER), SetMinimalSize(0, 8),
EndContainer(),
};
@@ -77,7 +78,7 @@ struct EnginePreviewWindow : Window {
this->flags |= WF_STICKY;
}
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
{
if (widget != WID_EP_QUESTION) return;
@@ -99,12 +100,12 @@ struct EnginePreviewWindow : Window {
size->width = std::max(size->width, x - x_offs);
SetDParam(0, GetEngineCategoryName(engine));
size->height = GetStringHeight(STR_ENGINE_PREVIEW_MESSAGE, size->width) + WidgetDimensions::scaled.vsep_wide + FONT_HEIGHT_NORMAL + this->vehicle_space;
size->height = GetStringHeight(STR_ENGINE_PREVIEW_MESSAGE, size->width) + WidgetDimensions::scaled.vsep_wide + GetCharacterHeight(FS_NORMAL) + this->vehicle_space;
SetDParam(0, engine);
size->height += GetStringHeight(GetEngineInfoString(engine), size->width);
}
void DrawWidget(const Rect &r, int widget) const override
void DrawWidget(const Rect &r, WidgetID widget) const override
{
if (widget != WID_EP_QUESTION) return;
@@ -114,7 +115,7 @@ struct EnginePreviewWindow : Window {
SetDParam(0, PackEngineNameDParam(engine, EngineNameContext::PreviewNews));
DrawString(r.left, r.right, y, STR_ENGINE_NAME, TC_BLACK, SA_HOR_CENTER);
y += FONT_HEIGHT_NORMAL;
y += GetCharacterHeight(FS_NORMAL);
DrawVehicleEngine(r.left, r.right, this->width >> 1, y + this->vehicle_space / 2, engine, GetEnginePalette(engine, _local_company), EIT_PREVIEW);
@@ -122,19 +123,19 @@ struct EnginePreviewWindow : Window {
DrawStringMultiLine(r.left, r.right, y, r.bottom, GetEngineInfoString(engine), TC_FROMSTRING, SA_CENTER);
}
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_EP_YES:
Command<CMD_WANT_ENGINE_PREVIEW>::Post(this->window_number);
FALLTHROUGH;
[[fallthrough]];
case WID_EP_NO:
if (!_shift_pressed) this->Close();
break;
}
}
void OnInvalidateData(int data = 0, bool gui_scope = true) override
void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
{
if (!gui_scope) return;
@@ -143,11 +144,11 @@ struct EnginePreviewWindow : Window {
}
};
static WindowDesc _engine_preview_desc(
WDP_CENTER, "engine_preview", 0, 0,
static WindowDesc _engine_preview_desc(__FILE__, __LINE__,
WDP_CENTER, nullptr, 0, 0,
WC_ENGINE_PREVIEW, WC_NONE,
WDF_CONSTRUCTION,
_nested_engine_preview_widgets, lengthof(_nested_engine_preview_widgets)
std::begin(_nested_engine_preview_widgets), std::end(_nested_engine_preview_widgets)
);
@@ -169,92 +170,97 @@ uint GetTotalCapacityOfArticulatedParts(EngineID engine)
static StringID GetTrainEngineInfoString(const Engine *e)
{
SetDParam(0, e->GetCost());
SetDParam(2, e->GetDisplayMaxSpeed());
SetDParam(3, e->GetPower());
SetDParam(1, e->GetDisplayWeight());
SetDParam(7, e->GetDisplayMaxTractiveEffort());
SetDParam(0, STR_ENGINE_PREVIEW_COST_WEIGHT);
SetDParam(1, e->GetCost());
SetDParam(2, e->GetDisplayWeight());
SetDParam(4, e->GetRunningCost());
SetDParam(3, (_settings_game.vehicle.train_acceleration_model != AM_ORIGINAL && GetRailTypeInfo(e->u.rail.railtype)->acceleration_type != 2) ? STR_ENGINE_PREVIEW_SPEED_POWER_MAX_TE : STR_ENGINE_PREVIEW_SPEED_POWER);
SetDParam(4, PackVelocity(e->GetDisplayMaxSpeed(), e->type));
SetDParam(5, e->GetPower());
SetDParam(6, e->GetDisplayMaxTractiveEffort());
SetDParam(7, TimerGameEconomy::UsingWallclockUnits() ? STR_ENGINE_PREVIEW_RUNCOST_PERIOD : STR_ENGINE_PREVIEW_RUNCOST_YEAR);
SetDParam(8, e->GetRunningCost());
SetDParam(9, STR_ENGINE_PREVIEW_CAPACITY);
uint capacity = GetTotalCapacityOfArticulatedParts(e->index);
if (capacity != 0) {
SetDParam(5, e->GetDefaultCargoType());
SetDParam(6, capacity);
} else {
SetDParam(5, CT_INVALID);
}
return (_settings_game.vehicle.train_acceleration_model != AM_ORIGINAL && GetRailTypeInfo(e->u.rail.railtype)->acceleration_type != 2) ? STR_ENGINE_PREVIEW_COST_WEIGHT_SPEED_POWER_MAX_TE : STR_ENGINE_PREVIEW_COST_WEIGHT_SPEED_POWER;
SetDParam(10, capacity != 0 ? e->GetDefaultCargoType() : INVALID_CARGO);
SetDParam(11, capacity);
return STR_ENGINE_PREVIEW_TEXT4;
}
static StringID GetAircraftEngineInfoString(const Engine *e)
{
CargoID cargo = e->GetDefaultCargoType();
uint16 mail_capacity;
uint16_t mail_capacity;
uint capacity = e->GetDisplayDefaultCapacity(&mail_capacity);
uint16 range = e->GetRange();
uint16_t range = e->GetRange();
uint i = 0;
SetDParam(i++, e->GetCost());
SetDParam(i++, e->GetDisplayMaxSpeed());
SetDParam(i++, e->GetAircraftTypeText());
if (range > 0) SetDParam(i++, range);
SetDParam(i++, cargo);
SetDParam(i++, capacity);
SetDParam(0, STR_ENGINE_PREVIEW_COST_MAX_SPEED);
SetDParam(1, e->GetCost());
SetDParam(2, PackVelocity(e->GetDisplayMaxSpeed(), e->type));
if (mail_capacity > 0) {
SetDParam(i++, CT_MAIL);
SetDParam(i++, mail_capacity);
SetDParam(i++, e->GetRunningCost());
return range > 0 ? STR_ENGINE_PREVIEW_COST_MAX_SPEED_TYPE_RANGE_CAP_CAP_RUNCOST : STR_ENGINE_PREVIEW_COST_MAX_SPEED_TYPE_CAP_CAP_RUNCOST;
} else {
SetDParam(i++, e->GetRunningCost());
return range > 0 ? STR_ENGINE_PREVIEW_COST_MAX_SPEED_TYPE_RANGE_CAP_RUNCOST : STR_ENGINE_PREVIEW_COST_MAX_SPEED_TYPE_CAP_RUNCOST;
}
SetDParam(3, range > 0 ? STR_ENGINE_PREVIEW_TYPE_RANGE : STR_ENGINE_PREVIEW_TYPE);
SetDParam(4, e->GetAircraftTypeText());
SetDParam(5, range);
SetDParam(7, TimerGameEconomy::UsingWallclockUnits() ? STR_ENGINE_PREVIEW_RUNCOST_PERIOD : STR_ENGINE_PREVIEW_RUNCOST_YEAR);
SetDParam(8, e->GetRunningCost());
SetDParam(9, mail_capacity > 0 ? STR_ENGINE_PREVIEW_CAPACITY_2 : STR_ENGINE_PREVIEW_CAPACITY);
SetDParam(10, cargo);
SetDParam(11, capacity);
SetDParam(12, CT_MAIL);
SetDParam(13, mail_capacity);
return STR_ENGINE_PREVIEW_TEXT4;
}
static StringID GetRoadVehEngineInfoString(const Engine *e)
{
SetDParam(7, TimerGameEconomy::UsingWallclockUnits() ? STR_ENGINE_PREVIEW_RUNCOST_PERIOD : STR_ENGINE_PREVIEW_RUNCOST_YEAR);
SetDParam(8, e->GetRunningCost());
SetDParam(9, STR_ENGINE_PREVIEW_CAPACITY);
uint capacity = GetTotalCapacityOfArticulatedParts(e->index);
SetDParam(10, capacity != 0 ? e->GetDefaultCargoType() : INVALID_CARGO);
SetDParam(11, capacity);
if (_settings_game.vehicle.roadveh_acceleration_model == AM_ORIGINAL) {
SetDParam(0, e->GetCost());
SetDParam(1, e->GetDisplayMaxSpeed());
uint capacity = GetTotalCapacityOfArticulatedParts(e->index);
if (capacity != 0) {
SetDParam(2, e->GetDefaultCargoType());
SetDParam(3, capacity);
} else {
SetDParam(2, CT_INVALID);
}
SetDParam(4, e->GetRunningCost());
return STR_ENGINE_PREVIEW_COST_MAX_SPEED_CAP_RUNCOST;
SetDParam(0, STR_ENGINE_PREVIEW_COST_MAX_SPEED);
SetDParam(1, e->GetCost());
SetDParam(2, PackVelocity(e->GetDisplayMaxSpeed(), e->type));
return STR_ENGINE_PREVIEW_TEXT3;
} else {
SetDParam(0, e->GetCost());
SetDParam(2, e->GetDisplayMaxSpeed());
SetDParam(3, e->GetPower());
SetDParam(1, e->GetDisplayWeight());
SetDParam(7, e->GetDisplayMaxTractiveEffort());
SetDParam(0, STR_ENGINE_PREVIEW_COST_WEIGHT);
SetDParam(1, e->GetCost());
SetDParam(2, e->GetDisplayWeight());
SetDParam(4, e->GetRunningCost());
SetDParam(3, STR_ENGINE_PREVIEW_SPEED_POWER_MAX_TE);
SetDParam(4, PackVelocity(e->GetDisplayMaxSpeed(), e->type));
SetDParam(5, e->GetPower());
SetDParam(6, e->GetDisplayMaxTractiveEffort());
uint capacity = GetTotalCapacityOfArticulatedParts(e->index);
if (capacity != 0) {
SetDParam(5, e->GetDefaultCargoType());
SetDParam(6, capacity);
} else {
SetDParam(5, CT_INVALID);
}
return STR_ENGINE_PREVIEW_COST_WEIGHT_SPEED_POWER_MAX_TE;
return STR_ENGINE_PREVIEW_TEXT4;
}
}
static StringID GetShipEngineInfoString(const Engine *e)
{
SetDParam(0, e->GetCost());
SetDParam(1, e->GetDisplayMaxSpeed());
SetDParam(2, e->GetDefaultCargoType());
SetDParam(3, e->GetDisplayDefaultCapacity());
SetDParam(4, e->GetRunningCost());
return STR_ENGINE_PREVIEW_COST_MAX_SPEED_CAP_RUNCOST;
SetDParam(0, STR_ENGINE_PREVIEW_COST_MAX_SPEED);
SetDParam(1, e->GetCost());
SetDParam(2, PackVelocity(e->GetDisplayMaxSpeed(), e->type));
SetDParam(7, TimerGameEconomy::UsingWallclockUnits() ? STR_ENGINE_PREVIEW_RUNCOST_PERIOD : STR_ENGINE_PREVIEW_RUNCOST_YEAR);
SetDParam(8, e->GetRunningCost());
SetDParam(9, STR_ENGINE_PREVIEW_CAPACITY);
SetDParam(10, e->GetDefaultCargoType());
SetDParam(11, e->GetDisplayDefaultCapacity());
return STR_ENGINE_PREVIEW_TEXT3;
}
@@ -324,10 +330,10 @@ void DrawVehicleEngine(int left, int right, int preferred_x, int y, EngineID eng
* @param el list to be sorted
* @param compare function for evaluation of the quicksort
*/
void EngList_Sort(GUIEngineList *el, EngList_SortTypeFunction compare)
void EngList_Sort(GUIEngineList &el, EngList_SortTypeFunction compare)
{
if (el->size() < 2) return;
std::sort(el->begin(), el->end(), compare);
if (el.size() < 2) return;
std::sort(el.begin(), el.end(), compare);
}
/**
@@ -337,11 +343,11 @@ void EngList_Sort(GUIEngineList *el, EngList_SortTypeFunction compare)
* @param begin start of sorting
* @param num_items count of items to be sorted
*/
void EngList_SortPartial(GUIEngineList *el, EngList_SortTypeFunction compare, size_t begin, size_t num_items)
void EngList_SortPartial(GUIEngineList &el, EngList_SortTypeFunction compare, size_t begin, size_t num_items)
{
if (num_items < 2) return;
assert(begin < el->size());
assert(begin + num_items <= el->size());
std::sort(el->begin() + begin, el->begin() + begin + num_items, compare);
assert(begin < el.size());
assert(begin + num_items <= el.size());
std::sort(el.begin() + begin, el.begin() + begin + num_items, compare);
}