OpenTTD Source: src/newgrf_gui.cpp Source File

OpenTTD Source 1.11.0-RC1

newgrf_gui.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
7
10 #include "stdafx.h"
11 #include "error.h"
12 #include "settings_gui.h"
13 #include "newgrf.h"
14 #include "strings_func.h"
15 #include "window_func.h"
16 #include "gamelog.h"
17 #include "settings_type.h"
18 #include "settings_func.h"
19 #include "widgets/dropdown_type.h"
20 #include "widgets/dropdown_func.h"
21 #include "network/network.h"
22 #include "network/network_content.h"
23 #include "sortlist_type.h"
24 #include "stringfilter_type.h"
25 #include "querystring_gui.h"
26 #include "core/geometry_func.hpp"
27 #include "newgrf_text.h"
28 #include "textfile_gui.h"
29 #include "tilehighlight_func.h"
30 #include "fios.h"
31 #include "guitimer_func.h"
32
33 #include "widgets/newgrf_widget.h"
34 #include "widgets/misc_widget.h"
35
36 #include "table/sprites.h"
37
38 #include <map>
39 #include "safeguards.h"
40
44 void ShowNewGRFError()
45 {
46 /* Do not show errors when entering the main screen */
47 if (_game_mode == GM_MENU) return;
48
49 for (const GRFConfig *c = _grfconfig; c != nullptr; c = c->next) {
50 /* We only want to show fatal errors */
51 if (c->error == nullptr || c->error->severity != STR_NEWGRF_ERROR_MSG_FATAL) continue;
52
53 SetDParam (0, c->error->message != STR_NULL ? c->error->message : STR_JUST_RAW_STRING);
54 SetDParamStr(1, c->error->custom_message.c_str());
55 SetDParamStr(2, c->filename);
56 SetDParamStr(3, c->error->data.c_str());
57 for (uint i = 0; i < lengthof(c->error->param_value); i++) {
58 SetDParam(4 + i, c->error->param_value[i]);
59 }
60 ShowErrorMessage(STR_NEWGRF_ERROR_FATAL_POPUP, INVALID_STRING_ID, WL_CRITICAL);
61 break;
62 }
63 }
64
65 static void ShowNewGRFInfo(const GRFConfig *c, uint x, uint y, uint right, uint bottom, bool show_params)
66 {
67 if (c->error != nullptr) {
68 char message[512];
69 SetDParamStr(0, c->error->custom_message.c_str()); // is skipped by built-in messages
70 SetDParamStr(1, c->filename);
71 SetDParamStr(2, c->error->data.c_str());
72 for (uint i = 0; i < lengthof(c->error->param_value); i++) {
73 SetDParam(3 + i, c->error->param_value[i]);
74 }
75 GetString(message, c->error->message != STR_NULL ? c->error->message : STR_JUST_RAW_STRING, lastof(message));
76
77 SetDParamStr(0, message);
78 y = DrawStringMultiLine(x, right, y, bottom, c->error->severity);
79 }
80
81 /* Draw filename or not if it is not known (GRF sent over internet) */
82 if (c->filename != nullptr) {
83 SetDParamStr(0, c->filename);
84 y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_FILENAME);
85 }
86
87 /* Prepare and draw GRF ID */
88 char buff[256];
89 seprintf(buff, lastof(buff), "%08X", BSWAP32(c->ident.grfid));
90 SetDParamStr(0, buff);
91 y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_GRF_ID);
92
93 if ((_settings_client.gui.newgrf_developer_tools || _settings_client.gui.newgrf_show_old_versions) && c->version != 0) {
94 SetDParam(0, c->version);
95 y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_VERSION);
96 }
97 if ((_settings_client.gui.newgrf_developer_tools || _settings_client.gui.newgrf_show_old_versions) && c->min_loadable_version != 0) {
98 SetDParam(0, c->min_loadable_version);
99 y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_MIN_VERSION);
100 }
101
102 /* Prepare and draw MD5 sum */
103 md5sumToString(buff, lastof(buff), c->ident.md5sum);
104 SetDParamStr(0, buff);
105 y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_MD5SUM);
106
107 /* Show GRF parameter list */
108 if (show_params) {
109 if (c->num_params > 0) {
110 GRFBuildParamList(buff, c, lastof(buff));
111 SetDParam(0, STR_JUST_RAW_STRING);
112 SetDParamStr(1, buff);
113 } else {
114 SetDParam(0, STR_NEWGRF_SETTINGS_PARAMETER_NONE);
115 }
116 y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_PARAMETER);
117
118 /* Draw the palette of the NewGRF */
119 if (c->palette & GRFP_BLT_32BPP) {
120 SetDParam(0, (c->palette & GRFP_USE_WINDOWS) ? STR_NEWGRF_SETTINGS_PALETTE_LEGACY_32BPP : STR_NEWGRF_SETTINGS_PALETTE_DEFAULT_32BPP);
121 } else {
122 SetDParam(0, (c->palette & GRFP_USE_WINDOWS) ? STR_NEWGRF_SETTINGS_PALETTE_LEGACY : STR_NEWGRF_SETTINGS_PALETTE_DEFAULT);
123 }
124 y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_PALETTE);
125 }
126
127 /* Show flags */
128 if (c->status == GCS_NOT_FOUND) y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_NOT_FOUND);
129 if (c->status == GCS_DISABLED) y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_DISABLED);
130 if (HasBit(c->flags, GCF_INVALID)) y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_INCOMPATIBLE);
131 if (HasBit(c->flags, GCF_COMPATIBLE)) y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_COMPATIBLE_LOADED);
132
133 /* Draw GRF info if it exists */
134 if (!StrEmpty(c->GetDescription())) {
135 SetDParamStr(0, c->GetDescription());
136 y = DrawStringMultiLine(x, right, y, bottom, STR_BLACK_RAW_STRING);
137 } else {
138 y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_NO_INFO);
139 }
140 }
141
145 struct NewGRFParametersWindow : public Window {
146 static GRFParameterInfo dummy_parameter_info;
147 GRFConfig *grf_config;
148 uint clicked_button;
149 bool clicked_increase;
150 bool clicked_dropdown;
151 bool closing_dropdown;
152 GUITimer timeout;
153 uint clicked_row;
154 int line_height;
155 Scrollbar *vscroll;
156 bool action14present;
157 bool editable;
158
159 NewGRFParametersWindow(WindowDesc *desc, GRFConfig *c, bool editable) : Window(desc),
160 grf_config(c),
161 clicked_button(UINT_MAX),
162 clicked_dropdown(false),
163 closing_dropdown(false),
164 clicked_row(UINT_MAX),
165 editable(editable)
166 {
167 this->action14present = (c->num_valid_params != lengthof(c->param) || c->param_info.size() != 0);
168
169 this->CreateNestedTree();
170 this->vscroll = this->GetScrollbar(WID_NP_SCROLLBAR);
171 this->GetWidget<NWidgetStacked>(WID_NP_SHOW_NUMPAR)->SetDisplayedPlane(this->action14present ? SZSP_HORIZONTAL : 0);
172 this->GetWidget<NWidgetStacked>(WID_NP_SHOW_DESCRIPTION)->SetDisplayedPlane(this->action14present ? 0 : SZSP_HORIZONTAL);
173 this->FinishInitNested(); // Initializes 'this->line_height' as side effect.
174
175 this->SetWidgetDisabledState(WID_NP_RESET, !this->editable);
176
177 this->InvalidateData();
178 }
179
185 static GRFParameterInfo *GetDummyParameterInfo(uint nr)
186 {
187 dummy_parameter_info.param_nr = nr;
188 return &dummy_parameter_info;
189 }
190
191 void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
192 {
193 switch (widget) {
194 case WID_NP_NUMPAR_DEC:
195 case WID_NP_NUMPAR_INC: {
196 size->width = std::max(SETTING_BUTTON_WIDTH / 2, FONT_HEIGHT_NORMAL);
197 size->height = std::max(SETTING_BUTTON_HEIGHT, FONT_HEIGHT_NORMAL);
198 break;
199 }
200
201 case WID_NP_NUMPAR: {
202 SetDParamMaxValue(0, lengthof(this->grf_config->param));
203 Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
204 d.width += padding.width;
205 d.height += padding.height;
206 *size = maxdim(*size, d);
207 break;
208 }
209
210 case WID_NP_BACKGROUND:
211 this->line_height = std::max(SETTING_BUTTON_HEIGHT, FONT_HEIGHT_NORMAL) + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
212
213 resize->width = 1;
214 resize->height = this->line_height;
215 size->height = 5 * this->line_height;
216 break;
217
218 case WID_NP_DESCRIPTION:
219 /* Minimum size of 4 lines. The 500 is the default size of the window. */
220 Dimension suggestion = {500 - WD_FRAMERECT_LEFT - WD_FRAMERECT_RIGHT, (uint)FONT_HEIGHT_NORMAL * 4 + WD_TEXTPANEL_TOP + WD_TEXTPANEL_BOTTOM};
221 for (uint i = 0; i < this->grf_config->param_info.size(); i++) {
222 const GRFParameterInfo *par_info = this->grf_config->param_info[i];
223 if (par_info == nullptr) continue;
224 const char *desc = GetGRFStringFromGRFText(par_info->desc);
225 if (desc == nullptr) continue;
226 Dimension d = GetStringMultiLineBoundingBox(desc, suggestion);
227 d.height += WD_TEXTPANEL_TOP + WD_TEXTPANEL_BOTTOM;
228 suggestion = maxdim(d, suggestion);
229 }
230 size->height = suggestion.height;
231 break;
232 }
233 }
234
235 void SetStringParameters(int widget) const override
236 {
237 switch (widget) {
238 case WID_NP_NUMPAR:
239 SetDParam(0, this->vscroll->GetCount());
240 break;
241 }
242 }
243
244 void DrawWidget(const Rect &r, int widget) const override
245 {
246 if (widget == WID_NP_DESCRIPTION) {
247 const GRFParameterInfo *par_info = (this->clicked_row < this->grf_config->param_info.size()) ? this->grf_config->param_info[this->clicked_row] : nullptr;
248 if (par_info == nullptr) return;
249 const char *desc = GetGRFStringFromGRFText(par_info->desc);
250 if (desc == nullptr) return;
251 DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_TEXTPANEL_TOP, r.bottom - WD_TEXTPANEL_BOTTOM, desc, TC_BLACK);
252 return;
253 } else if (widget != WID_NP_BACKGROUND) {
254 return;
255 }
256
257 bool rtl = _current_text_dir == TD_RTL;
258 uint buttons_left = rtl ? r.right - SETTING_BUTTON_WIDTH - 3 : r.left + 4;
259 uint text_left = r.left + (rtl ? WD_FRAMERECT_LEFT : SETTING_BUTTON_WIDTH + 8);
260 uint text_right = r.right - (rtl ? SETTING_BUTTON_WIDTH + 8 : WD_FRAMERECT_RIGHT);
261
262 int y = r.top;
263 int button_y_offset = (this->line_height - SETTING_BUTTON_HEIGHT) / 2;
264 int text_y_offset = (this->line_height - FONT_HEIGHT_NORMAL) / 2;
265 for (uint i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < this->vscroll->GetCount(); i++) {
266 GRFParameterInfo *par_info = (i < this->grf_config->param_info.size()) ? this->grf_config->param_info[i] : nullptr;
267 if (par_info == nullptr) par_info = GetDummyParameterInfo(i);
268 uint32 current_value = par_info->GetValue(this->grf_config);
269 bool selected = (i == this->clicked_row);
270
271 if (par_info->type == PTYPE_BOOL) {
272 DrawBoolButton(buttons_left, y + button_y_offset, current_value != 0, this->editable);
273 SetDParam(2, par_info->GetValue(this->grf_config) == 0 ? STR_CONFIG_SETTING_OFF : STR_CONFIG_SETTING_ON);
274 } else if (par_info->type == PTYPE_UINT_ENUM) {
275 if (par_info->complete_labels) {
276 DrawDropDownButton(buttons_left, y + button_y_offset, COLOUR_YELLOW, this->clicked_row == i && this->clicked_dropdown, this->editable);
277 } else {
278 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);
279 }
280 SetDParam(2, STR_JUST_INT);
281 SetDParam(3, current_value);
282 if (par_info->value_names.Contains(current_value)) {
283 const char *label = GetGRFStringFromGRFText(par_info->value_names.Find(current_value)->second);
284 if (label != nullptr) {
285 SetDParam(2, STR_JUST_RAW_STRING);
286 SetDParamStr(3, label);
287 }
288 }
289 }
290
291 const char *name = GetGRFStringFromGRFText(par_info->name);
292 if (name != nullptr) {
293 SetDParam(0, STR_JUST_RAW_STRING);
294 SetDParamStr(1, name);
295 } else {
296 SetDParam(0, STR_NEWGRF_PARAMETERS_DEFAULT_NAME);
297 SetDParam(1, i + 1);
298 }
299
300 DrawString(text_left, text_right, y + text_y_offset, STR_NEWGRF_PARAMETERS_SETTING, selected ? TC_WHITE : TC_LIGHT_BLUE);
301 y += this->line_height;
302 }
303 }
304
305 void OnPaint() override
306 {
307 if (this->closing_dropdown) {
308 this->closing_dropdown = false;
309 this->clicked_dropdown = false;
310 }
311 this->DrawWidgets();
312 }
313
314 void OnClick(Point pt, int widget, int click_count) override
315 {
316 switch (widget) {
317 case WID_NP_NUMPAR_DEC:
318 if (this->editable && !this->action14present && this->grf_config->num_params > 0) {
319 this->grf_config->num_params--;
320 this->InvalidateData();
321 SetWindowDirty(WC_GAME_OPTIONS, WN_GAME_OPTIONS_NEWGRF_STATE);
322 }
323 break;
324
325 case WID_NP_NUMPAR_INC: {
326 GRFConfig *c = this->grf_config;
327 if (this->editable && !this->action14present && c->num_params < c->num_valid_params) {
328 c->param[c->num_params++] = 0;
329 this->InvalidateData();
330 SetWindowDirty(WC_GAME_OPTIONS, WN_GAME_OPTIONS_NEWGRF_STATE);
331 }
332 break;
333 }
334
335 case WID_NP_BACKGROUND: {
336 if (!this->editable) break;
337 uint num = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_NP_BACKGROUND);
338 if (num >= this->vscroll->GetCount()) break;
339 if (this->clicked_row != num) {
340 DeleteChildWindows(WC_QUERY_STRING);
341 HideDropDownMenu(this);
342 this->clicked_row = num;
343 this->clicked_dropdown = false;
344 }
345
346 const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_NP_BACKGROUND);
347 int x = pt.x - wid->pos_x;
348 if (_current_text_dir == TD_RTL) x = wid->current_x - 1 - x;
349 x -= 4;
350
351 GRFParameterInfo *par_info = (num < this->grf_config->param_info.size()) ? this->grf_config->param_info[num] : nullptr;
352 if (par_info == nullptr) par_info = GetDummyParameterInfo(num);
353
354 /* One of the arrows is clicked */
355 uint32 old_val = par_info->GetValue(this->grf_config);
356 if (par_info->type != PTYPE_BOOL && IsInsideMM(x, 0, SETTING_BUTTON_WIDTH) && par_info->complete_labels) {
357 if (this->clicked_dropdown) {
358 /* unclick the dropdown */
359 HideDropDownMenu(this);
360 this->clicked_dropdown = false;
361 this->closing_dropdown = false;
362 } else {
363 const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_NP_BACKGROUND);
364 int rel_y = (pt.y - (int)wid->pos_y) % this->line_height;
365
366 Rect wi_rect;
367 wi_rect.left = pt.x - (_current_text_dir == TD_RTL ? SETTING_BUTTON_WIDTH - 1 - x : x);;
368 wi_rect.right = wi_rect.left + SETTING_BUTTON_WIDTH - 1;
369 wi_rect.top = pt.y - rel_y + (this->line_height - SETTING_BUTTON_HEIGHT) / 2;
370 wi_rect.bottom = wi_rect.top + SETTING_BUTTON_HEIGHT - 1;
371
372 /* For dropdowns we also have to check the y position thoroughly, the mouse may not above the just opening dropdown */
373 if (pt.y >= wi_rect.top && pt.y <= wi_rect.bottom) {
374 this->clicked_dropdown = true;
375 this->closing_dropdown = false;
376
377 DropDownList list;
378 for (uint32 i = par_info->min_value; i <= par_info->max_value; i++) {
379 list.emplace_back(new DropDownListCharStringItem(GetGRFStringFromGRFText(par_info->value_names.Find(i)->second), i, false));
380 }
381
382 ShowDropDownListAt(this, std::move(list), old_val, -1, wi_rect, COLOUR_ORANGE, true);
383 }
384 }
385 } else if (IsInsideMM(x, 0, SETTING_BUTTON_WIDTH)) {
386 uint32 val = old_val;
387 if (par_info->type == PTYPE_BOOL) {
388 val = !val;
389 } else {
390 if (x >= SETTING_BUTTON_WIDTH / 2) {
391 /* Increase button clicked */
392 if (val < par_info->max_value) val++;
393 this->clicked_increase = true;
394 } else {
395 /* Decrease button clicked */
396 if (val > par_info->min_value) val--;
397 this->clicked_increase = false;
398 }
399 }
400 if (val != old_val) {
401 par_info->SetValue(this->grf_config, val);
402
403 this->clicked_button = num;
404 this->timeout.SetInterval(150);
405 }
406 } else if (par_info->type == PTYPE_UINT_ENUM && !par_info->complete_labels && click_count >= 2) {
407 /* Display a query box so users can enter a custom value. */
408 SetDParam(0, old_val);
409 ShowQueryString(STR_JUST_INT, STR_CONFIG_SETTING_QUERY_CAPTION, 10, this, CS_NUMERAL, QSF_NONE);
410 }
411 this->SetDirty();
412 break;
413 }
414
415 case WID_NP_RESET:
416 if (!this->editable) break;
417 this->grf_config->SetParameterDefaults();
418 this->InvalidateData();
419 SetWindowDirty(WC_GAME_OPTIONS, WN_GAME_OPTIONS_NEWGRF_STATE);
420 break;
421
422 case WID_NP_ACCEPT:
423 delete this;
424 break;
425 }
426 }
427
428 void OnQueryTextFinished(char *str) override
429 {
430 if (StrEmpty(str)) return;
431 int32 value = atoi(str);
432 GRFParameterInfo *par_info = ((uint)this->clicked_row < this->grf_config->param_info.size()) ? this->grf_config->param_info[this->clicked_row] : nullptr;
433 if (par_info == nullptr) par_info = GetDummyParameterInfo(this->clicked_row);
434 uint32 val = Clamp<uint32>(value, par_info->min_value, par_info->max_value);
435 par_info->SetValue(this->grf_config, val);
436 this->SetDirty();
437 }
438
439 void OnDropdownSelect(int widget, int index) override
440 {
441 assert(this->clicked_dropdown);
442 GRFParameterInfo *par_info = ((uint)this->clicked_row < this->grf_config->param_info.size()) ? this->grf_config->param_info[this->clicked_row] : nullptr;
443 if (par_info == nullptr) par_info = GetDummyParameterInfo(this->clicked_row);
444 par_info->SetValue(this->grf_config, index);
445 this->SetDirty();
446 }
447
448 void OnDropdownClose(Point pt, int widget, int index, bool instant_close) override
449 {
450 /* We cannot raise the dropdown button just yet. OnClick needs some hint, whether
451 * the same dropdown button was clicked again, and then not open the dropdown again.
452 * So, we only remember that it was closed, and process it on the next OnPaint, which is
453 * after OnClick. */
454 assert(this->clicked_dropdown);
455 this->closing_dropdown = true;
456 this->SetDirty();
457 }
458
459 void OnResize() override
460 {
461 this->vscroll->SetCapacityFromWidget(this, WID_NP_BACKGROUND);
462 }
463
469 void OnInvalidateData(int data = 0, bool gui_scope = true) override
470 {
471 if (!gui_scope) return;
472 if (!this->action14present) {
473 this->SetWidgetDisabledState(WID_NP_NUMPAR_DEC, !this->editable || this->grf_config->num_params == 0);
474 this->SetWidgetDisabledState(WID_NP_NUMPAR_INC, !this->editable || this->grf_config->num_params >= this->grf_config->num_valid_params);
475 }
476
477 this->vscroll->SetCount(this->action14present ? this->grf_config->num_valid_params : this->grf_config->num_params);
478 if (this->clicked_row != UINT_MAX && this->clicked_row >= this->vscroll->GetCount()) {
479 this->clicked_row = UINT_MAX;
480 DeleteChildWindows(WC_QUERY_STRING);
481 }
482 }
483
484 void OnRealtimeTick(uint delta_ms) override
485 {
486 if (timeout.Elapsed(delta_ms)) {
487 this->clicked_button = UINT_MAX;
488 this->SetDirty();
489 }
490 }
491 };
492 GRFParameterInfo NewGRFParametersWindow::dummy_parameter_info(0);
493
494
495 static const NWidgetPart _nested_newgrf_parameter_widgets[] = {
496 NWidget(NWID_HORIZONTAL),
497 NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
498 NWidget(WWT_CAPTION, COLOUR_MAUVE), SetDataTip(STR_NEWGRF_PARAMETERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
499 NWidget(WWT_DEFSIZEBOX, COLOUR_MAUVE),
500 EndContainer(),
501 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_NP_SHOW_NUMPAR),
502 NWidget(WWT_PANEL, COLOUR_MAUVE), SetResize(1, 0), SetFill(1, 0), SetPIP(4, 0, 4),
503 NWidget(NWID_HORIZONTAL), SetPIP(4, 0, 4),
504 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_NP_NUMPAR_DEC), SetMinimalSize(12, 12), SetDataTip(AWV_DECREASE, STR_NULL),
505 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_NP_NUMPAR_INC), SetMinimalSize(12, 12), SetDataTip(AWV_INCREASE, STR_NULL),
506 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),
507 EndContainer(),
508 EndContainer(),
509 EndContainer(),
510 NWidget(NWID_HORIZONTAL),
511 NWidget(WWT_MATRIX, COLOUR_MAUVE, WID_NP_BACKGROUND), SetMinimalSize(188, 182), SetResize(1, 1), SetFill(1, 0), SetMatrixDataTip(1, 0, STR_NULL), SetScrollbar(WID_NP_SCROLLBAR),
512 NWidget(NWID_VSCROLLBAR, COLOUR_MAUVE, WID_NP_SCROLLBAR),
513 EndContainer(),
514 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_NP_SHOW_DESCRIPTION),
515 NWidget(WWT_PANEL, COLOUR_MAUVE, WID_NP_DESCRIPTION), SetResize(1, 0), SetFill(1, 0),
516 EndContainer(),
517 EndContainer(),
518 NWidget(NWID_HORIZONTAL),
519 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
520 NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_NP_ACCEPT), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_NEWGRF_PARAMETERS_CLOSE, STR_NULL),
521 NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_NP_RESET), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_NEWGRF_PARAMETERS_RESET, STR_NEWGRF_PARAMETERS_RESET_TOOLTIP),
522 EndContainer(),
523 NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
524 EndContainer(),
525 };
526
528 static WindowDesc _newgrf_parameters_desc(
529 WDP_CENTER, "settings_newgrf_config", 500, 208,
530 WC_GRF_PARAMETERS, WC_NONE,
531 0,
532 _nested_newgrf_parameter_widgets, lengthof(_nested_newgrf_parameter_widgets)
533 );
534
535 static void OpenGRFParameterWindow(GRFConfig *c, bool editable)
536 {
537 DeleteWindowByClass(WC_GRF_PARAMETERS);
538 new NewGRFParametersWindow(&_newgrf_parameters_desc, c, editable);
539 }
540
542 struct NewGRFTextfileWindow : public TextfileWindow {
543 const GRFConfig *grf_config;
544
545 NewGRFTextfileWindow(TextfileType file_type, const GRFConfig *c) : TextfileWindow(file_type), grf_config(c)
546 {
547 const char *textfile = this->grf_config->GetTextfile(file_type);
548 this->LoadTextfile(textfile, NEWGRF_DIR);
549 }
550
551 void SetStringParameters(int widget) const override
552 {
553 if (widget == WID_TF_CAPTION) {
554 SetDParam(0, STR_CONTENT_TYPE_NEWGRF);
555 SetDParamStr(1, this->grf_config->GetName());
556 }
557 }
558 };
559
560 void ShowNewGRFTextfileWindow(TextfileType file_type, const GRFConfig *c)
561 {
562 DeleteWindowById(WC_TEXTFILE, file_type);
563 new NewGRFTextfileWindow(file_type, c);
564 }
565
566 typedef std::map<uint32, const GRFConfig *> GrfIdMap;
567
573 static void FillGrfidMap(const GRFConfig *c, GrfIdMap *grfid_map)
574 {
575 while (c != nullptr) {
576 std::pair<uint32, const GRFConfig *> p(c->ident.grfid, c);
577 grfid_map->insert(p);
578 c = c->next;
579 }
580 }
581
582 static void NewGRFConfirmationCallback(Window *w, bool confirmed);
583 static void ShowSavePresetWindow(const char *initial_text);
584
588 struct NewGRFWindow : public Window, NewGRFScanCallback {
589 typedef GUIList<const GRFConfig *, StringFilter &> GUIGRFConfigList;
590
591 static const uint EDITBOX_MAX_SIZE = 50;
592
593 static Listing last_sorting;
594 static Filtering last_filtering;
595 static GUIGRFConfigList::SortFunction * const sorter_funcs[];
596 static GUIGRFConfigList::FilterFunction * const filter_funcs[];
597
598 GUIGRFConfigList avails;
599 const GRFConfig *avail_sel;
600 int avail_pos;
601 StringFilter string_filter;
602 QueryString filter_editbox;
603
604 StringList grf_presets;
605
606 GRFConfig *actives;
607 GRFConfig *active_sel;
608
609 GRFConfig **orig_list;
610 bool editable;
611 bool show_params;
612 bool execute;
613 int preset;
614 int active_over;
615
616 Scrollbar *vscroll;
617 Scrollbar *vscroll2;
618
619 NewGRFWindow(WindowDesc *desc, bool editable, bool show_params, bool execute, GRFConfig **orig_list) : Window(desc), filter_editbox(EDITBOX_MAX_SIZE)
620 {
621 this->avail_sel = nullptr;
622 this->avail_pos = -1;
623 this->active_sel = nullptr;
624 this->actives = nullptr;
625 this->orig_list = orig_list;
626 this->editable = editable;
627 this->execute = execute;
628 this->show_params = show_params;
629 this->preset = -1;
630 this->active_over = -1;
631
632 CopyGRFConfigList(&this->actives, *orig_list, false);
633 this->grf_presets = GetGRFPresetList();
634
635 this->CreateNestedTree();
636 this->vscroll = this->GetScrollbar(WID_NS_SCROLLBAR);
637 this->vscroll2 = this->GetScrollbar(WID_NS_SCROLL2BAR);
638
639 this->GetWidget<NWidgetStacked>(WID_NS_SHOW_REMOVE)->SetDisplayedPlane(this->editable ? 0 : 1);
640 this->GetWidget<NWidgetStacked>(WID_NS_SHOW_APPLY)->SetDisplayedPlane(this->editable ? 0 : this->show_params ? 1 : SZSP_HORIZONTAL);
641 this->FinishInitNested(WN_GAME_OPTIONS_NEWGRF_STATE);
642
643 this->querystrings[WID_NS_FILTER] = &this->filter_editbox;
644 this->filter_editbox.cancel_button = QueryString::ACTION_CLEAR;
645 if (editable) {
646 this->SetFocusedWidget(WID_NS_FILTER);
647 } else {
648 this->DisableWidget(WID_NS_FILTER);
649 }
650
651 this->avails.SetListing(this->last_sorting);
652 this->avails.SetFiltering(this->last_filtering);
653 this->avails.SetSortFuncs(this->sorter_funcs);
654 this->avails.SetFilterFuncs(this->filter_funcs);
655 this->avails.ForceRebuild();
656
657 this->OnInvalidateData(GOID_NEWGRF_LIST_EDITED);
658 }
659
660 ~NewGRFWindow()
661 {
662 DeleteWindowByClass(WC_GRF_PARAMETERS);
663 DeleteWindowByClass(WC_TEXTFILE);
664 DeleteWindowByClass(WC_SAVE_PRESET);
665
666 if (this->editable && !this->execute && !_exit_game) {
667 CopyGRFConfigList(this->orig_list, this->actives, true);
668 ResetGRFConfig(false);
669 ReloadNewGRFData();
670 }
671
672 /* Remove the temporary copy of grf-list used in window */
673 ClearGRFConfigList(&this->actives);
674 }
675
680 bool CanUpgradeCurrent()
681 {
682 GrfIdMap grfid_map;
683 FillGrfidMap(this->actives, &grfid_map);
684
685 for (const GRFConfig *a = _all_grfs; a != nullptr; a = a->next) {
686 GrfIdMap::const_iterator iter = grfid_map.find(a->ident.grfid);
687 if (iter != grfid_map.end() && a->version > iter->second->version) return true;
688 }
689 return false;
690 }
691
693 void UpgradeCurrent()
694 {
695 GrfIdMap grfid_map;
696 FillGrfidMap(this->actives, &grfid_map);
697
698 for (const GRFConfig *a = _all_grfs; a != nullptr; a = a->next) {
699 GrfIdMap::iterator iter = grfid_map.find(a->ident.grfid);
700 if (iter == grfid_map.end() || iter->second->version >= a->version) continue;
701
702 GRFConfig **c = &this->actives;
703 while (*c != iter->second) c = &(*c)->next;
704 GRFConfig *d = new GRFConfig(*a);
705 d->next = (*c)->next;
706 d->CopyParams(**c);
707 if (this->active_sel == *c) {
708 DeleteWindowByClass(WC_GRF_PARAMETERS);
709 DeleteWindowByClass(WC_TEXTFILE);
710 this->active_sel = nullptr;
711 }
712 delete *c;
713 *c = d;
714 iter->second = d;
715 }
716 }
717
718 void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
719 {
720 switch (widget) {
721 case WID_NS_FILE_LIST:
722 {
723 Dimension d = maxdim(GetSpriteSize(SPR_SQUARE), GetSpriteSize(SPR_WARNING_SIGN));
724 resize->height = std::max(d.height + 2U, FONT_HEIGHT_NORMAL + 2U);
725 size->height = std::max(size->height, WD_FRAMERECT_TOP + 6 * resize->height + WD_FRAMERECT_BOTTOM);
726 break;
727 }
728
729 case WID_NS_AVAIL_LIST:
730 resize->height = std::max(12, FONT_HEIGHT_NORMAL + 2);
731 size->height = std::max(size->height, WD_FRAMERECT_TOP + 8 * resize->height + WD_FRAMERECT_BOTTOM);
732 break;
733
734 case WID_NS_NEWGRF_INFO_TITLE: {
735 Dimension dim = GetStringBoundingBox(STR_NEWGRF_SETTINGS_INFO_TITLE);
736 size->height = std::max(size->height, dim.height + WD_FRAMETEXT_TOP + WD_FRAMETEXT_BOTTOM);
737 size->width = std::max(size->width, dim.width + WD_FRAMETEXT_LEFT + WD_FRAMETEXT_RIGHT);
738 break;
739 }
740
741 case WID_NS_NEWGRF_INFO:
742 size->height = std::max(size->height, WD_FRAMERECT_TOP + 10 * FONT_HEIGHT_NORMAL + WD_FRAMERECT_BOTTOM + padding.height + 2);
743 break;
744
745 case WID_NS_PRESET_LIST: {
746 Dimension d = GetStringBoundingBox(STR_NUM_CUSTOM);
747 for (const auto &i : this->grf_presets) {
748 SetDParamStr(0, i.c_str());
749 d = maxdim(d, GetStringBoundingBox(STR_JUST_RAW_STRING));
750 }
751 d.width += padding.width;
752 *size = maxdim(d, *size);
753 break;
754 }
755
756 case WID_NS_CONTENT_DOWNLOAD:
757 case WID_NS_CONTENT_DOWNLOAD2: {
758 Dimension d = GetStringBoundingBox(STR_NEWGRF_SETTINGS_FIND_MISSING_CONTENT_BUTTON);
759 *size = maxdim(d, GetStringBoundingBox(STR_INTRO_ONLINE_CONTENT));
760 size->width += padding.width;
761 size->height += padding.height;
762 break;
763 }
764 }
765 }
766
767 void OnResize() override
768 {
769 this->vscroll->SetCapacityFromWidget(this, WID_NS_FILE_LIST);
770 this->vscroll2->SetCapacityFromWidget(this, WID_NS_AVAIL_LIST);
771 }
772
773 void SetStringParameters(int widget) const override
774 {
775 switch (widget) {
776 case WID_NS_PRESET_LIST:
777 if (this->preset == -1) {
778 SetDParam(0, STR_NUM_CUSTOM);
779 } else {
780 SetDParam(0, STR_JUST_RAW_STRING);
781 SetDParamStr(1, this->grf_presets[this->preset].c_str());
782 }
783 break;
784 }
785 }
786
792 inline PaletteID GetPalette(const GRFConfig *c) const
793 {
794 PaletteID pal;
795
796 /* Pick a colour */
797 switch (c->status) {
798 case GCS_NOT_FOUND:
799 case GCS_DISABLED:
800 pal = PALETTE_TO_RED;
801 break;
802 case GCS_ACTIVATED:
803 pal = PALETTE_TO_GREEN;
804 break;
805 default:
806 pal = PALETTE_TO_BLUE;
807 break;
808 }
809
810 /* Do not show a "not-failure" colour when it actually failed to load */
811 if (pal != PALETTE_TO_RED) {
812 if (HasBit(c->flags, GCF_STATIC)) {
813 pal = PALETTE_TO_GREY;
814 } else if (HasBit(c->flags, GCF_COMPATIBLE)) {
815 pal = PALETTE_TO_ORANGE;
816 }
817 }
818
819 return pal;
820 }
821
822 void DrawWidget(const Rect &r, int widget) const override
823 {
824 switch (widget) {
825 case WID_NS_FILE_LIST: {
826 GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, PC_BLACK);
827
828 uint step_height = this->GetWidget<NWidgetBase>(WID_NS_FILE_LIST)->resize_y;
829 uint y = r.top + WD_FRAMERECT_TOP;
830 Dimension square = GetSpriteSize(SPR_SQUARE);
831 Dimension warning = GetSpriteSize(SPR_WARNING_SIGN);
832 int square_offset_y = (step_height - square.height) / 2;
833 int warning_offset_y = (step_height - warning.height) / 2;
834 int offset_y = (step_height - FONT_HEIGHT_NORMAL) / 2;
835
836 bool rtl = _current_text_dir == TD_RTL;
837 uint text_left = rtl ? r.left + WD_FRAMERECT_LEFT : r.left + square.width + 15;
838 uint text_right = rtl ? r.right - square.width - 15 : r.right - WD_FRAMERECT_RIGHT;
839 uint square_left = rtl ? r.right - square.width - 5 : r.left + 5;
840 uint warning_left = rtl ? r.right - square.width - warning.width - 10 : r.left + square.width + 10;
841
842 int i = 0;
843 for (const GRFConfig *c = this->actives; c != nullptr; c = c->next, i++) {
844 if (this->vscroll->IsVisible(i)) {
845 const char *text = c->GetName();
846 bool h = (this->active_sel == c);
847 PaletteID pal = this->GetPalette(c);
848
849 if (h) {
850 GfxFillRect(r.left + 1, y, r.right - 1, y + step_height - 1, PC_DARK_BLUE);
851 } else if (i == this->active_over) {
852 /* Get index of current selection. */
853 int active_sel_pos = 0;
854 for (GRFConfig *c = this->actives; c != nullptr && c != this->active_sel; c = c->next, active_sel_pos++) {}
855 if (active_sel_pos != this->active_over) {
856 uint top = this->active_over < active_sel_pos ? y + 1 : y + step_height - 2;
857 GfxFillRect(r.left + WD_FRAMERECT_LEFT, top - 1, r.right - WD_FRAMERECT_RIGHT, top + 1, PC_GREY);
858 }
859 }
860 DrawSprite(SPR_SQUARE, pal, square_left, y + square_offset_y);
861 if (c->error != nullptr) DrawSprite(SPR_WARNING_SIGN, 0, warning_left, y + warning_offset_y);
862 uint txtoffset = c->error == nullptr ? 0 : warning.width;
863 DrawString(text_left + (rtl ? 0 : txtoffset), text_right - (rtl ? txtoffset : 0), y + offset_y, text, h ? TC_WHITE : TC_ORANGE);
864 y += step_height;
865 }
866 }
867 if (i == this->active_over && this->vscroll->IsVisible(i)) { // Highlight is after the last GRF entry.
868 GfxFillRect(r.left + WD_FRAMERECT_LEFT, y, r.right - WD_FRAMERECT_RIGHT, y + 2, PC_GREY);
869 }
870 break;
871 }
872
873 case WID_NS_AVAIL_LIST: {
874 GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, this->active_over == -2 ? PC_DARK_GREY : PC_BLACK);
875
876 uint step_height = this->GetWidget<NWidgetBase>(WID_NS_AVAIL_LIST)->resize_y;
877 int offset_y = (step_height - FONT_HEIGHT_NORMAL) / 2;
878 uint y = r.top + WD_FRAMERECT_TOP;
879 uint min_index = this->vscroll2->GetPosition();
880 uint max_index = std::min(min_index + this->vscroll2->GetCapacity(), (uint)this->avails.size());
881
882 for (uint i = min_index; i < max_index; i++) {
883 const GRFConfig *c = this->avails[i];
884 bool h = (c == this->avail_sel);
885 const char *text = c->GetName();
886
887 if (h) GfxFillRect(r.left + 1, y, r.right - 1, y + step_height - 1, PC_DARK_BLUE);
888 DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y + offset_y, text, h ? TC_WHITE : TC_SILVER);
889 y += step_height;
890 }
891 break;
892 }
893
894 case WID_NS_NEWGRF_INFO_TITLE:
895 /* Create the nice grayish rectangle at the details top. */
896 GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, PC_DARK_BLUE);
897 DrawString(r.left, r.right, (r.top + r.bottom - FONT_HEIGHT_NORMAL) / 2, STR_NEWGRF_SETTINGS_INFO_TITLE, TC_FROMSTRING, SA_HOR_CENTER);
898 break;
899
900 case WID_NS_NEWGRF_INFO: {
901 const GRFConfig *selected = this->active_sel;
902 if (selected == nullptr) selected = this->avail_sel;
903 if (selected != nullptr) {
904 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);
905 }
906 break;
907 }
908 }
909 }
910
911 void OnClick(Point pt, int widget, int click_count) override
912 {
913 if (widget >= WID_NS_NEWGRF_TEXTFILE && widget < WID_NS_NEWGRF_TEXTFILE + TFT_END) {
914 if (this->active_sel == nullptr && this->avail_sel == nullptr) return;
915
916 ShowNewGRFTextfileWindow((TextfileType)(widget - WID_NS_NEWGRF_TEXTFILE), this->active_sel != nullptr ? this->active_sel : this->avail_sel);
917 return;
918 }
919
920 switch (widget) {
921 case WID_NS_PRESET_LIST: {
922 DropDownList list;
923
924 /* Add 'None' option for clearing list */
925 list.emplace_back(new DropDownListStringItem(STR_NONE, -1, false));
926
927 for (uint i = 0; i < this->grf_presets.size(); i++) {
928 list.emplace_back(new DropDownListCharStringItem(this->grf_presets[i], i, false));
929 }
930
931 this->DeleteChildWindows(WC_QUERY_STRING); // Remove the parameter query window
932 ShowDropDownList(this, std::move(list), this->preset, WID_NS_PRESET_LIST);
933 break;
934 }
935
936 case WID_NS_OPEN_URL: {
937 const GRFConfig *c = (this->avail_sel == nullptr) ? this->active_sel : this->avail_sel;
938
939 extern void OpenBrowser(const char *url);
940 OpenBrowser(c->GetURL());
941 break;
942 }
943
944 case WID_NS_PRESET_SAVE:
945 ShowSavePresetWindow((this->preset == -1) ? nullptr : this->grf_presets[this->preset].c_str());
946 break;
947
948 case WID_NS_PRESET_DELETE:
949 if (this->preset == -1) return;
950
951 DeleteGRFPresetFromConfig(this->grf_presets[this->preset].c_str());
952 this->grf_presets = GetGRFPresetList();
953 this->preset = -1;
954 this->InvalidateData();
955 this->DeleteChildWindows(WC_QUERY_STRING); // Remove the parameter query window
956 break;
957
958 case WID_NS_MOVE_UP: { // Move GRF up
959 if (this->active_sel == nullptr || !this->editable) break;
960
961 int pos = 0;
962 for (GRFConfig **pc = &this->actives; *pc != nullptr; pc = &(*pc)->next, pos++) {
963 GRFConfig *c = *pc;
964 if (c->next == this->active_sel) {
965 c->next = this->active_sel->next;
966 this->active_sel->next = c;
967 *pc = this->active_sel;
968 break;
969 }
970 }
971 this->vscroll->ScrollTowards(pos);
972 this->preset = -1;
973 this->InvalidateData();
974 break;
975 }
976
977 case WID_NS_MOVE_DOWN: { // Move GRF down
978 if (this->active_sel == nullptr || !this->editable) break;
979
980 int pos = 1; // Start at 1 as we swap the selected newgrf with the next one
981 for (GRFConfig **pc = &this->actives; *pc != nullptr; pc = &(*pc)->next, pos++) {
982 GRFConfig *c = *pc;
983 if (c == this->active_sel) {
984 *pc = c->next;
985 c->next = c->next->next;
986 (*pc)->next = c;
987 break;
988 }
989 }
990 this->vscroll->ScrollTowards(pos);
991 this->preset = -1;
992 this->InvalidateData();
993 break;
994 }
995
996 case WID_NS_FILE_LIST: { // Select an active GRF.
997 ResetObjectToPlace();
998
999 uint i = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_NS_FILE_LIST);
1000
1001 GRFConfig *c;
1002 for (c = this->actives; c != nullptr && i > 0; c = c->next, i--) {}
1003
1004 if (this->active_sel != c) {
1005 DeleteWindowByClass(WC_GRF_PARAMETERS);
1006 DeleteWindowByClass(WC_TEXTFILE);
1007 }
1008 this->active_sel = c;
1009 this->avail_sel = nullptr;
1010 this->avail_pos = -1;
1011
1012 this->InvalidateData();
1013 if (click_count == 1) {
1014 if (this->editable && this->active_sel != nullptr) SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this);
1015 break;
1016 }
1017 /* With double click, continue */
1018 FALLTHROUGH;
1019 }
1020
1021 case WID_NS_REMOVE: { // Remove GRF
1022 if (this->active_sel == nullptr || !this->editable) break;
1023 DeleteWindowByClass(WC_GRF_PARAMETERS);
1024 DeleteWindowByClass(WC_TEXTFILE);
1025
1026 /* Choose the next GRF file to be the selected file. */
1027 GRFConfig *newsel = this->active_sel->next;
1028 for (GRFConfig **pc = &this->actives; *pc != nullptr; pc = &(*pc)->next) {
1029 GRFConfig *c = *pc;
1030 /* If the new selection is empty (i.e. we're deleting the last item
1031 * in the list, pick the file just before the selected file */
1032 if (newsel == nullptr && c->next == this->active_sel) newsel = c;
1033
1034 if (c == this->active_sel) {
1035 if (newsel == c) newsel = nullptr;
1036
1037 *pc = c->next;
1038 delete c;
1039 break;
1040 }
1041 }
1042
1043 this->active_sel = newsel;
1044 this->preset = -1;
1045 this->avail_pos = -1;
1046 this->avail_sel = nullptr;
1047 this->avails.ForceRebuild();
1048 this->InvalidateData(GOID_NEWGRF_LIST_EDITED);
1049 break;
1050 }
1051
1052 case WID_NS_UPGRADE: { // Upgrade GRF.
1053 if (!this->editable || this->actives == nullptr) break;
1054 UpgradeCurrent();
1055 this->InvalidateData(GOID_NEWGRF_LIST_EDITED);
1056 break;
1057 }
1058
1059 case WID_NS_AVAIL_LIST: { // Select a non-active GRF.
1060 ResetObjectToPlace();
1061
1062 uint i = this->vscroll2->GetScrolledRowFromWidget(pt.y, this, WID_NS_AVAIL_LIST);
1063 this->active_sel = nullptr;
1064 DeleteWindowByClass(WC_GRF_PARAMETERS);
1065 if (i < this->avails.size()) {
1066 if (this->avail_sel != this->avails[i]) DeleteWindowByClass(WC_TEXTFILE);
1067 this->avail_sel = this->avails[i];
1068 this->avail_pos = i;
1069 }
1070 this->InvalidateData();
1071 if (click_count == 1) {
1072 if (this->editable && this->avail_sel != nullptr && !HasBit(this->avail_sel->flags, GCF_INVALID)) SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this);
1073 break;
1074 }
1075 /* With double click, continue */
1076 FALLTHROUGH;
1077 }
1078
1079 case WID_NS_ADD:
1080 if (this->avail_sel == nullptr || !this->editable || HasBit(this->avail_sel->flags, GCF_INVALID)) break;
1081
1082 this->AddGRFToActive();
1083 break;
1084
1085 case WID_NS_APPLY_CHANGES: // Apply changes made to GRF list
1086 if (!this->editable) break;
1087 if (this->execute) {
1088 ShowQuery(
1089 STR_NEWGRF_POPUP_CAUTION_CAPTION,
1090 STR_NEWGRF_CONFIRMATION_TEXT,
1091 this,
1092 NewGRFConfirmationCallback
1093 );
1094 } else {
1095 CopyGRFConfigList(this->orig_list, this->actives, true);
1096 ResetGRFConfig(false);
1097 ReloadNewGRFData();
1098 }
1099 this->DeleteChildWindows(WC_QUERY_STRING); // Remove the parameter query window
1100 break;
1101
1102 case WID_NS_VIEW_PARAMETERS:
1103 case WID_NS_SET_PARAMETERS: { // Edit parameters
1104 if (this->active_sel == nullptr || !this->show_params || this->active_sel->num_valid_params == 0) break;
1105
1106 OpenGRFParameterWindow(this->active_sel, this->editable);
1107 break;
1108 }
1109
1110 case WID_NS_TOGGLE_PALETTE:
1111 if (this->active_sel != nullptr && this->editable) {
1112 this->active_sel->palette ^= GRFP_USE_MASK;
1113 this->SetDirty();
1114 }
1115 break;
1116
1117 case WID_NS_CONTENT_DOWNLOAD:
1118 case WID_NS_CONTENT_DOWNLOAD2:
1119 if (!_network_available) {
1120 ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, WL_ERROR);
1121 } else {
1122 this->DeleteChildWindows(WC_QUERY_STRING); // Remove the parameter query window
1123
1124 ShowMissingContentWindow(this->actives);
1125 }
1126 break;
1127
1128 case WID_NS_RESCAN_FILES:
1129 case WID_NS_RESCAN_FILES2:
1130 RequestNewGRFScan(this);
1131 break;
1132 }
1133 }
1134
1135 void OnNewGRFsScanned() override
1136 {
1137 if (this->active_sel == nullptr) DeleteWindowByClass(WC_TEXTFILE);
1138 this->avail_sel = nullptr;
1139 this->avail_pos = -1;
1140 this->avails.ForceRebuild();
1141 this->DeleteChildWindows(WC_QUERY_STRING); // Remove the parameter query window
1142 }
1143
1144 void OnDropdownSelect(int widget, int index) override
1145 {
1146 if (!this->editable) return;
1147
1148 ClearGRFConfigList(&this->actives);
1149 this->preset = index;
1150
1151 if (index != -1) {
1152 this->actives = LoadGRFPresetFromConfig(this->grf_presets[index].c_str());
1153 }
1154 this->avails.ForceRebuild();
1155
1156 ResetObjectToPlace();
1157 DeleteWindowByClass(WC_GRF_PARAMETERS);
1158 DeleteWindowByClass(WC_TEXTFILE);
1159 this->active_sel = nullptr;
1160 this->InvalidateData(GOID_NEWGRF_PRESET_LOADED);
1161 }
1162
1163 void OnQueryTextFinished(char *str) override
1164 {
1165 if (str == nullptr) return;
1166
1167 SaveGRFPresetToConfig(str, this->actives);
1168 this->grf_presets = GetGRFPresetList();
1169
1170 /* Switch to this preset */
1171 for (uint i = 0; i < this->grf_presets.size(); i++) {
1172 if (this->grf_presets[i] == str) {
1173 this->preset = i;
1174 break;
1175 }
1176 }
1177
1178 this->InvalidateData();
1179 }
1180
1186 void OnInvalidateData(int data = 0, bool gui_scope = true) override
1187 {
1188 if (!gui_scope) return;
1189 switch (data) {
1190 default:
1191 /* Nothing important to do */
1192 break;
1193
1194 case GOID_NEWGRF_RESCANNED:
1195 /* Search the list for items that are now found and mark them as such. */
1196 for (GRFConfig **l = &this->actives; *l != nullptr; l = &(*l)->next) {
1197 GRFConfig *c = *l;
1198 bool compatible = HasBit(c->flags, GCF_COMPATIBLE);
1199 if (c->status != GCS_NOT_FOUND && !compatible) continue;
1200
1201 const GRFConfig *f = FindGRFConfig(c->ident.grfid, FGCM_EXACT, compatible ? c->original_md5sum : c->ident.md5sum);
1202 if (f == nullptr || HasBit(f->flags, GCF_INVALID)) continue;
1203
1204 *l = new GRFConfig(*f);
1205 (*l)->next = c->next;
1206
1207 if (this->active_sel == c) this->active_sel = *l;
1208
1209 delete c;
1210 }
1211
1212 this->avails.ForceRebuild();
1213 FALLTHROUGH;
1214
1215 case GOID_NEWGRF_LIST_EDITED:
1216 this->preset = -1;
1217 FALLTHROUGH;
1218
1219 case GOID_NEWGRF_PRESET_LOADED: {
1220 /* Update scrollbars */
1221 int i = 0;
1222 for (const GRFConfig *c = this->actives; c != nullptr; c = c->next, i++) {}
1223
1224 this->vscroll->SetCount(i + 1); // Reserve empty space for drag and drop handling.
1225
1226 if (this->avail_pos >= 0) this->vscroll2->ScrollTowards(this->avail_pos);
1227 break;
1228 }
1229 }
1230
1231 this->BuildAvailables();
1232
1233 this->SetWidgetsDisabledState(!this->editable,
1234 WID_NS_PRESET_LIST,
1235 WID_NS_APPLY_CHANGES,
1236 WID_NS_TOGGLE_PALETTE,
1237 WIDGET_LIST_END
1238 );
1239 this->SetWidgetDisabledState(WID_NS_ADD, !this->editable || this->avail_sel == nullptr || HasBit(this->avail_sel->flags, GCF_INVALID));
1240 this->SetWidgetDisabledState(WID_NS_UPGRADE, !this->editable || this->actives == nullptr || !this->CanUpgradeCurrent());
1241
1242 bool disable_all = this->active_sel == nullptr || !this->editable;
1243 this->SetWidgetsDisabledState(disable_all,
1244 WID_NS_REMOVE,
1245 WID_NS_MOVE_UP,
1246 WID_NS_MOVE_DOWN,
1247 WIDGET_LIST_END
1248 );
1249
1250 const GRFConfig *c = (this->avail_sel == nullptr) ? this->active_sel : this->avail_sel;
1251 for (TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) {
1252 this->SetWidgetDisabledState(WID_NS_NEWGRF_TEXTFILE + tft, c == nullptr || c->GetTextfile(tft) == nullptr);
1253 }
1254 this->SetWidgetDisabledState(WID_NS_OPEN_URL, c == nullptr || StrEmpty(c->GetURL()));
1255
1256 this->SetWidgetDisabledState(WID_NS_SET_PARAMETERS, !this->show_params || this->active_sel == nullptr || this->active_sel->num_valid_params == 0);
1257 this->SetWidgetDisabledState(WID_NS_VIEW_PARAMETERS, !this->show_params || this->active_sel == nullptr || this->active_sel->num_valid_params == 0);
1258 this->SetWidgetDisabledState(WID_NS_TOGGLE_PALETTE, disable_all ||
1259 (!(_settings_client.gui.newgrf_developer_tools || _settings_client.gui.scenario_developer) && ((c->palette & GRFP_GRF_MASK) != GRFP_GRF_UNSET)));
1260
1261 if (!disable_all) {
1262 /* All widgets are now enabled, so disable widgets we can't use */
1263 if (this->active_sel == this->actives) this->DisableWidget(WID_NS_MOVE_UP);
1264 if (this->active_sel->next == nullptr) this->DisableWidget(WID_NS_MOVE_DOWN);
1265 }
1266
1267 this->SetWidgetDisabledState(WID_NS_PRESET_DELETE, this->preset == -1);
1268
1269 bool has_missing = false;
1270 bool has_compatible = false;
1271 for (const GRFConfig *c = this->actives; !has_missing && c != nullptr; c = c->next) {
1272 has_missing |= c->status == GCS_NOT_FOUND;
1273 has_compatible |= HasBit(c->flags, GCF_COMPATIBLE);
1274 }
1275 uint32 widget_data;
1276 StringID tool_tip;
1277 if (has_missing || has_compatible) {
1278 widget_data = STR_NEWGRF_SETTINGS_FIND_MISSING_CONTENT_BUTTON;
1279 tool_tip = STR_NEWGRF_SETTINGS_FIND_MISSING_CONTENT_TOOLTIP;
1280 } else {
1281 widget_data = STR_INTRO_ONLINE_CONTENT;
1282 tool_tip = STR_INTRO_TOOLTIP_ONLINE_CONTENT;
1283 }
1284 this->GetWidget<NWidgetCore>(WID_NS_CONTENT_DOWNLOAD)->widget_data = widget_data;
1285 this->GetWidget<NWidgetCore>(WID_NS_CONTENT_DOWNLOAD)->tool_tip = tool_tip;
1286 this->GetWidget<NWidgetCore>(WID_NS_CONTENT_DOWNLOAD2)->widget_data = widget_data;
1287 this->GetWidget<NWidgetCore>(WID_NS_CONTENT_DOWNLOAD2)->tool_tip = tool_tip;
1288
1289 this->SetWidgetDisabledState(WID_NS_PRESET_SAVE, has_missing);
1290 }
1291
1292 EventState OnKeyPress(WChar key, uint16 keycode) override
1293 {
1294 if (!this->editable) return ES_NOT_HANDLED;
1295
1296 switch (keycode) {
1297 case WKC_UP:
1298 /* scroll up by one */
1299 if (this->avail_pos > 0) this->avail_pos--;
1300 break;
1301
1302 case WKC_DOWN:
1303 /* scroll down by one */
1304 if (this->avail_pos < (int)this->avails.size() - 1) this->avail_pos++;
1305 break;
1306
1307 case WKC_PAGEUP:
1308 /* scroll up a page */
1309 this->avail_pos = (this->avail_pos < this->vscroll2->GetCapacity()) ? 0 : this->avail_pos - this->vscroll2->GetCapacity();
1310 break;
1311
1312 case WKC_PAGEDOWN:
1313 /* scroll down a page */
1314 this->avail_pos = std::min(this->avail_pos + this->vscroll2->GetCapacity(), (int)this->avails.size() - 1);
1315 break;
1316
1317 case WKC_HOME:
1318 /* jump to beginning */
1319 this->avail_pos = 0;
1320 break;
1321
1322 case WKC_END:
1323 /* jump to end */
1324 this->avail_pos = (uint)this->avails.size() - 1;
1325 break;
1326
1327 default:
1328 return ES_NOT_HANDLED;
1329 }
1330
1331 if (this->avails.size() == 0) this->avail_pos = -1;
1332 if (this->avail_pos >= 0) {
1333 this->active_sel = nullptr;
1334 DeleteWindowByClass(WC_GRF_PARAMETERS);
1335 if (this->avail_sel != this->avails[this->avail_pos]) DeleteWindowByClass(WC_TEXTFILE);
1336 this->avail_sel = this->avails[this->avail_pos];
1337 this->vscroll2->ScrollTowards(this->avail_pos);
1338 this->InvalidateData(0);
1339 }
1340
1341 return ES_HANDLED;
1342 }
1343
1344 void OnEditboxChanged(int wid) override
1345 {
1346 if (!this->editable) return;
1347
1348 string_filter.SetFilterTerm(this->filter_editbox.text.buf);
1349 this->avails.SetFilterState(!string_filter.IsEmpty());
1350 this->avails.ForceRebuild();
1351 this->InvalidateData(0);
1352 }
1353
1354 void OnDragDrop(Point pt, int widget) override
1355 {
1356 if (!this->editable) return;
1357
1358 if (widget == WID_NS_FILE_LIST) {
1359 if (this->active_sel != nullptr) {
1360 /* Get pointer to the selected file in the active list. */
1361 int from_pos = 0;
1362 GRFConfig **from_prev;
1363 for (from_prev = &this->actives; *from_prev != this->active_sel; from_prev = &(*from_prev)->next, from_pos++) {}
1364
1365 /* Gets the drag-and-drop destination offset. Ignore the last dummy line. */
1366 int to_pos = std::min(this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_NS_FILE_LIST), this->vscroll->GetCount() - 2);
1367 if (to_pos != from_pos) { // Don't move NewGRF file over itself.
1368 /* Get pointer to destination position. */
1369 GRFConfig **to_prev = &this->actives;
1370 for (int i = from_pos < to_pos ? -1 : 0; *to_prev != nullptr && i < to_pos; to_prev = &(*to_prev)->next, i++) {}
1371
1372 /* Detach NewGRF file from its original position. */
1373 *from_prev = this->active_sel->next;
1374
1375 /* Attach NewGRF file to its new position. */
1376 this->active_sel->next = *to_prev;
1377 *to_prev = this->active_sel;
1378
1379 this->vscroll->ScrollTowards(to_pos);
1380 this->preset = -1;
1381 this->InvalidateData();
1382 }
1383 } else if (this->avail_sel != nullptr) {
1384 int to_pos = std::min(this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_NS_FILE_LIST), this->vscroll->GetCount() - 1);
1385 this->AddGRFToActive(to_pos);
1386 }
1387 } else if (widget == WID_NS_AVAIL_LIST && this->active_sel != nullptr) {
1388 /* Remove active NewGRF file by dragging it over available list. */
1389 Point dummy = {-1, -1};
1390 this->OnClick(dummy, WID_NS_REMOVE, 1);
1391 }
1392
1393 ResetObjectToPlace();
1394
1395 if (this->active_over != -1) {
1396 /* End of drag-and-drop, hide dragged destination highlight. */
1397 this->SetWidgetDirty(this->active_over == -2 ? WID_NS_AVAIL_LIST : WID_NS_FILE_LIST);
1398 this->active_over = -1;
1399 }
1400 }
1401
1402 void OnMouseDrag(Point pt, int widget) override
1403 {
1404 if (!this->editable) return;
1405
1406 if (widget == WID_NS_FILE_LIST && (this->active_sel != nullptr || this->avail_sel != nullptr)) {
1407 /* An NewGRF file is dragged over the active list. */
1408 int to_pos = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_NS_FILE_LIST);
1409 /* Skip the last dummy line if the source is from the active list. */
1410 to_pos = std::min(to_pos, this->vscroll->GetCount() - (this->active_sel != nullptr ? 2 : 1));
1411
1412 if (to_pos != this->active_over) {
1413 this->active_over = to_pos;
1414 this->SetWidgetDirty(WID_NS_FILE_LIST);
1415 }
1416 } else if (widget == WID_NS_AVAIL_LIST && this->active_sel != nullptr) {
1417 this->active_over = -2;
1418 this->SetWidgetDirty(WID_NS_AVAIL_LIST);
1419 } else if (this->active_over != -1) {
1420 this->SetWidgetDirty(this->active_over == -2 ? WID_NS_AVAIL_LIST : WID_NS_FILE_LIST);
1421 this->active_over = -1;
1422 }
1423 }
1424
1425 private:
1427 static bool NameSorter(const GRFConfig * const &a, const GRFConfig * const &b)
1428 {
1429 int i = strnatcmp(a->GetName(), b->GetName(), true); // Sort by name (natural sorting).
1430 if (i != 0) return i < 0;
1431
1432 i = a->version - b->version;
1433 if (i != 0) return i < 0;
1434
1435 return memcmp(a->ident.md5sum, b->ident.md5sum, lengthof(b->ident.md5sum)) < 0;
1436 }
1437
1439 static bool CDECL TagNameFilter(const GRFConfig * const *a, StringFilter &filter)
1440 {
1441 filter.ResetState();
1442 filter.AddLine((*a)->GetName());
1443 filter.AddLine((*a)->filename);
1444 filter.AddLine((*a)->GetDescription());
1445 return filter.GetState();;
1446 }
1447
1448 void BuildAvailables()
1449 {
1450 if (!this->avails.NeedRebuild()) return;
1451
1452 this->avails.clear();
1453
1454 for (const GRFConfig *c = _all_grfs; c != nullptr; c = c->next) {
1455 bool found = false;
1456 for (const GRFConfig *grf = this->actives; grf != nullptr && !found; grf = grf->next) found = grf->ident.HasGrfIdentifier(c->ident.grfid, c->ident.md5sum);
1457 if (found) continue;
1458
1459 if (_settings_client.gui.newgrf_show_old_versions) {
1460 this->avails.push_back(c);
1461 } else {
1462 const GRFConfig *best = FindGRFConfig(c->ident.grfid, HasBit(c->flags, GCF_INVALID) ? FGCM_NEWEST : FGCM_NEWEST_VALID);
1463 /*
1464 * If the best version is 0, then all NewGRF with this GRF ID
1465 * have version 0, so for backward compatibility reasons we
1466 * want to show them all.
1467 * If we are the best version, then we definitely want to
1468 * show that NewGRF!.
1469 */
1470 if (best->version == 0 || best->ident.HasGrfIdentifier(c->ident.grfid, c->ident.md5sum)) {
1471 this->avails.push_back(c);
1472 }
1473 }
1474 }
1475
1476 this->avails.Filter(this->string_filter);
1477 this->avails.shrink_to_fit();
1478 this->avails.RebuildDone();
1479 this->avails.Sort();
1480
1481 if (this->avail_sel != nullptr) {
1482 this->avail_pos = find_index(this->avails, this->avail_sel);
1483 if (this->avail_pos == -1) {
1484 this->avail_sel = nullptr;
1485 }
1486 }
1487
1488 this->vscroll2->SetCount((uint)this->avails.size()); // Update the scrollbar
1489 }
1490
1496 bool AddGRFToActive(int ins_pos = -1)
1497 {
1498 if (this->avail_sel == nullptr || !this->editable || HasBit(this->avail_sel->flags, GCF_INVALID)) return false;
1499
1500 DeleteWindowByClass(WC_TEXTFILE);
1501
1502 uint count = 0;
1503 GRFConfig **entry = nullptr;
1504 GRFConfig **list;
1505 /* Find last entry in the list, checking for duplicate grfid on the way */
1506 for (list = &this->actives; *list != nullptr; list = &(*list)->next, ins_pos--) {
1507 if (ins_pos == 0) entry = list; // Insert position? Save.
1508 if ((*list)->ident.grfid == this->avail_sel->ident.grfid) {
1509 ShowErrorMessage(STR_NEWGRF_DUPLICATE_GRFID, INVALID_STRING_ID, WL_INFO);
1510 return false;
1511 }
1512 if (!HasBit((*list)->flags, GCF_STATIC)) count++;
1513 }
1514 if (entry == nullptr) entry = list;
1515 if (count >= NETWORK_MAX_GRF_COUNT) {
1516 ShowErrorMessage(STR_NEWGRF_TOO_MANY_NEWGRFS, INVALID_STRING_ID, WL_INFO);
1517 return false;
1518 }
1519
1520 GRFConfig *c = new GRFConfig(*this->avail_sel); // Copy GRF details from scanned list.
1521 c->SetParameterDefaults();
1522
1523 /* Insert GRF config to configuration list. */
1524 c->next = *entry;
1525 *entry = c;
1526
1527 /* Select next (or previous, if last one) item in the list. */
1528 int new_pos = this->avail_pos + 1;
1529 if (new_pos >= (int)this->avails.size()) new_pos = this->avail_pos - 1;
1530 this->avail_pos = new_pos;
1531 if (new_pos >= 0) this->avail_sel = this->avails[new_pos];
1532
1533 this->avails.ForceRebuild();
1534 this->InvalidateData(GOID_NEWGRF_LIST_EDITED);
1535 return true;
1536 }
1537 };
1538
1543 void ShowMissingContentWindow(const GRFConfig *list)
1544 {
1545 /* Only show the things in the current list, or everything when nothing's selected */
1546 ContentVector cv;
1547 for (const GRFConfig *c = list; c != nullptr; c = c->next) {
1548 if (c->status != GCS_NOT_FOUND && !HasBit(c->flags, GCF_COMPATIBLE)) continue;
1549
1550 ContentInfo *ci = new ContentInfo();
1551 ci->type = CONTENT_TYPE_NEWGRF;
1552 ci->state = ContentInfo::DOES_NOT_EXIST;
1553 strecpy(ci->name, c->GetName(), lastof(ci->name));
1554 ci->unique_id = BSWAP32(c->ident.grfid);
1555 memcpy(ci->md5sum, HasBit(c->flags, GCF_COMPATIBLE) ? c->original_md5sum : c->ident.md5sum, sizeof(ci->md5sum));
1556 cv.push_back(ci);
1557 }
1558 ShowNetworkContentListWindow(cv.size() == 0 ? nullptr : &cv, CONTENT_TYPE_NEWGRF);
1559 }
1560
1561 Listing NewGRFWindow::last_sorting = {false, 0};
1562 Filtering NewGRFWindow::last_filtering = {false, 0};
1563
1564 NewGRFWindow::GUIGRFConfigList::SortFunction * const NewGRFWindow::sorter_funcs[] = {
1565 &NameSorter,
1566 };
1567
1568 NewGRFWindow::GUIGRFConfigList::FilterFunction * const NewGRFWindow::filter_funcs[] = {
1569 &TagNameFilter,
1570 };
1571
1578 class NWidgetNewGRFDisplay : public NWidgetContainer {
1579 public:
1580 static const uint INTER_LIST_SPACING;
1581 static const uint INTER_COLUMN_SPACING;
1582 static const uint MAX_EXTRA_INFO_WIDTH;
1583 static const uint MIN_EXTRA_FOR_3_COLUMNS;
1584
1585 NWidgetBase *avs;
1586 NWidgetBase *acs;
1587 NWidgetBase *inf;
1588 bool editable;
1589
1590 NWidgetNewGRFDisplay(NWidgetBase *avs, NWidgetBase *acs, NWidgetBase *inf) : NWidgetContainer(NWID_HORIZONTAL)
1591 {
1592 this->avs = avs;
1593 this->acs = acs;
1594 this->inf = inf;
1595
1596 this->Add(this->avs);
1597 this->Add(this->acs);
1598 this->Add(this->inf);
1599
1600 this->editable = true; // Temporary setting, 'real' value is set in SetupSmallestSize().
1601 }
1602
1603 void SetupSmallestSize(Window *w, bool init_array) override
1604 {
1605 /* Copy state flag from the window. */
1606 assert(dynamic_cast<NewGRFWindow *>(w) != nullptr);
1607 NewGRFWindow *ngw = (NewGRFWindow *)w;
1608 this->editable = ngw->editable;
1609
1610 this->avs->SetupSmallestSize(w, init_array);
1611 this->acs->SetupSmallestSize(w, init_array);
1612 this->inf->SetupSmallestSize(w, init_array);
1613
1614 uint min_avs_width = this->avs->smallest_x + this->avs->padding_left + this->avs->padding_right;
1615 uint min_acs_width = this->acs->smallest_x + this->acs->padding_left + this->acs->padding_right;
1616 uint min_inf_width = this->inf->smallest_x + this->inf->padding_left + this->inf->padding_right;
1617
1618 uint min_avs_height = this->avs->smallest_y + this->avs->padding_top + this->avs->padding_bottom;
1619 uint min_acs_height = this->acs->smallest_y + this->acs->padding_top + this->acs->padding_bottom;
1620 uint min_inf_height = this->inf->smallest_y + this->inf->padding_top + this->inf->padding_bottom;
1621
1622 /* Smallest window is in two column mode. */
1623 this->smallest_x = std::max(min_avs_width, min_acs_width) + INTER_COLUMN_SPACING + min_inf_width;
1624 this->smallest_y = std::max(min_inf_height, min_acs_height + INTER_LIST_SPACING + min_avs_height);
1625
1626 /* Filling. */
1627 this->fill_x = LeastCommonMultiple(this->avs->fill_x, this->acs->fill_x);
1628 if (this->inf->fill_x > 0 && (this->fill_x == 0 || this->fill_x > this->inf->fill_x)) this->fill_x = this->inf->fill_x;
1629
1630 this->fill_y = this->avs->fill_y;
1631 if (this->acs->fill_y > 0 && (this->fill_y == 0 || this->fill_y > this->acs->fill_y)) this->fill_y = this->acs->fill_y;
1632 this->fill_y = LeastCommonMultiple(this->fill_y, this->inf->fill_y);
1633
1634 /* Resizing. */
1635 this->resize_x = LeastCommonMultiple(this->avs->resize_x, this->acs->resize_x);
1636 if (this->inf->resize_x > 0 && (this->resize_x == 0 || this->resize_x > this->inf->resize_x)) this->resize_x = this->inf->resize_x;
1637
1638 this->resize_y = this->avs->resize_y;
1639 if (this->acs->resize_y > 0 && (this->resize_y == 0 || this->resize_y > this->acs->resize_y)) this->resize_y = this->acs->resize_y;
1640 this->resize_y = LeastCommonMultiple(this->resize_y, this->inf->resize_y);
1641
1642 /* Make sure the height suits the 3 column (resp. not-editable) format; the 2 column format can easily fill space between the lists */
1643 this->smallest_y = ComputeMaxSize(min_acs_height, this->smallest_y + this->resize_y - 1, this->resize_y);
1644 }
1645
1646 void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override
1647 {
1648 this->StoreSizePosition(sizing, x, y, given_width, given_height);
1649
1650 uint min_avs_width = this->avs->smallest_x + this->avs->padding_left + this->avs->padding_right;
1651 uint min_acs_width = this->acs->smallest_x + this->acs->padding_left + this->acs->padding_right;
1652 uint min_inf_width = this->inf->smallest_x + this->inf->padding_left + this->inf->padding_right;
1653
1654 uint min_list_width = std::max(min_avs_width, min_acs_width); // Smallest width of the lists such that they have equal width (incl padding).
1655 uint avs_extra_width = min_list_width - min_avs_width; // Additional width needed for avs to reach min_list_width.
1656 uint acs_extra_width = min_list_width - min_acs_width; // Additional width needed for acs to reach min_list_width.
1657
1658 /* Use 2 or 3 columns? */
1659 uint min_three_columns = min_avs_width + min_acs_width + min_inf_width + 2 * INTER_COLUMN_SPACING;
1660 uint min_two_columns = min_list_width + min_inf_width + INTER_COLUMN_SPACING;
1661 bool use_three_columns = this->editable && (min_three_columns + MIN_EXTRA_FOR_3_COLUMNS <= given_width);
1662
1663 /* Info panel is a separate column in both modes. Compute its width first. */
1664 uint extra_width, inf_width;
1665 if (use_three_columns) {
1666 extra_width = given_width - min_three_columns;
1667 inf_width = std::min(MAX_EXTRA_INFO_WIDTH, extra_width / 2);
1668 } else {
1669 extra_width = given_width - min_two_columns;
1670 inf_width = std::min(MAX_EXTRA_INFO_WIDTH, extra_width / 2);
1671 }
1672 inf_width = ComputeMaxSize(this->inf->smallest_x, this->inf->smallest_x + inf_width, this->inf->GetHorizontalStepSize(sizing));
1673 extra_width -= inf_width - this->inf->smallest_x;
1674
1675 uint inf_height = ComputeMaxSize(this->inf->smallest_y, given_height, this->inf->GetVerticalStepSize(sizing));
1676
1677 if (use_three_columns) {
1678 /* Three column display, first make both lists equally wide, then divide whatever is left between both lists.
1679 * Only keep track of what avs gets, all other space goes to acs. */
1680 uint avs_width = std::min(avs_extra_width, extra_width);
1681 extra_width -= avs_width;
1682 extra_width -= std::min(acs_extra_width, extra_width);
1683 avs_width += extra_width / 2;
1684
1685 avs_width = ComputeMaxSize(this->avs->smallest_x, this->avs->smallest_x + avs_width, this->avs->GetHorizontalStepSize(sizing));
1686
1687 uint acs_width = given_width - // Remaining space, including horizontal padding.
1688 inf_width - this->inf->padding_left - this->inf->padding_right -
1689 avs_width - this->avs->padding_left - this->avs->padding_right - 2 * INTER_COLUMN_SPACING;
1690 acs_width = ComputeMaxSize(min_acs_width, acs_width, this->acs->GetHorizontalStepSize(sizing)) -
1691 this->acs->padding_left - this->acs->padding_right;
1692
1693 /* Never use fill_y on these; the minimal size is chosen, so that the 3 column view looks nice */
1694 uint avs_height = ComputeMaxSize(this->avs->smallest_y, given_height, this->avs->resize_y);
1695 uint acs_height = ComputeMaxSize(this->acs->smallest_y, given_height, this->acs->resize_y);
1696
1697 /* Assign size and position to the children. */
1698 if (rtl) {
1699 x += this->inf->padding_left;
1700 this->inf->AssignSizePosition(sizing, x, y + this->inf->padding_top, inf_width, inf_height, rtl);
1701 x += inf_width + this->inf->padding_right + INTER_COLUMN_SPACING;
1702 } else {
1703 x += this->avs->padding_left;
1704 this->avs->AssignSizePosition(sizing, x, y + this->avs->padding_top, avs_width, avs_height, rtl);
1705 x += avs_width + this->avs->padding_right + INTER_COLUMN_SPACING;
1706 }
1707
1708 x += this->acs->padding_left;
1709 this->acs->AssignSizePosition(sizing, x, y + this->acs->padding_top, acs_width, acs_height, rtl);
1710 x += acs_width + this->acs->padding_right + INTER_COLUMN_SPACING;
1711
1712 if (rtl) {
1713 x += this->avs->padding_left;
1714 this->avs->AssignSizePosition(sizing, x, y + this->avs->padding_top, avs_width, avs_height, rtl);
1715 } else {
1716 x += this->inf->padding_left;
1717 this->inf->AssignSizePosition(sizing, x, y + this->inf->padding_top, inf_width, inf_height, rtl);
1718 }
1719 } else {
1720 /* Two columns, all space in extra_width goes to both lists. Since the lists are underneath each other,
1721 * the column is min_list_width wide at least. */
1722 uint avs_width = ComputeMaxSize(this->avs->smallest_x, this->avs->smallest_x + avs_extra_width + extra_width,
1723 this->avs->GetHorizontalStepSize(sizing));
1724 uint acs_width = ComputeMaxSize(this->acs->smallest_x, this->acs->smallest_x + acs_extra_width + extra_width,
1725 this->acs->GetHorizontalStepSize(sizing));
1726
1727 uint min_avs_height = (!this->editable) ? 0 : this->avs->smallest_y + this->avs->padding_top + this->avs->padding_bottom + INTER_LIST_SPACING;
1728 uint min_acs_height = this->acs->smallest_y + this->acs->padding_top + this->acs->padding_bottom;
1729 uint extra_height = given_height - min_acs_height - min_avs_height;
1730
1731 /* Never use fill_y on these; instead use the INTER_LIST_SPACING as filler */
1732 uint avs_height = ComputeMaxSize(this->avs->smallest_y, this->avs->smallest_y + extra_height / 2, this->avs->resize_y);
1733 if (this->editable) extra_height -= avs_height - this->avs->smallest_y;
1734 uint acs_height = ComputeMaxSize(this->acs->smallest_y, this->acs->smallest_y + extra_height, this->acs->resize_y);
1735
1736 /* Assign size and position to the children. */
1737 if (rtl) {
1738 x += this->inf->padding_left;
1739 this->inf->AssignSizePosition(sizing, x, y + this->inf->padding_top, inf_width, inf_height, rtl);
1740 x += inf_width + this->inf->padding_right + INTER_COLUMN_SPACING;
1741
1742 this->acs->AssignSizePosition(sizing, x + this->acs->padding_left, y + this->acs->padding_top, acs_width, acs_height, rtl);
1743 if (this->editable) {
1744 this->avs->AssignSizePosition(sizing, x + this->avs->padding_left, y + given_height - avs_height - this->avs->padding_bottom, avs_width, avs_height, rtl);
1745 } else {
1746 this->avs->AssignSizePosition(sizing, 0, 0, this->avs->smallest_x, this->avs->smallest_y, rtl);
1747 }
1748 } else {
1749 this->acs->AssignSizePosition(sizing, x + this->acs->padding_left, y + this->acs->padding_top, acs_width, acs_height, rtl);
1750 if (this->editable) {
1751 this->avs->AssignSizePosition(sizing, x + this->avs->padding_left, y + given_height - avs_height - this->avs->padding_bottom, avs_width, avs_height, rtl);
1752 } else {
1753 this->avs->AssignSizePosition(sizing, 0, 0, this->avs->smallest_x, this->avs->smallest_y, rtl);
1754 }
1755 uint dx = this->acs->current_x + this->acs->padding_left + this->acs->padding_right;
1756 if (this->editable) {
1757 dx = std::max(dx, this->avs->current_x + this->avs->padding_left + this->avs->padding_right);
1758 }
1759 x += dx + INTER_COLUMN_SPACING + this->inf->padding_left;
1760 this->inf->AssignSizePosition(sizing, x, y + this->inf->padding_top, inf_width, inf_height, rtl);
1761 }
1762 }
1763 }
1764
1765 NWidgetCore *GetWidgetFromPos(int x, int y) override
1766 {
1767 if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return nullptr;
1768
1769 NWidgetCore *nw = (this->editable) ? this->avs->GetWidgetFromPos(x, y) : nullptr;
1770 if (nw == nullptr) nw = this->acs->GetWidgetFromPos(x, y);
1771 if (nw == nullptr) nw = this->inf->GetWidgetFromPos(x, y);
1772 return nw;
1773 }
1774
1775 void Draw(const Window *w) override
1776 {
1777 if (this->editable) this->avs->Draw(w);
1778 this->acs->Draw(w);
1779 this->inf->Draw(w);
1780 }
1781 };
1782
1783 const uint NWidgetNewGRFDisplay::INTER_LIST_SPACING = WD_RESIZEBOX_WIDTH + 1;
1784 const uint NWidgetNewGRFDisplay::INTER_COLUMN_SPACING = WD_RESIZEBOX_WIDTH;
1785 const uint NWidgetNewGRFDisplay::MAX_EXTRA_INFO_WIDTH = 150;
1786 const uint NWidgetNewGRFDisplay::MIN_EXTRA_FOR_3_COLUMNS = 50;
1787
1788 static const NWidgetPart _nested_newgrf_actives_widgets[] = {
1789 /* Left side, presets. */
1790 NWidget(NWID_HORIZONTAL),
1791 NWidget(WWT_TEXT, COLOUR_MAUVE), SetDataTip(STR_NEWGRF_SETTINGS_SELECT_PRESET, STR_NULL),
1792 SetPadding(0, WD_FRAMETEXT_RIGHT, 0, 0),
1793 NWidget(WWT_DROPDOWN, COLOUR_YELLOW, WID_NS_PRESET_LIST), SetFill(1, 0), SetResize(1, 0),
1794 SetDataTip(STR_JUST_STRING, STR_NEWGRF_SETTINGS_PRESET_LIST_TOOLTIP),
1795 EndContainer(),
1796 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1797 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NS_PRESET_SAVE), SetFill(1, 0), SetResize(1, 0),
1798 SetDataTip(STR_NEWGRF_SETTINGS_PRESET_SAVE, STR_NEWGRF_SETTINGS_PRESET_SAVE_TOOLTIP),
1799 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NS_PRESET_DELETE), SetFill(1, 0), SetResize(1, 0),
1800 SetDataTip(STR_NEWGRF_SETTINGS_PRESET_DELETE, STR_NEWGRF_SETTINGS_PRESET_DELETE_TOOLTIP),
1801 EndContainer(),
1802
1803 NWidget(NWID_SPACER), SetMinimalSize(0, WD_RESIZEBOX_WIDTH), SetResize(1, 0), SetFill(1, 0),
1804 NWidget(WWT_PANEL, COLOUR_MAUVE),
1805 NWidget(WWT_LABEL, COLOUR_MAUVE), SetDataTip(STR_NEWGRF_SETTINGS_ACTIVE_LIST, STR_NULL),
1806 SetFill(1, 0), SetResize(1, 0), SetPadding(3, WD_FRAMETEXT_RIGHT, 0, WD_FRAMETEXT_LEFT),
1807 /* Left side, active grfs. */
1808 NWidget(NWID_HORIZONTAL), SetPadding(0, 2, 0, 2),
1809 NWidget(WWT_PANEL, COLOUR_MAUVE),
1810 NWidget(WWT_INSET, COLOUR_MAUVE, WID_NS_FILE_LIST), SetMinimalSize(100, 1), SetPadding(2, 2, 2, 2),
1811 SetFill(1, 1), SetResize(1, 1), SetScrollbar(WID_NS_SCROLLBAR), SetDataTip(STR_NULL, STR_NEWGRF_SETTINGS_FILE_TOOLTIP),
1812 EndContainer(),
1813 EndContainer(),
1814 NWidget(NWID_VSCROLLBAR, COLOUR_MAUVE, WID_NS_SCROLLBAR),
1815 EndContainer(),
1816 /* Buttons. */
1817 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_NS_SHOW_REMOVE),
1818 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPadding(2, 2, 2, 2), SetPIP(0, WD_RESIZEBOX_WIDTH, 0),
1819 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NS_REMOVE), SetFill(1, 0), SetResize(1, 0),
1820 SetDataTip(STR_NEWGRF_SETTINGS_REMOVE, STR_NEWGRF_SETTINGS_REMOVE_TOOLTIP),
1821 NWidget(NWID_VERTICAL),
1822 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NS_MOVE_UP), SetFill(1, 0), SetResize(1, 0),
1823 SetDataTip(STR_NEWGRF_SETTINGS_MOVEUP, STR_NEWGRF_SETTINGS_MOVEUP_TOOLTIP),
1824 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NS_MOVE_DOWN), SetFill(1, 0), SetResize(1, 0),
1825 SetDataTip(STR_NEWGRF_SETTINGS_MOVEDOWN, STR_NEWGRF_SETTINGS_MOVEDOWN_TOOLTIP),
1826 EndContainer(),
1827 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NS_UPGRADE), SetFill(1, 0), SetResize(1, 0),
1828 SetDataTip(STR_NEWGRF_SETTINGS_UPGRADE, STR_NEWGRF_SETTINGS_UPGRADE_TOOLTIP),
1829 EndContainer(),
1830
1831 NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPadding(2, 2, 2, 2),
1832 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NS_RESCAN_FILES2), SetFill(1, 0), SetResize(1, 0),
1833 SetDataTip(STR_NEWGRF_SETTINGS_RESCAN_FILES, STR_NEWGRF_SETTINGS_RESCAN_FILES_TOOLTIP),
1834 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NS_CONTENT_DOWNLOAD2), SetFill(1, 0), SetResize(1, 0),
1835 SetDataTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
1836 EndContainer(),
1837 EndContainer(),
1838 EndContainer(),
1839 };
1840
1841 static const NWidgetPart _nested_newgrf_availables_widgets[] = {
1842 NWidget(WWT_PANEL, COLOUR_MAUVE),
1843 NWidget(WWT_LABEL, COLOUR_MAUVE), SetDataTip(STR_NEWGRF_SETTINGS_INACTIVE_LIST, STR_NULL),
1844 SetFill(1, 0), SetResize(1, 0), SetPadding(3, WD_FRAMETEXT_RIGHT, 0, WD_FRAMETEXT_LEFT),
1845 /* Left side, available grfs, filter edit box. */
1846 NWidget(NWID_HORIZONTAL), SetPadding(WD_TEXTPANEL_TOP, 0, WD_TEXTPANEL_BOTTOM, 0),
1847 SetPIP(WD_FRAMETEXT_LEFT, WD_FRAMETEXT_RIGHT, WD_FRAMETEXT_RIGHT),
1848 NWidget(WWT_TEXT, COLOUR_MAUVE), SetFill(0, 1), SetDataTip(STR_NEWGRF_FILTER_TITLE, STR_NULL),
1849 NWidget(WWT_EDITBOX, COLOUR_MAUVE, WID_NS_FILTER), SetFill(1, 0), SetMinimalSize(50, 12), SetResize(1, 0),
1850 SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
1851 EndContainer(),
1852 /* Left side, available grfs. */
1853 NWidget(NWID_HORIZONTAL), SetPadding(0, 2, 0, 2),
1854 NWidget(WWT_PANEL, COLOUR_MAUVE),
1855 NWidget(WWT_INSET, COLOUR_MAUVE, WID_NS_AVAIL_LIST), SetMinimalSize(100, 1), SetPadding(2, 2, 2, 2),
1856 SetFill(1, 1), SetResize(1, 1), SetScrollbar(WID_NS_SCROLL2BAR),
1857 EndContainer(),
1858 EndContainer(),
1859 NWidget(NWID_VSCROLLBAR, COLOUR_MAUVE, WID_NS_SCROLL2BAR),
1860 EndContainer(),
1861 /* Left side, available grfs, buttons. */
1862 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPadding(2, 2, 2, 2), SetPIP(0, WD_RESIZEBOX_WIDTH, 0),
1863 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NS_ADD), SetFill(1, 0), SetResize(1, 0),
1864 SetDataTip(STR_NEWGRF_SETTINGS_ADD, STR_NEWGRF_SETTINGS_ADD_FILE_TOOLTIP),
1865 NWidget(NWID_VERTICAL),
1866 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NS_RESCAN_FILES), SetFill(1, 0), SetResize(1, 0),
1867 SetDataTip(STR_NEWGRF_SETTINGS_RESCAN_FILES, STR_NEWGRF_SETTINGS_RESCAN_FILES_TOOLTIP),
1868 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NS_CONTENT_DOWNLOAD), SetFill(1, 0), SetResize(1, 0),
1869 SetDataTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
1870 EndContainer(),
1871 EndContainer(),
1872 EndContainer(),
1873 };
1874
1875 static const NWidgetPart _nested_newgrf_infopanel_widgets[] = {
1876 /* Right side, info panel. */
1877 NWidget(NWID_VERTICAL), SetPadding(0, 0, 2, 0),
1878 NWidget(WWT_PANEL, COLOUR_MAUVE), SetPadding(0, 0, 2, 0),
1879 NWidget(WWT_EMPTY, COLOUR_MAUVE, WID_NS_NEWGRF_INFO_TITLE), SetFill(1, 0), SetResize(1, 0),
1880 NWidget(WWT_EMPTY, COLOUR_MAUVE, WID_NS_NEWGRF_INFO), SetFill(1, 1), SetResize(1, 1), SetMinimalSize(150, 100),
1881 EndContainer(),
1882 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NS_OPEN_URL), SetFill(1, 0), SetResize(1, 0),
1883 SetDataTip(STR_CONTENT_OPEN_URL, STR_CONTENT_OPEN_URL_TOOLTIP),
1884 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NS_NEWGRF_TEXTFILE + TFT_README), SetFill(1, 0), SetResize(1, 0),
1885 SetDataTip(STR_TEXTFILE_VIEW_README, STR_NULL),
1886 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1887 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NS_NEWGRF_TEXTFILE + TFT_CHANGELOG), SetFill(1, 0), SetResize(1, 0),
1888 SetDataTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_NULL),
1889 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NS_NEWGRF_TEXTFILE + TFT_LICENSE), SetFill(1, 0), SetResize(1, 0),
1890 SetDataTip(STR_TEXTFILE_VIEW_LICENCE, STR_NULL),
1891 EndContainer(),
1892 EndContainer(),
1893 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_NS_SHOW_APPLY),
1894 /* Right side, buttons. */
1895 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(0, WD_RESIZEBOX_WIDTH, 0),
1896 NWidget(NWID_VERTICAL),
1897 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NS_SET_PARAMETERS), SetFill(1, 0), SetResize(1, 0),
1898 SetDataTip(STR_NEWGRF_SETTINGS_SET_PARAMETERS, STR_NULL),
1899 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NS_TOGGLE_PALETTE), SetFill(1, 0), SetResize(1, 0),
1900 SetDataTip(STR_NEWGRF_SETTINGS_TOGGLE_PALETTE, STR_NEWGRF_SETTINGS_TOGGLE_PALETTE_TOOLTIP),
1901 EndContainer(),
1902 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NS_APPLY_CHANGES), SetFill(1, 0), SetResize(1, 0),
1903 SetDataTip(STR_NEWGRF_SETTINGS_APPLY_CHANGES, STR_NULL),
1904 EndContainer(),
1905 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_NS_VIEW_PARAMETERS), SetFill(1, 0), SetResize(1, 0),
1906 SetDataTip(STR_NEWGRF_SETTINGS_SHOW_PARAMETERS, STR_NULL),
1907 EndContainer(),
1908 };
1909
1911 NWidgetBase* NewGRFDisplay(int *biggest_index)
1912 {
1913 NWidgetBase *avs = MakeNWidgets(_nested_newgrf_availables_widgets, lengthof(_nested_newgrf_availables_widgets), biggest_index, nullptr);
1914
1915 int biggest2;
1916 NWidgetBase *acs = MakeNWidgets(_nested_newgrf_actives_widgets, lengthof(_nested_newgrf_actives_widgets), &biggest2, nullptr);
1917 *biggest_index = std::max(*biggest_index, biggest2);
1918
1919 NWidgetBase *inf = MakeNWidgets(_nested_newgrf_infopanel_widgets, lengthof(_nested_newgrf_infopanel_widgets), &biggest2, nullptr);
1920 *biggest_index = std::max(*biggest_index, biggest2);
1921
1922 return new NWidgetNewGRFDisplay(avs, acs, inf);
1923 }
1924
1925 /* Widget definition of the manage newgrfs window */
1926 static const NWidgetPart _nested_newgrf_widgets[] = {
1927 NWidget(NWID_HORIZONTAL),
1928 NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
1929 NWidget(WWT_CAPTION, COLOUR_MAUVE), SetDataTip(STR_NEWGRF_SETTINGS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1930 NWidget(WWT_DEFSIZEBOX, COLOUR_MAUVE),
1931 EndContainer(),
1932 NWidget(WWT_PANEL, COLOUR_MAUVE),
1933 NWidgetFunction(NewGRFDisplay), SetPadding(WD_RESIZEBOX_WIDTH, WD_RESIZEBOX_WIDTH, 2, WD_RESIZEBOX_WIDTH),
1934 /* Resize button. */
1935 NWidget(NWID_HORIZONTAL),
1936 NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
1937 NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
1938 EndContainer(),
1939 EndContainer(),
1940 };
1941
1942 /* Window definition of the manage newgrfs window */
1943 static WindowDesc _newgrf_desc(
1944 WDP_CENTER, "settings_newgrf", 300, 263,
1945 WC_GAME_OPTIONS, WC_NONE,
1946 0,
1947 _nested_newgrf_widgets, lengthof(_nested_newgrf_widgets)
1948 );
1949
1955 static void NewGRFConfirmationCallback(Window *w, bool confirmed)
1956 {
1957 if (confirmed) {
1958 DeleteWindowByClass(WC_GRF_PARAMETERS);
1959 DeleteWindowByClass(WC_TEXTFILE);
1960 NewGRFWindow *nw = dynamic_cast<NewGRFWindow*>(w);
1961
1962 GamelogStartAction(GLAT_GRF);
1963 GamelogGRFUpdate(_grfconfig, nw->actives); // log GRF changes
1964 CopyGRFConfigList(nw->orig_list, nw->actives, false);
1965 ReloadNewGRFData();
1966 GamelogStopAction();
1967
1968 /* Show new, updated list */
1969 GRFConfig *c;
1970 int i = 0;
1971 for (c = nw->actives; c != nullptr && c != nw->active_sel; c = c->next, i++) {}
1972 CopyGRFConfigList(&nw->actives, *nw->orig_list, false);
1973 for (c = nw->actives; c != nullptr && i > 0; c = c->next, i--) {}
1974 nw->active_sel = c;
1975 nw->avails.ForceRebuild();
1976
1977 w->InvalidateData();
1978
1979 ReInitAllWindows();
1980 DeleteWindowByClass(WC_BUILD_OBJECT);
1981 }
1982 }
1983
1984
1985
1994 void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config)
1995 {
1996 DeleteWindowByClass(WC_GAME_OPTIONS);
1997 new NewGRFWindow(&_newgrf_desc, editable, show_params, exec_changes, config);
1998 }
1999
2001 static const NWidgetPart _nested_save_preset_widgets[] = {
2002 NWidget(NWID_HORIZONTAL),
2003 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
2004 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_SAVE_PRESET_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
2005 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
2006 EndContainer(),
2007 NWidget(WWT_PANEL, COLOUR_GREY),
2008 NWidget(NWID_HORIZONTAL),
2009 NWidget(WWT_INSET, COLOUR_GREY, WID_SVP_PRESET_LIST), SetPadding(2, 1, 0, 2),
2010 SetDataTip(0x0, STR_SAVE_PRESET_LIST_TOOLTIP), SetResize(1, 10), SetScrollbar(WID_SVP_SCROLLBAR), EndContainer(),
2011 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_SVP_SCROLLBAR),
2012 EndContainer(),
2013 NWidget(WWT_EDITBOX, COLOUR_GREY, WID_SVP_EDITBOX), SetPadding(3, 2, 2, 2), SetFill(1, 0), SetResize(1, 0),
2014 SetDataTip(STR_SAVE_PRESET_TITLE, STR_SAVE_PRESET_EDITBOX_TOOLTIP),
2015 EndContainer(),
2016 NWidget(NWID_HORIZONTAL),
2017 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SVP_CANCEL), SetDataTip(STR_SAVE_PRESET_CANCEL, STR_SAVE_PRESET_CANCEL_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
2018 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SVP_SAVE), SetDataTip(STR_SAVE_PRESET_SAVE, STR_SAVE_PRESET_SAVE_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
2019 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
2020 EndContainer(),
2021 };
2022
2024 static WindowDesc _save_preset_desc(
2025 WDP_CENTER, "save_preset", 140, 110,
2026 WC_SAVE_PRESET, WC_GAME_OPTIONS,
2027 WDF_MODAL,
2028 _nested_save_preset_widgets, lengthof(_nested_save_preset_widgets)
2029 );
2030
2032 struct SavePresetWindow : public Window {
2033 QueryString presetname_editbox;
2034 StringList presets;
2035 Scrollbar *vscroll;
2036 int selected;
2037
2042 SavePresetWindow(const char *initial_text) : Window(&_save_preset_desc), presetname_editbox(32)
2043 {
2044 this->presets = GetGRFPresetList();
2045 this->selected = -1;
2046 if (initial_text != nullptr) {
2047 for (uint i = 0; i < this->presets.size(); i++) {
2048 if (this->presets[i] == initial_text) {
2049 this->selected = i;
2050 break;
2051 }
2052 }
2053 }
2054
2055 this->querystrings[WID_SVP_EDITBOX] = &this->presetname_editbox;
2056 this->presetname_editbox.ok_button = WID_SVP_SAVE;
2057 this->presetname_editbox.cancel_button = WID_SVP_CANCEL;
2058
2059 this->CreateNestedTree();
2060 this->vscroll = this->GetScrollbar(WID_SVP_SCROLLBAR);
2061 this->FinishInitNested(0);
2062
2063 this->vscroll->SetCount((uint)this->presets.size());
2064 this->SetFocusedWidget(WID_SVP_EDITBOX);
2065 if (initial_text != nullptr) this->presetname_editbox.text.Assign(initial_text);
2066 }
2067
2068 ~SavePresetWindow()
2069 {
2070 }
2071
2072 void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
2073 {
2074 switch (widget) {
2075 case WID_SVP_PRESET_LIST: {
2076 resize->height = FONT_HEIGHT_NORMAL + 2U;
2077 size->height = 0;
2078 for (uint i = 0; i < this->presets.size(); i++) {
2079 Dimension d = GetStringBoundingBox(this->presets[i].c_str());
2080 size->width = std::max(size->width, d.width + WD_FRAMETEXT_LEFT + WD_FRAMETEXT_RIGHT);
2081 resize->height = std::max(resize->height, d.height);
2082 }
2083 size->height = ClampU((uint)this->presets.size(), 5, 20) * resize->height + 1;
2084 break;
2085 }
2086 }
2087 }
2088
2089 void DrawWidget(const Rect &r, int widget) const override
2090 {
2091 switch (widget) {
2092 case WID_SVP_PRESET_LIST: {
2093 GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, PC_BLACK);
2094
2095 uint step_height = this->GetWidget<NWidgetBase>(WID_SVP_PRESET_LIST)->resize_y;
2096 int offset_y = (step_height - FONT_HEIGHT_NORMAL) / 2;
2097 uint y = r.top + WD_FRAMERECT_TOP;
2098 uint min_index = this->vscroll->GetPosition();
2099 uint max_index = std::min(min_index + this->vscroll->GetCapacity(), (uint)this->presets.size());
2100
2101 for (uint i = min_index; i < max_index; i++) {
2102 if ((int)i == this->selected) GfxFillRect(r.left + 1, y, r.right - 1, y + step_height - 2, PC_DARK_BLUE);
2103
2104 const char *text = this->presets[i].c_str();
2105 DrawString(r.left + WD_FRAMERECT_LEFT, r.right, y + offset_y, text, ((int)i == this->selected) ? TC_WHITE : TC_SILVER);
2106 y += step_height;
2107 }
2108 break;
2109 }
2110 }
2111 }
2112
2113 void OnClick(Point pt, int widget, int click_count) override
2114 {
2115 switch (widget) {
2116 case WID_SVP_PRESET_LIST: {
2117 uint row = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SVP_PRESET_LIST);
2118 if (row < this->presets.size()) {
2119 this->selected = row;
2120 this->presetname_editbox.text.Assign(this->presets[row].c_str());
2121 this->SetWidgetDirty(WID_SVP_PRESET_LIST);
2122 this->SetWidgetDirty(WID_SVP_EDITBOX);
2123 }
2124 break;
2125 }
2126
2127 case WID_SVP_CANCEL:
2128 delete this;
2129 break;
2130
2131 case WID_SVP_SAVE: {
2132 Window *w = FindWindowById(WC_GAME_OPTIONS, WN_GAME_OPTIONS_NEWGRF_STATE);
2133 if (w != nullptr && !StrEmpty(this->presetname_editbox.text.buf)) w->OnQueryTextFinished(this->presetname_editbox.text.buf);
2134 delete this;
2135 break;
2136 }
2137 }
2138 }
2139
2140 void OnResize() override
2141 {
2142 this->vscroll->SetCapacityFromWidget(this, WID_SVP_PRESET_LIST);
2143 }
2144 };
2145
2150 static void ShowSavePresetWindow(const char *initial_text)
2151 {
2152 DeleteWindowByClass(WC_SAVE_PRESET);
2153 new SavePresetWindow(initial_text);
2154 }
2155
2157 static const NWidgetPart _nested_scan_progress_widgets[] = {
2158 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_NEWGRF_SCAN_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
2159 NWidget(WWT_PANEL, COLOUR_GREY),
2160 NWidget(NWID_HORIZONTAL), SetPIP(20, 0, 20),
2161 NWidget(NWID_VERTICAL), SetPIP(11, 8, 11),
2162 NWidget(WWT_LABEL, INVALID_COLOUR), SetDataTip(STR_NEWGRF_SCAN_MESSAGE, STR_NULL), SetFill(1, 0),
2163 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_SP_PROGRESS_BAR), SetFill(1, 0),
2164 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_SP_PROGRESS_TEXT), SetFill(1, 0),
2165 EndContainer(),
2166 EndContainer(),
2167 EndContainer(),
2168 };
2169
2171 static WindowDesc _scan_progress_desc(
2172 WDP_CENTER, nullptr, 0, 0,
2173 WC_MODAL_PROGRESS, WC_NONE,
2174 0,
2175 _nested_scan_progress_widgets, lengthof(_nested_scan_progress_widgets)
2176 );
2177
2179 struct ScanProgressWindow : public Window {
2180 char *last_name;
2181 int scanned;
2182
2184 ScanProgressWindow() : Window(&_scan_progress_desc), last_name(nullptr), scanned(0)
2185 {
2186 this->InitNested(1);
2187 }
2188
2190 ~ScanProgressWindow()
2191 {
2192 free(last_name);
2193 }
2194
2195 void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
2196 {
2197 switch (widget) {
2198 case WID_SP_PROGRESS_BAR: {
2199 SetDParamMaxValue(0, 100);
2200 *size = GetStringBoundingBox(STR_GENERATION_PROGRESS);
2201 /* We need some spacing for the 'border' */
2202 size->height += 8;
2203 size->width += 8;
2204 break;
2205 }
2206
2207 case WID_SP_PROGRESS_TEXT:
2208 SetDParamMaxDigits(0, 4);
2209 SetDParamMaxDigits(1, 4);
2210 /* We really don't know the width. We could determine it by scanning the NewGRFs,
2211 * but this is the status window for scanning them... */
2212 size->width = std::max(400U, GetStringBoundingBox(STR_NEWGRF_SCAN_STATUS).width);
2213 size->height = FONT_HEIGHT_NORMAL * 2 + WD_PAR_VSEP_NORMAL;
2214 break;
2215 }
2216 }
2217
2218 void DrawWidget(const Rect &r, int widget) const override
2219 {
2220 switch (widget) {
2221 case WID_SP_PROGRESS_BAR: {
2222 /* Draw the % complete with a bar and a text */
2223 DrawFrameRect(r.left, r.top, r.right, r.bottom, COLOUR_GREY, FR_BORDERONLY);
2224 uint percent = scanned * 100 / std::max(1U, _settings_client.gui.last_newgrf_count);
2225 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);
2226 SetDParam(0, percent);
2227 DrawString(r.left, r.right, r.top + 5, STR_GENERATION_PROGRESS, TC_FROMSTRING, SA_HOR_CENTER);
2228 break;
2229 }
2230
2231 case WID_SP_PROGRESS_TEXT:
2232 SetDParam(0, this->scanned);
2233 SetDParam(1, _settings_client.gui.last_newgrf_count);
2234 DrawString(r.left, r.right, r.top, STR_NEWGRF_SCAN_STATUS, TC_FROMSTRING, SA_HOR_CENTER);
2235
2236 DrawString(r.left, r.right, r.top + FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL, this->last_name == nullptr ? "" : this->last_name, TC_BLACK, SA_HOR_CENTER);
2237 break;
2238 }
2239 }
2240
2246 void UpdateNewGRFScanStatus(uint num, const char *name)
2247 {
2248 free(this->last_name);
2249 if (name == nullptr) {
2250 char buf[256];
2251 GetString(buf, STR_NEWGRF_SCAN_ARCHIVES, lastof(buf));
2252 this->last_name = stredup(buf);
2253 } else {
2254 this->last_name = stredup(name);
2255 }
2256 this->scanned = num;
2257 if (num > _settings_client.gui.last_newgrf_count) _settings_client.gui.last_newgrf_count = num;
2258
2259 this->SetDirty();
2260 }
2261 };
2262
2268 void UpdateNewGRFScanStatus(uint num, const char *name)
2269 {
2270 ScanProgressWindow *w = dynamic_cast<ScanProgressWindow *>(FindWindowByClass(WC_MODAL_PROGRESS));
2271 if (w == nullptr) w = new ScanProgressWindow();
2272 w->UpdateNewGRFScanStatus(num, name);
2273 }
GRFConfig::version
uint32 version
NOSAVE: Version a NewGRF can set so only the newest NewGRF is shown.
Definition: newgrf_config.h:165
NewGRFParametersWindow::OnDropdownClose
void OnDropdownClose(Point pt, int widget, int index, bool instant_close) override
A dropdown window associated to this window has been closed.
Definition: newgrf_gui.cpp:448
NewGRFWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: newgrf_gui.cpp:1186
ES_HANDLED
@ ES_HANDLED
The passed event is handled.
Definition: window_type.h:718
network_content.h
GRFP_USE_MASK
@ GRFP_USE_MASK
Bitmask to get only the use palette use states.
Definition: newgrf_config.h:68
NewGRFWindow::AddGRFToActive
bool AddGRFToActive(int ins_pos=-1)
Insert a GRF into the active list.
Definition: newgrf_gui.cpp:1496
_save_preset_desc
static WindowDesc _save_preset_desc(WDP_CENTER, "save_preset", 140, 110, WC_SAVE_PRESET, WC_GAME_OPTIONS, WDF_MODAL, _nested_save_preset_widgets, lengthof(_nested_save_preset_widgets))
Window description of the preset save window.
WD_FRAMERECT_TOP
@ WD_FRAMERECT_TOP
Offset at top to draw the frame rectangular area.
Definition: window_gui.h:62
GRFConfig::num_valid_params
uint8 num_valid_params
NOSAVE: Number of valid parameters (action 0x14)
Definition: newgrf_config.h:172
ScanProgressWindow::~ScanProgressWindow
~ScanProgressWindow()
Free the last name buffer.
Definition: newgrf_gui.cpp:2190
NewGRFWindow::string_filter
StringFilter string_filter
Filter for available grf.
Definition: newgrf_gui.cpp:601
ReInitAllWindows
void ReInitAllWindows()
Re-initialize all windows.
Definition: window.cpp:3456
WID_NS_SCROLLBAR
@ WID_NS_SCROLLBAR
Scrollbar for active NewGRF list.
Definition: newgrf_widget.h:43
NWidgetFunction
static NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
Definition: widget_type.h:1145
ComputeMaxSize
static uint ComputeMaxSize(uint base, uint max_space, uint step)
Return the biggest possible size of a nested widget.
Definition: widget_type.h:797
GRFIdentifier::HasGrfIdentifier
bool HasGrfIdentifier(uint32 grfid, const uint8 *md5sum) const
Does the identification match the provided values?
Definition: newgrf_config.h:103
TextfileWindow::LoadTextfile
virtual void LoadTextfile(const char *textfile, Subdirectory dir)
Loads the textfile text from file and setup lines.
Definition: textfile_gui.cpp:317
NWidgetNewGRFDisplay::MAX_EXTRA_INFO_WIDTH
static const uint MAX_EXTRA_INFO_WIDTH
Maximal additional width given to the panel.
Definition: newgrf_gui.cpp:1582
QueryString::ok_button
int ok_button
Widget button of parent window to simulate when pressing OK in OSK.
Definition: querystring_gui.h:27
ContentInfo::type
ContentType type
Type of content.
Definition: tcp_content.h:65
GRFConfig::error
GRFError * error
NOSAVE: Error/Warning during GRF loading (Action 0x0B)
Definition: newgrf_config.h:163
WChar
char32_t WChar
Type for wide characters, i.e.
Definition: string_type.h:35
SetWindowDirty
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3220
querystring_gui.h
ReloadNewGRFData
void ReloadNewGRFData()
Reload all NewGRF files during a running game.
Definition: afterload.cpp:3162
SetScrollbar
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1094
ScanProgressWindow
Window for showing the progress of NewGRF scanning.
Definition: newgrf_gui.cpp:2179
GUISettings::newgrf_developer_tools
bool newgrf_developer_tools
activate NewGRF developer tools and allow modifying NewGRFs in an existing game
Definition: settings_type.h:175
NewGRFWindow::OnNewGRFsScanned
void OnNewGRFsScanned() override
Called whenever the NewGRF scan completed.
Definition: newgrf_gui.cpp:1135
NewGRFWindow::OnKeyPress
EventState OnKeyPress(WChar key, uint16 keycode) override
A key has been pressed.
Definition: newgrf_gui.cpp:1292
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:27
NewGRFParametersWindow::GetDummyParameterInfo
static GRFParameterInfo * GetDummyParameterInfo(uint nr)
Get a dummy parameter-info object with default information.
Definition: newgrf_gui.cpp:185
Scrollbar::GetCapacity
uint16 GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:621
GRFError::custom_message
std::string custom_message
Custom message (if present)
Definition: newgrf_config.h:116
FindGRFConfig
const GRFConfig * FindGRFConfig(uint32 grfid, FindGRFConfigMode mode, const uint8 *md5sum, uint32 desired_version)
Find a NewGRF in the scanned list.
Definition: newgrf_config.cpp:737
GCS_ACTIVATED
@ GCS_ACTIVATED
GRF file has been activated.
Definition: newgrf_config.h:39
SetPadding
static NWidgetPart SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1045
Window::DeleteChildWindows
void DeleteChildWindows(WindowClass wc=WC_INVALID) const
Delete all children a window might have in a head-recursive manner.
Definition: window.cpp:1072
GUIList::Sort
bool Sort(Comp compare)
Sort the list.
Definition: sortlist_type.h:247
Window::GetScrollbar
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:309
dropdown_func.h
ClearGRFConfigList
void ClearGRFConfigList(GRFConfig **config)
Clear a GRF Config list, freeing all nodes.
Definition: newgrf_config.cpp:401
StringFilter::IsEmpty
bool IsEmpty() const
Check whether any filter words were entered.
Definition: stringfilter_type.h:59
WID_NS_TOGGLE_PALETTE
@ WID_NS_TOGGLE_PALETTE
Toggle Palette of selected, active NewGRF.
Definition: newgrf_widget.h:52
NWidgetNewGRFDisplay::avs
NWidgetBase * avs
Widget with the available grfs list and buttons.
Definition: newgrf_gui.cpp:1585
guitimer_func.h
ContentInfo::DOES_NOT_EXIST
@ DOES_NOT_EXIST
The content does not exist in the content system.
Definition: tcp_content.h:61
NWidgetContainer::Add
void Add(NWidgetBase *wid)
Append widget wid to container.
Definition: widget.cpp:951
StringFilter::SetFilterTerm
void SetFilterTerm(const char *str)
Set the term to filter on.
Definition: stringfilter.cpp:27
WD_MATRIX_TOP
@ WD_MATRIX_TOP
Offset at top of a matrix cell.
Definition: window_gui.h:78
SavePresetWindow
Class for the save preset window.
Definition: newgrf_gui.cpp:2032
Scrollbar::ScrollTowards
void ScrollTowards(int position)
Scroll towards the given position; if the item is visible nothing happens, otherwise it will be shown...
Definition: widget_type.h:730
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
UpdateNewGRFScanStatus
void UpdateNewGRFScanStatus(uint num, const char *name)
Update the NewGRF scan status.
Definition: newgrf_gui.cpp:2268
ShowSavePresetWindow
static void ShowSavePresetWindow(const char *initial_text)
Open the window for saving a preset.
Definition: newgrf_gui.cpp:2150
Scrollbar::GetScrolledRowFromWidget
int GetScrolledRowFromWidget(int clickpos, const Window *const w, int widget, int padding=0, int line_height=-1) const
Compute the row of a scrolled widget that a user clicked in.
Definition: widget.cpp:1966
GRFConfig::num_params
uint8 num_params
Number of used parameters.
Definition: newgrf_config.h:171
NWidgetBase::GetHorizontalStepSize
uint GetHorizontalStepSize(SizingType sizing) const
Get the horizontal sizing step.
Definition: widget_type.h:194
GUIList< const GRFConfig *, StringFilter & >
Textbuf::Assign
void Assign(StringID string)
Render a string into the textbuffer.
Definition: textbuf.cpp:396
WID_NS_PRESET_LIST
@ WID_NS_PRESET_LIST
Active NewGRF preset.
Definition: newgrf_widget.h:33
WWT_LABEL
@ WWT_LABEL
Centered label.
Definition: widget_type.h:55
NWidgetNewGRFDisplay::Draw
void Draw(const Window *w) override
Definition: newgrf_gui.cpp:1775
DropDownList
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
Definition: dropdown_type.h:100
GrfIdMap
std::map< uint32, const GRFConfig * > GrfIdMap
Map of grfid to the grf config.
Definition: newgrf_gui.cpp:566
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:63
NWidgetNewGRFDisplay::acs
NWidgetBase * acs
Widget with the active grfs list and buttons.
Definition: newgrf_gui.cpp:1586
Window::CreateNestedTree
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1832
_all_grfs
GRFConfig * _all_grfs
First item in list of all scanned NewGRFs.
Definition: newgrf_config.cpp:169
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:73
DropDownListCharStringItem
List item containing a C char string.
Definition: dropdown_type.h:70
ShowNetworkContentListWindow
void ShowNetworkContentListWindow(ContentVector *cv=nullptr, ContentType type1=CONTENT_TYPE_END, ContentType type2=CONTENT_TYPE_END)
Show the content list window with a given set of content.
Definition: network_content_gui.cpp:1138
NewGRFWindow
Window for showing NewGRF files.
Definition: newgrf_gui.cpp:588
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition: geometry_func.cpp:22
WID_NS_PRESET_DELETE
@ WID_NS_PRESET_DELETE
Delete active preset.
Definition: newgrf_widget.h:35
_nested_save_preset_widgets
static const NWidgetPart _nested_save_preset_widgets[]
Widget parts of the save preset window.
Definition: newgrf_gui.cpp:2001
WWT_MATRIX
@ WWT_MATRIX
Grid of rows and columns.
Definition: widget_type.h:57
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1133
ClampU
static uint ClampU(const uint a, const uint min, const uint max)
Clamp an unsigned integer between an interval.
Definition: math_func.hpp:122
ContentVector
std::vector< ContentInfo * > ContentVector
Vector with content info.
Definition: network_content.h:17
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
ShowMissingContentWindow
void ShowMissingContentWindow(const GRFConfig *list)
Show the content list window with all missing grfs from the given list.
Definition: newgrf_gui.cpp:1543
SavePresetWindow::SavePresetWindow
SavePresetWindow(const char *initial_text)
Constructor of the save preset window.
Definition: newgrf_gui.cpp:2042
Scrollbar::SetCount
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:669
GRFParameterInfo::SetValue
void SetValue(struct GRFConfig *config, uint32 value)
Set the value of this user-changeable parameter in the given config.
Definition: newgrf_config.cpp:255
GRFParameterInfo::param_nr
byte param_nr
GRF parameter to store content in.
Definition: newgrf_config.h:140
NewGRFWindow::filter_funcs
static GUIGRFConfigList::FilterFunction *const filter_funcs[]
Filter functions of the #GUIGRFConfigList.
Definition: newgrf_gui.cpp:596
GRFError::severity
StringID severity
Info / Warning / Error / Fatal.
Definition: newgrf_config.h:119
NewGRFWindow::actives
GRFConfig * actives
Temporary active grf list to which changes are made.
Definition: newgrf_gui.cpp:606
SetResize
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:929
GCS_NOT_FOUND
@ GCS_NOT_FOUND
GRF file was not found in the local cache.
Definition: newgrf_config.h:37
ScanProgressWindow::ScanProgressWindow
ScanProgressWindow()
Create the window.
Definition: newgrf_gui.cpp:2184
WD_FRAMETEXT_TOP
@ WD_FRAMETEXT_TOP
Top offset of the text of the frame.
Definition: window_gui.h:72
NewGRFWindow::sorter_funcs
static GUIGRFConfigList::SortFunction *const sorter_funcs[]
Sort functions of the #GUIGRFConfigList.
Definition: newgrf_gui.cpp:595
NewGRFWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: newgrf_gui.cpp:773
GRFConfig::ident
GRFIdentifier ident
grfid and md5sum to uniquely identify newgrfs
Definition: newgrf_config.h:157
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:79
NWidgetNewGRFDisplay::GetWidgetFromPos
NWidgetCore * GetWidgetFromPos(int x, int y) override
Definition: newgrf_gui.cpp:1765
NewGRFParametersWindow::editable
bool editable
Allow editing parameters.
Definition: newgrf_gui.cpp:157
DrawString
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:640
NewGRFDisplay
NWidgetBase * NewGRFDisplay(int *biggest_index)
Construct nested container widget for managing the lists and the info panel of the NewGRF GUI.
Definition: newgrf_gui.cpp:1911
WID_NP_RESET
@ WID_NP_RESET
Reset button.
Definition: newgrf_widget.h:26
SZSP_HORIZONTAL
@ SZSP_HORIZONTAL
Display plane with zero size vertically, and filling and resizing horizontally.
Definition: widget_type.h:388
WID_NS_NEWGRF_TEXTFILE
@ WID_NS_NEWGRF_TEXTFILE
Open NewGRF readme, changelog (+1) or license (+2).
Definition: newgrf_widget.h:49
GRFConfig::status
GRFStatus status
NOSAVE: GRFStatus, enum.
Definition: newgrf_config.h:168
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget array.
Definition: widget_type.h:46
DeleteWindowByClass
void DeleteWindowByClass(WindowClass cls)
Delete all windows of a given class.
Definition: window.cpp:1178
WWT_PUSHARROWBTN
@ WWT_PUSHARROWBTN
Normal push-button (no toggle button) with arrow caption.
Definition: widget_type.h:104
GRFP_GRF_UNSET
@ GRFP_GRF_UNSET
The NewGRF provided no information.
Definition: newgrf_config.h:70
StringFilter::AddLine
void AddLine(const char *str)
Pass another text line from the current item to the filter.
Definition: stringfilter.cpp:104
NewGRFWindow::execute
bool execute
On pressing 'apply changes' are grf changes applied immediately, or only list is updated.
Definition: newgrf_gui.cpp:612
WID_NS_AVAIL_LIST
@ WID_NS_AVAIL_LIST
List window of available NewGRFs.
Definition: newgrf_widget.h:44
NewGRFWindow::NameSorter
static bool NameSorter(const GRFConfig *const &a, const GRFConfig *const &b)
Sort grfs by name.
Definition: newgrf_gui.cpp:1427
NewGRFWindow::preset
int preset
Selected preset or -1 if none selected.
Definition: newgrf_gui.cpp:613
GRFParameterInfo::type
GRFParameterType type
The type of this parameter.
Definition: newgrf_config.h:136
SA_HOR_CENTER
@ SA_HOR_CENTER
Horizontally center the text.
Definition: gfx_func.h:97
gamelog.h
fios.h
NewGRFParametersWindow::clicked_dropdown
bool clicked_dropdown
Whether the dropdown is open.
Definition: newgrf_gui.cpp:150
NWidgetBase::smallest_y
uint smallest_y
Smallest vertical size of the widget in a filled window.
Definition: widget_type.h:170
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:588
MakeNWidgets
NWidgetContainer * MakeNWidgets(const NWidgetPart *parts, int count, int *biggest_index, NWidgetContainer *container)
Construct a nested widget tree from an array of parts.
Definition: widget.cpp:2799
NWidgetBase::padding_top
uint8 padding_top
Paddings added to the top of the widget. Managed by parent container widget.
Definition: widget_type.h:181
WID_NP_BACKGROUND
@ WID_NP_BACKGROUND
Panel to draw the settings on.
Definition: newgrf_widget.h:23
WD_FRAMETEXT_LEFT
@ WD_FRAMETEXT_LEFT
Left offset of the text of the frame.
Definition: window_gui.h:70
TextfileWindow::file_type
TextfileType file_type
Type of textfile to view.
Definition: textfile_gui.h:22
TFT_CHANGELOG
@ TFT_CHANGELOG
NewGRF changelog.
Definition: textfile_type.h:18
GRFIdentifier::md5sum
uint8 md5sum[16]
MD5 checksum of file to distinguish files with the same GRF ID (eg. newer version of GRF)
Definition: newgrf_config.h:85
WN_GAME_OPTIONS_NEWGRF_STATE
@ WN_GAME_OPTIONS_NEWGRF_STATE
NewGRF settings.
Definition: window_type.h:17
SetDParam
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:199
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:909
textfile_gui.h
NewGRFWindow::active_sel
GRFConfig * active_sel
Selected active grf item.
Definition: newgrf_gui.cpp:607
WID_NS_NEWGRF_INFO
@ WID_NS_NEWGRF_INFO
Panel for Info on selected NewGRF.
Definition: newgrf_widget.h:47
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1013
QueryString
Data stored about a string that can be modified in the GUI.
Definition: querystring_gui.h:20
WC_GRF_PARAMETERS
@ WC_GRF_PARAMETERS
NewGRF parameters; Window numbers:
Definition: window_type.h:174
WID_NS_MOVE_DOWN
@ WID_NS_MOVE_DOWN
Move NewGRF down in active list.
Definition: newgrf_widget.h:39
NewGRFWindow::active_over
int active_over
Active GRF item over which another one is dragged, -1 if none.
Definition: newgrf_gui.cpp:614
WC_SAVE_PRESET
@ WC_SAVE_PRESET
Save preset; Window numbers:
Definition: window_type.h:680
GRFIdentifier::grfid
uint32 grfid
GRF ID (defined by Action 0x08)
Definition: newgrf_config.h:84
GRFParameterInfo::GetValue
uint32 GetValue(struct GRFConfig *config) const
Get the value of this user-changeable parameter from the given config.
Definition: newgrf_config.cpp:243
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:842
GUIList::SetFilterFuncs
void SetFilterFuncs(FilterFunction *const *n_funcs)
Hand the array of filter function pointers to the sort list.
Definition: sortlist_type.h:341
GCF_COMPATIBLE
@ GCF_COMPATIBLE
GRF file does not exactly match the requested GRF (different MD5SUM), but grfid matches)
Definition: newgrf_config.h:26
Textbuf::buf
char *const buf
buffer in which text is saved
Definition: textbuf_type.h:32
Window::querystrings
SmallMap< int, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
Definition: window_gui.h:328
ShowErrorMessage
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x=0, int y=0, const GRFFile *textref_stack_grffile=nullptr, uint textref_stack_size=0, const uint32 *textref_stack=nullptr)
Display an error message in a window.
Definition: error_gui.cpp:372
DrawStringMultiLine
int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition: gfx.cpp:763
GCF_INVALID
@ GCF_INVALID
GRF is unusable with this version of OpenTTD.
Definition: newgrf_config.h:30
NewGRFParametersWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: newgrf_gui.cpp:305
IsInsideMM
static bool IsInsideMM(const T x, const size_t min, const size_t max)
Checks if a value is in an interval.
Definition: math_func.hpp:204
SavePresetWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: newgrf_gui.cpp:2113
NWidgetBase::Draw
virtual void Draw(const Window *w)=0
NewGRFParametersWindow::clicked_increase
bool clicked_increase
True if the increase button was clicked, false for the decrease button.
Definition: newgrf_gui.cpp:149
SavePresetWindow::selected
int selected
Selected entry in the preset list, or -1 if none selected.
Definition: newgrf_gui.cpp:2036
WindowDesc
High level window description.
Definition: window_gui.h:166
GRFBuildParamList
char * GRFBuildParamList(char *dst, const GRFConfig *c, const char *last)
Build a string containing space separated parameter values, and terminate.
Definition: newgrf_config.cpp:823
WC_MODAL_PROGRESS
@ WC_MODAL_PROGRESS
Progress report of landscape generation; Window numbers:
Definition: window_type.h:456
NewGRFWindow::OnMouseDrag
void OnMouseDrag(Point pt, int widget) override
An 'object' is being dragged at the provided position, highlight the target if possible.
Definition: newgrf_gui.cpp:1402
NETWORK_MAX_GRF_COUNT
static const uint NETWORK_MAX_GRF_COUNT
Maximum number of GRFs that can be sent.
Definition: config.h:58
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:428
GetGRFPresetList
StringList GetGRFPresetList()
Get the list of known NewGrf presets.
Definition: settings.cpp:1807
WC_QUERY_STRING
@ WC_QUERY_STRING
Query string window; Window numbers:
Definition: window_type.h:116
GUITimer
Definition: guitimer_func.h:13
DrawDropDownButton
void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool clickable)
Draw a dropdown button.
Definition: settings_gui.cpp:2446
Listing
Data structure describing how to show the list (what sort direction and criteria).
Definition: sortlist_type.h:30
GUIList::SetFilterState
void SetFilterState(bool state)
Enable or disable the filter.
Definition: sortlist_type.h:302
NWidgetBase::padding_left
uint8 padding_left
Paddings added to the left of the widget. Managed by parent container widget. (parent container may s...
Definition: widget_type.h:184
NewGRFWindow::CanUpgradeCurrent
bool CanUpgradeCurrent()
Test whether the currently active set of NewGRFs can be upgraded with the available NewGRFs.
Definition: newgrf_gui.cpp:680
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:322
NWidgetNewGRFDisplay::inf
NWidgetBase * inf
Info panel.
Definition: newgrf_gui.cpp:1587
settings_func.h
ScanProgressWindow::UpdateNewGRFScanStatus
void UpdateNewGRFScanStatus(uint num, const char *name)
Update the NewGRF scan status.
Definition: newgrf_gui.cpp:2246
Scrollbar::GetCount
uint16 GetCount() const
Gets the number of elements in the list.
Definition: widget_type.h:612
tilehighlight_func.h
GRFConfig
Information about GRF, used in the game and (part of it) in savegames.
Definition: newgrf_config.h:152
NewGRFParametersWindow::OnRealtimeTick
void OnRealtimeTick(uint delta_ms) override
Called periodically.
Definition: newgrf_gui.cpp:484
NewGRFWindow::last_sorting
static Listing last_sorting
Default sorting of #GUIGRFConfigList.
Definition: newgrf_gui.cpp:593
_nested_scan_progress_widgets
static const NWidgetPart _nested_scan_progress_widgets[]
Widgets for the progress window.
Definition: newgrf_gui.cpp:2157
NewGRFParametersWindow
Window for setting the parameters of a NewGRF.
Definition: newgrf_gui.cpp:145
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1861
NWidgetNewGRFDisplay
Custom nested widget container for the NewGRF gui.
Definition: newgrf_gui.cpp:1578
WWT_EDITBOX
@ WWT_EDITBOX
a textbox for typing
Definition: widget_type.h:69
WID_NS_RESCAN_FILES2
@ WID_NS_RESCAN_FILES2
Rescan files (active NewGRFs).
Definition: newgrf_widget.h:55
WID_SVP_SAVE
@ WID_SVP_SAVE
Button to save the preset.
Definition: newgrf_widget.h:68
GOID_NEWGRF_LIST_EDITED
@ GOID_NEWGRF_LIST_EDITED
List of active NewGRFs is being edited.
Definition: window_type.h:707
GUIList< const GRFConfig *, StringFilter & >::SortFunction
bool SortFunction(const const GRFConfig * &, const const GRFConfig * &)
Signature of sort function.
Definition: sortlist_type.h:48
WID_NP_NUMPAR_INC
@ WID_NP_NUMPAR_INC
Button to increase number of parameters.
Definition: newgrf_widget.h:20
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:984
GRFConfig::SetParameterDefaults
void SetParameterDefaults()
Set the default value for all parameters as specified by action14.
Definition: newgrf_config.cpp:129
WID_NP_SCROLLBAR
@ WID_NP_SCROLLBAR
Scrollbar to scroll through all settings.
Definition: newgrf_widget.h:24
GUIList::SetListing
void SetListing(Listing l)
Import sort conditions.
Definition: sortlist_type.h:130
NWidgetBase::smallest_x
uint smallest_x
Smallest horizontal size of the widget in a filled window.
Definition: widget_type.h:169
WD_FRAMERECT_LEFT
@ WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
Definition: window_gui.h:60
GRFConfig::flags
uint8 flags
NOSAVE: GCF_Flags, bitset.
Definition: newgrf_config.h:167
ContentInfo
Container for all important information about a piece of content.
Definition: tcp_content.h:54
GRFP_USE_WINDOWS
@ GRFP_USE_WINDOWS
The palette state is set to use the Windows palette.
Definition: newgrf_config.h:67
NWidgetBase::AssignSizePosition
virtual void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)=0
FillGrfidMap
static void FillGrfidMap(const GRFConfig *c, GrfIdMap *grfid_map)
Add all grf configs from c into the map.
Definition: newgrf_gui.cpp:573
IsInsideBS
static bool IsInsideBS(const T x, const size_t base, const size_t size)
Checks if a value is between a window started at some base point.
Definition: math_func.hpp:188
WD_PAR_VSEP_NORMAL
@ WD_PAR_VSEP_NORMAL
Normal amount of vertical space between two paragraphs of text.
Definition: window_gui.h:137
WD_FRAMERECT_RIGHT
@ WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:61
find_index
int find_index(std::vector< T > const &vec, T const &item)
Helper function to get the index of an item Consider using std::set, std::unordered_set or std::flat_...
Definition: smallvec_type.hpp:44
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition: window_type.h:719
WD_FRAMERECT_BOTTOM
@ WD_FRAMERECT_BOTTOM
Offset at bottom to draw the frame rectangular area.
Definition: window_gui.h:63
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:102
CopyGRFConfigList
GRFConfig ** CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src, bool init_only)
Copy a GRF Config list.
Definition: newgrf_config.cpp:419
GetGRFStringFromGRFText
const char * GetGRFStringFromGRFText(const GRFTextList &text_list)
Get a C-string from a GRFText-list.
Definition: newgrf_text.cpp:621
NWidgetBase
Baseclass for nested widgets.
Definition: widget_type.h:124
WID_NS_OPEN_URL
@ WID_NS_OPEN_URL
Open URL of NewGRF.
Definition: newgrf_widget.h:48
WD_FRAMETEXT_BOTTOM
@ WD_FRAMETEXT_BOTTOM
Bottom offset of the text of the frame.
Definition: window_gui.h:73
WID_NS_UPGRADE
@ WID_NS_UPGRADE
Upgrade NewGRFs that have a newer version available.
Definition: newgrf_widget.h:40
ShowDropDownList
void ShowDropDownList(Window *w, DropDownList &&list, int selected, int button, uint width, bool auto_width, bool instant_close)
Show a drop down list.
Definition: dropdown.cpp:453
SetMatrixDataTip
static NWidgetPart SetMatrixDataTip(uint8 cols, uint8 rows, StringID tip)
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition: widget_type.h:1031
NWidgetNewGRFDisplay::INTER_COLUMN_SPACING
static const uint INTER_COLUMN_SPACING
Empty horizontal space between two columns.
Definition: newgrf_gui.cpp:1581
ContentInfo::md5sum
byte md5sum[16]
The MD5 checksum.
Definition: tcp_content.h:74
ShowNewGRFError
void ShowNewGRFError()
Show the first NewGRF error we can find.
Definition: newgrf_gui.cpp:44
dropdown_type.h
GRFConfig::GetTextfile
const char * GetTextfile(TextfileType type) const
Search a textfile file next to this NewGRF.
Definition: newgrf_config.cpp:845
Filtering
Data structure describing what to show in the list (filter criteria).
Definition: sortlist_type.h:35
GamelogStartAction
void GamelogStartAction(GamelogActionType at)
Stores information about new action, but doesn't allocate it Action is allocated only when there is a...
Definition: gamelog.cpp:69
GRFParameterInfo
Information about one grf parameter.
Definition: newgrf_config.h:131
Window::SetWidgetDisabledState
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:392
WL_INFO
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
Definition: error.h:22
StringList
std::vector< std::string > StringList
Type for a list of strings.
Definition: string_type.h:58
NewGRFWindow::UpgradeCurrent
void UpgradeCurrent()
Upgrade the currently active set of NewGRFs.
Definition: newgrf_gui.cpp:693
DropDownListStringItem
Common string list item.
Definition: dropdown_type.h:39
NewGRFParametersWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: newgrf_gui.cpp:469
safeguards.h
NewGRFWindow::OnEditboxChanged
void OnEditboxChanged(int wid) override
The text in an editbox has been edited.
Definition: newgrf_gui.cpp:1344
sortlist_type.h
ShowQueryString
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
Definition: misc_gui.cpp:1131
WID_NS_MOVE_UP
@ WID_NS_MOVE_UP
Move NewGRF up in active list.
Definition: newgrf_widget.h:38
GRFP_BLT_32BPP
@ GRFP_BLT_32BPP
The NewGRF prefers a 32 bpp blitter.
Definition: newgrf_config.h:77
StrEmpty
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:60
WID_NS_APPLY_CHANGES
@ WID_NS_APPLY_CHANGES
Apply changes to NewGRF config.
Definition: newgrf_widget.h:53
DrawSprite
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Definition: gfx.cpp:978
WDF_MODAL
@ WDF_MODAL
The window is a modal child of some other window, meaning the parent is 'inactive'.
Definition: window_gui.h:209
DeleteGRFPresetFromConfig
void DeleteGRFPresetFromConfig(const char *config_name)
Delete a NewGRF configuration by preset name.
Definition: settings.cpp:1862
newgrf_text.h
WID_NS_CONTENT_DOWNLOAD2
@ WID_NS_CONTENT_DOWNLOAD2
Open content download (active NewGRFs).
Definition: newgrf_widget.h:57
settings_type.h
GetStringMultiLineBoundingBox
Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion)
Calculate string bounding box for multi-line strings.
Definition: gfx.cpp:729
WID_NS_REMOVE
@ WID_NS_REMOVE
Remove NewGRF from active list.
Definition: newgrf_widget.h:37
sprites.h
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
error.h
NewGRFConfirmationCallback
static void NewGRFConfirmationCallback(Window *w, bool confirmed)
Callback function for the newgrf 'apply changes' confirmation window.
Definition: newgrf_gui.cpp:1955
NewGRFTextfileWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: newgrf_gui.cpp:551
GRFConfig::GetURL
const char * GetURL() const
Get the grf url.
Definition: newgrf_config.cpp:123
GRFP_GRF_MASK
@ GRFP_GRF_MASK
Bitmask to get only the NewGRF supplied information.
Definition: newgrf_config.h:74
SETTING_BUTTON_WIDTH
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
Definition: settings_gui.h:17
NWidgetNewGRFDisplay::MIN_EXTRA_FOR_3_COLUMNS
static const uint MIN_EXTRA_FOR_3_COLUMNS
Minimal additional width needed before switching to 3 columns.
Definition: newgrf_gui.cpp:1583
WD_FRAMETEXT_RIGHT
@ WD_FRAMETEXT_RIGHT
Right offset of the text of the frame.
Definition: window_gui.h:71
Window::SetFocusedWidget
bool SetFocusedWidget(int widget_index)
Set focus within this window to the given widget.
Definition: window.cpp:495
stdafx.h
PC_BLACK
static const uint8 PC_BLACK
Black palette colour.
Definition: gfx_func.h:206
DrawArrowButtons
void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clickable_left, bool clickable_right)
Draw [<][>] boxes.
Definition: settings_gui.cpp:2418
GRFConfig::CopyParams
void CopyParams(const GRFConfig &src)
Copy the parameter information from the src config.
Definition: newgrf_config.cpp:92
GfxFillRect
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Definition: gfx.cpp:114
WID_SVP_CANCEL
@ WID_SVP_CANCEL
Button to cancel saving the preset.
Definition: newgrf_widget.h:67
NWidgetNewGRFDisplay::INTER_LIST_SPACING
static const uint INTER_LIST_SPACING
Empty vertical space between both lists in the 2 column mode.
Definition: newgrf_gui.cpp:1580
TFT_README
@ TFT_README
NewGRF readme.
Definition: textfile_type.h:17
BSWAP32
static uint32 BSWAP32(uint32 x)
Perform a 32 bits endianness bitswap on x.
Definition: bitmath_func.hpp:380
NewGRFWindow::orig_list
GRFConfig ** orig_list
List active grfs in the game. Used as initial value, may be updated by the window.
Definition: newgrf_gui.cpp:609
NWidgetNewGRFDisplay::editable
bool editable
Editable status of the parent NewGRF window (if false, drop all widgets that make the window editable...
Definition: newgrf_gui.cpp:1588
Window::InvalidateData
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Definition: window.cpp:3261
NEWGRF_DIR
@ NEWGRF_DIR
Subdirectory for all NewGRFs.
Definition: fileio_type.h:117
NewGRFWindow::TagNameFilter
static bool CDECL TagNameFilter(const GRFConfig *const *a, StringFilter &filter)
Filter grfs by tags/name.
Definition: newgrf_gui.cpp:1439
WID_NS_CONTENT_DOWNLOAD
@ WID_NS_CONTENT_DOWNLOAD
Open content download (available NewGRFs).
Definition: newgrf_widget.h:56
CONTENT_TYPE_NEWGRF
@ CONTENT_TYPE_NEWGRF
The content consists of a NewGRF.
Definition: tcp_content.h:24
SavePresetWindow::presetname_editbox
QueryString presetname_editbox
Edit box of the save preset.
Definition: newgrf_gui.cpp:2033
NWidgetBase::current_y
uint current_y
Current vertical size (after resizing).
Definition: widget_type.h:173
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:38
WID_NP_NUMPAR_DEC
@ WID_NP_NUMPAR_DEC
Button to decrease number of parameters.
Definition: newgrf_widget.h:19
ScanProgressWindow::scanned
int scanned
The number of NewGRFs that we have seen.
Definition: newgrf_gui.cpp:2181
GamelogStopAction
void GamelogStopAction()
Stops logging of any changes.
Definition: gamelog.cpp:78
PC_GREY
static const uint8 PC_GREY
Grey palette colour.
Definition: gfx_func.h:208
WID_NS_SHOW_APPLY
@ WID_NS_SHOW_APPLY
Select display of the buttons below the 'details'.
Definition: newgrf_widget.h:59
LoadGRFPresetFromConfig
GRFConfig * LoadGRFPresetFromConfig(const char *config_name)
Load a NewGRF configuration by preset-name.
Definition: settings.cpp:1827
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:75
NewGRFWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: newgrf_gui.cpp:822
HT_DRAG
@ HT_DRAG
dragging items in the depot windows
Definition: tilehighlight_type.h:24
NewGRFParametersWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: newgrf_gui.cpp:235
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:913
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:67
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:66
WID_NS_ADD
@ WID_NS_ADD
Add NewGRF to active list.
Definition: newgrf_widget.h:36
GUISettings::newgrf_show_old_versions
bool newgrf_show_old_versions
whether to show old versions in the NewGRF list
Definition: settings_type.h:179
GUIList::NeedRebuild
bool NeedRebuild() const
Check if a rebuild is needed.
Definition: sortlist_type.h:362
NWidgetBase::GetWidgetFromPos
virtual NWidgetCore * GetWidgetFromPos(int x, int y)=0
WID_NP_NUMPAR
@ WID_NP_NUMPAR
Optional number of parameters.
Definition: newgrf_widget.h:21
TFT_LICENSE
@ TFT_LICENSE
NewGRF license.
Definition: textfile_type.h:19
NewGRFWindow::filter_editbox
QueryString filter_editbox
Filter editbox;.
Definition: newgrf_gui.cpp:602
GCS_DISABLED
@ GCS_DISABLED
GRF file is disabled.
Definition: newgrf_config.h:36
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
NWidgetBase::fill_y
uint fill_y
Vertical fill stepsize (from initial size, 0 means not resizable).
Definition: widget_type.h:163
ShowQuery
void ShowQuery(StringID caption, StringID message, Window *parent, QueryCallbackProc *callback)
Show a modal confirmation window with standard 'yes' and 'no' buttons The window is aligned to the ce...
Definition: misc_gui.cpp:1274
RequestNewGRFScan
void RequestNewGRFScan(NewGRFScanCallback *callback)
Request a new NewGRF scan.
Definition: openttd.cpp:1454
QueryString::cancel_button
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
Definition: querystring_gui.h:28
GRFParameterInfo::max_value
uint32 max_value
The maximal value of this parameter.
Definition: newgrf_config.h:138
GRFError::message
StringID message
Default message.
Definition: newgrf_config.h:118
WID_SP_PROGRESS_TEXT
@ WID_SP_PROGRESS_TEXT
Text explaining what is happening.
Definition: newgrf_widget.h:74
WID_NS_VIEW_PARAMETERS
@ WID_NS_VIEW_PARAMETERS
Open Parameters Window for selected NewGRF for viewing parameters.
Definition: newgrf_widget.h:51
WC_GAME_OPTIONS
@ WC_GAME_OPTIONS
Game options window; Window numbers:
Definition: window_type.h:606
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:998
NewGRFParametersWindow::line_height
int line_height
Height of a row in the matrix widget.
Definition: newgrf_gui.cpp:154
strings_func.h
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:82
NewGRFWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: newgrf_gui.cpp:767
DeleteWindowById
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
Definition: window.cpp:1165
GRFParameterInfo::value_names
SmallMap< uint32, GRFTextList > value_names
Names for each value.
Definition: newgrf_config.h:143
ScanProgressWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: newgrf_gui.cpp:2195
NWidgetBase::pos_x
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:175
WID_SVP_PRESET_LIST
@ WID_SVP_PRESET_LIST
List with available preset names.
Definition: newgrf_widget.h:64
NewGRFWindow::avail_sel
const GRFConfig * avail_sel
Currently selected available grf. nullptr is none is selected.
Definition: newgrf_gui.cpp:599
GRFParameterInfo::desc
GRFTextList desc
The description of this parameter.
Definition: newgrf_config.h:135
HideDropDownMenu
int HideDropDownMenu(Window *pw)
Delete the drop-down menu from window pw.
Definition: dropdown.cpp:512
NewGRFParametersWindow::closing_dropdown
bool closing_dropdown
True, if the dropdown list is currently closing.
Definition: newgrf_gui.cpp:151
WIDGET_LIST_END
static const int WIDGET_LIST_END
indicate the end of widgets' list for vararg functions
Definition: widget_type.h:20
NewGRFParametersWindow::OnDropdownSelect
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
Definition: newgrf_gui.cpp:439
WWT_TEXT
@ WWT_TEXT
Pure simple text.
Definition: widget_type.h:56
GRFConfig::min_loadable_version
uint32 min_loadable_version
NOSAVE: Minimum compatible version a NewGRF can define.
Definition: newgrf_config.h:166
SavePresetWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: newgrf_gui.cpp:2072
_newgrf_parameters_desc
static WindowDesc _newgrf_parameters_desc(WDP_CENTER, "settings_newgrf_config", 500, 208, WC_GRF_PARAMETERS, WC_NONE, 0, _nested_newgrf_parameter_widgets, lengthof(_nested_newgrf_parameter_widgets))
Window definition for the change grf parameters window.
WID_NS_SET_PARAMETERS
@ WID_NS_SET_PARAMETERS
Open Parameters Window for selected NewGRF for editing parameters.
Definition: newgrf_widget.h:50
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:179
GRFConfig::GetDescription
const char * GetDescription() const
Get the grf info.
Definition: newgrf_config.cpp:114
GRFConfig::original_md5sum
uint8 original_md5sum[16]
MD5 checksum of original file if only a 'compatible' file was loaded.
Definition: newgrf_config.h:158
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1113
PC_DARK_BLUE
static const uint8 PC_DARK_BLUE
Dark blue palette colour.
Definition: gfx_func.h:226
NWidgetBase::fill_x
uint fill_x
Horizontal fill stepsize (from initial size, 0 means not resizable).
Definition: widget_type.h:162
Scrollbar::IsVisible
bool IsVisible(uint16 item) const
Checks whether given current item is visible in the list.
Definition: widget_type.h:640
geometry_func.hpp
GUIList< const GRFConfig *, StringFilter & >::FilterFunction
bool CDECL FilterFunction(const const GRFConfig * *, StringFilter &)
Signature of filter function.
Definition: sortlist_type.h:49
PaletteID
uint32 PaletteID
The number of the palette.
Definition: gfx_type.h:18
SetDParamMaxValue
void SetDParamMaxValue(uint n, uint64 max_value, uint min_count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
Definition: strings.cpp:104
NewGRFWindow::grf_presets
StringList grf_presets
List of known NewGRF presets.
Definition: newgrf_gui.cpp:604
GOID_NEWGRF_RESCANNED
@ GOID_NEWGRF_RESCANNED
NewGRFs were just rescanned.
Definition: window_type.h:706
ShowNewGRFSettings
void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config)
Setup the NewGRF gui.
Definition: newgrf_gui.cpp:1994
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:946
GRFConfig::next
struct GRFConfig * next
NOSAVE: Next item in the linked list.
Definition: newgrf_config.h:177
StringFilter::ResetState
void ResetState()
Reset the matching state to process a new item.
Definition: stringfilter.cpp:88
NewGRFParametersWindow::timeout
GUITimer timeout
How long before we unpress the last-pressed button?
Definition: newgrf_gui.cpp:152
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:48
GamelogGRFUpdate
void GamelogGRFUpdate(const GRFConfig *oldc, const GRFConfig *newc)
Compares two NewGRF lists and logs any change.
Definition: gamelog.cpp:722
Window::SetWidgetsDisabledState
void CDECL SetWidgetsDisabledState(bool disab_stat, int widgets,...)
Sets the enabled/disabled status of a list of widgets.
Definition: window.cpp:536
NWidgetBase::resize_y
uint resize_y
Vertical resize step (0 means not resizable).
Definition: widget_type.h:165
newgrf.h
NWidgetBase::StoreSizePosition
void StoreSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height)
Store size and position.
Definition: widget_type.h:216
NewGRFWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: newgrf_gui.cpp:718
EventState
EventState
State of handling an event.
Definition: window_type.h:717
FGCM_NEWEST
@ FGCM_NEWEST
Find newest Grf.
Definition: newgrf_config.h:195
FGCM_NEWEST_VALID
@ FGCM_NEWEST_VALID
Find newest Grf, ignoring Grfs with GCF_INVALID set.
Definition: newgrf_config.h:196
GRFParameterInfo::name
GRFTextList name
The name of this parameter.
Definition: newgrf_config.h:134
GLAT_GRF
@ GLAT_GRF
GRF changed.
Definition: gamelog.h:19
Scrollbar::GetPosition
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:630
GUIList::SetFiltering
void SetFiltering(Filtering f)
Import filter conditions.
Definition: sortlist_type.h:181
FindWindowByClass
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
Definition: window.cpp:1149
NewGRFWindow::show_params
bool show_params
Are the grf-parameters shown in the info-panel?
Definition: newgrf_gui.cpp:611
StringFilter::GetState
bool GetState() const
Get the matching state of the current item.
Definition: stringfilter_type.h:69
NewGRFParametersWindow::action14present
bool action14present
True if action14 information is present.
Definition: newgrf_gui.cpp:156
WID_NS_FILTER
@ WID_NS_FILTER
Filter list of available NewGRFs.
Definition: newgrf_widget.h:41
WD_RESIZEBOX_WIDTH
@ WD_RESIZEBOX_WIDTH
Width of a resize box widget.
Definition: window_gui.h:110
NewGRFParametersWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: newgrf_gui.cpp:314
seprintf
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
Definition: string.cpp:442
GUIList::Filter
bool Filter(FilterFunction *decide, F filter_data)
Filter the list.
Definition: sortlist_type.h:318
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1848
NWID_SPACER
@ NWID_SPACER
Invisible widget that takes some space.
Definition: widget_type.h:77
NewGRFParametersWindow::OnQueryTextFinished
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
Definition: newgrf_gui.cpp:428
WWT_INSET
@ WWT_INSET
Pressed (inset) panel, most commonly used as combo box text area.
Definition: widget_type.h:49
WL_ERROR
@ WL_ERROR
Errors (eg. saving/loading failed)
Definition: error.h:24
QueryString::ACTION_CLEAR
static const int ACTION_CLEAR
Clear editbox.
Definition: querystring_gui.h:24
NWidgetContainer
Baseclass for container widgets.
Definition: widget_type.h:367
Window::top
int top
y position of top edge of the window
Definition: window_gui.h:318
WID_NS_SCROLL2BAR
@ WID_NS_SCROLL2BAR
Scrollbar for available NewGRF list.
Definition: newgrf_widget.h:45
NWidgetBase::padding_right
uint8 padding_right
Paddings added to the right of the widget. Managed by parent container widget. (parent container may ...
Definition: widget_type.h:182
stredup
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
Definition: string.cpp:137
GUITimer::Elapsed
bool Elapsed(uint delta)
Test if a timer has elapsed.
Definition: guitimer_func.h:55
GRFConfig::palette
uint8 palette
GRFPalette, bitset.
Definition: newgrf_config.h:173
GRFParameterInfo::complete_labels
bool complete_labels
True if all values have a label.
Definition: newgrf_config.h:144
DrawFrameRect
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition: widget.cpp:175
network.h
_grfconfig
GRFConfig * _grfconfig
First item in list of current GRF set up.
Definition: newgrf_config.cpp:170
ContentInfo::state
State state
Whether the content info is selected (for download)
Definition: tcp_content.h:79
NewGRFTextfileWindow::grf_config
const GRFConfig * grf_config
View the textfile of this GRFConfig.
Definition: newgrf_gui.cpp:543
SmallMap::Find
std::vector< Pair >::const_iterator Find(const T &key) const
Finds given key in this map.
Definition: smallmap_type.hpp:41
ContentInfo::unique_id
uint32 unique_id
Unique ID; either GRF ID or shortname.
Definition: tcp_content.h:73
WD_MATRIX_BOTTOM
@ WD_MATRIX_BOTTOM
Offset at bottom of a matrix cell.
Definition: window_gui.h:79
ShowDropDownListAt
void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, int button, Rect wi_rect, Colours wi_colour, bool auto_width, bool instant_close)
Show a drop down list.
Definition: dropdown.cpp:366
window_func.h
WID_NP_SHOW_NUMPAR
@ WID_NP_SHOW_NUMPAR
NWID_SELECTION to optionally display WID_NP_NUMPAR.
Definition: newgrf_widget.h:18
GUIList::ForceRebuild
void ForceRebuild()
Force that a rebuild is needed.
Definition: sortlist_type.h:370
NewGRFScanCallback
Callback for NewGRF scanning.
Definition: newgrf_config.h:207
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:367
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:319
_scan_progress_desc
static WindowDesc _scan_progress_desc(WDP_CENTER, nullptr, 0, 0, WC_MODAL_PROGRESS, WC_NONE, 0, _nested_scan_progress_widgets, lengthof(_nested_scan_progress_widgets))
Description of the widgets and other settings of the window.
stringfilter_type.h
WID_NS_NEWGRF_INFO_TITLE
@ WID_NS_NEWGRF_INFO_TITLE
Title for Info on selected NewGRF.
Definition: newgrf_widget.h:46
Scrollbar::SetCapacityFromWidget
void SetCapacityFromWidget(Window *w, int widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition: widget.cpp:1980
WC_BUILD_OBJECT
@ WC_BUILD_OBJECT
Build object; Window numbers:
Definition: window_type.h:369
WID_NS_FILE_LIST
@ WID_NS_FILE_LIST
List window of active NewGRFs.
Definition: newgrf_widget.h:42
SetPIP
static NWidgetPart SetPIP(uint8 pre, uint8 inter, uint8 post)
Widget part function for setting a pre/inter/post spaces.
Definition: widget_type.h:1075
NewGRFWindow::last_filtering
static Filtering last_filtering
Default filtering of #GUIGRFConfigList.
Definition: newgrf_gui.cpp:594
ScanProgressWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: newgrf_gui.cpp:2218
WID_NP_SHOW_DESCRIPTION
@ WID_NP_SHOW_DESCRIPTION
NWID_SELECTION to optionally display parameter descriptions.
Definition: newgrf_widget.h:27
NWidgetBase::pos_y
int pos_y
Vertical position of top-left corner of the widget in the window.
Definition: widget_type.h:176
NewGRFWindow::editable
bool editable
Is the window editable?
Definition: newgrf_gui.cpp:610
PTYPE_BOOL
@ PTYPE_BOOL
The parameter is either 0 or 1.
Definition: newgrf_config.h:126
SetObjectToPlaceWnd
void SetObjectToPlaceWnd(CursorID icon, PaletteID pal, HighLightStyle mode, Window *w)
Change the cursor and mouse click/drag handling to a mode for performing special operations like tile...
Definition: viewport.cpp:3358
strnatcmp
int strnatcmp(const char *s1, const char *s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
Definition: string.cpp:625
SetFill
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:982
GUISettings::scenario_developer
bool scenario_developer
activate scenario developer: allow modifying NewGRFs in an existing game
Definition: settings_type.h:177
TextfileWindow
Window for displaying a textfile.
Definition: textfile_gui.h:21
NewGRFWindow::OnDragDrop
void OnDragDrop(Point pt, int widget) override
A dragged 'object' has been released.
Definition: newgrf_gui.cpp:1354
NewGRFParametersWindow::grf_config
GRFConfig * grf_config
Set the parameters of this GRFConfig.
Definition: newgrf_gui.cpp:147
NewGRFParametersWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: newgrf_gui.cpp:244
WID_SVP_SCROLLBAR
@ WID_SVP_SCROLLBAR
Scrollbar for the list available preset names.
Definition: newgrf_widget.h:65
SPR_CURSOR_MOUSE
static const CursorID SPR_CURSOR_MOUSE
Cursor sprite numbers.
Definition: sprites.h:1374
GUISettings::last_newgrf_count
uint32 last_newgrf_count
the numbers of NewGRFs we found during the last scan
Definition: settings_type.h:153
NWidgetBase::padding_bottom
uint8 padding_bottom
Paddings added to the bottom of the widget. Managed by parent container widget.
Definition: widget_type.h:183
PTYPE_UINT_ENUM
@ PTYPE_UINT_ENUM
The parameter allows a range of numbers, each of which can have a special name.
Definition: newgrf_config.h:125
newgrf_widget.h
NWidgetNewGRFDisplay::SetupSmallestSize
void SetupSmallestSize(Window *w, bool init_array) override
Definition: newgrf_gui.cpp:1603
Window
Data structure for an opened window.
Definition: window_gui.h:276
WID_NP_ACCEPT
@ WID_NP_ACCEPT
Accept button.
Definition: newgrf_widget.h:25
SizingType
SizingType
Different forms of sizing nested widgets, using NWidgetBase::AssignSizePosition()
Definition: widget_type.h:109
GUIList::RebuildDone
void RebuildDone()
Notify the sortlist that the rebuild is done.
Definition: sortlist_type.h:380
TextfileType
TextfileType
Additional text files accompanying Tar archives.
Definition: textfile_type.h:14
md5sumToString
char * md5sumToString(char *buf, const char *last, const uint8 md5sum[16])
Convert the md5sum to a hexadecimal string representation.
Definition: string.cpp:460
ResetGRFConfig
void ResetGRFConfig(bool defaults)
Reset the current GRF Config to either blank or newgame settings.
Definition: newgrf_config.cpp:496
NWidgetNewGRFDisplay::AssignSizePosition
void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override
Definition: newgrf_gui.cpp:1646
ContentInfo::name
char name[32]
Name of the content.
Definition: tcp_content.h:69
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:602
NewGRFWindow::OnDropdownSelect
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
Definition: newgrf_gui.cpp:1144
FGCM_EXACT
@ FGCM_EXACT
Only find Grfs matching md5sum.
Definition: newgrf_config.h:193
NewGRFParametersWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: newgrf_gui.cpp:191
PC_DARK_GREY
static const uint8 PC_DARK_GREY
Dark grey palette colour.
Definition: gfx_func.h:207
Window::OnQueryTextFinished
virtual void OnQueryTextFinished(char *str)
The query window opened from this window has closed.
Definition: window_gui.h:738
GRFConfig::filename
char * filename
Filename - either with or without full path.
Definition: newgrf_config.h:159
DrawBoolButton
void DrawBoolButton(int x, int y, bool state, bool clickable)
Draw a toggle button.
Definition: settings_gui.cpp:2465
NewGRFWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: newgrf_gui.cpp:911
settings_gui.h
_network_available
bool _network_available
is network mode available?
Definition: network.cpp:54
strecpy
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
Definition: string.cpp:112
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:78
NewGRFTextfileWindow
Window for displaying the textfile of a NewGRF.
Definition: newgrf_gui.cpp:542
WID_TF_CAPTION
@ WID_TF_CAPTION
The caption of the window.
Definition: misc_widget.h:51
free
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: stdafx.h:454
NWidgetCore
Base class for a 'real' widget.
Definition: widget_type.h:282
Window::SetWidgetDirty
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:597
NewGRFParametersWindow::clicked_button
uint clicked_button
The row in which a button was clicked or UINT_MAX.
Definition: newgrf_gui.cpp:148
NewGRFWindow::GetPalette
PaletteID GetPalette(const GRFConfig *c) const
Pick the palette for the sprite of the grf to display.
Definition: newgrf_gui.cpp:792
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:47
WID_NP_DESCRIPTION
@ WID_NP_DESCRIPTION
Multi-line description of a parameter.
Definition: newgrf_widget.h:28
SavePresetWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: newgrf_gui.cpp:2089
NWidgetBase::resize_x
uint resize_x
Horizontal resize step (0 means not resizable).
Definition: widget_type.h:164
NewGRFParametersWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: newgrf_gui.cpp:459
AWV_INCREASE
@ AWV_INCREASE
Arrow to the right or in case of RTL to the left.
Definition: widget_type.h:36
NewGRFWindow::avail_pos
int avail_pos
Index of avail_sel if existing, else -1.
Definition: newgrf_gui.cpp:600
GRFError::param_value
uint32 param_value[2]
Values of GRF parameters to show for message and custom_message.
Definition: newgrf_config.h:120
Window::DisableWidget
void DisableWidget(byte widget_index)
Sets a widget to disabled.
Definition: window_gui.h:402
NWidgetBase::current_x
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:172
WC_TEXTFILE
@ WC_TEXTFILE
textfile; Window numbers:
Definition: window_type.h:180
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:383
NewGRFWindow::OnQueryTextFinished
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
Definition: newgrf_gui.cpp:1163
WID_NS_PRESET_SAVE
@ WID_NS_PRESET_SAVE
Save list of active NewGRFs as presets.
Definition: newgrf_widget.h:34
SetDParamMaxDigits
void SetDParamMaxDigits(uint n, uint count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
Definition: strings.cpp:120
ResetObjectToPlace
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
Definition: viewport.cpp:3421
SaveGRFPresetToConfig
void SaveGRFPresetToConfig(const char *config_name, GRFConfig *config)
Save a NewGRF configuration with a preset name.
Definition: settings.cpp:1846
SavePresetWindow::vscroll
Scrollbar * vscroll
Pointer to the scrollbar widget.
Definition: newgrf_gui.cpp:2035
WDP_CENTER
@ WDP_CENTER
Center the window.
Definition: window_gui.h:155
SETTING_BUTTON_HEIGHT
#define SETTING_BUTTON_HEIGHT
Height of setting buttons.
Definition: settings_gui.h:19
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:48
WID_SVP_EDITBOX
@ WID_SVP_EDITBOX
Edit box for changing the preset name.
Definition: newgrf_widget.h:66
LeastCommonMultiple
int LeastCommonMultiple(int a, int b)
Compute least common multiple (lcm) of arguments a and b, the smallest integer value that is a multip...
Definition: math_func.cpp:24
CS_NUMERAL
@ CS_NUMERAL
Only numeric ones.
Definition: string_type.h:28
misc_widget.h
WD_TEXTPANEL_BOTTOM
@ WD_TEXTPANEL_BOTTOM
Offset at bottom to draw below the text.
Definition: window_gui.h:67
StringFilter
String filter and state.
Definition: stringfilter_type.h:31
SavePresetWindow::presets
StringList presets
Available presets.
Definition: newgrf_gui.cpp:2034
NewGRFParametersWindow::clicked_row
uint clicked_row
The selected parameter.
Definition: newgrf_gui.cpp:153
SetDParamStr
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:286
SavePresetWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: newgrf_gui.cpp:2140
WID_NS_SHOW_REMOVE
@ WID_NS_SHOW_REMOVE
Select active list buttons (0 = normal, 1 = simple layout).
Definition: newgrf_widget.h:58
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17
GCF_STATIC
@ GCF_STATIC
GRF file is used statically (can be used in any MP game)
Definition: newgrf_config.h:25
GRFConfig::param_info
std::vector< GRFParameterInfo * > param_info
NOSAVE: extra information about the parameters.
Definition: newgrf_config.h:174
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:577
WL_CRITICAL
@ WL_CRITICAL
Critical errors, the MessageBox is shown in all cases.
Definition: error.h:25
WID_NS_RESCAN_FILES
@ WID_NS_RESCAN_FILES
Rescan files (available NewGRFs).
Definition: newgrf_widget.h:54
GRFConfig::param
uint32 param[0x80]
GRF parameters.
Definition: newgrf_config.h:170
GRFParameterInfo::min_value
uint32 min_value
The minimal value this parameter can have.
Definition: newgrf_config.h:137
FR_BORDERONLY
@ FR_BORDERONLY
Draw border only, no background.
Definition: window_gui.h:28
AWV_DECREASE
@ AWV_DECREASE
Arrow to the left or in case of RTL to the right.
Definition: widget_type.h:35
WWT_DROPDOWN
@ WWT_DROPDOWN
Drop down list.
Definition: widget_type.h:68
GRFConfig::GetName
const char * GetName() const
Get the name of this grf.
Definition: newgrf_config.cpp:104
GUIList::SetSortFuncs
void SetSortFuncs(SortFunction *const *n_funcs)
Hand the array of sort function pointers to the sort list.
Definition: sortlist_type.h:270
WD_TEXTPANEL_TOP
@ WD_TEXTPANEL_TOP
Offset at top to draw above the text.
Definition: window_gui.h:66
ScanProgressWindow::last_name
char * last_name
The name of the last 'seen' NewGRF.
Definition: newgrf_gui.cpp:2180
GOID_NEWGRF_PRESET_LOADED
@ GOID_NEWGRF_PRESET_LOADED
A NewGRF preset was picked.
Definition: window_type.h:708
GRFError::data
std::string data
Additional data for message and custom_message.
Definition: newgrf_config.h:117
NWidgetBase::SetupSmallestSize
virtual void SetupSmallestSize(Window *w, bool init_array)=0
NewGRFWindow::avails
GUIGRFConfigList avails
Available (non-active) grfs.
Definition: newgrf_gui.cpp:598
NewGRFParametersWindow::dummy_parameter_info
static GRFParameterInfo dummy_parameter_info
Dummy info in case a newgrf didn't provide info about some parameter.
Definition: newgrf_gui.cpp:146
SmallMap::Contains
bool Contains(const T &key) const
Tests whether a key is assigned in this map.
Definition: smallmap_type.hpp:79
WID_SP_PROGRESS_BAR
@ WID_SP_PROGRESS_BAR
Simple progress bar.
Definition: newgrf_widget.h:73