src/newgrf_gui.cpp
author peter1138
Thu, 12 Jun 2008 09:25:04 +0000
changeset 9502 8c67bbeb7efd
parent 9457 75f11a6caef8
child 9648 c79160082c0f
permissions -rw-r--r--
(svn r13482) -Codechange: Use "extended bytes" in Actions 3 and 4 for vehicles
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
9111
48ce04029fe4 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 8749
diff changeset
     3
/** @file newgrf_gui.cpp GUI to change NewGRF settings. */
6348
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"
9457
75f11a6caef8 (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents: 9317
diff changeset
    18
#include "gamelog.h"
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    19
8264
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/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
    21
#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
    22
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    23
/** 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
    24
 * @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
    25
 * comma or a space character
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    26
 * @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
    27
 * @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
    28
 * @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
    29
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
    30
{
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    31
	int n = 0, v;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    32
	char *end;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    33
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    34
	for (;;) {
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    35
		v = strtol(p, &end, 0);
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    36
		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
    37
		p = end;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    38
		items[n++] = v;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    39
		if (*p == '\0') break;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    40
		if (*p != ',' && *p != ' ') return -1;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    41
		p++;
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
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    44
	return n;
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
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    47
6377
c1bc323eaf0c (svn r9449) -Fix: Truncate the newgrf information text in the newgrf gui if it's too long.
maedhros
parents: 6348
diff changeset
    48
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
    49
{
5634
ba6b9ebe197a (svn r8093) -Codechange: Add a function to get a string representation of an MD5SUM and use it.
Darkvater
parents: 5609
diff changeset
    50
	char buff[256];
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    51
6103
d38163ddfef9 (svn r8838) -Feature: Show newgrf error messages loaded in Action B in the newgrf gui
maedhros
parents: 5893
diff changeset
    52
	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
    53
		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
    54
		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
    55
		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
    56
			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
    57
			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
    58
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
			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
    60
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
			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
    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
cd42df0c1f0f (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6103
diff changeset
    64
		char message[512];
6873
b4d0648edd29 (svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents: 6783
diff changeset
    65
		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
    66
cd42df0c1f0f (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6103
diff changeset
    67
		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
    68
		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
    69
	}
d38163ddfef9 (svn r8838) -Feature: Show newgrf error messages loaded in Action B in the newgrf gui
maedhros
parents: 5893
diff changeset
    70
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
    71
	/* 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
    72
	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
    73
		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
    74
		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
    75
	}
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    76
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    77
	/* Prepare and draw GRF ID */
5643
b373887faf8b (svn r8102) -Cleanup: Remove unreachable code (r8096), useless cast
Darkvater
parents: 5638
diff changeset
    78
	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
    79
	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
    80
	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
    81
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    82
	/* 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
    83
	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
    84
	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
    85
	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
    86
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    87
	/* Show GRF parameter list */
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    88
	if (show_params) {
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    89
		if (c->num_params > 0) {
5308
990a4b188233 (svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents: 5248
diff changeset
    90
			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
    91
			SetDParamStr(0, buff);
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    92
		} else {
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    93
			SetDParam(0, STR_01A9_NONE);
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    94
		}
6377
c1bc323eaf0c (svn r9449) -Fix: Truncate the newgrf information text in the newgrf gui if it's too long.
maedhros
parents: 6348
diff changeset
    95
		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
    96
	}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    97
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    98
	/* 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
    99
	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
   100
	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
   101
	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
   102
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   103
	/* 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
   104
	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
   105
		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
   106
		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
   107
	} 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
   108
		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
   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
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   113
/**
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   114
 * Window for adding NewGRF files
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   115
 */
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   116
struct NewGRFAddWindow : public Window {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   117
	/* Names of the add a newgrf window widgets */
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   118
	enum AddNewGRFWindowWidgets {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   119
		ANGRFW_CLOSEBOX = 0,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   120
		ANGRFW_CAPTION,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   121
		ANGRFW_BACKGROUND,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   122
		ANGRFW_GRF_LIST,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   123
		ANGRFW_SCROLLBAR,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   124
		ANGRFW_GRF_INFO,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   125
		ANGRFW_ADD,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   126
		ANGRFW_RESCAN,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   127
		ANGRFW_RESIZE,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   128
	};
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   129
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   130
	GRFConfig **list;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   131
	const GRFConfig *sel;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   132
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   133
	NewGRFAddWindow(const WindowDesc *desc, GRFConfig **list) : Window(desc, 0)
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   134
	{
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   135
		this->list = list;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   136
		this->resize.step_height = 10;
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   137
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   138
		this->FindWindowPlacementAndResize(desc);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   139
	}
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   140
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   141
	virtual void OnPaint()
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   142
	{
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   143
		const GRFConfig *c;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   144
		const Widget *wl = &this->widget[ANGRFW_GRF_LIST];
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   145
		int n = 0;
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   146
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   147
		/* Count the number of GRFs */
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   148
		for (c = _all_grfs; c != NULL; c = c->next) n++;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   149
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   150
		this->vscroll.cap = (wl->bottom - wl->top) / 10;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   151
		SetVScrollCount(this, n);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   152
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   153
		this->SetWidgetDisabledState(ANGRFW_ADD, this->sel == NULL || this->sel->IsOpenTTDBaseGRF());
9273
35e0224ea8f1 (svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents: 9207
diff changeset
   154
		this->DrawWidgets();
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   155
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   156
		GfxFillRect(wl->left + 1, wl->top + 1, wl->right, wl->bottom, 0xD7);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   157
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   158
		uint y = wl->top + 1;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   159
		for (c = _all_grfs, n = 0; c != NULL && n < (this->vscroll.pos + this->vscroll.cap); c = c->next, n++) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   160
			if (n >= this->vscroll.pos) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   161
				bool h = c == this->sel;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   162
				const char *text = (c->name != NULL && !StrEmpty(c->name)) ? c->name : c->filename;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   163
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   164
				/* Draw selection background */
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   165
				if (h) GfxFillRect(3, y, this->width - 15, y + 9, 156);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   166
				DoDrawStringTruncated(text, 4, y, h ? TC_WHITE : TC_ORANGE, this->width - 18);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   167
				y += 10;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   168
			}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   169
		}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   170
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   171
		if (this->sel != NULL) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   172
			const Widget *wi = &this->widget[ANGRFW_GRF_INFO];
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   173
			ShowNewGRFInfo(this->sel, wi->left + 2, wi->top + 2, wi->right - wi->left - 2, wi->bottom, false);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   174
		}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   175
	}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   176
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   177
	virtual void OnDoubleClick(Point pt, int widget)
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   178
	{
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   179
		if (widget == ANGRFW_GRF_LIST) this->OnClick(pt, ANGRFW_ADD);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   180
	}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   181
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   182
	virtual void OnClick(Point pt, int widget)
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   183
	{
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   184
		switch (widget) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   185
			case ANGRFW_GRF_LIST: {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   186
				/* Get row... */
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   187
				const GRFConfig *c;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   188
				uint i = (pt.y - this->widget[ANGRFW_GRF_LIST].top) / 10 + this->vscroll.pos;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   189
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   190
				for (c = _all_grfs; c != NULL && i > 0; c = c->next, i--) {}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   191
				this->sel = c;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   192
				this->SetDirty();
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   193
				break;
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   194
			}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   195
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   196
			case ANGRFW_ADD: // Add selection to list
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   197
				if (this->sel != NULL) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   198
					const GRFConfig *src = this->sel;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   199
					GRFConfig **list;
5243
29235600e8fc (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   200
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   201
					/* Find last entry in the list, checking for duplicate grfid on the way */
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   202
					for (list = this->list; *list != NULL; list = &(*list)->next) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   203
						if ((*list)->grfid == src->grfid) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   204
							ShowErrorMessage(INVALID_STRING_ID, STR_NEWGRF_DUPLICATE_GRFID, 0, 0);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   205
							return;
5243
29235600e8fc (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   206
						}
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   207
					}
5243
29235600e8fc (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   208
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   209
					/* Copy GRF details from scanned list */
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   210
					GRFConfig *c = CallocT<GRFConfig>(1);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   211
					*c = *src;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   212
					c->filename = strdup(src->filename);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   213
					if (src->name      != NULL) c->name      = strdup(src->name);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   214
					if (src->info      != NULL) c->info      = strdup(src->info);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   215
					c->next = NULL;
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   216
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   217
					/* Append GRF config to configuration list */
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   218
					*list = c;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   219
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   220
					DeleteWindowByClass(WC_SAVELOAD);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   221
					InvalidateWindowData(WC_GAME_OPTIONS, 0);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   222
				}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   223
				break;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   224
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   225
			case ANGRFW_RESCAN: // Rescan list
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   226
				this->sel = NULL;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   227
				ScanNewGRFFiles();
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   228
				this->SetDirty();
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   229
				break;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   230
		}
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   231
	}
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   232
};
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   233
8025
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   234
/* 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
   235
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
   236
{   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
   237
{    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
   238
{      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
   239
{      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
   240
{  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
   241
{      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
   242
{ 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
   243
{ 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
   244
{  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
   245
{   WIDGETS_END },
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   246
};
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   247
8025
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   248
/* 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
   249
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
   250
	WDP_CENTER, WDP_CENTER, 307, 237, 307, 337,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5668
diff changeset
   251
	WC_SAVELOAD, WC_NONE,
8019
fc0e94dee165 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8018
diff changeset
   252
	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
   253
	_newgrf_add_dlg_widgets,
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   254
};
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   255
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   256
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   257
static void NewGRFConfirmationCallback(Window *w, bool confirmed);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   258
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   259
/**
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   260
 * Window for showing NewGRF files
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   261
 */
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   262
struct NewGRFWindow : public Window {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   263
	/* Names of the manage newgrfs window widgets */
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   264
	enum ShowNewGRFStateWidgets {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   265
		SNGRFS_CLOSEBOX = 0,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   266
		SNGRFS_CAPTION,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   267
		SNGRFS_BACKGROUND,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   268
		SNGRFS_ADD,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   269
		SNGRFS_REMOVE,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   270
		SNGRFS_MOVE_UP,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   271
		SNGRFS_MOVE_DOWN,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   272
		SNGRFS_FILE_LIST,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   273
		SNGRFS_SCROLLBAR,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   274
		SNGRFS_NEWGRF_INFO,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   275
		SNGRFS_SET_PARAMETERS,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   276
		SNGRFS_APPLY_CHANGES,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   277
		SNGRFS_RESIZE,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   278
	};
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   279
5352
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   280
	GRFConfig **orig_list; ///< grf list the window is shown with
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   281
	GRFConfig *list;       ///< temporary grf list to which changes are made
5352
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   282
	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
   283
	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
   284
	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
   285
	bool execute;          ///< on pressing 'apply changes' are grf changes applied immediately, or only list is updated
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   286
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   287
	NewGRFWindow(const WindowDesc *desc, bool editable, bool show_params, bool exec_changes, GRFConfig **config) : Window(desc, 0)
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   288
	{
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   289
		this->resize.step_height = 14;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   290
		this->sel         = NULL;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   291
		this->list        = NULL;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   292
		this->orig_list   = config;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   293
		this->editable    = editable;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   294
		this->execute     = exec_changes;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   295
		this->show_params = show_params;
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   296
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   297
		CopyGRFConfigList(&this->list, *config, false);
6229
695400602ab0 (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6166
diff changeset
   298
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   299
		this->FindWindowPlacementAndResize(desc);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   300
		this->SetupNewGRFWindow();
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   301
	}
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   302
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   303
	~NewGRFWindow()
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   304
	{
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   305
		if (!this->execute) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   306
			CopyGRFConfigList(this->orig_list, this->list, true);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   307
			ResetGRFConfig(false);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   308
			ReloadNewGRFData();
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   309
		}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   310
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   311
		/* Remove the temporary copy of grf-list used in window */
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   312
		ClearGRFConfigList(&this->list);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   313
	}
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
   314
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   315
	void SetupNewGRFWindow()
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   316
	{
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   317
		const GRFConfig *c;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   318
		int i;
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
   319
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   320
		for (c = this->list, i = 0; c != NULL; c = c->next, i++) {}
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   321
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   322
		this->vscroll.cap = (this->widget[SNGRFS_FILE_LIST].bottom - this->widget[SNGRFS_FILE_LIST].top) / 14 + 1;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   323
		SetVScrollCount(this, i);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   324
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   325
		this->SetWidgetDisabledState(SNGRFS_ADD, !this->editable);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   326
		this->SetWidgetDisabledState(SNGRFS_APPLY_CHANGES, !this->editable);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   327
	}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   328
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   329
	virtual void OnPaint()
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   330
	{
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   331
		bool disable_all = this->sel == NULL || !this->editable;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   332
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   333
		this->SetWidgetsDisabledState(disable_all,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   334
			SNGRFS_REMOVE,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   335
			SNGRFS_MOVE_UP,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   336
			SNGRFS_MOVE_DOWN,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   337
			WIDGET_LIST_END
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   338
		);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   339
		this->SetWidgetDisabledState(SNGRFS_SET_PARAMETERS, !this->show_params || disable_all);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   340
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   341
		if (!disable_all) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   342
			/* All widgets are now enabled, so disable widgets we can't use */
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   343
			if (this->sel == this->list)       this->DisableWidget(SNGRFS_MOVE_UP);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   344
			if (this->sel->next == NULL)       this->DisableWidget(SNGRFS_MOVE_DOWN);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   345
			if (this->sel->IsOpenTTDBaseGRF()) this->DisableWidget(SNGRFS_REMOVE);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   346
		}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   347
9273
35e0224ea8f1 (svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents: 9207
diff changeset
   348
		this->DrawWidgets();
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   349
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   350
		/* Draw NewGRF list */
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   351
		int y = this->widget[SNGRFS_FILE_LIST].top;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   352
		int i = 0;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   353
		for (const GRFConfig *c = this->list; c != NULL; c = c->next, i++) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   354
			if (i >= this->vscroll.pos && i < this->vscroll.pos + this->vscroll.cap) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   355
				const char *text = (c->name != NULL && !StrEmpty(c->name)) ? c->name : c->filename;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   356
				SpriteID pal;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   357
				byte txtoffset;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   358
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   359
				/* Pick a colour */
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   360
				switch (c->status) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   361
					case GCS_NOT_FOUND:
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   362
					case GCS_DISABLED:
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   363
						pal = PALETTE_TO_RED;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   364
						break;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   365
					case GCS_ACTIVATED:
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   366
						pal = PALETTE_TO_GREEN;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   367
						break;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   368
					default:
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   369
						pal = PALETTE_TO_BLUE;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   370
						break;
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   371
				}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   372
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   373
				/* Do not show a "not-failure" colour when it actually failed to load */
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   374
				if (pal != PALETTE_TO_RED) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   375
					if (HasBit(c->flags, GCF_STATIC)) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   376
						pal = PALETTE_TO_GREY;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   377
					} else if (HasBit(c->flags, GCF_COMPATIBLE)) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   378
						pal = PALETTE_TO_ORANGE;
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   379
					}
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
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   382
				DrawSprite(SPR_SQUARE, pal, 5, y + 2);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   383
				if (c->error != NULL) DrawSprite(SPR_WARNING_SIGN, 0, 20, y + 2);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   384
				txtoffset = c->error != NULL ? 35 : 25;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   385
				DoDrawStringTruncated(text, txtoffset, y + 3, this->sel == c ? TC_WHITE : TC_BLACK, this->width - txtoffset - 10);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   386
				y += 14;
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   387
			}
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   388
		}
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   389
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   390
		if (this->sel != NULL) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   391
			/* Draw NewGRF file info */
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   392
			const Widget *wi = &this->widget[SNGRFS_NEWGRF_INFO];
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   393
			ShowNewGRFInfo(this->sel, wi->left + 2, wi->top + 2, wi->right - wi->left - 2, wi->bottom, this->show_params);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   394
		}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   395
	}
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   396
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   397
	virtual void OnClick(Point pt, int widget)
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   398
	{
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   399
		switch (widget) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   400
			case SNGRFS_ADD: // Add GRF
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   401
				DeleteWindowByClass(WC_SAVELOAD);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   402
				new NewGRFAddWindow(&_newgrf_add_dlg_desc, &this->list);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   403
				break;
5352
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   404
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   405
			case SNGRFS_REMOVE: { // Remove GRF
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   406
				GRFConfig **pc, *c, *newsel;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   407
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   408
				/* Choose the next GRF file to be the selected file */
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   409
				newsel = this->sel->next;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   410
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   411
				for (pc = &this->list; (c = *pc) != NULL; pc = &c->next) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   412
					/* If the new selection is empty (i.e. we're deleting the last item
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   413
					 * in the list, pick the file just before the selected file */
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   414
					if (newsel == NULL && c->next == this->sel) newsel = c;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   415
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   416
					if (c == this->sel) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   417
						*pc = c->next;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   418
						free(c);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   419
						break;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   420
					}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   421
				}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   422
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   423
				this->sel = newsel;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   424
				this->SetupNewGRFWindow();
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   425
				this->SetDirty();
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   426
				break;
