Skip to content

Commit d2169c5

Browse files
committed
Change: Selecting rail/roadtype updates build toolbar
1 parent d81eefc commit d2169c5

7 files changed

Lines changed: 68 additions & 9 deletions

File tree

src/engine.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "articulated_vehicles.h"
3131
#include "error.h"
3232
#include "engine_base.h"
33+
#include "road_gui.h"
3334
#include "timer/timer.h"
3435
#include "timer/timer_game_tick.h"
3536
#include "timer/timer_game_calendar.h"
@@ -872,7 +873,7 @@ static void EnableEngineForCompany(EngineID eid, CompanyID company)
872873

873874
/* Update the toolbar. */
874875
InvalidateWindowData(WindowClass::MainToolbar, 0);
875-
if (e->type == VehicleType::Road) InvalidateWindowData(WindowClass::BuildToolbar, TRANSPORT_ROAD);
876+
if (e->type == VehicleType::Road) InvalidateWindowData(WindowClass::BuildToolbar, TRANSPORT_ROAD, GetToolbarRoadType());
876877
if (e->type == VehicleType::Ship) InvalidateWindowData(WindowClass::BuildToolbar, TRANSPORT_WATER);
877878
if (e->type == VehicleType::Aircraft) InvalidateWindowData(WindowClass::BuildToolbar, TRANSPORT_AIR);
878879
}
@@ -1155,7 +1156,7 @@ static void NewVehicleAvailable(Engine *e)
11551156
}
11561157

11571158
/* Update the toolbar. */
1158-
if (e->type == VehicleType::Road) InvalidateWindowData(WindowClass::BuildToolbar, TRANSPORT_ROAD);
1159+
if (e->type == VehicleType::Road) InvalidateWindowData(WindowClass::BuildToolbar, TRANSPORT_ROAD, GetToolbarRoadType());
11591160
if (e->type == VehicleType::Ship) InvalidateWindowData(WindowClass::BuildToolbar, TRANSPORT_WATER);
11601161
if (e->type == VehicleType::Aircraft) InvalidateWindowData(WindowClass::BuildToolbar, TRANSPORT_AIR);
11611162

src/rail_gui.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ static bool IsStationAvailable(const StationSpec *statspec)
9696
return Convert8bitBooleanCallback(statspec->grf_prop.grffile, CBID_STATION_AVAILABILITY, cb_res);
9797
}
9898

