src/newgrf_gui.cpp
author rubidium
Thu, 18 Dec 2008 12:23:08 +0000
changeset 10436 8d3a9fbe8f19
parent 10145 849ba8b8626b
permissions -rw-r--r--
(svn r14689) -Change: make configure die on commonly made user mistakes, like not having SDL development files or zlib headers installed; you can still compile a dedicated server or a binary without zlib, but you have to explicitly force it.
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"
9677
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
    19
#include "settings_func.h"
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
    20
#include "widgets/dropdown_type.h"
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    21
8264
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8224
diff changeset
    22
#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
    23
#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
    24
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    25
/** 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
    26
 * @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
    27
 * comma or a space character
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    28
 * @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
    29
 * @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
    30
 * @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
    31
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
    32
{
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    33
	int n = 0, v;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    34
	char *end;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    35
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    36
	for (;;) {
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    37
		v = strtol(p, &end, 0);
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    38
		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
    39
		p = end;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    40
		items[n++] = v;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    41
		if (*p == '\0') break;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    42
		if (*p != ',' && *p != ' ') return -1;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    43
		p++;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    44
	}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    45
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    46
	return n;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    47
}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    48
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    49
6377
c1bc323eaf0c (svn r9449) -Fix: Truncate the newgrf information text in the newgrf gui if it's too long.
maedhros
parents: 6348
diff changeset
    50
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
    51
{
5634
ba6b9ebe197a (svn r8093) -Codechange: Add a function to get a string representation of an MD5SUM and use it.
Darkvater
parents: 5609
diff changeset
    52
	char buff[256];
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    53
6103
d38163ddfef9 (svn r8838) -Feature: Show newgrf error messages loaded in Action B in the newgrf gui
maedhros
parents: 5893
diff changeset
    54
	if (c->error != NULL) {
9648
c79160082c0f (svn r13715) -Fix [FS#2129]: C-like strings had to be rebound each time they were printed, otherwise the text could change due to the few number of slots that could be used to bind.
rubidium
parents: 9457
diff changeset
    55
		char message[512];
9957
eee22936a397 (svn r14112) -Fix (r13715)[FS#2232]: Action B custom messages with parameteers were broken.
frosch
parents: 9864
diff changeset
    56
		SetDParamStr(0, c->error->custom_message); // is skipped by built-in messages
eee22936a397 (svn r14112) -Fix (r13715)[FS#2232]: Action B custom messages with parameteers were broken.
frosch
parents: 9864
diff changeset
    57
		SetDParam   (1, STR_JUST_RAW_STRING);
eee22936a397 (svn r14112) -Fix (r13715)[FS#2232]: Action B custom messages with parameteers were broken.
frosch
parents: 9864
diff changeset
    58
		SetDParamStr(2, c->filename);
eee22936a397 (svn r14112) -Fix (r13715)[FS#2232]: Action B custom messages with parameteers were broken.
frosch
parents: 9864
diff changeset
    59
		SetDParam   (3, STR_JUST_RAW_STRING);
eee22936a397 (svn r14112) -Fix (r13715)[FS#2232]: Action B custom messages with parameteers were broken.
frosch
parents: 9864
diff changeset
    60
		SetDParamStr(4, c->error->data);
eee22936a397 (svn r14112) -Fix (r13715)[FS#2232]: Action B custom messages with parameteers were broken.
frosch
parents: 9864
diff changeset
    61
		for (uint i = 0; i < c->error->num_params; i++) {
eee22936a397 (svn r14112) -Fix (r13715)[FS#2232]: Action B custom messages with parameteers were broken.
frosch
parents: 9864
diff changeset
    62
			uint32 param = 0;
eee22936a397 (svn r14112) -Fix (r13715)[FS#2232]: Action B custom messages with parameteers were broken.
frosch
parents: 9864
diff changeset
    63
			byte param_number = c->error->param_number[i];
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
    64
9957
eee22936a397 (svn r14112) -Fix (r13715)[FS#2232]: Action B custom messages with parameteers were broken.
frosch
parents: 9864
diff changeset
    65
			if (param_number < c->num_params) param = c->param[param_number];
9648
c79160082c0f (svn r13715) -Fix [FS#2129]: C-like strings had to be rebound each time they were printed, otherwise the text could change due to the few number of slots that could be used to bind.
rubidium
parents: 9457
diff changeset
    66
9957
eee22936a397 (svn r14112) -Fix (r13715)[FS#2232]: Action B custom messages with parameteers were broken.
frosch
parents: 9864
diff changeset
    67
			SetDParam(5 + i, param);
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
    68
		}
9957
eee22936a397 (svn r14112) -Fix (r13715)[FS#2232]: Action B custom messages with parameteers were broken.
frosch
parents: 9864
diff changeset
    69
		GetString(message, c->error->custom_message == NULL ? c->error->message : STR_JUST_RAW_STRING, 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
    70
cd42df0c1f0f (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6103
diff changeset
    71
		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
    72
		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
    73
	}
d38163ddfef9 (svn r8838) -Feature: Show newgrf error messages loaded in Action B in the newgrf gui
maedhros
parents: 5893
diff changeset
    74
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
	/* 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
    76
	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
    77
		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
    78
		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
    79
	}
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    80
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    81
	/* Prepare and draw GRF ID */
5643
b373887faf8b (svn r8102) -Cleanup: Remove unreachable code (r8096), useless cast
Darkvater
parents: 5638
diff changeset
    82
	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
    83
	SetDParamStr(0, buff);