8591
d73cc7cd733c (svn r12172) -Codechange: Allow buttons to resize in NewGRF settings window
peter1138
parents: 8264
diff changeset
   427
			}
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   428
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   429
			case SNGRFS_MOVE_UP: { // Move GRF up
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   430
				GRFConfig **pc, *c;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   431
				if (this->sel == NULL) break;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   432
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   433
				for (pc = &this->list; (c = *pc) != NULL; pc = &c->next) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   434
					if (c->next == this->sel) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   435
						c->next = this->sel->next;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   436
						this->sel->next = c;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   437
						*pc = this->sel;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   438
						break;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   439
					}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   440
				}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   441
				this->SetDirty();
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   442
				break;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   443
			}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   444
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   445
			case SNGRFS_MOVE_DOWN: { // Move GRF down
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   446
				GRFConfig **pc, *c;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   447
				if (this->sel == NULL) break;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   448
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   449
				for (pc = &this->list; (c = *pc) != NULL; pc = &c->next) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   450
					if (c == this->sel) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   451
						*pc = c->next;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   452
						c->next = c->next->next;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   453
						(*pc)->next = c;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   454
						break;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   455
					}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   456
				}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   457
				this->SetDirty();
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   458
				break;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   459
			}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   460
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   461
			case SNGRFS_FILE_LIST: { // Select a GRF
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   462
				GRFConfig *c;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   463
				uint i = (pt.y - this->widget[SNGRFS_FILE_LIST].top) / 14 + this->vscroll.pos;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   464
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   465
				for (c = this->list; c != NULL && i > 0; c = c->next, i--) {}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   466
				this->sel = c;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   467
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   468
				this->SetDirty();
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   469
				break;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   470
			}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   471
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   472
			case SNGRFS_APPLY_CHANGES: // Apply changes made to GRF list
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   473
				if (this->execute) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   474
					ShowQuery(
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   475
						STR_POPUP_CAUTION_CAPTION,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   476
						STR_NEWGRF_CONFIRMATION_TEXT,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   477
						this,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   478
						NewGRFConfirmationCallback
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   479
					);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   480
				} else {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   481
					CopyGRFConfigList(this->orig_list, this->list, true);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   482
					ResetGRFConfig(false);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   483
					ReloadNewGRFData();
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   484
				}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   485
				break;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   486
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   487
			case SNGRFS_SET_PARAMETERS: { // Edit parameters
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   488
				if (this->sel == NULL) break;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   489
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   490
				char buff[512];
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   491
				GRFBuildParamList(buff, this->sel, lastof(buff));
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   492
				ShowQueryString(BindCString(buff), STR_NEWGRF_PARAMETER_QUERY, 63, 250, this, CS_ALPHANUMERAL);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   493
				break;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   494
			}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   495
		}
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   496
	}
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   497
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   498
	virtual void OnQueryTextFinished(char *str)
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   499
	{
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   500
		if (str == NULL) return;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   501
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   502
		/* Parse our new "int list" */
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   503
		GRFConfig *c = this->sel;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   504
		c->num_params = parse_intlist(str, (int*)c->param, lengthof(c->param));
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   505
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   506
		/* parse_intlist returns -1 on error */
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   507
		if (c->num_params == (byte)-1) c->num_params = 0;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   508
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   509
		this->SetDirty();
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   510
	}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   511
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   512
	virtual void OnResize(Point new_size, Point delta)
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   513
	{
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   514
		if (delta.x != 0) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   515
			ResizeButtons(this, SNGRFS_ADD, SNGRFS_MOVE_DOWN);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   516
			ResizeButtons(this, SNGRFS_SET_PARAMETERS, SNGRFS_APPLY_CHANGES);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   517
		}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   518
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   519
		this->vscroll.cap += delta.y / 14;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   520
		this->widget[SNGRFS_FILE_LIST].data = (this->vscroll.cap << 8) + 1;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   521
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   522
		this->SetupNewGRFWindow();
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   523
	}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   524
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   525
	virtual void OnInvalidateData(int data = 0)
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   526
	{
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   527
		this->SetupNewGRFWindow();
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   528
	}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   529
};
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   530
8025
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   531
/* 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
   532
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
   533
{   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
   534
{    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
   535
{      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
   536
{ 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
   537
{ 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
   538
{ WWT_PUSHTXTBTN,  RESIZE_NONE,  3, 150, 219,  16,  27, STR_NEWGRF_MOVEUP,           STR_NEWGRF_MOVEUP_TIP },            // SNGRFS_MOVE_UP
8591
d73cc7cd733c (svn r12172) -Codechange: Allow buttons to resize in NewGRF settings window
peter1138
parents: 8264
diff changeset
   539
{ WWT_PUSHTXTBTN, RESIZE_RIGHT,  3, 220, 289,  16,  27, STR_NEWGRF_MOVEDOWN,         STR_NEWGRF_MOVEDOWN_TIP },          // 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
   540
{     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
   541
{  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
   542
{      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
   543
{ 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
   544
{ 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
   545
{  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
   546
{ WIDGETS_END },
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   547
};
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   548
8025
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   549
/* 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
   550
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
   551
	WDP_CENTER, WDP_CENTER, 300, 225, 300, 225,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5668
diff changeset
   552
	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
   553
	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
   554
	_newgrf_widgets,
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   555
};
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   556
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   557
/** Callback function for the newgrf 'apply changes' confirmation window
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   558
 * @param w Window which is calling this callback
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   559
 * @param confirmed boolean value, true when yes was clicked, false otherwise
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   560
 */
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   561
static void NewGRFConfirmationCallback(Window *w, bool confirmed)
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   562
{
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   563
	if (confirmed) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   564
		NewGRFWindow *nw = dynamic_cast<NewGRFWindow*>(w);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   565
		GRFConfig *c;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   566
		int i = 0;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   567
9457
75f11a6caef8 (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents: 9317
diff changeset
   568
		GamelogStartAction(GLAT_GRF);
75f11a6caef8 (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents: 9317
diff changeset
   569
		GamelogGRFUpdate(_grfconfig, nw->list); // log GRF changes
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   570
		CopyGRFConfigList(nw->orig_list, nw->list, false);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   571
		ReloadNewGRFData();
9457
75f11a6caef8 (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents: 9317
diff changeset
   572
		GamelogStopAction();
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   573
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   574
		/* Show new, updated list */
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   575
		for (c = nw->list; c != NULL && c != nw->sel; c = c->next, i++) {}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   576
		CopyGRFConfigList(&nw->list, *nw->orig_list, false);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   577
		for (c = nw->list; c != NULL && i > 0; c = c->next, i--) {}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   578
		nw->sel = c;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   579
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   580
		w->SetDirty();
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   581
	}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   582
}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   583
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   584
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   585
5352
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   586
/** 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
   587
 * @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
   588
 * @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
   589
 * @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
   590
 *        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
   591
 * @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
   592
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
   593
{
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   594
	DeleteWindowByClass(WC_GAME_OPTIONS);
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   595
	new NewGRFWindow(&_newgrf_desc, editable, show_params, exec_changes, config);
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   596
}