This repository has been archived by the owner on May 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
siggui0_153.diff
executable file
·634 lines (603 loc) · 23.4 KB
/
siggui0_153.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
Index: lang/english.txt
===================================================================
--- lang/english.txt (revision 2364)
+++ lang/english.txt (working copy)
@@ -1121,6 +1121,25 @@
STR_WAYPOINT :{WHITE}Waypoint
STR_WAYPOINT_GRAPHICS_TIP :{BLACK}Select waypoint type
+STR_SIGNAL_SELECTION :{WHITE}Signal Type Selection
+STR_SIGNAL_PRESIG_COMBO :{BLACK}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{SKIP}{STRING}
+STR_SIGNAL_NORMAL :Normal Signals
+STR_SIGNAL_ENTRANCE :Entrance Presignals
+STR_SIGNAL_COMBO :Combo Presignals
+STR_SIGNAL_EXIT :Exit Presignals
+STR_SIGNAL_COMPLETION :{BLACK}Auto Completion
+STR_SIGNAL_DENSITY_DESC :{BLACK}Signal Density:
+STR_SIGNAL_DENSITY_TILES :{GOLD}{INT32} tile(s)
+############ Leave those lines in this order!!
+STR_SIGNAL_TYPE_STANDARD :{GOLD}Light Signals
+STR_SIGNAL_TYPE_SEMAPHORES :{GOLD}Semaphores
+############ End of leave-in-this-order
+
+STR_SIGNAL_TYPE_TIP :{BLACK}Select signal type
+STR_SIGNAL_DENSITY_TIP :{BLACK}Select signal density for dragging
+STR_SIGNAL_COMPLETION_TIP :{BLACK}With autocompletion on, signals will be built in the direction you were dragging, following the track until a junction is encountered.
+STR_SIGNAL_PRESIG_TIP :{BLACK}Select the type of presignal, if any
+
STR_WAYPOINT_VIEWPORT :{WHITE}{WAYPOINT}
STR_WAYPOINT_VIEWPORT_TINY :{TINYFONT}{WHITE}{WAYPOINT}
STR_WAYPOINT_RAW :{WAYPOINT}
Index: ttd.h
===================================================================
--- ttd.h (revision 2364)
+++ ttd.h (working copy)
@@ -438,6 +438,7 @@
WC_REPLACE_VEHICLE = 0x4C,
WC_HIGHSCORE_ENDSCREEN = 0x4D,
WC_SIGN_LIST = 0x4E,
+ WC_BUILD_SIGNALS = 0x4F,
};
Index: table/sprites.h
===================================================================
--- table/sprites.h (revision 2364)
+++ table/sprites.h (working copy)
@@ -60,6 +60,7 @@
/* Network GUI sprites */
+ SPR_SEMA = SPR_OPENTTD_BASE + 24, // semaphore icon
SPR_SQUARE = SPR_OPENTTD_BASE + 23, // colored square (used for newgrf compatibility)
SPR_LOCK = SPR_OPENTTD_BASE + 22, // lock icon (for password protected servers)
SPR_FLAGS_BASE = SPR_OPENTTD_BASE + 90, // start of the flags block (in same order as enum NetworkLanguage)
Index: rail_cmd.c
===================================================================
--- rail_cmd.c (revision 2364)
+++ rail_cmd.c (working copy)
@@ -700,15 +700,18 @@
* pre/exit/combo-signals, and what-else not
* @param x,y coordinates where signals is being built
* @param p1 various bitstuffed elements
- * - p1 = (bit 0-2) - track-orientation, valid values: 0-5
- * - p1 = (bit 3) - choose semaphores/signals or cycle normal/pre/exit/combo depending on context
+ * - p1 (bit 0-2) - track-orientation, valid values: 0-5
+ * - p1 (bit 3) - cycle normal/pre/exit/combo (only applies when signals already exist)
+ * - p1 (bit 4) - choose semaphores/light signals (only applies when no signals already exist)
+ * - p1 (bit 5-6) - choose presignal type (only aplies when no signals already exist)
* @param p2 used for CmdBuildManySignals() to copy style of first signal
*/
int32 CmdBuildSingleSignal(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
TileIndex tile = TILE_FROM_XY(x, y);
bool semaphore;
- bool pre_signal;
+ bool pre_signal_cycle;
+ byte pre_signal_type;
uint track = p1 & 0x7;
byte m5;
int32 cost;
@@ -722,7 +725,7 @@
m5 = _map5[tile];
/* You can't build signals in a depot, and the selected track must exist */
- if (m5 & 0x80 || !HASBIT(m5, track)) return CMD_ERROR;
+ if (m5 & RAIL_TYPE_SPECIAL || !HASBIT(m5, track)) return CMD_ERROR;
if (!CheckTileOwnership(tile)) return CMD_ERROR;
@@ -743,8 +746,11 @@
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
- // Same bit, used in different contexts
- semaphore = pre_signal = HASBIT(p1, 3);
+ // for when signals already exist
+ pre_signal_cycle = HASBIT(p1, 3);
+ // for placing new signals
+ semaphore = HASBIT(p1, 4);
+ pre_signal_type = (p1 >> 5) & 3;
if ((_map3_lo[tile] & _signals_table_both[track]) == 0) {
// build new signals
@@ -767,7 +773,7 @@
_map5[tile] |= RAIL_TYPE_SIGNALS; // change into signals
_map2[tile] |= 0xF0; // all signals are on
_map3_lo[tile] &= ~0xF0; // no signals built by default
- _map3_hi[tile] = semaphore ? 4 : 0;
+ _map3_hi[tile] = (semaphore ? 4 : 0) + pre_signal_type;
}
if (p2 == 0) {
@@ -775,7 +781,7 @@
// build new signals
_map3_lo[tile] |= _signals_table_both[track];
} else {
- if (pre_signal) {
+ if (pre_signal_cycle) {
// cycle between normal -> pre -> exit -> combo -> ...
byte type = (_map3_hi[tile] + 1) & 0x03;
_map3_hi[tile] &= ~0x03;
@@ -821,13 +827,231 @@
return cost;
}
+static const byte _dir_from_track[14] = {
+ 0,1,0,1,2,1, 0,0,
+ 2,3,3,2,3,0,
+};
+
+/** Build many signals automagically,
+ * Copy a signal along the entire length of connected rail, stopping only when a junction is reached
+ * @param x,y tile to start from
+ * @param railbit the railbit (direction in which to start placing signals)
+ * @param signals type of signals to copy
+ * @param p2 various bitstuffed elements
+ * - p2 (bit 0) - 1 = remove signals, 0 = build signals
+ * - p2 (bit 3) - 0 = signals, 1 = semaphores
+ * - p2 (bit 24-31) - user defined signals_density
+ */
+int32 BuildAutoSignals(int x, int y, byte railbit, uint32 flags, uint32 p2, byte signals)
+{
+ byte signal_density = (p2 >> 24);
+ int16 signal_ctr = signal_density * 2;
+ byte signal_dir = 0; // direction in which signals are placed 1=forward 2=backward 3=twoway
+ byte track_mode = 0; // 128=bridge, 64=tunnel, 192=end of tunnel/bridge, 0=normal track
+ byte track_height = 0; // height of tunnel currently in
+ int32 retr, total_cost = 0;
+ TileIndex tile = TILE_FROM_XY(x, y);
+ byte m5 = _map5[tile];
+ byte m3 = _map3_lo[tile];
+ byte semaphores = (_map3_hi[tile] & ~3) ? 16 : 0;
+ int mode = p2 & 0x1;
+ int lx, ly;
+ byte dir;
+
+
+ // remember start position and direction
+ int sx = x, sy = y;
+ int srb = railbit;
+
+ // get first signal mode
+ if (signals & _signals_table[railbit]) signal_dir |= 1;
+ if (signals & _signals_table_other[railbit]) signal_dir |= 2;
+
+ // check for semaphores
+ if (!(m5 & RAIL_TYPE_SPECIAL) && (m5 & RAIL_BIT_MASK) && (m5 & RAIL_TYPE_SIGNALS))
+ semaphores = (_map3_hi[tile] & ~3) ? 16 : 0; // copy signal/semaphores style (independent of GUI)
+
+ if (signal_dir == 0)
+ return CMD_ERROR; // no signal on start tile to copy
+
+ signals = 0;
+ lx = 0;
+ ly = 0;
+
+ for(;;) {
+ x += _railbit.xinc[railbit];
+ y += _railbit.yinc[railbit];
+
+ tile = TILE_FROM_XY(x, y);
+
+ m5 = _map5[tile];
+
+ m3 = _map3_lo[tile];
+
+ dir = _dir_from_track[railbit];
+
+ if (track_mode & 128) { // currently on bridge
+ if (IsTileType(tile, MP_TUNNELBRIDGE) && ((m5 & 192) == 128))
+ // end of bridge
+ track_mode = 192;
+ } else if (track_mode & 64) { // currently in tunnel
+ if (IsTileType(tile, MP_TUNNELBRIDGE)
+ && ((m5 & 0xF0) == 0)
+ && ((m5 & 3) == (dir ^ 2))
+ && (GetSlopeZ(x+8, y+8) == track_height))
+ // end of tunnel
+ track_mode = 192;
+ } else { // currently not on bridge/in tunnel
+ if (IsTileType(tile,MP_TUNNELBRIDGE)
+ && (((m5 >> 1) & 3) == 0)
+ && ((m5 & 192) == 128)
+ && ((m5 & 1) == (dir & 1)) ) {
+ // start of bridge
+ track_mode = 128;
+ } else if (IsTileType(tile, MP_TUNNELBRIDGE)
+ && ((m5 & 0xF0) == 0)
+ && (((m5 >> 2) & 3) == 0) ) {
+ // start of tunnel
+ track_mode = 64;
+ track_height = GetSlopeZ(x+8, y+8);
+ };
+ };
+
+ /* for pieces that we cannot build signals on but are not an end of track or a junction, we continue counting. When a signal
+ should be placed in one of these tiles, it is instead placed on the last possible place for signals, and the counting is
+ reset from that place. If a signal already is there, one will be placed one the first possible tile encountered.
+ last place where a signal could be placed is remembered by lx,ly
+ if signal==0 a signal is already on lx,ly
+ */
+ if ( (IsTileType(tile, MP_RAILWAY) && ((m5 & ~1) == RAIL_TYPE_WAYPOINT) && ((m5 & 1) == (dir & 1))) // check for waypoints
+ || (IsTileType(tile, MP_STREET) && ((m5 >> 4) == 1) && (!(m5 & 8) != !(dir & 1))) // check for road crossings
+ || (IsTileType(tile,MP_TUNNELBRIDGE) && ((m5 & 0xF8) == 0xE0) && ((m5 & 1) != (dir & 1))) // check overhanging bridges
+ || (track_mode != 0) // are we on a bridge/in a tunnel
+ ) {
+ if (track_mode == 192) track_mode = 0; // end of tunnel/bridge
+ signal_ctr -= 2; // these pieces are always diagonal, so count faster
+ if (signal_ctr <= 0) {
+ if (signals == 0) {
+ // signal will be placed on next available tile
+ signal_ctr = 1;
+ } else {
+ // signal will be placed on last possible tile, counting will reset from there
+ signal_ctr += signal_density * 2;
+ x = lx;
+ y = ly;
+ // Place Signal
+ retr = DoCommand(x, y, (railbit & 7) | semaphores, signals, flags, (mode == 1) ? CMD_REMOVE_SIGNALS : CMD_BUILD_SIGNALS);
+ if (retr == CMD_ERROR) return CMD_ERROR;
+ total_cost += retr;
+ signals = 0;
+ track_mode = 0;
+ };
+ };
+ continue;
+ };
+
+ if (!IsTileType(tile, MP_RAILWAY))
+ return total_cost; // no more track, we are finished
+
+ if ((m5 & RAIL_TYPE_SPECIAL) || !(m5 & RAIL_BIT_MASK))
+ return total_cost; // no more track, we are finished
+
+ // check for valid track combination, and calculate the railbit
+ m5 &= RAIL_BIT_MASK;
+ switch (railbit) {
+ case 0: case 2: case 13: { // from SW
+ if (m5 == RAIL_BIT_DIAG1) { // SW to NE track
+ railbit = 0;
+ } else if ((m5 & ~RAIL_BIT_UPPER) == RAIL_BIT_LOWER) { // SW to SE track
+ railbit = 3;
+ } else if ((m5 & ~RAIL_BIT_RIGHT) == RAIL_BIT_LEFT) { // SW to NW track
+ railbit = 12;
+ } else {
+ return total_cost; // unsuitable track for signals, we are finished
+ }
+ } break;
+ case 8: case 4: case 11: { // from NE
+ if (m5 == RAIL_BIT_DIAG1) { // NE to SW track
+ railbit = 8;
+ } else if ((m5 & ~RAIL_BIT_LOWER) == RAIL_BIT_UPPER) { // NE to NW track
+ railbit = 10;
+ } else if ((m5 & ~RAIL_BIT_LEFT) == RAIL_BIT_RIGHT) { // NE to SE track
+ railbit = 5;
+ } else {
+ return total_cost; // unsuitable track for signals, we are finished
+ }
+ } break;
+ case 9: case 10: case 12: { // from SE
+ if (m5 == RAIL_BIT_DIAG2) { // SE to NW track
+ railbit = 9;
+ } else if ((m5 & ~RAIL_BIT_UPPER) == RAIL_BIT_LOWER ) { // SE to SW track
+ railbit = 11;
+ } else if ((m5 & ~RAIL_BIT_LEFT) == RAIL_BIT_RIGHT) { // SE to NE track
+ railbit = 13;
+ } else {
+ return total_cost; // unsuitable track for signals, we are finished
+ }
+ } break;
+ case 1: case 3: case 5: { // from NW
+ if (m5 == RAIL_BIT_DIAG2) { // NW to SE track
+ railbit = 1;
+ } else if ((m5 & ~RAIL_BIT_LOWER) == RAIL_BIT_UPPER) { // NW to NE track
+ railbit = 2;
+ } else if((m5 & ~RAIL_BIT_RIGHT) == RAIL_BIT_LEFT) { // NW to SW track
+ railbit = 4;
+ } else {
+ return total_cost; // unsuitable track for signals, we are finished
+ }
+ } break;
+ }
+
+ // calculate signals to place
+ signals = 0;
+ if (signal_dir & 1) signals |= _signals_table[railbit];
+ if (signal_dir & 2) signals |= _signals_table_other[railbit];
+
+ if (x == sx && y == sy && railbit == srb)
+ return total_cost; // back at the start, we are finished
+
+ // remember last place signals could be placed
+ lx = x; ly = y;
+
+ m5 = _map5[tile];
+ if (mode)
+ // when removing signals, remove all signals we encounter
+ signal_ctr =( (((m5 & RAIL_TYPE_MASK) == RAIL_TYPE_SIGNALS)) && (m3 & _signals_table_both[railbit]) ) ? 0 : 1;
+ else if (m5 & 0x3)
+ // count faster on diagonal tracks
+ signal_ctr -= 2;
+ else
+ signal_ctr -= 1;
+
+ if (signal_ctr <= 0) {
+ signal_ctr += signal_density * 2;
+ // Place Signal
+ retr = DoCommand(lx, ly, (railbit & 7) | semaphores, signals , flags, (mode == 1) ? CMD_REMOVE_SIGNALS : CMD_BUILD_SIGNALS);
+ if (retr == CMD_ERROR) return CMD_ERROR;
+ total_cost += retr;
+ signals = 0;
+ };
+
+ // when removing signals, the last position is always handled
+ if (mode) signals = 0;
+
+ };
+
+
+};
+
+
/** Build many signals by dragging; AutoSignals
* @param x,y start tile of drag
* @param p1 end tile of drag
* @param p2 various bitstuffed elements
- * - p2 = (bit 0) - 0 = build, 1 = remove signals
- * - p2 = (bit 3) - 0 = signals, 1 = semaphores
- * - p2 = (bit 4- 6) - track-orientation, valid values: 0-5
+ * - p2 = (bit 0) - 0 = build, 1 = remove signals
+ * - p2 = (bit 1) - 1 = autocompletion on, 0 = off
+ * - p2 = (bit 3) - 0 = signals, 1 = semaphores
+ * - p2 = (bit 4- 6) - track-orientation, valid values: 0-5
* - p2 = (bit 24-31) - user defined signals_density
*/
static int32 CmdSignalTrackHelper(int x, int y, uint32 flags, uint32 p1, uint32 p2)
@@ -839,7 +1063,7 @@
bool error = true;
int mode = p2 & 0x1;
- byte semaphores = (HASBIT(p2, 3)) ? 8 : 0;
+ byte semaphores = (HASBIT(p2, 3)) ? 16 : 0;
byte railbit = (p2 >> 4) & 0x7;
byte signal_density = (p2 >> 24);
@@ -864,7 +1088,7 @@
signals = _map3_lo[tile] & _signals_table_both[railbit];
if (signals == 0) signals = _signals_table_both[railbit];
- semaphores = (_map3_hi[tile] & ~3) ? 8 : 0; // copy signal/semaphores style (independent of CTRL)
+ semaphores = (_map3_hi[tile] & ~3) ? 16 : 0; // copy signal/semaphores style (independent of CTRL)
} else // no signals exist, drag a two-way signal stretch
signals = _signals_table_both[railbit];
@@ -889,6 +1113,15 @@
} else {
error = false;
total_cost += ret;
+
+ /* when autocompletion is on, use that to place the rest of the signals */
+ if HASBIT(p2, 1) {
+ ret = BuildAutoSignals(x, y, railbit, flags, p2, signals);
+ if (ret == CMD_ERROR)
+ return CMD_ERROR;
+ total_cost += ret;
+ return total_cost;
+ }
}
}
@@ -1691,12 +1924,6 @@
}
}
-static const byte _dir_from_track[14] = {
- 0,1,0,1,2,1, 0,0,
- 2,3,3,2,3,0,
-};
-
-
static void ChangeSignalStates(SetSignalsData *ssd)
{
int i;
Index: rail_gui.c
===================================================================
--- rail_gui.c (revision 2364)
+++ rail_gui.c (working copy)
@@ -20,7 +20,18 @@
static byte _build_depot_direction;
static byte _waypoint_count=1;
static byte _cur_waypoint_type;
+static byte _cur_signal_type;
+static byte _cur_presig_type;
+static bool _cur_autosig_compl;
+static const StringID _presig_types_dropdown[] = {
+ STR_SIGNAL_NORMAL,
+ STR_SIGNAL_ENTRANCE,
+ STR_SIGNAL_EXIT,
+ STR_SIGNAL_COMBO,
+ INVALID_STRING_ID
+};
+
struct {
byte orientation;
byte numtracks;
@@ -33,6 +44,7 @@
static void ShowBuildTrainDepotPicker(void);
static void ShowBuildWaypointPicker(void);
static void ShowStationBuilder(void);
+static void ShowSignalBuilder(void);
typedef void OnButtonClick(Window *w);
@@ -168,8 +180,10 @@
if (trackstat != 0) { while (!(trackstat & 1)) { i++; trackstat >>= 1; }}
if (!_remove_button_clicked) {
- DoCommandP(tile, i + (_ctrl_pressed ? 8 : 0), 0, CcPlaySound1E,
- CMD_BUILD_SIGNALS | CMD_AUTO | CMD_MSG(STR_1010_CAN_T_BUILD_SIGNALS_HERE));
+ DoCommandP(tile, i + (_ctrl_pressed ? 8 : 0) +
+ (!HASBIT(_cur_signal_type, 0) != !_ctrl_pressed ? 16 : 0) +
+ (_cur_presig_type << 5) ,
+ 0, CcPlaySound1E, CMD_BUILD_SIGNALS | CMD_AUTO | CMD_MSG(STR_1010_CAN_T_BUILD_SIGNALS_HERE));
} else {
DoCommandP(tile, i, 0, CcPlaySound1E,
CMD_REMOVE_SIGNALS | CMD_AUTO | CMD_MSG(STR_1013_CAN_T_REMOVE_SIGNALS_FROM));
@@ -250,7 +264,8 @@
static void BuildRailClick_Depot(Window *w)
{
- if (HandlePlacePushButton(w, 10, _depot_cursors[_cur_railtype], 1, PlaceRail_Depot)) ShowBuildTrainDepotPicker();
+ if (HandlePlacePushButton(w, 10, _depot_cursors[_cur_railtype], 1, PlaceRail_Depot))
+ ShowBuildTrainDepotPicker();
}
static void BuildRailClick_Waypoint(Window *w)
@@ -268,7 +283,8 @@
static void BuildRailClick_AutoSignals(Window *w)
{
- HandlePlacePushButton(w, 13, ANIMCURSOR_BUILDSIGNALS, VHM_RECT, PlaceRail_AutoSignals);
+ if (HandlePlacePushButton(w, 13, ANIMCURSOR_BUILDSIGNALS, VHM_RECT, PlaceRail_AutoSignals))
+ ShowSignalBuilder();
}
static void BuildRailClick_Bridge(Window *w)
@@ -347,10 +363,11 @@
// _patches.drag_signals_density is given as a parameter such that each user in a network
// game can specify his/her own signal density
DoCommandP(TILE_FROM_XY(thd->selstart.x, thd->selstart.y), TILE_FROM_XY(thd->selend.x, thd->selend.y),
- (_ctrl_pressed ? 1 << 3 : 0) | (trackstat << 4) | (_patches.drag_signals_density << 24),
- CcPlaySound1E,
- (_remove_button_clicked ? CMD_REMOVE_SIGNAL_TRACK | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1013_CAN_T_REMOVE_SIGNALS_FROM) :
- CMD_BUILD_SIGNAL_TRACK | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1010_CAN_T_BUILD_SIGNALS_HERE) ) );
+ (!HASBIT(_cur_signal_type, 0) != !_ctrl_pressed ? 1 << 3 : 0) | (trackstat << 4) |
+ (_patches.drag_signals_density << 24) | (_cur_autosig_compl ? 2 : 0),
+ CcPlaySound1E,
+ (_remove_button_clicked ? CMD_REMOVE_SIGNAL_TRACK | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1013_CAN_T_REMOVE_SIGNALS_FROM) :
+ CMD_BUILD_SIGNAL_TRACK | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1010_CAN_T_BUILD_SIGNALS_HERE) ) );
}
static OnButtonClick * const _build_railroad_button_proc[] = {
@@ -470,6 +487,9 @@
if (w != NULL) WP(w,def_d).close=true;
w = FindWindowById(WC_BUILD_DEPOT, 0);
if (w != NULL) WP(w,def_d).close=true;
+ w = FindWindowById(WC_BUILD_SIGNALS, 0);
+ if (w != NULL) WP(w,def_d).close=true;
+
break;
case WE_PLACE_PRESIZE: {
@@ -933,10 +953,123 @@
}
+static void BuildSignalWndProc(Window *w, WindowEvent *e)
+{
+ switch(e->event) {
+ case WE_PAINT: {
+ /* XXX TODO: dont always hide the buttons when more than 2 signal types are available */
+ w->hidden_state = (1 << 3) | (1 << 6);
+
+ /* XXX TODO: take into account the scroll position for setting the click state */
+ w->click_state = ((1 << 4) << _cur_signal_type) | (_cur_autosig_compl ? 1 << 9 : 0);
+
+ SetDParam(10, _presig_types_dropdown[_cur_presig_type]);
+ DrawWindowWidgets(w);
+
+ // Draw the string for current signal type
+ DrawStringCentered(69, 49, STR_SIGNAL_TYPE_STANDARD + _cur_signal_type, 0);
+
+ // Draw the strings for drag density
+ DrawStringCentered(69, 60, STR_SIGNAL_DENSITY_DESC, 0);
+ SetDParam(0, _patches.drag_signals_density);
+ DrawString( 50, 71, STR_SIGNAL_DENSITY_TILES , 0);
+
+ // Draw the '<' and '>' characters for the decrease/increase buttons
+ DrawStringCentered(30, 72, STR_6819, 0);
+ DrawStringCentered(40, 72, STR_681A, 0);
+
+ break;
+ }
+ case WE_CLICK: {
+ switch(e->click.widget) {
+ case 3: case 6: // scroll signal types
+ /* XXX TODO: implement scrolling */
+ break;
+ case 4: case 5: // select signal type
+ /* XXX TODO: take into account the scroll position for changing selected type */
+ _cur_signal_type = e->click.widget - 4;
+ SndPlayFx(SND_15_BEEP);
+ SetWindowDirty(w);
+ break;
+ case 7: // decrease drag density
+ if (_patches.drag_signals_density > 1) {
+ _patches.drag_signals_density--;
+ SndPlayFx(SND_15_BEEP);
+ SetWindowDirty(w);
+ };
+ break;
+ case 8: // increase drag density
+ if (_patches.drag_signals_density < 20) {
+ _patches.drag_signals_density++;
+ SndPlayFx(SND_15_BEEP);
+ SetWindowDirty(w);
+ };
+ break;
+ case 9: // autosignal mode toggle button
+ _cur_autosig_compl ^= 1;
+ SndPlayFx(SND_15_BEEP);
+ SetWindowDirty(w);
+ break;
+ case 10: case 11: // presignal-type dropdown list
+ ShowDropDownMenu(w, _presig_types_dropdown, _cur_presig_type, 11, 0, 0);
+ break;
+ }
+ break;
+ case WE_DROPDOWN_SELECT: // change presignal type
+ _cur_presig_type = e->dropdown.index;
+ SetWindowDirty(w);
+ break;
+ }
+
+ case WE_MOUSELOOP:
+ if (WP(w,def_d).close)
+ DeleteWindow(w);
+ return;
+
+ case WE_DESTROY:
+ if (!WP(w,def_d).close)
+ ResetObjectToPlace();
+ break;
+ }
+}
+
+static const Widget _build_signal_widgets[] = {
+{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5 , STR_018B_CLOSE_WINDOW},
+{ WWT_CAPTION, RESIZE_NONE, 7, 11, 139, 0, 13, STR_SIGNAL_SELECTION , STR_018C_WINDOW_TITLE_DRAG_THIS},
+{ WWT_PANEL, RESIZE_NONE, 7, 0, 139, 14, 114, 0x0 , STR_NULL},
+{ WWT_PANEL, RESIZE_NONE, 7, 22, 30, 29, 39, SPR_ARROW_LEFT , STR_SIGNAL_TYPE_TIP},
+{ WWT_PANEL, RESIZE_NONE, 7, 43, 64, 24, 45, 0x50B , STR_SIGNAL_TYPE_TIP},
+{ WWT_PANEL, RESIZE_NONE, 7, 75, 96, 24, 45, SPR_SEMA , STR_SIGNAL_TYPE_TIP},
+{ WWT_PANEL, RESIZE_NONE, 7, 109, 117, 29, 39, SPR_ARROW_RIGHT , STR_SIGNAL_TYPE_TIP},
+{ WWT_IMGBTN, RESIZE_NONE, 3, 25, 34, 72, 80, 0x0 , STR_SIGNAL_DENSITY_TIP},
+{ WWT_IMGBTN, RESIZE_NONE, 3, 35, 44, 72, 80, 0x0 , STR_SIGNAL_DENSITY_TIP},
+{ WWT_TEXTBTN, RESIZE_NONE, 7, 20, 119, 84, 95, STR_SIGNAL_COMPLETION , STR_SIGNAL_COMPLETION_TIP},
+{ WWT_6, RESIZE_NONE, 7, 10, 129, 99, 110, STR_SIGNAL_PRESIG_COMBO , STR_SIGNAL_PRESIG_TIP},
+{ WWT_CLOSEBOX, RESIZE_NONE, 7, 118, 128, 100, 109, STR_0225 , STR_SIGNAL_PRESIG_TIP},
+{ WIDGETS_END},
+};
+
+static const WindowDesc _build_signal_desc = {
+ -1,-1, 140, 115,
+ WC_BUILD_SIGNALS,WC_BUILD_TOOLBAR,
+ WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
+ _build_signal_widgets,
+ BuildSignalWndProc
+};
+
+static void ShowSignalBuilder(void)
+{
+ _cur_presig_type = 0;
+ AllocateWindowDesc(&_build_signal_desc);
+}
+
void InitializeRailGui(void)
{
_build_depot_direction = 3;
_railstation.numtracks = 1;
_railstation.platlength = 1;
_railstation.dragdrop = true;
+ _cur_signal_type = 0;
+ _cur_presig_type = 0;
+ _cur_autosig_compl = false;
}
Index: command.c
===================================================================
--- command.c (revision 2364)
+++ command.c (working copy)
@@ -438,7 +438,12 @@
// road fragments still stay there and the town won't let you
// disconnect the road system), but the exec will succeed and this
// fact will trigger an assertion failure. --pasky
+ // CMD_BUILD_SIGNAL_TRACK: With autosignal completion, it could happen
+ // 2 parts of a tile with 2 signals both get changed to semaphores (or back)
+ // cause the semaphore/normal status is stored per-tile, the real run will
+ // only charge you once for changing, but the test run will charge you twice
notest =
+ (cmd & 0xFF) == CMD_BUILD_SIGNAL_TRACK ||
(cmd & 0xFF) == CMD_CLEAR_AREA ||
(cmd & 0xFF) == CMD_CONVERT_RAIL ||
(cmd & 0xFF) == CMD_LEVEL_LAND ||