mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Build engine preview strings from separate strings. (#13579)
This replaces stuffing substrings and parameters in various global parameters and uses local parameters instead.pull/13585/head
parent
af00b835a1
commit
d13b0e0813
|
@ -120,7 +120,7 @@ struct EnginePreviewWindow : Window {
|
|||
DrawVehicleEngine(r.left, r.right, this->width >> 1, y + this->vehicle_space / 2, engine, GetEnginePalette(engine, _local_company), EIT_PREVIEW);
|
||||
|
||||
y += this->vehicle_space;
|
||||
DrawStringMultiLine(r.left, r.right, y, r.bottom, GetEngineInfoString(engine), TC_FROMSTRING, SA_CENTER);
|
||||
DrawStringMultiLine(r.left, r.right, y, r.bottom, GetEngineInfoString(engine), TC_BLACK, SA_CENTER);
|
||||
}
|
||||
|
||||
void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
|
||||
|
@ -168,99 +168,106 @@ uint GetTotalCapacityOfArticulatedParts(EngineID engine)
|
|||
return cap.GetSum<uint>();
|
||||
}
|
||||
|
||||
static StringID GetTrainEngineInfoString(const Engine *e)
|
||||
/**
|
||||
* Get preview running cost string for an engine.
|
||||
* @param e Engine.
|
||||
* @returns Formatted string of running cost.
|
||||
*/
|
||||
static std::string GetPreviewRunningCostString(const Engine &e)
|
||||
{
|
||||
SetDParam(0, STR_ENGINE_PREVIEW_COST_WEIGHT);
|
||||
SetDParam(1, e->GetCost());
|
||||
SetDParam(2, e->GetDisplayWeight());
|
||||
|
||||
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);
|
||||
SetDParam(10, capacity != 0 ? e->GetDefaultCargoType() : INVALID_CARGO);
|
||||
SetDParam(11, capacity);
|
||||
|
||||
return STR_ENGINE_PREVIEW_TEXT4;
|
||||
return GetString(TimerGameEconomy::UsingWallclockUnits() ? STR_ENGINE_PREVIEW_RUNCOST_PERIOD : STR_ENGINE_PREVIEW_RUNCOST_YEAR, e.GetRunningCost());
|
||||
}
|
||||
|
||||
static StringID GetAircraftEngineInfoString(const Engine *e)
|
||||
static std::string GetTrainEngineInfoString(const Engine &e)
|
||||
{
|
||||
CargoType cargo = e->GetDefaultCargoType();
|
||||
std::stringstream res;
|
||||
|
||||
res << GetString(STR_ENGINE_PREVIEW_COST_WEIGHT, e.GetCost(), e.GetDisplayWeight());
|
||||
res << '\n';
|
||||
|
||||
if (_settings_game.vehicle.train_acceleration_model != AM_ORIGINAL && GetRailTypeInfo(e.u.rail.railtype)->acceleration_type != 2) {
|
||||
res << GetString(STR_ENGINE_PREVIEW_SPEED_POWER_MAX_TE, PackVelocity(e.GetDisplayMaxSpeed(), e.type), e.GetPower(), e.GetDisplayMaxTractiveEffort());
|
||||
res << '\n';
|
||||
} else {
|
||||
res << GetString(STR_ENGINE_PREVIEW_SPEED_POWER, PackVelocity(e.GetDisplayMaxSpeed(), e.type), e.GetPower());
|
||||
res << '\n';
|
||||
}
|
||||
|
||||
res << GetPreviewRunningCostString(e);
|
||||
res << '\n';
|
||||
|
||||
uint capacity = GetTotalCapacityOfArticulatedParts(e.index);
|
||||
res << GetString(STR_ENGINE_PREVIEW_CAPACITY, capacity == 0 ? INVALID_CARGO : e.GetDefaultCargoType(), capacity);
|
||||
|
||||
return res.str();
|
||||
}
|
||||
|
||||
static std::string GetAircraftEngineInfoString(const Engine &e)
|
||||
{
|
||||
std::stringstream res;
|
||||
|
||||
res << GetString(STR_ENGINE_PREVIEW_COST_MAX_SPEED, e.GetCost(), PackVelocity(e.GetDisplayMaxSpeed(), e.type));
|
||||
res << '\n';
|
||||
|
||||
if (uint16_t range = e.GetRange(); range > 0) {
|
||||
res << GetString(STR_ENGINE_PREVIEW_TYPE_RANGE, e.GetAircraftTypeText(), range);
|
||||
res << '\n';
|
||||
} else {
|
||||
res << GetString(STR_ENGINE_PREVIEW_TYPE, e.GetAircraftTypeText());
|
||||
res << '\n';
|
||||
}
|
||||
|
||||
res << GetPreviewRunningCostString(e);
|
||||
res << '\n';
|
||||
|
||||
CargoType cargo = e.GetDefaultCargoType();
|
||||
uint16_t mail_capacity;
|
||||
uint capacity = e->GetDisplayDefaultCapacity(&mail_capacity);
|
||||
uint16_t range = e->GetRange();
|
||||
uint capacity = e.GetDisplayDefaultCapacity(&mail_capacity);
|
||||
if (mail_capacity > 0) {
|
||||
res << GetString(STR_ENGINE_PREVIEW_CAPACITY_2, cargo, capacity, GetCargoTypeByLabel(CT_MAIL), mail_capacity);
|
||||
} else {
|
||||
res << GetString(STR_ENGINE_PREVIEW_CAPACITY, cargo, capacity);
|
||||
}
|
||||
|
||||
SetDParam(0, STR_ENGINE_PREVIEW_COST_MAX_SPEED);
|
||||
SetDParam(1, e->GetCost());
|
||||
SetDParam(2, PackVelocity(e->GetDisplayMaxSpeed(), e->type));
|
||||
|
||||
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, GetCargoTypeByLabel(CT_MAIL));
|
||||
SetDParam(13, mail_capacity);
|
||||
|
||||
return STR_ENGINE_PREVIEW_TEXT4;
|
||||
return res.str();
|
||||
}
|
||||
|
||||
static StringID GetRoadVehEngineInfoString(const Engine *e)
|
||||
static std::string 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);
|
||||
std::stringstream res;
|
||||
|
||||
if (_settings_game.vehicle.roadveh_acceleration_model == AM_ORIGINAL) {
|
||||
SetDParam(0, STR_ENGINE_PREVIEW_COST_MAX_SPEED);
|
||||
SetDParam(1, e->GetCost());
|
||||
SetDParam(2, PackVelocity(e->GetDisplayMaxSpeed(), e->type));
|
||||
|
||||
return STR_ENGINE_PREVIEW_TEXT3;
|
||||
res << GetString(STR_ENGINE_PREVIEW_COST_MAX_SPEED, e.GetCost(), PackVelocity(e.GetDisplayMaxSpeed(), e.type));
|
||||
res << '\n';
|
||||
} else {
|
||||
SetDParam(0, STR_ENGINE_PREVIEW_COST_WEIGHT);
|
||||
SetDParam(1, e->GetCost());
|
||||
SetDParam(2, e->GetDisplayWeight());
|
||||
|
||||
SetDParam(3, STR_ENGINE_PREVIEW_SPEED_POWER_MAX_TE);
|
||||
SetDParam(4, PackVelocity(e->GetDisplayMaxSpeed(), e->type));
|
||||
SetDParam(5, e->GetPower());
|
||||
SetDParam(6, e->GetDisplayMaxTractiveEffort());
|
||||
|
||||
return STR_ENGINE_PREVIEW_TEXT4;
|
||||
res << GetString(STR_ENGINE_PREVIEW_COST_WEIGHT, e.GetCost(), e.GetDisplayWeight());
|
||||
res << '\n';
|
||||
res << GetString(STR_ENGINE_PREVIEW_SPEED_POWER_MAX_TE, PackVelocity(e.GetDisplayMaxSpeed(), e.type), e.GetPower(), e.GetDisplayMaxTractiveEffort());
|
||||
res << '\n';
|
||||
}
|
||||
|
||||
res << GetPreviewRunningCostString(e);
|
||||
res << '\n';
|
||||
|
||||
uint capacity = GetTotalCapacityOfArticulatedParts(e.index);
|
||||
res << GetString(STR_ENGINE_PREVIEW_CAPACITY, capacity == 0 ? INVALID_CARGO : e.GetDefaultCargoType(), capacity);
|
||||
|
||||
return res.str();
|
||||
}
|
||||
|
||||
static StringID GetShipEngineInfoString(const Engine *e)
|
||||
static std::string GetShipEngineInfoString(const Engine &e)
|
||||
{
|
||||
SetDParam(0, STR_ENGINE_PREVIEW_COST_MAX_SPEED);
|
||||
SetDParam(1, e->GetCost());
|
||||
SetDParam(2, PackVelocity(e->GetDisplayMaxSpeed(), e->type));
|
||||
std::stringstream res;
|
||||
|
||||
SetDParam(7, TimerGameEconomy::UsingWallclockUnits() ? STR_ENGINE_PREVIEW_RUNCOST_PERIOD : STR_ENGINE_PREVIEW_RUNCOST_YEAR);
|
||||
SetDParam(8, e->GetRunningCost());
|
||||
res << GetString(STR_ENGINE_PREVIEW_COST_MAX_SPEED, e.GetCost(), PackVelocity(e.GetDisplayMaxSpeed(), e.type));
|
||||
res << '\n';
|
||||
|
||||
SetDParam(9, STR_ENGINE_PREVIEW_CAPACITY);
|
||||
SetDParam(10, e->GetDefaultCargoType());
|
||||
SetDParam(11, e->GetDisplayDefaultCapacity());
|
||||
res << GetPreviewRunningCostString(e);
|
||||
res << '\n';
|
||||
|
||||
return STR_ENGINE_PREVIEW_TEXT3;
|
||||
res << GetString(STR_ENGINE_PREVIEW_CAPACITY, e.GetDefaultCargoType(), e.GetDisplayDefaultCapacity());
|
||||
|
||||
return res.str();
|
||||
}
|
||||
|
||||
|
||||
|
@ -270,11 +277,11 @@ static StringID GetShipEngineInfoString(const Engine *e)
|
|||
* @return String describing the engine.
|
||||
* @post \c DParam array is set up for printing the string.
|
||||
*/
|
||||
StringID GetEngineInfoString(EngineID engine)
|
||||
std::string GetEngineInfoString(EngineID engine)
|
||||
{
|
||||
const Engine *e = Engine::Get(engine);
|
||||
const Engine &e = *Engine::Get(engine);
|
||||
|
||||
switch (e->type) {
|
||||
switch (e.type) {
|
||||
case VEH_TRAIN:
|
||||
return GetTrainEngineInfoString(e);
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ void EngList_Sort(GUIEngineList &el, EngList_SortTypeFunction compare);
|
|||
void EngList_SortPartial(GUIEngineList &el, EngList_SortTypeFunction compare, size_t begin, size_t num_items);
|
||||
|
||||
StringID GetEngineCategoryName(EngineID engine);
|
||||
StringID GetEngineInfoString(EngineID engine);
|
||||
std::string GetEngineInfoString(EngineID engine);
|
||||
|
||||
void DrawVehicleEngine(int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type);
|
||||
void DrawTrainEngine(int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type);
|
||||
|
|
|
@ -4337,8 +4337,6 @@ STR_ENGINE_PREVIEW_TRAM_VEHICLE :tramway vehicle
|
|||
STR_ENGINE_PREVIEW_AIRCRAFT :aircraft
|
||||
STR_ENGINE_PREVIEW_SHIP :ship
|
||||
|
||||
STR_ENGINE_PREVIEW_TEXT3 :{BLACK}{STRING2}{}{5:STRING1}{}{STRING4}
|
||||
STR_ENGINE_PREVIEW_TEXT4 :{BLACK}{STRING2}{}{STRING3}{}{STRING1}{}{STRING4}
|
||||
STR_ENGINE_PREVIEW_COST_WEIGHT :Cost: {CURRENCY_LONG} Weight: {WEIGHT_SHORT}
|
||||
STR_ENGINE_PREVIEW_COST_MAX_SPEED :Cost: {CURRENCY_LONG} Max. Speed: {VELOCITY}
|
||||
STR_ENGINE_PREVIEW_SPEED_POWER :Speed: {VELOCITY} Power: {POWER}
|
||||
|
|
|
@ -430,7 +430,7 @@ struct NewsWindow : Window {
|
|||
|
||||
void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
|
||||
{
|
||||
StringID str = STR_NULL;
|
||||
std::string str;
|
||||
switch (widget) {
|
||||
case WID_N_CAPTION: {
|
||||
/* Caption is not a real caption (so that the window cannot be moved)
|
||||
|
@ -447,16 +447,16 @@ struct NewsWindow : Window {
|
|||
|
||||
case WID_N_MESSAGE:
|
||||
CopyInDParam(this->ni->params);
|
||||
str = this->ni->string_id;
|
||||
str = GetString(this->ni->string_id);
|
||||
break;
|
||||
|
||||
case WID_N_COMPANY_MSG:
|
||||
str = this->GetCompanyMessageString();
|
||||
str = GetString(this->GetCompanyMessageString());
|
||||
break;
|
||||
|
||||
case WID_N_VEH_NAME:
|
||||
case WID_N_VEH_TITLE:
|
||||
str = this->GetNewVehicleMessageString(widget);
|
||||
str = GetString(this->GetNewVehicleMessageString(widget));
|
||||
break;
|
||||
|
||||
case WID_N_VEH_INFO: {
|
||||
|
|
Loading…
Reference in New Issue