Files @ r26254:4dd185cf8a2d
Branch filter:

Location: cpp/openttd-patchpack/source/src/goal_gui.cpp - annotation

Theleruby
Merge with master
  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
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18807:da6eedb2e92e
r20359:fae457d8d0be
r24130:fb25135e54b7
r20947:e99af07846a3
r18872:35e831d058c7
r21410:ae5961f02724
r26103:316b73a1be08
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r21383:942c32fb8b0e
r21383:942c32fb8b0e
r20587:9d770437152c
r20587:9d770437152c
r20587:9d770437152c
r20587:9d770437152c
r20587:9d770437152c
r20587:9d770437152c
r20586:98f798a4a17f
r20586:98f798a4a17f
r20586:98f798a4a17f
r18772:80ffc4ed8122
r20280:ca1fc41725ff
r18772:80ffc4ed8122
r20280:ca1fc41725ff
r20357:d3a903f059db
r20280:ca1fc41725ff
r20720:53a4744858a4
r25010:cc3b6b985580
r25010:cc3b6b985580
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r23497:a0ab44ebd2fa
r20359:fae457d8d0be
r20359:fae457d8d0be
r20359:fae457d8d0be
r20359:fae457d8d0be
r20359:fae457d8d0be
r20359:fae457d8d0be
r20359:fae457d8d0be
r20359:fae457d8d0be
r20359:fae457d8d0be
r20359:fae457d8d0be
r20359:fae457d8d0be
r23497:a0ab44ebd2fa
r18772:80ffc4ed8122
r25010:cc3b6b985580
r25010:cc3b6b985580
r25010:cc3b6b985580
r25010:cc3b6b985580
r25010:cc3b6b985580
r25010:cc3b6b985580
r25010:cc3b6b985580
r25010:cc3b6b985580
r18772:80ffc4ed8122
r25010:cc3b6b985580
r25010:cc3b6b985580
r25010:cc3b6b985580
r25010:cc3b6b985580
r25010:cc3b6b985580
r25010:cc3b6b985580
r25010:cc3b6b985580
r25010:cc3b6b985580
r25010:cc3b6b985580
r25010:cc3b6b985580
r18772:80ffc4ed8122
r25010:cc3b6b985580
r18772:80ffc4ed8122
r25010:cc3b6b985580
r25010:cc3b6b985580
r25010:cc3b6b985580
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r20586:98f798a4a17f
r20586:98f798a4a17f
r23023:7b8669afd1db
r20586:98f798a4a17f
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r20586:98f798a4a17f
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r24130:fb25135e54b7
r24130:fb25135e54b7
r24130:fb25135e54b7
r24130:fb25135e54b7
r24130:fb25135e54b7
r24130:fb25135e54b7
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r20947:e99af07846a3
r20947:e99af07846a3
r20947:e99af07846a3
r20947:e99af07846a3
r20947:e99af07846a3
r20947:e99af07846a3
r20947:e99af07846a3
r20947:e99af07846a3
r20947:e99af07846a3
r20947:e99af07846a3
r20947:e99af07846a3
r20947:e99af07846a3
r20947:e99af07846a3
r20947:e99af07846a3
r20947:e99af07846a3
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r24333:94ef0c6c84e2
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r20586:98f798a4a17f
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r20586:98f798a4a17f
r25009:40a73870eb9b
r23960:7332b2a6afc5
r25009:40a73870eb9b
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r20586:98f798a4a17f
r25009:40a73870eb9b
r18772:80ffc4ed8122
r25009:40a73870eb9b
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r23497:a0ab44ebd2fa
r18772:80ffc4ed8122
r20587:9d770437152c
r25009:40a73870eb9b
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r19874:ee1f6282fb23
r25009:40a73870eb9b
r20587:9d770437152c
r25009:40a73870eb9b
r25009:40a73870eb9b
r25009:40a73870eb9b
r19874:ee1f6282fb23
r25009:40a73870eb9b
r19874:ee1f6282fb23
r25009:40a73870eb9b
r25009:40a73870eb9b
r25009:40a73870eb9b
r25009:40a73870eb9b
r25009:40a73870eb9b
r19874:ee1f6282fb23
r25009:40a73870eb9b
r25009:40a73870eb9b
r20587:9d770437152c
r19874:ee1f6282fb23
r23960:7332b2a6afc5
r25009:40a73870eb9b
r19874:ee1f6282fb23
r20587:9d770437152c
r20587:9d770437152c
r20289:1f623493c20d
r20289:1f623493c20d
r20587:9d770437152c
r20587:9d770437152c
r20289:1f623493c20d
r20587:9d770437152c
r20289:1f623493c20d
r20587:9d770437152c
r23607:36c15679007d
r20289:1f623493c20d
r20586:98f798a4a17f
r20587:9d770437152c
r20587:9d770437152c
r20587:9d770437152c
r20289:1f623493c20d
r20289:1f623493c20d
r20289:1f623493c20d
r19874:ee1f6282fb23
r19874:ee1f6282fb23
r19874:ee1f6282fb23
r19874:ee1f6282fb23
r19874:ee1f6282fb23
r19874:ee1f6282fb23
r20877:cd37e1fdd8a4
r20877:cd37e1fdd8a4
r25009:40a73870eb9b
r20586:98f798a4a17f
r19874:ee1f6282fb23
r19874:ee1f6282fb23
r19874:ee1f6282fb23
r19874:ee1f6282fb23
r23497:a0ab44ebd2fa
r20587:9d770437152c
r20587:9d770437152c
r20587:9d770437152c
r21327:e996efc4b558
r21327:e996efc4b558
r20587:9d770437152c
r20587:9d770437152c
r23960:7332b2a6afc5
r23607:36c15679007d
r20587:9d770437152c
r20587:9d770437152c
r20587:9d770437152c
r20587:9d770437152c
r20587:9d770437152c
r20587:9d770437152c
r20587:9d770437152c
r20587:9d770437152c
r24597:afde5721a3b6
r20587:9d770437152c
r20587:9d770437152c
r20587:9d770437152c
r20587:9d770437152c
r20587:9d770437152c
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r23497:a0ab44ebd2fa
r18772:80ffc4ed8122
r20587:9d770437152c
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r23497:a0ab44ebd2fa
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r25010:cc3b6b985580
r25010:cc3b6b985580
r20587:9d770437152c
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r20586:98f798a4a17f
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r20359:fae457d8d0be
r25010:cc3b6b985580
r25010:cc3b6b985580
r25010:cc3b6b985580
r25010:cc3b6b985580
r18772:80ffc4ed8122
r20287:5b9a8691769e
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r20587:9d770437152c
r20587:9d770437152c
r20587:9d770437152c
r20289:1f623493c20d
r18772:80ffc4ed8122
r20357:d3a903f059db
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r20280:ca1fc41725ff
r20283:2a199c78224c
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r18772:80ffc4ed8122
r20586:98f798a4a17f
r20586:98f798a4a17f
r20586:98f798a4a17f
r20586:98f798a4a17f
r20359:fae457d8d0be
r18772:80ffc4ed8122
r20359:fae457d8d0be
r20359:fae457d8d0be
r20359:fae457d8d0be
r18772:80ffc4ed8122
r18872:35e831d058c7
r20586:98f798a4a17f
r20586:98f798a4a17f
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r18872:35e831d058c7
r24535:5af09085ab10
r18872:35e831d058c7
r21410:ae5961f02724
r18872:35e831d058c7
r20586:98f798a4a17f
r18872:35e831d058c7
r25784:3baf56e102e0
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r24808:e7cb02d1ad0d
r18872:35e831d058c7
r20280:ca1fc41725ff
r24808:e7cb02d1ad0d
r24808:e7cb02d1ad0d
r24808:e7cb02d1ad0d
r24808:e7cb02d1ad0d
r24808:e7cb02d1ad0d
r24808:e7cb02d1ad0d
r24808:e7cb02d1ad0d
r20280:ca1fc41725ff
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r23497:a0ab44ebd2fa
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r23497:a0ab44ebd2fa
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r26117:dec8ad7628ec
r25564:c875d92c537a
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r26117:dec8ad7628ec
r25564:c875d92c537a
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r26117:dec8ad7628ec
r25564:c875d92c537a
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r23497:a0ab44ebd2fa
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r23497:a0ab44ebd2fa
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r24535:5af09085ab10
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r20586:98f798a4a17f
r24535:5af09085ab10
r18872:35e831d058c7
r18872:35e831d058c7
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24808:e7cb02d1ad0d
r24808:e7cb02d1ad0d
r24808:e7cb02d1ad0d
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r24808:e7cb02d1ad0d
r24808:e7cb02d1ad0d
r24808:e7cb02d1ad0d
r18872:35e831d058c7
r18872:35e831d058c7
r18872:35e831d058c7
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24808:e7cb02d1ad0d
r24808:e7cb02d1ad0d
r24808:e7cb02d1ad0d
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24808:e7cb02d1ad0d
r24808:e7cb02d1ad0d
r24808:e7cb02d1ad0d
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r24535:5af09085ab10
r18872:35e831d058c7
r20586:98f798a4a17f
r20586:98f798a4a17f
r20586:98f798a4a17f
r20586:98f798a4a17f
r20586:98f798a4a17f
r20586:98f798a4a17f
r20586:98f798a4a17f
r18962:69567f39810d
r18872:35e831d058c7
r24808:e7cb02d1ad0d
r24535:5af09085ab10
r18872:35e831d058c7
/*
 * This file is part of OpenTTD.
 * 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.
 * 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.
 * 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/>.
 */

