newgrf_gui.c
author glx
Mon, 24 Sep 2007 03:08:47 +0000
branch0.5
changeset 5545 f42dc59a45f5
parent 5455 547cba149cbd
permissions -rw-r--r--
(svn r11153) [0.5] -Fix [FS#1251]: incorrect usage of {G} tag in slovak translation
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
     1
/* $Id$ */
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
     2
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
     3
#include "stdafx.h"
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
     4
#include "openttd.h"
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
     5
#include "functions.h"
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
     6
#include "variables.h"
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
     7
#include "gfx.h"
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
     8
#include "gui.h"
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
     9
#include "window.h"
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    10
#include "table/strings.h"
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    11
#include "table/sprites.h"
5352
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
    12
#include "newgrf.h"
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    13
#include "newgrf_config.h"
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    14
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    15
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    16
/** Parse an integerlist string and set each found value
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    17
 * @param p the string to be parsed. Each element in the list is seperated by a
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    18
 * comma or a space character
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    19
 * @param items pointer to the integerlist-array that will be filled with values
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    20
 * @param maxitems the maximum number of elements the integerlist-array has
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    21
 * @return returns the number of items found, or -1 on an error */
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    22
static int parse_intlist(const char *p, int *items, int maxitems)
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    23
{
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    24
	int n = 0, v;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    25
	char *end;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    26
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    27
	for (;;) {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    28
		v = strtol(p, &end, 0);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    29
		if (p == end || n == maxitems) return -1;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    30
		p = end;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    31
		items[n++] = v;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    32
		if (*p == '\0') break;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    33
		if (*p != ',' && *p != ' ') return -1;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    34
		p++;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    35
	}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    36
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    37
	return n;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    38
}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    39
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    40
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    41
static void ShowNewGRFInfo(const GRFConfig *c, uint x, uint y, uint w, bool show_params)
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    42
{
5416
87d5e006851b (svn r8180) -Backport from trunk (r8093, r8094, r8105, r8106, (r8107), r8111, r8165):
Darkvater
parents: 5366
diff changeset
    43
	char buff[256];
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    44
5339
7573f179efe8 (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5329
diff changeset
    45
	/* Draw filename or not if it is not known (GRF sent over internet) */
7573f179efe8 (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5329
diff changeset
    46
	if (c->filename != NULL) {
7573f179efe8 (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5329
diff changeset
    47
		SetDParamStr(0, c->filename);
7573f179efe8 (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5329
diff changeset
    48
		y += DrawStringMultiLine(x, y, STR_NEWGRF_FILENAME, w);
7573f179efe8 (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5329
diff changeset
    49
	}
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    50
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    51
	/* Prepare and draw GRF ID */
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    52
	snprintf(buff, lengthof(buff), "%08X", (uint32)BSWAP32(c->grfid));
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    53
	SetDParamStr(0, buff);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    54
	y += DrawStringMultiLine(x, y, STR_NEWGRF_GRF_ID, w);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    55
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    56
	/* Prepare and draw MD5 sum */
5416
87d5e006851b (svn r8180) -Backport from trunk (r8093, r8094, r8105, r8106, (r8107), r8111, r8165):
Darkvater
parents: 5366
diff changeset
    57
	md5sumToString(buff, lastof(buff), c->md5sum);
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    58
	SetDParamStr(0, buff);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    59
	y += DrawStringMultiLine(x, y, STR_NEWGRF_MD5SUM, w);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    60
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    61
	/* Show GRF parameter list */
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    62
	if (show_params) {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    63
		if (c->num_params > 0) {
5308
bad31e174cc6 (svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents: 5248
diff changeset
    64
			GRFBuildParamList(buff, c, lastof(buff));
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    65
			SetDParamStr(0, buff);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    66
		} else {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    67
			SetDParam(0, STR_01A9_NONE);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    68
		}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    69
		y += DrawStringMultiLine(x, y, STR_NEWGRF_PARAMETER, w);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    70
	}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    71
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    72
	/* Show flags */
5416
87d5e006851b (svn r8180) -Backport from trunk (r8093, r8094, r8105, r8106, (r8107), r8111, r8165):
Darkvater
parents: 5366
diff changeset
    73
	if (HASBIT(c->flags, GCF_NOT_FOUND))  y += DrawStringMultiLine(x, y, STR_NEWGRF_NOT_FOUND, w);
87d5e006851b (svn r8180) -Backport from trunk (r8093, r8094, r8105, r8106, (r8107), r8111, r8165):
Darkvater
parents: 5366
diff changeset
    74
	if (HASBIT(c->flags, GCF_DISABLED))   y += DrawStringMultiLine(x, y, STR_NEWGRF_DISABLED, w);
87d5e006851b (svn r8180) -Backport from trunk (r8093, r8094, r8105, r8106, (r8107), r8111, r8165):
Darkvater
parents: 5366
diff changeset
    75
	if (HASBIT(c->flags, GCF_COMPATIBLE)) y += DrawStringMultiLine(x, y, STR_NEWGRF_COMPATIBLE_LOADED, w);
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    76
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    77
	/* Draw GRF info if it exists */
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    78
	if (c->info != NULL && strlen(c->info) != 0) {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    79
		SetDParamStr(0, c->info);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    80
		y += DrawStringMultiLine(x, y, STR_02BD, w);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    81
	} else {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    82
		y += DrawStringMultiLine(x, y, STR_NEWGRF_NO_INFO, w);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    83
	}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    84
}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    85
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    86
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    87
/* Dialogue for adding NewGRF files to the selection */
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    88
typedef struct newgrf_add_d {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    89
	GRFConfig **list;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    90
	const GRFConfig *sel;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    91
} newgrf_add_d;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    92
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    93
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    94
static void NewGRFAddDlgWndProc(Window *w, WindowEvent *e)
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    95
{
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    96
	switch (e->event) {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    97
		case WE_PAINT: {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    98
			const GRFConfig *c;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    99
			int y;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   100
			int n = 0;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   101
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   102
			/* Count the number of GRFs */
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   103
			for (c = _all_grfs; c != NULL; c = c->next) n++;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   104
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   105
			w->vscroll.cap = (w->widget[3].bottom - w->widget[3].top) / 10;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   106
			SetVScrollCount(w, n);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   107
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   108
			SetWindowWidgetDisabledState(w, 6, WP(w, newgrf_add_d).sel == NULL);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   109
			DrawWindowWidgets(w);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   110
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   111
			GfxFillRect(w->widget[3].left + 1, w->widget[3].top + 1, w->widget[3].right, w->widget[3].bottom, 0xD7);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   112
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   113
			n = 0;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   114
			y = w->widget[3].top + 1;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   115
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   116
			for (c = _all_grfs; c != NULL; c = c->next) {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   117
				if (n >= w->vscroll.pos && n < w->vscroll.pos + w->vscroll.cap) {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   118
					bool h = c == WP(w, newgrf_add_d).sel;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   119
					const char *text = (c->name != NULL && strlen(c->name) != 0) ? c->name : c->filename;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   120
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   121
					/* Draw selection background */
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   122
					if (h) GfxFillRect(3, y, w->width - 15, y + 9, 156);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   123
					DoDrawStringTruncated(text, 4, y, h ? 0xC : 0x6, w->width - 18);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   124
					y += 10;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   125
				}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   126
				n++;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   127
			}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   128
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   129
			if (WP(w, newgrf_add_d).sel != NULL) {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   130
				const Widget *wi = &w->widget[5];
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   131
				ShowNewGRFInfo(WP(w, newgrf_add_d).sel, wi->left + 2, wi->top + 2, wi->right - wi->left - 2, false);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   132
			}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   133
			break;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   134
		}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   135
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   136
		case WE_CLICK:
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   137
			switch (e->we.click.widget) {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   138
				case 3: {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   139
					// Get row...
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   140
					const GRFConfig *c;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   141
					uint i = (e->we.click.pt.y - w->widget[3].top) / 10 + w->vscroll.pos;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   142
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   143
					for (c = _all_grfs; c != NULL && i > 0; c = c->next, i--);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   144
					WP(w, newgrf_add_d).sel = c;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   145
					SetWindowDirty(w);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   146
					break;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   147
				}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   148
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   149
				case 6: /* Add selection to list */
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   150
					if (WP(w, newgrf_add_d).sel != NULL) {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   151
						const GRFConfig *src = WP(w, newgrf_add_d).sel;
5243
a564347a939b (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   152
						GRFConfig **list, *c;
a564347a939b (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   153
a564347a939b (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   154
						/* Find last entry in the list, checking for duplicate grfid on the way */
a564347a939b (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   155
						for (list = WP(w, newgrf_add_d).list; *list != NULL; list = &(*list)->next) {
a564347a939b (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   156
							if ((*list)->grfid == src->grfid) {
a564347a939b (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   157
								ShowErrorMessage(INVALID_STRING_ID, STR_NEWGRF_DUPLICATE_GRFID, 0, 0);
a564347a939b (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   158
								return;
a564347a939b (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   159
							}
a564347a939b (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   160
						}
a564347a939b (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   161
a564347a939b (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   162
						/* Copy GRF details from scanned list */
a564347a939b (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   163
						c = calloc(1, sizeof(*c));
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   164
						*c = *src;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   165
						c->filename = strdup(src->filename);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   166
						if (src->name != NULL) c->name = strdup(src->name);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   167
						if (src->info != NULL) c->info = strdup(src->info);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   168
						c->next = NULL;
5243
a564347a939b (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   169
a564347a939b (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   170
						/* Append GRF config to configuration list */
a564347a939b (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   171
						*list = c;
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   172
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   173
						DeleteWindowByClass(WC_SAVELOAD);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   174
						InvalidateWindowData(WC_GAME_OPTIONS, 0);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   175
					}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   176
					break;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   177
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   178
				case 7: /* Rescan list */
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   179
					WP(w, newgrf_add_d).sel = NULL;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   180
					ScanNewGRFFiles();
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   181
					SetWindowDirty(w);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   182
					break;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   183
			}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   184
			break;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   185
	}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   186
}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   187
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   188
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   189
static const Widget _newgrf_add_dlg_widgets[] = {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   190
{   WWT_CLOSEBOX,    RESIZE_NONE, 14,   0,  10,   0,  13, STR_00C5,                STR_018B_CLOSE_WINDOW },
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   191
{    WWT_CAPTION,   RESIZE_RIGHT, 14,  11, 306,   0,  13, STR_NEWGRF_ADD_CAPTION,  STR_018C_WINDOW_TITLE_DRAG_THIS },
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   192
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   193
/* List of files */
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   194
{      WWT_PANEL,      RESIZE_RB, 14,   0, 294,  14, 221, 0x0,                     STR_NULL },
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   195
{      WWT_INSET,      RESIZE_RB, 14,   2, 292,  16, 219, 0x0,                     STR_NULL },
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   196
{  WWT_SCROLLBAR,     RESIZE_LRB, 14, 295, 306,  14, 221, 0x0,                     STR_NULL },
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   197
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   198
/* NewGRF file info */
5366
ef01dc923a5b (svn r7667) -Backport from trunk (r7549, r7551, r7554, r7582, r7594):
Darkvater
parents: 5352
diff changeset
   199
{      WWT_PANEL,     RESIZE_RTB, 14,   0, 306, 222, 324, 0x0,                     STR_NULL },
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   200
5366
ef01dc923a5b (svn r7667) -Backport from trunk (r7549, r7551, r7554, r7582, r7594):
Darkvater
parents: 5352
diff changeset
   201
{ WWT_PUSHTXTBTN,     RESIZE_RTB, 14,   0, 146, 325, 336, STR_NEWGRF_ADD_FILE,     STR_NEWGRF_ADD_FILE_TIP },
ef01dc923a5b (svn r7667) -Backport from trunk (r7549, r7551, r7554, r7582, r7594):
Darkvater
parents: 5352
diff changeset
   202
{ WWT_PUSHTXTBTN,    RESIZE_LRTB, 14, 147, 294, 325, 336, STR_NEWGRF_RESCAN_FILES, STR_NEWGRF_RESCAN_FILES_TIP },
ef01dc923a5b (svn r7667) -Backport from trunk (r7549, r7551, r7554, r7582, r7594):
Darkvater
parents: 5352
diff changeset
   203
{  WWT_RESIZEBOX,    RESIZE_LRTB, 14, 295, 306, 325, 336, 0x0,                     STR_RESIZE_BUTTON },
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   204
{   WIDGETS_END },
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   205
};
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   206
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   207
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   208
static const WindowDesc _newgrf_add_dlg_desc = {
5366
ef01dc923a5b (svn r7667) -Backport from trunk (r7549, r7551, r7554, r7582, r7594):
Darkvater
parents: 5352
diff changeset
   209
	WDP_CENTER, WDP_CENTER, 307, 337,
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   210
	WC_SAVELOAD, 0,
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   211
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   212
	_newgrf_add_dlg_widgets,
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   213
	NewGRFAddDlgWndProc,
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   214
};
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   215
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   216
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   217
/* 'NewGRF Settings' dialogue */
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   218
typedef struct newgrf_d {
5352
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   219
	GRFConfig **orig_list; ///< grf list the window is shown with
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   220
	GRFConfig **list;      ///< temporary grf list to which changes are made
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   221
	GRFConfig *sel;        ///< selected grf item
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   222
	bool editable;         ///< is the window editable
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   223
	bool show_params;      ///< are the grf-parameters shown in the info-panel
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   224
	bool execute;          ///< on pressing 'apply changes' are grf changes applied immediately, or only list is updated
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   225
} newgrf_d;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   226
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(newgrf_d));
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   227
5352
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   228
5345
00c5ff01191a (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   229
enum ShowNewGRFStateWidgets {
00c5ff01191a (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   230
	SNGRFS_ADD = 3,
00c5ff01191a (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   231
	SNGRFS_REMOVE,
00c5ff01191a (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   232
	SNGRFS_MOVE_UP,
00c5ff01191a (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   233
	SNGRFS_MOVE_DOWN,
00c5ff01191a (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   234
	SNGRFS_FILE_LIST = 7,
00c5ff01191a (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   235
	SNGRFS_NEWGRF_INFO = 9,
00c5ff01191a (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   236
	SNGRFS_SET_PARAMETERS,
5352
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   237
	SNGRFS_APPLY_CHANGES,
5345
00c5ff01191a (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   238
};
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   239
5352
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   240
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   241
static void SetupNewGRFState(Window *w)
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   242
{
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   243
	bool disable_all = WP(w, newgrf_d).sel == NULL || !WP(w, newgrf_d).editable;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   244
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   245
	SetWindowWidgetDisabledState(w, 3, !WP(w, newgrf_d).editable);
5345
00c5ff01191a (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   246
	SetWindowWidgetsDisabledState(w, disable_all,
00c5ff01191a (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   247
		SNGRFS_REMOVE,
00c5ff01191a (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   248
		SNGRFS_MOVE_UP,
00c5ff01191a (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   249
		SNGRFS_MOVE_DOWN,
00c5ff01191a (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   250
		WIDGET_LIST_END
00c5ff01191a (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   251
	);
00c5ff01191a (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   252
	SetWindowWidgetDisabledState(w, SNGRFS_SET_PARAMETERS, !WP(w, newgrf_d).show_params || disable_all);
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   253
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   254
	if (!disable_all) {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   255
		/* All widgets are now enabled, so disable widgets we can't use */
5345
00c5ff01191a (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   256
		if (WP(w, newgrf_d).sel == *WP(w, newgrf_d).list) DisableWindowWidget(w, SNGRFS_MOVE_UP);
00c5ff01191a (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   257
		if (WP(w, newgrf_d).sel->next == NULL) DisableWindowWidget(w, SNGRFS_MOVE_DOWN);
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   258
	}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   259
}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   260
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   261
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   262
static void SetupNewGRFWindow(Window *w)
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   263
{
5345
00c5ff01191a (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   264
	const GRFConfig *c;
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   265
	int i;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   266
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   267
	for (c = *WP(w, newgrf_d).list, i = 0; c != NULL; c = c->next, i++);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   268
5345
00c5ff01191a (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   269
	w->vscroll.cap = (w->widget[SNGRFS_FILE_LIST].bottom - w->widget[SNGRFS_FILE_LIST].top) / 14 + 1;
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   270
	SetVScrollCount(w, i);
5352
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   271
	SetWindowWidgetDisabledState(w, SNGRFS_APPLY_CHANGES, !WP(w, newgrf_d).editable);
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   272
}
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   273
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   274
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   275
/** Callback function for the newgrf 'apply changes' confirmation window
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   276
 * @param yes_clicked boolean value, true when yes was clicked, false otherwise */
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   277
static void NewGRFConfirmationCallback(bool yes_clicked)
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   278
{
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   279
	if (yes_clicked) {
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   280
		Window *w = FindWindowById(WC_GAME_OPTIONS, 0);
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   281
		newgrf_d *nd = &WP(w, newgrf_d);
5416
87d5e006851b (svn r8180) -Backport from trunk (r8093, r8094, r8105, r8106, (r8107), r8111, r8165):
Darkvater
parents: 5366
diff changeset
   282
		GRFConfig *c;
87d5e006851b (svn r8180) -Backport from trunk (r8093, r8094, r8105, r8106, (r8107), r8111, r8165):
Darkvater
parents: 5366
diff changeset
   283
		int i = 0;
5352
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   284
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   285
		CopyGRFConfigList(nd->orig_list, *nd->list);
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   286
		ReloadNewGRFData();
5416
87d5e006851b (svn r8180) -Backport from trunk (r8093, r8094, r8105, r8106, (r8107), r8111, r8165):
Darkvater
parents: 5366
diff changeset
   287
87d5e006851b (svn r8180) -Backport from trunk (r8093, r8094, r8105, r8106, (r8107), r8111, r8165):
Darkvater
parents: 5366
diff changeset
   288
		/* Show new, updated list */
87d5e006851b (svn r8180) -Backport from trunk (r8093, r8094, r8105, r8106, (r8107), r8111, r8165):
Darkvater
parents: 5366
diff changeset
   289
		for (c = *nd->list; c != NULL && c != nd->sel; c = c->next, i++);
87d5e006851b (svn r8180) -Backport from trunk (r8093, r8094, r8105, r8106, (r8107), r8111, r8165):
Darkvater
parents: 5366
diff changeset
   290
		CopyGRFConfigList(nd->list, *nd->orig_list);
87d5e006851b (svn r8180) -Backport from trunk (r8093, r8094, r8105, r8106, (r8107), r8111, r8165):
Darkvater
parents: 5366
diff changeset
   291
		for (c = *nd->list; c != NULL && i > 0; c = c->next, i--);
87d5e006851b (svn r8180) -Backport from trunk (r8093, r8094, r8105, r8106, (r8107), r8111, r8165):
Darkvater
parents: 5366
diff changeset
   292
		nd->sel = c;
87d5e006851b (svn r8180) -Backport from trunk (r8093, r8094, r8105, r8106, (r8107), r8111, r8165):
Darkvater
parents: 5366
diff changeset
   293
87d5e006851b (svn r8180) -Backport from trunk (r8093, r8094, r8105, r8106, (r8107), r8111, r8165):
Darkvater
parents: 5366
diff changeset
   294
		SetWindowDirty(w);
5352
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   295
	}
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   296
}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   297
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   298
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   299
static void NewGRFWndProc(Window *w, WindowEvent *e)
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   300
{
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   301
	switch (e->event) {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   302
		case WE_PAINT: {
5345
00c5ff01191a (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   303
			const GRFConfig *c;
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   304
			int i, y;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   305
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   306
			SetupNewGRFState(w);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   307
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   308
			DrawWindowWidgets(w);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   309
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   310
			/* Draw NewGRF list */
5345
00c5ff01191a (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   311
			y = w->widget[SNGRFS_FILE_LIST].top;
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   312
			for (c = *WP(w, newgrf_d).list, i = 0; c != NULL; c = c->next, i++) {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   313
				if (i >= w->vscroll.pos && i < w->vscroll.pos + w->vscroll.cap) {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   314
					const char *text = (c->name != NULL && strlen(c->name) != 0) ? c->name : c->filename;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   315
					PalSpriteID pal;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   316
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   317
					/* Pick a colour */
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   318
					if (HASBIT(c->flags, GCF_NOT_FOUND) || HASBIT(c->flags, GCF_DISABLED)) {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   319
						pal = PALETTE_TO_RED;
5329
2b117d8652f0 (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5308
diff changeset
   320
					} else if (HASBIT(c->flags, GCF_STATIC)) {
5416
87d5e006851b (svn r8180) -Backport from trunk (r8093, r8094, r8105, r8106, (r8107), r8111, r8165):
Darkvater
parents: 5366
diff changeset
   321
						pal = PALETTE_TO_GREY;
87d5e006851b (svn r8180) -Backport from trunk (r8093, r8094, r8105, r8106, (r8107), r8111, r8165):
Darkvater
parents: 5366
diff changeset
   322
					} else if (HASBIT(c->flags, GCF_COMPATIBLE)) {
87d5e006851b (svn r8180) -Backport from trunk (r8093, r8094, r8105, r8106, (r8107), r8111, r8165):
Darkvater
parents: 5366
diff changeset
   323
						pal = PALETTE_TO_ORANGE;
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   324
					} else if (HASBIT(c->flags, GCF_ACTIVATED)) {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   325
						pal = PALETTE_TO_GREEN;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   326
					} else {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   327
						pal = PALETTE_TO_BLUE;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   328
					}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   329
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   330
					DrawSprite(SPRITE_PALETTE(SPR_SQUARE | pal), 5, y + 2);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   331
					DoDrawString(text, 25, y + 3, WP(w, newgrf_d).sel == c ? 0xC : 0x10);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   332
					y += 14;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   333
				}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   334
			}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   335
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   336
			if (WP(w, newgrf_d).sel != NULL) {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   337
				/* Draw NewGRF file info */
5345
00c5ff01191a (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   338
				const Widget *wi = &w->widget[SNGRFS_NEWGRF_INFO];
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   339
				ShowNewGRFInfo(WP(w, newgrf_d).sel, wi->left + 2, wi->top + 2, wi->right - wi->left - 2, WP(w, newgrf_d).show_params);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   340
			}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   341
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   342
			break;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   343
		}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   344
5241
2dafe1235308 (svn r7363) -Fix (r7357): Update count of NewGRFs when adding an file
peter1138
parents: 5237
diff changeset
   345
		case WE_INVALIDATE_DATA:
2dafe1235308 (svn r7363) -Fix (r7357): Update count of NewGRFs when adding an file
peter1138
parents: 5237
diff changeset
   346
			SetupNewGRFWindow(w);
2dafe1235308 (svn r7363) -Fix (r7357): Update count of NewGRFs when adding an file
peter1138
parents: 5237
diff changeset
   347
			break;
2dafe1235308 (svn r7363) -Fix (r7357): Update count of NewGRFs when adding an file
peter1138
parents: 5237
diff changeset
   348
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   349
		case WE_CLICK:
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   350
			switch (e->we.click.widget) {
5345
00c5ff01191a (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   351
				case SNGRFS_ADD: { /* Add GRF */
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   352
					GRFConfig **list = WP(w, newgrf_d).list;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   353
					Window *w;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   354
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   355
					DeleteWindowByClass(WC_SAVELOAD);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   356
					w = AllocateWindowDesc(&_newgrf_add_dlg_desc);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   357
					w->resize.step_height = 10;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   358
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   359
					WP(w, newgrf_add_d).list = list;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   360
					break;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   361
				}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   362
5345
00c5ff01191a (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   363
				case SNGRFS_REMOVE: { /* Remove GRF */
5248
2aa0c4cc8f23 (svn r7373) -Codechange: when removing a GRF from the list, make the next one selected, or the previous file if the last item is being removed. This makes clearing the list easier.
peter1138
parents: 5243
diff changeset
   364
					GRFConfig **pc, *c, *newsel;
2aa0c4cc8f23 (svn r7373) -Codechange: when removing a GRF from the list, make the next one selected, or the previous file if the last item is being removed. This makes clearing the list easier.
peter1138
parents: 5243
diff changeset
   365
2aa0c4cc8f23 (svn r7373) -Codechange: when removing a GRF from the list, make the next one selected, or the previous file if the last item is being removed. This makes clearing the list easier.
peter1138
parents: 5243
diff changeset
   366
					/* Choose the next GRF file to be the selected file */
2aa0c4cc8f23 (svn r7373) -Codechange: when removing a GRF from the list, make the next one selected, or the previous file if the last item is being removed. This makes clearing the list easier.
peter1138
parents: 5243
diff changeset
   367
					newsel = WP(w, newgrf_d).sel->next;
2aa0c4cc8f23 (svn r7373) -Codechange: when removing a GRF from the list, make the next one selected, or the previous file if the last item is being removed. This makes clearing the list easier.
peter1138
parents: 5243
diff changeset
   368
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   369
					for (pc = WP(w, newgrf_d).list; (c = *pc) != NULL; pc = &c->next) {
5248
2aa0c4cc8f23 (svn r7373) -Codechange: when removing a GRF from the list, make the next one selected, or the previous file if the last item is being removed. This makes clearing the list easier.
peter1138
parents: 5243
diff changeset
   370
						/* If the new selection is empty (i.e. we're deleting the last item
2aa0c4cc8f23 (svn r7373) -Codechange: when removing a GRF from the list, make the next one selected, or the previous file if the last item is being removed. This makes clearing the list easier.
peter1138
parents: 5243
diff changeset
   371
						 * in the list, pick the file just before the selected file */
2aa0c4cc8f23 (svn r7373) -Codechange: when removing a GRF from the list, make the next one selected, or the previous file if the last item is being removed. This makes clearing the list easier.
peter1138
parents: 5243
diff changeset
   372
						if (newsel == NULL && c->next == WP(w, newgrf_d).sel) newsel = c;
2aa0c4cc8f23 (svn r7373) -Codechange: when removing a GRF from the list, make the next one selected, or the previous file if the last item is being removed. This makes clearing the list easier.
peter1138
parents: 5243
diff changeset
   373
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   374
						if (c == WP(w, newgrf_d).sel) {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   375
							*pc = c->next;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   376
							free(c);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   377
							break;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   378
						}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   379
					}
5248
2aa0c4cc8f23 (svn r7373) -Codechange: when removing a GRF from the list, make the next one selected, or the previous file if the last item is being removed. This makes clearing the list easier.
peter1138
parents: 5243
diff changeset
   380
2aa0c4cc8f23 (svn r7373) -Codechange: when removing a GRF from the list, make the next one selected, or the previous file if the last item is being removed. This makes clearing the list easier.
peter1138
parents: 5243
diff changeset
   381
					WP(w, newgrf_d).sel = newsel;
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   382
					SetupNewGRFWindow(w);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   383
					SetWindowDirty(w);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   384
					break;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   385
				}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   386
5345
00c5ff01191a (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   387
				case SNGRFS_MOVE_UP: { /* Move GRF up */
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   388
					GRFConfig **pc, *c;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   389
					if (WP(w, newgrf_d).sel == NULL) break;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   390
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   391
					for (pc = WP(w, newgrf_d).list; (c = *pc) != NULL; pc = &c->next) {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   392
						if (c->next == WP(w, newgrf_d).sel) {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   393
							c->next = WP(w, newgrf_d).sel->next;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   394
							WP(w, newgrf_d).sel->next = c;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   395
							*pc = WP(w, newgrf_d).sel;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   396
							break;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   397
						}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   398
					}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   399
					SetWindowDirty(w);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   400
					break;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   401
				}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   402
5345
00c5ff01191a (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   403
				case SNGRFS_MOVE_DOWN: { /* Move GRF down */
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   404
					GRFConfig **pc, *c;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   405
					if (WP(w, newgrf_d).sel == NULL) break;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   406
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   407
					for (pc = WP(w, newgrf_d).list; (c = *pc) != NULL; pc = &c->next) {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   408
						if (c == WP(w, newgrf_d).sel) {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   409
							*pc = c->next;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   410
							c->next = c->next->next;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   411
							(*pc)->next = c;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   412
							break;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   413
						}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   414
					}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   415
					SetWindowDirty(w);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   416
					break;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   417
				}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   418
5345
00c5ff01191a (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   419
				case SNGRFS_FILE_LIST: { /* Select a GRF */
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   420
					GRFConfig *c;
5345
00c5ff01191a (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   421
					uint i = (e->we.click.pt.y - w->widget[SNGRFS_FILE_LIST].top) / 14 + w->vscroll.pos;
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   422
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   423
					for (c = *WP(w, newgrf_d).list; c != NULL && i > 0; c = c->next, i--);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   424
					WP(w, newgrf_d).sel = c;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   425
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   426
					SetWindowDirty(w);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   427
					break;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   428
				}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   429
5352
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   430
				case SNGRFS_APPLY_CHANGES: /* Apply changes made to GRF list */
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   431
					if (WP(w, newgrf_d).execute) {
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   432
						ShowQuery(
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   433
							STR_POPUP_CAUTION_CAPTION,
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   434
							STR_NEWGRF_CONFIRMATION_TEXT,
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   435
							NewGRFConfirmationCallback,
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   436
							w->window_class,
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   437
							w->window_number
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   438
						);
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   439
					} else {
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   440
						CopyGRFConfigList(WP(w, newgrf_d).orig_list, *WP(w, newgrf_d).list);
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   441
					}
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   442
					break;
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   443
5345
00c5ff01191a (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   444
				case SNGRFS_SET_PARAMETERS: { /* Edit parameters */
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   445
					char buff[512];
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   446
					if (WP(w, newgrf_d).sel == NULL) break;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   447
5308
bad31e174cc6 (svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents: 5248
diff changeset
   448
					GRFBuildParamList(buff, WP(w, newgrf_d).sel, lastof(buff));
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   449
					ShowQueryString(BindCString(buff), STR_NEWGRF_PARAMETER_QUERY, 63, 250, w->window_class, w->window_number, CS_ALPHANUMERAL);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   450
					break;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   451
				}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   452
			}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   453
			break;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   454
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   455
		case WE_ON_EDIT_TEXT:
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   456
			if (e->we.edittext.str != NULL) {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   457
				/* Parse our new "int list" */
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   458
				GRFConfig *c = WP(w, newgrf_d).sel;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   459
				c->num_params = parse_intlist(e->we.edittext.str, (int*)c->param, lengthof(c->param));
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   460
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   461
				/* parse_intlist returns -1 on error */
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   462
				if (c->num_params == (byte)-1) c->num_params = 0;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   463
			}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   464
			SetWindowDirty(w);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   465
			break;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   466
5352
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   467
		case WE_DESTROY:
5455
547cba149cbd (svn r8922) [0.5] -Backport from trunk (r8907, r8919, r8920, r8921):
Darkvater
parents: 5416
diff changeset
   468
			if (!WP(w, newgrf_d).execute) {
547cba149cbd (svn r8922) [0.5] -Backport from trunk (r8907, r8919, r8920, r8921):
Darkvater
parents: 5416
diff changeset
   469
				CopyGRFConfigList(WP(w, newgrf_d).orig_list, *WP(w, newgrf_d).list);
547cba149cbd (svn r8922) [0.5] -Backport from trunk (r8907, r8919, r8920, r8921):
Darkvater
parents: 5416
diff changeset
   470
			}
5352
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   471
			/* Remove the temporary copy of grf-list used in window */
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   472
			ClearGRFConfigList(WP(w, newgrf_d).list);
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   473
			break;
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   474
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   475
		case WE_RESIZE:
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   476
			w->vscroll.cap += e->we.sizing.diff.y / 14;
5345
00c5ff01191a (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   477
			w->widget[SNGRFS_FILE_LIST].data = (w->vscroll.cap << 8) + 1;
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   478
			break;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   479
	}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   480
}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   481
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   482
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   483
static const Widget _newgrf_widgets[] = {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   484
{   WWT_CLOSEBOX,  RESIZE_NONE, 10,   0,  10,   0,  13, STR_00C5,                    STR_018B_CLOSE_WINDOW },
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   485
{    WWT_CAPTION, RESIZE_RIGHT, 10,  11, 299,   0,  13, STR_NEWGRF_SETTINGS_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS },
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   486
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   487
/* NewGRF file Add, Remove, Move up, Move down */
5345
00c5ff01191a (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   488
{      WWT_PANEL, RESIZE_RIGHT, 10,   0, 299,  14,  29, STR_NULL,                    STR_NULL },
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   489
{ WWT_PUSHTXTBTN,  RESIZE_NONE,  3,  10,  79,  16,  27, STR_NEWGRF_ADD,              STR_NEWGRF_ADD_TIP },
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   490
{ WWT_PUSHTXTBTN,  RESIZE_NONE,  3,  80, 149,  16,  27, STR_NEWGRF_REMOVE,           STR_NEWGRF_REMOVE_TIP },
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   491
{ WWT_PUSHTXTBTN,  RESIZE_NONE,  3, 150, 219,  16,  27, STR_NEWGRF_MOVEUP,           STR_NEWGRF_MOVEUP_TIP },
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   492
{ WWT_PUSHTXTBTN,  RESIZE_NONE,  3, 220, 289,  16,  27, STR_NEWGRF_MOVEDOWN,         STR_NEWGRF_MOVEDOWN_TIP },
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   493
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   494
/* NewGRF file list */
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   495
{     WWT_MATRIX,    RESIZE_RB, 10,   0, 287,  30,  99, 0x501,                       STR_NEWGRF_FILE_TIP },
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   496
{  WWT_SCROLLBAR,   RESIZE_LRB, 10, 288, 299,  30,  99, 0x0,                         STR_0190_SCROLL_BAR_SCROLLS_LIST },
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   497
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   498
/* NewGRF file info */
5366
ef01dc923a5b (svn r7667) -Backport from trunk (r7549, r7551, r7554, r7582, r7594):
Darkvater
parents: 5352
diff changeset
   499
{      WWT_PANEL,   RESIZE_RTB, 10,   0, 299, 100, 212, STR_NULL,                    STR_NULL },
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   500
5352
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   501
/* Edit parameter and apply changes button... */
5366
ef01dc923a5b (svn r7667) -Backport from trunk (r7549, r7551, r7554, r7582, r7594):
Darkvater
parents: 5352
diff changeset
   502
{ WWT_PUSHTXTBTN,    RESIZE_TB, 10,   0, 143, 213, 224, STR_NEWGRF_SET_PARAMETERS,   STR_NULL },
ef01dc923a5b (svn r7667) -Backport from trunk (r7549, r7551, r7554, r7582, r7594):
Darkvater
parents: 5352
diff changeset
   503
{ WWT_PUSHTXTBTN,   RESIZE_RTB, 10, 144, 287, 213, 224, STR_NEWGRF_APPLY_CHANGES,    STR_NULL },
5352
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   504
5366
ef01dc923a5b (svn r7667) -Backport from trunk (r7549, r7551, r7554, r7582, r7594):
Darkvater
parents: 5352
diff changeset
   505
{  WWT_RESIZEBOX,  RESIZE_LRTB, 10, 288, 299, 213, 224, 0x0,                         STR_RESIZE_BUTTON },
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   506
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   507
{ WIDGETS_END },
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   508
};
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   509
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   510
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   511
static const WindowDesc _newgrf_desc = {
5366
ef01dc923a5b (svn r7667) -Backport from trunk (r7549, r7551, r7554, r7582, r7594):
Darkvater
parents: 5352
diff changeset
   512
	WDP_CENTER, WDP_CENTER, 300, 225,
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   513
	WC_GAME_OPTIONS, 0,
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   514
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   515
	_newgrf_widgets,
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   516
	NewGRFWndProc,
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   517
};
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   518
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   519
5352
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   520
/** Setup the NewGRF gui
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   521
 * @param editable allow the user to make changes to the grfconfig in the window
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   522
 * @param show_params show information about what parameters are set for the grf files
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   523
 * @param exec_changes if changes are made to the list (editable is true), apply these
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   524
 *        changes immediately or only update the list
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   525
 * @param config pointer to a linked-list of grfconfig's that will be shown */
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   526
void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config)
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   527
{
5352
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   528
	static GRFConfig *local = NULL;
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   529
	Window *w;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   530
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   531
	DeleteWindowByClass(WC_GAME_OPTIONS);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   532
	w = AllocateWindowDesc(&_newgrf_desc);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   533
	if (w == NULL) return;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   534
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   535
	w->resize.step_height = 14;
5352
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   536
	CopyGRFConfigList(&local, *config);
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   537
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   538
	/* Clear selections */
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   539
	WP(w, newgrf_d).sel         = NULL;
5352
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   540
	WP(w, newgrf_d).list        = &local;
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   541
	WP(w, newgrf_d).orig_list   = config;
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   542
	WP(w, newgrf_d).editable    = editable;
5352
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   543
	WP(w, newgrf_d).execute     = exec_changes;
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   544
	WP(w, newgrf_d).show_params = show_params;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   545
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   546
	SetupNewGRFWindow(w);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   547
}