Files @ r9652:8dc9b501f076
Branch filter:

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

rubidium
(svn r13719) -Codechange: rename IsValidPlayer to IsValidPlayerID in line with all other structs/classes that are in a pool.
  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
r5584:545d748cc681
r5584:545d748cc681
r9111:983de9c5a848
r6348:a905c3e6d8fa
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r8107:82461791b7a2
r8107:82461791b7a2
r5584:545d748cc681
r5584:545d748cc681
r8114:866ed489ed98
r8131:7a50db7be0ff
r8213:466402e95092
r8214:9a3935f9ef4e
r8224:194097dc7288
r9457:ecfeb802c57a
r5584:545d748cc681
r8264:d493cb51fe8a
r8264:d493cb51fe8a
r8264:d493cb51fe8a
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r6377:8544b7560945
r5584:545d748cc681
r5634:5809aab23a85
r5584:545d748cc681
r6103:436b6b65ad3d
r9648:996b8efd5c66
r9648:996b8efd5c66
r9648:996b8efd5c66
r9648:996b8efd5c66
r9648:996b8efd5c66
r9648:996b8efd5c66
r9648:996b8efd5c66
r6139:0128edd33976
r9648:996b8efd5c66
r9648:996b8efd5c66
r9648:996b8efd5c66
r9648:996b8efd5c66
r6139:0128edd33976
r9648:996b8efd5c66
r9648:996b8efd5c66
r9648:996b8efd5c66
r9648:996b8efd5c66
r6139:0128edd33976
r6139:0128edd33976
r6139:0128edd33976
r6377:8544b7560945
r6103:436b6b65ad3d
r6103:436b6b65ad3d
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r6377:8544b7560945
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5643:f4144f9d438e
r5584:545d748cc681
r6377:8544b7560945
r5584:545d748cc681
r5584:545d748cc681
r5634:5809aab23a85
r5584:545d748cc681
r6377:8544b7560945
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r9648:996b8efd5c66
r9648:996b8efd5c66
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r6377:8544b7560945
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r6377:8544b7560945
r6377:8544b7560945
r7928:a80e7e05d6c5
r5584:545d748cc681
r5584:545d748cc681
r5638:174d9d13ce21
r9648:996b8efd5c66
r9648:996b8efd5c66
r6377:8544b7560945
r5584:545d748cc681
r6377:8544b7560945
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9273:0df9c11598cc
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r7011:f744ff7cd04b
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r9207:1a7e1796f6bf
r5584:545d748cc681
r8025:bed915e3f346
r5584:545d748cc681
r8025:bed915e3f346
r8025:bed915e3f346
r8025:bed915e3f346
r8025:bed915e3f346
r8025:bed915e3f346
r8025:bed915e3f346
r8025:bed915e3f346
r8025:bed915e3f346
r8025:bed915e3f346
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r8025:bed915e3f346
r5584:545d748cc681
r7341:72820788b006
r5893:6c4fd9987e0f
r8019:cc25a5b61a28
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r9207:1a7e1796f6bf
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r9207:1a7e1796f6bf
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r9273:0df9c11598cc
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r6229:a69564e4eb2e
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r9207:1a7e1796f6bf
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r9207:1a7e1796f6bf
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r9648:996b8efd5c66
r9207:1a7e1796f6bf
r9648:996b8efd5c66
r9648:996b8efd5c66
r9207:1a7e1796f6bf
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r8025:bed915e3f346
r5584:545d748cc681
r8025:bed915e3f346
r8025:bed915e3f346
r8025:bed915e3f346
r8025:bed915e3f346
r8025:bed915e3f346
r8025:bed915e3f346
r8591:b9b5c1c437ed
r8025:bed915e3f346
r8025:bed915e3f346
r8025:bed915e3f346
r8025:bed915e3f346
r8025:bed915e3f346
r8025:bed915e3f346
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r8025:bed915e3f346
r5584:545d748cc681
r7341:72820788b006
r5893:6c4fd9987e0f
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9457:ecfeb802c57a
r9457:ecfeb802c57a
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9457:ecfeb802c57a
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r9207:1a7e1796f6bf
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r5584:545d748cc681
r9207:1a7e1796f6bf
r5584:545d748cc681
/* $Id$ */

