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