OpenTTD Source: src/newgrf_gui.cpp Source File

OpenTTD Source 13.1

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