/** @file goal_gui.cpp GUI for goals. */

#include "stdafx.h"
#include "industry.h"
#include "town.h"
#include "window_gui.h"
#include "strings_func.h"
#include "date_func.h"
#include "viewport_func.h"
#include "gui.h"
#include "goal_base.h"
#include "core/geometry_func.hpp"
#include "company_func.h"
#include "company_base.h"
#include "company_gui.h"
#include "story_base.h"
#include "command_func.h"
#include "string_func.h"
#include "goal_cmd.h"

#include "widgets/goal_widget.h"

#include "table/strings.h"

#include "safeguards.h"

/** Goal list columns. */
enum GoalColumn {
	GC_GOAL = 0, ///< Goal text column.
	GC_PROGRESS, ///< Goal progress column.
};

/** Window for displaying goals. */
struct GoalListWindow : public Window {
	Scrollbar *vscroll; ///< Reference to the scrollbar widget.

	GoalListWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
	{
		this->CreateNestedTree();
		this->vscroll = this->GetScrollbar(WID_GOAL_SCROLLBAR);
		this->FinishInitNested(window_number);
		this->owner = (Owner)this->window_number;
		NWidgetStacked *wi = this->GetWidget<NWidgetStacked>(WID_GOAL_SELECT_BUTTONS);
		wi->SetDisplayedPlane(window_number == INVALID_COMPANY ? 1 : 0);
		this->OnInvalidateData(0);
	}

