11 #include "station_gui.h" |
11 #include "station_gui.h" |
12 #include "terraform_gui.h" |
12 #include "terraform_gui.h" |
13 #include "viewport_func.h" |
13 #include "viewport_func.h" |
14 #include "gfx_func.h" |
14 #include "gfx_func.h" |
15 #include "command_func.h" |
15 #include "command_func.h" |
16 #include "station.h" |
16 #include "town_type.h" |
17 #include "waypoint.h" |
17 #include "waypoint.h" |
18 #include "debug.h" |
18 #include "debug.h" |
19 #include "variables.h" |
19 #include "variables.h" |
20 #include "newgrf_callbacks.h" |
20 #include "newgrf_callbacks.h" |
21 #include "newgrf_station.h" |
21 #include "newgrf_station.h" |
43 static RailType _cur_railtype; |
43 static RailType _cur_railtype; |
44 static bool _remove_button_clicked; |
44 static bool _remove_button_clicked; |
45 static DiagDirection _build_depot_direction; |
45 static DiagDirection _build_depot_direction; |
46 static byte _waypoint_count = 1; |
46 static byte _waypoint_count = 1; |
47 static byte _cur_waypoint_type; |
47 static byte _cur_waypoint_type; |
48 static bool _convert_signal_button; // convert signal button in the signal GUI pressed |
48 static bool _convert_signal_button; ///< convert signal button in the signal GUI pressed |
49 static SignalVariant _cur_signal_variant; // set the signal variant (for signal GUI) |
49 static SignalVariant _cur_signal_variant; ///< set the signal variant (for signal GUI) |
50 static SignalType _cur_signal_type; // set the signal type (for signal GUI) |
50 static SignalType _cur_signal_type; ///< set the signal type (for signal GUI) |
51 |
51 |
52 static struct { |
52 static struct { |
53 byte orientation; |
53 byte orientation; |
54 byte numtracks; |
54 byte numtracks; |
55 byte platlength; |
55 byte platlength; |
203 |
203 |
204 if (_remove_button_clicked) { |
204 if (_remove_button_clicked) { |
205 DoCommandP(tile, track, 0, CcPlaySound1E, |
205 DoCommandP(tile, track, 0, CcPlaySound1E, |
206 CMD_REMOVE_SIGNALS | CMD_MSG(STR_1013_CAN_T_REMOVE_SIGNALS_FROM)); |
206 CMD_REMOVE_SIGNALS | CMD_MSG(STR_1013_CAN_T_REMOVE_SIGNALS_FROM)); |
207 } else { |
207 } else { |
208 if (!_patches.enable_signal_gui) _cur_signal_variant = _cur_year < _patches.semaphore_build_before ? SIG_SEMAPHORE : SIG_ELECTRIC; |
208 const Window *w = FindWindowById(WC_BUILD_SIGNAL, 0); |
209 |
209 |
210 /* various bitstuffed elements for CmdBuildSingleSignal() */ |
210 /* various bitstuffed elements for CmdBuildSingleSignal() */ |
211 uint32 p1 = track; |
211 uint32 p1 = track; |
212 SB(p1, 3, 1, _ctrl_pressed); |
212 |
213 SB(p1, 4, 1, _cur_signal_variant); |
213 if (w != NULL) { |
214 SB(p1, 5, 2, _patches.enable_signal_gui ? _cur_signal_type : SIGTYPE_NORMAL); |
214 /* signal GUI is used */ |
215 SB(p1, 7, 1, _convert_signal_button); |
215 SB(p1, 3, 1, _ctrl_pressed); |
|
216 SB(p1, 4, 1, _cur_signal_variant); |
|
217 SB(p1, 5, 2, _cur_signal_type); |
|
218 SB(p1, 7, 1, _convert_signal_button); |
|
219 } else { |
|
220 SB(p1, 3, 1, _ctrl_pressed); |
|
221 SB(p1, 4, 1, (_cur_year < _patches.semaphore_build_before ? SIG_SEMAPHORE : SIG_ELECTRIC)); |
|
222 SB(p1, 5, 2, SIGTYPE_NORMAL); |
|
223 SB(p1, 7, 1, 0); |
|
224 } |
216 |
225 |
217 DoCommandP(tile, p1, 0, CcPlaySound1E, CMD_BUILD_SIGNALS | |
226 DoCommandP(tile, p1, 0, CcPlaySound1E, CMD_BUILD_SIGNALS | |
218 CMD_MSG(_convert_signal_button ? STR_SIGNAL_CAN_T_CONVERT_SIGNALS_HERE : STR_1010_CAN_T_BUILD_SIGNALS_HERE)); |
227 CMD_MSG((w != NULL && _convert_signal_button) ? STR_SIGNAL_CAN_T_CONVERT_SIGNALS_HERE : STR_1010_CAN_T_BUILD_SIGNALS_HERE)); |
219 } |
228 } |
220 } |
229 } |
221 |
230 |
222 static void PlaceRail_Bridge(TileIndex tile) |
231 static void PlaceRail_Bridge(TileIndex tile) |
223 { |
232 { |
362 } |
371 } |
363 |
372 |
364 /** The "build signal"-button proc from BuildRailToolbWndProc() (start ShowSignalBuilder() and/or HandleAutoSignalPlacement()) */ |
373 /** The "build signal"-button proc from BuildRailToolbWndProc() (start ShowSignalBuilder() and/or HandleAutoSignalPlacement()) */ |
365 static void BuildRailClick_AutoSignals(Window *w) |
374 static void BuildRailClick_AutoSignals(Window *w) |
366 { |
375 { |
367 if (_patches.enable_signal_gui) { |
376 if (_patches.enable_signal_gui != _ctrl_pressed) { |
368 if (HandlePlacePushButton(w, RTW_BUILD_SIGNALS, ANIMCURSOR_BUILDSIGNALS, VHM_RECT, PlaceRail_AutoSignals)) ShowSignalBuilder(); |
377 if (HandlePlacePushButton(w, RTW_BUILD_SIGNALS, ANIMCURSOR_BUILDSIGNALS, VHM_RECT, PlaceRail_AutoSignals)) ShowSignalBuilder(); |
369 } else { |
378 } else { |
370 HandlePlacePushButton(w, RTW_BUILD_SIGNALS, ANIMCURSOR_BUILDSIGNALS, VHM_RECT, PlaceRail_AutoSignals); |
379 HandlePlacePushButton(w, RTW_BUILD_SIGNALS, ANIMCURSOR_BUILDSIGNALS, VHM_RECT, PlaceRail_AutoSignals); |
371 } |
380 } |
372 } |
381 } |
452 if (thd->drawstyle == HT_RECT) { // one tile case |
461 if (thd->drawstyle == HT_RECT) { // one tile case |
453 GenericPlaceSignals(TileVirtXY(thd->selend.x, thd->selend.y)); |
462 GenericPlaceSignals(TileVirtXY(thd->selend.x, thd->selend.y)); |
454 return; |
463 return; |
455 } |
464 } |
456 |
465 |
457 /* XXX Steal ctrl for autosignal function, until we get some GUI */ |
466 const Window *w = FindWindowById(WC_BUILD_SIGNAL, 0); |
458 SB(p2, 3, 1, 0); |
467 |
459 SB(p2, 4, 1, _cur_year < _patches.semaphore_build_before); |
468 if (w != NULL) { |
460 SB(p2, 6, 1, _ctrl_pressed); |
469 /* signal GUI is used */ |
461 SB(p2, 24, 8, _patches.drag_signals_density); |
470 SB(p2, 3, 1, 0); |
|
471 SB(p2, 4, 1, _cur_signal_variant); |
|
472 SB(p2, 6, 1, _ctrl_pressed); |
|
473 SB(p2, 24, 8, _patches.drag_signals_density); |
|
474 } else { |
|
475 SB(p2, 3, 1, 0); |
|
476 SB(p2, 4, 1, (_cur_year < _patches.semaphore_build_before ? SIG_SEMAPHORE : SIG_ELECTRIC)); |
|
477 SB(p2, 6, 1, _ctrl_pressed); |
|
478 SB(p2, 24, 8, _patches.drag_signals_density); |
|
479 } |
462 |
480 |
463 /* _patches.drag_signals_density is given as a parameter such that each user |
481 /* _patches.drag_signals_density is given as a parameter such that each user |
464 * in a network game can specify his/her own signal density */ |
482 * in a network game can specify his/her own signal density */ |
465 DoCommandP( |
483 DoCommandP( |
466 TileVirtXY(thd->selstart.x, thd->selstart.y), |
484 TileVirtXY(thd->selstart.x, thd->selstart.y), |
581 _place_proc(e->we.place.tile); |
599 _place_proc(e->we.place.tile); |
582 return; |
600 return; |
583 |
601 |
584 case WE_PLACE_DRAG: { |
602 case WE_PLACE_DRAG: { |
585 /* no dragging if you have pressed the convert button */ |
603 /* no dragging if you have pressed the convert button */ |
586 if (_convert_signal_button && w->IsWidgetLowered(RTW_BUILD_SIGNALS)) return; |
604 if (FindWindowById(WC_BUILD_SIGNAL, 0) != NULL && _convert_signal_button && w->IsWidgetLowered(RTW_BUILD_SIGNALS)) return; |
587 |
605 |
588 VpSelectTilesWithMethod(e->we.place.pt.x, e->we.place.pt.y, e->we.place.select_method); |
606 VpSelectTilesWithMethod(e->we.place.pt.x, e->we.place.pt.y, e->we.place.select_method); |
589 return; |
607 return; |
590 } |
608 } |
591 |
609 |
919 DrawStringCentered(74, 15 + y_offset, STR_3002_ORIENTATION, TC_FROMSTRING); |
937 DrawStringCentered(74, 15 + y_offset, STR_3002_ORIENTATION, TC_FROMSTRING); |
920 DrawStringCentered(74, 76 + y_offset, STR_3003_NUMBER_OF_TRACKS, TC_FROMSTRING); |
938 DrawStringCentered(74, 76 + y_offset, STR_3003_NUMBER_OF_TRACKS, TC_FROMSTRING); |
921 DrawStringCentered(74, 101 + y_offset, STR_3004_PLATFORM_LENGTH, TC_FROMSTRING); |
939 DrawStringCentered(74, 101 + y_offset, STR_3004_PLATFORM_LENGTH, TC_FROMSTRING); |
922 DrawStringCentered(74, 141 + y_offset, STR_3066_COVERAGE_AREA_HIGHLIGHT, TC_FROMSTRING); |
940 DrawStringCentered(74, 141 + y_offset, STR_3066_COVERAGE_AREA_HIGHLIGHT, TC_FROMSTRING); |
923 |
941 |
924 int text_end = DrawStationCoverageAreaText(2, 166 + y_offset, SCT_ALL, rad) + 4; |
942 int text_end = DrawStationCoverageAreaText(2, 166 + y_offset, SCT_ALL, rad, false); |
925 if (text_end > w->widget[BRSW_BACKGROUND].bottom) { |
943 text_end = DrawStationCoverageAreaText(2, text_end + 4, SCT_ALL, rad, true) + 4; |
|
944 if (text_end != w->widget[BRSW_BACKGROUND].bottom) { |
926 SetWindowDirty(w); |
945 SetWindowDirty(w); |
927 ResizeWindowForWidget(w, BRSW_BACKGROUND, 0, text_end - w->widget[BRSW_BACKGROUND].bottom); |
946 ResizeWindowForWidget(w, BRSW_BACKGROUND, 0, text_end - w->widget[BRSW_BACKGROUND].bottom); |
928 SetWindowDirty(w); |
947 SetWindowDirty(w); |
929 } |
948 } |
930 |
949 |
1311 case BSW_CONVERT: |
1330 case BSW_CONVERT: |
1312 _convert_signal_button = !_convert_signal_button; |
1331 _convert_signal_button = !_convert_signal_button; |
1313 break; |
1332 break; |
1314 |
1333 |
1315 case BSW_DRAG_SIGNALS_DENSITY_DECREASE: |
1334 case BSW_DRAG_SIGNALS_DENSITY_DECREASE: |
1316 if (_patches.drag_signals_density > 1) _patches.drag_signals_density--; |
1335 if (_patches.drag_signals_density > 1) { |
|
1336 _patches.drag_signals_density--; |
|
1337 const Window *w = FindWindowById(WC_GAME_OPTIONS, 0); |
|
1338 if (w != NULL) SetWindowDirty(w); |
|
1339 } |
1317 break; |
1340 break; |
1318 |
1341 |
1319 case BSW_DRAG_SIGNALS_DENSITY_INCREASE: |
1342 case BSW_DRAG_SIGNALS_DENSITY_INCREASE: |
1320 if (_patches.drag_signals_density < 20) _patches.drag_signals_density++; |
1343 if (_patches.drag_signals_density < 20) { |
|
1344 _patches.drag_signals_density++; |
|
1345 const Window *w = FindWindowById(WC_GAME_OPTIONS, 0); |
|
1346 if (w != NULL) SetWindowDirty(w); |
|
1347 } |
1321 break; |
1348 break; |
1322 |
1349 |
1323 default: break; |
1350 default: break; |
1324 } |
1351 } |
1325 |
1352 |
1368 SignalBuildWndProc |
1395 SignalBuildWndProc |
1369 }; |
1396 }; |
1370 |
1397 |
1371 /** |
1398 /** |
1372 * Open the signal selection window |
1399 * Open the signal selection window |
1373 * @pre reset all signal GUI relevant variables |
|
1374 */ |
1400 */ |
1375 static void ShowSignalBuilder() |
1401 static void ShowSignalBuilder() |
1376 { |
1402 { |
1377 _convert_signal_button = false; |
|
1378 _cur_signal_variant = _cur_year < _patches.semaphore_build_before ? SIG_SEMAPHORE : SIG_ELECTRIC; |
|
1379 _cur_signal_type = SIGTYPE_NORMAL; |
|
1380 |
|
1381 AllocateWindowDesc(&_signal_builder_desc); |
1403 AllocateWindowDesc(&_signal_builder_desc); |
1382 } |
1404 } |
1383 |
1405 |
1384 /** Enum referring to the widgets of the build rail depot window */ |
1406 /** Enum referring to the widgets of the build rail depot window */ |
1385 enum BuildRailDepotWidgets { |
1407 enum BuildRailDepotWidgets { |
1633 SetupRailToolbar(_cur_railtype, w); |
1655 SetupRailToolbar(_cur_railtype, w); |
1634 SetWindowDirty(w); |
1656 SetWindowDirty(w); |
1635 } |
1657 } |
1636 } |
1658 } |
1637 |
1659 |
1638 |
1660 /** |
1639 |
1661 * Updates the current signal variant used in the signal GUI |
|
1662 * to the one adequate to current year. |
|
1663 * @param 0 needed to be called when a patch setting changes |
|
1664 * @return success, needed for patch settings |
|
1665 */ |
|
1666 int32 ResetSignalVariant(int32 = 0) |
|
1667 { |
|
1668 SignalVariant new_variant = (_cur_year < _patches.semaphore_build_before ? SIG_SEMAPHORE : SIG_ELECTRIC); |
|
1669 |
|
1670 if (new_variant != _cur_signal_variant) { |
|
1671 Window *w = FindWindowById(WC_BUILD_SIGNAL, 0); |
|
1672 if (w != NULL) { |
|
1673 SetWindowDirty(w); |
|
1674 w->RaiseWidget((_cur_signal_variant == SIG_ELECTRIC ? BSW_ELECTRIC_NORM : BSW_SEMAPHORE_NORM) + _cur_signal_type); |
|
1675 } |
|
1676 _cur_signal_variant = new_variant; |
|
1677 } |
|
1678 |
|
1679 return 0; |
|
1680 } |
|
1681 |
|
1682 /** Resets the rail GUI - sets default railtype to build |
|
1683 * and resets the signal GUI |
|
1684 */ |
|
1685 void InitializeRailGUI() |
|
1686 { |
|
1687 SetDefaultRailGui(); |
|
1688 |
|
1689 _convert_signal_button = false; |
|
1690 _cur_signal_type = SIGTYPE_NORMAL; |
|
1691 ResetSignalVariant(); |
|
1692 } |