mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use parameterised GetString() for industry window. (#13685)
parent
b92172e3d2
commit
170002ff7e
|
@ -8,6 +8,7 @@
|
|||
/** @file industry_gui.cpp GUIs related to industries. */
|
||||
|
||||
#include "stdafx.h"
|
||||
#include <ranges>
|
||||
#include "error.h"
|
||||
#include "gui.h"
|
||||
#include "settings_gui.h"
|
||||
|
@ -870,6 +871,18 @@ public:
|
|||
DrawSprite(icon, PAL_NONE, CenterBounds(ir.left, ir.right, d.width), CenterBounds(ir.top, ir.bottom, this->cargo_icon_size.height));
|
||||
}
|
||||
|
||||
std::string GetAcceptedCargoString(const Industry::AcceptedCargo &ac, const CargoSuffix &suffix) const
|
||||
{
|
||||
auto params = MakeParameters(CargoSpec::Get(ac.cargo)->name, ac.cargo, ac.waiting, suffix.text);
|
||||
switch (suffix.display) {
|
||||
case CSD_CARGO_AMOUNT_TEXT: return GetStringWithArgs(STR_INDUSTRY_VIEW_ACCEPT_CARGO_AMOUNT_SUFFIX, params);
|
||||
case CSD_CARGO_TEXT: return GetStringWithArgs(STR_INDUSTRY_VIEW_ACCEPT_CARGO_SUFFIX, params);
|
||||
case CSD_CARGO_AMOUNT: return GetStringWithArgs(STR_INDUSTRY_VIEW_ACCEPT_CARGO_AMOUNT_NOSUFFIX, params);
|
||||
case CSD_CARGO: return GetStringWithArgs(STR_INDUSTRY_VIEW_ACCEPT_CARGO_NOSUFFIX, params);
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the text in the #WID_IV_INFO panel.
|
||||
* @param r Rectangle of the panel.
|
||||
|
@ -908,31 +921,11 @@ public:
|
|||
|
||||
CargoSuffix suffix;
|
||||
GetCargoSuffix(CARGOSUFFIX_IN, CST_VIEW, i, i->type, ind, a.cargo, &a - i->accepted.data(), suffix);
|
||||
/* if the industry is not stockpiling then don't show amount in the acceptance display. */
|
||||
if (!stockpiling && suffix.display == CSD_CARGO_AMOUNT_TEXT) suffix.display = CSD_CARGO_TEXT;
|
||||
if (!stockpiling && suffix.display == CSD_CARGO_AMOUNT) suffix.display = CSD_CARGO;
|
||||
|
||||
SetDParam(0, CargoSpec::Get(a.cargo)->name);
|
||||
SetDParam(1, a.cargo);
|
||||
SetDParam(2, a.waiting);
|
||||
SetDParamStr(3, "");
|
||||
StringID str = STR_NULL;
|
||||
switch (suffix.display) {
|
||||
case CSD_CARGO_AMOUNT_TEXT:
|
||||
SetDParamStr(3, suffix.text);
|
||||
[[fallthrough]];
|
||||
case CSD_CARGO_AMOUNT:
|
||||
str = stockpiling ? STR_INDUSTRY_VIEW_ACCEPT_CARGO_AMOUNT : STR_INDUSTRY_VIEW_ACCEPT_CARGO;
|
||||
break;
|
||||
|
||||
case CSD_CARGO_TEXT:
|
||||
SetDParamStr(3, suffix.text);
|
||||
[[fallthrough]];
|
||||
case CSD_CARGO:
|
||||
str = STR_INDUSTRY_VIEW_ACCEPT_CARGO;
|
||||
break;
|
||||
|
||||
default:
|
||||
NOT_REACHED();
|
||||
}
|
||||
DrawString(ir.Indent(label_indent, rtl), str);
|
||||
DrawString(ir.Indent(label_indent, rtl), this->GetAcceptedCargoString(a, suffix));
|
||||
ir.top += GetCharacterHeight(FS_NORMAL);
|
||||
}
|
||||
|
||||
|
@ -955,11 +948,8 @@ public:
|
|||
CargoSuffix suffix;
|
||||
GetCargoSuffix(CARGOSUFFIX_OUT, CST_VIEW, i, i->type, ind, p.cargo, &p - i->produced.data(), suffix);
|
||||
|
||||
SetDParam(0, p.cargo);
|
||||
SetDParam(1, p.history[LAST_MONTH].production);
|
||||
SetDParamStr(2, suffix.text);
|
||||
SetDParam(3, ToPercent8(p.history[LAST_MONTH].PctTransported()));
|
||||
DrawString(ir.Indent(label_indent + (this->editable == EA_RATE ? SETTING_BUTTON_WIDTH + WidgetDimensions::scaled.hsep_normal : 0), rtl).Translate(0, text_y_offset), STR_INDUSTRY_VIEW_TRANSPORTED);
|
||||
DrawString(ir.Indent(label_indent + (this->editable == EA_RATE ? SETTING_BUTTON_WIDTH + WidgetDimensions::scaled.hsep_normal : 0), rtl).Translate(0, text_y_offset),
|
||||
GetString(STR_INDUSTRY_VIEW_TRANSPORTED, p.cargo, p.history[LAST_MONTH].production, suffix.text, ToPercent8(p.history[LAST_MONTH].PctTransported())));
|
||||
/* Let's put out those buttons.. */
|
||||
if (this->editable == EA_RATE) {
|
||||
DrawArrowButtons(ir.Indent(label_indent, rtl).WithWidth(SETTING_BUTTON_WIDTH, rtl).left, ir.top + button_y_offset, COLOUR_YELLOW, (this->clicked_line == IL_RATE1 + (&p - i->produced.data())) ? this->clicked_button : 0,
|
||||
|
@ -975,8 +965,8 @@ public:
|
|||
button_y_offset = (line_height - SETTING_BUTTON_HEIGHT) / 2;
|
||||
ir.top += WidgetDimensions::scaled.vsep_wide;
|
||||
this->production_offset_y = ir.top;
|
||||
SetDParam(0, RoundDivSU(i->prod_level * 100, PRODLEVEL_DEFAULT));
|
||||
DrawString(ir.Indent(label_indent + SETTING_BUTTON_WIDTH + WidgetDimensions::scaled.hsep_normal, rtl).Translate(0, text_y_offset), STR_INDUSTRY_VIEW_PRODUCTION_LEVEL);
|
||||
DrawString(ir.Indent(label_indent + SETTING_BUTTON_WIDTH + WidgetDimensions::scaled.hsep_normal, rtl).Translate(0, text_y_offset),
|
||||
GetString(STR_INDUSTRY_VIEW_PRODUCTION_LEVEL, RoundDivSU(i->prod_level * 100, PRODLEVEL_DEFAULT)));
|
||||
DrawArrowButtons(ir.Indent(label_indent, rtl).WithWidth(SETTING_BUTTON_WIDTH, rtl).left, ir.top + button_y_offset, COLOUR_YELLOW, (this->clicked_line == IL_MULTIPLIER) ? this->clicked_button : 0,
|
||||
i->prod_level > PRODLEVEL_MINIMUM, i->prod_level < PRODLEVEL_MAXIMUM);
|
||||
ir.top += line_height;
|
||||
|
@ -999,9 +989,8 @@ public:
|
|||
}
|
||||
|
||||
if (!i->text.empty()) {
|
||||
SetDParamStr(0, i->text);
|
||||
ir.top += WidgetDimensions::scaled.vsep_wide;
|
||||
ir.top = DrawStringMultiLine(ir, STR_JUST_RAW_STRING, TC_BLACK);
|
||||
ir.top = DrawStringMultiLine(ir, GetString(STR_JUST_RAW_STRING, i->text), TC_BLACK);
|
||||
}
|
||||
|
||||
/* Return required bottom position, the last pixel row plus some padding. */
|
||||
|
@ -1567,18 +1556,25 @@ protected:
|
|||
return (r == 0) ? IndustryNameSorter(a, b, filter) : r < 0;
|
||||
}
|
||||
|
||||
StringID GetStringForNumCargo(size_t count) const
|
||||
{
|
||||
switch (count) {
|
||||
case 0: return STR_INDUSTRY_DIRECTORY_ITEM_NOPROD;
|
||||
case 1: return STR_INDUSTRY_DIRECTORY_ITEM_PROD1;
|
||||
case 2: return STR_INDUSTRY_DIRECTORY_ITEM_PROD2;
|
||||
case 3: return STR_INDUSTRY_DIRECTORY_ITEM_PROD3;
|
||||
default: return STR_INDUSTRY_DIRECTORY_ITEM_PRODMORE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the StringID to draw and set the appropriate DParams.
|
||||
* @param i the industry to get the StringID of.
|
||||
* @return the StringID.
|
||||
*/
|
||||
StringID GetIndustryString(const Industry *i) const
|
||||
std::string GetIndustryString(const Industry *i) const
|
||||
{
|
||||
const IndustrySpec *indsp = GetIndustrySpec(i->type);
|
||||
uint8_t p = 0;
|
||||
|
||||
/* Industry name */
|
||||
SetDParam(p++, i->index);
|
||||
|
||||
/* Get industry productions (CargoType, production, suffix, transported) */
|
||||
struct CargoInfo {
|
||||
|
@ -1628,27 +1624,26 @@ protected:
|
|||
}
|
||||
}
|
||||
|
||||
/* Display first 3 cargos */
|
||||
for (size_t j = 0; j < std::min<size_t>(3, cargos.size()); j++) {
|
||||
CargoInfo &ci = cargos[j];
|
||||
SetDParam(p++, STR_INDUSTRY_DIRECTORY_ITEM_INFO);
|
||||
SetDParam(p++, ci.cargo_type);
|
||||
SetDParam(p++, ci.production);
|
||||
SetDParamStr(p++, std::move(ci.suffix));
|
||||
SetDParam(p++, ci.transported);
|
||||
static constexpr size_t MAX_DISPLAYED_CARGOES = 3;
|
||||
std::array<StringParameter, 2 + 5 * MAX_DISPLAYED_CARGOES> params{};
|
||||
auto it = params.begin();
|
||||
|
||||
/* Industry name */
|
||||
*it++ = i->index;
|
||||
|
||||
/* Display first MAX_DISPLAYED_CARGOES cargoes */
|
||||
for (CargoInfo &ci : cargos | std::views::take(MAX_DISPLAYED_CARGOES)) {
|
||||
*it++ = STR_INDUSTRY_DIRECTORY_ITEM_INFO;
|
||||
*it++ = ci.cargo_type;
|
||||
*it++ = ci.production;
|
||||
*it++ = std::move(ci.suffix);
|
||||
*it++ = ci.transported;
|
||||
}
|
||||
|
||||
/* Undisplayed cargos if any */
|
||||
SetDParam(p++, cargos.size() - 3);
|
||||
if (std::size(cargos) > MAX_DISPLAYED_CARGOES) *it++ = std::size(cargos) - MAX_DISPLAYED_CARGOES;
|
||||
|
||||
/* Drawing the right string */
|
||||
switch (cargos.size()) {
|
||||
case 0: return STR_INDUSTRY_DIRECTORY_ITEM_NOPROD;
|
||||
case 1: return STR_INDUSTRY_DIRECTORY_ITEM_PROD1;
|
||||
case 2: return STR_INDUSTRY_DIRECTORY_ITEM_PROD2;
|
||||
case 3: return STR_INDUSTRY_DIRECTORY_ITEM_PROD3;
|
||||
default: return STR_INDUSTRY_DIRECTORY_ITEM_PRODMORE;
|
||||
}
|
||||
return GetStringWithArgs(GetStringForNumCargo(std::size(cargos)), {params.begin(), it});
|
||||
}
|
||||
|
||||
public:
|
||||
|
|
|
@ -4039,8 +4039,10 @@ STR_INDUSTRY_VIEW_PRODUCES_N_CARGO :{BLACK}Produces
|
|||
STR_INDUSTRY_VIEW_CARGO_LIST_EXTENSION :, {STRING}{RAW_STRING}
|
||||
|
||||
STR_INDUSTRY_VIEW_REQUIRES :{BLACK}Requires:
|
||||
STR_INDUSTRY_VIEW_ACCEPT_CARGO :{YELLOW}{0:STRING}{BLACK}{3:RAW_STRING}
|
||||
STR_INDUSTRY_VIEW_ACCEPT_CARGO_AMOUNT :{YELLOW}{STRING}{BLACK}: {CARGO_SHORT} waiting{RAW_STRING}
|
||||
STR_INDUSTRY_VIEW_ACCEPT_CARGO_SUFFIX :{YELLOW}{0:STRING}{BLACK}{3:RAW_STRING}
|
||||
STR_INDUSTRY_VIEW_ACCEPT_CARGO_AMOUNT_SUFFIX :{YELLOW}{0:STRING}{BLACK}: {1:CARGO_SHORT} waiting{3:RAW_STRING}
|
||||
STR_INDUSTRY_VIEW_ACCEPT_CARGO_NOSUFFIX :{YELLOW}{0:STRING}
|
||||
STR_INDUSTRY_VIEW_ACCEPT_CARGO_AMOUNT_NOSUFFIX :{YELLOW}{0:STRING}{BLACK}: {1:CARGO_SHORT} waiting
|
||||
|
||||
STR_CONFIG_GAME_PRODUCTION :{WHITE}Change production (multiple of 8, up to 2040)
|
||||
STR_CONFIG_GAME_PRODUCTION_LEVEL :{WHITE}Change production level (percentage, up to 800%)
|
||||
|
|
Loading…
Reference in New Issue