mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: use std::span instead of pointer + length
This commit is contained in:
parent
54be756aae
commit
883d3e7a9f
|
@ -367,16 +367,18 @@ class BuildIndustryWindow : public Window {
|
||||||
* @param prefixstr String to use for the first item
|
* @param prefixstr String to use for the first item
|
||||||
* @return A formatted raw string
|
* @return A formatted raw string
|
||||||
*/
|
*/
|
||||||
std::string MakeCargoListString(const CargoID *cargolist, const CargoSuffix *cargo_suffix, int cargolistlen, StringID prefixstr) const
|
std::string MakeCargoListString(const std::span<const CargoID> cargolist, const std::span<const CargoSuffix> cargo_suffix, StringID prefixstr) const
|
||||||
{
|
{
|
||||||
std::string cargostring;
|
assert(cargolist.size() == cargo_suffix.size());
|
||||||
int numcargo = 0;
|
|
||||||
int firstcargo = -1;
|
|
||||||
|
|
||||||
for (int j = 0; j < cargolistlen; j++) {
|
std::string cargostring;
|
||||||
|
size_t numcargo = 0;
|
||||||
|
size_t firstcargo;
|
||||||
|
|
||||||
|
for (size_t j = 0; j < cargolist.size(); j++) {
|
||||||
if (!IsValidCargoID(cargolist[j])) continue;
|
if (!IsValidCargoID(cargolist[j])) continue;
|
||||||
numcargo++;
|
numcargo++;
|
||||||
if (firstcargo < 0) {
|
if (numcargo == 1) {
|
||||||
firstcargo = j;
|
firstcargo = j;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -452,7 +454,7 @@ public:
|
||||||
|
|
||||||
/* Measure the accepted cargoes, if any. */
|
/* Measure the accepted cargoes, if any. */
|
||||||
GetAllCargoSuffixes(CARGOSUFFIX_IN, CST_FUND, nullptr, indtype, indsp, indsp->accepts_cargo, cargo_suffix);
|
GetAllCargoSuffixes(CARGOSUFFIX_IN, CST_FUND, nullptr, indtype, indsp, indsp->accepts_cargo, cargo_suffix);
|
||||||
std::string cargostring = this->MakeCargoListString(indsp->accepts_cargo, cargo_suffix, lengthof(indsp->accepts_cargo), STR_INDUSTRY_VIEW_REQUIRES_N_CARGO);
|
std::string cargostring = this->MakeCargoListString(indsp->accepts_cargo, cargo_suffix, STR_INDUSTRY_VIEW_REQUIRES_N_CARGO);
|
||||||
Dimension strdim = GetStringBoundingBox(cargostring);
|
Dimension strdim = GetStringBoundingBox(cargostring);
|
||||||
if (strdim.width > max_minwidth) {
|
if (strdim.width > max_minwidth) {
|
||||||
extra_lines_req = std::max(extra_lines_req, strdim.width / max_minwidth + 1);
|
extra_lines_req = std::max(extra_lines_req, strdim.width / max_minwidth + 1);
|
||||||
|
@ -462,7 +464,7 @@ public:
|
||||||
|
|
||||||
/* Measure the produced cargoes, if any. */
|
/* Measure the produced cargoes, if any. */
|
||||||
GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_FUND, nullptr, indtype, indsp, indsp->produced_cargo, cargo_suffix);
|
GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_FUND, nullptr, indtype, indsp, indsp->produced_cargo, cargo_suffix);
|
||||||
cargostring = this->MakeCargoListString(indsp->produced_cargo, cargo_suffix, lengthof(indsp->produced_cargo), STR_INDUSTRY_VIEW_PRODUCES_N_CARGO);
|
cargostring = this->MakeCargoListString(indsp->produced_cargo, cargo_suffix, STR_INDUSTRY_VIEW_PRODUCES_N_CARGO);
|
||||||
strdim = GetStringBoundingBox(cargostring);
|
strdim = GetStringBoundingBox(cargostring);
|
||||||
if (strdim.width > max_minwidth) {
|
if (strdim.width > max_minwidth) {
|
||||||
extra_lines_prd = std::max(extra_lines_prd, strdim.width / max_minwidth + 1);
|
extra_lines_prd = std::max(extra_lines_prd, strdim.width / max_minwidth + 1);
|
||||||
|
@ -568,12 +570,12 @@ public:
|
||||||
|
|
||||||
/* Draw the accepted cargoes, if any. Otherwise, will print "Nothing". */
|
/* Draw the accepted cargoes, if any. Otherwise, will print "Nothing". */
|
||||||
GetAllCargoSuffixes(CARGOSUFFIX_IN, CST_FUND, nullptr, this->selected_type, indsp, indsp->accepts_cargo, cargo_suffix);
|
GetAllCargoSuffixes(CARGOSUFFIX_IN, CST_FUND, nullptr, this->selected_type, indsp, indsp->accepts_cargo, cargo_suffix);
|
||||||
std::string cargostring = this->MakeCargoListString(indsp->accepts_cargo, cargo_suffix, lengthof(indsp->accepts_cargo), STR_INDUSTRY_VIEW_REQUIRES_N_CARGO);
|
std::string cargostring = this->MakeCargoListString(indsp->accepts_cargo, cargo_suffix, STR_INDUSTRY_VIEW_REQUIRES_N_CARGO);
|
||||||
ir.top = DrawStringMultiLine(ir, cargostring);
|
ir.top = DrawStringMultiLine(ir, cargostring);
|
||||||
|
|
||||||
/* Draw the produced cargoes, if any. Otherwise, will print "Nothing". */
|
/* Draw the produced cargoes, if any. Otherwise, will print "Nothing". */
|
||||||
GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_FUND, nullptr, this->selected_type, indsp, indsp->produced_cargo, cargo_suffix);
|
GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_FUND, nullptr, this->selected_type, indsp, indsp->produced_cargo, cargo_suffix);
|
||||||
cargostring = this->MakeCargoListString(indsp->produced_cargo, cargo_suffix, lengthof(indsp->produced_cargo), STR_INDUSTRY_VIEW_PRODUCES_N_CARGO);
|
cargostring = this->MakeCargoListString(indsp->produced_cargo, cargo_suffix, STR_INDUSTRY_VIEW_PRODUCES_N_CARGO);
|
||||||
ir.top = DrawStringMultiLine(ir, cargostring);
|
ir.top = DrawStringMultiLine(ir, cargostring);
|
||||||
|
|
||||||
/* Get the additional purchase info text, if it has not already been queried. */
|
/* Get the additional purchase info text, if it has not already been queried. */
|
||||||
|
|
Loading…
Reference in New Issue