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"
37 #include "tracerestrict.h"
38 #include "logic_signals.h"
41 #include "station_map.h"
42 #include "tunnelbridge_map.h"
44 #include "widgets/rail_widget.h"
46 #include "safeguards.h"
49 static RailType _cur_railtype
; ///< Rail type of the current build-rail toolbar.
50 static bool _remove_button_clicked
; ///< Flag whether 'remove' toggle-button is currently enabled
51 static DiagDirection _build_depot_direction
; ///< Currently selected depot direction
52 static byte _waypoint_count
= 1; ///< Number of waypoint types
53 static byte _cur_waypoint_type
; ///< Currently selected waypoint type
54 static bool _convert_signal_button
; ///< convert signal button in the signal GUI pressed
55 static bool _trace_restrict_button
; ///< trace restrict button in the signal GUI pressed
56 static SignalVariant _cur_signal_variant
; ///< set the signal variant (for signal GUI)
57 static SignalType _cur_signal_type
; ///< set the signal type (for signal GUI)
59 extern TileIndex _rail_track_endtile
;
61 /* Map the setting: default_signal_type to the corresponding signal type */
62 static const SignalType _default_signal_type
[] = {SIGTYPE_NORMAL
, SIGTYPE_PBS
, SIGTYPE_PBS_ONEWAY
};
64 static const int HOTKEY_POLYRAIL
= 0x1000;
65 static const int HOTKEY_NEW_POLYRAIL
= 0x1001;
67 struct RailStationGUISettings
{
68 Axis orientation
; ///< Currently selected rail station orientation
70 bool newstations
; ///< Are custom station definitions available?
71 StationClassID station_class
; ///< Currently selected custom station class (if newstations is \c true )
72 byte station_type
; ///< %Station type within the currently selected custom station class (if newstations is \c true )
73 byte station_count
; ///< Number of custom stations (if newstations is \c true )
75 static RailStationGUISettings _railstation
; ///< Settings of the station builder GUI
78 static void HandleStationPlacement(TileIndex start
, TileIndex end
);
79 static void ShowBuildTrainDepotPicker(Window
*parent
);
80 static void ShowBuildWaypointPicker(Window
*parent
);
81 static void ShowStationBuilder(Window
*parent
);
82 static void ShowSignalBuilder(Window
*parent
);
85 * Check whether a station type can be build.
86 * @return true if building is allowed.
88 static bool IsStationAvailable(const StationSpec
*statspec
)
90 if (statspec
== NULL
|| !HasBit(statspec
->callback_mask
, CBM_STATION_AVAIL
)) return true;
92 uint16 cb_res
= GetStationCallback(CBID_STATION_AVAILABILITY
, 0, 0, statspec
, NULL
, INVALID_TILE
);
93 if (cb_res
== CALLBACK_FAILED
) return true;
95 return Convert8bitBooleanCallback(statspec
->grf_prop
.grffile
, CBID_STATION_AVAILABILITY
, cb_res
);
98 void CcPlaySound_SPLAT_RAIL(const CommandCost
&result
, TileIndex tile
, uint32 p1
, uint32 p2
)
100 if (result
.Succeeded() && _settings_client
.sound
.confirm
) SndPlayTileFx(SND_20_SPLAT_RAIL
, tile
);
103 static CommandContainer
GenericPlaceRailCmd(TileIndex tile
, Track track
)
105 CommandContainer ret
= {
107 (uint32
)_cur_railtype
, // p1
109 _remove_button_clicked
?
110 CMD_REMOVE_SINGLE_RAIL
| CMD_MSG(STR_ERROR_CAN_T_REMOVE_RAILROAD_TRACK
) :
111 CMD_BUILD_SINGLE_RAIL
| CMD_MSG(STR_ERROR_CAN_T_BUILD_RAILROAD_TRACK
), // cmd
112 CcPlaySound_SPLAT_RAIL
, // callback
121 * Try to add an additional rail-track at the entrance of a depot
122 * @param tile Tile to use for adding the rail-track
123 * @param dir Direction to check for already present tracks
124 * @param track Track to add
127 static void PlaceExtraDepotRail(TileIndex tile
, DiagDirection dir
, Track track
)
129 if (GetRailTileType(tile
) != RAIL_TILE_NORMAL
) return;
130 if ((GetTrackBits(tile
) & DiagdirReachesTracks(dir
)) == 0) return;
132 DoCommandP(tile
, _cur_railtype
, track
, CMD_BUILD_SINGLE_RAIL
);
135 /** Additional pieces of track to add at the entrance of a depot. */
136 static const Track _place_depot_extra_track
[12] = {
137 TRACK_LEFT
, TRACK_UPPER
, TRACK_UPPER
, TRACK_RIGHT
, // First additional track for directions 0..3
138 TRACK_X
, TRACK_Y
, TRACK_X
, TRACK_Y
, // Second additional track
139 TRACK_LOWER
, TRACK_LEFT
, TRACK_RIGHT
, TRACK_LOWER
, // Third additional track
142 /** Direction to check for existing track pieces. */
143 static const DiagDirection _place_depot_extra_dir
[12] = {
144 DIAGDIR_SE
, DIAGDIR_SW
, DIAGDIR_SE
, DIAGDIR_SW
,
145 DIAGDIR_SW
, DIAGDIR_NW
, DIAGDIR_NE
, DIAGDIR_SE
,
146 DIAGDIR_NW
, DIAGDIR_NE
, DIAGDIR_NW
, DIAGDIR_NE
,
149 void CcRailDepot(const CommandCost
&result
, TileIndex tile
, uint32 p1
, uint32 p2
)
151 if (result
.Failed()) return;
153 DiagDirection dir
= (DiagDirection
)p2
;
155 if (_settings_client
.sound
.confirm
) SndPlayTileFx(SND_20_SPLAT_RAIL
, tile
);
156 if (!_settings_client
.gui
.persistent_buildingtools
) ResetObjectToPlace();
158 tile
+= TileOffsByDiagDir(dir
);
160 if (IsTileType(tile
, MP_RAILWAY
)) {
161 PlaceExtraDepotRail(tile
, _place_depot_extra_dir
[dir
], _place_depot_extra_track
[dir
]);
162 PlaceExtraDepotRail(tile
, _place_depot_extra_dir
[dir
+ 4], _place_depot_extra_track
[dir
+ 4]);
163 PlaceExtraDepotRail(tile
, _place_depot_extra_dir
[dir
+ 8], _place_depot_extra_track
[dir
+ 8]);
168 * Place a rail waypoint.
169 * @param tile Position to start dragging a waypoint.
171 static void PlaceRail_Waypoint(TileIndex tile
)
173 if (_remove_button_clicked
) {
174 VpStartPlaceSizing(tile
, VPM_X_AND_Y
, DDSP_REMOVE_STATION
);
178 Axis axis
= GetAxisForNewWaypoint(tile
);
179 if (IsValidAxis(axis
)) {
180 /* Valid tile for waypoints */
181 VpStartPlaceSizing(tile
, axis
== AXIS_X
? VPM_X_LIMITED
: VPM_Y_LIMITED
, DDSP_BUILD_STATION
);
182 VpSetPlaceSizingLimit(_settings_game
.station
.station_spread
);
184 /* Tile where we can't build rail waypoints. This is always going to fail,
185 * but provides the user with a proper error message. */
186 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
));
190 void CcStation(const CommandCost
&result
, TileIndex tile
, uint32 p1
, uint32 p2
)
192 if (result
.Failed()) return;
194 if (_settings_client
.sound
.confirm
) SndPlayTileFx(SND_20_SPLAT_RAIL
, tile
);
195 /* Only close the station builder window if the default station and non persistent building is chosen. */
196 if (_railstation
.station_class
== STAT_CLASS_DFLT
&& _railstation
.station_type
== 0 && !_settings_client
.gui
.persistent_buildingtools
) ResetObjectToPlace();
200 * Place a rail station.
201 * @param tile Position to place or start dragging a station.
203 static void PlaceRail_Station(TileIndex tile
)
205 if (_remove_button_clicked
) {
206 VpStartPlaceSizing(tile
, VPM_X_AND_Y_LIMITED
, DDSP_REMOVE_STATION
);
207 VpSetPlaceSizingLimit(-1);
208 } else if (_settings_client
.gui
.station_dragdrop
) {
209 VpStartPlaceSizing(tile
, VPM_X_AND_Y_LIMITED
, DDSP_BUILD_STATION
);
210 VpSetPlaceSizingLimit(_settings_game
.station
.station_spread
);
212 uint32 p1
= _cur_railtype
| _railstation
.orientation
<< 5 | _settings_client
.gui
.station_numtracks
<< 8 | _settings_client
.gui
.station_platlength
<< 16 | _ctrl_pressed
<< 24;
213 uint32 p2
= _railstation
.station_class
| _railstation
.station_type
<< 8 | INVALID_STATION
<< 16;
215 int w
= _settings_client
.gui
.station_numtracks
;
216 int h
= _settings_client
.gui
.station_platlength
;
217 if (!_railstation
.orientation
) Swap(w
, h
);
219 CommandContainer cmdcont
= { tile
, p1
, p2
, CMD_BUILD_RAIL_STATION
| CMD_MSG(STR_ERROR_CAN_T_BUILD_RAILROAD_STATION
), CcStation
, 0, "" };
220 ShowSelectStationIfNeeded(cmdcont
, TileArea(tile
, w
, h
));
225 * Build a new signal or edit/remove a present signal, use CmdBuildSingleSignal() or CmdRemoveSingleSignal() in rail_cmd.cpp
227 * @param tile The tile where the signal will build or edit
229 static void GenericPlaceSignals(TileIndex tile
)
231 TrackBits trackbits
= TrackStatusToTrackBits(GetTileTrackStatus(tile
, TRANSPORT_RAIL
, 0));
233 if (trackbits
& TRACK_BIT_VERT
) { // N-S direction
234 trackbits
= (_tile_fract_coords
.x
<= _tile_fract_coords
.y
) ? TRACK_BIT_RIGHT
: TRACK_BIT_LEFT
;
237 if (trackbits
& TRACK_BIT_HORZ
) { // E-W direction
238 trackbits
= (_tile_fract_coords
.x
+ _tile_fract_coords
.y
<= 15) ? TRACK_BIT_UPPER
: TRACK_BIT_LOWER
;
241 Track track
= FindFirstTrack(trackbits
);
243 if (_remove_button_clicked
) {
244 DoCommandP(tile
, track
, 0, CMD_REMOVE_SIGNALS
| CMD_MSG(STR_ERROR_CAN_T_REMOVE_SIGNALS_FROM
), CcPlaySound_SPLAT_RAIL
);
245 } else if (_trace_restrict_button
) {
246 if (IsPlainRailTile(tile
) && HasTrack(tile
, track
) && HasSignalOnTrack(tile
, track
)) {
247 ShowTraceRestrictProgramWindow(tile
, track
);
250 const Window
*w
= FindWindowById(WC_BUILD_SIGNAL
, 0);
252 /* Map the setting cycle_signal_types to the lower and upper allowed signal type. */
253 static const uint cycle_bounds
[] = {SIGTYPE_NORMAL
| (SIGTYPE_LAST_NOPBS
<< 3), SIGTYPE_PBS
| (SIGTYPE_LAST
<< 3), SIGTYPE_NORMAL
| (SIGTYPE_LAST
<< 3)};
255 /* various bitstuffed elements for CmdBuildSingleSignal() */
259 /* signal GUI is used */
260 SB(p1
, 3, 1, _ctrl_pressed
);
261 SB(p1
, 4, 1, _cur_signal_variant
);
262 SB(p1
, 5, 3, _cur_signal_type
);
263 SB(p1
, 8, 1, _convert_signal_button
);
264 SB(p1
, 9, 6, cycle_bounds
[_settings_client
.gui
.cycle_signal_types
]);
266 SB(p1
, 3, 1, _ctrl_pressed
);
267 SB(p1
, 4, 1, (_cur_year
< _settings_client
.gui
.semaphore_build_before
? SIG_SEMAPHORE
: SIG_ELECTRIC
));
268 SB(p1
, 5, 3, _default_signal_type
[_settings_client
.gui
.default_signal_type
]);
270 SB(p1
, 9, 6, cycle_bounds
[_settings_client
.gui
.cycle_signal_types
]);
273 DoCommandP(tile
, p1
, 0, CMD_BUILD_SIGNALS
|
274 CMD_MSG((w
!= NULL
&& _convert_signal_button
) ? STR_ERROR_SIGNAL_CAN_T_CONVERT_SIGNALS_HERE
: STR_ERROR_CAN_T_BUILD_SIGNALS_HERE
),
275 CcPlaySound_SPLAT_RAIL
);
280 * Start placing a rail bridge.
281 * @param tile Position of the first tile of the bridge.
282 * @param w Rail toolbar window.
284 static void PlaceRail_Bridge(TileIndex tile
, Window
*w
)
286 if (IsBridgeTile(tile
)) {
287 TileIndex other_tile
= GetOtherTunnelBridgeEnd(tile
);
289 w
->OnPlaceMouseUp(VPM_X_OR_Y
, DDSP_BUILD_BRIDGE
, pt
, other_tile
, tile
);
291 VpStartPlaceSizing(tile
, VPM_X_OR_Y
, DDSP_BUILD_BRIDGE
);
295 /** Command callback for building a tunnel */
296 void CcBuildRailTunnel(const CommandCost
&result
, TileIndex tile
, uint32 p1
, uint32 p2
)
298 if (result
.Succeeded()) {
299 if (_settings_client
.sound
.confirm
) SndPlayTileFx(SND_20_SPLAT_RAIL
, tile
);
300 if (!_settings_client
.gui
.persistent_buildingtools
) ResetObjectToPlace();
301 StoreRailPlacementEndpoints(tile
, _build_tunnel_endtile
, TileX(tile
) == TileX(_build_tunnel_endtile
) ? TRACK_Y
: TRACK_X
, false);
303 SetRedErrorSquare(_build_tunnel_endtile
);
308 * Toggles state of the Remove button of Build rail toolbar
309 * @param w window the button belongs to
311 static void ToggleRailButton_Remove(Window
*w
)
313 DeleteWindowById(WC_SELECT_STATION
, 0);
314 w
->ToggleWidgetLoweredState(WID_RAT_REMOVE
);
315 w
->SetWidgetDirty(WID_RAT_REMOVE
);
316 _remove_button_clicked
= w
->IsWidgetLowered(WID_RAT_REMOVE
);
317 SetSelectionRed(_remove_button_clicked
);
321 * Updates the Remove button because of Ctrl state change
322 * @param w window the button belongs to
323 * @return true iff the remove button was changed
325 static bool RailToolbar_CtrlChanged(Window
*w
)
327 if (w
->IsWidgetDisabled(WID_RAT_REMOVE
)) return false;
329 /* allow ctrl to switch remove mode only for these widgets */
330 for (uint i
= WID_RAT_BUILD_NS
; i
<= WID_RAT_BUILD_STATION
; i
++) {
331 if ((i
<= WID_RAT_POLYRAIL
|| i
>= WID_RAT_BUILD_WAYPOINT
) && w
->IsWidgetLowered(i
)) {
332 ToggleRailButton_Remove(w
);
342 * The "remove"-button click proc of the build-rail toolbar.
343 * @param w Build-rail toolbar window
344 * @see BuildRailToolbarWindow::OnClick()
346 static void BuildRailClick_Remove(Window
*w
)
348 if (w
->IsWidgetDisabled(WID_RAT_REMOVE
)) return;
349 ToggleRailButton_Remove(w
);
350 if (_settings_client
.sound
.click_beep
) SndPlayFx(SND_15_BEEP
);
352 /* handle station builder */
353 if (w
->IsWidgetLowered(WID_RAT_BUILD_STATION
)) {
354 if (_remove_button_clicked
) {
355 /* starting drag & drop remove */
356 if (!_settings_client
.gui
.station_dragdrop
) {
357 SetTileSelectSize(1, 1);
359 VpSetPlaceSizingLimit(-1);
362 /* starting station build mode */
363 if (!_settings_client
.gui
.station_dragdrop
) {
364 int x
= _settings_client
.gui
.station_numtracks
;
365 int y
= _settings_client
.gui
.station_platlength
;
366 if (_railstation
.orientation
== 0) Swap(x
, y
);
367 SetTileSelectSize(x
, y
);
369 VpSetPlaceSizingLimit(_settings_game
.station
.station_spread
);
375 static CommandContainer
DoRailroadTrackCmd(TileIndex start_tile
, TileIndex end_tile
, Track track
)
377 CommandContainer ret
= {
380 (uint32
)(_cur_railtype
| (track
<< 5)), // p2
381 (uint32
)(_remove_button_clicked
?
382 CMD_REMOVE_RAILROAD_TRACK
| CMD_MSG(STR_ERROR_CAN_T_REMOVE_RAILROAD_TRACK
) :
383 CMD_BUILD_RAILROAD_TRACK
| CMD_MSG(STR_ERROR_CAN_T_BUILD_RAILROAD_TRACK
)), // cmd
384 CcPlaySound_SPLAT_RAIL
, // callback
392 static void HandleAutodirPlacement()
394 Track track
= (Track
)(_thd
.drawstyle
& HT_DIR_MASK
); // 0..5
395 TileIndex start_tile
= TileVirtXY(_thd
.selstart
.x
, _thd
.selstart
.y
);
396 TileIndex end_tile
= TileVirtXY(_thd
.selend
.x
, _thd
.selend
.y
);
398 CommandContainer cmd
= (_thd
.drawstyle
& HT_RAIL
) ?
399 GenericPlaceRailCmd(end_tile
, track
) : // one tile case
400 DoRailroadTrackCmd(start_tile
, end_tile
, track
); // multitile selection
402 /* When overbuilding existing tracks in polyline mode we just want to move the
403 * snap point without altering the user with the "already built" error. Don't
404 * execute the command right away, firstly check if tracks are being overbuilt. */
405 if (!(_thd
.place_mode
& HT_POLY
) || _shift_pressed
||
406 DoCommand(&cmd
, DC_AUTO
| DC_NO_WATER
).GetErrorMessage() != STR_ERROR_ALREADY_BUILT
) {
408 if (!DoCommandP(&cmd
)) return;
411 /* save new snap points for the polyline tool */
412 if (!_shift_pressed
&& _rail_track_endtile
!= INVALID_TILE
) {
413 StoreRailPlacementEndpoints(start_tile
, _rail_track_endtile
, track
, true);
418 * Build new signals or remove signals or (if only one tile marked) edit a signal.
420 * If one tile marked abort and use GenericPlaceSignals()
421 * else use CmdBuildSingleSignal() or CmdRemoveSingleSignal() in rail_cmd.cpp to build many signals
423 static void HandleAutoSignalPlacement()
425 uint32 p2
= GB(_thd
.drawstyle
, 0, 3); // 0..5
427 if ((_thd
.drawstyle
& HT_DRAG_MASK
) == HT_RECT
) { // one tile case
428 GenericPlaceSignals(TileVirtXY(_thd
.selend
.x
, _thd
.selend
.y
));
432 const Window
*w
= FindWindowById(WC_BUILD_SIGNAL
, 0);
435 /* signal GUI is used */
437 SB(p2
, 4, 1, _cur_signal_variant
);
438 SB(p2
, 6, 1, _ctrl_pressed
);
439 SB(p2
, 7, 3, _cur_signal_type
);
440 SB(p2
, 24, 8, _settings_client
.gui
.drag_signals_density
);
441 SB(p2
, 10, 1, !_settings_client
.gui
.drag_signals_fixed_distance
);
444 SB(p2
, 4, 1, (_cur_year
< _settings_client
.gui
.semaphore_build_before
? SIG_SEMAPHORE
: SIG_ELECTRIC
));
445 SB(p2
, 6, 1, _ctrl_pressed
);
446 SB(p2
, 7, 3, _default_signal_type
[_settings_client
.gui
.default_signal_type
]);
447 SB(p2
, 24, 8, _settings_client
.gui
.drag_signals_density
);
448 SB(p2
, 10, 1, !_settings_client
.gui
.drag_signals_fixed_distance
);
451 /* _settings_client.gui.drag_signals_density is given as a parameter such that each user
452 * in a network game can specify his/her own signal density */
453 DoCommandP(TileVirtXY(_thd
.selstart
.x
, _thd
.selstart
.y
), TileVirtXY(_thd
.selend
.x
, _thd
.selend
.y
), p2
,
454 _remove_button_clicked
?
455 CMD_REMOVE_SIGNAL_TRACK
| CMD_MSG(STR_ERROR_CAN_T_REMOVE_SIGNALS_FROM
) :
456 CMD_BUILD_SIGNAL_TRACK
| CMD_MSG(STR_ERROR_CAN_T_BUILD_SIGNALS_HERE
),
457 CcPlaySound_SPLAT_RAIL
);
461 /** Rail toolbar management class. */
462 struct BuildRailToolbarWindow
: Window
{
463 RailType railtype
; ///< Rail type to build.
464 int last_user_action
; ///< Last started user action.
466 BuildRailToolbarWindow(WindowDesc
*desc
, RailType railtype
) : Window(desc
)
468 this->InitNested(TRANSPORT_RAIL
);
469 this->SetupRailToolbar(railtype
);
470 this->DisableWidget(WID_RAT_REMOVE
);
471 this->last_user_action
= WIDGET_LIST_END
;
473 if (_settings_client
.gui
.link_terraform_toolbar
) ShowTerraformToolbar(this);
476 ~BuildRailToolbarWindow()
478 if (_settings_client
.gui
.link_terraform_toolbar
) DeleteWindowById(WC_SCEN_LAND_GEN
, 0, false);
482 * Some data on this window has become invalid.
483 * @param data Information about the changed data.
484 * @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.
486 virtual void OnInvalidateData(int data
= 0, bool gui_scope
= true)
488 if (!gui_scope
) return;
490 if (!CanBuildVehicleInfrastructure(VEH_TRAIN
)) delete this;
494 * Configures the rail toolbar for railtype given
495 * @param railtype the railtype to display
497 void SetupRailToolbar(RailType railtype
)
499 this->railtype
= railtype
;
500 const RailtypeInfo
*rti
= GetRailTypeInfo(railtype
);
502 assert(railtype
< RAILTYPE_END
);
503 this->GetWidget
<NWidgetCore
>(WID_RAT_BUILD_NS
)->widget_data
= rti
->gui_sprites
.build_ns_rail
;
504 this->GetWidget
<NWidgetCore
>(WID_RAT_BUILD_X
)->widget_data
= rti
->gui_sprites
.build_x_rail
;
505 this->GetWidget
<NWidgetCore
>(WID_RAT_BUILD_EW
)->widget_data
= rti
->gui_sprites
.build_ew_rail
;
506 this->GetWidget
<NWidgetCore
>(WID_RAT_BUILD_Y
)->widget_data
= rti
->gui_sprites
.build_y_rail
;
507 this->GetWidget
<NWidgetCore
>(WID_RAT_AUTORAIL
)->widget_data
= rti
->gui_sprites
.auto_rail
;
508 this->GetWidget
<NWidgetCore
>(WID_RAT_POLYRAIL
)->widget_data
= rti
->gui_sprites
.auto_rail
;
509 this->GetWidget
<NWidgetCore
>(WID_RAT_BUILD_DEPOT
)->widget_data
= rti
->gui_sprites
.build_depot
;
510 this->GetWidget
<NWidgetCore
>(WID_RAT_CONVERT_RAIL
)->widget_data
= rti
->gui_sprites
.convert_rail
;
511 this->GetWidget
<NWidgetCore
>(WID_RAT_BUILD_TUNNEL
)->widget_data
= rti
->gui_sprites
.build_tunnel
;
515 * Switch to another rail type.
516 * @param railtype New rail type.
518 void ModifyRailType(RailType railtype
)
520 this->SetupRailToolbar(railtype
);
524 void UpdateRemoveWidgetStatus(int clicked_widget
)
526 switch (clicked_widget
) {
528 /* If it is the removal button that has been clicked, do nothing,
529 * as it is up to the other buttons to drive removal status */
532 case WID_RAT_BUILD_NS
:
533 case WID_RAT_BUILD_X
:
534 case WID_RAT_BUILD_EW
:
535 case WID_RAT_BUILD_Y
:
536 case WID_RAT_AUTORAIL
:
537 case WID_RAT_POLYRAIL
:
538 case WID_RAT_BUILD_WAYPOINT
:
539 case WID_RAT_BUILD_STATION
:
540 case WID_RAT_BUILD_SIGNALS
:
541 /* Removal button is enabled only if the rail/signal/waypoint/station
542 * button is still lowered. Once raised, it has to be disabled */
543 this->SetWidgetDisabledState(WID_RAT_REMOVE
, !this->IsWidgetLowered(clicked_widget
));
547 /* When any other buttons than rail/signal/waypoint/station, raise and
548 * disable the removal button */
549 this->DisableWidget(WID_RAT_REMOVE
);
550 this->RaiseWidget(WID_RAT_REMOVE
);
555 virtual void SetStringParameters(int widget
) const
557 if (widget
== WID_RAT_CAPTION
) {
558 const RailtypeInfo
*rti
= GetRailTypeInfo(this->railtype
);
559 if (rti
->max_speed
> 0) {
560 SetDParam(0, STR_TOOLBAR_RAILTYPE_VELOCITY
);
561 SetDParam(1, rti
->strings
.toolbar_caption
);
562 SetDParam(2, rti
->max_speed
);
564 SetDParam(0, rti
->strings
.toolbar_caption
);
569 virtual void DrawWidget(const Rect
&r
, int widget
) const
571 if (widget
== WID_RAT_POLYRAIL
) {
572 Dimension d
= GetSpriteSize(SPR_BLOT
);
573 uint offset
= this->IsWidgetLowered(WID_RAT_POLYRAIL
) ? 1 : 0;
574 DrawSprite(SPR_BLOT
, PALETTE_TO_GREY
, (r
.left
+ r
.right
- d
.width
) / 2 + offset
, (r
.top
+ r
.bottom
- d
.height
) / 2 + offset
);
578 virtual void OnClick(Point pt
, int widget
, int click_count
)
580 if (widget
< WID_RAT_BUILD_NS
) return;
582 _remove_button_clicked
= false;
584 case WID_RAT_BUILD_NS
:
585 HandlePlacePushButton(this, WID_RAT_BUILD_NS
, GetRailTypeInfo(_cur_railtype
)->cursor
.rail_ns
, HT_LINE
| HT_DIR_VL
);
586 this->last_user_action
= widget
;
589 case WID_RAT_BUILD_X
:
590 HandlePlacePushButton(this, WID_RAT_BUILD_X
, GetRailTypeInfo(_cur_railtype
)->cursor
.rail_swne
, HT_LINE
| HT_DIR_X
);
591 this->last_user_action
= widget
;
594 case WID_RAT_BUILD_EW
:
595 HandlePlacePushButton(this, WID_RAT_BUILD_EW
, GetRailTypeInfo(_cur_railtype
)->cursor
.rail_ew
, HT_LINE
| HT_DIR_HL
);
596 this->last_user_action
= widget
;
599 case WID_RAT_BUILD_Y
:
600 HandlePlacePushButton(this, WID_RAT_BUILD_Y
, GetRailTypeInfo(_cur_railtype
)->cursor
.rail_nwse
, HT_LINE
| HT_DIR_Y
);
601 this->last_user_action
= widget
;
604 case WID_RAT_AUTORAIL
:
605 HandlePlacePushButton(this, WID_RAT_AUTORAIL
, GetRailTypeInfo(_cur_railtype
)->cursor
.autorail
, HT_RAIL
);
606 this->last_user_action
= widget
;
609 case WID_RAT_POLYRAIL
: {
610 bool was_snap
= CurrentlySnappingRailPlacement();
611 bool was_open
= this->IsWidgetLowered(WID_RAT_POLYRAIL
);
614 /* "polyrail" hotkey - activate polyline tool in snapping mode, close the tool if snapping mode is already active
615 * "new_polyrail" hotkey - activate polyline tool in non-snapping (new line) mode, close the tool if non-snapping mode is already active
616 * button ctrl-clicking - switch between snapping and non-snapping modes, open the tool in non-snapping mode if it is closed
617 * button clicking - open the tool in non-snapping mode, close the tool if it is opened */
618 if (this->last_user_action
== HOTKEY_POLYRAIL
) {
620 do_open
= !was_open
|| !was_snap
;
621 } else if (this->last_user_action
== HOTKEY_NEW_POLYRAIL
) {
623 do_open
= !was_open
|| was_snap
;
624 } else if (_ctrl_pressed
) {
625 do_snap
= !was_open
|| !was_snap
;
631 /* close the tool explicitly so it can be re-opened in different snapping mode */
632 if (was_open
) ResetObjectToPlace();
633 /* open the tool in desired mode */
634 if (do_open
&& HandlePlacePushButton(this, WID_RAT_POLYRAIL
, GetRailTypeInfo(railtype
)->cursor
.autorail
, do_snap
? (HT_RAIL
| HT_POLY
) : (HT_RAIL
| HT_NEW_POLY
))) {
635 /* if we are re-opening the tool but we couldn't switch the snapping
636 * then close the tool instead of appearing to be doing nothing */
637 if (was_open
&& do_snap
!= CurrentlySnappingRailPlacement()) ResetObjectToPlace();
639 this->last_user_action
= WID_RAT_POLYRAIL
;
643 case WID_RAT_DEMOLISH
:
644 HandlePlacePushButton(this, WID_RAT_DEMOLISH
, ANIMCURSOR_DEMOLISH
, HT_RECT
| HT_DIAGONAL
);
645 this->last_user_action
= widget
;
648 case WID_RAT_BUILD_DEPOT
:
649 if (HandlePlacePushButton(this, WID_RAT_BUILD_DEPOT
, GetRailTypeInfo(_cur_railtype
)->cursor
.depot
, HT_RECT
)) {
650 ShowBuildTrainDepotPicker(this);
651 this->last_user_action
= widget
;
655 case WID_RAT_BUILD_WAYPOINT
:
656 this->last_user_action
= widget
;
657 _waypoint_count
= StationClass::Get(STAT_CLASS_WAYP
)->GetSpecCount();
658 if (HandlePlacePushButton(this, WID_RAT_BUILD_WAYPOINT
, SPR_CURSOR_WAYPOINT
, HT_RECT
) && _waypoint_count
> 1) {
659 ShowBuildWaypointPicker(this);
663 case WID_RAT_BUILD_STATION
:
664 if (HandlePlacePushButton(this, WID_RAT_BUILD_STATION
, SPR_CURSOR_RAIL_STATION
, HT_RECT
)) {
665 ShowStationBuilder(this);
666 this->last_user_action
= widget
;
670 case WID_RAT_BUILD_SIGNALS
: {
671 this->last_user_action
= widget
;
672 bool started
= HandlePlacePushButton(this, WID_RAT_BUILD_SIGNALS
, ANIMCURSOR_BUILDSIGNALS
, HT_RECT
);
673 if (started
&& _settings_client
.gui
.enable_signal_gui
!= _ctrl_pressed
) {
674 ShowSignalBuilder(this);
679 case WID_RAT_PROGRAM_SIGNALS
:
680 HandlePlacePushButton(this, WID_RAT_PROGRAM_SIGNALS
, SPR_CURSOR_MOUSE
, HT_RECT
);
681 this->last_user_action
= widget
;
684 case WID_RAT_BUILD_BRIDGE
:
685 HandlePlacePushButton(this, WID_RAT_BUILD_BRIDGE
, SPR_CURSOR_BRIDGE
, HT_RECT
);
686 this->last_user_action
= widget
;
689 case WID_RAT_BUILD_TUNNEL
:
690 HandlePlacePushButton(this, WID_RAT_BUILD_TUNNEL
, GetRailTypeInfo(_cur_railtype
)->cursor
.tunnel
, HT_SPECIAL
| HT_TUNNEL
);
691 this->last_user_action
= widget
;
695 BuildRailClick_Remove(this);
698 case WID_RAT_CONVERT_RAIL
:
699 HandlePlacePushButton(this, WID_RAT_CONVERT_RAIL
, GetRailTypeInfo(_cur_railtype
)->cursor
.convert
, HT_RECT
| HT_DIAGONAL
);
700 this->last_user_action
= widget
;
703 default: NOT_REACHED();
705 this->UpdateRemoveWidgetStatus(widget
);
706 if (_ctrl_pressed
) RailToolbar_CtrlChanged(this);
709 virtual EventState
OnHotkey(int hotkey
)
711 MarkTileDirtyByTile(TileVirtXY(_thd
.pos
.x
, _thd
.pos
.y
)); // redraw tile selection
713 if (hotkey
== HOTKEY_POLYRAIL
|| hotkey
== HOTKEY_NEW_POLYRAIL
) {
714 /* Indicate to the OnClick that the action comes from a hotkey rather
715 * then from a click and that the CTRL state should be ignored. */
716 this->last_user_action
= hotkey
;
717 hotkey
= WID_RAT_POLYRAIL
;
720 return this->Window::OnHotkey(hotkey
);
723 virtual void OnPlaceObject(Point pt
, TileIndex tile
)
725 switch (this->last_user_action
) {
726 case WID_RAT_BUILD_NS
:
727 VpStartPlaceSizing(tile
, VPM_FIX_VERTICAL
| VPM_RAILDIRS
, DDSP_PLACE_RAIL
);
730 case WID_RAT_BUILD_X
:
731 VpStartPlaceSizing(tile
, VPM_FIX_Y
| VPM_RAILDIRS
, DDSP_PLACE_RAIL
);
734 case WID_RAT_BUILD_EW
:
735 VpStartPlaceSizing(tile
, VPM_FIX_HORIZONTAL
| VPM_RAILDIRS
, DDSP_PLACE_RAIL
);
738 case WID_RAT_BUILD_Y
:
739 VpStartPlaceSizing(tile
, VPM_FIX_X
| VPM_RAILDIRS
, DDSP_PLACE_RAIL
);
742 case WID_RAT_AUTORAIL
:
743 case WID_RAT_POLYRAIL
:
744 VpStartPlaceSizing(tile
, VPM_RAILDIRS
, DDSP_PLACE_RAIL
);
747 case WID_RAT_DEMOLISH
:
748 PlaceProc_DemolishArea(tile
);
751 case WID_RAT_BUILD_DEPOT
:
752 DoCommandP(tile
, _cur_railtype
, _build_depot_direction
,
753 CMD_BUILD_TRAIN_DEPOT
| CMD_MSG(STR_ERROR_CAN_T_BUILD_TRAIN_DEPOT
),
757 case WID_RAT_BUILD_WAYPOINT
:
758 PlaceRail_Waypoint(tile
);
761 case WID_RAT_BUILD_STATION
:
762 PlaceRail_Station(tile
);
765 case WID_RAT_BUILD_SIGNALS
:
766 VpStartPlaceSizing(tile
, VPM_SIGNALDIRS
, DDSP_BUILD_SIGNALS
);
769 case WID_RAT_PROGRAM_SIGNALS
:
770 if (IsPlainRailTile(tile
)) {
771 Track track
= SignalTrackFromTile(tile
);
773 if (HasSignalOnTrack(tile
, track
) && IsLogicSignal(tile
, track
)) {
774 ShowSignalProgramWindow(FindSignalProgram(tile
, track
));
775 ResetObjectToPlace();
779 ShowErrorMessage(STR_ERROR_PROGRAM_NOT_LOGIC_SIGNAL
, INVALID_STRING_ID
, WL_ERROR
);
782 case WID_RAT_BUILD_BRIDGE
:
783 PlaceRail_Bridge(tile
, this);
786 case WID_RAT_BUILD_TUNNEL
:
787 DoCommandP(tile
, _cur_railtype
| (TRANSPORT_RAIL
<< 8), 0, CMD_BUILD_TUNNEL
| CMD_MSG(STR_ERROR_CAN_T_BUILD_TUNNEL_HERE
), CcBuildRailTunnel
);
790 case WID_RAT_CONVERT_RAIL
:
791 VpStartPlaceSizing(tile
, VPM_X_AND_Y
, DDSP_CONVERT_RAIL
);
794 default: NOT_REACHED();
798 virtual void OnPlaceDrag(ViewportPlaceMethod select_method
, ViewportDragDropSelectionProcess select_proc
, Point pt
)
800 /* no dragging if you have pressed the convert button */
801 if (FindWindowById(WC_BUILD_SIGNAL
, 0) != NULL
&& _convert_signal_button
&& this->IsWidgetLowered(WID_RAT_BUILD_SIGNALS
)) return;
803 VpSelectTilesWithMethod(pt
.x
, pt
.y
, select_method
);
806 virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method
, ViewportDragDropSelectionProcess select_proc
, Point pt
, TileIndex start_tile
, TileIndex end_tile
)
809 switch (select_proc
) {
810 default: NOT_REACHED();
811 case DDSP_BUILD_BRIDGE
:
812 if (!_settings_client
.gui
.persistent_buildingtools
) ResetObjectToPlace();
813 ShowBuildBridgeWindow(start_tile
, end_tile
, TRANSPORT_RAIL
, _cur_railtype
);
816 case DDSP_PLACE_RAIL
:
817 HandleAutodirPlacement();
820 case DDSP_BUILD_SIGNALS
:
821 HandleAutoSignalPlacement();
824 case DDSP_DEMOLISH_AREA
:
825 GUIPlaceProcDragXY(select_proc
, start_tile
, end_tile
);
828 case DDSP_CONVERT_RAIL
:
829 DoCommandP(end_tile
, start_tile
, _cur_railtype
| (_ctrl_pressed
? (1 << 5) : 0), CMD_CONVERT_RAIL
| CMD_MSG(STR_ERROR_CAN_T_CONVERT_RAIL
), CcPlaySound_SPLAT_RAIL
);
832 case DDSP_REMOVE_STATION
:
833 case DDSP_BUILD_STATION
:
834 if (this->IsWidgetLowered(WID_RAT_BUILD_STATION
)) {
836 if (_remove_button_clicked
) {
837 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
);
839 HandleStationPlacement(start_tile
, end_tile
);
843 if (_remove_button_clicked
) {
844 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
);
846 TileArea
ta(start_tile
, end_tile
);
847 uint32 p1
= _cur_railtype
| (select_method
== VPM_X_LIMITED
? AXIS_X
: AXIS_Y
) << 4 | ta
.w
<< 8 | ta
.h
<< 16 | _ctrl_pressed
<< 24;
848 uint32 p2
= STAT_CLASS_WAYP
| _cur_waypoint_type
<< 8 | INVALID_STATION
<< 16;
850 CommandContainer cmdcont
= { ta
.tile
, p1
, p2
, CMD_BUILD_RAIL_WAYPOINT
| CMD_MSG(STR_ERROR_CAN_T_BUILD_TRAIN_WAYPOINT
), CcPlaySound_SPLAT_RAIL
, 0, "" };
851 ShowSelectWaypointIfNeeded(cmdcont
, ta
);
859 virtual void OnPlaceObjectAbort()
861 this->RaiseButtons();
862 this->DisableWidget(WID_RAT_REMOVE
);
863 this->SetWidgetDirty(WID_RAT_REMOVE
);
865 DeleteWindowById(WC_BUILD_SIGNAL
, TRANSPORT_RAIL
);
866 DeleteWindowById(WC_BUILD_STATION
, TRANSPORT_RAIL
);
867 DeleteWindowById(WC_BUILD_DEPOT
, TRANSPORT_RAIL
);
868 DeleteWindowById(WC_BUILD_WAYPOINT
, TRANSPORT_RAIL
);
869 DeleteWindowById(WC_SELECT_STATION
, 0);
870 DeleteWindowByClass(WC_BUILD_BRIDGE
);
873 virtual void OnPlacePresize(Point pt
, TileIndex tile
)
875 DoCommand(tile
, _cur_railtype
| (TRANSPORT_RAIL
<< 8), 0, DC_AUTO
, CMD_BUILD_TUNNEL
);
876 VpSetPresizeRange(tile
, _build_tunnel_endtile
== 0 ? tile
: _build_tunnel_endtile
);
879 virtual EventState
OnCTRLStateChange()
881 /* do not toggle Remove button by Ctrl when placing station */
882 if (!this->IsWidgetLowered(WID_RAT_BUILD_STATION
) && !this->IsWidgetLowered(WID_RAT_BUILD_WAYPOINT
) && RailToolbar_CtrlChanged(this)) return ES_HANDLED
;
883 return ES_NOT_HANDLED
;
886 static HotkeyList hotkeys
;
890 * Handler for global hotkeys of the BuildRailToolbarWindow.
891 * @param hotkey Hotkey
892 * @return ES_HANDLED if hotkey was accepted.
894 static EventState
RailToolbarGlobalHotkeys(int hotkey
)
896 if (_game_mode
!= GM_NORMAL
|| !CanBuildVehicleInfrastructure(VEH_TRAIN
)) return ES_NOT_HANDLED
;
897 extern RailType _last_built_railtype
;
898 Window
*w
= ShowBuildRailToolbar(_last_built_railtype
);
899 if (w
== NULL
) return ES_NOT_HANDLED
;
900 return w
->OnHotkey(hotkey
);
903 const uint16 _railtoolbar_autorail_keys
[] = {'5', 'A' | WKC_GLOBAL_HOTKEY
, 0};
904 const uint16 _railtoolbar_polyrail_keys
[] = {'5' | WKC_CTRL
, 'A' | WKC_CTRL
| WKC_GLOBAL_HOTKEY
, 0};
905 const uint16 _railtoolbar_new_poly_keys
[] = {'5' | WKC_CTRL
| WKC_SHIFT
, 'A' | WKC_CTRL
| WKC_SHIFT
| WKC_GLOBAL_HOTKEY
, 0};
907 static Hotkey railtoolbar_hotkeys
[] = {
908 Hotkey('1', "build_ns", WID_RAT_BUILD_NS
),
909 Hotkey('2', "build_x", WID_RAT_BUILD_X
),
910 Hotkey('3', "build_ew", WID_RAT_BUILD_EW
),
911 Hotkey('4', "build_y", WID_RAT_BUILD_Y
),
912 Hotkey(_railtoolbar_autorail_keys
, "autorail", WID_RAT_AUTORAIL
),
913 Hotkey(_railtoolbar_polyrail_keys
, "polyrail", HOTKEY_POLYRAIL
),
914 Hotkey(_railtoolbar_new_poly_keys
, "new_polyrail", HOTKEY_NEW_POLYRAIL
),
915 Hotkey('6', "demolish", WID_RAT_DEMOLISH
),
916 Hotkey('7', "depot", WID_RAT_BUILD_DEPOT
),
917 Hotkey('8', "waypoint", WID_RAT_BUILD_WAYPOINT
),
918 Hotkey('9', "station", WID_RAT_BUILD_STATION
),
919 Hotkey('S', "signal", WID_RAT_BUILD_SIGNALS
),
920 Hotkey('B', "bridge", WID_RAT_BUILD_BRIDGE
),
921 Hotkey('T', "tunnel", WID_RAT_BUILD_TUNNEL
),
922 Hotkey('R', "remove", WID_RAT_REMOVE
),
923 Hotkey('C', "convert", WID_RAT_CONVERT_RAIL
),
926 HotkeyList
BuildRailToolbarWindow::hotkeys("railtoolbar", railtoolbar_hotkeys
, RailToolbarGlobalHotkeys
);
928 static const NWidgetPart _nested_build_rail_widgets
[] = {
929 NWidget(NWID_HORIZONTAL
),
930 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
931 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
, WID_RAT_CAPTION
), SetDataTip(STR_WHITE_STRING
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
932 NWidget(WWT_STICKYBOX
, COLOUR_DARK_GREEN
),
934 NWidget(NWID_HORIZONTAL
),
935 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_BUILD_NS
),
936 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_RAIL_NS
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_TRACK
),
937 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_BUILD_X
),
938 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_RAIL_NE
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_TRACK
),
939 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_BUILD_EW
),
940 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_RAIL_EW
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_TRACK
),
941 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_BUILD_Y
),
942 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_RAIL_NW
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_TRACK
),
943 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_AUTORAIL
),
944 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_AUTORAIL
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_AUTORAIL
),
945 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_POLYRAIL
),
946 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_AUTORAIL
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_POLYRAIL
),
948 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
), SetMinimalSize(4, 22), SetDataTip(0x0, STR_NULL
), EndContainer(),
950 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_DEMOLISH
),
951 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DYNAMITE
, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC
),
952 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_BUILD_DEPOT
),
953 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DEPOT_RAIL
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_TRAIN_DEPOT_FOR_BUILDING
),
954 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_BUILD_WAYPOINT
),
955 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_WAYPOINT
, STR_RAIL_TOOLBAR_TOOLTIP_CONVERT_RAIL_TO_WAYPOINT
),
956 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_BUILD_STATION
),
957 SetFill(0, 1), SetMinimalSize(42, 22), SetDataTip(SPR_IMG_RAIL_STATION
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_STATION
),
958 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_BUILD_SIGNALS
),
959 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_RAIL_SIGNALS
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_SIGNALS
),
960 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_PROGRAM_SIGNALS
),
961 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_SETTINGS
, STR_RAIL_TOOLBAR_TOOLTIP_PROGRAM_SIGNAL
),
962 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_BUILD_BRIDGE
),
963 SetFill(0, 1), SetMinimalSize(42, 22), SetDataTip(SPR_IMG_BRIDGE
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_BRIDGE
),
964 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_BUILD_TUNNEL
),
965 SetFill(0, 1), SetMinimalSize(20, 22), SetDataTip(SPR_IMG_TUNNEL_RAIL
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_TUNNEL
),
966 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_REMOVE
),
967 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_REMOVE
, STR_RAIL_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR
),
968 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_CONVERT_RAIL
),
969 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_CONVERT_RAIL
, STR_RAIL_TOOLBAR_TOOLTIP_CONVERT_RAIL
),
973 static WindowDesc
_build_rail_desc(
974 WDP_ALIGN_TOOLBAR
, "toolbar_rail", 0, 0,
975 WC_BUILD_TOOLBAR
, WC_NONE
,
977 _nested_build_rail_widgets
, lengthof(_nested_build_rail_widgets
),
978 &BuildRailToolbarWindow::hotkeys
983 * Open the build rail toolbar window for a specific rail type.
985 * If the terraform toolbar is linked to the toolbar, that window is also opened.
987 * @param railtype Rail type to open the window for
988 * @return newly opened rail toolbar, or NULL if the toolbar could not be opened.
990 Window
*ShowBuildRailToolbar(RailType railtype
)
992 if (!Company::IsValidID(_local_company
)) return NULL
;
993 if (!ValParamRailtype(railtype
)) return NULL
;
995 DeleteWindowByClass(WC_BUILD_TOOLBAR
);
996 _cur_railtype
= railtype
;
997 _remove_button_clicked
= false;
998 return new BuildRailToolbarWindow(&_build_rail_desc
, railtype
);
1001 /* TODO: For custom stations, respect their allowed platforms/lengths bitmasks!
1004 static void HandleStationPlacement(TileIndex start
, TileIndex end
)
1006 TileArea
ta(start
, end
);
1007 uint numtracks
= ta
.w
;
1008 uint platlength
= ta
.h
;
1010 if (_railstation
.orientation
== AXIS_X
) Swap(numtracks
, platlength
);
1012 uint32 p1
= _cur_railtype
| _railstation
.orientation
<< 5 | numtracks
<< 8 | platlength
<< 16 | _ctrl_pressed
<< 24;
1013 uint32 p2
= _railstation
.station_class
| _railstation
.station_type
<< 8 | INVALID_STATION
<< 16;
1015 CommandContainer cmdcont
= { ta
.tile
, p1
, p2
, CMD_BUILD_RAIL_STATION
| CMD_MSG(STR_ERROR_CAN_T_BUILD_RAILROAD_STATION
), CcStation
, 0, "" };
1016 ShowSelectStationIfNeeded(cmdcont
, ta
);
1019 struct BuildRailStationWindow
: public PickerWindowBase
{
1021 uint line_height
; ///< Height of a single line in the newstation selection matrix (#WID_BRAS_NEWST_LIST widget).
1022 uint coverage_height
; ///< Height of the coverage texts.
1023 Scrollbar
*vscroll
; ///< Vertical scrollbar of the new station list.
1024 Scrollbar
*vscroll2
; ///< Vertical scrollbar of the matrix with new stations.
1027 * Verify whether the currently selected station size is allowed after selecting a new station class/type.
1028 * If not, change the station size variables ( _settings_client.gui.station_numtracks and _settings_client.gui.station_platlength ).
1029 * @param statspec Specification of the new station class/type
1031 void CheckSelectedSize(const StationSpec
*statspec
)
1033 if (statspec
== NULL
|| _settings_client
.gui
.station_dragdrop
) return;
1035 /* If current number of tracks is not allowed, make it as big as possible */
1036 if (HasBit(statspec
->disallowed_platforms
, _settings_client
.gui
.station_numtracks
- 1)) {
1037 this->RaiseWidget(_settings_client
.gui
.station_numtracks
+ WID_BRAS_PLATFORM_NUM_BEGIN
);
1038 _settings_client
.gui
.station_numtracks
= 1;
1039 if (statspec
->disallowed_platforms
!= UINT8_MAX
) {
1040 while (HasBit(statspec
->disallowed_platforms
, _settings_client
.gui
.station_numtracks
- 1)) {
1041 _settings_client
.gui
.station_numtracks
++;
1043 this->LowerWidget(_settings_client
.gui
.station_numtracks
+ WID_BRAS_PLATFORM_NUM_BEGIN
);
1047 if (HasBit(statspec
->disallowed_lengths
, _settings_client
.gui
.station_platlength
- 1)) {
1048 this->RaiseWidget(_settings_client
.gui
.station_platlength
+ WID_BRAS_PLATFORM_LEN_BEGIN
);
1049 _settings_client
.gui
.station_platlength
= 1;
1050 if (statspec
->disallowed_lengths
!= UINT8_MAX
) {
1051 while (HasBit(statspec
->disallowed_lengths
, _settings_client
.gui
.station_platlength
- 1)) {
1052 _settings_client
.gui
.station_platlength
++;
1054 this->LowerWidget(_settings_client
.gui
.station_platlength
+ WID_BRAS_PLATFORM_LEN_BEGIN
);
1060 BuildRailStationWindow(WindowDesc
*desc
, Window
*parent
, bool newstation
) : PickerWindowBase(desc
, parent
)
1062 this->coverage_height
= 2 * FONT_HEIGHT_NORMAL
+ 3 * WD_PAR_VSEP_NORMAL
;
1063 this->vscroll
= NULL
;
1064 _railstation
.newstations
= newstation
;
1066 this->CreateNestedTree();
1067 NWidgetStacked
*newst_additions
= this->GetWidget
<NWidgetStacked
>(WID_BRAS_SHOW_NEWST_ADDITIONS
);
1068 newst_additions
->SetDisplayedPlane(newstation
? 0 : SZSP_NONE
);
1069 newst_additions
= this->GetWidget
<NWidgetStacked
>(WID_BRAS_SHOW_NEWST_MATRIX
);
1070 newst_additions
->SetDisplayedPlane(newstation
? 0 : SZSP_NONE
);
1071 newst_additions
= this->GetWidget
<NWidgetStacked
>(WID_BRAS_SHOW_NEWST_DEFSIZE
);
1072 newst_additions
->SetDisplayedPlane(newstation
? 0 : SZSP_NONE
);
1073 newst_additions
= this->GetWidget
<NWidgetStacked
>(WID_BRAS_SHOW_NEWST_RESIZE
);
1074 newst_additions
->SetDisplayedPlane(newstation
? 0 : SZSP_NONE
);
1076 this->vscroll
= this->GetScrollbar(WID_BRAS_NEWST_SCROLL
);
1077 this->vscroll2
= this->GetScrollbar(WID_BRAS_MATRIX_SCROLL
);
1079 this->FinishInitNested(TRANSPORT_RAIL
);
1081 this->LowerWidget(_railstation
.orientation
+ WID_BRAS_PLATFORM_DIR_X
);
1082 if (_settings_client
.gui
.station_dragdrop
) {
1083 this->LowerWidget(WID_BRAS_PLATFORM_DRAG_N_DROP
);
1085 this->LowerWidget(_settings_client
.gui
.station_numtracks
+ WID_BRAS_PLATFORM_NUM_BEGIN
);
1086 this->LowerWidget(_settings_client
.gui
.station_platlength
+ WID_BRAS_PLATFORM_LEN_BEGIN
);
1088 this->SetWidgetLoweredState(WID_BRAS_HIGHLIGHT_OFF
, !_settings_client
.gui
.station_show_coverage
);
1089 this->SetWidgetLoweredState(WID_BRAS_HIGHLIGHT_ON
, _settings_client
.gui
.station_show_coverage
);
1091 if (!newstation
|| _railstation
.station_class
>= (int)StationClass::GetClassCount()) {
1092 /* New stations are not available or changed, so ensure the default station
1093 * type is 'selected'. */
1094 _railstation
.station_class
= STAT_CLASS_DFLT
;
1095 _railstation
.station_type
= 0;
1096 this->vscroll2
= NULL
;
1099 _railstation
.station_count
= StationClass::Get(_railstation
.station_class
)->GetSpecCount();
1100 _railstation
.station_type
= min(_railstation
.station_type
, _railstation
.station_count
- 1);
1103 for (uint i
= 0; i
< StationClass::GetClassCount(); i
++) {
1104 if (i
== STAT_CLASS_WAYP
) continue;
1107 this->vscroll
->SetCount(count
);
1108 this->vscroll
->SetPosition(Clamp(_railstation
.station_class
- 2, 0, max(this->vscroll
->GetCount() - this->vscroll
->GetCapacity(), 0)));
1110 NWidgetMatrix
*matrix
= this->GetWidget
<NWidgetMatrix
>(WID_BRAS_MATRIX
);
1111 matrix
->SetScrollbar(this->vscroll2
);
1112 matrix
->SetCount(_railstation
.station_count
);
1113 matrix
->SetClicked(_railstation
.station_type
);
1117 virtual ~BuildRailStationWindow()
1119 DeleteWindowById(WC_SELECT_STATION
, 0);
1122 virtual void OnPaint()
1124 bool newstations
= _railstation
.newstations
;
1125 const StationSpec
*statspec
= newstations
? StationClass::Get(_railstation
.station_class
)->GetSpec(_railstation
.station_type
) : NULL
;
1127 if (_settings_client
.gui
.station_dragdrop
) {
1128 SetTileSelectSize(1, 1);
1130 int x
= _settings_client
.gui
.station_numtracks
;
1131 int y
= _settings_client
.gui
.station_platlength
;
1132 if (_railstation
.orientation
== AXIS_X
) Swap(x
, y
);
1133 if (!_remove_button_clicked
) {
1134 SetTileSelectSize(x
, y
);
1138 int rad
= (_settings_game
.station
.modified_catchment
) ? CA_TRAIN
: CA_UNMODIFIED
;
1140 if (_settings_client
.gui
.station_show_coverage
) SetTileSelectBigSize(-rad
, -rad
, 2 * rad
, 2 * rad
);
1142 for (uint bits
= 0; bits
< 7; bits
++) {
1143 bool disable
= bits
>= _settings_game
.station
.station_spread
;
1144 if (statspec
== NULL
) {
1145 this->SetWidgetDisabledState(bits
+ WID_BRAS_PLATFORM_NUM_1
, disable
);
1146 this->SetWidgetDisabledState(bits
+ WID_BRAS_PLATFORM_LEN_1
, disable
);
1148 this->SetWidgetDisabledState(bits
+ WID_BRAS_PLATFORM_NUM_1
, HasBit(statspec
->disallowed_platforms
, bits
) || disable
);
1149 this->SetWidgetDisabledState(bits
+ WID_BRAS_PLATFORM_LEN_1
, HasBit(statspec
->disallowed_lengths
, bits
) || disable
);
1153 this->DrawWidgets();
1155 /* 'Accepts' and 'Supplies' texts. */
1156 NWidgetBase
*cov
= this->GetWidget
<NWidgetBase
>(WID_BRAS_COVERAGE_TEXTS
);
1157 int top
= cov
->pos_y
+ WD_PAR_VSEP_NORMAL
;
1158 int left
= cov
->pos_x
+ WD_FRAMERECT_LEFT
;
1159 int right
= cov
->pos_x
+ cov
->current_x
- WD_FRAMERECT_RIGHT
;
1160 int bottom
= cov
->pos_y
+ cov
->current_y
;
1161 top
= DrawStationCoverageAreaText(left
, right
, top
, SCT_ALL
, rad
, false) + WD_PAR_VSEP_NORMAL
;
1162 top
= DrawStationCoverageAreaText(left
, right
, top
, SCT_ALL
, rad
, true) + WD_PAR_VSEP_NORMAL
;
1163 /* Resize background if the window is too small.
1164 * Never make the window smaller to avoid oscillating if the size change affects the acceptance.
1165 * (This is the case, if making the window bigger moves the mouse into the window.) */
1167 this->coverage_height
+= top
- bottom
;
1172 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
1175 case WID_BRAS_NEWST_LIST
: {
1176 Dimension d
= {0, 0};
1177 for (uint i
= 0; i
< StationClass::GetClassCount(); i
++) {
1178 if (i
== STAT_CLASS_WAYP
) continue;
1179 d
= maxdim(d
, GetStringBoundingBox(StationClass::Get((StationClassID
)i
)->name
));
1181 size
->width
= max(size
->width
, d
.width
+ padding
.width
);
1182 this->line_height
= FONT_HEIGHT_NORMAL
+ WD_MATRIX_TOP
+ WD_MATRIX_BOTTOM
;
1183 size
->height
= 5 * this->line_height
;
1184 resize
->height
= this->line_height
;
1188 case WID_BRAS_SHOW_NEWST_TYPE
: {
1189 if (!_railstation
.newstations
) {
1195 /* If newstations exist, compute the non-zero minimal size. */
1196 Dimension d
= {0, 0};
1197 StringID str
= this->GetWidget
<NWidgetCore
>(widget
)->widget_data
;
1198 for (StationClassID statclass
= STAT_CLASS_BEGIN
; statclass
< (StationClassID
)StationClass::GetClassCount(); statclass
++) {
1199 if (statclass
== STAT_CLASS_WAYP
) continue;
1200 StationClass
*stclass
= StationClass::Get(statclass
);
1201 for (uint16 j
= 0; j
< stclass
->GetSpecCount(); j
++) {
1202 const StationSpec
*statspec
= stclass
->GetSpec(j
);
1203 SetDParam(0, (statspec
!= NULL
&& statspec
->name
!= 0) ? statspec
->name
: STR_STATION_CLASS_DFLT
);
1204 d
= maxdim(d
, GetStringBoundingBox(str
));
1207 size
->width
= max(size
->width
, d
.width
+ padding
.width
);
1211 case WID_BRAS_PLATFORM_DIR_X
:
1212 case WID_BRAS_PLATFORM_DIR_Y
:
1213 case WID_BRAS_IMAGE
:
1214 size
->width
= ScaleGUITrad(64) + 2;
1215 size
->height
= ScaleGUITrad(58) + 2;
1218 case WID_BRAS_COVERAGE_TEXTS
:
1219 size
->height
= this->coverage_height
;
1222 case WID_BRAS_MATRIX
:
1229 virtual void DrawWidget(const Rect
&r
, int widget
) const
1231 DrawPixelInfo tmp_dpi
;
1233 switch (GB(widget
, 0, 16)) {
1234 case WID_BRAS_PLATFORM_DIR_X
:
1235 /* Set up a clipping area for the '/' station preview */
1236 if (FillDrawPixelInfo(&tmp_dpi
, r
.left
, r
.top
, r
.right
- r
.left
+ 1, r
.bottom
- r
.top
+ 1)) {
1237 DrawPixelInfo
*old_dpi
= _cur_dpi
;
1238 _cur_dpi
= &tmp_dpi
;
1239 int x
= ScaleGUITrad(31) + 1;
1240 int y
= r
.bottom
- r
.top
- ScaleGUITrad(31);
1241 if (!DrawStationTile(x
, y
, _cur_railtype
, AXIS_X
, _railstation
.station_class
, _railstation
.station_type
)) {
1242 StationPickerDrawSprite(x
, y
, STATION_RAIL
, _cur_railtype
, INVALID_ROADTYPE
, 2);
1248 case WID_BRAS_PLATFORM_DIR_Y
:
1249 /* Set up a clipping area for the '\' station preview */
1250 if (FillDrawPixelInfo(&tmp_dpi
, r
.left
, r
.top
, r
.right
- r
.left
+ 1, r
.bottom
- r
.top
+ 1)) {
1251 DrawPixelInfo
*old_dpi
= _cur_dpi
;
1252 _cur_dpi
= &tmp_dpi
;
1253 int x
= ScaleGUITrad(31) + 1;
1254 int y
= r
.bottom
- r
.top
- ScaleGUITrad(31);
1255 if (!DrawStationTile(x
, y
, _cur_railtype
, AXIS_Y
, _railstation
.station_class
, _railstation
.station_type
)) {
1256 StationPickerDrawSprite(x
, y
, STATION_RAIL
, _cur_railtype
, INVALID_ROADTYPE
, 3);
1262 case WID_BRAS_NEWST_LIST
: {
1265 for (uint i
= 0; i
< StationClass::GetClassCount(); i
++) {
1266 if (i
== STAT_CLASS_WAYP
) continue;
1267 if (this->vscroll
->IsVisible(statclass
)) {
1268 DrawString(r
.left
+ WD_MATRIX_LEFT
, r
.right
- WD_MATRIX_RIGHT
, row
* this->line_height
+ r
.top
+ WD_MATRIX_TOP
,
1269 StationClass::Get((StationClassID
)i
)->name
,
1270 (StationClassID
)i
== _railstation
.station_class
? TC_WHITE
: TC_BLACK
);
1278 case WID_BRAS_IMAGE
: {
1279 byte type
= GB(widget
, 16, 16);
1280 assert(type
< _railstation
.station_count
);
1281 /* Check station availability callback */
1282 const StationSpec
*statspec
= StationClass::Get(_railstation
.station_class
)->GetSpec(type
);
1283 if (!IsStationAvailable(statspec
)) {
1284 GfxFillRect(r
.left
+ 1, r
.top
+ 1, r
.right
- 1, r
.bottom
- 1, PC_BLACK
, FILLRECT_CHECKER
);
1287 /* Set up a clipping area for the station preview. */
1288 if (FillDrawPixelInfo(&tmp_dpi
, r
.left
, r
.top
, r
.right
- r
.left
+ 1, r
.bottom
- r
.top
+ 1)) {
1289 DrawPixelInfo
*old_dpi
= _cur_dpi
;
1290 _cur_dpi
= &tmp_dpi
;
1291 int x
= ScaleGUITrad(31) + 1;
1292 int y
= r
.bottom
- r
.top
- ScaleGUITrad(31);
1293 if (!DrawStationTile(x
, y
, _cur_railtype
, _railstation
.orientation
, _railstation
.station_class
, type
)) {
1294 StationPickerDrawSprite(x
, y
, STATION_RAIL
, _cur_railtype
, INVALID_ROADTYPE
, 2 + _railstation
.orientation
);
1303 virtual void OnResize()
1305 if (this->vscroll
!= NULL
) { // New stations available.
1306 this->vscroll
->SetCapacityFromWidget(this, WID_BRAS_NEWST_LIST
);
1310 virtual void SetStringParameters(int widget
) const
1312 if (widget
== WID_BRAS_SHOW_NEWST_TYPE
) {
1313 const StationSpec
*statspec
= StationClass::Get(_railstation
.station_class
)->GetSpec(_railstation
.station_type
);
1314 SetDParam(0, (statspec
!= NULL
&& statspec
->name
!= 0) ? statspec
->name
: STR_STATION_CLASS_DFLT
);
1318 virtual void OnClick(Point pt
, int widget
, int click_count
)
1320 switch (GB(widget
, 0, 16)) {
1321 case WID_BRAS_PLATFORM_DIR_X
:
1322 case WID_BRAS_PLATFORM_DIR_Y
:
1323 this->RaiseWidget(_railstation
.orientation
+ WID_BRAS_PLATFORM_DIR_X
);
1324 _railstation
.orientation
= (Axis
)(widget
- WID_BRAS_PLATFORM_DIR_X
);
1325 this->LowerWidget(_railstation
.orientation
+ WID_BRAS_PLATFORM_DIR_X
);
1326 if (_settings_client
.sound
.click_beep
) SndPlayFx(SND_15_BEEP
);
1328 DeleteWindowById(WC_SELECT_STATION
, 0);
1331 case WID_BRAS_PLATFORM_NUM_1
:
1332 case WID_BRAS_PLATFORM_NUM_2
:
1333 case WID_BRAS_PLATFORM_NUM_3
:
1334 case WID_BRAS_PLATFORM_NUM_4
:
1335 case WID_BRAS_PLATFORM_NUM_5
:
1336 case WID_BRAS_PLATFORM_NUM_6
:
1337 case WID_BRAS_PLATFORM_NUM_7
: {
1338 this->RaiseWidget(_settings_client
.gui
.station_numtracks
+ WID_BRAS_PLATFORM_NUM_BEGIN
);
1339 this->RaiseWidget(WID_BRAS_PLATFORM_DRAG_N_DROP
);
1341 _settings_client
.gui
.station_numtracks
= widget
- WID_BRAS_PLATFORM_NUM_BEGIN
;
1342 _settings_client
.gui
.station_dragdrop
= false;
1344 _settings_client
.gui
.station_dragdrop
= false;
1346 const StationSpec
*statspec
= _railstation
.newstations
? StationClass::Get(_railstation
.station_class
)->GetSpec(_railstation
.station_type
) : NULL
;
1347 if (statspec
!= NULL
&& HasBit(statspec
->disallowed_lengths
, _settings_client
.gui
.station_platlength
- 1)) {
1348 /* The previously selected number of platforms in invalid */
1349 for (uint i
= 0; i
< 7; i
++) {
1350 if (!HasBit(statspec
->disallowed_lengths
, i
)) {
1351 this->RaiseWidget(_settings_client
.gui
.station_platlength
+ WID_BRAS_PLATFORM_LEN_BEGIN
);
1352 _settings_client
.gui
.station_platlength
= i
+ 1;
1358 this->LowerWidget(_settings_client
.gui
.station_numtracks
+ WID_BRAS_PLATFORM_NUM_BEGIN
);
1359 this->LowerWidget(_settings_client
.gui
.station_platlength
+ WID_BRAS_PLATFORM_LEN_BEGIN
);
1360 if (_settings_client
.sound
.click_beep
) SndPlayFx(SND_15_BEEP
);
1362 DeleteWindowById(WC_SELECT_STATION
, 0);
1366 case WID_BRAS_PLATFORM_LEN_1
:
1367 case WID_BRAS_PLATFORM_LEN_2
:
1368 case WID_BRAS_PLATFORM_LEN_3
:
1369 case WID_BRAS_PLATFORM_LEN_4
:
1370 case WID_BRAS_PLATFORM_LEN_5
:
1371 case WID_BRAS_PLATFORM_LEN_6
:
1372 case WID_BRAS_PLATFORM_LEN_7
: {
1373 this->RaiseWidget(_settings_client
.gui
.station_platlength
+ WID_BRAS_PLATFORM_LEN_BEGIN
);
1374 this->RaiseWidget(WID_BRAS_PLATFORM_DRAG_N_DROP
);
1376 _settings_client
.gui
.station_platlength
= widget
- WID_BRAS_PLATFORM_LEN_BEGIN
;
1377 _settings_client
.gui
.station_dragdrop
= false;
1379 _settings_client
.gui
.station_dragdrop
= false;
1381 const StationSpec
*statspec
= _railstation
.newstations
? StationClass::Get(_railstation
.station_class
)->GetSpec(_railstation
.station_type
) : NULL
;
1382 if (statspec
!= NULL
&& HasBit(statspec
->disallowed_platforms
, _settings_client
.gui
.station_numtracks
- 1)) {
1383 /* The previously selected number of tracks in invalid */
1384 for (uint i
= 0; i
< 7; i
++) {
1385 if (!HasBit(statspec
->disallowed_platforms
, i
)) {
1386 this->RaiseWidget(_settings_client
.gui
.station_numtracks
+ WID_BRAS_PLATFORM_NUM_BEGIN
);
1387 _settings_client
.gui
.station_numtracks
= i
+ 1;
1393 this->LowerWidget(_settings_client
.gui
.station_numtracks
+ WID_BRAS_PLATFORM_NUM_BEGIN
);
1394 this->LowerWidget(_settings_client
.gui
.station_platlength
+ WID_BRAS_PLATFORM_LEN_BEGIN
);
1395 if (_settings_client
.sound
.click_beep
) SndPlayFx(SND_15_BEEP
);
1397 DeleteWindowById(WC_SELECT_STATION
, 0);
1401 case WID_BRAS_PLATFORM_DRAG_N_DROP
: {
1402 _settings_client
.gui
.station_dragdrop
^= true;
1404 this->ToggleWidgetLoweredState(WID_BRAS_PLATFORM_DRAG_N_DROP
);
1406 /* get the first allowed length/number of platforms */
1407 const StationSpec
*statspec
= _railstation
.newstations
? StationClass::Get(_railstation
.station_class
)->GetSpec(_railstation
.station_type
) : NULL
;
1408 if (statspec
!= NULL
&& HasBit(statspec
->disallowed_lengths
, _settings_client
.gui
.station_platlength
- 1)) {
1409 for (uint i
= 0; i
< 7; i
++) {
1410 if (!HasBit(statspec
->disallowed_lengths
, i
)) {
1411 this->RaiseWidget(_settings_client
.gui
.station_platlength
+ WID_BRAS_PLATFORM_LEN_BEGIN
);
1412 _settings_client
.gui
.station_platlength
= i
+ 1;
1417 if (statspec
!= NULL
&& HasBit(statspec
->disallowed_platforms
, _settings_client
.gui
.station_numtracks
- 1)) {
1418 for (uint i
= 0; i
< 7; i
++) {
1419 if (!HasBit(statspec
->disallowed_platforms
, i
)) {
1420 this->RaiseWidget(_settings_client
.gui
.station_numtracks
+ WID_BRAS_PLATFORM_NUM_BEGIN
);
1421 _settings_client
.gui
.station_numtracks
= i
+ 1;
1427 this->SetWidgetLoweredState(_settings_client
.gui
.station_numtracks
+ WID_BRAS_PLATFORM_NUM_BEGIN
, !_settings_client
.gui
.station_dragdrop
);
1428 this->SetWidgetLoweredState(_settings_client
.gui
.station_platlength
+ WID_BRAS_PLATFORM_LEN_BEGIN
, !_settings_client
.gui
.station_dragdrop
);
1429 if (_settings_client
.sound
.click_beep
) SndPlayFx(SND_15_BEEP
);
1431 DeleteWindowById(WC_SELECT_STATION
, 0);
1435 case WID_BRAS_HIGHLIGHT_OFF
:
1436 case WID_BRAS_HIGHLIGHT_ON
:
1437 _settings_client
.gui
.station_show_coverage
= (widget
!= WID_BRAS_HIGHLIGHT_OFF
);
1439 this->SetWidgetLoweredState(WID_BRAS_HIGHLIGHT_OFF
, !_settings_client
.gui
.station_show_coverage
);
1440 this->SetWidgetLoweredState(WID_BRAS_HIGHLIGHT_ON
, _settings_client
.gui
.station_show_coverage
);
1441 if (_settings_client
.sound
.click_beep
) SndPlayFx(SND_15_BEEP
);
1445 case WID_BRAS_NEWST_LIST
: {
1446 int y
= this->vscroll
->GetScrolledRowFromWidget(pt
.y
, this, WID_BRAS_NEWST_LIST
, 0, this->line_height
);
1447 if (y
>= (int)StationClass::GetClassCount()) return;
1448 for (uint i
= 0; i
< StationClass::GetClassCount(); i
++) {
1449 if (i
== STAT_CLASS_WAYP
) continue;
1451 if (_railstation
.station_class
!= (StationClassID
)i
) {
1452 _railstation
.station_class
= (StationClassID
)i
;
1453 StationClass
*stclass
= StationClass::Get(_railstation
.station_class
);
1454 _railstation
.station_count
= stclass
->GetSpecCount();
1455 _railstation
.station_type
= min((int)_railstation
.station_type
, max(0, (int)_railstation
.station_count
- 1));
1457 this->CheckSelectedSize(stclass
->GetSpec(_railstation
.station_type
));
1459 NWidgetMatrix
*matrix
= this->GetWidget
<NWidgetMatrix
>(WID_BRAS_MATRIX
);
1460 matrix
->SetCount(_railstation
.station_count
);
1461 matrix
->SetClicked(_railstation
.station_type
);
1463 if (_settings_client
.sound
.click_beep
) SndPlayFx(SND_15_BEEP
);
1465 DeleteWindowById(WC_SELECT_STATION
, 0);
1473 case WID_BRAS_IMAGE
: {
1474 int y
= GB(widget
, 16, 16);
1475 if (y
>= _railstation
.station_count
) return;
1477 /* Check station availability callback */
1478 const StationSpec
*statspec
= StationClass::Get(_railstation
.station_class
)->GetSpec(y
);
1479 if (!IsStationAvailable(statspec
)) return;
1481 _railstation
.station_type
= y
;
1483 this->CheckSelectedSize(statspec
);
1484 this->GetWidget
<NWidgetMatrix
>(WID_BRAS_MATRIX
)->SetClicked(_railstation
.station_type
);
1486 if (_settings_client
.sound
.click_beep
) SndPlayFx(SND_15_BEEP
);
1488 DeleteWindowById(WC_SELECT_STATION
, 0);
1494 virtual void OnTick()
1496 CheckRedrawStationCoverage(this);
1500 static const NWidgetPart _nested_station_builder_widgets
[] = {
1501 NWidget(NWID_HORIZONTAL
),
1502 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
1503 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
), SetDataTip(STR_STATION_BUILD_RAIL_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
1504 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_BRAS_SHOW_NEWST_DEFSIZE
),
1505 NWidget(WWT_DEFSIZEBOX
, COLOUR_DARK_GREEN
),
1508 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
),
1509 NWidget(NWID_HORIZONTAL
),
1510 NWidget(NWID_VERTICAL
),
1511 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_BRAS_SHOW_NEWST_ADDITIONS
),
1512 NWidget(NWID_HORIZONTAL
), SetPIP(7, 0, 7), SetPadding(2, 0, 1, 0),
1513 NWidget(WWT_MATRIX
, COLOUR_GREY
, WID_BRAS_NEWST_LIST
), SetMinimalSize(122, 71), SetFill(1, 0),
1514 SetMatrixDataTip(1, 0, STR_STATION_BUILD_STATION_CLASS_TOOLTIP
), SetScrollbar(WID_BRAS_NEWST_SCROLL
),
1515 NWidget(NWID_VSCROLLBAR
, COLOUR_GREY
, WID_BRAS_NEWST_SCROLL
),
1518 NWidget(WWT_LABEL
, COLOUR_DARK_GREEN
), SetMinimalSize(144, 11), SetDataTip(STR_STATION_BUILD_ORIENTATION
, STR_NULL
), SetPadding(1, 2, 0, 2),
1519 NWidget(NWID_HORIZONTAL
),
1520 NWidget(NWID_SPACER
), SetMinimalSize(7, 0), SetFill(1, 0),
1521 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(),
1522 NWidget(NWID_SPACER
), SetMinimalSize(2, 0), SetFill(1, 0),
1523 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(),
1524 NWidget(NWID_SPACER
), SetMinimalSize(7, 0), SetFill(1, 0),
1526 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),
1527 NWidget(WWT_LABEL
, COLOUR_DARK_GREEN
), SetMinimalSize(144, 11), SetDataTip(STR_STATION_BUILD_NUMBER_OF_TRACKS
, STR_NULL
), SetPadding(0, 2, 0, 2),
1528 NWidget(NWID_HORIZONTAL
),
1529 NWidget(NWID_SPACER
), SetFill(1, 0),
1530 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_NUM_1
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_1
, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP
),
1531 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_NUM_2
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_2
, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP
),
1532 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_NUM_3
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_3
, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP
),
1533 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_NUM_4
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_4
, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP
),
1534 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_NUM_5
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_5
, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP
),
1535 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_NUM_6
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_6
, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP
),
1536 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_NUM_7
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_7
, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP
),
1537 NWidget(NWID_SPACER
), SetFill(1, 0),
1539 NWidget(WWT_LABEL
, COLOUR_DARK_GREEN
), SetMinimalSize(144, 11), SetDataTip(STR_STATION_BUILD_PLATFORM_LENGTH
, STR_NULL
), SetPadding(2, 2, 0, 2),
1540 NWidget(NWID_HORIZONTAL
),
1541 NWidget(NWID_SPACER
), SetFill(1, 0),
1542 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_LEN_1
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_1
, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP
),
1543 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_LEN_2
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_2
, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP
),
1544 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_LEN_3
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_3
, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP
),
1545 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_LEN_4
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_4
, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP
),
1546 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_LEN_5
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_5
, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP
),
1547 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_LEN_6
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_6
, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP
),
1548 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_LEN_7
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_7
, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP
),
1549 NWidget(NWID_SPACER
), SetFill(1, 0),
1551 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
1552 NWidget(NWID_HORIZONTAL
),
1553 NWidget(NWID_SPACER
), SetMinimalSize(2, 0), SetFill(1, 0),
1554 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
),
1555 NWidget(NWID_SPACER
), SetMinimalSize(2, 0), SetFill(1, 0),
1557 NWidget(WWT_LABEL
, COLOUR_DARK_GREEN
), SetMinimalSize(144, 11), SetDataTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE
, STR_NULL
), SetPadding(3, 2, 0, 2),
1558 NWidget(NWID_HORIZONTAL
),
1559 NWidget(NWID_SPACER
), SetMinimalSize(2, 0), SetFill(1, 0),
1560 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_HIGHLIGHT_OFF
), SetMinimalSize(60, 12),
1561 SetDataTip(STR_STATION_BUILD_COVERAGE_OFF
, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP
),
1562 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_HIGHLIGHT_ON
), SetMinimalSize(60, 12),
1563 SetDataTip(STR_STATION_BUILD_COVERAGE_ON
, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP
),
1564 NWidget(NWID_SPACER
), SetMinimalSize(2, 0), SetFill(1, 0),
1567 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_BRAS_SHOW_NEWST_MATRIX
),
1568 /* We need an additional background for the matrix, as the matrix cannot handle the scrollbar due to not being an NWidgetCore. */
1569 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
), SetScrollbar(WID_BRAS_MATRIX_SCROLL
),
1570 NWidget(NWID_HORIZONTAL
),
1571 NWidget(NWID_MATRIX
, COLOUR_DARK_GREEN
, WID_BRAS_MATRIX
), SetScrollbar(WID_BRAS_MATRIX_SCROLL
), SetPIP(0, 2, 0), SetPadding(2, 0, 0, 0),
1572 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BRAS_IMAGE
), SetMinimalSize(66, 60),
1573 SetFill(0, 0), SetResize(0, 0), SetDataTip(0x0, STR_STATION_BUILD_STATION_TYPE_TOOLTIP
), SetScrollbar(WID_BRAS_MATRIX_SCROLL
),
1576 NWidget(NWID_VSCROLLBAR
, COLOUR_DARK_GREEN
, WID_BRAS_MATRIX_SCROLL
),
1581 NWidget(NWID_HORIZONTAL
),
1582 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_BRAS_COVERAGE_TEXTS
), SetFill(1, 1), SetResize(1, 0),
1583 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_BRAS_SHOW_NEWST_RESIZE
),
1584 NWidget(NWID_VERTICAL
),
1585 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
), SetFill(0, 1), EndContainer(),
1586 NWidget(WWT_RESIZEBOX
, COLOUR_DARK_GREEN
),
1593 /** High level window description of the station-build window (default & newGRF) */
1594 static WindowDesc
_station_builder_desc(
1595 WDP_AUTO
, "build_station_rail", 350, 0,
1596 WC_BUILD_STATION
, WC_BUILD_TOOLBAR
,
1598 _nested_station_builder_widgets
, lengthof(_nested_station_builder_widgets
)
1601 /** Open station build window */
1602 static void ShowStationBuilder(Window
*parent
)
1604 bool newstations
= StationClass::GetClassCount() > 2 || StationClass::Get(STAT_CLASS_DFLT
)->GetSpecCount() != 1;
1605 new BuildRailStationWindow(&_station_builder_desc
, parent
, newstations
);
1608 struct BuildSignalWindow
: public PickerWindowBase
{
1610 Dimension sig_sprite_size
; ///< Maximum size of signal GUI sprites.
1611 int sig_sprite_bottom_offset
; ///< Maximum extent of signal GUI sprite from reference point towards bottom.
1614 * Draw dynamic a signal-sprite in a button in the signal GUI
1615 * Draw the sprite +1px to the right and down if the button is lowered
1617 * @param widget_index index of this widget in the window
1618 * @param image the sprite to draw
1620 void DrawSignalSprite(byte widget_index
, SpriteID image
) const
1623 Dimension sprite_size
= GetSpriteSize(image
, &offset
);
1624 const NWidgetBase
*widget
= this->GetWidget
<NWidgetBase
>(widget_index
);
1625 int x
= widget
->pos_x
- offset
.x
+
1626 (widget
->current_x
- sprite_size
.width
+ offset
.x
) / 2; // centered
1627 int y
= widget
->pos_y
- sig_sprite_bottom_offset
+ WD_IMGBTN_TOP
+
1628 (widget
->current_y
- WD_IMGBTN_TOP
- WD_IMGBTN_BOTTOM
+ sig_sprite_size
.height
) / 2; // aligned to bottom
1630 DrawSprite(image
, PAL_NONE
,
1631 x
+ this->IsWidgetLowered(widget_index
),
1632 y
+ this->IsWidgetLowered(widget_index
));
1636 BuildSignalWindow(WindowDesc
*desc
, Window
*parent
) : PickerWindowBase(desc
, parent
)
1638 this->InitNested(TRANSPORT_RAIL
);
1639 this->OnInvalidateData();
1642 ~BuildSignalWindow()
1644 _convert_signal_button
= false;
1645 _trace_restrict_button
= false;
1648 virtual void OnInit()
1650 /* Calculate maximum signal sprite size. */
1651 this->sig_sprite_size
.width
= 0;
1652 this->sig_sprite_size
.height
= 0;
1653 this->sig_sprite_bottom_offset
= 0;
1654 const RailtypeInfo
*rti
= GetRailTypeInfo(_cur_railtype
);
1655 for (uint type
= SIGTYPE_NORMAL
; type
< SIGTYPE_END
; type
++) {
1656 for (uint variant
= SIG_ELECTRIC
; variant
<= SIG_SEMAPHORE
; variant
++) {
1657 for (uint lowered
= 0; lowered
< 2; lowered
++) {
1659 Dimension sprite_size
= GetSpriteSize(rti
->gui_sprites
.signals
[type
][variant
][lowered
], &offset
);
1660 this->sig_sprite_bottom_offset
= max
<int>(this->sig_sprite_bottom_offset
, sprite_size
.height
);
1661 this->sig_sprite_size
.width
= max
<int>(this->sig_sprite_size
.width
, sprite_size
.width
- offset
.x
);
1662 this->sig_sprite_size
.height
= max
<int>(this->sig_sprite_size
.height
, sprite_size
.height
- offset
.y
);
1668 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
1670 if (widget
== WID_BS_DRAG_SIGNALS_DENSITY_LABEL
) {
1671 /* Two digits for signals density. */
1672 size
->width
= max(size
->width
, 2 * GetDigitWidth() + padding
.width
+ WD_FRAMERECT_LEFT
+ WD_FRAMERECT_RIGHT
);
1673 } else if (IsInsideMM(widget
, WID_BS_SEMAPHORE_NORM
, WID_BS_ELECTRIC_PBS_OWAY
+ 1)) {
1674 size
->width
= max(size
->width
, this->sig_sprite_size
.width
+ WD_IMGBTN_LEFT
+ WD_IMGBTN_RIGHT
);
1675 size
->height
= max(size
->height
, this->sig_sprite_size
.height
+ WD_IMGBTN_TOP
+ WD_IMGBTN_BOTTOM
);
1679 virtual void SetStringParameters(int widget
) const
1682 case WID_BS_DRAG_SIGNALS_DENSITY_LABEL
:
1683 SetDParam(0, _settings_client
.gui
.drag_signals_density
);
1688 virtual void DrawWidget(const Rect
&r
, int widget
) const
1690 if (IsInsideMM(widget
, WID_BS_SEMAPHORE_NORM
, WID_BS_ELECTRIC_LOGIC
+ 1)) {
1691 /* Extract signal from widget number. */
1692 int type
= (widget
- WID_BS_SEMAPHORE_NORM
) % SIGTYPE_END
;
1693 int var
= SIG_SEMAPHORE
- (widget
- WID_BS_SEMAPHORE_NORM
) / SIGTYPE_END
; // SignalVariant order is reversed compared to the widgets.
1694 SpriteID sprite
= GetRailTypeInfo(_cur_railtype
)->gui_sprites
.signals
[type
][var
][this->IsWidgetLowered(widget
)];
1696 this->DrawSignalSprite(widget
, sprite
);
1700 virtual void OnClick(Point pt
, int widget
, int click_count
)
1703 case WID_BS_SEMAPHORE_NORM
:
1704 case WID_BS_SEMAPHORE_ENTRY
:
1705 case WID_BS_SEMAPHORE_EXIT
:
1706 case WID_BS_SEMAPHORE_COMBO
:
1707 case WID_BS_SEMAPHORE_PBS
:
1708 case WID_BS_SEMAPHORE_PBS_OWAY
:
1709 case WID_BS_SEMAPHORE_LOGIC
:
1710 case WID_BS_ELECTRIC_NORM
:
1711 case WID_BS_ELECTRIC_ENTRY
:
1712 case WID_BS_ELECTRIC_EXIT
:
1713 case WID_BS_ELECTRIC_COMBO
:
1714 case WID_BS_ELECTRIC_PBS
:
1715 case WID_BS_ELECTRIC_PBS_OWAY
:
1716 case WID_BS_ELECTRIC_LOGIC
:
1717 this->RaiseWidget((_cur_signal_variant
== SIG_ELECTRIC
? WID_BS_ELECTRIC_NORM
: WID_BS_SEMAPHORE_NORM
) + _cur_signal_type
);
1719 _cur_signal_type
= (SignalType
)((uint
)((widget
- WID_BS_SEMAPHORE_NORM
) % (SIGTYPE_LAST
+ 1)));
1720 _cur_signal_variant
= widget
>= WID_BS_ELECTRIC_NORM
? SIG_ELECTRIC
: SIG_SEMAPHORE
;
1722 /* If 'remove' button of rail build toolbar is active, disable it. */
1723 if (_remove_button_clicked
) {
1724 Window
*w
= FindWindowById(WC_BUILD_TOOLBAR
, TRANSPORT_RAIL
);
1725 if (w
!= NULL
) ToggleRailButton_Remove(w
);
1730 case WID_BS_CONVERT
:
1731 _convert_signal_button
= !_convert_signal_button
;
1732 if (_convert_signal_button
) _trace_restrict_button
= false;
1735 case WID_BS_TRACE_RESTRICT
:
1736 _trace_restrict_button
= !_trace_restrict_button
;
1737 if (_trace_restrict_button
) _convert_signal_button
= false;
1740 case WID_BS_DRAG_SIGNALS_DENSITY_DECREASE
:
1741 if (_settings_client
.gui
.drag_signals_density
> 1) {
1742 _settings_client
.gui
.drag_signals_density
--;
1743 SetWindowDirty(WC_GAME_OPTIONS
, WN_GAME_OPTIONS_GAME_SETTINGS
);
1747 case WID_BS_DRAG_SIGNALS_DENSITY_INCREASE
:
1748 if (_settings_client
.gui
.drag_signals_density
< 20) {
1749 _settings_client
.gui
.drag_signals_density
++;
1750 SetWindowDirty(WC_GAME_OPTIONS
, WN_GAME_OPTIONS_GAME_SETTINGS
);
1757 this->InvalidateData();
1761 * Some data on this window has become invalid.
1762 * @param data Information about the changed data.
1763 * @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.
1765 virtual void OnInvalidateData(int data
= 0, bool gui_scope
= true)
1767 if (!gui_scope
) return;
1768 this->LowerWidget((_cur_signal_variant
== SIG_ELECTRIC
? WID_BS_ELECTRIC_NORM
: WID_BS_SEMAPHORE_NORM
) + _cur_signal_type
);
1770 this->SetWidgetLoweredState(WID_BS_CONVERT
, _convert_signal_button
);
1771 this->SetWidgetLoweredState(WID_BS_TRACE_RESTRICT
, _trace_restrict_button
);
1773 this->SetWidgetDisabledState(WID_BS_DRAG_SIGNALS_DENSITY_DECREASE
, _settings_client
.gui
.drag_signals_density
== 1);
1774 this->SetWidgetDisabledState(WID_BS_DRAG_SIGNALS_DENSITY_INCREASE
, _settings_client
.gui
.drag_signals_density
== 20);
1778 /** Nested widget definition of the build signal window */
1779 static const NWidgetPart _nested_signal_builder_widgets
[] = {
1780 NWidget(NWID_HORIZONTAL
),
1781 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
1782 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
), SetDataTip(STR_BUILD_SIGNAL_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
1784 NWidget(NWID_VERTICAL
, NC_EQUALSIZE
),
1785 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
1786 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_SEMAPHORE_NORM
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_SEMAPHORE_NORM_TOOLTIP
), EndContainer(), SetFill(1, 1),
1787 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_SEMAPHORE_ENTRY
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_SEMAPHORE_ENTRY_TOOLTIP
), EndContainer(), SetFill(1, 1),
1788 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_SEMAPHORE_EXIT
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_SEMAPHORE_EXIT_TOOLTIP
), EndContainer(), SetFill(1, 1),
1789 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_SEMAPHORE_COMBO
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_SEMAPHORE_COMBO_TOOLTIP
), EndContainer(), SetFill(1, 1),
1790 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_SEMAPHORE_PBS
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_SEMAPHORE_PBS_TOOLTIP
), EndContainer(), SetFill(1, 1),
1791 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),
1792 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_SEMAPHORE_LOGIC
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_SEMAPHORE_LOGIC_TOOLTIP
), EndContainer(), SetFill(1, 1),
1793 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_BS_CONVERT
), SetDataTip(SPR_IMG_SIGNAL_CONVERT
, STR_BUILD_SIGNAL_CONVERT_TOOLTIP
), SetFill(1, 1),
1794 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_BS_TRACE_RESTRICT
), SetDataTip(SPR_IMG_SETTINGS
, STR_TRACE_RESTRICT_SIGNAL_GUI_TOOLTIP
), SetFill(1, 1),
1796 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
1797 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_ELECTRIC_NORM
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_ELECTRIC_NORM_TOOLTIP
), EndContainer(), SetFill(1, 1),
1798 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_ELECTRIC_ENTRY
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_ELECTRIC_ENTRY_TOOLTIP
), EndContainer(), SetFill(1, 1),
1799 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_ELECTRIC_EXIT
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_ELECTRIC_EXIT_TOOLTIP
), EndContainer(), SetFill(1, 1),
1800 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_ELECTRIC_COMBO
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_ELECTRIC_COMBO_TOOLTIP
), EndContainer(), SetFill(1, 1),
1801 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_ELECTRIC_PBS
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_ELECTRIC_PBS_TOOLTIP
), EndContainer(), SetFill(1, 1),
1802 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),
1803 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_ELECTRIC_LOGIC
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_ELECTRIC_LOGIC_TOOLTIP
), EndContainer(), SetFill(1, 1),
1804 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_DRAG_SIGNALS_DENSITY_TOOLTIP
), SetFill(1, 1),
1805 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),
1806 NWidget(NWID_HORIZONTAL
), SetPIP(2, 0, 2),
1807 NWidget(NWID_SPACER
), SetFill(1, 0),
1808 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
),
1809 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
),
1810 NWidget(NWID_SPACER
), SetFill(1, 0),
1812 NWidget(NWID_SPACER
), SetMinimalSize(0, 2), SetFill(1, 0),
1814 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
), EndContainer(), SetFill(1, 1),
1819 /** Signal selection window description */
1820 static WindowDesc
_signal_builder_desc(
1821 WDP_AUTO
, "build_signal", 0, 0,
1822 WC_BUILD_SIGNAL
, WC_BUILD_TOOLBAR
,
1824 _nested_signal_builder_widgets
, lengthof(_nested_signal_builder_widgets
)
1828 * Open the signal selection window
1830 static void ShowSignalBuilder(Window
*parent
)
1832 new BuildSignalWindow(&_signal_builder_desc
, parent
);
1835 struct BuildRailDepotWindow
: public PickerWindowBase
{
1836 BuildRailDepotWindow(WindowDesc
*desc
, Window
*parent
) : PickerWindowBase(desc
, parent
)
1838 this->InitNested(TRANSPORT_RAIL
);
1839 this->LowerWidget(_build_depot_direction
+ WID_BRAD_DEPOT_NE
);
1842 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
1844 if (!IsInsideMM(widget
, WID_BRAD_DEPOT_NE
, WID_BRAD_DEPOT_NW
+ 1)) return;
1846 size
->width
= ScaleGUITrad(64) + 2;
1847 size
->height
= ScaleGUITrad(48) + 2;
1850 virtual void DrawWidget(const Rect
&r
, int widget
) const
1852 if (!IsInsideMM(widget
, WID_BRAD_DEPOT_NE
, WID_BRAD_DEPOT_NW
+ 1)) return;
1854 DrawTrainDepotSprite(r
.left
+ 1 + ScaleGUITrad(31), r
.bottom
- ScaleGUITrad(31), widget
- WID_BRAD_DEPOT_NE
+ DIAGDIR_NE
, _cur_railtype
);
1857 virtual void OnClick(Point pt
, int widget
, int click_count
)
1860 case WID_BRAD_DEPOT_NE
:
1861 case WID_BRAD_DEPOT_SE
:
1862 case WID_BRAD_DEPOT_SW
:
1863 case WID_BRAD_DEPOT_NW
:
1864 this->RaiseWidget(_build_depot_direction
+ WID_BRAD_DEPOT_NE
);
1865 _build_depot_direction
= (DiagDirection
)(widget
- WID_BRAD_DEPOT_NE
);
1866 this->LowerWidget(_build_depot_direction
+ WID_BRAD_DEPOT_NE
);
1867 if (_settings_client
.sound
.click_beep
) SndPlayFx(SND_15_BEEP
);
1874 /** Nested widget definition of the build rail depot window */
1875 static const NWidgetPart _nested_build_depot_widgets
[] = {
1876 NWidget(NWID_HORIZONTAL
),
1877 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
1878 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
), SetDataTip(STR_BUILD_DEPOT_TRAIN_ORIENTATION_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
1880 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
),
1881 NWidget(NWID_SPACER
), SetMinimalSize(0, 3),
1882 NWidget(NWID_HORIZONTAL_LTR
),
1883 NWidget(NWID_SPACER
), SetMinimalSize(3, 0), SetFill(1, 0),
1884 NWidget(NWID_VERTICAL
),
1885 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BRAD_DEPOT_NW
), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_TRAIN_ORIENTATION_TOOLTIP
),
1887 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
1888 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BRAD_DEPOT_SW
), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_TRAIN_ORIENTATION_TOOLTIP
),
1891 NWidget(NWID_SPACER
), SetMinimalSize(2, 0),
1892 NWidget(NWID_VERTICAL
),
1893 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BRAD_DEPOT_NE
), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_TRAIN_ORIENTATION_TOOLTIP
),
1895 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
1896 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BRAD_DEPOT_SE
), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_TRAIN_ORIENTATION_TOOLTIP
),
1899 NWidget(NWID_SPACER
), SetMinimalSize(3, 0), SetFill(1, 0),
1901 NWidget(NWID_SPACER
), SetMinimalSize(0, 3),
1905 static WindowDesc
_build_depot_desc(
1906 WDP_AUTO
, NULL
, 0, 0,
1907 WC_BUILD_DEPOT
, WC_BUILD_TOOLBAR
,
1909 _nested_build_depot_widgets
, lengthof(_nested_build_depot_widgets
)
1912 static void ShowBuildTrainDepotPicker(Window
*parent
)
1914 new BuildRailDepotWindow(&_build_depot_desc
, parent
);
1917 struct BuildRailWaypointWindow
: PickerWindowBase
{
1918 BuildRailWaypointWindow(WindowDesc
*desc
, Window
*parent
) : PickerWindowBase(desc
, parent
)
1920 this->CreateNestedTree();
1922 NWidgetMatrix
*matrix
= this->GetWidget
<NWidgetMatrix
>(WID_BRW_WAYPOINT_MATRIX
);
1923 matrix
->SetScrollbar(this->GetScrollbar(WID_BRW_SCROLL
));
1925 this->FinishInitNested(TRANSPORT_RAIL
);
1927 matrix
->SetCount(_waypoint_count
);
1928 matrix
->SetClicked(_cur_waypoint_type
);
1931 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
1934 case WID_BRW_WAYPOINT_MATRIX
:
1935 /* Three blobs high and wide. */
1936 size
->width
+= resize
->width
* 2;
1937 size
->height
+= resize
->height
* 2;
1939 /* Resizing in X direction only at blob size, but at pixel level in Y. */
1943 case WID_BRW_WAYPOINT
:
1944 size
->width
= ScaleGUITrad(64) + 2;
1945 size
->height
= ScaleGUITrad(58) + 2;
1950 virtual void DrawWidget(const Rect
&r
, int widget
) const
1952 switch (GB(widget
, 0, 16)) {
1953 case WID_BRW_WAYPOINT
: {
1954 byte type
= GB(widget
, 16, 16);
1955 const StationSpec
*statspec
= StationClass::Get(STAT_CLASS_WAYP
)->GetSpec(type
);
1956 DrawWaypointSprite(r
.left
+ 1 + ScaleGUITrad(31), r
.bottom
- ScaleGUITrad(31), type
, _cur_railtype
);
1958 if (!IsStationAvailable(statspec
)) {
1959 GfxFillRect(r
.left
+ 1, r
.top
+ 1, r
.right
- 1, r
.bottom
- 1, PC_BLACK
, FILLRECT_CHECKER
);
1965 virtual void OnClick(Point pt
, int widget
, int click_count
)
1967 switch (GB(widget
, 0, 16)) {
1968 case WID_BRW_WAYPOINT
: {
1969 byte type
= GB(widget
, 16, 16);
1970 this->GetWidget
<NWidgetMatrix
>(WID_BRW_WAYPOINT_MATRIX
)->SetClicked(_cur_waypoint_type
);
1972 /* Check station availability callback */
1973 const StationSpec
*statspec
= StationClass::Get(STAT_CLASS_WAYP
)->GetSpec(type
);
1974 if (!IsStationAvailable(statspec
)) return;
1976 _cur_waypoint_type
= type
;
1977 this->GetWidget
<NWidgetMatrix
>(WID_BRW_WAYPOINT_MATRIX
)->SetClicked(_cur_waypoint_type
);
1978 if (_settings_client
.sound
.click_beep
) SndPlayFx(SND_15_BEEP
);
1986 /** Nested widget definition for the build NewGRF rail waypoint window */
1987 static const NWidgetPart _nested_build_waypoint_widgets
[] = {
1988 NWidget(NWID_HORIZONTAL
),
1989 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
1990 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
), SetDataTip(STR_WAYPOINT_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
1991 NWidget(WWT_DEFSIZEBOX
, COLOUR_DARK_GREEN
),
1993 NWidget(NWID_HORIZONTAL
),
1994 NWidget(NWID_MATRIX
, COLOUR_DARK_GREEN
, WID_BRW_WAYPOINT_MATRIX
), SetPIP(3, 2, 3), SetScrollbar(WID_BRW_SCROLL
),
1995 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BRW_WAYPOINT
), SetMinimalSize(66, 60), SetDataTip(0x0, STR_WAYPOINT_GRAPHICS_TOOLTIP
), SetScrollbar(WID_BRW_SCROLL
), EndContainer(),
1997 NWidget(NWID_VERTICAL
),
1998 NWidget(NWID_VSCROLLBAR
, COLOUR_DARK_GREEN
, WID_BRW_SCROLL
),
1999 NWidget(WWT_RESIZEBOX
, COLOUR_DARK_GREEN
),
2004 static WindowDesc
_build_waypoint_desc(
2005 WDP_AUTO
, "build_waypoint", 0, 0,
2006 WC_BUILD_WAYPOINT
, WC_BUILD_TOOLBAR
,
2008 _nested_build_waypoint_widgets
, lengthof(_nested_build_waypoint_widgets
)
2011 static void ShowBuildWaypointPicker(Window
*parent
)
2013 new BuildRailWaypointWindow(&_build_waypoint_desc
, parent
);
2017 * Initialize rail building GUI settings
2019 void InitializeRailGui()
2021 _build_depot_direction
= DIAGDIR_NW
;
2025 * Re-initialize rail-build toolbar after toggling support for electric trains
2026 * @param disable Boolean whether electric trains are disabled (removed from the game)
2028 void ReinitGuiAfterToggleElrail(bool disable
)
2030 extern RailType _last_built_railtype
;
2031 if (disable
&& _last_built_railtype
== RAILTYPE_ELECTRIC
) {
2032 _last_built_railtype
= _cur_railtype
= RAILTYPE_RAIL
;
2033 BuildRailToolbarWindow
*w
= dynamic_cast<BuildRailToolbarWindow
*>(FindWindowById(WC_BUILD_TOOLBAR
, TRANSPORT_RAIL
));
2034 if (w
!= NULL
) w
->ModifyRailType(_cur_railtype
);
2036 MarkWholeScreenDirty();
2039 /** Set the initial (default) railtype to use */
2040 static void SetDefaultRailGui()
2042 if (_local_company
== COMPANY_SPECTATOR
|| !Company::IsValidID(_local_company
)) return;
2044 extern RailType _last_built_railtype
;
2045 RailType rt
= (RailType
)(_settings_client
.gui
.default_rail_type
+ RAILTYPE_END
);
2046 if (rt
== DEF_RAILTYPE_MOST_USED
) {
2047 /* Find the most used rail type */
2048 RailType count
[RAILTYPE_END
];
2049 memset(count
, 0, sizeof(count
));
2050 for (TileIndex t
= 0; t
< MapSize(); t
++) {
2051 if (IsTileType(t
, MP_RAILWAY
) || IsLevelCrossingTile(t
) || HasStationTileRail(t
) ||
2052 (IsTileType(t
, MP_TUNNELBRIDGE
) && GetTunnelBridgeTransportType(t
) == TRANSPORT_RAIL
)) {
2053 count
[GetRailType(t
)]++;
2058 for (RailType r
= RAILTYPE_ELECTRIC
; r
< RAILTYPE_END
; r
++) {
2059 if (count
[r
] >= count
[rt
]) rt
= r
;
2062 /* No rail, just get the first available one */
2063 if (count
[rt
] == 0) rt
= DEF_RAILTYPE_FIRST
;
2066 case DEF_RAILTYPE_FIRST
:
2068 while (rt
< RAILTYPE_END
&& !HasRailtypeAvail(_local_company
, rt
)) rt
++;
2071 case DEF_RAILTYPE_LAST
:
2072 rt
= GetBestRailtype(_local_company
);
2079 _last_built_railtype
= _cur_railtype
= rt
;
2080 BuildRailToolbarWindow
*w
= dynamic_cast<BuildRailToolbarWindow
*>(FindWindowById(WC_BUILD_TOOLBAR
, TRANSPORT_RAIL
));
2081 if (w
!= NULL
) w
->ModifyRailType(_cur_railtype
);
2085 * Updates the current signal variant used in the signal GUI
2086 * to the one adequate to current year.
2087 * @param p needed to be called when a setting changes
2088 * @return success, needed for settings
2090 bool ResetSignalVariant(int32 p
)
2092 SignalVariant new_variant
= (_cur_year
< _settings_client
.gui
.semaphore_build_before
? SIG_SEMAPHORE
: SIG_ELECTRIC
);
2094 if (new_variant
!= _cur_signal_variant
) {
2095 Window
*w
= FindWindowById(WC_BUILD_SIGNAL
, 0);
2098 w
->RaiseWidget((_cur_signal_variant
== SIG_ELECTRIC
? WID_BS_ELECTRIC_NORM
: WID_BS_SEMAPHORE_NORM
) + _cur_signal_type
);
2100 _cur_signal_variant
= new_variant
;
2107 * Resets the rail GUI - sets default railtype to build
2108 * and resets the signal GUI
2110 void InitializeRailGUI()
2112 SetDefaultRailGui();
2114 _convert_signal_button
= false;
2115 _trace_restrict_button
= false;
2116 _cur_signal_type
= _default_signal_type
[_settings_client
.gui
.default_signal_type
];
2117 ResetSignalVariant();
2121 * Create a drop down list for all the rail types of the local company.
2122 * @param for_replacement Whether this list is for the replacement window.
2123 * @param all_option Whether to add an 'all types' item.
2124 * @return The populated and sorted #DropDownList.
2126 DropDownList
*GetRailTypeDropDownList(bool for_replacement
, bool all_option
)
2128 RailTypes used_railtypes
= RAILTYPES_NONE
;
2130 /* Find the used railtypes. */
2132 FOR_ALL_ENGINES_OF_TYPE(e
, VEH_TRAIN
) {
2133 if (!HasBit(e
->info
.climates
, _settings_game
.game_creation
.landscape
)) continue;
2135 used_railtypes
|= GetRailTypeInfo(e
->u
.rail
.railtype
)->introduces_railtypes
;
2138 /* Get the date introduced railtypes as well. */
2139 used_railtypes
= AddDateIntroducedRailTypes(used_railtypes
, MAX_DAY
);
2141 const Company
*c
= Company::Get(_local_company
);
2142 DropDownList
*list
= new DropDownList();
2145 DropDownListStringItem
*item
= new DropDownListStringItem(STR_REPLACE_ALL_RAILTYPE
, INVALID_RAILTYPE
, false);
2146 *list
->Append() = item
;
2150 FOR_ALL_SORTED_RAILTYPES(rt
) {
2151 /* If it's not used ever, don't show it to the user. */
2152 if (!HasBit(used_railtypes
, rt
)) continue;
2154 const RailtypeInfo
*rti
= GetRailTypeInfo(rt
);
2156 StringID str
= for_replacement
? rti
->strings
.replace_text
: (rti
->max_speed
> 0 ? STR_TOOLBAR_RAILTYPE_VELOCITY
: STR_JUST_STRING
);
2157 DropDownListParamStringItem
*item
= new DropDownListParamStringItem(str
, rt
, !HasBit(c
->avail_railtypes
, rt
));
2158 item
->SetParam(0, rti
->strings
.menu_text
);
2159 item
->SetParam(1, rti
->max_speed
);
2160 *list
->Append() = item
;