	void SetStringParameters(int widget) const override
	{
		if (widget != WID_GOAL_CAPTION) return;

		if (this->window_number == INVALID_COMPANY) {
			SetDParam(0, STR_GOALS_SPECTATOR_CAPTION);
		} else {
			SetDParam(0, STR_GOALS_CAPTION);
			SetDParam(1, this->window_number);
		}
	}

	void OnClick(Point pt, int widget, int click_count) override
	{
		switch (widget) {
			case WID_GOAL_GLOBAL_BUTTON:
				ShowGoalsList(INVALID_COMPANY);
				break;

			case WID_GOAL_COMPANY_BUTTON:
				ShowGoalsList(_local_company);
				break;

			case WID_GOAL_LIST: {
				int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_GOAL_LIST, WD_FRAMERECT_TOP);
				for (const Goal *s : Goal::Iterate()) {
					if (s->company == this->window_number) {
						if (y == 0) {
							this->HandleClick(s);
							return;
						}
						y--;
					}
				}
				break;
			}

			default:
				break;
		}
	}

	/**
	 * Handle clicking at a goal.
	 * @param s #Goal clicked at.
	 */
	void HandleClick(const Goal *s)
	{
		/* Determine dst coordinate for goal and try to scroll to it. */
		TileIndex xy;
		switch (s->type) {
			case GT_NONE: return;

			case GT_COMPANY:
				/* s->dst here is not a tile, but a CompanyID.
				 * Show the window with the overview of the company instead. */
				ShowCompany((CompanyID)s->dst);
				return;

			case GT_TILE:
				if (!IsValidTile(s->dst)) return;
				xy = s->dst;
				break;

			case GT_INDUSTRY:
				if (!Industry::IsValidID(s->dst)) return;
				xy = Industry::Get(s->dst)->location.tile;
				break;

			case GT_TOWN:
				if (!Town::IsValidID(s->dst)) return;
				xy = Town::Get(s->dst)->xy;
				break;

			case GT_STORY_PAGE: {
				if (!StoryPage::IsValidID(s->dst)) return;

				/* Verify that:
				 * - if global goal: story page must be global.
				 * - if company goal: story page must be global or of the same company.
				 */
				CompanyID goal_company = s->company;
				CompanyID story_company = StoryPage::Get(s->dst)->company;
				if (goal_company == INVALID_COMPANY ? story_company != INVALID_COMPANY : story_company != INVALID_COMPANY && story_company != goal_company) return;

				ShowStoryBook((CompanyID)this->window_number, s->dst);
				return;
			}

			default: NOT_REACHED();
		}

		if (_ctrl_pressed) {
			ShowExtraViewportWindow(xy);
		} else {
			ScrollMainWindowToTile(xy);
		}
	}

	/**
	 * Count the number of lines in this window.
	 * @return the number of lines.
	 */
	uint CountLines()
	{
		/* Count number of (non) awarded goals. */
		uint num = 0;
		for (const Goal *s : Goal::Iterate()) {
			if (s->company == this->window_number) num++;
		}

		/* Count the 'none' lines. */
		if (num == 0) num = 1;

		return num;
	}

	void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
	{
		if (widget != WID_GOAL_LIST) return;
		Dimension d = GetStringBoundingBox(STR_GOALS_NONE);

		resize->height = d.height;

		d.height *= 5;
		d.width += padding.width + WD_FRAMERECT_RIGHT + WD_FRAMERECT_LEFT;
		d.height += padding.height + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
		*size = maxdim(*size, d);
	}

	/**
	 * Draws a given column of the goal list.
	 * @param column Which column to draw.
	 * @param wid Pointer to the goal list widget.
	 * @param progress_col_width Width of the progress column.
	 * @return max width of drawn text
	 */
	void DrawListColumn(GoalColumn column, NWidgetBase *wid, uint progress_col_width) const
	{
		/* Get column draw area. */
		int y = wid->pos_y + WD_FRAMERECT_TOP;
		int x = wid->pos_x + WD_FRAMERECT_LEFT;
		int right = x + wid->current_x - WD_FRAMERECT_RIGHT;
		bool rtl = _current_text_dir == TD_RTL;

		int pos = -this->vscroll->GetPosition();
		const int cap = this->vscroll->GetCapacity();

		uint num = 0;
		for (const Goal *s : Goal::Iterate()) {
			if (s->company == this->window_number) {
				if (IsInsideMM(pos, 0, cap)) {
					switch (column) {
						case GC_GOAL: {
							/* Display the goal. */
							SetDParamStr(0, s->text);
							uint width_reduction = progress_col_width > 0 ? progress_col_width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT : 0;
							DrawString(x + (rtl ? width_reduction : 0), right - (rtl ? 0 : width_reduction), y + pos * FONT_HEIGHT_NORMAL, STR_GOALS_TEXT);
							break;
						}

						case GC_PROGRESS:
							if (s->progress != nullptr) {
								SetDParamStr(0, s->progress);
								StringID str = s->completed ? STR_GOALS_PROGRESS_COMPLETE : STR_GOALS_PROGRESS;
								int progress_x = x;
								int progress_right = rtl ? x + progress_col_width : right;
								DrawString(progress_x, progress_right, y + pos * FONT_HEIGHT_NORMAL, str, TC_FROMSTRING, SA_RIGHT | SA_FORCE);
							}
							break;
					}
				}
				pos++;
				num++;
			}
		}

		if (num == 0) {
			if (column == GC_GOAL && IsInsideMM(pos, 0, cap)) {
				DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_GOALS_NONE);
			}
			pos++;
		}
	}

	void OnPaint() override
	{
		this->DrawWidgets();

		if (this->IsShaded()) return; // Don't draw anything when the window is shaded.

		/* Calculate progress column width. */
		uint max_width = 0;
		for (const Goal *s : Goal::Iterate()) {
			if (s->progress != nullptr) {
				SetDParamStr(0, s->progress);
				StringID str = s->completed ? STR_GOALS_PROGRESS_COMPLETE : STR_GOALS_PROGRESS;
				uint str_width = GetStringBoundingBox(str).width;
				if (str_width > max_width) max_width = str_width;
			}
		}

		NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_GOAL_LIST);
		uint progress_col_width = std::min(max_width, wid->current_x);

		/* Draw goal list. */
		this->DrawListColumn(GC_PROGRESS, wid, progress_col_width);
		this->DrawListColumn(GC_GOAL, wid, progress_col_width);

	}

	void OnResize() override
	{
		this->vscroll->SetCapacityFromWidget(this, WID_GOAL_LIST);
	}

	/**
	 * Some data on this window has become invalid.
	 * @param data Information about the changed data.
	 * @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.
	 */
	void OnInvalidateData(int data = 0, bool gui_scope = true) override
	{
		if (!gui_scope) return;
		this->vscroll->SetCount(this->CountLines());
		this->SetWidgetDisabledState(WID_GOAL_COMPANY_BUTTON, _local_company == COMPANY_SPECTATOR);
		this->SetWidgetDirty(WID_GOAL_COMPANY_BUTTON);
		this->SetWidgetDirty(WID_GOAL_LIST);
	}
};

