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 virtual EventState
OnHotkey(int hotkey
)
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
, Point pt
, TileIndex start_tile
, TileIndex end_tile
) OVERRIDE
732 default: NOT_REACHED();
733 case DRAG_BUILD_BRIDGE
:
734 HandleBuildRailBridge (start_tile
, end_tile
);
737 case DRAG_PLACE_RAIL
:
738 HandleAutodirPlacement (start_tile
, end_tile
);
741 case DRAG_BUILD_SIGNALS
:
742 HandleAutoSignalPlacement (start_tile
, end_tile
);
745 case DRAG_DEMOLISH_AREA
:
746 HandleDemolishMouseUp (start_tile
, end_tile
);
749 case DRAG_CONVERT_RAIL
:
750 DoCommandP(end_tile
, start_tile
, _cur_railtype
| (_ctrl_pressed
? 0x10 : 0), CMD_CONVERT_RAIL
);
754 if (_remove_button_clicked
) {
755 DoCommandP (end_tile
, start_tile
, _ctrl_pressed
? 0 : 1, CMD_REMOVE_FROM_RAIL_STATION
);
757 HandleStationPlacement (start_tile
, end_tile
);
761 case DRAG_BUILD_WAYPOINT_X
:
762 case DRAG_BUILD_WAYPOINT_Y
: {
763 TileArea
ta (start_tile
, end_tile
);
764 uint32 p1
= _cur_railtype
| (userdata
== DRAG_BUILD_WAYPOINT_X
? AXIS_X
: AXIS_Y
) << 4 | ta
.w
<< 8 | ta
.h
<< 16 | _ctrl_pressed
<< 24;
765 uint32 p2
= STAT_CLASS_WAYP
| _cur_waypoint_type
<< 8 | INVALID_STATION
<< 16;
767 Command
cmdcont (ta
.tile
, p1
, p2
, CMD_BUILD_RAIL_WAYPOINT
);
768 ShowSelectWaypointIfNeeded (&cmdcont
, ta
);
772 case DRAG_REMOVE_WAYPOINT
:
773 DoCommandP (end_tile
, start_tile
, _ctrl_pressed
? 0 : 1, CMD_REMOVE_FROM_RAIL_WAYPOINT
);
779 virtual void OnPlaceObjectAbort()
781 this->RaiseButtons();
782 this->DisableWidget(WID_RAT_REMOVE
);
783 this->SetWidgetDirty(WID_RAT_REMOVE
);
785 DeleteWindowById(WC_BUILD_SIGNAL
, TRANSPORT_RAIL
);
786 DeleteWindowById(WC_BUILD_STATION
, TRANSPORT_RAIL
);
787 DeleteWindowById(WC_BUILD_DEPOT
, TRANSPORT_RAIL
);
788 DeleteWindowById(WC_BUILD_WAYPOINT
, TRANSPORT_RAIL
);
789 DeleteWindowById(WC_SELECT_STATION
, 0);
790 DeleteWindowByClass(WC_BUILD_BRIDGE
);
793 void OnPlacePresize (TileIndex
*tile
, TileIndex
*tile2
) OVERRIDE
795 DoCommand (*tile
, _cur_railtype
| (TRANSPORT_RAIL
<< 8), 0, DC_AUTO
, CMD_BUILD_TUNNEL
);
796 if (_build_tunnel_endtile
!= 0) *tile2
= _build_tunnel_endtile
;
799 virtual EventState
OnCTRLStateChange()
801 /* do not toggle Remove button by Ctrl when placing station */
802 if (!this->IsWidgetLowered(WID_RAT_BUILD_STATION
) && !this->IsWidgetLowered(WID_RAT_BUILD_WAYPOINT
) && RailToolbar_CtrlChanged(this)) return ES_HANDLED
;
803 return ES_NOT_HANDLED
;
806 static HotkeyList hotkeys
;
810 * Handler for global hotkeys of the BuildRailToolbarWindow.
811 * @param hotkey Hotkey
812 * @return ES_HANDLED if hotkey was accepted.
814 static EventState
RailToolbarGlobalHotkeys(int hotkey
)
816 if (_game_mode
!= GM_NORMAL
|| !CanBuildVehicleInfrastructure(VEH_TRAIN
)) return ES_NOT_HANDLED
;
817 extern RailType _last_built_railtype
;
818 Window
*w
= ShowBuildRailToolbar(_last_built_railtype
);
819 if (w
== NULL
) return ES_NOT_HANDLED
;
820 return w
->OnHotkey(hotkey
);
823 static const Hotkey railtoolbar_hotkeys
[] = {
824 Hotkey ("build_ns", WID_RAT_BUILD_NS
, '1'),
825 Hotkey ("build_x", WID_RAT_BUILD_X
, '2'),
826 Hotkey ("build_ew", WID_RAT_BUILD_EW
, '3'),
827 Hotkey ("build_y", WID_RAT_BUILD_Y
, '4'),
828 Hotkey ("autorail", WID_RAT_AUTORAIL
, '5', 'A' | WKC_GLOBAL_HOTKEY
),
829 Hotkey ("demolish", WID_RAT_DEMOLISH
, '6'),
830 Hotkey ("depot", WID_RAT_BUILD_DEPOT
, '7'),
831 Hotkey ("waypoint", WID_RAT_BUILD_WAYPOINT
, '8'),
832 Hotkey ("station", WID_RAT_BUILD_STATION
, '9'),
833 Hotkey ("signal", WID_RAT_BUILD_SIGNALS
, 'S'),
834 Hotkey ("bridge", WID_RAT_BUILD_BRIDGE
, 'B'),
835 Hotkey ("tunnel", WID_RAT_BUILD_TUNNEL
, 'T'),
836 Hotkey ("remove", WID_RAT_REMOVE
, 'R'),
837 Hotkey ("convert", WID_RAT_CONVERT_RAIL
, 'C'),
839 HotkeyList
BuildRailToolbarWindow::hotkeys("railtoolbar", railtoolbar_hotkeys
, RailToolbarGlobalHotkeys
);
841 static const NWidgetPart _nested_build_rail_widgets
[] = {
842 NWidget(NWID_HORIZONTAL
),
843 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
844 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
, WID_RAT_CAPTION
), SetDataTip(STR_WHITE_STRING
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
845 NWidget(WWT_STICKYBOX
, COLOUR_DARK_GREEN
),
847 NWidget(NWID_HORIZONTAL
),
848 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_BUILD_NS
),
849 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_RAIL_NS
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_TRACK
),
850 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_BUILD_X
),
851 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_RAIL_NE
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_TRACK
),
852 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_BUILD_EW
),
853 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_RAIL_EW
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_TRACK
),
854 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_BUILD_Y
),
855 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_RAIL_NW
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_TRACK
),
856 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_AUTORAIL
),
857 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_AUTORAIL
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_AUTORAIL
),
859 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
), SetMinimalSize(4, 22), SetDataTip(0x0, STR_NULL
), EndContainer(),
861 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_DEMOLISH
),
862 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DYNAMITE
, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC
),
863 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_BUILD_DEPOT
),
864 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DEPOT_RAIL
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_TRAIN_DEPOT_FOR_BUILDING
),
865 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_BUILD_WAYPOINT
),
866 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_WAYPOINT
, STR_RAIL_TOOLBAR_TOOLTIP_CONVERT_RAIL_TO_WAYPOINT
),
867 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_BUILD_STATION
),
868 SetFill(0, 1), SetMinimalSize(42, 22), SetDataTip(SPR_IMG_RAIL_STATION
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_STATION
),
869 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_BUILD_SIGNALS
),
870 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_RAIL_SIGNALS
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_SIGNALS
),
871 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_BUILD_BRIDGE
),
872 SetFill(0, 1), SetMinimalSize(42, 22), SetDataTip(SPR_IMG_BRIDGE
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_BRIDGE
),
873 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_BUILD_TUNNEL
),
874 SetFill(0, 1), SetMinimalSize(20, 22), SetDataTip(SPR_IMG_TUNNEL_RAIL
, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_TUNNEL
),
875 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_REMOVE
),
876 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_REMOVE
, STR_RAIL_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR
),
877 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_RAT_CONVERT_RAIL
),
878 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_CONVERT_RAIL
, STR_RAIL_TOOLBAR_TOOLTIP_CONVERT_RAIL
),
882 static WindowDesc::Prefs
_build_rail_prefs ("toolbar_rail");
884 static const WindowDesc
_build_rail_desc(
885 WDP_ALIGN_TOOLBAR
, 0, 0,
886 WC_BUILD_TOOLBAR
, WC_NONE
,
888 _nested_build_rail_widgets
, lengthof(_nested_build_rail_widgets
),
889 &_build_rail_prefs
, &BuildRailToolbarWindow::hotkeys
894 * Open the build rail toolbar window for a specific rail type.
896 * If the terraform toolbar is linked to the toolbar, that window is also opened.
898 * @param railtype Rail type to open the window for
899 * @return newly opened rail toolbar, or NULL if the toolbar could not be opened.
901 Window
*ShowBuildRailToolbar(RailType railtype
)
903 if (!Company::IsValidID(_local_company
)) return NULL
;
904 if (!ValParamRailtype(railtype
)) return NULL
;
906 DeleteWindowByClass(WC_BUILD_TOOLBAR
);
907 _cur_railtype
= railtype
;
908 _remove_button_clicked
= false;
909 return new BuildRailToolbarWindow(&_build_rail_desc
, railtype
);
912 /* TODO: For custom stations, respect their allowed platforms/lengths bitmasks!
915 static void HandleStationPlacement(TileIndex start
, TileIndex end
)
917 TileArea
ta(start
, end
);
918 uint numtracks
= ta
.w
;
919 uint platlength
= ta
.h
;
921 if (_railstation
.orientation
== AXIS_X
) Swap(numtracks
, platlength
);
923 uint32 p1
= _cur_railtype
| _railstation
.orientation
<< 4 | numtracks
<< 8 | platlength
<< 16 | _ctrl_pressed
<< 24;
924 uint32 p2
= _railstation
.station_class
| _railstation
.station_type
<< 8 | INVALID_STATION
<< 16;
926 Command
cmdcont (ta
.tile
, p1
, p2
, CMD_BUILD_RAIL_STATION
);
927 ShowSelectStationIfNeeded (&cmdcont
, ta
);
930 /** Check the selected number of tracks when turning drag&drop off. */
931 static void CheckPlatformWidth (const StationSpec
*statspec
)
933 byte disallowed
= statspec
->disallowed_platforms
;
934 if (HasBit(disallowed
, _settings_client
.gui
.station_numtracks
- 1)) {
935 /* The previously selected number of tracks is invalid. */
936 for (uint i
= 0; i
< 7; i
++) {
937 if (!HasBit(disallowed
, i
)) {
938 _settings_client
.gui
.station_numtracks
= i
+ 1;
945 /** Check the selected platform length when turning drag&drop off. */
946 static void CheckPlatformLength (const StationSpec
*statspec
)
948 byte disallowed
= statspec
->disallowed_lengths
;
949 if (HasBit(disallowed
, _settings_client
.gui
.station_platlength
- 1)) {
950 /* The previously selected number of platforms is invalid. */
951 for (uint i
= 0; i
< 7; i
++) {
952 if (!HasBit(disallowed
, i
)) {
953 _settings_client
.gui
.station_platlength
= i
+ 1;
960 /** Draw a station preview in a widget. */
961 static void DrawStationPreview (BlitArea
*dpi
, const Rect
&r
,
962 StationClassID cls
, uint type
, uint image
, bool check_avail
)
964 /* Set up a clipping area for the station preview. */
966 if (InitBlitArea (dpi
, &tmp_dpi
, r
.left
, r
.top
, r
.right
- r
.left
+ 1, r
.bottom
- r
.top
+ 1)) {
967 int x
= ScaleGUITrad(31) + 1;
968 int y
= r
.bottom
- r
.top
- ScaleGUITrad(31);
969 if (!DrawStationTile (&tmp_dpi
, x
, y
, _cur_railtype
, (Axis
)(image
% 2), cls
, type
)) {
970 RailStationPickerDrawSprite (&tmp_dpi
, x
, y
, cls
== STAT_CLASS_WAYP
, _cur_railtype
, image
);
974 /* Check station availability callback */
975 if (check_avail
&& !IsStationAvailable (StationClass::Get(cls
)->GetSpec(type
))) {
976 GfxFillRect (dpi
, r
.left
+ 1, r
.top
+ 1, r
.right
- 1, r
.bottom
- 1, PC_BLACK
, FILLRECT_CHECKER
);
980 struct BuildRailStationWindow
: public PickerWindowBase
{
982 uint line_height
; ///< Height of a single line in the newstation selection matrix (#WID_BRAS_NEWST_LIST widget).
983 uint coverage_height
; ///< Height of the coverage texts.
984 Scrollbar
*vscroll
; ///< Vertical scrollbar of the new station list.
985 Scrollbar
*vscroll2
; ///< Vertical scrollbar of the matrix with new stations.
988 * Verify whether the currently selected station size is allowed after selecting a new station class/type.
989 * If not, change the station size variables ( _settings_client.gui.station_numtracks and _settings_client.gui.station_platlength ).
990 * @param statspec Specification of the new station class/type
992 void CheckSelectedSize(const StationSpec
*statspec
)
994 if (statspec
== NULL
|| _settings_client
.gui
.station_dragdrop
) return;
996 /* If current number of tracks is not allowed, make it as big as possible */
997 if (HasBit(statspec
->disallowed_platforms
, _settings_client
.gui
.station_numtracks
- 1)) {
998 this->RaiseWidget(_settings_client
.gui
.station_numtracks
+ WID_BRAS_PLATFORM_NUM_BEGIN
);
999 _settings_client
.gui
.station_numtracks
= 1;
1000 if (statspec
->disallowed_platforms
!= UINT8_MAX
) {
1001 while (HasBit(statspec
->disallowed_platforms
, _settings_client
.gui
.station_numtracks
- 1)) {
1002 _settings_client
.gui
.station_numtracks
++;
1004 this->LowerWidget(_settings_client
.gui
.station_numtracks
+ WID_BRAS_PLATFORM_NUM_BEGIN
);
1008 if (HasBit(statspec
->disallowed_lengths
, _settings_client
.gui
.station_platlength
- 1)) {
1009 this->RaiseWidget(_settings_client
.gui
.station_platlength
+ WID_BRAS_PLATFORM_LEN_BEGIN
);
1010 _settings_client
.gui
.station_platlength
= 1;
1011 if (statspec
->disallowed_lengths
!= UINT8_MAX
) {
1012 while (HasBit(statspec
->disallowed_lengths
, _settings_client
.gui
.station_platlength
- 1)) {
1013 _settings_client
.gui
.station_platlength
++;
1015 this->LowerWidget(_settings_client
.gui
.station_platlength
+ WID_BRAS_PLATFORM_LEN_BEGIN
);
1021 BuildRailStationWindow (const WindowDesc
*desc
, Window
*parent
, bool newstation
) :
1022 PickerWindowBase (desc
, parent
), line_height (0),
1023 coverage_height (2 * FONT_HEIGHT_NORMAL
+ 3 * WD_PAR_VSEP_NORMAL
),
1024 vscroll (NULL
), vscroll2 (NULL
)
1026 _railstation
.newstations
= newstation
;
1028 this->CreateNestedTree();
1029 NWidgetStacked
*newst_additions
= this->GetWidget
<NWidgetStacked
>(WID_BRAS_SHOW_NEWST_ADDITIONS
);
1030 newst_additions
->SetDisplayedPlane(newstation
? 0 : SZSP_NONE
);
1031 newst_additions
= this->GetWidget
<NWidgetStacked
>(WID_BRAS_SHOW_NEWST_MATRIX
);
1032 newst_additions
->SetDisplayedPlane(newstation
? 0 : SZSP_NONE
);
1033 newst_additions
= this->GetWidget
<NWidgetStacked
>(WID_BRAS_SHOW_NEWST_DEFSIZE
);
1034 newst_additions
->SetDisplayedPlane(newstation
? 0 : SZSP_NONE
);
1035 newst_additions
= this->GetWidget
<NWidgetStacked
>(WID_BRAS_SHOW_NEWST_RESIZE
);
1036 newst_additions
->SetDisplayedPlane(newstation
? 0 : SZSP_NONE
);
1038 this->vscroll
= this->GetScrollbar(WID_BRAS_NEWST_SCROLL
);
1039 this->vscroll2
= this->GetScrollbar(WID_BRAS_MATRIX_SCROLL
);
1041 this->InitNested(TRANSPORT_RAIL
);
1043 this->LowerWidget(_railstation
.orientation
+ WID_BRAS_PLATFORM_DIR_X
);
1044 if (_settings_client
.gui
.station_dragdrop
) {
1045 this->LowerWidget(WID_BRAS_PLATFORM_DRAG_N_DROP
);
1047 this->LowerWidget(_settings_client
.gui
.station_numtracks
+ WID_BRAS_PLATFORM_NUM_BEGIN
);
1048 this->LowerWidget(_settings_client
.gui
.station_platlength
+ WID_BRAS_PLATFORM_LEN_BEGIN
);
1050 this->SetWidgetLoweredState(WID_BRAS_HIGHLIGHT_OFF
, !_settings_client
.gui
.station_show_coverage
);
1051 this->SetWidgetLoweredState(WID_BRAS_HIGHLIGHT_ON
, _settings_client
.gui
.station_show_coverage
);
1053 if (!newstation
|| _railstation
.station_class
>= (int)StationClass::GetClassCount()) {
1054 /* New stations are not available or changed, so ensure the default station
1055 * type is 'selected'. */
1056 _railstation
.station_class
= STAT_CLASS_DFLT
;
1057 _railstation
.station_type
= 0;
1058 this->vscroll2
= NULL
;
1061 _railstation
.station_count
= StationClass::Get(_railstation
.station_class
)->GetSpecCount();
1062 _railstation
.station_type
= min(_railstation
.station_type
, _railstation
.station_count
- 1);
1065 for (uint i
= 0; i
< StationClass::GetClassCount(); i
++) {
1066 if (i
== STAT_CLASS_WAYP
) continue;
1069 this->vscroll
->SetCount(count
);
1070 this->vscroll
->SetPosition(Clamp(_railstation
.station_class
- 2, 0, max(this->vscroll
->GetCount() - this->vscroll
->GetCapacity(), 0)));
1072 NWidgetMatrix
*matrix
= this->GetWidget
<NWidgetMatrix
>(WID_BRAS_MATRIX
);
1073 matrix
->SetScrollbar(this->vscroll2
);
1074 matrix
->SetCount(_railstation
.station_count
);
1075 matrix
->SetClicked(_railstation
.station_type
);
1079 void OnDelete (void) FINAL_OVERRIDE
1081 DeleteWindowById(WC_SELECT_STATION
, 0);
1082 this->PickerWindowBase::OnDelete();
1085 void OnPaint (BlitArea
*dpi
) OVERRIDE
1087 bool newstations
= _railstation
.newstations
;
1088 const StationSpec
*statspec
= newstations
? StationClass::Get(_railstation
.station_class
)->GetSpec(_railstation
.station_type
) : NULL
;
1090 int rad
= (_settings_game
.station
.modified_catchment
) ? CA_TRAIN
: CA_UNMODIFIED
;
1092 if (_settings_client
.gui
.station_show_coverage
) SetTileSelectBigSize(-rad
, -rad
, 2 * rad
, 2 * rad
);
1094 for (uint bits
= 0; bits
< 7; bits
++) {
1095 bool disable
= bits
>= _settings_game
.station
.station_spread
;
1096 if (statspec
== NULL
) {
1097 this->SetWidgetDisabledState(bits
+ WID_BRAS_PLATFORM_NUM_1
, disable
);
1098 this->SetWidgetDisabledState(bits
+ WID_BRAS_PLATFORM_LEN_1
, disable
);
1100 this->SetWidgetDisabledState(bits
+ WID_BRAS_PLATFORM_NUM_1
, HasBit(statspec
->disallowed_platforms
, bits
) || disable
);
1101 this->SetWidgetDisabledState(bits
+ WID_BRAS_PLATFORM_LEN_1
, HasBit(statspec
->disallowed_lengths
, bits
) || disable
);
1105 this->DrawWidgets (dpi
);
1107 /* 'Accepts' and 'Supplies' texts. */
1108 NWidgetBase
*cov
= this->GetWidget
<NWidgetBase
>(WID_BRAS_COVERAGE_TEXTS
);
1109 int top
= cov
->pos_y
+ WD_PAR_VSEP_NORMAL
;
1110 int left
= cov
->pos_x
+ WD_FRAMERECT_LEFT
;
1111 int right
= cov
->pos_x
+ cov
->current_x
- WD_FRAMERECT_RIGHT
;
1112 int bottom
= cov
->pos_y
+ cov
->current_y
;
1113 top
= DrawStationCoverageAreaText (dpi
, left
, right
, top
, rad
);
1114 /* Resize background if the window is too small.
1115 * Never make the window smaller to avoid oscillating if the size change affects the acceptance.
1116 * (This is the case, if making the window bigger moves the mouse into the window.) */
1118 this->coverage_height
+= top
- bottom
;
1123 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
1126 case WID_BRAS_NEWST_LIST
: {
1127 Dimension d
= {0, 0};
1128 for (uint i
= 0; i
< StationClass::GetClassCount(); i
++) {
1129 if (i
== STAT_CLASS_WAYP
) continue;
1130 d
= maxdim(d
, GetStringBoundingBox(StationClass::Get((StationClassID
)i
)->name
));
1132 size
->width
= max(size
->width
, d
.width
+ padding
.width
);
1133 this->line_height
= FONT_HEIGHT_NORMAL
+ WD_MATRIX_TOP
+ WD_MATRIX_BOTTOM
;
1134 size
->height
= 5 * this->line_height
;
1135 resize
->height
= this->line_height
;
1139 case WID_BRAS_SHOW_NEWST_TYPE
: {
1140 if (!_railstation
.newstations
) {
1146 /* If newstations exist, compute the non-zero minimal size. */
1147 Dimension d
= {0, 0};
1148 StringID str
= this->GetWidget
<NWidgetCore
>(widget
)->widget_data
;
1149 for (StationClassID statclass
= STAT_CLASS_BEGIN
; statclass
< (StationClassID
)StationClass::GetClassCount(); statclass
++) {
1150 if (statclass
== STAT_CLASS_WAYP
) continue;
1151 StationClass
*stclass
= StationClass::Get(statclass
);
1152 for (uint16 j
= 0; j
< stclass
->GetSpecCount(); j
++) {
1153 const StationSpec
*statspec
= stclass
->GetSpec(j
);
1154 SetDParam(0, (statspec
!= NULL
&& statspec
->name
!= 0) ? statspec
->name
: STR_STATION_CLASS_DFLT
);
1155 d
= maxdim(d
, GetStringBoundingBox(str
));
1158 size
->width
= max(size
->width
, d
.width
+ padding
.width
);
1162 case WID_BRAS_PLATFORM_DIR_X
:
1163 case WID_BRAS_PLATFORM_DIR_Y
:
1164 case WID_BRAS_IMAGE
:
1165 size
->width
= ScaleGUITrad(64) + 2;
1166 size
->height
= ScaleGUITrad(58) + 2;
1169 case WID_BRAS_COVERAGE_TEXTS
:
1170 size
->height
= this->coverage_height
;
1173 case WID_BRAS_MATRIX
:
1180 void DrawWidget (BlitArea
*dpi
, const Rect
&r
, int widget
) const OVERRIDE
1182 int widn
= GB(widget
, 0, 16);
1184 case WID_BRAS_PLATFORM_DIR_X
:
1185 case WID_BRAS_PLATFORM_DIR_Y
:
1186 assert_compile (WID_BRAS_PLATFORM_DIR_X
== 0);
1187 assert_compile (WID_BRAS_PLATFORM_DIR_Y
== 1);
1188 DrawStationPreview (dpi
, r
, _railstation
.station_class
, _railstation
.station_type
, 2 + widn
, false);
1191 case WID_BRAS_NEWST_LIST
: {
1194 for (uint i
= 0; i
< StationClass::GetClassCount(); i
++) {
1195 if (i
== STAT_CLASS_WAYP
) continue;
1196 if (this->vscroll
->IsVisible(statclass
)) {
1197 DrawString (dpi
, r
.left
+ WD_MATRIX_LEFT
, r
.right
- WD_MATRIX_RIGHT
, row
* this->line_height
+ r
.top
+ WD_MATRIX_TOP
,
1198 StationClass::Get((StationClassID
)i
)->name
,
1199 (StationClassID
)i
== _railstation
.station_class
? TC_WHITE
: TC_BLACK
);
1207 case WID_BRAS_IMAGE
: {
1208 byte type
= GB(widget
, 16, 16);
1209 assert(type
< _railstation
.station_count
);
1210 DrawStationPreview (dpi
, r
, _railstation
.station_class
, type
, 2 + _railstation
.orientation
, true);
1216 virtual void OnResize()
1218 if (this->vscroll
!= NULL
) { // New stations available.
1219 this->vscroll
->SetCapacityFromWidget(this, WID_BRAS_NEWST_LIST
);
1223 virtual void SetStringParameters(int widget
) const
1225 if (widget
== WID_BRAS_SHOW_NEWST_TYPE
) {
1226 const StationSpec
*statspec
= StationClass::Get(_railstation
.station_class
)->GetSpec(_railstation
.station_type
);
1227 SetDParam(0, (statspec
!= NULL
&& statspec
->name
!= 0) ? statspec
->name
: STR_STATION_CLASS_DFLT
);
1231 virtual void OnClick(Point pt
, int widget
, int click_count
)
1234 CHANGED_NONE
, ///< Nothing changed.
1235 CHANGED_DIRTY
, ///< Play a sound and mark window dirty.
1236 CHANGED_RESET
, ///< The same, plus reset construction.
1237 } changed
= CHANGED_NONE
;
1239 switch (GB(widget
, 0, 16)) {
1240 case WID_BRAS_PLATFORM_DIR_X
:
1241 case WID_BRAS_PLATFORM_DIR_Y
:
1242 this->RaiseWidget(_railstation
.orientation
+ WID_BRAS_PLATFORM_DIR_X
);
1243 _railstation
.orientation
= (Axis
)(widget
- WID_BRAS_PLATFORM_DIR_X
);
1244 this->LowerWidget(_railstation
.orientation
+ WID_BRAS_PLATFORM_DIR_X
);
1245 changed
= CHANGED_RESET
;
1248 case WID_BRAS_PLATFORM_NUM_1
:
1249 case WID_BRAS_PLATFORM_NUM_2
:
1250 case WID_BRAS_PLATFORM_NUM_3
:
1251 case WID_BRAS_PLATFORM_NUM_4
:
1252 case WID_BRAS_PLATFORM_NUM_5
:
1253 case WID_BRAS_PLATFORM_NUM_6
:
1254 case WID_BRAS_PLATFORM_NUM_7
: {
1255 this->RaiseWidget(_settings_client
.gui
.station_numtracks
+ WID_BRAS_PLATFORM_NUM_BEGIN
);
1256 this->RaiseWidget(WID_BRAS_PLATFORM_DRAG_N_DROP
);
1258 _settings_client
.gui
.station_numtracks
= widget
- WID_BRAS_PLATFORM_NUM_BEGIN
;
1259 _settings_client
.gui
.station_dragdrop
= false;
1261 _settings_client
.gui
.station_dragdrop
= false;
1263 const StationSpec
*statspec
= _railstation
.newstations
? StationClass::Get(_railstation
.station_class
)->GetSpec(_railstation
.station_type
) : NULL
;
1264 if (statspec
!= NULL
) CheckPlatformLength (statspec
);
1266 this->LowerWidget(_settings_client
.gui
.station_numtracks
+ WID_BRAS_PLATFORM_NUM_BEGIN
);
1267 this->LowerWidget(_settings_client
.gui
.station_platlength
+ WID_BRAS_PLATFORM_LEN_BEGIN
);
1268 changed
= CHANGED_RESET
;
1272 case WID_BRAS_PLATFORM_LEN_1
:
1273 case WID_BRAS_PLATFORM_LEN_2
:
1274 case WID_BRAS_PLATFORM_LEN_3
:
1275 case WID_BRAS_PLATFORM_LEN_4
:
1276 case WID_BRAS_PLATFORM_LEN_5
:
1277 case WID_BRAS_PLATFORM_LEN_6
:
1278 case WID_BRAS_PLATFORM_LEN_7
: {
1279 this->RaiseWidget(_settings_client
.gui
.station_platlength
+ WID_BRAS_PLATFORM_LEN_BEGIN
);
1280 this->RaiseWidget(WID_BRAS_PLATFORM_DRAG_N_DROP
);
1282 _settings_client
.gui
.station_platlength
= widget
- WID_BRAS_PLATFORM_LEN_BEGIN
;
1283 _settings_client
.gui
.station_dragdrop
= false;
1285 _settings_client
.gui
.station_dragdrop
= false;
1287 const StationSpec
*statspec
= _railstation
.newstations
? StationClass::Get(_railstation
.station_class
)->GetSpec(_railstation
.station_type
) : NULL
;
1288 if (statspec
!= NULL
) CheckPlatformWidth (statspec
);
1290 this->LowerWidget(_settings_client
.gui
.station_numtracks
+ WID_BRAS_PLATFORM_NUM_BEGIN
);
1291 this->LowerWidget(_settings_client
.gui
.station_platlength
+ WID_BRAS_PLATFORM_LEN_BEGIN
);
1292 changed
= CHANGED_RESET
;
1296 case WID_BRAS_PLATFORM_DRAG_N_DROP
: {
1297 _settings_client
.gui
.station_dragdrop
^= true;
1299 this->ToggleWidgetLoweredState(WID_BRAS_PLATFORM_DRAG_N_DROP
);
1301 /* get the first allowed length/number of platforms */
1302 const StationSpec
*statspec
= _railstation
.newstations
? StationClass::Get(_railstation
.station_class
)->GetSpec(_railstation
.station_type
) : NULL
;
1303 if (statspec
!= NULL
) {
1304 CheckPlatformLength (statspec
);
1305 CheckPlatformWidth (statspec
);
1308 this->SetWidgetLoweredState(_settings_client
.gui
.station_numtracks
+ WID_BRAS_PLATFORM_NUM_BEGIN
, !_settings_client
.gui
.station_dragdrop
);
1309 this->SetWidgetLoweredState(_settings_client
.gui
.station_platlength
+ WID_BRAS_PLATFORM_LEN_BEGIN
, !_settings_client
.gui
.station_dragdrop
);
1310 changed
= CHANGED_RESET
;
1314 case WID_BRAS_HIGHLIGHT_OFF
:
1315 case WID_BRAS_HIGHLIGHT_ON
:
1316 _settings_client
.gui
.station_show_coverage
= (widget
!= WID_BRAS_HIGHLIGHT_OFF
);
1318 this->SetWidgetLoweredState(WID_BRAS_HIGHLIGHT_OFF
, !_settings_client
.gui
.station_show_coverage
);
1319 this->SetWidgetLoweredState(WID_BRAS_HIGHLIGHT_ON
, _settings_client
.gui
.station_show_coverage
);
1320 changed
= CHANGED_DIRTY
;
1323 case WID_BRAS_NEWST_LIST
: {
1324 int y
= this->vscroll
->GetScrolledRowFromWidget(pt
.y
, this, WID_BRAS_NEWST_LIST
, 0, this->line_height
);
1325 if (y
>= (int)StationClass::GetClassCount()) return;
1326 for (uint i
= 0; i
< StationClass::GetClassCount(); i
++) {
1327 if (i
== STAT_CLASS_WAYP
) continue;
1329 if (_railstation
.station_class
!= (StationClassID
)i
) {
1330 _railstation
.station_class
= (StationClassID
)i
;
1331 StationClass
*stclass
= StationClass::Get(_railstation
.station_class
);
1332 _railstation
.station_count
= stclass
->GetSpecCount();
1333 _railstation
.station_type
= min((int)_railstation
.station_type
, max(0, (int)_railstation
.station_count
- 1));
1335 this->CheckSelectedSize(stclass
->GetSpec(_railstation
.station_type
));
1337 NWidgetMatrix
*matrix
= this->GetWidget
<NWidgetMatrix
>(WID_BRAS_MATRIX
);
1338 matrix
->SetCount(_railstation
.station_count
);
1339 matrix
->SetClicked(_railstation
.station_type
);
1341 changed
= CHANGED_RESET
;
1349 case WID_BRAS_IMAGE
: {
1350 int y
= GB(widget
, 16, 16);
1351 if (y
>= _railstation
.station_count
) return;
1353 /* Check station availability callback */
1354 const StationSpec
*statspec
= StationClass::Get(_railstation
.station_class
)->GetSpec(y
);
1355 if (!IsStationAvailable(statspec
)) return;
1357 _railstation
.station_type
= y
;
1359 this->CheckSelectedSize(statspec
);
1360 this->GetWidget
<NWidgetMatrix
>(WID_BRAS_MATRIX
)->SetClicked(_railstation
.station_type
);
1362 changed
= CHANGED_RESET
;
1369 DeleteWindowById (WC_SELECT_STATION
, 0);
1370 SetStationTileSelectSize();
1373 if (_settings_client
.sound
.click_beep
) SndPlayFx(SND_15_BEEP
);
1380 virtual void OnTick()
1382 CheckRedrawStationCoverage(this);
1386 static const NWidgetPart _nested_station_builder_widgets
[] = {
1387 NWidget(NWID_HORIZONTAL
),
1388 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
1389 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
), SetDataTip(STR_STATION_BUILD_RAIL_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
1390 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_BRAS_SHOW_NEWST_DEFSIZE
),
1391 NWidget(WWT_DEFSIZEBOX
, COLOUR_DARK_GREEN
),
1394 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
),
1395 NWidget(NWID_HORIZONTAL
),
1396 NWidget(NWID_VERTICAL
),
1397 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_BRAS_SHOW_NEWST_ADDITIONS
),
1398 NWidget(NWID_HORIZONTAL
), SetPIP(7, 0, 7), SetPadding(2, 0, 1, 0),
1399 NWidget(WWT_MATRIX
, COLOUR_GREY
, WID_BRAS_NEWST_LIST
), SetMinimalSize(122, 71), SetFill(1, 0),
1400 SetMatrixDataTip(1, 0, STR_STATION_BUILD_STATION_CLASS_TOOLTIP
), SetScrollbar(WID_BRAS_NEWST_SCROLL
),
1401 NWidget(NWID_VSCROLLBAR
, COLOUR_GREY
, WID_BRAS_NEWST_SCROLL
),
1404 NWidget(WWT_LABEL
, COLOUR_DARK_GREEN
), SetMinimalSize(144, 11), SetDataTip(STR_STATION_BUILD_ORIENTATION
, STR_NULL
), SetPadding(1, 2, 0, 2),
1405 NWidget(NWID_HORIZONTAL
),
1406 NWidget(NWID_SPACER
), SetMinimalSize(7, 0), SetFill(1, 0),
1407 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(),
1408 NWidget(NWID_SPACER
), SetMinimalSize(2, 0), SetFill(1, 0),
1409 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(),
1410 NWidget(NWID_SPACER
), SetMinimalSize(7, 0), SetFill(1, 0),
1412 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),
1413 NWidget(WWT_LABEL
, COLOUR_DARK_GREEN
), SetMinimalSize(144, 11), SetDataTip(STR_STATION_BUILD_NUMBER_OF_TRACKS
, STR_NULL
), SetPadding(0, 2, 0, 2),
1414 NWidget(NWID_HORIZONTAL
),
1415 NWidget(NWID_SPACER
), SetFill(1, 0),
1416 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_NUM_1
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_1
, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP
),
1417 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_NUM_2
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_2
, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP
),
1418 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_NUM_3
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_3
, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP
),
1419 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_NUM_4
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_4
, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP
),
1420 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_NUM_5
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_5
, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP
),
1421 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_NUM_6
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_6
, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP
),
1422 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_NUM_7
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_7
, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP
),
1423 NWidget(NWID_SPACER
), SetFill(1, 0),
1425 NWidget(WWT_LABEL
, COLOUR_DARK_GREEN
), SetMinimalSize(144, 11), SetDataTip(STR_STATION_BUILD_PLATFORM_LENGTH
, STR_NULL
), SetPadding(2, 2, 0, 2),
1426 NWidget(NWID_HORIZONTAL
),
1427 NWidget(NWID_SPACER
), SetFill(1, 0),
1428 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_LEN_1
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_1
, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP
),
1429 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_LEN_2
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_2
, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP
),
1430 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_LEN_3
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_3
, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP
),
1431 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_LEN_4
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_4
, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP
),
1432 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_LEN_5
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_5
, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP
),
1433 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_LEN_6
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_6
, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP
),
1434 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_PLATFORM_LEN_7
), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_7
, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP
),
1435 NWidget(NWID_SPACER
), SetFill(1, 0),
1437 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
1438 NWidget(NWID_HORIZONTAL
),
1439 NWidget(NWID_SPACER
), SetMinimalSize(2, 0), SetFill(1, 0),
1440 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
),
1441 NWidget(NWID_SPACER
), SetMinimalSize(2, 0), SetFill(1, 0),
1443 NWidget(WWT_LABEL
, COLOUR_DARK_GREEN
), SetMinimalSize(144, 11), SetDataTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE
, STR_NULL
), SetPadding(3, 2, 0, 2),
1444 NWidget(NWID_HORIZONTAL
),
1445 NWidget(NWID_SPACER
), SetMinimalSize(2, 0), SetFill(1, 0),
1446 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_HIGHLIGHT_OFF
), SetMinimalSize(60, 12),
1447 SetDataTip(STR_STATION_BUILD_COVERAGE_OFF
, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP
),
1448 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BRAS_HIGHLIGHT_ON
), SetMinimalSize(60, 12),
1449 SetDataTip(STR_STATION_BUILD_COVERAGE_ON
, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP
),
1450 NWidget(NWID_SPACER
), SetMinimalSize(2, 0), SetFill(1, 0),
1453 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_BRAS_SHOW_NEWST_MATRIX
),
1454 /* We need an additional background for the matrix, as the matrix cannot handle the scrollbar due to not being an NWidgetCore. */
1455 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
), SetScrollbar(WID_BRAS_MATRIX_SCROLL
),
1456 NWidget(NWID_HORIZONTAL
),
1457 NWidget(NWID_MATRIX
, COLOUR_DARK_GREEN
, WID_BRAS_MATRIX
), SetScrollbar(WID_BRAS_MATRIX_SCROLL
), SetPIP(0, 2, 0), SetPadding(2, 0, 0, 0),
1458 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BRAS_IMAGE
), SetMinimalSize(66, 60),
1459 SetFill(0, 0), SetResize(0, 0), SetDataTip(0x0, STR_STATION_BUILD_STATION_TYPE_TOOLTIP
), SetScrollbar(WID_BRAS_MATRIX_SCROLL
),
1462 NWidget(NWID_VSCROLLBAR
, COLOUR_DARK_GREEN
, WID_BRAS_MATRIX_SCROLL
),
1467 NWidget(NWID_HORIZONTAL
),
1468 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_BRAS_COVERAGE_TEXTS
), SetFill(1, 1), SetResize(1, 0),
1469 NWidget(NWID_SELECTION
, INVALID_COLOUR
, WID_BRAS_SHOW_NEWST_RESIZE
),
1470 NWidget(NWID_VERTICAL
),
1471 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
), SetFill(0, 1), EndContainer(),
1472 NWidget(WWT_RESIZEBOX
, COLOUR_DARK_GREEN
),
1479 /** Window preferences of the station-build window (default & newGRF) */
1480 static WindowDesc::Prefs
_station_builder_prefs ("build_station_rail");
1482 /** High level window description of the station-build window (default & newGRF) */
1483 static const WindowDesc
_station_builder_desc(
1485 WC_BUILD_STATION
, WC_BUILD_TOOLBAR
,
1487 _nested_station_builder_widgets
, lengthof(_nested_station_builder_widgets
),
1488 &_station_builder_prefs
1491 /** Open station build window */
1492 static void ShowStationBuilder(Window
*parent
)
1494 bool newstations
= StationClass::GetClassCount() > 2 || StationClass::Get(STAT_CLASS_DFLT
)->GetSpecCount() != 1;
1495 new BuildRailStationWindow(&_station_builder_desc
, parent
, newstations
);
1498 struct BuildSignalWindow
: public PickerWindowBase
{
1500 Dimension sig_sprite_size
; ///< Maximum size of signal GUI sprites.
1501 int sig_sprite_bottom_offset
; ///< Maximum extent of signal GUI sprite from reference point towards bottom.
1504 * Draw dynamic a signal-sprite in a button in the signal GUI
1505 * Draw the sprite +1px to the right and down if the button is lowered
1507 * @param widget_index index of this widget in the window
1508 * @param image the sprite to draw
1510 void DrawSignalSprite (BlitArea
*dpi
, byte widget_index
, SpriteID image
) const
1513 Dimension sprite_size
= GetSpriteSize(image
, &offset
);
1514 const NWidgetBase
*widget
= this->GetWidget
<NWidgetBase
>(widget_index
);
1515 int x
= widget
->pos_x
- offset
.x
+
1516 (widget
->current_x
- sprite_size
.width
+ offset
.x
) / 2; // centered
1517 int y
= widget
->pos_y
- sig_sprite_bottom_offset
+ WD_IMGBTN_TOP
+
1518 (widget
->current_y
- WD_IMGBTN_TOP
- WD_IMGBTN_BOTTOM
+ sig_sprite_size
.height
) / 2; // aligned to bottom
1520 DrawSprite (dpi
, image
, PAL_NONE
,
1521 x
+ this->IsWidgetLowered(widget_index
),
1522 y
+ this->IsWidgetLowered(widget_index
));
1526 BuildSignalWindow (const WindowDesc
*desc
, Window
*parent
) :
1527 PickerWindowBase (desc
, parent
), sig_sprite_bottom_offset (0)
1529 this->sig_sprite_size
.width
= 0;
1530 this->sig_sprite_size
.height
= 0;
1532 this->InitNested(TRANSPORT_RAIL
);
1533 this->OnInvalidateData();
1536 void OnDelete (void) FINAL_OVERRIDE
1538 _convert_signal_button
= false;
1539 this->PickerWindowBase::OnDelete();
1542 virtual void OnInit()
1544 /* Calculate maximum signal sprite size. */
1545 this->sig_sprite_size
.width
= 0;
1546 this->sig_sprite_size
.height
= 0;
1547 this->sig_sprite_bottom_offset
= 0;
1548 const RailtypeInfo
*rti
= GetRailTypeInfo(_cur_railtype
);
1549 for (uint type
= SIGTYPE_NORMAL
; type
< SIGTYPE_END
; type
++) {
1550 for (uint variant
= SIG_ELECTRIC
; variant
<= SIG_SEMAPHORE
; variant
++) {
1551 for (uint lowered
= 0; lowered
< 2; lowered
++) {
1553 Dimension sprite_size
= GetSpriteSize(rti
->gui_sprites
.signals
[type
][variant
][lowered
], &offset
);
1554 this->sig_sprite_bottom_offset
= max
<int>(this->sig_sprite_bottom_offset
, sprite_size
.height
);
1555 this->sig_sprite_size
.width
= max
<int>(this->sig_sprite_size
.width
, sprite_size
.width
- offset
.x
);
1556 this->sig_sprite_size
.height
= max
<int>(this->sig_sprite_size
.height
, sprite_size
.height
- offset
.y
);
1562 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
1564 if (widget
== WID_BS_DRAG_SIGNALS_DENSITY_LABEL
) {
1565 /* Two digits for signals density. */
1566 size
->width
= max(size
->width
, 2 * GetDigitWidth() + padding
.width
+ WD_FRAMERECT_LEFT
+ WD_FRAMERECT_RIGHT
);
1567 } else if (IsInsideMM(widget
, WID_BS_SEMAPHORE_NORM
, WID_BS_ELECTRIC_PBS_OWAY
+ 1)) {
1568 size
->width
= max(size
->width
, this->sig_sprite_size
.width
+ WD_IMGBTN_LEFT
+ WD_IMGBTN_RIGHT
);
1569 size
->height
= max(size
->height
, this->sig_sprite_size
.height
+ WD_IMGBTN_TOP
+ WD_IMGBTN_BOTTOM
);
1573 virtual void SetStringParameters(int widget
) const
1576 case WID_BS_DRAG_SIGNALS_DENSITY_LABEL
:
1577 SetDParam(0, _settings_client
.gui
.drag_signals_density
);
1582 void DrawWidget (BlitArea
*dpi
, const Rect
&r
, int widget
) const OVERRIDE
1584 if (IsInsideMM(widget
, WID_BS_SEMAPHORE_NORM
, WID_BS_ELECTRIC_PBS_OWAY
+ 1)) {
1585 /* Extract signal from widget number. */
1586 int type
= (widget
- WID_BS_SEMAPHORE_NORM
) % SIGTYPE_END
;
1587 int var
= SIG_SEMAPHORE
- (widget
- WID_BS_SEMAPHORE_NORM
) / SIGTYPE_END
; // SignalVariant order is reversed compared to the widgets.
1588 SpriteID sprite
= GetRailTypeInfo(_cur_railtype
)->gui_sprites
.signals
[type
][var
][this->IsWidgetLowered(widget
)];
1590 this->DrawSignalSprite (dpi
, widget
, sprite
);
1594 virtual void OnClick(Point pt
, int widget
, int click_count
)
1597 case WID_BS_SEMAPHORE_NORM
:
1598 case WID_BS_SEMAPHORE_ENTRY
:
1599 case WID_BS_SEMAPHORE_EXIT
:
1600 case WID_BS_SEMAPHORE_COMBO
:
1601 case WID_BS_SEMAPHORE_PBS
:
1602 case WID_BS_SEMAPHORE_PBS_OWAY
:
1603 case WID_BS_ELECTRIC_NORM
:
1604 case WID_BS_ELECTRIC_ENTRY
:
1605 case WID_BS_ELECTRIC_EXIT
:
1606 case WID_BS_ELECTRIC_COMBO
:
1607 case WID_BS_ELECTRIC_PBS
:
1608 case WID_BS_ELECTRIC_PBS_OWAY
:
1609 this->RaiseWidget((_cur_signal_variant
== SIG_ELECTRIC
? WID_BS_ELECTRIC_NORM
: WID_BS_SEMAPHORE_NORM
) + _cur_signal_type
);
1611 _cur_signal_type
= (SignalType
)((uint
)((widget
- WID_BS_SEMAPHORE_NORM
) % SIGTYPE_END
));
1612 _cur_signal_variant
= widget
>= WID_BS_ELECTRIC_NORM
? SIG_ELECTRIC
: SIG_SEMAPHORE
;
1614 /* If 'remove' button of rail build toolbar is active, disable it. */
1615 if (_remove_button_clicked
) {
1616 Window
*w
= FindWindowById(WC_BUILD_TOOLBAR
, TRANSPORT_RAIL
);
1617 if (w
!= NULL
) ToggleRailButton_Remove(w
);
1622 case WID_BS_CONVERT
:
1623 _convert_signal_button
= !_convert_signal_button
;
1626 case WID_BS_DRAG_SIGNALS_DENSITY_DECREASE
:
1627 if (_settings_client
.gui
.drag_signals_density
> 1) {
1628 _settings_client
.gui
.drag_signals_density
--;
1629 SetWindowDirty(WC_GAME_OPTIONS
, WN_GAME_OPTIONS_GAME_SETTINGS
);
1633 case WID_BS_DRAG_SIGNALS_DENSITY_INCREASE
:
1634 if (_settings_client
.gui
.drag_signals_density
< 20) {
1635 _settings_client
.gui
.drag_signals_density
++;
1636 SetWindowDirty(WC_GAME_OPTIONS
, WN_GAME_OPTIONS_GAME_SETTINGS
);
1643 this->InvalidateData();
1647 * Some data on this window has become invalid.
1648 * @param data Information about the changed data.
1649 * @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.
1651 virtual void OnInvalidateData(int data
= 0, bool gui_scope
= true)
1653 if (!gui_scope
) return;
1654 this->LowerWidget((_cur_signal_variant
== SIG_ELECTRIC
? WID_BS_ELECTRIC_NORM
: WID_BS_SEMAPHORE_NORM
) + _cur_signal_type
);
1656 this->SetWidgetLoweredState(WID_BS_CONVERT
, _convert_signal_button
);
1658 this->SetWidgetDisabledState(WID_BS_DRAG_SIGNALS_DENSITY_DECREASE
, _settings_client
.gui
.drag_signals_density
== 1);
1659 this->SetWidgetDisabledState(WID_BS_DRAG_SIGNALS_DENSITY_INCREASE
, _settings_client
.gui
.drag_signals_density
== 20);
1663 /** Nested widget definition of the build signal window */
1664 static const NWidgetPart _nested_signal_builder_widgets
[] = {
1665 NWidget(NWID_HORIZONTAL
),
1666 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
1667 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
), SetDataTip(STR_BUILD_SIGNAL_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
1669 NWidget(NWID_VERTICAL
, NC_EQUALSIZE
),
1670 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
1671 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_SEMAPHORE_NORM
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_SEMAPHORE_NORM_TOOLTIP
), EndContainer(), SetFill(1, 1),
1672 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_SEMAPHORE_ENTRY
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_SEMAPHORE_ENTRY_TOOLTIP
), EndContainer(), SetFill(1, 1),
1673 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_SEMAPHORE_EXIT
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_SEMAPHORE_EXIT_TOOLTIP
), EndContainer(), SetFill(1, 1),
1674 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_SEMAPHORE_COMBO
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_SEMAPHORE_COMBO_TOOLTIP
), EndContainer(), SetFill(1, 1),
1675 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_SEMAPHORE_PBS
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_SEMAPHORE_PBS_TOOLTIP
), EndContainer(), SetFill(1, 1),
1676 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),
1677 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_BS_CONVERT
), SetDataTip(SPR_IMG_SIGNAL_CONVERT
, STR_BUILD_SIGNAL_CONVERT_TOOLTIP
), SetFill(1, 1),
1679 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
),
1680 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_ELECTRIC_NORM
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_ELECTRIC_NORM_TOOLTIP
), EndContainer(), SetFill(1, 1),
1681 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_ELECTRIC_ENTRY
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_ELECTRIC_ENTRY_TOOLTIP
), EndContainer(), SetFill(1, 1),
1682 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_ELECTRIC_EXIT
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_ELECTRIC_EXIT_TOOLTIP
), EndContainer(), SetFill(1, 1),
1683 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_ELECTRIC_COMBO
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_ELECTRIC_COMBO_TOOLTIP
), EndContainer(), SetFill(1, 1),
1684 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BS_ELECTRIC_PBS
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_ELECTRIC_PBS_TOOLTIP
), EndContainer(), SetFill(1, 1),
1685 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),
1686 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
), SetDataTip(STR_NULL
, STR_BUILD_SIGNAL_DRAG_SIGNALS_DENSITY_TOOLTIP
), SetFill(1, 1),
1687 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),
1688 NWidget(NWID_HORIZONTAL
), SetPIP(2, 0, 2),
1689 NWidget(NWID_SPACER
), SetFill(1, 0),
1690 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
),
1691 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
),
1692 NWidget(NWID_SPACER
), SetFill(1, 0),
1694 NWidget(NWID_SPACER
), SetMinimalSize(0, 2), SetFill(1, 0),
1700 /** Signal selection window preferences */
1701 static WindowDesc::Prefs
_signal_builder_prefs ("build_signal");
1703 /** Signal selection window description */
1704 static const WindowDesc
_signal_builder_desc(
1706 WC_BUILD_SIGNAL
, WC_BUILD_TOOLBAR
,
1708 _nested_signal_builder_widgets
, lengthof(_nested_signal_builder_widgets
),
1709 &_signal_builder_prefs
1713 * Open the signal selection window
1715 static void ShowSignalBuilder(Window
*parent
)
1717 new BuildSignalWindow(&_signal_builder_desc
, parent
);
1720 struct BuildRailDepotWindow
: public PickerWindowBase
{
1721 BuildRailDepotWindow (const WindowDesc
*desc
, Window
*parent
) : PickerWindowBase(desc
, parent
)
1723 this->InitNested(TRANSPORT_RAIL
);
1724 this->LowerWidget(_build_depot_direction
+ WID_BRAD_DEPOT_NE
);
1727 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
1729 if (!IsInsideMM(widget
, WID_BRAD_DEPOT_NE
, WID_BRAD_DEPOT_NW
+ 1)) return;
1731 size
->width
= ScaleGUITrad(64) + 2;
1732 size
->height
= ScaleGUITrad(48) + 2;
1735 void DrawWidget (BlitArea
*dpi
, const Rect
&r
, int widget
) const OVERRIDE
1737 if (!IsInsideMM(widget
, WID_BRAD_DEPOT_NE
, WID_BRAD_DEPOT_NW
+ 1)) return;
1739 DrawTrainDepotSprite (dpi
, r
.left
+ 1 + ScaleGUITrad(31), r
.bottom
- ScaleGUITrad(31), widget
- WID_BRAD_DEPOT_NE
+ DIAGDIR_NE
, _cur_railtype
);
1742 virtual void OnClick(Point pt
, int widget
, int click_count
)
1745 case WID_BRAD_DEPOT_NE
:
1746 case WID_BRAD_DEPOT_SE
:
1747 case WID_BRAD_DEPOT_SW
:
1748 case WID_BRAD_DEPOT_NW
:
1749 this->RaiseWidget(_build_depot_direction
+ WID_BRAD_DEPOT_NE
);
1750 _build_depot_direction
= (DiagDirection
)(widget
- WID_BRAD_DEPOT_NE
);
1751 this->LowerWidget(_build_depot_direction
+ WID_BRAD_DEPOT_NE
);
1752 if (_settings_client
.sound
.click_beep
) SndPlayFx(SND_15_BEEP
);
1759 /** Nested widget definition of the build rail depot window */
1760 static const NWidgetPart _nested_build_depot_widgets
[] = {
1761 NWidget(NWID_HORIZONTAL
),
1762 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
1763 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
), SetDataTip(STR_BUILD_DEPOT_TRAIN_ORIENTATION_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
1765 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
),
1766 NWidget(NWID_SPACER
), SetMinimalSize(0, 3),
1767 NWidget(NWID_HORIZONTAL_LTR
),
1768 NWidget(NWID_SPACER
), SetMinimalSize(3, 0), SetFill(1, 0),
1769 NWidget(NWID_VERTICAL
),
1770 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BRAD_DEPOT_NW
), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_TRAIN_ORIENTATION_TOOLTIP
),
1772 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
1773 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BRAD_DEPOT_SW
), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_TRAIN_ORIENTATION_TOOLTIP
),
1776 NWidget(NWID_SPACER
), SetMinimalSize(2, 0),
1777 NWidget(NWID_VERTICAL
),
1778 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BRAD_DEPOT_NE
), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_TRAIN_ORIENTATION_TOOLTIP
),
1780 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
1781 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BRAD_DEPOT_SE
), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_TRAIN_ORIENTATION_TOOLTIP
),
1784 NWidget(NWID_SPACER
), SetMinimalSize(3, 0), SetFill(1, 0),
1786 NWidget(NWID_SPACER
), SetMinimalSize(0, 3),
1790 static const WindowDesc
_build_depot_desc(
1792 WC_BUILD_DEPOT
, WC_BUILD_TOOLBAR
,
1794 _nested_build_depot_widgets
, lengthof(_nested_build_depot_widgets
)
1797 static void ShowBuildTrainDepotPicker(Window
*parent
)
1799 new BuildRailDepotWindow(&_build_depot_desc
, parent
);
1802 struct BuildRailWaypointWindow
: PickerWindowBase
{
1803 BuildRailWaypointWindow (const WindowDesc
*desc
, Window
*parent
) : PickerWindowBase(desc
, parent
)
1805 this->CreateNestedTree();
1807 NWidgetMatrix
*matrix
= this->GetWidget
<NWidgetMatrix
>(WID_BRW_WAYPOINT_MATRIX
);
1808 matrix
->SetScrollbar(this->GetScrollbar(WID_BRW_SCROLL
));
1810 this->InitNested(TRANSPORT_RAIL
);
1812 matrix
->SetCount(_waypoint_count
);
1813 matrix
->SetClicked(_cur_waypoint_type
);
1816 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
1819 case WID_BRW_WAYPOINT_MATRIX
:
1820 /* Three blobs high and wide. */
1821 size
->width
+= resize
->width
* 2;
1822 size
->height
+= resize
->height
* 2;
1824 /* Resizing in X direction only at blob size, but at pixel level in Y. */
1828 case WID_BRW_WAYPOINT
:
1829 size
->width
= ScaleGUITrad(64) + 2;
1830 size
->height
= ScaleGUITrad(58) + 2;
1835 void DrawWidget (BlitArea
*dpi
, const Rect
&r
, int widget
) const OVERRIDE
1837 switch (GB(widget
, 0, 16)) {
1838 case WID_BRW_WAYPOINT
: {
1839 byte type
= GB(widget
, 16, 16);
1840 DrawStationPreview (dpi
, r
, STAT_CLASS_WAYP
, type
, AXIS_X
, true);
1846 virtual void OnClick(Point pt
, int widget
, int click_count
)
1848 switch (GB(widget
, 0, 16)) {
1849 case WID_BRW_WAYPOINT
: {
1850 byte type
= GB(widget
, 16, 16);
1851 this->GetWidget
<NWidgetMatrix
>(WID_BRW_WAYPOINT_MATRIX
)->SetClicked(_cur_waypoint_type
);
1853 /* Check station availability callback */
1854 const StationSpec
*statspec
= StationClass::Get(STAT_CLASS_WAYP
)->GetSpec(type
);
1855 if (!IsStationAvailable(statspec
)) return;
1857 _cur_waypoint_type
= type
;
1858 this->GetWidget
<NWidgetMatrix
>(WID_BRW_WAYPOINT_MATRIX
)->SetClicked(_cur_waypoint_type
);
1859 if (_settings_client
.sound
.click_beep
) SndPlayFx(SND_15_BEEP
);
1867 /** Nested widget definition for the build NewGRF rail waypoint window */
1868 static const NWidgetPart _nested_build_waypoint_widgets
[] = {
1869 NWidget(NWID_HORIZONTAL
),
1870 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
1871 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
), SetDataTip(STR_WAYPOINT_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
1872 NWidget(WWT_DEFSIZEBOX
, COLOUR_DARK_GREEN
),
1874 NWidget(NWID_HORIZONTAL
),
1875 NWidget(NWID_MATRIX
, COLOUR_DARK_GREEN
, WID_BRW_WAYPOINT_MATRIX
), SetPIP(3, 2, 3), SetScrollbar(WID_BRW_SCROLL
),
1876 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BRW_WAYPOINT
), SetMinimalSize(66, 60), SetDataTip(0x0, STR_WAYPOINT_GRAPHICS_TOOLTIP
), SetScrollbar(WID_BRW_SCROLL
), EndContainer(),
1878 NWidget(NWID_VERTICAL
),
1879 NWidget(NWID_VSCROLLBAR
, COLOUR_DARK_GREEN
, WID_BRW_SCROLL
),
1880 NWidget(WWT_RESIZEBOX
, COLOUR_DARK_GREEN
),
1885 static WindowDesc::Prefs
_build_waypoint_prefs ("build_waypoint");
1887 static const WindowDesc
_build_waypoint_desc(
1889 WC_BUILD_WAYPOINT
, WC_BUILD_TOOLBAR
,
1891 _nested_build_waypoint_widgets
, lengthof(_nested_build_waypoint_widgets
),
1892 &_build_waypoint_prefs
1895 static void ShowBuildWaypointPicker(Window
*parent
)
1897 new BuildRailWaypointWindow(&_build_waypoint_desc
, parent
);
1901 * Initialize rail building GUI settings
1903 void InitializeRailGui()
1905 _build_depot_direction
= DIAGDIR_NW
;
1909 * Re-initialize rail-build toolbar after toggling support for electric trains
1910 * @param disable Boolean whether electric trains are disabled (removed from the game)
1912 void ReinitGuiAfterToggleElrail(bool disable
)
1914 extern RailType _last_built_railtype
;
1915 if (disable
&& _last_built_railtype
== RAILTYPE_ELECTRIC
) {
1916 _last_built_railtype
= _cur_railtype
= RAILTYPE_RAIL
;
1917 BuildRailToolbarWindow
*w
= dynamic_cast<BuildRailToolbarWindow
*>(FindWindowById(WC_BUILD_TOOLBAR
, TRANSPORT_RAIL
));
1918 if (w
!= NULL
) w
->ModifyRailType(_cur_railtype
);
1920 MarkWholeScreenDirty();
1923 /** Set the initial (default) railtype to use */
1924 static void SetDefaultRailGui()
1926 if (_local_company
== COMPANY_SPECTATOR
|| !Company::IsValidID(_local_company
)) return;
1928 extern RailType _last_built_railtype
;
1929 RailType rt
= (RailType
)(_settings_client
.gui
.default_rail_type
+ RAILTYPE_END
);
1930 if (rt
== DEF_RAILTYPE_MOST_USED
) {
1931 /* Find the most used rail type */
1932 RailType count
[RAILTYPE_END
];
1933 memset(count
, 0, sizeof(count
));
1934 for (TileIndex t
= 0; t
< MapSize(); t
++) {
1935 if (IsRailwayTile(t
) || IsRailDepotTile(t
) || IsLevelCrossingTile(t
) || HasStationTileRail(t
) ||
1936 maptile_is_rail_tunnel(t
)) {
1937 count
[GetRailType(t
)]++;
1942 for (RailType r
= RAILTYPE_ELECTRIC
; r
< RAILTYPE_END
; r
++) {
1943 if (count
[r
] >= count
[rt
]) rt
= r
;
1946 /* No rail, just get the first available one */
1947 if (count
[rt
] == 0) rt
= DEF_RAILTYPE_FIRST
;
1950 case DEF_RAILTYPE_FIRST
:
1952 while (rt
< RAILTYPE_END
&& !HasRailtypeAvail(_local_company
, rt
)) rt
++;
1955 case DEF_RAILTYPE_LAST
:
1956 rt
= GetBestRailtype(_local_company
);
1963 _last_built_railtype
= _cur_railtype
= rt
;
1964 BuildRailToolbarWindow
*w
= dynamic_cast<BuildRailToolbarWindow
*>(FindWindowById(WC_BUILD_TOOLBAR
, TRANSPORT_RAIL
));
1965 if (w
!= NULL
) w
->ModifyRailType(_cur_railtype
);
1969 * Updates the current signal variant used in the signal GUI
1970 * to the one adequate to current year.
1971 * @param p needed to be called when a setting changes
1972 * @return success, needed for settings
1974 bool ResetSignalVariant(int32 p
)
1976 SignalVariant new_variant
= (_cur_year
< _settings_client
.gui
.semaphore_build_before
? SIG_SEMAPHORE
: SIG_ELECTRIC
);
1978 if (new_variant
!= _cur_signal_variant
) {
1979 Window
*w
= FindWindowById(WC_BUILD_SIGNAL
, 0);
1982 w
->RaiseWidget((_cur_signal_variant
== SIG_ELECTRIC
? WID_BS_ELECTRIC_NORM
: WID_BS_SEMAPHORE_NORM
) + _cur_signal_type
);
1984 _cur_signal_variant
= new_variant
;
1991 * Resets the rail GUI - sets default railtype to build
1992 * and resets the signal GUI
1994 void InitializeRailGUI()
1996 SetDefaultRailGui();
1998 _convert_signal_button
= false;
1999 _cur_signal_type
= _default_signal_type
[_settings_client
.gui
.default_signal_type
];
2000 ResetSignalVariant();
2004 * Create a drop down list for all the rail types of the local company.
2005 * @param for_replacement Whether this list is for the replacement window.
2006 * @param all_option Whether to add an 'all types' item.
2007 * @return The populated and sorted #DropDownList.
2009 DropDownList
*GetRailTypeDropDownList(bool for_replacement
, bool all_option
)
2011 RailTypes used_railtypes
= RAILTYPES_NONE
;
2013 /* Find the used railtypes. */
2015 FOR_ALL_ENGINES_OF_TYPE(e
, VEH_TRAIN
) {
2016 if (!HasBit(e
->info
.climates
, _settings_game
.game_creation
.landscape
)) continue;
2018 used_railtypes
|= GetRailTypeInfo(e
->u
.rail
.railtype
)->introduces_railtypes
;
2021 /* Get the date introduced railtypes as well. */
2022 used_railtypes
= AddDateIntroducedRailTypes(used_railtypes
, MAX_DAY
);
2024 const Company
*c
= Company::Get(_local_company
);
2025 DropDownList
*list
= new DropDownList();
2028 DropDownListStringItem
*item
= new DropDownListStringItem(STR_REPLACE_ALL_RAILTYPE
, INVALID_RAILTYPE
, false);
2029 *list
->Append() = item
;
2033 FOR_ALL_SORTED_RAILTYPES(rt
) {
2034 /* If it's not used ever, don't show it to the user. */
2035 if (!HasBit(used_railtypes
, rt
)) continue;
2037 const RailtypeInfo
*rti
= GetRailTypeInfo(rt
);
2039 StringID str
= for_replacement
? rti
->strings
.replace_text
: (rti
->max_speed
> 0 ? STR_TOOLBAR_RAILTYPE_VELOCITY
: STR_JUST_STRING
);
2040 DropDownListParamStringItem
*item
= new DropDownListParamStringItem(str
, rt
, !HasBit(c
->avail_railtypes
, rt
));
2041 item
->SetParam(0, rti
->strings
.menu_text
);
2042 item
->SetParam(1, rti
->max_speed
);
2043 *list
->Append() = item
;