Merge branch 'master' into jgrpp
# Conflicts: # src/autoreplace_gui.cpp # src/build_vehicle_gui.cpp # src/cheat_gui.cpp # src/company_gui.cpp # src/debug.cpp # src/engine_gui.h # src/error_gui.cpp # src/group_gui.cpp # src/industry_cmd.cpp # src/industry_gui.cpp # src/misc_gui.cpp # src/network/network_gui.cpp # src/newgrf.cpp # src/newgrf_debug_gui.cpp # src/newgrf_gui.cpp # src/order_gui.cpp # src/rail_gui.cpp # src/road_gui.cpp # src/saveload/saveload.cpp # src/screenshot_gui.cpp # src/sound/win32_s.cpp # src/statusbar_gui.cpp # src/strgen/strgen.cpp # src/table/newgrf_debug_data.h # src/timetable_gui.cpp # src/toolbar_gui.cpp # src/town_gui.cpp # src/vehicle_gui.cpp # src/video/sdl2_v.cpp # src/video/sdl_v.cpp # src/viewport.cpp
This commit is contained in:
@@ -361,36 +361,34 @@ class BuildIndustryWindow : public Window {
|
||||
* @param prefixstr String to use for the first item
|
||||
* @return A formatted raw string
|
||||
*/
|
||||
std::string MakeCargoListString(const CargoID *cargolist, const CargoSuffix *cargo_suffix, size_t 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;
|
||||
size_t firstcargo = cargolistlen;
|
||||
assert(cargolist.size() == cargo_suffix.size());
|
||||
|
||||
size_t j = 0;
|
||||
for (; j < cargolistlen; j++) {
|
||||
if (cargolist[j] == INVALID_CARGO) continue;
|
||||
if (firstcargo == cargolistlen) {
|
||||
std::string cargostring;
|
||||
size_t numcargo = 0;
|
||||
size_t firstcargo;
|
||||
|
||||
for (size_t j = 0; j < cargolist.size(); j++) {
|
||||
if (!IsValidCargoID(cargolist[j])) continue;
|
||||
numcargo++;
|
||||
if (numcargo == 1) {
|
||||
firstcargo = j;
|
||||
j++;
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
SetDParam(0, CargoSpec::Get(cargolist[j])->name);
|
||||
SetDParamStr(1, cargo_suffix[j].text);
|
||||
cargostring += GetString(STR_INDUSTRY_VIEW_CARGO_LIST_EXTENSION);
|
||||
}
|
||||
|
||||
if (firstcargo < cargolistlen) {
|
||||
if (numcargo > 0) {
|
||||
SetDParam(0, CargoSpec::Get(cargolist[firstcargo])->name);
|
||||
SetDParamStr(1, cargo_suffix[firstcargo].text);
|
||||
GetString(StringBuilder(cargostring), prefixstr);
|
||||
cargostring = GetString(prefixstr) + cargostring;
|
||||
} else {
|
||||
SetDParam(0, STR_JUST_NOTHING);
|
||||
SetDParamStr(1, "");
|
||||
GetString(StringBuilder(cargostring), prefixstr);
|
||||
}
|
||||
|
||||
for (; j < cargolistlen; j++) {
|
||||
if (cargolist[j] == INVALID_CARGO) continue;
|
||||
SetDParam(0, CargoSpec::Get(cargolist[j])->name);
|
||||
SetDParamStr(1, cargo_suffix[j].text);
|
||||
GetString(StringBuilder(cargostring), STR_INDUSTRY_VIEW_CARGO_LIST_EXTENSION);
|
||||
cargostring = GetString(prefixstr);
|
||||
}
|
||||
|
||||
return cargostring;
|
||||
@@ -421,7 +419,7 @@ public:
|
||||
this->SetupArrays();
|
||||
}
|
||||
|
||||
void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] 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_DPI_MATRIX_WIDGET: {
|
||||
@@ -429,10 +427,10 @@ public:
|
||||
for (const auto &indtype : this->list) {
|
||||
d = maxdim(d, GetStringBoundingBox(GetIndustrySpec(indtype)->name));
|
||||
}
|
||||
resize->height = std::max<uint>(this->legend.height, GetCharacterHeight(FS_NORMAL)) + padding.height;
|
||||
resize.height = std::max<uint>(this->legend.height, GetCharacterHeight(FS_NORMAL)) + padding.height;
|
||||
d.width += this->legend.width + WidgetDimensions::scaled.hsep_wide + padding.width;
|
||||
d.height = 5 * resize->height;
|
||||
*size = maxdim(*size, d);
|
||||
d.height = 5 * resize.height;
|
||||
size = maxdim(size, d);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -450,7 +448,7 @@ public:
|
||||
|
||||
/* Measure the accepted cargoes, if any. */
|
||||
GetAllCargoSuffixes(CARGOSUFFIX_IN, CST_FUND, nullptr, indtype, indsp, indsp->accepts_cargo, cargo_suffix);
|
||||
std::string cargostring = this->MakeCargoListString(indsp->accepts_cargo.data(), cargo_suffix.data(), indsp->accepts_cargo.size(), 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);
|
||||
if (strdim.width > max_minwidth) {
|
||||
extra_lines_req = std::max(extra_lines_req, strdim.width / max_minwidth + 1);
|
||||
@@ -460,7 +458,7 @@ public:
|
||||
|
||||
/* Measure the produced cargoes, if any. */
|
||||
GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_FUND, nullptr, indtype, indsp, indsp->produced_cargo, cargo_suffix);
|
||||
cargostring = this->MakeCargoListString(indsp->produced_cargo.data(), cargo_suffix.data(), indsp->produced_cargo.size(), STR_INDUSTRY_VIEW_PRODUCES_N_CARGO);
|
||||
cargostring = this->MakeCargoListString(indsp->produced_cargo, cargo_suffix, STR_INDUSTRY_VIEW_PRODUCES_N_CARGO);
|
||||
strdim = GetStringBoundingBox(cargostring);
|
||||
if (strdim.width > max_minwidth) {
|
||||
extra_lines_prd = std::max(extra_lines_prd, strdim.width / max_minwidth + 1);
|
||||
@@ -476,8 +474,8 @@ public:
|
||||
|
||||
/* Set it to something more sane :) */
|
||||
height += extra_lines_prd + extra_lines_req + extra_lines_newgrf;
|
||||
size->height = height * GetCharacterHeight(FS_NORMAL) + padding.height;
|
||||
size->width = d.width + padding.width;
|
||||
size.height = height * GetCharacterHeight(FS_NORMAL) + padding.height;
|
||||
size.width = d.width + padding.width;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -487,7 +485,7 @@ public:
|
||||
d = maxdim(d, GetStringBoundingBox(STR_FUND_INDUSTRY_FUND_NEW_INDUSTRY));
|
||||
d.width += padding.width;
|
||||
d.height += padding.height;
|
||||
*size = maxdim(*size, d);
|
||||
size = maxdim(size, d);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -566,12 +564,12 @@ public:
|
||||
|
||||
/* 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);
|
||||
std::string cargostring = this->MakeCargoListString(indsp->accepts_cargo.data(), cargo_suffix.data(), indsp->accepts_cargo.size(), 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);
|
||||
|
||||
/* 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);
|
||||
cargostring = this->MakeCargoListString(indsp->produced_cargo.data(), cargo_suffix.data(), indsp->produced_cargo.size(), 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);
|
||||
|
||||
/* Get the additional purchase info text, if it has not already been queried. */
|
||||
@@ -1038,9 +1036,9 @@ public:
|
||||
if (widget == WID_IV_CAPTION) SetDParam(0, this->window_number);
|
||||
}
|
||||
|
||||
void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] 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_IV_INFO) size->height = this->info_height;
|
||||
if (widget == WID_IV_INFO) size.height = this->info_height;
|
||||
}
|
||||
|
||||
void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
|
||||
@@ -1755,14 +1753,14 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] 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_ID_DROPDOWN_ORDER: {
|
||||
Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
|
||||
d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
|
||||
d.height += padding.height;
|
||||
*size = maxdim(*size, d);
|
||||
size = maxdim(size, d);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1773,17 +1771,17 @@ public:
|
||||
}
|
||||
d.width += padding.width;
|
||||
d.height += padding.height;
|
||||
*size = maxdim(*size, d);
|
||||
size = maxdim(size, d);
|
||||
break;
|
||||
}
|
||||
|
||||
case WID_ID_INDUSTRY_LIST: {
|
||||
Dimension d = GetStringBoundingBox(STR_INDUSTRY_DIRECTORY_NONE);
|
||||
resize->height = d.height;
|
||||
resize.height = d.height;
|
||||
d.height *= 5;
|
||||
d.width += padding.width;
|
||||
d.height += padding.height;
|
||||
*size = maxdim(*size, d);
|
||||
size = maxdim(size, d);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -2670,21 +2668,21 @@ struct IndustryCargoesWindow : public Window {
|
||||
CargoesField::cargo_field_width = CargoesField::cargo_border.width * 2 + CargoesField::cargo_line.width * CargoesField::max_cargoes + CargoesField::cargo_space.width * (CargoesField::max_cargoes - 1);
|
||||
}
|
||||
|
||||
void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] 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_IC_PANEL:
|
||||
resize->height = CargoesField::normal_height;
|
||||
size->width = CargoesField::industry_width * 3 + CargoesField::cargo_field_width * 2 + WidgetDimensions::scaled.frametext.Horizontal();
|
||||
size->height = CargoesField::small_height + 2 * resize->height + WidgetDimensions::scaled.frametext.Vertical();
|
||||
resize.height = CargoesField::normal_height;
|
||||
size.width = CargoesField::industry_width * 3 + CargoesField::cargo_field_width * 2 + WidgetDimensions::scaled.frametext.Horizontal();
|
||||
size.height = CargoesField::small_height + 2 * resize.height + WidgetDimensions::scaled.frametext.Vertical();
|
||||
break;
|
||||
|
||||
case WID_IC_IND_DROPDOWN:
|
||||
size->width = std::max(size->width, this->ind_textsize.width + padding.width);
|
||||
size.width = std::max(size.width, this->ind_textsize.width + padding.width);
|
||||
break;
|
||||
|
||||
case WID_IC_CARGO_DROPDOWN:
|
||||
size->width = std::max(size->width, this->cargo_textsize.width + padding.width);
|
||||
size.width = std::max(size.width, this->cargo_textsize.width + padding.width);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user