/** @file newgrf_gui.cpp GUI to change NewGRF settings. */

#include "stdafx.h"
#include "openttd.h"
#include "variables.h"
#include "gui.h"
#include "window_gui.h"
#include "textbuf_gui.h"
#include "newgrf.h"
#include "newgrf_config.h"
#include "strings_func.h"
#include "window_func.h"
#include "core/alloc_func.hpp"
#include "string_func.h"
#include "gfx_func.h"
#include "gamelog.h"

#include "table/strings.h"
#include "table/sprites.h"

/** Parse an integerlist string and set each found value
 * @param p the string to be parsed. Each element in the list is seperated by a
 * comma or a space character
 * @param items pointer to the integerlist-array that will be filled with values
 * @param maxitems the maximum number of elements the integerlist-array has
 * @return returns the number of items found, or -1 on an error */
static int parse_intlist(const char *p, int *items, int maxitems)
{
	int n = 0, v;
	char *end;

	for (;;) {
		v = strtol(p, &end, 0);
		if (p == end || n == maxitems) return -1;
		p = end;
		items[n++] = v;
		if (*p == '\0') break;
		if (*p != ',' && *p != ' ') return -1;
		p++;
	}

	return n;
}


static void ShowNewGRFInfo(const GRFConfig *c, uint x, uint y, uint w, uint bottom, bool show_params)
{
	char buff[256];

	if (c->error != NULL) {
		char message[512];
		if (c->error->custom_message == NULL) {
			SetDParamStr(0, c->filename);
			SetDParamStr(1, c->error->data);
			for (uint i = 0; i < c->error->num_params; i++) {
				uint32 param = 0;
				byte param_number = c->error->param_number[i];

				if (param_number < c->num_params) param = c->param[param_number];

				SetDParam(2 + i, param);
			}

			GetString(message, c->error->message, lastof(message));
		} else {
			SetDParamStr(0, c->error->custom_message);
			GetString(message, STR_JUST_RAW_STRING, lastof(message));
		}

		SetDParamStr(0, message);
		y += DrawStringMultiLine(x, y, c->error->severity, w, bottom - y);
	}

	/* Draw filename or not if it is not known (GRF sent over internet) */
	if (c->filename != NULL) {
		SetDParamStr(0, c->filename);
		y += DrawStringMultiLine(x, y, STR_NEWGRF_FILENAME, w, bottom - y);
	}

	/* Prepare and draw GRF ID */
	snprintf(buff, lengthof(buff), "%08X", BSWAP32(c->grfid));
	SetDParamStr(0, buff);
	y += DrawStringMultiLine(x, y, STR_NEWGRF_GRF_ID, w, bottom - y);

	/* Prepare and draw MD5 sum */
	md5sumToString(buff, lastof(buff), c->md5sum);
	SetDParamStr(0, buff);
	y += DrawStringMultiLine(x, y, STR_NEWGRF_MD5SUM, w, bottom - y);

	/* Show GRF parameter list */
	if (show_params) {
		if (c->num_params > 0) {
			GRFBuildParamList(buff, c, lastof(buff));
			SetDParam(0, STR_JUST_RAW_STRING);
			SetDParamStr(1, buff);
		} else {
			SetDParam(0, STR_01A9_NONE);
		}
		y += DrawStringMultiLine(x, y, STR_NEWGRF_PARAMETER, w, bottom - y);
	}

	/* Show flags */
	if (c->status == GCS_NOT_FOUND)        y += DrawStringMultiLine(x, y, STR_NEWGRF_NOT_FOUND, w, bottom - y);
	if (c->status == GCS_DISABLED)         y += DrawStringMultiLine(x, y, STR_NEWGRF_DISABLED, w, bottom - y);
	if (HasBit(c->flags, GCF_COMPATIBLE)) y += DrawStringMultiLine(x, y, STR_NEWGRF_COMPATIBLE_LOADED, w, bottom - y);

	/* Draw GRF info if it exists */
	if (c->info != NULL && !StrEmpty(c->info)) {
		SetDParam(0, STR_JUST_RAW_STRING);
		SetDParamStr(1, c->info);
		y += DrawStringMultiLine(x, y, STR_02BD, w, bottom - y);
	} else {
		y += DrawStringMultiLine(x, y, STR_NEWGRF_NO_INFO, w, bottom - y);
	}
}


