41#include "table/strings.h"
55 if (c->errors.empty())
continue;
57 const GRFError &error = c->errors.back();
58 if (error.
severity != STR_NEWGRF_ERROR_MSG_FATAL && error.
severity != STR_NEWGRF_ERROR_MSG_ERROR)
continue;
60 std::vector<StringParameter> params;
61 params.emplace_back(c->GetName());
62 params.emplace_back(error.
message != STR_NULL ? error.
message : STR_JUST_RAW_STRING);
64 params.emplace_back(c->filename);
65 params.emplace_back(error.
data);
66 for (
const uint32_t &value : error.
param_value) params.emplace_back(value);
68 if (error.
severity == STR_NEWGRF_ERROR_MSG_FATAL) {
77static StringID GetGRFPaletteString(uint8_t palette)
80 return (palette &
GRFP_USE_WINDOWS) ? STR_NEWGRF_SETTINGS_PALETTE_LEGACY_32BPP : STR_NEWGRF_SETTINGS_PALETTE_DEFAULT_32BPP;
82 return (palette &
GRFP_USE_WINDOWS) ? STR_NEWGRF_SETTINGS_PALETTE_LEGACY : STR_NEWGRF_SETTINGS_PALETTE_DEFAULT;
85static void ShowNewGRFInfo(
const GRFConfig &c,
const Rect &r,
bool show_params)
90 auto it = params.begin();
94 for (
const uint32_t &value : error.
param_value) *it++ = value;
119 if (!c.
param.empty()) {
136 if (
auto desc = c.
GetDescription(); desc.has_value() && !desc->empty()) {
146struct NewGRFParametersWindow :
public Window {
163 this->action14present = (this->grf_config.
num_valid_params != GRFConfig::MAX_NUM_PARAMS || !this->grf_config.
param_info.empty());
221 d.
width += padding.width;
222 d.
height += padding.height;
231 fill.height =
resize.height = this->line_height;
232 size.
height = 5 * this->line_height;
238 for (
const auto &par_info : this->grf_config.
param_info) {
239 if (!par_info.has_value())
continue;
241 if (!desc.has_value())
continue;
244 suggestion =
maxdim(d, suggestion);
262 std::pair<StringParameter, StringParameter> GetValueParams(
const GRFParameterInfo &par_info, uint32_t value)
const
266 auto it = std::ranges::lower_bound(par_info.
value_names, value, std::less{}, &GRFParameterInfo::ValueName::first);
267 if (it != std::end(par_info.
value_names) && it->first == value) {
271 return {STR_JUST_INT, value};
274 std::string GetSettingString(
const GRFParameterInfo &par_info,
int i, uint32_t value)
const
276 auto [param1, param2] = this->GetValueParams(par_info, value);
278 return name.has_value()
279 ?
GetString(STR_NEWGRF_PARAMETERS_SETTING, STR_JUST_RAW_STRING, std::string(*name), param1, param2)
280 :
GetString(STR_NEWGRF_PARAMETERS_SETTING, STR_NEWGRF_PARAMETERS_DEFAULT_NAME, i + 1, param1, param2);
289 if (!desc.has_value())
return;
303 for (int32_t i = this->vscroll->
GetPosition(); this->vscroll->IsVisible(i) && i < this->vscroll->GetCount(); i++) {
305 uint32_t current_value = this->grf_config.
GetValue(par_info);
306 bool selected = (i == this->clicked_row);
314 DrawArrowButtons(buttons_left, ir.top + button_y_offset,
Colours::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);
319 ir.top += this->line_height;
325 if (this->closing_dropdown) {
326 this->closing_dropdown =
false;
327 this->clicked_dropdown =
false;
336 if (this->editable && !this->action14present && !this->grf_config.
param.empty()) {
337 this->grf_config.
param.pop_back();
344 if (this->editable && !this->action14present && this->grf_config.
param.size() < this->grf_config.num_valid_params) {
345 this->grf_config.
param.emplace_back(0);
352 if (!this->editable)
break;
354 if (num >= this->vscroll->
GetCount())
break;
356 if (this->clicked_row != num) {
359 this->clicked_row = num;
360 this->clicked_dropdown =
false;
364 int x = pt.x - r.left;
370 uint32_t old_val = this->grf_config.
GetValue(par_info);
372 if (this->clicked_dropdown) {
375 this->clicked_dropdown =
false;
376 this->closing_dropdown =
false;
378 int rel_y = (pt.y - r.top) % this->line_height;
387 if (pt.y >= wi_rect.top && pt.y <= wi_rect.bottom) {
388 this->clicked_dropdown =
true;
389 this->closing_dropdown =
false;
392 for (
const auto &[value, name] : par_info.
value_names) {
394 assert(text.has_value());
402 uint32_t val = old_val;
409 this->clicked_increase =
true;
413 this->clicked_increase =
false;
416 if (val != old_val) {
417 this->grf_config.
SetValue(par_info, val);
419 this->clicked_button = num;
431 if (!this->editable)
break;
441 if (!str.has_value() || str->empty())
return;
443 if (!value.has_value())
return;
445 this->grf_config.
SetValue(par_info, *value);
452 assert(this->clicked_dropdown);
454 this->grf_config.
SetValue(par_info, index);
465 assert(this->clicked_dropdown);
466 this->closing_dropdown =
true;
480 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
482 if (!gui_scope)
return;
483 if (!this->action14present) {
489 if (this->clicked_row != INT32_MAX && this->clicked_row >= this->vscroll->
GetCount()) {
490 this->clicked_row = INT32_MAX;
497 this->clicked_button = INT32_MAX;
504static constexpr std::initializer_list<NWidgetPart> _nested_newgrf_parameter_widgets = {
515 NWidget(
WWT_TEXT,
Colours::Invalid,
WID_NP_NUMPAR),
SetResize(1, 0),
SetFill(1, 0),
SetPadding(0, 0, 0, 4),
520 NWidget(
WWT_MATRIX,
Colours::Mauve,
WID_NP_BACKGROUND),
SetMinimalSize(188, 182),
SetResize(1, 1),
SetFill(1, 0),
SetMatrixDataTip(1, 0),
SetScrollbar(
WID_NP_SCROLLBAR),
538 WindowClass::NewGRFParameters, WindowClass::None,
540 _nested_newgrf_parameter_widgets
543void OpenGRFParameterWindow(
bool is_baseset,
GRFConfig &c,
bool editable)
550struct NewGRFTextfileWindow :
public TextfileWindow {
555 this->ConstructWindow();
564 return GetString(stringid, STR_CONTENT_TYPE_NEWGRF, this->grf_config->
GetName());
577typedef std::map<GrfID, const GRFConfig *>
GrfIdMap;
586 for (
const auto &c : lst) {
600 static const uint EDITBOX_MAX_SIZE = 50;
604 static const std::initializer_list<GUIGRFConfigList::SortFunction * const>
sorter_funcs;
605 static const std::initializer_list<GUIGRFConfigList::FilterFunction * const>
filter_funcs;
664 void Close([[maybe_unused]]
int data = 0)
override
669 if (this->editable && this->modified && !this->execute && !_exit_game) {
678 int GetCurrentActivePosition()
const
680 if (this->active_sel !=
nullptr) {
681 auto it = std::ranges::find_if(this->actives, [
this](
const auto &c) {
return c.get() == this->active_sel; });
682 if (it != std::end(this->
actives))
return static_cast<int>(std::distance(std::begin(this->
actives), it));
697 GrfIdMap::const_iterator iter = grfid_map.find(a->ident.grfid);
698 if (iter != grfid_map.end() && a->version > iter->second->version)
return true;
710 GrfIdMap::iterator iter = grfid_map.find(a->ident.grfid);
711 if (iter == grfid_map.end() || iter->second->version >= a->version)
continue;
713 auto c = std::ranges::find_if(this->actives, [&iter](
const auto &grfconfig) {
return grfconfig.get() == iter->second; });
714 assert(c != std::end(this->actives));
715 auto d = std::make_unique<GRFConfig>(*a);
716 if (d->IsCompatible((*c)->version)) {
719 d->SetParameterDefaults();
721 if (this->active_sel == c->get()) {
724 this->active_sel =
nullptr;
727 iter->second = c->get();
763 for (
const auto &i : this->grf_presets) {
766 d.
width += padding.width;
775 size.
width += padding.width;
776 size.
height += padding.height;
792 if (this->preset == -1)
return GetString(STR_NUM_CUSTOM);
794 return this->grf_presets[this->preset];
847 int square_offset_y = (step_height - square.
height) / 2;
848 int warning_offset_y = (step_height - warning.
height) / 2;
852 uint text_left = rtl ? tr.left : tr.left + square.
width + 13;
853 uint text_right = rtl ? tr.right - square.
width - 13 : tr.right;
854 uint square_left = rtl ? tr.right - square.
width - 3 : tr.left + 3;
855 uint warning_left = rtl ? tr.right - square.
width - warning.
width - 8 : tr.left + square.
width + 8;
858 for (
const auto &c : this->actives) {
860 std::string text = c->
GetName();
861 bool h = (this->active_sel == c.get());
866 }
else if (i == this->active_over) {
868 int active_sel_pos = this->GetCurrentActivePosition();
869 if (active_sel_pos != this->active_over) {
870 uint
top = (active_sel_pos < 0 || this->active_over < active_sel_pos) ? tr.top + 1 : tr.top + step_height - 2;
876 uint txtoffset = c->
errors.empty() ? 0 : warning.
width;
878 tr.top += step_height;
882 if (i == this->active_over && this->vscroll->
IsVisible(i)) {
897 for (
auto it = first; it != last; ++it) {
899 bool h = (c == this->avail_sel);
900 std::string text = c->
GetName();
904 tr.top += step_height;
917 const GRFConfig *selected = this->active_sel;
918 if (selected ==
nullptr) selected = this->avail_sel;
919 if (selected !=
nullptr) {
920 ShowNewGRFInfo(*selected, r, this->show_params);
930 if (this->active_sel ==
nullptr && this->avail_sel ==
nullptr)
return;
943 for (uint i = 0; i < this->grf_presets.size(); i++) {
953 const GRFConfig *c = (this->avail_sel ==
nullptr) ? this->active_sel : this->avail_sel;
955 if (url.has_value()) OpenBrowser(std::move(*url));
960 ShowSavePresetWindow((this->preset == -1) ? std::string_view{} : this->grf_presets[this->preset]);
964 if (this->preset == -1)
return;
974 if (this->active_sel ==
nullptr || !this->editable)
break;
976 int pos = this->GetCurrentActivePosition();
979 std::swap(this->actives[pos - 1], this->actives[pos]);
988 if (this->active_sel ==
nullptr || !this->editable)
break;
990 int pos = this->GetCurrentActivePosition();
991 if (pos == -1 ||
static_cast<size_t>(pos) >= this->actives.size() - 1)
break;
993 std::swap(this->actives[pos], this->actives[pos + 1]);
1004 const GRFConfig *old_sel = this->active_sel;
1006 if (i < this->
actives.size()) {
1007 this->active_sel = this->actives[i].get();
1009 this->active_sel =
nullptr;
1011 if (this->active_sel != old_sel) {
1015 this->avail_sel =
nullptr;
1016 this->avail_pos = -1;
1019 if (click_count == 1) {
1028 if (this->active_sel ==
nullptr || !this->editable)
break;
1033 int pos = this->GetCurrentActivePosition();
1036 auto it = std::next(std::begin(this->actives), pos);
1037 it = this->actives.erase(it);
1038 if (this->actives.empty()) {
1039 this->active_sel =
nullptr;
1040 }
else if (it == std::end(this->actives)) {
1041 this->active_sel = this->actives.back().get();
1043 this->active_sel = it->get();
1046 this->avail_pos = -1;
1047 this->avail_sel =
nullptr;
1054 if (!this->editable || this->actives.empty())
break;
1064 this->active_sel =
nullptr;
1066 if (it != std::end(this->avails)) {
1068 this->avail_sel = *it;
1069 this->avail_pos =
static_cast<int>(std::distance(std::begin(this->avails), it));
1072 if (click_count == 1) {
1087 if (!this->editable)
break;
1101 if (this->active_sel ==
nullptr || !this->show_params || this->active_sel->
num_valid_params == 0)
break;
1103 OpenGRFParameterWindow(
false, *this->active_sel, this->editable);
1109 if (this->active_sel !=
nullptr && this->editable) {
1136 if (this->active_sel ==
nullptr) this->
CloseChildWindows(WindowClass::Textfile);
1137 this->avail_sel =
nullptr;
1138 this->avail_pos = -1;
1146 if (!this->editable)
return;
1149 this->preset = index;
1159 this->active_sel =
nullptr;
1165 if (!str.has_value())
return;
1171 for (uint i = 0; i < this->grf_presets.size(); i++) {
1172 if (this->grf_presets[i] == str) {
1187 this->vscroll->
SetCount(this->actives.size() + 1);
1189 if (this->avail_pos >= 0) this->vscroll2->
ScrollTowards(this->avail_pos);
1197 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
1199 if (!gui_scope)
return;
1207 for (
auto &c : this->actives) {
1214 c = std::make_unique<GRFConfig>(*f);
1221 this->modified =
false;
1233 this->modified =
true;
1238 this->BuildAvailables();
1248 bool disable_all = this->active_sel ==
nullptr || !this->editable;
1255 const GRFConfig *selected_config = (this->avail_sel ==
nullptr) ? this->active_sel : this->avail_sel;
1274 bool has_missing =
false;
1275 bool has_compatible =
false;
1276 for (
const auto &c : this->actives) {
1282 if (has_missing || has_compatible) {
1283 text = STR_NEWGRF_SETTINGS_FIND_MISSING_CONTENT_BUTTON;
1284 tool_tip = STR_NEWGRF_SETTINGS_FIND_MISSING_CONTENT_TOOLTIP;
1286 text = STR_INTRO_ONLINE_CONTENT;
1287 tool_tip = STR_INTRO_TOOLTIP_ONLINE_CONTENT;
1301 if (this->avail_pos >= 0) {
1302 this->active_sel =
nullptr;
1304 if (this->avail_sel != this->avails[this->avail_pos]) this->
CloseChildWindows(WindowClass::Textfile);
1305 this->avail_sel = this->avails[this->avail_pos];
1315 if (!this->editable)
return;
1327 if (!this->editable)
return;
1330 if (this->active_sel !=
nullptr) {
1331 int from_pos = this->GetCurrentActivePosition();
1335 if (to_pos != from_pos) {
1336 if (to_pos > from_pos) ++to_pos;
1338 auto from = std::next(std::begin(this->actives), from_pos);
1339 auto to = std::next(std::begin(this->actives), to_pos);
1340 Slide(from, std::next(from), to);
1346 }
else if (this->avail_sel !=
nullptr) {
1353 Point dummy = {-1, -1};
1360 if (this->active_over != -1) {
1363 this->active_over = -1;
1369 if (!this->editable)
return;
1371 if (widget ==
WID_NS_FILE_LIST && (this->active_sel !=
nullptr || this->avail_sel !=
nullptr)) {
1375 to_pos = std::min(to_pos, this->vscroll->
GetCount() - (this->active_sel !=
nullptr ? 2 : 1));
1377 if (to_pos != this->active_over) {
1378 this->active_over = to_pos;
1382 this->active_over = -2;
1384 }
else if (this->active_over != -1) {
1386 this->active_over = -1;
1397 if (i != 0)
return i < 0;
1400 if (i != 0)
return i < 0;
1409 filter.AddLine((*item)->GetName());
1410 filter.AddLine((*item)->filename);
1411 if (
auto desc = (*item)->GetDescription(); desc.has_value()) filter.AddLine(*desc);
1415 void BuildAvailables()
1419 this->avails.clear();
1422 if (std::ranges::any_of(this->actives, [&c](
const auto &gc) {
return gc->ident.HasGrfIdentifier(c->
ident.
grfid, &c->
ident.
md5sum); }))
continue;
1425 this->
avails.push_back(c.get());
1429 assert(best !=
nullptr);
1439 this->
avails.push_back(c.get());
1445 this->
avails.RebuildDone();
1455 this->vscroll2->SetCount(this->
avails.size());
1470 size_t count = std::ranges::count_if(this->actives, [](
const auto &gc) {
return !gc->flags.Test(
GRFConfigFlag::Static); });
1477 if (std::ranges::any_of(this->actives, [&grfid = this->avail_sel->
ident.
grfid](
const auto &gc) { return gc->ident.grfid == grfid; })) {
1482 auto entry = (ins_pos >= 0 &&
static_cast<size_t>(ins_pos) < std::size(this->actives))
1483 ? std::next(std::begin(this->actives), ins_pos)
1484 : std::end(this->actives);
1487 entry = this->actives.insert(entry, std::make_unique<GRFConfig>(*this->avail_sel));
1488 (*entry)->SetParameterDefaults();
1491 int new_pos = this->avail_pos + 1;
1492 if (new_pos >= (
int)this->avails.size()) new_pos = this->avail_pos - 1;
1493 this->avail_pos = new_pos;
1494 if (new_pos >= 0) this->avail_sel = this->avails[new_pos];
1510 for (
const auto &c : list) {
1513 auto ci = std::make_unique<ContentInfo>();
1519 cv.push_back(std::move(ci));
1541class NWidgetNewGRFDisplay :
public NWidgetBase {
1546 std::unique_ptr<NWidgetBase>
avs{};
1547 std::unique_ptr<NWidgetBase>
acs{};
1548 std::unique_ptr<NWidgetBase>
inf{};
1551 NWidgetNewGRFDisplay(std::unique_ptr<NWidgetBase> &&
avs, std::unique_ptr<NWidgetBase> &&
acs, std::unique_ptr<NWidgetBase> &&
inf) : NWidgetBase(
NWID_CUSTOM)
1565 this->avs->SetupSmallestSize(w);
1566 this->acs->SetupSmallestSize(w);
1567 this->inf->SetupSmallestSize(w);
1569 uint min_avs_width = this->avs->smallest_x + this->avs->padding.Horizontal();
1570 uint min_acs_width = this->acs->smallest_x + this->acs->padding.Horizontal();
1571 uint min_inf_width = this->inf->smallest_x + this->inf->padding.Horizontal();
1573 uint min_avs_height = this->avs->smallest_y + this->avs->padding.Vertical();
1574 uint min_acs_height = this->acs->smallest_y + this->acs->padding.Vertical();
1575 uint min_inf_height = this->inf->smallest_y + this->inf->padding.Vertical();
1582 this->
fill_x = std::lcm(this->avs->fill_x, this->acs->fill_x);
1583 if (this->inf->fill_x > 0 && (this->fill_x == 0 || this->fill_x > this->inf->fill_x)) this->
fill_x = this->inf->fill_x;
1585 this->
fill_y = this->avs->fill_y;
1586 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->
fill_y = std::lcm(this->
fill_y, this->inf->fill_y);
1590 this->
resize_x = std::lcm(this->avs->resize_x, this->acs->resize_x);
1591 if (this->inf->resize_x > 0 && (this->resize_x == 0 || this->resize_x > this->inf->resize_x)) this->
resize_x = this->inf->resize_x;
1593 this->
resize_y = this->avs->resize_y;
1594 if (this->acs->resize_y > 0 && (this->resize_y == 0 || this->resize_y > this->acs->resize_y)) this->
resize_y = this->acs->resize_y;
1605 uint min_avs_width = this->avs->smallest_x + this->avs->padding.Horizontal();
1606 uint min_acs_width = this->acs->smallest_x + this->acs->padding.Horizontal();
1607 uint min_inf_width = this->inf->smallest_x + this->inf->padding.Horizontal();
1609 uint min_list_width = std::max(min_avs_width, min_acs_width);
1610 uint avs_extra_width = min_list_width - min_avs_width;
1611 uint acs_extra_width = min_list_width - min_acs_width;
1619 uint extra_width, inf_width;
1620 if (use_three_columns) {
1621 extra_width = given_width - min_three_columns;
1624 extra_width = given_width - min_two_columns;
1627 inf_width =
ComputeMaxSize(this->inf->smallest_x, this->inf->smallest_x + inf_width, this->inf->GetHorizontalStepSize(sizing));
1628 extra_width -= inf_width - this->inf->smallest_x;
1630 uint inf_height =
ComputeMaxSize(this->inf->smallest_y, given_height, this->inf->GetVerticalStepSize(sizing));
1632 if (use_three_columns) {
1635 uint avs_width = std::min(avs_extra_width, extra_width);
1636 extra_width -= avs_width;
1637 extra_width -= std::min(acs_extra_width, extra_width);
1638 avs_width += extra_width / 2;
1640 avs_width =
ComputeMaxSize(this->avs->smallest_x, this->avs->smallest_x + avs_width, this->avs->GetHorizontalStepSize(sizing));
1642 uint acs_width = given_width -
1643 inf_width - this->inf->padding.Horizontal() -
1645 acs_width =
ComputeMaxSize(min_acs_width, acs_width, this->acs->GetHorizontalStepSize(sizing)) -
1646 this->acs->padding.Horizontal();
1649 uint avs_height =
ComputeMaxSize(this->avs->smallest_y, given_height, this->avs->resize_y);
1650 uint acs_height =
ComputeMaxSize(this->acs->smallest_y, given_height, this->acs->resize_y);
1654 x += this->inf->padding.left;
1655 this->inf->AssignSizePosition(sizing, x, y + this->inf->padding.top, inf_width, inf_height, rtl);
1658 x += this->avs->padding.left;
1659 this->avs->AssignSizePosition(sizing, x, y + this->avs->padding.top, avs_width, avs_height, rtl);
1663 x += this->acs->padding.left;
1664 this->acs->AssignSizePosition(sizing, x, y + this->acs->padding.top, acs_width, acs_height, rtl);
1668 x += this->avs->padding.left;
1669 this->avs->AssignSizePosition(sizing, x, y + this->avs->padding.top, avs_width, avs_height, rtl);
1671 x += this->inf->padding.left;
1672 this->inf->AssignSizePosition(sizing, x, y + this->inf->padding.top, inf_width, inf_height, rtl);
1677 uint avs_width =
ComputeMaxSize(this->avs->smallest_x, this->avs->smallest_x + avs_extra_width + extra_width,
1678 this->avs->GetHorizontalStepSize(sizing));
1679 uint acs_width =
ComputeMaxSize(this->acs->smallest_x, this->acs->smallest_x + acs_extra_width + extra_width,
1680 this->acs->GetHorizontalStepSize(sizing));
1682 uint min_avs_height = (!this->editable) ? 0 : this->avs->smallest_y + this->avs->padding.Vertical() +
WidgetDimensions::scaled.vsep_wide;
1683 uint min_acs_height = this->acs->smallest_y + this->acs->padding.Vertical();
1684 uint extra_height = given_height - min_acs_height - min_avs_height;
1687 uint avs_height =
ComputeMaxSize(this->avs->smallest_y, this->avs->smallest_y + extra_height / 2, this->avs->resize_y);
1688 if (this->editable) extra_height -= avs_height - this->avs->smallest_y;
1689 uint acs_height =
ComputeMaxSize(this->acs->smallest_y, this->acs->smallest_y + extra_height, this->acs->resize_y);
1693 x += this->inf->padding.left;
1694 this->inf->AssignSizePosition(sizing, x, y + this->inf->padding.top, inf_width, inf_height, rtl);
1697 this->acs->AssignSizePosition(sizing, x + this->acs->padding.left, y + this->acs->padding.top, acs_width, acs_height, rtl);
1698 if (this->editable) {
1699 this->avs->AssignSizePosition(sizing, x + this->avs->padding.left, y + given_height - avs_height - this->avs->padding.bottom, avs_width, avs_height, rtl);
1701 this->avs->AssignSizePosition(sizing, 0, 0, this->avs->smallest_x, this->avs->smallest_y, rtl);
1704 this->acs->AssignSizePosition(sizing, x + this->acs->padding.left, y + this->acs->padding.top, acs_width, acs_height, rtl);
1705 if (this->editable) {
1706 this->avs->AssignSizePosition(sizing, x + this->avs->padding.left, y + given_height - avs_height - this->avs->padding.bottom, avs_width, avs_height, rtl);
1708 this->avs->AssignSizePosition(sizing, 0, 0, this->avs->smallest_x, this->avs->smallest_y, rtl);
1710 uint dx = this->acs->current_x + this->acs->padding.Horizontal();
1711 if (this->editable) {
1712 dx = std::max(dx, this->avs->current_x + this->avs->padding.Horizontal());
1715 this->inf->AssignSizePosition(sizing, x, y + this->inf->padding.top, inf_width, inf_height, rtl);
1723 this->avs->FillWidgetLookup(widget_lookup);
1724 this->acs->FillWidgetLookup(widget_lookup);
1725 this->inf->FillWidgetLookup(widget_lookup);
1740 if (this->editable) this->avs->Draw(w);
1749static constexpr std::initializer_list<NWidgetPart> _nested_newgrf_actives_widgets = {
1757 SetToolTip(STR_NEWGRF_SETTINGS_PRESET_LIST_TOOLTIP),
1761 SetStringTip(STR_NEWGRF_SETTINGS_PRESET_SAVE, STR_NEWGRF_SETTINGS_PRESET_SAVE_TOOLTIP),
1763 SetStringTip(STR_NEWGRF_SETTINGS_PRESET_DELETE, STR_NEWGRF_SETTINGS_PRESET_DELETE_TOOLTIP),
1782 SetStringTip(STR_NEWGRF_SETTINGS_REMOVE, STR_NEWGRF_SETTINGS_REMOVE_TOOLTIP),
1785 SetStringTip(STR_NEWGRF_SETTINGS_MOVEUP, STR_NEWGRF_SETTINGS_MOVEUP_TOOLTIP),
1787 SetStringTip(STR_NEWGRF_SETTINGS_MOVEDOWN, STR_NEWGRF_SETTINGS_MOVEDOWN_TOOLTIP),
1790 SetStringTip(STR_NEWGRF_SETTINGS_UPGRADE, STR_NEWGRF_SETTINGS_UPGRADE_TOOLTIP),
1795 SetStringTip(STR_NEWGRF_SETTINGS_RESCAN_FILES, STR_NEWGRF_SETTINGS_RESCAN_FILES_TOOLTIP),
1797 SetStringTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
1804static constexpr std::initializer_list<NWidgetPart> _nested_newgrf_availables_widgets = {
1810 SetStringTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
1826 SetStringTip(STR_NEWGRF_SETTINGS_ADD, STR_NEWGRF_SETTINGS_ADD_FILE_TOOLTIP),
1829 SetStringTip(STR_NEWGRF_SETTINGS_RESCAN_FILES, STR_NEWGRF_SETTINGS_RESCAN_FILES_TOOLTIP),
1831 SetStringTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
1837static constexpr std::initializer_list<NWidgetPart> _nested_newgrf_infopanel_widgets = {
1849 SetStringTip(STR_CONTENT_OPEN_URL, STR_CONTENT_OPEN_URL_TOOLTIP),
1851 SetStringTip(STR_TEXTFILE_VIEW_README, STR_TEXTFILE_VIEW_README_TOOLTIP),
1855 SetStringTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_TEXTFILE_VIEW_CHANGELOG_TOOLTIP),
1857 SetStringTip(STR_TEXTFILE_VIEW_LICENCE, STR_TEXTFILE_VIEW_LICENCE_TOOLTIP),
1868 SetStringTip(STR_NEWGRF_SETTINGS_TOGGLE_PALETTE, STR_NEWGRF_SETTINGS_TOGGLE_PALETTE_TOOLTIP),
1884 std::unique_ptr<NWidgetBase> avs =
MakeNWidgets(_nested_newgrf_availables_widgets,
nullptr);
1885 std::unique_ptr<NWidgetBase> acs =
MakeNWidgets(_nested_newgrf_actives_widgets,
nullptr);
1886 std::unique_ptr<NWidgetBase> inf =
MakeNWidgets(_nested_newgrf_infopanel_widgets,
nullptr);
1888 return std::make_unique<NWidgetNewGRFDisplay>(std::move(avs), std::move(acs), std::move(inf));
1911 WindowClass::GameOptions, WindowClass::None,
1927 assert(nw !=
nullptr);
1936 int pos = nw->GetCurrentActivePosition();
1942 if (
static_cast<size_t>(pos) >= nw->
actives.size()) {
1945 auto it = std::next(std::begin(nw->
actives), pos);
1990 NWidget(
WWT_EDITBOX,
Colours::Grey,
WID_SVP_EDITBOX),
SetPadding(2, 2, 2, 2),
SetFill(1, 0),
SetResize(1, 0),
1991 SetStringTip(STR_SAVE_PRESET_TITLE, STR_SAVE_PRESET_EDITBOX_TOOLTIP),
2002 WindowClass::SavePreset, WindowClass::GameOptions,
2021 if (!initial_text.empty()) {
2022 for (uint i = 0; i < this->presets.size(); i++) {
2023 if (this->presets[i] == initial_text) {
2037 this->vscroll->
SetCount(this->presets.size());
2039 this->presetname_editbox.text.
Assign(initial_text);
2048 for (uint i = 0; i < this->presets.size(); i++) {
2052 size.
height =
ClampU((uint)this->presets.size(), 5, 20) *
resize.height + padding.height;
2070 for (
auto it = first; it != last; ++it) {
2071 int row =
static_cast<int>(std::distance(std::begin(this->presets), it));
2075 tr.top += step_height;
2087 if (it != this->presets.end()) {
2088 this->selected = it - this->presets.begin();
2089 this->presetname_editbox.text.
Assign(*it);
2099 auto text = this->presetname_editbox.text.
GetText();
2139 WindowClass::ModalProgress, WindowClass::None,
2204 this->last_name = std::move(name);
2205 this->scanned = num;
constexpr enable_if_t< is_integral_v< T >, T > byteswap(T x) noexcept
Custom implementation of std::byteswap; remove once we build with C++23.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Iterate a range of enum values.
List template of 'things' T to sort in a GUI.
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.
void SetSortFuncs(std::span< SortFunction *const > n_funcs)
Hand the sort function pointers to the GUIList.
A timeout timer will fire once after the interval.
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 ShowDropDownListAt(Window *w, DropDownList &&list, int selected, WidgetID button, Rect wi_rect, Colours wi_colour, DropDownOptions options, std::string *const persistent_filter_text)
Show a drop down list.
std::unique_ptr< DropDownListItem > MakeDropDownListStringItem(StringID str, int value, bool masked, bool shaded)
Creates new DropDownListStringItem.
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, DropDownOptions options, std::string *const persistent_filter_text)
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.
@ Filterable
Set if the dropdown is filterable.
Functions related to errors.
@ Critical
Critical errors, the MessageBox is shown in all cases.
@ Info
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
@ Error
Errors (eg. saving/loading failed).
void ShowErrorMessage(EncodedString &&summary_msg, int x, int y, CommandCost &cc)
Display an error message in a window.
@ NewGrf
Subdirectory for all NewGRFs.
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.
@ Centre
Align to the centre.
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.
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.
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.
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, ExtendedTextColour colour, Alignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
int DrawString(int left, int right, int top, std::string_view str, ExtendedTextColour colour, Alignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Dimension GetScaledSpriteSize(SpriteID sprid)
Scale sprite size for GUI.
@ Normal
Index of the normal font in the font tables.
uint32_t PaletteID
The number of the palette.
@ LightBlue
Light blue colour.
@ FromString
Marker for telling to use the colour from the string.
static const CursorID SPR_CURSOR_MOUSE
void SetDirty() const
Mark entire window as dirty (in need of re-paint).
#define Rect
Macro that prevents name conflicts between included headers.
#define Point
Macro that prevents name conflicts between included headers.
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.
std::vector< std::unique_ptr< ContentInfo > > ContentVector
Vector with content info.
void ShowNetworkContentListWindow(ContentVector *cv=nullptr, ContentType type1=ContentType::End, ContentType type2=ContentType::End)
Show the content list window with a given set of content.
Base for the NewGRF implementation.
constexpr uint32_t FlattenNewGRFLabel(T label)
Flatten a NewGRF related label to a 32 bits integer.
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.
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.
const GRFConfig * FindGRFConfig(GrfID grfid, FindGRFConfigMode mode, const MD5Hash *md5sum, uint32_t desired_version)
Find a NewGRF in the scanned list.
void ClearGRFConfigList(GRFConfigList &config)
Clear a GRF Config list, freeing all nodes.
@ NotFound
GRF file was not found in the local cache.
@ Disabled
GRF file is disabled.
@ Activated
GRF file has been activated.
@ Invalid
GRF is unusable with this version of OpenTTD.
@ Static
GRF file is used statically (can be used in any MP game).
@ Compatible
GRF file does not exactly match the requested GRF (different MD5SUM), but grfid matches).
@ UintEnum
The parameter allows a range of numbers, each of which can have a special name.
@ Bool
The parameter is either 0 or 1.
@ Exact
Only find Grfs matching md5sum.
@ NewestValid
Find newest Grf, ignoring Grfs with GRFConfigFlag::Invalid set.
@ 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.
static WindowDesc _newgrf_parameters_desc(WindowPosition::Center, "settings_newgrf_config", 500, 208, WindowClass::NewGRFParameters, WindowClass::None, {}, _nested_newgrf_parameter_widgets)
Window definition for the change grf parameters 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.
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 std::initializer_list< NWidgetPart > _nested_scan_progress_widgets
Widgets for the progress window.
static WindowDesc _save_preset_desc(WindowPosition::Center, "save_preset", 140, 110, WindowClass::SavePreset, WindowClass::GameOptions, WindowDefaultFlag::Modal, _nested_save_preset_widgets)
Window description of the preset save window.
static constexpr std::initializer_list< NWidgetPart > _nested_newgrf_widgets
Widget definition of the manage newgrfs 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_desc(WindowPosition::Center, "settings_newgrf", 300, 263, WindowClass::GameOptions, WindowClass::None, {}, _nested_newgrf_widgets)
Window definition of the manage newgrfs window.
static constexpr std::initializer_list< NWidgetPart > _nested_save_preset_widgets
Widget parts of the save preset window.
void ShowNewGRFError()
Show the first NewGRF error we can find.
static WindowDesc _scan_progress_desc(WindowPosition::Center, {}, 0, 0, WindowClass::ModalProgress, WindowClass::None, {}, _nested_scan_progress_widgets)
Description of the widgets and other settings of the window.
void ShowMissingContentWindow(const GRFConfigList &list)
Show the content list window with all missing grfs from the given list.
std::map< GrfID, const GRFConfig * > GrfIdMap
Map of grfid to the grf config.
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, Shade shade)
Get colour gradient palette index.
@ Normal
Normal colour shade.
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 SpriteID SPR_WARNING_SIGN
Warning sign (shown if there are any newgrf errors).
static const SpriteID SPR_SQUARE
Coloured square (used for newgrf compatibility).
static const PaletteID PALETTE_TO_BLUE
static const PaletteID PALETTE_TO_GREEN
static const PaletteID PALETTE_TO_RED
static const PaletteID PALETTE_TO_GREY
static const PaletteID PALETTE_TO_ORANGE
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.
static std::optional< T > ParseInteger(std::string_view arg, int base=10, bool clamp=false)
Change a string into its number representation.
Functions related to low-level strings.
@ 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.
StrongType::Typedef< uint32_t, struct StringIDTag, StrongType::Compare, StrongType::Integer > 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.
value_type height
The height of the rectangle.
value_type width
The width of the rectangle.
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(GrfID grfid, const MD5Hash *md5sum) const
Does the identification match the provided values?
GrfID 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.
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.
bool newgrf_show_old_versions
whether to show old versions in the NewGRF list
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 *item, 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.
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.
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.
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.
void CloseChildWindows(WindowClass wc=WindowClass::Invalid) const
Close all children a window might have in a head-recursive manner.
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.
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
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
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)
@ NewGRF
The content consists of a NewGRF.
Stuff related to the text buffer GUI.
GUI functions related to textfiles.
TextfileType
Additional text files accompanying Tar archives.
@ ContentBegin
This marker is used to generate the below three buttons in sequence by various of places in the code.
@ ContentEnd
This marker is used to generate the above three buttons in sequence by various of places in the code.
@ License
Content license.
@ 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).
@ Center
Center the window.
EventState
State of handling an event.
@ Handled
The passed event is handled.
@ NotHandled
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.
@ NewGRFState
NewGRF settings.
Functions related to zooming.