4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
10 /** @file rail_gui.cpp %File for dealing with rail construction user interface */
14 #include "window_gui.h"
15 #include "station_gui.h"
16 #include "terraform_gui.h"
17 #include "viewport_func.h"
18 #include "command_func.h"
19 #include "waypoint_func.h"
20 #include "newgrf_station.h"
21 #include "company_base.h"
22 #include "strings_func.h"
23 #include "window_func.h"
24 #include "date_func.h"
25 #include "sound_func.h"
26 #include "company_func.h"
27 #include "widgets/dropdown_type.h"
28 #include "tunnelbridge.h"
29 #include "tilehighlight_func.h"
30 #include "spritecache.h"
31 #include "core/geometry_func.hpp"
33 #include "engine_base.h"
34 #include "vehicle_func.h"
35 #include "zoom_func.h"
38 #include "station_map.h"
39 #include "tunnelbridge_map.h"
41 #include "widgets/rail_widget.h"
43 #include "safeguards.h"
46 static RailType _cur_railtype
; ///< Rail type of the current build-rail toolbar.
47 static bool _remove_button_clicked
; ///< Flag whether 'remove' toggle-button is currently enabled
48 static DiagDirection _build_depot_direction
; ///< Currently selected depot direction
49 static byte _waypoint_count
= 1; ///< Number of waypoint types
50 static byte _cur_waypoint_type
; ///< Currently selected waypoint type
51 static bool _convert_signal_button
; ///< convert signal button in the signal GUI pressed
52 static SignalVariant _cur_signal_variant
; ///< set the signal variant (for signal GUI)
53 static SignalType _cur_signal_type
; ///< set the signal type (for signal GUI)
55 /* Map the setting: default_signal_type to the corresponding signal type */
56 static const SignalType _default_signal_type
[] = {SIGTYPE_NORMAL
, SIGTYPE_PBS
, SIGTYPE_PBS_ONEWAY
};
58 struct RailStationGUISettings
{
59 Axis orientation
; ///< Currently selected rail station orientation
61 bool newstations
; ///< Are custom station definitions available?
62 StationClassID station_class
; ///< Currently selected custom station class (if newstations is \c true )
63 byte station_type
; ///< %Station type within the currently selected custom station class (if newstations is \c true )
64 byte station_count
; ///< Number of custom stations (if newstations is \c true )
66 static RailStationGUISettings _railstation
; ///< Settings of the station builder GUI
69 static void HandleStationPlacement(TileIndex start
, TileIndex end
);
70 static void ShowBuildTrainDepotPicker(Window
*parent
);
71 static void ShowBuildWaypointPicker(Window
*parent
);
72 static void ShowStationBuilder(Window
*parent
);
73 static void ShowSignalBuilder(Window
*parent
);
76 * Check whether a station type can be build.
77 * @return true if building is allowed.
79 static bool IsStationAvailable(const StationSpec
*statspec
)
81 if (statspec
== nullptr || !HasBit(statspec
->callback_mask
, CBM_STATION_AVAIL
)) return true;
83 uint16 cb_res
= GetStationCallback(CBID_STATION_AVAILABILITY
, 0, 0, statspec
, nullptr, INVALID_TILE
);
84 if (cb_res
== CALLBACK_FAILED
) return true;
86 return Convert8bitBooleanCallback(statspec
->grf_prop
.grffile
, CBID_STATION_AVAILABILITY
, cb_res
);
89 void CcPlaySound_SPLAT_RAIL(const CommandCost
&result
, TileIndex tile
, uint32 p1
, uint32 p2
)
91 if (result
.Succeeded() && _settings_client
.sound
.confirm
) SndPlayTileFx(SND_20_SPLAT_RAIL
, tile
);
94 static void GenericPlaceRail(TileIndex tile
, int cmd
)
96 DoCommandP(tile
, _cur_railtype
, cmd
,
97 _remove_button_clicked
?
98 CMD_REMOVE_SINGLE_RAIL
| CMD_MSG(STR_ERROR_CAN_T_REMOVE_RAILROAD_TRACK
) :
99 CMD_BUILD_SINGLE_RAIL
| CMD_MSG(STR_ERROR_CAN_T_BUILD_RAILROAD_TRACK
),
100 CcPlaySound_SPLAT_RAIL
);
104 * Try to add an additional rail-track at the entrance of a depot
105 * @param tile Tile to use for adding the rail-track
106 * @param dir Direction to check for already present tracks
107 * @param track Track to add
110 static void PlaceExtraDepotRail(TileIndex tile
, DiagDirection dir
, Track track
)
112 if (GetRailTileType(tile
) != RAIL_TILE_NORMAL
) return;
113 if ((GetTrackBits(tile
) & DiagdirReachesTracks(dir
)) == 0) return;
115 DoCommandP(tile
, _cur_railtype
, track
, CMD_BUILD_SINGLE_RAIL
);
118 /** Additional pieces of track to add at the entrance of a depot. */
119 static const Track _place_depot_extra_track
[12] = {
120 TRACK_LEFT
, TRACK_UPPER
, TRACK_UPPER
, TRACK_RIGHT
, // First additional track for directions 0..3
121 TRACK_X
, TRACK_Y
, TRACK_X
, TRACK_Y
, // Second additional track
122 TRACK_LOWER
, TRACK_LEFT
, TRACK_RIGHT
, TRACK_LOWER
, // Third additional track
125 /** Direction to check for existing track pieces. */
126 static const DiagDirection _place_depot_extra_dir
[12] = {
127 DIAGDIR_SE
, DIAGDIR_SW
, DIAGDIR_SE
, DIAGDIR_SW
,
128 DIAGDIR_SW
, DIAGDIR_NW
, DIAGDIR_NE
, DIAGDIR_SE
,
129 DIAGDIR_NW
, DIAGDIR_NE
, DIAGDIR_NW
, DIAGDIR_NE
,
132 void CcRailDepot(const CommandCost
&result
, TileIndex tile
, uint32 p1
, uint32 p2
)
134 if (result
.Failed()) return;
136 DiagDirection dir
= (DiagDirection
)p2
;
138 if (_settings_client
.sound
.confirm
) SndPlayTileFx(SND_20_SPLAT_RAIL
, tile
);
139 if (!_settings_client
.gui
.persistent_buildingtools
) ResetObjectToPlace();
141 tile
+= TileOffsByDiagDir(dir
);
143 if (IsTileType(tile
, MP_RAILWAY
)) {
144 PlaceExtraDepotRail(tile
, _place_depot_extra_dir
[dir
], _place_depot_extra_track
[dir
]);
145 PlaceExtraDepotRail(tile
, _place_depot_extra_dir
[dir
+ 4], _place_depot_extra_track
[dir
+ 4]);
146 PlaceExtraDepotRail(tile
, _place_depot_extra_dir
[dir
+ 8], _place_depot_extra_track
[dir
+ 8]);
151 * Place a rail waypoint.
152 * @param tile Position to start dragging a waypoint.
154 static void PlaceRail_Waypoint(TileIndex tile
)
156 if (_remove_button_clicked
) {
157 VpStartPlaceSizing(tile
, VPM_X_AND_Y
, DDSP_REMOVE_STATION
);
161 Axis axis
= GetAxisForNewWaypoint(tile
);
162 if (IsValidAxis(axis
)) {
163 /* Valid tile for waypoints */
164 VpStartPlaceSizing(tile
, axis
== AXIS_X
? VPM_X_LIMITED
: VPM_Y_LIMITED
, DDSP_BUILD_STATION
);
165 VpSetPlaceSizingLimit(_settings_game
.station
.station_spread
);
167 /* Tile where we can't build rail waypoints. This is always going to fail,
168 * but provides the user with a proper error message. */
169 DoCommandP(tile
, 1 << 8 | 1 << 16, STAT_CLASS_WAYP
| INVALID_STATION
<< 16, CMD_BUILD_RAIL_WAYPOINT
| CMD_MSG(STR_ERROR_CAN_T_BUILD_TRAIN_WAYPOINT
));
173 void CcStation(const CommandCost
&result
, TileIndex tile
, uint32 p1
, uint32 p2
)
175 if (result
.Failed()) return;
177 if (_settings_client
.sound
.confirm
) SndPlayTileFx(SND_20_SPLAT_RAIL
, tile
);
178 /* Only close the station builder window if the default station and non persistent building is chosen. */
179 if (_railstation
.station_class
== STAT_CLASS_DFLT
&& _railstation
.station_type
== 0 && !_settings_client
.gui
.persistent_buildingtools
) ResetObjectToPlace();
183 * Place a rail station.
184 * @param tile Position to place or start dragging a station.
186 static void PlaceRail_Station(TileIndex tile
)
188 if (_remove_button_clicked
) {
189 VpStartPlaceSizing(tile
, VPM_X_AND_Y_LIMITED
, DDSP_REMOVE_STATION
);
190 VpSetPlaceSizingLimit(-1);
191 } else if (_settings_client
.gui
.station_dragdrop
) {
192 VpStartPlaceSizing(tile
, VPM_X_AND_Y_LIMITED
, DDSP_BUILD_STATION
);
193 VpSetPlaceSizingLimit(_settings_game
.station
.station_spread
);
195 uint32 p1
= _cur_railtype
| _railstation
.orientation
<< 6 | _settings_client
.gui
.station_numtracks
<< 8 | _settings_client
.gui
.station_platlength
<< 16 | _ctrl_pressed
<< 24;
196 uint32 p2
= _railstation
.station_class
| _railstation
.station_type
<< 8 | INVALID_STATION
<< 16;
198 int w
= _settings_client
.gui
.station_numtracks
;
199 int h
= _settings_client
.gui
.station_platlength
;
200 if (!_railstation
.orientation
) Swap(w
, h
);
202 CommandContainer cmdcont
= { tile
, p1
, p2
, CMD_BUILD_RAIL_STATION
| CMD_MSG(STR_ERROR_CAN_T_BUILD_RAILROAD_STATION
), CcStation
, "" };
203 ShowSelectStationIfNeeded(cmdcont
, TileArea(tile
, w
, h
));
208 * Build a new signal or edit/remove a present signal, use CmdBuildSingleSignal() or CmdRemoveSingleSignal() in rail_cmd.cpp
210 * @param tile The tile where the signal will build or edit
212 static void GenericPlaceSignals(TileIndex tile
)
214 TrackBits trackbits
= TrackStatusToTrackBits(GetTileTrackStatus(tile
, TRANSPORT_RAIL
, 0));
216 if (trackbits
& TRACK_BIT_VERT
) { // N-S direction
217 trackbits
= (_tile_fract_coords
.x
<= _tile_fract_coords
.y
) ? TRACK_BIT_RIGHT
: TRACK_BIT_LEFT
;
220 if (trackbits
& TRACK_BIT_HORZ
) { // E-W direction
221 trackbits
= (_tile_fract_coords
.x
+ _tile_fract_coords
.y
<= 15) ? TRACK_BIT_UPPER
: TRACK_BIT_LOWER
;
224 Track track
= FindFirstTrack(trackbits
);
226 if (_remove_button_clicked
) {
227 DoCommandP(tile
, track
, 0, CMD_REMOVE_SIGNALS
| CMD_MSG(STR_ERROR_CAN_T_REMOVE_SIGNALS_FROM
), CcPlaySound_SPLAT_RAIL
);
229 const Window
*w
= FindWindowById(WC_BUILD_SIGNAL
, 0);
231 /* Map the setting cycle_signal_types to the lower and upper allowed signal type. */
232 static const uint cycle_bounds
[] = {SIGTYPE_NORMAL
| (SIGTYPE_LAST_NOPBS
<< 3), SIGTYPE_PBS
| (SIGTYPE_LAST
<< 3), SIGTYPE_NORMAL
| (SIGTYPE_LAST
<< 3)};
234 /* various bitstuffed elements for CmdBuildSingleSignal() */
238 /* signal GUI is used */
239 SB(p1
, 3, 1, _ctrl_pressed
);
240 SB(p1
, 4, 1, _cur_signal_variant
);
241 SB(p1
, 5, 3, _cur_signal_type
);
242 SB(p1
, 8, 1, _convert_signal_button
);
243 SB(p1
, 9, 6, cycle_bounds
[_settings_client
.gui
.cycle_signal_types
]);
245 SB(p1
, 3, 1, _ctrl_pressed
);
246 SB(p1
, 4, 1, (_cur_year
< _settings_client
.gui
.semaphore_build_before
? SIG_SEMAPHORE
: SIG_ELECTRIC
));
247 SB(p1
, 5, 3, _default_signal_type
[_settings_client
.gui
.default_signal_type
]);
249 SB(p1
, 9, 6, cycle_bounds
[_settings_client
.gui
.cycle_signal_types
]);
252 DoCommandP(tile
, p1
, 0, CMD_BUILD_SIGNALS
|
253 CMD_MSG((w
!= nullptr && _convert_signal_button
) ? STR_ERROR_SIGNAL_CAN_T_CONVERT_SIGNALS_HERE
: STR_ERROR_CAN_T_BUILD_SIGNALS_HERE
),
254 CcPlaySound_SPLAT_RAIL
);
259 * Start placing a rail bridge.
260 * @param tile Position of the first tile of the bridge.
261 * @param w Rail toolbar window.
263 static void PlaceRail_Bridge(TileIndex tile
, Window
*w
)
265 if (IsBridgeTile(tile
)) {
266 TileIndex other_tile
= GetOtherTunnelBridgeEnd(tile
);
268 w
->OnPlaceMouseUp(VPM_X_OR_Y
, DDSP_BUILD_BRIDGE
, pt
, other_tile
, tile
);
270 VpStartPlaceSizing(tile
, VPM_X_OR_Y
, DDSP_BUILD_BRIDGE
);
274 /** Command callback for building a tunnel */
275 void CcBuildRailTunnel(const CommandCost
&result
, TileIndex tile
, uint32 p1
, uint32 p2
)
277 if (result
.Succeeded()) {
278 if (_settings_client
.sound
.confirm
) SndPlayTileFx(SND_20_SPLAT_RAIL
, tile
);
279 if (!_settings_client
.gui
.persistent_buildingtools
) ResetObjectToPlace();
281 SetRedErrorSquare(_build_tunnel_endtile
);
286 * Toggles state of the Remove button of Build rail toolbar
287 * @param w window the button belongs to
289 static void ToggleRailButton_Remove(Window
*w
)
291 DeleteWindowById(WC_SELECT_STATION
, 0);
292 w
->ToggleWidgetLoweredState(WID_RAT_REMOVE
);
293 w
->SetWidgetDirty(WID_RAT_REMOVE
);
294 _remove_button_clicked
= w
->IsWidgetLowered(WID_RAT_REMOVE
);
295 SetSelectionRed(_remove_button_clicked
);
299 * Updates the Remove button because of Ctrl state change
300 * @param w window the button belongs to
301 * @return true iff the remove button was changed
303 static bool RailToolbar_CtrlChanged(Window
*w
)
305 if (w
->IsWidgetDisabled(WID_RAT_REMOVE
)) return false;
307 /* allow ctrl to switch remove mode only for these widgets */
308 for (uint i
= WID_RAT_BUILD_NS
; i
<= WID_RAT_BUILD_STATION
; i
++) {
309 if ((i
<= WID_RAT_AUTORAIL
|| i
>= WID_RAT_BUILD_WAYPOINT
) && w
->IsWidgetLowered(i
)) {
310 ToggleRailButton_Remove(w
);
320 * The "remove"-button click proc of the build-rail toolbar.
321 * @param w Build-rail toolbar window
322 * @see BuildRailToolbarWindow::OnClick()
324 static void BuildRailClick_Remove(Window
*w
)
326 if (w
->IsWidgetDisabled(WID_RAT_REMOVE
)) return;
327 ToggleRailButton_Remove(w
);
328 if (_settings_client
.sound
.click_beep
) SndPlayFx(SND_15_BEEP
);
330 /* handle station builder */
331 if (w
->IsWidgetLowered(WID_RAT_BUILD_STATION
)) {
332 if (_remove_button_clicked
) {
333 /* starting drag & drop remove */
334 if (!_settings_client
.gui
.station_dragdrop
) {
335 SetTileSelectSize(1, 1);
337 VpSetPlaceSizingLimit(-1);
340 /* starting station build mode */
341 if (!_settings_client
.gui
.station_dragdrop
) {
342 int x
= _settings_client
.gui
.station_numtracks
;
343 int y
= _settings_client
.gui
.station_platlength
;
344 if (_railstation
.orientation
== 0) Swap(x
, y
);
345 SetTileSelectSize(x
, y
);
347 VpSetPlaceSizingLimit(_settings_game
.station
.station_spread
);
353 static void DoRailroadTrack(int mode
)
355 DoCommandP(TileVirtXY(_thd
.selstart
.x
, _thd
.selstart
.y
), TileVirtXY(_thd
.selend
.x
, _thd
.selend
.y
), _cur_railtype
| (mode
<< 6),
356 _remove_button_clicked
?
357 CMD_REMOVE_RAILROAD_TRACK
| CMD_MSG(STR_ERROR_CAN_T_REMOVE_RAILROAD_TRACK
) :
358 CMD_BUILD_RAILROAD_TRACK
| CMD_MSG(STR_ERROR_CAN_T_BUILD_RAILROAD_TRACK
),
359 CcPlaySound_SPLAT_RAIL
);
362 static void HandleAutodirPlacement()
364 int trackstat
= _thd
.drawstyle
& HT_DIR_MASK
; // 0..5
366 if (_thd
.drawstyle
& HT_RAIL
) { // one tile case
367 GenericPlaceRail(TileVirtXY(_thd
.selend
.x
, _thd
.selend
.y
), trackstat
);
371 DoRailroadTrack(trackstat
);
375 * Build new signals or remove signals or (if only one tile marked) edit a signal.
377 * If one tile marked abort and use GenericPlaceSignals()
378 * else use CmdBuildSingleSignal() or CmdRemoveSingleSignal() in rail_cmd.cpp to build many signals
380 static void HandleAutoSignalPlacement()
382 uint32 p2
= GB(_thd
.drawstyle
, 0, 3); // 0..5
384 if ((_thd
.drawstyle
& HT_DRAG_MASK
) == HT_RECT
) { // one tile case
385 GenericPlaceSignals(TileVirtXY(_thd
.selend
.x
, _thd
.selend
.y
));
389 const Window
*w
= FindWindowById(WC_BUILD_SIGNAL
, 0);
392 /* signal GUI is used */
394 SB(p2
, 4, 1, _cur_signal_variant
);
395 SB(p2
, 6, 1, _ctrl_pressed
);
396 SB(p2
, 7, 3, _cur_signal_type
);
397 SB(p2
, 24, 8, _settings_client
.gui
.drag_signals_density
);
398 SB(p2
, 10, 1, !_settings_client
.gui
.drag_signals_fixed_distance
);
401 SB(p2
, 4, 1, (_cur_year
< _settings_client
.gui
.semaphore_build_before
? SIG_SEMAPHORE
: SIG_ELECTRIC
));
402 SB(p2
, 6, 1, _ctrl_pressed
);
403 SB(p2
, 7, 3, _default_signal_type
[_settings_client
.gui
.default_signal_type
]);
404 SB(p2
, 24, 8, _settings_client
.gui
.drag_signals_density
);
405 SB(p2
, 10, 1, !_settings_client
.gui
.drag_signals_fixed_distance
);
408 /* _settings_client.gui.drag_signals_density is given as a parameter such that each user
409 * in a network game can specify his/her own signal density */
410 DoCommandP(TileVirtXY(_thd
.selstart
.x
, _thd
.selstart
.y
), TileVirtXY(_thd
.selend
.x
, _thd
.selend
.y
), p2
,
411 _remove_button_clicked
?
412 CMD_REMOVE_SIGNAL_TRACK
| CMD_MSG(STR_ERROR_CAN_T_REMOVE_SIGNALS_FROM
) :
413 CMD_BUILD_SIGNAL_TRACK
| CMD_MSG(STR_ERROR_CAN_T_BUILD_SIGNALS_HERE
),
414 CcPlaySound_SPLAT_RAIL
);
418 /** Rail toolbar management class. */
419 struct BuildRailToolbarWindow
: Window
{
420 RailType railtype
; ///< Rail type to build.
421 int last_user_action
; ///< Last started user action.
423 BuildRailToolbarWindow(WindowDesc
*desc
, RailType railtype
) : Window(desc
)
425 this->InitNested(TRANSPORT_RAIL
);
426 this->SetupRailToolbar(railtype
);
427 this->DisableWidget(WID_RAT_REMOVE
);
428 this->last_user_action
= WIDGET_LIST_END
;
430 if (_settings_client
.gui
.link_terraform_toolbar
) ShowTerraformToolbar(this);
433 ~BuildRailToolbarWindow()
435 if (_settings_client
.gui
.link_terraform_toolbar
) DeleteWindowById(WC_SCEN_LAND_GEN
, 0, false);
439 * Some data on this window has become invalid.
440 * @param data Information about the changed data.
441 * @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.
443 void OnInvalidateData(int data
= 0, bool gui_scope
= true) override
445 if (!gui_scope
) return;
447 if (!CanBuildVehicleInfrastructure(VEH_TRAIN
)) delete this;
451 * Configures the rail toolbar for railtype given
452 * @param railtype the railtype to display
454 void SetupRailToolbar(RailType railtype
)
456 this->railtype
= railtype
;
457 const RailtypeInfo
*rti
= GetRailTypeInfo(railtype
);
459 assert(railtype
< RAILTYPE_END
);
460 this->GetWidget
<NWidgetCore
>(WID_RAT_BUILD_NS
)->widget_data
= rti
->gui_sprites
.build_ns_rail
;
461 this->GetWidget
<NWidgetCore
>(WID_RAT_BUILD_X
)->widget_data
= rti
->gui_sprites
.build_x_rail
;
462 this->GetWidget
<NWidgetCore
>(WID_RAT_BUILD_EW
)->widget_data
= rti
->gui_sprites
.build_ew_rail
;
463 this->GetWidget
<NWidgetCore
>(WID_RAT_BUILD_Y
)->widget_data
= rti
->gui_sprites
.build_y_rail
;
464 this->GetWidget
<NWidgetCore
>(WID_RAT_AUTORAIL
)->widget_data
= rti
->gui_sprites
.auto_rail
;
465 this->GetWidget
<NWidgetCore
>(WID_RAT_BUILD_DEPOT
)->widget_data
= rti
->gui_sprites
.build_depot
;
466 this->GetWidget
<NWidgetCore
>(WID_RAT_CONVERT_RAIL
)->widget_data
= rti
->gui_sprites
.convert_rail
;
467 this->GetWidget
<NWidgetCore
>(WID_RAT_BUILD_TUNNEL
)->widget_data
= rti
->gui_sprites
.build_tunnel
;
471 * Switch to another rail type.
472 * @param railtype New rail type.
474 void ModifyRailType(RailType railtype
)
476 this->SetupRailToolbar(railtype
);
480 void UpdateRemoveWidgetStatus(int clicked_widget
)
482 switch (clicked_widget
) {
484 /* If it is the removal button that has been clicked, do nothing,
485 * as it is up to the other buttons to drive removal status */
488 case WID_RAT_BUILD_NS
:
489 case WID_RAT_BUILD_X
:
490 case WID_RAT_BUILD_EW
:
491 case WID_RAT_BUILD_Y
:
492 case WID_RAT_AUTORAIL
:
493 case WID_RAT_BUILD_WAYPOINT
:
494 case WID_RAT_BUILD_STATION
:
495 case WID_RAT_BUILD_SIGNALS
:
496 /* Removal button is enabled only if the rail/signal/waypoint/station
497 * button is still lowered. Once raised, it has to be disabled */
498 this->SetWidgetDisabledState(WID_RAT_REMOVE
, !this->IsWidgetLowered(clicked_widget
));
502 /* When any other buttons than rail/signal/waypoint/station, raise and
503 * disable the removal button */
504 this->DisableWidget(WID_RAT_REMOVE
);
505 this->RaiseWidget(WID_RAT_REMOVE
);
510 void SetStringParameters(int widget
) const override
512 if (widget
== WID_RAT_CAPTION
) {
513 const RailtypeInfo
*rti
= GetRailTypeInfo(this->railtype
);
514 if (rti
->max_speed
> 0) {
515 SetDParam(0, STR_TOOLBAR_RAILTYPE_VELOCITY
);
516 SetDParam(1, rti
->strings
.toolbar_caption
);
517 SetDParam(2, rti
->max_speed
);
519 SetDParam(0, rti
->strings
.toolbar_caption
);
524 void OnClick(Point pt
, int widget
, int click_count
) override
526 if (widget
< WID_RAT_BUILD_NS
) return;
528 _remove_button_clicked
= false;
530 case WID_RAT_BUILD_NS
:
531 HandlePlacePushButton(this, WID_RAT_BUILD_NS
, GetRailTypeInfo(_cur_railtype
)->cursor
.rail_ns
, HT_LINE
| HT_DIR_VL
);
532 this->last_user_action
= widget
;
535 case WID_RAT_BUILD_X
:
536 HandlePlacePushButton(this, WID_RAT_BUILD_X
, GetRailTypeInfo(_cur_railtype
)->cursor
.rail_swne
, HT_LINE
| HT_DIR_X
);
537 this->last_user_action
= widget
;
540 case WID_RAT_BUILD_EW
:
541 HandlePlacePushButton(this, WID_RAT_BUILD_EW
, GetRailTypeInfo(_cur_railtype
)->cursor
.rail_ew
, HT_LINE
| HT_DIR_HL
);
542 this->last_user_action
= widget
;
545 case WID_RAT_BUILD_Y
:
546 HandlePlacePushButton(this, WID_RAT_BUILD_Y
, GetRailTypeInfo(_cur_railtype
)->cursor
.rail_nwse
, HT_LINE
| HT_DIR_Y
);
547 this->last_user_action
= widget
;
550 case WID_RAT_AUTORAIL
:
551 HandlePlacePushButton(this, WID_RAT_AUTORAIL
, GetRailTypeInfo(_cur_railtype
)->cursor
.autorail
, HT_RAIL
);
552 this->last_user_action
= widget
;
555 case WID_RAT_DEMOLISH
:
556 HandlePlacePushButton(this, WID_RAT_DEMOLISH
, ANIMCURSOR_DEMOLISH
, HT_RECT
| HT_DIAGONAL
);
557 this->last_user_action
= widget
;
560 case WID_RAT_BUILD_DEPOT
:
561 if (HandlePlacePushButton(this, WID_RAT_BUILD_DEPOT
, GetRailTypeInfo(_cur_railtype
)->cursor
.depot
, HT_RECT
)) {
562 ShowBuildTrainDepotPicker(this);
563 this->last_user_action
= widget
;
567 case WID_RAT_BUILD_WAYPOINT
:
568 this->last_user_action
= widget
;
569 _waypoint_count
= StationClass::Get(STAT_CLASS_WAYP
)->GetSpecCount();
570 if (HandlePlacePushButton(this, WID_RAT_BUILD_WAYPOINT
, SPR_CURSOR_WAYPOINT
, HT_RECT
) && _waypoint_count
> 1) {
571 ShowBuildWaypointPicker(this);
575 case WID_RAT_BUILD_STATION
:
576 if (HandlePlacePushButton(this, WID_RAT_BUILD_STATION
, SPR_CURSOR_RAIL_STATION
, HT_RECT
)) {
577 ShowStationBuilder(this);
578 this->last_user_action
= widget
;
582 case WID_RAT_BUILD_SIGNALS
: {
583 this->last_user_action
= widget
;
584 bool started
= HandlePlacePushButton(this, WID_RAT_BUILD_SIGNALS
, ANIMCURSOR_BUILDSIGNALS
, HT_RECT
);
585 if (started
&& _settings_client
.gui
.enable_signal_gui
!= _ctrl_pressed
) {
586 ShowSignalBuilder(this);
591 case WID_RAT_BUILD_BRIDGE
:
592 HandlePlacePushButton(this, WID_RAT_BUILD_BRIDGE
, SPR_CURSOR_BRIDGE
, HT_RECT
);
593 this->last_user_action
= widget
;
596 case WID_RAT_BUILD_TUNNEL
:
597 HandlePlacePushButton(this, WID_RAT_BUILD_TUNNEL
, GetRailTypeInfo(_cur_railtype
)->cursor
.tunnel
, HT_SPECIAL
);
598 this->last_user_action
= widget
;
602 BuildRailClick_Remove(this);
605 case WID_RAT_CONVERT_RAIL
:
606 HandlePlacePushButton(this, WID_RAT_CONVERT_RAIL
, GetRailTypeInfo(_cur_railtype
)->cursor
.convert
, HT_RECT
| HT_DIAGONAL
);
607 this->last_user_action
= widget
;
610 default: NOT_REACHED();
612 this->UpdateRemoveWidgetStatus(widget
);
613 if (_ctrl_pressed
) RailToolbar_CtrlChanged(this);
616 EventState
OnHotkey(int hotkey
) override
618 MarkTileDirtyByTile(TileVirtXY(_thd
.pos
.x
, _thd
.pos
.y
)); // redraw tile selection
619 return Window::OnHotkey(hotkey
);
622 void OnPlaceObject(Point pt
, TileIndex tile
) override
624 switch (this->last_user_action
) {
625 case WID_RAT_BUILD_NS
:
626 VpStartPlaceSizing(tile
, VPM_FIX_VERTICAL
| VPM_RAILDIRS
, DDSP_PLACE_RAIL
);
629 case WID_RAT_BUILD_X
:
630 VpStartPlaceSizing(tile
, VPM_FIX_Y
| VPM_RAILDIRS
, DDSP_PLACE_RAIL
);
633 case WID_RAT_BUILD_EW
:
634 VpStartPlaceSizing(tile
, VPM_FIX_HORIZONTAL
| VPM_RAILDIRS
, DDSP_PLACE_RAIL
);
637 case WID_RAT_BUILD_Y
:
638 VpStartPlaceSizing(tile
, VPM_FIX_X
| VPM_RAILDIRS
, DDSP_PLACE_RAIL
);
641 case WID_RAT_AUTORAIL
:
642 VpStartPlaceSizing(tile
, VPM_RAILDIRS
, DDSP_PLACE_RAIL
);
645 case WID_RAT_DEMOLISH
:
646 PlaceProc_DemolishArea(tile
);
649 case WID_RAT_BUILD_DEPOT
:
650 DoCommandP(tile
, _cur_railtype
, _build_depot_direction
,
651 CMD_BUILD_TRAIN_DEPOT
| CMD_MSG(STR_ERROR_CAN_T_BUILD_TRAIN_DEPOT
),
655 case WID_RAT_BUILD_WAYPOINT
:
656 PlaceRail_Waypoint(tile
);
659 case WID_RAT_BUILD_STATION
:
660 PlaceRail_Station(tile
);
663 case WID_RAT_BUILD_SIGNALS
:
664 VpStartPlaceSizing(tile
, VPM_SIGNALDIRS
, DDSP_BUILD_SIGNALS
);
667 case WID_RAT_BUILD_BRIDGE
:
668 PlaceRail_Bridge(tile
, this);
671 case WID_RAT_BUILD_TUNNEL
:
672 DoCommandP(tile
, _cur_railtype
| (TRANSPORT_RAIL
<< 8), 0, CMD_BUILD_TUNNEL
| CMD_MSG(STR_ERROR_CAN_T_BUILD_TUNNEL_HERE
), CcBuildRailTunnel
);
675 case WID_RAT_CONVERT_RAIL
:
676 VpStartPlaceSizing(tile
, VPM_X_AND_Y
, DDSP_CONVERT_RAIL
);
679 default: NOT_REACHED();
683 void OnPlaceDrag(ViewportPlaceMethod select_method
, ViewportDragDropSelectionProcess select_proc
, Point pt
) override
685 /* no dragging if you have pressed the convert button */
686 if (FindWindowById(WC_BUILD_SIGNAL
, 0) != nullptr && _convert_signal_button
&& this->IsWidgetLowered(WID_RAT_BUILD_SIGNALS
)) return;
688 VpSelectTilesWithMethod(pt
.x
, pt
.y
, select_method
);
691 void OnPlaceMouseUp(ViewportPlaceMethod select_method
, ViewportDragDropSelectionProcess select_proc
, Point pt
, TileIndex start_tile
, TileIndex end_tile
) override
694 switch (select_proc
) {
695 default: NOT_REACHED();
696 case DDSP_BUILD_BRIDGE
:
697 if (!_settings_client
.gui
.persistent_buildingtools
) ResetObjectToPlace();
698 ShowBuildBridgeWindow(start_tile
, end_tile
, TRANSPORT_RAIL
, _cur_railtype
);
701 case DDSP_PLACE_RAIL
:
702 HandleAutodirPlacement();
705 case DDSP_BUILD_SIGNALS
:
706 HandleAutoSignalPlacement();
709 case DDSP_DEMOLISH_AREA
:
710 GUIPlaceProcDragXY(select_proc
, start_tile
, end_tile
);
713 case DDSP_CONVERT_RAIL
:
714 DoCommandP(end_tile
, start_tile
, _cur_railtype
| (_ctrl_pressed
? 1 << 6 : 0), CMD_CONVERT_RAIL
| CMD_MSG(STR_ERROR_CAN_T_CONVERT_RAIL
), CcPlaySound_SPLAT_RAIL
);
717 case DDSP_REMOVE_STATION
:
718 case DDSP_BUILD_STATION
:
719 if (this->IsWidgetLowered(WID_RAT_BUILD_STATION
)) {
721 if (_remove_button_clicked
) {
722 DoCommandP(end_tile
, start_tile
, _ctrl_pressed
? 0 : 1, CMD_REMOVE_FROM_RAIL_STATION
| CMD_MSG(STR_ERROR_CAN_T_REMOVE_PART_OF_STATION
), CcPlaySound_SPLAT_RAIL
);
724 HandleStationPlacement(start_tile
, end_tile
);
728 if (_remove_button_clicked
) {
729 DoCommandP(end_tile
, start_tile
, _ctrl_pressed
? 0 : 1, CMD_REMOVE_FROM_RAIL_WAYPOINT
| CMD_MSG(STR_ERROR_CAN_T_REMOVE_TRAIN_WAYPOINT
), CcPlaySound_SPLAT_RAIL
);
731 TileArea
ta(start_tile
, end_tile
);
732 uint32 p1
= _cur_railtype
| (select_method
== VPM_X_LIMITED
? AXIS_X
: AXIS_Y
) << 6 | ta
.w
<< 8 | ta
.h
<< 16 | _ctrl_pressed
<< 24;
733 uint32 p2
= STAT_CLASS_WAYP
| _cur_waypoint_type
<< 8 | INVALID_STATION
<< 16;
735 CommandContainer cmdcont
= { ta
.tile
, p1
, p2
, CMD_BUILD_RAIL_WAYPOINT
| CMD_MSG(STR_ERROR_CAN_T_BUILD_TRAIN_WAYPOINT
), CcPlaySound_SPLAT_RAIL
, "" };
736 ShowSelectWaypointIfNeeded(cmdcont
, ta
);
744 void OnPlaceObjectAbort() override
746 this->RaiseButtons();
747 this->DisableWidget(WID_RAT_REMOVE
);
748 this->SetWidgetDirty(WID_RAT_REMOVE
);
750 DeleteWindowById(WC_BUILD_SIGNAL
, TRANSPORT_RAIL
);
751 DeleteWindowById(WC_BUILD_STATION
, TRANSPORT_RAIL
);
752 DeleteWindowById(WC_BUILD_DEPOT
, TRANSPORT_RAIL
);
753 DeleteWindowById(WC_BUILD_WAYPOINT
, TRANSPORT_RAIL
);
754 DeleteWindowById(WC_SELECT_STATION
, 0);
755 DeleteWindowByClass(WC_BUILD_BRIDGE
);
758 void OnPlacePresize(Point pt
, TileIndex tile
) override
760 DoCommand(tile
, _cur_railtype
| (TRANSPORT_RAIL
<< 8), 0, DC_AUTO
, CMD_BUILD_TUNNEL
);
761 VpSetPresizeRange(tile
, _build_tunnel_endtile
== 0 ? tile
: _build_tunnel_endtile
);
764 EventState
OnCTRLStateChange() override
766 /* do not toggle Remove button by Ctrl when placing station */
767 if (!this->IsWidgetLowered(WID_RAT_BUILD_STATION
) && !this->IsWidgetLowered(WID_RAT_BUILD_WAYPOINT
) && RailToolbar_CtrlChanged(this)) return ES_HANDLED
;
768 return ES_NOT_HANDLED
;
771 static HotkeyList hotkeys
;
775 * Handler for global hotkeys of the BuildRailToolbarWindow.
776 * @param hotkey Hotkey
777 * @return ES_HANDLED if hotkey was accepted.
779 static EventState
RailToolbarGlobalHotkeys(int hotkey
)
781 if (_game_mode
!= GM_NORMAL
|| !CanBuildVehicleInfrastructure(VEH_TRAIN
)) return ES_NOT_HANDLED
;
782 extern RailType _last_built_railtype
;
783 Window
*w
= ShowBuildRailToolbar(_last_built_railtype
);
784 if (w
== nullptr) return ES_NOT_HANDLED
;
785 return w
->OnHotkey(hotkey
);
788 const uint16 _railtoolbar_autorail_keys
[] = {'5', 'A' | WKC_GLOBAL_HOTKEY
, 0};
790 static Hotkey railtoolbar_hotkeys
[] = {
791 Hotkey('1', "build_ns", WID_RAT_BUILD_NS
),
792 Hotkey('2', "build_x", WID_RAT_BUILD_X
),
793 Hotkey('3', "build_ew", WID_RAT_BUILD_EW
),
794 Hotkey('4', "build_y", WID_RAT_BUILD_Y
),
795 Hotkey(_railtoolbar_autorail_keys
, "autorail", WID_RAT_AUTORAIL
),
796 Hotkey('6', "demolish", WID_RAT_DEMOLISH
),
797 Hotkey('7', "depot", WID_RAT_BUILD_DEPOT
),
798 Hotkey('8', "waypoint", WID_RAT_BUILD_WAYPOINT
),
799 Hotkey('9', "station", WID_RAT_BUILD_STATION
),
800 Hotkey('S', "signal", WID_RAT_BUILD_SIGNALS
),
801 Hotkey('B', "bridge", WID_RAT_BUILD_BRIDGE
),
802 Hotkey('T', "tunnel", WID_RAT_BUILD_TUNNEL
),
803 Hotkey('R', "remove", WID_RAT_REMOVE
),
804 Hotkey('C', "convert", WID_RAT_CONVERT_RAIL
),
807 HotkeyList
BuildRailToolbarWindow::hotkeys("railtoolbar", railtoolbar_hotkeys
, RailToolbarGlobalHotkeys
);
809 static const NWidgetPart _nested_build_rail_widgets
[] = {
810 NWidget(NWID_HORIZONTAL
),
811 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
812 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
, WID_RAT_CAPTION
), SetDataTip(STR_WHITE_STRING
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
813 NWidget(WWT_STICKYBOX
, COLOUR_DARK_GREEN
),
815 NWidget(NWID_HORIZONTAL
),
816 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_BUILD_NS
),
817 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_RAIL_NS
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_TRACK
),
818 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_BUILD_X
),
819 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_RAIL_NE
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_TRACK
),
820 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_BUILD_EW
),
821 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_RAIL_EW
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_TRACK
),
822 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_BUILD_Y
),
823 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_RAIL_NW
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_TRACK
),
824 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_AUTORAIL
),
825 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_AUTORAIL
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_AUTORAIL
),
827 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
), SetMinimalSize(4, 22), SetDataTip(0x0, STR_NULL
), EndContainer(),
829 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_DEMOLISH
),
830 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DYNAMITE
, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC
),
831 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_BUILD_DEPOT
),
832 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DEPOT_RAIL
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_TRAIN_DEPOT_FOR_BUILDING
),
833 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_BUILD_WAYPOINT
),
834 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_WAYPOINT
, STR_RAIL_TOOLBAR_TOOLTIP_CONVERT_RAIL_TO_WAYPOINT
),
835 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_BUILD_STATION
),
836 SetFill(0, 1), SetMinimalSize(42, 22), SetDataTip(SPR_IMG_RAIL_STATION
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_STATION
),
837 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_BUILD_SIGNALS
),
838 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_RAIL_SIGNALS
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_SIGNALS
),
839 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_BUILD_BRIDGE
),
840 SetFill(0, 1), SetMinimalSize(42, 22), SetDataTip(SPR_IMG_BRIDGE
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_BRIDGE
),
841 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_BUILD_TUNNEL
),
842 SetFill(0, 1), SetMinimalSize(20, 22), SetDataTip(SPR_IMG_TUNNEL_RAIL
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_TUNNEL
),
843 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_REMOVE
),
844 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_REMOVE
, STR_RAIL_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR
),
845 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_CONVERT_RAIL
),
846 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_CONVERT_RAIL
, STR_RAIL_TOOLBAR_TOOLTIP_CONVERT_RAIL
),
850 static WindowDesc
_build_rail_desc(
851 WDP_ALIGN_TOOLBAR
, "toolbar_rail", 0, 0,
852 WC_BUILD_TOOLBAR
, WC_NONE
,
854 _nested_build_rail_widgets
, lengthof(_nested_build_rail_widgets
),
855 &BuildRailToolbarWindow::hotkeys
860 * Open the build rail toolbar window for a specific rail type.
862 * If the terraform toolbar is linked to the toolbar, that window is also opened.
864 * @param railtype Rail type to open the window for
865 * @return newly opened rail toolbar, or nullptr if the toolbar could not be opened.
867 Window
*ShowBuildRailToolbar(RailType railtype
)
869 if (!Company::IsValidID(_local_company
)) return nullptr;
870 if (!ValParamRailtype(railtype
)) return nullptr;
872 DeleteWindowByClass(WC_BUILD_TOOLBAR
);
873 _cur_railtype
= railtype
;
874 _remove_button_clicked
= false;
875 return new BuildRailToolbarWindow(&_build_rail_desc
, railtype
);
878 /* TODO: For custom stations, respect their allowed platforms/lengths bitmasks!
881 static void HandleStationPlacement(TileIndex start
, TileIndex end
)
883 TileArea
ta(start
, end
);
884 uint numtracks
= ta
.w
;
885 uint platlength
= ta
.h
;
887 if (_railstation
.orientation
== AXIS_X
) Swap(numtracks
, platlength
);
889 uint32 p1
= _cur_railtype
| _railstation
.orientation
<< 6 | numtracks
<< 8 | platlength
<< 16 | _ctrl_pressed
<< 24;
890 uint32 p2
= _railstation
.station_class
| _railstation
.station_type
<< 8 | INVALID_STATION
<< 16;
892 CommandContainer cmdcont
= { ta
.tile
, p1
, p2
, CMD_BUILD_RAIL_STATION
| CMD_MSG(STR_ERROR_CAN_T_BUILD_RAILROAD_STATION
), CcStation
, "" };
893 ShowSelectStationIfNeeded(cmdcont
, ta
);
896 struct BuildRailStationWindow
: public PickerWindowBase
{
898 uint line_height
; ///< Height of a single line in the newstation selection matrix (#WID_BRAS_NEWST_LIST widget).
899 uint coverage_height
; ///< Height of the coverage texts.
900 Scrollbar
*vscroll
; ///< Vertical scrollbar of the new station list.
901 Scrollbar
*vscroll2
; ///< Vertical scrollbar of the matrix with new stations.
904 * Verify whether the currently selected station size is allowed after selecting a new station class/type.
905 * If not, change the station size variables ( _settings_client.gui.station_numtracks and _settings_client.gui.station_platlength ).
906 * @param statspec Specification of the new station class/type
908 void CheckSelectedSize(const StationSpec
*statspec
)
910 if (statspec
== nullptr || _settings_client
.gui
.station_dragdrop
) return;
912 /* If current number of tracks is not allowed, make it as big as possible */
913 if (HasBit(statspec
->disallowed_platforms
, _settings_client
.gui
.station_numtracks
- 1)) {
914 this->RaiseWidget(_settings_client
.gui
.station_numtracks
+ WID_BRAS_PLATFORM_NUM_BEGIN
);
915 _settings_client
.gui
.station_numtracks
= 1;
916 if (statspec
->disallowed_platforms
!= UINT8_MAX
) {
917 while (HasBit(statspec
->disallowed_platforms
, _settings_client
.gui
.station_numtracks
- 1)) {
918 _settings_client
.gui
.station_numtracks
++;
920 this->LowerWidget(_settings_client
.gui
.station_numtracks
+ WID_BRAS_PLATFORM_NUM_BEGIN
);
924 if (HasBit(statspec
->disallowed_lengths
, _settings_client
.gui
.station_platlength
- 1)) {
925 this->RaiseWidget(_settings_client
.gui
.station_platlength
+ WID_BRAS_PLATFORM_LEN_BEGIN
);
926 _settings_client
.gui
.station_platlength
= 1;
927 if (statspec
->disallowed_lengths
!= UINT8_MAX
) {
928 while (HasBit(statspec
->disallowed_lengths
, _settings_client
.gui
.station_platlength
- 1)) {
929 _settings_client
.gui
.station_platlength
++;
931 this->LowerWidget(_settings_client
.gui
.station_platlength
+ WID_BRAS_PLATFORM_LEN_BEGIN
);
937 BuildRailStationWindow(WindowDesc
*desc
, Window
*parent
, bool newstation
) : PickerWindowBase(desc
, parent
)
939 this->coverage_height
= 2 * FONT_HEIGHT_NORMAL
+ 3 * WD_PAR_VSEP_NORMAL
;
940 this->vscroll
= nullptr;
941 _railstation
.newstations
= newstation
;
943 this->CreateNestedTree();
944 NWidgetStacked
*newst_additions
= this->GetWidget
<NWidgetStacked
>(WID_BRAS_SHOW_NEWST_ADDITIONS
);
945 newst_additions
->SetDisplayedPlane(newstation
? 0 : SZSP_NONE
);
946 newst_additions
= this->GetWidget
<NWidgetStacked
>(WID_BRAS_SHOW_NEWST_MATRIX
);
947 newst_additions
->SetDisplayedPlane(newstation
? 0 : SZSP_NONE
);
948 newst_additions
= this->GetWidget
<NWidgetStacked
>(WID_BRAS_SHOW_NEWST_DEFSIZE
);
949 newst_additions
->SetDisplayedPlane(newstation
? 0 : SZSP_NONE
);
950 newst_additions
= this->GetWidget
<NWidgetStacked
>(WID_BRAS_SHOW_NEWST_RESIZE
);
951 newst_additions
->SetDisplayedPlane(newstation
? 0 : SZSP_NONE
);
953 this->vscroll
= this->GetScrollbar(WID_BRAS_NEWST_SCROLL
);
954 this->vscroll2
= this->GetScrollbar(WID_BRAS_MATRIX_SCROLL
);
956 this->FinishInitNested(TRANSPORT_RAIL
);
958 this->LowerWidget(_railstation
.orientation
+ WID_BRAS_PLATFORM_DIR_X
);
959 if (_settings_client
.gui
.station_dragdrop
) {
960 this->LowerWidget(WID_BRAS_PLATFORM_DRAG_N_DROP
);
962 this->LowerWidget(_settings_client
.gui
.station_numtracks
+ WID_BRAS_PLATFORM_NUM_BEGIN
);
963 this->LowerWidget(_settings_client
.gui
.station_platlength
+ WID_BRAS_PLATFORM_LEN_BEGIN
);
965 this->SetWidgetLoweredState(WID_BRAS_HIGHLIGHT_OFF
, !_settings_client
.gui
.station_show_coverage
);
966 this->SetWidgetLoweredState(WID_BRAS_HIGHLIGHT_ON
, _settings_client
.gui
.station_show_coverage
);
968 if (!newstation
|| _railstation
.station_class
>= (int)StationClass::GetClassCount()) {
969 /* New stations are not available or changed, so ensure the default station
970 * type is 'selected'. */
971 _railstation
.station_class
= STAT_CLASS_DFLT
;
972 _railstation
.station_type
= 0;
973 this->vscroll2
= nullptr;
976 _railstation
.station_count
= StationClass::Get(_railstation
.station_class
)->GetSpecCount();
977 _railstation
.station_type
= min(_railstation
.station_type
, _railstation
.station_count
- 1);
980 for (uint i
= 0; i
< StationClass::GetClassCount(); i
++) {
981 if (i
== STAT_CLASS_WAYP
) continue;
984 this->vscroll
->SetCount(count
);
985 this->vscroll
->SetPosition(Clamp(_railstation
.station_class
- 2, 0, max(this->vscroll
->GetCount() - this->vscroll
->GetCapacity(), 0)));
987 NWidgetMatrix
*matrix
= this->GetWidget
<NWidgetMatrix
>(WID_BRAS_MATRIX
);
988 matrix
->SetScrollbar(this->vscroll2
);
989 matrix
->SetCount(_railstation
.station_count
);
990 matrix
->SetClicked(_railstation
.station_type
);
994 virtual ~BuildRailStationWindow()
996 DeleteWindowById(WC_SELECT_STATION
, 0);
999 void OnPaint() override
1001 bool newstations
= _railstation
.newstations
;
1002 const StationSpec
*statspec
= newstations
? StationClass::Get(_railstation
.station_class
)->GetSpec(_railstation
.station_type
) : nullptr;
1004 if (_settings_client
.gui
.station_dragdrop
) {
1005 SetTileSelectSize(1, 1);
1007 int x
= _settings_client
.gui
.station_numtracks
;
1008 int y
= _settings_client
.gui
.station_platlength
;
1009 if (_railstation
.orientation
== AXIS_X
) Swap(x
, y
);
1010 if (!_remove_button_clicked
) {
1011 SetTileSelectSize(x
, y
);
1015 int rad
= (_settings_game
.station
.modified_catchment
) ? CA_TRAIN
: CA_UNMODIFIED
;
1017 if (_settings_client
.gui
.station_show_coverage
) SetTileSelectBigSize(-rad
, -rad
, 2 * rad
, 2 * rad
);
1019 for (uint bits
= 0; bits
< 7; bits
++) {
1020 bool disable
= bits
>= _settings_game
.station
.station_spread
;
1021 if (statspec
== nullptr) {
1022 this->SetWidgetDisabledState(bits
+ WID_BRAS_PLATFORM_NUM_1
, disable
);
1023 this->SetWidgetDisabledState(bits
+ WID_BRAS_PLATFORM_LEN_1
, disable
);
1025 this->SetWidgetDisabledState(bits
+ WID_BRAS_PLATFORM_NUM_1
, HasBit(statspec
->disallowed_platforms
, bits
) || disable
);
1026 this->SetWidgetDisabledState(bits
+ WID_BRAS_PLATFORM_LEN_1
, HasBit(statspec
->disallowed_lengths
, bits
) || disable
);
1030 this->DrawWidgets();
1032 if (this->IsShaded()) return;
1033 /* 'Accepts' and 'Supplies' texts. */
1034 NWidgetBase
*cov
= this->GetWidget
<NWidgetBase
>(WID_BRAS_COVERAGE_TEXTS
);
1035 int top
= cov
->pos_y
+ WD_PAR_VSEP_NORMAL
;
1036 int left
= cov
->pos_x
+ WD_FRAMERECT_LEFT
;
1037 int right
= cov
->pos_x
+ cov
->current_x
- WD_FRAMERECT_RIGHT
;
1038 int bottom
= cov
->pos_y
+ cov
->current_y
;
1039 top
= DrawStationCoverageAreaText(left
, right
, top
, SCT_ALL
, rad
, false) + WD_PAR_VSEP_NORMAL
;
1040 top
= DrawStationCoverageAreaText(left
, right
, top
, SCT_ALL
, rad
, true) + WD_PAR_VSEP_NORMAL
;
1041 /* Resize background if the window is too small.
1042 * Never make the window smaller to avoid oscillating if the size change affects the acceptance.
1043 * (This is the case, if making the window bigger moves the mouse into the window.) */
1045 this->coverage_height
+= top
- bottom
;
1050 void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
) override
1053 case WID_BRAS_NEWST_LIST
: {
1054 Dimension d
= {0, 0};
1055 for (uint i
= 0; i
< StationClass::GetClassCount(); i
++) {
1056 if (i
== STAT_CLASS_WAYP
) continue;
1057 d
= maxdim(d
, GetStringBoundingBox(StationClass::Get((StationClassID
)i
)->name
));
1059 size
->width
= max(size
->width
, d
.width
+ padding
.width
);
1060 this->line_height
= FONT_HEIGHT_NORMAL
+ WD_MATRIX_TOP
+ WD_MATRIX_BOTTOM
;
1061 size
->height
= 5 * this->line_height
;
1062 resize
->height
= this->line_height
;
1066 case WID_BRAS_SHOW_NEWST_TYPE
: {
1067 if (!_railstation
.newstations
) {
1073 /* If newstations exist, compute the non-zero minimal size. */
1074 Dimension d
= {0, 0};
1075 StringID str
= this->GetWidget
<NWidgetCore
>(widget
)->widget_data
;
1076 for (StationClassID statclass
= STAT_CLASS_BEGIN
; statclass
< (StationClassID
)StationClass::GetClassCount(); statclass
++) {
1077 if (statclass
== STAT_CLASS_WAYP
) continue;
1078 StationClass
*stclass
= StationClass::Get(statclass
);
1079 for (uint16 j
= 0; j
< stclass
->GetSpecCount(); j
++) {
1080 const StationSpec
*statspec
= stclass
->GetSpec(j
);
1081 SetDParam(0, (statspec
!= nullptr && statspec
->name
!= 0) ? statspec
->name
: STR_STATION_CLASS_DFLT
);
1082 d
= maxdim(d
, GetStringBoundingBox(str
));
1085 size
->width
= max(size
->width
, d
.width
+ padding
.width
);
1089 case WID_BRAS_PLATFORM_DIR_X
:
1090 case WID_BRAS_PLATFORM_DIR_Y
:
1091 case WID_BRAS_IMAGE
:
1092 size
->width
= ScaleGUITrad(64) + 2;
1093 size
->height
= ScaleGUITrad(58) + 2;
1096 case WID_BRAS_COVERAGE_TEXTS
:
1097 size
->height
= this->coverage_height
;
1100 case WID_BRAS_MATRIX
:
1107 void DrawWidget(const Rect
&r
, int widget
) const override
1109 DrawPixelInfo tmp_dpi
;
1111 switch (GB(widget
, 0, 16)) {
1112 case WID_BRAS_PLATFORM_DIR_X
:
1113 /* Set up a clipping area for the '/' station preview */
1114 if (FillDrawPixelInfo(&tmp_dpi
, r
.left
, r
.top
, r
.right
- r
.left
+ 1, r
.bottom
- r
.top
+ 1)) {
1115 DrawPixelInfo
*old_dpi
= _cur_dpi
;
1116 _cur_dpi
= &tmp_dpi
;
1117 int x
= ScaleGUITrad(31) + 1;
1118 int y
= r
.bottom
- r
.top
- ScaleGUITrad(31);
1119 if (!DrawStationTile(x
, y
, _cur_railtype
, AXIS_X
, _railstation
.station_class
, _railstation
.station_type
)) {
1120 StationPickerDrawSprite(x
, y
, STATION_RAIL
, _cur_railtype
, INVALID_ROADTYPE
, 2);
1126 case WID_BRAS_PLATFORM_DIR_Y
:
1127 /* Set up a clipping area for the '\' station preview */
1128 if (FillDrawPixelInfo(&tmp_dpi
, r
.left
, r
.top
, r
.right
- r
.left
+ 1, r
.bottom
- r
.top
+ 1)) {
1129 DrawPixelInfo
*old_dpi
= _cur_dpi
;
1130 _cur_dpi
= &tmp_dpi
;
1131 int x
= ScaleGUITrad(31) + 1;
1132 int y
= r
.bottom
- r
.top
- ScaleGUITrad(31);
1133 if (!DrawStationTile(x
, y
, _cur_railtype
, AXIS_Y
, _railstation
.station_class
, _railstation
.station_type
)) {
1134 StationPickerDrawSprite(x
, y
, STATION_RAIL
, _cur_railtype
, INVALID_ROADTYPE
, 3);
1140 case WID_BRAS_NEWST_LIST
: {
1143 for (uint i
= 0; i
< StationClass::GetClassCount(); i
++) {
1144 if (i
== STAT_CLASS_WAYP
) continue;
1145 if (this->vscroll
->IsVisible(statclass
)) {
1146 DrawString(r
.left
+ WD_MATRIX_LEFT
, r
.right
- WD_MATRIX_RIGHT
, row
* this->line_height
+ r
.top
+ WD_MATRIX_TOP
,
1147 StationClass::Get((StationClassID
)i
)->name
,
1148 (StationClassID
)i
== _railstation
.station_class
? TC_WHITE
: TC_BLACK
);
1156 case WID_BRAS_IMAGE
: {
1157 byte type
= GB(widget
, 16, 16);
1158 assert(type
< _railstation
.station_count
);
1159 /* Check station availability callback */
1160 const StationSpec
*statspec
= StationClass::Get(_railstation
.station_class
)->GetSpec(type
);
1161 if (!IsStationAvailable(statspec
)) {
1162 GfxFillRect(r
.left
+ 1, r
.top
+ 1, r
.right
- 1, r
.bottom
- 1, PC_BLACK
, FILLRECT_CHECKER
);
1165 /* Set up a clipping area for the station preview. */
1166 if (FillDrawPixelInfo(&tmp_dpi
, r
.left
, r
.top
, r
.right
- r
.left
+ 1, r
.bottom
- r
.top
+ 1)) {
1167 DrawPixelInfo
*old_dpi
= _cur_dpi
;
1168 _cur_dpi
= &tmp_dpi
;
1169 int x
= ScaleGUITrad(31) + 1;
1170 int y
= r
.bottom
- r
.top
- ScaleGUITrad(31);
1171 if (!DrawStationTile(x
, y
, _cur_railtype
, _railstation
.orientation
, _railstation
.station_class
, type
)) {
1172 StationPickerDrawSprite(x
, y
, STATION_RAIL
, _cur_railtype
, INVALID_ROADTYPE
, 2 + _railstation
.orientation
);
1181 void OnResize() override
1183 if (this->vscroll
!= nullptr) { // New stations available.
1184 this->vscroll
->SetCapacityFromWidget(this, WID_BRAS_NEWST_LIST
);
1188 void SetStringParameters(int widget
) const override
1190 if (widget
== WID_BRAS_SHOW_NEWST_TYPE
) {
1191 const StationSpec
*statspec
= StationClass::Get(_railstation
.station_class
)->GetSpec(_railstation
.station_type
);
1192 SetDParam(0, (statspec
!= nullptr && statspec
->name
!= 0) ? statspec
->name
: STR_STATION_CLASS_DFLT
);
1196 void OnClick(Point pt
, int widget
, int click_count
) override
1198 switch (GB(widget
, 0, 16)) {
1199 case WID_BRAS_PLATFORM_DIR_X
:
1200 case WID_BRAS_PLATFORM_DIR_Y
:
1201 this->RaiseWidget(_railstation
.orientation
+ WID_BRAS_PLATFORM_DIR_X
);
1202 _railstation
.orientation
= (Axis
)(widget
- WID_BRAS_PLATFORM_DIR_X
);
1203 this->LowerWidget(_railstation
.orientation
+ WID_BRAS_PLATFORM_DIR_X
);
1204 if (_settings_client
.sound
.click_beep
) SndPlayFx(SND_15_BEEP
);
1206 DeleteWindowById(WC_SELECT_STATION
, 0);
1209 case WID_BRAS_PLATFORM_NUM_1
:
1210 case WID_BRAS_PLATFORM_NUM_2
:
1211 case WID_BRAS_PLATFORM_NUM_3
:
1212 case WID_BRAS_PLATFORM_NUM_4
:
1213 case WID_BRAS_PLATFORM_NUM_5
:
1214 case WID_BRAS_PLATFORM_NUM_6
:
1215 case WID_BRAS_PLATFORM_NUM_7
: {
1216 this->RaiseWidget(_settings_client
.gui
.station_numtracks
+ WID_BRAS_PLATFORM_NUM_BEGIN
);
1217 this->RaiseWidget(WID_BRAS_PLATFORM_DRAG_N_DROP
);
1219 _settings_client
.gui
.station_numtracks
= widget
- WID_BRAS_PLATFORM_NUM_BEGIN
;
1220 _settings_client
.gui
.station_dragdrop
= false;
1222 _settings_client
.gui
.station_dragdrop
= false;
1224 const StationSpec
*statspec
= _railstation
.newstations
? StationClass::Get(_railstation
.station_class
)->GetSpec(_railstation
.station_type
) : nullptr;
1225 if (statspec
!= nullptr && HasBit(statspec
->disallowed_lengths
, _settings_client
.gui
.station_platlength
- 1)) {
1226 /* The previously selected number of platforms in invalid */
1227 for (uint i
= 0; i
< 7; i
++) {
1228 if (!HasBit(statspec
->disallowed_lengths
, i
)) {
1229 this->RaiseWidget(_settings_client
.gui
.station_platlength
+ WID_BRAS_PLATFORM_LEN_BEGIN
);
1230 _settings_client
.gui
.station_platlength
= i
+ 1;
1236 this->LowerWidget(_settings_client
.gui
.station_numtracks
+ WID_BRAS_PLATFORM_NUM_BEGIN
);
1237 this->LowerWidget(_settings_client
.gui
.station_platlength
+ WID_BRAS_PLATFORM_LEN_BEGIN
);
1238 if (_settings_client
.sound
.click_beep
) SndPlayFx(SND_15_BEEP
);
1240 DeleteWindowById(WC_SELECT_STATION
, 0);
1244 case WID_BRAS_PLATFORM_LEN_1
:
1245 case WID_BRAS_PLATFORM_LEN_2
:
1246 case WID_BRAS_PLATFORM_LEN_3
:
1247 case WID_BRAS_PLATFORM_LEN_4
:
1248 case WID_BRAS_PLATFORM_LEN_5
:
1249 case WID_BRAS_PLATFORM_LEN_6
:
1250 case WID_BRAS_PLATFORM_LEN_7
: {
1251 this->RaiseWidget(_settings_client
.gui
.station_platlength
+ WID_BRAS_PLATFORM_LEN_BEGIN
);
1252 this->RaiseWidget(WID_BRAS_PLATFORM_DRAG_N_DROP
);
1254 _settings_client
.gui
.station_platlength
= widget
- WID_BRAS_PLATFORM_LEN_BEGIN
;
1255 _settings_client
.gui
.station_dragdrop
= false;
1257 _settings_client
.gui
.station_dragdrop
= false;
1259 const StationSpec
*statspec
= _railstation
.newstations
? StationClass::Get(_railstation
.station_class
)->GetSpec(_railstation
.station_type
) : nullptr;
1260 if (statspec
!= nullptr && HasBit(statspec
->disallowed_platforms
, _settings_client
.gui
.station_numtracks
- 1)) {
1261 /* The previously selected number of tracks in invalid */
1262 for (uint i
= 0; i
< 7; i
++) {
1263 if (!HasBit(statspec
->disallowed_platforms
, i
)) {
1264 this->RaiseWidget(_settings_client
.gui
.station_numtracks
+ WID_BRAS_PLATFORM_NUM_BEGIN
);
1265 _settings_client
.gui
.station_numtracks
= i
+ 1;
1271 this->LowerWidget(_settings_client
.gui
.station_numtracks
+ WID_BRAS_PLATFORM_NUM_BEGIN
);
1272 this->LowerWidget(_settings_client
.gui
.station_platlength
+ WID_BRAS_PLATFORM_LEN_BEGIN
);
1273 if (_settings_client
.sound
.click_beep
) SndPlayFx(SND_15_BEEP
);
1275 DeleteWindowById(WC_SELECT_STATION
, 0);
1279 case WID_BRAS_PLATFORM_DRAG_N_DROP
: {
1280 _settings_client
.gui
.station_dragdrop
^= true;
1282 this->ToggleWidgetLoweredState(WID_BRAS_PLATFORM_DRAG_N_DROP
);
1284 /* get the first allowed length/number of platforms */
1285 const StationSpec
*statspec
= _railstation
.newstations
? StationClass::Get(_railstation
.station_class
)->GetSpec(_railstation
.station_type
) : nullptr;
1286 if (statspec
!= nullptr && HasBit(statspec
->disallowed_lengths
, _settings_client
.gui
.station_platlength
- 1)) {
1287 for (uint i
= 0; i
< 7; i
++) {
1288 if (!HasBit(statspec
->disallowed_lengths
, i
)) {
1289 this->RaiseWidget(_settings_client
.gui
.station_platlength
+ WID_BRAS_PLATFORM_LEN_BEGIN
);
1290 _settings_client
.gui
.station_platlength
= i
+ 1;
1295 if (statspec
!= nullptr && HasBit(statspec
->disallowed_platforms
, _settings_client
.gui
.station_numtracks
- 1)) {
1296 for (uint i
= 0; i
< 7; i
++) {
1297 if (!HasBit(statspec
->disallowed_platforms
, i
)) {
1298 this->RaiseWidget(_settings_client
.gui
.station_numtracks
+ WID_BRAS_PLATFORM_NUM_BEGIN
);
1299 _settings_client
.gui
.station_numtracks
= i
+ 1;
1305 this->SetWidgetLoweredState(_settings_client
.gui
.station_numtracks
+ WID_BRAS_PLATFORM_NUM_BEGIN
, !_settings_client
.gui
.station_dragdrop
);
1306 this->SetWidgetLoweredState(_settings_client
.gui
.station_platlength
+ WID_BRAS_PLATFORM_LEN_BEGIN
, !_settings_client
.gui
.station_dragdrop
);
1307 if (_settings_client
.sound
.click_beep
) SndPlayFx(SND_15_BEEP
);
1309 DeleteWindowById(WC_SELECT_STATION
, 0);
1313 case WID_BRAS_HIGHLIGHT_OFF
:
1314 case WID_BRAS_HIGHLIGHT_ON
:
1315 _settings_client
.gui
.station_show_coverage
= (widget
!= WID_BRAS_HIGHLIGHT_OFF
);
1317 this->SetWidgetLoweredState(WID_BRAS_HIGHLIGHT_OFF
, !_settings_client
.gui
.station_show_coverage
);
1318 this->SetWidgetLoweredState(WID_BRAS_HIGHLIGHT_ON
, _settings_client
.gui
.station_show_coverage
);
1319 if (_settings_client
.sound
.click_beep
) SndPlayFx(SND_15_BEEP
);
1323 case WID_BRAS_NEWST_LIST
: {
1324 int y
= this->vscroll
->GetScrolledRowFromWidget(pt
.y
, this, WID_BRAS_NEWST_LIST
, 0, this->line_height
);
1325 if (y
>= (int)StationClass::GetClassCount()) return;
1326 for (uint i
= 0; i
< StationClass::GetClassCount(); i
++) {
1327 if (i
== STAT_CLASS_WAYP
) continue;
1329 if (_railstation
.station_class
!= (StationClassID
)i
) {
1330 _railstation
.station_class
= (StationClassID
)i
;
1331 StationClass
*stclass
= StationClass::Get(_railstation
.station_class
);
1332 _railstation
.station_count
= stclass
->GetSpecCount();
1333 _railstation
.station_type
= min((int)_railstation
.station_type
, max(0, (int)_railstation
.station_count
- 1));
1335 this->CheckSelectedSize(stclass
->GetSpec(_railstation
.station_type
));
1337 NWidgetMatrix
*matrix
= this->GetWidget
<NWidgetMatrix
>(WID_BRAS_MATRIX
);
1338 matrix
->SetCount(_railstation
.station_count
);
1339 matrix
->SetClicked(_railstation
.station_type
);
1341 if (_settings_client
.sound
.click_beep
) SndPlayFx(SND_15_BEEP
);
1343 DeleteWindowById(WC_SELECT_STATION
, 0);
1351 case WID_BRAS_IMAGE
: {
1352 int y
= GB(widget
, 16, 16);
1353 if (y
>= _railstation
.station_count
) return;
1355 /* Check station availability callback */
1356 const StationSpec
*statspec
= StationClass::Get(_railstation
.station_class
)->GetSpec(y
);
1357 if (!IsStationAvailable(statspec
)) return;
1359 _railstation
.station_type
= y
;
1361 this->CheckSelectedSize(statspec
);
1362 this->GetWidget
<NWidgetMatrix
>(WID_BRAS_MATRIX
)->SetClicked(_railstation
.station_type
);
1364 if (_settings_client
.sound
.click_beep
) SndPlayFx(SND_15_BEEP
);
1366 DeleteWindowById(WC_SELECT_STATION
, 0);
1372 void OnRealtimeTick(uint delta_ms
) override
1374 CheckRedrawStationCoverage(this);
1378 static const NWidgetPart _nested_station_builder_widgets
[] = {
1379 NWidget(NWID_HORIZONTAL
),
1380 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
1381 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
), SetDataTip(STR_STATION_BUILD_RAIL_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
1382 NWidget(WWT_SHADEBOX
, COLOUR_DARK_GREEN
),
1383 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_BRAS_SHOW_NEWST_DEFSIZE
),
1384 NWidget(WWT_DEFSIZEBOX
, COLOUR_DARK_GREEN
),
1387 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
),
1388 NWidget(NWID_HORIZONTAL
),
1389 NWidget(NWID_VERTICAL
),
1390 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_BRAS_SHOW_NEWST_ADDITIONS
),
1391 NWidget(NWID_HORIZONTAL
), SetPIP(7, 0, 7), SetPadding(2, 0, 1, 0),
1392 NWidget(WWT_MATRIX
, COLOUR_GREY
, WID_BRAS_NEWST_LIST
), SetMinimalSize(122, 71), SetFill(1, 0),
1393 SetMatrixDataTip(1, 0, STR_STATION_BUILD_STATION_CLASS_TOOLTIP
), SetScrollbar(WID_BRAS_NEWST_SCROLL
),
1394 NWidget(NWID_VSCROLLBAR
, COLOUR_GREY
, WID_BRAS_NEWST_SCROLL
),
1397 NWidget(WWT_LABEL
, COLOUR_DARK_GREEN
), SetMinimalSize(144, 11), SetDataTip(STR_STATION_BUILD_ORIENTATION
, STR_NULL
), SetPadding(1, 2, 0, 2),
1398 NWidget(NWID_HORIZONTAL
),
1399 NWidget(NWID_SPACER
), SetMinimalSize(7, 0), SetFill(1, 0),
1400 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BRAS_PLATFORM_DIR_X
), SetMinimalSize(66, 60), SetFill(0, 0), SetDataTip(0x0, STR_STATION_BUILD_RAILROAD_ORIENTATION_TOOLTIP
), EndContainer(),
1401 NWidget(NWID_SPACER
), SetMinimalSize(2, 0), SetFill(1, 0),
1402 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BRAS_PLATFORM_DIR_Y
), SetMinimalSize(66, 60), SetFill(0, 0), SetDataTip(0x0, STR_STATION_BUILD_RAILROAD_ORIENTATION_TOOLTIP
), EndContainer(),
1403 NWidget(NWID_SPACER
), SetMinimalSize(7, 0), SetFill(1, 0),
1405 NWidget(WWT_LABEL
, COLOUR_DARK_GREEN
, WID_BRAS_SHOW_NEWST_TYPE
), SetMinimalSize(144, 11), SetDataTip(STR_ORANGE_STRING
, STR_NULL
), SetPadding(1, 2, 4, 2),
1406 NWidget(WWT_LABEL
, COLOUR_DARK_GREEN
), SetMinimalSize(144, 11), SetDataTip(STR_STATION_BUILD_NUMBER_OF_TRACKS
, STR_NULL
), SetPadding(0, 2, 0, 2),
1407 NWidget(NWID_HORIZONTAL
),
1408 NWidget(NWID_SPACER
), SetFill(1, 0),
1409 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_NUM_1
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_1
, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP
),
1410 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_NUM_2
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_2
, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP
),
1411 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_NUM_3
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_3
, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP
),
1412 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_NUM_4
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_4
, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP
),
1413 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_NUM_5
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_5
, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP
),
1414 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_NUM_6
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_6
, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP
),
1415 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_NUM_7
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_7
, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP
),
1416 NWidget(NWID_SPACER
), SetFill(1, 0),
1418 NWidget(WWT_LABEL
, COLOUR_DARK_GREEN
), SetMinimalSize(144, 11), SetDataTip(STR_STATION_BUILD_PLATFORM_LENGTH
, STR_NULL
), SetPadding(2, 2, 0, 2),
1419 NWidget(NWID_HORIZONTAL
),
1420 NWidget(NWID_SPACER
), SetFill(1, 0),
1421 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_LEN_1
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_1
, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP
),
1422 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_LEN_2
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_2
, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP
),
1423 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_LEN_3
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_3
, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP
),
1424 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_LEN_4
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_4
, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP
),
1425 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_LEN_5
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_5
, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP
),
1426 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_LEN_6
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_6
, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP
),
1427 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_LEN_7
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_7
, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP
),
1428 NWidget(NWID_SPACER
), SetFill(1, 0),
1430 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
1431 NWidget(NWID_HORIZONTAL
),
1432 NWidget(NWID_SPACER
), SetMinimalSize(2, 0), SetFill(1, 0),
1433 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_DRAG_N_DROP
), SetMinimalSize(75, 12), SetDataTip(STR_STATION_BUILD_DRAG_DROP
, STR_STATION_BUILD_DRAG_DROP_TOOLTIP
),
1434 NWidget(NWID_SPACER
), SetMinimalSize(2, 0), SetFill(1, 0),
1436 NWidget(WWT_LABEL
, COLOUR_DARK_GREEN
), SetMinimalSize(144, 11), SetDataTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE
, STR_NULL
), SetPadding(3, 2, 0, 2),
1437 NWidget(NWID_HORIZONTAL
),
1438 NWidget(NWID_SPACER
), SetMinimalSize(2, 0), SetFill(1, 0),
1439 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_HIGHLIGHT_OFF
), SetMinimalSize(60, 12),
1440 SetDataTip(STR_STATION_BUILD_COVERAGE_OFF
, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP
),
1441 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_HIGHLIGHT_ON
), SetMinimalSize(60, 12),
1442 SetDataTip(STR_STATION_BUILD_COVERAGE_ON
, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP
),
1443 NWidget(NWID_SPACER
), SetMinimalSize(2, 0), SetFill(1, 0),
1446 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_BRAS_SHOW_NEWST_MATRIX
),
1447 /* We need an additional background for the matrix, as the matrix cannot handle the scrollbar due to not being an NWidgetCore. */
1448 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
), SetScrollbar(WID_BRAS_MATRIX_SCROLL
),
1449 NWidget(NWID_HORIZONTAL
),
1450 NWidget(NWID_MATRIX
, COLOUR_DARK_GREEN
, WID_BRAS_MATRIX
), SetScrollbar(WID_BRAS_MATRIX_SCROLL
), SetPIP(0, 2, 0), SetPadding(2, 0, 0, 0),
1451 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BRAS_IMAGE
), SetMinimalSize(66, 60),
1452 SetFill(0, 0), SetResize(0, 0), SetDataTip(0x0, STR_STATION_BUILD_STATION_TYPE_TOOLTIP
), SetScrollbar(WID_BRAS_MATRIX_SCROLL
),
1455 NWidget(NWID_VSCROLLBAR
, COLOUR_DARK_GREEN
, WID_BRAS_MATRIX_SCROLL
),
1460 NWidget(NWID_HORIZONTAL
),
1461 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_BRAS_COVERAGE_TEXTS
), SetFill(1, 1), SetResize(1, 0),
1462 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_BRAS_SHOW_NEWST_RESIZE
),
1463 NWidget(NWID_VERTICAL
),
1464 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
), SetFill(0, 1), EndContainer(),
1465 NWidget(WWT_RESIZEBOX
, COLOUR_DARK_GREEN
),
1472 /** High level window description of the station-build window (default & newGRF) */
1473 static WindowDesc
_station_builder_desc(
1474 WDP_AUTO
, "build_station_rail", 350, 0,
1475 WC_BUILD_STATION
, WC_BUILD_TOOLBAR
,
1477 _nested_station_builder_widgets
, lengthof(_nested_station_builder_widgets
)
1480 /** Open station build window */
1481 static void ShowStationBuilder(Window
*parent
)
1483 bool newstations
= StationClass::GetClassCount() > 2 || StationClass::Get(STAT_CLASS_DFLT
)->GetSpecCount() != 1;
1484 new BuildRailStationWindow(&_station_builder_desc
, parent
, newstations
);
1487 struct BuildSignalWindow
: public PickerWindowBase
{
1489 Dimension sig_sprite_size
; ///< Maximum size of signal GUI sprites.
1490 int sig_sprite_bottom_offset
; ///< Maximum extent of signal GUI sprite from reference point towards bottom.
1493 * Draw dynamic a signal-sprite in a button in the signal GUI
1494 * Draw the sprite +1px to the right and down if the button is lowered
1496 * @param widget_index index of this widget in the window
1497 * @param image the sprite to draw
1499 void DrawSignalSprite(byte widget_index
, SpriteID image
) const
1502 Dimension sprite_size
= GetSpriteSize(image
, &offset
);
1503 const NWidgetBase
*widget
= this->GetWidget
<NWidgetBase
>(widget_index
);
1504 int x
= widget
->pos_x
- offset
.x
+
1505 (widget
->current_x
- sprite_size
.width
+ offset
.x
) / 2; // centered
1506 int y
= widget
->pos_y
- sig_sprite_bottom_offset
+ WD_IMGBTN_TOP
+
1507 (widget
->current_y
- WD_IMGBTN_TOP
- WD_IMGBTN_BOTTOM
+ sig_sprite_size
.height
) / 2; // aligned to bottom
1509 DrawSprite(image
, PAL_NONE
,
1510 x
+ this->IsWidgetLowered(widget_index
),
1511 y
+ this->IsWidgetLowered(widget_index
));
1515 BuildSignalWindow(WindowDesc
*desc
, Window
*parent
) : PickerWindowBase(desc
, parent
)
1517 this->InitNested(TRANSPORT_RAIL
);
1518 this->OnInvalidateData();
1521 ~BuildSignalWindow()
1523 _convert_signal_button
= false;
1526 void OnInit() override
1528 /* Calculate maximum signal sprite size. */
1529 this->sig_sprite_size
.width
= 0;
1530 this->sig_sprite_size
.height
= 0;
1531 this->sig_sprite_bottom_offset
= 0;
1532 const RailtypeInfo
*rti
= GetRailTypeInfo(_cur_railtype
);
1533 for (uint type
= SIGTYPE_NORMAL
; type
< SIGTYPE_END
; type
++) {
1534 for (uint variant
= SIG_ELECTRIC
; variant
<= SIG_SEMAPHORE
; variant
++) {
1535 for (uint lowered
= 0; lowered
< 2; lowered
++) {
1537 Dimension sprite_size
= GetSpriteSize(rti
->gui_sprites
.signals
[type
][variant
][lowered
], &offset
);
1538 this->sig_sprite_bottom_offset
= max
<int>(this->sig_sprite_bottom_offset
, sprite_size
.height
);
1539 this->sig_sprite_size
.width
= max
<int>(this->sig_sprite_size
.width
, sprite_size
.width
- offset
.x
);
1540 this->sig_sprite_size
.height
= max
<int>(this->sig_sprite_size
.height
, sprite_size
.height
- offset
.y
);
1546 void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
) override
1548 if (widget
== WID_BS_DRAG_SIGNALS_DENSITY_LABEL
) {
1549 /* Two digits for signals density. */
1550 size
->width
= max(size
->width
, 2 * GetDigitWidth() + padding
.width
+ WD_FRAMERECT_LEFT
+ WD_FRAMERECT_RIGHT
);
1551 } else if (IsInsideMM(widget
, WID_BS_SEMAPHORE_NORM
, WID_BS_ELECTRIC_PBS_OWAY
+ 1)) {
1552 size
->width
= max(size
->width
, this->sig_sprite_size
.width
+ WD_IMGBTN_LEFT
+ WD_IMGBTN_RIGHT
);
1553 size
->height
= max(size
->height
, this->sig_sprite_size
.height
+ WD_IMGBTN_TOP
+ WD_IMGBTN_BOTTOM
);
1557 void SetStringParameters(int widget
) const override
1560 case WID_BS_DRAG_SIGNALS_DENSITY_LABEL
:
1561 SetDParam(0, _settings_client
.gui
.drag_signals_density
);
1566 void DrawWidget(const Rect
&r
, int widget
) const override
1568 if (IsInsideMM(widget
, WID_BS_SEMAPHORE_NORM
, WID_BS_ELECTRIC_PBS_OWAY
+ 1)) {
1569 /* Extract signal from widget number. */
1570 int type
= (widget
- WID_BS_SEMAPHORE_NORM
) % SIGTYPE_END
;
1571 int var
= SIG_SEMAPHORE
- (widget
- WID_BS_SEMAPHORE_NORM
) / SIGTYPE_END
; // SignalVariant order is reversed compared to the widgets.
1572 SpriteID sprite
= GetRailTypeInfo(_cur_railtype
)->gui_sprites
.signals
[type
][var
][this->IsWidgetLowered(widget
)];
1574 this->DrawSignalSprite(widget
, sprite
);
1578 void OnClick(Point pt
, int widget
, int click_count
) override
1581 case WID_BS_SEMAPHORE_NORM
:
1582 case WID_BS_SEMAPHORE_ENTRY
:
1583 case WID_BS_SEMAPHORE_EXIT
:
1584 case WID_BS_SEMAPHORE_COMBO
:
1585 case WID_BS_SEMAPHORE_PBS
:
1586 case WID_BS_SEMAPHORE_PBS_OWAY
:
1587 case WID_BS_ELECTRIC_NORM
:
1588 case WID_BS_ELECTRIC_ENTRY
:
1589 case WID_BS_ELECTRIC_EXIT
:
1590 case WID_BS_ELECTRIC_COMBO
:
1591 case WID_BS_ELECTRIC_PBS
:
1592 case WID_BS_ELECTRIC_PBS_OWAY
:
1593 this->RaiseWidget((_cur_signal_variant
== SIG_ELECTRIC
? WID_BS_ELECTRIC_NORM
: WID_BS_SEMAPHORE_NORM
) + _cur_signal_type
);
1595 _cur_signal_type
= (SignalType
)((uint
)((widget
- WID_BS_SEMAPHORE_NORM
) % (SIGTYPE_LAST
+ 1)));
1596 _cur_signal_variant
= widget
>= WID_BS_ELECTRIC_NORM
? SIG_ELECTRIC
: SIG_SEMAPHORE
;
1598 /* If 'remove' button of rail build toolbar is active, disable it. */
1599 if (_remove_button_clicked
) {
1600 Window
*w
= FindWindowById(WC_BUILD_TOOLBAR
, TRANSPORT_RAIL
);
1601 if (w
!= nullptr) ToggleRailButton_Remove(w
);
1606 case WID_BS_CONVERT
:
1607 _convert_signal_button
= !_convert_signal_button
;
1610 case WID_BS_DRAG_SIGNALS_DENSITY_DECREASE
:
1611 if (_settings_client
.gui
.drag_signals_density
> 1) {
1612 _settings_client
.gui
.drag_signals_density
--;
1613 SetWindowDirty(WC_GAME_OPTIONS
, WN_GAME_OPTIONS_GAME_SETTINGS
);
1617 case WID_BS_DRAG_SIGNALS_DENSITY_INCREASE
:
1618 if (_settings_client
.gui
.drag_signals_density
< 20) {
1619 _settings_client
.gui
.drag_signals_density
++;
1620 SetWindowDirty(WC_GAME_OPTIONS
, WN_GAME_OPTIONS_GAME_SETTINGS
);
1627 this->InvalidateData();
1631 * Some data on this window has become invalid.
1632 * @param data Information about the changed data.
1633 * @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.
1635 void OnInvalidateData(int data
= 0, bool gui_scope
= true) override
1637 if (!gui_scope
) return;
1638 this->LowerWidget((_cur_signal_variant
== SIG_ELECTRIC
? WID_BS_ELECTRIC_NORM
: WID_BS_SEMAPHORE_NORM
) + _cur_signal_type
);
1640 this->SetWidgetLoweredState(WID_BS_CONVERT
, _convert_signal_button
);
1642 this->SetWidgetDisabledState(WID_BS_DRAG_SIGNALS_DENSITY_DECREASE
, _settings_client
.gui
.drag_signals_density
== 1);
1643 this->SetWidgetDisabledState(WID_BS_DRAG_SIGNALS_DENSITY_INCREASE
, _settings_client
.gui
.drag_signals_density
== 20);
1647 /** Nested widget definition of the build signal window */
1648 static const NWidgetPart _nested_signal_builder_widgets
[] = {
1649 NWidget(NWID_HORIZONTAL
),
1650 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
1651 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
), SetDataTip(STR_BUILD_SIGNAL_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
1653 NWidget(NWID_VERTICAL
, NC_EQUALSIZE
),
1654 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
1655 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_SEMAPHORE_NORM
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_SEMAPHORE_NORM_TOOLTIP
), EndContainer(), SetFill(1, 1),
1656 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_SEMAPHORE_ENTRY
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_SEMAPHORE_ENTRY_TOOLTIP
), EndContainer(), SetFill(1, 1),
1657 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_SEMAPHORE_EXIT
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_SEMAPHORE_EXIT_TOOLTIP
), EndContainer(), SetFill(1, 1),
1658 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_SEMAPHORE_COMBO
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_SEMAPHORE_COMBO_TOOLTIP
), EndContainer(), SetFill(1, 1),
1659 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_SEMAPHORE_PBS
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_SEMAPHORE_PBS_TOOLTIP
), EndContainer(), SetFill(1, 1),
1660 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_SEMAPHORE_PBS_OWAY
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_SEMAPHORE_PBS_OWAY_TOOLTIP
), EndContainer(), SetFill(1, 1),
1661 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_BS_CONVERT
), SetDataTip(SPR_IMG_SIGNAL_CONVERT
, STR_BUILD_SIGNAL_CONVERT_TOOLTIP
), SetFill(1, 1),
1663 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
1664 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_ELECTRIC_NORM
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_ELECTRIC_NORM_TOOLTIP
), EndContainer(), SetFill(1, 1),
1665 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_ELECTRIC_ENTRY
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_ELECTRIC_ENTRY_TOOLTIP
), EndContainer(), SetFill(1, 1),
1666 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_ELECTRIC_EXIT
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_ELECTRIC_EXIT_TOOLTIP
), EndContainer(), SetFill(1, 1),
1667 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_ELECTRIC_COMBO
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_ELECTRIC_COMBO_TOOLTIP
), EndContainer(), SetFill(1, 1),
1668 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_ELECTRIC_PBS
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_ELECTRIC_PBS_TOOLTIP
), EndContainer(), SetFill(1, 1),
1669 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_ELECTRIC_PBS_OWAY
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_ELECTRIC_PBS_OWAY_TOOLTIP
), EndContainer(), SetFill(1, 1),
1670 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_DRAG_SIGNALS_DENSITY_TOOLTIP
), SetFill(1, 1),
1671 NWidget(WWT_LABEL
, COLOUR_DARK_GREEN
, WID_BS_DRAG_SIGNALS_DENSITY_LABEL
), SetDataTip(STR_ORANGE_INT
, STR_BUILD_SIGNAL_DRAG_SIGNALS_DENSITY_TOOLTIP
), SetFill(1, 1),
1672 NWidget(NWID_HORIZONTAL
), SetPIP(2, 0, 2),
1673 NWidget(NWID_SPACER
), SetFill(1, 0),
1674 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_BS_DRAG_SIGNALS_DENSITY_DECREASE
), SetMinimalSize(9, 12), SetDataTip(AWV_DECREASE
, STR_BUILD_SIGNAL_DRAG_SIGNALS_DENSITY_DECREASE_TOOLTIP
),
1675 NWidget(WWT_PUSHARROWBTN
, COLOUR_GREY
, WID_BS_DRAG_SIGNALS_DENSITY_INCREASE
), SetMinimalSize(9, 12), SetDataTip(AWV_INCREASE
, STR_BUILD_SIGNAL_DRAG_SIGNALS_DENSITY_INCREASE_TOOLTIP
),
1676 NWidget(NWID_SPACER
), SetFill(1, 0),
1678 NWidget(NWID_SPACER
), SetMinimalSize(0, 2), SetFill(1, 0),
1684 /** Signal selection window description */
1685 static WindowDesc
_signal_builder_desc(
1686 WDP_AUTO
, "build_signal", 0, 0,
1687 WC_BUILD_SIGNAL
, WC_BUILD_TOOLBAR
,
1689 _nested_signal_builder_widgets
, lengthof(_nested_signal_builder_widgets
)
1693 * Open the signal selection window
1695 static void ShowSignalBuilder(Window
*parent
)
1697 new BuildSignalWindow(&_signal_builder_desc
, parent
);
1700 struct BuildRailDepotWindow
: public PickerWindowBase
{
1701 BuildRailDepotWindow(WindowDesc
*desc
, Window
*parent
) : PickerWindowBase(desc
, parent
)
1703 this->InitNested(TRANSPORT_RAIL
);
1704 this->LowerWidget(_build_depot_direction
+ WID_BRAD_DEPOT_NE
);
1707 void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
) override
1709 if (!IsInsideMM(widget
, WID_BRAD_DEPOT_NE
, WID_BRAD_DEPOT_NW
+ 1)) return;
1711 size
->width
= ScaleGUITrad(64) + 2;
1712 size
->height
= ScaleGUITrad(48) + 2;
1715 void DrawWidget(const Rect
&r
, int widget
) const override
1717 if (!IsInsideMM(widget
, WID_BRAD_DEPOT_NE
, WID_BRAD_DEPOT_NW
+ 1)) return;
1719 DrawTrainDepotSprite(r
.left
+ 1 + ScaleGUITrad(31), r
.bottom
- ScaleGUITrad(31), widget
- WID_BRAD_DEPOT_NE
+ DIAGDIR_NE
, _cur_railtype
);
1722 void OnClick(Point pt
, int widget
, int click_count
) override
1725 case WID_BRAD_DEPOT_NE
:
1726 case WID_BRAD_DEPOT_SE
:
1727 case WID_BRAD_DEPOT_SW
:
1728 case WID_BRAD_DEPOT_NW
:
1729 this->RaiseWidget(_build_depot_direction
+ WID_BRAD_DEPOT_NE
);
1730 _build_depot_direction
= (DiagDirection
)(widget
- WID_BRAD_DEPOT_NE
);
1731 this->LowerWidget(_build_depot_direction
+ WID_BRAD_DEPOT_NE
);
1732 if (_settings_client
.sound
.click_beep
) SndPlayFx(SND_15_BEEP
);
1739 /** Nested widget definition of the build rail depot window */
1740 static const NWidgetPart _nested_build_depot_widgets
[] = {
1741 NWidget(NWID_HORIZONTAL
),
1742 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
1743 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
), SetDataTip(STR_BUILD_DEPOT_TRAIN_ORIENTATION_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
1745 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
),
1746 NWidget(NWID_SPACER
), SetMinimalSize(0, 3),
1747 NWidget(NWID_HORIZONTAL_LTR
),
1748 NWidget(NWID_SPACER
), SetMinimalSize(3, 0), SetFill(1, 0),
1749 NWidget(NWID_VERTICAL
),
1750 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BRAD_DEPOT_NW
), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_TRAIN_ORIENTATION_TOOLTIP
),
1752 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
1753 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BRAD_DEPOT_SW
), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_TRAIN_ORIENTATION_TOOLTIP
),
1756 NWidget(NWID_SPACER
), SetMinimalSize(2, 0),
1757 NWidget(NWID_VERTICAL
),
1758 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BRAD_DEPOT_NE
), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_TRAIN_ORIENTATION_TOOLTIP
),
1760 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
1761 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BRAD_DEPOT_SE
), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_TRAIN_ORIENTATION_TOOLTIP
),
1764 NWidget(NWID_SPACER
), SetMinimalSize(3, 0), SetFill(1, 0),
1766 NWidget(NWID_SPACER
), SetMinimalSize(0, 3),
1770 static WindowDesc
_build_depot_desc(
1771 WDP_AUTO
, nullptr, 0, 0,
1772 WC_BUILD_DEPOT
, WC_BUILD_TOOLBAR
,
1774 _nested_build_depot_widgets
, lengthof(_nested_build_depot_widgets
)
1777 static void ShowBuildTrainDepotPicker(Window
*parent
)
1779 new BuildRailDepotWindow(&_build_depot_desc
, parent
);
1782 struct BuildRailWaypointWindow
: PickerWindowBase
{
1783 BuildRailWaypointWindow(WindowDesc
*desc
, Window
*parent
) : PickerWindowBase(desc
, parent
)
1785 this->CreateNestedTree();
1787 NWidgetMatrix
*matrix
= this->GetWidget
<NWidgetMatrix
>(WID_BRW_WAYPOINT_MATRIX
);
1788 matrix
->SetScrollbar(this->GetScrollbar(WID_BRW_SCROLL
));
1790 this->FinishInitNested(TRANSPORT_RAIL
);
1792 matrix
->SetCount(_waypoint_count
);
1793 matrix
->SetClicked(_cur_waypoint_type
);
1796 void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
) override
1799 case WID_BRW_WAYPOINT_MATRIX
:
1800 /* Three blobs high and wide. */
1801 size
->width
+= resize
->width
* 2;
1802 size
->height
+= resize
->height
* 2;
1804 /* Resizing in X direction only at blob size, but at pixel level in Y. */
1808 case WID_BRW_WAYPOINT
:
1809 size
->width
= ScaleGUITrad(64) + 2;
1810 size
->height
= ScaleGUITrad(58) + 2;
1815 void DrawWidget(const Rect
&r
, int widget
) const override
1817 switch (GB(widget
, 0, 16)) {
1818 case WID_BRW_WAYPOINT
: {
1819 byte type
= GB(widget
, 16, 16);
1820 const StationSpec
*statspec
= StationClass::Get(STAT_CLASS_WAYP
)->GetSpec(type
);
1821 DrawWaypointSprite(r
.left
+ 1 + ScaleGUITrad(31), r
.bottom
- ScaleGUITrad(31), type
, _cur_railtype
);
1823 if (!IsStationAvailable(statspec
)) {
1824 GfxFillRect(r
.left
+ 1, r
.top
+ 1, r
.right
- 1, r
.bottom
- 1, PC_BLACK
, FILLRECT_CHECKER
);
1830 void OnClick(Point pt
, int widget
, int click_count
) override
1832 switch (GB(widget
, 0, 16)) {
1833 case WID_BRW_WAYPOINT
: {
1834 byte type
= GB(widget
, 16, 16);
1835 this->GetWidget
<NWidgetMatrix
>(WID_BRW_WAYPOINT_MATRIX
)->SetClicked(_cur_waypoint_type
);
1837 /* Check station availability callback */
1838 const StationSpec
*statspec
= StationClass::Get(STAT_CLASS_WAYP
)->GetSpec(type
);
1839 if (!IsStationAvailable(statspec
)) return;
1841 _cur_waypoint_type
= type
;
1842 this->GetWidget
<NWidgetMatrix
>(WID_BRW_WAYPOINT_MATRIX
)->SetClicked(_cur_waypoint_type
);
1843 if (_settings_client
.sound
.click_beep
) SndPlayFx(SND_15_BEEP
);
1851 /** Nested widget definition for the build NewGRF rail waypoint window */
1852 static const NWidgetPart _nested_build_waypoint_widgets
[] = {
1853 NWidget(NWID_HORIZONTAL
),
1854 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
1855 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
), SetDataTip(STR_WAYPOINT_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
1856 NWidget(WWT_DEFSIZEBOX
, COLOUR_DARK_GREEN
),
1858 NWidget(NWID_HORIZONTAL
),
1859 NWidget(NWID_MATRIX
, COLOUR_DARK_GREEN
, WID_BRW_WAYPOINT_MATRIX
), SetPIP(3, 2, 3), SetScrollbar(WID_BRW_SCROLL
),
1860 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BRW_WAYPOINT
), SetMinimalSize(66, 60), SetDataTip(0x0, STR_WAYPOINT_GRAPHICS_TOOLTIP
), SetScrollbar(WID_BRW_SCROLL
), EndContainer(),
1862 NWidget(NWID_VERTICAL
),
1863 NWidget(NWID_VSCROLLBAR
, COLOUR_DARK_GREEN
, WID_BRW_SCROLL
),
1864 NWidget(WWT_RESIZEBOX
, COLOUR_DARK_GREEN
),
1869 static WindowDesc
_build_waypoint_desc(
1870 WDP_AUTO
, "build_waypoint", 0, 0,
1871 WC_BUILD_WAYPOINT
, WC_BUILD_TOOLBAR
,
1873 _nested_build_waypoint_widgets
, lengthof(_nested_build_waypoint_widgets
)
1876 static void ShowBuildWaypointPicker(Window
*parent
)
1878 new BuildRailWaypointWindow(&_build_waypoint_desc
, parent
);
1882 * Initialize rail building GUI settings
1884 void InitializeRailGui()
1886 _build_depot_direction
= DIAGDIR_NW
;
1890 * Re-initialize rail-build toolbar after toggling support for electric trains
1891 * @param disable Boolean whether electric trains are disabled (removed from the game)
1893 void ReinitGuiAfterToggleElrail(bool disable
)
1895 extern RailType _last_built_railtype
;
1896 if (disable
&& _last_built_railtype
== RAILTYPE_ELECTRIC
) {
1897 _last_built_railtype
= _cur_railtype
= RAILTYPE_RAIL
;
1898 BuildRailToolbarWindow
*w
= dynamic_cast<BuildRailToolbarWindow
*>(FindWindowById(WC_BUILD_TOOLBAR
, TRANSPORT_RAIL
));
1899 if (w
!= nullptr) w
->ModifyRailType(_cur_railtype
);
1901 MarkWholeScreenDirty();
1904 /** Set the initial (default) railtype to use */
1905 static void SetDefaultRailGui()
1907 if (_local_company
== COMPANY_SPECTATOR
|| !Company::IsValidID(_local_company
)) return;
1909 extern RailType _last_built_railtype
;
1910 RailType rt
= (RailType
)(_settings_client
.gui
.default_rail_type
+ RAILTYPE_END
);
1911 if (rt
== DEF_RAILTYPE_MOST_USED
) {
1912 /* Find the most used rail type */
1913 uint count
[RAILTYPE_END
];
1914 memset(count
, 0, sizeof(count
));
1915 for (TileIndex t
= 0; t
< MapSize(); t
++) {
1916 if (IsTileType(t
, MP_RAILWAY
) || IsLevelCrossingTile(t
) || HasStationTileRail(t
) ||
1917 (IsTileType(t
, MP_TUNNELBRIDGE
) && GetTunnelBridgeTransportType(t
) == TRANSPORT_RAIL
)) {
1918 count
[GetRailType(t
)]++;
1923 for (RailType r
= RAILTYPE_ELECTRIC
; r
< RAILTYPE_END
; r
++) {
1924 if (count
[r
] >= count
[rt
]) rt
= r
;
1927 /* No rail, just get the first available one */
1928 if (count
[rt
] == 0) rt
= DEF_RAILTYPE_FIRST
;
1931 case DEF_RAILTYPE_FIRST
:
1933 while (rt
< RAILTYPE_END
&& !HasRailtypeAvail(_local_company
, rt
)) rt
++;
1936 case DEF_RAILTYPE_LAST
:
1937 rt
= GetBestRailtype(_local_company
);
1944 _last_built_railtype
= _cur_railtype
= rt
;
1945 BuildRailToolbarWindow
*w
= dynamic_cast<BuildRailToolbarWindow
*>(FindWindowById(WC_BUILD_TOOLBAR
, TRANSPORT_RAIL
));
1946 if (w
!= nullptr) w
->ModifyRailType(_cur_railtype
);
1950 * Updates the current signal variant used in the signal GUI
1951 * to the one adequate to current year.
1952 * @param p needed to be called when a setting changes
1953 * @return success, needed for settings
1955 bool ResetSignalVariant(int32 p
)
1957 SignalVariant new_variant
= (_cur_year
< _settings_client
.gui
.semaphore_build_before
? SIG_SEMAPHORE
: SIG_ELECTRIC
);
1959 if (new_variant
!= _cur_signal_variant
) {
1960 Window
*w
= FindWindowById(WC_BUILD_SIGNAL
, 0);
1963 w
->RaiseWidget((_cur_signal_variant
== SIG_ELECTRIC
? WID_BS_ELECTRIC_NORM
: WID_BS_SEMAPHORE_NORM
) + _cur_signal_type
);
1965 _cur_signal_variant
= new_variant
;
1972 * Resets the rail GUI - sets default railtype to build
1973 * and resets the signal GUI
1975 void InitializeRailGUI()
1977 SetDefaultRailGui();
1979 _convert_signal_button
= false;
1980 _cur_signal_type
= _default_signal_type
[_settings_client
.gui
.default_signal_type
];
1981 ResetSignalVariant();
1985 * Create a drop down list for all the rail types of the local company.
1986 * @param for_replacement Whether this list is for the replacement window.
1987 * @param all_option Whether to add an 'all types' item.
1988 * @return The populated and sorted #DropDownList.
1990 DropDownList
GetRailTypeDropDownList(bool for_replacement
, bool all_option
)
1992 RailTypes used_railtypes
;
1993 RailTypes avail_railtypes
;
1995 const Company
*c
= Company::Get(_local_company
);
1997 /* Find the used railtypes. */
1998 if (for_replacement
) {
1999 avail_railtypes
= GetCompanyRailtypes(c
->index
, false);
2000 used_railtypes
= GetRailTypes(false);
2002 avail_railtypes
= c
->avail_railtypes
;
2003 used_railtypes
= GetRailTypes(true);
2009 list
.emplace_back(new DropDownListStringItem(STR_REPLACE_ALL_RAILTYPE
, INVALID_RAILTYPE
, false));
2012 Dimension d
= { 0, 0 };
2014 /* Get largest icon size, to ensure text is aligned on each menu item. */
2015 if (!for_replacement
) {
2016 FOR_ALL_SORTED_RAILTYPES(rt
) {
2017 if (!HasBit(used_railtypes
, rt
)) continue;
2018 const RailtypeInfo
*rti
= GetRailTypeInfo(rt
);
2019 d
= maxdim(d
, GetSpriteSize(rti
->gui_sprites
.build_x_rail
));
2023 FOR_ALL_SORTED_RAILTYPES(rt
) {
2024 /* If it's not used ever, don't show it to the user. */
2025 if (!HasBit(used_railtypes
, rt
)) continue;
2027 const RailtypeInfo
*rti
= GetRailTypeInfo(rt
);
2029 StringID str
= for_replacement
? rti
->strings
.replace_text
: (rti
->max_speed
> 0 ? STR_TOOLBAR_RAILTYPE_VELOCITY
: STR_JUST_STRING
);
2030 DropDownListParamStringItem
*item
;
2031 if (for_replacement
) {
2032 item
= new DropDownListParamStringItem(str
, rt
, !HasBit(avail_railtypes
, rt
));
2034 DropDownListIconItem
*iconitem
= new DropDownListIconItem(rti
->gui_sprites
.build_x_rail
, PAL_NONE
, str
, rt
, !HasBit(avail_railtypes
, rt
));
2035 iconitem
->SetDimension(d
);
2038 item
->SetParam(0, rti
->strings
.menu_text
);
2039 item
->SetParam(1, rti
->max_speed
);
2040 list
.emplace_back(item
);