/**
 * Window for adding NewGRF files
 */
struct NewGRFAddWindow : public Window {
	/* Names of the add a newgrf window widgets */
	enum AddNewGRFWindowWidgets {
		ANGRFW_CLOSEBOX = 0,
		ANGRFW_CAPTION,
		ANGRFW_BACKGROUND,
		ANGRFW_GRF_LIST,
		ANGRFW_SCROLLBAR,
		ANGRFW_GRF_INFO,
		ANGRFW_ADD,
		ANGRFW_RESCAN,
		ANGRFW_RESIZE,
	};

	GRFConfig **list;
	const GRFConfig *sel;

	NewGRFAddWindow(const WindowDesc *desc, GRFConfig **list) : Window(desc, 0)
	{
		this->list = list;
		this->resize.step_height = 10;

		this->FindWindowPlacementAndResize(desc);
	}

	virtual void OnPaint()
	{
		const GRFConfig *c;
		const Widget *wl = &this->widget[ANGRFW_GRF_LIST];
		int n = 0;

		/* Count the number of GRFs */
		for (c = _all_grfs; c != NULL; c = c->next) n++;

		this->vscroll.cap = (wl->bottom - wl->top) / 10;
		SetVScrollCount(this, n);

		this->SetWidgetDisabledState(ANGRFW_ADD, this->sel == NULL || this->sel->IsOpenTTDBaseGRF());
		this->DrawWidgets();

		GfxFillRect(wl->left + 1, wl->top + 1, wl->right, wl->bottom, 0xD7);

		uint y = wl->top + 1;
		for (c = _all_grfs, n = 0; c != NULL && n < (this->vscroll.pos + this->vscroll.cap); c = c->next, n++) {
			if (n >= this->vscroll.pos) {
				bool h = c == this->sel;
				const char *text = (c->name != NULL && !StrEmpty(c->name)) ? c->name : c->filename;

				/* Draw selection background */
				if (h) GfxFillRect(3, y, this->width - 15, y + 9, 156);
				DoDrawStringTruncated(text, 4, y, h ? TC_WHITE : TC_ORANGE, this->width - 18);
				y += 10;
			}
		}

		if (this->sel != NULL) {
			const Widget *wi = &this->widget[ANGRFW_GRF_INFO];
			ShowNewGRFInfo(this->sel, wi->left + 2, wi->top + 2, wi->right - wi->left - 2, wi->bottom, false);
		}
	}

	virtual void OnDoubleClick(Point pt, int widget)
	{
		if (widget == ANGRFW_GRF_LIST) this->OnClick(pt, ANGRFW_ADD);
	}

	virtual void OnClick(Point pt, int widget)
	{
		switch (widget) {
			case ANGRFW_GRF_LIST: {
				/* Get row... */
				const GRFConfig *c;
				uint i = (pt.y - this->widget[ANGRFW_GRF_LIST].top) / 10 + this->vscroll.pos;

				for (c = _all_grfs; c != NULL && i > 0; c = c->next, i--) {}
				this->sel = c;
				this->SetDirty();
				break;
			}

			case ANGRFW_ADD: // Add selection to list
				if (this->sel != NULL) {
					const GRFConfig *src = this->sel;
					GRFConfig **list;

					/* Find last entry in the list, checking for duplicate grfid on the way */
					for (list = this->list; *list != NULL; list = &(*list)->next) {
						if ((*list)->grfid == src->grfid) {
							ShowErrorMessage(INVALID_STRING_ID, STR_NEWGRF_DUPLICATE_GRFID, 0, 0);
							return;
						}
					}

					/* Copy GRF details from scanned list */
					GRFConfig *c = CallocT<GRFConfig>(1);
					*c = *src;
					c->filename = strdup(src->filename);
					if (src->name      != NULL) c->name      = strdup(src->name);
					if (src->info      != NULL) c->info      = strdup(src->info);
					c->next = NULL;

					/* Append GRF config to configuration list */
					*list = c;

					DeleteWindowByClass(WC_SAVELOAD);
					InvalidateWindowData(WC_GAME_OPTIONS, 0);
				}
				break;

			case ANGRFW_RESCAN: // Rescan list
				this->sel = NULL;
				ScanNewGRFFiles();
				this->SetDirty();
				break;
		}
	}
};