6377
c1bc323eaf0c (svn r9449) -Fix: Truncate the newgrf information text in the newgrf gui if it's too long.
maedhros
parents: 6348
diff changeset
    84
	y += DrawStringMultiLine(x, y, STR_NEWGRF_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
    85
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    86
	/* 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
    87
	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
    88
	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
    89
	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
    90
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    91
	/* Show GRF parameter list */
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    92
	if (show_params) {
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    93
		if (c->num_params > 0) {
5308
990a4b188233 (svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents: 5248
diff changeset
    94
			GRFBuildParamList(buff, c, lastof(buff));
9648
c79160082c0f (svn r13715) -Fix [FS#2129]: C-like strings had to be rebound each time they were printed, otherwise the text could change due to the few number of slots that could be used to bind.
rubidium
parents: 9457
diff changeset
    95
			SetDParam(0, STR_JUST_RAW_STRING);
c79160082c0f (svn r13715) -Fix [FS#2129]: C-like strings had to be rebound each time they were printed, otherwise the text could change due to the few number of slots that could be used to bind.
rubidium
parents: 9457
diff changeset
    96
			SetDParamStr(1, buff);
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    97
		} else {
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    98
			SetDParam(0, STR_01A9_NONE);
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
    99
		}
6377
c1bc323eaf0c (svn r9449) -Fix: Truncate the newgrf information text in the newgrf gui if it's too long.
maedhros
parents: 6348
diff changeset
   100
		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
   101
10126
48162ce1b642 (svn r14310) -Fix: don't show palette information in the newgrf lists of the network lobby.
rubidium
parents: 10115
diff changeset
   102
		/* Draw the palette of the NewGRF */
48162ce1b642 (svn r14310) -Fix: don't show palette information in the newgrf lists of the network lobby.
rubidium
parents: 10115
diff changeset
   103
		SetDParamStr(0, c->windows_paletted ? "Windows" : "DOS");
48162ce1b642 (svn r14310) -Fix: don't show palette information in the newgrf lists of the network lobby.
rubidium
parents: 10115
diff changeset
   104
		y += DrawStringMultiLine(x, y, STR_NEWGRF_PALETTE, w, bottom - y);
48162ce1b642 (svn r14310) -Fix: don't show palette information in the newgrf lists of the network lobby.
rubidium
parents: 10115
diff changeset
   105
	}
10066
f18e97752eeb (svn r14233) -Feature/Fix [FS#2172]: save the palette of the loaded NewGRFs in the savegame, so joining with a server using Windows palette will make a client with the DOS palette do palette conversion and (thus) not cause a desync due to the different palettes disabling different NewGRFs.
rubidium
parents: 9957
diff changeset
   106
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   107
	/* 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
   108
	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
   109
	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
   110
	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
   111
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   112
	/* 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
   113
	if (c->info != NULL && !StrEmpty(c->info)) {
9648
c79160082c0f (svn r13715) -Fix [FS#2129]: C-like strings had to be rebound each time they were printed, otherwise the text could change due to the few number of slots that could be used to bind.
rubidium
parents: 9457
diff changeset
   114
		SetDParam(0, STR_JUST_RAW_STRING);
c79160082c0f (svn r13715) -Fix [FS#2129]: C-like strings had to be rebound each time they were printed, otherwise the text could change due to the few number of slots that could be used to bind.
rubidium
parents: 9457
diff changeset
   115
		SetDParamStr(1, 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
   116
		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
   117
	} 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
   118
		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
   119
	}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   120
}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   121
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   122
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   123
/**
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   124
 * Window for adding NewGRF files
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   125
 */
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   126
struct NewGRFAddWindow : public Window {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   127
	/* Names of the add a newgrf window widgets */
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   128
	enum AddNewGRFWindowWidgets {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   129
		ANGRFW_CLOSEBOX = 0,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   130
		ANGRFW_CAPTION,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   131
		ANGRFW_BACKGROUND,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   132
		ANGRFW_GRF_LIST,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   133
		ANGRFW_SCROLLBAR,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   134
		ANGRFW_GRF_INFO,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   135
		ANGRFW_ADD,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   136
		ANGRFW_RESCAN,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   137
		ANGRFW_RESIZE,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   138
	};
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
	GRFConfig **list;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   141
	const GRFConfig *sel;
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   142
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   143
	NewGRFAddWindow(const WindowDesc *desc, GRFConfig **list) : Window(desc, 0)
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   144
	{
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   145
		this->list = list;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   146
		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
   147
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   148
		this->FindWindowPlacementAndResize(desc);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   149
	}
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   150
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   151
	virtual void OnPaint()
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
		const GRFConfig *c;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   154
		const Widget *wl = &this->widget[ANGRFW_GRF_LIST];
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   155
		int n = 0;
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   156
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   157
		/* Count the number of GRFs */
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   158
		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
   159
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   160
		this->vscroll.cap = (wl->bottom - wl->top) / 10;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   161
		SetVScrollCount(this, n);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   162
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   163
		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
   164
		this->DrawWidgets();
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   165
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   166
		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
   167
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   168
		uint y = wl->top + 1;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   169
		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
   170
			if (n >= this->vscroll.pos) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   171
				bool h = c == this->sel;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   172
				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
   173
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   174
				/* Draw selection background */
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   175
				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
   176
				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
   177
				y += 10;
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
		}
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
		if (this->sel != NULL) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   182
			const Widget *wi = &this->widget[ANGRFW_GRF_INFO];
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   183
			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
   184
		}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   185
	}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   186
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   187
	virtual void OnDoubleClick(Point pt, int widget)
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   188
	{
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   189
		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
   190
	}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   191
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   192
	virtual void OnClick(Point pt, int widget)
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   193
	{
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   194
		switch (widget) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   195
			case ANGRFW_GRF_LIST: {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   196
				/* Get row... */
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   197
				const GRFConfig *c;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   198
				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
   199
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   200
				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
   201
				this->sel = c;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   202
				this->SetDirty();
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   203
				break;
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   204
			}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   205
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   206
			case ANGRFW_ADD: // Add selection to list
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   207
				if (this->sel != NULL) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   208
					const GRFConfig *src = this->sel;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   209
					GRFConfig **list;
5243
29235600e8fc (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   210
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   211
					/* 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
   212
					for (list = this->list; *list != NULL; list = &(*list)->next) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   213
						if ((*list)->grfid == src->grfid) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   214
							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
   215
							return;
5243
29235600e8fc (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   216
						}
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   217
					}
5243
29235600e8fc (svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents: 5241
diff changeset
   218
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   219
					/* Copy GRF details from scanned list */
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   220
					GRFConfig *c = CallocT<GRFConfig>(1);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   221
					*c = *src;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   222
					c->filename = strdup(src->filename);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   223
					if (src->name      != NULL) c->name      = strdup(src->name);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   224
					if (src->info      != NULL) c->info      = strdup(src->info);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   225
					c->next = NULL;
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   226
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   227
					/* Append GRF config to configuration list */
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   228
					*list = c;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   229
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   230
					DeleteWindowByClass(WC_SAVELOAD);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   231
					InvalidateWindowData(WC_GAME_OPTIONS, 0);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   232
				}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   233
				break;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   234
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   235
			case ANGRFW_RESCAN: // Rescan list
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   236
				this->sel = NULL;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   237
				ScanNewGRFFiles();
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   238
				this->SetDirty();
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   239
				break;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   240
		}
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   241
	}
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   242
};
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   243
8025
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   244
/* 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
   245
static const Widget _newgrf_add_dlg_widgets[] = {
9760
92202f8b455a (svn r13896) -Codechange: Replace numbers with Colours enum on newgrf, order and osk guis
belugas
parents: 9706
diff changeset
   246
{   WWT_CLOSEBOX,    RESIZE_NONE,  COLOUR_GREY,   0,  10,   0,  13, STR_00C5,                STR_018B_CLOSE_WINDOW },           // ANGRFW_CLOSEBOX
92202f8b455a (svn r13896) -Codechange: Replace numbers with Colours enum on newgrf, order and osk guis
belugas
parents: 9706
diff changeset
   247
{    WWT_CAPTION,   RESIZE_RIGHT,  COLOUR_GREY,  11, 306,   0,  13, STR_NEWGRF_ADD_CAPTION,  STR_018C_WINDOW_TITLE_DRAG_THIS }, // ANGRFW_CAPTION
92202f8b455a (svn r13896) -Codechange: Replace numbers with Colours enum on newgrf, order and osk guis
belugas
parents: 9706
diff changeset
   248
{      WWT_PANEL,      RESIZE_RB,  COLOUR_GREY,   0, 294,  14, 121, 0x0,                     STR_NULL },                        // ANGRFW_BACKGROUND
92202f8b455a (svn r13896) -Codechange: Replace numbers with Colours enum on newgrf, order and osk guis
belugas
parents: 9706
diff changeset
   249
{      WWT_INSET,      RESIZE_RB,  COLOUR_GREY,   2, 292,  16, 119, 0x0,                     STR_NULL },                        // ANGRFW_GRF_LIST
92202f8b455a (svn r13896) -Codechange: Replace numbers with Colours enum on newgrf, order and osk guis
belugas
parents: 9706
diff changeset
   250
{  WWT_SCROLLBAR,     RESIZE_LRB,  COLOUR_GREY, 295, 306,  14, 121, 0x0,                     STR_NULL },                        // ANGRFW_SCROLLBAR
92202f8b455a (svn r13896) -Codechange: Replace numbers with Colours enum on newgrf, order and osk guis
belugas
parents: 9706
diff changeset
   251
{      WWT_PANEL,     RESIZE_RTB,  COLOUR_GREY,   0, 306, 122, 224, 0x0,                     STR_NULL },                        // ANGRFW_GRF_INFO
92202f8b455a (svn r13896) -Codechange: Replace numbers with Colours enum on newgrf, order and osk guis
belugas
parents: 9706
diff changeset
   252
{ WWT_PUSHTXTBTN,     RESIZE_RTB,  COLOUR_GREY,   0, 146, 225, 236, STR_NEWGRF_ADD_FILE,     STR_NEWGRF_ADD_FILE_TIP },         // ANGRFW_ADD
92202f8b455a (svn r13896) -Codechange: Replace numbers with Colours enum on newgrf, order and osk guis
belugas
parents: 9706
diff changeset
   253
{ WWT_PUSHTXTBTN,    RESIZE_LRTB,  COLOUR_GREY, 147, 294, 225, 236, STR_NEWGRF_RESCAN_FILES, STR_NEWGRF_RESCAN_FILES_TIP },     // ANGRFW_RESCAN
92202f8b455a (svn r13896) -Codechange: Replace numbers with Colours enum on newgrf, order and osk guis
belugas
parents: 9706
diff changeset
   254
{  WWT_RESIZEBOX,    RESIZE_LRTB,  COLOUR_GREY, 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
   255
{   WIDGETS_END },
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   256
};
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   257
8025
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   258
/* 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
   259
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
   260
	WDP_CENTER, WDP_CENTER, 307, 237, 307, 337,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5668
diff changeset
   261
	WC_SAVELOAD, WC_NONE,
8019
fc0e94dee165 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8018
diff changeset
   262
	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
   263
	_newgrf_add_dlg_widgets,
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   264
};
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   265
9677
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   266
static GRFPresetList _grf_preset_list;
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   267
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   268
class DropDownListPresetItem : public DropDownListItem {
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   269
public:
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   270
	DropDownListPresetItem(int result) : DropDownListItem(result, false) {}
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   271
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   272
	virtual ~DropDownListPresetItem() {}
9864
1ea12c90e7dd (svn r14009) -Cleanup (r14008): Bad whitespace...
peter1138
parents: 9863
diff changeset
   273
9863
af31097a285f (svn r14008) -Fix (r14004): NewGRF preset drop down list not working
peter1138
parents: 9760
diff changeset
   274
	bool Selectable() const
9677
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   275
	{
9863
af31097a285f (svn r14008) -Fix (r14004): NewGRF preset drop down list not working
peter1138
parents: 9760
diff changeset
   276
		return true;
9677
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   277
	}
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   278
9863
af31097a285f (svn r14008) -Fix (r14004): NewGRF preset drop down list not working
peter1138
parents: 9760
diff changeset
   279
	void Draw(int x, int y, uint width, uint height, bool sel, int bg_colour) const
9677
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   280
	{
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   281
		DoDrawStringTruncated(_grf_preset_list[this->result], x + 2, y, sel ? TC_WHITE : TC_BLACK, x + width);
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   282
	}
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   283
};
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   284
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   285
static void NewGRFConfirmationCallback(Window *w, bool confirmed);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   286
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   287
/**
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   288
 * Window for showing NewGRF files
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   289
 */
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   290
struct NewGRFWindow : public Window {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   291
	/* Names of the manage newgrfs window widgets */
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   292
	enum ShowNewGRFStateWidgets {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   293
		SNGRFS_CLOSEBOX = 0,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   294
		SNGRFS_CAPTION,
9677
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   295
		SNGRFS_BACKGROUND1,
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   296
		SNGRFS_PRESET_LIST,
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   297
		SNGRFS_PRESET_SAVE,
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   298
		SNGRFS_PRESET_DELETE,
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   299
		SNGRFS_BACKGROUND2,
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   300
		SNGRFS_ADD,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   301
		SNGRFS_REMOVE,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   302
		SNGRFS_MOVE_UP,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   303
		SNGRFS_MOVE_DOWN,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   304
		SNGRFS_FILE_LIST,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   305
		SNGRFS_SCROLLBAR,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   306
		SNGRFS_NEWGRF_INFO,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   307
		SNGRFS_SET_PARAMETERS,
10066
f18e97752eeb (svn r14233) -Feature/Fix [FS#2172]: save the palette of the loaded NewGRFs in the savegame, so joining with a server using Windows palette will make a client with the DOS palette do palette conversion and (thus) not cause a desync due to the different palettes disabling different NewGRFs.
rubidium
parents: 9957
diff changeset
   308
		SNGRFS_TOGGLE_PALETTE,
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   309
		SNGRFS_APPLY_CHANGES,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   310
		SNGRFS_RESIZE,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   311
	};
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   312
5352
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   313
	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
   314
	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
   315
	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
   316
	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
   317
	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
   318
	bool execute;          ///< on pressing 'apply changes' are grf changes applied immediately, or only list is updated
9677
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   319
	int query_widget;      ///< widget that opened a query
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   320
	int preset;            ///< selected preset
5352
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   321
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   322
	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
   323
	{
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   324
		this->resize.step_height = 14;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   325
		this->sel         = NULL;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   326
		this->list        = NULL;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   327
		this->orig_list   = config;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   328
		this->editable    = editable;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   329
		this->execute     = exec_changes;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   330
		this->show_params = show_params;
9677
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   331
		this->preset      = -1;
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   332
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   333
		CopyGRFConfigList(&this->list, *config, false);
9677
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   334
		GetGRFPresetList(&_grf_preset_list);
6229
695400602ab0 (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6166
diff changeset
   335
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   336
		this->FindWindowPlacementAndResize(desc);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   337
		this->SetupNewGRFWindow();
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   338
	}
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   339
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   340
	~NewGRFWindow()
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   341
	{
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   342
		if (!this->execute) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   343
			CopyGRFConfigList(this->orig_list, this->list, true);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   344
			ResetGRFConfig(false);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   345
			ReloadNewGRFData();
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   346
		}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   347
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   348
		/* 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
   349
		ClearGRFConfigList(&this->list);
9677
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   350
		_grf_preset_list.Clear();
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   351
	}
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
   352
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   353
	void SetupNewGRFWindow()
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   354
	{
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   355
		const GRFConfig *c;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   356
		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
   357
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   358
		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
   359
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   360
		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
   361
		SetVScrollCount(this, i);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   362
9677
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   363
		this->SetWidgetsDisabledState(!this->editable,
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   364
			SNGRFS_PRESET_LIST,
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   365
			SNGRFS_ADD,
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   366
			SNGRFS_APPLY_CHANGES,
10066
f18e97752eeb (svn r14233) -Feature/Fix [FS#2172]: save the palette of the loaded NewGRFs in the savegame, so joining with a server using Windows palette will make a client with the DOS palette do palette conversion and (thus) not cause a desync due to the different palettes disabling different NewGRFs.
rubidium
parents: 9957
diff changeset
   367
			SNGRFS_TOGGLE_PALETTE,
9677
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   368
			WIDGET_LIST_END
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   369
		);
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   370
	}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   371
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   372
	virtual void OnPaint()
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   373
	{
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   374
		bool disable_all = this->sel == NULL || !this->editable;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   375
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   376
		this->SetWidgetsDisabledState(disable_all,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   377
			SNGRFS_REMOVE,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   378
			SNGRFS_MOVE_UP,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   379
			SNGRFS_MOVE_DOWN,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   380
			WIDGET_LIST_END
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   381
		);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   382
		this->SetWidgetDisabledState(SNGRFS_SET_PARAMETERS, !this->show_params || disable_all);
10115
e162dbf901d2 (svn r14299) -Fix: disable 'toggle palette' when no NewGRF has been selected.
rubidium
parents: 10066
diff changeset
   383
		this->SetWidgetDisabledState(SNGRFS_TOGGLE_PALETTE, disable_all);
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   384
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   385
		if (!disable_all) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   386
			/* 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
   387
			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
   388
			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
   389
			if (this->sel->IsOpenTTDBaseGRF()) this->DisableWidget(SNGRFS_REMOVE);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   390
		}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   391
9677
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   392
		if (this->preset == -1) {
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   393
			this->widget[SNGRFS_PRESET_LIST].data = STR_02BF_CUSTOM;
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   394
		} else {
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   395
			SetDParamStr(0, _grf_preset_list[this->preset]);
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   396
			this->widget[SNGRFS_PRESET_LIST].data = STR_JUST_RAW_STRING;
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   397
		}
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   398
9273
35e0224ea8f1 (svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents: 9207
diff changeset
   399
		this->DrawWidgets();
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   400
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   401
		/* Draw NewGRF list */
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   402
		int y = this->widget[SNGRFS_FILE_LIST].top;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   403
		int i = 0;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   404
		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
   405
			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
   406
				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
   407
				SpriteID pal;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   408
				byte txtoffset;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   409
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   410
				/* Pick a colour */
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   411
				switch (c->status) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   412
					case GCS_NOT_FOUND:
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   413
					case GCS_DISABLED:
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   414
						pal = PALETTE_TO_RED;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   415
						break;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   416
					case GCS_ACTIVATED:
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   417
						pal = PALETTE_TO_GREEN;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   418
						break;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   419
					default:
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   420
						pal = PALETTE_TO_BLUE;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   421
						break;
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   422
				}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   423
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   424
				/* 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
   425
				if (pal != PALETTE_TO_RED) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   426
					if (HasBit(c->flags, GCF_STATIC)) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   427
						pal = PALETTE_TO_GREY;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   428
					} else if (HasBit(c->flags, GCF_COMPATIBLE)) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   429
						pal = PALETTE_TO_ORANGE;
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   430
					}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   431
				}
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   432
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   433
				DrawSprite(SPR_SQUARE, pal, 5, y + 2);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   434
				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
   435
				txtoffset = c->error != NULL ? 35 : 25;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   436
				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
   437
				y += 14;
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   438
			}
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   439
		}
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   440
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   441
		if (this->sel != NULL) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   442
			/* Draw NewGRF file info */
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   443
			const Widget *wi = &this->widget[SNGRFS_NEWGRF_INFO];
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   444
			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
   445
		}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   446
	}
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   447
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   448
	virtual void OnClick(Point pt, int widget)
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   449
	{
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   450
		switch (widget) {
9677
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   451
			case SNGRFS_PRESET_LIST: {
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   452
				DropDownList *list = new DropDownList();
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   453
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   454
				/* Add 'None' option for clearing list */
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   455
				list->push_back(new DropDownListStringItem(STR_NONE, -1, false));
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   456
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   457
				for (uint i = 0; i < _grf_preset_list.Length(); i++) {
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   458
					if (_grf_preset_list[i] != NULL) {
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   459
						list->push_back(new DropDownListPresetItem(i));
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   460
					}
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   461
				}
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   462
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   463
				ShowDropDownList(this, list, this->preset, SNGRFS_PRESET_LIST);
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   464
				break;
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   465
			}
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   466
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   467
			case SNGRFS_PRESET_SAVE:
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   468
				this->query_widget = widget;
10145
849ba8b8626b (svn r14331) -Codechange: use an enum as additional parameter for ShowQueryString()
smatz
parents: 10126
diff changeset
   469
				ShowQueryString(STR_EMPTY, STR_NEWGRF_PRESET_SAVE_QUERY, 32, 100, this, CS_ALPHANUMERAL, QSF_NONE);
9677
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   470
				break;
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   471
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   472
			case SNGRFS_PRESET_DELETE:
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   473
				if (this->preset == -1) return;
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   474
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   475
				DeleteGRFPresetFromConfig(_grf_preset_list[this->preset]);
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   476
				GetGRFPresetList(&_grf_preset_list);
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   477
				this->preset = -1;
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   478
				this->SetDirty();
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   479
				break;
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   480
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   481
			case SNGRFS_ADD: // Add GRF
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   482
				DeleteWindowByClass(WC_SAVELOAD);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   483
				new NewGRFAddWindow(&_newgrf_add_dlg_desc, &this->list);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   484
				break;
5352
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   485
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   486
			case SNGRFS_REMOVE: { // Remove GRF
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   487
				GRFConfig **pc, *c, *newsel;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   488
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   489
				/* 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
   490
				newsel = this->sel->next;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   491
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   492
				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
   493
					/* 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
   494
					 * 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
   495
					if (newsel == NULL && c->next == this->sel) newsel = c;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   496
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   497
					if (c == this->sel) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   498
						*pc = c->next;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   499
						free(c);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   500
						break;
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
				}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   503
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   504
				this->sel = newsel;
9677
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   505
				this->preset = -1;
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   506
				this->SetupNewGRFWindow();
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   507
				this->SetDirty();
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   508
				break;
8591
d73cc7cd733c (svn r12172) -Codechange: Allow buttons to resize in NewGRF settings window
peter1138
parents: 8264
diff changeset
   509
			}
9207
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
			case SNGRFS_MOVE_UP: { // Move GRF up
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   512
				GRFConfig **pc, *c;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   513
				if (this->sel == NULL) break;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   514
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   515
				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
   516
					if (c->next == this->sel) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   517
						c->next = this->sel->next;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   518
						this->sel->next = c;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   519
						*pc = this->sel;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   520
						break;
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
				}
9677
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   523
				this->preset = -1;
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   524
				this->SetDirty();
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   525
				break;
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
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   528
			case SNGRFS_MOVE_DOWN: { // Move GRF down
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   529
				GRFConfig **pc, *c;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   530
				if (this->sel == NULL) break;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   531
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   532
				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
   533
					if (c == this->sel) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   534
						*pc = c->next;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   535
						c->next = c->next->next;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   536
						(*pc)->next = c;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   537
						break;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   538
					}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   539
				}
9677
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   540
				this->preset = -1;
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   541
				this->SetDirty();
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   542
				break;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   543
			}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   544
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   545
			case SNGRFS_FILE_LIST: { // Select a GRF
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   546
				GRFConfig *c;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   547
				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
   548
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   549
				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
   550
				this->sel = c;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   551
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   552
				this->SetDirty();
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   553
				break;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   554
			}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   555
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   556
			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
   557
				if (this->execute) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   558
					ShowQuery(
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   559
						STR_POPUP_CAUTION_CAPTION,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   560
						STR_NEWGRF_CONFIRMATION_TEXT,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   561
						this,
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   562
						NewGRFConfirmationCallback
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   563
					);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   564
				} else {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   565
					CopyGRFConfigList(this->orig_list, this->list, true);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   566
					ResetGRFConfig(false);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   567
					ReloadNewGRFData();
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   568
				}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   569
				break;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   570
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   571
			case SNGRFS_SET_PARAMETERS: { // Edit parameters
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   572
				if (this->sel == NULL) break;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   573
9677
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   574
				this->query_widget = widget;
9648
c79160082c0f (svn r13715) -Fix [FS#2129]: C-like strings had to be rebound each time they were printed, otherwise the text could change due to the few number of slots that could be used to bind.
rubidium
parents: 9457
diff changeset
   575
				static char buff[512];
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   576
				GRFBuildParamList(buff, this->sel, lastof(buff));
9648
c79160082c0f (svn r13715) -Fix [FS#2129]: C-like strings had to be rebound each time they were printed, otherwise the text could change due to the few number of slots that could be used to bind.
rubidium
parents: 9457
diff changeset
   577
				SetDParamStr(0, buff);
10145
849ba8b8626b (svn r14331) -Codechange: use an enum as additional parameter for ShowQueryString()
smatz
parents: 10126
diff changeset
   578
				ShowQueryString(STR_JUST_RAW_STRING, STR_NEWGRF_PARAMETER_QUERY, 63, 250, this, CS_ALPHANUMERAL, QSF_NONE);
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   579
				break;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   580
			}
10066
f18e97752eeb (svn r14233) -Feature/Fix [FS#2172]: save the palette of the loaded NewGRFs in the savegame, so joining with a server using Windows palette will make a client with the DOS palette do palette conversion and (thus) not cause a desync due to the different palettes disabling different NewGRFs.
rubidium
parents: 9957
diff changeset
   581
f18e97752eeb (svn r14233) -Feature/Fix [FS#2172]: save the palette of the loaded NewGRFs in the savegame, so joining with a server using Windows palette will make a client with the DOS palette do palette conversion and (thus) not cause a desync due to the different palettes disabling different NewGRFs.
rubidium
parents: 9957
diff changeset
   582
			case SNGRFS_TOGGLE_PALETTE: {
f18e97752eeb (svn r14233) -Feature/Fix [FS#2172]: save the palette of the loaded NewGRFs in the savegame, so joining with a server using Windows palette will make a client with the DOS palette do palette conversion and (thus) not cause a desync due to the different palettes disabling different NewGRFs.
rubidium
parents: 9957
diff changeset
   583
				if (this->sel != NULL) {
f18e97752eeb (svn r14233) -Feature/Fix [FS#2172]: save the palette of the loaded NewGRFs in the savegame, so joining with a server using Windows palette will make a client with the DOS palette do palette conversion and (thus) not cause a desync due to the different palettes disabling different NewGRFs.
rubidium
parents: 9957
diff changeset
   584
					this->sel->windows_paletted ^= true;
f18e97752eeb (svn r14233) -Feature/Fix [FS#2172]: save the palette of the loaded NewGRFs in the savegame, so joining with a server using Windows palette will make a client with the DOS palette do palette conversion and (thus) not cause a desync due to the different palettes disabling different NewGRFs.
rubidium
parents: 9957
diff changeset
   585
					this->SetDirty();
f18e97752eeb (svn r14233) -Feature/Fix [FS#2172]: save the palette of the loaded NewGRFs in the savegame, so joining with a server using Windows palette will make a client with the DOS palette do palette conversion and (thus) not cause a desync due to the different palettes disabling different NewGRFs.
rubidium
parents: 9957
diff changeset
   586
				}
f18e97752eeb (svn r14233) -Feature/Fix [FS#2172]: save the palette of the loaded NewGRFs in the savegame, so joining with a server using Windows palette will make a client with the DOS palette do palette conversion and (thus) not cause a desync due to the different palettes disabling different NewGRFs.
rubidium
parents: 9957
diff changeset
   587
				break;
f18e97752eeb (svn r14233) -Feature/Fix [FS#2172]: save the palette of the loaded NewGRFs in the savegame, so joining with a server using Windows palette will make a client with the DOS palette do palette conversion and (thus) not cause a desync due to the different palettes disabling different NewGRFs.
rubidium
parents: 9957
diff changeset
   588
			}
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   589
		}
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   590
	}
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   591
9677
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   592
	virtual void OnDropdownSelect(int widget, int index)
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   593
	{
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   594
		if (index == -1) {
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   595
			ClearGRFConfigList(&this->list);
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   596
			this->preset = -1;
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   597
		} else {
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   598
			GRFConfig *c = LoadGRFPresetFromConfig(_grf_preset_list[index]);
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   599
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   600
			if (c != NULL) {
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   601
				this->sel = NULL;
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   602
				ClearGRFConfigList(&this->list);
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   603
				this->list = c;
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   604
				this->preset = index;
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   605
			}
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   606
		}
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   607
9706
1afd96cc2be6 (svn r13818) -Fix [FS#2157]: Deselect currently selected NewGRF when changing GRF preset.
peter1138
parents: 9683
diff changeset
   608
		this->sel = NULL;
9677
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   609
		this->SetupNewGRFWindow();
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   610
		this->SetDirty();
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   611
	}
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   612
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   613
	virtual void OnQueryTextFinished(char *str)
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   614
	{
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   615
		if (str == NULL) return;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   616
9677
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   617
		switch (this->query_widget) {
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   618
			case SNGRFS_PRESET_SAVE:
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   619
				SaveGRFPresetToConfig(str, this->list);
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   620
				GetGRFPresetList(&_grf_preset_list);
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   621
9677
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   622
				/* Switch to this preset */
9683
6faf40f7a9ac (svn r13789) -Fix (r13781): Saved preset was not automatically selected.
peter1138
parents: 9677
diff changeset
   623
				for (uint i = 0; i < _grf_preset_list.Length(); i++) {
9677
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   624
					if (_grf_preset_list[i] != NULL && strcmp(_grf_preset_list[i], str) == 0) {
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   625
						this->preset = i;
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   626
						break;
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   627
					}
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   628
				}
9683
6faf40f7a9ac (svn r13789) -Fix (r13781): Saved preset was not automatically selected.
peter1138
parents: 9677
diff changeset
   629
6faf40f7a9ac (svn r13789) -Fix (r13781): Saved preset was not automatically selected.
peter1138
parents: 9677
diff changeset
   630
				this->SetDirty();
9677
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   631
				break;
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   632
9677
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   633
			case SNGRFS_SET_PARAMETERS: {
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   634
				/* Parse our new "int list" */
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   635
				GRFConfig *c = this->sel;
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   636
				c->num_params = parse_intlist(str, (int*)c->param, lengthof(c->param));
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   637
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   638
				/* parse_intlist returns -1 on error */
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   639
				if (c->num_params == (byte)-1) c->num_params = 0;
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   640
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   641
				this->preset = -1;
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   642
				this->SetDirty();
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   643
				break;
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   644
			}
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   645
		}
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   646
	}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   647
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   648
	virtual void OnResize(Point new_size, Point delta)
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   649
	{
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   650
		if (delta.x != 0) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   651
			ResizeButtons(this, SNGRFS_ADD, SNGRFS_MOVE_DOWN);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   652
			ResizeButtons(this, SNGRFS_SET_PARAMETERS, SNGRFS_APPLY_CHANGES);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   653
		}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   654
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   655
		this->vscroll.cap += delta.y / 14;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   656
		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
   657
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   658
		this->SetupNewGRFWindow();
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   659
	}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   660
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   661
	virtual void OnInvalidateData(int data = 0)
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   662
	{
9677
4767b9937c04 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138
parents: 9648
diff changeset
   663
		this->preset = -1;
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   664
		this->SetupNewGRFWindow();
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   665
	}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   666
};
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   667
8025
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   668
/* 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
   669
static const Widget _newgrf_widgets[] = {
9760
92202f8b455a (svn r13896) -Codechange: Replace numbers with Colours enum on newgrf, order and osk guis
belugas
parents: 9706
diff changeset
   670
{   WWT_CLOSEBOX,  RESIZE_NONE,  COLOUR_MAUVE,    0,  10,   0,  13, STR_00C5,                    STR_018B_CLOSE_WINDOW },            // SNGRFS_CLOSEBOX
92202f8b455a (svn r13896) -Codechange: Replace numbers with Colours enum on newgrf, order and osk guis
belugas
parents: 9706
diff changeset
   671
{    WWT_CAPTION, RESIZE_RIGHT,  COLOUR_MAUVE,   11, 299,   0,  13, STR_NEWGRF_SETTINGS_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS },  // SNGRFS_CAPTION
92202f8b455a (svn r13896) -Codechange: Replace numbers with Colours enum on newgrf, order and osk guis
belugas
parents: 9706
diff changeset
   672
{      WWT_PANEL, RESIZE_RIGHT,  COLOUR_MAUVE,    0, 299,  14,  41, STR_NULL,                    STR_NULL },                         // SNGRFS_BACKGROUND1
92202f8b455a (svn r13896) -Codechange: Replace numbers with Colours enum on newgrf, order and osk guis
belugas
parents: 9706
diff changeset
   673
{   WWT_DROPDOWN, RESIZE_RIGHT,  COLOUR_YELLOW,  10, 103,  16,  27, STR_EMPTY,                   STR_NEWGRF_PRESET_LIST_TIP },       // SNGRFS_PRESET_LIST
92202f8b455a (svn r13896) -Codechange: Replace numbers with Colours enum on newgrf, order and osk guis
belugas
parents: 9706
diff changeset
   674
{ WWT_PUSHTXTBTN,    RESIZE_LR,  COLOUR_YELLOW, 104, 196,  16,  27, STR_NEWGRF_PRESET_SAVE,      STR_NEWGRF_PRESET_SAVE_TIP },       // SNGRFS_PRESET_SAVE
92202f8b455a (svn r13896) -Codechange: Replace numbers with Colours enum on newgrf, order and osk guis
belugas
parents: 9706
diff changeset
   675
{ WWT_PUSHTXTBTN,    RESIZE_LR,  COLOUR_YELLOW, 197, 289,  16,  27, STR_NEWGRF_PRESET_DELETE,    STR_NEWGRF_PRESET_DELETE_TIP },     // SNGRFS_PRESET_DELETE
92202f8b455a (svn r13896) -Codechange: Replace numbers with Colours enum on newgrf, order and osk guis
belugas
parents: 9706
diff changeset
   676
{      WWT_PANEL, RESIZE_RIGHT,  COLOUR_MAUVE,    0, 299,  30,  45, STR_NULL,                    STR_NULL },                         // SNGRFS_BACKGROUND
92202f8b455a (svn r13896) -Codechange: Replace numbers with Colours enum on newgrf, order and osk guis
belugas
parents: 9706
diff changeset
   677
{ WWT_PUSHTXTBTN,  RESIZE_NONE,  COLOUR_YELLOW,  10,  79,  32,  43, STR_NEWGRF_ADD,              STR_NEWGRF_ADD_TIP },               // SNGRFS_ADD
92202f8b455a (svn r13896) -Codechange: Replace numbers with Colours enum on newgrf, order and osk guis
belugas
parents: 9706
diff changeset
   678
{ WWT_PUSHTXTBTN,  RESIZE_NONE,  COLOUR_YELLOW,  80, 149,  32,  43, STR_NEWGRF_REMOVE,           STR_NEWGRF_REMOVE_TIP },            // SNGRFS_REMOVE
92202f8b455a (svn r13896) -Codechange: Replace numbers with Colours enum on newgrf, order and osk guis
belugas
parents: 9706
diff changeset
   679
{ WWT_PUSHTXTBTN,  RESIZE_NONE,  COLOUR_YELLOW, 150, 219,  32,  43, STR_NEWGRF_MOVEUP,           STR_NEWGRF_MOVEUP_TIP },            // SNGRFS_MOVE_UP
92202f8b455a (svn r13896) -Codechange: Replace numbers with Colours enum on newgrf, order and osk guis
belugas
parents: 9706
diff changeset
   680
{ WWT_PUSHTXTBTN, RESIZE_RIGHT,  COLOUR_YELLOW, 220, 289,  32,  43, STR_NEWGRF_MOVEDOWN,         STR_NEWGRF_MOVEDOWN_TIP },          // SNGRFS_MOVE_DOWN
92202f8b455a (svn r13896) -Codechange: Replace numbers with Colours enum on newgrf, order and osk guis
belugas
parents: 9706
diff changeset
   681
{     WWT_MATRIX,    RESIZE_RB,  COLOUR_MAUVE,    0, 287,  46, 115, 0x501,                       STR_NEWGRF_FILE_TIP },              // SNGRFS_FILE_LIST
92202f8b455a (svn r13896) -Codechange: Replace numbers with Colours enum on newgrf, order and osk guis
belugas
parents: 9706
diff changeset
   682
{  WWT_SCROLLBAR,   RESIZE_LRB,  COLOUR_MAUVE,  288, 299,  46, 115, 0x0,                         STR_0190_SCROLL_BAR_SCROLLS_LIST }, // SNGRFS_SCROLLBAR
10066
f18e97752eeb (svn r14233) -Feature/Fix [FS#2172]: save the palette of the loaded NewGRFs in the savegame, so joining with a server using Windows palette will make a client with the DOS palette do palette conversion and (thus) not cause a desync due to the different palettes disabling different NewGRFs.
rubidium
parents: 9957
diff changeset
   683
{      WWT_PANEL,   RESIZE_RTB,  COLOUR_MAUVE,    0, 299, 116, 238, STR_NULL,                    STR_NULL },                         // SNGRFS_NEWGRF_INFO
f18e97752eeb (svn r14233) -Feature/Fix [FS#2172]: save the palette of the loaded NewGRFs in the savegame, so joining with a server using Windows palette will make a client with the DOS palette do palette conversion and (thus) not cause a desync due to the different palettes disabling different NewGRFs.
rubidium
parents: 9957
diff changeset
   684
{ WWT_PUSHTXTBTN,    RESIZE_TB,  COLOUR_MAUVE,    0,  95, 239, 250, STR_NEWGRF_SET_PARAMETERS,   STR_NULL },                         // SNGRFS_SET_PARAMETERS
f18e97752eeb (svn r14233) -Feature/Fix [FS#2172]: save the palette of the loaded NewGRFs in the savegame, so joining with a server using Windows palette will make a client with the DOS palette do palette conversion and (thus) not cause a desync due to the different palettes disabling different NewGRFs.
rubidium
parents: 9957
diff changeset
   685
{ WWT_PUSHTXTBTN,   RESIZE_RTB,  COLOUR_MAUVE,   96, 191, 239, 250, STR_NEWGRF_TOGGLE_PALETTE,   STR_NEWGRF_TOGGLE_PALETTE_TIP },    // SNGRFS_TOGGLE_PALETTE
f18e97752eeb (svn r14233) -Feature/Fix [FS#2172]: save the palette of the loaded NewGRFs in the savegame, so joining with a server using Windows palette will make a client with the DOS palette do palette conversion and (thus) not cause a desync due to the different palettes disabling different NewGRFs.
rubidium
parents: 9957
diff changeset
   686
{ WWT_PUSHTXTBTN,   RESIZE_RTB,  COLOUR_MAUVE,  192, 287, 239, 250, STR_NEWGRF_APPLY_CHANGES,    STR_NULL },                         // SNGRFS_APPLY_CHANGES
f18e97752eeb (svn r14233) -Feature/Fix [FS#2172]: save the palette of the loaded NewGRFs in the savegame, so joining with a server using Windows palette will make a client with the DOS palette do palette conversion and (thus) not cause a desync due to the different palettes disabling different NewGRFs.
rubidium
parents: 9957
diff changeset
   687
{  WWT_RESIZEBOX,  RESIZE_LRTB,  COLOUR_MAUVE,  288, 299, 239, 250, 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
   688
{ WIDGETS_END },
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   689
};
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   690
8025
151e377fde0a (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13
parents: 8019
diff changeset
   691
/* 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
   692
static const WindowDesc _newgrf_desc = {
10066
f18e97752eeb (svn r14233) -Feature/Fix [FS#2172]: save the palette of the loaded NewGRFs in the savegame, so joining with a server using Windows palette will make a client with the DOS palette do palette conversion and (thus) not cause a desync due to the different palettes disabling different NewGRFs.
rubidium
parents: 9957
diff changeset
   693
	WDP_CENTER, WDP_CENTER, 300, 251, 300, 251,
5893
7e431a4abebb (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 5668
diff changeset
   694
	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
   695
	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
   696
	_newgrf_widgets,
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   697
};
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   698
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   699
/** Callback function for the newgrf 'apply changes' confirmation window
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   700
 * @param w Window which is calling this callback
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   701
 * @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
   702
 */
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   703
static void NewGRFConfirmationCallback(Window *w, bool confirmed)
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   704
{
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   705
	if (confirmed) {
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   706
		NewGRFWindow *nw = dynamic_cast<NewGRFWindow*>(w);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   707
		GRFConfig *c;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   708
		int i = 0;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   709
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
   710
		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
   711
		GamelogGRFUpdate(_grfconfig, nw->list); // log GRF changes
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   712
		CopyGRFConfigList(nw->orig_list, nw->list, false);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   713
		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
   714
		GamelogStopAction();
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   715
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   716
		/* Show new, updated list */
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   717
		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
   718
		CopyGRFConfigList(&nw->list, *nw->orig_list, false);
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   719
		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
   720
		nw->sel = c;
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   721
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   722
		w->SetDirty();
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   723
	}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   724
}
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   725
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   726
5237
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   727
5352
86fca6a41aa1 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5345
diff changeset
   728
/** 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
   729
 * @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
   730
 * @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
   731
 * @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
   732
 *        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
   733
 * @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
   734
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
   735
{
4fce3ea379c2 (svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff changeset
   736
	DeleteWindowByClass(WC_GAME_OPTIONS);
9207
24e3a428ac76 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138
parents: 9164
diff changeset
   737
	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
   738
}