Skip to content

Commit

Permalink
Change: always allow to click on the toolbar icons for road/rail/dock…
Browse files Browse the repository at this point in the history
…/airport

This change allows a user to see what is available and what will become
available before it is available, instead of only disabling the button
with no further explanation. It also always allows building roads and
canals, even if no vehicles are available for road / water.

For rail/road/tram, a dropdown with available types is shown. If
none are available, it reads "None". If the type is not yet available,
it is greyed out.

For dock/airport, this always open the toolbar, but building airports,
docks, and depots buttons are disabled till vehicles are available
for those.

Road is the only exception, with the primary road always being
available. Here too, stations and depots are disabled till vehicles
become available. It does mean you can now always build roads to
for example help towns grow.
  • Loading branch information
TrueBrain committed Jan 8, 2021
1 parent a6aec25 commit 85a49a0
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 31 deletions.
10 changes: 8 additions & 2 deletions src/airport_gui.cpp
Expand Up @@ -71,6 +71,7 @@ struct BuildAirToolbarWindow : Window {
BuildAirToolbarWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
{
this->InitNested(window_number);
this->OnInvalidateData();
if (_settings_client.gui.link_terraform_toolbar) ShowTerraformToolbar(this);
this->last_user_action = WIDGET_LIST_END;
}
Expand All @@ -90,7 +91,13 @@ struct BuildAirToolbarWindow : Window {
{
if (!gui_scope) return;

if (!CanBuildVehicleInfrastructure(VEH_AIRCRAFT)) delete this;
bool can_build = CanBuildVehicleInfrastructure(VEH_AIRCRAFT);
this->SetWidgetsDisabledState(!can_build,
WID_AT_AIRPORT,
WIDGET_LIST_END);
if (!can_build) {
DeleteWindowById(WC_BUILD_STATION, TRANSPORT_AIR);
}
}

void OnClick(Point pt, int widget, int click_count) override
Expand Down Expand Up @@ -160,7 +167,6 @@ struct BuildAirToolbarWindow : Window {
*/
static EventState AirportToolbarGlobalHotkeys(int hotkey)
{
if (_game_mode != GM_NORMAL || !CanBuildVehicleInfrastructure(VEH_AIRCRAFT)) return ES_NOT_HANDLED;
Window *w = ShowBuildAirToolbar();
if (w == nullptr) return ES_NOT_HANDLED;
return w->OnHotkey(hotkey);
Expand Down
3 changes: 0 additions & 3 deletions src/dock_gui.cpp
Expand Up @@ -144,17 +144,14 @@ struct BuildDocksToolbarWindow : Window {
break;

case WID_DT_DEPOT: // Build depot button
if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return;
if (HandlePlacePushButton(this, WID_DT_DEPOT, SPR_CURSOR_SHIP_DEPOT, HT_RECT)) ShowBuildDocksDepotPicker(this);
break;

case WID_DT_STATION: // Build station button
if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return;
if (HandlePlacePushButton(this, WID_DT_STATION, SPR_CURSOR_DOCK, HT_SPECIAL)) ShowBuildDockStationPicker(this);
break;

case WID_DT_BUOY: // Build buoy button
if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return;
HandlePlacePushButton(this, WID_DT_BUOY, SPR_CURSOR_BUOY, HT_RECT);
break;

Expand Down
13 changes: 0 additions & 13 deletions src/rail_gui.cpp
Expand Up @@ -436,18 +436,6 @@ struct BuildRailToolbarWindow : Window {
if (_settings_client.gui.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0, false);
}

/**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
if (!gui_scope) return;

if (!CanBuildVehicleInfrastructure(VEH_TRAIN)) delete this;
}

/**
* Configures the rail toolbar for railtype given
* @param railtype the railtype to display
Expand Down Expand Up @@ -781,7 +769,6 @@ struct BuildRailToolbarWindow : Window {
*/
static EventState RailToolbarGlobalHotkeys(int hotkey)
{
if (_game_mode != GM_NORMAL || !CanBuildVehicleInfrastructure(VEH_TRAIN)) return ES_NOT_HANDLED;
extern RailType _last_built_railtype;
Window *w = ShowBuildRailToolbar(_last_built_railtype);
if (w == nullptr) return ES_NOT_HANDLED;
Expand Down
16 changes: 11 additions & 5 deletions src/road_gui.cpp
Expand Up @@ -304,7 +304,17 @@ struct BuildRoadToolbarWindow : Window {
{
if (!gui_scope) return;

if (_game_mode != GM_EDITOR && !CanBuildVehicleInfrastructure(VEH_ROAD, GetRoadTramType(this->roadtype))) delete this;
bool can_build = CanBuildVehicleInfrastructure(VEH_ROAD, GetRoadTramType(this->roadtype));
this->SetWidgetsDisabledState(!can_build,
WID_ROT_DEPOT,
WID_ROT_BUS_STATION,
WID_ROT_TRUCK_STATION,
WIDGET_LIST_END);
if (!can_build) {
DeleteWindowById(WC_BUS_STATION, TRANSPORT_ROAD);
DeleteWindowById(WC_TRUCK_STATION, TRANSPORT_ROAD);
DeleteWindowById(WC_BUILD_DEPOT, TRANSPORT_ROAD);
}
}

void Initialize(RoadType roadtype)
Expand Down Expand Up @@ -434,23 +444,20 @@ struct BuildRoadToolbarWindow : Window {
break;

case WID_ROT_DEPOT:
if (_game_mode == GM_EDITOR || !CanBuildVehicleInfrastructure(VEH_ROAD, GetRoadTramType(this->roadtype))) return;
if (HandlePlacePushButton(this, WID_ROT_DEPOT, this->rti->cursor.depot, HT_RECT)) {
ShowRoadDepotPicker(this);
this->last_started_action = widget;
}
break;

case WID_ROT_BUS_STATION:
if (_game_mode == GM_EDITOR || !CanBuildVehicleInfrastructure(VEH_ROAD, GetRoadTramType(this->roadtype))) return;
if (HandlePlacePushButton(this, WID_ROT_BUS_STATION, SPR_CURSOR_BUS_STATION, HT_RECT)) {
ShowRVStationPicker(this, ROADSTOP_BUS);
this->last_started_action = widget;
}
break;

case WID_ROT_TRUCK_STATION:
if (_game_mode == GM_EDITOR || !CanBuildVehicleInfrastructure(VEH_ROAD, GetRoadTramType(this->roadtype))) return;
if (HandlePlacePushButton(this, WID_ROT_TRUCK_STATION, SPR_CURSOR_TRUCK_STATION, HT_RECT)) {
ShowRVStationPicker(this, ROADSTOP_TRUCK);
this->last_started_action = widget;
Expand Down Expand Up @@ -711,7 +718,6 @@ static EventState RoadTramToolbarGlobalHotkeys(int hotkey, RoadType last_build,
Window* w = nullptr;
switch (_game_mode) {
case GM_NORMAL:
if (!CanBuildVehicleInfrastructure(VEH_ROAD, rtt)) return ES_NOT_HANDLED;
w = ShowBuildRoadToolbar(last_build);
break;

Expand Down
11 changes: 3 additions & 8 deletions src/toolbar_gui.cpp
Expand Up @@ -2033,11 +2033,6 @@ struct MainToolbarWindow : Window {
this->SetWidgetDisabledState(WID_TN_GOAL, Goal::GetNumItems() == 0);
this->SetWidgetDisabledState(WID_TN_STORY, StoryPage::GetNumItems() == 0);

this->SetWidgetDisabledState(WID_TN_RAILS, !CanBuildVehicleInfrastructure(VEH_TRAIN));
this->SetWidgetDisabledState(WID_TN_ROADS, !CanBuildVehicleInfrastructure(VEH_ROAD, RTT_ROAD));
this->SetWidgetDisabledState(WID_TN_TRAMS, !CanBuildVehicleInfrastructure(VEH_ROAD, RTT_TRAM));
this->SetWidgetDisabledState(WID_TN_AIR, !CanBuildVehicleInfrastructure(VEH_AIRCRAFT));

this->DrawWidgets();
}

Expand Down Expand Up @@ -2078,11 +2073,11 @@ struct MainToolbarWindow : Window {
case MTHK_AIRCRAFT_LIST: ShowVehicleListWindow(_local_company, VEH_AIRCRAFT); break;
case MTHK_ZOOM_IN: ToolbarZoomInClick(this); break;
case MTHK_ZOOM_OUT: ToolbarZoomOutClick(this); break;
case MTHK_BUILD_RAIL: if (CanBuildVehicleInfrastructure(VEH_TRAIN)) ShowBuildRailToolbar(_last_built_railtype); break;
case MTHK_BUILD_RAIL: ShowBuildRailToolbar(_last_built_railtype); break;
case MTHK_BUILD_ROAD: ShowBuildRoadToolbar(_last_built_roadtype); break;
case MTHK_BUILD_TRAM: if (CanBuildVehicleInfrastructure(VEH_ROAD, RTT_TRAM)) ShowBuildRoadToolbar(_last_built_tramtype); break;
case MTHK_BUILD_TRAM: ShowBuildRoadToolbar(_last_built_tramtype); break;
case MTHK_BUILD_DOCKS: ShowBuildDocksToolbar(); break;
case MTHK_BUILD_AIRPORT: if (CanBuildVehicleInfrastructure(VEH_AIRCRAFT)) ShowBuildAirToolbar(); break;
case MTHK_BUILD_AIRPORT: ShowBuildAirToolbar(); break;
case MTHK_BUILD_TREES: ShowBuildTreesToolbar(); break;
case MTHK_MUSIC: ShowMusicWindow(); break;
case MTHK_AI_DEBUG: ShowAIDebugWindow(); break;
Expand Down

0 comments on commit 85a49a0

Please sign in to comment.