99+
/**
100+
* Get the current railtype.
101+
* @return the current railtype.
102+
*/
103+
RailType GetToolbarRailType()
104+
{
105+
return _cur_railtype;
106+
}
107+
99108
void CcPlaySound_CONSTRUCTION_RAIL(Commands, const CommandCost &result, TileIndex tile)
100109
{
101110
if (result.Succeeded() && _settings_client.sound.confirm) SndPlayTileFx(SND_20_CONSTRUCTION_RAIL, tile);
@@ -450,7 +459,7 @@ struct BuildRailToolbarWindow : Window {
450459
this->CreateNestedTree();
451460
this->FinishInitNested(TRANSPORT_RAIL);
452461
this->DisableWidget(WID_RAT_REMOVE);
453-
this->OnInvalidateData();
462+
this->OnInvalidateData(railtype);
454463

455464
if (_settings_client.gui.link_terraform_toolbar) ShowTerraformToolbar(this);
456465
}
@@ -475,7 +484,15 @@ struct BuildRailToolbarWindow : Window {
475484
{
476485
if (!gui_scope) return;
477486

478-
if (!ValParamRailType(this->railtype)) {
487+
if (ValParamRailType(static_cast<RailType>(data))) {
488+
_last_built_railtype = _cur_railtype = static_cast<RailType>(data);
489+
this->ModifyRailType(_last_built_railtype);
490+
491+
/* Update cursor and all sub windows. */
492+
if (_thd.GetCallbackWnd() == this) SetCursor(this->GetCursorForWidget(this->last_user_action), PAL_NONE);
493+
for (WindowClass cls : {WindowClass::BuildStation, WindowClass::BuildSignal, WindowClass::BuildWaypoint, WindowClass::BuildDepot}) SetWindowDirty(cls, TRANSPORT_RAIL);
494+
495+
} else {
479496
/* Close toolbar if rail type is not available. */
480497
this->Close();
481498
return;
@@ -964,6 +981,12 @@ Window *ShowBuildRailToolbar(RailType railtype)
964981
{
965982
if (!Company::IsValidID(_local_company)) return nullptr;
966983
if (!ValParamRailType(railtype)) return nullptr;
984+
Window *w = FindWindowById(WindowClass::BuildToolbar, TRANSPORT_RAIL);
985+
986+
if (w != nullptr) {
987+
w->OnInvalidateData(railtype);
988+
return w;
989+
}
967990

968991
CloseWindowByClass(WindowClass::BuildToolbar);
969992
_cur_railtype = railtype;

src/rail_gui.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ void ReinitGuiAfterToggleElrail(bool disable);
1818
void ResetSignalVariant(int32_t = 0);
1919
void InitializeSignalGui();
2020
DropDownList GetRailTypeDropDownList(bool for_replacement = false, bool all_option = false);
21+
RailType GetToolbarRailType();
2122
void SetDefaultRailGui();
2223

2324
/** Settings for which signals are shown by the signal GUI. */

src/road_gui.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,15 @@ static bool IsRoadStopAvailable(const RoadStopSpec *spec, StationType type)
115115
return Convert8bitBooleanCallback(spec->grf_prop.grffile, CBID_STATION_AVAILABILITY, cb_res);
116116
}
117117

118+
/**
119+
* Get the current roadtype.
120+
* @return the current roadtype.
121+
*/
122+
RoadType GetToolbarRoadType()
123+
{
124+
return _cur_roadtype;
125+
}
126+
118127
void CcPlaySound_CONSTRUCTION_OTHER(Commands, const CommandCost &result, TileIndex tile)
119128
{
120129
if (result.Succeeded() && _settings_client.sound.confirm) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER, tile);
@@ -360,7 +369,7 @@ struct BuildRoadToolbarWindow : Window {
360369
this->SetWidgetDisabledState(WID_ROT_ONE_WAY, true);
361370
}
362371

363-
this->OnInvalidateData();
372+
this->OnInvalidateData(roadtype);
364373

365374
if (_settings_client.gui.link_terraform_toolbar) ShowTerraformToolbar(this);
366375
}
@@ -381,7 +390,18 @@ struct BuildRoadToolbarWindow : Window {
381390
{
382391
if (!gui_scope) return;
383392

384-
if (!ValParamRoadType(this->roadtype)) {
393+
if (ValParamRoadType(static_cast<RoadType>(data))) {
394+
if (RoadTypeIsRoad(static_cast<RoadType>(data))) {
395+
_last_built_roadtype = _cur_roadtype = static_cast<RoadType>(data);
396+
} else {
397+
_last_built_tramtype = _cur_roadtype = static_cast<RoadType>(data);
398+
}
399+
this->ModifyRoadType(_cur_roadtype);
400+
401+
if (_thd.GetCallbackWnd() == this) SetCursor(this->GetCursorForWidget(this->last_started_action), PAL_NONE);
402+
for (WindowClass cls : {WindowClass::BuildBusStation, WindowClass::BuildTruckStation, WindowClass::BuildWaypoint, WindowClass::BuildDepot}) SetWindowDirty(cls, TRANSPORT_ROAD);
403+
404+
} else {
385405
/* Close toolbar if road type is not available. */
386406
this->Close();
387407
return;
@@ -1061,6 +1081,12 @@ Window *ShowBuildRoadToolbar(RoadType roadtype)
10611081
{
10621082
if (!Company::IsValidID(_local_company)) return nullptr;
10631083
if (!ValParamRoadType(roadtype)) return nullptr;
1084+
Window *w = FindWindowById(WindowClass::BuildToolbar, TRANSPORT_ROAD);
1085+
1086+
if (w != nullptr && GetRoadTramType(roadtype) == GetRoadTramType(_cur_roadtype)) {
1087+
w->OnInvalidateData(roadtype);
1088+
return w;
1089+
}
10641090

10651091
CloseWindowByClass(WindowClass::BuildToolbar);
10661092
_cur_roadtype = roadtype;

src/road_gui.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ void ConnectRoadToStructure(TileIndex tile, DiagDirection direction);
2222
DropDownList GetRoadTypeDropDownList(RoadTramTypes rtts, bool for_replacement = false, bool all_option = false);
2323
DropDownList GetScenRoadTypeDropDownList(RoadTramTypes rtts);
2424
void SetDefaultRoadGui();
25+
RoadType GetToolbarRoadType();
2526

2627
#endif /* ROAD_GUI_H */

src/saveload/afterload.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include "../newgrf_station.h"
5454
#include "../engine_func.h"
5555
#include "../rail_gui.h"
56+
#include "../road_gui.h"
5657
#include "../core/backup_type.hpp"
5758
#include "../smallmap_gui.h"
5859
#include "../news_func.h"
@@ -3500,8 +3501,10 @@ void ReloadNewGRFData()
35003501
for (CompanyID i = CompanyID::Begin(); i < MAX_COMPANIES; ++i) InvalidateWindowData(WindowClass::CompanyLivery, i);
35013502
/* Update company infrastructure counts. */
35023503
InvalidateWindowClassesData(WindowClass::CompanyInfrastructure);
3503-
InvalidateWindowClassesData(WindowClass::BuildToolbar);
3504-
InvalidateAllPickerWindows();
3504+
InvalidateWindowData(WindowClass::BuildToolbar, TRANSPORT_RAIL, GetToolbarRailType());
3505+
InvalidateWindowData(WindowClass::BuildToolbar, TRANSPORT_ROAD, GetToolbarRoadType());
3506+
InvalidateWindowData(WindowClass::BuildToolbar, TRANSPORT_WATER);
3507+
InvalidateWindowData(WindowClass::BuildToolbar, TRANSPORT_AIR);
35053508
/* redraw the whole screen */
35063509
MarkWholeScreenDirty();
35073510
CheckTrainsLengths();

src/settings_table.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#endif
2929
#include "textbuf_gui.h"
3030
#include "rail_gui.h"
31+
#include "road_gui.h"
3132
#include "elrail_func.h"
3233
#include "error.h"
3334
#include "town.h"
@@ -583,7 +584,10 @@ static void StationCatchmentChanged(int32_t)
583584

584585
static void MaxVehiclesChanged(int32_t)
585586
{
586-
InvalidateWindowClassesData(WindowClass::BuildToolbar);
587+
InvalidateWindowData(WindowClass::BuildToolbar, TRANSPORT_RAIL, GetToolbarRailType());
588+
InvalidateWindowData(WindowClass::BuildToolbar, TRANSPORT_ROAD, GetToolbarRoadType());
589+
InvalidateWindowData(WindowClass::BuildToolbar, TRANSPORT_WATER);
590+
InvalidateWindowData(WindowClass::BuildToolbar, TRANSPORT_AIR);
587591
MarkWholeScreenDirty();
588592
}
589593

0 commit comments

Comments
 (0)