40#include "table/strings.h"
50 if (_game_mode == GM_MENU)
return;
54 if (c->errors.empty())
continue;
56 const GRFError &error = c->errors.back();
57 if (error.
severity != STR_NEWGRF_ERROR_MSG_FATAL && error.
severity != STR_NEWGRF_ERROR_MSG_ERROR)
continue;
59 std::vector<StringParameter> params;
60 params.emplace_back(c->GetName());
61 params.emplace_back(error.
message != STR_NULL ? error.
message : STR_JUST_RAW_STRING);
63 params.emplace_back(c->filename);
64 params.emplace_back(error.
data);
65 for (
const uint32_t &value : error.
param_value) params.emplace_back(value);
67 if (error.
severity == STR_NEWGRF_ERROR_MSG_FATAL) {
76static StringID GetGRFPaletteString(uint8_t palette)
79 return (palette &
GRFP_USE_WINDOWS) ? STR_NEWGRF_SETTINGS_PALETTE_LEGACY_32BPP : STR_NEWGRF_SETTINGS_PALETTE_DEFAULT_32BPP;
81 return (palette &
GRFP_USE_WINDOWS) ? STR_NEWGRF_SETTINGS_PALETTE_LEGACY : STR_NEWGRF_SETTINGS_PALETTE_DEFAULT;
84static void ShowNewGRFInfo(
const GRFConfig &c,
const Rect &r,
bool show_params)
87 for (
const GRFError &error : c.errors) {
88 std::array<
StringParameter, 3 + std::tuple_size_v<
decltype(error.param_value)>> params{};
89 auto it = params.begin();
90 *it++ = error.custom_message;
93 for (
const uint32_t &value : error.param_value) *it++ = value;
118 if (!c.
param.empty()) {
135 if (
auto desc = c.
GetDescription(); desc.has_value() && !desc->empty()) {
162 this->action14present = (this->grf_config.
num_valid_params != GRFConfig::MAX_NUM_PARAMS || !this->grf_config.
param_info.empty());
165 this->GetWidget<NWidgetCore>(
WID_NP_CAPTION)->SetStringTip(is_baseset ? STR_BASEGRF_PARAMETERS_CAPTION : STR_NEWGRF_PARAMETERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS);
220 d.width += padding.width;
221 d.height += padding.height;
237 for (
const auto &par_info : this->grf_config.
param_info) {
238 if (!par_info.has_value())
continue;
240 if (!desc.has_value())
continue;
243 suggestion =
maxdim(d, suggestion);
245 size.height = suggestion.height;
261 std::pair<StringParameter, StringParameter> GetValueParams(
const GRFParameterInfo &par_info, uint32_t value)
const
263 if (par_info.
type ==
PTYPE_BOOL)
return {value != 0 ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF, {}};
265 auto it = std::ranges::lower_bound(par_info.
value_names, value, std::less{}, &GRFParameterInfo::ValueName::first);
266 if (it != std::end(par_info.
value_names) && it->first == value) {
270 return {STR_JUST_INT, value};
273 std::string GetSettingString(
const GRFParameterInfo &par_info,
int i, uint32_t value)
const
275 auto [param1, param2] = this->GetValueParams(par_info, value);
277 return name.has_value()
278 ?
GetString(STR_NEWGRF_PARAMETERS_SETTING, STR_JUST_RAW_STRING, std::string(*name), param1, param2)
279 :
GetString(STR_NEWGRF_PARAMETERS_SETTING, STR_NEWGRF_PARAMETERS_DEFAULT_NAME, i + 1, param1, param2);
288 if (!desc.has_value())
return;
304 uint32_t current_value = this->grf_config.
GetValue(par_info);
308 DrawBoolButton(buttons_left, ir.top + button_y_offset, COLOUR_YELLOW, COLOUR_MAUVE, current_value != 0, this->editable);
311 DrawDropDownButton(buttons_left, ir.top + button_y_offset, COLOUR_YELLOW, this->clicked_row == i && this->clicked_dropdown, this->editable);
313 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);
317 DrawString(tr.left, tr.right, ir.top + text_y_offset, this->GetSettingString(par_info, i, current_value), selected ? TC_WHITE : TC_LIGHT_BLUE);
324 if (this->closing_dropdown) {
325 this->closing_dropdown =
false;
326 this->clicked_dropdown =
false;
335 if (this->editable && !this->action14present && !this->grf_config.
param.empty()) {
336 this->grf_config.
param.pop_back();
343 if (this->editable && !this->action14present && this->grf_config.
param.size() < this->grf_config.num_valid_params) {
344 this->grf_config.
param.emplace_back(0);
351 if (!this->editable)
break;
353 if (num >= this->vscroll->
GetCount())
break;
355 if (this->clicked_row != num) {
358 this->clicked_row = num;
359 this->clicked_dropdown =
false;
363 int x = pt.x - r.left;
369 uint32_t old_val = this->grf_config.
GetValue(par_info);
371 if (this->clicked_dropdown) {
374 this->clicked_dropdown =
false;
375 this->closing_dropdown =
false;
377 int rel_y = (pt.y - r.top) % this->line_height;
386 if (pt.y >= wi_rect.top && pt.y <= wi_rect.bottom) {
387 this->clicked_dropdown =
true;
388 this->closing_dropdown =
false;
391 for (
const auto &[value, name] : par_info.
value_names) {
393 assert(text.has_value());
394 list.push_back(MakeDropDownListStringItem(
GetString(STR_JUST_RAW_STRING, std::string(*text)), value));
401 uint32_t val = old_val;
408 this->clicked_increase =
true;
412 this->clicked_increase =
false;
415 if (val != old_val) {
416 this->grf_config.
SetValue(par_info, val);
418 this->clicked_button = num;
430 if (!this->editable)
break;
440 if (!str.has_value() || str->empty())
return;
441 auto value = ParseInteger<int32_t>(*str, 10,
true);
442 if (!value.has_value())
return;
444 this->grf_config.
SetValue(par_info, *value);
451 assert(this->clicked_dropdown);
453 this->grf_config.
SetValue(par_info, index);
464 assert(this->clicked_dropdown);
465 this->closing_dropdown =
true;
479 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
481 if (!gui_scope)
return;
482 if (!this->action14present) {
488 if (this->clicked_row != INT32_MAX && this->clicked_row >= this->vscroll->
GetCount()) {
489 this->clicked_row = INT32_MAX;
496 this->clicked_button = INT32_MAX;
503static constexpr NWidgetPart _nested_newgrf_parameter_widgets[] = {
514 NWidget(
WWT_TEXT, INVALID_COLOUR,
WID_NP_NUMPAR),
SetResize(1, 0),
SetFill(1, 0),
SetPadding(0, 0, 0, 4),
519 NWidget(
WWT_MATRIX, COLOUR_MAUVE,
WID_NP_BACKGROUND),
SetMinimalSize(188, 182),
SetResize(1, 1),
SetFill(1, 0),
SetMatrixDataTip(1, 0),
SetScrollbar(
WID_NP_SCROLLBAR),
536 WDP_CENTER,
"settings_newgrf_config", 500, 208,
539 _nested_newgrf_parameter_widgets
542void OpenGRFParameterWindow(
bool is_baseset,
GRFConfig &c,
bool editable)
554 this->ConstructWindow();
563 return GetString(stringid, STR_CONTENT_TYPE_NEWGRF, this->grf_config->
GetName());
576typedef std::map<uint32_t, const GRFConfig *>
GrfIdMap;
585 for (
const auto &c : lst) {
599 static const uint EDITBOX_MAX_SIZE = 50;
603 static const std::initializer_list<GUIGRFConfigList::SortFunction * const>
sorter_funcs;
604 static const std::initializer_list<GUIGRFConfigList::FilterFunction * const>
filter_funcs;
641 this->GetWidget<NWidgetStacked>(
WID_NS_SHOW_REMOVE)->SetDisplayedPlane(this->editable ? 0 : 1);
663 void Close([[maybe_unused]]
int data = 0)
override
668 if (this->editable && this->modified && !this->execute && !_exit_game) {
677 int GetCurrentActivePosition()
const
679 if (this->active_sel !=
nullptr) {
680 auto it = std::ranges::find_if(this->
actives, [
this](
const auto &c) {
return c.get() == this->active_sel; });
681 if (it != std::end(this->
actives))
return static_cast<int>(std::distance(std::begin(this->
actives), it));
696 GrfIdMap::const_iterator iter = grfid_map.find(a->ident.grfid);
697 if (iter != grfid_map.end() && a->version > iter->second->version)
return true;
709 GrfIdMap::iterator iter = grfid_map.find(a->ident.grfid);
710 if (iter == grfid_map.end() || iter->second->version >= a->version)
continue;
712 auto c = std::ranges::find_if(this->
actives, [&iter](
const auto &grfconfig) {
return grfconfig.get() == iter->second; });
713 assert(c != std::end(this->
actives));
714 auto d = std::make_unique<GRFConfig>(*a);
715 if (d->IsCompatible((*c)->version)) {
718 d->SetParameterDefaults();
720 if (this->active_sel == c->get()) {
723 this->active_sel =
nullptr;
726 iter->second = c->get();
737 size.height = std::max(size.height, padding.height + 6 *
resize.height);
745 size.height = std::max(size.height, padding.height + 8 *
resize.height);
765 d.width += padding.width;
774 size.width += padding.width;
775 size.height += padding.height;
791 if (this->preset == -1)
return GetString(STR_NUM_CUSTOM);
813 pal = PALETTE_TO_RED;
816 pal = PALETTE_TO_GREEN;
819 pal = PALETTE_TO_BLUE;
824 if (pal != PALETTE_TO_RED) {
826 pal = PALETTE_TO_GREY;
828 pal = PALETTE_TO_ORANGE;
843 uint step_height = this->GetWidget<NWidgetBase>(
WID_NS_FILE_LIST)->resize_y;
846 int square_offset_y = (step_height - square.height) / 2;
847 int warning_offset_y = (step_height - warning.height) / 2;
851 uint text_left = rtl ? tr.left : tr.left + square.width + 13;
852 uint text_right = rtl ? tr.right - square.width - 13 : tr.right;
853 uint square_left = rtl ? tr.right - square.width - 3 : tr.left + 3;
854 uint warning_left = rtl ? tr.right - square.width - warning.width - 8 : tr.left + square.width + 8;
857 for (
const auto &c : this->
actives) {
859 std::string text = c->
GetName();
860 bool h = (this->active_sel == c.get());
865 }
else if (i == this->active_over) {
867 int active_sel_pos = this->GetCurrentActivePosition();
868 if (active_sel_pos != this->active_over) {
869 uint
top = (active_sel_pos < 0 || this->active_over < active_sel_pos) ? tr.top + 1 : tr.top + step_height - 2;
873 DrawSprite(SPR_SQUARE, pal, square_left, tr.top + square_offset_y);
874 if (!c->
errors.empty())
DrawSprite(SPR_WARNING_SIGN, 0, warning_left, tr.top + warning_offset_y);
875 uint txtoffset = c->
errors.empty() ? 0 : warning.width;
876 DrawString(text_left + (rtl ? 0 : txtoffset), text_right - (rtl ? txtoffset : 0), tr.top + offset_y, std::move(text), h ? TC_WHITE : TC_ORANGE);
877 tr.top += step_height;
881 if (i == this->active_over && this->vscroll->
IsVisible(i)) {
896 for (
auto it = first; it != last; ++it) {
899 std::string text = c->
GetName();
902 DrawString(tr.left, tr.right, tr.top + offset_y, std::move(text), h ? TC_WHITE : TC_SILVER);
903 tr.top += step_height;
917 if (selected ==
nullptr) selected = this->
avail_sel;
918 if (selected !=
nullptr) {
919 ShowNewGRFInfo(*selected, r, this->show_params);
929 if (this->active_sel ==
nullptr && this->avail_sel ==
nullptr)
return;
940 list.push_back(MakeDropDownListStringItem(STR_NONE, -1));
942 for (uint i = 0; i < this->
grf_presets.size(); i++) {
943 list.push_back(MakeDropDownListStringItem(std::string{this->
grf_presets[i]}, i));
952 const GRFConfig *c = (this->avail_sel ==
nullptr) ? this->active_sel : this->
avail_sel;
954 if (url.has_value()) OpenBrowser(std::move(*url));
963 if (this->preset == -1)
return;
973 if (this->active_sel ==
nullptr || !this->editable)
break;
975 int pos = this->GetCurrentActivePosition();
987 if (this->active_sel ==
nullptr || !this->editable)
break;
989 int pos = this->GetCurrentActivePosition();
990 if (pos == -1 ||
static_cast<size_t>(pos) >= this->
actives.size() - 1)
break;
1005 if (i < this->
actives.size()) {
1006 this->active_sel = this->
actives[i].get();
1008 this->active_sel =
nullptr;
1010 if (this->active_sel != old_sel) {
1014 this->avail_sel =
nullptr;
1015 this->avail_pos = -1;
1018 if (click_count == 1) {
1027 if (this->active_sel ==
nullptr || !this->editable)
break;
1032 int pos = this->GetCurrentActivePosition();
1035 auto it = std::next(std::begin(this->
actives), pos);
1038 this->active_sel =
nullptr;
1039 }
else if (it == std::end(this->
actives)) {
1040 this->active_sel = this->
actives.back().get();
1042 this->active_sel = it->get();
1045 this->avail_pos = -1;
1046 this->avail_sel =
nullptr;
1053 if (!this->editable || this->
actives.empty())
break;
1063 this->active_sel =
nullptr;
1065 if (it != std::end(this->
avails)) {
1067 this->avail_sel = *it;
1068 this->avail_pos =
static_cast<int>(std::distance(std::begin(this->
avails), it));
1071 if (click_count == 1) {
1086 if (!this->editable)
break;
1100 if (this->active_sel ==
nullptr || !this->show_params || this->active_sel->
num_valid_params == 0)
break;
1102 OpenGRFParameterWindow(
false, *this->active_sel, this->editable);
1108 if (this->active_sel !=
nullptr && this->editable) {
1136 this->avail_sel =
nullptr;
1137 this->avail_pos = -1;
1145 if (!this->editable)
return;
1148 this->preset = index;
1158 this->active_sel =
nullptr;
1164 if (!str.has_value())
return;
1170 for (uint i = 0; i < this->
grf_presets.size(); i++) {
1188 if (this->avail_pos >= 0) this->vscroll2->
ScrollTowards(this->avail_pos);
1196 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
1198 if (!gui_scope)
return;
1206 for (
auto &c : this->
actives) {
1213 c = std::make_unique<GRFConfig>(*f);
1220 this->modified =
false;
1232 this->modified =
true;
1237 this->BuildAvailables();
1247 bool disable_all = this->active_sel ==
nullptr || !this->
editable;
1254 const GRFConfig *selected_config = (this->avail_sel ==
nullptr) ? this->active_sel : this->
avail_sel;
1255 for (
TextfileType tft = TFT_CONTENT_BEGIN; tft < TFT_CONTENT_END; tft++) {
1273 bool has_missing =
false;
1274 bool has_compatible =
false;
1275 for (
const auto &c : this->
actives) {
1281 if (has_missing || has_compatible) {
1282 text = STR_NEWGRF_SETTINGS_FIND_MISSING_CONTENT_BUTTON;
1283 tool_tip = STR_NEWGRF_SETTINGS_FIND_MISSING_CONTENT_TOOLTIP;
1285 text = STR_INTRO_ONLINE_CONTENT;
1286 tool_tip = STR_INTRO_TOOLTIP_ONLINE_CONTENT;
1300 if (this->avail_pos >= 0) {
1301 this->active_sel =
nullptr;
1314 if (!this->editable)
return;
1326 if (!this->editable)
return;
1329 if (this->active_sel !=
nullptr) {
1330 int from_pos = this->GetCurrentActivePosition();
1334 if (to_pos != from_pos) {
1335 if (to_pos > from_pos) ++to_pos;
1337 auto from = std::next(std::begin(this->
actives), from_pos);
1338 auto to = std::next(std::begin(this->
actives), to_pos);
1339 Slide(from, std::next(from), to);
1345 }
else if (this->avail_sel !=
nullptr) {
1351 Point dummy = {-1, -1};
1357 if (this->active_over != -1) {
1360 this->active_over = -1;
1366 if (!this->editable)
return;
1368 if (widget ==
WID_NS_FILE_LIST && (this->active_sel !=
nullptr || this->avail_sel !=
nullptr)) {
1372 to_pos = std::min(to_pos, this->vscroll->
GetCount() - (this->active_sel !=
nullptr ? 2 : 1));
1374 if (to_pos != this->active_over) {
1375 this->active_over = to_pos;
1379 this->active_over = -2;
1381 }
else if (this->active_over != -1) {
1383 this->active_over = -1;
1394 if (i != 0)
return i < 0;
1397 if (i != 0)
return i < 0;
1406 filter.AddLine((*a)->GetName());
1407 filter.AddLine((*a)->filename);
1408 if (
auto desc = (*a)->GetDescription(); desc.has_value()) filter.AddLine(*desc);
1412 void BuildAvailables()
1419 if (std::ranges::any_of(this->
actives, [&c](
const auto &gc) {
return gc->ident.HasGrfIdentifier(c->
ident.
grfid, &c->
ident.
md5sum); }))
continue;
1422 this->
avails.push_back(c.get());
1426 assert(best !=
nullptr);
1436 this->
avails.push_back(c.get());
1445 if (this->avail_sel !=
nullptr) {
1447 if (this->avail_pos == -1) {
1448 this->avail_sel =
nullptr;
1474 if (std::ranges::any_of(this->
actives, [&grfid = this->avail_sel->
ident.
grfid](
const auto &gc) { return gc->ident.grfid == grfid; })) {
1479 auto entry = (ins_pos >= 0 &&
static_cast<size_t>(ins_pos) < std::size(this->
actives))
1480 ? std::next(std::begin(this->
actives), ins_pos)
1484 entry = this->
actives.insert(entry, std::make_unique<GRFConfig>(*this->avail_sel));
1485 (*entry)->SetParameterDefaults();
1488 int new_pos = this->avail_pos + 1;
1489 if (new_pos >= (
int)this->
avails.size()) new_pos = this->avail_pos - 1;
1490 this->avail_pos = new_pos;
1491 if (new_pos >= 0) this->avail_sel = this->
avails[new_pos];
1507 for (
const auto &c : list) {
1510 auto ci = std::make_unique<ContentInfo>();
1514 ci->unique_id = std::byteswap(c->
ident.
grfid);
1516 cv.push_back(std::move(ci));
1543 std::unique_ptr<NWidgetBase>
avs{};
1544 std::unique_ptr<NWidgetBase>
acs{};
1545 std::unique_ptr<NWidgetBase>
inf{};
1562 this->
avs->SetupSmallestSize(w);
1563 this->
acs->SetupSmallestSize(w);
1564 this->
inf->SetupSmallestSize(w);
1566 uint min_avs_width = this->
avs->smallest_x + this->
avs->padding.Horizontal();
1567 uint min_acs_width = this->
acs->smallest_x + this->
acs->padding.Horizontal();
1568 uint min_inf_width = this->
inf->smallest_x + this->
inf->padding.Horizontal();
1570 uint min_avs_height = this->
avs->smallest_y + this->
avs->padding.Vertical();
1571 uint min_acs_height = this->
acs->smallest_y + this->
acs->padding.Vertical();
1572 uint min_inf_height = this->
inf->smallest_y + this->
inf->padding.Vertical();
1579 this->
fill_x = std::lcm(this->
avs->fill_x, this->acs->fill_x);
1580 if (this->
inf->fill_x > 0 && (this->fill_x == 0 || this->fill_x > this->inf->fill_x)) this->
fill_x = this->
inf->fill_x;
1583 if (this->
acs->fill_y > 0 && (this->fill_y == 0 || this->fill_y > this->acs->fill_y)) this->
fill_y = this->
acs->fill_y;
1587 this->
resize_x = std::lcm(this->
avs->resize_x, this->acs->resize_x);
1588 if (this->
inf->resize_x > 0 && (this->resize_x == 0 || this->resize_x > this->inf->resize_x)) this->
resize_x = this->
inf->resize_x;
1591 if (this->
acs->resize_y > 0 && (this->resize_y == 0 || this->resize_y > this->acs->resize_y)) this->
resize_y = this->
acs->resize_y;
1602 uint min_avs_width = this->
avs->smallest_x + this->
avs->padding.Horizontal();
1603 uint min_acs_width = this->
acs->smallest_x + this->
acs->padding.Horizontal();
1604 uint min_inf_width = this->
inf->smallest_x + this->
inf->padding.Horizontal();
1606 uint min_list_width = std::max(min_avs_width, min_acs_width);
1607 uint avs_extra_width = min_list_width - min_avs_width;
1608 uint acs_extra_width = min_list_width - min_acs_width;
1616 uint extra_width, inf_width;
1617 if (use_three_columns) {
1618 extra_width = given_width - min_three_columns;
1621 extra_width = given_width - min_two_columns;
1624 inf_width =
ComputeMaxSize(this->
inf->smallest_x, this->inf->smallest_x + inf_width, this->inf->GetHorizontalStepSize(sizing));
1625 extra_width -= inf_width - this->
inf->smallest_x;
1627 uint inf_height =
ComputeMaxSize(this->
inf->smallest_y, given_height, this->inf->GetVerticalStepSize(sizing));
1629 if (use_three_columns) {
1632 uint avs_width = std::min(avs_extra_width, extra_width);
1633 extra_width -= avs_width;
1634 extra_width -= std::min(acs_extra_width, extra_width);
1635 avs_width += extra_width / 2;
1637 avs_width =
ComputeMaxSize(this->
avs->smallest_x, this->avs->smallest_x + avs_width, this->avs->GetHorizontalStepSize(sizing));
1639 uint acs_width = given_width -
1640 inf_width - this->
inf->padding.Horizontal() -
1642 acs_width =
ComputeMaxSize(min_acs_width, acs_width, this->
acs->GetHorizontalStepSize(sizing)) -
1643 this->
acs->padding.Horizontal();
1646 uint avs_height =
ComputeMaxSize(this->
avs->smallest_y, given_height, this->avs->resize_y);
1647 uint acs_height =
ComputeMaxSize(this->
acs->smallest_y, given_height, this->acs->resize_y);
1651 x += this->
inf->padding.left;
1652 this->
inf->AssignSizePosition(sizing, x, y + this->
inf->padding.top, inf_width, inf_height, rtl);
1655 x += this->
avs->padding.left;
1656 this->
avs->AssignSizePosition(sizing, x, y + this->
avs->padding.top, avs_width, avs_height, rtl);
1660 x += this->
acs->padding.left;
1661 this->
acs->AssignSizePosition(sizing, x, y + this->
acs->padding.top, acs_width, acs_height, rtl);
1665 x += this->
avs->padding.left;
1666 this->
avs->AssignSizePosition(sizing, x, y + this->
avs->padding.top, avs_width, avs_height, rtl);
1668 x += this->
inf->padding.left;
1669 this->
inf->AssignSizePosition(sizing, x, y + this->
inf->padding.top, inf_width, inf_height, rtl);
1674 uint avs_width =
ComputeMaxSize(this->
avs->smallest_x, this->avs->smallest_x + avs_extra_width + extra_width,
1675 this->avs->GetHorizontalStepSize(sizing));
1676 uint acs_width =
ComputeMaxSize(this->
acs->smallest_x, this->acs->smallest_x + acs_extra_width + extra_width,
1677 this->acs->GetHorizontalStepSize(sizing));
1680 uint min_acs_height = this->
acs->smallest_y + this->
acs->padding.Vertical();
1681 uint extra_height = given_height - min_acs_height - min_avs_height;
1684 uint avs_height =
ComputeMaxSize(this->
avs->smallest_y, this->avs->smallest_y + extra_height / 2, this->avs->resize_y);
1685 if (this->editable) extra_height -= avs_height - this->
avs->smallest_y;
1686 uint acs_height =
ComputeMaxSize(this->
acs->smallest_y, this->acs->smallest_y + extra_height, this->acs->resize_y);
1690 x += this->
inf->padding.left;
1691 this->
inf->AssignSizePosition(sizing, x, y + this->
inf->padding.top, inf_width, inf_height, rtl);
1694 this->
acs->AssignSizePosition(sizing, x + this->
acs->padding.left, y + this->acs->padding.top, acs_width, acs_height, rtl);
1695 if (this->editable) {
1696 this->
avs->AssignSizePosition(sizing, x + this->
avs->padding.left, y + given_height - avs_height - this->avs->padding.bottom, avs_width, avs_height, rtl);
1698 this->
avs->AssignSizePosition(sizing, 0, 0, this->
avs->smallest_x, this->avs->smallest_y, rtl);
1701 this->
acs->AssignSizePosition(sizing, x + this->
acs->padding.left, y + this->acs->padding.top, acs_width, acs_height, rtl);
1702 if (this->editable) {
1703 this->
avs->AssignSizePosition(sizing, x + this->
avs->padding.left, y + given_height - avs_height - this->avs->padding.bottom, avs_width, avs_height, rtl);
1705 this->
avs->AssignSizePosition(sizing, 0, 0, this->
avs->smallest_x, this->avs->smallest_y, rtl);
1707 uint dx = this->
acs->current_x + this->
acs->padding.Horizontal();
1708 if (this->editable) {
1709 dx = std::max(dx, this->
avs->current_x + this->avs->padding.Horizontal());
1712 this->
inf->AssignSizePosition(sizing, x, y + this->
inf->padding.top, inf_width, inf_height, rtl);
1720 this->
avs->FillWidgetLookup(widget_lookup);
1721 this->
acs->FillWidgetLookup(widget_lookup);
1722 this->
inf->FillWidgetLookup(widget_lookup);
1737 if (this->editable) this->
avs->Draw(w);
1746static constexpr NWidgetPart _nested_newgrf_actives_widgets[] = {
1754 SetToolTip(STR_NEWGRF_SETTINGS_PRESET_LIST_TOOLTIP),
1758 SetStringTip(STR_NEWGRF_SETTINGS_PRESET_SAVE, STR_NEWGRF_SETTINGS_PRESET_SAVE_TOOLTIP),
1760 SetStringTip(STR_NEWGRF_SETTINGS_PRESET_DELETE, STR_NEWGRF_SETTINGS_PRESET_DELETE_TOOLTIP),
1779 SetStringTip(STR_NEWGRF_SETTINGS_REMOVE, STR_NEWGRF_SETTINGS_REMOVE_TOOLTIP),
1782 SetStringTip(STR_NEWGRF_SETTINGS_MOVEUP, STR_NEWGRF_SETTINGS_MOVEUP_TOOLTIP),
1784 SetStringTip(STR_NEWGRF_SETTINGS_MOVEDOWN, STR_NEWGRF_SETTINGS_MOVEDOWN_TOOLTIP),
1787 SetStringTip(STR_NEWGRF_SETTINGS_UPGRADE, STR_NEWGRF_SETTINGS_UPGRADE_TOOLTIP),
1792 SetStringTip(STR_NEWGRF_SETTINGS_RESCAN_FILES, STR_NEWGRF_SETTINGS_RESCAN_FILES_TOOLTIP),
1794 SetStringTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
1801static constexpr NWidgetPart _nested_newgrf_availables_widgets[] = {
1807 SetStringTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
1823 SetStringTip(STR_NEWGRF_SETTINGS_ADD, STR_NEWGRF_SETTINGS_ADD_FILE_TOOLTIP),
1826 SetStringTip(STR_NEWGRF_SETTINGS_RESCAN_FILES, STR_NEWGRF_SETTINGS_RESCAN_FILES_TOOLTIP),
1828 SetStringTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
1834static constexpr NWidgetPart _nested_newgrf_infopanel_widgets[] = {
1846 SetStringTip(STR_CONTENT_OPEN_URL, STR_CONTENT_OPEN_URL_TOOLTIP),
1848 SetStringTip(STR_TEXTFILE_VIEW_README, STR_TEXTFILE_VIEW_README_TOOLTIP),
1852 SetStringTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_TEXTFILE_VIEW_CHANGELOG_TOOLTIP),
1854 SetStringTip(STR_TEXTFILE_VIEW_LICENCE, STR_TEXTFILE_VIEW_LICENCE_TOOLTIP),
1865 SetStringTip(STR_NEWGRF_SETTINGS_TOGGLE_PALETTE, STR_NEWGRF_SETTINGS_TOGGLE_PALETTE_TOOLTIP),
1881 std::unique_ptr<NWidgetBase> avs =
MakeNWidgets(_nested_newgrf_availables_widgets,
nullptr);
1882 std::unique_ptr<NWidgetBase> acs =
MakeNWidgets(_nested_newgrf_actives_widgets,
nullptr);
1883 std::unique_ptr<NWidgetBase> inf =
MakeNWidgets(_nested_newgrf_infopanel_widgets,
nullptr);
1885 return std::make_unique<NWidgetNewGRFDisplay>(std::move(avs), std::move(acs), std::move(inf));
1889static constexpr NWidgetPart _nested_newgrf_widgets[] = {
1910 _nested_newgrf_widgets
1924 assert(nw !=
nullptr);
1933 int pos = nw->GetCurrentActivePosition();
1939 if (
static_cast<size_t>(pos) >= nw->
actives.size()) {
1942 auto it = std::next(std::begin(nw->
actives), pos);
1969 new NewGRFWindow(_newgrf_desc, editable, show_params, exec_changes, config);
1987 NWidget(
WWT_EDITBOX, COLOUR_GREY,
WID_SVP_EDITBOX),
SetPadding(2, 2, 2, 2),
SetFill(1, 0),
SetResize(1, 0),
1988 SetStringTip(STR_SAVE_PRESET_TITLE, STR_SAVE_PRESET_EDITBOX_TOOLTIP),
2018 if (!initial_text.empty()) {
2019 for (uint i = 0; i < this->
presets.size(); i++) {
2020 if (this->
presets[i] == initial_text) {
2036 this->presetname_editbox.text.
Assign(initial_text);
2049 for (uint i = 0; i < this->
presets.size(); i++) {
2051 size.width = std::max(size.width, d.width + padding.width);
2053 size.height =
ClampU((uint)this->
presets.size(), 5, 20) * resize.height + padding.height;
2071 for (
auto it = first; it != last; ++it) {
2072 int row =
static_cast<int>(std::distance(std::begin(this->
presets), it));
2075 DrawString(tr.left, tr.right, tr.top + offset_y, *it, (row == this->selected) ? TC_WHITE : TC_SILVER);
2076 tr.top += step_height;
2088 if (it != this->
presets.end()) {
2089 this->selected = it - this->
presets.begin();
2090 this->presetname_editbox.text.
Assign(*it);
2100 auto text = this->presetname_editbox.text.
GetText();
2206 this->scanned = num;
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
List template of 'things' T to sort in a GUI.
bool Filter(FilterFunction *decide, F filter_data)
Filter the list.
void RebuildDone()
Notify the sortlist that the rebuild is done.
void SetFiltering(Filtering f)
Import filter conditions.
void SetListing(Listing l)
Import sort conditions.
void SetFilterState(bool state)
Enable or disable the filter.
void SetFilterFuncs(std::span< FilterFunction *const > n_funcs)
Hand the filter function pointers to the GUIList.
bool NeedRebuild() const
Check if a rebuild is needed.
void ForceRebuild()
Force that a rebuild is needed.
bool Sort(Comp compare)
Sort the list.
void SetSortFuncs(std::span< SortFunction *const > n_funcs)
Hand the sort function pointers to the GUIList.
void StartAction(GamelogActionType at)
Stores information about new action, but doesn't allocate it Action is allocated only when there is a...
void StopAction()
Stops logging of any changes.
void GRFUpdate(const GRFConfigList &oldg, const GRFConfigList &newg)
Compares two NewGRF lists and logs any change.
A timeout timer will fire once after the interval.
void Reset()
Reset the timer, so it will fire again after the timeout.
static const uint NETWORK_MAX_GRF_COUNT
Maximum number of GRFs that can be sent.
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_...
auto Slide(TIter first, TIter last, TIter position) -> std::pair< TIter, TIter >
Move elements between first and last to a new position, rotating elements in between as necessary.
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, bool instant_close, bool persist)
Show a drop down list.
void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, WidgetID button, Rect wi_rect, Colours wi_colour, bool instant_close, bool persist)
Show a drop down list.
Functions related to the drop down widget.
Types related to the drop down widget.
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
Functions related to errors.
@ WL_ERROR
Errors (eg. saving/loading failed)
@ WL_CRITICAL
Critical errors, the MessageBox is shown in all cases.
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
void ShowErrorMessage(EncodedString &&summary_msg, int x, int y, CommandCost &cc)
Display an error message in a window.
@ NEWGRF_DIR
Subdirectory for all NewGRFs.
Declarations for savegames operations.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Gamelog _gamelog
Gamelog instance.
Functions to be called to log fundamental changes to the game.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
int CentreBounds(int min, int max, int size)
Determine where to position a centred object.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
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 DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion)
Calculate string bounding box for multi-line strings.
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.
void GfxFillRect(int left, int top, int right, int bottom, const std::variant< PixelColour, PaletteID > &colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Dimension GetScaledSpriteSize(SpriteID sprid)
Scale sprite size for GUI.
@ FS_NORMAL
Index of the normal font in the font tables.
@ SA_HOR_CENTER
Horizontally center the text.
uint32_t PaletteID
The number of the palette.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
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.
constexpr bool IsInsideMM(const size_t x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
constexpr uint ClampU(const uint a, const uint min, const uint max)
Clamp an unsigned integer between an interval.
void ShowQuery(EncodedString &&caption, EncodedString &&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...
void ShowQueryString(std::string_view str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
bool _network_available
is network mode available?
Basic functions/variables used all over the place.
Part of the network protocol handling content distribution.
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.
std::vector< std::unique_ptr< ContentInfo > > ContentVector
Vector with content info.
Base for the NewGRF implementation.
void ReloadNewGRFData()
Reload all NewGRF files during a running game.
GRFConfigList _grfconfig
First item in list of current GRF set up.
void CopyGRFConfigList(GRFConfigList &dst, const GRFConfigList &src, bool init_only)
Copy a GRF Config list.
std::string GRFBuildParamList(const GRFConfig &c)
Build a string containing space separated parameter values, and terminate.
const GRFConfig * FindGRFConfig(uint32_t grfid, FindGRFConfigMode mode, const MD5Hash *md5sum, uint32_t desired_version)
Find a NewGRF in the scanned list.
void ResetGRFConfig(bool defaults)
Reset the current GRF Config to either blank or newgame settings.
GRFConfigList _all_grfs
First item in list of all scanned NewGRFs.
void ClearGRFConfigList(GRFConfigList &config)
Clear a GRF Config list, freeing all nodes.
@ GCS_DISABLED
GRF file is disabled.
@ GCS_NOT_FOUND
GRF file was not found in the local cache.
@ GCS_ACTIVATED
GRF file has been activated.
@ Compatible
GRF file does not exactly match the requested GRF (different MD5SUM), but grfid matches)
@ Static
GRF file is used statically (can be used in any MP game)
@ Invalid
GRF is unusable with this version of OpenTTD.
@ PTYPE_UINT_ENUM
The parameter allows a range of numbers, each of which can have a special name.
@ PTYPE_BOOL
The parameter is either 0 or 1.
@ FGCM_NEWEST
Find newest Grf.
@ FGCM_NEWEST_VALID
Find newest Grf, ignoring Grfs with GRFConfigFlag::Invalid set.
@ FGCM_EXACT
Only find Grfs matching md5sum.
@ GRFP_GRF_UNSET
The NewGRF provided no information.
@ GRFP_USE_WINDOWS
The palette state is set to use the Windows palette.
@ GRFP_BLT_32BPP
The NewGRF prefers a 32 bpp blitter.
@ GRFP_USE_MASK
Bitmask to get only the use palette use states.
@ GRFP_GRF_MASK
Bitmask to get only the NewGRF supplied information.
static void ShowSavePresetWindow(std::string_view initial_text)
Open the window for saving a preset.
std::map< uint32_t, const GRFConfig * > GrfIdMap
Map of grfid to the grf config.
static WindowDesc _save_preset_desc(WDP_CENTER, "save_preset", 140, 110, WC_SAVE_PRESET, WC_GAME_OPTIONS, WindowDefaultFlag::Modal, _nested_save_preset_widgets)
Window description of the preset save window.
static WindowDesc _scan_progress_desc(WDP_CENTER, {}, 0, 0, WC_MODAL_PROGRESS, WC_NONE, {}, _nested_scan_progress_widgets)
Description of the widgets and other settings of the window.
static void NewGRFConfirmationCallback(Window *w, bool confirmed)
Callback function for the newgrf 'apply changes' confirmation window.
static void FillGrfidMap(const GRFConfigList &lst, GrfIdMap &grfid_map)
Add all grf configs from c into the map.
static constexpr NWidgetPart _nested_scan_progress_widgets[]
Widgets for the progress window.
void UpdateNewGRFScanStatus(uint num, std::string &&name)
Update the NewGRF scan status.
void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfigList &config)
Setup the NewGRF gui.
static constexpr NWidgetPart _nested_save_preset_widgets[]
Widget parts of the save preset window.
std::unique_ptr< NWidgetBase > NewGRFDisplay()
Construct nested container widget for managing the lists and the info panel of the NewGRF GUI.
static WindowDesc _newgrf_parameters_desc(WDP_CENTER, "settings_newgrf_config", 500, 208, WC_GRF_PARAMETERS, WC_NONE, {}, _nested_newgrf_parameter_widgets)
Window definition for the change grf parameters window.
void ShowNewGRFError()
Show the first NewGRF error we can find.
void ShowMissingContentWindow(const GRFConfigList &list)
Show the content list window with all missing grfs from the given list.
std::optional< std::string_view > GetGRFStringFromGRFText(const GRFTextList &text_list)
Get a C-string from a GRFText-list.
Header of Action 04 "universal holder" structure and functions.
bool RequestNewGRFScan(NewGRFScanCallback *callback)
Request a new NewGRF scan.
PixelColour GetColourGradient(Colours colour, ColourShade shade)
Get colour gradient palette index.
static constexpr PixelColour PC_DARK_BLUE
Dark blue palette colour.
static constexpr PixelColour PC_GREY
Grey palette colour.
static constexpr PixelColour PC_DARK_GREY
Dark grey palette colour.
static constexpr PixelColour PC_BLACK
Black palette colour.
Base for the GUIs that have an edit box in them.
A number of safeguards to prevent using unsafe methods.
void SaveGRFPresetToConfig(std::string_view config_name, GRFConfigList &config)
Save a NewGRF configuration with a preset name.
StringList GetGRFPresetList()
Get the list of known NewGrf presets.
void DeleteGRFPresetFromConfig(std::string_view config_name)
Delete a NewGRF configuration by preset name.
GRFConfigList LoadGRFPresetFromConfig(std::string_view config_name)
Load a NewGRF configuration by preset-name.
ClientSettings _settings_client
The current settings for this game.
Functions related to setting/changing the settings.
void DrawArrowButtons(int x, int y, Colours button_colour, uint8_t state, bool clickable_left, bool clickable_right)
Draw [<][>] boxes.
void DrawBoolButton(int x, int y, Colours button_colour, Colours background, bool state, bool clickable)
Draw a toggle button.
void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool clickable)
Draw a dropdown button.
Functions for setting GUIs.
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
#define SETTING_BUTTON_HEIGHT
Height of setting buttons.
Types related to global configuration settings.
Base types for having sorted lists in GUIs.
This file contains all sprite-related enums and defines.
static const CursorID SPR_CURSOR_MOUSE
Cursor sprite numbers.
Definition of base types and functions in a cross-platform compatible way.
std::string FormatArrayAsHex(std::span< const uint8_t > data)
Format a byte array into a continuous hex string.
int StrNaturalCompare(std::string_view s1, std::string_view s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
static void StrMakeValid(Builder &builder, StringConsumer &consumer, StringValidationSettings settings)
Copies the valid (UTF-8) characters from consumer to the builder.
@ CS_NUMERAL
Only numeric ones.
std::vector< std::string > StringList
Type for a list of strings.
Searching and filtering using a stringterm.
uint64_t GetParamMaxValue(uint64_t max_value, uint min_count, FontSize size)
Get some number that is suitable for string size computations.
EncodedString GetEncodedStringWithArgs(StringID str, std::span< const StringParameter > params)
Encode a string with its parameters into an encoded string.
void GetStringWithArgs(StringBuilder &builder, StringID string, StringParameters &args, uint case_index, bool game_script)
Get a parsed string with most special stringcodes replaced by the string parameters.
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
TextDirection _current_text_dir
Text direction of the currently selected language.
uint64_t GetParamMaxDigits(uint count, FontSize size)
Get some number that is suitable for string size computations.
Functions related to OTTD's strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
@ TD_RTL
Text is written right-to-left by default.
GUISettings gui
settings related to the GUI
@ DoesNotExist
The content does not exist in the content system.
Dimensions (a width and height) of a rectangle in 2D.
Data structure describing what to show in the list (filter criteria).
Information about GRF, used in the game and (part of it) in savegames.
MD5Hash original_md5sum
MD5 checksum of original file if only a 'compatible' file was loaded.
void SetParameterDefaults()
Set the default value for all parameters as specified by action14.
uint8_t palette
GRFPalette, bitset.
std::vector< std::optional< GRFParameterInfo > > param_info
NOSAVE: extra information about the parameters.
std::vector< GRFError > errors
NOSAVE: Error/Warning during GRF loading (Action 0x0B)
uint32_t version
NOSAVE: Version a NewGRF can set so only the newest NewGRF is shown.
std::vector< uint32_t > param
GRF parameters.
std::optional< std::string > GetURL() const
Get the grf url.
GRFStatus status
NOSAVE: GRFStatus, enum.
void SetValue(const GRFParameterInfo &info, uint32_t value)
Set the value of the given user-changeable parameter.
std::optional< std::string > GetTextfile(TextfileType type) const
Search a textfile file next to this NewGRF.
GRFConfigFlags flags
NOSAVE: GCF_Flags, bitset.
uint8_t num_valid_params
NOSAVE: Number of valid parameters (action 0x14)
std::string filename
Filename - either with or without full path.
GRFIdentifier ident
grfid and md5sum to uniquely identify newgrfs
uint32_t min_loadable_version
NOSAVE: Minimum compatible version a NewGRF can define.
std::string GetName() const
Get the name of this grf.
std::optional< std::string > GetDescription() const
Get the grf info.
uint32_t GetValue(const GRFParameterInfo &info) const
Get the value of the given user-changeable parameter.
Information about why GRF had problems during initialisation.
StringID severity
Info / Warning / Error / Fatal.
std::array< uint32_t, 2 > param_value
Values of GRF parameters to show for message and custom_message.
StringID message
Default message.
std::string custom_message
Custom message (if present)
std::string data
Additional data for message and custom_message.
bool HasGrfIdentifier(uint32_t grfid, const MD5Hash *md5sum) const
Does the identification match the provided values?
uint32_t grfid
GRF ID (defined by Action 0x08)
MD5Hash md5sum
MD5 checksum of file to distinguish files with the same GRF ID (eg. newer version of GRF)
Information about one grf parameter.
bool complete_labels
True if all values have a label.
uint8_t param_nr
GRF parameter to store content in.
uint32_t min_value
The minimal value this parameter can have.
uint32_t max_value
The maximal value of this parameter.
GRFParameterType type
The type of this parameter.
std::vector< ValueName > value_names
Names for each value.
GRFTextList name
The name of this parameter.
GRFTextList desc
The description of this parameter.
uint32_t last_newgrf_count
the numbers of NewGRFs we found during the last scan
bool newgrf_show_old_versions
whether to show old versions in the NewGRF list
bool scenario_developer
activate scenario developer: allow modifying NewGRFs in an existing game
bool newgrf_developer_tools
activate NewGRF developer tools and allow modifying NewGRFs in an existing game
Data structure describing how to show the list (what sort direction and criteria).
Window for setting the parameters of a NewGRF.
bool clicked_dropdown
Whether the dropdown is open.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
void OnDropdownClose(Point, WidgetID widget, int, int, bool) override
A dropdown window associated to this window has been closed.
void OnPaint() override
The window must be repainted.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
bool editable
Allow editing parameters.
bool HasParameterInfo(uint nr) const
Test if GRF Parameter Info exists for a given parameter index.
static GRFParameterInfo dummy_parameter_info
Dummy info in case a newgrf didn't provide info about some parameter.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void OnDropdownSelect(WidgetID widget, int index, int) override
A dropdown option associated to this window has been selected.
TimeoutTimer< TimerWindow > unclick_timeout
When reset, unclick the button after a small timeout.
bool action14present
True if action14 information is present.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
int line_height
Height of a row in the matrix widget.
bool clicked_increase
True if the increase button was clicked, false for the decrease button.
int32_t clicked_row
The selected parameter, or INT32_MAX when none is selected.
bool closing_dropdown
True, if the dropdown list is currently closing.
GRFConfig & grf_config
Set the parameters of this GRFConfig.
int32_t clicked_button
The row in which a button was clicked or INT32_MAX when none is selected.
static GRFParameterInfo & GetDummyParameterInfo(uint nr)
Get a dummy parameter-info object with default information.
GRFParameterInfo & GetParameterInfo(uint nr) const
Get GRF Parameter Info exists for a given parameter index.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void OnResize() override
Called after the window got resized.
Callback for NewGRF scanning.
Window for displaying the textfile of a NewGRF.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
const GRFConfig * grf_config
View the textfile of this GRFConfig.
Window for showing NewGRF files.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
bool editable
Is the window editable?
void OnEditboxChanged(WidgetID widget) override
The text in an editbox has been edited.
bool CanUpgradeCurrent()
Test whether the currently active set of NewGRFs can be upgraded with the available NewGRFs.
GRFConfig * active_sel
Selected active grf item.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
bool show_params
Are the grf-parameters shown in the info-panel?
void UpgradeCurrent()
Upgrade the currently active set of NewGRFs.
void OnResize() override
Called after the window got resized.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
bool AddGRFToActive(int ins_pos=-1)
Insert a GRF into the active list.
GRFConfigList actives
Temporary active grf list to which changes are made.
int avail_pos
Index of avail_sel if existing, else -1.
int active_over
Active GRF item over which another one is dragged, -1 if none.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void OnMouseDrag(Point pt, WidgetID widget) override
An 'object' is being dragged at the provided position, highlight the target if possible.
bool modified
The list of active NewGRFs has been modified since the last time they got saved.
bool execute
On pressing 'apply changes' are grf changes applied immediately, or only list is updated.
GRFConfigList & orig_list
List active grfs in the game. Used as initial value, may be updated by the window.
EventState OnKeyPress(char32_t key, uint16_t keycode) override
A key has been pressed.
int preset
Selected preset or -1 if none selected.
PaletteID GetPalette(const GRFConfig &c) const
Pick the palette for the sprite of the grf to display.
StringList grf_presets
List of known NewGRF presets.
const GRFConfig * avail_sel
Currently selected available grf. nullptr is none is selected.
void UpdateScrollBars()
Updates the scroll bars for the active and inactive NewGRF lists.
QueryString filter_editbox
Filter editbox;.
static bool TagNameFilter(const GRFConfig *const *a, StringFilter &filter)
Filter grfs by tags/name.
void OnDropdownSelect(WidgetID widget, int index, int) override
A dropdown option associated to this window has been selected.
void OnDragDrop(Point pt, WidgetID widget) override
A dragged 'object' has been released.
static Filtering last_filtering
Default filtering of GUIGRFConfigList.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
static const std::initializer_list< GUIGRFConfigList::SortFunction *const > sorter_funcs
Sort functions of the GUIGRFConfigList.
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
static const std::initializer_list< GUIGRFConfigList::FilterFunction *const > filter_funcs
Filter functions of the GUIGRFConfigList.
void OnNewGRFsScanned() override
Called whenever the NewGRF scan completed.
GUIGRFConfigList avails
Available (non-active) grfs.
StringFilter string_filter
Filter for available grf.
static Listing last_sorting
Default sorting of GUIGRFConfigList.
static bool NameSorter(const GRFConfig *const &a, const GRFConfig *const &b)
Sort grfs by name.
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
Data stored about a string that can be modified in the GUI.
int ok_button
Widget button of parent window to simulate when pressing OK in OSK.
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
static const int ACTION_CLEAR
Clear editbox.
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Specification of a rectangle with absolute coordinates of all edges.
int Width() const
Get width of Rect.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Class for the save preset window.
QueryString presetname_editbox
Edit box of the save preset.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void OnResize() override
Called after the window got resized.
int selected
Selected entry in the preset list, or -1 if none selected.
Scrollbar * vscroll
Pointer to the scrollbar widget.
StringList presets
Available presets.
SavePresetWindow(std::string_view initial_text)
Constructor of the save preset window.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Window for showing the progress of NewGRF scanning.
std::string last_name
The name of the last 'seen' NewGRF.
int scanned
The number of NewGRFs that we have seen.
void UpdateNewGRFScanStatus(uint num, std::string &&name)
Update the NewGRF scan status.
ScanProgressWindow()
Create the window.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
bool IsEmpty() const
Check whether any filter words were entered.
void SetFilterTerm(std::string_view str)
Set the term to filter on.
void ResetState()
Reset the matching state to process a new item.
bool GetState() const
Get the matching state of the current item.
The data required to format and validate a single parameter of a string.
std::string_view GetText() const
Get the current text.
void Assign(std::string_view text)
Copy a string into the textbuffer.
Window for displaying a textfile.
TextfileType file_type
Type of textfile to view.
virtual void LoadTextfile(const std::string &textfile, Subdirectory dir)
Loads the textfile text from file and setup lines.
High level window description.
Data structure for an opened window.
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
void DrawWidgets() const
Paint all widgets of a window.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Window * parent
Parent window.
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
void CloseChildWindows(WindowClass wc=WC_INVALID) const
Close all children a window might have in a head-recursive manner.
ResizeInfo resize
Resize information.
void DisableWidget(WidgetID widget_index)
Sets a widget to disabled.
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
void CloseChildWindowById(WindowClass wc, WindowNumber number) const
Close all children a window might have in a head-recursive manner.
virtual void OnQueryTextFinished(std::optional< std::string > str)
The query window opened from this window has closed.
bool SetFocusedWidget(WidgetID widget_index)
Set focus within this window to the given widget.
int top
y position of top edge of the window
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
int width
width of the window (number of pixels to the right in x direction)
@ CONTENT_TYPE_NEWGRF
The content consists of a NewGRF.
GUI functions related to textfiles.
TextfileType
Additional text files accompanying Tar archives.
@ TFT_LICENSE
Content license.
@ TFT_README
Content readme.
@ TFT_CHANGELOG
Content changelog.
Functions related to tile highlights.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
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...
@ HT_DRAG
dragging items in the depot windows
Definition of Interval and OneShot timers.
Definition of the Window system.
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
void ReInitAllWindows(bool zoom_changed)
Re-initialize all windows.
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Window functions not directly related to making/drawing windows.
@ Modal
The window is a modal child of some other window, meaning the parent is 'inactive'.
@ BorderOnly
Draw border only, no background.
@ Lowered
If set the frame is lowered and the background colour brighter (ie. buttons when pressed)
@ WDP_CENTER
Center the window.
@ WN_GAME_OPTIONS_NEWGRF_STATE
NewGRF settings.
EventState
State of handling an event.
@ ES_HANDLED
The passed event is handled.
@ ES_NOT_HANDLED
The passed event is not handled.
@ GOID_NEWGRF_CURRENT_LOADED
The current list of active NewGRF has been loaded.
@ GOID_NEWGRF_RESCANNED
NewGRFs were just rescanned.
@ GOID_NEWGRF_CHANGES_MADE
Changes have been made to a given NewGRF either through the palette or its parameters.
@ GOID_NEWGRF_LIST_EDITED
List of active NewGRFs is being edited.
@ WC_BUILD_OBJECT
Build object; Window numbers:
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
@ WC_SAVE_PRESET
Save preset; Window numbers:
@ WC_GAME_OPTIONS
Game options window; Window numbers:
@ WC_TEXTFILE
textfile; Window numbers:
@ WC_DROPDOWN_MENU
Drop down menu; Window numbers:
@ WC_QUERY_STRING
Query string window; Window numbers:
@ WC_GRF_PARAMETERS
NewGRF parameters; Window numbers:
@ WC_MODAL_PROGRESS
Progress report of landscape generation; Window numbers:
Functions related to zooming.