/* Widget definition for the add a newgrf window */
static const Widget _newgrf_add_dlg_widgets[] = {
{   WWT_CLOSEBOX,    RESIZE_NONE, 14,   0,  10,   0,  13, STR_00C5,                STR_018B_CLOSE_WINDOW },           // ANGRFW_CLOSEBOX
{    WWT_CAPTION,   RESIZE_RIGHT, 14,  11, 306,   0,  13, STR_NEWGRF_ADD_CAPTION,  STR_018C_WINDOW_TITLE_DRAG_THIS }, // ANGRFW_CAPTION
{      WWT_PANEL,      RESIZE_RB, 14,   0, 294,  14, 121, 0x0,                     STR_NULL },                        // ANGRFW_BACKGROUND
{      WWT_INSET,      RESIZE_RB, 14,   2, 292,  16, 119, 0x0,                     STR_NULL },                        // ANGRFW_GRF_LIST
{  WWT_SCROLLBAR,     RESIZE_LRB, 14, 295, 306,  14, 121, 0x0,                     STR_NULL },                        // ANGRFW_SCROLLBAR
{      WWT_PANEL,     RESIZE_RTB, 14,   0, 306, 122, 224, 0x0,                     STR_NULL },                        // ANGRFW_GRF_INFO
{ WWT_PUSHTXTBTN,     RESIZE_RTB, 14,   0, 146, 225, 236, STR_NEWGRF_ADD_FILE,     STR_NEWGRF_ADD_FILE_TIP },         // ANGRFW_ADD
{ WWT_PUSHTXTBTN,    RESIZE_LRTB, 14, 147, 294, 225, 236, STR_NEWGRF_RESCAN_FILES, STR_NEWGRF_RESCAN_FILES_TIP },     // ANGRFW_RESCAN
{  WWT_RESIZEBOX,    RESIZE_LRTB, 14, 295, 306, 225, 236, 0x0,                     STR_RESIZE_BUTTON },               // ANGRFW_RESIZE
{   WIDGETS_END },
};

/* Window definition for the add a newgrf window */
static const WindowDesc _newgrf_add_dlg_desc = {
	WDP_CENTER, WDP_CENTER, 307, 237, 307, 337,
	WC_SAVELOAD, WC_NONE,
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
	_newgrf_add_dlg_widgets,
};


static void NewGRFConfirmationCallback(Window *w, bool confirmed);

/**
 * Window for showing NewGRF files
 */
struct NewGRFWindow : public Window {
	/* Names of the manage newgrfs window widgets */
	enum ShowNewGRFStateWidgets {
		SNGRFS_CLOSEBOX = 0,
		SNGRFS_CAPTION,
		SNGRFS_BACKGROUND,
		SNGRFS_ADD,
		SNGRFS_REMOVE,
		SNGRFS_MOVE_UP,
		SNGRFS_MOVE_DOWN,
		SNGRFS_FILE_LIST,
		SNGRFS_SCROLLBAR,
		SNGRFS_NEWGRF_INFO,
		SNGRFS_SET_PARAMETERS,
		SNGRFS_APPLY_CHANGES,
		SNGRFS_RESIZE,
	};

	GRFConfig **orig_list; ///< grf list the window is shown with
	GRFConfig *list;       ///< temporary grf list to which changes are made
	GRFConfig *sel;        ///< selected grf item
	bool editable;         ///< is the window editable
	bool show_params;      ///< are the grf-parameters shown in the info-panel
	bool execute;          ///< on pressing 'apply changes' are grf changes applied immediately, or only list is updated

	NewGRFWindow(const WindowDesc *desc, bool editable, bool show_params, bool exec_changes, GRFConfig **config) : Window(desc, 0)
	{
		this->resize.step_height = 14;
		this->sel         = NULL;
		this->list        = NULL;
		this->orig_list   = config;
		this->editable    = editable;
		this->execute     = exec_changes;
		this->show_params = show_params;

		CopyGRFConfigList(&this->list, *config, false);

		this->FindWindowPlacementAndResize(desc);
		this->SetupNewGRFWindow();
	}

