author | truebrain |
Fri, 13 Jun 2008 19:57:25 +0000 | |
branch | noai |
changeset 10957 | 7a140b4cd91d |
parent 10829 | 8a0ec0f0f928 |
permissions | -rw-r--r-- |
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
1 |
/* $Id$ */ |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
2 |
|
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
9826
diff
changeset
|
3 |
/** @file newgrf_gui.cpp GUI to change NewGRF settings. */ |
9505 | 4 |
|
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
5 |
#include "stdafx.h" |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
6 |
#include "openttd.h" |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
7 |
#include "variables.h" |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
8 |
#include "gui.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
9 |
#include "window_gui.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
10 |
#include "textbuf_gui.h" |
5352
82a50c80b0c4
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5345
diff
changeset
|
11 |
#include "newgrf.h" |
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
12 |
#include "newgrf_config.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
13 |
#include "strings_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
14 |
#include "window_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
15 |
#include "core/alloc_func.hpp" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
16 |
#include "string_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
17 |
#include "gfx_func.h" |
10829 | 18 |
#include "gamelog.h" |
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
19 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
20 |
#include "table/strings.h" |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
21 |
#include "table/sprites.h" |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
22 |
|
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
23 |
/** Parse an integerlist string and set each found value |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
24 |
* @param p the string to be parsed. Each element in the list is seperated by a |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
25 |
* comma or a space character |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
26 |
* @param items pointer to the integerlist-array that will be filled with values |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
27 |
* @param maxitems the maximum number of elements the integerlist-array has |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
28 |
* @return returns the number of items found, or -1 on an error */ |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
29 |
static int parse_intlist(const char *p, int *items, int maxitems) |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
30 |
{ |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
31 |
int n = 0, v; |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
32 |
char *end; |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
33 |
|
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
34 |
for (;;) { |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
35 |
v = strtol(p, &end, 0); |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
36 |
if (p == end || n == maxitems) return -1; |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
37 |
p = end; |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
38 |
items[n++] = v; |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
39 |
if (*p == '\0') break; |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
40 |
if (*p != ',' && *p != ' ') return -1; |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
41 |
p++; |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
42 |
} |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
43 |
|
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
44 |
return n; |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
45 |
} |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
46 |
|
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
47 |
|
9545 | 48 |
static void ShowNewGRFInfo(const GRFConfig *c, uint x, uint y, uint w, uint bottom, bool show_params) |
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
49 |
{ |
5885
262234e81333
(svn r8093) -Codechange: Add a function to get a string representation of an MD5SUM and use it.
Darkvater
parents:
5860
diff
changeset
|
50 |
char buff[256]; |
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
51 |
|
6429
02c062eb2c74
(svn r8838) -Feature: Show newgrf error messages loaded in Action B in the newgrf gui
maedhros
parents:
6144
diff
changeset
|
52 |
if (c->error != NULL) { |
6465
dddb39b41ee0
(svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents:
6429
diff
changeset
|
53 |
SetDParamStr(0, c->filename); |
9627 | 54 |
SetDParamStr(1, c->error->data); |
6465
dddb39b41ee0
(svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents:
6429
diff
changeset
|
55 |
for (uint i = 0; i < c->error->num_params; i++) { |
dddb39b41ee0
(svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents:
6429
diff
changeset
|
56 |
uint32 param = 0; |
dddb39b41ee0
(svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents:
6429
diff
changeset
|
57 |
byte param_number = c->error->param_number[i]; |
dddb39b41ee0
(svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents:
6429
diff
changeset
|
58 |
|
dddb39b41ee0
(svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents:
6429
diff
changeset
|
59 |
if (param_number < c->num_params) param = c->param[param_number]; |
dddb39b41ee0
(svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents:
6429
diff
changeset
|
60 |
|
dddb39b41ee0
(svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents:
6429
diff
changeset
|
61 |
SetDParam(2 + i, param); |
dddb39b41ee0
(svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents:
6429
diff
changeset
|
62 |
} |
dddb39b41ee0
(svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents:
6429
diff
changeset
|
63 |
|
dddb39b41ee0
(svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents:
6429
diff
changeset
|
64 |
char message[512]; |
9627 | 65 |
GetString(message, c->error->custom_message != NULL ? BindCString(c->error->custom_message) : c->error->message, lastof(message)); |
6465
dddb39b41ee0
(svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents:
6429
diff
changeset
|
66 |
|
dddb39b41ee0
(svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents:
6429
diff
changeset
|
67 |
SetDParamStr(0, message); |
9545 | 68 |
y += DrawStringMultiLine(x, y, c->error->severity, w, bottom - y); |
6429
02c062eb2c74
(svn r8838) -Feature: Show newgrf error messages loaded in Action B in the newgrf gui
maedhros
parents:
6144
diff
changeset
|
69 |
} |
02c062eb2c74
(svn r8838) -Feature: Show newgrf error messages loaded in Action B in the newgrf gui
maedhros
parents:
6144
diff
changeset
|
70 |
|
5339
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5329
diff
changeset
|
71 |
/* Draw filename or not if it is not known (GRF sent over internet) */ |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5329
diff
changeset
|
72 |
if (c->filename != NULL) { |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5329
diff
changeset
|
73 |
SetDParamStr(0, c->filename); |
9545 | 74 |
y += DrawStringMultiLine(x, y, STR_NEWGRF_FILENAME, w, bottom - y); |
5339
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5329
diff
changeset
|
75 |
} |
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
76 |
|
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
77 |
/* Prepare and draw GRF ID */ |
5894
eb5ff472c10f
(svn r8102) -Cleanup: Remove unreachable code (r8096), useless cast
Darkvater
parents:
5889
diff
changeset
|
78 |
snprintf(buff, lengthof(buff), "%08X", BSWAP32(c->grfid)); |
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
79 |
SetDParamStr(0, buff); |
9545 | 80 |
y += DrawStringMultiLine(x, y, STR_NEWGRF_GRF_ID, w, bottom - y); |
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
81 |
|
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
82 |
/* Prepare and draw MD5 sum */ |
5885
262234e81333
(svn r8093) -Codechange: Add a function to get a string representation of an MD5SUM and use it.
Darkvater
parents:
5860
diff
changeset
|
83 |
md5sumToString(buff, lastof(buff), c->md5sum); |
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
84 |
SetDParamStr(0, buff); |
9545 | 85 |
y += DrawStringMultiLine(x, y, STR_NEWGRF_MD5SUM, w, bottom - y); |
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
86 |
|
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
87 |
/* Show GRF parameter list */ |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
88 |
if (show_params) { |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
89 |
if (c->num_params > 0) { |
5308
bad31e174cc6
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5248
diff
changeset
|
90 |
GRFBuildParamList(buff, c, lastof(buff)); |
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
91 |
SetDParamStr(0, buff); |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
92 |
} else { |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
93 |
SetDParam(0, STR_01A9_NONE); |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
94 |
} |
9545 | 95 |
y += DrawStringMultiLine(x, y, STR_NEWGRF_PARAMETER, w, bottom - y); |
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
96 |
} |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
97 |
|
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
98 |
/* Show flags */ |
9545 | 99 |
if (c->status == GCS_NOT_FOUND) y += DrawStringMultiLine(x, y, STR_NEWGRF_NOT_FOUND, w, bottom - y); |
100 |
if (c->status == GCS_DISABLED) y += DrawStringMultiLine(x, y, STR_NEWGRF_DISABLED, w, bottom - y); |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
101 |
if (HasBit(c->flags, GCF_COMPATIBLE)) y += DrawStringMultiLine(x, y, STR_NEWGRF_COMPATIBLE_LOADED, w, bottom - y); |
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
102 |
|
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
103 |
/* Draw GRF info if it exists */ |
5889
272800d151ac
(svn r8097) Replace strlen() {==,!=,>} 0 by the more concise {,!}StrEmpty(). Additionally the test takes O(1) instead of O(n) now
tron
parents:
5886
diff
changeset
|
104 |
if (c->info != NULL && !StrEmpty(c->info)) { |
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
105 |
SetDParamStr(0, c->info); |
9545 | 106 |
y += DrawStringMultiLine(x, y, STR_02BD, w, bottom - y); |
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
107 |
} else { |
9545 | 108 |
y += DrawStringMultiLine(x, y, STR_NEWGRF_NO_INFO, w, bottom - y); |
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
109 |
} |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
110 |
} |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
111 |
|
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
112 |
|
10645 | 113 |
/** |
114 |
* Window for adding NewGRF files |
|
115 |
*/ |
|
116 |
struct NewGRFAddWindow : public Window { |
|
117 |
/* Names of the add a newgrf window widgets */ |
|
118 |
enum AddNewGRFWindowWidgets { |
|
119 |
ANGRFW_CLOSEBOX = 0, |
|
120 |
ANGRFW_CAPTION, |
|
121 |
ANGRFW_BACKGROUND, |
|
122 |
ANGRFW_GRF_LIST, |
|
123 |
ANGRFW_SCROLLBAR, |
|
124 |
ANGRFW_GRF_INFO, |
|
125 |
ANGRFW_ADD, |
|
126 |
ANGRFW_RESCAN, |
|
127 |
ANGRFW_RESIZE, |
|
128 |
}; |
|
129 |
||
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
130 |
GRFConfig **list; |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
131 |
const GRFConfig *sel; |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
132 |
|
10645 | 133 |
NewGRFAddWindow(const WindowDesc *desc, GRFConfig **list) : Window(desc, 0) |
134 |
{ |
|
135 |
this->list = list; |
|
136 |
this->resize.step_height = 10; |
|
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
137 |
|
10645 | 138 |
this->FindWindowPlacementAndResize(desc); |
139 |
} |
|
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
140 |
|
10645 | 141 |
virtual void OnPaint() |
142 |
{ |
|
143 |
const GRFConfig *c; |
|
144 |
const Widget *wl = &this->widget[ANGRFW_GRF_LIST]; |
|
145 |
int n = 0; |
|
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
146 |
|
10645 | 147 |
/* Count the number of GRFs */ |
148 |
for (c = _all_grfs; c != NULL; c = c->next) n++; |
|
149 |
||
150 |
this->vscroll.cap = (wl->bottom - wl->top) / 10; |
|
151 |
SetVScrollCount(this, n); |
|
152 |
||
153 |
this->SetWidgetDisabledState(ANGRFW_ADD, this->sel == NULL || this->sel->IsOpenTTDBaseGRF()); |
|
154 |
this->DrawWidgets(); |
|
155 |
||
156 |
GfxFillRect(wl->left + 1, wl->top + 1, wl->right, wl->bottom, 0xD7); |
|
157 |
||
158 |
uint y = wl->top + 1; |
|
159 |
for (c = _all_grfs, n = 0; c != NULL && n < (this->vscroll.pos + this->vscroll.cap); c = c->next, n++) { |
|
160 |
if (n >= this->vscroll.pos) { |
|
161 |
bool h = c == this->sel; |
|
162 |
const char *text = (c->name != NULL && !StrEmpty(c->name)) ? c->name : c->filename; |
|
163 |
||
164 |
/* Draw selection background */ |
|
165 |
if (h) GfxFillRect(3, y, this->width - 15, y + 9, 156); |
|
166 |
DoDrawStringTruncated(text, 4, y, h ? TC_WHITE : TC_ORANGE, this->width - 18); |
|
167 |
y += 10; |
|
168 |
} |
|
169 |
} |
|
170 |
||
171 |
if (this->sel != NULL) { |
|
172 |
const Widget *wi = &this->widget[ANGRFW_GRF_INFO]; |
|
173 |
ShowNewGRFInfo(this->sel, wi->left + 2, wi->top + 2, wi->right - wi->left - 2, wi->bottom, false); |
|
174 |
} |
|
175 |
} |
|
176 |
||
177 |
virtual void OnDoubleClick(Point pt, int widget) |
|
178 |
{ |
|
179 |
if (widget == ANGRFW_GRF_LIST) this->OnClick(pt, ANGRFW_ADD); |
|
180 |
} |
|
181 |
||
182 |
virtual void OnClick(Point pt, int widget) |
|
183 |
{ |
|
184 |
switch (widget) { |
|
185 |
case ANGRFW_GRF_LIST: { |
|
186 |
/* Get row... */ |
|
187 |
const GRFConfig *c; |
|
188 |
uint i = (pt.y - this->widget[ANGRFW_GRF_LIST].top) / 10 + this->vscroll.pos; |
|
189 |
||
190 |
for (c = _all_grfs; c != NULL && i > 0; c = c->next, i--) {} |
|
191 |
this->sel = c; |
|
192 |
this->SetDirty(); |
|
193 |
break; |
|
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
194 |
} |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
195 |
|
10645 | 196 |
case ANGRFW_ADD: // Add selection to list |
197 |
if (this->sel != NULL) { |
|
198 |
const GRFConfig *src = this->sel; |
|
199 |
GRFConfig **list; |
|
5243
a564347a939b
(svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents:
5241
diff
changeset
|
200 |
|
10645 | 201 |
/* Find last entry in the list, checking for duplicate grfid on the way */ |
202 |
for (list = this->list; *list != NULL; list = &(*list)->next) { |
|
203 |
if ((*list)->grfid == src->grfid) { |
|
204 |
ShowErrorMessage(INVALID_STRING_ID, STR_NEWGRF_DUPLICATE_GRFID, 0, 0); |
|
205 |
return; |
|
5243
a564347a939b
(svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents:
5241
diff
changeset
|
206 |
} |
10645 | 207 |
} |
5243
a564347a939b
(svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
peter1138
parents:
5241
diff
changeset
|
208 |
|
10645 | 209 |
/* Copy GRF details from scanned list */ |
210 |
GRFConfig *c = CallocT<GRFConfig>(1); |
|
211 |
*c = *src; |
|
212 |
c->filename = strdup(src->filename); |
|
213 |
if (src->name != NULL) c->name = strdup(src->name); |
|
214 |
if (src->info != NULL) c->info = strdup(src->info); |
|
215 |
c->next = NULL; |
|
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
216 |
|
10645 | 217 |
/* Append GRF config to configuration list */ |
218 |
*list = c; |
|
219 |
||
220 |
DeleteWindowByClass(WC_SAVELOAD); |
|
221 |
InvalidateWindowData(WC_GAME_OPTIONS, 0); |
|
222 |
} |
|
223 |
break; |
|
224 |
||
225 |
case ANGRFW_RESCAN: // Rescan list |
|
226 |
this->sel = NULL; |
|
227 |
ScanNewGRFFiles(); |
|
228 |
this->SetDirty(); |
|
229 |
break; |
|
230 |
} |
|
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
231 |
} |
10645 | 232 |
}; |
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
233 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
234 |
/* Widget definition for the add a newgrf window */ |
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
235 |
static const Widget _newgrf_add_dlg_widgets[] = { |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
236 |
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW }, // ANGRFW_CLOSEBOX |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
237 |
{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 306, 0, 13, STR_NEWGRF_ADD_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS }, // ANGRFW_CAPTION |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
238 |
{ WWT_PANEL, RESIZE_RB, 14, 0, 294, 14, 121, 0x0, STR_NULL }, // ANGRFW_BACKGROUND |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
239 |
{ WWT_INSET, RESIZE_RB, 14, 2, 292, 16, 119, 0x0, STR_NULL }, // ANGRFW_GRF_LIST |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
240 |
{ WWT_SCROLLBAR, RESIZE_LRB, 14, 295, 306, 14, 121, 0x0, STR_NULL }, // ANGRFW_SCROLLBAR |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
241 |
{ WWT_PANEL, RESIZE_RTB, 14, 0, 306, 122, 224, 0x0, STR_NULL }, // ANGRFW_GRF_INFO |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
242 |
{ WWT_PUSHTXTBTN, RESIZE_RTB, 14, 0, 146, 225, 236, STR_NEWGRF_ADD_FILE, STR_NEWGRF_ADD_FILE_TIP }, // ANGRFW_ADD |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
243 |
{ WWT_PUSHTXTBTN, RESIZE_LRTB, 14, 147, 294, 225, 236, STR_NEWGRF_RESCAN_FILES, STR_NEWGRF_RESCAN_FILES_TIP }, // ANGRFW_RESCAN |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
244 |
{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 295, 306, 225, 236, 0x0, STR_RESIZE_BUTTON }, // ANGRFW_RESIZE |
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
245 |
{ WIDGETS_END }, |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
246 |
}; |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
247 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
248 |
/* Window definition for the add a newgrf window */ |
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
249 |
static const WindowDesc _newgrf_add_dlg_desc = { |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9629
diff
changeset
|
250 |
WDP_CENTER, WDP_CENTER, 307, 237, 307, 337, |
6144
5a0ffbf27ced
(svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents:
5919
diff
changeset
|
251 |
WC_SAVELOAD, WC_NONE, |
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
252 |
WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE, |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
253 |
_newgrf_add_dlg_widgets, |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
254 |
}; |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
255 |
|
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
256 |
|
10645 | 257 |
static void NewGRFConfirmationCallback(Window *w, bool confirmed); |
258 |
||
259 |
/** |
|
260 |
* Window for showing NewGRF files |
|
261 |
*/ |
|
262 |
struct NewGRFWindow : public Window { |
|
263 |
/* Names of the manage newgrfs window widgets */ |
|
264 |
enum ShowNewGRFStateWidgets { |
|
265 |
SNGRFS_CLOSEBOX = 0, |
|
266 |
SNGRFS_CAPTION, |
|
267 |
SNGRFS_BACKGROUND, |
|
268 |
SNGRFS_ADD, |
|
269 |
SNGRFS_REMOVE, |
|
270 |
SNGRFS_MOVE_UP, |
|
271 |
SNGRFS_MOVE_DOWN, |
|
272 |
SNGRFS_FILE_LIST, |
|
273 |
SNGRFS_SCROLLBAR, |
|
274 |
SNGRFS_NEWGRF_INFO, |
|
275 |
SNGRFS_SET_PARAMETERS, |
|
276 |
SNGRFS_APPLY_CHANGES, |
|
277 |
SNGRFS_RESIZE, |
|
278 |
}; |
|
279 |
||
5352
82a50c80b0c4
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5345
diff
changeset
|
280 |
GRFConfig **orig_list; ///< grf list the window is shown with |
10645 | 281 |
GRFConfig *list; ///< temporary grf list to which changes are made |
5352
82a50c80b0c4
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5345
diff
changeset
|
282 |
GRFConfig *sel; ///< selected grf item |
82a50c80b0c4
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5345
diff
changeset
|
283 |
bool editable; ///< is the window editable |
82a50c80b0c4
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5345
diff
changeset
|
284 |
bool show_params; ///< are the grf-parameters shown in the info-panel |
82a50c80b0c4
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5345
diff
changeset
|
285 |
bool execute; ///< on pressing 'apply changes' are grf changes applied immediately, or only list is updated |
82a50c80b0c4
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5345
diff
changeset
|
286 |
|
10645 | 287 |
NewGRFWindow(const WindowDesc *desc, bool editable, bool show_params, bool exec_changes, GRFConfig **config) : Window(desc, 0) |
288 |
{ |
|
289 |
this->resize.step_height = 14; |
|
290 |
this->sel = NULL; |
|
291 |
this->list = NULL; |
|
292 |
this->orig_list = config; |
|
293 |
this->editable = editable; |
|
294 |
this->execute = exec_changes; |
|
295 |
this->show_params = show_params; |
|
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
296 |
|
10645 | 297 |
CopyGRFConfigList(&this->list, *config, false); |
6555
c27c9d5b459f
(svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents:
6492
diff
changeset
|
298 |
|
10645 | 299 |
this->FindWindowPlacementAndResize(desc); |
300 |
this->SetupNewGRFWindow(); |
|
301 |
} |
|
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
302 |
|
10645 | 303 |
~NewGRFWindow() |
304 |
{ |
|
305 |
if (!this->execute) { |
|
306 |
CopyGRFConfigList(this->orig_list, this->list, true); |
|
307 |
ResetGRFConfig(false); |
|
308 |
ReloadNewGRFData(); |
|
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
309 |
} |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
310 |
|
10645 | 311 |
/* Remove the temporary copy of grf-list used in window */ |
312 |
ClearGRFConfigList(&this->list); |
|
313 |
} |
|
5248
2aa0c4cc8f23
(svn r7373) -Codechange: when removing a GRF from the list, make the next one selected, or the previous file if the last item is being removed. This makes clearing the list easier.
peter1138
parents:
5243
diff
changeset
|
314 |
|
10645 | 315 |
void SetupNewGRFWindow() |
316 |
{ |
|
317 |
const GRFConfig *c; |
|
318 |
int i; |
|
5248
2aa0c4cc8f23
(svn r7373) -Codechange: when removing a GRF from the list, make the next one selected, or the previous file if the last item is being removed. This makes clearing the list easier.
peter1138
parents:
5243
diff
changeset
|
319 |
|
10645 | 320 |
for (c = this->list, i = 0; c != NULL; c = c->next, i++) {} |
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
321 |
|
10645 | 322 |
this->vscroll.cap = (this->widget[SNGRFS_FILE_LIST].bottom - this->widget[SNGRFS_FILE_LIST].top) / 14 + 1; |
323 |
SetVScrollCount(this, i); |
|
324 |
||
325 |
this->SetWidgetDisabledState(SNGRFS_ADD, !this->editable); |
|
326 |
this->SetWidgetDisabledState(SNGRFS_APPLY_CHANGES, !this->editable); |
|
327 |
} |
|
328 |
||
329 |
virtual void OnPaint() |
|
330 |
{ |
|
331 |
bool disable_all = this->sel == NULL || !this->editable; |
|
332 |
||
333 |
this->SetWidgetsDisabledState(disable_all, |
|
334 |
SNGRFS_REMOVE, |
|
335 |
SNGRFS_MOVE_UP, |
|
336 |
SNGRFS_MOVE_DOWN, |
|
337 |
WIDGET_LIST_END |
|
338 |
); |
|
339 |
this->SetWidgetDisabledState(SNGRFS_SET_PARAMETERS, !this->show_params || disable_all); |
|
340 |
||
341 |
if (!disable_all) { |
|
342 |
/* All widgets are now enabled, so disable widgets we can't use */ |
|
343 |
if (this->sel == this->list) this->DisableWidget(SNGRFS_MOVE_UP); |
|
344 |
if (this->sel->next == NULL) this->DisableWidget(SNGRFS_MOVE_DOWN); |
|
345 |
if (this->sel->IsOpenTTDBaseGRF()) this->DisableWidget(SNGRFS_REMOVE); |
|
346 |
} |
|
347 |
||
348 |
this->DrawWidgets(); |
|
349 |
||
350 |
/* Draw NewGRF list */ |
|
351 |
int y = this->widget[SNGRFS_FILE_LIST].top; |
|
352 |
int i = 0; |
|
353 |
for (const GRFConfig *c = this->list; c != NULL; c = c->next, i++) { |
|
354 |
if (i >= this->vscroll.pos && i < this->vscroll.pos + this->vscroll.cap) { |
|
355 |
const char *text = (c->name != NULL && !StrEmpty(c->name)) ? c->name : c->filename; |
|
356 |
SpriteID pal; |
|
357 |
byte txtoffset; |
|
358 |
||
359 |
/* Pick a colour */ |
|
360 |
switch (c->status) { |
|
361 |
case GCS_NOT_FOUND: |
|
362 |
case GCS_DISABLED: |
|
363 |
pal = PALETTE_TO_RED; |
|
364 |
break; |
|
365 |
case GCS_ACTIVATED: |
|
366 |
pal = PALETTE_TO_GREEN; |
|
367 |
break; |
|
368 |
default: |
|
369 |
pal = PALETTE_TO_BLUE; |
|
370 |
break; |
|
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
371 |
} |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
372 |
|
10645 | 373 |
/* Do not show a "not-failure" colour when it actually failed to load */ |
374 |
if (pal != PALETTE_TO_RED) { |
|
375 |
if (HasBit(c->flags, GCF_STATIC)) { |
|
376 |
pal = PALETTE_TO_GREY; |
|
377 |
} else if (HasBit(c->flags, GCF_COMPATIBLE)) { |
|
378 |
pal = PALETTE_TO_ORANGE; |
|
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
379 |
} |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
380 |
} |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
381 |
|
10645 | 382 |
DrawSprite(SPR_SQUARE, pal, 5, y + 2); |
383 |
if (c->error != NULL) DrawSprite(SPR_WARNING_SIGN, 0, 20, y + 2); |
|
384 |
txtoffset = c->error != NULL ? 35 : 25; |
|
385 |
DoDrawStringTruncated(text, txtoffset, y + 3, this->sel == c ? TC_WHITE : TC_BLACK, this->width - txtoffset - 10); |
|
386 |
y += 14; |
|
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
387 |
} |
10645 | 388 |
} |
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
389 |
|
10645 | 390 |
if (this->sel != NULL) { |
391 |
/* Draw NewGRF file info */ |
|
392 |
const Widget *wi = &this->widget[SNGRFS_NEWGRF_INFO]; |
|
393 |
ShowNewGRFInfo(this->sel, wi->left + 2, wi->top + 2, wi->right - wi->left - 2, wi->bottom, this->show_params); |
|
394 |
} |
|
395 |
} |
|
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
396 |
|
10645 | 397 |
virtual void OnClick(Point pt, int widget) |
398 |
{ |
|
399 |
switch (widget) { |
|
400 |
case SNGRFS_ADD: // Add GRF |
|
401 |
DeleteWindowByClass(WC_SAVELOAD); |
|
402 |
new NewGRFAddWindow(&_newgrf_add_dlg_desc, &this->list); |
|
403 |
break; |
|
5352
82a50c80b0c4
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5345
diff
changeset
|
404 |
|
10645 | 405 |
case SNGRFS_REMOVE: { // Remove GRF |
406 |
GRFConfig **pc, *c, *newsel; |
|
407 |
||
408 |
/* Choose the next GRF file to be the selected file */ |
|
409 |
newsel = this->sel->next; |
|
410 |
||
411 |
for (pc = &this->list; (c = *pc) != NULL; pc = &c->next) { |
|
412 |
/* If the new selection is empty (i.e. we're deleting the last item |
|
413 |
* in the list, pick the file just before the selected file */ |
|
414 |
if (newsel == NULL && c->next == this->sel) newsel = c; |
|
415 |
||
416 |
if (c == this->sel) { |
|
417 |
*pc = c->next; |
|
418 |
free(c); |
|
419 |
break; |
|
420 |
} |
|
421 |
} |
|
422 |
||
423 |
this->sel = newsel; |
|
424 |
this->SetupNewGRFWindow(); |
|
425 |
this->SetDirty(); |
|
426 |
break; |
|
9732 | 427 |
} |
10645 | 428 |
|
429 |
case SNGRFS_MOVE_UP: { // Move GRF up |
|
430 |
GRFConfig **pc, *c; |
|
431 |
if (this->sel == NULL) break; |
|
432 |
||
433 |
for (pc = &this->list; (c = *pc) != NULL; pc = &c->next) { |
|
434 |
if (c->next == this->sel) { |
|
435 |
c->next = this->sel->next; |
|
436 |
this->sel->next = c; |
|
437 |
*pc = this->sel; |
|
438 |
break; |
|
439 |
} |
|
440 |
} |
|
441 |
this->SetDirty(); |
|
442 |
break; |
|
443 |
} |
|
444 |
||
445 |
case SNGRFS_MOVE_DOWN: { // Move GRF down |
|
446 |
GRFConfig **pc, *c; |
|
447 |
if (this->sel == NULL) break; |
|
448 |
||
449 |
for (pc = &this->list; (c = *pc) != NULL; pc = &c->next) { |
|
450 |
if (c == this->sel) { |
|
451 |
*pc = c->next; |
|
452 |
c->next = c->next->next; |
|
453 |
(*pc)->next = c; |
|
454 |
break; |
|
455 |
} |
|
456 |
} |
|
457 |
this->SetDirty(); |
|
458 |
break; |
|
459 |
} |
|
460 |
||
461 |
case SNGRFS_FILE_LIST: { // Select a GRF |
|
462 |
GRFConfig *c; |
|
463 |
uint i = (pt.y - this->widget[SNGRFS_FILE_LIST].top) / 14 + this->vscroll.pos; |
|
464 |
||
465 |
for (c = this->list; c != NULL && i > 0; c = c->next, i--) {} |
|
466 |
this->sel = c; |
|
467 |
||
468 |
this->SetDirty(); |
|
469 |
break; |
|
470 |
} |
|
471 |
||
472 |
case SNGRFS_APPLY_CHANGES: // Apply changes made to GRF list |
|
473 |
if (this->execute) { |
|
474 |
ShowQuery( |
|
475 |
STR_POPUP_CAUTION_CAPTION, |
|
476 |
STR_NEWGRF_CONFIRMATION_TEXT, |
|
477 |
this, |
|
478 |
NewGRFConfirmationCallback |
|
479 |
); |
|
480 |
} else { |
|
481 |
CopyGRFConfigList(this->orig_list, this->list, true); |
|
482 |
ResetGRFConfig(false); |
|
483 |
ReloadNewGRFData(); |
|
484 |
} |
|
485 |
break; |
|
486 |
||
487 |
case SNGRFS_SET_PARAMETERS: { // Edit parameters |
|
488 |
if (this->sel == NULL) break; |
|
489 |
||
490 |
char buff[512]; |
|
491 |
GRFBuildParamList(buff, this->sel, lastof(buff)); |
|
492 |
ShowQueryString(BindCString(buff), STR_NEWGRF_PARAMETER_QUERY, 63, 250, this, CS_ALPHANUMERAL); |
|
493 |
break; |
|
494 |
} |
|
495 |
} |
|
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
496 |
} |
10645 | 497 |
|
498 |
virtual void OnQueryTextFinished(char *str) |
|
499 |
{ |
|
500 |
if (str == NULL) return; |
|
501 |
||
502 |
/* Parse our new "int list" */ |
|
503 |
GRFConfig *c = this->sel; |
|
504 |
c->num_params = parse_intlist(str, (int*)c->param, lengthof(c->param)); |
|
505 |
||
506 |
/* parse_intlist returns -1 on error */ |
|
507 |
if (c->num_params == (byte)-1) c->num_params = 0; |
|
508 |
||
509 |
this->SetDirty(); |
|
510 |
} |
|
511 |
||
512 |
virtual void OnResize(Point new_size, Point delta) |
|
513 |
{ |
|
514 |
if (delta.x != 0) { |
|
515 |
ResizeButtons(this, SNGRFS_ADD, SNGRFS_MOVE_DOWN); |
|
516 |
ResizeButtons(this, SNGRFS_SET_PARAMETERS, SNGRFS_APPLY_CHANGES); |
|
517 |
} |
|
518 |
||
519 |
this->vscroll.cap += delta.y / 14; |
|
520 |
this->widget[SNGRFS_FILE_LIST].data = (this->vscroll.cap << 8) + 1; |
|
521 |
||
522 |
this->SetupNewGRFWindow(); |
|
523 |
} |
|
524 |
||
525 |
virtual void OnInvalidateData(int data = 0) |
|
526 |
{ |
|
527 |
this->SetupNewGRFWindow(); |
|
528 |
} |
|
529 |
}; |
|
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
530 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
531 |
/* Widget definition of the manage newgrfs window */ |
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
532 |
static const Widget _newgrf_widgets[] = { |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
533 |
{ WWT_CLOSEBOX, RESIZE_NONE, 10, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW }, // SNGRFS_CLOSEBOX |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
534 |
{ WWT_CAPTION, RESIZE_RIGHT, 10, 11, 299, 0, 13, STR_NEWGRF_SETTINGS_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS }, // SNGRFS_CAPTION |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
535 |
{ WWT_PANEL, RESIZE_RIGHT, 10, 0, 299, 14, 29, STR_NULL, STR_NULL }, // SNGRFS_BACKGROUND |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
536 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 3, 10, 79, 16, 27, STR_NEWGRF_ADD, STR_NEWGRF_ADD_TIP }, // SNGRFS_ADD |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
537 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 3, 80, 149, 16, 27, STR_NEWGRF_REMOVE, STR_NEWGRF_REMOVE_TIP }, // SNGRFS_REMOVE |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
538 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 3, 150, 219, 16, 27, STR_NEWGRF_MOVEUP, STR_NEWGRF_MOVEUP_TIP }, // SNGRFS_MOVE_UP |
9732 | 539 |
{ WWT_PUSHTXTBTN, RESIZE_RIGHT, 3, 220, 289, 16, 27, STR_NEWGRF_MOVEDOWN, STR_NEWGRF_MOVEDOWN_TIP }, // SNGRFS_MOVE_DOWN |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
540 |
{ WWT_MATRIX, RESIZE_RB, 10, 0, 287, 30, 99, 0x501, STR_NEWGRF_FILE_TIP }, // SNGRFS_FILE_LIST |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
541 |
{ WWT_SCROLLBAR, RESIZE_LRB, 10, 288, 299, 30, 99, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST }, // SNGRFS_SCROLLBAR |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
542 |
{ WWT_PANEL, RESIZE_RTB, 10, 0, 299, 100, 212, STR_NULL, STR_NULL }, // SNGRFS_NEWGRF_INFO |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
543 |
{ WWT_PUSHTXTBTN, RESIZE_TB, 10, 0, 143, 213, 224, STR_NEWGRF_SET_PARAMETERS, STR_NULL }, // SNGRFS_SET_PARAMETERS |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
544 |
{ WWT_PUSHTXTBTN, RESIZE_RTB, 10, 144, 287, 213, 224, STR_NEWGRF_APPLY_CHANGES, STR_NULL }, // SNGRFS_APPLY_CHANGES |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
545 |
{ WWT_RESIZEBOX, RESIZE_LRTB, 10, 288, 299, 213, 224, 0x0, STR_RESIZE_BUTTON }, // SNGRFS_RESIZE |
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
546 |
{ WIDGETS_END }, |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
547 |
}; |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
548 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
549 |
/* Window definition of the manage newgrfs window */ |
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
550 |
static const WindowDesc _newgrf_desc = { |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9629
diff
changeset
|
551 |
WDP_CENTER, WDP_CENTER, 300, 225, 300, 225, |
6144
5a0ffbf27ced
(svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents:
5919
diff
changeset
|
552 |
WC_GAME_OPTIONS, WC_NONE, |
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
553 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE, |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
554 |
_newgrf_widgets, |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
555 |
}; |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
556 |
|
10645 | 557 |
/** Callback function for the newgrf 'apply changes' confirmation window |
558 |
* @param w Window which is calling this callback |
|
559 |
* @param confirmed boolean value, true when yes was clicked, false otherwise |
|
560 |
*/ |
|
561 |
static void NewGRFConfirmationCallback(Window *w, bool confirmed) |
|
562 |
{ |
|
563 |
if (confirmed) { |
|
564 |
NewGRFWindow *nw = dynamic_cast<NewGRFWindow*>(w); |
|
565 |
GRFConfig *c; |
|
566 |
int i = 0; |
|
567 |
||
10829 | 568 |
GamelogStartAction(GLAT_GRF); |
569 |
GamelogGRFUpdate(_grfconfig, nw->list); // log GRF changes |
|
10645 | 570 |
CopyGRFConfigList(nw->orig_list, nw->list, false); |
571 |
ReloadNewGRFData(); |
|
10829 | 572 |
GamelogStopAction(); |
10645 | 573 |
|
574 |
/* Show new, updated list */ |
|
575 |
for (c = nw->list; c != NULL && c != nw->sel; c = c->next, i++) {} |
|
576 |
CopyGRFConfigList(&nw->list, *nw->orig_list, false); |
|
577 |
for (c = nw->list; c != NULL && i > 0; c = c->next, i--) {} |
|
578 |
nw->sel = c; |
|
579 |
||
580 |
w->SetDirty(); |
|
581 |
} |
|
582 |
} |
|
583 |
||
584 |
||
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
585 |
|
5352
82a50c80b0c4
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5345
diff
changeset
|
586 |
/** Setup the NewGRF gui |
82a50c80b0c4
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5345
diff
changeset
|
587 |
* @param editable allow the user to make changes to the grfconfig in the window |
82a50c80b0c4
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5345
diff
changeset
|
588 |
* @param show_params show information about what parameters are set for the grf files |
82a50c80b0c4
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5345
diff
changeset
|
589 |
* @param exec_changes if changes are made to the list (editable is true), apply these |
82a50c80b0c4
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5345
diff
changeset
|
590 |
* changes immediately or only update the list |
82a50c80b0c4
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5345
diff
changeset
|
591 |
* @param config pointer to a linked-list of grfconfig's that will be shown */ |
82a50c80b0c4
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5345
diff
changeset
|
592 |
void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config) |
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
593 |
{ |
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
594 |
DeleteWindowByClass(WC_GAME_OPTIONS); |
10645 | 595 |
new NewGRFWindow(&_newgrf_desc, editable, show_params, exec_changes, config); |
5237
c14c97d7030a
(svn r7357) -Codechange: new NewGRF set up window which allows modification of NewGRF settings.
peter1138
parents:
diff
changeset
|
596 |
} |