newgrf_gui.c
author KUDr
Sun, 31 Dec 2006 02:53:23 +0000
branchcustombridgeheads
changeset 5611 11da6bafbfb9
parent 5552 8463cf69909c
child 5416 87d5e006851b
child 5623 ef2a8a524a95
child 5669 ea25407ffa55
permissions -rw-r--r--
(svn r7687) [cbh] - Fix: trains can now enter the bridge from side. They still can't leave it from side (pathfinder will need to be invoked when the other ramp is entered). Also the code is not very clear and needs review. It is more proof of concept than final solution. I hope that somebody smarter (Celestar) can do it better.
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
{
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    43
	char buff[512];
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    44
	char *s;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    45
	uint i;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    46
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
    47
	/* 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
    48
	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
    49
		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
    50
		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
    51
	}
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    52
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    53
	/* Prepare and draw GRF ID */
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    54
	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
    55
	SetDParamStr(0, buff);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    56
	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
    57
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    58
	/* Prepare and draw MD5 sum */
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    59
	s = buff;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    60
	for (i = 0; i < lengthof(c->md5sum); i++) {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    61
		s += snprintf(s, lastof(buff) - s, "%02X", c->md5sum[i]);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    62
	}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    63
	SetDParamStr(0, buff);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    64
	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
    65
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    66
	/* Show GRF parameter list */
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    67
	if (show_params) {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    68
		if (c->num_params > 0) {
5308
bad31e174cc6 (svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents: 5248
diff changeset
    69
			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
    70
			SetDParamStr(0, buff);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    71
		} else {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    72
			SetDParam(0, STR_01A9_NONE);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    73
		}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    74
		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
    75
	}
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
	/* Show flags */
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    78
	if (HASBIT(c->flags, GCF_NOT_FOUND)) y += DrawStringMultiLine(x, y, STR_NEWGRF_NOT_FOUND, w);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    79
	if (HASBIT(c->flags, GCF_DISABLED))  y += DrawStringMultiLine(x, y, STR_NEWGRF_DISABLED, w);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    80
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    81
	/* 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
    82
	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
    83
		SetDParamStr(0, c->info);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    84
		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
    85
	} else {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    86
		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
    87
	}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    88
}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    89
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    90
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    91
/* 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
    92
typedef struct newgrf_add_d {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    93
	GRFConfig **list;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    94
	const GRFConfig *sel;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    95
} newgrf_add_d;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    96
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    97
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    98
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
    99
{
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   100
	switch (e->event) {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   101
		case WE_PAINT: {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   102
			const GRFConfig *c;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   103
			int y;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   104
			int n = 0;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   105
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   106
			/* Count the number of GRFs */
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   107
			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
   108
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   109
			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
   110
			SetVScrollCount(w, n);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   111
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   112
			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
   113
			DrawWindowWidgets(w);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   114
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   115
			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
   116
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   117
			n = 0;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   118
			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
   119
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   120
			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
   121
				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
   122
					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
   123
					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
   124
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   125
					/* Draw selection background */
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   126
					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
   127
					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
   128
					y += 10;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   129
				}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   130
				n++;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   131
			}
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
			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
   134
				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
   135
				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
   136
			}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   137
			break;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   138
		}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   139
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   140
		case WE_CLICK:
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   141
			switch (e->we.click.widget) {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   142
				case 3: {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   143
					// Get row...
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   144
					const GRFConfig *c;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   145
					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
   146
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   147
					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
   148
					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
   149
					SetWindowDirty(w);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   150
					break;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   151
				}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   152
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   153
				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
   154
					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
   155
						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
   156
						GRFConfig **list, *c;
a564347a939b (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   157
a564347a939b (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   158
						/* 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
   159
						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
   160
							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
   161
								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
   162
								return;
a564347a939b (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   163
							}
a564347a939b (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   164
						}
a564347a939b (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   165
a564347a939b (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   166
						/* 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
   167
						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
   168
						*c = *src;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   169
						c->filename = strdup(src->filename);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   170
						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
   171
						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
   172
						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
   173
a564347a939b (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   174
						/* 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
   175
						*list = c;
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   176
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   177
						DeleteWindowByClass(WC_SAVELOAD);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   178
						InvalidateWindowData(WC_GAME_OPTIONS, 0);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   179
					}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   180
					break;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   181
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   182
				case 7: /* Rescan list */
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   183
					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
   184
					ScanNewGRFFiles();
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   185
					SetWindowDirty(w);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   186
					break;
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
			break;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   189
	}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   190
}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   191
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
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
   194
{   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
   195
{    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
   196
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   197
/* List of files */
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   198
{      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
   199
{      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
   200
{  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
   201
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   202
/* NewGRF file info */
5552
8463cf69909c (svn r7549) -Fix (r7357): change the size of the NewGRF GUIs so any description of a GRF that is shown in TTDPatch without overflowing, does not overflow in OpenTTD.
rubidium
parents: 5352
diff changeset
   203
{      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
   204
5552
8463cf69909c (svn r7549) -Fix (r7357): change the size of the NewGRF GUIs so any description of a GRF that is shown in TTDPatch without overflowing, does not overflow in OpenTTD.
rubidium
parents: 5352
diff changeset
   205
{ WWT_PUSHTXTBTN,     RESIZE_RTB, 14,   0, 146, 325, 336, STR_NEWGRF_ADD_FILE,     STR_NEWGRF_ADD_FILE_TIP },
8463cf69909c (svn r7549) -Fix (r7357): change the size of the NewGRF GUIs so any description of a GRF that is shown in TTDPatch without overflowing, does not overflow in OpenTTD.
rubidium
parents: 5352
diff changeset
   206
{ WWT_PUSHTXTBTN,    RESIZE_LRTB, 14, 147, 294, 325, 336, STR_NEWGRF_RESCAN_FILES, STR_NEWGRF_RESCAN_FILES_TIP },
8463cf69909c (svn r7549) -Fix (r7357): change the size of the NewGRF GUIs so any description of a GRF that is shown in TTDPatch without overflowing, does not overflow in OpenTTD.
rubidium
parents: 5352
diff changeset
   207
{  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
   208
{   WIDGETS_END },
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   209
};
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   210
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   211
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   212
static const WindowDesc _newgrf_add_dlg_desc = {
5552
8463cf69909c (svn r7549) -Fix (r7357): change the size of the NewGRF GUIs so any description of a GRF that is shown in TTDPatch without overflowing, does not overflow in OpenTTD.
rubidium
parents: 5352
diff changeset
   213
	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
   214
	WC_SAVELOAD, 0,
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   215
	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
   216
	_newgrf_add_dlg_widgets,
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   217
	NewGRFAddDlgWndProc,
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   218
};
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   219
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   220
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   221
/* 'NewGRF Settings' dialogue */
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   222
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
   223
	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
   224
	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
   225
	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
   226
	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
   227
	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
   228
	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
   229
} newgrf_d;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   230
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
   231
5352
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   232
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
   233
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
   234
	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
   235
	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
   236
	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
   237
	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
   238
	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
   239
	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
   240
	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
   241
	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
   242
};
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   243
5352
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   244
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   245
static void SetupNewGRFState(Window *w)
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   246
{
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   247
	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
   248
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   249
	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
   250
	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
   251
		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
   252
		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
   253
		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
   254
		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
   255
	);
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
	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
   257
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   258
	if (!disable_all) {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   259
		/* 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
   260
		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
   261
		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
   262
	}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   263
}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   264
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   265
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   266
static void SetupNewGRFWindow(Window *w)
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   267
{
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
   268
	const GRFConfig *c;
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   269
	int i;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   270
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   271
	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
   272
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
   273
	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
   274
	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
   275
	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
   276
}
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   277
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
/** 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
   280
 * @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
   281
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
   282
{
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   283
	if (yes_clicked) {
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   284
		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
   285
		newgrf_d *nd = &WP(w, newgrf_d);
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   286
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   287
		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
   288
		ReloadNewGRFData();
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   289
	}
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   290
}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   291
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   292
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   293
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
   294
{
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   295
	switch (e->event) {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   296
		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
   297
			const GRFConfig *c;
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   298
			int i, y;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   299
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   300
			SetupNewGRFState(w);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   301
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   302
			DrawWindowWidgets(w);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   303
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   304
			/* 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
   305
			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
   306
			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
   307
				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
   308
					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
   309
					PalSpriteID pal;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   310
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   311
					/* Pick a colour */
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   312
					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
   313
						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
   314
					} else if (HASBIT(c->flags, GCF_STATIC)) {
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
   315
						pal = PALETTE_TO_YELLOW;
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   316
					} 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
   317
						pal = PALETTE_TO_GREEN;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   318
					} else {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   319
						pal = PALETTE_TO_BLUE;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   320
					}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   321
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   322
					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
   323
					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
   324
					y += 14;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   325
				}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   326
			}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   327
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   328
			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
   329
				/* 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
   330
				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
   331
				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
   332
			}
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
			break;
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
5241
2dafe1235308 (svn r7363) -Fix (r7357): Update count of NewGRFs when adding an file
peter1138
parents: 5237
diff changeset
   337
		case WE_INVALIDATE_DATA:
2dafe1235308 (svn r7363) -Fix (r7357): Update count of NewGRFs when adding an file
peter1138
parents: 5237
diff changeset
   338
			SetupNewGRFWindow(w);
2dafe1235308 (svn r7363) -Fix (r7357): Update count of NewGRFs when adding an file
peter1138
parents: 5237
diff changeset
   339
			break;
2dafe1235308 (svn r7363) -Fix (r7357): Update count of NewGRFs when adding an file
peter1138
parents: 5237
diff changeset
   340
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   341
		case WE_CLICK:
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   342
			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
   343
				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
   344
					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
   345
					Window *w;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   346
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   347
					DeleteWindowByClass(WC_SAVELOAD);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   348
					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
   349
					w->resize.step_height = 10;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   350
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   351
					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
   352
					break;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   353
				}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   354
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
   355
				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
   356
					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
   357
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
   358
					/* 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
   359
					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
   360
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   361
					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
   362
						/* 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
   363
						 * 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
   364
						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
   365
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   366
						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
   367
							*pc = c->next;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   368
							free(c);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   369
							break;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   370
						}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   371
					}
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
   372
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
					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
   374
					SetupNewGRFWindow(w);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   375
					SetWindowDirty(w);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   376
					break;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   377
				}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   378
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
   379
				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
   380
					GRFConfig **pc, *c;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   381
					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
   382
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   383
					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
   384
						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
   385
							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
   386
							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
   387
							*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
   388
							break;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   389
						}
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
					SetWindowDirty(w);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   392
					break;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   393
				}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   394
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
   395
				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
   396
					GRFConfig **pc, *c;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   397
					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
   398
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   399
					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
   400
						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
   401
							*pc = c->next;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   402
							c->next = c->next->next;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   403
							(*pc)->next = c;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   404
							break;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   405
						}
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
					SetWindowDirty(w);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   408
					break;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   409
				}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   410
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
   411
				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
   412
					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
   413
					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
   414
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   415
					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
   416
					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
   417
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   418
					SetWindowDirty(w);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   419
					break;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   420
				}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   421
5352
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   422
				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
   423
					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
   424
						ShowQuery(
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   425
							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
   426
							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
   427
							NewGRFConfirmationCallback,
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   428
							w->window_class,
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   429
							w->window_number
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   430
						);
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   431
					} else {
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   432
						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
   433
					}
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   434
					break;
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   435
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
   436
				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
   437
					char buff[512];
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   438
					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
   439
5308
bad31e174cc6 (svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents: 5248
diff changeset
   440
					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
   441
					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
   442
					break;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   443
				}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   444
			}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   445
			break;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   446
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   447
		case WE_ON_EDIT_TEXT:
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   448
			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
   449
				/* Parse our new "int list" */
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   450
				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
   451
				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
   452
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   453
				/* 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
   454
				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
   455
			}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   456
			SetWindowDirty(w);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   457
			break;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   458
5352
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   459
		case WE_DESTROY:
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   460
			/* 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
   461
			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
   462
			break;
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   463
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   464
		case WE_RESIZE:
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   465
			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
   466
			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
   467
			break;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   468
	}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   469
}
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   470
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   471
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   472
static const Widget _newgrf_widgets[] = {
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   473
{   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
   474
{    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
   475
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   476
/* 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
   477
{      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
   478
{ 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
   479
{ 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
   480
{ 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
   481
{ 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
   482
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   483
/* NewGRF file list */
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   484
{     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
   485
{  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
   486
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   487
/* NewGRF file info */
5552
8463cf69909c (svn r7549) -Fix (r7357): change the size of the NewGRF GUIs so any description of a GRF that is shown in TTDPatch without overflowing, does not overflow in OpenTTD.
rubidium
parents: 5352
diff changeset
   488
{      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
   489
5352
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   490
/* Edit parameter and apply changes button... */
5552
8463cf69909c (svn r7549) -Fix (r7357): change the size of the NewGRF GUIs so any description of a GRF that is shown in TTDPatch without overflowing, does not overflow in OpenTTD.
rubidium
parents: 5352
diff changeset
   491
{ WWT_PUSHTXTBTN,    RESIZE_TB, 10,   0, 143, 213, 224, STR_NEWGRF_SET_PARAMETERS,   STR_NULL },
8463cf69909c (svn r7549) -Fix (r7357): change the size of the NewGRF GUIs so any description of a GRF that is shown in TTDPatch without overflowing, does not overflow in OpenTTD.
rubidium
parents: 5352
diff changeset
   492
{ 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
   493
5552
8463cf69909c (svn r7549) -Fix (r7357): change the size of the NewGRF GUIs so any description of a GRF that is shown in TTDPatch without overflowing, does not overflow in OpenTTD.
rubidium
parents: 5352
diff changeset
   494
{  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
   495
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   496
{ WIDGETS_END },
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
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   499
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   500
static const WindowDesc _newgrf_desc = {
5552
8463cf69909c (svn r7549) -Fix (r7357): change the size of the NewGRF GUIs so any description of a GRF that is shown in TTDPatch without overflowing, does not overflow in OpenTTD.
rubidium
parents: 5352
diff changeset
   501
	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
   502
	WC_GAME_OPTIONS, 0,
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   503
	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
   504
	_newgrf_widgets,
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   505
	NewGRFWndProc,
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
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   508
5352
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   509
/** 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
   510
 * @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
   511
 * @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
   512
 * @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
   513
 *        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
   514
 * @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
   515
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
   516
{
5352
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   517
	static GRFConfig *local = NULL;
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   518
	Window *w;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   519
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   520
	DeleteWindowByClass(WC_GAME_OPTIONS);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   521
	w = AllocateWindowDesc(&_newgrf_desc);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   522
	if (w == NULL) return;
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   523
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   524
	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
   525
	CopyGRFConfigList(&local, *config);
5237
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   526
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   527
	/* Clear selections */
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   528
	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
   529
	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
   530
	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
   531
	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
   532
	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
   533
	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
   534
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   535
	SetupNewGRFWindow(w);
c14c97d7030a (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   536
}