/** Widgets of the #GoalListWindow. */
static const NWidgetPart _nested_goals_list_widgets[] = {
	NWidget(NWID_HORIZONTAL),
		NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
		NWidget(WWT_CAPTION, COLOUR_BROWN, WID_GOAL_CAPTION), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
		NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GOAL_SELECT_BUTTONS),
			NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_GOAL_GLOBAL_BUTTON), SetMinimalSize(50, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_GOALS_GLOBAL_BUTTON, STR_GOALS_GLOBAL_BUTTON_HELPTEXT),
			NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_GOAL_COMPANY_BUTTON), SetMinimalSize(50, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_GOALS_COMPANY_BUTTON, STR_GOALS_COMPANY_BUTTON_HELPTEXT),
		EndContainer(),
		NWidget(WWT_SHADEBOX, COLOUR_BROWN),
		NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
		NWidget(WWT_STICKYBOX, COLOUR_BROWN),
	EndContainer(),
	NWidget(NWID_HORIZONTAL),
		NWidget(WWT_PANEL, COLOUR_BROWN), SetDataTip(0x0, STR_GOALS_TOOLTIP_CLICK_ON_SERVICE_TO_CENTER), SetScrollbar(WID_GOAL_SCROLLBAR),
			NWidget(WWT_EMPTY, COLOUR_GREY, WID_GOAL_LIST), SetResize(1, 1), SetMinimalTextLines(2, 0), SetFill(1, 1), SetPadding(WD_FRAMERECT_TOP, 2, WD_FRAMETEXT_BOTTOM, 2),
		EndContainer(),
		NWidget(NWID_VERTICAL),
			NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_GOAL_SCROLLBAR),
			NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
		EndContainer(),
	EndContainer(),
};

