annotate src/newgrf_gui.cpp @ 19796:b5e26ecef856 draft

(svn r24729) -Codechange: Unify the handling of HEBR_EDITING.
author frosch <frosch@openttd.org>
date Tue, 13 Nov 2012 21:46:46 +0000
parents 012a8beddd97
children b43322410b60
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1 /* $Id$ */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2
12778
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12632
diff changeset
3 /*
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12632
diff changeset
4 * This file is part of OpenTTD.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12632
diff changeset
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12632
diff changeset
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12632
diff changeset
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12632
diff changeset
8 */
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12632
diff changeset
9
9111
d48433370037 (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 <rubidium@openttd.org>
parents: 8749
diff changeset
10 /** @file newgrf_gui.cpp GUI to change NewGRF settings. */
6348
bcf98ba27bbf (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas <belugas@openttd.org>
parents: 6248
diff changeset
11
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
12 #include "stdafx.h"
18627
1972f6346144 (svn r23474) -Codechange: move the declaration error related functions to error.h
rubidium <rubidium@openttd.org>
parents: 18618
diff changeset
13 #include "error.h"
19406
0731e1a0613a (svn r24309) -Codechange: Split some functions from gui.h to settings_gui.h
frosch <frosch@openttd.org>
parents: 19237
diff changeset
14 #include "settings_gui.h"
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
15 #include "newgrf.h"
8114
2d6af5d7a142 (svn r11675) -Codechange: split the string types from the string functions.
rubidium <rubidium@openttd.org>
parents: 8107
diff changeset
16 #include "strings_func.h"
8131
e300ac8001ae (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 <rubidium@openttd.org>
parents: 8130
diff changeset
17 #include "window_func.h"
9457
267a95510fdf (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz <smatz@openttd.org>
parents: 9317
diff changeset
18 #include "gamelog.h"
15599
146255899304 (svn r20259) -Add: allow NewGRFs to specify their version and use that to hide old NewGRFs / to choose the newest when loading compatible NewGRFs
rubidium <rubidium@openttd.org>
parents: 15598
diff changeset
19 #include "settings_type.h"
9677
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
20 #include "settings_func.h"
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
21 #include "widgets/dropdown_type.h"
19415
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
22 #include "widgets/dropdown_func.h"
10793
0744d383a56b (svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents: 10145
diff changeset
23 #include "network/network.h"
0744d383a56b (svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents: 10145
diff changeset
24 #include "network/network_content.h"
13043
8eef3a6e299f (svn r17541) -Feature: Filtering in Add-NewGRF dialog.
frosch <frosch@openttd.org>
parents: 13020
diff changeset
25 #include "sortlist_type.h"
19434
24df8a97401e (svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents: 19421
diff changeset
26 #include "stringfilter_type.h"
13043
8eef3a6e299f (svn r17541) -Feature: Filtering in Add-NewGRF dialog.
frosch <frosch@openttd.org>
parents: 13020
diff changeset
27 #include "querystring_gui.h"
14258
a899d4e5ee1a (svn r18809) -Codechange/Cleanup: remove unneeded headers from some files, if a header require a header make it include that header
rubidium <rubidium@openttd.org>
parents: 14149
diff changeset
28 #include "core/geometry_func.hpp"
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
29 #include "newgrf_text.h"
19078
8cb1275f2bb3 (svn r23932) -Codechange: split the NewGRF text window into its own source files
rubidium <rubidium@openttd.org>
parents: 18957
diff changeset
30 #include "textfile_gui.h"
19237
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
31 #include "tilehighlight_func.h"
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
32
18680
e87c7c30e606 (svn r23528) -Codechange: move widget enums to widgets/NNN_type.h
truebrain <truebrain@openttd.org>
parents: 18648
diff changeset
33 #include "widgets/newgrf_widget.h"
19078
8cb1275f2bb3 (svn r23932) -Codechange: split the NewGRF text window into its own source files
rubidium <rubidium@openttd.org>
parents: 18957
diff changeset
34 #include "widgets/misc_widget.h"
18680
e87c7c30e606 (svn r23528) -Codechange: move widget enums to widgets/NNN_type.h
truebrain <truebrain@openttd.org>
parents: 18648
diff changeset
35
8264
2495310e220f (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents: 8224
diff changeset
36 #include "table/sprites.h"
2495310e220f (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents: 8224
diff changeset
37
13968
070572f1272d (svn r18506) -Fix [FS#3368]: no error message was created for the first fatal NewGRF error.
rubidium <rubidium@openttd.org>
parents: 13796
diff changeset
38 /**
070572f1272d (svn r18506) -Fix [FS#3368]: no error message was created for the first fatal NewGRF error.
rubidium <rubidium@openttd.org>
parents: 13796
diff changeset
39 * Show the first NewGRF error we can find.
070572f1272d (svn r18506) -Fix [FS#3368]: no error message was created for the first fatal NewGRF error.
rubidium <rubidium@openttd.org>
parents: 13796
diff changeset
40 */
070572f1272d (svn r18506) -Fix [FS#3368]: no error message was created for the first fatal NewGRF error.
rubidium <rubidium@openttd.org>
parents: 13796
diff changeset
41 void ShowNewGRFError()
070572f1272d (svn r18506) -Fix [FS#3368]: no error message was created for the first fatal NewGRF error.
rubidium <rubidium@openttd.org>
parents: 13796
diff changeset
42 {
17670
20f6e34b8ff6 (svn r22442) -Fix: Do not popup fatal NewGRF error messages in the intro screen. The GRFs are not going to be activated there anyway and the GRF settings GUI will not display the errors either.
frosch <frosch@openttd.org>
parents: 17657
diff changeset
43 /* Do not show errors when entering the main screen */
20f6e34b8ff6 (svn r22442) -Fix: Do not popup fatal NewGRF error messages in the intro screen. The GRFs are not going to be activated there anyway and the GRF settings GUI will not display the errors either.
frosch <frosch@openttd.org>
parents: 17657
diff changeset
44 if (_game_mode == GM_MENU) return;
20f6e34b8ff6 (svn r22442) -Fix: Do not popup fatal NewGRF error messages in the intro screen. The GRFs are not going to be activated there anyway and the GRF settings GUI will not display the errors either.
frosch <frosch@openttd.org>
parents: 17657
diff changeset
45
13968
070572f1272d (svn r18506) -Fix [FS#3368]: no error message was created for the first fatal NewGRF error.
rubidium <rubidium@openttd.org>
parents: 13796
diff changeset
46 for (const GRFConfig *c = _grfconfig; c != NULL; c = c->next) {
070572f1272d (svn r18506) -Fix [FS#3368]: no error message was created for the first fatal NewGRF error.
rubidium <rubidium@openttd.org>
parents: 13796
diff changeset
47 /* We only want to show fatal errors */
070572f1272d (svn r18506) -Fix [FS#3368]: no error message was created for the first fatal NewGRF error.
rubidium <rubidium@openttd.org>
parents: 13796
diff changeset
48 if (c->error == NULL || c->error->severity != STR_NEWGRF_ERROR_MSG_FATAL) continue;
070572f1272d (svn r18506) -Fix [FS#3368]: no error message was created for the first fatal NewGRF error.
rubidium <rubidium@openttd.org>
parents: 13796
diff changeset
49
070572f1272d (svn r18506) -Fix [FS#3368]: no error message was created for the first fatal NewGRF error.
rubidium <rubidium@openttd.org>
parents: 13796
diff changeset
50 SetDParam (0, c->error->custom_message == NULL ? c->error->message : STR_JUST_RAW_STRING);
070572f1272d (svn r18506) -Fix [FS#3368]: no error message was created for the first fatal NewGRF error.
rubidium <rubidium@openttd.org>
parents: 13796
diff changeset
51 SetDParamStr(1, c->error->custom_message);
18957
f7df1757f6d9 (svn r23812) -Fix [FS#4977] (r23804): custom ActionB messages were broken
yexo <yexo@openttd.org>
parents: 18953
diff changeset
52 SetDParamStr(2, c->filename);
f7df1757f6d9 (svn r23812) -Fix [FS#4977] (r23804): custom ActionB messages were broken
yexo <yexo@openttd.org>
parents: 18953
diff changeset
53 SetDParamStr(3, c->error->data);
18953
2f02d08b8db8 (svn r23807) -Codechange: GRFError::num_params is not needed, remove it.
frosch <frosch@openttd.org>
parents: 18943
diff changeset
54 for (uint i = 0; i < lengthof(c->error->param_value); i++) {
18957
f7df1757f6d9 (svn r23812) -Fix [FS#4977] (r23804): custom ActionB messages were broken
yexo <yexo@openttd.org>
parents: 18953
diff changeset
55 SetDParam(4 + i, c->error->param_value[i]);
13968
070572f1272d (svn r18506) -Fix [FS#3368]: no error message was created for the first fatal NewGRF error.
rubidium <rubidium@openttd.org>
parents: 13796
diff changeset
56 }
14645
b7a22979b84e (svn r19224) -Codechange: change parameters passed to ShowErrorMessage() a bit
smatz <smatz@openttd.org>
parents: 14561
diff changeset
57 ShowErrorMessage(STR_NEWGRF_ERROR_FATAL_POPUP, INVALID_STRING_ID, WL_CRITICAL);
13968
070572f1272d (svn r18506) -Fix [FS#3368]: no error message was created for the first fatal NewGRF error.
rubidium <rubidium@openttd.org>
parents: 13796
diff changeset
58 break;
070572f1272d (svn r18506) -Fix [FS#3368]: no error message was created for the first fatal NewGRF error.
rubidium <rubidium@openttd.org>
parents: 13796
diff changeset
59 }
070572f1272d (svn r18506) -Fix [FS#3368]: no error message was created for the first fatal NewGRF error.
rubidium <rubidium@openttd.org>
parents: 13796
diff changeset
60 }
070572f1272d (svn r18506) -Fix [FS#3368]: no error message was created for the first fatal NewGRF error.
rubidium <rubidium@openttd.org>
parents: 13796
diff changeset
61
13017
ab07d6d87608 (svn r17511) -Codechange: Simplify ShowNewGRFInfo() by passing 'right' instead of 'width'.
frosch <frosch@openttd.org>
parents: 12879
diff changeset
62 static void ShowNewGRFInfo(const GRFConfig *c, uint x, uint y, uint right, uint bottom, bool show_params)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
63 {
6103
e3a3a903fa28 (svn r8838) -Feature: Show newgrf error messages loaded in Action B in the newgrf gui
maedhros <maedhros@openttd.org>
parents: 5893
diff changeset
64 if (c->error != NULL) {
9648
b53049484e44 (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 <rubidium@openttd.org>
parents: 9457
diff changeset
65 char message[512];
9957
2416082e752c (svn r14112) -Fix (r13715)[FS#2232]: Action B custom messages with parameteers were broken.
frosch <frosch@openttd.org>
parents: 9864
diff changeset
66 SetDParamStr(0, c->error->custom_message); // is skipped by built-in messages
18957
f7df1757f6d9 (svn r23812) -Fix [FS#4977] (r23804): custom ActionB messages were broken
yexo <yexo@openttd.org>
parents: 18953
diff changeset
67 SetDParamStr(1, c->filename);
f7df1757f6d9 (svn r23812) -Fix [FS#4977] (r23804): custom ActionB messages were broken
yexo <yexo@openttd.org>
parents: 18953
diff changeset
68 SetDParamStr(2, c->error->data);
18953
2f02d08b8db8 (svn r23807) -Codechange: GRFError::num_params is not needed, remove it.
frosch <frosch@openttd.org>
parents: 18943
diff changeset
69 for (uint i = 0; i < lengthof(c->error->param_value); i++) {
18957
f7df1757f6d9 (svn r23812) -Fix [FS#4977] (r23804): custom ActionB messages were broken
yexo <yexo@openttd.org>
parents: 18953
diff changeset
70 SetDParam(3 + i, c->error->param_value[i]);
6139
3c76c0f47447 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros <maedhros@openttd.org>
parents: 6103
diff changeset
71 }
9957
2416082e752c (svn r14112) -Fix (r13715)[FS#2232]: Action B custom messages with parameteers were broken.
frosch <frosch@openttd.org>
parents: 9864
diff changeset
72 GetString(message, c->error->custom_message == NULL ? c->error->message : STR_JUST_RAW_STRING, lastof(message));
6139
3c76c0f47447 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros <maedhros@openttd.org>
parents: 6103
diff changeset
73
3c76c0f47447 (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros <maedhros@openttd.org>
parents: 6103
diff changeset
74 SetDParamStr(0, message);
13017
ab07d6d87608 (svn r17511) -Codechange: Simplify ShowNewGRFInfo() by passing 'right' instead of 'width'.
frosch <frosch@openttd.org>
parents: 12879
diff changeset
75 y = DrawStringMultiLine(x, right, y, bottom, c->error->severity);
6103
e3a3a903fa28 (svn r8838) -Feature: Show newgrf error messages loaded in Action B in the newgrf gui
maedhros <maedhros@openttd.org>
parents: 5893
diff changeset
76 }
e3a3a903fa28 (svn r8838) -Feature: Show newgrf error messages loaded in Action B in the newgrf gui
maedhros <maedhros@openttd.org>
parents: 5893
diff changeset
77
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
78 /* Draw filename or not if it is not known (GRF sent over internet) */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
79 if (c->filename != NULL) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
80 SetDParamStr(0, c->filename);
13017
ab07d6d87608 (svn r17511) -Codechange: Simplify ShowNewGRFInfo() by passing 'right' instead of 'width'.
frosch <frosch@openttd.org>
parents: 12879
diff changeset
81 y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_FILENAME);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
82 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
83
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
84 /* Prepare and draw GRF ID */
15201
071e920abcfb (svn r19830) -Codechange: Move variable declarations to their first use.
alberth <alberth@openttd.org>
parents: 15200
diff changeset
85 char buff[256];
14676
353df593bee0 (svn r19255) -Codechange: encapsulate GRFIdentifier in GRFConfig instead of subclassing it
yexo <yexo@openttd.org>
parents: 14645
diff changeset
86 snprintf(buff, lengthof(buff), "%08X", BSWAP32(c->ident.grfid));
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
87 SetDParamStr(0, buff);
13017
ab07d6d87608 (svn r17511) -Codechange: Simplify ShowNewGRFInfo() by passing 'right' instead of 'width'.
frosch <frosch@openttd.org>
parents: 12879
diff changeset
88 y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_GRF_ID);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
89
16286
3210d6542c3f (svn r20992) -Fix (r20958): Show either version and minimum compatible version or neither
planetmaker <planetmaker@openttd.org>
parents: 16259
diff changeset
90 if ((_settings_client.gui.newgrf_developer_tools || _settings_client.gui.newgrf_show_old_versions) && c->version != 0) {
15599
146255899304 (svn r20259) -Add: allow NewGRFs to specify their version and use that to hide old NewGRFs / to choose the newest when loading compatible NewGRFs
rubidium <rubidium@openttd.org>
parents: 15598
diff changeset
91 SetDParam(0, c->version);
146255899304 (svn r20259) -Add: allow NewGRFs to specify their version and use that to hide old NewGRFs / to choose the newest when loading compatible NewGRFs
rubidium <rubidium@openttd.org>
parents: 15598
diff changeset
92 y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_VERSION);
146255899304 (svn r20259) -Add: allow NewGRFs to specify their version and use that to hide old NewGRFs / to choose the newest when loading compatible NewGRFs
rubidium <rubidium@openttd.org>
parents: 15598
diff changeset
93 }
16286
3210d6542c3f (svn r20992) -Fix (r20958): Show either version and minimum compatible version or neither
planetmaker <planetmaker@openttd.org>
parents: 16259
diff changeset
94 if ((_settings_client.gui.newgrf_developer_tools || _settings_client.gui.newgrf_show_old_versions) && c->min_loadable_version != 0) {
16259
8a820ca2e1f7 (svn r20960) -Add: Allow setting 'minimal compatible version' via Action14. (planetmaker)
frosch <frosch@openttd.org>
parents: 16256
diff changeset
95 SetDParam(0, c->min_loadable_version);
8a820ca2e1f7 (svn r20960) -Add: Allow setting 'minimal compatible version' via Action14. (planetmaker)
frosch <frosch@openttd.org>
parents: 16256
diff changeset
96 y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_MIN_VERSION);
8a820ca2e1f7 (svn r20960) -Add: Allow setting 'minimal compatible version' via Action14. (planetmaker)
frosch <frosch@openttd.org>
parents: 16256
diff changeset
97 }
15599
146255899304 (svn r20259) -Add: allow NewGRFs to specify their version and use that to hide old NewGRFs / to choose the newest when loading compatible NewGRFs
rubidium <rubidium@openttd.org>
parents: 15598
diff changeset
98
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
99 /* Prepare and draw MD5 sum */
14676
353df593bee0 (svn r19255) -Codechange: encapsulate GRFIdentifier in GRFConfig instead of subclassing it
yexo <yexo@openttd.org>
parents: 14645
diff changeset
100 md5sumToString(buff, lastof(buff), c->ident.md5sum);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
101 SetDParamStr(0, buff);
13017
ab07d6d87608 (svn r17511) -Codechange: Simplify ShowNewGRFInfo() by passing 'right' instead of 'width'.
frosch <frosch@openttd.org>
parents: 12879
diff changeset
102 y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_MD5SUM);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
103
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
104 /* Show GRF parameter list */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
105 if (show_params) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
106 if (c->num_params > 0) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
107 GRFBuildParamList(buff, c, lastof(buff));
9648
b53049484e44 (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 <rubidium@openttd.org>
parents: 9457
diff changeset
108 SetDParam(0, STR_JUST_RAW_STRING);
b53049484e44 (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 <rubidium@openttd.org>
parents: 9457
diff changeset
109 SetDParamStr(1, buff);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
110 } else {
11730
a39da1e4c1f5 (svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents: 11524
diff changeset
111 SetDParam(0, STR_LAND_AREA_INFORMATION_LOCAL_AUTHORITY_NONE);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
112 }
13017
ab07d6d87608 (svn r17511) -Codechange: Simplify ShowNewGRFInfo() by passing 'right' instead of 'width'.
frosch <frosch@openttd.org>
parents: 12879
diff changeset
113 y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_PARAMETER);
10126
c5ceca8952d5 (svn r14310) -Fix: don't show palette information in the newgrf lists of the network lobby.
rubidium <rubidium@openttd.org>
parents: 10115
diff changeset
114
c5ceca8952d5 (svn r14310) -Fix: don't show palette information in the newgrf lists of the network lobby.
rubidium <rubidium@openttd.org>
parents: 10115
diff changeset
115 /* Draw the palette of the NewGRF */
18173
4a83f4b2e636 (svn r23002) -Add: Extend palette information in the NewGRF GUI with the 32 bpp state.
michi_cc <michi_cc@openttd.org>
parents: 18011
diff changeset
116 if (c->palette & GRFP_BLT_32BPP) {
4a83f4b2e636 (svn r23002) -Add: Extend palette information in the NewGRF GUI with the 32 bpp state.
michi_cc <michi_cc@openttd.org>
parents: 18011
diff changeset
117 SetDParamStr(0, (c->palette & GRFP_USE_WINDOWS) ? "Windows / 32 bpp" : "DOS / 32 bpp");
4a83f4b2e636 (svn r23002) -Add: Extend palette information in the NewGRF GUI with the 32 bpp state.
michi_cc <michi_cc@openttd.org>
parents: 18011
diff changeset
118 } else {
4a83f4b2e636 (svn r23002) -Add: Extend palette information in the NewGRF GUI with the 32 bpp state.
michi_cc <michi_cc@openttd.org>
parents: 18011
diff changeset
119 SetDParamStr(0, (c->palette & GRFP_USE_WINDOWS) ? "Windows" : "DOS");
4a83f4b2e636 (svn r23002) -Add: Extend palette information in the NewGRF GUI with the 32 bpp state.
michi_cc <michi_cc@openttd.org>
parents: 18011
diff changeset
120 }
13017
ab07d6d87608 (svn r17511) -Codechange: Simplify ShowNewGRFInfo() by passing 'right' instead of 'width'.
frosch <frosch@openttd.org>
parents: 12879
diff changeset
121 y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_PALETTE);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
122 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
123
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
124 /* Show flags */
13017
ab07d6d87608 (svn r17511) -Codechange: Simplify ShowNewGRFInfo() by passing 'right' instead of 'width'.
frosch <frosch@openttd.org>
parents: 12879
diff changeset
125 if (c->status == GCS_NOT_FOUND) y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_NOT_FOUND);
ab07d6d87608 (svn r17511) -Codechange: Simplify ShowNewGRFInfo() by passing 'right' instead of 'width'.
frosch <frosch@openttd.org>
parents: 12879
diff changeset
126 if (c->status == GCS_DISABLED) y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_DISABLED);
17077
5a60038ce980 (svn r21814) -Fix/Add: Check GRF version from action 8, and disallow usage of GRFs with versions above 7.
frosch <frosch@openttd.org>
parents: 16614
diff changeset
127 if (HasBit(c->flags, GCF_INVALID)) y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_INCOMPATIBLE);
13017
ab07d6d87608 (svn r17511) -Codechange: Simplify ShowNewGRFInfo() by passing 'right' instead of 'width'.
frosch <frosch@openttd.org>
parents: 12879
diff changeset
128 if (HasBit(c->flags, GCF_COMPATIBLE)) y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_COMPATIBLE_LOADED);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
129
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
130 /* Draw GRF info if it exists */
14711
74b0a8a64ff5 (svn r19295) -Codechange: introduce wrapper functions for GRFConfig::name/info
yexo <yexo@openttd.org>
parents: 14676
diff changeset
131 if (!StrEmpty(c->GetDescription())) {
9648
b53049484e44 (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 <rubidium@openttd.org>
parents: 9457
diff changeset
132 SetDParam(0, STR_JUST_RAW_STRING);
14711
74b0a8a64ff5 (svn r19295) -Codechange: introduce wrapper functions for GRFConfig::name/info
yexo <yexo@openttd.org>
parents: 14676
diff changeset
133 SetDParamStr(1, c->GetDescription());
13017
ab07d6d87608 (svn r17511) -Codechange: Simplify ShowNewGRFInfo() by passing 'right' instead of 'width'.
frosch <frosch@openttd.org>
parents: 12879
diff changeset
134 y = DrawStringMultiLine(x, right, y, bottom, STR_BLACK_STRING);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
135 } else {
13017
ab07d6d87608 (svn r17511) -Codechange: Simplify ShowNewGRFInfo() by passing 'right' instead of 'width'.
frosch <frosch@openttd.org>
parents: 12879
diff changeset
136 y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_NO_INFO);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
137 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
138 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
139
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
140 /**
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
141 * Window for setting the parameters of a NewGRF.
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
142 */
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
143 struct NewGRFParametersWindow : public Window {
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
144 static GRFParameterInfo dummy_parameter_info; ///< Dummy info in case a newgrf didn't provide info about some parameter.
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
145 GRFConfig *grf_config; ///< Set the parameters of this GRFConfig.
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
146 uint clicked_button; ///< The row in which a button was clicked or UINT_MAX.
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
147 bool clicked_increase; ///< True if the increase button was clicked, false for the decrease button.
19415
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
148 bool clicked_dropdown; ///< Whether the dropdown is open.
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
149 bool closing_dropdown; ///< True, if the dropdown list is currently closing.
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
150 int timeout; ///< How long before we unpress the last-pressed button?
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
151 uint clicked_row; ///< The selected parameter
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
152 int line_height; ///< Height of a row in the matrix widget.
15779
9ad2843db6f4 (svn r20453) -Codechange: Remove direct accesses to Window::hscroll, vscroll and vscroll2.
frosch <frosch@openttd.org>
parents: 15778
diff changeset
153 Scrollbar *vscroll;
16086
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
154 bool action14present; ///< True if action14 information is present.
18911
e48659f8d5c4 (svn r23760) -Feature: Allow readonly display of NewGRF parameters, if GRF list may not be edited.
frosch <frosch@openttd.org>
parents: 18908
diff changeset
155 bool editable; ///< Allow editing parameters.
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
156
18911
e48659f8d5c4 (svn r23760) -Feature: Allow readonly display of NewGRF parameters, if GRF list may not be edited.
frosch <frosch@openttd.org>
parents: 18908
diff changeset
157 NewGRFParametersWindow(const WindowDesc *desc, GRFConfig *c, bool editable) : Window(),
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
158 grf_config(c),
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
159 clicked_button(UINT_MAX),
19415
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
160 clicked_dropdown(false),
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
161 closing_dropdown(false),
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
162 timeout(0),
18911
e48659f8d5c4 (svn r23760) -Feature: Allow readonly display of NewGRF parameters, if GRF list may not be edited.
frosch <frosch@openttd.org>
parents: 18908
diff changeset
163 clicked_row(UINT_MAX),
e48659f8d5c4 (svn r23760) -Feature: Allow readonly display of NewGRF parameters, if GRF list may not be edited.
frosch <frosch@openttd.org>
parents: 18908
diff changeset
164 editable(editable)
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
165 {
16086
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
166 this->action14present = (c->num_valid_params != lengthof(c->param) || c->param_info.Length() != 0);
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
167
15779
9ad2843db6f4 (svn r20453) -Codechange: Remove direct accesses to Window::hscroll, vscroll and vscroll2.
frosch <frosch@openttd.org>
parents: 15778
diff changeset
168 this->CreateNestedTree(desc);
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
169 this->vscroll = this->GetScrollbar(WID_NP_SCROLLBAR);
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
170 this->GetWidget<NWidgetStacked>(WID_NP_SHOW_NUMPAR)->SetDisplayedPlane(this->action14present ? SZSP_HORIZONTAL : 0);
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
171 this->GetWidget<NWidgetStacked>(WID_NP_SHOW_DESCRIPTION)->SetDisplayedPlane(this->action14present ? 0 : SZSP_HORIZONTAL);
15779
9ad2843db6f4 (svn r20453) -Codechange: Remove direct accesses to Window::hscroll, vscroll and vscroll2.
frosch <frosch@openttd.org>
parents: 15778
diff changeset
172 this->FinishInitNested(desc); // Initializes 'this->line_height' as side effect.
16086
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
173
18911
e48659f8d5c4 (svn r23760) -Feature: Allow readonly display of NewGRF parameters, if GRF list may not be edited.
frosch <frosch@openttd.org>
parents: 18908
diff changeset
174 this->SetWidgetDisabledState(WID_NP_RESET, !this->editable);
e48659f8d5c4 (svn r23760) -Feature: Allow readonly display of NewGRF parameters, if GRF list may not be edited.
frosch <frosch@openttd.org>
parents: 18908
diff changeset
175
16086
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
176 this->InvalidateData();
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
177 }
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
178
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
179 /**
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
180 * Get a dummy parameter-info object with default information.
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
181 * @param nr The param number that should be changed.
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
182 * @return GRFParameterInfo with dummy information about the given parameter.
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
183 */
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
184 static GRFParameterInfo *GetDummyParameterInfo(uint nr)
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
185 {
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
186 dummy_parameter_info.param_nr = nr;
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
187 return &dummy_parameter_info;
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
188 }
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
189
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
190 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
191 {
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
192 switch (widget) {
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
193 case WID_NP_NUMPAR_DEC:
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
194 case WID_NP_NUMPAR_INC: {
16086
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
195 size->width = size->height = FONT_HEIGHT_NORMAL;
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
196 break;
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
197 }
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
198
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
199 case WID_NP_NUMPAR: {
16086
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
200 SetDParam(0, 999);
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
201 Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
202 d.width += padding.width;
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
203 d.height += padding.height;
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
204 *size = maxdim(*size, d);
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
205 break;
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
206 }
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
207
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
208 case WID_NP_BACKGROUND:
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
209 this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
210
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
211 resize->width = 1;
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
212 resize->height = this->line_height;
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
213 size->height = GB(this->GetWidget<NWidgetCore>(widget)->widget_data, MAT_ROW_START, MAT_ROW_BITS) * this->line_height;
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
214 break;
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
215
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
216 case WID_NP_DESCRIPTION:
18941
51721ad3085a (svn r23791) -Fix [FS#4960]: resize text panel for parameter description if it doesn't fit in 4 lines.
yexo <yexo@openttd.org>
parents: 18911
diff changeset
217 /* Minimum size of 4 lines. The 500 is the default size of the window. */
51721ad3085a (svn r23791) -Fix [FS#4960]: resize text panel for parameter description if it doesn't fit in 4 lines.
yexo <yexo@openttd.org>
parents: 18911
diff changeset
218 Dimension suggestion = {500 - WD_FRAMERECT_LEFT - WD_FRAMERECT_RIGHT, FONT_HEIGHT_NORMAL * 4 + WD_TEXTPANEL_TOP + WD_TEXTPANEL_BOTTOM};
51721ad3085a (svn r23791) -Fix [FS#4960]: resize text panel for parameter description if it doesn't fit in 4 lines.
yexo <yexo@openttd.org>
parents: 18911
diff changeset
219 for (uint i = 0; i < this->grf_config->param_info.Length(); i++) {
51721ad3085a (svn r23791) -Fix [FS#4960]: resize text panel for parameter description if it doesn't fit in 4 lines.
yexo <yexo@openttd.org>
parents: 18911
diff changeset
220 const GRFParameterInfo *par_info = this->grf_config->param_info[i];
51721ad3085a (svn r23791) -Fix [FS#4960]: resize text panel for parameter description if it doesn't fit in 4 lines.
yexo <yexo@openttd.org>
parents: 18911
diff changeset
221 if (par_info == NULL) continue;
51721ad3085a (svn r23791) -Fix [FS#4960]: resize text panel for parameter description if it doesn't fit in 4 lines.
yexo <yexo@openttd.org>
parents: 18911
diff changeset
222 const char *desc = GetGRFStringFromGRFText(par_info->desc);
51721ad3085a (svn r23791) -Fix [FS#4960]: resize text panel for parameter description if it doesn't fit in 4 lines.
yexo <yexo@openttd.org>
parents: 18911
diff changeset
223 if (desc == NULL) continue;
18943
b506035edee7 (svn r23793) -Fix (r23791): height computation was missing a few pixels so the last line was still missing
yexo <yexo@openttd.org>
parents: 18941
diff changeset
224 Dimension d = GetStringMultiLineBoundingBox(desc, suggestion);
b506035edee7 (svn r23793) -Fix (r23791): height computation was missing a few pixels so the last line was still missing
yexo <yexo@openttd.org>
parents: 18941
diff changeset
225 d.height += WD_TEXTPANEL_TOP + WD_TEXTPANEL_BOTTOM;
18941
51721ad3085a (svn r23791) -Fix [FS#4960]: resize text panel for parameter description if it doesn't fit in 4 lines.
yexo <yexo@openttd.org>
parents: 18911
diff changeset
226 suggestion = maxdim(d, suggestion);
51721ad3085a (svn r23791) -Fix [FS#4960]: resize text panel for parameter description if it doesn't fit in 4 lines.
yexo <yexo@openttd.org>
parents: 18911
diff changeset
227 }
51721ad3085a (svn r23791) -Fix [FS#4960]: resize text panel for parameter description if it doesn't fit in 4 lines.
yexo <yexo@openttd.org>
parents: 18911
diff changeset
228 size->height = suggestion.height;
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
229 break;
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
230 }
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
231 }
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
232
16086
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
233 virtual void SetStringParameters(int widget) const
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
234 {
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
235 switch (widget) {
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
236 case WID_NP_NUMPAR:
16086
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
237 SetDParam(0, this->vscroll->GetCount());
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
238 break;
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
239 }
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
240 }
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
241
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
242 virtual void DrawWidget(const Rect &r, int widget) const
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
243 {
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
244 if (widget == WID_NP_DESCRIPTION) {
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
245 const GRFParameterInfo *par_info = (this->clicked_row < this->grf_config->param_info.Length()) ? this->grf_config->param_info[this->clicked_row] : NULL;
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
246 if (par_info == NULL) return;
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
247 const char *desc = GetGRFStringFromGRFText(par_info->desc);
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
248 if (desc == NULL) return;
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
249 DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_TEXTPANEL_TOP, r.bottom - WD_TEXTPANEL_BOTTOM, desc, TC_BLACK);
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
250 return;
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
251 } else if (widget != WID_NP_BACKGROUND) {
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
252 return;
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
253 }
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
254
16441
86fd9bcc9d2f (svn r21157) -Codechange: remove information about the text direction out of the language "list"
rubidium <rubidium@openttd.org>
parents: 16395
diff changeset
255 bool rtl = _current_text_dir == TD_RTL;
19407
e4f32df0a2b7 (svn r24310) -Codechange: Add named constants for the dimensions of settings buttons, and generally make their usage more consistent.
frosch <frosch@openttd.org>
parents: 19406
diff changeset
256 uint buttons_left = rtl ? r.right - SETTING_BUTTON_WIDTH - 3 : r.left + 4;
e4f32df0a2b7 (svn r24310) -Codechange: Add named constants for the dimensions of settings buttons, and generally make their usage more consistent.
frosch <frosch@openttd.org>
parents: 19406
diff changeset
257 uint text_left = r.left + (rtl ? WD_FRAMERECT_LEFT : SETTING_BUTTON_WIDTH + 8);
e4f32df0a2b7 (svn r24310) -Codechange: Add named constants for the dimensions of settings buttons, and generally make their usage more consistent.
frosch <frosch@openttd.org>
parents: 19406
diff changeset
258 uint text_right = r.right - (rtl ? SETTING_BUTTON_WIDTH + 8 : WD_FRAMERECT_RIGHT);
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
259
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
260 int y = r.top;
19409
9e09a99aba22 (svn r24312) -Change: Center the settings buttons in the AI and NewGRF config windows.
frosch <frosch@openttd.org>
parents: 19407
diff changeset
261 int button_y_offset = (this->line_height - SETTING_BUTTON_HEIGHT) / 2;
16086
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
262 for (uint i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < this->vscroll->GetCount(); i++) {
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
263 GRFParameterInfo *par_info = (i < this->grf_config->param_info.Length()) ? this->grf_config->param_info[i] : NULL;
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
264 if (par_info == NULL) par_info = GetDummyParameterInfo(i);
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
265 uint32 current_value = par_info->GetValue(this->grf_config);
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
266 bool selected = (i == this->clicked_row);
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
267
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
268 if (par_info->type == PTYPE_BOOL) {
19409
9e09a99aba22 (svn r24312) -Change: Center the settings buttons in the AI and NewGRF config windows.
frosch <frosch@openttd.org>
parents: 19407
diff changeset
269 DrawBoolButton(buttons_left, y + button_y_offset, current_value != 0, this->editable);
15804
cefe74c2f556 (svn r20479) -Change: Use 'Buttons Name: Value' layout for AI and NewGRF parameter GUI.
frosch <frosch@openttd.org>
parents: 15787
diff changeset
270 SetDParam(2, par_info->GetValue(this->grf_config) == 0 ? STR_CONFIG_SETTING_OFF : STR_CONFIG_SETTING_ON);
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
271 } else if (par_info->type == PTYPE_UINT_ENUM) {
19415
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
272 if (par_info->complete_labels) {
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
273 DrawDropDownButton(buttons_left, y + button_y_offset, COLOUR_YELLOW, this->clicked_row == i && this->clicked_dropdown, this->editable);
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
274 } else {
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
275 DrawArrowButtons(buttons_left, y + button_y_offset, COLOUR_YELLOW, (this->clicked_button == i) ? 1 + (this->clicked_increase != rtl) : 0, this->editable && current_value > par_info->min_value, this->editable && current_value < par_info->max_value);
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
276 }
15804
cefe74c2f556 (svn r20479) -Change: Use 'Buttons Name: Value' layout for AI and NewGRF parameter GUI.
frosch <frosch@openttd.org>
parents: 15787
diff changeset
277 SetDParam(2, STR_JUST_INT);
cefe74c2f556 (svn r20479) -Change: Use 'Buttons Name: Value' layout for AI and NewGRF parameter GUI.
frosch <frosch@openttd.org>
parents: 15787
diff changeset
278 SetDParam(3, current_value);
16250
dd6d2c758c96 (svn r20951) -Codechange: Add SmallMap::Contains() and use it.
frosch <frosch@openttd.org>
parents: 16116
diff changeset
279 if (par_info->value_names.Contains(current_value)) {
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
280 const char *label = GetGRFStringFromGRFText(par_info->value_names.Find(current_value)->second);
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
281 if (label != NULL) {
15804
cefe74c2f556 (svn r20479) -Change: Use 'Buttons Name: Value' layout for AI and NewGRF parameter GUI.
frosch <frosch@openttd.org>
parents: 15787
diff changeset
282 SetDParam(2, STR_JUST_RAW_STRING);
cefe74c2f556 (svn r20479) -Change: Use 'Buttons Name: Value' layout for AI and NewGRF parameter GUI.
frosch <frosch@openttd.org>
parents: 15787
diff changeset
283 SetDParamStr(3, label);
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
284 }
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
285 }
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
286 }
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
287
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
288 const char *name = GetGRFStringFromGRFText(par_info->name);
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
289 if (name != NULL) {
15804
cefe74c2f556 (svn r20479) -Change: Use 'Buttons Name: Value' layout for AI and NewGRF parameter GUI.
frosch <frosch@openttd.org>
parents: 15787
diff changeset
290 SetDParam(0, STR_JUST_RAW_STRING);
cefe74c2f556 (svn r20479) -Change: Use 'Buttons Name: Value' layout for AI and NewGRF parameter GUI.
frosch <frosch@openttd.org>
parents: 15787
diff changeset
291 SetDParamStr(1, name);
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
292 } else {
15804
cefe74c2f556 (svn r20479) -Change: Use 'Buttons Name: Value' layout for AI and NewGRF parameter GUI.
frosch <frosch@openttd.org>
parents: 15787
diff changeset
293 SetDParam(0, STR_NEWGRF_PARAMETERS_DEFAULT_NAME);
cefe74c2f556 (svn r20479) -Change: Use 'Buttons Name: Value' layout for AI and NewGRF parameter GUI.
frosch <frosch@openttd.org>
parents: 15787
diff changeset
294 SetDParam(1, i + 1);
15605
391d97ec4083 (svn r20268) -Add: append 'On'/'Off' after the name for boolean NewGRF settings
yexo <yexo@openttd.org>
parents: 15603
diff changeset
295 }
15804
cefe74c2f556 (svn r20479) -Change: Use 'Buttons Name: Value' layout for AI and NewGRF parameter GUI.
frosch <frosch@openttd.org>
parents: 15787
diff changeset
296
cefe74c2f556 (svn r20479) -Change: Use 'Buttons Name: Value' layout for AI and NewGRF parameter GUI.
frosch <frosch@openttd.org>
parents: 15787
diff changeset
297 DrawString(text_left, text_right, y + WD_MATRIX_TOP, STR_NEWGRF_PARAMETERS_SETTING, selected ? TC_WHITE : TC_LIGHT_BLUE);
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
298 y += this->line_height;
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
299 }
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
300 }
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
301
19415
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
302 virtual void OnPaint()
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
303 {
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
304 if (this->closing_dropdown) {
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
305 this->closing_dropdown = false;
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
306 this->clicked_dropdown = false;
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
307 }
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
308 this->DrawWidgets();
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
309 }
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
310
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
311 virtual void OnClick(Point pt, int widget, int click_count)
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
312 {
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
313 switch (widget) {
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
314 case WID_NP_NUMPAR_DEC:
18911
e48659f8d5c4 (svn r23760) -Feature: Allow readonly display of NewGRF parameters, if GRF list may not be edited.
frosch <frosch@openttd.org>
parents: 18908
diff changeset
315 if (this->editable && !this->action14present && this->grf_config->num_params > 0) {
16086
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
316 this->grf_config->num_params--;
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
317 this->InvalidateData();
18753
8d2cdabac894 (svn r23601) -Fix: fix the conflict in window number
truebrain <truebrain@openttd.org>
parents: 18742
diff changeset
318 SetWindowDirty(WC_GAME_OPTIONS, WN_GAME_OPTIONS_NEWGRF_STATE);
16086
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
319 }
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
320 break;
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
321
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
322 case WID_NP_NUMPAR_INC: {
16086
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
323 GRFConfig *c = this->grf_config;
18911
e48659f8d5c4 (svn r23760) -Feature: Allow readonly display of NewGRF parameters, if GRF list may not be edited.
frosch <frosch@openttd.org>
parents: 18908
diff changeset
324 if (this->editable && !this->action14present && c->num_params < c->num_valid_params) {
16086
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
325 c->param[c->num_params++] = 0;
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
326 this->InvalidateData();
18753
8d2cdabac894 (svn r23601) -Fix: fix the conflict in window number
truebrain <truebrain@openttd.org>
parents: 18742
diff changeset
327 SetWindowDirty(WC_GAME_OPTIONS, WN_GAME_OPTIONS_NEWGRF_STATE);
16086
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
328 }
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
329 break;
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
330 }
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
331
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
332 case WID_NP_BACKGROUND: {
18911
e48659f8d5c4 (svn r23760) -Feature: Allow readonly display of NewGRF parameters, if GRF list may not be edited.
frosch <frosch@openttd.org>
parents: 18908
diff changeset
333 if (!this->editable) break;
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
334 uint num = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_NP_BACKGROUND);
16086
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
335 if (num >= this->vscroll->GetCount()) break;
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
336 if (this->clicked_row != num) {
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
337 DeleteChildWindows(WC_QUERY_STRING);
19415
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
338 HideDropDownMenu(this);
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
339 this->clicked_row = num;
19415
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
340 this->clicked_dropdown = false;
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
341 }
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
342
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
343 const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_NP_BACKGROUND);
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
344 int x = pt.x - wid->pos_x;
19410
b326bdfc63d3 (svn r24313) -Fix: Some obiwans wrt. clicking on setting buttons.
frosch <frosch@openttd.org>
parents: 19409
diff changeset
345 if (_current_text_dir == TD_RTL) x = wid->current_x - 1 - x;
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
346 x -= 4;
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
347
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
348 GRFParameterInfo *par_info = (num < this->grf_config->param_info.Length()) ? this->grf_config->param_info[num] : NULL;
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
349 if (par_info == NULL) par_info = GetDummyParameterInfo(num);
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
350
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
351 /* One of the arrows is clicked */
19411
89148abbf734 (svn r24314) -Fix: Editing NewGRF parameters using the query window showed wrong values, if there was no direct relation between parameter index and parameter register.
frosch <frosch@openttd.org>
parents: 19410
diff changeset
352 uint32 old_val = par_info->GetValue(this->grf_config);
19415
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
353 if (par_info->type != PTYPE_BOOL && IsInsideMM(x, 0, SETTING_BUTTON_WIDTH) && par_info->complete_labels) {
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
354 if (this->clicked_dropdown) {
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
355 /* unclick the dropdown */
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
356 HideDropDownMenu(this);
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
357 this->clicked_dropdown = false;
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
358 this->closing_dropdown = false;
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
359 } else {
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
360 const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_NP_BACKGROUND);
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
361 int rel_y = (pt.y - (int)wid->pos_y) % this->line_height;
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
362
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
363 Rect wi_rect;
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
364 wi_rect.left = pt.x - (_current_text_dir == TD_RTL ? SETTING_BUTTON_WIDTH - 1 - x : x);;
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
365 wi_rect.right = wi_rect.left + SETTING_BUTTON_WIDTH - 1;
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
366 wi_rect.top = pt.y - rel_y + (this->line_height - SETTING_BUTTON_HEIGHT) / 2;
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
367 wi_rect.bottom = wi_rect.top + SETTING_BUTTON_HEIGHT - 1;
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
368
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
369 /* For dropdowns we also have to check the y position thoroughly, the mouse may not above the just opening dropdown */
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
370 if (pt.y >= wi_rect.top && pt.y <= wi_rect.bottom) {
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
371 this->clicked_dropdown = true;
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
372 this->closing_dropdown = false;
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
373
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
374 DropDownList *list = new DropDownList();
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
375 for (uint32 i = par_info->min_value; i <= par_info->max_value; i++) {
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
376 list->push_back(new DropDownListCharStringItem(GetGRFStringFromGRFText(par_info->value_names.Find(i)->second), i, false));
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
377 }
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
378
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
379 ShowDropDownListAt(this, list, old_val, -1, wi_rect, COLOUR_ORANGE, true);
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
380 }
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
381 }
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
382 } else if (IsInsideMM(x, 0, SETTING_BUTTON_WIDTH)) {
19411
89148abbf734 (svn r24314) -Fix: Editing NewGRF parameters using the query window showed wrong values, if there was no direct relation between parameter index and parameter register.
frosch <frosch@openttd.org>
parents: 19410
diff changeset
383 uint32 val = old_val;
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
384 if (par_info->type == PTYPE_BOOL) {
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
385 val = !val;
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
386 } else {
19407
e4f32df0a2b7 (svn r24310) -Codechange: Add named constants for the dimensions of settings buttons, and generally make their usage more consistent.
frosch <frosch@openttd.org>
parents: 19406
diff changeset
387 if (x >= SETTING_BUTTON_WIDTH / 2) {
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
388 /* Increase button clicked */
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
389 if (val < par_info->max_value) val++;
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
390 this->clicked_increase = true;
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
391 } else {
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
392 /* Decrease button clicked */
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
393 if (val > par_info->min_value) val--;
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
394 this->clicked_increase = false;
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
395 }
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
396 }
17719
8e82fec94067 (svn r22499) -Fix: don't lower the arrow buttons in the newgrf/AI parameter windows if they're clicked when disabled
yexo <yexo@openttd.org>
parents: 17670
diff changeset
397 if (val != old_val) {
8e82fec94067 (svn r22499) -Fix: don't lower the arrow buttons in the newgrf/AI parameter windows if they're clicked when disabled
yexo <yexo@openttd.org>
parents: 17670
diff changeset
398 par_info->SetValue(this->grf_config, val);
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
399
17719
8e82fec94067 (svn r22499) -Fix: don't lower the arrow buttons in the newgrf/AI parameter windows if they're clicked when disabled
yexo <yexo@openttd.org>
parents: 17670
diff changeset
400 this->clicked_button = num;
8e82fec94067 (svn r22499) -Fix: don't lower the arrow buttons in the newgrf/AI parameter windows if they're clicked when disabled
yexo <yexo@openttd.org>
parents: 17670
diff changeset
401 this->timeout = 5;
8e82fec94067 (svn r22499) -Fix: don't lower the arrow buttons in the newgrf/AI parameter windows if they're clicked when disabled
yexo <yexo@openttd.org>
parents: 17670
diff changeset
402 }
19415
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
403 } else if (par_info->type == PTYPE_UINT_ENUM && !par_info->complete_labels && click_count >= 2) {
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
404 /* Display a query box so users can enter a custom value. */
19411
89148abbf734 (svn r24314) -Fix: Editing NewGRF parameters using the query window showed wrong values, if there was no direct relation between parameter index and parameter register.
frosch <frosch@openttd.org>
parents: 19410
diff changeset
405 SetDParam(0, old_val);
17579
105b4e4eb168 (svn r22343) -Change: Remove pixel limiter for query strings.
terkhen <terkhen@openttd.org>
parents: 17486
diff changeset
406 ShowQueryString(STR_JUST_INT, STR_CONFIG_SETTING_QUERY_CAPTION, 10, this, CS_NUMERAL, QSF_NONE);
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
407 }
17769
fc23ab1c0733 (svn r22553) -Fix (r22499): NewGRF parameter window was not set dirty, when changing row selection.
frosch <frosch@openttd.org>
parents: 17719
diff changeset
408 this->SetDirty();
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
409 break;
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
410 }
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
411
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
412 case WID_NP_RESET:
18911
e48659f8d5c4 (svn r23760) -Feature: Allow readonly display of NewGRF parameters, if GRF list may not be edited.
frosch <frosch@openttd.org>
parents: 18908
diff changeset
413 if (!this->editable) break;
15920
74e5e0907a80 (svn r20604) -Feature: add a reset button to the newgrf parameters window
yexo <yexo@openttd.org>
parents: 15917
diff changeset
414 this->grf_config->SetParameterDefaults();
16086
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
415 this->InvalidateData();
18753
8d2cdabac894 (svn r23601) -Fix: fix the conflict in window number
truebrain <truebrain@openttd.org>
parents: 18742
diff changeset
416 SetWindowDirty(WC_GAME_OPTIONS, WN_GAME_OPTIONS_NEWGRF_STATE);
15920
74e5e0907a80 (svn r20604) -Feature: add a reset button to the newgrf parameters window
yexo <yexo@openttd.org>
parents: 15917
diff changeset
417 break;
74e5e0907a80 (svn r20604) -Feature: add a reset button to the newgrf parameters window
yexo <yexo@openttd.org>
parents: 15917
diff changeset
418
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
419 case WID_NP_ACCEPT:
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
420 delete this;
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
421 break;
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
422 }
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
423 }
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
424
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
425 virtual void OnQueryTextFinished(char *str)
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
426 {
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
427 if (StrEmpty(str)) return;
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
428 int32 value = atoi(str);
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
429 GRFParameterInfo *par_info = ((uint)this->clicked_row < this->grf_config->param_info.Length()) ? this->grf_config->param_info[this->clicked_row] : NULL;
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
430 if (par_info == NULL) par_info = GetDummyParameterInfo(this->clicked_row);
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
431 uint32 val = Clamp<uint32>(value, par_info->min_value, par_info->max_value);
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
432 par_info->SetValue(this->grf_config, val);
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
433 this->SetDirty();
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
434 }
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
435
19415
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
436 virtual void OnDropdownSelect(int widget, int index)
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
437 {
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
438 assert(this->clicked_dropdown);
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
439 GRFParameterInfo *par_info = ((uint)this->clicked_row < this->grf_config->param_info.Length()) ? this->grf_config->param_info[this->clicked_row] : NULL;
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
440 if (par_info == NULL) par_info = GetDummyParameterInfo(this->clicked_row);
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
441 par_info->SetValue(this->grf_config, index);
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
442 this->SetDirty();
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
443 }
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
444
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
445 virtual void OnDropdownClose(Point pt, int widget, int index, bool instant_close)
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
446 {
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
447 /* We cannot raise the dropdown button just yet. OnClick needs some hint, whether
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
448 * the same dropdown button was clicked again, and then not open the dropdown again.
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
449 * So, we only remember that it was closed, and process it on the next OnPaint, which is
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
450 * after OnClick. */
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
451 assert(this->clicked_dropdown);
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
452 this->closing_dropdown = true;
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
453 this->SetDirty();
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
454 }
899f24660723 (svn r24318) -Feature: Add dropdowns to NewGRF configurations, if all values have labels.
frosch <frosch@openttd.org>
parents: 19411
diff changeset
455
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
456 virtual void OnResize()
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
457 {
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
458 NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_NP_BACKGROUND);
15779
9ad2843db6f4 (svn r20453) -Codechange: Remove direct accesses to Window::hscroll, vscroll and vscroll2.
frosch <frosch@openttd.org>
parents: 15778
diff changeset
459 this->vscroll->SetCapacity(nwi->current_y / this->line_height);
9ad2843db6f4 (svn r20453) -Codechange: Remove direct accesses to Window::hscroll, vscroll and vscroll2.
frosch <frosch@openttd.org>
parents: 15778
diff changeset
460 nwi->widget_data = (this->vscroll->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
461 }
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
462
17486
e7672bafbe1c (svn r22241) -Codechange: Add additional to-be-used parameter to OnInvalidateData().
frosch <frosch@openttd.org>
parents: 17077
diff changeset
463 /**
e7672bafbe1c (svn r22241) -Codechange: Add additional to-be-used parameter to OnInvalidateData().
frosch <frosch@openttd.org>
parents: 17077
diff changeset
464 * Some data on this window has become invalid.
e7672bafbe1c (svn r22241) -Codechange: Add additional to-be-used parameter to OnInvalidateData().
frosch <frosch@openttd.org>
parents: 17077
diff changeset
465 * @param data Information about the changed data.
e7672bafbe1c (svn r22241) -Codechange: Add additional to-be-used parameter to OnInvalidateData().
frosch <frosch@openttd.org>
parents: 17077
diff changeset
466 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
e7672bafbe1c (svn r22241) -Codechange: Add additional to-be-used parameter to OnInvalidateData().
frosch <frosch@openttd.org>
parents: 17077
diff changeset
467 */
e7672bafbe1c (svn r22241) -Codechange: Add additional to-be-used parameter to OnInvalidateData().
frosch <frosch@openttd.org>
parents: 17077
diff changeset
468 virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
16086
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
469 {
17486
e7672bafbe1c (svn r22241) -Codechange: Add additional to-be-used parameter to OnInvalidateData().
frosch <frosch@openttd.org>
parents: 17077
diff changeset
470 if (!gui_scope) return;
16086
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
471 if (!this->action14present) {
18911
e48659f8d5c4 (svn r23760) -Feature: Allow readonly display of NewGRF parameters, if GRF list may not be edited.
frosch <frosch@openttd.org>
parents: 18908
diff changeset
472 this->SetWidgetDisabledState(WID_NP_NUMPAR_DEC, !this->editable || this->grf_config->num_params == 0);
e48659f8d5c4 (svn r23760) -Feature: Allow readonly display of NewGRF parameters, if GRF list may not be edited.
frosch <frosch@openttd.org>
parents: 18908
diff changeset
473 this->SetWidgetDisabledState(WID_NP_NUMPAR_INC, !this->editable || this->grf_config->num_params >= this->grf_config->num_valid_params);
16086
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
474 }
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
475
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
476 this->vscroll->SetCount(this->action14present ? this->grf_config->num_valid_params : this->grf_config->num_params);
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
477 if (this->clicked_row != UINT_MAX && this->clicked_row >= this->vscroll->GetCount()) {
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
478 this->clicked_row = UINT_MAX;
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
479 DeleteChildWindows(WC_QUERY_STRING);
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
480 }
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
481 }
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
482
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
483 virtual void OnTick()
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
484 {
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
485 if (--this->timeout == 0) {
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
486 this->clicked_button = UINT_MAX;
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
487 this->SetDirty();
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
488 }
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
489 }
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
490 };
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
491 GRFParameterInfo NewGRFParametersWindow::dummy_parameter_info(0);
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
492
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
493
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
494 static const NWidgetPart _nested_newgrf_parameter_widgets[] = {
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
495 NWidget(NWID_HORIZONTAL),
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
496 NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
497 NWidget(WWT_CAPTION, COLOUR_MAUVE), SetDataTip(STR_NEWGRF_PARAMETERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
498 EndContainer(),
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
499 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_NP_SHOW_NUMPAR),
16086
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
500 NWidget(WWT_PANEL, COLOUR_MAUVE), SetResize(1, 0), SetFill(1, 0), SetPIP(4, 0, 4),
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
501 NWidget(NWID_HORIZONTAL), SetPIP(4, 0, 4),
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
502 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_NP_NUMPAR_DEC), SetMinimalSize(12, 12), SetDataTip(AWV_DECREASE, STR_NULL),
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
503 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_NP_NUMPAR_INC), SetMinimalSize(12, 12), SetDataTip(AWV_INCREASE, STR_NULL),
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
504 NWidget(WWT_TEXT, COLOUR_MAUVE, WID_NP_NUMPAR), SetResize(1, 0), SetFill(1, 0), SetPadding(0, 0, 0, 4), SetDataTip(STR_NEWGRF_PARAMETERS_NUM_PARAM, STR_NULL),
16086
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
505 EndContainer(),
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
506 EndContainer(),
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
507 EndContainer(),
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
508 NWidget(NWID_HORIZONTAL),
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
509 NWidget(WWT_MATRIX, COLOUR_MAUVE, WID_NP_BACKGROUND), SetMinimalSize(188, 182), SetResize(1, 1), SetFill(1, 0), SetDataTip(0x501, STR_NULL), SetScrollbar(WID_NP_SCROLLBAR),
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
510 NWidget(NWID_VSCROLLBAR, COLOUR_MAUVE, WID_NP_SCROLLBAR),
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
511 EndContainer(),
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
512 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_NP_SHOW_DESCRIPTION),
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
513 NWidget(WWT_PANEL, COLOUR_MAUVE, WID_NP_DESCRIPTION), SetResize(1, 0), SetFill(1, 0),
16086
8963162a35da (svn r20779) -Add [FS#4025]: If GRFs do not have action14 parameter information, allow to set the number of parameters in the GUI explicitly.
frosch <frosch@openttd.org>
parents: 16006
diff changeset
514 EndContainer(),
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
515 EndContainer(),
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
516 NWidget(NWID_HORIZONTAL),
15920
74e5e0907a80 (svn r20604) -Feature: add a reset button to the newgrf parameters window
yexo <yexo@openttd.org>
parents: 15917
diff changeset
517 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
518 NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_NP_ACCEPT), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_NEWGRF_PARAMETERS_CLOSE, STR_NULL),
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
519 NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_NP_RESET), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_NEWGRF_PARAMETERS_RESET, STR_NEWGRF_PARAMETERS_RESET_TOOLTIP),
15920
74e5e0907a80 (svn r20604) -Feature: add a reset button to the newgrf parameters window
yexo <yexo@openttd.org>
parents: 15917
diff changeset
520 EndContainer(),
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
521 NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
522 EndContainer(),
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
523 };
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
524
18342
d52fe213742a (svn r23178) -Feature [FS#4780]: in-game readme.txt readmer (LordAro)
rubidium <rubidium@openttd.org>
parents: 18192
diff changeset
525 /** Window definition for the change grf parameters window */
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
526 static const WindowDesc _newgrf_parameters_desc(
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
527 WDP_CENTER, 500, 208,
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
528 WC_GRF_PARAMETERS, WC_NONE,
19767
2a11204038e3 (svn r24700) -Cleanup: Remove WDF_UNCLICK_BUTTONS and make it the default.
frosch <frosch@openttd.org>
parents: 19560
diff changeset
529 0,
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
530 _nested_newgrf_parameter_widgets, lengthof(_nested_newgrf_parameter_widgets)
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
531 );
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
532
18911
e48659f8d5c4 (svn r23760) -Feature: Allow readonly display of NewGRF parameters, if GRF list may not be edited.
frosch <frosch@openttd.org>
parents: 18908
diff changeset
533 static void OpenGRFParameterWindow(GRFConfig *c, bool editable)
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
534 {
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
535 DeleteWindowByClass(WC_GRF_PARAMETERS);
18911
e48659f8d5c4 (svn r23760) -Feature: Allow readonly display of NewGRF parameters, if GRF list may not be edited.
frosch <frosch@openttd.org>
parents: 18908
diff changeset
536 new NewGRFParametersWindow(&_newgrf_parameters_desc, c, editable);
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
537 }
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
538
18412
ed6973313b87 (svn r23248) -Codechange: Rename everything related to the NewGRF 'readme' to 'textfile', so it is more generic.
frosch <frosch@openttd.org>
parents: 18386
diff changeset
539 /** Window for displaying the textfile of a NewGRF. */
19078
8cb1275f2bb3 (svn r23932) -Codechange: split the NewGRF text window into its own source files
rubidium <rubidium@openttd.org>
parents: 18957
diff changeset
540 struct NewGRFTextfileWindow : public TextfileWindow {
8cb1275f2bb3 (svn r23932) -Codechange: split the NewGRF text window into its own source files
rubidium <rubidium@openttd.org>
parents: 18957
diff changeset
541 const GRFConfig *grf_config; ///< View the textfile of this GRFConfig.
18342
d52fe213742a (svn r23178) -Feature [FS#4780]: in-game readme.txt readmer (LordAro)
rubidium <rubidium@openttd.org>
parents: 18192
diff changeset
542
19078
8cb1275f2bb3 (svn r23932) -Codechange: split the NewGRF text window into its own source files
rubidium <rubidium@openttd.org>
parents: 18957
diff changeset
543 NewGRFTextfileWindow(TextfileType file_type, const GRFConfig *c) : TextfileWindow(file_type), grf_config(c)
18342
d52fe213742a (svn r23178) -Feature [FS#4780]: in-game readme.txt readmer (LordAro)
rubidium <rubidium@openttd.org>
parents: 18192
diff changeset
544 {
19078
8cb1275f2bb3 (svn r23932) -Codechange: split the NewGRF text window into its own source files
rubidium <rubidium@openttd.org>
parents: 18957
diff changeset
545 const char *textfile = this->grf_config->GetTextfile(file_type);
8cb1275f2bb3 (svn r23932) -Codechange: split the NewGRF text window into its own source files
rubidium <rubidium@openttd.org>
parents: 18957
diff changeset
546 this->LoadTextfile(textfile, NEWGRF_DIR);
18342
d52fe213742a (svn r23178) -Feature [FS#4780]: in-game readme.txt readmer (LordAro)
rubidium <rubidium@openttd.org>
parents: 18192
diff changeset
547 }
d52fe213742a (svn r23178) -Feature [FS#4780]: in-game readme.txt readmer (LordAro)
rubidium <rubidium@openttd.org>
parents: 18192
diff changeset
548
19078
8cb1275f2bb3 (svn r23932) -Codechange: split the NewGRF text window into its own source files
rubidium <rubidium@openttd.org>
parents: 18957
diff changeset
549 /* virtual */ void SetStringParameters(int widget) const
18342
d52fe213742a (svn r23178) -Feature [FS#4780]: in-game readme.txt readmer (LordAro)
rubidium <rubidium@openttd.org>
parents: 18192
diff changeset
550 {
19079
0af594336a81 (svn r23933) -Codechange: make the text file window strings more generic (LordAro)
rubidium <rubidium@openttd.org>
parents: 19078
diff changeset
551 if (widget == WID_TF_CAPTION) {
0af594336a81 (svn r23933) -Codechange: make the text file window strings more generic (LordAro)
rubidium <rubidium@openttd.org>
parents: 19078
diff changeset
552 SetDParam(0, STR_CONTENT_TYPE_NEWGRF);
0af594336a81 (svn r23933) -Codechange: make the text file window strings more generic (LordAro)
rubidium <rubidium@openttd.org>
parents: 19078
diff changeset
553 SetDParamStr(1, this->grf_config->GetName());
0af594336a81 (svn r23933) -Codechange: make the text file window strings more generic (LordAro)
rubidium <rubidium@openttd.org>
parents: 19078
diff changeset
554 }
18342
d52fe213742a (svn r23178) -Feature [FS#4780]: in-game readme.txt readmer (LordAro)
rubidium <rubidium@openttd.org>
parents: 18192
diff changeset
555 }
d52fe213742a (svn r23178) -Feature [FS#4780]: in-game readme.txt readmer (LordAro)
rubidium <rubidium@openttd.org>
parents: 18192
diff changeset
556 };
d52fe213742a (svn r23178) -Feature [FS#4780]: in-game readme.txt readmer (LordAro)
rubidium <rubidium@openttd.org>
parents: 18192
diff changeset
557
19078
8cb1275f2bb3 (svn r23932) -Codechange: split the NewGRF text window into its own source files
rubidium <rubidium@openttd.org>
parents: 18957
diff changeset
558 void ShowNewGRFTextfileWindow(TextfileType file_type, const GRFConfig *c)
18342
d52fe213742a (svn r23178) -Feature [FS#4780]: in-game readme.txt readmer (LordAro)
rubidium <rubidium@openttd.org>
parents: 18192
diff changeset
559 {
19078
8cb1275f2bb3 (svn r23932) -Codechange: split the NewGRF text window into its own source files
rubidium <rubidium@openttd.org>
parents: 18957
diff changeset
560 DeleteWindowByClass(WC_TEXTFILE);
8cb1275f2bb3 (svn r23932) -Codechange: split the NewGRF text window into its own source files
rubidium <rubidium@openttd.org>
parents: 18957
diff changeset
561 new NewGRFTextfileWindow(file_type, c);
18342
d52fe213742a (svn r23178) -Feature [FS#4780]: in-game readme.txt readmer (LordAro)
rubidium <rubidium@openttd.org>
parents: 18192
diff changeset
562 }
d52fe213742a (svn r23178) -Feature [FS#4780]: in-game readme.txt readmer (LordAro)
rubidium <rubidium@openttd.org>
parents: 18192
diff changeset
563
9677
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
564 static GRFPresetList _grf_preset_list;
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
565
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
566 class DropDownListPresetItem : public DropDownListItem {
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
567 public:
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
568 DropDownListPresetItem(int result) : DropDownListItem(result, false) {}
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
569
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
570 virtual ~DropDownListPresetItem() {}
9864
199cb67d074d (svn r14009) -Cleanup (r14008): Bad whitespace...
peter1138 <peter1138@openttd.org>
parents: 9863
diff changeset
571
9863
3db7ce31355e (svn r14008) -Fix (r14004): NewGRF preset drop down list not working
peter1138 <peter1138@openttd.org>
parents: 9760
diff changeset
572 bool Selectable() const
9677
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
573 {
9863
3db7ce31355e (svn r14008) -Fix (r14004): NewGRF preset drop down list not working
peter1138 <peter1138@openttd.org>
parents: 9760
diff changeset
574 return true;
9677
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
575 }
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
576
11425
532a1c74074d (svn r15783) -Codechange: make the dropdown draw code pass around the left/right instead of the x and width to make drawing text at offsets easier.
rubidium <rubidium@openttd.org>
parents: 11373
diff changeset
577 void Draw(int left, int right, int top, int bottom, bool sel, int bg_colour) const
9677
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
578 {
11425
532a1c74074d (svn r15783) -Codechange: make the dropdown draw code pass around the left/right instead of the x and width to make drawing text at offsets easier.
rubidium <rubidium@openttd.org>
parents: 11373
diff changeset
579 DrawString(left + 2, right + 2, top, _grf_preset_list[this->result], sel ? TC_WHITE : TC_BLACK);
9677
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
580 }
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
581 };
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
582
9207
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
583 static void NewGRFConfirmationCallback(Window *w, bool confirmed);
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
584
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
585 /**
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
586 * Window for showing NewGRF files
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
587 */
17982
ad0c8dce1699 (svn r22791) -Codechange: use callback for scanning from the NewGRF window
rubidium <rubidium@openttd.org>
parents: 17962
diff changeset
588 struct NewGRFWindow : public QueryStringBaseWindow, NewGRFScanCallback {
19434
24df8a97401e (svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents: 19421
diff changeset
589 typedef GUIList<const GRFConfig *, StringFilter &> GUIGRFConfigList;
15208
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
590
15209
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
591 static const uint EDITBOX_MAX_SIZE = 50;
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
592
15208
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
593 static Listing last_sorting; ///< Default sorting of #GUIGRFConfigList.
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
594 static Filtering last_filtering; ///< Default filtering of #GUIGRFConfigList.
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
595 static GUIGRFConfigList::SortFunction * const sorter_funcs[]; ///< Sort functions of the #GUIGRFConfigList.
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
596 static GUIGRFConfigList::FilterFunction * const filter_funcs[]; ///< Filter functions of the #GUIGRFConfigList.
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
597
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
598 GUIGRFConfigList avails; ///< Available (non-active) grfs.
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
599 const GRFConfig *avail_sel; ///< Currently selected available grf. \c NULL is none is selected.
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
600 int avail_pos; ///< Index of #avail_sel if existing, else \c -1.
19434
24df8a97401e (svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents: 19421
diff changeset
601 StringFilter string_filter; ///< Filter for available grf.
15208
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
602
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
603 GRFConfig *actives; ///< Temporary active grf list to which changes are made.
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
604 GRFConfig *active_sel; ///< Selected active grf item.
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
605
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
606 GRFConfig **orig_list; ///< List active grfs in the game. Used as initial value, may be updated by the window.
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
607 bool editable; ///< Is the window editable?
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
608 bool show_params; ///< Are the grf-parameters shown in the info-panel?
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
609 bool execute; ///< On pressing 'apply changes' are grf changes applied immediately, or only list is updated.
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
610 int preset; ///< Selected preset.
19237
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
611 int active_over; ///< Active GRF item over which another one is dragged, \c -1 if none.
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
612
15779
9ad2843db6f4 (svn r20453) -Codechange: Remove direct accesses to Window::hscroll, vscroll and vscroll2.
frosch <frosch@openttd.org>
parents: 15778
diff changeset
613 Scrollbar *vscroll;
9ad2843db6f4 (svn r20453) -Codechange: Remove direct accesses to Window::hscroll, vscroll and vscroll2.
frosch <frosch@openttd.org>
parents: 15778
diff changeset
614 Scrollbar *vscroll2;
9ad2843db6f4 (svn r20453) -Codechange: Remove direct accesses to Window::hscroll, vscroll and vscroll2.
frosch <frosch@openttd.org>
parents: 15778
diff changeset
615
15209
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
616 NewGRFWindow(const WindowDesc *desc, bool editable, bool show_params, bool execute, GRFConfig **orig_list) : QueryStringBaseWindow(EDITBOX_MAX_SIZE)
9207
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
617 {
15208
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
618 this->avail_sel = NULL;
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
619 this->avail_pos = -1;
15203
2ef926c44a98 (svn r19832) -Codechange: Rename variables list->actives, sel->active_sel.
alberth <alberth@openttd.org>
parents: 15202
diff changeset
620 this->active_sel = NULL;
2ef926c44a98 (svn r19832) -Codechange: Rename variables list->actives, sel->active_sel.
alberth <alberth@openttd.org>
parents: 15202
diff changeset
621 this->actives = NULL;
15202
e9db5d2f634e (svn r19831) -Codechange: Rename formal parameters of the constructor to match data member variable names.
alberth <alberth@openttd.org>
parents: 15201
diff changeset
622 this->orig_list = orig_list;
9207
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
623 this->editable = editable;
15202
e9db5d2f634e (svn r19831) -Codechange: Rename formal parameters of the constructor to match data member variable names.
alberth <alberth@openttd.org>
parents: 15201
diff changeset
624 this->execute = execute;
9207
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
625 this->show_params = show_params;
9677
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
626 this->preset = -1;
19237
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
627 this->active_over = -1;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
628
15203
2ef926c44a98 (svn r19832) -Codechange: Rename variables list->actives, sel->active_sel.
alberth <alberth@openttd.org>
parents: 15202
diff changeset
629 CopyGRFConfigList(&this->actives, *orig_list, false);
9677
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
630 GetGRFPresetList(&_grf_preset_list);
9207
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
631
15779
9ad2843db6f4 (svn r20453) -Codechange: Remove direct accesses to Window::hscroll, vscroll and vscroll2.
frosch <frosch@openttd.org>
parents: 15778
diff changeset
632 this->CreateNestedTree(desc);
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
633 this->vscroll = this->GetScrollbar(WID_NS_SCROLLBAR);
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
634 this->vscroll2 = this->GetScrollbar(WID_NS_SCROLL2BAR);
16394
82aa3e68581d (svn r21110) -Add: Tidy up the buttons of the active newgrfs list.
alberth <alberth@openttd.org>
parents: 16393
diff changeset
635
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
636 this->GetWidget<NWidgetStacked>(WID_NS_SHOW_REMOVE)->SetDisplayedPlane(this->editable ? 0 : 1);
18911
e48659f8d5c4 (svn r23760) -Feature: Allow readonly display of NewGRF parameters, if GRF list may not be edited.
frosch <frosch@openttd.org>
parents: 18908
diff changeset
637 this->GetWidget<NWidgetStacked>(WID_NS_SHOW_APPLY)->SetDisplayedPlane(this->editable ? 0 : this->show_params ? 1 : SZSP_HORIZONTAL);
18753
8d2cdabac894 (svn r23601) -Fix: fix the conflict in window number
truebrain <truebrain@openttd.org>
parents: 18742
diff changeset
638 this->FinishInitNested(desc, WN_GAME_OPTIONS_NEWGRF_STATE);
15779
9ad2843db6f4 (svn r20453) -Codechange: Remove direct accesses to Window::hscroll, vscroll and vscroll2.
frosch <frosch@openttd.org>
parents: 15778
diff changeset
639
19421
904203312f04 (svn r24324) -Codechange: Turn functions dealing with Textbufs into member functions.
frosch <frosch@openttd.org>
parents: 19415
diff changeset
640 this->text.Initialize(this->edit_str_buf, this->edit_str_size);
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
641 this->SetFocusedWidget(WID_NS_FILTER);
15209
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
642
15208
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
643 this->avails.SetListing(this->last_sorting);
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
644 this->avails.SetFiltering(this->last_filtering);
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
645 this->avails.SetSortFuncs(this->sorter_funcs);
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
646 this->avails.SetFilterFuncs(this->filter_funcs);
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
647 this->avails.ForceRebuild();
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
648
17826
03d75c842b87 (svn r22617) -Codechange: Add GameOptionsInvalidationData enum for data values for Window::OnInvalidateData() of windows with class WC_GAME_OPTIONS.
frosch <frosch@openttd.org>
parents: 17809
diff changeset
649 this->OnInvalidateData(GOID_NEWGRF_LIST_EDITED);
9207
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
650 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
651
9207
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
652 ~NewGRFWindow()
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
653 {
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
654 DeleteWindowByClass(WC_GRF_PARAMETERS);
19078
8cb1275f2bb3 (svn r23932) -Codechange: split the NewGRF text window into its own source files
rubidium <rubidium@openttd.org>
parents: 18957
diff changeset
655 DeleteWindowByClass(WC_TEXTFILE);
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
656
10910
9276e5a96995 (svn r15245) -Fix: don't "save" the NewGRF settings on closing the NewGRF window when the content of the window isn't editable
rubidium <rubidium@openttd.org>
parents: 10890
diff changeset
657 if (this->editable && !this->execute) {
15203
2ef926c44a98 (svn r19832) -Codechange: Rename variables list->actives, sel->active_sel.
alberth <alberth@openttd.org>
parents: 15202
diff changeset
658 CopyGRFConfigList(this->orig_list, this->actives, true);
9207
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
659 ResetGRFConfig(false);
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
660 ReloadNewGRFData();
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
661 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
662
9207
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
663 /* Remove the temporary copy of grf-list used in window */
15203
2ef926c44a98 (svn r19832) -Codechange: Rename variables list->actives, sel->active_sel.
alberth <alberth@openttd.org>
parents: 15202
diff changeset
664 ClearGRFConfigList(&this->actives);
9677
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
665 _grf_preset_list.Clear();
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
666 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
667
13705
8dee47e001b2 (svn r18230) -Codechange: Allow fill stepsize to be set from Window::UpdateWidgetSize().
alberth <alberth@openttd.org>
parents: 13704
diff changeset
668 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
13171
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
669 {
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
670 switch (widget) {
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
671 case WID_NS_FILE_LIST:
18192
a28c8d15ff75 (svn r23021) -Codechange: Support resized square and warning icons in NewGRF selection window.
peter1138 <peter1138@openttd.org>
parents: 18173
diff changeset
672 {
a28c8d15ff75 (svn r23021) -Codechange: Support resized square and warning icons in NewGRF selection window.
peter1138 <peter1138@openttd.org>
parents: 18173
diff changeset
673 Dimension d = maxdim(GetSpriteSize(SPR_SQUARE), GetSpriteSize(SPR_WARNING_SIGN));
a28c8d15ff75 (svn r23021) -Codechange: Support resized square and warning icons in NewGRF selection window.
peter1138 <peter1138@openttd.org>
parents: 18173
diff changeset
674 resize->height = max(d.height + 2U, FONT_HEIGHT_NORMAL + 2U);
15208
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
675 size->height = max(size->height, WD_FRAMERECT_TOP + 6 * resize->height + WD_FRAMERECT_BOTTOM);
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
676 break;
18192
a28c8d15ff75 (svn r23021) -Codechange: Support resized square and warning icons in NewGRF selection window.
peter1138 <peter1138@openttd.org>
parents: 18173
diff changeset
677 }
15208
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
678
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
679 case WID_NS_AVAIL_LIST:
15208
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
680 resize->height = max(12, FONT_HEIGHT_NORMAL + 2);
15205
0dca88008a3a (svn r19834) -Change: Replace matrix list widget in NewGRF gui by a panel with black background.
alberth <alberth@openttd.org>
parents: 15204
diff changeset
681 size->height = max(size->height, WD_FRAMERECT_TOP + 8 * resize->height + WD_FRAMERECT_BOTTOM);
13171
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
682 break;
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
683
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
684 case WID_NS_NEWGRF_INFO_TITLE: {
15204
f29231ce72e1 (svn r19833) -Change: Modify NewGRF window towards having combined lists, add captions.
alberth <alberth@openttd.org>
parents: 15203
diff changeset
685 Dimension dim = GetStringBoundingBox(STR_NEWGRF_SETTINGS_INFO_TITLE);
f29231ce72e1 (svn r19833) -Change: Modify NewGRF window towards having combined lists, add captions.
alberth <alberth@openttd.org>
parents: 15203
diff changeset
686 size->height = max(size->height, dim.height + WD_FRAMETEXT_TOP + WD_FRAMETEXT_BOTTOM);
f29231ce72e1 (svn r19833) -Change: Modify NewGRF window towards having combined lists, add captions.
alberth <alberth@openttd.org>
parents: 15203
diff changeset
687 size->width = max(size->width, dim.width + WD_FRAMETEXT_LEFT + WD_FRAMETEXT_RIGHT);
f29231ce72e1 (svn r19833) -Change: Modify NewGRF window towards having combined lists, add captions.
alberth <alberth@openttd.org>
parents: 15203
diff changeset
688 break;
f29231ce72e1 (svn r19833) -Change: Modify NewGRF window towards having combined lists, add captions.
alberth <alberth@openttd.org>
parents: 15203
diff changeset
689 }
f29231ce72e1 (svn r19833) -Change: Modify NewGRF window towards having combined lists, add captions.
alberth <alberth@openttd.org>
parents: 15203
diff changeset
690
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
691 case WID_NS_NEWGRF_INFO:
13171
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
692 size->height = max(size->height, WD_FRAMERECT_TOP + 10 * FONT_HEIGHT_NORMAL + WD_FRAMERECT_BOTTOM + padding.height + 2);
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
693 break;
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
694
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
695 case WID_NS_PRESET_LIST: {
13171
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
696 Dimension d = GetStringBoundingBox(STR_NUM_CUSTOM);
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
697 for (uint i = 0; i < _grf_preset_list.Length(); i++) {
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
698 if (_grf_preset_list[i] != NULL) {
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
699 SetDParamStr(0, _grf_preset_list[i]);
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
700 d = maxdim(d, GetStringBoundingBox(STR_JUST_RAW_STRING));
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
701 }
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
702 }
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
703 d.width += padding.width;
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
704 *size = maxdim(d, *size);
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
705 break;
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
706 }
15194
2d9d9be17bbe (svn r19823) -Fix: Ensure that both texts of the newgrf gui download button fit.
alberth <alberth@openttd.org>
parents: 15185
diff changeset
707
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
708 case WID_NS_CONTENT_DOWNLOAD:
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
709 case WID_NS_CONTENT_DOWNLOAD2: {
15194
2d9d9be17bbe (svn r19823) -Fix: Ensure that both texts of the newgrf gui download button fit.
alberth <alberth@openttd.org>
parents: 15185
diff changeset
710 Dimension d = GetStringBoundingBox(STR_NEWGRF_SETTINGS_FIND_MISSING_CONTENT_BUTTON);
2d9d9be17bbe (svn r19823) -Fix: Ensure that both texts of the newgrf gui download button fit.
alberth <alberth@openttd.org>
parents: 15185
diff changeset
711 *size = maxdim(d, GetStringBoundingBox(STR_INTRO_ONLINE_CONTENT));
2d9d9be17bbe (svn r19823) -Fix: Ensure that both texts of the newgrf gui download button fit.
alberth <alberth@openttd.org>
parents: 15185
diff changeset
712 size->width += padding.width;
2d9d9be17bbe (svn r19823) -Fix: Ensure that both texts of the newgrf gui download button fit.
alberth <alberth@openttd.org>
parents: 15185
diff changeset
713 size->height += padding.height;
2d9d9be17bbe (svn r19823) -Fix: Ensure that both texts of the newgrf gui download button fit.
alberth <alberth@openttd.org>
parents: 15185
diff changeset
714 break;
2d9d9be17bbe (svn r19823) -Fix: Ensure that both texts of the newgrf gui download button fit.
alberth <alberth@openttd.org>
parents: 15185
diff changeset
715 }
13171
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
716 }
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
717 }
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
718
13344
04b02b2cfa2b (svn r17853) -Codechange: remove the 'delta' parameter from OnResize; it was used in ways that aren't always wanted, causing bugs and the like. Also with nested widgets most reasons for handling OnResize have gone.
rubidium <rubidium@openttd.org>
parents: 13277
diff changeset
719 virtual void OnResize()
13171
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
720 {
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
721 this->vscroll->SetCapacityFromWidget(this, WID_NS_FILE_LIST);
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
722 this->vscroll2->SetCapacityFromWidget(this, WID_NS_AVAIL_LIST);
13171
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
723 }
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
724
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
725 virtual void SetStringParameters(int widget) const
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
726 {
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
727 switch (widget) {
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
728 case WID_NS_PRESET_LIST:
13171
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
729 if (this->preset == -1) {
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
730 SetDParam(0, STR_NUM_CUSTOM);
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
731 } else {
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
732 SetDParam(0, STR_JUST_RAW_STRING);
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
733 SetDParamStr(1, _grf_preset_list[this->preset]);
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
734 }
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
735 break;
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
736 }
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
737 }
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
738
15620
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
739 /**
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
740 * Pick the palette for the sprite of the grf to display.
15207
e31a7ac11eb1 (svn r19836) -Codechange: Move sprite palette selection code in NewGRF gui to its own method.
alberth <alberth@openttd.org>
parents: 15205
diff changeset
741 * @param c grf to display.
e31a7ac11eb1 (svn r19836) -Codechange: Move sprite palette selection code in NewGRF gui to its own method.
alberth <alberth@openttd.org>
parents: 15205
diff changeset
742 * @return Palette for the sprite.
e31a7ac11eb1 (svn r19836) -Codechange: Move sprite palette selection code in NewGRF gui to its own method.
alberth <alberth@openttd.org>
parents: 15205
diff changeset
743 */
18792
c99e695378ce (svn r23640) -Fix: stop using FORCEINLINE (1/3rd of the instances were, the others were still regular inline), but make sure inline is always a 'forced' inline (I am looking at you MSVC)
truebrain <truebrain@openttd.org>
parents: 18753
diff changeset
744 inline PaletteID GetPalette(const GRFConfig *c) const
15207
e31a7ac11eb1 (svn r19836) -Codechange: Move sprite palette selection code in NewGRF gui to its own method.
alberth <alberth@openttd.org>
parents: 15205
diff changeset
745 {
e31a7ac11eb1 (svn r19836) -Codechange: Move sprite palette selection code in NewGRF gui to its own method.
alberth <alberth@openttd.org>
parents: 15205
diff changeset
746 PaletteID pal;
e31a7ac11eb1 (svn r19836) -Codechange: Move sprite palette selection code in NewGRF gui to its own method.
alberth <alberth@openttd.org>
parents: 15205
diff changeset
747
e31a7ac11eb1 (svn r19836) -Codechange: Move sprite palette selection code in NewGRF gui to its own method.
alberth <alberth@openttd.org>
parents: 15205
diff changeset
748 /* Pick a colour */
e31a7ac11eb1 (svn r19836) -Codechange: Move sprite palette selection code in NewGRF gui to its own method.
alberth <alberth@openttd.org>
parents: 15205
diff changeset
749 switch (c->status) {
e31a7ac11eb1 (svn r19836) -Codechange: Move sprite palette selection code in NewGRF gui to its own method.
alberth <alberth@openttd.org>
parents: 15205
diff changeset
750 case GCS_NOT_FOUND:
e31a7ac11eb1 (svn r19836) -Codechange: Move sprite palette selection code in NewGRF gui to its own method.
alberth <alberth@openttd.org>
parents: 15205
diff changeset
751 case GCS_DISABLED:
e31a7ac11eb1 (svn r19836) -Codechange: Move sprite palette selection code in NewGRF gui to its own method.
alberth <alberth@openttd.org>
parents: 15205
diff changeset
752 pal = PALETTE_TO_RED;
e31a7ac11eb1 (svn r19836) -Codechange: Move sprite palette selection code in NewGRF gui to its own method.
alberth <alberth@openttd.org>
parents: 15205
diff changeset
753 break;
e31a7ac11eb1 (svn r19836) -Codechange: Move sprite palette selection code in NewGRF gui to its own method.
alberth <alberth@openttd.org>
parents: 15205
diff changeset
754 case GCS_ACTIVATED:
e31a7ac11eb1 (svn r19836) -Codechange: Move sprite palette selection code in NewGRF gui to its own method.
alberth <alberth@openttd.org>
parents: 15205
diff changeset
755 pal = PALETTE_TO_GREEN;
e31a7ac11eb1 (svn r19836) -Codechange: Move sprite palette selection code in NewGRF gui to its own method.
alberth <alberth@openttd.org>
parents: 15205
diff changeset
756 break;
e31a7ac11eb1 (svn r19836) -Codechange: Move sprite palette selection code in NewGRF gui to its own method.
alberth <alberth@openttd.org>
parents: 15205
diff changeset
757 default:
e31a7ac11eb1 (svn r19836) -Codechange: Move sprite palette selection code in NewGRF gui to its own method.
alberth <alberth@openttd.org>
parents: 15205
diff changeset
758 pal = PALETTE_TO_BLUE;
e31a7ac11eb1 (svn r19836) -Codechange: Move sprite palette selection code in NewGRF gui to its own method.
alberth <alberth@openttd.org>
parents: 15205
diff changeset
759 break;
e31a7ac11eb1 (svn r19836) -Codechange: Move sprite palette selection code in NewGRF gui to its own method.
alberth <alberth@openttd.org>
parents: 15205
diff changeset
760 }
e31a7ac11eb1 (svn r19836) -Codechange: Move sprite palette selection code in NewGRF gui to its own method.
alberth <alberth@openttd.org>
parents: 15205
diff changeset
761
e31a7ac11eb1 (svn r19836) -Codechange: Move sprite palette selection code in NewGRF gui to its own method.
alberth <alberth@openttd.org>
parents: 15205
diff changeset
762 /* Do not show a "not-failure" colour when it actually failed to load */
e31a7ac11eb1 (svn r19836) -Codechange: Move sprite palette selection code in NewGRF gui to its own method.
alberth <alberth@openttd.org>
parents: 15205
diff changeset
763 if (pal != PALETTE_TO_RED) {
e31a7ac11eb1 (svn r19836) -Codechange: Move sprite palette selection code in NewGRF gui to its own method.
alberth <alberth@openttd.org>
parents: 15205
diff changeset
764 if (HasBit(c->flags, GCF_STATIC)) {
e31a7ac11eb1 (svn r19836) -Codechange: Move sprite palette selection code in NewGRF gui to its own method.
alberth <alberth@openttd.org>
parents: 15205
diff changeset
765 pal = PALETTE_TO_GREY;
e31a7ac11eb1 (svn r19836) -Codechange: Move sprite palette selection code in NewGRF gui to its own method.
alberth <alberth@openttd.org>
parents: 15205
diff changeset
766 } else if (HasBit(c->flags, GCF_COMPATIBLE)) {
e31a7ac11eb1 (svn r19836) -Codechange: Move sprite palette selection code in NewGRF gui to its own method.
alberth <alberth@openttd.org>
parents: 15205
diff changeset
767 pal = PALETTE_TO_ORANGE;
e31a7ac11eb1 (svn r19836) -Codechange: Move sprite palette selection code in NewGRF gui to its own method.
alberth <alberth@openttd.org>
parents: 15205
diff changeset
768 }
e31a7ac11eb1 (svn r19836) -Codechange: Move sprite palette selection code in NewGRF gui to its own method.
alberth <alberth@openttd.org>
parents: 15205
diff changeset
769 }
e31a7ac11eb1 (svn r19836) -Codechange: Move sprite palette selection code in NewGRF gui to its own method.
alberth <alberth@openttd.org>
parents: 15205
diff changeset
770
e31a7ac11eb1 (svn r19836) -Codechange: Move sprite palette selection code in NewGRF gui to its own method.
alberth <alberth@openttd.org>
parents: 15205
diff changeset
771 return pal;
e31a7ac11eb1 (svn r19836) -Codechange: Move sprite palette selection code in NewGRF gui to its own method.
alberth <alberth@openttd.org>
parents: 15205
diff changeset
772 }
e31a7ac11eb1 (svn r19836) -Codechange: Move sprite palette selection code in NewGRF gui to its own method.
alberth <alberth@openttd.org>
parents: 15205
diff changeset
773
13171
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
774 virtual void DrawWidget(const Rect &r, int widget) const
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
775 {
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
776 switch (widget) {
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
777 case WID_NS_FILE_LIST: {
17657
c2a2cda37d1b (svn r22429) -Add: some constants for specific palette colours used in the GUI.
frosch <frosch@openttd.org>
parents: 17649
diff changeset
778 GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, PC_BLACK);
15205
0dca88008a3a (svn r19834) -Change: Replace matrix list widget in NewGRF gui by a panel with black background.
alberth <alberth@openttd.org>
parents: 15204
diff changeset
779
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
780 uint step_height = this->GetWidget<NWidgetBase>(WID_NS_FILE_LIST)->resize_y;
15205
0dca88008a3a (svn r19834) -Change: Replace matrix list widget in NewGRF gui by a panel with black background.
alberth <alberth@openttd.org>
parents: 15204
diff changeset
781 uint y = r.top + WD_FRAMERECT_TOP;
18192
a28c8d15ff75 (svn r23021) -Codechange: Support resized square and warning icons in NewGRF selection window.
peter1138 <peter1138@openttd.org>
parents: 18173
diff changeset
782 Dimension square = GetSpriteSize(SPR_SQUARE);
a28c8d15ff75 (svn r23021) -Codechange: Support resized square and warning icons in NewGRF selection window.
peter1138 <peter1138@openttd.org>
parents: 18173
diff changeset
783 Dimension warning = GetSpriteSize(SPR_WARNING_SIGN);
a28c8d15ff75 (svn r23021) -Codechange: Support resized square and warning icons in NewGRF selection window.
peter1138 <peter1138@openttd.org>
parents: 18173
diff changeset
784 int square_offset_y = (step_height - square.height) / 2;
a28c8d15ff75 (svn r23021) -Codechange: Support resized square and warning icons in NewGRF selection window.
peter1138 <peter1138@openttd.org>
parents: 18173
diff changeset
785 int warning_offset_y = (step_height - warning.height) / 2;
15220
ef4601cbbb98 (svn r19849) -Fix: Center sprite and text seperately in the newgrf gui active list.
alberth <alberth@openttd.org>
parents: 15219
diff changeset
786 int offset_y = (step_height - FONT_HEIGHT_NORMAL) / 2;
13171
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
787
16441
86fd9bcc9d2f (svn r21157) -Codechange: remove information about the text direction out of the language "list"
rubidium <rubidium@openttd.org>
parents: 16395
diff changeset
788 bool rtl = _current_text_dir == TD_RTL;
18192
a28c8d15ff75 (svn r23021) -Codechange: Support resized square and warning icons in NewGRF selection window.
peter1138 <peter1138@openttd.org>
parents: 18173
diff changeset
789 uint text_left = rtl ? r.left + WD_FRAMERECT_LEFT : r.left + square.width + 15;
a28c8d15ff75 (svn r23021) -Codechange: Support resized square and warning icons in NewGRF selection window.
peter1138 <peter1138@openttd.org>
parents: 18173
diff changeset
790 uint text_right = rtl ? r.right - square.width - 15 : r.right - WD_FRAMERECT_RIGHT;
a28c8d15ff75 (svn r23021) -Codechange: Support resized square and warning icons in NewGRF selection window.
peter1138 <peter1138@openttd.org>
parents: 18173
diff changeset
791 uint square_left = rtl ? r.right - square.width - 5 : r.left + 5;
a28c8d15ff75 (svn r23021) -Codechange: Support resized square and warning icons in NewGRF selection window.
peter1138 <peter1138@openttd.org>
parents: 18173
diff changeset
792 uint warning_left = rtl ? r.right - square.width - warning.width - 10 : r.left + square.width + 10;
13659
2c473236b6fd (svn r18183) -Codechange: make the NewGRF window RTL aware
rubidium <rubidium@openttd.org>
parents: 13654
diff changeset
793
13171
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
794 int i = 0;
15203
2ef926c44a98 (svn r19832) -Codechange: Rename variables list->actives, sel->active_sel.
alberth <alberth@openttd.org>
parents: 15202
diff changeset
795 for (const GRFConfig *c = this->actives; c != NULL; c = c->next, i++) {
15779
9ad2843db6f4 (svn r20453) -Codechange: Remove direct accesses to Window::hscroll, vscroll and vscroll2.
frosch <frosch@openttd.org>
parents: 15778
diff changeset
796 if (this->vscroll->IsVisible(i)) {
14711
74b0a8a64ff5 (svn r19295) -Codechange: introduce wrapper functions for GRFConfig::name/info
yexo <yexo@openttd.org>
parents: 14676
diff changeset
797 const char *text = c->GetName();
15205
0dca88008a3a (svn r19834) -Change: Replace matrix list widget in NewGRF gui by a panel with black background.
alberth <alberth@openttd.org>
parents: 15204
diff changeset
798 bool h = (this->active_sel == c);
15207
e31a7ac11eb1 (svn r19836) -Codechange: Move sprite palette selection code in NewGRF gui to its own method.
alberth <alberth@openttd.org>
parents: 15205
diff changeset
799 PaletteID pal = this->GetPalette(c);
13171
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
800
19237
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
801 if (h) {
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
802 GfxFillRect(r.left + 1, y, r.right - 1, y + step_height - 1, PC_DARK_BLUE);
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
803 } else if (i == this->active_over) {
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
804 /* Get index of current selection. */
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
805 int active_sel_pos = 0;
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
806 for (GRFConfig *c = this->actives; c != NULL && c != this->active_sel; c = c->next, active_sel_pos++) {}
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
807 if (active_sel_pos != this->active_over) {
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
808 uint top = this->active_over < active_sel_pos ? y + 1 : y + step_height - 2;
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
809 GfxFillRect(r.left + WD_FRAMERECT_LEFT, top - 1, r.right - WD_FRAMERECT_RIGHT, top + 1, PC_GREY);
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
810 }
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
811 }
18192
a28c8d15ff75 (svn r23021) -Codechange: Support resized square and warning icons in NewGRF selection window.
peter1138 <peter1138@openttd.org>
parents: 18173
diff changeset
812 DrawSprite(SPR_SQUARE, pal, square_left, y + square_offset_y);
a28c8d15ff75 (svn r23021) -Codechange: Support resized square and warning icons in NewGRF selection window.
peter1138 <peter1138@openttd.org>
parents: 18173
diff changeset
813 if (c->error != NULL) DrawSprite(SPR_WARNING_SIGN, 0, warning_left, y + warning_offset_y);
a28c8d15ff75 (svn r23021) -Codechange: Support resized square and warning icons in NewGRF selection window.
peter1138 <peter1138@openttd.org>
parents: 18173
diff changeset
814 uint txtoffset = c->error == NULL ? 0 : warning.width;
15220
ef4601cbbb98 (svn r19849) -Fix: Center sprite and text seperately in the newgrf gui active list.
alberth <alberth@openttd.org>
parents: 15219
diff changeset
815 DrawString(text_left + (rtl ? 0 : txtoffset), text_right - (rtl ? txtoffset : 0), y + offset_y, text, h ? TC_WHITE : TC_ORANGE);
15205
0dca88008a3a (svn r19834) -Change: Replace matrix list widget in NewGRF gui by a panel with black background.
alberth <alberth@openttd.org>
parents: 15204
diff changeset
816 y += step_height;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
817 }
9207
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
818 }
19237
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
819 if (i == this->active_over && this->vscroll->IsVisible(i)) { // Highlight is after the last GRF entry.
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
820 GfxFillRect(r.left + WD_FRAMERECT_LEFT, y, r.right - WD_FRAMERECT_RIGHT, y + 2, PC_GREY);
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
821 }
15618
e4640748f223 (svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents: 15605
diff changeset
822 break;
e4640748f223 (svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents: 15605
diff changeset
823 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
824
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
825 case WID_NS_AVAIL_LIST: {
19237
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
826 GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, this->active_over == -2 ? PC_DARK_GREY : PC_BLACK);
15208
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
827
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
828 uint step_height = this->GetWidget<NWidgetBase>(WID_NS_AVAIL_LIST)->resize_y;
15219
861c943801ad (svn r19848) -Fix (r19837): Center the texts of the inactive newgrfs.
alberth <alberth@openttd.org>
parents: 15216
diff changeset
829 int offset_y = (step_height - FONT_HEIGHT_NORMAL) / 2;
15208
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
830 uint y = r.top + WD_FRAMERECT_TOP;
15779
9ad2843db6f4 (svn r20453) -Codechange: Remove direct accesses to Window::hscroll, vscroll and vscroll2.
frosch <frosch@openttd.org>
parents: 15778
diff changeset
831 uint min_index = this->vscroll2->GetPosition();
9ad2843db6f4 (svn r20453) -Codechange: Remove direct accesses to Window::hscroll, vscroll and vscroll2.
frosch <frosch@openttd.org>
parents: 15778
diff changeset
832 uint max_index = min(min_index + this->vscroll2->GetCapacity(), this->avails.Length());
15208
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
833
15599
146255899304 (svn r20259) -Add: allow NewGRFs to specify their version and use that to hide old NewGRFs / to choose the newest when loading compatible NewGRFs
rubidium <rubidium@openttd.org>
parents: 15598
diff changeset
834 for (uint i = min_index; i < max_index; i++) {
15208
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
835 const GRFConfig *c = this->avails[i];
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
836 bool h = (c == this->avail_sel);
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
837 const char *text = c->GetName();
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
838
17657
c2a2cda37d1b (svn r22429) -Add: some constants for specific palette colours used in the GUI.
frosch <frosch@openttd.org>
parents: 17649
diff changeset
839 if (h) GfxFillRect(r.left + 1, y, r.right - 1, y + step_height - 1, PC_DARK_BLUE);
15219
861c943801ad (svn r19848) -Fix (r19837): Center the texts of the inactive newgrfs.
alberth <alberth@openttd.org>
parents: 15216
diff changeset
840 DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y + offset_y, text, h ? TC_WHITE : TC_SILVER);
15208
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
841 y += step_height;
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
842 }
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
843 break;
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
844 }
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
845
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
846 case WID_NS_NEWGRF_INFO_TITLE:
15204
f29231ce72e1 (svn r19833) -Change: Modify NewGRF window towards having combined lists, add captions.
alberth <alberth@openttd.org>
parents: 15203
diff changeset
847 /* Create the nice grayish rectangle at the details top. */
17657
c2a2cda37d1b (svn r22429) -Add: some constants for specific palette colours used in the GUI.
frosch <frosch@openttd.org>
parents: 17649
diff changeset
848 GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, PC_DARK_BLUE);
15400
821c26b30fd9 (svn r20043) -Codechange: Introduce vertical alignment for DrawStringMultiLine().
alberth <alberth@openttd.org>
parents: 15345
diff changeset
849 DrawString(r.left, r.right, (r.top + r.bottom - FONT_HEIGHT_NORMAL) / 2, STR_NEWGRF_SETTINGS_INFO_TITLE, TC_FROMSTRING, SA_HOR_CENTER);
15204
f29231ce72e1 (svn r19833) -Change: Modify NewGRF window towards having combined lists, add captions.
alberth <alberth@openttd.org>
parents: 15203
diff changeset
850 break;
f29231ce72e1 (svn r19833) -Change: Modify NewGRF window towards having combined lists, add captions.
alberth <alberth@openttd.org>
parents: 15203
diff changeset
851
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
852 case WID_NS_NEWGRF_INFO: {
15208
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
853 const GRFConfig *selected = this->active_sel;
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
854 if (selected == NULL) selected = this->avail_sel;
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
855 if (selected != NULL) {
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
856 ShowNewGRFInfo(selected, r.left + WD_FRAMERECT_LEFT, r.top + WD_FRAMERECT_TOP, r.right - WD_FRAMERECT_RIGHT, r.bottom - WD_FRAMERECT_BOTTOM, this->show_params);
13171
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
857 }
93c95e6c1a53 (svn r17676) -Codechange: make the NewGRF GUI nested
rubidium <rubidium@openttd.org>
parents: 13170
diff changeset
858 break;
15208
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
859 }
9207
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
860 }
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
861 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
862
14409
1eaefde497fd (svn r18966) -Codechange: Remove Window::OnDoubleClick() in favour of a parameter for OnClick().
frosch <frosch@openttd.org>
parents: 14391
diff changeset
863 virtual void OnClick(Point pt, int widget, int click_count)
9207
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
864 {
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
865 if (widget >= WID_NS_NEWGRF_TEXTFILE && widget < WID_NS_NEWGRF_TEXTFILE + TFT_END) {
18413
e5c315e27c0a (svn r23249) -Feature: Also allow viewing of the other two textfiles supplied by BaNaNaS tars, i.e. changelog and license.
frosch <frosch@openttd.org>
parents: 18412
diff changeset
866 if (this->active_sel == NULL && this->avail_sel == NULL) return;
e5c315e27c0a (svn r23249) -Feature: Also allow viewing of the other two textfiles supplied by BaNaNaS tars, i.e. changelog and license.
frosch <frosch@openttd.org>
parents: 18412
diff changeset
867
19078
8cb1275f2bb3 (svn r23932) -Codechange: split the NewGRF text window into its own source files
rubidium <rubidium@openttd.org>
parents: 18957
diff changeset
868 ShowNewGRFTextfileWindow((TextfileType)(widget - WID_NS_NEWGRF_TEXTFILE), this->active_sel != NULL ? this->active_sel : this->avail_sel);
18413
e5c315e27c0a (svn r23249) -Feature: Also allow viewing of the other two textfiles supplied by BaNaNaS tars, i.e. changelog and license.
frosch <frosch@openttd.org>
parents: 18412
diff changeset
869 return;
e5c315e27c0a (svn r23249) -Feature: Also allow viewing of the other two textfiles supplied by BaNaNaS tars, i.e. changelog and license.
frosch <frosch@openttd.org>
parents: 18412
diff changeset
870 }
e5c315e27c0a (svn r23249) -Feature: Also allow viewing of the other two textfiles supplied by BaNaNaS tars, i.e. changelog and license.
frosch <frosch@openttd.org>
parents: 18412
diff changeset
871
9207
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
872 switch (widget) {
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
873 case WID_NS_PRESET_LIST: {
9677
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
874 DropDownList *list = new DropDownList();
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
875
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
876 /* Add 'None' option for clearing list */
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
877 list->push_back(new DropDownListStringItem(STR_NONE, -1, false));
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
878
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
879 for (uint i = 0; i < _grf_preset_list.Length(); i++) {
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
880 if (_grf_preset_list[i] != NULL) {
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
881 list->push_back(new DropDownListPresetItem(i));
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
882 }
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
883 }
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
884
15212
a4e976b89e90 (svn r19841) -Feature: Setup NewGRFs from a single window.
alberth <alberth@openttd.org>
parents: 15211
diff changeset
885 this->DeleteChildWindows(WC_QUERY_STRING); // Remove the parameter query window
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
886 ShowDropDownList(this, list, this->preset, WID_NS_PRESET_LIST);
9677
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
887 break;
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
888 }
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
889
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
890 case WID_NS_OPEN_URL: {
18648
f68b9653f952 (svn r23495) -Feature: button in NewGRF window to open URL from action14
yexo <yexo@openttd.org>
parents: 18627
diff changeset
891 const GRFConfig *c = (this->avail_sel == NULL) ? this->active_sel : this->avail_sel;
f68b9653f952 (svn r23495) -Feature: button in NewGRF window to open URL from action14
yexo <yexo@openttd.org>
parents: 18627
diff changeset
892
f68b9653f952 (svn r23495) -Feature: button in NewGRF window to open URL from action14
yexo <yexo@openttd.org>
parents: 18627
diff changeset
893 extern void OpenBrowser(const char *url);
f68b9653f952 (svn r23495) -Feature: button in NewGRF window to open URL from action14
yexo <yexo@openttd.org>
parents: 18627
diff changeset
894 OpenBrowser(c->GetURL());
f68b9653f952 (svn r23495) -Feature: button in NewGRF window to open URL from action14
yexo <yexo@openttd.org>
parents: 18627
diff changeset
895 break;
f68b9653f952 (svn r23495) -Feature: button in NewGRF window to open URL from action14
yexo <yexo@openttd.org>
parents: 18627
diff changeset
896 }
f68b9653f952 (svn r23495) -Feature: button in NewGRF window to open URL from action14
yexo <yexo@openttd.org>
parents: 18627
diff changeset
897
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
898 case WID_NS_PRESET_SAVE:
17579
105b4e4eb168 (svn r22343) -Change: Remove pixel limiter for query strings.
terkhen <terkhen@openttd.org>
parents: 17486
diff changeset
899 ShowQueryString(STR_EMPTY, STR_NEWGRF_SETTINGS_PRESET_SAVE_QUERY, 32, this, CS_ALPHANUMERAL, QSF_NONE);
9677
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
900 break;
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
901
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
902 case WID_NS_PRESET_DELETE:
9677
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
903 if (this->preset == -1) return;
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
904
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
905 DeleteGRFPresetFromConfig(_grf_preset_list[this->preset]);
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
906 GetGRFPresetList(&_grf_preset_list);
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
907 this->preset = -1;
13170
c001604f4ab3 (svn r17675) -Codechange: move the 'state' changes out of the OnPaint of the newgrf window
rubidium <rubidium@openttd.org>
parents: 13168
diff changeset
908 this->InvalidateData();
13413
a3d40c489804 (svn r17922) -Fix [FS#3291]: crash when closing NewGRF parameter window with no NewGRF selected
rubidium <rubidium@openttd.org>
parents: 13411
diff changeset
909 this->DeleteChildWindows(WC_QUERY_STRING); // Remove the parameter query window
9207
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
910 break;
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
911
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
912 case WID_NS_MOVE_UP: { // Move GRF up
15345
52c9ee163c8f (svn r19986) -Fix (r19841): One could add and remove Grfs from the list via doubleclicking even if editing the list is not allowed.
frosch <frosch@openttd.org>
parents: 15331
diff changeset
913 if (this->active_sel == NULL || !this->editable) break;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
914
14390
48685f9d7f68 (svn r18947) -Fix [FS#1510]: after clicking move up/move down in the newgrf/ai the selected item could be out of range
yexo <yexo@openttd.org>
parents: 14319
diff changeset
915 int pos = 0;
15203
2ef926c44a98 (svn r19832) -Codechange: Rename variables list->actives, sel->active_sel.
alberth <alberth@openttd.org>
parents: 15202
diff changeset
916 for (GRFConfig **pc = &this->actives; *pc != NULL; pc = &(*pc)->next, pos++) {
15200
0865df725761 (svn r19829) -Codechange: Extract assignment from the condition-check in the for statement.
alberth <alberth@openttd.org>
parents: 15194
diff changeset
917 GRFConfig *c = *pc;
15203
2ef926c44a98 (svn r19832) -Codechange: Rename variables list->actives, sel->active_sel.
alberth <alberth@openttd.org>
parents: 15202
diff changeset
918 if (c->next == this->active_sel) {
2ef926c44a98 (svn r19832) -Codechange: Rename variables list->actives, sel->active_sel.
alberth <alberth@openttd.org>
parents: 15202
diff changeset
919 c->next = this->active_sel->next;
2ef926c44a98 (svn r19832) -Codechange: Rename variables list->actives, sel->active_sel.
alberth <alberth@openttd.org>
parents: 15202
diff changeset
920 this->active_sel->next = c;
2ef926c44a98 (svn r19832) -Codechange: Rename variables list->actives, sel->active_sel.
alberth <alberth@openttd.org>
parents: 15202
diff changeset
921 *pc = this->active_sel;
9207
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
922 break;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
923 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
924 }
15779
9ad2843db6f4 (svn r20453) -Codechange: Remove direct accesses to Window::hscroll, vscroll and vscroll2.
frosch <frosch@openttd.org>
parents: 15778
diff changeset
925 this->vscroll->ScrollTowards(pos);
9677
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
926 this->preset = -1;
13170
c001604f4ab3 (svn r17675) -Codechange: move the 'state' changes out of the OnPaint of the newgrf window
rubidium <rubidium@openttd.org>
parents: 13168
diff changeset
927 this->InvalidateData();
9207
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
928 break;
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
929 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
930
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
931 case WID_NS_MOVE_DOWN: { // Move GRF down
15345
52c9ee163c8f (svn r19986) -Fix (r19841): One could add and remove Grfs from the list via doubleclicking even if editing the list is not allowed.
frosch <frosch@openttd.org>
parents: 15331
diff changeset
932 if (this->active_sel == NULL || !this->editable) break;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
933
14390
48685f9d7f68 (svn r18947) -Fix [FS#1510]: after clicking move up/move down in the newgrf/ai the selected item could be out of range
yexo <yexo@openttd.org>
parents: 14319
diff changeset
934 int pos = 1; // Start at 1 as we swap the selected newgrf with the next one
15203
2ef926c44a98 (svn r19832) -Codechange: Rename variables list->actives, sel->active_sel.
alberth <alberth@openttd.org>
parents: 15202
diff changeset
935 for (GRFConfig **pc = &this->actives; *pc != NULL; pc = &(*pc)->next, pos++) {
15200
0865df725761 (svn r19829) -Codechange: Extract assignment from the condition-check in the for statement.
alberth <alberth@openttd.org>
parents: 15194
diff changeset
936 GRFConfig *c = *pc;
15203
2ef926c44a98 (svn r19832) -Codechange: Rename variables list->actives, sel->active_sel.
alberth <alberth@openttd.org>
parents: 15202
diff changeset
937 if (c == this->active_sel) {
9207
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
938 *pc = c->next;
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
939 c->next = c->next->next;
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
940 (*pc)->next = c;
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
941 break;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
942 }
9207
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
943 }
15779
9ad2843db6f4 (svn r20453) -Codechange: Remove direct accesses to Window::hscroll, vscroll and vscroll2.
frosch <frosch@openttd.org>
parents: 15778
diff changeset
944 this->vscroll->ScrollTowards(pos);
9677
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
945 this->preset = -1;
13170
c001604f4ab3 (svn r17675) -Codechange: move the 'state' changes out of the OnPaint of the newgrf window
rubidium <rubidium@openttd.org>
parents: 13168
diff changeset
946 this->InvalidateData();
9207
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
947 break;
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
948 }
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
949
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
950 case WID_NS_FILE_LIST: { // Select an active GRF.
19237
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
951 ResetObjectToPlace();
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
952
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
953 uint i = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_NS_FILE_LIST);
9207
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
954
15201
071e920abcfb (svn r19830) -Codechange: Move variable declarations to their first use.
alberth <alberth@openttd.org>
parents: 15200
diff changeset
955 GRFConfig *c;
15203
2ef926c44a98 (svn r19832) -Codechange: Rename variables list->actives, sel->active_sel.
alberth <alberth@openttd.org>
parents: 15202
diff changeset
956 for (c = this->actives; c != NULL && i > 0; c = c->next, i--) {}
13413
a3d40c489804 (svn r17922) -Fix [FS#3291]: crash when closing NewGRF parameter window with no NewGRF selected
rubidium <rubidium@openttd.org>
parents: 13411
diff changeset
957
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
958 if (this->active_sel != c) DeleteWindowByClass(WC_GRF_PARAMETERS);
15203
2ef926c44a98 (svn r19832) -Codechange: Rename variables list->actives, sel->active_sel.
alberth <alberth@openttd.org>
parents: 15202
diff changeset
959 this->active_sel = c;
15208
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
960 this->avail_sel = NULL;
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
961 this->avail_pos = -1;
9207
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
962
13170
c001604f4ab3 (svn r17675) -Codechange: move the 'state' changes out of the OnPaint of the newgrf window
rubidium <rubidium@openttd.org>
parents: 13168
diff changeset
963 this->InvalidateData();
19237
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
964 if (click_count == 1) {
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
965 if (this->editable && this->active_sel != NULL) SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this);
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
966 break;
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
967 }
15626
33d3500b2a62 (svn r20289) -Codechange: Unify fall through coding style.
terkhen <terkhen@openttd.org>
parents: 15623
diff changeset
968 /* FALL THROUGH, with double click. */
15212
a4e976b89e90 (svn r19841) -Feature: Setup NewGRFs from a single window.
alberth <alberth@openttd.org>
parents: 15211
diff changeset
969 }
15626
33d3500b2a62 (svn r20289) -Codechange: Unify fall through coding style.
terkhen <terkhen@openttd.org>
parents: 15623
diff changeset
970
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
971 case WID_NS_REMOVE: { // Remove GRF
15345
52c9ee163c8f (svn r19986) -Fix (r19841): One could add and remove Grfs from the list via doubleclicking even if editing the list is not allowed.
frosch <frosch@openttd.org>
parents: 15331
diff changeset
972 if (this->active_sel == NULL || !this->editable) break;
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
973 DeleteWindowByClass(WC_GRF_PARAMETERS);
15212
a4e976b89e90 (svn r19841) -Feature: Setup NewGRFs from a single window.
alberth <alberth@openttd.org>
parents: 15211
diff changeset
974
a4e976b89e90 (svn r19841) -Feature: Setup NewGRFs from a single window.
alberth <alberth@openttd.org>
parents: 15211
diff changeset
975 /* Choose the next GRF file to be the selected file. */
a4e976b89e90 (svn r19841) -Feature: Setup NewGRFs from a single window.
alberth <alberth@openttd.org>
parents: 15211
diff changeset
976 GRFConfig *newsel = this->active_sel->next;
a4e976b89e90 (svn r19841) -Feature: Setup NewGRFs from a single window.
alberth <alberth@openttd.org>
parents: 15211
diff changeset
977 for (GRFConfig **pc = &this->actives; *pc != NULL; pc = &(*pc)->next) {
a4e976b89e90 (svn r19841) -Feature: Setup NewGRFs from a single window.
alberth <alberth@openttd.org>
parents: 15211
diff changeset
978 GRFConfig *c = *pc;
a4e976b89e90 (svn r19841) -Feature: Setup NewGRFs from a single window.
alberth <alberth@openttd.org>
parents: 15211
diff changeset
979 /* If the new selection is empty (i.e. we're deleting the last item
a4e976b89e90 (svn r19841) -Feature: Setup NewGRFs from a single window.
alberth <alberth@openttd.org>
parents: 15211
diff changeset
980 * in the list, pick the file just before the selected file */
a4e976b89e90 (svn r19841) -Feature: Setup NewGRFs from a single window.
alberth <alberth@openttd.org>
parents: 15211
diff changeset
981 if (newsel == NULL && c->next == this->active_sel) newsel = c;
a4e976b89e90 (svn r19841) -Feature: Setup NewGRFs from a single window.
alberth <alberth@openttd.org>
parents: 15211
diff changeset
982
a4e976b89e90 (svn r19841) -Feature: Setup NewGRFs from a single window.
alberth <alberth@openttd.org>
parents: 15211
diff changeset
983 if (c == this->active_sel) {
a4e976b89e90 (svn r19841) -Feature: Setup NewGRFs from a single window.
alberth <alberth@openttd.org>
parents: 15211
diff changeset
984 *pc = c->next;
a4e976b89e90 (svn r19841) -Feature: Setup NewGRFs from a single window.
alberth <alberth@openttd.org>
parents: 15211
diff changeset
985 delete c;
a4e976b89e90 (svn r19841) -Feature: Setup NewGRFs from a single window.
alberth <alberth@openttd.org>
parents: 15211
diff changeset
986 break;
a4e976b89e90 (svn r19841) -Feature: Setup NewGRFs from a single window.
alberth <alberth@openttd.org>
parents: 15211
diff changeset
987 }
a4e976b89e90 (svn r19841) -Feature: Setup NewGRFs from a single window.
alberth <alberth@openttd.org>
parents: 15211
diff changeset
988 }
a4e976b89e90 (svn r19841) -Feature: Setup NewGRFs from a single window.
alberth <alberth@openttd.org>
parents: 15211
diff changeset
989
a4e976b89e90 (svn r19841) -Feature: Setup NewGRFs from a single window.
alberth <alberth@openttd.org>
parents: 15211
diff changeset
990 this->active_sel = newsel;
a4e976b89e90 (svn r19841) -Feature: Setup NewGRFs from a single window.
alberth <alberth@openttd.org>
parents: 15211
diff changeset
991 this->preset = -1;
a4e976b89e90 (svn r19841) -Feature: Setup NewGRFs from a single window.
alberth <alberth@openttd.org>
parents: 15211
diff changeset
992 this->avail_pos = -1;
a4e976b89e90 (svn r19841) -Feature: Setup NewGRFs from a single window.
alberth <alberth@openttd.org>
parents: 15211
diff changeset
993 this->avail_sel = NULL;
a4e976b89e90 (svn r19841) -Feature: Setup NewGRFs from a single window.
alberth <alberth@openttd.org>
parents: 15211
diff changeset
994 this->avails.ForceRebuild();
17826
03d75c842b87 (svn r22617) -Codechange: Add GameOptionsInvalidationData enum for data values for Window::OnInvalidateData() of windows with class WC_GAME_OPTIONS.
frosch <frosch@openttd.org>
parents: 17809
diff changeset
995 this->InvalidateData(GOID_NEWGRF_LIST_EDITED);
9207
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
996 break;
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
997 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
998
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
999 case WID_NS_AVAIL_LIST: { // Select a non-active GRF.
19237
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1000 ResetObjectToPlace();
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1001
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1002 uint i = this->vscroll2->GetScrolledRowFromWidget(pt.y, this, WID_NS_AVAIL_LIST);
15208
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1003 this->active_sel = NULL;
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
1004 DeleteWindowByClass(WC_GRF_PARAMETERS);
15208
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1005 if (i < this->avails.Length()) {
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1006 this->avail_sel = this->avails[i];
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1007 this->avail_pos = i;
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1008 }
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1009 this->InvalidateData();
19237
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1010 if (click_count == 1) {
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1011 if (this->editable && this->avail_sel != NULL && !HasBit(this->avail_sel->flags, GCF_INVALID)) SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this);
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1012 break;
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1013 }
15626
33d3500b2a62 (svn r20289) -Codechange: Unify fall through coding style.
terkhen <terkhen@openttd.org>
parents: 15623
diff changeset
1014 /* FALL THROUGH, with double click. */
15212
a4e976b89e90 (svn r19841) -Feature: Setup NewGRFs from a single window.
alberth <alberth@openttd.org>
parents: 15211
diff changeset
1015 }
15626
33d3500b2a62 (svn r20289) -Codechange: Unify fall through coding style.
terkhen <terkhen@openttd.org>
parents: 15623
diff changeset
1016
19237
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1017 case WID_NS_ADD:
17077
5a60038ce980 (svn r21814) -Fix/Add: Check GRF version from action 8, and disallow usage of GRFs with versions above 7.
frosch <frosch@openttd.org>
parents: 16614
diff changeset
1018 if (this->avail_sel == NULL || !this->editable || HasBit(this->avail_sel->flags, GCF_INVALID)) break;
15212
a4e976b89e90 (svn r19841) -Feature: Setup NewGRFs from a single window.
alberth <alberth@openttd.org>
parents: 15211
diff changeset
1019
19237
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1020 this->AddGRFToActive();
15208
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1021 break;
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1022
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1023 case WID_NS_APPLY_CHANGES: // Apply changes made to GRF list
15345
52c9ee163c8f (svn r19986) -Fix (r19841): One could add and remove Grfs from the list via doubleclicking even if editing the list is not allowed.
frosch <frosch@openttd.org>
parents: 15331
diff changeset
1024 if (!this->editable) break;
9207
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
1025 if (this->execute) {
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
1026 ShowQuery(
12632
e41943276802 (svn r17075) -Codechange: rename ~750 strings to be more uniform with their relatives
rubidium <rubidium@openttd.org>
parents: 12619
diff changeset
1027 STR_NEWGRF_POPUP_CAUTION_CAPTION,
9207
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
1028 STR_NEWGRF_CONFIRMATION_TEXT,
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
1029 this,
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
1030 NewGRFConfirmationCallback
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
1031 );
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
1032 } else {
15203
2ef926c44a98 (svn r19832) -Codechange: Rename variables list->actives, sel->active_sel.
alberth <alberth@openttd.org>
parents: 15202
diff changeset
1033 CopyGRFConfigList(this->orig_list, this->actives, true);
9207
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
1034 ResetGRFConfig(false);
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
1035 ReloadNewGRFData();
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1036 }
15212
a4e976b89e90 (svn r19841) -Feature: Setup NewGRFs from a single window.
alberth <alberth@openttd.org>
parents: 15211
diff changeset
1037 this->DeleteChildWindows(WC_QUERY_STRING); // Remove the parameter query window
9207
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
1038 break;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1039
18911
e48659f8d5c4 (svn r23760) -Feature: Allow readonly display of NewGRF parameters, if GRF list may not be edited.
frosch <frosch@openttd.org>
parents: 18908
diff changeset
1040 case WID_NS_VIEW_PARAMETERS:
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1041 case WID_NS_SET_PARAMETERS: { // Edit parameters
18911
e48659f8d5c4 (svn r23760) -Feature: Allow readonly display of NewGRF parameters, if GRF list may not be edited.
frosch <frosch@openttd.org>
parents: 18908
diff changeset
1042 if (this->active_sel == NULL || !this->show_params || this->active_sel->num_valid_params == 0) break;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1043
18911
e48659f8d5c4 (svn r23760) -Feature: Allow readonly display of NewGRF parameters, if GRF list may not be edited.
frosch <frosch@openttd.org>
parents: 18908
diff changeset
1044 OpenGRFParameterWindow(this->active_sel, this->editable);
9207
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
1045 break;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1046 }
10066
42653fe231a2 (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 <rubidium@openttd.org>
parents: 9957
diff changeset
1047
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1048 case WID_NS_TOGGLE_PALETTE:
15345
52c9ee163c8f (svn r19986) -Fix (r19841): One could add and remove Grfs from the list via doubleclicking even if editing the list is not allowed.
frosch <frosch@openttd.org>
parents: 15331
diff changeset
1049 if (this->active_sel != NULL || !this->editable) {
15593
7d5548deab3f (svn r20253) -Codechange: change GRFConfig::windows_paletted into a bitmask/bitset
rubidium <rubidium@openttd.org>
parents: 15588
diff changeset
1050 this->active_sel->palette ^= GRFP_USE_MASK;
10066
42653fe231a2 (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 <rubidium@openttd.org>
parents: 9957
diff changeset
1051 this->SetDirty();
42653fe231a2 (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 <rubidium@openttd.org>
parents: 9957
diff changeset
1052 }
42653fe231a2 (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 <rubidium@openttd.org>
parents: 9957
diff changeset
1053 break;
10793
0744d383a56b (svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents: 10145
diff changeset
1054
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1055 case WID_NS_CONTENT_DOWNLOAD:
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1056 case WID_NS_CONTENT_DOWNLOAD2:
10793
0744d383a56b (svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents: 10145
diff changeset
1057 if (!_network_available) {
14645
b7a22979b84e (svn r19224) -Codechange: change parameters passed to ShowErrorMessage() a bit
smatz <smatz@openttd.org>
parents: 14561
diff changeset
1058 ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, WL_ERROR);
10793
0744d383a56b (svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents: 10145
diff changeset
1059 } else {
0744d383a56b (svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents: 10145
diff changeset
1060 #if defined(ENABLE_NETWORK)
15331
fcc18215652e (svn r19972) -Change: Use the md5sum from the previous save of the game for BaNaNaS instead of the initial (when the grf was added) md5sum from the gamelog. Neither method is 'better', but this way it is independent from the gamelog.
frosch <frosch@openttd.org>
parents: 15220
diff changeset
1061 this->DeleteChildWindows(WC_QUERY_STRING); // Remove the parameter query window
15212
a4e976b89e90 (svn r19841) -Feature: Setup NewGRFs from a single window.
alberth <alberth@openttd.org>
parents: 15211
diff changeset
1062
18618
690f883cee0e (svn r23465) -Feature [FS#4827]: add 'find missing content online' button to 'load savegame' and 'find network game' windows
yexo <yexo@openttd.org>
parents: 18444
diff changeset
1063 ShowMissingContentWindow(this->actives);
10793
0744d383a56b (svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents: 10145
diff changeset
1064 #endif
0744d383a56b (svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents: 10145
diff changeset
1065 }
0744d383a56b (svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents: 10145
diff changeset
1066 break;
15211
e28e566488a9 (svn r19840) -Add: Add 'rescan' functionality to the NewGRF window.
alberth <alberth@openttd.org>
parents: 15209
diff changeset
1067
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1068 case WID_NS_RESCAN_FILES:
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1069 case WID_NS_RESCAN_FILES2:
17982
ad0c8dce1699 (svn r22791) -Codechange: use callback for scanning from the NewGRF window
rubidium <rubidium@openttd.org>
parents: 17962
diff changeset
1070 ScanNewGRFFiles(this);
15211
e28e566488a9 (svn r19840) -Add: Add 'rescan' functionality to the NewGRF window.
alberth <alberth@openttd.org>
parents: 15209
diff changeset
1071 break;
9207
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
1072 }
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
1073 }
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
1074
17982
ad0c8dce1699 (svn r22791) -Codechange: use callback for scanning from the NewGRF window
rubidium <rubidium@openttd.org>
parents: 17962
diff changeset
1075 virtual void OnNewGRFsScanned()
ad0c8dce1699 (svn r22791) -Codechange: use callback for scanning from the NewGRF window
rubidium <rubidium@openttd.org>
parents: 17962
diff changeset
1076 {
ad0c8dce1699 (svn r22791) -Codechange: use callback for scanning from the NewGRF window
rubidium <rubidium@openttd.org>
parents: 17962
diff changeset
1077 this->avail_sel = NULL;
ad0c8dce1699 (svn r22791) -Codechange: use callback for scanning from the NewGRF window
rubidium <rubidium@openttd.org>
parents: 17962
diff changeset
1078 this->avail_pos = -1;
ad0c8dce1699 (svn r22791) -Codechange: use callback for scanning from the NewGRF window
rubidium <rubidium@openttd.org>
parents: 17962
diff changeset
1079 this->avails.ForceRebuild();
19078
8cb1275f2bb3 (svn r23932) -Codechange: split the NewGRF text window into its own source files
rubidium <rubidium@openttd.org>
parents: 18957
diff changeset
1080 this->DeleteChildWindows(WC_QUERY_STRING); // Remove the parameter query window
8cb1275f2bb3 (svn r23932) -Codechange: split the NewGRF text window into its own source files
rubidium <rubidium@openttd.org>
parents: 18957
diff changeset
1081 this->DeleteChildWindows(WC_TEXTFILE); // Remove the view textfile window
17982
ad0c8dce1699 (svn r22791) -Codechange: use callback for scanning from the NewGRF window
rubidium <rubidium@openttd.org>
parents: 17962
diff changeset
1082 }
ad0c8dce1699 (svn r22791) -Codechange: use callback for scanning from the NewGRF window
rubidium <rubidium@openttd.org>
parents: 17962
diff changeset
1083
9677
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
1084 virtual void OnDropdownSelect(int widget, int index)
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
1085 {
15345
52c9ee163c8f (svn r19986) -Fix (r19841): One could add and remove Grfs from the list via doubleclicking even if editing the list is not allowed.
frosch <frosch@openttd.org>
parents: 15331
diff changeset
1086 if (!this->editable) return;
16006
25371ea61636 (svn r20694) -Fix [FS#4087]: empty newgrf presets were not selectable
yexo <yexo@openttd.org>
parents: 15982
diff changeset
1087
25371ea61636 (svn r20694) -Fix [FS#4087]: empty newgrf presets were not selectable
yexo <yexo@openttd.org>
parents: 15982
diff changeset
1088 ClearGRFConfigList(&this->actives);
25371ea61636 (svn r20694) -Fix [FS#4087]: empty newgrf presets were not selectable
yexo <yexo@openttd.org>
parents: 15982
diff changeset
1089 this->preset = index;
25371ea61636 (svn r20694) -Fix [FS#4087]: empty newgrf presets were not selectable
yexo <yexo@openttd.org>
parents: 15982
diff changeset
1090
25371ea61636 (svn r20694) -Fix [FS#4087]: empty newgrf presets were not selectable
yexo <yexo@openttd.org>
parents: 15982
diff changeset
1091 if (index != -1) {
17809
981f157de59f (svn r22594) -Fix [FS#4644]: add active NewGRFs to the list of available ones when selecting the empty preset
yexo <yexo@openttd.org>
parents: 17769
diff changeset
1092 this->actives = LoadGRFPresetFromConfig(_grf_preset_list[index]);
9677
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
1093 }
17809
981f157de59f (svn r22594) -Fix [FS#4644]: add active NewGRFs to the list of available ones when selecting the empty preset
yexo <yexo@openttd.org>
parents: 17769
diff changeset
1094 this->avails.ForceRebuild();
9677
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
1095
19237
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1096 ResetObjectToPlace();
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
1097 DeleteWindowByClass(WC_GRF_PARAMETERS);
15203
2ef926c44a98 (svn r19832) -Codechange: Rename variables list->actives, sel->active_sel.
alberth <alberth@openttd.org>
parents: 15202
diff changeset
1098 this->active_sel = NULL;
17826
03d75c842b87 (svn r22617) -Codechange: Add GameOptionsInvalidationData enum for data values for Window::OnInvalidateData() of windows with class WC_GAME_OPTIONS.
frosch <frosch@openttd.org>
parents: 17809
diff changeset
1099 this->InvalidateData(GOID_NEWGRF_PRESET_LOADED);
9677
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
1100 }
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
1101
9207
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
1102 virtual void OnQueryTextFinished(char *str)
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
1103 {
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
1104 if (str == NULL) return;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1105
15603
ea0089ca72ef (svn r20264) -Fix (r20258): saving a new preset was broken
yexo <yexo@openttd.org>
parents: 15602
diff changeset
1106 SaveGRFPresetToConfig(str, this->actives);
ea0089ca72ef (svn r20264) -Fix (r20258): saving a new preset was broken
yexo <yexo@openttd.org>
parents: 15602
diff changeset
1107 GetGRFPresetList(&_grf_preset_list);
ea0089ca72ef (svn r20264) -Fix (r20258): saving a new preset was broken
yexo <yexo@openttd.org>
parents: 15602
diff changeset
1108
15598
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
1109 /* Switch to this preset */
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
1110 for (uint i = 0; i < _grf_preset_list.Length(); i++) {
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
1111 if (_grf_preset_list[i] != NULL && strcmp(_grf_preset_list[i], str) == 0) {
b5da2954ec59 (svn r20258) -Feature: more user-friendly gui to change NewGRF parameters
yexo <yexo@openttd.org>
parents: 15593
diff changeset
1112 this->preset = i;
9677
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
1113 break;
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
1114 }
44a8397a07d4 (svn r13781) -Feature: NewGRF presets, selected by a drop down list in the NewGRF window. Presets are saved in the config file.
peter1138 <peter1138@openttd.org>
parents: 9648
diff changeset
1115 }
13170
c001604f4ab3 (svn r17675) -Codechange: move the 'state' changes out of the OnPaint of the newgrf window
rubidium <rubidium@openttd.org>
parents: 13168
diff changeset
1116
c001604f4ab3 (svn r17675) -Codechange: move the 'state' changes out of the OnPaint of the newgrf window
rubidium <rubidium@openttd.org>
parents: 13168
diff changeset
1117 this->InvalidateData();
9207
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
1118 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1119
15620
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
1120 /**
17486
e7672bafbe1c (svn r22241) -Codechange: Add additional to-be-used parameter to OnInvalidateData().
frosch <frosch@openttd.org>
parents: 17077
diff changeset
1121 * Some data on this window has become invalid.
17826
03d75c842b87 (svn r22617) -Codechange: Add GameOptionsInvalidationData enum for data values for Window::OnInvalidateData() of windows with class WC_GAME_OPTIONS.
frosch <frosch@openttd.org>
parents: 17809
diff changeset
1122 * @param data Information about the changed data. @see GameOptionsInvalidationData
17486
e7672bafbe1c (svn r22241) -Codechange: Add additional to-be-used parameter to OnInvalidateData().
frosch <frosch@openttd.org>
parents: 17077
diff changeset
1123 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
15208
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1124 */
17486
e7672bafbe1c (svn r22241) -Codechange: Add additional to-be-used parameter to OnInvalidateData().
frosch <frosch@openttd.org>
parents: 17077
diff changeset
1125 virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
9207
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
1126 {
17486
e7672bafbe1c (svn r22241) -Codechange: Add additional to-be-used parameter to OnInvalidateData().
frosch <frosch@openttd.org>
parents: 17077
diff changeset
1127 if (!gui_scope) return;
10793
0744d383a56b (svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents: 10145
diff changeset
1128 switch (data) {
17826
03d75c842b87 (svn r22617) -Codechange: Add GameOptionsInvalidationData enum for data values for Window::OnInvalidateData() of windows with class WC_GAME_OPTIONS.
frosch <frosch@openttd.org>
parents: 17809
diff changeset
1129 default:
13170
c001604f4ab3 (svn r17675) -Codechange: move the 'state' changes out of the OnPaint of the newgrf window
rubidium <rubidium@openttd.org>
parents: 13168
diff changeset
1130 /* Nothing important to do */
10793
0744d383a56b (svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents: 10145
diff changeset
1131 break;
0744d383a56b (svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents: 10145
diff changeset
1132
17826
03d75c842b87 (svn r22617) -Codechange: Add GameOptionsInvalidationData enum for data values for Window::OnInvalidateData() of windows with class WC_GAME_OPTIONS.
frosch <frosch@openttd.org>
parents: 17809
diff changeset
1133 case GOID_NEWGRF_RESCANNED:
10793
0744d383a56b (svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents: 10145
diff changeset
1134 /* Search the list for items that are now found and mark them as such. */
15423
fa1322ffb258 (svn r20066) -Fix: When rescanning NewGRFs resp. after content download also check whether compatible grfs are available now.
frosch <frosch@openttd.org>
parents: 15400
diff changeset
1135 for (GRFConfig **l = &this->actives; *l != NULL; l = &(*l)->next) {
fa1322ffb258 (svn r20066) -Fix: When rescanning NewGRFs resp. after content download also check whether compatible grfs are available now.
frosch <frosch@openttd.org>
parents: 15400
diff changeset
1136 GRFConfig *c = *l;
fa1322ffb258 (svn r20066) -Fix: When rescanning NewGRFs resp. after content download also check whether compatible grfs are available now.
frosch <frosch@openttd.org>
parents: 15400
diff changeset
1137 bool compatible = HasBit(c->flags, GCF_COMPATIBLE);
fa1322ffb258 (svn r20066) -Fix: When rescanning NewGRFs resp. after content download also check whether compatible grfs are available now.
frosch <frosch@openttd.org>
parents: 15400
diff changeset
1138 if (c->status != GCS_NOT_FOUND && !compatible) continue;
10793
0744d383a56b (svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents: 10145
diff changeset
1139
16256
49226e68e209 (svn r20957) -Codechange: Add another parameter to FindGRFConfig() to define search restrictions.
frosch <frosch@openttd.org>
parents: 16250
diff changeset
1140 const GRFConfig *f = FindGRFConfig(c->ident.grfid, FGCM_EXACT, compatible ? c->original_md5sum : c->ident.md5sum);
17077
5a60038ce980 (svn r21814) -Fix/Add: Check GRF version from action 8, and disallow usage of GRFs with versions above 7.
frosch <frosch@openttd.org>
parents: 16614
diff changeset
1141 if (f == NULL || HasBit(f->flags, GCF_INVALID)) continue;
10793
0744d383a56b (svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents: 10145
diff changeset
1142
15588
04eb4c42c0a0 (svn r20248) -Codechange: use a copy-constructor instead of a separate function co clone GRFConfig/GRFError
yexo <yexo@openttd.org>
parents: 15579
diff changeset
1143 *l = new GRFConfig(*f);
15423
fa1322ffb258 (svn r20066) -Fix: When rescanning NewGRFs resp. after content download also check whether compatible grfs are available now.
frosch <frosch@openttd.org>
parents: 15400
diff changeset
1144 (*l)->next = c->next;
10793
0744d383a56b (svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents: 10145
diff changeset
1145
15423
fa1322ffb258 (svn r20066) -Fix: When rescanning NewGRFs resp. after content download also check whether compatible grfs are available now.
frosch <frosch@openttd.org>
parents: 15400
diff changeset
1146 if (active_sel == c) active_sel = *l;
fa1322ffb258 (svn r20066) -Fix: When rescanning NewGRFs resp. after content download also check whether compatible grfs are available now.
frosch <frosch@openttd.org>
parents: 15400
diff changeset
1147
fa1322ffb258 (svn r20066) -Fix: When rescanning NewGRFs resp. after content download also check whether compatible grfs are available now.
frosch <frosch@openttd.org>
parents: 15400
diff changeset
1148 delete c;
10793
0744d383a56b (svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents: 10145
diff changeset
1149 }
17826
03d75c842b87 (svn r22617) -Codechange: Add GameOptionsInvalidationData enum for data values for Window::OnInvalidateData() of windows with class WC_GAME_OPTIONS.
frosch <frosch@openttd.org>
parents: 17809
diff changeset
1150
15208
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1151 this->avails.ForceRebuild();
15579
5f128be91f59 (svn r20239) -Doc: Give a common name to all fall throughs (FALL THROUGH).
terkhen <terkhen@openttd.org>
parents: 15563
diff changeset
1152 /* FALL THROUGH */
17826
03d75c842b87 (svn r22617) -Codechange: Add GameOptionsInvalidationData enum for data values for Window::OnInvalidateData() of windows with class WC_GAME_OPTIONS.
frosch <frosch@openttd.org>
parents: 17809
diff changeset
1153 case GOID_NEWGRF_LIST_EDITED:
13170
c001604f4ab3 (svn r17675) -Codechange: move the 'state' changes out of the OnPaint of the newgrf window
rubidium <rubidium@openttd.org>
parents: 13168
diff changeset
1154 this->preset = -1;
15579
5f128be91f59 (svn r20239) -Doc: Give a common name to all fall throughs (FALL THROUGH).
terkhen <terkhen@openttd.org>
parents: 15563
diff changeset
1155 /* FALL THROUGH */
17826
03d75c842b87 (svn r22617) -Codechange: Add GameOptionsInvalidationData enum for data values for Window::OnInvalidateData() of windows with class WC_GAME_OPTIONS.
frosch <frosch@openttd.org>
parents: 17809
diff changeset
1156 case GOID_NEWGRF_PRESET_LOADED: {
03d75c842b87 (svn r22617) -Codechange: Add GameOptionsInvalidationData enum for data values for Window::OnInvalidateData() of windows with class WC_GAME_OPTIONS.
frosch <frosch@openttd.org>
parents: 17809
diff changeset
1157 /* Update scrollbars */
15201
071e920abcfb (svn r19830) -Codechange: Move variable declarations to their first use.
alberth <alberth@openttd.org>
parents: 15200
diff changeset
1158 int i = 0;
15203
2ef926c44a98 (svn r19832) -Codechange: Rename variables list->actives, sel->active_sel.
alberth <alberth@openttd.org>
parents: 15202
diff changeset
1159 for (const GRFConfig *c = this->actives; c != NULL; c = c->next, i++) {}
13170
c001604f4ab3 (svn r17675) -Codechange: move the 'state' changes out of the OnPaint of the newgrf window
rubidium <rubidium@openttd.org>
parents: 13168
diff changeset
1160
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1161 this->vscroll->SetCapacityFromWidget(this, WID_NS_FILE_LIST);
19237
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1162 this->vscroll->SetCount(i + 1); // Reserve empty space for drag and drop handling.
15208
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1163
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1164 this->vscroll2->SetCapacityFromWidget(this, WID_NS_AVAIL_LIST);
15779
9ad2843db6f4 (svn r20453) -Codechange: Remove direct accesses to Window::hscroll, vscroll and vscroll2.
frosch <frosch@openttd.org>
parents: 15778
diff changeset
1165 if (this->avail_pos >= 0) this->vscroll2->ScrollTowards(this->avail_pos);
13170
c001604f4ab3 (svn r17675) -Codechange: move the 'state' changes out of the OnPaint of the newgrf window
rubidium <rubidium@openttd.org>
parents: 13168
diff changeset
1166 break;
15201
071e920abcfb (svn r19830) -Codechange: Move variable declarations to their first use.
alberth <alberth@openttd.org>
parents: 15200
diff changeset
1167 }
10793
0744d383a56b (svn r15126) -Feature: downloading content from a central server (content.openttd.org) where authors can upload they NewGRFS/AI etc. This should make joining servers that use only NewGRFs that are distributed via this system easier as the players can download the NewGRFs from in the game. It should also make it easier to see whether there are updates for NewGRFs and make the necessary updates.
rubidium <rubidium@openttd.org>
parents: 10145
diff changeset
1168 }
13170
c001604f4ab3 (svn r17675) -Codechange: move the 'state' changes out of the OnPaint of the newgrf window
rubidium <rubidium@openttd.org>
parents: 13168
diff changeset
1169
15208
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1170 this->BuildAvailables();
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1171
13170
c001604f4ab3 (svn r17675) -Codechange: move the 'state' changes out of the OnPaint of the newgrf window
rubidium <rubidium@openttd.org>
parents: 13168
diff changeset
1172 this->SetWidgetsDisabledState(!this->editable,
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1173 WID_NS_PRESET_LIST,
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1174 WID_NS_APPLY_CHANGES,
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1175 WID_NS_TOGGLE_PALETTE,
13170
c001604f4ab3 (svn r17675) -Codechange: move the 'state' changes out of the OnPaint of the newgrf window
rubidium <rubidium@openttd.org>
parents: 13168
diff changeset
1176 WIDGET_LIST_END
c001604f4ab3 (svn r17675) -Codechange: move the 'state' changes out of the OnPaint of the newgrf window
rubidium <rubidium@openttd.org>
parents: 13168
diff changeset
1177 );
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1178 this->SetWidgetDisabledState(WID_NS_ADD, !this->editable || this->avail_sel == NULL || HasBit(this->avail_sel->flags, GCF_INVALID));
13170
c001604f4ab3 (svn r17675) -Codechange: move the 'state' changes out of the OnPaint of the newgrf window
rubidium <rubidium@openttd.org>
parents: 13168
diff changeset
1179
15203
2ef926c44a98 (svn r19832) -Codechange: Rename variables list->actives, sel->active_sel.
alberth <alberth@openttd.org>
parents: 15202
diff changeset
1180 bool disable_all = this->active_sel == NULL || !this->editable;
13170
c001604f4ab3 (svn r17675) -Codechange: move the 'state' changes out of the OnPaint of the newgrf window
rubidium <rubidium@openttd.org>
parents: 13168
diff changeset
1181 this->SetWidgetsDisabledState(disable_all,
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1182 WID_NS_REMOVE,
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1183 WID_NS_MOVE_UP,
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1184 WID_NS_MOVE_DOWN,
13170
c001604f4ab3 (svn r17675) -Codechange: move the 'state' changes out of the OnPaint of the newgrf window
rubidium <rubidium@openttd.org>
parents: 13168
diff changeset
1185 WIDGET_LIST_END
c001604f4ab3 (svn r17675) -Codechange: move the 'state' changes out of the OnPaint of the newgrf window
rubidium <rubidium@openttd.org>
parents: 13168
diff changeset
1186 );
18342
d52fe213742a (svn r23178) -Feature [FS#4780]: in-game readme.txt readmer (LordAro)
rubidium <rubidium@openttd.org>
parents: 18192
diff changeset
1187
d52fe213742a (svn r23178) -Feature [FS#4780]: in-game readme.txt readmer (LordAro)
rubidium <rubidium@openttd.org>
parents: 18192
diff changeset
1188 const GRFConfig *c = (this->avail_sel == NULL) ? this->active_sel : this->avail_sel;
18413
e5c315e27c0a (svn r23249) -Feature: Also allow viewing of the other two textfiles supplied by BaNaNaS tars, i.e. changelog and license.
frosch <frosch@openttd.org>
parents: 18412
diff changeset
1189 for (TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) {
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1190 this->SetWidgetDisabledState(WID_NS_NEWGRF_TEXTFILE + tft, c == NULL || c->GetTextfile(tft) == NULL);
18413
e5c315e27c0a (svn r23249) -Feature: Also allow viewing of the other two textfiles supplied by BaNaNaS tars, i.e. changelog and license.
frosch <frosch@openttd.org>
parents: 18412
diff changeset
1191 }
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1192 this->SetWidgetDisabledState(WID_NS_OPEN_URL, c == NULL || StrEmpty(c->GetURL()));
18342
d52fe213742a (svn r23178) -Feature [FS#4780]: in-game readme.txt readmer (LordAro)
rubidium <rubidium@openttd.org>
parents: 18192
diff changeset
1193
18911
e48659f8d5c4 (svn r23760) -Feature: Allow readonly display of NewGRF parameters, if GRF list may not be edited.
frosch <frosch@openttd.org>
parents: 18908
diff changeset
1194 this->SetWidgetDisabledState(WID_NS_SET_PARAMETERS, !this->show_params || this->active_sel == NULL || this->active_sel->num_valid_params == 0);
e48659f8d5c4 (svn r23760) -Feature: Allow readonly display of NewGRF parameters, if GRF list may not be edited.
frosch <frosch@openttd.org>
parents: 18908
diff changeset
1195 this->SetWidgetDisabledState(WID_NS_VIEW_PARAMETERS, !this->show_params || this->active_sel == NULL || this->active_sel->num_valid_params == 0);
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1196 this->SetWidgetDisabledState(WID_NS_TOGGLE_PALETTE, disable_all);
13170
c001604f4ab3 (svn r17675) -Codechange: move the 'state' changes out of the OnPaint of the newgrf window
rubidium <rubidium@openttd.org>
parents: 13168
diff changeset
1197
c001604f4ab3 (svn r17675) -Codechange: move the 'state' changes out of the OnPaint of the newgrf window
rubidium <rubidium@openttd.org>
parents: 13168
diff changeset
1198 if (!disable_all) {
c001604f4ab3 (svn r17675) -Codechange: move the 'state' changes out of the OnPaint of the newgrf window
rubidium <rubidium@openttd.org>
parents: 13168
diff changeset
1199 /* All widgets are now enabled, so disable widgets we can't use */
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1200 if (this->active_sel == this->actives) this->DisableWidget(WID_NS_MOVE_UP);
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1201 if (this->active_sel->next == NULL) this->DisableWidget(WID_NS_MOVE_DOWN);
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1202 if (this->active_sel->IsOpenTTDBaseGRF()) this->DisableWidget(WID_NS_REMOVE);
13170
c001604f4ab3 (svn r17675) -Codechange: move the 'state' changes out of the OnPaint of the newgrf window
rubidium <rubidium@openttd.org>
parents: 13168
diff changeset
1203 }
c001604f4ab3 (svn r17675) -Codechange: move the 'state' changes out of the OnPaint of the newgrf window
rubidium <rubidium@openttd.org>
parents: 13168
diff changeset
1204
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1205 this->SetWidgetDisabledState(WID_NS_PRESET_DELETE, this->preset == -1);
13170
c001604f4ab3 (svn r17675) -Codechange: move the 'state' changes out of the OnPaint of the newgrf window
rubidium <rubidium@openttd.org>
parents: 13168
diff changeset
1206
c001604f4ab3 (svn r17675) -Codechange: move the 'state' changes out of the OnPaint of the newgrf window
rubidium <rubidium@openttd.org>
parents: 13168
diff changeset
1207 bool has_missing = false;
c001604f4ab3 (svn r17675) -Codechange: move the 'state' changes out of the OnPaint of the newgrf window
rubidium <rubidium@openttd.org>
parents: 13168
diff changeset
1208 bool has_compatible = false;
15203
2ef926c44a98 (svn r19832) -Codechange: Rename variables list->actives, sel->active_sel.
alberth <alberth@openttd.org>
parents: 15202
diff changeset
1209 for (const GRFConfig *c = this->actives; !has_missing && c != NULL; c = c->next) {
13170
c001604f4ab3 (svn r17675) -Codechange: move the 'state' changes out of the OnPaint of the newgrf window
rubidium <rubidium@openttd.org>
parents: 13168
diff changeset
1210 has_missing |= c->status == GCS_NOT_FOUND;
c001604f4ab3 (svn r17675) -Codechange: move the 'state' changes out of the OnPaint of the newgrf window
rubidium <rubidium@openttd.org>
parents: 13168
diff changeset
1211 has_compatible |= HasBit(c->flags, GCF_COMPATIBLE);
c001604f4ab3 (svn r17675) -Codechange: move the 'state' changes out of the OnPaint of the newgrf window
rubidium <rubidium@openttd.org>
parents: 13168
diff changeset
1212 }
16394
82aa3e68581d (svn r21110) -Add: Tidy up the buttons of the active newgrfs list.
alberth <alberth@openttd.org>
parents: 16393
diff changeset
1213 uint16 widget_data;
82aa3e68581d (svn r21110) -Add: Tidy up the buttons of the active newgrfs list.
alberth <alberth@openttd.org>
parents: 16393
diff changeset
1214 StringID tool_tip;
13170
c001604f4ab3 (svn r17675) -Codechange: move the 'state' changes out of the OnPaint of the newgrf window
rubidium <rubidium@openttd.org>
parents: 13168
diff changeset
1215 if (has_missing || has_compatible) {
16394
82aa3e68581d (svn r21110) -Add: Tidy up the buttons of the active newgrfs list.
alberth <alberth@openttd.org>
parents: 16393
diff changeset
1216 widget_data = STR_NEWGRF_SETTINGS_FIND_MISSING_CONTENT_BUTTON;
82aa3e68581d (svn r21110) -Add: Tidy up the buttons of the active newgrfs list.
alberth <alberth@openttd.org>
parents: 16393
diff changeset
1217 tool_tip = STR_NEWGRF_SETTINGS_FIND_MISSING_CONTENT_TOOLTIP;
13170
c001604f4ab3 (svn r17675) -Codechange: move the 'state' changes out of the OnPaint of the newgrf window
rubidium <rubidium@openttd.org>
parents: 13168
diff changeset
1218 } else {
16394
82aa3e68581d (svn r21110) -Add: Tidy up the buttons of the active newgrfs list.
alberth <alberth@openttd.org>
parents: 16393
diff changeset
1219 widget_data = STR_INTRO_ONLINE_CONTENT;
82aa3e68581d (svn r21110) -Add: Tidy up the buttons of the active newgrfs list.
alberth <alberth@openttd.org>
parents: 16393
diff changeset
1220 tool_tip = STR_INTRO_TOOLTIP_ONLINE_CONTENT;
13170
c001604f4ab3 (svn r17675) -Codechange: move the 'state' changes out of the OnPaint of the newgrf window
rubidium <rubidium@openttd.org>
parents: 13168
diff changeset
1221 }
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1222 this->GetWidget<NWidgetCore>(WID_NS_CONTENT_DOWNLOAD)->widget_data = widget_data;
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1223 this->GetWidget<NWidgetCore>(WID_NS_CONTENT_DOWNLOAD)->tool_tip = tool_tip;
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1224 this->GetWidget<NWidgetCore>(WID_NS_CONTENT_DOWNLOAD2)->widget_data = widget_data;
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1225 this->GetWidget<NWidgetCore>(WID_NS_CONTENT_DOWNLOAD2)->tool_tip = tool_tip;
16394
82aa3e68581d (svn r21110) -Add: Tidy up the buttons of the active newgrfs list.
alberth <alberth@openttd.org>
parents: 16393
diff changeset
1226
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1227 this->SetWidgetDisabledState(WID_NS_PRESET_SAVE, has_missing);
9207
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
1228 }
15208
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1229
15209
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1230 virtual EventState OnKeyPress(uint16 key, uint16 keycode)
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1231 {
16393
b7cc33056746 (svn r21109) -Add: Don't display available newgrfs when the newgrf list is not editable.
alberth <alberth@openttd.org>
parents: 16392
diff changeset
1232 if (!this->editable) return ES_NOT_HANDLED;
b7cc33056746 (svn r21109) -Add: Don't display available newgrfs when the newgrf list is not editable.
alberth <alberth@openttd.org>
parents: 16392
diff changeset
1233
15209
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1234 switch (keycode) {
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1235 case WKC_UP:
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1236 /* scroll up by one */
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1237 if (this->avail_pos > 0) this->avail_pos--;
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1238 break;
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1239
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1240 case WKC_DOWN:
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1241 /* scroll down by one */
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1242 if (this->avail_pos < (int)this->avails.Length() - 1) this->avail_pos++;
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1243 break;
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1244
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1245 case WKC_PAGEUP:
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1246 /* scroll up a page */
15779
9ad2843db6f4 (svn r20453) -Codechange: Remove direct accesses to Window::hscroll, vscroll and vscroll2.
frosch <frosch@openttd.org>
parents: 15778
diff changeset
1247 this->avail_pos = (this->avail_pos < this->vscroll2->GetCapacity()) ? 0 : this->avail_pos - this->vscroll2->GetCapacity();
15209
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1248 break;
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1249
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1250 case WKC_PAGEDOWN:
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1251 /* scroll down a page */
15779
9ad2843db6f4 (svn r20453) -Codechange: Remove direct accesses to Window::hscroll, vscroll and vscroll2.
frosch <frosch@openttd.org>
parents: 15778
diff changeset
1252 this->avail_pos = min(this->avail_pos + this->vscroll2->GetCapacity(), (int)this->avails.Length() - 1);
15209
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1253 break;
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1254
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1255 case WKC_HOME:
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1256 /* jump to beginning */
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1257 this->avail_pos = 0;
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1258 break;
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1259
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1260 case WKC_END:
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1261 /* jump to end */
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1262 this->avail_pos = this->avails.Length() - 1;
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1263 break;
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1264
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1265 default: {
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1266 /* Handle editbox input */
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1267 EventState state = ES_NOT_HANDLED;
19796
b5e26ecef856 (svn r24729) -Codechange: Unify the handling of HEBR_EDITING.
frosch <frosch@openttd.org>
parents: 19793
diff changeset
1268 this->HandleEditBoxKey(WID_NS_FILTER, key, keycode, state);
15209
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1269 return state;
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1270 }
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1271 }
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1272
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1273 if (this->avails.Length() == 0) this->avail_pos = -1;
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1274 if (this->avail_pos >= 0) {
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1275 this->avail_sel = this->avails[this->avail_pos];
15779
9ad2843db6f4 (svn r20453) -Codechange: Remove direct accesses to Window::hscroll, vscroll and vscroll2.
frosch <frosch@openttd.org>
parents: 15778
diff changeset
1276 this->vscroll2->ScrollTowards(this->avail_pos);
15209
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1277 this->InvalidateData(0);
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1278 }
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1279
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1280 return ES_HANDLED;
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1281 }
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1282
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1283 virtual void OnOSKInput(int wid)
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1284 {
16393
b7cc33056746 (svn r21109) -Add: Don't display available newgrfs when the newgrf list is not editable.
alberth <alberth@openttd.org>
parents: 16392
diff changeset
1285 if (!this->editable) return;
b7cc33056746 (svn r21109) -Add: Don't display available newgrfs when the newgrf list is not editable.
alberth <alberth@openttd.org>
parents: 16392
diff changeset
1286
19434
24df8a97401e (svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents: 19421
diff changeset
1287 string_filter.SetFilterTerm(this->edit_str_buf);
24df8a97401e (svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents: 19421
diff changeset
1288 this->avails.SetFilterState(!string_filter.IsEmpty());
15209
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1289 this->avails.ForceRebuild();
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1290 this->InvalidateData(0);
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1291 }
eb71d6bac72c (svn r19838) -Change: Add filter capability to the availables list.
alberth <alberth@openttd.org>
parents: 15208
diff changeset
1292
19237
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1293 virtual void OnDragDrop(Point pt, int widget)
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1294 {
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1295 if (!this->editable) return;
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1296
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1297 if (widget == WID_NS_FILE_LIST) {
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1298 if (this->active_sel != NULL) {
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1299 /* Get pointer to the selected file in the active list. */
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1300 int from_pos = 0;
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1301 GRFConfig **from_prev;
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1302 for (from_prev = &this->actives; *from_prev != this->active_sel; from_prev = &(*from_prev)->next, from_pos++) {}
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1303
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1304 /* Gets the drag-and-drop destination offset. Ignore the last dummy line. */
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1305 int to_pos = min(this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_NS_FILE_LIST), this->vscroll->GetCount() - 2);
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1306 if (to_pos != from_pos) { // Don't move NewGRF file over itself.
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1307 /* Get pointer to destination position. */
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1308 GRFConfig **to_prev = &this->actives;
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1309 for (int i = from_pos < to_pos ? -1 : 0; *to_prev != NULL && i < to_pos; to_prev = &(*to_prev)->next, i++) {}
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1310
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1311 /* Detach NewGRF file from its original position. */
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1312 *from_prev = this->active_sel->next;
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1313
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1314 /* Attach NewGRF file to its new position. */
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1315 this->active_sel->next = *to_prev;
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1316 *to_prev = this->active_sel;
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1317
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1318 this->vscroll->ScrollTowards(to_pos);
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1319 this->preset = -1;
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1320 this->InvalidateData();
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1321 }
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1322 } else if (this->avail_sel != NULL) {
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1323 int to_pos = min(this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_NS_FILE_LIST), this->vscroll->GetCount() - 1);
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1324 this->AddGRFToActive(to_pos);
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1325 }
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1326 } else if (widget == WID_NS_AVAIL_LIST && this->active_sel != NULL) {
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1327 /* Remove active NewGRF file by dragging it over available list. */
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1328 Point dummy = {-1, -1};
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1329 this->OnClick(dummy, WID_NS_REMOVE, 1);
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1330 }
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1331
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1332 ResetObjectToPlace();
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1333
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1334 if (this->active_over != -1) {
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1335 /* End of drag-and-drop, hide dragged destination highlight. */
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1336 this->SetWidgetDirty(this->active_over == -2 ? WID_NS_AVAIL_LIST : WID_NS_FILE_LIST);
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1337 this->active_over = -1;
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1338 }
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1339 }
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1340
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1341 virtual void OnMouseDrag(Point pt, int widget)
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1342 {
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1343 if (!this->editable) return;
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1344
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1345 if (widget == WID_NS_FILE_LIST && (this->active_sel != NULL || this->avail_sel != NULL)) {
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1346 /* An NewGRF file is dragged over the active list. */
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1347 int to_pos = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_NS_FILE_LIST);
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1348 /* Skip the last dummy line if the source is from the active list. */
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1349 to_pos = min(to_pos, this->vscroll->GetCount() - (this->active_sel != NULL ? 2 : 1));
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1350
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1351 if (to_pos != this->active_over) {
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1352 this->active_over = to_pos;
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1353 this->SetWidgetDirty(WID_NS_FILE_LIST);
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1354 }
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1355 } else if (widget == WID_NS_AVAIL_LIST && this->active_sel != NULL) {
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1356 this->active_over = -2;
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1357 this->SetWidgetDirty(WID_NS_AVAIL_LIST);
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1358 } else if (this->active_over != -1) {
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1359 this->SetWidgetDirty(this->active_over == -2 ? WID_NS_AVAIL_LIST : WID_NS_FILE_LIST);
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1360 this->active_over = -1;
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1361 }
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1362 }
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1363
15208
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1364 private:
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1365 /** Sort grfs by name. */
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1366 static int CDECL NameSorter(const GRFConfig * const *a, const GRFConfig * const *b)
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1367 {
16614
1111794047a4 (svn r21344) -Feature [FS#4214]: Natural sorting of strings using ICU.
terkhen <terkhen@openttd.org>
parents: 16601
diff changeset
1368 int i = strnatcmp((*a)->GetName(), (*b)->GetName()); // Sort by name (natural sorting).
15599
146255899304 (svn r20259) -Add: allow NewGRFs to specify their version and use that to hide old NewGRFs / to choose the newest when loading compatible NewGRFs
rubidium <rubidium@openttd.org>
parents: 15598
diff changeset
1369 if (i != 0) return i;
146255899304 (svn r20259) -Add: allow NewGRFs to specify their version and use that to hide old NewGRFs / to choose the newest when loading compatible NewGRFs
rubidium <rubidium@openttd.org>
parents: 15598
diff changeset
1370
146255899304 (svn r20259) -Add: allow NewGRFs to specify their version and use that to hide old NewGRFs / to choose the newest when loading compatible NewGRFs
rubidium <rubidium@openttd.org>
parents: 15598
diff changeset
1371 i = (*a)->version - (*b)->version;
146255899304 (svn r20259) -Add: allow NewGRFs to specify their version and use that to hide old NewGRFs / to choose the newest when loading compatible NewGRFs
rubidium <rubidium@openttd.org>
parents: 15598
diff changeset
1372 if (i != 0) return i;
146255899304 (svn r20259) -Add: allow NewGRFs to specify their version and use that to hide old NewGRFs / to choose the newest when loading compatible NewGRFs
rubidium <rubidium@openttd.org>
parents: 15598
diff changeset
1373
146255899304 (svn r20259) -Add: allow NewGRFs to specify their version and use that to hide old NewGRFs / to choose the newest when loading compatible NewGRFs
rubidium <rubidium@openttd.org>
parents: 15598
diff changeset
1374 return memcmp((*a)->ident.md5sum, (*b)->ident.md5sum, lengthof((*b)->ident.md5sum));
15208
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1375 }
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1376
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1377 /** Filter grfs by tags/name */
19434
24df8a97401e (svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents: 19421
diff changeset
1378 static bool CDECL TagNameFilter(const GRFConfig * const *a, StringFilter &filter)
15208
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1379 {
19434
24df8a97401e (svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents: 19421
diff changeset
1380 filter.ResetState();
24df8a97401e (svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents: 19421
diff changeset
1381 filter.AddLine((*a)->GetName());
24df8a97401e (svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents: 19421
diff changeset
1382 filter.AddLine((*a)->filename);
24df8a97401e (svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents: 19421
diff changeset
1383 filter.AddLine((*a)->GetDescription());
24df8a97401e (svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents: 19421
diff changeset
1384 return filter.GetState();;
15208
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1385 }
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1386
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1387 void BuildAvailables()
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1388 {
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1389 if (!this->avails.NeedRebuild()) return;
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1390
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1391 this->avails.Clear();
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1392
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1393 for (const GRFConfig *c = _all_grfs; c != NULL; c = c->next) {
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1394 bool found = false;
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1395 for (const GRFConfig *grf = this->actives; grf != NULL && !found; grf = grf->next) found = grf->ident.HasGrfIdentifier(c->ident.grfid, c->ident.md5sum);
15599
146255899304 (svn r20259) -Add: allow NewGRFs to specify their version and use that to hide old NewGRFs / to choose the newest when loading compatible NewGRFs
rubidium <rubidium@openttd.org>
parents: 15598
diff changeset
1396 if (found) continue;
146255899304 (svn r20259) -Add: allow NewGRFs to specify their version and use that to hide old NewGRFs / to choose the newest when loading compatible NewGRFs
rubidium <rubidium@openttd.org>
parents: 15598
diff changeset
1397
146255899304 (svn r20259) -Add: allow NewGRFs to specify their version and use that to hide old NewGRFs / to choose the newest when loading compatible NewGRFs
rubidium <rubidium@openttd.org>
parents: 15598
diff changeset
1398 if (_settings_client.gui.newgrf_show_old_versions) {
146255899304 (svn r20259) -Add: allow NewGRFs to specify their version and use that to hide old NewGRFs / to choose the newest when loading compatible NewGRFs
rubidium <rubidium@openttd.org>
parents: 15598
diff changeset
1399 *this->avails.Append() = c;
146255899304 (svn r20259) -Add: allow NewGRFs to specify their version and use that to hide old NewGRFs / to choose the newest when loading compatible NewGRFs
rubidium <rubidium@openttd.org>
parents: 15598
diff changeset
1400 } else {
17077
5a60038ce980 (svn r21814) -Fix/Add: Check GRF version from action 8, and disallow usage of GRFs with versions above 7.
frosch <frosch@openttd.org>
parents: 16614
diff changeset
1401 const GRFConfig *best = FindGRFConfig(c->ident.grfid, HasBit(c->flags, GCF_INVALID) ? FGCM_NEWEST : FGCM_NEWEST_VALID);
15599
146255899304 (svn r20259) -Add: allow NewGRFs to specify their version and use that to hide old NewGRFs / to choose the newest when loading compatible NewGRFs
rubidium <rubidium@openttd.org>
parents: 15598
diff changeset
1402 /*
146255899304 (svn r20259) -Add: allow NewGRFs to specify their version and use that to hide old NewGRFs / to choose the newest when loading compatible NewGRFs
rubidium <rubidium@openttd.org>
parents: 15598
diff changeset
1403 * If the best version is 0, then all NewGRF with this GRF ID
146255899304 (svn r20259) -Add: allow NewGRFs to specify their version and use that to hide old NewGRFs / to choose the newest when loading compatible NewGRFs
rubidium <rubidium@openttd.org>
parents: 15598
diff changeset
1404 * have version 0, so for backward compatability reasons we
146255899304 (svn r20259) -Add: allow NewGRFs to specify their version and use that to hide old NewGRFs / to choose the newest when loading compatible NewGRFs
rubidium <rubidium@openttd.org>
parents: 15598
diff changeset
1405 * want to show them all.
146255899304 (svn r20259) -Add: allow NewGRFs to specify their version and use that to hide old NewGRFs / to choose the newest when loading compatible NewGRFs
rubidium <rubidium@openttd.org>
parents: 15598
diff changeset
1406 * If we are the best version, then we definitely want to
146255899304 (svn r20259) -Add: allow NewGRFs to specify their version and use that to hide old NewGRFs / to choose the newest when loading compatible NewGRFs
rubidium <rubidium@openttd.org>
parents: 15598
diff changeset
1407 * show that NewGRF!.
146255899304 (svn r20259) -Add: allow NewGRFs to specify their version and use that to hide old NewGRFs / to choose the newest when loading compatible NewGRFs
rubidium <rubidium@openttd.org>
parents: 15598
diff changeset
1408 */
146255899304 (svn r20259) -Add: allow NewGRFs to specify their version and use that to hide old NewGRFs / to choose the newest when loading compatible NewGRFs
rubidium <rubidium@openttd.org>
parents: 15598
diff changeset
1409 if (best->version == 0 || best->ident.HasGrfIdentifier(c->ident.grfid, c->ident.md5sum)) {
146255899304 (svn r20259) -Add: allow NewGRFs to specify their version and use that to hide old NewGRFs / to choose the newest when loading compatible NewGRFs
rubidium <rubidium@openttd.org>
parents: 15598
diff changeset
1410 *this->avails.Append() = c;
146255899304 (svn r20259) -Add: allow NewGRFs to specify their version and use that to hide old NewGRFs / to choose the newest when loading compatible NewGRFs
rubidium <rubidium@openttd.org>
parents: 15598
diff changeset
1411 }
146255899304 (svn r20259) -Add: allow NewGRFs to specify their version and use that to hide old NewGRFs / to choose the newest when loading compatible NewGRFs
rubidium <rubidium@openttd.org>
parents: 15598
diff changeset
1412 }
15208
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1413 }
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1414
19434
24df8a97401e (svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
frosch <frosch@openttd.org>
parents: 19421
diff changeset
1415 this->avails.Filter(this->string_filter);
15208
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1416 this->avails.Compact();
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1417 this->avails.RebuildDone();
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1418 this->avails.Sort();
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1419
15212
a4e976b89e90 (svn r19841) -Feature: Setup NewGRFs from a single window.
alberth <alberth@openttd.org>
parents: 15211
diff changeset
1420 if (this->avail_sel != NULL) {
a4e976b89e90 (svn r19841) -Feature: Setup NewGRFs from a single window.
alberth <alberth@openttd.org>
parents: 15211
diff changeset
1421 this->avail_pos = this->avails.FindIndex(this->avail_sel);
a4e976b89e90 (svn r19841) -Feature: Setup NewGRFs from a single window.
alberth <alberth@openttd.org>
parents: 15211
diff changeset
1422 if (this->avail_pos < 0) this->avail_sel = NULL;
a4e976b89e90 (svn r19841) -Feature: Setup NewGRFs from a single window.
alberth <alberth@openttd.org>
parents: 15211
diff changeset
1423 }
a4e976b89e90 (svn r19841) -Feature: Setup NewGRFs from a single window.
alberth <alberth@openttd.org>
parents: 15211
diff changeset
1424
15779
9ad2843db6f4 (svn r20453) -Codechange: Remove direct accesses to Window::hscroll, vscroll and vscroll2.
frosch <frosch@openttd.org>
parents: 15778
diff changeset
1425 this->vscroll2->SetCount(this->avails.Length()); // Update the scrollbar
15208
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1426 }
19237
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1427
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1428 /**
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1429 * Insert a GRF into the active list.
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1430 * @param ins_pos Insert GRF at this position.
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1431 * @return True if the GRF was successfully added.
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1432 */
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1433 bool AddGRFToActive(int ins_pos = -1)
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1434 {
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1435 if (this->avail_sel == NULL || !this->editable || HasBit(this->avail_sel->flags, GCF_INVALID)) return false;
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1436
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1437 GRFConfig **entry = NULL;
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1438 GRFConfig **list;
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1439 /* Find last entry in the list, checking for duplicate grfid on the way */
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1440 for (list = &this->actives; *list != NULL; list = &(*list)->next, ins_pos--) {
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1441 if (ins_pos == 0) entry = list; // Insert position? Save.
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1442 if ((*list)->ident.grfid == this->avail_sel->ident.grfid) {
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1443 ShowErrorMessage(STR_NEWGRF_DUPLICATE_GRFID, INVALID_STRING_ID, WL_INFO);
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1444 return false;
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1445 }
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1446 }
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1447 if (entry == NULL) entry = list;
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1448
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1449 GRFConfig *c = new GRFConfig(*this->avail_sel); // Copy GRF details from scanned list.
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1450 c->SetParameterDefaults();
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1451
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1452 /* Insert GRF config to configuration list. */
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1453 c->next = *entry;
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1454 *entry = c;
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1455
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1456 /* Select next (or previous, if last one) item in the list. */
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1457 int new_pos = this->avail_pos + 1;
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1458 if (new_pos >= (int)this->avails.Length()) new_pos = this->avail_pos - 1;
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1459 this->avail_pos = new_pos;
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1460 if (new_pos >= 0) this->avail_sel = this->avails[new_pos];
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1461
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1462 this->avails.ForceRebuild();
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1463 this->InvalidateData(GOID_NEWGRF_LIST_EDITED);
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1464 return true;
ac215e4838cf (svn r24126) -Feature [FS#3854]: Drag and drop support for the NewGRF list window. (Based on patch by sbr)
michi_cc <michi_cc@openttd.org>
parents: 19079
diff changeset
1465 }
9207
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
1466 };
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1467
18618
690f883cee0e (svn r23465) -Feature [FS#4827]: add 'find missing content online' button to 'load savegame' and 'find network game' windows
yexo <yexo@openttd.org>
parents: 18444
diff changeset
1468 #if defined(ENABLE_NETWORK)
690f883cee0e (svn r23465) -Feature [FS#4827]: add 'find missing content online' button to 'load savegame' and 'find network game' windows
yexo <yexo@openttd.org>
parents: 18444
diff changeset
1469 /**
690f883cee0e (svn r23465) -Feature [FS#4827]: add 'find missing content online' button to 'load savegame' and 'find network game' windows
yexo <yexo@openttd.org>
parents: 18444
diff changeset
1470 * Show the content list window with all missing grfs from the given list.
690f883cee0e (svn r23465) -Feature [FS#4827]: add 'find missing content online' button to 'load savegame' and 'find network game' windows
yexo <yexo@openttd.org>
parents: 18444
diff changeset
1471 * @param list The list of grfs to check for missings / not exactly matching ones.
690f883cee0e (svn r23465) -Feature [FS#4827]: add 'find missing content online' button to 'load savegame' and 'find network game' windows
yexo <yexo@openttd.org>
parents: 18444
diff changeset
1472 */
690f883cee0e (svn r23465) -Feature [FS#4827]: add 'find missing content online' button to 'load savegame' and 'find network game' windows
yexo <yexo@openttd.org>
parents: 18444
diff changeset
1473 void ShowMissingContentWindow(const GRFConfig *list)
690f883cee0e (svn r23465) -Feature [FS#4827]: add 'find missing content online' button to 'load savegame' and 'find network game' windows
yexo <yexo@openttd.org>
parents: 18444
diff changeset
1474 {
690f883cee0e (svn r23465) -Feature [FS#4827]: add 'find missing content online' button to 'load savegame' and 'find network game' windows
yexo <yexo@openttd.org>
parents: 18444
diff changeset
1475 /* Only show the things in the current list, or everything when nothing's selected */
690f883cee0e (svn r23465) -Feature [FS#4827]: add 'find missing content online' button to 'load savegame' and 'find network game' windows
yexo <yexo@openttd.org>
parents: 18444
diff changeset
1476 ContentVector cv;
690f883cee0e (svn r23465) -Feature [FS#4827]: add 'find missing content online' button to 'load savegame' and 'find network game' windows
yexo <yexo@openttd.org>
parents: 18444
diff changeset
1477 for (const GRFConfig *c = list; c != NULL; c = c->next) {
690f883cee0e (svn r23465) -Feature [FS#4827]: add 'find missing content online' button to 'load savegame' and 'find network game' windows
yexo <yexo@openttd.org>
parents: 18444
diff changeset
1478 if (c->status != GCS_NOT_FOUND && !HasBit(c->flags, GCF_COMPATIBLE)) continue;
690f883cee0e (svn r23465) -Feature [FS#4827]: add 'find missing content online' button to 'load savegame' and 'find network game' windows
yexo <yexo@openttd.org>
parents: 18444
diff changeset
1479
690f883cee0e (svn r23465) -Feature [FS#4827]: add 'find missing content online' button to 'load savegame' and 'find network game' windows
yexo <yexo@openttd.org>
parents: 18444
diff changeset
1480 ContentInfo *ci = new ContentInfo();
690f883cee0e (svn r23465) -Feature [FS#4827]: add 'find missing content online' button to 'load savegame' and 'find network game' windows
yexo <yexo@openttd.org>
parents: 18444
diff changeset
1481 ci->type = CONTENT_TYPE_NEWGRF;
690f883cee0e (svn r23465) -Feature [FS#4827]: add 'find missing content online' button to 'load savegame' and 'find network game' windows
yexo <yexo@openttd.org>
parents: 18444
diff changeset
1482 ci->state = ContentInfo::DOES_NOT_EXIST;
690f883cee0e (svn r23465) -Feature [FS#4827]: add 'find missing content online' button to 'load savegame' and 'find network game' windows
yexo <yexo@openttd.org>
parents: 18444
diff changeset
1483 ttd_strlcpy(ci->name, c->GetName(), lengthof(ci->name));
690f883cee0e (svn r23465) -Feature [FS#4827]: add 'find missing content online' button to 'load savegame' and 'find network game' windows
yexo <yexo@openttd.org>
parents: 18444
diff changeset
1484 ci->unique_id = BSWAP32(c->ident.grfid);
690f883cee0e (svn r23465) -Feature [FS#4827]: add 'find missing content online' button to 'load savegame' and 'find network game' windows
yexo <yexo@openttd.org>
parents: 18444
diff changeset
1485 memcpy(ci->md5sum, HasBit(c->flags, GCF_COMPATIBLE) ? c->original_md5sum : c->ident.md5sum, sizeof(ci->md5sum));
690f883cee0e (svn r23465) -Feature [FS#4827]: add 'find missing content online' button to 'load savegame' and 'find network game' windows
yexo <yexo@openttd.org>
parents: 18444
diff changeset
1486 *cv.Append() = ci;
690f883cee0e (svn r23465) -Feature [FS#4827]: add 'find missing content online' button to 'load savegame' and 'find network game' windows
yexo <yexo@openttd.org>
parents: 18444
diff changeset
1487 }
690f883cee0e (svn r23465) -Feature [FS#4827]: add 'find missing content online' button to 'load savegame' and 'find network game' windows
yexo <yexo@openttd.org>
parents: 18444
diff changeset
1488 ShowNetworkContentListWindow(cv.Length() == 0 ? NULL : &cv, CONTENT_TYPE_NEWGRF);
690f883cee0e (svn r23465) -Feature [FS#4827]: add 'find missing content online' button to 'load savegame' and 'find network game' windows
yexo <yexo@openttd.org>
parents: 18444
diff changeset
1489 }
690f883cee0e (svn r23465) -Feature [FS#4827]: add 'find missing content online' button to 'load savegame' and 'find network game' windows
yexo <yexo@openttd.org>
parents: 18444
diff changeset
1490 #endif
690f883cee0e (svn r23465) -Feature [FS#4827]: add 'find missing content online' button to 'load savegame' and 'find network game' windows
yexo <yexo@openttd.org>
parents: 18444
diff changeset
1491
15208
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1492 Listing NewGRFWindow::last_sorting = {false, 0};
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1493 Filtering NewGRFWindow::last_filtering = {false, 0};
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1494
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1495 NewGRFWindow::GUIGRFConfigList::SortFunction * const NewGRFWindow::sorter_funcs[] = {
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1496 &NameSorter,
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1497 };
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1498
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1499 NewGRFWindow::GUIGRFConfigList::FilterFunction * const NewGRFWindow::filter_funcs[] = {
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1500 &TagNameFilter,
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1501 };
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1502
15620
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
1503 /**
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
1504 * Custom nested widget container for the NewGRF gui.
15216
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1505 * Depending on the space in the gui, it uses either
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1506 * - two column mode, put the #acs and the #avs underneath each other and the #info next to it, or
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1507 * - three column mode, put the #avs, #acs, and #info each in its own column.
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1508 */
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1509 class NWidgetNewGRFDisplay : public NWidgetContainer {
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1510 public:
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1511 static const uint INTER_LIST_SPACING; ///< Empty vertical space between both lists in the 2 column mode.
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1512 static const uint INTER_COLUMN_SPACING; ///< Empty horizontal space between two columns.
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1513 static const uint MAX_EXTRA_INFO_WIDTH; ///< Maximal additional width given to the panel.
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1514 static const uint MIN_EXTRA_FOR_3_COLUMNS; ///< Minimal additional width needed before switching to 3 columns.
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1515
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1516 NWidgetBase *avs; ///< Widget with the available grfs list and buttons.
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1517 NWidgetBase *acs; ///< Widget with the active grfs list and buttons.
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1518 NWidgetBase *inf; ///< Info panel.
16392
67f16153e351 (svn r21108) -Add: Copy the 'editable' flag of the newgrf window to its layout widget.
alberth <alberth@openttd.org>
parents: 16286
diff changeset
1519 bool editable; ///< Editable status of the parent NewGRF window (if \c false, drop all widgets that make the window editable).
15216
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1520
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1521 NWidgetNewGRFDisplay(NWidgetBase *avs, NWidgetBase *acs, NWidgetBase *inf) : NWidgetContainer(NWID_HORIZONTAL)
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1522 {
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1523 this->avs = avs;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1524 this->acs = acs;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1525 this->inf = inf;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1526
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1527 this->Add(this->avs);
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1528 this->Add(this->acs);
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1529 this->Add(this->inf);
16392
67f16153e351 (svn r21108) -Add: Copy the 'editable' flag of the newgrf window to its layout widget.
alberth <alberth@openttd.org>
parents: 16286
diff changeset
1530
67f16153e351 (svn r21108) -Add: Copy the 'editable' flag of the newgrf window to its layout widget.
alberth <alberth@openttd.org>
parents: 16286
diff changeset
1531 this->editable = true; // Temporary setting, 'real' value is set in SetupSmallestSize().
15216
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1532 }
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1533
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1534 virtual void SetupSmallestSize(Window *w, bool init_array)
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1535 {
16392
67f16153e351 (svn r21108) -Add: Copy the 'editable' flag of the newgrf window to its layout widget.
alberth <alberth@openttd.org>
parents: 16286
diff changeset
1536 /* Copy state flag from the window. */
67f16153e351 (svn r21108) -Add: Copy the 'editable' flag of the newgrf window to its layout widget.
alberth <alberth@openttd.org>
parents: 16286
diff changeset
1537 assert(dynamic_cast<NewGRFWindow *>(w) != NULL);
67f16153e351 (svn r21108) -Add: Copy the 'editable' flag of the newgrf window to its layout widget.
alberth <alberth@openttd.org>
parents: 16286
diff changeset
1538 NewGRFWindow *ngw = (NewGRFWindow *)w;
67f16153e351 (svn r21108) -Add: Copy the 'editable' flag of the newgrf window to its layout widget.
alberth <alberth@openttd.org>
parents: 16286
diff changeset
1539 this->editable = ngw->editable;
67f16153e351 (svn r21108) -Add: Copy the 'editable' flag of the newgrf window to its layout widget.
alberth <alberth@openttd.org>
parents: 16286
diff changeset
1540
15216
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1541 this->avs->SetupSmallestSize(w, init_array);
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1542 this->acs->SetupSmallestSize(w, init_array);
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1543 this->inf->SetupSmallestSize(w, init_array);
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1544
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1545 uint min_avs_width = this->avs->smallest_x + this->avs->padding_left + this->avs->padding_right;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1546 uint min_acs_width = this->acs->smallest_x + this->acs->padding_left + this->acs->padding_right;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1547 uint min_inf_width = this->inf->smallest_x + this->inf->padding_left + this->inf->padding_right;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1548
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1549 uint min_avs_height = this->avs->smallest_y + this->avs->padding_top + this->avs->padding_bottom;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1550 uint min_acs_height = this->acs->smallest_y + this->acs->padding_top + this->acs->padding_bottom;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1551 uint min_inf_height = this->inf->smallest_y + this->inf->padding_top + this->inf->padding_bottom;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1552
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1553 /* Smallest window is in two column mode. */
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1554 this->smallest_x = max(min_avs_width, min_acs_width) + INTER_COLUMN_SPACING + min_inf_width;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1555 this->smallest_y = max(min_inf_height, min_acs_height + INTER_LIST_SPACING + min_avs_height);
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1556
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1557 /* Filling. */
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1558 this->fill_x = LeastCommonMultiple(this->avs->fill_x, this->acs->fill_x);
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1559 if (this->inf->fill_x > 0 && (this->fill_x == 0 || this->fill_x > this->inf->fill_x)) this->fill_x = this->inf->fill_x;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1560
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1561 this->fill_y = this->avs->fill_y;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1562 if (this->acs->fill_y > 0 && (this->fill_y == 0 || this->fill_y > this->acs->fill_y)) this->fill_y = this->acs->fill_y;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1563 this->fill_y = LeastCommonMultiple(this->fill_y, this->inf->fill_y);
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1564
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1565 /* Resizing. */
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1566 this->resize_x = LeastCommonMultiple(this->avs->resize_x, this->acs->resize_x);
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1567 if (this->inf->resize_x > 0 && (this->resize_x == 0 || this->resize_x > this->inf->resize_x)) this->resize_x = this->inf->resize_x;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1568
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1569 this->resize_y = this->avs->resize_y;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1570 if (this->acs->resize_y > 0 && (this->resize_y == 0 || this->resize_y > this->acs->resize_y)) this->resize_y = this->acs->resize_y;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1571 this->resize_y = LeastCommonMultiple(this->resize_y, this->inf->resize_y);
18415
8abe19c16b0b (svn r23251) -Fix: 3-column view of NewGRF GUI had too much space for certain font sizes.
frosch <frosch@openttd.org>
parents: 18413
diff changeset
1572
8abe19c16b0b (svn r23251) -Fix: 3-column view of NewGRF GUI had too much space for certain font sizes.
frosch <frosch@openttd.org>
parents: 18413
diff changeset
1573 /* Make sure the height suits the 3 column (resp. not-editable) format; the 2 column format can easily fill space between the lists */
8abe19c16b0b (svn r23251) -Fix: 3-column view of NewGRF GUI had too much space for certain font sizes.
frosch <frosch@openttd.org>
parents: 18413
diff changeset
1574 this->smallest_y = ComputeMaxSize(min_acs_height, this->smallest_y + this->resize_y - 1, this->resize_y);
15216
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1575 }
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1576
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1577 virtual void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1578 {
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1579 this->StoreSizePosition(sizing, x, y, given_width, given_height);
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1580
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1581 uint min_avs_width = this->avs->smallest_x + this->avs->padding_left + this->avs->padding_right;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1582 uint min_acs_width = this->acs->smallest_x + this->acs->padding_left + this->acs->padding_right;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1583 uint min_inf_width = this->inf->smallest_x + this->inf->padding_left + this->inf->padding_right;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1584
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1585 uint min_list_width = max(min_avs_width, min_acs_width); // Smallest width of the lists such that they have equal width (incl padding).
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1586 uint avs_extra_width = min_list_width - min_avs_width; // Additional width needed for avs to reach min_list_width.
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1587 uint acs_extra_width = min_list_width - min_acs_width; // Additional width needed for acs to reach min_list_width.
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1588
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1589 /* Use 2 or 3 colmuns? */
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1590 uint min_three_columns = min_avs_width + min_acs_width + min_inf_width + 2 * INTER_COLUMN_SPACING;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1591 uint min_two_columns = min_list_width + min_inf_width + INTER_COLUMN_SPACING;
16393
b7cc33056746 (svn r21109) -Add: Don't display available newgrfs when the newgrf list is not editable.
alberth <alberth@openttd.org>
parents: 16392
diff changeset
1592 bool use_three_columns = this->editable && (min_three_columns + MIN_EXTRA_FOR_3_COLUMNS <= given_width);
15216
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1593
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1594 /* Info panel is a seperate column in both modes. Compute its width first. */
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1595 uint extra_width, inf_width;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1596 if (use_three_columns) {
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1597 extra_width = given_width - min_three_columns;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1598 inf_width = min(MAX_EXTRA_INFO_WIDTH, extra_width / 2);
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1599 } else {
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1600 extra_width = given_width - min_two_columns;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1601 inf_width = min(MAX_EXTRA_INFO_WIDTH, extra_width / 2);
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1602 }
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1603 inf_width = ComputeMaxSize(this->inf->smallest_x, this->inf->smallest_x + inf_width, this->inf->GetHorizontalStepSize(sizing));
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1604 extra_width -= inf_width - this->inf->smallest_x;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1605
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1606 uint inf_height = ComputeMaxSize(this->inf->smallest_y, given_height, this->inf->GetVerticalStepSize(sizing));
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1607
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1608 if (use_three_columns) {
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1609 /* Three column display, first make both lists equally wide, then divide whatever is left between both lists.
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1610 * Only keep track of what avs gets, all other space goes to acs. */
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1611 uint avs_width = min(avs_extra_width, extra_width);
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1612 extra_width -= avs_width;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1613 extra_width -= min(acs_extra_width, extra_width);
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1614 avs_width += extra_width / 2;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1615
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1616 avs_width = ComputeMaxSize(this->avs->smallest_x, this->avs->smallest_x + avs_width, this->avs->GetHorizontalStepSize(sizing));
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1617
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1618 uint acs_width = given_width - // Remaining space, including horizontal padding.
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1619 inf_width - this->inf->padding_left - this->inf->padding_right -
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1620 avs_width - this->avs->padding_left - this->avs->padding_right - 2 * INTER_COLUMN_SPACING;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1621 acs_width = ComputeMaxSize(min_acs_width, acs_width, this->acs->GetHorizontalStepSize(sizing)) -
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1622 this->acs->padding_left - this->acs->padding_right;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1623
18415
8abe19c16b0b (svn r23251) -Fix: 3-column view of NewGRF GUI had too much space for certain font sizes.
frosch <frosch@openttd.org>
parents: 18413
diff changeset
1624 /* Never use fill_y on these; the minimal size is choosen, so that the 3 column view looks nice */
8abe19c16b0b (svn r23251) -Fix: 3-column view of NewGRF GUI had too much space for certain font sizes.
frosch <frosch@openttd.org>
parents: 18413
diff changeset
1625 uint avs_height = ComputeMaxSize(this->avs->smallest_y, given_height, this->avs->resize_y);
8abe19c16b0b (svn r23251) -Fix: 3-column view of NewGRF GUI had too much space for certain font sizes.
frosch <frosch@openttd.org>
parents: 18413
diff changeset
1626 uint acs_height = ComputeMaxSize(this->acs->smallest_y, given_height, this->acs->resize_y);
15216
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1627
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1628 /* Assign size and position to the childs. */
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1629 if (rtl) {
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1630 x += this->inf->padding_left;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1631 this->inf->AssignSizePosition(sizing, x, y + this->inf->padding_top, inf_width, inf_height, rtl);
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1632 x += inf_width + this->inf->padding_right + INTER_COLUMN_SPACING;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1633 } else {
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1634 x += this->avs->padding_left;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1635 this->avs->AssignSizePosition(sizing, x, y + this->avs->padding_top, avs_width, avs_height, rtl);
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1636 x += avs_width + this->avs->padding_right + INTER_COLUMN_SPACING;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1637 }
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1638
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1639 x += this->acs->padding_left;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1640 this->acs->AssignSizePosition(sizing, x, y + this->acs->padding_top, acs_width, acs_height, rtl);
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1641 x += acs_width + this->acs->padding_right + INTER_COLUMN_SPACING;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1642
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1643 if (rtl) {
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1644 x += this->avs->padding_left;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1645 this->avs->AssignSizePosition(sizing, x, y + this->avs->padding_top, avs_width, avs_height, rtl);
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1646 } else {
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1647 x += this->inf->padding_left;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1648 this->inf->AssignSizePosition(sizing, x, y + this->inf->padding_top, inf_width, inf_height, rtl);
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1649 }
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1650 } else {
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1651 /* Two columns, all space in extra_width goes to both lists. Since the lists are underneath each other,
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1652 * the column is min_list_width wide at least. */
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1653 uint avs_width = ComputeMaxSize(this->avs->smallest_x, this->avs->smallest_x + avs_extra_width + extra_width,
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1654 this->avs->GetHorizontalStepSize(sizing));
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1655 uint acs_width = ComputeMaxSize(this->acs->smallest_x, this->acs->smallest_x + acs_extra_width + extra_width,
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1656 this->acs->GetHorizontalStepSize(sizing));
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1657
16393
b7cc33056746 (svn r21109) -Add: Don't display available newgrfs when the newgrf list is not editable.
alberth <alberth@openttd.org>
parents: 16392
diff changeset
1658 uint min_avs_height = (!this->editable) ? 0 : this->avs->smallest_y + this->avs->padding_top + this->avs->padding_bottom + INTER_LIST_SPACING;
15216
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1659 uint min_acs_height = this->acs->smallest_y + this->acs->padding_top + this->acs->padding_bottom;
16393
b7cc33056746 (svn r21109) -Add: Don't display available newgrfs when the newgrf list is not editable.
alberth <alberth@openttd.org>
parents: 16392
diff changeset
1660 uint extra_height = given_height - min_acs_height - min_avs_height;
15216
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1661
18415
8abe19c16b0b (svn r23251) -Fix: 3-column view of NewGRF GUI had too much space for certain font sizes.
frosch <frosch@openttd.org>
parents: 18413
diff changeset
1662 /* Never use fill_y on these; instead use the INTER_LIST_SPACING as filler */
8abe19c16b0b (svn r23251) -Fix: 3-column view of NewGRF GUI had too much space for certain font sizes.
frosch <frosch@openttd.org>
parents: 18413
diff changeset
1663 uint avs_height = ComputeMaxSize(this->avs->smallest_y, this->avs->smallest_y + extra_height / 2, this->avs->resize_y);
16393
b7cc33056746 (svn r21109) -Add: Don't display available newgrfs when the newgrf list is not editable.
alberth <alberth@openttd.org>
parents: 16392
diff changeset
1664 if (this->editable) extra_height -= avs_height - this->avs->smallest_y;
18415
8abe19c16b0b (svn r23251) -Fix: 3-column view of NewGRF GUI had too much space for certain font sizes.
frosch <frosch@openttd.org>
parents: 18413
diff changeset
1665 uint acs_height = ComputeMaxSize(this->acs->smallest_y, this->acs->smallest_y + extra_height, this->acs->resize_y);
15216
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1666
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1667 /* Assign size and position to the childs. */
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1668 if (rtl) {
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1669 x += this->inf->padding_left;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1670 this->inf->AssignSizePosition(sizing, x, y + this->inf->padding_top, inf_width, inf_height, rtl);
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1671 x += inf_width + this->inf->padding_right + INTER_COLUMN_SPACING;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1672
18415
8abe19c16b0b (svn r23251) -Fix: 3-column view of NewGRF GUI had too much space for certain font sizes.
frosch <frosch@openttd.org>
parents: 18413
diff changeset
1673 this->acs->AssignSizePosition(sizing, x + this->acs->padding_left, y + this->acs->padding_top, acs_width, acs_height, rtl);
16393
b7cc33056746 (svn r21109) -Add: Don't display available newgrfs when the newgrf list is not editable.
alberth <alberth@openttd.org>
parents: 16392
diff changeset
1674 if (this->editable) {
18415
8abe19c16b0b (svn r23251) -Fix: 3-column view of NewGRF GUI had too much space for certain font sizes.
frosch <frosch@openttd.org>
parents: 18413
diff changeset
1675 this->avs->AssignSizePosition(sizing, x + this->avs->padding_left, y + given_height - avs_height - this->avs->padding_bottom, avs_width, avs_height, rtl);
16393
b7cc33056746 (svn r21109) -Add: Don't display available newgrfs when the newgrf list is not editable.
alberth <alberth@openttd.org>
parents: 16392
diff changeset
1676 } else {
b7cc33056746 (svn r21109) -Add: Don't display available newgrfs when the newgrf list is not editable.
alberth <alberth@openttd.org>
parents: 16392
diff changeset
1677 this->avs->AssignSizePosition(sizing, 0, 0, this->avs->smallest_x, this->avs->smallest_y, rtl);
b7cc33056746 (svn r21109) -Add: Don't display available newgrfs when the newgrf list is not editable.
alberth <alberth@openttd.org>
parents: 16392
diff changeset
1678 }
15216
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1679 } else {
18415
8abe19c16b0b (svn r23251) -Fix: 3-column view of NewGRF GUI had too much space for certain font sizes.
frosch <frosch@openttd.org>
parents: 18413
diff changeset
1680 this->acs->AssignSizePosition(sizing, x + this->acs->padding_left, y + this->acs->padding_top, acs_width, acs_height, rtl);
16393
b7cc33056746 (svn r21109) -Add: Don't display available newgrfs when the newgrf list is not editable.
alberth <alberth@openttd.org>
parents: 16392
diff changeset
1681 if (this->editable) {
18415
8abe19c16b0b (svn r23251) -Fix: 3-column view of NewGRF GUI had too much space for certain font sizes.
frosch <frosch@openttd.org>
parents: 18413
diff changeset
1682 this->avs->AssignSizePosition(sizing, x + this->avs->padding_left, y + given_height - avs_height - this->avs->padding_bottom, avs_width, avs_height, rtl);
16393
b7cc33056746 (svn r21109) -Add: Don't display available newgrfs when the newgrf list is not editable.
alberth <alberth@openttd.org>
parents: 16392
diff changeset
1683 } else {
b7cc33056746 (svn r21109) -Add: Don't display available newgrfs when the newgrf list is not editable.
alberth <alberth@openttd.org>
parents: 16392
diff changeset
1684 this->avs->AssignSizePosition(sizing, 0, 0, this->avs->smallest_x, this->avs->smallest_y, rtl);
b7cc33056746 (svn r21109) -Add: Don't display available newgrfs when the newgrf list is not editable.
alberth <alberth@openttd.org>
parents: 16392
diff changeset
1685 }
b7cc33056746 (svn r21109) -Add: Don't display available newgrfs when the newgrf list is not editable.
alberth <alberth@openttd.org>
parents: 16392
diff changeset
1686 uint dx = this->acs->current_x + this->acs->padding_left + this->acs->padding_right;
b7cc33056746 (svn r21109) -Add: Don't display available newgrfs when the newgrf list is not editable.
alberth <alberth@openttd.org>
parents: 16392
diff changeset
1687 if (this->editable) {
b7cc33056746 (svn r21109) -Add: Don't display available newgrfs when the newgrf list is not editable.
alberth <alberth@openttd.org>
parents: 16392
diff changeset
1688 dx = max(dx, this->avs->current_x + this->avs->padding_left + this->avs->padding_right);
b7cc33056746 (svn r21109) -Add: Don't display available newgrfs when the newgrf list is not editable.
alberth <alberth@openttd.org>
parents: 16392
diff changeset
1689 }
b7cc33056746 (svn r21109) -Add: Don't display available newgrfs when the newgrf list is not editable.
alberth <alberth@openttd.org>
parents: 16392
diff changeset
1690 x += dx + INTER_COLUMN_SPACING + this->inf->padding_left;
15216
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1691 this->inf->AssignSizePosition(sizing, x, y + this->inf->padding_top, inf_width, inf_height, rtl);
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1692 }
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1693 }
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1694 }
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1695
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1696 virtual NWidgetCore *GetWidgetFromPos(int x, int y)
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1697 {
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1698 if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return NULL;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1699
16393
b7cc33056746 (svn r21109) -Add: Don't display available newgrfs when the newgrf list is not editable.
alberth <alberth@openttd.org>
parents: 16392
diff changeset
1700 NWidgetCore *nw = (this->editable) ? this->avs->GetWidgetFromPos(x, y) : NULL;
15216
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1701 if (nw == NULL) nw = this->acs->GetWidgetFromPos(x, y);
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1702 if (nw == NULL) nw = this->inf->GetWidgetFromPos(x, y);
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1703 return nw;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1704 }
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1705
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1706 virtual void Draw(const Window *w)
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1707 {
16393
b7cc33056746 (svn r21109) -Add: Don't display available newgrfs when the newgrf list is not editable.
alberth <alberth@openttd.org>
parents: 16392
diff changeset
1708 if (this->editable) this->avs->Draw(w);
15216
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1709 this->acs->Draw(w);
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1710 this->inf->Draw(w);
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1711 }
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1712 };
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1713
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1714 const uint NWidgetNewGRFDisplay::INTER_LIST_SPACING = WD_RESIZEBOX_WIDTH + 1;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1715 const uint NWidgetNewGRFDisplay::INTER_COLUMN_SPACING = WD_RESIZEBOX_WIDTH;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1716 const uint NWidgetNewGRFDisplay::MAX_EXTRA_INFO_WIDTH = 150;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1717 const uint NWidgetNewGRFDisplay::MIN_EXTRA_FOR_3_COLUMNS = 50;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1718
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1719 static const NWidgetPart _nested_newgrf_actives_widgets[] = {
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1720 /* Left side, presets. */
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1721 NWidget(NWID_HORIZONTAL),
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1722 NWidget(WWT_TEXT, COLOUR_MAUVE), SetDataTip(STR_NEWGRF_SETTINGS_SELECT_PRESET, STR_NULL),
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1723 SetPadding(0, WD_FRAMETEXT_RIGHT, 0, 0),
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1724 NWidget(WWT_DROPDOWN, COLOUR_YELLOW, WID_NS_PRESET_LIST), SetFill(1, 0), SetResize(1, 0),
15216
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1725 SetDataTip(STR_JUST_STRING, STR_NEWGRF_SETTINGS_PRESET_LIST_TOOLTIP),
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1726 EndContainer(),
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1727 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1728 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NS_PRESET_SAVE), SetFill(1, 0), SetResize(1, 0),
15216
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1729 SetDataTip(STR_NEWGRF_SETTINGS_PRESET_SAVE, STR_NEWGRF_SETTINGS_PRESET_SAVE_TOOLTIP),
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1730 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NS_PRESET_DELETE), SetFill(1, 0), SetResize(1, 0),
15216
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1731 SetDataTip(STR_NEWGRF_SETTINGS_PRESET_DELETE, STR_NEWGRF_SETTINGS_PRESET_DELETE_TOOLTIP),
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1732 EndContainer(),
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1733
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1734 NWidget(NWID_SPACER), SetMinimalSize(0, WD_RESIZEBOX_WIDTH), SetResize(1, 0), SetFill(1, 0),
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1735 NWidget(WWT_PANEL, COLOUR_MAUVE),
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1736 NWidget(WWT_LABEL, COLOUR_MAUVE), SetDataTip(STR_NEWGRF_SETTINGS_ACTIVE_LIST, STR_NULL),
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1737 SetFill(1, 0), SetResize(1, 0), SetPadding(3, WD_FRAMETEXT_RIGHT, 0, WD_FRAMETEXT_LEFT),
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1738 /* Left side, active grfs. */
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1739 NWidget(NWID_HORIZONTAL), SetPadding(0, 2, 0, 2),
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1740 NWidget(WWT_PANEL, COLOUR_MAUVE),
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1741 NWidget(WWT_INSET, COLOUR_MAUVE, WID_NS_FILE_LIST), SetMinimalSize(100, 1), SetPadding(2, 2, 2, 2),
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1742 SetFill(1, 1), SetResize(1, 1), SetScrollbar(WID_NS_SCROLLBAR), SetDataTip(STR_NULL, STR_NEWGRF_SETTINGS_FILE_TOOLTIP),
15216
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1743 EndContainer(),
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1744 EndContainer(),
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1745 NWidget(NWID_VSCROLLBAR, COLOUR_MAUVE, WID_NS_SCROLLBAR),
15216
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1746 EndContainer(),
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1747 /* Buttons. */
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1748 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_NS_SHOW_REMOVE),
16394
82aa3e68581d (svn r21110) -Add: Tidy up the buttons of the active newgrfs list.
alberth <alberth@openttd.org>
parents: 16393
diff changeset
1749 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPadding(2, 2, 2, 2), SetPIP(0, WD_RESIZEBOX_WIDTH, 0),
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1750 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NS_REMOVE), SetFill(1, 0), SetResize(1, 0),
16394
82aa3e68581d (svn r21110) -Add: Tidy up the buttons of the active newgrfs list.
alberth <alberth@openttd.org>
parents: 16393
diff changeset
1751 SetDataTip(STR_NEWGRF_SETTINGS_REMOVE, STR_NEWGRF_SETTINGS_REMOVE_TOOLTIP),
82aa3e68581d (svn r21110) -Add: Tidy up the buttons of the active newgrfs list.
alberth <alberth@openttd.org>
parents: 16393
diff changeset
1752 NWidget(NWID_VERTICAL),
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1753 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NS_MOVE_UP), SetFill(1, 0), SetResize(1, 0),
16394
82aa3e68581d (svn r21110) -Add: Tidy up the buttons of the active newgrfs list.
alberth <alberth@openttd.org>
parents: 16393
diff changeset
1754 SetDataTip(STR_NEWGRF_SETTINGS_MOVEUP, STR_NEWGRF_SETTINGS_MOVEUP_TOOLTIP),
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1755 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NS_MOVE_DOWN), SetFill(1, 0), SetResize(1, 0),
16394
82aa3e68581d (svn r21110) -Add: Tidy up the buttons of the active newgrfs list.
alberth <alberth@openttd.org>
parents: 16393
diff changeset
1756 SetDataTip(STR_NEWGRF_SETTINGS_MOVEDOWN, STR_NEWGRF_SETTINGS_MOVEDOWN_TOOLTIP),
82aa3e68581d (svn r21110) -Add: Tidy up the buttons of the active newgrfs list.
alberth <alberth@openttd.org>
parents: 16393
diff changeset
1757 EndContainer(),
82aa3e68581d (svn r21110) -Add: Tidy up the buttons of the active newgrfs list.
alberth <alberth@openttd.org>
parents: 16393
diff changeset
1758 EndContainer(),
82aa3e68581d (svn r21110) -Add: Tidy up the buttons of the active newgrfs list.
alberth <alberth@openttd.org>
parents: 16393
diff changeset
1759
82aa3e68581d (svn r21110) -Add: Tidy up the buttons of the active newgrfs list.
alberth <alberth@openttd.org>
parents: 16393
diff changeset
1760 NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPadding(2, 2, 2, 2),
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1761 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NS_RESCAN_FILES2), SetFill(1, 0), SetResize(1, 0),
16394
82aa3e68581d (svn r21110) -Add: Tidy up the buttons of the active newgrfs list.
alberth <alberth@openttd.org>
parents: 16393
diff changeset
1762 SetDataTip(STR_NEWGRF_SETTINGS_RESCAN_FILES, STR_NEWGRF_SETTINGS_RESCAN_FILES_TOOLTIP),
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1763 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NS_CONTENT_DOWNLOAD2), SetFill(1, 0), SetResize(1, 0),
16394
82aa3e68581d (svn r21110) -Add: Tidy up the buttons of the active newgrfs list.
alberth <alberth@openttd.org>
parents: 16393
diff changeset
1764 SetDataTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
15216
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1765 EndContainer(),
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1766 EndContainer(),
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1767 EndContainer(),
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1768 };
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1769
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1770 static const NWidgetPart _nested_newgrf_availables_widgets[] = {
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1771 NWidget(WWT_PANEL, COLOUR_MAUVE),
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1772 NWidget(WWT_LABEL, COLOUR_MAUVE), SetDataTip(STR_NEWGRF_SETTINGS_INACTIVE_LIST, STR_NULL),
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1773 SetFill(1, 0), SetResize(1, 0), SetPadding(3, WD_FRAMETEXT_RIGHT, 0, WD_FRAMETEXT_LEFT),
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1774 /* Left side, available grfs, filter edit box. */
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1775 NWidget(NWID_HORIZONTAL), SetPadding(WD_TEXTPANEL_TOP, 0, WD_TEXTPANEL_BOTTOM, 0),
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1776 SetPIP(WD_FRAMETEXT_LEFT, WD_FRAMETEXT_RIGHT, WD_FRAMETEXT_RIGHT),
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1777 NWidget(WWT_TEXT, COLOUR_MAUVE), SetFill(0, 1), SetDataTip(STR_NEWGRF_FILTER_TITLE, STR_NULL),
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1778 NWidget(WWT_EDITBOX, COLOUR_MAUVE, WID_NS_FILTER), SetFill(1, 0), SetMinimalSize(50, 12), SetResize(1, 0),
15216
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1779 SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1780 EndContainer(),
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1781 /* Left side, available grfs. */
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1782 NWidget(NWID_HORIZONTAL), SetPadding(0, 2, 0, 2),
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1783 NWidget(WWT_PANEL, COLOUR_MAUVE),
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1784 NWidget(WWT_INSET, COLOUR_MAUVE, WID_NS_AVAIL_LIST), SetMinimalSize(100, 1), SetPadding(2, 2, 2, 2),
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1785 SetFill(1, 1), SetResize(1, 1), SetScrollbar(WID_NS_SCROLL2BAR),
15216
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1786 EndContainer(),
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1787 EndContainer(),
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1788 NWidget(NWID_VSCROLLBAR, COLOUR_MAUVE, WID_NS_SCROLL2BAR),
15216
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1789 EndContainer(),
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1790 /* Left side, available grfs, buttons. */
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1791 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPadding(2, 2, 2, 2), SetPIP(0, WD_RESIZEBOX_WIDTH, 0),
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1792 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NS_ADD), SetFill(1, 0), SetResize(1, 0),
15216
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1793 SetDataTip(STR_NEWGRF_SETTINGS_ADD, STR_NEWGRF_SETTINGS_ADD_FILE_TOOLTIP),
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1794 NWidget(NWID_VERTICAL),
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1795 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NS_RESCAN_FILES), SetFill(1, 0), SetResize(1, 0),
15216
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1796 SetDataTip(STR_NEWGRF_SETTINGS_RESCAN_FILES, STR_NEWGRF_SETTINGS_RESCAN_FILES_TOOLTIP),
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1797 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NS_CONTENT_DOWNLOAD), SetFill(1, 0), SetResize(1, 0),
15216
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1798 SetDataTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1799 EndContainer(),
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1800 EndContainer(),
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1801 EndContainer(),
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1802 };
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1803
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1804 static const NWidgetPart _nested_newgrf_infopanel_widgets[] = {
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1805 /* Right side, info panel. */
18413
e5c315e27c0a (svn r23249) -Feature: Also allow viewing of the other two textfiles supplied by BaNaNaS tars, i.e. changelog and license.
frosch <frosch@openttd.org>
parents: 18412
diff changeset
1806 NWidget(NWID_VERTICAL), SetPadding(0, 0, 2, 0),
e5c315e27c0a (svn r23249) -Feature: Also allow viewing of the other two textfiles supplied by BaNaNaS tars, i.e. changelog and license.
frosch <frosch@openttd.org>
parents: 18412
diff changeset
1807 NWidget(WWT_PANEL, COLOUR_MAUVE), SetPadding(0, 0, 2, 0),
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1808 NWidget(WWT_EMPTY, COLOUR_MAUVE, WID_NS_NEWGRF_INFO_TITLE), SetFill(1, 0), SetResize(1, 0),
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1809 NWidget(WWT_EMPTY, COLOUR_MAUVE, WID_NS_NEWGRF_INFO), SetFill(1, 1), SetResize(1, 1), SetMinimalSize(150, 100),
18413
e5c315e27c0a (svn r23249) -Feature: Also allow viewing of the other two textfiles supplied by BaNaNaS tars, i.e. changelog and license.
frosch <frosch@openttd.org>
parents: 18412
diff changeset
1810 EndContainer(),
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1811 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NS_OPEN_URL), SetFill(1, 0), SetResize(1, 0),
18648
f68b9653f952 (svn r23495) -Feature: button in NewGRF window to open URL from action14
yexo <yexo@openttd.org>
parents: 18627
diff changeset
1812 SetDataTip(STR_CONTENT_OPEN_URL, STR_CONTENT_OPEN_URL_TOOLTIP),
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1813 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NS_NEWGRF_TEXTFILE + TFT_README), SetFill(1, 0), SetResize(1, 0),
19079
0af594336a81 (svn r23933) -Codechange: make the text file window strings more generic (LordAro)
rubidium <rubidium@openttd.org>
parents: 19078
diff changeset
1814 SetDataTip(STR_TEXTFILE_VIEW_README, STR_NULL),
18413
e5c315e27c0a (svn r23249) -Feature: Also allow viewing of the other two textfiles supplied by BaNaNaS tars, i.e. changelog and license.
frosch <frosch@openttd.org>
parents: 18412
diff changeset
1815 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1816 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NS_NEWGRF_TEXTFILE + TFT_CHANGELOG), SetFill(1, 0), SetResize(1, 0),
19079
0af594336a81 (svn r23933) -Codechange: make the text file window strings more generic (LordAro)
rubidium <rubidium@openttd.org>
parents: 19078
diff changeset
1817 SetDataTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_NULL),
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1818 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NS_NEWGRF_TEXTFILE + TFT_LICENSE), SetFill(1, 0), SetResize(1, 0),
19079
0af594336a81 (svn r23933) -Codechange: make the text file window strings more generic (LordAro)
rubidium <rubidium@openttd.org>
parents: 19078
diff changeset
1819 SetDataTip(STR_TEXTFILE_VIEW_LICENCE, STR_NULL),
18413
e5c315e27c0a (svn r23249) -Feature: Also allow viewing of the other two textfiles supplied by BaNaNaS tars, i.e. changelog and license.
frosch <frosch@openttd.org>
parents: 18412
diff changeset
1820 EndContainer(),
15216
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1821 EndContainer(),
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1822 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_NS_SHOW_APPLY),
16395
2bef44471f4d (svn r21111) -Add: Remove the buttons below the newgrf details if the list is not editable.
alberth <alberth@openttd.org>
parents: 16394
diff changeset
1823 /* Right side, buttons. */
2bef44471f4d (svn r21111) -Add: Remove the buttons below the newgrf details if the list is not editable.
alberth <alberth@openttd.org>
parents: 16394
diff changeset
1824 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(0, WD_RESIZEBOX_WIDTH, 0),
2bef44471f4d (svn r21111) -Add: Remove the buttons below the newgrf details if the list is not editable.
alberth <alberth@openttd.org>
parents: 16394
diff changeset
1825 NWidget(NWID_VERTICAL),
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1826 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NS_SET_PARAMETERS), SetFill(1, 0), SetResize(1, 0),
16395
2bef44471f4d (svn r21111) -Add: Remove the buttons below the newgrf details if the list is not editable.
alberth <alberth@openttd.org>
parents: 16394
diff changeset
1827 SetDataTip(STR_NEWGRF_SETTINGS_SET_PARAMETERS, STR_NULL),
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1828 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NS_TOGGLE_PALETTE), SetFill(1, 0), SetResize(1, 0),
16395
2bef44471f4d (svn r21111) -Add: Remove the buttons below the newgrf details if the list is not editable.
alberth <alberth@openttd.org>
parents: 16394
diff changeset
1829 SetDataTip(STR_NEWGRF_SETTINGS_TOGGLE_PALETTE, STR_NEWGRF_SETTINGS_TOGGLE_PALETTE_TOOLTIP),
2bef44471f4d (svn r21111) -Add: Remove the buttons below the newgrf details if the list is not editable.
alberth <alberth@openttd.org>
parents: 16394
diff changeset
1830 EndContainer(),
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1831 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NS_APPLY_CHANGES), SetFill(1, 0), SetResize(1, 0),
16395
2bef44471f4d (svn r21111) -Add: Remove the buttons below the newgrf details if the list is not editable.
alberth <alberth@openttd.org>
parents: 16394
diff changeset
1832 SetDataTip(STR_NEWGRF_SETTINGS_APPLY_CHANGES, STR_NULL),
15216
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1833 EndContainer(),
18911
e48659f8d5c4 (svn r23760) -Feature: Allow readonly display of NewGRF parameters, if GRF list may not be edited.
frosch <frosch@openttd.org>
parents: 18908
diff changeset
1834 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NS_VIEW_PARAMETERS), SetFill(1, 0), SetResize(1, 0),
e48659f8d5c4 (svn r23760) -Feature: Allow readonly display of NewGRF parameters, if GRF list may not be edited.
frosch <frosch@openttd.org>
parents: 18908
diff changeset
1835 SetDataTip(STR_NEWGRF_SETTINGS_SHOW_PARAMETERS, STR_NULL),
15216
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1836 EndContainer(),
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1837 };
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1838
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1839 /** Construct nested container widget for managing the lists and the info panel of the NewGRF GUI. */
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1840 NWidgetBase* NewGRFDisplay(int *biggest_index)
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1841 {
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1842 NWidgetBase *avs = MakeNWidgets(_nested_newgrf_availables_widgets, lengthof(_nested_newgrf_availables_widgets), biggest_index, NULL);
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1843
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1844 int biggest2;
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1845 NWidgetBase *acs = MakeNWidgets(_nested_newgrf_actives_widgets, lengthof(_nested_newgrf_actives_widgets), &biggest2, NULL);
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1846 *biggest_index = max(*biggest_index, biggest2);
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1847
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1848 NWidgetBase *inf = MakeNWidgets(_nested_newgrf_infopanel_widgets, lengthof(_nested_newgrf_infopanel_widgets), &biggest2, NULL);
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1849 *biggest_index = max(*biggest_index, biggest2);
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1850
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1851 return new NWidgetNewGRFDisplay(avs, acs, inf);
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1852 }
15208
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1853
8025
7a501cf42789 (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13 <skidd13@openttd.org>
parents: 8019
diff changeset
1854 /* Widget definition of the manage newgrfs window */
11796
b89215528d20 (svn r16186) -Codechange: Adding nested widgets to _newgrf_desc and _newgrf_add_dlg_desc window descriptions.
alberth <alberth@openttd.org>
parents: 11795
diff changeset
1855 static const NWidgetPart _nested_newgrf_widgets[] = {
b89215528d20 (svn r16186) -Codechange: Adding nested widgets to _newgrf_desc and _newgrf_add_dlg_desc window descriptions.
alberth <alberth@openttd.org>
parents: 11795
diff changeset
1856 NWidget(NWID_HORIZONTAL),
13752
517d77f53919 (svn r18277) -Codechange: remove unneeded widget indices for close, resize and sticky boxes and for window captions
rubidium <rubidium@openttd.org>
parents: 13749
diff changeset
1857 NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
517d77f53919 (svn r18277) -Codechange: remove unneeded widget indices for close, resize and sticky boxes and for window captions
rubidium <rubidium@openttd.org>
parents: 13749
diff changeset
1858 NWidget(WWT_CAPTION, COLOUR_MAUVE), SetDataTip(STR_NEWGRF_SETTINGS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
11796
b89215528d20 (svn r16186) -Codechange: Adding nested widgets to _newgrf_desc and _newgrf_add_dlg_desc window descriptions.
alberth <alberth@openttd.org>
parents: 11795
diff changeset
1859 EndContainer(),
13755
bf8a4ced15fe (svn r18280) -Codechange: remove widget indices that are not needed for custom drawing/handling input
rubidium <rubidium@openttd.org>
parents: 13752
diff changeset
1860 NWidget(WWT_PANEL, COLOUR_MAUVE),
15216
7be3e18b9c57 (svn r19845) -Feature: Dynamically switch between 2 and 3 column NewGRF gui for improved user experience.
alberth <alberth@openttd.org>
parents: 15212
diff changeset
1861 NWidgetFunction(NewGRFDisplay), SetPadding(WD_RESIZEBOX_WIDTH, WD_RESIZEBOX_WIDTH, 2, WD_RESIZEBOX_WIDTH),
15211
e28e566488a9 (svn r19840) -Add: Add 'rescan' functionality to the NewGRF window.
alberth <alberth@openttd.org>
parents: 15209
diff changeset
1862 /* Resize button. */
e28e566488a9 (svn r19840) -Add: Add 'rescan' functionality to the NewGRF window.
alberth <alberth@openttd.org>
parents: 15209
diff changeset
1863 NWidget(NWID_HORIZONTAL),
e28e566488a9 (svn r19840) -Add: Add 'rescan' functionality to the NewGRF window.
alberth <alberth@openttd.org>
parents: 15209
diff changeset
1864 NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
e28e566488a9 (svn r19840) -Add: Add 'rescan' functionality to the NewGRF window.
alberth <alberth@openttd.org>
parents: 15209
diff changeset
1865 NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
e28e566488a9 (svn r19840) -Add: Add 'rescan' functionality to the NewGRF window.
alberth <alberth@openttd.org>
parents: 15209
diff changeset
1866 EndContainer(),
11796
b89215528d20 (svn r16186) -Codechange: Adding nested widgets to _newgrf_desc and _newgrf_add_dlg_desc window descriptions.
alberth <alberth@openttd.org>
parents: 11795
diff changeset
1867 EndContainer(),
b89215528d20 (svn r16186) -Codechange: Adding nested widgets to _newgrf_desc and _newgrf_add_dlg_desc window descriptions.
alberth <alberth@openttd.org>
parents: 11795
diff changeset
1868 };
b89215528d20 (svn r16186) -Codechange: Adding nested widgets to _newgrf_desc and _newgrf_add_dlg_desc window descriptions.
alberth <alberth@openttd.org>
parents: 11795
diff changeset
1869
8025
7a501cf42789 (svn r11585) -Codechange: Enumify the widgets of the newGRF gui and a slight cleanup there
skidd13 <skidd13@openttd.org>
parents: 8019
diff changeset
1870 /* Window definition of the manage newgrfs window */
11373
474ba6cc0946 (svn r15723) -Codechange: use a constructor for WindowDescs as that makes expanding them much easier (Alberth)
rubidium <rubidium@openttd.org>
parents: 11208
diff changeset
1871 static const WindowDesc _newgrf_desc(
13796
3e68f07eb821 (svn r18322) -Codechange: remove the WDP duplication; no need to tell the same twice.
rubidium <rubidium@openttd.org>
parents: 13755
diff changeset
1872 WDP_CENTER, 300, 263,
5893
8547517ef719 (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium <rubidium@openttd.org>
parents: 5668
diff changeset
1873 WC_GAME_OPTIONS, WC_NONE,
19767
2a11204038e3 (svn r24700) -Cleanup: Remove WDF_UNCLICK_BUTTONS and make it the default.
frosch <frosch@openttd.org>
parents: 19560
diff changeset
1874 0,
13564
bae287664b02 (svn r18086) -Codechange: remove 'widget' from WindowDesc
rubidium <rubidium@openttd.org>
parents: 13419
diff changeset
1875 _nested_newgrf_widgets, lengthof(_nested_newgrf_widgets)
11373
474ba6cc0946 (svn r15723) -Codechange: use a constructor for WindowDescs as that makes expanding them much easier (Alberth)
rubidium <rubidium@openttd.org>
parents: 11208
diff changeset
1876 );
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1877
15620
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
1878 /**
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
1879 * Callback function for the newgrf 'apply changes' confirmation window
9207
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
1880 * @param w Window which is calling this callback
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
1881 * @param confirmed boolean value, true when yes was clicked, false otherwise
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
1882 */
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
1883 static void NewGRFConfirmationCallback(Window *w, bool confirmed)
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
1884 {
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
1885 if (confirmed) {
16116
50a0ec38c886 (svn r20812) -Fix [FS#4125]: crash when confirming newgrf changes with the newgrf parameter window open
yexo <yexo@openttd.org>
parents: 16086
diff changeset
1886 DeleteWindowByClass(WC_GRF_PARAMETERS);
9207
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
1887 NewGRFWindow *nw = dynamic_cast<NewGRFWindow*>(w);
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
1888
9457
267a95510fdf (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz <smatz@openttd.org>
parents: 9317
diff changeset
1889 GamelogStartAction(GLAT_GRF);
15203
2ef926c44a98 (svn r19832) -Codechange: Rename variables list->actives, sel->active_sel.
alberth <alberth@openttd.org>
parents: 15202
diff changeset
1890 GamelogGRFUpdate(_grfconfig, nw->actives); // log GRF changes
2ef926c44a98 (svn r19832) -Codechange: Rename variables list->actives, sel->active_sel.
alberth <alberth@openttd.org>
parents: 15202
diff changeset
1891 CopyGRFConfigList(nw->orig_list, nw->actives, false);
9207
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
1892 ReloadNewGRFData();
9457
267a95510fdf (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz <smatz@openttd.org>
parents: 9317
diff changeset
1893 GamelogStopAction();
9207
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
1894
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
1895 /* Show new, updated list */
15201
071e920abcfb (svn r19830) -Codechange: Move variable declarations to their first use.
alberth <alberth@openttd.org>
parents: 15200
diff changeset
1896 GRFConfig *c;
071e920abcfb (svn r19830) -Codechange: Move variable declarations to their first use.
alberth <alberth@openttd.org>
parents: 15200
diff changeset
1897 int i = 0;
15203
2ef926c44a98 (svn r19832) -Codechange: Rename variables list->actives, sel->active_sel.
alberth <alberth@openttd.org>
parents: 15202
diff changeset
1898 for (c = nw->actives; c != NULL && c != nw->active_sel; c = c->next, i++) {}
2ef926c44a98 (svn r19832) -Codechange: Rename variables list->actives, sel->active_sel.
alberth <alberth@openttd.org>
parents: 15202
diff changeset
1899 CopyGRFConfigList(&nw->actives, *nw->orig_list, false);
2ef926c44a98 (svn r19832) -Codechange: Rename variables list->actives, sel->active_sel.
alberth <alberth@openttd.org>
parents: 15202
diff changeset
1900 for (c = nw->actives; c != NULL && i > 0; c = c->next, i--) {}
2ef926c44a98 (svn r19832) -Codechange: Rename variables list->actives, sel->active_sel.
alberth <alberth@openttd.org>
parents: 15202
diff changeset
1901 nw->active_sel = c;
15208
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1902 nw->avails.ForceRebuild();
9207
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
1903
15208
ebff51f3984b (svn r19837) -Change: Display list of available (non-active) grfs in the NewGRF window.
alberth <alberth@openttd.org>
parents: 15207
diff changeset
1904 w->InvalidateData();
15982
62befe1b097c (svn r20670) -Add: support for action F
rubidium <rubidium@openttd.org>
parents: 15920
diff changeset
1905
62befe1b097c (svn r20670) -Add: support for action F
rubidium <rubidium@openttd.org>
parents: 15920
diff changeset
1906 ReInitAllWindows();
62befe1b097c (svn r20670) -Add: support for action F
rubidium <rubidium@openttd.org>
parents: 15920
diff changeset
1907 DeleteWindowByClass(WC_BUILD_OBJECT);
9207
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
1908 }
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
1909 }
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
1910
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
1911
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1912
15620
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
1913 /**
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
1914 * Setup the NewGRF gui
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1915 * @param editable allow the user to make changes to the grfconfig in the window
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1916 * @param show_params show information about what parameters are set for the grf files
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1917 * @param exec_changes if changes are made to the list (editable is true), apply these
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1918 * changes immediately or only update the list
15623
c62577640878 (svn r20286) -Codechange: Unify end of doxygen comments.
frosch <frosch@openttd.org>
parents: 15620
diff changeset
1919 * @param config pointer to a linked-list of grfconfig's that will be shown
c62577640878 (svn r20286) -Codechange: Unify end of doxygen comments.
frosch <frosch@openttd.org>
parents: 15620
diff changeset
1920 */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1921 void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1922 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1923 DeleteWindowByClass(WC_GAME_OPTIONS);
9207
839a532bf0f6 (svn r13073) -Codechange: make classes of the NewGRF windows
peter1138 <peter1138@openttd.org>
parents: 9164
diff changeset
1924 new NewGRFWindow(&_newgrf_desc, editable, show_params, exec_changes, config);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1925 }
17988
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1926
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1927 /** Widgets for the progress window. */
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1928 static const NWidgetPart _nested_scan_progress_widgets[] = {
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1929 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_NEWGRF_SCAN_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1930 NWidget(WWT_PANEL, COLOUR_GREY),
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1931 NWidget(NWID_HORIZONTAL), SetPIP(20, 0, 20),
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1932 NWidget(NWID_VERTICAL), SetPIP(11, 8, 11),
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1933 NWidget(WWT_LABEL, INVALID_COLOUR), SetDataTip(STR_NEWGRF_SCAN_MESSAGE, STR_NULL), SetFill(1, 0),
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1934 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_SP_PROGRESS_BAR), SetFill(1, 0),
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1935 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_SP_PROGRESS_TEXT), SetFill(1, 0),
17988
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1936 EndContainer(),
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1937 EndContainer(),
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1938 EndContainer(),
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1939 };
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1940
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1941 /** Description of the widgets and other settings of the window. */
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1942 static const WindowDesc _scan_progress_desc(
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1943 WDP_CENTER, 0, 0,
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1944 WC_MODAL_PROGRESS, WC_NONE,
19767
2a11204038e3 (svn r24700) -Cleanup: Remove WDF_UNCLICK_BUTTONS and make it the default.
frosch <frosch@openttd.org>
parents: 19560
diff changeset
1945 0,
17988
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1946 _nested_scan_progress_widgets, lengthof(_nested_scan_progress_widgets)
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1947 );
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1948
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1949 /** Window for showing the progress of NewGRF scanning. */
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1950 struct ScanProgressWindow : public Window {
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1951 char *last_name; ///< The name of the last 'seen' NewGRF.
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1952 int scanned; ///< The number of NewGRFs that we have seen.
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1953
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1954 /** Create the window. */
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1955 ScanProgressWindow() : Window(), last_name(NULL), scanned(0)
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1956 {
18753
8d2cdabac894 (svn r23601) -Fix: fix the conflict in window number
truebrain <truebrain@openttd.org>
parents: 18742
diff changeset
1957 this->InitNested(&_scan_progress_desc, 1);
17988
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1958 }
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1959
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1960 /** Free the last name buffer. */
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1961 ~ScanProgressWindow()
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1962 {
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1963 free(last_name);
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1964 }
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1965
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1966 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1967 {
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1968 switch (widget) {
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1969 case WID_SP_PROGRESS_BAR: {
17988
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1970 SetDParam(0, 100);
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1971 *size = GetStringBoundingBox(STR_GENERATION_PROGRESS);
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1972 /* We need some spacing for the 'border' */
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1973 size->height += 8;
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1974 size->width += 8;
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1975 break;
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1976 }
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1977
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1978 case WID_SP_PROGRESS_TEXT:
17988
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1979 SetDParam(0, 9999);
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1980 SetDParam(1, 9999);
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1981 /* We really don't know the width. We could determine it by scanning the NewGRFs,
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1982 * but this is the status window for scanning them... */
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1983 size->width = max(400U, GetStringBoundingBox(STR_NEWGRF_SCAN_STATUS).width);
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1984 size->height = FONT_HEIGHT_NORMAL * 2 + WD_PAR_VSEP_NORMAL;
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1985 break;
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1986 }
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1987 }
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1988
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1989 virtual void DrawWidget(const Rect &r, int widget) const
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1990 {
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1991 switch (widget) {
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
1992 case WID_SP_PROGRESS_BAR: {
17988
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1993 /* Draw the % complete with a bar and a text */
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1994 DrawFrameRect(r.left, r.top, r.right, r.bottom, COLOUR_GREY, FR_BORDERONLY);
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1995 uint percent = scanned * 100 / max(1U, _settings_client.gui.last_newgrf_count);
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1996 DrawFrameRect(r.left + 1, r.top + 1, (int)((r.right - r.left - 2) * percent / 100) + r.left + 1, r.bottom - 1, COLOUR_MAUVE, FR_NONE);
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1997 SetDParam(0, percent);
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1998 DrawString(r.left, r.right, r.top + 5, STR_GENERATION_PROGRESS, TC_FROMSTRING, SA_HOR_CENTER);
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
1999 break;
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
2000 }
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
2001
18695
7abb0c8c8227 (svn r23543) -Codechange: Document and name consistently widgets of NewGRF window
planetmaker <planetmaker@openttd.org>
parents: 18681
diff changeset
2002 case WID_SP_PROGRESS_TEXT:
17988
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
2003 SetDParam(0, this->scanned);
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
2004 SetDParam(1, _settings_client.gui.last_newgrf_count);
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
2005 DrawString(r.left, r.right, r.top, STR_NEWGRF_SCAN_STATUS, TC_FROMSTRING, SA_HOR_CENTER);
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
2006
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
2007 DrawString(r.left, r.right, r.top + FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL, this->last_name == NULL ? "" : this->last_name, TC_BLACK, SA_HOR_CENTER);
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
2008 break;
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
2009 }
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
2010 }
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
2011
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
2012 /**
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
2013 * Update the NewGRF scan status.
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
2014 * @param num The number of NewGRFs scanned so far.
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
2015 * @param name The name of the last scanned NewGRF.
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
2016 */
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
2017 void UpdateNewGRFScanStatus(uint num, const char *name)
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
2018 {
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
2019 free(this->last_name);
18011
9243bb1fc073 (svn r22820) -Codechange: perform a full (re)draw cycle in the first draw during progress instead of waiting 200ms
rubidium <rubidium@openttd.org>
parents: 17988
diff changeset
2020 if (name == NULL) {
9243bb1fc073 (svn r22820) -Codechange: perform a full (re)draw cycle in the first draw during progress instead of waiting 200ms
rubidium <rubidium@openttd.org>
parents: 17988
diff changeset
2021 char buf[256];
9243bb1fc073 (svn r22820) -Codechange: perform a full (re)draw cycle in the first draw during progress instead of waiting 200ms
rubidium <rubidium@openttd.org>
parents: 17988
diff changeset
2022 GetString(buf, STR_NEWGRF_SCAN_ARCHIVES, lastof(buf));
9243bb1fc073 (svn r22820) -Codechange: perform a full (re)draw cycle in the first draw during progress instead of waiting 200ms
rubidium <rubidium@openttd.org>
parents: 17988
diff changeset
2023 this->last_name = strdup(buf);
9243bb1fc073 (svn r22820) -Codechange: perform a full (re)draw cycle in the first draw during progress instead of waiting 200ms
rubidium <rubidium@openttd.org>
parents: 17988
diff changeset
2024 } else {
9243bb1fc073 (svn r22820) -Codechange: perform a full (re)draw cycle in the first draw during progress instead of waiting 200ms
rubidium <rubidium@openttd.org>
parents: 17988
diff changeset
2025 this->last_name = strdup(name);
9243bb1fc073 (svn r22820) -Codechange: perform a full (re)draw cycle in the first draw during progress instead of waiting 200ms
rubidium <rubidium@openttd.org>
parents: 17988
diff changeset
2026 }
17988
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
2027 this->scanned = num;
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
2028 if (num > _settings_client.gui.last_newgrf_count) _settings_client.gui.last_newgrf_count = num;
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
2029
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
2030 this->SetDirty();
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
2031 }
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
2032 };
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
2033
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
2034 /**
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
2035 * Update the NewGRF scan status.
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
2036 * @param num The number of NewGRFs scanned so far.
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
2037 * @param name The name of the last scanned NewGRF.
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
2038 */
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
2039 void UpdateNewGRFScanStatus(uint num, const char *name)
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
2040 {
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
2041 ScanProgressWindow *w = dynamic_cast<ScanProgressWindow *>(FindWindowByClass(WC_MODAL_PROGRESS));
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
2042 if (w == NULL) w = new ScanProgressWindow();
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
2043 w->UpdateNewGRFScanStatus(num, name);
77b13e743894 (svn r22797) -Add: progress bar for scanning NewGRFs
rubidium <rubidium@openttd.org>
parents: 17982
diff changeset
2044 }