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