	~NewGRFWindow()
	{
		if (!this->execute) {
			CopyGRFConfigList(this->orig_list, this->list, true);
			ResetGRFConfig(false);
			ReloadNewGRFData();
		}

		/* Remove the temporary copy of grf-list used in window */
		ClearGRFConfigList(&this->list);
	}

	void SetupNewGRFWindow()
	{
		const GRFConfig *c;
		int i;

		for (c = this->list, i = 0; c != NULL; c = c->next, i++) {}

		this->vscroll.cap = (this->widget[SNGRFS_FILE_LIST].bottom - this->widget[SNGRFS_FILE_LIST].top) / 14 + 1;
		SetVScrollCount(this, i);

		this->SetWidgetDisabledState(SNGRFS_ADD, !this->editable);
		this->SetWidgetDisabledState(SNGRFS_APPLY_CHANGES, !this->editable);
	}

	virtual void OnPaint()
	{
		bool disable_all = this->sel == NULL || !this->editable;

		this->SetWidgetsDisabledState(disable_all,
			SNGRFS_REMOVE,
			SNGRFS_MOVE_UP,
			SNGRFS_MOVE_DOWN,
			WIDGET_LIST_END
		);
		this->SetWidgetDisabledState(SNGRFS_SET_PARAMETERS, !this->show_params || disable_all);

		if (!disable_all) {
			/* All widgets are now enabled, so disable widgets we can't use */
			if (this->sel == this->list)       this->DisableWidget(SNGRFS_MOVE_UP);
			if (this->sel->next == NULL)       this->DisableWidget(SNGRFS_MOVE_DOWN);
			if (this->sel->IsOpenTTDBaseGRF()) this->DisableWidget(SNGRFS_REMOVE);
		}

		this->DrawWidgets();

		/* Draw NewGRF list */
		int y = this->widget[SNGRFS_FILE_LIST].top;
		int i = 0;
		for (const GRFConfig *c = this->list; c != NULL; c = c->next, i++) {
			if (i >= this->vscroll.pos && i < this->vscroll.pos + this->vscroll.cap) {
				const char *text = (c->name != NULL && !StrEmpty(c->name)) ? c->name : c->filename;
				SpriteID pal;
				byte txtoffset;

				/* Pick a colour */
				switch (c->status) {
					case GCS_NOT_FOUND:
					case GCS_DISABLED:
						pal = PALETTE_TO_RED;
						break;
					case GCS_ACTIVATED:
						pal = PALETTE_TO_GREEN;
						break;
					default:
						pal = PALETTE_TO_BLUE;
						break;
				}

				/* Do not show a "not-failure" colour when it actually failed to load */
				if (pal != PALETTE_TO_RED) {
					if (HasBit(c->flags, GCF_STATIC)) {
						pal = PALETTE_TO_GREY;
					} else if (HasBit(c->flags, GCF_COMPATIBLE)) {
						pal = PALETTE_TO_ORANGE;
					}
				}

				DrawSprite(SPR_SQUARE, pal, 5, y + 2);
				if (c->error != NULL) DrawSprite(SPR_WARNING_SIGN, 0, 20, y + 2);
				txtoffset = c->error != NULL ? 35 : 25;
				DoDrawStringTruncated(text, txtoffset, y + 3, this->sel == c ? TC_WHITE : TC_BLACK, this->width - txtoffset - 10);
				y += 14;
			}
		}

		if (this->sel != NULL) {
			/* Draw NewGRF file info */
			const Widget *wi = &this->widget[SNGRFS_NEWGRF_INFO];
			ShowNewGRFInfo(this->sel, wi->left + 2, wi->top + 2, wi->right - wi->left - 2, wi->bottom, this->show_params);
		}
	}

