|
OpenTTD Source
14.0-beta3
|
Go to the documentation of this file.
48 if (_game_mode == GM_MENU)
return;
52 if (!c->error.has_value() || (c->error->severity != STR_NEWGRF_ERROR_MSG_FATAL && c->error->severity != STR_NEWGRF_ERROR_MSG_ERROR))
continue;
55 SetDParam (1, c->error->message != STR_NULL ? c->error->message : STR_JUST_RAW_STRING);
59 for (uint i = 0; i < c->error->param_value.size(); i++) {
60 SetDParam(5 + i, c->error->param_value[i]);
62 if (c->error->severity == STR_NEWGRF_ERROR_MSG_FATAL) {
71 static void ShowNewGRFInfo(
const GRFConfig *c,
const Rect &r,
bool show_params)
74 if (c->
error.has_value()) {
78 for (uint i = 0; i < c->
error->param_value.size(); i++) {
115 SetDParam(0, STR_NEWGRF_SETTINGS_PARAMETER_NONE);
170 this->GetWidget<NWidgetCore>(
WID_NP_CAPTION)->SetDataTip(is_baseset ? STR_BASEGRF_PARAMETERS_CAPTION : STR_NEWGRF_PARAMETERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS);
199 return nr < this->grf_config->
param_info.size() && this->grf_config->
param_info[nr].has_value();
226 d.width += padding.width;
227 d.height += padding.height;
243 for (
const auto &par_info : this->grf_config->
param_info) {
244 if (!par_info.has_value())
continue;
246 if (desc ==
nullptr)
continue;
249 suggestion =
maxdim(d, suggestion);
251 size->height = suggestion.height;
256 void SetStringParameters(
WidgetID widget)
const override
265 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
271 if (desc ==
nullptr)
return;
287 uint32_t current_value = par_info.
GetValue(this->grf_config);
291 DrawBoolButton(buttons_left, ir.top + button_y_offset, current_value != 0, this->editable);
292 SetDParam(2, par_info.
GetValue(this->grf_config) == 0 ? STR_CONFIG_SETTING_OFF : STR_CONFIG_SETTING_ON);
295 DrawDropDownButton(buttons_left, ir.top + button_y_offset, COLOUR_YELLOW, this->clicked_row == i && this->clicked_dropdown, this->editable);
297 DrawArrowButtons(buttons_left, ir.top + button_y_offset, COLOUR_YELLOW, (this->clicked_button == i) ? 1 + (this->clicked_increase != rtl) : 0, this->editable && current_value > par_info.
min_value, this->editable && current_value < par_info.
max_value);
301 auto it = par_info.
value_names.find(current_value);
304 if (label !=
nullptr) {
312 if (name !=
nullptr) {
316 SetDParam(0, STR_NEWGRF_PARAMETERS_DEFAULT_NAME);
320 DrawString(tr.left, tr.right, ir.top + text_y_offset, STR_NEWGRF_PARAMETERS_SETTING, selected ? TC_WHITE : TC_LIGHT_BLUE);
327 if (this->closing_dropdown) {
328 this->closing_dropdown =
false;
329 this->clicked_dropdown =
false;
334 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
338 if (this->editable && !this->action14present && this->grf_config->
num_params > 0) {
356 if (!this->editable)
break;
358 if (num >= this->vscroll->
GetCount())
break;
360 if (this->clicked_row != num) {
363 this->clicked_row = num;
364 this->clicked_dropdown =
false;
368 int x = pt.x - r.left;
374 uint32_t old_val = par_info.
GetValue(this->grf_config);
376 if (this->clicked_dropdown) {
379 this->clicked_dropdown =
false;
380 this->closing_dropdown =
false;
382 int rel_y = (pt.y - r.top) % this->line_height;
391 if (pt.y >= wi_rect.top && pt.y <= wi_rect.bottom) {
392 this->clicked_dropdown =
true;
393 this->closing_dropdown =
false;
404 uint32_t val = old_val;
411 this->clicked_increase =
true;
415 this->clicked_increase =
false;
418 if (val != old_val) {
419 par_info.
SetValue(this->grf_config, val);
421 this->clicked_button = num;
434 if (!this->editable)
break;
446 void OnQueryTextFinished(
char *str)
override
449 int32_t value = atoi(str);
452 par_info.
SetValue(this->grf_config, val);
456 void OnDropdownSelect(
WidgetID widget,
int index)
override
459 assert(this->clicked_dropdown);
461 par_info.
SetValue(this->grf_config, index);
472 assert(this->clicked_dropdown);
473 this->closing_dropdown =
true;
487 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
489 if (!gui_scope)
return;
490 if (!this->action14present) {
496 if (this->clicked_row != UINT_MAX && this->clicked_row >= this->vscroll->
GetCount()) {
497 this->clicked_row = UINT_MAX;
504 this->clicked_button = UINT_MAX;
511 static constexpr
NWidgetPart _nested_newgrf_parameter_widgets[] = {
522 NWidget(
WWT_TEXT, COLOUR_MAUVE,
WID_NP_NUMPAR),
SetResize(1, 0),
SetFill(1, 0),
SetPadding(0, 0, 0, 4),
SetDataTip(STR_NEWGRF_PARAMETERS_NUM_PARAM, STR_NULL),
527 NWidget(
WWT_MATRIX, COLOUR_MAUVE,
WID_NP_BACKGROUND),
SetMinimalSize(188, 182),
SetResize(1, 1),
SetFill(1, 0),
SetMatrixDataTip(1, 0, STR_NULL),
SetScrollbar(
WID_NP_SCROLLBAR),
545 WDP_CENTER,
"settings_newgrf_config", 500, 208,
548 std::begin(_nested_newgrf_parameter_widgets), std::end(_nested_newgrf_parameter_widgets)
551 void OpenGRFParameterWindow(
bool is_baseset,
GRFConfig *c,
bool editable)
563 this->ConstructWindow();
569 void SetStringParameters(
WidgetID widget)
const override
584 typedef std::map<uint32_t, const GRFConfig *>
GrfIdMap;
593 while (c !=
nullptr) {
594 std::pair<uint32_t, const GRFConfig *> p(c->
ident.
grfid, c);
595 grfid_map->insert(p);
609 static const uint EDITBOX_MAX_SIZE = 50;
640 this->avail_sel =
nullptr;
641 this->avail_pos = -1;
642 this->active_sel =
nullptr;
643 this->actives =
nullptr;
649 this->active_over = -1;
658 this->GetWidget<NWidgetStacked>(
WID_NS_SHOW_REMOVE)->SetDisplayedPlane(this->editable ? 0 : 1);
679 void Close([[maybe_unused]]
int data = 0)
override
685 if (this->editable && this->modified && !this->execute && !_exit_game) {
710 GrfIdMap::const_iterator iter = grfid_map.find(a->ident.grfid);
711 if (iter != grfid_map.end() && a->version > iter->second->version)
return true;
723 GrfIdMap::iterator iter = grfid_map.find(a->ident.grfid);
724 if (iter == grfid_map.end() || iter->second->version >= a->version)
continue;
727 while (*c != iter->second) c = &(*c)->
next;
735 if (this->active_sel == *c) {
738 this->active_sel =
nullptr;
753 size->height = std::max(size->height, padding.height + 6 *
resize->height);
761 size->height = std::max(size->height, padding.height + 8 *
resize->height);
778 for (
const auto &i : this->grf_presets) {
782 d.width += padding.width;
791 size->width += padding.width;
792 size->height += padding.height;
804 void SetStringParameters(
WidgetID widget)
const override
808 if (this->preset == -1) {
831 pal = PALETTE_TO_RED;
834 pal = PALETTE_TO_GREEN;
837 pal = PALETTE_TO_BLUE;
842 if (pal != PALETTE_TO_RED) {
844 pal = PALETTE_TO_GREY;
846 pal = PALETTE_TO_ORANGE;
853 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
861 uint step_height = this->GetWidget<NWidgetBase>(
WID_NS_FILE_LIST)->resize_y;
864 int square_offset_y = (step_height - square.height) / 2;
865 int warning_offset_y = (step_height - warning.height) / 2;
869 uint text_left = rtl ? tr.left : tr.left + square.width + 13;
870 uint text_right = rtl ? tr.right - square.width - 13 : tr.right;
871 uint square_left = rtl ? tr.right - square.width - 3 : tr.left + 3;
872 uint warning_left = rtl ? tr.right - square.width - warning.width - 8 : tr.left + square.width + 8;
875 for (
const GRFConfig *c = this->actives; c !=
nullptr; c = c->
next, i++) {
877 const char *text = c->
GetName();
878 bool h = (this->active_sel == c);
883 }
else if (i == this->active_over) {
885 int active_sel_pos = 0;
887 if (active_sel_pos != this->active_over) {
888 uint
top = this->active_over < active_sel_pos ? tr.top + 1 : tr.top + step_height - 2;
892 DrawSprite(SPR_SQUARE, pal, square_left, tr.top + square_offset_y);
893 if (c->
error.has_value())
DrawSprite(SPR_WARNING_SIGN, 0, warning_left, tr.top + warning_offset_y);
894 uint txtoffset = !c->
error.has_value() ? 0 : warning.width;
895 DrawString(text_left + (rtl ? 0 : txtoffset), text_right - (rtl ? txtoffset : 0), tr.top + offset_y, text, h ? TC_WHITE : TC_ORANGE);
896 tr.top += step_height;
899 if (i == this->active_over && this->vscroll->
IsVisible(i)) {
913 uint max_index = std::min(min_index + this->vscroll2->
GetCapacity(), (uint)this->avails.size());
915 for (uint i = min_index; i < max_index; i++) {
918 const char *text = c->
GetName();
921 DrawString(tr.left, tr.right, tr.top + offset_y, text, h ? TC_WHITE : TC_SILVER);
922 tr.top += step_height;
936 if (selected ==
nullptr) selected = this->
avail_sel;
937 if (selected !=
nullptr) {
938 ShowNewGRFInfo(selected, r, this->show_params);
945 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
948 if (this->active_sel ==
nullptr && this->avail_sel ==
nullptr)
return;
959 list.push_back(std::make_unique<DropDownListStringItem>(STR_NONE, -1,
false));
961 for (uint i = 0; i < this->grf_presets.size(); i++) {
962 list.push_back(std::make_unique<DropDownListStringItem>(this->grf_presets[i], i,
false));
971 const GRFConfig *c = (this->avail_sel ==
nullptr) ? this->active_sel : this->avail_sel;
982 if (this->preset == -1)
return;
992 if (this->active_sel ==
nullptr || !this->editable)
break;
995 for (
GRFConfig **pc = &this->actives; *pc !=
nullptr; pc = &(*pc)->
next, pos++) {
997 if (c->
next == this->active_sel) {
999 this->active_sel->
next = c;
1011 if (this->active_sel ==
nullptr || !this->editable)
break;
1014 for (
GRFConfig **pc = &this->actives; *pc !=
nullptr; pc = &(*pc)->
next, pos++) {
1016 if (c == this->active_sel) {
1035 for (c = this->actives; c !=
nullptr && i > 0; c = c->
next, i--) {}
1037 if (this->active_sel != c) {
1041 this->active_sel = c;
1042 this->avail_sel =
nullptr;
1043 this->avail_pos = -1;
1046 if (click_count == 1) {
1055 if (this->active_sel ==
nullptr || !this->editable)
break;
1061 for (
GRFConfig **pc = &this->actives; *pc !=
nullptr; pc = &(*pc)->
next) {
1065 if (newsel ==
nullptr && c->
next == this->active_sel) newsel = c;
1067 if (c == this->active_sel) {
1068 if (newsel == c) newsel =
nullptr;
1076 this->active_sel = newsel;
1078 this->avail_pos = -1;
1079 this->avail_sel =
nullptr;
1086 if (!this->editable || this->actives ==
nullptr)
break;
1096 this->active_sel =
nullptr;
1098 if (it != this->avails.end()) {
1100 this->avail_sel = *it;
1101 this->avail_pos = it - this->avails.begin();
1104 if (click_count == 1) {
1119 if (!this->editable)
break;
1120 if (this->execute) {
1122 STR_NEWGRF_POPUP_CAUTION_CAPTION,
1123 STR_NEWGRF_CONFIRMATION_TEXT,
1138 if (this->active_sel ==
nullptr || !this->show_params || this->active_sel->
num_valid_params == 0)
break;
1140 OpenGRFParameterWindow(
false, this->active_sel, this->editable);
1146 if (this->active_sel !=
nullptr && this->editable) {
1174 this->avail_sel =
nullptr;
1175 this->avail_pos = -1;
1180 void OnDropdownSelect(
WidgetID widget,
int index)
override
1183 if (!this->editable)
return;
1186 this->preset = index;
1196 this->active_sel =
nullptr;
1200 void OnQueryTextFinished(
char *str)
override
1202 if (str ==
nullptr)
return;
1208 for (uint i = 0; i < this->grf_presets.size(); i++) {
1209 if (this->grf_presets[i] == str) {
1225 for (
const GRFConfig *c = this->actives; c !=
nullptr; c = c->
next, i++) {}
1229 if (this->avail_pos >= 0) this->vscroll2->
ScrollTowards(this->avail_pos);
1237 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
1239 if (!gui_scope)
return;
1247 for (
GRFConfig **l = &this->actives; *l !=
nullptr; l = &(*l)->
next) {
1256 (*l)->next = c->
next;
1258 if (this->active_sel == c) this->active_sel = *l;
1267 this->modified =
false;
1279 this->modified =
true;
1285 this->modified =
false;
1289 this->BuildAvailables();
1299 bool disable_all = this->active_sel ==
nullptr || !this->
editable;
1306 const GRFConfig *selected_config = (this->avail_sel ==
nullptr) ? this->active_sel : this->avail_sel;
1307 for (
TextfileType tft = TFT_CONTENT_BEGIN; tft < TFT_CONTENT_END; tft++) {
1325 bool has_missing =
false;
1326 bool has_compatible =
false;
1327 for (
const GRFConfig *c = this->actives; !has_missing && c !=
nullptr; c = c->
next) {
1331 uint32_t widget_data;
1333 if (has_missing || has_compatible) {
1334 widget_data = STR_NEWGRF_SETTINGS_FIND_MISSING_CONTENT_BUTTON;
1335 tool_tip = STR_NEWGRF_SETTINGS_FIND_MISSING_CONTENT_TOOLTIP;
1337 widget_data = STR_INTRO_ONLINE_CONTENT;
1338 tool_tip = STR_INTRO_TOOLTIP_ONLINE_CONTENT;
1348 EventState OnKeyPress([[maybe_unused]] char32_t key, uint16_t keycode)
override
1354 if (this->avail_pos >= 0) {
1355 this->active_sel =
nullptr;
1358 this->avail_sel = this->avails[this->
avail_pos];
1366 void OnEditboxChanged(
WidgetID widget)
override
1368 if (!this->editable)
return;
1380 if (!this->editable)
return;
1383 if (this->active_sel !=
nullptr) {
1387 for (from_prev = &this->actives; *from_prev != this->
active_sel; from_prev = &(*from_prev)->
next, from_pos++) {}
1391 if (to_pos != from_pos) {
1394 for (
int i = from_pos < to_pos ? -1 : 0; *to_prev !=
nullptr && i < to_pos; to_prev = &(*to_prev)->
next, i++) {}
1397 *from_prev = this->active_sel->
next;
1400 this->active_sel->
next = *to_prev;
1407 }
else if (this->avail_sel !=
nullptr) {
1413 Point dummy = {-1, -1};
1419 if (this->active_over != -1) {
1422 this->active_over = -1;
1428 if (!this->editable)
return;
1430 if (widget ==
WID_NS_FILE_LIST && (this->active_sel !=
nullptr || this->avail_sel !=
nullptr)) {
1434 to_pos = std::min(to_pos, this->vscroll->
GetCount() - (this->active_sel !=
nullptr ? 2 : 1));
1436 if (to_pos != this->active_over) {
1437 this->active_over = to_pos;
1441 this->active_over = -2;
1443 }
else if (this->active_over != -1) {
1445 this->active_over = -1;
1454 if (i != 0)
return i < 0;
1457 if (i != 0)
return i < 0;
1466 filter.
AddLine((*a)->GetName());
1467 filter.
AddLine((*a)->filename);
1468 filter.
AddLine((*a)->GetDescription());
1472 void BuildAvailables()
1476 this->avails.clear();
1481 if (found)
continue;
1484 this->avails.push_back(c);
1488 assert(best !=
nullptr);
1498 this->avails.push_back(c);
1503 this->avails.
Filter(this->string_filter);
1504 this->avails.shrink_to_fit();
1506 this->avails.
Sort();
1508 if (this->avail_sel !=
nullptr) {
1509 this->avail_pos =
find_index(this->avails, this->avail_sel);
1510 if (this->avail_pos == -1) {
1511 this->avail_sel =
nullptr;
1515 this->vscroll2->
SetCount(this->avails.size());
1525 if (this->avail_sel ==
nullptr || !this->editable ||
HasBit(this->avail_sel->
flags,
GCF_INVALID))
return false;
1533 for (list = &this->actives; *list !=
nullptr; list = &(*list)->
next, ins_pos--) {
1534 if (ins_pos == 0) entry = list;
1535 if ((*list)->ident.grfid == this->avail_sel->ident.grfid) {
1541 if (entry ==
nullptr) entry = list;
1555 int new_pos = this->avail_pos + 1;
1556 if (new_pos >= (
int)this->avails.size()) new_pos = this->avail_pos - 1;
1557 this->avail_pos = new_pos;
1558 if (new_pos >= 0) this->avail_sel = this->avails[new_pos];
1574 for (
const GRFConfig *c = list; c !=
nullptr; c = c->
next) {
1610 std::unique_ptr<NWidgetBase>
avs;
1611 std::unique_ptr<NWidgetBase>
acs;
1612 std::unique_ptr<NWidgetBase>
inf;
1630 this->avs->SetupSmallestSize(w);
1631 this->acs->SetupSmallestSize(w);
1632 this->inf->SetupSmallestSize(w);
1634 uint min_avs_width = this->avs->smallest_x + this->avs->padding.Horizontal();
1635 uint min_acs_width = this->acs->smallest_x + this->acs->padding.Horizontal();
1636 uint min_inf_width = this->inf->smallest_x + this->inf->padding.Horizontal();
1638 uint min_avs_height = this->avs->smallest_y + this->avs->padding.Vertical();
1639 uint min_acs_height = this->acs->smallest_y + this->acs->padding.Vertical();
1640 uint min_inf_height = this->inf->smallest_y + this->inf->padding.Vertical();
1647 this->
fill_x = std::lcm(this->avs->fill_x, this->acs->fill_x);
1648 if (this->inf->fill_x > 0 && (this->fill_x == 0 || this->fill_x > this->inf->fill_x)) this->
fill_x = this->inf->fill_x;
1650 this->
fill_y = this->avs->fill_y;
1651 if (this->acs->fill_y > 0 && (this->fill_y == 0 || this->fill_y > this->acs->fill_y)) this->
fill_y = this->acs->fill_y;
1652 this->
fill_y = std::lcm(this->
fill_y, this->inf->fill_y);
1655 this->
resize_x = std::lcm(this->avs->resize_x, this->acs->resize_x);
1656 if (this->inf->resize_x > 0 && (this->resize_x == 0 || this->resize_x > this->inf->resize_x)) this->
resize_x = this->inf->resize_x;
1658 this->
resize_y = this->avs->resize_y;
1659 if (this->acs->resize_y > 0 && (this->resize_y == 0 || this->resize_y > this->acs->resize_y)) this->
resize_y = this->acs->resize_y;
1670 uint min_avs_width = this->avs->smallest_x + this->avs->padding.Horizontal();
1671 uint min_acs_width = this->acs->smallest_x + this->acs->padding.Horizontal();
1672 uint min_inf_width = this->inf->smallest_x + this->inf->padding.Horizontal();
1674 uint min_list_width = std::max(min_avs_width, min_acs_width);
1675 uint avs_extra_width = min_list_width - min_avs_width;
1676 uint acs_extra_width = min_list_width - min_acs_width;
1684 uint extra_width, inf_width;
1685 if (use_three_columns) {
1686 extra_width = given_width - min_three_columns;
1689 extra_width = given_width - min_two_columns;
1692 inf_width =
ComputeMaxSize(this->inf->smallest_x, this->inf->smallest_x + inf_width, this->inf->GetHorizontalStepSize(sizing));
1693 extra_width -= inf_width - this->inf->smallest_x;
1695 uint inf_height =
ComputeMaxSize(this->inf->smallest_y, given_height, this->inf->GetVerticalStepSize(sizing));
1697 if (use_three_columns) {
1700 uint avs_width = std::min(avs_extra_width, extra_width);
1701 extra_width -= avs_width;
1702 extra_width -= std::min(acs_extra_width, extra_width);
1703 avs_width += extra_width / 2;
1705 avs_width =
ComputeMaxSize(this->avs->smallest_x, this->avs->smallest_x + avs_width, this->avs->GetHorizontalStepSize(sizing));
1707 uint acs_width = given_width -
1708 inf_width - this->inf->padding.Horizontal() -
1710 acs_width =
ComputeMaxSize(min_acs_width, acs_width, this->acs->GetHorizontalStepSize(sizing)) -
1711 this->acs->padding.Horizontal();
1714 uint avs_height =
ComputeMaxSize(this->avs->smallest_y, given_height, this->avs->resize_y);
1715 uint acs_height =
ComputeMaxSize(this->acs->smallest_y, given_height, this->acs->resize_y);
1719 x += this->inf->padding.left;
1720 this->inf->AssignSizePosition(sizing, x, y + this->inf->padding.top, inf_width, inf_height, rtl);
1723 x += this->avs->padding.left;
1724 this->avs->AssignSizePosition(sizing, x, y + this->avs->padding.top, avs_width, avs_height, rtl);
1728 x += this->acs->padding.left;
1729 this->acs->AssignSizePosition(sizing, x, y + this->acs->padding.top, acs_width, acs_height, rtl);
1733 x += this->avs->padding.left;
1734 this->avs->AssignSizePosition(sizing, x, y + this->avs->padding.top, avs_width, avs_height, rtl);
1736 x += this->inf->padding.left;
1737 this->inf->AssignSizePosition(sizing, x, y + this->inf->padding.top, inf_width, inf_height, rtl);
1742 uint avs_width =
ComputeMaxSize(this->avs->smallest_x, this->avs->smallest_x + avs_extra_width + extra_width,
1743 this->avs->GetHorizontalStepSize(sizing));
1744 uint acs_width =
ComputeMaxSize(this->acs->smallest_x, this->acs->smallest_x + acs_extra_width + extra_width,
1745 this->acs->GetHorizontalStepSize(sizing));
1748 uint min_acs_height = this->acs->smallest_y + this->acs->padding.Vertical();
1749 uint extra_height = given_height - min_acs_height - min_avs_height;
1752 uint avs_height =
ComputeMaxSize(this->avs->smallest_y, this->avs->smallest_y + extra_height / 2, this->avs->resize_y);
1753 if (this->editable) extra_height -= avs_height - this->avs->smallest_y;
1754 uint acs_height =
ComputeMaxSize(this->acs->smallest_y, this->acs->smallest_y + extra_height, this->acs->resize_y);
1758 x += this->inf->padding.left;
1759 this->inf->AssignSizePosition(sizing, x, y + this->inf->padding.top, inf_width, inf_height, rtl);
1762 this->acs->AssignSizePosition(sizing, x + this->acs->padding.left, y + this->acs->padding.top, acs_width, acs_height, rtl);
1763 if (this->editable) {
1764 this->avs->AssignSizePosition(sizing, x + this->avs->padding.left, y + given_height - avs_height - this->avs->padding.bottom, avs_width, avs_height, rtl);
1766 this->avs->AssignSizePosition(sizing, 0, 0, this->avs->smallest_x, this->avs->smallest_y, rtl);
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);
1773 this->avs->AssignSizePosition(sizing, 0, 0, this->avs->smallest_x, this->avs->smallest_y, rtl);
1775 uint dx = this->acs->current_x + this->acs->padding.Horizontal();
1776 if (this->editable) {
1777 dx = std::max(dx, this->avs->current_x + this->avs->padding.Horizontal());
1780 this->inf->AssignSizePosition(sizing, x, y + this->inf->padding.top, inf_width, inf_height, rtl);
1787 this->avs->FillWidgetLookup(widget_lookup);
1788 this->acs->FillWidgetLookup(widget_lookup);
1789 this->inf->FillWidgetLookup(widget_lookup);
1804 if (this->editable) this->avs->Draw(w);
1813 static constexpr
NWidgetPart _nested_newgrf_actives_widgets[] = {
1821 SetDataTip(STR_JUST_STRING1, STR_NEWGRF_SETTINGS_PRESET_LIST_TOOLTIP),
1825 SetDataTip(STR_NEWGRF_SETTINGS_PRESET_SAVE, STR_NEWGRF_SETTINGS_PRESET_SAVE_TOOLTIP),
1827 SetDataTip(STR_NEWGRF_SETTINGS_PRESET_DELETE, STR_NEWGRF_SETTINGS_PRESET_DELETE_TOOLTIP),
1846 SetDataTip(STR_NEWGRF_SETTINGS_REMOVE, STR_NEWGRF_SETTINGS_REMOVE_TOOLTIP),
1849 SetDataTip(STR_NEWGRF_SETTINGS_MOVEUP, STR_NEWGRF_SETTINGS_MOVEUP_TOOLTIP),
1851 SetDataTip(STR_NEWGRF_SETTINGS_MOVEDOWN, STR_NEWGRF_SETTINGS_MOVEDOWN_TOOLTIP),
1854 SetDataTip(STR_NEWGRF_SETTINGS_UPGRADE, STR_NEWGRF_SETTINGS_UPGRADE_TOOLTIP),
1859 SetDataTip(STR_NEWGRF_SETTINGS_RESCAN_FILES, STR_NEWGRF_SETTINGS_RESCAN_FILES_TOOLTIP),
1861 SetDataTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
1868 static constexpr
NWidgetPart _nested_newgrf_availables_widgets[] = {
1874 SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
1890 SetDataTip(STR_NEWGRF_SETTINGS_ADD, STR_NEWGRF_SETTINGS_ADD_FILE_TOOLTIP),
1893 SetDataTip(STR_NEWGRF_SETTINGS_RESCAN_FILES, STR_NEWGRF_SETTINGS_RESCAN_FILES_TOOLTIP),
1895 SetDataTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
1901 static constexpr
NWidgetPart _nested_newgrf_infopanel_widgets[] = {
1913 SetDataTip(STR_CONTENT_OPEN_URL, STR_CONTENT_OPEN_URL_TOOLTIP),
1915 SetDataTip(STR_TEXTFILE_VIEW_README, STR_TEXTFILE_VIEW_README_TOOLTIP),
1919 SetDataTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_TEXTFILE_VIEW_CHANGELOG_TOOLTIP),
1921 SetDataTip(STR_TEXTFILE_VIEW_LICENCE, STR_TEXTFILE_VIEW_LICENCE_TOOLTIP),
1930 SetDataTip(STR_NEWGRF_SETTINGS_SET_PARAMETERS, STR_NULL),
1932 SetDataTip(STR_NEWGRF_SETTINGS_TOGGLE_PALETTE, STR_NEWGRF_SETTINGS_TOGGLE_PALETTE_TOOLTIP),
1935 SetDataTip(STR_NEWGRF_SETTINGS_APPLY_CHANGES, STR_NULL),
1938 SetDataTip(STR_NEWGRF_SETTINGS_SHOW_PARAMETERS, STR_NULL),
1946 std::unique_ptr<NWidgetBase> avs =
MakeNWidgets(std::begin(_nested_newgrf_availables_widgets), std::end(_nested_newgrf_availables_widgets),
nullptr);
1947 std::unique_ptr<NWidgetBase> acs =
MakeNWidgets(std::begin(_nested_newgrf_actives_widgets), std::end(_nested_newgrf_actives_widgets),
nullptr);
1948 std::unique_ptr<NWidgetBase> inf =
MakeNWidgets(std::begin(_nested_newgrf_infopanel_widgets), std::end(_nested_newgrf_infopanel_widgets),
nullptr);
1950 return std::make_unique<NWidgetNewGRFDisplay>(std::move(avs), std::move(acs), std::move(inf));
1954 static constexpr
NWidgetPart _nested_newgrf_widgets[] = {
1971 static WindowDesc _newgrf_desc(__FILE__, __LINE__,
1975 std::begin(_nested_newgrf_widgets), std::end(_nested_newgrf_widgets)
2001 for (c = nw->
actives; c !=
nullptr && i > 0; c = c->
next, i--) {}
2026 new NewGRFWindow(&_newgrf_desc, editable, show_params, exec_changes, config);
2044 NWidget(
WWT_EDITBOX, COLOUR_GREY,
WID_SVP_EDITBOX),
SetPadding(2, 2, 2, 2),
SetFill(1, 0),
SetResize(1, 0),
2045 SetDataTip(STR_SAVE_PRESET_TITLE, STR_SAVE_PRESET_EDITBOX_TOOLTIP),
2076 this->selected = -1;
2077 if (initial_text !=
nullptr) {
2078 for (uint i = 0; i < this->presets.size(); i++) {
2079 if (this->presets[i] == initial_text) {
2094 this->vscroll->
SetCount(this->presets.size());
2096 if (initial_text !=
nullptr) this->presetname_editbox.text.
Assign(initial_text);
2109 for (uint i = 0; i < this->presets.size(); i++) {
2111 size->width = std::max(size->width, d.width + padding.width);
2114 size->height =
ClampU((uint)this->presets.size(), 5, 20) *
resize->height + padding.height;
2120 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
2131 uint max_index = std::min(min_index + this->vscroll->
GetCapacity(), (uint)this->presets.size());
2133 for (uint i = min_index; i < max_index; i++) {
2136 DrawString(tr.left, tr.right, tr.top + offset_y, this->presets[i], ((
int)i == this->selected) ? TC_WHITE : TC_SILVER);
2137 tr.top += step_height;
2144 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
2149 if (it != this->presets.end()) {
2150 this->selected = it - this->presets.begin();
2151 this->presetname_editbox.text.
Assign(*it);
2241 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
2272 if (name ==
nullptr) {
2273 this->last_name =
GetString(STR_NEWGRF_SCAN_ARCHIVES);
2275 this->last_name = name;
2277 this->scanned = num;
@ ES_HANDLED
The passed event is handled.
GRFParameterInfo & GetParameterInfo(uint nr) const
Get GRF Parameter Info exists for a given parameter index.
@ GRFP_USE_MASK
Bitmask to get only the use palette use states.
bool AddGRFToActive(int ins_pos=-1)
Insert a GRF into the active list.
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
static const uint8_t PC_DARK_BLUE
Dark blue palette colour.
std::string FormatArrayAsHex(std::span< const byte > data)
Format a byte array into a continuous hex string.
std::string name
Name of the content.
StringFilter string_filter
Filter for available grf.
int ok_button
Widget button of parent window to simulate when pressing OK in OSK.
ContentType type
Type of content.
@ GOID_NEWGRF_CHANGES_MADE
Changes have been made to a given NewGRF either through the palette or its parameters.
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
void ReloadNewGRFData()
Reload all NewGRF files during a running game.
void ShowQuery(StringID caption, StringID message, Window *parent, QueryCallbackProc *callback, bool focus)
Show a confirmation window with standard 'yes' and 'no' buttons The window is aligned to the centre o...
Window for showing the progress of NewGRF scanning.
bool newgrf_developer_tools
activate NewGRF developer tools and allow modifying NewGRFs in an existing game
uint8_t num_valid_params
NOSAVE: Number of valid parameters (action 0x14)
void SetDParamMaxDigits(size_t n, uint count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
void OnNewGRFsScanned() override
Called whenever the NewGRF scan completed.
Dimensions (a width and height) of a rectangle in 2D.
constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
@ GCS_ACTIVATED
GRF file has been activated.
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
void SetFilterState(bool state)
Enable or disable the filter.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
void ClearGRFConfigList(GRFConfig **config)
Clear a GRF Config list, freeing all nodes.
bool IsEmpty() const
Check whether any filter words were entered.
@ DOES_NOT_EXIST
The content does not exist in the content system.
void SetFilterTerm(const char *str)
Set the term to filter on.
Class for the save preset window.
Gamelog _gamelog
Gamelog instance.
void UpdateNewGRFScanStatus(uint num, const char *name)
Update the NewGRF scan status.
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
static void ShowSavePresetWindow(const char *initial_text)
Open the window for saving a preset.
uint32_t GetValue(struct GRFConfig *config) const
Get the value of this user-changeable parameter from the given config.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
void Assign(StringID string)
Render a string into the textbuffer.
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
GRFConfig * _all_grfs
First item in list of all scanned NewGRFs.
void ShowNetworkContentListWindow(ContentVector *cv=nullptr, ContentType type1=CONTENT_TYPE_END, ContentType type2=CONTENT_TYPE_END)
Show the content list window with a given set of content.
Window for showing NewGRF files.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
@ CONTENT_TYPE_NEWGRF
The content consists of a NewGRF.
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
std::vector< ContentInfo * > ContentVector
Vector with content info.
void ShowMissingContentWindow(const GRFConfig *list)
Show the content list window with all missing grfs from the given list.
SavePresetWindow(const char *initial_text)
Constructor of the save preset window.
std::string filename
Filename - either with or without full path.
byte param_nr
GRF parameter to store content in.
static GUIGRFConfigList::FilterFunction *const filter_funcs[]
Filter functions of the #GUIGRFConfigList.
bool modified
The list of active NewGRFs has been modified since the last time they got saved.
GRFConfig * actives
Temporary active grf list to which changes are made.
bool RequestNewGRFScan(NewGRFScanCallback *callback)
Request a new NewGRF scan.
int StrNaturalCompare(std::string_view s1, std::string_view s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
@ GCS_NOT_FOUND
GRF file was not found in the local cache.
ScanProgressWindow()
Create the window.
static GUIGRFConfigList::SortFunction *const sorter_funcs[]
Sort functions of the #GUIGRFConfigList.
GRFIdentifier ident
grfid and md5sum to uniquely identify newgrfs
ClientSettings _settings_client
The current settings for this game.
bool editable
Allow editing parameters.
GRFStatus status
NOSAVE: GRFStatus, enum.
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
@ GRFP_GRF_UNSET
The NewGRF provided no information.
constexpr uint ClampU(const uint a, const uint min, const uint max)
Clamp an unsigned integer between an interval.
void AddLine(const char *str)
Pass another text line from the current item to the filter.
bool execute
On pressing 'apply changes' are grf changes applied immediately, or only list is updated.
@ FR_LOWERED
If set the frame is lowered and the background colour brighter (ie. buttons when pressed)
std::unique_ptr< NWidgetBase > NewGRFDisplay()
Construct nested container widget for managing the lists and the info panel of the NewGRF GUI.
uint32_t min_loadable_version
NOSAVE: Minimum compatible version a NewGRF can define.
static bool NameSorter(const GRFConfig *const &a, const GRFConfig *const &b)
Sort grfs by name.
static WindowDesc _newgrf_parameters_desc(__FILE__, __LINE__, WDP_CENTER, "settings_newgrf_config", 500, 208, WC_GRF_PARAMETERS, WC_NONE, 0, std::begin(_nested_newgrf_parameter_widgets), std::end(_nested_newgrf_parameter_widgets))
Window definition for the change grf parameters window.
int preset
Selected preset or -1 if none selected.
GRFParameterType type
The type of this parameter.
bool clicked_dropdown
Whether the dropdown is open.
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
MD5Hash md5sum
The MD5 checksum.
bool StrEmpty(const char *s)
Check if a string buffer is empty.
uint32_t PaletteID
The number of the palette.
TextfileType file_type
Type of textfile to view.
@ TFT_CHANGELOG
Content changelog.
@ WN_GAME_OPTIONS_NEWGRF_STATE
NewGRF settings.
GRFConfig * active_sel
Selected active grf item.
uint32_t min_value
The minimal value this parameter can have.
bool NeedRebuild() const
Check if a rebuild is needed.
Data stored about a string that can be modified in the GUI.
@ WC_GRF_PARAMETERS
NewGRF parameters; Window numbers:
int active_over
Active GRF item over which another one is dragged, -1 if none.
@ WC_SAVE_PRESET
Save preset; Window numbers:
@ GCF_COMPATIBLE
GRF file does not exactly match the requested GRF (different MD5SUM), but grfid matches)
char *const buf
buffer in which text is saved
@ GCF_INVALID
GRF is unusable with this version of OpenTTD.
void OnPaint() override
The window must be repainted.
int find_index(Container const &container, typename Container::const_reference item)
Helper function to get the index of an item Consider using std::set, std::unordered_set or std::flat_...
bool clicked_increase
True if the increase button was clicked, false for the decrease button.
int selected
Selected entry in the preset list, or -1 if none selected.
High level window description.
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
void Reset()
Reset the timer, so it will fire again after the timeout.
std::optional< std::string > GetTextfile(TextfileType type) const
Search a textfile file next to this NewGRF.
@ WC_MODAL_PROGRESS
Progress report of landscape generation; Window numbers:
int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
bool HasParameterInfo(uint nr) const
Test if GRF Parameter Info exists for a given parameter index.
static const uint NETWORK_MAX_GRF_COUNT
Maximum number of GRFs that can be sent.
static WindowDesc _save_preset_desc(__FILE__, __LINE__, WDP_CENTER, "save_preset", 140, 110, WC_SAVE_PRESET, WC_GAME_OPTIONS, WDF_MODAL, std::begin(_nested_save_preset_widgets), std::end(_nested_save_preset_widgets))
Window description of the preset save window.
static constexpr NWidgetPart _nested_scan_progress_widgets[]
Widgets for the progress window.
StringList GetGRFPresetList()
Get the list of known NewGrf presets.
constexpr bool IsInsideBS(const T x, const size_t base, const size_t size)
Checks if a value is between a window started at some base point.
void SetValue(struct GRFConfig *config, uint32_t value)
Set the value of this user-changeable parameter in the given config.
@ WC_QUERY_STRING
Query string window; Window numbers:
uint32_t version
NOSAVE: Version a NewGRF can set so only the newest NewGRF is shown.
std::map< uint32_t, GRFTextList > value_names
Names for each value.
void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool clickable)
Draw a dropdown button.
Data structure describing how to show the list (what sort direction and criteria).
bool CanUpgradeCurrent()
Test whether the currently active set of NewGRFs can be upgraded with the available NewGRFs.
ResizeInfo resize
Resize information.
static uint32_t BSWAP32(uint32_t x)
Perform a 32 bits endianness bitswap on x.
@ GOID_NEWGRF_CURRENT_LOADED
The current list of active NewGRF has been loaded.
void UpdateNewGRFScanStatus(uint num, const char *name)
Update the NewGRF scan status.
void UpdateScrollBars()
Updates the scroll bars for the active and inactive NewGRF lists.
Information about GRF, used in the game and (part of it) in savegames.
static Listing last_sorting
Default sorting of #GUIGRFConfigList.
@ FS_NORMAL
Index of the normal font in the font tables.
Window for setting the parameters of a NewGRF.
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
static GRFParameterInfo & GetDummyParameterInfo(uint nr)
Get a dummy parameter-info object with default information.
bool Filter(FilterFunction *decide, F filter_data)
Filter the list.
void ReInitAllWindows(bool zoom_changed)
Re-initialize all windows.
@ GOID_NEWGRF_LIST_EDITED
List of active NewGRFs is being edited.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
void SetParameterDefaults()
Set the default value for all parameters as specified by action14.
std::conditional_t< std::is_same_v< P, std::nullptr_t >, bool(const T &, const T &), bool(const T &, const T &, const P)> SortFunction
Signature of sort function.
Container for all important information about a piece of content.
@ GRFP_USE_WINDOWS
The palette state is set to use the Windows palette.
static void FillGrfidMap(const GRFConfig *c, GrfIdMap *grfid_map)
Add all grf configs from c into the map.
MD5Hash md5sum
MD5 checksum of file to distinguish files with the same GRF ID (eg. newer version of GRF)
@ ES_NOT_HANDLED
The passed event is not handled.
GRFConfig ** CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src, bool init_only)
Copy a GRF Config list.
const char * GetGRFStringFromGRFText(const GRFTextList &text_list)
Get a C-string from a GRFText-list.
void ShowNewGRFError()
Show the first NewGRF error we can find.
Data structure describing what to show in the list (filter criteria).
Information about one grf parameter.
virtual void LoadTextfile(const std::string &textfile, Subdirectory dir)
Loads the textfile text from file and setup lines.
std::optional< GRFError > error
NOSAVE: Error/Warning during GRF loading (Action 0x0B)
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
std::vector< std::string > StringList
Type for a list of strings.
void UpgradeCurrent()
Upgrade the currently active set of NewGRFs.
@ GOID_NEWGRF_CHANGES_APPLIED
The active NewGRF list changes have been applied.
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
@ GRFP_BLT_32BPP
The NewGRF prefers a 32 bpp blitter.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
std::string last_name
The name of the last 'seen' NewGRF.
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
@ WDF_MODAL
The window is a modal child of some other window, meaning the parent is 'inactive'.
bool IsCompatible(uint32_t old_version) const
Return whether this NewGRF can replace an older version of the same NewGRF.
void DeleteGRFPresetFromConfig(const char *config_name)
Delete a NewGRF configuration by preset name.
Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion)
Calculate string bounding box for multi-line strings.
Coordinates of a point in 2D.
static void NewGRFConfirmationCallback(Window *w, bool confirmed)
Callback function for the newgrf 'apply changes' confirmation window.
const char * GetURL() const
Get the grf url.
int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
@ GRFP_GRF_MASK
Bitmask to get only the NewGRF supplied information.
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
TimeoutTimer< TimerWindow > unclick_timeout
When reset, unclick the button after a small timeout.
void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clickable_left, bool clickable_right)
Draw [<][>] boxes.
void GRFUpdate(const GRFConfig *oldg, const GRFConfig *newg)
Compares two NewGRF lists and logs any change.
void CopyParams(const GRFConfig &src)
Copy the parameter information from the src config.
bool SetFocusedWidget(WidgetID widget_index)
Set focus within this window to the given widget.
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.
@ TFT_README
Content readme.
GRFConfig ** orig_list
List active grfs in the game. Used as initial value, may be updated by the window.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
@ NEWGRF_DIR
Subdirectory for all NewGRFs.
static bool CDECL TagNameFilter(const GRFConfig *const *a, StringFilter &filter)
Filter grfs by tags/name.
QueryString presetname_editbox
Edit box of the save preset.
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
int scanned
The number of NewGRFs that we have seen.
uint8_t palette
GRFPalette, bitset.
@ SA_HOR_CENTER
Horizontally center the text.
std::vector< std::optional< GRFParameterInfo > > param_info
NOSAVE: extra information about the parameters.
GRFConfig * LoadGRFPresetFromConfig(const char *config_name)
Load a NewGRF configuration by preset-name.
@ HT_DRAG
dragging items in the depot windows
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
bool newgrf_show_old_versions
whether to show old versions in the NewGRF list
void ForceRebuild()
Force that a rebuild is needed.
@ TFT_LICENSE
Content license.
QueryString filter_editbox
Filter editbox;.
void StartAction(GamelogActionType at)
Stores information about new action, but doesn't allocate it Action is allocated only when there is a...
@ GCS_DISABLED
GRF file is disabled.
void StopAction()
Stops logging of any changes.
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
uint32_t max_value
The maximal value of this parameter.
@ WC_GAME_OPTIONS
Game options window; Window numbers:
int line_height
Height of a row in the matrix widget.
uint8_t flags
NOSAVE: GCF_Flags, bitset.
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
void OnResize() override
Called after the window got resized.
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, bool instant_close)
Show a drop down list.
const GRFConfig * avail_sel
Currently selected available grf. nullptr is none is selected.
std::array< uint32_t, 0x80 > param
GRF parameters.
GRFTextList desc
The description of this parameter.
bool closing_dropdown
True, if the dropdown list is currently closing.
void DisableWidget(WidgetID widget_index)
Sets a widget to disabled.
void CloseChildWindows(WindowClass wc=WC_INVALID) const
Close all children a window might have in a head-recursive manner.
void SetDParamMaxValue(size_t n, uint64_t max_value, uint min_count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
std::string GRFBuildParamList(const GRFConfig *c)
Build a string containing space separated parameter values, and terminate.
const char * GetDescription() const
Get the grf info.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
StringList grf_presets
List of known NewGRF presets.
@ GOID_NEWGRF_RESCANNED
NewGRFs were just rescanned.
void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config)
Setup the NewGRF gui.
struct GRFConfig * next
NOSAVE: Next item in the linked list.
virtual void OnQueryTextFinished([[maybe_unused]] char *str)
The query window opened from this window has closed.
void ResetState()
Reset the matching state to process a new item.
bool HasGrfIdentifier(uint32_t grfid, const MD5Hash *md5sum) const
Does the identification match the provided values?
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
EventState
State of handling an event.
@ FGCM_NEWEST
Find newest Grf.
@ FGCM_NEWEST_VALID
Find newest Grf, ignoring Grfs with GCF_INVALID set.
GRFTextList name
The name of this parameter.
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
static const uint8_t PC_GREY
Grey palette colour.
bool show_params
Are the grf-parameters shown in the info-panel?
bool GetState() const
Get the matching state of the current item.
bool action14present
True if action14 information is present.
void SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
std::map< uint32_t, const GRFConfig * > GrfIdMap
Map of grfid to the grf config.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
static const uint8_t PC_BLACK
Black palette colour.
@ WL_ERROR
Errors (eg. saving/loading failed)
static const int ACTION_CLEAR
Clear editbox.
int top
y position of top edge of the window
uint32_t last_newgrf_count
the numbers of NewGRFs we found during the last scan
static constexpr NWidgetPart _nested_save_preset_widgets[]
Widget parts of the save preset window.
bool complete_labels
True if all values have a label.
GRFConfig * _grfconfig
First item in list of current GRF set up.
State state
Whether the content info is selected (for download)
const GRFConfig * grf_config
View the textfile of this GRFConfig.
void SetFilterFuncs(FilterFunction *const *n_funcs)
Hand the array of filter function pointers to the sort list.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Callback for NewGRF scanning.
int width
width of the window (number of pixels to the right in x direction)
static WindowDesc _scan_progress_desc(__FILE__, __LINE__, WDP_CENTER, nullptr, 0, 0, WC_MODAL_PROGRESS, WC_NONE, 0, std::begin(_nested_scan_progress_widgets), std::end(_nested_scan_progress_widgets))
Description of the widgets and other settings of the window.
uint32_t grfid
GRF ID (defined by Action 0x08)
void SetSortFuncs(SortFunction *const *n_funcs)
Hand the array of sort function pointers to the sort list.
void RebuildDone()
Notify the sortlist that the rebuild is done.
@ WC_BUILD_OBJECT
Build object; Window numbers:
bool CDECL FilterFunction(const const GRFConfig * *, StringFilter &)
Signature of filter function.
uint8_t num_params
Number of used parameters.
static Filtering last_filtering
Default filtering of #GUIGRFConfigList.
bool editable
Is the window editable?
@ PTYPE_BOOL
The parameter is either 0 or 1.
MD5Hash original_md5sum
MD5 checksum of original file if only a 'compatible' file was loaded.
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
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...
void OnDropdownClose(Point, WidgetID widget, int, bool) override
A dropdown window associated to this window has been closed.
bool scenario_developer
activate scenario developer: allow modifying NewGRFs in an existing game
Window for displaying a textfile.
GRFConfig * grf_config
Set the parameters of this GRFConfig.
static const CursorID SPR_CURSOR_MOUSE
Cursor sprite numbers.
@ PTYPE_UINT_ENUM
The parameter allows a range of numbers, each of which can have a special name.
Data structure for an opened window.
TextfileType
Additional text files accompanying Tar archives.
void ResetGRFConfig(bool defaults)
Reset the current GRF Config to either blank or newgame settings.
void DrawWidgets() const
Paint all widgets of a window.
@ FGCM_EXACT
Only find Grfs matching md5sum.
static const uint8_t PC_DARK_GREY
Dark grey palette colour.
void DrawBoolButton(int x, int y, bool state, bool clickable)
Draw a toggle button.
bool _network_available
is network mode available?
int Width() const
Get width of Rect.
Window for displaying the textfile of a NewGRF.
Dimension GetScaledSpriteSize(SpriteID sprid)
Scale sprite size for GUI.
uint clicked_button
The row in which a button was clicked or UINT_MAX.
PaletteID GetPalette(const GRFConfig *c) const
Pick the palette for the sprite of the grf to display.
Specification of a rectangle with absolute coordinates of all edges.
@ WC_DROPDOWN_MENU
Drop down menu; Window numbers:
bool Sort(Comp compare)
Sort the list.
void OnResize() override
Called after the window got resized.
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
const GRFConfig * FindGRFConfig(uint32_t grfid, FindGRFConfigMode mode, const MD5Hash *md5sum, uint32_t desired_version)
Find a NewGRF in the scanned list.
int avail_pos
Index of avail_sel if existing, else -1.
@ WC_TEXTFILE
textfile; Window numbers:
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
void SaveGRFPresetToConfig(const char *config_name, GRFConfig *config)
Save a NewGRF configuration with a preset name.
Scrollbar * vscroll
Pointer to the scrollbar widget.
@ WDP_CENTER
Center the window.
#define SETTING_BUTTON_HEIGHT
Height of setting buttons.
void SetFiltering(Filtering f)
Import filter conditions.
@ TD_RTL
Text is written right-to-left by default.
TextDirection _current_text_dir
Text direction of the currently selected language.
@ CS_NUMERAL
Only numeric ones.
uint32_t unique_id
Unique ID; either GRF ID or shortname.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
StringList presets
Available presets.
uint clicked_row
The selected parameter.
void OnResize() override
Called after the window got resized.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
@ GCF_STATIC
GRF file is used statically (can be used in any MP game)
GUISettings gui
settings related to the GUI
@ WL_CRITICAL
Critical errors, the MessageBox is shown in all cases.
@ FR_BORDERONLY
Draw border only, no background.
void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, WidgetID button, Rect wi_rect, Colours wi_colour, bool instant_close)
Show a drop down list.
const char * GetName() const
Get the name of this grf.
void SetListing(Listing l)
Import sort conditions.
GUIGRFConfigList avails
Available (non-active) grfs.
static GRFParameterInfo dummy_parameter_info
Dummy info in case a newgrf didn't provide info about some parameter.
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.