static WindowDesc _goals_list_desc(
	WDP_AUTO, "list_goals", 500, 127,
	WC_GOALS_LIST, WC_NONE,
	0,
	_nested_goals_list_widgets, lengthof(_nested_goals_list_widgets)
);

/**
 * Open a goal list window.
 * @param company %Company to display the goals for, use #INVALID_COMPANY to display global goals.
 */
void ShowGoalsList(CompanyID company)
{
	if (!Company::IsValidID(company)) company = (CompanyID)INVALID_COMPANY;

	AllocateWindowDescFront<GoalListWindow>(&_goals_list_desc, company);
}

/** Ask a question about a goal. */
struct GoalQuestionWindow : public Window {
	char *question;     ///< Question to ask (private copy).
	int buttons;        ///< Number of valid buttons in #button.
	int button[3];      ///< Buttons to display.
	TextColour colour;  ///< Colour of the question text.

	GoalQuestionWindow(WindowDesc *desc, WindowNumber window_number, TextColour colour, uint32 button_mask, const char *question) : Window(desc), colour(colour)
	{
		this->question = stredup(question);

		/* Figure out which buttons we have to enable. */
		int n = 0;
		for (uint bit : SetBitIterator(button_mask)) {
			if (bit >= GOAL_QUESTION_BUTTON_COUNT) break;
			this->button[n++] = bit;
			if (n == 3) break;
		}
		this->buttons = n;
		assert(this->buttons < 4);

		this->CreateNestedTree();
		if (this->buttons == 0) {
			this->GetWidget<NWidgetStacked>(WID_GQ_BUTTONS)->SetDisplayedPlane(SZSP_HORIZONTAL);
			this->GetWidget<NWidgetStacked>(WID_GQ_BUTTON_SPACER)->SetDisplayedPlane(SZSP_HORIZONTAL);
		} else {
			this->GetWidget<NWidgetStacked>(WID_GQ_BUTTONS)->SetDisplayedPlane(this->buttons - 1);
			this->GetWidget<NWidgetStacked>(WID_GQ_BUTTON_SPACER)->SetDisplayedPlane(0);
		}
		this->FinishInitNested(window_number);
	}

