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_func.h"
43 #include "map/depot.h"
44 #include "map/bridge.h"
46 #include "widgets/rail_widget.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 SignalVariant _cur_signal_variant
; ///< set the signal variant (for signal GUI)
56 static SignalType _cur_signal_type
; ///< set the signal type (for signal GUI)
58 /* Map the setting: default_signal_type to the corresponding signal type */
59 static const SignalType _default_signal_type
[] = {SIGTYPE_NORMAL
, SIGTYPE_PBS
, SIGTYPE_PBS_ONEWAY
};
61 struct RailStationGUISettings
{
62 Axis orientation
; ///< Currently selected rail station orientation
64 bool newstations
; ///< Are custom station definitions available?
65 StationClassID station_class
; ///< Currently selected custom station class (if newstations is \c true )
66 byte station_type
; ///< %Station type within the currently selected custom station class (if newstations is \c true )
67 byte station_count
; ///< Number of custom stations (if newstations is \c true )
69 static RailStationGUISettings _railstation
; ///< Settings of the station builder GUI
72 /** Dragging actions in the rail toolbar. */
74 DRAG_DEMOLISH_AREA
, ///< Clear area
75 DRAG_BUILD_BRIDGE
, ///< Bridge placement
76 DRAG_PLACE_RAIL
, ///< Rail placement
77 DRAG_BUILD_SIGNALS
, ///< Signal placement
78 DRAG_STATION
, ///< Station placement/removal
79 DRAG_BUILD_WAYPOINT_X
, ///< Waypoint placement along AXIS_X
80 DRAG_BUILD_WAYPOINT_Y
, ///< Waypoint placement along AXIS_Y
81 DRAG_REMOVE_WAYPOINT
, ///< Waypoint removal
82 DRAG_CONVERT_RAIL
, ///< Rail conversion
86 static void HandleStationPlacement(TileIndex start
, TileIndex end
);
87 static void ShowBuildTrainDepotPicker(Window
*parent
);
88 static void ShowBuildWaypointPicker(Window
*parent
);
89 static void ShowStationBuilder(Window
*parent
);
90 static void ShowSignalBuilder(Window
*parent
);
93 * Check whether a station type can be build.
94 * @return true if building is allowed.
96 static bool IsStationAvailable(const StationSpec
*statspec
)
98 if (statspec
== NULL
|| !HasBit(statspec
->callback_mask
, CBM_STATION_AVAIL
)) return true;
100 uint16 cb_res
= GetStationCallback (CBID_STATION_AVAILABILITY
, 0, 0, statspec
, _cur_railtype
);
101 if (cb_res
== CALLBACK_FAILED
) return true;
103 return Convert8bitBooleanCallback(statspec
->grf_prop
.grffile
, CBID_STATION_AVAILABILITY
, cb_res
);
106 void CcPlaySound_SPLAT_RAIL(const CommandCost
&result
, TileIndex tile
, uint32 p1
, uint32 p2
)
108 if (result
.Succeeded() && _settings_client
.sound
.confirm
) SndPlayTileFx(SND_20_SPLAT_RAIL
, tile
);
111 void CcSingleRail(const CommandCost
&result
, TileIndex tile
, uint32 p1
, uint32 p2
)
113 if (HasBit(p1
, 31)) return;
115 CcPlaySound_SPLAT_RAIL(result
, tile
, p1
, p2
);
118 StringID
GetErrBuildSingleRail (TileIndex tile
, uint32 p1
, uint32 p2
, const char *text
)
120 return HasBit(p1
, 31) ? 0 : STR_ERROR_CAN_T_BUILD_RAILROAD_TRACK
;
123 void CcRailDepot(const CommandCost
&result
, TileIndex tile
, uint32 p1
, uint32 p2
)
125 struct PlaceDepotExtraData
{
126 DiagDirection dir
; ///< direction to check
127 Track track
; ///< track to build
130 static const PlaceDepotExtraData place_depot_extra_data
[4][3] = {
131 { {DIAGDIR_SE
, TRACK_LEFT
}, {DIAGDIR_SW
, TRACK_X
}, {DIAGDIR_NW
, TRACK_LOWER
} },
132 { {DIAGDIR_SW
, TRACK_UPPER
}, {DIAGDIR_NW
, TRACK_Y
}, {DIAGDIR_NE
, TRACK_LEFT
} },
133 { {DIAGDIR_SE
, TRACK_UPPER
}, {DIAGDIR_NE
, TRACK_X
}, {DIAGDIR_NW
, TRACK_RIGHT
} },
134 { {DIAGDIR_SW
, TRACK_RIGHT
}, {DIAGDIR_SE
, TRACK_Y
}, {DIAGDIR_NE
, TRACK_LOWER
} },
137 if (result
.Failed()) return;
139 DiagDirection dir
= (DiagDirection
)p2
;
141 if (_settings_client
.sound
.confirm
) SndPlayTileFx(SND_20_SPLAT_RAIL
, tile
);
142 if (!_settings_client
.gui
.persistent_buildingtools
) ResetPointerMode();
144 tile
+= TileOffsByDiagDir(dir
);
146 if (IsNormalRailTile(tile
) && !HasSignalOnTrack(tile
, TRACK_UPPER
) && !HasSignalOnTrack(tile
, TRACK_LOWER
)) {
147 for (int i
= 0; i
< 3; i
++) {
148 if ((GetTrackBits(tile
) & DiagdirReachesTracks(place_depot_extra_data
[dir
][i
].dir
)) != TRACK_BIT_NONE
) {
149 DoCommandP(tile
, _cur_railtype
| (1 << 31), place_depot_extra_data
[dir
][i
].track
, CMD_BUILD_SINGLE_RAIL
);
156 * Place a rail waypoint.
157 * @param tile Position to start dragging a waypoint.
159 static void PlaceRail_Waypoint(TileIndex tile
)
161 if (_remove_button_clicked
) {
162 VpStartPlaceSizing(tile
, VPM_X_AND_Y
, DRAG_REMOVE_WAYPOINT
);
166 switch (GetAxisForNewWaypoint(tile
)) {
168 VpStartPlaceSizing (tile
, VPM_Y
, DRAG_BUILD_WAYPOINT_X
);
172 VpStartPlaceSizing (tile
, VPM_X
, DRAG_BUILD_WAYPOINT_Y
);
176 /* Tile where we can't build rail waypoints. This is always going to fail,
177 * but provides the user with a proper error message. */
178 DoCommandP (tile
, 1 << 8 | 1 << 16, STAT_CLASS_WAYP
| INVALID_STATION
<< 16, CMD_BUILD_RAIL_WAYPOINT
);
182 VpSetPlaceSizingLimit (_settings_game
.station
.station_spread
);
185 void CcStation(const CommandCost
&result
, TileIndex tile
, uint32 p1
, uint32 p2
)
187 if (result
.Failed()) return;
189 if (_settings_client
.sound
.confirm
) SndPlayTileFx(SND_20_SPLAT_RAIL
, tile
);
190 /* Only close the station builder window if the default station and non persistent building is chosen. */
191 if (_railstation
.station_class
== STAT_CLASS_DFLT
&& _railstation
.station_type
== 0 && !_settings_client
.gui
.persistent_buildingtools
) ResetPointerMode();
194 /** Get the only allowed bit, or a default if several are available. */
195 static inline uint
GetSingleAllowedValue (byte disallowed
, uint def
)
197 /* Sign-extend bit 7. */
198 uint allowed
= (int)(int8
)(~disallowed
);
199 return HasExactlyOneBit (allowed
) ? (FindFirstBit (allowed
) + 1) : def
;
203 * Place a rail station.
204 * @param tile Position to place or start dragging a station.
206 static void PlaceRail_Station(TileIndex tile
)
208 if (_remove_button_clicked
) {
209 VpStartPlaceSizing (tile
, VPM_X_AND_Y
, DRAG_STATION
);
214 if (_settings_client
.gui
.station_dragdrop
) {
215 const StationSpec
*statspec
= _railstation
.newstations
? StationClass::Get(_railstation
.station_class
)->GetSpec(_railstation
.station_type
) : NULL
;
216 if (statspec
== NULL
) {
219 w
= GetSingleAllowedValue (statspec
->disallowed_platforms
, 0);
220 h
= GetSingleAllowedValue (statspec
->disallowed_lengths
, 0);
223 ViewportPlaceMethod method
;
224 if (w
== 0 || h
== 0) {
226 /* fixed number of tracks */
227 method
= _railstation
.orientation
? VPM_Y
: VPM_X
;
229 /* fixed platform length */
230 method
= _railstation
.orientation
? VPM_X
: VPM_Y
;
232 method
= VPM_X_AND_Y
;
234 VpStartPlaceSizing (tile
, method
, DRAG_STATION
, _settings_game
.station
.station_spread
);
238 w
= _settings_client
.gui
.station_numtracks
;
239 h
= _settings_client
.gui
.station_platlength
;
242 uint32 p1
= _cur_railtype
| _railstation
.orientation
<< 4 | w
<< 8 | h
<< 16 | _ctrl_pressed
<< 24;
243 uint32 p2
= _railstation
.station_class
| _railstation
.station_type
<< 8 | INVALID_STATION
<< 16;
245 if (!_railstation
.orientation
) Swap (w
, h
);
247 Command
cmdcont (tile
, p1
, p2
, CMD_BUILD_RAIL_STATION
);
248 ShowSelectStationIfNeeded (&cmdcont
, TileArea (tile
, w
, h
));
251 StringID
GetErrBuildSignals (TileIndex tile
, uint32 p1
, uint32 p2
, const char *text
)
253 switch (GB(p1
, 17, 3)) {
254 case SIGNALS_CONVERT
:
255 case SIGNALS_TOGGLE_VARIANT
:
256 return STR_ERROR_SIGNAL_CAN_T_CONVERT_SIGNALS_HERE
;
259 return STR_ERROR_CAN_T_BUILD_SIGNALS_HERE
;
264 * Build a new signal or edit/remove a present signal, use CmdBuildSingleSignal() or CmdRemoveSingleSignal() in rail_cmd.cpp
266 * @param tile The tile where the signal will build or edit
268 static void GenericPlaceSignals(TileIndex tile
)
270 TrackBits trackbits
= TrackStatusToTrackBits(GetTileRailwayStatus(tile
));
272 if (trackbits
& TRACK_BIT_VERT
) { // N-S direction
273 trackbits
= (_tile_fract_coords
.x
<= _tile_fract_coords
.y
) ? TRACK_BIT_RIGHT
: TRACK_BIT_LEFT
;
276 if (trackbits
& TRACK_BIT_HORZ
) { // E-W direction
277 trackbits
= (_tile_fract_coords
.x
+ _tile_fract_coords
.y
<= 15) ? TRACK_BIT_UPPER
: TRACK_BIT_LOWER
;
280 Track track
= FindFirstTrack(trackbits
);
282 if (_remove_button_clicked
) {
283 DoCommandP(tile
, track
, 0, CMD_REMOVE_SIGNALS
);
285 const Window
*w
= FindWindowById(WC_BUILD_SIGNAL
, 0);
287 /* Map the setting cycle_signal_types to the allowed signal bitmask. */
288 static const uint signal_mask
[] = {
289 (1 << SIGTYPE_PBS
) - 1,
290 (1 << SIGTYPE_END
) - (1 << SIGTYPE_PBS
),
291 (1 << SIGTYPE_END
) - 1,
294 /* various bitstuffed elements for CmdBuildSingleSignal() */
298 /* signal GUI not used */
299 SB(p1
, 4, 1, ((_cur_year
< _settings_client
.gui
.semaphore_build_before
) ^ _ctrl_pressed
) ? SIG_SEMAPHORE
: SIG_ELECTRIC
);
300 SB(p1
, 5, 3, _default_signal_type
[_settings_client
.gui
.default_signal_type
]);
301 SB(p1
, 17, 3, _ctrl_pressed
? SIGNALS_CYCLE_TYPE
: SIGNALS_BUILD
);
302 } else if (!_convert_signal_button
) {
303 /* signal GUI is used, not converting */
304 SB(p1
, 4, 1, _cur_signal_variant
^ _ctrl_pressed
);
305 SB(p1
, 5, 3, _cur_signal_type
);
306 SB(p1
, 17, 3, _ctrl_pressed
? SIGNALS_CYCLE_TYPE
: SIGNALS_BUILD
);
308 /* signal GUI is used, converting */
309 SB(p1
, 4, 1, _cur_signal_variant
^ _ctrl_pressed
);
310 SB(p1
, 5, 3, _cur_signal_type
);
311 SB(p1
, 17, 3, _ctrl_pressed
? SIGNALS_TOGGLE_VARIANT
: SIGNALS_CONVERT
);
314 DoCommandP(tile
, p1
, signal_mask
[_settings_client
.gui
.cycle_signal_types
], CMD_BUILD_SIGNALS
);
318 /** Show the bridge building window between a pair of tiles. */
319 static void HandleBuildRailBridge (TileIndex start_tile
, TileIndex end_tile
)
321 if (!_settings_client
.gui
.persistent_buildingtools
) ResetPointerMode();
322 ShowBuildBridgeWindow (start_tile
, end_tile
, TRANSPORT_RAIL
, _cur_railtype
);
326 * Toggles state of the Remove button of Build rail toolbar
327 * @param w window the button belongs to
329 static void ToggleRailButton_Remove(Window
*w
)
331 DeleteWindowById(WC_SELECT_STATION
, 0);
332 w
->ToggleWidgetLoweredState(WID_RAT_REMOVE
);
333 w
->SetWidgetDirty(WID_RAT_REMOVE
);
334 _remove_button_clicked
= w
->IsWidgetLowered(WID_RAT_REMOVE
);
335 SetSelectionRed(_remove_button_clicked
);
339 * Updates the Remove button because of Ctrl state change
340 * @param w window the button belongs to
341 * @return true iff the remove button was changed
343 static bool RailToolbar_CtrlChanged(Window
*w
)
345 if (w
->IsWidgetDisabled(WID_RAT_REMOVE
)) return false;
347 /* allow ctrl to switch remove mode only for these widgets */
348 for (uint i
= WID_RAT_BUILD_NS
; i
<= WID_RAT_BUILD_STATION
; i
++) {
349 if ((i
<= WID_RAT_AUTORAIL
|| i
>= WID_RAT_BUILD_WAYPOINT
) && w
->IsWidgetLowered(i
)) {
350 ToggleRailButton_Remove(w
);
359 /** Set the selection size for building a station. */
360 static void SetStationTileSelectSize (void)
363 if (_settings_client
.gui
.station_dragdrop
) {
364 const StationSpec
*statspec
= _railstation
.newstations
? StationClass::Get(_railstation
.station_class
)->GetSpec(_railstation
.station_type
) : NULL
;
365 if (statspec
== NULL
) {
368 x
= GetSingleAllowedValue (statspec
->disallowed_platforms
, 1);
369 y
= GetSingleAllowedValue (statspec
->disallowed_lengths
, 1);
372 x
= _settings_client
.gui
.station_numtracks
;
373 y
= _settings_client
.gui
.station_platlength
;
376 if (_railstation
.orientation
== AXIS_X
) Swap(x
, y
);
377 SetTileSelectSize (x
, y
);
378 VpSetPlaceSizingLimit (_settings_game
.station
.station_spread
);
382 * The "remove"-button click proc of the build-rail toolbar.
383 * @param w Build-rail toolbar window
384 * @see BuildRailToolbarWindow::OnClick()
386 static void BuildRailClick_Remove(Window
*w
)
388 if (w
->IsWidgetDisabled(WID_RAT_REMOVE
)) return;
389 ToggleRailButton_Remove(w
);
390 if (_settings_client
.sound
.click_beep
) SndPlayFx(SND_15_BEEP
);
392 /* handle station builder */
393 if (w
->IsWidgetLowered(WID_RAT_BUILD_STATION
)) {
394 if (_remove_button_clicked
) {
395 /* starting drag & drop remove */
396 SetTileSelectSize(1, 1);
397 VpSetPlaceSizingLimit (0);
399 /* starting station build mode */
400 SetStationTileSelectSize();
402 } else if (w
->IsWidgetLowered(WID_RAT_BUILD_WAYPOINT
)) {
403 /* Dragging is different for waypoints when removing,
409 static void HandleAutodirPlacement (TileIndex start
, TileIndex end
)
411 Track track
= (Track
)(_thd
.drawstyle
& HT_TRACK_MASK
); // 0..5
412 assert (IsValidTrack (track
));
414 if (start
== end
) { // one-tile case
415 DoCommandP (end
, _cur_railtype
, track
,
416 _remove_button_clicked
? CMD_REMOVE_SINGLE_RAIL
: CMD_BUILD_SINGLE_RAIL
);
420 DoCommandP (start
, end
, _cur_railtype
| (track
<< 4),
421 _remove_button_clicked
? CMD_REMOVE_RAILROAD_TRACK
: CMD_BUILD_RAILROAD_TRACK
);
425 * Build new signals or remove signals or (if only one tile marked) edit a signal.
427 * If one tile marked abort and use GenericPlaceSignals()
428 * else use CmdBuildSingleSignal() or CmdRemoveSingleSignal() in rail_cmd.cpp to build many signals
430 static void HandleAutoSignalPlacement (TileIndex start
, TileIndex end
)
432 uint32 p2
= GB(_thd
.drawstyle
, 0, 3); // 0..5
434 if (start
== end
) { // one-tile case
435 GenericPlaceSignals (end
);
439 const Window
*w
= FindWindowById(WC_BUILD_SIGNAL
, 0);
442 /* signal GUI is used */
443 SB(p2
, 4, 1, _cur_signal_variant
);
444 SB(p2
, 6, 1, _ctrl_pressed
);
445 SB(p2
, 7, 3, _cur_signal_type
);
446 SB(p2
, 24, 8, _settings_client
.gui
.drag_signals_density
);
447 SB(p2
, 10, 1, !_settings_client
.gui
.drag_signals_fixed_distance
);
449 SB(p2
, 4, 1, (_cur_year
< _settings_client
.gui
.semaphore_build_before
? SIG_SEMAPHORE
: SIG_ELECTRIC
));
450 SB(p2
, 6, 1, _ctrl_pressed
);
451 SB(p2
, 7, 3, _default_signal_type
[_settings_client
.gui
.default_signal_type
]);
452 SB(p2
, 24, 8, _settings_client
.gui
.drag_signals_density
);
453 SB(p2
, 10, 1, !_settings_client
.gui
.drag_signals_fixed_distance
);
456 /* _settings_client.gui.drag_signals_density is given as a parameter such that each user
457 * in a network game can specify his/her own signal density */
458 DoCommandP (start
, end
, p2
,
459 _remove_button_clicked
? CMD_REMOVE_SIGNAL_TRACK
: CMD_BUILD_SIGNAL_TRACK
);
463 /** Rail toolbar management class. */
464 struct BuildRailToolbarWindow
: Window
{
465 RailType railtype
; ///< Rail type to build.
466 int last_user_action
; ///< Last started user action.
468 BuildRailToolbarWindow (const WindowDesc
*desc
, RailType railtype
) :
469 Window (desc
), railtype ((RailType
)0),
470 last_user_action (WIDGET_LIST_END
)
472 this->InitNested(TRANSPORT_RAIL
);
473 this->SetupRailToolbar(railtype
);
474 this->DisableWidget(WID_RAT_REMOVE
);
476 if (_settings_client
.gui
.link_terraform_toolbar
) ShowTerraformToolbar(this);
479 void OnDelete (void) FINAL_OVERRIDE
481 if (_settings_client
.gui
.link_terraform_toolbar
) DeleteWindowById(WC_SCEN_LAND_GEN
, 0, false);
485 * Some data on this window has become invalid.
486 * @param data Information about the changed data.
487 * @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.
489 virtual void OnInvalidateData(int data
= 0, bool gui_scope
= true)
491 if (!gui_scope
) return;
493 if (!CanBuildVehicleInfrastructure(VEH_TRAIN
)) this->Delete();
497 * Configures the rail toolbar for railtype given
498 * @param railtype the railtype to display
500 void SetupRailToolbar(RailType railtype
)
502 this->railtype
= railtype
;
503 const RailtypeInfo
*rti
= GetRailTypeInfo(railtype
);
505 assert(railtype
< RAILTYPE_END
);
506 this->GetWidget
<NWidgetCore
>(WID_RAT_BUILD_NS
)->widget_data
= rti
->gui_sprites
.build_ns_rail
;
507 this->GetWidget
<NWidgetCore
>(WID_RAT_BUILD_X
)->widget_data
= rti
->gui_sprites
.build_x_rail
;
508 this->GetWidget
<NWidgetCore
>(WID_RAT_BUILD_EW
)->widget_data
= rti
->gui_sprites
.build_ew_rail
;
509 this->GetWidget
<NWidgetCore
>(WID_RAT_BUILD_Y
)->widget_data
= rti
->gui_sprites
.build_y_rail
;
510 this->GetWidget
<NWidgetCore
>(WID_RAT_AUTORAIL
)->widget_data
= rti
->gui_sprites
.auto_rail
;
511 this->GetWidget
<NWidgetCore
>(WID_RAT_BUILD_DEPOT
)->widget_data
= rti
->gui_sprites
.build_depot
;
512 this->GetWidget
<NWidgetCore
>(WID_RAT_CONVERT_RAIL
)->widget_data
= rti
->gui_sprites
.convert_rail
;
513 this->GetWidget
<NWidgetCore
>(WID_RAT_BUILD_TUNNEL
)->widget_data
= rti
->gui_sprites
.build_tunnel
;
517 * Switch to another rail type.
518 * @param railtype New rail type.
520 void ModifyRailType(RailType railtype
)
522 this->SetupRailToolbar(railtype
);
526 void UpdateRemoveWidgetStatus(int clicked_widget
)
528 switch (clicked_widget
) {
530 /* If it is the removal button that has been clicked, do nothing,
531 * as it is up to the other buttons to drive removal status */
534 case WID_RAT_BUILD_NS
:
535 case WID_RAT_BUILD_X
:
536 case WID_RAT_BUILD_EW
:
537 case WID_RAT_BUILD_Y
:
538 case WID_RAT_AUTORAIL
:
539 case WID_RAT_BUILD_WAYPOINT
:
540 case WID_RAT_BUILD_STATION
:
541 case WID_RAT_BUILD_SIGNALS
:
542 /* Removal button is enabled only if the rail/signal/waypoint/station
543 * button is still lowered. Once raised, it has to be disabled */
544 this->SetWidgetDisabledState(WID_RAT_REMOVE
, !this->IsWidgetLowered(clicked_widget
));
548 /* When any other buttons than rail/signal/waypoint/station, raise and
549 * disable the removal button */
550 this->DisableWidget(WID_RAT_REMOVE
);
551 this->RaiseWidget(WID_RAT_REMOVE
);
556 virtual void SetStringParameters(int widget
) const
558 if (widget
== WID_RAT_CAPTION
) {
559 const RailtypeInfo
*rti
= GetRailTypeInfo(this->railtype
);
560 if (rti
->max_speed
> 0) {
561 SetDParam(0, STR_TOOLBAR_RAILTYPE_VELOCITY
);
562 SetDParam(1, rti
->strings
.toolbar_caption
);
563 SetDParam(2, rti
->max_speed
);
565 SetDParam(0, rti
->strings
.toolbar_caption
);
570 virtual void OnClick(Point pt
, int widget
, int click_count
)
572 if (widget
< WID_RAT_BUILD_NS
) return;
574 _remove_button_clicked
= false;
576 case WID_RAT_BUILD_NS
:
577 HandlePlacePushButton (this, WID_RAT_BUILD_NS
, GetRailTypeInfo(_cur_railtype
)->cursor
.rail_ns
, POINTER_RAIL_V
);
578 this->last_user_action
= widget
;
581 case WID_RAT_BUILD_X
:
582 HandlePlacePushButton (this, WID_RAT_BUILD_X
, GetRailTypeInfo(_cur_railtype
)->cursor
.rail_swne
, POINTER_RAIL_X
);
583 this->last_user_action
= widget
;
586 case WID_RAT_BUILD_EW
:
587 HandlePlacePushButton (this, WID_RAT_BUILD_EW
, GetRailTypeInfo(_cur_railtype
)->cursor
.rail_ew
, POINTER_RAIL_H
);
588 this->last_user_action
= widget
;
591 case WID_RAT_BUILD_Y
:
592 HandlePlacePushButton (this, WID_RAT_BUILD_Y
, GetRailTypeInfo(_cur_railtype
)->cursor
.rail_nwse
, POINTER_RAIL_Y
);
593 this->last_user_action
= widget
;
596 case WID_RAT_AUTORAIL
:
597 HandlePlacePushButton (this, WID_RAT_AUTORAIL
, GetRailTypeInfo(_cur_railtype
)->cursor
.autorail
, POINTER_RAIL_AUTO
);
598 this->last_user_action
= widget
;
601 case WID_RAT_DEMOLISH
:
602 HandlePlacePushButton (this, WID_RAT_DEMOLISH
, ANIMCURSOR_DEMOLISH
, POINTER_TILE
);
603 this->last_user_action
= widget
;
606 case WID_RAT_BUILD_DEPOT
:
607 if (HandlePlacePushButton (this, WID_RAT_BUILD_DEPOT
, GetRailTypeInfo(_cur_railtype
)->cursor
.depot
, POINTER_TILE
)) {
608 ShowBuildTrainDepotPicker(this);
609 this->last_user_action
= widget
;
613 case WID_RAT_BUILD_WAYPOINT
:
614 this->last_user_action
= widget
;
615 _waypoint_count
= StationClass::Get(STAT_CLASS_WAYP
)->GetSpecCount();
616 if (HandlePlacePushButton (this, WID_RAT_BUILD_WAYPOINT
, SPR_CURSOR_WAYPOINT
, POINTER_TILE
) && _waypoint_count
> 1) {
617 ShowBuildWaypointPicker(this);
621 case WID_RAT_BUILD_STATION
:
622 if (HandlePlacePushButton (this, WID_RAT_BUILD_STATION
, SPR_CURSOR_RAIL_STATION
, POINTER_TILE
)) {
623 ShowStationBuilder(this);
624 this->last_user_action
= widget
;
628 case WID_RAT_BUILD_SIGNALS
: {
629 this->last_user_action
= widget
;
630 bool started
= HandlePlacePushButton (this, WID_RAT_BUILD_SIGNALS
, ANIMCURSOR_BUILDSIGNALS
, POINTER_TILE
);
631 if (started
&& _settings_client
.gui
.enable_signal_gui
!= _ctrl_pressed
) {
632 ShowSignalBuilder(this);
637 case WID_RAT_BUILD_BRIDGE
:
638 HandlePlacePushButton (this, WID_RAT_BUILD_BRIDGE
, SPR_CURSOR_BRIDGE
, POINTER_TILE
);
639 this->last_user_action
= widget
;
642 case WID_RAT_BUILD_TUNNEL
:
643 HandlePlacePushButton (this, WID_RAT_BUILD_TUNNEL
, GetRailTypeInfo(_cur_railtype
)->cursor
.tunnel
, POINTER_AREA
);
644 this->last_user_action
= widget
;
648 BuildRailClick_Remove(this);
651 case WID_RAT_CONVERT_RAIL
:
652 HandlePlacePushButton (this, WID_RAT_CONVERT_RAIL
, GetRailTypeInfo(_cur_railtype
)->cursor
.convert
, POINTER_TILE
);
653 this->last_user_action
= widget
;
656 default: NOT_REACHED();
658 this->UpdateRemoveWidgetStatus(widget
);
659 if (_ctrl_pressed
) RailToolbar_CtrlChanged(this);
662 bool OnHotkey (int hotkey
) OVERRIDE
664 MarkTileDirtyByTile(TileVirtXY(_thd
.pos
.x
, _thd
.pos
.y
)); // redraw tile selection
665 return Window::OnHotkey(hotkey
);
668 virtual void OnPlaceObject(Point pt
, TileIndex tile
)
670 switch (this->last_user_action
) {
671 case WID_RAT_BUILD_NS
:
672 case WID_RAT_BUILD_X
:
673 case WID_RAT_BUILD_EW
:
674 case WID_RAT_BUILD_Y
:
675 case WID_RAT_AUTORAIL
:
676 VpStartPlaceSizing(tile
, VPM_RAILDIRS
, DRAG_PLACE_RAIL
);
679 case WID_RAT_DEMOLISH
:
680 VpStartPlaceSizing(tile
, VPM_X_AND_Y_ROTATED
, DRAG_DEMOLISH_AREA
);
683 case WID_RAT_BUILD_DEPOT
:
684 DoCommandP(tile
, _cur_railtype
, _build_depot_direction
, CMD_BUILD_TRAIN_DEPOT
);
687 case WID_RAT_BUILD_WAYPOINT
:
688 PlaceRail_Waypoint(tile
);
691 case WID_RAT_BUILD_STATION
:
692 PlaceRail_Station(tile
);
695 case WID_RAT_BUILD_SIGNALS
:
696 VpStartPlaceSizing (tile
, VPM_RAILDIRS
, DRAG_BUILD_SIGNALS
);
699 case WID_RAT_BUILD_BRIDGE
:
700 if (IsBridgeHeadTile(tile
)) {
701 TileIndex other_tile
= GetOtherBridgeEnd (tile
);
702 HandleBuildRailBridge (other_tile
, tile
);
704 VpStartPlaceSizing (tile
, VPM_X_OR_Y
, DRAG_BUILD_BRIDGE
);
708 case WID_RAT_BUILD_TUNNEL
:
709 DoCommandP(tile
, _cur_railtype
| (TRANSPORT_RAIL
<< 8), 0, CMD_BUILD_TUNNEL
);
712 case WID_RAT_CONVERT_RAIL
:
713 VpStartPlaceSizing(tile
, VPM_X_AND_Y_ROTATED
, DRAG_CONVERT_RAIL
);
716 default: NOT_REACHED();
720 bool OnPlaceDrag (int userdata
, Point pt
) OVERRIDE
722 /* no dragging if you have pressed the convert button */
723 return (FindWindowById (WC_BUILD_SIGNAL
, 0) == NULL
)
724 || !_convert_signal_button
725 || !this->IsWidgetLowered (WID_RAT_BUILD_SIGNALS
);
728 void OnPlaceMouseUp (int userdata
, TileIndex start_tile
, TileIndex end_tile
) OVERRIDE
731 default: NOT_REACHED();
732 case DRAG_BUILD_BRIDGE
:
733 HandleBuildRailBridge (start_tile
, end_tile
);
736 case DRAG_PLACE_RAIL
:
737 HandleAutodirPlacement (start_tile
, end_tile
);
740 case DRAG_BUILD_SIGNALS
:
741 HandleAutoSignalPlacement (start_tile
, end_tile
);
744 case DRAG_DEMOLISH_AREA
:
745 HandleDemolishMouseUp (start_tile
, end_tile
);
748 case DRAG_CONVERT_RAIL
:
749 DoCommandP (end_tile
, start_tile
, _cur_railtype
| (_ctrl_pressed
? 0x10 : 0), CMD_CONVERT_RAIL
);
753 if (_remove_button_clicked
) {
754 DoCommandP (end_tile
, start_tile
, _ctrl_pressed
? 0 : 1, CMD_REMOVE_FROM_RAIL_STATION
);
756 HandleStationPlacement (start_tile
, end_tile
);
760 case DRAG_BUILD_WAYPOINT_X
:
761 case DRAG_BUILD_WAYPOINT_Y
: {
762 TileArea
ta (start_tile
, end_tile
);
763 uint32 p1
= _cur_railtype
| (userdata
== DRAG_BUILD_WAYPOINT_X
? AXIS_X
: AXIS_Y
) << 4 | ta
.w
<< 8 | ta
.h
<< 16 | _ctrl_pressed
<< 24;
764 uint32 p2
= STAT_CLASS_WAYP
| _cur_waypoint_type
<< 8 | INVALID_STATION
<< 16;
766 Command
cmdcont (ta
.tile
, p1
, p2
, CMD_BUILD_RAIL_WAYPOINT
);
767 ShowSelectWaypointIfNeeded (&cmdcont
, ta
);
771 case DRAG_REMOVE_WAYPOINT
:
772 DoCommandP (end_tile
, start_tile
, _ctrl_pressed
? 0 : 1, CMD_REMOVE_FROM_RAIL_WAYPOINT
);
777 virtual void OnPlaceObjectAbort()
779 this->RaiseButtons();
780 this->DisableWidget(WID_RAT_REMOVE
);
781 this->SetWidgetDirty(WID_RAT_REMOVE
);
783 DeleteWindowById(WC_BUILD_SIGNAL
, TRANSPORT_RAIL
);
784 DeleteWindowById(WC_BUILD_STATION
, TRANSPORT_RAIL
);
785 DeleteWindowById(WC_BUILD_DEPOT
, TRANSPORT_RAIL
);
786 DeleteWindowById(WC_BUILD_WAYPOINT
, TRANSPORT_RAIL
);
787 DeleteWindowById(WC_SELECT_STATION
, 0);
788 DeleteWindowByClass(WC_BUILD_BRIDGE
);
791 void OnPlacePresize (TileIndex
*tile
, TileIndex
*tile2
) OVERRIDE
793 DoCommand (*tile
, _cur_railtype
| (TRANSPORT_RAIL
<< 8), 0, DC_AUTO
, CMD_BUILD_TUNNEL
);
794 if (_build_tunnel_endtile
!= 0) *tile2
= _build_tunnel_endtile
;
797 bool OnCTRLStateChange (void) OVERRIDE
799 /* do not toggle Remove button by Ctrl when placing station */
800 return !this->IsWidgetLowered (WID_RAT_BUILD_STATION
)
801 && !this->IsWidgetLowered (WID_RAT_BUILD_WAYPOINT
)
802 && RailToolbar_CtrlChanged (this);
805 static HotkeyList hotkeys
;
809 * Handler for global hotkeys of the BuildRailToolbarWindow.
810 * @param hotkey Hotkey
811 * @return Whether the hotkey was handled.
813 static bool RailToolbarGlobalHotkeys (int hotkey
)
815 if (_game_mode
!= GM_NORMAL
|| !CanBuildVehicleInfrastructure(VEH_TRAIN
)) return false;
816 extern RailType _last_built_railtype
;
817 Window
*w
= ShowBuildRailToolbar(_last_built_railtype
);
818 return (w
!= NULL
) && w
->OnHotkey (hotkey
);
821 static const Hotkey railtoolbar_hotkeys
[] = {
822 Hotkey ("build_ns", WID_RAT_BUILD_NS
, '1'),
823 Hotkey ("build_x", WID_RAT_BUILD_X
, '2'),
824 Hotkey ("build_ew", WID_RAT_BUILD_EW
, '3'),
825 Hotkey ("build_y", WID_RAT_BUILD_Y
, '4'),
826 Hotkey ("autorail", WID_RAT_AUTORAIL
, '5', 'A' | WKC_GLOBAL_HOTKEY
),
827 Hotkey ("demolish", WID_RAT_DEMOLISH
, '6'),
828 Hotkey ("depot", WID_RAT_BUILD_DEPOT
, '7'),
829 Hotkey ("waypoint", WID_RAT_BUILD_WAYPOINT
, '8'),
830 Hotkey ("station", WID_RAT_BUILD_STATION
, '9'),
831 Hotkey ("signal", WID_RAT_BUILD_SIGNALS
, 'S'),
832 Hotkey ("bridge", WID_RAT_BUILD_BRIDGE
, 'B'),
833 Hotkey ("tunnel", WID_RAT_BUILD_TUNNEL
, 'T'),
834 Hotkey ("remove", WID_RAT_REMOVE
, 'R'),
835 Hotkey ("convert", WID_RAT_CONVERT_RAIL
, 'C'),
837 HotkeyList
BuildRailToolbarWindow::hotkeys("railtoolbar", railtoolbar_hotkeys
, RailToolbarGlobalHotkeys
);
839 static const NWidgetPart _nested_build_rail_widgets
[] = {
840 NWidget(NWID_HORIZONTAL
),
841 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
842 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
, WID_RAT_CAPTION
), SetDataTip(STR_WHITE_STRING
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
843 NWidget(WWT_STICKYBOX
, COLOUR_DARK_GREEN
),
845 NWidget(NWID_HORIZONTAL
),
846 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_BUILD_NS
),
847 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_RAIL_NS
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_TRACK
),
848 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_BUILD_X
),
849 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_RAIL_NE
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_TRACK
),
850 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_BUILD_EW
),
851 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_RAIL_EW
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_TRACK
),
852 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_BUILD_Y
),
853 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_RAIL_NW
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_TRACK
),
854 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_AUTORAIL
),
855 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_AUTORAIL
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_AUTORAIL
),
857 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
), SetMinimalSize(4, 22), SetDataTip(0x0, STR_NULL
), EndContainer(),
859 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_DEMOLISH
),
860 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DYNAMITE
, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC
),
861 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_BUILD_DEPOT
),
862 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DEPOT_RAIL
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_TRAIN_DEPOT_FOR_BUILDING
),
863 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_BUILD_WAYPOINT
),
864 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_WAYPOINT
, STR_RAIL_TOOLBAR_TOOLTIP_CONVERT_RAIL_TO_WAYPOINT
),
865 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_BUILD_STATION
),
866 SetFill(0, 1), SetMinimalSize(42, 22), SetDataTip(SPR_IMG_RAIL_STATION
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_STATION
),
867 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_BUILD_SIGNALS
),
868 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_RAIL_SIGNALS
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_SIGNALS
),
869 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_BUILD_BRIDGE
),
870 SetFill(0, 1), SetMinimalSize(42, 22), SetDataTip(SPR_IMG_BRIDGE
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_BRIDGE
),
871 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_BUILD_TUNNEL
),
872 SetFill(0, 1), SetMinimalSize(20, 22), SetDataTip(SPR_IMG_TUNNEL_RAIL
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_TUNNEL
),
873 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_REMOVE
),
874 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_REMOVE
, STR_RAIL_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR
),
875 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_CONVERT_RAIL
),
876 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_CONVERT_RAIL
, STR_RAIL_TOOLBAR_TOOLTIP_CONVERT_RAIL
),
880 static WindowDesc::Prefs
_build_rail_prefs ("toolbar_rail");
882 static const WindowDesc
_build_rail_desc(
883 WDP_ALIGN_TOOLBAR
, 0, 0,
884 WC_BUILD_TOOLBAR
, WC_NONE
,
886 _nested_build_rail_widgets
, lengthof(_nested_build_rail_widgets
),
887 &_build_rail_prefs
, &BuildRailToolbarWindow::hotkeys
892 * Open the build rail toolbar window for a specific rail type.
894 * If the terraform toolbar is linked to the toolbar, that window is also opened.
896 * @param railtype Rail type to open the window for
897 * @return newly opened rail toolbar, or NULL if the toolbar could not be opened.
899 Window
*ShowBuildRailToolbar(RailType railtype
)
901 if (!Company::IsValidID(_local_company
)) return NULL
;
902 if (!ValParamRailtype(railtype
)) return NULL
;
904 DeleteWindowByClass(WC_BUILD_TOOLBAR
);
905 _cur_railtype
= railtype
;
906 _remove_button_clicked
= false;
907 return new BuildRailToolbarWindow(&_build_rail_desc
, railtype
);
910 /* TODO: For custom stations, respect their allowed platforms/lengths bitmasks!
913 static void HandleStationPlacement(TileIndex start
, TileIndex end
)
915 TileArea
ta(start
, end
);
916 uint numtracks
= ta
.w
;
917 uint platlength
= ta
.h
;
919 if (_railstation
.orientation
== AXIS_X
) Swap(numtracks
, platlength
);
921 uint32 p1
= _cur_railtype
| _railstation
.orientation
<< 4 | numtracks
<< 8 | platlength
<< 16 | _ctrl_pressed
<< 24;
922 uint32 p2
= _railstation
.station_class
| _railstation
.station_type
<< 8 | INVALID_STATION
<< 16;
924 Command
cmdcont (ta
.tile
, p1
, p2
, CMD_BUILD_RAIL_STATION
);
925 ShowSelectStationIfNeeded (&cmdcont
, ta
);
928 /** Check the selected number of tracks when turning drag&drop off. */
929 static void CheckPlatformWidth (const StationSpec
*statspec
)
931 byte disallowed
= statspec
->disallowed_platforms
;
932 if (HasBit(disallowed
, _settings_client
.gui
.station_numtracks
- 1)) {
933 /* The previously selected number of tracks is invalid. */
934 for (uint i
= 0; i
< 7; i
++) {
935 if (!HasBit(disallowed
, i
)) {
936 _settings_client
.gui
.station_numtracks
= i
+ 1;
943 /** Check the selected platform length when turning drag&drop off. */
944 static void CheckPlatformLength (const StationSpec
*statspec
)
946 byte disallowed
= statspec
->disallowed_lengths
;
947 if (HasBit(disallowed
, _settings_client
.gui
.station_platlength
- 1)) {
948 /* The previously selected number of platforms is invalid. */
949 for (uint i
= 0; i
< 7; i
++) {
950 if (!HasBit(disallowed
, i
)) {
951 _settings_client
.gui
.station_platlength
= i
+ 1;
958 /** Draw a station preview in a widget. */
959 static void DrawStationPreview (BlitArea
*dpi
, const Rect
&r
,
960 StationClassID cls
, uint type
, uint image
, bool check_avail
)
962 /* Set up a clipping area for the station preview. */
964 if (InitBlitArea (dpi
, &tmp_dpi
, r
.left
, r
.top
, r
.right
- r
.left
+ 1, r
.bottom
- r
.top
+ 1)) {
965 int x
= ScaleGUITrad(31) + 1;
966 int y
= r
.bottom
- r
.top
- ScaleGUITrad(31);
967 if (!DrawStationTile (&tmp_dpi
, x
, y
, _cur_railtype
, (Axis
)(image
% 2), cls
, type
)) {
968 RailStationPickerDrawSprite (&tmp_dpi
, x
, y
, cls
== STAT_CLASS_WAYP
, _cur_railtype
, image
);
972 /* Check station availability callback */
973 if (check_avail
&& !IsStationAvailable (StationClass::Get(cls
)->GetSpec(type
))) {
974 GfxFillRect (dpi
, r
.left
+ 1, r
.top
+ 1, r
.right
- 1, r
.bottom
- 1, PC_BLACK
, FILLRECT_CHECKER
);
978 struct BuildRailStationWindow
: public PickerWindowBase
{
980 uint line_height
; ///< Height of a single line in the newstation selection matrix (#WID_BRAS_NEWST_LIST widget).
981 uint coverage_height
; ///< Height of the coverage texts.
982 Scrollbar
*vscroll
; ///< Vertical scrollbar of the new station list.
983 Scrollbar
*vscroll2
; ///< Vertical scrollbar of the matrix with new stations.
986 * Verify whether the currently selected station size is allowed after selecting a new station class/type.
987 * If not, change the station size variables ( _settings_client.gui.station_numtracks and _settings_client.gui.station_platlength ).
988 * @param statspec Specification of the new station class/type
990 void CheckSelectedSize(const StationSpec
*statspec
)
992 if (statspec
== NULL
|| _settings_client
.gui
.station_dragdrop
) return;
994 /* If current number of tracks is not allowed, make it as big as possible */
995 if (HasBit(statspec
->disallowed_platforms
, _settings_client
.gui
.station_numtracks
- 1)) {
996 this->RaiseWidget(_settings_client
.gui
.station_numtracks
+ WID_BRAS_PLATFORM_NUM_BEGIN
);
997 _settings_client
.gui
.station_numtracks
= 1;
998 if (statspec
->disallowed_platforms
!= UINT8_MAX
) {
999 while (HasBit(statspec
->disallowed_platforms
, _settings_client
.gui
.station_numtracks
- 1)) {
1000 _settings_client
.gui
.station_numtracks
++;
1002 this->LowerWidget(_settings_client
.gui
.station_numtracks
+ WID_BRAS_PLATFORM_NUM_BEGIN
);
1006 if (HasBit(statspec
->disallowed_lengths
, _settings_client
.gui
.station_platlength
- 1)) {
1007 this->RaiseWidget(_settings_client
.gui
.station_platlength
+ WID_BRAS_PLATFORM_LEN_BEGIN
);
1008 _settings_client
.gui
.station_platlength
= 1;
1009 if (statspec
->disallowed_lengths
!= UINT8_MAX
) {
1010 while (HasBit(statspec
->disallowed_lengths
, _settings_client
.gui
.station_platlength
- 1)) {
1011 _settings_client
.gui
.station_platlength
++;
1013 this->LowerWidget(_settings_client
.gui
.station_platlength
+ WID_BRAS_PLATFORM_LEN_BEGIN
);
1019 BuildRailStationWindow (const WindowDesc
*desc
, Window
*parent
, bool newstation
) :
1020 PickerWindowBase (desc
, parent
), line_height (0),
1021 coverage_height (2 * FONT_HEIGHT_NORMAL
+ 3 * WD_PAR_VSEP_NORMAL
),
1022 vscroll (NULL
), vscroll2 (NULL
)
1024 _railstation
.newstations
= newstation
;
1026 this->CreateNestedTree();
1027 NWidgetStacked
*newst_additions
= this->GetWidget
<NWidgetStacked
>(WID_BRAS_SHOW_NEWST_ADDITIONS
);
1028 newst_additions
->SetDisplayedPlane(newstation
? 0 : SZSP_NONE
);
1029 newst_additions
= this->GetWidget
<NWidgetStacked
>(WID_BRAS_SHOW_NEWST_MATRIX
);
1030 newst_additions
->SetDisplayedPlane(newstation
? 0 : SZSP_NONE
);
1031 newst_additions
= this->GetWidget
<NWidgetStacked
>(WID_BRAS_SHOW_NEWST_DEFSIZE
);
1032 newst_additions
->SetDisplayedPlane(newstation
? 0 : SZSP_NONE
);
1033 newst_additions
= this->GetWidget
<NWidgetStacked
>(WID_BRAS_SHOW_NEWST_RESIZE
);
1034 newst_additions
->SetDisplayedPlane(newstation
? 0 : SZSP_NONE
);
1036 this->vscroll
= this->GetScrollbar(WID_BRAS_NEWST_SCROLL
);
1037 this->vscroll2
= this->GetScrollbar(WID_BRAS_MATRIX_SCROLL
);
1039 this->InitNested(TRANSPORT_RAIL
);
1041 this->LowerWidget(_railstation
.orientation
+ WID_BRAS_PLATFORM_DIR_X
);
1042 if (_settings_client
.gui
.station_dragdrop
) {
1043 this->LowerWidget(WID_BRAS_PLATFORM_DRAG_N_DROP
);
1045 this->LowerWidget(_settings_client
.gui
.station_numtracks
+ WID_BRAS_PLATFORM_NUM_BEGIN
);
1046 this->LowerWidget(_settings_client
.gui
.station_platlength
+ WID_BRAS_PLATFORM_LEN_BEGIN
);
1048 this->SetWidgetLoweredState(WID_BRAS_HIGHLIGHT_OFF
, !_settings_client
.gui
.station_show_coverage
);
1049 this->SetWidgetLoweredState(WID_BRAS_HIGHLIGHT_ON
, _settings_client
.gui
.station_show_coverage
);
1051 if (!newstation
|| _railstation
.station_class
>= (int)StationClass::GetClassCount()) {
1052 /* New stations are not available or changed, so ensure the default station
1053 * type is 'selected'. */
1054 _railstation
.station_class
= STAT_CLASS_DFLT
;
1055 _railstation
.station_type
= 0;
1056 this->vscroll2
= NULL
;
1059 _railstation
.station_count
= StationClass::Get(_railstation
.station_class
)->GetSpecCount();
1060 _railstation
.station_type
= min(_railstation
.station_type
, _railstation
.station_count
- 1);
1063 for (uint i
= 0; i
< StationClass::GetClassCount(); i
++) {
1064 if (i
== STAT_CLASS_WAYP
) continue;
1067 this->vscroll
->SetCount(count
);
1068 this->vscroll
->SetPosition(Clamp(_railstation
.station_class
- 2, 0, max(this->vscroll
->GetCount() - this->vscroll
->GetCapacity(), 0)));
1070 NWidgetMatrix
*matrix
= this->GetWidget
<NWidgetMatrix
>(WID_BRAS_MATRIX
);
1071 matrix
->SetScrollbar(this->vscroll2
);
1072 matrix
->SetCount(_railstation
.station_count
);
1073 matrix
->SetClicked(_railstation
.station_type
);
1077 void OnDelete (void) FINAL_OVERRIDE
1079 DeleteWindowById(WC_SELECT_STATION
, 0);
1080 this->PickerWindowBase::OnDelete();
1083 void OnPaint (BlitArea
*dpi
) OVERRIDE
1085 bool newstations
= _railstation
.newstations
;
1086 const StationSpec
*statspec
= newstations
? StationClass::Get(_railstation
.station_class
)->GetSpec(_railstation
.station_type
) : NULL
;
1088 int rad
= (_settings_game
.station
.modified_catchment
) ? CA_TRAIN
: CA_UNMODIFIED
;
1090 if (_settings_client
.gui
.station_show_coverage
) SetTileSelectBigSize(-rad
, -rad
, 2 * rad
, 2 * rad
);
1092 for (uint bits
= 0; bits
< 7; bits
++) {
1093 bool disable
= bits
>= _settings_game
.station
.station_spread
;
1094 if (statspec
== NULL
) {
1095 this->SetWidgetDisabledState(bits
+ WID_BRAS_PLATFORM_NUM_1
, disable
);
1096 this->SetWidgetDisabledState(bits
+ WID_BRAS_PLATFORM_LEN_1
, disable
);
1098 this->SetWidgetDisabledState(bits
+ WID_BRAS_PLATFORM_NUM_1
, HasBit(statspec
->disallowed_platforms
, bits
) || disable
);
1099 this->SetWidgetDisabledState(bits
+ WID_BRAS_PLATFORM_LEN_1
, HasBit(statspec
->disallowed_lengths
, bits
) || disable
);
1103 this->DrawWidgets (dpi
);
1105 /* 'Accepts' and 'Supplies' texts. */
1106 NWidgetBase
*cov
= this->GetWidget
<NWidgetBase
>(WID_BRAS_COVERAGE_TEXTS
);
1107 int top
= cov
->pos_y
+ WD_PAR_VSEP_NORMAL
;
1108 int left
= cov
->pos_x
+ WD_FRAMERECT_LEFT
;
1109 int right
= cov
->pos_x
+ cov
->current_x
- WD_FRAMERECT_RIGHT
;
1110 int bottom
= cov
->pos_y
+ cov
->current_y
;
1111 top
= DrawStationCoverageAreaText (dpi
, left
, right
, top
, rad
);
1112 /* Resize background if the window is too small.
1113 * Never make the window smaller to avoid oscillating if the size change affects the acceptance.
1114 * (This is the case, if making the window bigger moves the mouse into the window.) */
1116 this->coverage_height
+= top
- bottom
;
1121 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
1124 case WID_BRAS_NEWST_LIST
: {
1125 Dimension d
= {0, 0};
1126 for (uint i
= 0; i
< StationClass::GetClassCount(); i
++) {
1127 if (i
== STAT_CLASS_WAYP
) continue;
1128 d
= maxdim(d
, GetStringBoundingBox(StationClass::Get((StationClassID
)i
)->name
));
1130 size
->width
= max(size
->width
, d
.width
+ padding
.width
);
1131 this->line_height
= FONT_HEIGHT_NORMAL
+ WD_MATRIX_TOP
+ WD_MATRIX_BOTTOM
;
1132 size
->height
= 5 * this->line_height
;
1133 resize
->height
= this->line_height
;
1137 case WID_BRAS_SHOW_NEWST_TYPE
: {
1138 if (!_railstation
.newstations
) {
1144 /* If newstations exist, compute the non-zero minimal size. */
1145 Dimension d
= {0, 0};
1146 StringID str
= this->GetWidget
<NWidgetCore
>(widget
)->widget_data
;
1147 for (StationClassID statclass
= STAT_CLASS_BEGIN
; statclass
< (StationClassID
)StationClass::GetClassCount(); statclass
++) {
1148 if (statclass
== STAT_CLASS_WAYP
) continue;
1149 StationClass
*stclass
= StationClass::Get(statclass
);
1150 for (uint16 j
= 0; j
< stclass
->GetSpecCount(); j
++) {
1151 const StationSpec
*statspec
= stclass
->GetSpec(j
);
1152 SetDParam(0, (statspec
!= NULL
&& statspec
->name
!= 0) ? statspec
->name
: STR_STATION_CLASS_DFLT
);
1153 d
= maxdim(d
, GetStringBoundingBox(str
));
1156 size
->width
= max(size
->width
, d
.width
+ padding
.width
);
1160 case WID_BRAS_PLATFORM_DIR_X
:
1161 case WID_BRAS_PLATFORM_DIR_Y
:
1162 case WID_BRAS_IMAGE
:
1163 size
->width
= ScaleGUITrad(64) + 2;
1164 size
->height
= ScaleGUITrad(58) + 2;
1167 case WID_BRAS_COVERAGE_TEXTS
:
1168 size
->height
= this->coverage_height
;
1171 case WID_BRAS_MATRIX
:
1178 void DrawWidget (BlitArea
*dpi
, const Rect
&r
, int widget
) const OVERRIDE
1180 int widn
= GB(widget
, 0, 16);
1182 case WID_BRAS_PLATFORM_DIR_X
:
1183 case WID_BRAS_PLATFORM_DIR_Y
:
1184 assert_compile (WID_BRAS_PLATFORM_DIR_X
== 0);
1185 assert_compile (WID_BRAS_PLATFORM_DIR_Y
== 1);
1186 DrawStationPreview (dpi
, r
, _railstation
.station_class
, _railstation
.station_type
, 2 + widn
, false);
1189 case WID_BRAS_NEWST_LIST
: {
1192 for (uint i
= 0; i
< StationClass::GetClassCount(); i
++) {
1193 if (i
== STAT_CLASS_WAYP
) continue;
1194 if (this->vscroll
->IsVisible(statclass
)) {
1195 DrawString (dpi
, r
.left
+ WD_MATRIX_LEFT
, r
.right
- WD_MATRIX_RIGHT
, row
* this->line_height
+ r
.top
+ WD_MATRIX_TOP
,
1196 StationClass::Get((StationClassID
)i
)->name
,
1197 (StationClassID
)i
== _railstation
.station_class
? TC_WHITE
: TC_BLACK
);
1205 case WID_BRAS_IMAGE
: {
1206 byte type
= GB(widget
, 16, 16);
1207 assert(type
< _railstation
.station_count
);
1208 DrawStationPreview (dpi
, r
, _railstation
.station_class
, type
, 2 + _railstation
.orientation
, true);
1214 virtual void OnResize()
1216 if (this->vscroll
!= NULL
) { // New stations available.
1217 this->vscroll
->SetCapacityFromWidget(this, WID_BRAS_NEWST_LIST
);
1221 virtual void SetStringParameters(int widget
) const
1223 if (widget
== WID_BRAS_SHOW_NEWST_TYPE
) {
1224 const StationSpec
*statspec
= StationClass::Get(_railstation
.station_class
)->GetSpec(_railstation
.station_type
);
1225 SetDParam(0, (statspec
!= NULL
&& statspec
->name
!= 0) ? statspec
->name
: STR_STATION_CLASS_DFLT
);
1229 virtual void OnClick(Point pt
, int widget
, int click_count
)
1232 CHANGED_NONE
, ///< Nothing changed.
1233 CHANGED_DIRTY
, ///< Play a sound and mark window dirty.
1234 CHANGED_RESET
, ///< The same, plus reset construction.
1235 } changed
= CHANGED_NONE
;
1237 switch (GB(widget
, 0, 16)) {
1238 case WID_BRAS_PLATFORM_DIR_X
:
1239 case WID_BRAS_PLATFORM_DIR_Y
:
1240 this->RaiseWidget(_railstation
.orientation
+ WID_BRAS_PLATFORM_DIR_X
);
1241 _railstation
.orientation
= (Axis
)(widget
- WID_BRAS_PLATFORM_DIR_X
);
1242 this->LowerWidget(_railstation
.orientation
+ WID_BRAS_PLATFORM_DIR_X
);
1243 changed
= CHANGED_RESET
;
1246 case WID_BRAS_PLATFORM_NUM_1
:
1247 case WID_BRAS_PLATFORM_NUM_2
:
1248 case WID_BRAS_PLATFORM_NUM_3
:
1249 case WID_BRAS_PLATFORM_NUM_4
:
1250 case WID_BRAS_PLATFORM_NUM_5
:
1251 case WID_BRAS_PLATFORM_NUM_6
:
1252 case WID_BRAS_PLATFORM_NUM_7
: {
1253 this->RaiseWidget(_settings_client
.gui
.station_numtracks
+ WID_BRAS_PLATFORM_NUM_BEGIN
);
1254 this->RaiseWidget(WID_BRAS_PLATFORM_DRAG_N_DROP
);
1256 _settings_client
.gui
.station_numtracks
= widget
- WID_BRAS_PLATFORM_NUM_BEGIN
;
1257 _settings_client
.gui
.station_dragdrop
= false;
1259 _settings_client
.gui
.station_dragdrop
= false;
1261 const StationSpec
*statspec
= _railstation
.newstations
? StationClass::Get(_railstation
.station_class
)->GetSpec(_railstation
.station_type
) : NULL
;
1262 if (statspec
!= NULL
) CheckPlatformLength (statspec
);
1264 this->LowerWidget(_settings_client
.gui
.station_numtracks
+ WID_BRAS_PLATFORM_NUM_BEGIN
);
1265 this->LowerWidget(_settings_client
.gui
.station_platlength
+ WID_BRAS_PLATFORM_LEN_BEGIN
);
1266 changed
= CHANGED_RESET
;
1270 case WID_BRAS_PLATFORM_LEN_1
:
1271 case WID_BRAS_PLATFORM_LEN_2
:
1272 case WID_BRAS_PLATFORM_LEN_3
:
1273 case WID_BRAS_PLATFORM_LEN_4
:
1274 case WID_BRAS_PLATFORM_LEN_5
:
1275 case WID_BRAS_PLATFORM_LEN_6
:
1276 case WID_BRAS_PLATFORM_LEN_7
: {
1277 this->RaiseWidget(_settings_client
.gui
.station_platlength
+ WID_BRAS_PLATFORM_LEN_BEGIN
);
1278 this->RaiseWidget(WID_BRAS_PLATFORM_DRAG_N_DROP
);
1280 _settings_client
.gui
.station_platlength
= widget
- WID_BRAS_PLATFORM_LEN_BEGIN
;
1281 _settings_client
.gui
.station_dragdrop
= false;
1283 _settings_client
.gui
.station_dragdrop
= false;
1285 const StationSpec
*statspec
= _railstation
.newstations
? StationClass::Get(_railstation
.station_class
)->GetSpec(_railstation
.station_type
) : NULL
;
1286 if (statspec
!= NULL
) CheckPlatformWidth (statspec
);
1288 this->LowerWidget(_settings_client
.gui
.station_numtracks
+ WID_BRAS_PLATFORM_NUM_BEGIN
);
1289 this->LowerWidget(_settings_client
.gui
.station_platlength
+ WID_BRAS_PLATFORM_LEN_BEGIN
);
1290 changed
= CHANGED_RESET
;
1294 case WID_BRAS_PLATFORM_DRAG_N_DROP
: {
1295 _settings_client
.gui
.station_dragdrop
^= true;
1297 this->ToggleWidgetLoweredState(WID_BRAS_PLATFORM_DRAG_N_DROP
);
1299 /* get the first allowed length/number of platforms */
1300 const StationSpec
*statspec
= _railstation
.newstations
? StationClass::Get(_railstation
.station_class
)->GetSpec(_railstation
.station_type
) : NULL
;
1301 if (statspec
!= NULL
) {
1302 CheckPlatformLength (statspec
);
1303 CheckPlatformWidth (statspec
);
1306 this->SetWidgetLoweredState(_settings_client
.gui
.station_numtracks
+ WID_BRAS_PLATFORM_NUM_BEGIN
, !_settings_client
.gui
.station_dragdrop
);
1307 this->SetWidgetLoweredState(_settings_client
.gui
.station_platlength
+ WID_BRAS_PLATFORM_LEN_BEGIN
, !_settings_client
.gui
.station_dragdrop
);
1308 changed
= CHANGED_RESET
;
1312 case WID_BRAS_HIGHLIGHT_OFF
:
1313 case WID_BRAS_HIGHLIGHT_ON
:
1314 _settings_client
.gui
.station_show_coverage
= (widget
!= WID_BRAS_HIGHLIGHT_OFF
);
1316 this->SetWidgetLoweredState(WID_BRAS_HIGHLIGHT_OFF
, !_settings_client
.gui
.station_show_coverage
);
1317 this->SetWidgetLoweredState(WID_BRAS_HIGHLIGHT_ON
, _settings_client
.gui
.station_show_coverage
);
1318 changed
= CHANGED_DIRTY
;
1321 case WID_BRAS_NEWST_LIST
: {
1322 int y
= this->vscroll
->GetScrolledRowFromWidget(pt
.y
, this, WID_BRAS_NEWST_LIST
, 0, this->line_height
);
1323 if (y
>= (int)StationClass::GetClassCount()) return;
1324 for (uint i
= 0; i
< StationClass::GetClassCount(); i
++) {
1325 if (i
== STAT_CLASS_WAYP
) continue;
1327 if (_railstation
.station_class
!= (StationClassID
)i
) {
1328 _railstation
.station_class
= (StationClassID
)i
;
1329 StationClass
*stclass
= StationClass::Get(_railstation
.station_class
);
1330 _railstation
.station_count
= stclass
->GetSpecCount();
1331 _railstation
.station_type
= min((int)_railstation
.station_type
, max(0, (int)_railstation
.station_count
- 1));
1333 this->CheckSelectedSize(stclass
->GetSpec(_railstation
.station_type
));
1335 NWidgetMatrix
*matrix
= this->GetWidget
<NWidgetMatrix
>(WID_BRAS_MATRIX
);
1336 matrix
->SetCount(_railstation
.station_count
);
1337 matrix
->SetClicked(_railstation
.station_type
);
1339 changed
= CHANGED_RESET
;
1347 case WID_BRAS_IMAGE
: {
1348 int y
= GB(widget
, 16, 16);
1349 if (y
>= _railstation
.station_count
) return;
1351 /* Check station availability callback */
1352 const StationSpec
*statspec
= StationClass::Get(_railstation
.station_class
)->GetSpec(y
);
1353 if (!IsStationAvailable(statspec
)) return;
1355 _railstation
.station_type
= y
;
1357 this->CheckSelectedSize(statspec
);
1358 this->GetWidget
<NWidgetMatrix
>(WID_BRAS_MATRIX
)->SetClicked(_railstation
.station_type
);
1360 changed
= CHANGED_RESET
;
1367 DeleteWindowById (WC_SELECT_STATION
, 0);
1368 SetStationTileSelectSize();
1371 if (_settings_client
.sound
.click_beep
) SndPlayFx(SND_15_BEEP
);
1378 virtual void OnTick()
1380 CheckRedrawStationCoverage(this);
1384 static const NWidgetPart _nested_station_builder_widgets
[] = {
1385 NWidget(NWID_HORIZONTAL
),
1386 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
1387 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
), SetDataTip(STR_STATION_BUILD_RAIL_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
1388 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_BRAS_SHOW_NEWST_DEFSIZE
),
1389 NWidget(WWT_DEFSIZEBOX
, COLOUR_DARK_GREEN
),
1392 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
),
1393 NWidget(NWID_HORIZONTAL
),
1394 NWidget(NWID_VERTICAL
),
1395 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_BRAS_SHOW_NEWST_ADDITIONS
),
1396 NWidget(NWID_HORIZONTAL
), SetPIP(7, 0, 7), SetPadding(2, 0, 1, 0),
1397 NWidget(WWT_MATRIX
, COLOUR_GREY
, WID_BRAS_NEWST_LIST
), SetMinimalSize(122, 71), SetFill(1, 0),
1398 SetMatrixDataTip(1, 0, STR_STATION_BUILD_STATION_CLASS_TOOLTIP
), SetScrollbar(WID_BRAS_NEWST_SCROLL
),
1399 NWidget(NWID_VSCROLLBAR
, COLOUR_GREY
, WID_BRAS_NEWST_SCROLL
),
1402 NWidget(WWT_LABEL
, COLOUR_DARK_GREEN
), SetMinimalSize(144, 11), SetDataTip(STR_STATION_BUILD_ORIENTATION
, STR_NULL
), SetPadding(1, 2, 0, 2),
1403 NWidget(NWID_HORIZONTAL
),
1404 NWidget(NWID_SPACER
), SetMinimalSize(7, 0), SetFill(1, 0),
1405 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(),
1406 NWidget(NWID_SPACER
), SetMinimalSize(2, 0), SetFill(1, 0),
1407 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(),
1408 NWidget(NWID_SPACER
), SetMinimalSize(7, 0), SetFill(1, 0),
1410 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),
1411 NWidget(WWT_LABEL
, COLOUR_DARK_GREEN
), SetMinimalSize(144, 11), SetDataTip(STR_STATION_BUILD_NUMBER_OF_TRACKS
, STR_NULL
), SetPadding(0, 2, 0, 2),
1412 NWidget(NWID_HORIZONTAL
),
1413 NWidget(NWID_SPACER
), SetFill(1, 0),
1414 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_NUM_1
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_1
, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP
),
1415 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_NUM_2
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_2
, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP
),
1416 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_NUM_3
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_3
, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP
),
1417 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_NUM_4
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_4
, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP
),
1418 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_NUM_5
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_5
, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP
),
1419 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_NUM_6
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_6
, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP
),
1420 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_NUM_7
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_7
, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP
),
1421 NWidget(NWID_SPACER
), SetFill(1, 0),
1423 NWidget(WWT_LABEL
, COLOUR_DARK_GREEN
), SetMinimalSize(144, 11), SetDataTip(STR_STATION_BUILD_PLATFORM_LENGTH
, STR_NULL
), SetPadding(2, 2, 0, 2),
1424 NWidget(NWID_HORIZONTAL
),
1425 NWidget(NWID_SPACER
), SetFill(1, 0),
1426 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_LEN_1
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_1
, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP
),
1427 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_LEN_2
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_2
, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP
),
1428 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_LEN_3
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_3
, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP
),
1429 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_LEN_4
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_4
, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP
),
1430 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_LEN_5
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_5
, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP
),
1431 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_LEN_6
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_6
, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP
),
1432 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_LEN_7
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_7
, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP
),
1433 NWidget(NWID_SPACER
), SetFill(1, 0),
1435 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
1436 NWidget(NWID_HORIZONTAL
),
1437 NWidget(NWID_SPACER
), SetMinimalSize(2, 0), SetFill(1, 0),
1438 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
),
1439 NWidget(NWID_SPACER
), SetMinimalSize(2, 0), SetFill(1, 0),
1441 NWidget(WWT_LABEL
, COLOUR_DARK_GREEN
), SetMinimalSize(144, 11), SetDataTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE
, STR_NULL
), SetPadding(3, 2, 0, 2),
1442 NWidget(NWID_HORIZONTAL
),
1443 NWidget(NWID_SPACER
), SetMinimalSize(2, 0), SetFill(1, 0),
1444 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_HIGHLIGHT_OFF
), SetMinimalSize(60, 12),
1445 SetDataTip(STR_STATION_BUILD_COVERAGE_OFF
, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP
),
1446 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_HIGHLIGHT_ON
), SetMinimalSize(60, 12),
1447 SetDataTip(STR_STATION_BUILD_COVERAGE_ON
, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP
),
1448 NWidget(NWID_SPACER
), SetMinimalSize(2, 0), SetFill(1, 0),
1451 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_BRAS_SHOW_NEWST_MATRIX
),
1452 /* We need an additional background for the matrix, as the matrix cannot handle the scrollbar due to not being an NWidgetCore. */
1453 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
), SetScrollbar(WID_BRAS_MATRIX_SCROLL
),
1454 NWidget(NWID_HORIZONTAL
),
1455 NWidget(NWID_MATRIX
, COLOUR_DARK_GREEN
, WID_BRAS_MATRIX
), SetScrollbar(WID_BRAS_MATRIX_SCROLL
), SetPIP(0, 2, 0), SetPadding(2, 0, 0, 0),
1456 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BRAS_IMAGE
), SetMinimalSize(66, 60),
1457 SetFill(0, 0), SetResize(0, 0), SetDataTip(0x0, STR_STATION_BUILD_STATION_TYPE_TOOLTIP
), SetScrollbar(WID_BRAS_MATRIX_SCROLL
),
1460 NWidget(NWID_VSCROLLBAR
, COLOUR_DARK_GREEN
, WID_BRAS_MATRIX_SCROLL
),
1465 NWidget(NWID_HORIZONTAL
),
1466 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_BRAS_COVERAGE_TEXTS
), SetFill(1, 1), SetResize(1, 0),
1467 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_BRAS_SHOW_NEWST_RESIZE
),
1468 NWidget(NWID_VERTICAL
),
1469 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
), SetFill(0, 1), EndContainer(),
1470 NWidget(WWT_RESIZEBOX
, COLOUR_DARK_GREEN
),
1477 /** Window preferences of the station-build window (default & newGRF) */
1478 static WindowDesc::Prefs
_station_builder_prefs ("build_station_rail");
1480 /** High level window description of the station-build window (default & newGRF) */
1481 static const WindowDesc
_station_builder_desc(
1483 WC_BUILD_STATION
, WC_BUILD_TOOLBAR
,
1485 _nested_station_builder_widgets
, lengthof(_nested_station_builder_widgets
),
1486 &_station_builder_prefs
1489 /** Open station build window */
1490 static void ShowStationBuilder(Window
*parent
)
1492 bool newstations
= StationClass::GetClassCount() > 2 || StationClass::Get(STAT_CLASS_DFLT
)->GetSpecCount() != 1;
1493 new BuildRailStationWindow(&_station_builder_desc
, parent
, newstations
);
1496 struct BuildSignalWindow
: public PickerWindowBase
{
1498 Dimension sig_sprite_size
; ///< Maximum size of signal GUI sprites.
1499 int sig_sprite_bottom_offset
; ///< Maximum extent of signal GUI sprite from reference point towards bottom.
1502 * Draw dynamic a signal-sprite in a button in the signal GUI
1503 * Draw the sprite +1px to the right and down if the button is lowered
1505 * @param widget_index index of this widget in the window
1506 * @param image the sprite to draw
1508 void DrawSignalSprite (BlitArea
*dpi
, byte widget_index
, SpriteID image
) const
1511 Dimension sprite_size
= GetSpriteSize(image
, &offset
);
1512 const NWidgetBase
*widget
= this->GetWidget
<NWidgetBase
>(widget_index
);
1513 int x
= widget
->pos_x
- offset
.x
+
1514 (widget
->current_x
- sprite_size
.width
+ offset
.x
) / 2; // centered
1515 int y
= widget
->pos_y
- sig_sprite_bottom_offset
+ WD_IMGBTN_TOP
+
1516 (widget
->current_y
- WD_IMGBTN_TOP
- WD_IMGBTN_BOTTOM
+ sig_sprite_size
.height
) / 2; // aligned to bottom
1518 DrawSprite (dpi
, image
, PAL_NONE
,
1519 x
+ this->IsWidgetLowered(widget_index
),
1520 y
+ this->IsWidgetLowered(widget_index
));
1524 BuildSignalWindow (const WindowDesc
*desc
, Window
*parent
) :
1525 PickerWindowBase (desc
, parent
), sig_sprite_bottom_offset (0)
1527 this->sig_sprite_size
.width
= 0;
1528 this->sig_sprite_size
.height
= 0;
1530 this->InitNested(TRANSPORT_RAIL
);
1531 this->OnInvalidateData();
1534 void OnDelete (void) FINAL_OVERRIDE
1536 _convert_signal_button
= false;
1537 this->PickerWindowBase::OnDelete();
1540 virtual void OnInit()
1542 /* Calculate maximum signal sprite size. */
1543 this->sig_sprite_size
.width
= 0;
1544 this->sig_sprite_size
.height
= 0;
1545 this->sig_sprite_bottom_offset
= 0;
1546 const RailtypeInfo
*rti
= GetRailTypeInfo(_cur_railtype
);
1547 for (uint type
= SIGTYPE_NORMAL
; type
< SIGTYPE_END
; type
++) {
1548 for (uint variant
= SIG_ELECTRIC
; variant
<= SIG_SEMAPHORE
; variant
++) {
1549 for (uint lowered
= 0; lowered
< 2; lowered
++) {
1551 Dimension sprite_size
= GetSpriteSize(rti
->gui_sprites
.signals
[type
][variant
][lowered
], &offset
);
1552 this->sig_sprite_bottom_offset
= max
<int>(this->sig_sprite_bottom_offset
, sprite_size
.height
);
1553 this->sig_sprite_size
.width
= max
<int>(this->sig_sprite_size
.width
, sprite_size
.width
- offset
.x
);
1554 this->sig_sprite_size
.height
= max
<int>(this->sig_sprite_size
.height
, sprite_size
.height
- offset
.y
);
1560 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
1562 if (widget
== WID_BS_DRAG_SIGNALS_DENSITY_LABEL
) {
1563 /* Two digits for signals density. */
1564 size
->width
= max(size
->width
, 2 * GetDigitWidth() + padding
.width
+ WD_FRAMERECT_LEFT
+ WD_FRAMERECT_RIGHT
);
1565 } else if (IsInsideMM(widget
, WID_BS_SEMAPHORE_NORM
, WID_BS_ELECTRIC_PBS_OWAY
+ 1)) {
1566 size
->width
= max(size
->width
, this->sig_sprite_size
.width
+ WD_IMGBTN_LEFT
+ WD_IMGBTN_RIGHT
);
1567 size
->height
= max(size
->height
, this->sig_sprite_size
.height
+ WD_IMGBTN_TOP
+ WD_IMGBTN_BOTTOM
);
1571 virtual void SetStringParameters(int widget
) const
1574 case WID_BS_DRAG_SIGNALS_DENSITY_LABEL
:
1575 SetDParam(0, _settings_client
.gui
.drag_signals_density
);
1580 void DrawWidget (BlitArea
*dpi
, const Rect
&r
, int widget
) const OVERRIDE
1582 if (IsInsideMM(widget
, WID_BS_SEMAPHORE_NORM
, WID_BS_ELECTRIC_PBS_OWAY
+ 1)) {
1583 /* Extract signal from widget number. */
1584 int type
= (widget
- WID_BS_SEMAPHORE_NORM
) % SIGTYPE_END
;
1585 int var
= SIG_SEMAPHORE
- (widget
- WID_BS_SEMAPHORE_NORM
) / SIGTYPE_END
; // SignalVariant order is reversed compared to the widgets.
1586 SpriteID sprite
= GetRailTypeInfo(_cur_railtype
)->gui_sprites
.signals
[type
][var
][this->IsWidgetLowered(widget
)];
1588 this->DrawSignalSprite (dpi
, widget
, sprite
);
1592 virtual void OnClick(Point pt
, int widget
, int click_count
)
1595 case WID_BS_SEMAPHORE_NORM
:
1596 case WID_BS_SEMAPHORE_ENTRY
:
1597 case WID_BS_SEMAPHORE_EXIT
:
1598 case WID_BS_SEMAPHORE_COMBO
:
1599 case WID_BS_SEMAPHORE_PBS
:
1600 case WID_BS_SEMAPHORE_PBS_OWAY
:
1601 case WID_BS_ELECTRIC_NORM
:
1602 case WID_BS_ELECTRIC_ENTRY
:
1603 case WID_BS_ELECTRIC_EXIT
:
1604 case WID_BS_ELECTRIC_COMBO
:
1605 case WID_BS_ELECTRIC_PBS
:
1606 case WID_BS_ELECTRIC_PBS_OWAY
:
1607 this->RaiseWidget((_cur_signal_variant
== SIG_ELECTRIC
? WID_BS_ELECTRIC_NORM
: WID_BS_SEMAPHORE_NORM
) + _cur_signal_type
);
1609 _cur_signal_type
= (SignalType
)((uint
)((widget
- WID_BS_SEMAPHORE_NORM
) % SIGTYPE_END
));
1610 _cur_signal_variant
= widget
>= WID_BS_ELECTRIC_NORM
? SIG_ELECTRIC
: SIG_SEMAPHORE
;
1612 /* If 'remove' button of rail build toolbar is active, disable it. */
1613 if (_remove_button_clicked
) {
1614 Window
*w
= FindWindowById(WC_BUILD_TOOLBAR
, TRANSPORT_RAIL
);
1615 if (w
!= NULL
) ToggleRailButton_Remove(w
);
1620 case WID_BS_CONVERT
:
1621 _convert_signal_button
= !_convert_signal_button
;
1624 case WID_BS_DRAG_SIGNALS_DENSITY_DECREASE
:
1625 if (_settings_client
.gui
.drag_signals_density
> 1) {
1626 _settings_client
.gui
.drag_signals_density
--;
1627 SetWindowDirty(WC_GAME_OPTIONS
, WN_GAME_OPTIONS_GAME_SETTINGS
);
1631 case WID_BS_DRAG_SIGNALS_DENSITY_INCREASE
:
1632 if (_settings_client
.gui
.drag_signals_density
< 20) {
1633 _settings_client
.gui
.drag_signals_density
++;
1634 SetWindowDirty(WC_GAME_OPTIONS
, WN_GAME_OPTIONS_GAME_SETTINGS
);
1641 this->InvalidateData();
1645 * Some data on this window has become invalid.
1646 * @param data Information about the changed data.
1647 * @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.
1649 virtual void OnInvalidateData(int data
= 0, bool gui_scope
= true)
1651 if (!gui_scope
) return;
1652 this->LowerWidget((_cur_signal_variant
== SIG_ELECTRIC
? WID_BS_ELECTRIC_NORM
: WID_BS_SEMAPHORE_NORM
) + _cur_signal_type
);
1654 this->SetWidgetLoweredState(WID_BS_CONVERT
, _convert_signal_button
);
1656 this->SetWidgetDisabledState(WID_BS_DRAG_SIGNALS_DENSITY_DECREASE
, _settings_client
.gui
.drag_signals_density
== 1);
1657 this->SetWidgetDisabledState(WID_BS_DRAG_SIGNALS_DENSITY_INCREASE
, _settings_client
.gui
.drag_signals_density
== 20);
1661 /** Nested widget definition of the build signal window */
1662 static const NWidgetPart _nested_signal_builder_widgets
[] = {
1663 NWidget(NWID_HORIZONTAL
),
1664 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
1665 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
), SetDataTip(STR_BUILD_SIGNAL_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
1667 NWidget(NWID_VERTICAL
, NC_EQUALSIZE
),
1668 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
1669 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_SEMAPHORE_NORM
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_SEMAPHORE_NORM_TOOLTIP
), EndContainer(), SetFill(1, 1),
1670 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_SEMAPHORE_ENTRY
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_SEMAPHORE_ENTRY_TOOLTIP
), EndContainer(), SetFill(1, 1),
1671 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_SEMAPHORE_EXIT
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_SEMAPHORE_EXIT_TOOLTIP
), EndContainer(), SetFill(1, 1),
1672 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_SEMAPHORE_COMBO
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_SEMAPHORE_COMBO_TOOLTIP
), EndContainer(), SetFill(1, 1),
1673 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_SEMAPHORE_PBS
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_SEMAPHORE_PBS_TOOLTIP
), EndContainer(), SetFill(1, 1),
1674 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),
1675 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_BS_CONVERT
), SetDataTip(SPR_IMG_SIGNAL_CONVERT
, STR_BUILD_SIGNAL_CONVERT_TOOLTIP
), SetFill(1, 1),
1677 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
1678 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_ELECTRIC_NORM
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_ELECTRIC_NORM_TOOLTIP
), EndContainer(), SetFill(1, 1),
1679 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_ELECTRIC_ENTRY
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_ELECTRIC_ENTRY_TOOLTIP
), EndContainer(), SetFill(1, 1),
1680 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_ELECTRIC_EXIT
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_ELECTRIC_EXIT_TOOLTIP
), EndContainer(), SetFill(1, 1),
1681 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_ELECTRIC_COMBO
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_ELECTRIC_COMBO_TOOLTIP
), EndContainer(), SetFill(1, 1),
1682 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_ELECTRIC_PBS
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_ELECTRIC_PBS_TOOLTIP
), EndContainer(), SetFill(1, 1),
1683 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),
1684 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_DRAG_SIGNALS_DENSITY_TOOLTIP
), SetFill(1, 1),
1685 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),
1686 NWidget(NWID_HORIZONTAL
), SetPIP(2, 0, 2),
1687 NWidget(NWID_SPACER
), SetFill(1, 0),
1688 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
),
1689 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
),
1690 NWidget(NWID_SPACER
), SetFill(1, 0),
1692 NWidget(NWID_SPACER
), SetMinimalSize(0, 2), SetFill(1, 0),
1698 /** Signal selection window preferences */
1699 static WindowDesc::Prefs
_signal_builder_prefs ("build_signal");
1701 /** Signal selection window description */
1702 static const WindowDesc
_signal_builder_desc(
1704 WC_BUILD_SIGNAL
, WC_BUILD_TOOLBAR
,
1706 _nested_signal_builder_widgets
, lengthof(_nested_signal_builder_widgets
),
1707 &_signal_builder_prefs
1711 * Open the signal selection window
1713 static void ShowSignalBuilder(Window
*parent
)
1715 new BuildSignalWindow(&_signal_builder_desc
, parent
);
1718 struct BuildRailDepotWindow
: public PickerWindowBase
{
1719 BuildRailDepotWindow (const WindowDesc
*desc
, Window
*parent
) : PickerWindowBase(desc
, parent
)
1721 this->InitNested(TRANSPORT_RAIL
);
1722 this->LowerWidget(_build_depot_direction
+ WID_BRAD_DEPOT_NE
);
1725 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
1727 if (!IsInsideMM(widget
, WID_BRAD_DEPOT_NE
, WID_BRAD_DEPOT_NW
+ 1)) return;
1729 size
->width
= ScaleGUITrad(64) + 2;
1730 size
->height
= ScaleGUITrad(48) + 2;
1733 void DrawWidget (BlitArea
*dpi
, const Rect
&r
, int widget
) const OVERRIDE
1735 if (!IsInsideMM(widget
, WID_BRAD_DEPOT_NE
, WID_BRAD_DEPOT_NW
+ 1)) return;
1737 DrawTrainDepotSprite (dpi
, r
.left
+ 1 + ScaleGUITrad(31), r
.bottom
- ScaleGUITrad(31), widget
- WID_BRAD_DEPOT_NE
+ DIAGDIR_NE
, _cur_railtype
);
1740 virtual void OnClick(Point pt
, int widget
, int click_count
)
1743 case WID_BRAD_DEPOT_NE
:
1744 case WID_BRAD_DEPOT_SE
:
1745 case WID_BRAD_DEPOT_SW
:
1746 case WID_BRAD_DEPOT_NW
:
1747 this->RaiseWidget(_build_depot_direction
+ WID_BRAD_DEPOT_NE
);
1748 _build_depot_direction
= (DiagDirection
)(widget
- WID_BRAD_DEPOT_NE
);
1749 this->LowerWidget(_build_depot_direction
+ WID_BRAD_DEPOT_NE
);
1750 if (_settings_client
.sound
.click_beep
) SndPlayFx(SND_15_BEEP
);
1757 /** Nested widget definition of the build rail depot window */
1758 static const NWidgetPart _nested_build_depot_widgets
[] = {
1759 NWidget(NWID_HORIZONTAL
),
1760 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
1761 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
), SetDataTip(STR_BUILD_DEPOT_TRAIN_ORIENTATION_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
1763 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
),
1764 NWidget(NWID_SPACER
), SetMinimalSize(0, 3),
1765 NWidget(NWID_HORIZONTAL_LTR
),
1766 NWidget(NWID_SPACER
), SetMinimalSize(3, 0), SetFill(1, 0),
1767 NWidget(NWID_VERTICAL
),
1768 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BRAD_DEPOT_NW
), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_TRAIN_ORIENTATION_TOOLTIP
),
1770 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
1771 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BRAD_DEPOT_SW
), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_TRAIN_ORIENTATION_TOOLTIP
),
1774 NWidget(NWID_SPACER
), SetMinimalSize(2, 0),
1775 NWidget(NWID_VERTICAL
),
1776 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BRAD_DEPOT_NE
), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_TRAIN_ORIENTATION_TOOLTIP
),
1778 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
1779 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BRAD_DEPOT_SE
), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_TRAIN_ORIENTATION_TOOLTIP
),
1782 NWidget(NWID_SPACER
), SetMinimalSize(3, 0), SetFill(1, 0),
1784 NWidget(NWID_SPACER
), SetMinimalSize(0, 3),
1788 static const WindowDesc
_build_depot_desc(
1790 WC_BUILD_DEPOT
, WC_BUILD_TOOLBAR
,
1792 _nested_build_depot_widgets
, lengthof(_nested_build_depot_widgets
)
1795 static void ShowBuildTrainDepotPicker(Window
*parent
)
1797 new BuildRailDepotWindow(&_build_depot_desc
, parent
);
1800 struct BuildRailWaypointWindow
: PickerWindowBase
{
1801 BuildRailWaypointWindow (const WindowDesc
*desc
, Window
*parent
) : PickerWindowBase(desc
, parent
)
1803 this->CreateNestedTree();
1805 NWidgetMatrix
*matrix
= this->GetWidget
<NWidgetMatrix
>(WID_BRW_WAYPOINT_MATRIX
);
1806 matrix
->SetScrollbar(this->GetScrollbar(WID_BRW_SCROLL
));
1808 this->InitNested(TRANSPORT_RAIL
);
1810 matrix
->SetCount(_waypoint_count
);
1811 matrix
->SetClicked(_cur_waypoint_type
);
1814 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
1817 case WID_BRW_WAYPOINT_MATRIX
:
1818 /* Three blobs high and wide. */
1819 size
->width
+= resize
->width
* 2;
1820 size
->height
+= resize
->height
* 2;
1822 /* Resizing in X direction only at blob size, but at pixel level in Y. */
1826 case WID_BRW_WAYPOINT
:
1827 size
->width
= ScaleGUITrad(64) + 2;
1828 size
->height
= ScaleGUITrad(58) + 2;
1833 void DrawWidget (BlitArea
*dpi
, const Rect
&r
, int widget
) const OVERRIDE
1835 switch (GB(widget
, 0, 16)) {
1836 case WID_BRW_WAYPOINT
: {
1837 byte type
= GB(widget
, 16, 16);
1838 DrawStationPreview (dpi
, r
, STAT_CLASS_WAYP
, type
, AXIS_X
, true);
1844 virtual void OnClick(Point pt
, int widget
, int click_count
)
1846 switch (GB(widget
, 0, 16)) {
1847 case WID_BRW_WAYPOINT
: {
1848 byte type
= GB(widget
, 16, 16);
1849 this->GetWidget
<NWidgetMatrix
>(WID_BRW_WAYPOINT_MATRIX
)->SetClicked(_cur_waypoint_type
);
1851 /* Check station availability callback */
1852 const StationSpec
*statspec
= StationClass::Get(STAT_CLASS_WAYP
)->GetSpec(type
);
1853 if (!IsStationAvailable(statspec
)) return;
1855 _cur_waypoint_type
= type
;
1856 this->GetWidget
<NWidgetMatrix
>(WID_BRW_WAYPOINT_MATRIX
)->SetClicked(_cur_waypoint_type
);
1857 if (_settings_client
.sound
.click_beep
) SndPlayFx(SND_15_BEEP
);
1865 /** Nested widget definition for the build NewGRF rail waypoint window */
1866 static const NWidgetPart _nested_build_waypoint_widgets
[] = {
1867 NWidget(NWID_HORIZONTAL
),
1868 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
1869 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
), SetDataTip(STR_WAYPOINT_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
1870 NWidget(WWT_DEFSIZEBOX
, COLOUR_DARK_GREEN
),
1872 NWidget(NWID_HORIZONTAL
),
1873 NWidget(NWID_MATRIX
, COLOUR_DARK_GREEN
, WID_BRW_WAYPOINT_MATRIX
), SetPIP(3, 2, 3), SetScrollbar(WID_BRW_SCROLL
),
1874 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BRW_WAYPOINT
), SetMinimalSize(66, 60), SetDataTip(0x0, STR_WAYPOINT_GRAPHICS_TOOLTIP
), SetScrollbar(WID_BRW_SCROLL
), EndContainer(),
1876 NWidget(NWID_VERTICAL
),
1877 NWidget(NWID_VSCROLLBAR
, COLOUR_DARK_GREEN
, WID_BRW_SCROLL
),
1878 NWidget(WWT_RESIZEBOX
, COLOUR_DARK_GREEN
),
1883 static WindowDesc::Prefs
_build_waypoint_prefs ("build_waypoint");
1885 static const WindowDesc
_build_waypoint_desc(
1887 WC_BUILD_WAYPOINT
, WC_BUILD_TOOLBAR
,
1889 _nested_build_waypoint_widgets
, lengthof(_nested_build_waypoint_widgets
),
1890 &_build_waypoint_prefs
1893 static void ShowBuildWaypointPicker(Window
*parent
)
1895 new BuildRailWaypointWindow(&_build_waypoint_desc
, parent
);
1899 * Initialize rail building GUI settings
1901 void InitializeRailGui()
1903 _build_depot_direction
= DIAGDIR_NW
;
1907 * Re-initialize rail-build toolbar after toggling support for electric trains
1908 * @param disable Boolean whether electric trains are disabled (removed from the game)
1910 void ReinitGuiAfterToggleElrail(bool disable
)
1912 extern RailType _last_built_railtype
;
1913 if (disable
&& _last_built_railtype
== RAILTYPE_ELECTRIC
) {
1914 _last_built_railtype
= _cur_railtype
= RAILTYPE_RAIL
;
1915 BuildRailToolbarWindow
*w
= dynamic_cast<BuildRailToolbarWindow
*>(FindWindowById(WC_BUILD_TOOLBAR
, TRANSPORT_RAIL
));
1916 if (w
!= NULL
) w
->ModifyRailType(_cur_railtype
);
1918 MarkWholeScreenDirty();
1921 /** Set the initial (default) railtype to use */
1922 static void SetDefaultRailGui()
1924 if (_local_company
== COMPANY_SPECTATOR
|| !Company::IsValidID(_local_company
)) return;
1926 extern RailType _last_built_railtype
;
1927 RailType rt
= (RailType
)(_settings_client
.gui
.default_rail_type
+ RAILTYPE_END
);
1928 if (rt
== DEF_RAILTYPE_MOST_USED
) {
1929 /* Find the most used rail type */
1930 RailType count
[RAILTYPE_END
];
1931 memset(count
, 0, sizeof(count
));
1932 for (TileIndex t
= 0; t
< MapSize(); t
++) {
1933 if (IsRailwayTile(t
) || IsRailDepotTile(t
) || IsLevelCrossingTile(t
) || HasStationTileRail(t
) ||
1934 maptile_is_rail_tunnel(t
)) {
1935 count
[GetRailType(t
)]++;
1940 for (RailType r
= RAILTYPE_ELECTRIC
; r
< RAILTYPE_END
; r
++) {
1941 if (count
[r
] >= count
[rt
]) rt
= r
;
1944 /* No rail, just get the first available one */
1945 if (count
[rt
] == 0) rt
= DEF_RAILTYPE_FIRST
;
1948 case DEF_RAILTYPE_FIRST
:
1950 while (rt
< RAILTYPE_END
&& !HasRailtypeAvail(_local_company
, rt
)) rt
++;
1953 case DEF_RAILTYPE_LAST
:
1954 rt
= GetBestRailtype(_local_company
);
1961 _last_built_railtype
= _cur_railtype
= rt
;
1962 BuildRailToolbarWindow
*w
= dynamic_cast<BuildRailToolbarWindow
*>(FindWindowById(WC_BUILD_TOOLBAR
, TRANSPORT_RAIL
));
1963 if (w
!= NULL
) w
->ModifyRailType(_cur_railtype
);
1967 * Updates the current signal variant used in the signal GUI
1968 * to the one adequate to current year.
1969 * @param p needed to be called when a setting changes
1970 * @return success, needed for settings
1972 bool ResetSignalVariant(int32 p
)
1974 SignalVariant new_variant
= (_cur_year
< _settings_client
.gui
.semaphore_build_before
? SIG_SEMAPHORE
: SIG_ELECTRIC
);
1976 if (new_variant
!= _cur_signal_variant
) {
1977 Window
*w
= FindWindowById(WC_BUILD_SIGNAL
, 0);
1980 w
->RaiseWidget((_cur_signal_variant
== SIG_ELECTRIC
? WID_BS_ELECTRIC_NORM
: WID_BS_SEMAPHORE_NORM
) + _cur_signal_type
);
1982 _cur_signal_variant
= new_variant
;
1989 * Resets the rail GUI - sets default railtype to build
1990 * and resets the signal GUI
1992 void InitializeRailGUI()
1994 SetDefaultRailGui();
1996 _convert_signal_button
= false;
1997 _cur_signal_type
= _default_signal_type
[_settings_client
.gui
.default_signal_type
];
1998 ResetSignalVariant();
2002 * Create a drop down list for all the rail types of the local company.
2003 * @param for_replacement Whether this list is for the replacement window.
2004 * @param all_option Whether to add an 'all types' item.
2005 * @return The populated and sorted #DropDownList.
2007 DropDownList
*GetRailTypeDropDownList(bool for_replacement
, bool all_option
)
2009 RailTypes used_railtypes
= RAILTYPES_NONE
;
2011 /* Find the used railtypes. */
2013 FOR_ALL_ENGINES_OF_TYPE(e
, VEH_TRAIN
) {
2014 if (!HasBit(e
->info
.climates
, _settings_game
.game_creation
.landscape
)) continue;
2016 used_railtypes
|= GetRailTypeInfo(e
->u
.rail
.railtype
)->introduces_railtypes
;
2019 /* Get the date introduced railtypes as well. */
2020 used_railtypes
= AddDateIntroducedRailTypes(used_railtypes
, MAX_DAY
);
2022 const Company
*c
= Company::Get(_local_company
);
2023 DropDownList
*list
= new DropDownList();
2026 DropDownListStringItem
*item
= new DropDownListStringItem(STR_REPLACE_ALL_RAILTYPE
, INVALID_RAILTYPE
, false);
2027 *list
->Append() = item
;
2031 FOR_ALL_SORTED_RAILTYPES(rt
) {
2032 /* If it's not used ever, don't show it to the user. */
2033 if (!HasBit(used_railtypes
, rt
)) continue;
2035 const RailtypeInfo
*rti
= GetRailTypeInfo(rt
);
2037 StringID str
= for_replacement
? rti
->strings
.replace_text
: (rti
->max_speed
> 0 ? STR_TOOLBAR_RAILTYPE_VELOCITY
: STR_JUST_STRING
);
2038 DropDownListParamStringItem
*item
= new DropDownListParamStringItem(str
, rt
, !HasBit(c
->avail_railtypes
, rt
));
2039 item
->SetParam(0, rti
->strings
.menu_text
);
2040 item
->SetParam(1, rti
->max_speed
);
2041 *list
->Append() = item
;