74 } |
74 } |
75 |
75 |
76 static void GenericPlaceRail(TileIndex tile, int cmd) |
76 static void GenericPlaceRail(TileIndex tile, int cmd) |
77 { |
77 { |
78 DoCommandP(tile, _cur_railtype, cmd, CcPlaySound1E, |
78 DoCommandP(tile, _cur_railtype, cmd, CcPlaySound1E, |
79 (_remove_button_clicked || _ctrl_pressed) ? |
79 _remove_button_clicked ? |
80 CMD_REMOVE_SINGLE_RAIL | CMD_MSG(STR_1012_CAN_T_REMOVE_RAILROAD_TRACK) | CMD_NO_WATER : |
80 CMD_REMOVE_SINGLE_RAIL | CMD_MSG(STR_1012_CAN_T_REMOVE_RAILROAD_TRACK) | CMD_NO_WATER : |
81 CMD_BUILD_SINGLE_RAIL | CMD_MSG(STR_1011_CAN_T_BUILD_RAILROAD_TRACK) | CMD_NO_WATER |
81 CMD_BUILD_SINGLE_RAIL | CMD_MSG(STR_1011_CAN_T_BUILD_RAILROAD_TRACK) | CMD_NO_WATER |
82 ); |
82 ); |
83 } |
83 } |
84 |
84 |
148 CMD_BUILD_TRAIN_DEPOT | CMD_NO_WATER | CMD_MSG(STR_100E_CAN_T_BUILD_TRAIN_DEPOT)); |
148 CMD_BUILD_TRAIN_DEPOT | CMD_NO_WATER | CMD_MSG(STR_100E_CAN_T_BUILD_TRAIN_DEPOT)); |
149 } |
149 } |
150 |
150 |
151 static void PlaceRail_Waypoint(TileIndex tile) |
151 static void PlaceRail_Waypoint(TileIndex tile) |
152 { |
152 { |
153 if (_remove_button_clicked || _ctrl_pressed) { |
153 if (_remove_button_clicked) { |
154 DoCommandP(tile, 0, 0, CcPlaySound1E, CMD_REMOVE_TRAIN_WAYPOINT | CMD_MSG(STR_CANT_REMOVE_TRAIN_WAYPOINT)); |
154 DoCommandP(tile, 0, 0, CcPlaySound1E, CMD_REMOVE_TRAIN_WAYPOINT | CMD_MSG(STR_CANT_REMOVE_TRAIN_WAYPOINT)); |
155 } else { |
155 } else { |
156 DoCommandP(tile, _cur_waypoint_type, 0, CcPlaySound1E, CMD_BUILD_TRAIN_WAYPOINT | CMD_MSG(STR_CANT_BUILD_TRAIN_WAYPOINT)); |
156 DoCommandP(tile, _cur_waypoint_type, 0, CcPlaySound1E, CMD_BUILD_TRAIN_WAYPOINT | CMD_MSG(STR_CANT_BUILD_TRAIN_WAYPOINT)); |
157 } |
157 } |
158 } |
158 } |
167 } |
167 } |
168 |
168 |
169 static void PlaceRail_Station(TileIndex tile) |
169 static void PlaceRail_Station(TileIndex tile) |
170 { |
170 { |
171 if (_remove_button_clicked) { |
171 if (_remove_button_clicked) { |
172 VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_REMOVE_STATION); |
172 VpStartPlaceSizing(tile, VPM_X_AND_Y_LIMITED, DDSP_REMOVE_STATION); |
|
173 VpSetPlaceSizingLimit(-1); |
173 } else if (_railstation.dragdrop) { |
174 } else if (_railstation.dragdrop) { |
174 VpStartPlaceSizing(tile, VPM_X_AND_Y_LIMITED, DDSP_BUILD_STATION); |
175 VpStartPlaceSizing(tile, VPM_X_AND_Y_LIMITED, DDSP_BUILD_STATION); |
175 VpSetPlaceSizingLimit(_patches.station_spread); |
176 VpSetPlaceSizingLimit(_patches.station_spread); |
176 } else { |
177 } else { |
177 DoCommandP(tile, |
178 DoCommandP(tile, |
186 * |
187 * |
187 * @param tile The tile where the signal will build or edit |
188 * @param tile The tile where the signal will build or edit |
188 */ |
189 */ |
189 static void GenericPlaceSignals(TileIndex tile) |
190 static void GenericPlaceSignals(TileIndex tile) |
190 { |
191 { |
191 TrackBits trackbits = (TrackBits)GB(GetTileTrackStatus(tile, TRANSPORT_RAIL, 0), 0, 6); |
192 TrackBits trackbits = TrackStatusToTrackBits(GetTileTrackStatus(tile, TRANSPORT_RAIL, 0)); |
192 |
193 |
193 if (trackbits & TRACK_BIT_VERT) { // N-S direction |
194 if (trackbits & TRACK_BIT_VERT) { // N-S direction |
194 trackbits = (_tile_fract_coords.x <= _tile_fract_coords.y) ? TRACK_BIT_RIGHT : TRACK_BIT_LEFT; |
195 trackbits = (_tile_fract_coords.x <= _tile_fract_coords.y) ? TRACK_BIT_RIGHT : TRACK_BIT_LEFT; |
195 } |
196 } |
196 |
197 |
275 RTW_BUILD_TUNNEL, |
276 RTW_BUILD_TUNNEL, |
276 RTW_REMOVE, |
277 RTW_REMOVE, |
277 RTW_CONVERT_RAIL, |
278 RTW_CONVERT_RAIL, |
278 }; |
279 }; |
279 |
280 |
|
281 |
|
282 /** Toogles state of the Remove button of Build rail toolbar |
|
283 * @param w window the button belongs to |
|
284 */ |
|
285 static void ToggleRailButton_Remove(Window *w) |
|
286 { |
|
287 w->ToggleWidgetLoweredState(RTW_REMOVE); |
|
288 w->InvalidateWidget(RTW_REMOVE); |
|
289 _remove_button_clicked = w->IsWidgetLowered(RTW_REMOVE); |
|
290 SetSelectionRed(_remove_button_clicked); |
|
291 } |
|
292 |
|
293 /** Updates the Remove button because of Ctrl state change |
|
294 * @param w window the button belongs to |
|
295 * @return true iff the remove buton was changed |
|
296 */ |
|
297 static bool RailToolbar_CtrlChanged(Window *w) |
|
298 { |
|
299 if (w->IsWidgetDisabled(RTW_REMOVE)) return false; |
|
300 |
|
301 /* allow ctrl to switch remove mode only for these widgets */ |
|
302 for (uint i = RTW_BUILD_NS; i <= RTW_BUILD_STATION; i++) { |
|
303 if ((i <= RTW_AUTORAIL || i >= RTW_BUILD_WAYPOINT) && w->IsWidgetLowered(i)) { |
|
304 ToggleRailButton_Remove(w); |
|
305 return true; |
|
306 } |
|
307 } |
|
308 |
|
309 return false; |
|
310 } |
|
311 |
|
312 |
280 static void BuildRailClick_N(Window *w) |
313 static void BuildRailClick_N(Window *w) |
281 { |
314 { |
282 HandlePlacePushButton(w, RTW_BUILD_NS, GetRailTypeInfo(_cur_railtype)->cursor.rail_ns, VHM_RECT, PlaceRail_N); |
315 HandlePlacePushButton(w, RTW_BUILD_NS, GetRailTypeInfo(_cur_railtype)->cursor.rail_ns, VHM_RECT, PlaceRail_N); |
283 } |
316 } |
284 |
317 |
349 } |
382 } |
350 |
383 |
351 static void BuildRailClick_Remove(Window *w) |
384 static void BuildRailClick_Remove(Window *w) |
352 { |
385 { |
353 if (w->IsWidgetDisabled(RTW_REMOVE)) return; |
386 if (w->IsWidgetDisabled(RTW_REMOVE)) return; |
354 SetWindowDirty(w); |
387 ToggleRailButton_Remove(w); |
355 SndPlayFx(SND_15_BEEP); |
388 SndPlayFx(SND_15_BEEP); |
356 |
389 |
357 w->ToggleWidgetLoweredState(RTW_REMOVE); |
390 /* handle station builder */ |
358 _remove_button_clicked = w->IsWidgetLowered(RTW_REMOVE); |
391 if (w->IsWidgetLowered(RTW_BUILD_STATION)) { |
359 SetSelectionRed(_remove_button_clicked); |
392 if (_remove_button_clicked) { |
360 |
393 /* starting drag & drop remove */ |
361 // handle station builder |
394 if (!_railstation.dragdrop) { |
362 if (_remove_button_clicked) { |
395 SetTileSelectSize(1, 1); |
363 SetTileSelectSize(1, 1); |
396 } else { |
|
397 VpSetPlaceSizingLimit(-1); |
|
398 } |
|
399 } else { |
|
400 /* starting station build mode */ |
|
401 if (!_railstation.dragdrop) { |
|
402 int x = _railstation.numtracks; |
|
403 int y = _railstation.platlength; |
|
404 if (_railstation.orientation == 0) Swap(x, y); |
|
405 SetTileSelectSize(x, y); |
|
406 } else { |
|
407 VpSetPlaceSizingLimit(_patches.station_spread); |
|
408 } |
|
409 } |
364 } |
410 } |
365 } |
411 } |
366 |
412 |
367 static void BuildRailClick_Convert(Window *w) |
413 static void BuildRailClick_Convert(Window *w) |
368 { |
414 { |
371 |
417 |
372 |
418 |
373 static void DoRailroadTrack(int mode) |
419 static void DoRailroadTrack(int mode) |
374 { |
420 { |
375 DoCommandP(TileVirtXY(_thd.selstart.x, _thd.selstart.y), TileVirtXY(_thd.selend.x, _thd.selend.y), _cur_railtype | (mode << 4), NULL, |
421 DoCommandP(TileVirtXY(_thd.selstart.x, _thd.selstart.y), TileVirtXY(_thd.selend.x, _thd.selend.y), _cur_railtype | (mode << 4), NULL, |
376 (_remove_button_clicked || _ctrl_pressed) ? |
422 _remove_button_clicked ? |
377 CMD_REMOVE_RAILROAD_TRACK | CMD_NO_WATER | CMD_MSG(STR_1012_CAN_T_REMOVE_RAILROAD_TRACK) : |
423 CMD_REMOVE_RAILROAD_TRACK | CMD_NO_WATER | CMD_MSG(STR_1012_CAN_T_REMOVE_RAILROAD_TRACK) : |
378 CMD_BUILD_RAILROAD_TRACK | CMD_NO_WATER | CMD_MSG(STR_1011_CAN_T_BUILD_RAILROAD_TRACK) |
424 CMD_BUILD_RAILROAD_TRACK | CMD_NO_WATER | CMD_MSG(STR_1011_CAN_T_BUILD_RAILROAD_TRACK) |
379 ); |
425 ); |
380 } |
426 } |
381 |
427 |
512 if (e->we.click.widget >= RTW_BUILD_NS) { |
558 if (e->we.click.widget >= RTW_BUILD_NS) { |
513 _remove_button_clicked = false; |
559 _remove_button_clicked = false; |
514 _build_railroad_button_proc[e->we.click.widget - RTW_BUILD_NS](w); |
560 _build_railroad_button_proc[e->we.click.widget - RTW_BUILD_NS](w); |
515 } |
561 } |
516 UpdateRemoveWidgetStatus(w, e->we.click.widget); |
562 UpdateRemoveWidgetStatus(w, e->we.click.widget); |
|
563 if (_ctrl_pressed) RailToolbar_CtrlChanged(w); |
517 break; |
564 break; |
518 |
565 |
519 case WE_KEYPRESS: |
566 case WE_KEYPRESS: |
520 for (uint8 i = 0; i != lengthof(_rail_keycodes); i++) { |
567 for (uint8 i = 0; i != lengthof(_rail_keycodes); i++) { |
521 if (e->we.keypress.keycode == _rail_keycodes[i]) { |
568 if (e->we.keypress.keycode == _rail_keycodes[i]) { |
522 e->we.keypress.cont = false; |
569 e->we.keypress.cont = false; |
523 _remove_button_clicked = false; |
570 _remove_button_clicked = false; |
524 _build_railroad_button_proc[i](w); |
571 _build_railroad_button_proc[i](w); |
525 UpdateRemoveWidgetStatus(w, i + RTW_BUILD_NS); |
572 UpdateRemoveWidgetStatus(w, i + RTW_BUILD_NS); |
|
573 if (_ctrl_pressed) RailToolbar_CtrlChanged(w); |
526 break; |
574 break; |
527 } |
575 } |
528 } |
576 } |
529 MarkTileDirty(_thd.pos.x, _thd.pos.y); // redraw tile selection |
577 MarkTileDirty(_thd.pos.x, _thd.pos.y); // redraw tile selection |
530 break; |
578 break; |
547 TileIndex end_tile = e->we.place.tile; |
595 TileIndex end_tile = e->we.place.tile; |
548 |
596 |
549 switch (e->we.place.select_proc) { |
597 switch (e->we.place.select_proc) { |
550 case DDSP_BUILD_BRIDGE: |
598 case DDSP_BUILD_BRIDGE: |
551 ResetObjectToPlace(); |
599 ResetObjectToPlace(); |
552 ShowBuildBridgeWindow(start_tile, end_tile, _cur_railtype); |
600 ShowBuildBridgeWindow(start_tile, end_tile, TRANSPORT_RAIL, _cur_railtype); |
553 break; |
601 break; |
554 |
602 |
555 case DDSP_PLACE_AUTORAIL: |
603 case DDSP_PLACE_AUTORAIL: |
556 HandleAutodirPlacement(); |
604 HandleAutodirPlacement(); |
557 break; |
605 break; |
562 |
610 |
563 case DDSP_DEMOLISH_AREA: |
611 case DDSP_DEMOLISH_AREA: |
564 GUIPlaceProcDragXY(e); |
612 GUIPlaceProcDragXY(e); |
565 break; |
613 break; |
566 |
614 |
567 case DDSP_REMOVE_STATION: |
|
568 DoCommandP(end_tile, start_tile, 0, CcPlaySound1E, CMD_REMOVE_FROM_RAILROAD_STATION | CMD_MSG(STR_CANT_REMOVE_PART_OF_STATION)); |
|
569 break; |
|
570 |
|
571 case DDSP_CONVERT_RAIL: |
615 case DDSP_CONVERT_RAIL: |
572 DoCommandP(end_tile, start_tile, _cur_railtype, CcPlaySound10, CMD_CONVERT_RAIL | CMD_MSG(STR_CANT_CONVERT_RAIL)); |
616 DoCommandP(end_tile, start_tile, _cur_railtype, CcPlaySound10, CMD_CONVERT_RAIL | CMD_MSG(STR_CANT_CONVERT_RAIL)); |
573 break; |
617 break; |
574 |
618 |
|
619 case DDSP_REMOVE_STATION: |
575 case DDSP_BUILD_STATION: |
620 case DDSP_BUILD_STATION: |
|
621 if (_remove_button_clicked) { |
|
622 DoCommandP(end_tile, start_tile, 0, CcPlaySound1E, CMD_REMOVE_FROM_RAILROAD_STATION | CMD_MSG(STR_CANT_REMOVE_PART_OF_STATION)); |
|
623 break; |
|
624 } |
576 HandleStationPlacement(start_tile, end_tile); |
625 HandleStationPlacement(start_tile, end_tile); |
577 break; |
626 break; |
578 |
627 |
579 case DDSP_PLACE_RAIL_NE: |
628 case DDSP_PLACE_RAIL_NE: |
580 case DDSP_PLACE_RAIL_NW: |
629 case DDSP_PLACE_RAIL_NW: |
604 VpSetPresizeRange(tile, _build_tunnel_endtile == 0 ? tile : _build_tunnel_endtile); |
653 VpSetPresizeRange(tile, _build_tunnel_endtile == 0 ? tile : _build_tunnel_endtile); |
605 } break; |
654 } break; |
606 |
655 |
607 case WE_DESTROY: |
656 case WE_DESTROY: |
608 if (_patches.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0); |
657 if (_patches.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0); |
|
658 break; |
|
659 |
|
660 case WE_CTRL_CHANGED: |
|
661 /* do not toggle Remove button by Ctrl when placing station */ |
|
662 if (!w->IsWidgetLowered(RTW_BUILD_STATION) && RailToolbar_CtrlChanged(w)) e->we.ctrl.cont = false; |
609 break; |
663 break; |
610 } |
664 } |
611 } |
665 } |
612 |
666 |
613 /** Widget definition for the rail toolbar */ |
667 /** Widget definition for the rail toolbar */ |
816 if (_railstation.orientation == 0) Swap(x, y); |
870 if (_railstation.orientation == 0) Swap(x, y); |
817 if (!_remove_button_clicked) |
871 if (!_remove_button_clicked) |
818 SetTileSelectSize(x, y); |
872 SetTileSelectSize(x, y); |
819 } |
873 } |
820 |
874 |
821 int rad = (_patches.modified_catchment) ? CA_TRAIN : 4; |
875 int rad = (_patches.modified_catchment) ? CA_TRAIN : CA_UNMODIFIED; |
822 |
876 |
823 if (_station_show_coverage) |
877 if (_station_show_coverage) |
824 SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad); |
878 SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad); |
825 |
879 |
826 for (uint bits = 0; bits < 7; bits++) { |
880 for (uint bits = 0; bits < 7; bits++) { |