diff options
author | Michael Lutz <michi@icosahedron.de> | 2021-10-29 00:56:07 +0200 |
---|---|---|
committer | Michael Lutz <michi@icosahedron.de> | 2021-12-16 22:28:32 +0100 |
commit | 996b16de707c449a83676c614edbd5a81d37b253 (patch) | |
tree | eb4298aef03768ca8483959db9799cd414f779af /src/dock_gui.cpp | |
parent | a05fd7aa50ecbee425df2d6f9015ec3ea359232f (diff) | |
download | openttd-996b16de707c449a83676c614edbd5a81d37b253.tar.xz |
Codechange: Use lambdas instead of CommandContainer to manage station picker commands.
Diffstat (limited to 'src/dock_gui.cpp')
-rw-r--r-- | src/dock_gui.cpp | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/dock_gui.cpp b/src/dock_gui.cpp index 52b148381..da7e0518f 100644 --- a/src/dock_gui.cpp +++ b/src/dock_gui.cpp @@ -27,6 +27,7 @@ #include "zoom_func.h" #include "tunnelbridge_cmd.h" #include "dock_cmd.h" +#include "station_cmd.h" #include "widgets/dock_widget.h" @@ -205,16 +206,25 @@ struct BuildDocksToolbarWindow : Window { break; case WID_DT_STATION: { // Build station button - uint32 p2 = (uint32)INVALID_STATION << 16; // no station to join - - /* tile is always the land tile, so need to evaluate _thd.pos */ - CommandContainer cmdcont = { tile, _ctrl_pressed, p2, CMD_BUILD_DOCK, STR_ERROR_CAN_T_BUILD_DOCK_HERE, CcBuildDocks, "" }; - /* Determine the watery part of the dock. */ DiagDirection dir = GetInclinedSlopeDirection(GetTileSlope(tile)); TileIndex tile_to = (dir != INVALID_DIAGDIR ? TileAddByDiagDir(tile, ReverseDiagDir(dir)) : tile); - ShowSelectStationIfNeeded(cmdcont, TileArea(tile, tile_to)); + uint32 p1 = _ctrl_pressed; + uint32 p2 = (uint32)INVALID_STATION << 16; // no station to join + + auto proc = [=](bool test, StationID to_join) -> bool { + if (test) { + return DoCommand(CommandFlagsToDCFlags(GetCommandFlags(CMD_BUILD_DOCK)), CMD_BUILD_DOCK, tile, p1, p2).Succeeded(); + } else { + uint32 p2_final = p2; + if (to_join != INVALID_STATION) SB(p2_final, 16, 16, to_join); + + return DoCommandP(CMD_BUILD_DOCK, STR_ERROR_CAN_T_BUILD_DOCK_HERE, CcBuildDocks, tile, p1, p2_final); + } + }; + + ShowSelectStationIfNeeded(TileArea(tile, tile_to), proc); break; } |