	virtual void OnClick(Point pt, int widget)
	{
		switch (widget) {
			case SNGRFS_ADD: // Add GRF
				DeleteWindowByClass(WC_SAVELOAD);
				new NewGRFAddWindow(&_newgrf_add_dlg_desc, &this->list);
				break;

			case SNGRFS_REMOVE: { // Remove GRF
				GRFConfig **pc, *c, *newsel;

				/* Choose the next GRF file to be the selected file */
				newsel = this->sel->next;

				for (pc = &this->list; (c = *pc) != NULL; pc = &c->next) {
					/* If the new selection is empty (i.e. we're deleting the last item
					 * in the list, pick the file just before the selected file */
					if (newsel == NULL && c->next == this->sel) newsel = c;

					if (c == this->sel) {
						*pc = c->next;
						free(c);
						break;
					}
				}

				this->sel = newsel;
				this->SetupNewGRFWindow();
				this->SetDirty();
				break;
			}

			case SNGRFS_MOVE_UP: { // Move GRF up
				GRFConfig **pc, *c;
				if (this->sel == NULL) break;

				for (pc = &this->list; (c = *pc) != NULL; pc = &c->next) {
					if (c->next == this->sel) {
						c->next = this->sel->next;
						this->sel->next = c;
						*pc = this->sel;
						break;
					}
				}
				this->SetDirty();
				break;
			}

			case SNGRFS_MOVE_DOWN: { // Move GRF down
				GRFConfig **pc, *c;
				if (this->sel == NULL) break;

				for (pc = &this->list; (c = *pc) != NULL; pc = &c->next) {
					if (c == this->sel) {
						*pc = c->next;
						c->next = c->next->next;
						(*pc)->next = c;
						break;
					}
				}
				this->SetDirty();
				break;
			}

			case SNGRFS_FILE_LIST: { // Select a GRF
				GRFConfig *c;
				uint i = (pt.y - this->widget[SNGRFS_FILE_LIST].top) / 14 + this->vscroll.pos;

				for (c = this->list; c != NULL && i > 0; c = c->next, i--) {}
				this->sel = c;

				this->SetDirty();
				break;
			}

			case SNGRFS_APPLY_CHANGES: // Apply changes made to GRF list
				if (this->execute) {
					ShowQuery(
						STR_POPUP_CAUTION_CAPTION,
						STR_NEWGRF_CONFIRMATION_TEXT,
						this,
						NewGRFConfirmationCallback
					);
				} else {
					CopyGRFConfigList(this->orig_list, this->list, true);
					ResetGRFConfig(false);
					ReloadNewGRFData();
				}
				break;

			case SNGRFS_SET_PARAMETERS: { // Edit parameters
				if (this->sel == NULL) break;

				static char buff[512];
				GRFBuildParamList(buff, this->sel, lastof(buff));
				SetDParamStr(0, buff);
				ShowQueryString(STR_JUST_RAW_STRING, STR_NEWGRF_PARAMETER_QUERY, 63, 250, this, CS_ALPHANUMERAL);
				break;
			}
		}
	}

	virtual void OnQueryTextFinished(char *str)
	{
		if (str == NULL) return;

		/* Parse our new "int list" */
		GRFConfig *c = this->sel;
		c->num_params = parse_intlist(str, (int*)c->param, lengthof(c->param));

		/* parse_intlist returns -1 on error */
		if (c->num_params == (byte)-1) c->num_params = 0;

		this->SetDirty();
	}

	virtual void OnResize(Point new_size, Point delta)
	{
		if (delta.x != 0) {
			ResizeButtons(this, SNGRFS_ADD, SNGRFS_MOVE_DOWN);
			ResizeButtons(this, SNGRFS_SET_PARAMETERS, SNGRFS_APPLY_CHANGES);
		}

		this->vscroll.cap += delta.y / 14;
		this->widget[SNGRFS_FILE_LIST].data = (this->vscroll.cap << 8) + 1;

		this->SetupNewGRFWindow();
	}

	virtual void OnInvalidateData(int data = 0)
	{
		this->SetupNewGRFWindow();
	}
};