	~GoalQuestionWindow()
	{
		free(this->question);
	}

	void SetStringParameters(int widget) const override
	{
		switch (widget) {
			case WID_GQ_BUTTON_1:
				SetDParam(0, STR_GOAL_QUESTION_BUTTON_CANCEL + this->button[0]);
				break;

			case WID_GQ_BUTTON_2:
				SetDParam(0, STR_GOAL_QUESTION_BUTTON_CANCEL + this->button[1]);
				break;

			case WID_GQ_BUTTON_3:
				SetDParam(0, STR_GOAL_QUESTION_BUTTON_CANCEL + this->button[2]);
				break;
		}
	}

	void OnClick(Point pt, int widget, int click_count) override
	{
		switch (widget) {
			case WID_GQ_BUTTON_1:
				Command<CMD_GOAL_QUESTION_ANSWER>::Post(this->window_number, this->button[0]);
				this->Close();
				break;

			case WID_GQ_BUTTON_2:
				Command<CMD_GOAL_QUESTION_ANSWER>::Post(this->window_number, this->button[1]);
				this->Close();
				break;

			case WID_GQ_BUTTON_3:
				Command<CMD_GOAL_QUESTION_ANSWER>::Post(this->window_number, this->button[2]);
				this->Close();
				break;
		}
	}

	void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
	{
		if (widget != WID_GQ_QUESTION) return;

		SetDParamStr(0, this->question);
		size->height = GetStringHeight(STR_JUST_RAW_STRING, size->width) + WD_PAR_VSEP_WIDE;
	}

	void DrawWidget(const Rect &r, int widget) const override
	{
		if (widget != WID_GQ_QUESTION) return;

		SetDParamStr(0, this->question);
		DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, STR_JUST_RAW_STRING, this->colour, SA_TOP | SA_HOR_CENTER);
	}
};

/** Widgets of the goal question window. */
static const NWidgetPart _nested_goal_question_widgets_question[] = {
	NWidget(NWID_HORIZONTAL),
		NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE),
		NWidget(WWT_CAPTION, COLOUR_LIGHT_BLUE, WID_GQ_CAPTION), SetDataTip(STR_GOAL_QUESTION_CAPTION_QUESTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
	EndContainer(),
	NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE),
		NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GQ_QUESTION), SetMinimalSize(300, 0), SetPadding(8, 8, 8, 8), SetFill(1, 0),
		NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTONS),
			NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(85, 10, 85),
				NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
			EndContainer(),
			NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(65, 10, 65),
				NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
				NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_2), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
			EndContainer(),
			NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(25, 10, 25),
				NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
				NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_2), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
				NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_3), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
			EndContainer(),
		EndContainer(),
		NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTON_SPACER),
			NWidget(NWID_SPACER), SetMinimalSize(0, 8),
		EndContainer(),
	EndContainer(),
};

