Merge branch 'master' into jgrpp

# Conflicts:
#	src/company_cmd.cpp
#	src/core/overflowsafe_type.hpp
#	src/economy.cpp
#	src/engine_base.h
#	src/ground_vehicle.cpp
#	src/group_gui.cpp
#	src/industry_cmd.cpp
#	src/industry_gui.cpp
#	src/newgrf_commons.cpp
#	src/newgrf_engine.cpp
#	src/newgrf_industries.cpp
#	src/newgrf_object.cpp
#	src/newgrf_roadstop.cpp
#	src/newgrf_station.cpp
#	src/rail_gui.cpp
#	src/road_cmd.h
#	src/road_gui.cpp
#	src/saveload/afterload.cpp
#	src/script/api/script_log.cpp
#	src/script/api/script_log.hpp
#	src/settings_gui.cpp
#	src/settingsgen/settingsgen.cpp
#	src/station_cmd.cpp
#	src/station_cmd.h
#	src/station_gui.cpp
#	src/strgen/strgen.cpp
#	src/string_func.h
#	src/string_type.h
#	src/table/settings/network_private_settings.ini
#	src/tests/math_func.cpp
#	src/textfile_gui.cpp
#	src/timetable_gui.cpp
#	src/town_cmd.cpp
#	src/vehicle.cpp
#	src/waypoint_cmd.cpp
#	src/waypoint_cmd.h
#	src/widgets/dropdown.cpp
This commit is contained in:
Jonathan G Rennison
2023-06-03 19:16:42 +01:00
101 changed files with 987 additions and 964 deletions

View File

