Skip to content

Commit

Permalink
Add: Option for toggling the airport specific ground tile.
Browse files Browse the repository at this point in the history
  • Loading branch information
J0anJosep committed Jul 2, 2024
1 parent da5feb7 commit 082ff82
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 1 deletion.
39 changes: 39 additions & 0 deletions src/airport_cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,45 @@ CommandCost CmdAirportChangeGFX(DoCommandFlag flags, TileIndex start_tile, TileI
return CommandCost();
}

CommandCost CmdAirportToogleGround(DoCommandFlag flags, TileIndex start_tile, TileIndex end_tile, AirType air_type, bool diagonal)
{
CommandCost ret = CheckSettingBuildByTile();
if (ret.Failed()) return ret;

/* Check air type. */
if (!ValParamAirType(air_type)) return_cmd_error(STR_ERROR_AIRPORT_INCORRECT_AIRTYPE);
if (air_type == AIRTYPE_WATER) return_cmd_error(STR_ERROR_AIRCRAFT_INCOMPATIBLE_AIR_TYPE);

std::unique_ptr<TileIterator> iter;
if (diagonal) {
iter = std::make_unique<DiagonalTileIterator>(start_tile, end_tile);
} else {
iter = std::make_unique<OrthogonalTileIterator>(start_tile, end_tile);
}

for (; *iter != INVALID_TILE; ++(*iter)) {
Tile tile = Tile(*iter);
if (!IsAirportTile(tile)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
if (air_type != GetAirType(tile)) return_cmd_error(STR_ERROR_AIRCRAFT_INCOMPATIBLE_AIR_TYPE);

if (CheckTileOwnership(tile).Failed()) {
/* We don't own it!. */
return_cmd_error(STR_ERROR_OWNED_BY);
}

if (flags & DC_EXEC) {
if (GetAirportGround(tile) == AIRPORT_AIRTYPE) {
SetAirportGroundAndDensity(tile, AIRPORT_GRASS, 0);
} else {
SetAirportGroundAndDensity(tile, AIRPORT_AIRTYPE, 0);
}
MarkTileDirtyByTile(tile);
}
}

return CommandCost();
}

CommandCost RemoveAirportTiles(DoCommandFlag flags, TileIndex start_tile, TileIndex end_tile, AirType air_type)
{
if (!IsValidTile(end_tile)) return CMD_ERROR;
Expand Down
2 changes: 2 additions & 0 deletions src/airport_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ CommandCost CmdAddRemoveAirportTiles(DoCommandFlag flags, TileIndex start_tile,
CommandCost CmdAddRemoveTracksToAirport(DoCommandFlag flags, TileIndex start_tile, TileIndex end_tile, AirType air_type, bool add, Track track);
CommandCost CmdChangeAirType(DoCommandFlag flags, TileIndex tile, AirType air_type);
CommandCost CmdAirportChangeGFX(DoCommandFlag flags, TileIndex start_tile, TileIndex end_tile, AirType air_type, bool diagonal);
CommandCost CmdAirportToogleGround(DoCommandFlag flags, TileIndex start_tile, TileIndex end_tile, AirType air_type, bool diagonal);

CommandCost CmdBuildAirport(DoCommandFlag flags, TileIndex tile, uint8_t airport_type, uint8_t layout, AirType air_type, DiagDirection rotation, StationID station_to_join, bool allow_adjacent);
CommandCost CmdOpenCloseAirport(DoCommandFlag flags, StationID station_id);
Expand All @@ -33,6 +34,7 @@ DEF_CMD_TRAIT(CMD_ADD_REM_AIRPORT, CmdAddRemoveAirportTiles, CMD_AUTO,
DEF_CMD_TRAIT(CMD_ADD_REM_TRACKS, CmdAddRemoveTracksToAirport, CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION)
DEF_CMD_TRAIT(CMD_CONVERT_AIRPORT, CmdChangeAirType, CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION)
DEF_CMD_TRAIT(CMD_AIRPORT_CHANGE_GFX, CmdAirportChangeGFX, CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION)
DEF_CMD_TRAIT(CMD_AIRPORT_TOGGLE_GROUND, CmdAirportToogleGround, CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION)

DEF_CMD_TRAIT(CMD_BUILD_AIRPORT, CmdBuildAirport, CMD_AUTO | CMD_NO_WATER, CMDT_LANDSCAPE_CONSTRUCTION)
DEF_CMD_TRAIT(CMD_OPEN_CLOSE_AIRPORT, CmdOpenCloseAirport, 0, CMDT_ROUTE_MANAGEMENT)
Expand Down
18 changes: 17 additions & 1 deletion src/airport_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,11 @@ struct BuildAirToolbarWindow : Window {
this->last_user_action = widget;
break;

case WID_AT_TOGGLE_GROUND:
HandlePlacePushButton(this, widget, SPR_CURSOR_MOUSE, HT_RECT | HT_DIAGONAL);
this->last_user_action = widget;
break;

default: break;
}

Expand Down Expand Up @@ -425,6 +430,11 @@ struct BuildAirToolbarWindow : Window {
VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_BUILD_STATION);
break;


case WID_AT_TOGGLE_GROUND:
VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_BUILD_STATION);
break;

default: NOT_REACHED();
}
}
Expand Down Expand Up @@ -497,6 +507,10 @@ struct BuildAirToolbarWindow : Window {
Command<CMD_AIRPORT_CHANGE_GFX>::Post(STR_ERROR_CAN_T_DO_THIS, start_tile, end_tile, _cur_airtype, _ctrl_pressed);
break;

case WID_AT_TOGGLE_GROUND:
Command<CMD_AIRPORT_TOGGLE_GROUND>::Post(STR_ERROR_CAN_T_DO_THIS, start_tile, end_tile, _cur_airtype, _ctrl_pressed);
break;

default: NOT_REACHED();
}
}
Expand Down Expand Up @@ -616,6 +630,8 @@ static constexpr NWidgetPart _nested_air_tile_toolbar_widgets[] = {
SetDataTip(0, STR_TOOLBAR_AIRPORT_CHANGE_AIRTYPE),
NWidget(WWT_TEXTBTN, COLOUR_DARK_GREEN, WID_AT_CHANGE_GRAPHICS), SetFill(0, 1),
SetDataTip(STR_TOOLBAR_AIRPORT_ROTATE_GRAPHICS, STR_TOOLBAR_AIRPORT_ROTATE_GRAPHICS_TOOLTIP),
NWidget(WWT_TEXTBTN, COLOUR_DARK_GREEN, WID_AT_TOGGLE_GROUND), SetFill(0, 1),
SetDataTip(STR_TOOLBAR_AIRPORT_TOGGLE_GROUND, STR_TOOLBAR_AIRPORT_TOGGLE_GROUND_TOOLBAR),
EndContainer(),
EndContainer(),
};
Expand All @@ -628,7 +644,7 @@ static const NWidgetPart _nested_air_nontile_toolbar_widgets[] = {
EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_AT_AIRPORT), SetFill(0, 1), SetMinimalSize(42, 22),
SetDataTip(SPR_IMG_AIRPORT, STR_TOOLBAR_AIRCRAFT_BUILD_PRE_AIRPORT_TOOLTIP),
SetDataTip(SPR_IMG_AIRPORT, STR_TOOLBAR_AIRPORT_BUILD_PRE_AIRPORT_TOOLTIP),
NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetMinimalSize(4, 22), SetFill(1, 1), EndContainer(),
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_AT_DEMOLISH), SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
EndContainer(),
Expand Down
1 change: 1 addition & 0 deletions src/command_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ enum Commands : uint16_t {
CMD_CONVERT_AIRPORT, ///< change the aiport type (gravel, asphalt, etc.)
CMD_BUILD_AIRPORT, ///< build an airport layout
CMD_AIRPORT_CHANGE_GFX, ///< change the graphics of an airport tile, if possible
CMD_AIRPORT_TOGGLE_GROUND, ///< toggle between showing the specific airtype ground or not, if possible

CMD_BUILD_DOCK, ///< build a dock

Expand Down
2 changes: 2 additions & 0 deletions src/lang/english.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3013,6 +3013,8 @@ STR_TOOLBAR_AIRPORT_BUILD_PRE_AIRPORT_TOOLTIP :{BLACK}Build a p
STR_TOOLBAR_AIRPORT_CHANGE_AIRTYPE :{BLACK}Change the airtype of an airport
STR_TOOLBAR_AIRPORT_ROTATE_GRAPHICS :{BLACK}Change track graphics
STR_TOOLBAR_AIRPORT_ROTATE_GRAPHICS_TOOLTIP :{BLACK}Click over a simple airport tile to change its graphics (experimental; only works on the Drawn tracks airtype)
STR_TOOLBAR_AIRPORT_TOGGLE_GROUND :{BLACK}Toogle ground graphics
STR_TOOLBAR_AIRPORT_TOGGLE_GROUND_TOOLBAR :{BLACK}Click over a simple airport tile to show or hide the airtype ground sprite.

STR_AIRTYPE_NAME_GRAVEL :Gravel airport
STR_AIRTYPE_NAME_ASPHALT :Asphalt airport
Expand Down
1 change: 1 addition & 0 deletions src/widgets/airport_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ enum AirportToolbarWidgets : WidgetID {
WID_AT_AIRPORT, ///< Build a predefined airport.
WID_AT_DEMOLISH, ///< Demolish button.
WID_AT_CHANGE_GRAPHICS, ///< Change base graphics, if possible.
WID_AT_TOGGLE_GROUND, ///< Toggle airport ground graphics on a tile.

WID_AT_REMOVE_FIRST = WID_AT_BUILD_TILE, ///< First an last widgets that work combined with remove widget.
WID_AT_REMOVE_LAST = WID_AT_HANGAR_EXTENDED,
Expand Down

0 comments on commit 082ff82

Please sign in to comment.