static const NWidgetPart _nested_goal_question_widgets_info[] = {
	NWidget(NWID_HORIZONTAL),
		NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE),
		NWidget(WWT_CAPTION, COLOUR_LIGHT_BLUE, WID_GQ_CAPTION), SetDataTip(STR_GOAL_QUESTION_CAPTION_INFORMATION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
	EndContainer(),
	NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE),
		NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GQ_QUESTION), SetMinimalSize(300, 0), SetPadding(8, 8, 8, 8), SetFill(1, 0),
		NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTONS),
			NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(85, 10, 85),
				NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
			EndContainer(),
			NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(65, 10, 65),
				NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
				NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_2), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
			EndContainer(),
			NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(25, 10, 25),
				NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
				NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_2), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
				NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_3), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
			EndContainer(),
		EndContainer(),
		NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTON_SPACER),
			NWidget(NWID_SPACER), SetMinimalSize(0, 8),
		EndContainer(),
	EndContainer(),
};

static const NWidgetPart _nested_goal_question_widgets_warning[] = {
	NWidget(NWID_HORIZONTAL),
		NWidget(WWT_CLOSEBOX, COLOUR_YELLOW),
		NWidget(WWT_CAPTION, COLOUR_YELLOW, WID_GQ_CAPTION), SetDataTip(STR_GOAL_QUESTION_CAPTION_WARNING, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
	EndContainer(),
	NWidget(WWT_PANEL, COLOUR_YELLOW),
		NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GQ_QUESTION), SetMinimalSize(300, 0), SetPadding(8, 8, 8, 8), SetFill(1, 0),
		NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTONS),
			NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(85, 10, 85),
				NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
			EndContainer(),
			NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(65, 10, 65),
				NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
				NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_2), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
			EndContainer(),
			NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(25, 10, 25),
				NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
				NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_2), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
				NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_3), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
			EndContainer(),
		EndContainer(),
		NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTON_SPACER),
			NWidget(NWID_SPACER), SetMinimalSize(0, 8),
		EndContainer(),
	EndContainer(),
};

static const NWidgetPart _nested_goal_question_widgets_error[] = {
	NWidget(NWID_HORIZONTAL),
		NWidget(WWT_CLOSEBOX, COLOUR_RED),
		NWidget(WWT_CAPTION, COLOUR_RED, WID_GQ_CAPTION), SetDataTip(STR_GOAL_QUESTION_CAPTION_ERROR, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
	EndContainer(),
	NWidget(WWT_PANEL, COLOUR_RED),
		NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GQ_QUESTION), SetMinimalSize(300, 0), SetPadding(8, 8, 8, 8), SetFill(1, 0),
		NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTONS),
			NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(85, 10, 85),
				NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
			EndContainer(),
			NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(65, 10, 65),
				NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
				NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_2), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
			EndContainer(),
			NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(25, 10, 25),
				NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
				NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_2), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
				NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_3), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
			EndContainer(),
		EndContainer(),
		NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTON_SPACER),
			NWidget(NWID_SPACER), SetMinimalSize(0, 8),
		EndContainer(),
	EndContainer(),
};

static WindowDesc _goal_question_list_desc[] = {
	{
		WDP_CENTER, nullptr, 0, 0,
		WC_GOAL_QUESTION, WC_NONE,
		WDF_CONSTRUCTION,
		_nested_goal_question_widgets_question, lengthof(_nested_goal_question_widgets_question),
	},
	{
		WDP_CENTER, nullptr, 0, 0,
		WC_GOAL_QUESTION, WC_NONE,
		WDF_CONSTRUCTION,
		_nested_goal_question_widgets_info, lengthof(_nested_goal_question_widgets_info),
	},
	{
		WDP_CENTER, nullptr, 0, 0,
		WC_GOAL_QUESTION, WC_NONE,
		WDF_CONSTRUCTION,
		_nested_goal_question_widgets_warning, lengthof(_nested_goal_question_widgets_warning),
	},
	{
		WDP_CENTER, nullptr, 0, 0,
		WC_GOAL_QUESTION, WC_NONE,
		WDF_CONSTRUCTION,
		_nested_goal_question_widgets_error, lengthof(_nested_goal_question_widgets_error),
	},
};

/**
 * Display a goal question.
 * @param id Window number to use.
 * @param type Type of question.
 * @param button_mask Buttons to display.
 * @param question Question to ask.
 */
void ShowGoalQuestion(uint16 id, byte type, uint32 button_mask, const char *question)
{
	assert(type < GQT_END);
	new GoalQuestionWindow(&_goal_question_list_desc[type], id, type == 3 ? TC_WHITE : TC_BLACK, button_mask, question);
}