@@ -302,25 +302,23 @@ static WindowDesc _build_industry_desc(
/** Build (fund or prospect) a new industry, */
class BuildIndustryWindow : public Window {
int selected_index; ///< index of the element in the matrix
IndustryType selected_type; ///< industry corresponding to the above index
uint16 count; ///< How many industries are loaded
IndustryType index[NUM_INDUSTRYTYPES + 1]; ///< Type of industry, in the order it was loaded
bool enabled[NUM_INDUSTRYTYPES + 1]; ///< availability state, coming from CBID_INDUSTRY_PROBABILITY (if ever)
std::vector<IndustryType> list; ///< List of industries.
bool enabled; ///< Availability state of the selected industry.
Scrollbar *vscroll;
Dimension legend; ///< Dimension of the legend 'blob'.
/** The largest allowed minimum-width of the window, given in line heights */
static const int MAX_MINWIDTH_LINEHEIGHTS = 20;
void UpdateAvailability()
{
this->enabled = this->selected_type != INVALID_INDUSTRYTYPE && (_game_mode == GM_EDITOR || GetIndustryProbabilityCallback(this->selected_type, IACT_USERCREATION, 1) > 0);
}
void SetupArrays()
{
this->count = 0;
for (uint i = 0; i < lengthof(this->index); i++) {
this->index[i] = INVALID_INDUSTRYTYPE;
this->enabled[i] = false;
}
this->list.clear();
/* Fill the arrays with industries.
* The tests performed after the enabled allow to load the industries
@@ -334,32 +332,27 @@ class BuildIndustryWindow : public Window {
* and raw ones are loaded only when setting allows it */
if (_game_mode != GM_EDITOR && indsp->IsRawIndustry() && _settings_game.construction.raw_industry_construction == 0) {
/* Unselect if the industry is no longer in the list */
if (this->selected_type == ind) this->selected_index = -1;
if (this->selected_type == ind) this->selected_type = INVALID_INDUSTRYTYPE;
continue;
}
this->index[this->count] = ind;
this->enabled[this->count] = (_game_mode == GM_EDITOR) || GetIndustryProbabilityCallback(ind, IACT_USERCREATION, 1) > 0;
/* Keep the selection to the correct line */
if (this->selected_type == ind) this->selected_index = this->count;
this->count++;
this->list.push_back(ind);
}
}
/* first industry type is selected if the current selection is invalid.
* I'll be damned if there are none available ;) */
if (this->selected_index == -1) {
this->selected_index = 0;
this->selected_type = this->index[0];
}
/* First industry type is selected if the current selection is invalid. */
if (this->selected_type == INVALID_INDUSTRYTYPE && !this->list.empty()) this->selected_type = this->list[0];
this->vscroll->SetCount(this->count);
this->UpdateAvailability();
this->vscroll->SetCount(this->list.size());
}
/** Update status of the fund and display-chain widgets. */
void SetButtons()
{
this->SetWidgetDisabledState(WID_DPI_FUND_WIDGET, this->selected_type != INVALID_INDUSTRYTYPE && !this->enabled[this->selected_index]);
this->SetWidgetDisabledState(WID_DPI_DISPLAY_WIDGET, this->selected_type == INVALID_INDUSTRYTYPE && this->enabled[this->selected_index]);
this->SetWidgetDisabledState(WID_DPI_FUND_WIDGET, this->selected_type != INVALID_INDUSTRYTYPE && !this->enabled);
this->SetWidgetDisabledState(WID_DPI_DISPLAY_WIDGET, this->selected_type == INVALID_INDUSTRYTYPE && this->enabled);
}
/**
@@ -412,7 +405,6 @@ class BuildIndustryWindow : public Window {
public:
BuildIndustryWindow() : Window(&_build_industry_desc)
{
this->selected_index = -1;
this->selected_type = INVALID_INDUSTRYTYPE;
this->CreateNestedTree();
@@ -443,9 +435,8 @@ public:
switch (widget) {
case WID_DPI_MATRIX_WIDGET: {
Dimension d = GetStringBoundingBox(STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES);
for (uint16 i = 0; i < this->count; i++) {
if (this->index[i] == INVALID_INDUSTRYTYPE) continue;
d = maxdim(d, GetStringBoundingBox(GetIndustrySpec(this->index[i])->name));
for (const auto &indtype : this->list) {
d = maxdim(d, GetStringBoundingBox(GetIndustrySpec(indtype)->name));
}
resize->height = std::max<uint>(this->legend.height, FONT_HEIGHT_NORMAL) + padding.height;
d.width += this->legend.width + WidgetDimensions::scaled.hsep_wide + padding.width;
@@ -462,14 +453,12 @@ public:
uint extra_lines_newgrf = 0;
uint max_minwidth = FONT_HEIGHT_NORMAL * MAX_MINWIDTH_LINEHEIGHTS;
Dimension d = {0, 0};
for (uint16 i = 0; i < this->count; i++) {
if (this->index[i] == INVALID_INDUSTRYTYPE) continue;
const IndustrySpec *indsp = GetIndustrySpec(this->index[i]);
for (const auto &indtype : this->list) {
const IndustrySpec *indsp = GetIndustrySpec(indtype);
CargoSuffix cargo_suffix[lengthof(indsp->accepts_cargo)];
/* Measure the accepted cargoes, if any. */
GetAllCargoSuffixes(CARGOSUFFIX_IN, CST_FUND, nullptr, this->index[i], 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);
Dimension strdim = GetStringBoundingBox(cargostring.c_str());
if (strdim.width > max_minwidth) {
@@ -479,7 +468,7 @@ public:
d = maxdim(d, strdim);
/* Measure the produced cargoes, if any. */
GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_FUND, nullptr, this->index[i], 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);
strdim = GetStringBoundingBox(cargostring.c_str());
if (strdim.width > max_minwidth) {
@@ -523,8 +512,8 @@ public:
/* We've chosen many random industries but no industries have been specified */
SetDParam(0, STR_FUND_INDUSTRY_BUILD_NEW_INDUSTRY);
} else {
if (count > 0) {
const IndustrySpec *indsp = GetIndustrySpec(this->index[this->selected_index]);
if (this->selected_type != INVALID_INDUSTRYTYPE) {
const IndustrySpec *indsp = GetIndustrySpec(this->selected_type);
SetDParam(0, (_settings_game.construction.raw_industry_construction == 2 && indsp->IsRawIndustry()) ? STR_FUND_INDUSTRY_PROSPECT_NEW_INDUSTRY : STR_FUND_INDUSTRY_FUND_NEW_INDUSTRY);
} else {
SetDParam(0, STR_FUND_INDUSTRY_FUND_NEW_INDUSTRY);
@@ -547,19 +536,15 @@ public:
icon.top = r.top + (this->resize.step_height - this->legend.height + 1) / 2;
icon.bottom = icon.top + this->legend.height - 1;
for (uint16 i = 0; i < this->vscroll->GetCapacity() && i + this->vscroll->GetPosition() < this->count; i++) {
bool selected = this->selected_index == i + this->vscroll->GetPosition();
for (uint16 i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < this->vscroll->GetCount(); i++) {
bool selected = this->selected_type == this->list[i];
if (this->index[i + this->vscroll->GetPosition()] == INVALID_INDUSTRYTYPE) {
DrawString(text, STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES, selected ? TC_WHITE : TC_ORANGE);
} else {
const IndustrySpec *indsp = GetIndustrySpec(this->index[i + this->vscroll->GetPosition()]);
const IndustrySpec *indsp = GetIndustrySpec(this->list[i]);
/* Draw the name of the industry in white is selected, otherwise, in orange */
DrawString(text, indsp->name, selected ? TC_WHITE : TC_ORANGE);
GfxFillRect(icon, selected ? PC_WHITE : PC_BLACK);
GfxFillRect(icon.Shrink(WidgetDimensions::scaled.bevel), indsp->map_colour);
}
/* Draw the name of the industry in white is selected, otherwise, in orange */
DrawString(text, indsp->name, selected ? TC_WHITE : TC_ORANGE);
GfxFillRect(icon, selected ? PC_WHITE : PC_BLACK);
GfxFillRect(icon.Shrink(WidgetDimensions::scaled.bevel), indsp->map_colour);
text = text.Translate(0, this->resize.step_height);
icon = icon.Translate(0, this->resize.step_height);
@@ -666,24 +651,23 @@ public:
case WID_DPI_MATRIX_WIDGET: {
int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_DPI_MATRIX_WIDGET);
if (y < this->count) { // Is it within the boundaries of available data?
this->selected_index = y;
this->selected_type = this->index[y];
const IndustrySpec *indsp = (this->selected_type == INVALID_INDUSTRYTYPE) ? nullptr : GetIndustrySpec(this->selected_type);
if (y != INT_MAX) { // Is it within the boundaries of available data?
this->selected_type = this->list[y];
this->UpdateAvailability();
const IndustrySpec *indsp = GetIndustrySpec(this->selected_type);
this->SetDirty();
if (_thd.GetCallbackWnd() == this &&
((_game_mode != GM_EDITOR && _settings_game.construction.raw_industry_construction == 2 && indsp != nullptr && indsp->IsRawIndustry()) ||
this->selected_type == INVALID_INDUSTRYTYPE ||
!this->enabled[this->selected_index])) {
((_game_mode != GM_EDITOR && _settings_game.construction.raw_industry_construction == 2 && indsp != nullptr && indsp->IsRawIndustry()) || !this->enabled)) {
/* Reset the button state if going to prospecting or "build many industries" */
this->RaiseButtons();
ResetObjectToPlace();
}
this->SetButtons();
if (this->enabled[this->selected_index] && click_count > 1) this->OnClick(pt, WID_DPI_FUND_WIDGET, 1);
if (this->enabled && click_count > 1) this->OnClick(pt, WID_DPI_FUND_WIDGET, 1);
}
break;
}
@@ -749,18 +733,13 @@ public:
void OnHundredthTick() override
{
if (_game_mode == GM_EDITOR) return;
if (this->count == 0) return;
const IndustrySpec *indsp = GetIndustrySpec(this->selected_type);
if (this->selected_type == INVALID_INDUSTRYTYPE) return;
if (indsp->enabled) {
bool call_back_result = GetIndustryProbabilityCallback(this->selected_type, IACT_USERCREATION, 1) > 0;
/* Only if result does match the previous state would it require a redraw. */
if (call_back_result != this->enabled[this->selected_index]) {
this->enabled[this->selected_index] = call_back_result;
this->SetButtons();
this->SetDirty();
}
bool enabled = this->enabled;
this->UpdateAvailability();
if (enabled != this->enabled) {
this->SetButtons();
this->SetDirty();
}
}
@@ -783,9 +762,6 @@ public:
{
if (!gui_scope) return;
this->SetupArrays();
const IndustrySpec *indsp = (this->selected_type == INVALID_INDUSTRYTYPE) ? nullptr : GetIndustrySpec(this->selected_type);
if (indsp == nullptr) this->enabled[this->selected_index] = _settings_game.difficulty.industry_density != ID_FUND_ONLY;
this->SetButtons();
this->SetDirty();
}
@@ -1059,10 +1035,10 @@ public:
case EA_MULTIPLIER:
if (decrease) {
if (i->prod_level <= PRODLEVEL_MINIMUM) return;
i->prod_level = std::max<uint>(i->prod_level / 2, PRODLEVEL_MINIMUM);
i->prod_level = static_cast<byte>(std::max<uint>(i->prod_level / 2, PRODLEVEL_MINIMUM));
} else {
if (i->prod_level >= PRODLEVEL_MAXIMUM) return;
i->prod_level = std::min<uint>(i->prod_level * 2, PRODLEVEL_MAXIMUM);
i->prod_level = static_cast<byte>(std::min<uint>(i->prod_level * 2, PRODLEVEL_MAXIMUM));
}
break;
@@ -1074,7 +1050,7 @@ public:
if (i->production_rate[line - IL_RATE1] >= 255) return;
/* a zero production industry is unlikely to give anything but zero, so push it a little bit */
int new_prod = i->production_rate[line - IL_RATE1] == 0 ? 1 : i->production_rate[line - IL_RATE1] * 2;
i->production_rate[line - IL_RATE1] = std::min<uint>(new_prod, 255);
i->production_rate[line - IL_RATE1] = ClampTo<byte>(new_prod);
}
break;
@@ -1465,7 +1441,7 @@ protected:
IndustryDirectoryWindow::produced_cargo_filter = this->cargo_filter[this->produced_cargo_filter_criteria];
this->industries.Sort();
this->vscroll->SetCount((uint)this->industries.size()); // Update scrollbar as well.
this->vscroll->SetCount(this->industries.size()); // Update scrollbar as well.
this->SetDirty();
}
@@ -1920,7 +1896,7 @@ static const NWidgetPart _nested_industry_cargoes_widgets[] = {
EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidget(NWID_VERTICAL),
NWidget(WWT_PANEL, COLOUR_BROWN, WID_IC_PANEL), SetResize(1, 10), SetMinimalSize(200, 90), SetScrollbar(WID_IC_SCROLLBAR), EndContainer(),
NWidget(WWT_PANEL, COLOUR_BROWN, WID_IC_PANEL), SetResize(1, 10), SetScrollbar(WID_IC_SCROLLBAR), EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidget(NWID_BUTTON_DROPDOWN, COLOUR_BROWN, WID_IC_NOTIFY),
SetDataTip(STR_INDUSTRY_CARGOES_NOTIFY_SMALLMAP, STR_INDUSTRY_CARGOES_NOTIFY_SMALLMAP_TOOLTIP),
@@ -2983,19 +2959,19 @@ struct IndustryCargoesWindow : public Window {
{
if (widget != WID_IC_PANEL) return;
Rect ir = r.Shrink(WidgetDimensions::scaled.framerect);
Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
DrawPixelInfo tmp_dpi;
if (!FillDrawPixelInfo(&tmp_dpi, ir.left, ir.top, ir.Width(), ir.Height())) return;
AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
int left_pos = ir.left;
int left_pos = WidgetDimensions::scaled.frametext.left - WidgetDimensions::scaled.bevel.left;
if (this->ind_cargo >= NUM_INDUSTRYTYPES) left_pos += (CargoesField::industry_width + CargoesField::cargo_field_width) / 2;
int last_column = (this->ind_cargo < NUM_INDUSTRYTYPES) ? 4 : 2;
const NWidgetBase *nwp = this->GetWidget<NWidgetBase>(WID_IC_PANEL);
int vpos = -this->vscroll->GetPosition() * nwp->resize_y;
for (uint i = 0; i < this->fields.size(); i++) {
int row_height = (i == 0) ? CargoesField::small_height : CargoesField::normal_height;
int vpos = WidgetDimensions::scaled.frametext.top - WidgetDimensions::scaled.bevel.top - this->vscroll->GetPosition() * nwp->resize_y;
int row_height = CargoesField::small_height;
for (const auto &field : this->fields) {
if (vpos + row_height >= 0) {
int xpos = left_pos;
int col, dir;
@@ -3007,13 +2983,14 @@ struct IndustryCargoesWindow : public Window {
dir = 1;
}
while (col >= 0 && col <= last_column) {
this->fields[i].columns[col].Draw(xpos, vpos);
field.columns[col].Draw(xpos, vpos);
xpos += (col & 1) ? CargoesField::cargo_field_width : CargoesField::industry_width;
col += dir;
}
}
vpos += row_height;
if (vpos >= height) break;
row_height = CargoesField::normal_height;
}
}