/* Widget definition of the manage newgrfs window */
static const Widget _newgrf_widgets[] = {
{   WWT_CLOSEBOX,  RESIZE_NONE, 10,   0,  10,   0,  13, STR_00C5,                    STR_018B_CLOSE_WINDOW },            // SNGRFS_CLOSEBOX
{    WWT_CAPTION, RESIZE_RIGHT, 10,  11, 299,   0,  13, STR_NEWGRF_SETTINGS_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS },  // SNGRFS_CAPTION
{      WWT_PANEL, RESIZE_RIGHT, 10,   0, 299,  14,  29, STR_NULL,                    STR_NULL },                         // SNGRFS_BACKGROUND
{ WWT_PUSHTXTBTN,  RESIZE_NONE,  3,  10,  79,  16,  27, STR_NEWGRF_ADD,              STR_NEWGRF_ADD_TIP },               // SNGRFS_ADD
{ WWT_PUSHTXTBTN,  RESIZE_NONE,  3,  80, 149,  16,  27, STR_NEWGRF_REMOVE,           STR_NEWGRF_REMOVE_TIP },            // SNGRFS_REMOVE
{ WWT_PUSHTXTBTN,  RESIZE_NONE,  3, 150, 219,  16,  27, STR_NEWGRF_MOVEUP,           STR_NEWGRF_MOVEUP_TIP },            // SNGRFS_MOVE_UP
{ WWT_PUSHTXTBTN, RESIZE_RIGHT,  3, 220, 289,  16,  27, STR_NEWGRF_MOVEDOWN,         STR_NEWGRF_MOVEDOWN_TIP },          // SNGRFS_MOVE_DOWN
{     WWT_MATRIX,    RESIZE_RB, 10,   0, 287,  30,  99, 0x501,                       STR_NEWGRF_FILE_TIP },              // SNGRFS_FILE_LIST
{  WWT_SCROLLBAR,   RESIZE_LRB, 10, 288, 299,  30,  99, 0x0,                         STR_0190_SCROLL_BAR_SCROLLS_LIST }, // SNGRFS_SCROLLBAR
{      WWT_PANEL,   RESIZE_RTB, 10,   0, 299, 100, 212, STR_NULL,                    STR_NULL },                         // SNGRFS_NEWGRF_INFO
{ WWT_PUSHTXTBTN,    RESIZE_TB, 10,   0, 143, 213, 224, STR_NEWGRF_SET_PARAMETERS,   STR_NULL },                         // SNGRFS_SET_PARAMETERS
{ WWT_PUSHTXTBTN,   RESIZE_RTB, 10, 144, 287, 213, 224, STR_NEWGRF_APPLY_CHANGES,    STR_NULL },                         // SNGRFS_APPLY_CHANGES
{  WWT_RESIZEBOX,  RESIZE_LRTB, 10, 288, 299, 213, 224, 0x0,                         STR_RESIZE_BUTTON },                // SNGRFS_RESIZE
{ WIDGETS_END },
};

/* Window definition of the manage newgrfs window */
static const WindowDesc _newgrf_desc = {
	WDP_CENTER, WDP_CENTER, 300, 225, 300, 225,
	WC_GAME_OPTIONS, WC_NONE,
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
	_newgrf_widgets,
};

/** Callback function for the newgrf 'apply changes' confirmation window
 * @param w Window which is calling this callback
 * @param confirmed boolean value, true when yes was clicked, false otherwise
 */
static void NewGRFConfirmationCallback(Window *w, bool confirmed)
{
	if (confirmed) {
		NewGRFWindow *nw = dynamic_cast<NewGRFWindow*>(w);
		GRFConfig *c;
		int i = 0;

		GamelogStartAction(GLAT_GRF);
		GamelogGRFUpdate(_grfconfig, nw->list); // log GRF changes
		CopyGRFConfigList(nw->orig_list, nw->list, false);
		ReloadNewGRFData();
		GamelogStopAction();

		/* Show new, updated list */
		for (c = nw->list; c != NULL && c != nw->sel; c = c->next, i++) {}
		CopyGRFConfigList(&nw->list, *nw->orig_list, false);
		for (c = nw->list; c != NULL && i > 0; c = c->next, i--) {}
		nw->sel = c;

		w->SetDirty();
	}
}



/** Setup the NewGRF gui
 * @param editable allow the user to make changes to the grfconfig in the window
 * @param show_params show information about what parameters are set for the grf files
 * @param exec_changes if changes are made to the list (editable is true), apply these
 *        changes immediately or only update the list
 * @param config pointer to a linked-list of grfconfig's that will be shown */
void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config)
{
	DeleteWindowByClass(WC_GAME_OPTIONS);
	new NewGRFWindow(&_newgrf_desc, editable, show_params, exec_changes, config);
}