Merge branch 'master' into jgrpp

# Conflicts:
#	cmake/CompileFlags.cmake
#	src/cargomonitor.cpp
#	src/core/CMakeLists.txt
#	src/economy.cpp
#	src/landscape.cpp
#	src/linkgraph/flowmapper.cpp
#	src/linkgraph/linkgraph_gui.cpp
#	src/linkgraph/linkgraphschedule.cpp
#	src/misc_gui.cpp
#	src/newgrf_generic.cpp
#	src/newgrf_storage.cpp
#	src/rail_gui.cpp
#	src/saveload/afterload.cpp
#	src/saveload/station_sl.cpp
#	src/script/script_gui.cpp
#	src/station_cmd.cpp
#	src/station_gui.cpp
#	src/string_func.h
#	src/terraform_cmd.cpp
This commit is contained in:
Jonathan G Rennison
2023-06-07 21:28:46 +01:00
129 changed files with 2080 additions and 2061 deletions

View File

@@ -52,8 +52,7 @@
static RailType _cur_railtype; ///< Rail type of the current build-rail toolbar.
static bool _remove_button_clicked; ///< Flag whether 'remove' toggle-button is currently enabled
static DiagDirection _build_depot_direction; ///< Currently selected depot direction
static uint _waypoint_count = 1; ///< Number of waypoint types
static uint _cur_waypoint_type; ///< Currently selected waypoint type
static uint16_t _cur_waypoint_type; ///< Currently selected waypoint type
static bool _convert_signal_button; ///< convert signal button in the signal GUI pressed
static bool _trace_restrict_button; ///< trace restrict button in the signal GUI pressed
static bool _program_signal_button; ///< program signal button in the signal GUI pressed
@@ -688,9 +687,8 @@ struct BuildRailToolbarWindow : Window {
case WID_RAT_BUILD_WAYPOINT:
this->last_user_action = widget;
_waypoint_count = StationClass::Get(STAT_CLASS_WAYP)->GetSpecCount();
if (HandlePlacePushButton(this, WID_RAT_BUILD_WAYPOINT, SPR_CURSOR_WAYPOINT, HT_RECT)) {
if (_waypoint_count > 1) {
if (StationClass::Get(STAT_CLASS_WAYP)->GetSpecCount() > 1) {
ShowBuildWaypointPicker(this);
} else {
_cur_waypoint_type = 0;
@@ -1414,7 +1412,7 @@ public:
StationClass *stclass = StationClass::Get(station_class);
for (uint j = 0; j < stclass->GetSpecCount(); j++) {
const StationSpec *statspec = stclass->GetSpec(j);
SetDParam(0, (statspec != nullptr && statspec->name != 0) ? statspec->name : STR_STATION_CLASS_DFLT);
SetDParam(0, (statspec != nullptr && statspec->name != 0) ? statspec->name : STR_STATION_CLASS_DFLT_STATION);
d = maxdim(d, GetStringBoundingBox(str));
}
}
@@ -1519,7 +1517,7 @@ public:
{
if (widget == WID_BRAS_SHOW_NEWST_TYPE) {
const StationSpec *statspec = StationClass::Get(_railstation.station_class)->GetSpec(_railstation.station_type);
SetDParam(0, (statspec != nullptr && statspec->name != 0) ? statspec->name : STR_STATION_CLASS_DFLT);
SetDParam(0, (statspec != nullptr && statspec->name != 0) ? statspec->name : STR_STATION_CLASS_DFLT_STATION);
}
}
@@ -2410,8 +2408,18 @@ static void ShowBuildTrainDepotPicker(Window *parent)
}
struct BuildRailWaypointWindow : PickerWindowBase {
BuildRailWaypointWindow(WindowDesc *desc, Window *parent) : PickerWindowBase(desc, parent)
using WaypointList = GUIList<uint>;
static const uint FILTER_LENGTH = 20;
const StationClass *waypoints;
WaypointList list;
StringFilter string_filter; ///< Filter for waypoint name
QueryString editbox; ///< Filter editbox
BuildRailWaypointWindow(WindowDesc *desc, Window *parent) : PickerWindowBase(desc, parent), editbox(FILTER_LENGTH * MAX_CHAR_LENGTH, FILTER_LENGTH)
{
this->waypoints = StationClass::Get(STAT_CLASS_WAYP);
this->CreateNestedTree();
NWidgetMatrix *matrix = this->GetWidget<NWidgetMatrix>(WID_BRW_WAYPOINT_MATRIX);
@@ -2419,9 +2427,61 @@ struct BuildRailWaypointWindow : PickerWindowBase {
this->FinishInitNested(TRANSPORT_RAIL);
matrix->SetCount(_waypoint_count);
if (_cur_waypoint_type >= _waypoint_count) _cur_waypoint_type = 0;
matrix->SetClicked(_cur_waypoint_type);
this->querystrings[WID_BRW_FILTER] = &this->editbox;
this->editbox.cancel_button = QueryString::ACTION_CLEAR;
this->list.ForceRebuild();
this->BuildPickerList();
}
bool FilterByText(const StationSpec *statspec)
{
if (this->string_filter.IsEmpty()) return true;
this->string_filter.ResetState();
if (statspec == nullptr) {
this->string_filter.AddLine(GetString(STR_STATION_CLASS_WAYP_WAYPOINT));
} else {
this->string_filter.AddLine(GetString(statspec->name));
if (statspec->grf_prop.grffile != nullptr) {
const GRFConfig *gc = GetGRFConfig(statspec->grf_prop.grffile->grfid);
this->string_filter.AddLine(gc->GetName());
}
}
return this->string_filter.GetState();
}
void BuildPickerList()
{
if (!this->list.NeedRebuild()) return;
this->list.clear();
this->list.reserve(this->waypoints->GetSpecCount());
for (uint i = 0; i < this->waypoints->GetSpecCount(); i++) {
const StationSpec *statspec = this->waypoints->GetSpec(i);
if (!FilterByText(statspec)) continue;
this->list.push_back(i);
}
this->list.RebuildDone();
NWidgetMatrix *matrix = this->GetWidget<NWidgetMatrix>(WID_BRW_WAYPOINT_MATRIX);
matrix->SetCount((int)this->list.size());
matrix->SetClicked(this->UpdateSelection(_cur_waypoint_type));
}
uint UpdateSelection(uint type)
{
auto found = std::find(std::begin(this->list), std::end(this->list), type);
if (found != std::end(this->list)) return found - std::begin(this->list);
/* Selection isn't in the list, default to first */
if (this->list.empty()) {
_cur_waypoint_type = 0;
return -1;
} else {
_cur_waypoint_type = this->list.front();
return 0;
}
}
virtual ~BuildRailWaypointWindow()
@@ -2433,9 +2493,9 @@ struct BuildRailWaypointWindow : PickerWindowBase {
{
switch (widget) {
case WID_BRW_WAYPOINT_MATRIX:
/* Three blobs high and wide. */
/* Two blobs high and three wide. */
size->width += resize->width * 2;
size->height += resize->height * 2;
size->height += resize->height * 1;
/* Resizing in X direction only at blob size, but at pixel level in Y. */
resize->height = 1;
@@ -2448,12 +2508,34 @@ struct BuildRailWaypointWindow : PickerWindowBase {
}
}
void SetStringParameters(int widget) const override
{
if (widget == WID_BRW_NAME) {
if (!this->list.empty() && IsInsideBS(_cur_waypoint_type, 0, this->waypoints->GetSpecCount())) {
const StationSpec *statspec = this->waypoints->GetSpec(_cur_waypoint_type);
if (statspec == nullptr) {
SetDParam(0, STR_STATION_CLASS_WAYP_WAYPOINT);
} else {
SetDParam(0, statspec->name);
}
} else {
SetDParam(0, STR_EMPTY);
}
}
}
void OnPaint() override
{
this->BuildPickerList();
this->DrawWidgets();
}
void DrawWidget(const Rect &r, int widget) const override
{
switch (GB(widget, 0, 16)) {
case WID_BRW_WAYPOINT: {
uint type = GB(widget, 16, 16);
const StationSpec *statspec = StationClass::Get(STAT_CLASS_WAYP)->GetSpec(type);
uint16_t type = this->list.at(GB(widget, 16, 16));
const StationSpec *statspec = this->waypoints->GetSpec(type);
DrawPixelInfo tmp_dpi;
if (FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.Width(), r.Height())) {
@@ -2474,15 +2556,16 @@ struct BuildRailWaypointWindow : PickerWindowBase {
{
switch (GB(widget, 0, 16)) {
case WID_BRW_WAYPOINT: {
uint type = GB(widget, 16, 16);
this->GetWidget<NWidgetMatrix>(WID_BRW_WAYPOINT_MATRIX)->SetClicked(_cur_waypoint_type);
uint16_t sel = GB(widget, 16, 16);
assert(sel < this->list.size());
uint16_t type = this->list.at(sel);
/* Check station availability callback */
const StationSpec *statspec = StationClass::Get(STAT_CLASS_WAYP)->GetSpec(type);
const StationSpec *statspec = this->waypoints->GetSpec(type);
if (!IsStationAvailable(statspec)) return;
_cur_waypoint_type = type;
this->GetWidget<NWidgetMatrix>(WID_BRW_WAYPOINT_MATRIX)->SetClicked(_cur_waypoint_type);
this->GetWidget<NWidgetMatrix>(WID_BRW_WAYPOINT_MATRIX)->SetClicked(sel);
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
this->SetDirty();
break;
@@ -2495,9 +2578,28 @@ struct BuildRailWaypointWindow : PickerWindowBase {
CheckRedrawWaypointCoverage(this, false);
}
void SelectWaypointSpec(int spec_id)
void SelectWaypointSpec(uint16 spec_id)
{
this->OnClick({}, WID_BRW_WAYPOINT | (spec_id << 16), 1);
for (uint i = 0; i < (uint)this->list.size(); i++) {
if (this->list[i] == spec_id) {
this->OnClick({}, WID_BRW_WAYPOINT | (i << 16), 1);
break;
}
}
}
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
if (!gui_scope) return;
this->list.ForceRebuild();
}
void OnEditboxChanged(int wid) override
{
if (wid == WID_BRW_FILTER) {
this->string_filter.SetFilterTerm(this->editbox.text.buf);
this->InvalidateData();
}
}
};
@@ -2508,16 +2610,22 @@ static const NWidgetPart _nested_build_waypoint_widgets[] = {
NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_WAYPOINT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_DEFSIZEBOX, COLOUR_DARK_GREEN),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
NWidget(WWT_EDITBOX, COLOUR_DARK_GREEN, WID_BRW_FILTER), SetPadding(2), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetScrollbar(WID_BRW_SCROLL),
NWidget(NWID_MATRIX, COLOUR_DARK_GREEN, WID_BRW_WAYPOINT_MATRIX), SetPIP(0, 2, 0), SetPadding(3), SetScrollbar(WID_BRW_SCROLL),
NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BRW_WAYPOINT), SetMinimalSize(66, 60), SetDataTip(0x0, STR_WAYPOINT_GRAPHICS_TOOLTIP), SetScrollbar(WID_BRW_SCROLL), EndContainer(),
NWidget(WWT_PANEL, COLOUR_GREY, WID_BRW_WAYPOINT), SetDataTip(0x0, STR_WAYPOINT_GRAPHICS_TOOLTIP), SetScrollbar(WID_BRW_SCROLL), EndContainer(),
EndContainer(),
EndContainer(),
NWidget(NWID_VERTICAL),
NWidget(NWID_VSCROLLBAR, COLOUR_DARK_GREEN, WID_BRW_SCROLL),
NWidget(WWT_RESIZEBOX, COLOUR_DARK_GREEN),
NWidget(NWID_VSCROLLBAR, COLOUR_DARK_GREEN, WID_BRW_SCROLL),
EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
NWidget(WWT_TEXT, COLOUR_DARK_GREEN, WID_BRW_NAME), SetPadding(2), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_JUST_STRING, STR_NULL), SetTextStyle(TC_ORANGE), SetAlignment(SA_CENTER),
EndContainer(),
NWidget(WWT_RESIZEBOX, COLOUR_DARK_GREEN),
EndContainer(),
};
@@ -2749,7 +2857,7 @@ void ShowBuildRailStationPickerAndSelect(StationType station_type, const Station
trigger_widget(WID_RAT_BUILD_WAYPOINT);
BuildRailWaypointWindow *waypoint_window = dynamic_cast<BuildRailWaypointWindow *>(FindWindowById(WC_BUILD_WAYPOINT, TRANSPORT_RAIL));
if (waypoint_window != nullptr) waypoint_window->SelectWaypointSpec(spec_id);
if (waypoint_window != nullptr) waypoint_window->SelectWaypointSpec((uint16)spec_id);
} else {
trigger_widget(WID_RAT_BUILD_STATION);