src/newgrf_gui.cpp
author peter1138
Tue, 22 Jan 2008 07:27:06 +0000
changeset 8374 7a1b6c89cb89
parent 8264 b1e85998c7d3
child 8591 d73cc7cd733c
permissions -rw-r--r--
(svn r11940) -Codechange: Store short filename once per open file instead of once per sprite cache entry. Not all file types need this, but most of the time no sprite cache entry needed it either.
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
     1
/* $Id$ */
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
     2
6348
6dd01da7a02b (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6248
diff changeset
     3
/** @file newgrf_gui.cpp */
6dd01da7a02b (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6248
diff changeset
     4
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
     5
#include "stdafx.h"
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
     6
#include "openttd.h"
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
     7
#include "variables.h"
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
     8
#include "gui.h"
8107
bb7deea89175 (svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium
parents: 8106
diff changeset
     9
#include "window_gui.h"
bb7deea89175 (svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium
parents: 8106
diff changeset
    10
#include "textbuf_gui.h"
5352
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
    11
#include "newgrf.h"
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    12
#include "newgrf_config.h"
8114
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 8107
diff changeset
    13
#include "strings_func.h"
8131
160939e24ed3 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8130
diff changeset
    14
#include "window_func.h"
8213
7bdd7593eb9b (svn r11776) -Codechange: more header splittings to reduce the dependencies.
rubidium
parents: 8131
diff changeset
    15
#include "core/alloc_func.hpp"
8214
971f861d5543 (svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents: 8213
diff changeset
    16
#include "string_func.h"
8224
c5a64d87cc54 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents: 8214
diff changeset
    17
#include "gfx_func.h"
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    18
8264
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8224
diff changeset
    19
#include "table/strings.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8224
diff changeset
    20
#include "table/sprites.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8224
diff changeset
    21
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    22
/** Parse an integerlist string and set each found value
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    23
 * @param p the string to be parsed. Each element in the list is seperated by a
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    24
 * comma or a space character
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    25
 * @param items pointer to the integerlist-array that will be filled with values
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    26
 * @param maxitems the maximum number of elements the integerlist-array has
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    27
 * @return returns the number of items found, or -1 on an error */
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    28
static int parse_intlist(const char *p, int *items, int maxitems)
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    29
{
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    30
	int n = 0, v;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    31
	char *end;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    32
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    33
	for (;;) {
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    34
		v = strtol(p, &end, 0);
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    35
		if (p == end || n == maxitems) return -1;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    36
		p = end;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    37
		items[n++] = v;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    38
		if (*p == '\0') break;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    39
		if (*p != ',' && *p != ' ') return -1;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    40
		p++;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    41
	}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    42
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    43
	return n;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    44
}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    45
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    46
6377
c1bc323eaf0c (svn r9449) -Fix: Truncate the newgrf information text in the newgrf gui if it's too long.
maedhros
parents: 6348
diff changeset
    47
static void ShowNewGRFInfo(const GRFConfig *c, uint x, uint y, uint w, uint bottom, bool show_params)
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    48
{
5634
ba6b9ebe197a (svn r8093) -Codechange: Add a function to get a string representation of an MD5SUM and use it.
Darkvater
parents: 5609
diff changeset
    49
	char buff[256];
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    50
6103
d38163ddfef9 (svn r8838) -Feature: Show newgrf error messages loaded in Action B in the newgrf gui
maedhros
parents: 5893
diff changeset
    51
	if (c->error != NULL) {
6139
cd42df0c1f0f (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6103
diff changeset
    52
		SetDParamStr(0, c->filename);
6873
b4d0648edd29 (svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents: 6783
diff changeset
    53
		SetDParamStr(1, c->error->data);
6139
cd42df0c1f0f (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6103
diff changeset
    54
		for (uint i = 0; i < c->error->num_params; i++) {
cd42df0c1f0f (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6103
diff changeset
    55
			uint32 param = 0;
cd42df0c1f0f (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6103
diff changeset
    56
			byte param_number = c->error->param_number[i];
cd42df0c1f0f (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6103
diff changeset
    57
cd42df0c1f0f (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6103
diff changeset
    58
			if (param_number < c->num_params) param = c->param[param_number];
cd42df0c1f0f (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6103
diff changeset
    59
cd42df0c1f0f (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6103
diff changeset
    60
			SetDParam(2 + i, param);
cd42df0c1f0f (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6103
diff changeset
    61
		}
cd42df0c1f0f (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6103
diff changeset
    62
cd42df0c1f0f (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6103
diff changeset
    63
		char message[512];
6873
b4d0648edd29 (svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents: 6783
diff changeset
    64
		GetString(message, c->error->custom_message != NULL ? BindCString(c->error->custom_message) : c->error->message, lastof(message));
6139
cd42df0c1f0f (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6103
diff changeset
    65
cd42df0c1f0f (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6103
diff changeset
    66
		SetDParamStr(0, message);
6377
c1bc323eaf0c (svn r9449) -Fix: Truncate the newgrf information text in the newgrf gui if it's too long.
maedhros
parents: 6348
diff changeset
    67
		y += DrawStringMultiLine(x, y, c->error->severity, w, bottom - y);
6103
d38163ddfef9 (svn r8838) -Feature: Show newgrf error messages loaded in Action B in the newgrf gui
maedhros
parents: 5893
diff changeset
    68
	}
d38163ddfef9 (svn r8838) -Feature: Show newgrf error messages loaded in Action B in the newgrf gui
maedhros
parents: 5893
diff changeset
    69
5339
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5329
diff changeset
    70
	/* Draw filename or not if it is not known (GRF sent over internet) */
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5329
diff changeset
    71
	if (c->filename != NULL) {
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5329
diff changeset
    72
		SetDParamStr(0, c->filename);
6377
c1bc323eaf0c (svn r9449) -Fix: Truncate the newgrf information text in the newgrf gui if it's too long.
maedhros
parents: 6348
diff changeset
    73
		y += DrawStringMultiLine(x, y, STR_NEWGRF_FILENAME, w, bottom - y);
5339
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5329
diff changeset
    74
	}
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    75
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    76
	/* Prepare and draw GRF ID */
5643
b373887faf8b (svn r8102) -Cleanup: Remove unreachable code (r8096), useless cast
Darkvater
parents: 5638
diff changeset
    77
	snprintf(buff, lengthof(buff), "%08X", BSWAP32(c->grfid));
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    78
	SetDParamStr(0, buff);
6377
c1bc323eaf0c (svn r9449) -Fix: Truncate the newgrf information text in the newgrf gui if it's too long.
maedhros
parents: 6348
diff changeset
    79
	y += DrawStringMultiLine(x, y, STR_NEWGRF_GRF_ID, w, bottom - y);
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    80
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    81
	/* Prepare and draw MD5 sum */
5634
ba6b9ebe197a (svn r8093) -Codechange: Add a function to get a string representation of an MD5SUM and use it.
Darkvater
parents: 5609
diff changeset
    82
	md5sumToString(buff, lastof(buff), c->md5sum);
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    83
	SetDParamStr(0, buff);
6377
c1bc323eaf0c (svn r9449) -Fix: Truncate the newgrf information text in the newgrf gui if it's too long.
maedhros
parents: 6348
diff changeset
    84
	y += DrawStringMultiLine(x, y, STR_NEWGRF_MD5SUM, w, bottom - y);
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    85
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    86
	/* Show GRF parameter list */
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    87
	if (show_params) {
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    88
		if (c->num_params > 0) {
5308
990a4b188233 (svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents: 5248
diff changeset
    89
			GRFBuildParamList(buff, c, lastof(buff));
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    90
			SetDParamStr(0, buff);
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    91
		} else {
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    92
			SetDParam(0, STR_01A9_NONE);
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    93
		}
6377
c1bc323eaf0c (svn r9449) -Fix: Truncate the newgrf information text in the newgrf gui if it's too long.
maedhros
parents: 6348
diff changeset
    94
		y += DrawStringMultiLine(x, y, STR_NEWGRF_PARAMETER, w, bottom - y);
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    95
	}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    96
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    97
	/* Show flags */
6377
c1bc323eaf0c (svn r9449) -Fix: Truncate the newgrf information text in the newgrf gui if it's too long.
maedhros
parents: 6348
diff changeset
    98
	if (c->status == GCS_NOT_FOUND)        y += DrawStringMultiLine(x, y, STR_NEWGRF_NOT_FOUND, w, bottom - y);
c1bc323eaf0c (svn r9449) -Fix: Truncate the newgrf information text in the newgrf gui if it's too long.
maedhros
parents: 6348
diff changeset
    99
	if (c->status == GCS_DISABLED)         y += DrawStringMultiLine(x, y, STR_NEWGRF_DISABLED, w, bottom - y);
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7882
diff changeset
   100
	if (HasBit(c->flags, GCF_COMPATIBLE)) y += DrawStringMultiLine(x, y, STR_NEWGRF_COMPATIBLE_LOADED, w, bottom - y);
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   101
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   102
	/* Draw GRF info if it exists */
5638
ee1871005c80 (svn r8097) Replace strlen() {==,!=,>} 0 by the more concise {,!}StrEmpty(). Additionally the test takes O(1) instead of O(n) now
tron
parents: 5635
diff changeset
   103
	if (c->info != NULL && !StrEmpty(c->info)) {
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   104
		SetDParamStr(0, c->info);
6377
c1bc323eaf0c (svn r9449) -Fix: Truncate the newgrf information text in the newgrf gui if it's too long.
maedhros
parents: 6348
diff changeset
   105
		y += DrawStringMultiLine(x, y, STR_02BD, w, bottom - y);
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   106
	} else {
6377
c1bc323eaf0c (svn r9449) -Fix: Truncate the newgrf information text in the newgrf gui if it's too long.
maedhros
parents: 6348
diff changeset
   107
		y += DrawStringMultiLine(x, y, STR_NEWGRF_NO_INFO, w, bottom - y);
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   108
	}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   109
}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   110
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   111
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   112
/* Dialogue for adding NewGRF files to the selection */
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6229
diff changeset
   113
struct newgrf_add_d {
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   114
	GRFConfig **list;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   115
	const GRFConfig *sel;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6229
diff changeset
   116
};
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   117
8025
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   118
/* Names of the add a newgrf window widgets */
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   119
enum AddNewGRFWindowWidgets {
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   120
	ANGRFW_CLOSEBOX = 0,
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   121
	ANGRFW_CAPTION,
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   122
	ANGRFW_BACKGROUND,
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   123
	ANGRFW_GRF_LIST,
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   124
	ANGRFW_SCROLLBAR,
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   125
	ANGRFW_GRF_INFO,
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   126
	ANGRFW_ADD,
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   127
	ANGRFW_RESCAN,
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   128
	ANGRFW_RESIZE,
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   129
};
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   130
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   131
static void NewGRFAddDlgWndProc(Window *w, WindowEvent *e)
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   132
{
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   133
	switch (e->event) {
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   134
		case WE_PAINT: {
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   135
			const GRFConfig *c;
8025
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   136
			const Widget *wl = &w->widget[ANGRFW_GRF_LIST];
8070
8e068f2e265a (svn r11631) -Fix (r11585, r11626): remove MSVC warnings
glx
parents: 8025
diff changeset
   137
			int n = 0;
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   138
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   139
			/* Count the number of GRFs */
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   140
			for (c = _all_grfs; c != NULL; c = c->next) n++;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   141
8025
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   142
			w->vscroll.cap = (wl->bottom - wl->top) / 10;
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   143
			SetVScrollCount(w, n);
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   144
8025
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   145
			w->SetWidgetDisabledState(ANGRFW_ADD, WP(w, newgrf_add_d).sel == NULL || WP(w, newgrf_add_d).sel->IsOpenTTDBaseGRF());
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   146
			DrawWindowWidgets(w);
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   147
8025
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   148
			GfxFillRect(wl->left + 1, wl->top + 1, wl->right, wl->bottom, 0xD7);
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   149
8025
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   150
			uint y = wl->top + 1;
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   151
			for (c = _all_grfs, n = 0; c != NULL && n < (w->vscroll.pos + w->vscroll.cap); c = c->next, n++) {
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   152
				if (n >= w->vscroll.pos) {
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   153
					bool h = c == WP(w, newgrf_add_d).sel;
5638
ee1871005c80 (svn r8097) Replace strlen() {==,!=,>} 0 by the more concise {,!}StrEmpty(). Additionally the test takes O(1) instead of O(n) now
tron
parents: 5635
diff changeset
   154
					const char *text = (c->name != NULL && !StrEmpty(c->name)) ? c->name : c->filename;
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   155
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   156
					/* Draw selection background */
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   157
					if (h) GfxFillRect(3, y, w->width - 15, y + 9, 156);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7779
diff changeset
   158
					DoDrawStringTruncated(text, 4, y, h ? TC_WHITE : TC_ORANGE, w->width - 18);
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   159
					y += 10;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   160
				}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   161
			}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   162
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   163
			if (WP(w, newgrf_add_d).sel != NULL) {
8025
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   164
				const Widget *wi = &w->widget[ANGRFW_GRF_INFO];
6377
c1bc323eaf0c (svn r9449) -Fix: Truncate the newgrf information text in the newgrf gui if it's too long.
maedhros
parents: 6348
diff changeset
   165
				ShowNewGRFInfo(WP(w, newgrf_add_d).sel, wi->left + 2, wi->top + 2, wi->right - wi->left - 2, wi->bottom, false);
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   166
			}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   167
			break;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   168
		}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   169
7011
3307df3a88a5 (svn r10267) -Add: enable double clic to add in 'add newgrf' window
glx
parents: 6956
diff changeset
   170
		case WE_DOUBLE_CLICK:
8025
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   171
			if (e->we.click.widget != ANGRFW_GRF_LIST) break;
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   172
			e->we.click.widget = ANGRFW_ADD;
7011
3307df3a88a5 (svn r10267) -Add: enable double clic to add in 'add newgrf' window
glx
parents: 6956
diff changeset
   173
			/* Fall through */
3307df3a88a5 (svn r10267) -Add: enable double clic to add in 'add newgrf' window
glx
parents: 6956
diff changeset
   174
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   175
		case WE_CLICK:
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   176
			switch (e->we.click.widget) {
8025
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   177
				case ANGRFW_GRF_LIST: {
6348
6dd01da7a02b (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6248
diff changeset
   178
					/* Get row... */
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   179
					const GRFConfig *c;
8025
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   180
					uint i = (e->we.click.pt.y - w->widget[ANGRFW_GRF_LIST].top) / 10 + w->vscroll.pos;
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   181
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   182
					for (c = _all_grfs; c != NULL && i > 0; c = c->next, i--);
4fce3ea379c2 (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 = c;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   184
					SetWindowDirty(w);
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   185
					break;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   186
				}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   187
8025
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   188
				case ANGRFW_ADD: // Add selection to list
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   189
					if (WP(w, newgrf_add_d).sel != NULL) {
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   190
						const GRFConfig *src = WP(w, newgrf_add_d).sel;
5609
dc6a58930ba4 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5587
diff changeset
   191
						GRFConfig **list;
5243
29235600e8fc (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   192
29235600e8fc (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   193
						/* Find last entry in the list, checking for duplicate grfid on the way */
29235600e8fc (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   194
						for (list = WP(w, newgrf_add_d).list; *list != NULL; list = &(*list)->next) {
29235600e8fc (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   195
							if ((*list)->grfid == src->grfid) {
29235600e8fc (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   196
								ShowErrorMessage(INVALID_STRING_ID, STR_NEWGRF_DUPLICATE_GRFID, 0, 0);
29235600e8fc (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   197
								return;
29235600e8fc (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   198
							}
29235600e8fc (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   199
						}
29235600e8fc (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   200
29235600e8fc (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   201
						/* Copy GRF details from scanned list */
5609
dc6a58930ba4 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5587
diff changeset
   202
						GRFConfig *c = CallocT<GRFConfig>(1);
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   203
						*c = *src;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   204
						c->filename = strdup(src->filename);
6783
5171c53c717d (svn r10021) -Fix (r9560): memory "corruption" that could lead to a failure to load newgrfs.
rubidium
parents: 6488
diff changeset
   205
						if (src->name      != NULL) c->name      = strdup(src->name);
5171c53c717d (svn r10021) -Fix (r9560): memory "corruption" that could lead to a failure to load newgrfs.
rubidium
parents: 6488
diff changeset
   206
						if (src->info      != NULL) c->info      = strdup(src->info);
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   207
						c->next = NULL;
5243
29235600e8fc (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   208
29235600e8fc (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   209
						/* Append GRF config to configuration list */
29235600e8fc (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   210
						*list = c;
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   211
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   212
						DeleteWindowByClass(WC_SAVELOAD);
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   213
						InvalidateWindowData(WC_GAME_OPTIONS, 0);
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   214
					}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   215
					break;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   216
8025
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   217
				case ANGRFW_RESCAN: // Rescan list
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   218
					WP(w, newgrf_add_d).sel = NULL;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   219
					ScanNewGRFFiles();
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   220
					SetWindowDirty(w);
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   221
					break;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   222
			}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   223
			break;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   224
	}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   225
}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   226
8025
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   227
/* Widget definition for the add a newgrf window */
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   228
static const Widget _newgrf_add_dlg_widgets[] = {
8025
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   229
{   WWT_CLOSEBOX,    RESIZE_NONE, 14,   0,  10,   0,  13, STR_00C5,                STR_018B_CLOSE_WINDOW },           // ANGRFW_CLOSEBOX
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   230
{    WWT_CAPTION,   RESIZE_RIGHT, 14,  11, 306,   0,  13, STR_NEWGRF_ADD_CAPTION,  STR_018C_WINDOW_TITLE_DRAG_THIS }, // ANGRFW_CAPTION
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   231
{      WWT_PANEL,      RESIZE_RB, 14,   0, 294,  14, 121, 0x0,                     STR_NULL },                        // ANGRFW_BACKGROUND
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   232
{      WWT_INSET,      RESIZE_RB, 14,   2, 292,  16, 119, 0x0,                     STR_NULL },                        // ANGRFW_GRF_LIST
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   233
{  WWT_SCROLLBAR,     RESIZE_LRB, 14, 295, 306,  14, 121, 0x0,                     STR_NULL },                        // ANGRFW_SCROLLBAR
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   234
{      WWT_PANEL,     RESIZE_RTB, 14,   0, 306, 122, 224, 0x0,                     STR_NULL },                        // ANGRFW_GRF_INFO
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   235
{ WWT_PUSHTXTBTN,     RESIZE_RTB, 14,   0, 146, 225, 236, STR_NEWGRF_ADD_FILE,     STR_NEWGRF_ADD_FILE_TIP },         // ANGRFW_ADD
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   236
{ WWT_PUSHTXTBTN,    RESIZE_LRTB, 14, 147, 294, 225, 236, STR_NEWGRF_RESCAN_FILES, STR_NEWGRF_RESCAN_FILES_TIP },     // ANGRFW_RESCAN
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   237
{  WWT_RESIZEBOX,    RESIZE_LRTB, 14, 295, 306, 225, 236, 0x0,                     STR_RESIZE_BUTTON },               // ANGRFW_RESIZE
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   238
{   WIDGETS_END },
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   239
};
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   240
8025
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   241
/* Window definition for the add a newgrf window */
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   242
static const WindowDesc _newgrf_add_dlg_desc = {
7341
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7034
diff changeset
   243
	WDP_CENTER, WDP_CENTER, 307, 237, 307, 337,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5668
diff changeset
   244
	WC_SAVELOAD, WC_NONE,
8019
fc0e94dee165 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8018
diff changeset
   245
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   246
	_newgrf_add_dlg_widgets,
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   247
	NewGRFAddDlgWndProc,
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   248
};
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   249
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   250
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   251
/* 'NewGRF Settings' dialogue */
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6229
diff changeset
   252
struct newgrf_d {
5352
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   253
	GRFConfig **orig_list; ///< grf list the window is shown with
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   254
	GRFConfig **list;      ///< temporary grf list to which changes are made
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   255
	GRFConfig *sel;        ///< selected grf item
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   256
	bool editable;         ///< is the window editable
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   257
	bool show_params;      ///< are the grf-parameters shown in the info-panel
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   258
	bool execute;          ///< on pressing 'apply changes' are grf changes applied immediately, or only list is updated
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6229
diff changeset
   259
};
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   260
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(newgrf_d));
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   261
5352
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   262
8025
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   263
/* Names of the manage newgrfs window widgets */
5345
4bc0f4814f15 (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   264
enum ShowNewGRFStateWidgets {
8025
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   265
	SNGRFS_CLOSEBOX = 0,
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   266
	SNGRFS_CAPTION,
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   267
	SNGRFS_BACKGROUND,
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   268
	SNGRFS_ADD,
5345
4bc0f4814f15 (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   269
	SNGRFS_REMOVE,
4bc0f4814f15 (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   270
	SNGRFS_MOVE_UP,
4bc0f4814f15 (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   271
	SNGRFS_MOVE_DOWN,
8025
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   272
	SNGRFS_FILE_LIST,
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   273
	SNGRFS_SCROLLBAR,
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   274
	SNGRFS_NEWGRF_INFO,
5345
4bc0f4814f15 (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   275
	SNGRFS_SET_PARAMETERS,
5352
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   276
	SNGRFS_APPLY_CHANGES,
8025
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   277
	SNGRFS_RESIZE,
5345
4bc0f4814f15 (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   278
};
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   279
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   280
static void SetupNewGRFState(Window *w)
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   281
{
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   282
	bool disable_all = WP(w, newgrf_d).sel == NULL || !WP(w, newgrf_d).editable;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   283
7997
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7928
diff changeset
   284
	w->SetWidgetDisabledState(3, !WP(w, newgrf_d).editable);
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7928
diff changeset
   285
	w->SetWidgetsDisabledState(disable_all,
5345
4bc0f4814f15 (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   286
		SNGRFS_REMOVE,
4bc0f4814f15 (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   287
		SNGRFS_MOVE_UP,
4bc0f4814f15 (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   288
		SNGRFS_MOVE_DOWN,
4bc0f4814f15 (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   289
		WIDGET_LIST_END
4bc0f4814f15 (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   290
	);
7997
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7928
diff changeset
   291
	w->SetWidgetDisabledState(SNGRFS_SET_PARAMETERS, !WP(w, newgrf_d).show_params || disable_all);
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   292
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   293
	if (!disable_all) {
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   294
		/* All widgets are now enabled, so disable widgets we can't use */
7997
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7928
diff changeset
   295
		if (WP(w, newgrf_d).sel == *WP(w, newgrf_d).list) w->DisableWidget(SNGRFS_MOVE_UP);
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7928
diff changeset
   296
		if (WP(w, newgrf_d).sel->next == NULL) w->DisableWidget(SNGRFS_MOVE_DOWN);
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7928
diff changeset
   297
		if (WP(w, newgrf_d).sel->IsOpenTTDBaseGRF()) w->DisableWidget(SNGRFS_REMOVE);
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   298
	}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   299
}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   300
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   301
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   302
static void SetupNewGRFWindow(Window *w)
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   303
{
5345
4bc0f4814f15 (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   304
	const GRFConfig *c;
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   305
	int i;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   306
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   307
	for (c = *WP(w, newgrf_d).list, i = 0; c != NULL; c = c->next, i++);
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   308
5345
4bc0f4814f15 (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   309
	w->vscroll.cap = (w->widget[SNGRFS_FILE_LIST].bottom - w->widget[SNGRFS_FILE_LIST].top) / 14 + 1;
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   310
	SetVScrollCount(w, i);
7997
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7928
diff changeset
   311
	w->SetWidgetDisabledState(SNGRFS_APPLY_CHANGES, !WP(w, newgrf_d).editable);
5352
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   312
}
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   313
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   314
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   315
/** Callback function for the newgrf 'apply changes' confirmation window
6488
b6c42e91bb35 (svn r9669) -Documentation: some more doxygen fixes
belugas
parents: 6377
diff changeset
   316
 * @param w Window which is calling this callback
b6c42e91bb35 (svn r9669) -Documentation: some more doxygen fixes
belugas
parents: 6377
diff changeset
   317
 * @param confirmed boolean value, true when yes was clicked, false otherwise
b6c42e91bb35 (svn r9669) -Documentation: some more doxygen fixes
belugas
parents: 6377
diff changeset
   318
 */
5418
793a133c6d2a (svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents: 5364
diff changeset
   319
static void NewGRFConfirmationCallback(Window *w, bool confirmed)
5352
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   320
{
5418
793a133c6d2a (svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents: 5364
diff changeset
   321
	if (confirmed) {
5352
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   322
		newgrf_d *nd = &WP(w, newgrf_d);
5635
9464b3edb2ea (svn r8094) -Feature/Fix (r7523): Show the activated status of the GRF list after pressing 'apply'
Darkvater
parents: 5634
diff changeset
   323
		GRFConfig *c;
9464b3edb2ea (svn r8094) -Feature/Fix (r7523): Show the activated status of the GRF list after pressing 'apply'
Darkvater
parents: 5634
diff changeset
   324
		int i = 0;
5352
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   325
6956
3579bfc5157b (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 6873
diff changeset
   326
		CopyGRFConfigList(nd->orig_list, *nd->list, false);
5352
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   327
		ReloadNewGRFData();
5635
9464b3edb2ea (svn r8094) -Feature/Fix (r7523): Show the activated status of the GRF list after pressing 'apply'
Darkvater
parents: 5634
diff changeset
   328
9464b3edb2ea (svn r8094) -Feature/Fix (r7523): Show the activated status of the GRF list after pressing 'apply'
Darkvater
parents: 5634
diff changeset
   329
		/* Show new, updated list */
9464b3edb2ea (svn r8094) -Feature/Fix (r7523): Show the activated status of the GRF list after pressing 'apply'
Darkvater
parents: 5634
diff changeset
   330
		for (c = *nd->list; c != NULL && c != nd->sel; c = c->next, i++);
6956
3579bfc5157b (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 6873
diff changeset
   331
		CopyGRFConfigList(nd->list, *nd->orig_list, false);
5635
9464b3edb2ea (svn r8094) -Feature/Fix (r7523): Show the activated status of the GRF list after pressing 'apply'
Darkvater
parents: 5634
diff changeset
   332
		for (c = *nd->list; c != NULL && i > 0; c = c->next, i--);
9464b3edb2ea (svn r8094) -Feature/Fix (r7523): Show the activated status of the GRF list after pressing 'apply'
Darkvater
parents: 5634
diff changeset
   333
		nd->sel = c;
9464b3edb2ea (svn r8094) -Feature/Fix (r7523): Show the activated status of the GRF list after pressing 'apply'
Darkvater
parents: 5634
diff changeset
   334
9464b3edb2ea (svn r8094) -Feature/Fix (r7523): Show the activated status of the GRF list after pressing 'apply'
Darkvater
parents: 5634
diff changeset
   335
		SetWindowDirty(w);
5352
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   336
	}
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   337
}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   338
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   339
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   340
static void NewGRFWndProc(Window *w, WindowEvent *e)
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   341
{
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   342
	switch (e->event) {
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   343
		case WE_PAINT: {
5345
4bc0f4814f15 (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   344
			const GRFConfig *c;
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   345
			int i, y;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   346
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   347
			SetupNewGRFState(w);
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   348
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   349
			DrawWindowWidgets(w);
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   350
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   351
			/* Draw NewGRF list */
5345
4bc0f4814f15 (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   352
			y = w->widget[SNGRFS_FILE_LIST].top;
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   353
			for (c = *WP(w, newgrf_d).list, i = 0; c != NULL; c = c->next, i++) {
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   354
				if (i >= w->vscroll.pos && i < w->vscroll.pos + w->vscroll.cap) {
5638
ee1871005c80 (svn r8097) Replace strlen() {==,!=,>} 0 by the more concise {,!}StrEmpty(). Additionally the test takes O(1) instead of O(n) now
tron
parents: 5635
diff changeset
   355
					const char *text = (c->name != NULL && !StrEmpty(c->name)) ? c->name : c->filename;
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5647
diff changeset
   356
					SpriteID pal;
7737
9d3de4ed7e60 (svn r11272) -Codechange: Truncate text describing the grf file in the NewGrf settings gui
belugas
parents: 7680
diff changeset
   357
					byte txtoffset;
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   358
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   359
					/* Pick a colour */
6229
695400602ab0 (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6166
diff changeset
   360
					switch (c->status) {
695400602ab0 (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6166
diff changeset
   361
						case GCS_NOT_FOUND:
695400602ab0 (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6166
diff changeset
   362
						case GCS_DISABLED:
695400602ab0 (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6166
diff changeset
   363
							pal = PALETTE_TO_RED;
695400602ab0 (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6166
diff changeset
   364
							break;
695400602ab0 (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6166
diff changeset
   365
						case GCS_ACTIVATED:
695400602ab0 (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6166
diff changeset
   366
							pal = PALETTE_TO_GREEN;
695400602ab0 (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6166
diff changeset
   367
							break;
695400602ab0 (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6166
diff changeset
   368
						default:
695400602ab0 (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6166
diff changeset
   369
							pal = PALETTE_TO_BLUE;
695400602ab0 (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6166
diff changeset
   370
							break;
695400602ab0 (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6166
diff changeset
   371
					}
695400602ab0 (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6166
diff changeset
   372
7779
fa1586b64dc8 (svn r11329) -Fix: if a NewGRF failed to load for some reason (like fatal errors), but it was a "compatible" NewGRF, it was shown with the compatible colour and not the not-loaded colour in the NewGRF list.
rubidium
parents: 7737
diff changeset
   373
					/* Do not show a "not-failure" colour when it actually failed to load */
fa1586b64dc8 (svn r11329) -Fix: if a NewGRF failed to load for some reason (like fatal errors), but it was a "compatible" NewGRF, it was shown with the compatible colour and not the not-loaded colour in the NewGRF list.
rubidium
parents: 7737
diff changeset
   374
					if (pal != PALETTE_TO_RED) {
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7882
diff changeset
   375
						if (HasBit(c->flags, GCF_STATIC)) {
7779
fa1586b64dc8 (svn r11329) -Fix: if a NewGRF failed to load for some reason (like fatal errors), but it was a "compatible" NewGRF, it was shown with the compatible colour and not the not-loaded colour in the NewGRF list.
rubidium
parents: 7737
diff changeset
   376
							pal = PALETTE_TO_GREY;
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7882
diff changeset
   377
						} else if (HasBit(c->flags, GCF_COMPATIBLE)) {
7779
fa1586b64dc8 (svn r11329) -Fix: if a NewGRF failed to load for some reason (like fatal errors), but it was a "compatible" NewGRF, it was shown with the compatible colour and not the not-loaded colour in the NewGRF list.
rubidium
parents: 7737
diff changeset
   378
							pal = PALETTE_TO_ORANGE;
fa1586b64dc8 (svn r11329) -Fix: if a NewGRF failed to load for some reason (like fatal errors), but it was a "compatible" NewGRF, it was shown with the compatible colour and not the not-loaded colour in the NewGRF list.
rubidium
parents: 7737
diff changeset
   379
						}
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   380
					}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   381
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5647
diff changeset
   382
					DrawSprite(SPR_SQUARE, pal, 5, y + 2);
6103
d38163ddfef9 (svn r8838) -Feature: Show newgrf error messages loaded in Action B in the newgrf gui
maedhros
parents: 5893
diff changeset
   383
					if (c->error != NULL) DrawSprite(SPR_WARNING_SIGN, 0, 20, y + 2);
7737
9d3de4ed7e60 (svn r11272) -Codechange: Truncate text describing the grf file in the NewGrf settings gui
belugas
parents: 7680
diff changeset
   384
					txtoffset = c->error != NULL ? 35 : 25;
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 7779
diff changeset
   385
					DoDrawStringTruncated(text, txtoffset, y + 3, WP(w, newgrf_d).sel == c ? TC_WHITE : TC_BLACK, w->width - txtoffset - 10);
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   386
					y += 14;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   387
				}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   388
			}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   389
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   390
			if (WP(w, newgrf_d).sel != NULL) {
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   391
				/* Draw NewGRF file info */
5345
4bc0f4814f15 (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   392
				const Widget *wi = &w->widget[SNGRFS_NEWGRF_INFO];
6377
c1bc323eaf0c (svn r9449) -Fix: Truncate the newgrf information text in the newgrf gui if it's too long.
maedhros
parents: 6348
diff changeset
   393
				ShowNewGRFInfo(WP(w, newgrf_d).sel, wi->left + 2, wi->top + 2, wi->right - wi->left - 2, wi->bottom, WP(w, newgrf_d).show_params);
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   394
			}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   395
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   396
			break;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   397
		}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   398
5241
4b5b63946288 (svn r7363) -Fix (r7357): Update count of NewGRFs when adding an file
peter1138
parents: 5237
diff changeset
   399
		case WE_INVALIDATE_DATA:
4b5b63946288 (svn r7363) -Fix (r7357): Update count of NewGRFs when adding an file
peter1138
parents: 5237
diff changeset
   400
			SetupNewGRFWindow(w);
4b5b63946288 (svn r7363) -Fix (r7357): Update count of NewGRFs when adding an file
peter1138
parents: 5237
diff changeset
   401
			break;
4b5b63946288 (svn r7363) -Fix (r7357): Update count of NewGRFs when adding an file
peter1138
parents: 5237
diff changeset
   402
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   403
		case WE_CLICK:
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   404
			switch (e->we.click.widget) {
6348
6dd01da7a02b (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6248
diff changeset
   405
				case SNGRFS_ADD: { // Add GRF
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   406
					GRFConfig **list = WP(w, newgrf_d).list;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   407
					Window *w;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   408
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   409
					DeleteWindowByClass(WC_SAVELOAD);
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   410
					w = AllocateWindowDesc(&_newgrf_add_dlg_desc);
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   411
					w->resize.step_height = 10;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   412
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   413
					WP(w, newgrf_add_d).list = list;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   414
					break;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   415
				}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   416
6348
6dd01da7a02b (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6248
diff changeset
   417
				case SNGRFS_REMOVE: { // Remove GRF
5248
45dba213783a (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
   418
					GRFConfig **pc, *c, *newsel;
45dba213783a (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
   419
45dba213783a (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
   420
					/* Choose the next GRF file to be the selected file */
45dba213783a (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
   421
					newsel = WP(w, newgrf_d).sel->next;
45dba213783a (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
   422
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   423
					for (pc = WP(w, newgrf_d).list; (c = *pc) != NULL; pc = &c->next) {
5248
45dba213783a (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
   424
						/* If the new selection is empty (i.e. we're deleting the last item
45dba213783a (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
   425
						 * in the list, pick the file just before the selected file */
45dba213783a (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
   426
						if (newsel == NULL && c->next == WP(w, newgrf_d).sel) newsel = c;
45dba213783a (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
   427
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   428
						if (c == WP(w, newgrf_d).sel) {
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   429
							*pc = c->next;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   430
							free(c);
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   431
							break;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   432
						}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   433
					}
5248
45dba213783a (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
   434
45dba213783a (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
   435
					WP(w, newgrf_d).sel = newsel;
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   436
					SetupNewGRFWindow(w);
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   437
					SetWindowDirty(w);
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   438
					break;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   439
				}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   440
6348
6dd01da7a02b (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6248
diff changeset
   441
				case SNGRFS_MOVE_UP: { // Move GRF up
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   442
					GRFConfig **pc, *c;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   443
					if (WP(w, newgrf_d).sel == NULL) break;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   444
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   445
					for (pc = WP(w, newgrf_d).list; (c = *pc) != NULL; pc = &c->next) {
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   446
						if (c->next == WP(w, newgrf_d).sel) {
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   447
							c->next = WP(w, newgrf_d).sel->next;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   448
							WP(w, newgrf_d).sel->next = c;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   449
							*pc = WP(w, newgrf_d).sel;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   450
							break;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   451
						}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   452
					}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   453
					SetWindowDirty(w);
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   454
					break;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   455
				}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   456
6348
6dd01da7a02b (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6248
diff changeset
   457
				case SNGRFS_MOVE_DOWN: { // Move GRF down
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   458
					GRFConfig **pc, *c;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   459
					if (WP(w, newgrf_d).sel == NULL) break;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   460
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   461
					for (pc = WP(w, newgrf_d).list; (c = *pc) != NULL; pc = &c->next) {
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   462
						if (c == WP(w, newgrf_d).sel) {
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   463
							*pc = c->next;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   464
							c->next = c->next->next;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   465
							(*pc)->next = c;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   466
							break;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   467
						}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   468
					}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   469
					SetWindowDirty(w);
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   470
					break;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   471
				}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   472
6348
6dd01da7a02b (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6248
diff changeset
   473
				case SNGRFS_FILE_LIST: { // Select a GRF
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   474
					GRFConfig *c;
5345
4bc0f4814f15 (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   475
					uint i = (e->we.click.pt.y - w->widget[SNGRFS_FILE_LIST].top) / 14 + w->vscroll.pos;
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   476
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   477
					for (c = *WP(w, newgrf_d).list; c != NULL && i > 0; c = c->next, i--);
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   478
					WP(w, newgrf_d).sel = c;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   479
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   480
					SetWindowDirty(w);
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   481
					break;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   482
				}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   483
6348
6dd01da7a02b (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6248
diff changeset
   484
				case SNGRFS_APPLY_CHANGES: // Apply changes made to GRF list
5352
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   485
					if (WP(w, newgrf_d).execute) {
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   486
						ShowQuery(
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   487
							STR_POPUP_CAUTION_CAPTION,
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   488
							STR_NEWGRF_CONFIRMATION_TEXT,
5418
793a133c6d2a (svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents: 5364
diff changeset
   489
							w,
793a133c6d2a (svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents: 5364
diff changeset
   490
							NewGRFConfirmationCallback
5352
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   491
						);
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   492
					} else {
6956
3579bfc5157b (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 6873
diff changeset
   493
						CopyGRFConfigList(WP(w, newgrf_d).orig_list, *WP(w, newgrf_d).list, true);
3579bfc5157b (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 6873
diff changeset
   494
						ResetGRFConfig(false);
3579bfc5157b (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 6873
diff changeset
   495
						ReloadNewGRFData();
5352
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   496
					}
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   497
					break;
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   498
6348
6dd01da7a02b (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6248
diff changeset
   499
				case SNGRFS_SET_PARAMETERS: { // Edit parameters
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   500
					char buff[512];
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   501
					if (WP(w, newgrf_d).sel == NULL) break;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   502
5308
990a4b188233 (svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents: 5248
diff changeset
   503
					GRFBuildParamList(buff, WP(w, newgrf_d).sel, lastof(buff));
5431
6e56b4f13dd7 (svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents: 5418
diff changeset
   504
					ShowQueryString(BindCString(buff), STR_NEWGRF_PARAMETER_QUERY, 63, 250, w, CS_ALPHANUMERAL);
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   505
					break;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   506
				}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   507
			}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   508
			break;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   509
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   510
		case WE_ON_EDIT_TEXT:
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   511
			if (e->we.edittext.str != NULL) {
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   512
				/* Parse our new "int list" */
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   513
				GRFConfig *c = WP(w, newgrf_d).sel;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   514
				c->num_params = parse_intlist(e->we.edittext.str, (int*)c->param, lengthof(c->param));
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   515
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   516
				/* parse_intlist returns -1 on error */
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   517
				if (c->num_params == (byte)-1) c->num_params = 0;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   518
			}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   519
			SetWindowDirty(w);
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   520
			break;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   521
5352
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   522
		case WE_DESTROY:
6166
07ccb150663d (svn r8920) -Codechange: Do not require to press 'Apply changes' in the newgrf GUI if the changes in there are not activated (this happens in the title screen)
Darkvater
parents: 6164
diff changeset
   523
			if (!WP(w, newgrf_d).execute) {
6956
3579bfc5157b (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 6873
diff changeset
   524
				CopyGRFConfigList(WP(w, newgrf_d).orig_list, *WP(w, newgrf_d).list, true);
3579bfc5157b (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 6873
diff changeset
   525
				ResetGRFConfig(false);
3579bfc5157b (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 6873
diff changeset
   526
				ReloadNewGRFData();
6166
07ccb150663d (svn r8920) -Codechange: Do not require to press 'Apply changes' in the newgrf GUI if the changes in there are not activated (this happens in the title screen)
Darkvater
parents: 6164
diff changeset
   527
			}
5352
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   528
			/* Remove the temporary copy of grf-list used in window */
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   529
			ClearGRFConfigList(WP(w, newgrf_d).list);
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   530
			break;
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   531
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   532
		case WE_RESIZE:
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   533
			w->vscroll.cap += e->we.sizing.diff.y / 14;
5345
4bc0f4814f15 (svn r7516) -Codechange: Number the newgrf-gui widgets and use their symbolic names for access with some const goodness.
Darkvater
parents: 5339
diff changeset
   534
			w->widget[SNGRFS_FILE_LIST].data = (w->vscroll.cap << 8) + 1;
7680
d325e2af5bc1 (svn r11211) -Fix [FS#1302]: NewGRF GUI scrollbar does funny things when being resized.
rubidium
parents: 7341
diff changeset
   535
			SetupNewGRFWindow(w);
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   536
			break;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   537
	}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   538
}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   539
8025
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   540
/* Widget definition of the manage newgrfs window */
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   541
static const Widget _newgrf_widgets[] = {
8025
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   542
{   WWT_CLOSEBOX,  RESIZE_NONE, 10,   0,  10,   0,  13, STR_00C5,                    STR_018B_CLOSE_WINDOW },            // SNGRFS_CLOSEBOX
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   543
{    WWT_CAPTION, RESIZE_RIGHT, 10,  11, 299,   0,  13, STR_NEWGRF_SETTINGS_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS },  // SNGRFS_CAPTION
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   544
{      WWT_PANEL, RESIZE_RIGHT, 10,   0, 299,  14,  29, STR_NULL,                    STR_NULL },                         // SNGRFS_BACKGROUND
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   545
{ WWT_PUSHTXTBTN,  RESIZE_NONE,  3,  10,  79,  16,  27, STR_NEWGRF_ADD,              STR_NEWGRF_ADD_TIP },               // SNGRFS_ADD
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   546
{ WWT_PUSHTXTBTN,  RESIZE_NONE,  3,  80, 149,  16,  27, STR_NEWGRF_REMOVE,           STR_NEWGRF_REMOVE_TIP },            // SNGRFS_REMOVE
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   547
{ WWT_PUSHTXTBTN,  RESIZE_NONE,  3, 150, 219,  16,  27, STR_NEWGRF_MOVEUP,           STR_NEWGRF_MOVEUP_TIP },            // SNGRFS_MOVE_UP
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   548
{ WWT_PUSHTXTBTN,  RESIZE_NONE,  3, 220, 289,  16,  27, STR_NEWGRF_MOVEDOWN,         STR_NEWGRF_MOVEDOWN_TIP },          // SNGRFS_MOVE_DOWN
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   549
{     WWT_MATRIX,    RESIZE_RB, 10,   0, 287,  30,  99, 0x501,                       STR_NEWGRF_FILE_TIP },              // SNGRFS_FILE_LIST
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   550
{  WWT_SCROLLBAR,   RESIZE_LRB, 10, 288, 299,  30,  99, 0x0,                         STR_0190_SCROLL_BAR_SCROLLS_LIST }, // SNGRFS_SCROLLBAR
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   551
{      WWT_PANEL,   RESIZE_RTB, 10,   0, 299, 100, 212, STR_NULL,                    STR_NULL },                         // SNGRFS_NEWGRF_INFO
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   552
{ WWT_PUSHTXTBTN,    RESIZE_TB, 10,   0, 143, 213, 224, STR_NEWGRF_SET_PARAMETERS,   STR_NULL },                         // SNGRFS_SET_PARAMETERS
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   553
{ WWT_PUSHTXTBTN,   RESIZE_RTB, 10, 144, 287, 213, 224, STR_NEWGRF_APPLY_CHANGES,    STR_NULL },                         // SNGRFS_APPLY_CHANGES
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   554
{  WWT_RESIZEBOX,  RESIZE_LRTB, 10, 288, 299, 213, 224, 0x0,                         STR_RESIZE_BUTTON },                // SNGRFS_RESIZE
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   555
{ WIDGETS_END },
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   556
};
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   557
8025
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   558
/* Window definition of the manage newgrfs window */
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   559
static const WindowDesc _newgrf_desc = {
7341
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7034
diff changeset
   560
	WDP_CENTER, WDP_CENTER, 300, 225, 300, 225,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5668
diff changeset
   561
	WC_GAME_OPTIONS, WC_NONE,
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   562
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   563
	_newgrf_widgets,
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   564
	NewGRFWndProc,
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   565
};
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   566
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   567
5352
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   568
/** Setup the NewGRF gui
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   569
 * @param editable allow the user to make changes to the grfconfig in the window
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   570
 * @param show_params show information about what parameters are set for the grf files
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   571
 * @param exec_changes if changes are made to the list (editable is true), apply these
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   572
 *        changes immediately or only update the list
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   573
 * @param config pointer to a linked-list of grfconfig's that will be shown */
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   574
void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config)
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   575
{
5352
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   576
	static GRFConfig *local = NULL;
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   577
	Window *w;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   578
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   579
	DeleteWindowByClass(WC_GAME_OPTIONS);
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   580
	w = AllocateWindowDesc(&_newgrf_desc);
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   581
	if (w == NULL) return;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   582
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   583
	w->resize.step_height = 14;
6956
3579bfc5157b (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 6873
diff changeset
   584
	CopyGRFConfigList(&local, *config, false);
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   585
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   586
	/* Clear selections */
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   587
	WP(w, newgrf_d).sel         = NULL;
5352
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   588
	WP(w, newgrf_d).list        = &local;
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   589
	WP(w, newgrf_d).orig_list   = config;
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   590
	WP(w, newgrf_d).editable    = editable;
5352
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   591
	WP(w, newgrf_d).execute     = exec_changes;
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   592
	WP(w, newgrf_d).show_params = show_params;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   593
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   594
	SetupNewGRFWindow(w);
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   595
}