From 082ff82feb2b79dde1b459389739e65f78f4faea Mon Sep 17 00:00:00 2001 From: J0anJosep Date: Tue, 2 Jul 2024 22:13:39 +0200 Subject: [PATCH] Add: Option for toggling the airport specific ground tile. --- src/airport_cmd.cpp | 39 ++++++++++++++++++++++++++++++++++++ src/airport_cmd.h | 2 ++ src/airport_gui.cpp | 18 ++++++++++++++++- src/command_type.h | 1 + src/lang/english.txt | 2 ++ src/widgets/airport_widget.h | 1 + 6 files changed, 62 insertions(+), 1 deletion(-) diff --git a/src/airport_cmd.cpp b/src/airport_cmd.cpp index a923dda551ed1..aff18441f1ed4 100644 --- a/src/airport_cmd.cpp +++ b/src/airport_cmd.cpp @@ -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 iter; + if (diagonal) { + iter = std::make_unique(start_tile, end_tile); + } else { + iter = std::make_unique(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; diff --git a/src/airport_cmd.h b/src/airport_cmd.h index d2322fa025c31..569f541d10efa 100644 --- a/src/airport_cmd.h +++ b/src/airport_cmd.h @@ -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); @@ -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) diff --git a/src/airport_gui.cpp b/src/airport_gui.cpp index abef765762d36..53f4108c16f8a 100644 --- a/src/airport_gui.cpp +++ b/src/airport_gui.cpp @@ -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; } @@ -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(); } } @@ -497,6 +507,10 @@ struct BuildAirToolbarWindow : Window { Command::Post(STR_ERROR_CAN_T_DO_THIS, start_tile, end_tile, _cur_airtype, _ctrl_pressed); break; + case WID_AT_TOGGLE_GROUND: + Command::Post(STR_ERROR_CAN_T_DO_THIS, start_tile, end_tile, _cur_airtype, _ctrl_pressed); + break; + default: NOT_REACHED(); } } @@ -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(), }; @@ -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(), diff --git a/src/command_type.h b/src/command_type.h index 1687596365589..f52dbb32dadec 100644 --- a/src/command_type.h +++ b/src/command_type.h @@ -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 diff --git a/src/lang/english.txt b/src/lang/english.txt index a31ca5825b3da..ce080435b9725 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -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 diff --git a/src/widgets/airport_widget.h b/src/widgets/airport_widget.h index fba57292ba53b..1ee70db030780 100644 --- a/src/widgets/airport_widget.h +++ b/src/widgets/airport_widget.h @@ -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,