diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4b3bf4810d..9257a061dd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -262,6 +262,7 @@ add_files( music_gui.cpp newgrf.cpp newgrf.h + newgrf_act5.h newgrf_airport.cpp newgrf_airport.h newgrf_airporttiles.cpp diff --git a/src/ai/ai_gui.cpp b/src/ai/ai_gui.cpp index 0ae1651574..d68001e163 100644 --- a/src/ai/ai_gui.cpp +++ b/src/ai/ai_gui.cpp @@ -127,20 +127,20 @@ struct AIConfigWindow : public Window { } } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_AIC_DECREASE_NUMBER: case WID_AIC_INCREASE_NUMBER: case WID_AIC_DECREASE_INTERVAL: case WID_AIC_INCREASE_INTERVAL: - *size = maxdim(*size, NWidgetScrollbar::GetHorizontalDimension()); + size = maxdim(size, NWidgetScrollbar::GetHorizontalDimension()); break; case WID_AIC_LIST: this->line_height = GetCharacterHeight(FS_NORMAL) + padding.height; - resize->height = this->line_height; - size->height = 8 * this->line_height; + resize.height = this->line_height; + size.height = 8 * this->line_height; break; } } diff --git a/src/airport_gui.cpp b/src/airport_gui.cpp index 1746f0d5f1..7cce99c9ac 100644 --- a/src/airport_gui.cpp +++ b/src/airport_gui.cpp @@ -309,7 +309,7 @@ public: } } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_AP_CLASS_DROPDOWN: { @@ -319,7 +319,7 @@ public: } d.width += padding.width; d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } @@ -328,11 +328,11 @@ public: const AirportSpec *as = AirportSpec::Get(i); if (!as->enabled) continue; - size->width = std::max(size->width, GetStringBoundingBox(as->name).width + padding.width); + size.width = std::max(size.width, GetStringBoundingBox(as->name).width + padding.width); } this->line_height = GetCharacterHeight(FS_NORMAL) + padding.height; - size->height = 5 * this->line_height; + size.height = 5 * this->line_height; break; } @@ -346,7 +346,7 @@ public: Dimension d = GetSpriteSize(sprite); d.width += WidgetDimensions::scaled.framerect.Horizontal(); d.height += WidgetDimensions::scaled.framerect.Vertical(); - *size = maxdim(d, *size); + size = maxdim(d, size); } } } @@ -360,8 +360,8 @@ public: StringID string = GetAirportTextCallback(as, layout, CBID_AIRPORT_ADDITIONAL_TEXT); if (string == STR_UNDEFINED) continue; - Dimension d = GetStringMultiLineBoundingBox(string, *size); - *size = maxdim(d, *size); + Dimension d = GetStringMultiLineBoundingBox(string, size); + size = maxdim(d, size); } } break; diff --git a/src/autoreplace_gui.cpp b/src/autoreplace_gui.cpp index 6cfe0d8422..ecf7e0aad4 100644 --- a/src/autoreplace_gui.cpp +++ b/src/autoreplace_gui.cpp @@ -31,8 +31,6 @@ #include "safeguards.h" -void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_list, const Scrollbar &sb, EngineID selected_id, bool show_count, GroupID selected_group); - static bool EngineNumberSorter(const GUIEngineListItem &a, const GUIEngineListItem &b, const GUIEngineListSortCache &cache) { return Engine::Get(a.engine_id)->list_position < Engine::Get(b.engine_id)->list_position; @@ -112,27 +110,6 @@ class ReplaceVehicleWindow : public Window { return true; } - void AddChildren(const GUIEngineList &source, GUIEngineList &target, EngineID parent, int indent, int side) - { - for (const auto &item : source) { - if (item.variant_id != parent || item.engine_id == parent) continue; - - const Engine *e = Engine::Get(item.engine_id); - EngineDisplayFlags flags = item.flags; - if (e->display_last_variant != INVALID_ENGINE) flags &= ~EngineDisplayFlags::Shaded; - target.emplace_back(e->display_last_variant == INVALID_ENGINE ? item.engine_id : e->display_last_variant, item.engine_id, flags, indent); - - /* Add variants if not folded */ - if ((item.flags & (EngineDisplayFlags::HasVariants | EngineDisplayFlags::IsFolded)) == EngineDisplayFlags::HasVariants) { - /* Add this engine again as a child */ - if ((item.flags & EngineDisplayFlags::Shaded) == EngineDisplayFlags::None) { - target.emplace_back(item.engine_id, item.engine_id, EngineDisplayFlags::None, indent + 1); - } - AddChildren(source, target, item.engine_id, indent + 1, side); - } - } - } - /** * Generate an engines list * @param draw_left true if generating the left list, otherwise false @@ -206,7 +183,7 @@ class ReplaceVehicleWindow : public Window { this->engines[side].clear(); if (side == 1) { - AddChildren(list, this->engines[side], INVALID_ENGINE, 0, side); + GUIEngineListAddChildren(this->engines[side], list); } else { this->engines[side].swap(list); } @@ -316,26 +293,26 @@ public: this->sel_group = id_g; } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_RV_SORT_ASCENDING_DESCENDING: { Dimension d = GetStringBoundingBox(this->GetWidget(widget)->widget_data); d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better. d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } case WID_RV_LEFT_MATRIX: case WID_RV_RIGHT_MATRIX: - resize->height = GetEngineListHeight((VehicleType)this->window_number); - size->height = (this->window_number <= VEH_ROAD ? 8 : 4) * resize->height; + resize.height = GetEngineListHeight((VehicleType)this->window_number); + size.height = (this->window_number <= VEH_ROAD ? 8 : 4) * resize.height; break; case WID_RV_LEFT_DETAILS: case WID_RV_RIGHT_DETAILS: - size->height = GetCharacterHeight(FS_NORMAL) * this->details_height + padding.height; + size.height = GetCharacterHeight(FS_NORMAL) * this->details_height + padding.height; break; case WID_RV_TRAIN_WAGONREMOVE_TOGGLE: { @@ -346,7 +323,7 @@ public: d = maxdim(d, GetStringBoundingBox(str)); d.width += padding.width; d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } @@ -355,7 +332,7 @@ public: d = maxdim(d, GetStringBoundingBox(STR_REPLACE_WAGONS)); d.width += padding.width; d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } @@ -364,7 +341,7 @@ public: d = maxdim(d, GetStringBoundingBox(STR_REPLACE_NOT_REPLACING_VEHICLE_SELECTED)); d.width += padding.width; d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } @@ -375,7 +352,7 @@ public: } d.width += padding.width; d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } @@ -386,7 +363,7 @@ public: } d.width += padding.width; d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } @@ -397,7 +374,7 @@ public: } d.width += padding.width; d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } } diff --git a/src/bootstrap_gui.cpp b/src/bootstrap_gui.cpp index bedc338959..4093b9484e 100644 --- a/src/bootstrap_gui.cpp +++ b/src/bootstrap_gui.cpp @@ -96,12 +96,12 @@ public: this->Window::Close(); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { if (widget == WID_BEM_MESSAGE) { - *size = GetStringBoundingBox(STR_MISSING_GRAPHICS_ERROR); - size->width += WidgetDimensions::scaled.frametext.Horizontal(); - size->height += WidgetDimensions::scaled.frametext.Vertical(); + size = GetStringBoundingBox(STR_MISSING_GRAPHICS_ERROR); + size.width += WidgetDimensions::scaled.frametext.Horizontal(); + size.height += WidgetDimensions::scaled.frametext.Vertical(); } } @@ -210,7 +210,7 @@ public: this->Window::Close(); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { /* We cache the button size. This is safe as no reinit can happen here. */ if (this->button_size.width == 0) { @@ -222,13 +222,13 @@ public: switch (widget) { case WID_BAFD_QUESTION: /* The question is twice as wide as the buttons, and determine the height based on the width. */ - size->width = this->button_size.width * 2; - size->height = GetStringHeight(STR_MISSING_GRAPHICS_SET_MESSAGE, size->width - WidgetDimensions::scaled.frametext.Horizontal()) + WidgetDimensions::scaled.frametext.Vertical(); + size.width = this->button_size.width * 2; + size.height = GetStringHeight(STR_MISSING_GRAPHICS_SET_MESSAGE, size.width - WidgetDimensions::scaled.frametext.Horizontal()) + WidgetDimensions::scaled.frametext.Vertical(); break; case WID_BAFD_YES: case WID_BAFD_NO: - *size = this->button_size; + size = this->button_size; break; } } diff --git a/src/bridge_gui.cpp b/src/bridge_gui.cpp index 4f0ebb8afe..922277e79d 100644 --- a/src/bridge_gui.cpp +++ b/src/bridge_gui.cpp @@ -189,14 +189,14 @@ public: this->Window::Close(); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_BBS_DROPDOWN_ORDER: { Dimension d = GetStringBoundingBox(this->GetWidget(widget)->widget_data); d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better. d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } case WID_BBS_DROPDOWN_CRITERIA: { @@ -206,7 +206,7 @@ public: } d.width += padding.width; d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } case WID_BBS_BRIDGE_LIST: { @@ -216,11 +216,11 @@ public: sprite_dim = maxdim(sprite_dim, GetScaledSpriteSize(bridge_data.spec->sprite)); text_dim = maxdim(text_dim, GetStringBoundingBox(GetBridgeSelectString(bridge_data))); } - resize->height = std::max(sprite_dim.height, text_dim.height) + padding.height; // Max of both sizes + account for matrix edges. + resize.height = std::max(sprite_dim.height, text_dim.height) + padding.height; // Max of both sizes + account for matrix edges. this->icon_width = sprite_dim.width; // Width of bridge icon. - size->width = this->icon_width + WidgetDimensions::scaled.hsep_normal + text_dim.width + padding.width; - size->height = 4 * resize->height; // Smallest bridge gui is 4 entries high in the matrix. + size.width = this->icon_width + WidgetDimensions::scaled.hsep_normal + text_dim.width + padding.width; + size.height = 4 * resize.height; // Smallest bridge gui is 4 entries high in the matrix. break; } } diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index edb8531cd2..836262abb4 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -1269,6 +1269,9 @@ void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_li int small_text_y_offset = ir.Height() - GetCharacterHeight(FS_SMALL); int replace_icon_y_offset = (ir.Height() - replace_icon.height) / 2; + const int offset = (rtl ? -circle_width : circle_width) / 2; + const int level_width = rtl ? -WidgetDimensions::scaled.hsep_indent : WidgetDimensions::scaled.hsep_indent; + int y = ir.top; for (auto it = first; it != last; ++it) { const auto &item = *it; @@ -1276,6 +1279,21 @@ void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_li bool has_variants = (item.flags & EngineDisplayFlags::HasVariants) != EngineDisplayFlags::None; bool is_folded = (item.flags & EngineDisplayFlags::IsFolded) != EngineDisplayFlags::None; bool shaded = (item.flags & EngineDisplayFlags::Shaded) != EngineDisplayFlags::None; + + if (item.indent > 0) { + /* Draw tree continuation lines. */ + int tx = (rtl ? ir.right : ir.left) + offset; + int ty = y - WidgetDimensions::scaled.matrix.top; + for (uint lvl = 1; lvl <= item.indent; ++lvl) { + if (HasBit(item.level_mask, lvl)) GfxDrawLine(tx, ty, tx, ty + step_size - 1, linecolour, WidgetDimensions::scaled.fullbevel.top); + if (lvl < item.indent) tx += level_width; + } + /* Draw our node in the tree. */ + int ycentre = y + normal_text_y_offset + GetCharacterHeight(FS_NORMAL) / 2 - 1; + if (!HasBit(item.level_mask, item.indent)) GfxDrawLine(tx, ty, tx, ycentre, linecolour, WidgetDimensions::scaled.fullbevel.top); + GfxDrawLine(tx, ycentre, tx + offset - (rtl ? -1 : 1), ycentre, linecolour, WidgetDimensions::scaled.fullbevel.top); + } + /* Note: num_engines is only used in the autoreplace GUI, so it is correct to use _local_company here. */ const uint num_engines = GetGroupNumEngines(_local_company, selected_group, item.engine_id); @@ -1303,14 +1321,6 @@ void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_li Rect fr = ir.Indent(indent, rtl).WithWidth(circle_width, rtl); DrawSpriteIgnorePadding(is_folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED, PAL_NONE, {fr.left, y, fr.right, y + ir.Height() - 1}, SA_CENTER); } - if (indent > 0) { - /* Draw tree lines */ - Rect fr = ir.Indent(indent - WidgetDimensions::scaled.hsep_indent, rtl).WithWidth(circle_width, rtl); - int ycenter = y + normal_text_y_offset + GetCharacterHeight(FS_NORMAL) / 2; - bool continues = std::next(it) != std::end(eng_list) && std::next(it)->indent == item.indent; - GfxDrawLine(fr.left + circle_width / 2, y - WidgetDimensions::scaled.matrix.top, fr.left + circle_width / 2, continues ? y - WidgetDimensions::scaled.matrix.top + step_size - 1 : ycenter, linecolour, WidgetDimensions::scaled.fullbevel.top); - GfxDrawLine(fr.left + circle_width / 2, ycenter, fr.right, ycenter, linecolour, WidgetDimensions::scaled.fullbevel.top); - } y += step_size; } } @@ -1338,6 +1348,44 @@ void DisplayVehicleSortDropDown(Window *w, VehicleType vehicle_type, int selecte ShowDropDownMenu(w, _engine_sort_listing[vehicle_type], selected, button, 0, hidden_mask); } +/** + * Add children to GUI engine list to build a hierarchical tree. + * @param dst Destination list. + * @param src Source list. + * @param parent Current tree parent (set by self with recursion). + * @param indent Current tree indentation level (set by self with recursion). + */ +void GUIEngineListAddChildren(GUIEngineList &dst, const GUIEngineList &src, EngineID parent, uint8_t indent) +{ + for (const auto &item : src) { + if (item.variant_id != parent || item.engine_id == parent) continue; + + const Engine *e = Engine::Get(item.engine_id); + EngineDisplayFlags flags = item.flags; + if (e->display_last_variant != INVALID_ENGINE) flags &= ~EngineDisplayFlags::Shaded; + dst.emplace_back(e->display_last_variant == INVALID_ENGINE ? item.engine_id : e->display_last_variant, item.engine_id, flags, indent); + + /* Add variants if not folded */ + if ((item.flags & (EngineDisplayFlags::HasVariants | EngineDisplayFlags::IsFolded)) == EngineDisplayFlags::HasVariants) { + /* Add this engine again as a child */ + if ((item.flags & EngineDisplayFlags::Shaded) == EngineDisplayFlags::None) { + dst.emplace_back(item.engine_id, item.engine_id, EngineDisplayFlags::None, indent + 1); + } + GUIEngineListAddChildren(dst, src, item.engine_id, indent + 1); + } + } + + if (indent > 0 || dst.empty()) return; + + /* Hierarchy is complete, traverse in reverse to find where indentation levels continue. */ + uint16_t level_mask = 0; + for (auto it = std::rbegin(dst); std::next(it) != std::rend(dst); ++it) { + auto next_it = std::next(it); + SB(level_mask, it->indent, 1, it->indent <= next_it->indent); + next_it->level_mask = level_mask; + } +} + /** Enum referring to the Hotkeys in the build vehicle window */ enum BuildVehicleHotkeys { BVHK_FOCUS_FILTER_BOX, ///< Focus the edit box for editing the filter string @@ -1359,27 +1407,6 @@ struct BuildVehicleWindowBase : Window { this->listview_mode = (tile == INVALID_TILE) && !virtual_train_mode; } - void AddChildren(GUIEngineList &eng_list, const GUIEngineList &source, EngineID parent, int indent) - { - for (const auto &item : source) { - if (item.variant_id != parent || item.engine_id == parent) continue; - - const Engine *e = Engine::Get(item.engine_id); - EngineDisplayFlags flags = item.flags; - if (e->display_last_variant != INVALID_ENGINE) flags &= ~EngineDisplayFlags::Shaded; - eng_list.emplace_back(e->display_last_variant == INVALID_ENGINE ? item.engine_id : e->display_last_variant, item.engine_id, flags, indent); - - /* Add variants if not folded */ - if ((item.flags & (EngineDisplayFlags::HasVariants | EngineDisplayFlags::IsFolded)) == EngineDisplayFlags::HasVariants) { - /* Add this engine again as a child */ - if ((item.flags & EngineDisplayFlags::Shaded) == EngineDisplayFlags::None) { - eng_list.emplace_back(item.engine_id, item.engine_id, EngineDisplayFlags::None, indent + 1); - } - AddChildren(eng_list, source, item.engine_id, indent + 1); - } - } - } - void AddVirtualEngine(Train *toadd) { if (this->virtual_train_out == nullptr) return; @@ -1873,7 +1900,7 @@ struct BuildVehicleWindow : BuildVehicleWindowBase { default: NOT_REACHED(); case VEH_TRAIN: this->GenerateBuildTrainList(list); - AddChildren(this->eng_list, list, INVALID_ENGINE, 0); + GUIEngineListAddChildren(this->eng_list, list); this->eng_list.shrink_to_fit(); this->eng_list.RebuildDone(); return; @@ -1914,7 +1941,7 @@ struct BuildVehicleWindow : BuildVehicleWindowBase { EngList_Sort(this->eng_list, _engine_sort_functions[this->vehicle_type][this->sort_criteria]); this->eng_list.swap(list); - AddChildren(this->eng_list, list, INVALID_ENGINE, 0); + GUIEngineListAddChildren(this->eng_list, list, INVALID_ENGINE, 0); this->eng_list.shrink_to_fit(); this->eng_list.RebuildDone(); } @@ -2083,43 +2110,43 @@ struct BuildVehicleWindow : BuildVehicleWindowBase { } } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_BV_LIST: - resize->height = GetEngineListHeight(this->vehicle_type); - size->height = 3 * resize->height; - size->width = std::max(size->width, GetVehicleImageCellSize(this->vehicle_type, EIT_PURCHASE).extend_left + GetVehicleImageCellSize(this->vehicle_type, EIT_PURCHASE).extend_right + 165) + padding.width; + resize.height = GetEngineListHeight(this->vehicle_type); + size.height = 3 * resize.height; + size.width = std::max(size.width, GetVehicleImageCellSize(this->vehicle_type, EIT_PURCHASE).extend_left + GetVehicleImageCellSize(this->vehicle_type, EIT_PURCHASE).extend_right + 165) + padding.width; break; case WID_BV_PANEL: - size->height = GetCharacterHeight(FS_NORMAL) * this->details_height + padding.height; + size.height = GetCharacterHeight(FS_NORMAL) * this->details_height + padding.height; break; case WID_BV_SORT_ASCENDING_DESCENDING: { Dimension d = GetStringBoundingBox(this->GetWidget(widget)->widget_data); d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better. d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } case WID_BV_CARGO_FILTER_DROPDOWN: - size->width = std::max(size->width, GetDropDownListDimension(this->BuildCargoDropDownList()).width + padding.width); + size.width = std::max(size.width, GetDropDownListDimension(this->BuildCargoDropDownList()).width + padding.width); break; case WID_BV_BUILD: - *size = GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_BUTTON + this->vehicle_type); - *size = maxdim(*size, GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_BUY_REFIT_VEHICLE_BUTTON + this->vehicle_type)); - size->width += padding.width; - size->height += padding.height; + size = GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_BUTTON + this->vehicle_type); + size = maxdim(size, GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_BUY_REFIT_VEHICLE_BUTTON + this->vehicle_type)); + size.width += padding.width; + size.height += padding.height; break; case WID_BV_SHOW_HIDE: - *size = GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_HIDE_TOGGLE_BUTTON + this->vehicle_type); - *size = maxdim(*size, GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_SHOW_TOGGLE_BUTTON + this->vehicle_type)); - size->width += padding.width; - size->height += padding.height; + size = GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_HIDE_TOGGLE_BUTTON + this->vehicle_type); + size = maxdim(size, GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_SHOW_TOGGLE_BUTTON + this->vehicle_type)); + size.width += padding.width; + size.height += padding.height; break; } } @@ -2677,10 +2704,10 @@ struct BuildVehicleWindowTrainAdvanced final : BuildVehicleWindowBase { GUIEngineList list; this->GenerateBuildTrainList(list, this->loco, false, _sorter_loco); - AddChildren(this->loco.eng_list, list, INVALID_ENGINE, 0); + GUIEngineListAddChildren(this->loco.eng_list, list, INVALID_ENGINE, 0); this->GenerateBuildTrainList(list, this->wagon, true, _sorter_wagon); - AddChildren(this->wagon.eng_list, list, INVALID_ENGINE, 0); + GUIEngineListAddChildren(this->wagon.eng_list, list, INVALID_ENGINE, 0); this->loco.eng_list.shrink_to_fit(); this->loco.eng_list.RebuildDone(); @@ -2987,17 +3014,17 @@ struct BuildVehicleWindowTrainAdvanced final : BuildVehicleWindowBase { } } - void UpdateWidgetSize(WidgetID widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override { switch (widget) { case WID_BV_LIST_LOCO: { - resize->height = GetEngineListHeight(this->vehicle_type); - size->height = 3 * resize->height; + resize.height = GetEngineListHeight(this->vehicle_type); + size.height = 3 * resize.height; break; } case WID_BV_PANEL_LOCO: { - size->height = this->loco.details_height; + size.height = this->loco.details_height; break; } @@ -3005,18 +3032,18 @@ struct BuildVehicleWindowTrainAdvanced final : BuildVehicleWindowBase { Dimension d = GetStringBoundingBox(this->GetWidget(widget)->widget_data); d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better. d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } case WID_BV_LIST_WAGON: { - resize->height = GetEngineListHeight(this->vehicle_type); - size->height = 3 * resize->height; + resize.height = GetEngineListHeight(this->vehicle_type); + size.height = 3 * resize.height; break; } case WID_BV_PANEL_WAGON: { - size->height = this->wagon.details_height; + size.height = this->wagon.details_height; break; } @@ -3024,22 +3051,22 @@ struct BuildVehicleWindowTrainAdvanced final : BuildVehicleWindowBase { Dimension d = GetStringBoundingBox(this->GetWidget(widget)->widget_data); d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better. d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } case WID_BV_SHOW_HIDE_LOCO: // Fallthrough case WID_BV_SHOW_HIDE_WAGON: case WID_BV_COMB_SHOW_HIDE: { - *size = GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_HIDE_TOGGLE_BUTTON + this->vehicle_type); - *size = maxdim(*size, GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_SHOW_TOGGLE_BUTTON + this->vehicle_type)); - size->width += padding.width; - size->height += padding.height; + size = GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_HIDE_TOGGLE_BUTTON + this->vehicle_type); + size = maxdim(size, GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_SHOW_TOGGLE_BUTTON + this->vehicle_type)); + size.width += padding.width; + size.height += padding.height; break; } case WID_BV_RENAME_LOCO: { - *size = maxdim(*size, NWidgetLeaf::GetResizeBoxDimension()); + size = maxdim(size, NWidgetLeaf::GetResizeBoxDimension()); break; } } diff --git a/src/cheat_gui.cpp b/src/cheat_gui.cpp index 89d0761970..f2000856b8 100644 --- a/src/cheat_gui.cpp +++ b/src/cheat_gui.cpp @@ -330,7 +330,7 @@ struct CheatWindow : Window { } } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { if (widget != WID_C_PANEL) return; @@ -379,8 +379,8 @@ struct CheatWindow : Window { this->line_height = std::max(this->line_height, SETTING_BUTTON_HEIGHT); this->line_height = std::max(this->line_height, GetCharacterHeight(FS_NORMAL)) + WidgetDimensions::scaled.framerect.Vertical(); - size->width = width + WidgetDimensions::scaled.hsep_wide * 4 + this->box.width + SETTING_BUTTON_WIDTH /* stuff on the left */ + WidgetDimensions::scaled.hsep_wide * 2 /* extra spacing on right */; - size->height = WidgetDimensions::scaled.framerect.Vertical() + this->line_height * lines; + size.width = width + WidgetDimensions::scaled.hsep_wide * 4 + this->box.width + SETTING_BUTTON_WIDTH /* stuff on the left */ + WidgetDimensions::scaled.hsep_wide * 2 /* extra spacing on right */; + size.height = WidgetDimensions::scaled.framerect.Vertical() + this->line_height * lines; } void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override diff --git a/src/company_gui.cpp b/src/company_gui.cpp index 770ee8080f..12a6255931 100644 --- a/src/company_gui.cpp +++ b/src/company_gui.cpp @@ -387,29 +387,29 @@ struct CompanyFinancesWindow : Window { } } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_CF_EXPS_CATEGORY: - size->width = GetMaxCategoriesWidth(); - size->height = GetTotalCategoriesHeight(); + size.width = GetMaxCategoriesWidth(); + size.height = GetTotalCategoriesHeight(); break; case WID_CF_EXPS_PRICE1: case WID_CF_EXPS_PRICE2: case WID_CF_EXPS_PRICE3: - size->height = GetTotalCategoriesHeight(); + size.height = GetTotalCategoriesHeight(); [[fallthrough]]; case WID_CF_BALANCE_VALUE: case WID_CF_LOAN_VALUE: case WID_CF_OWN_VALUE: SetDParamMaxValue(0, this->max_money); - size->width = std::max(GetStringBoundingBox(STR_FINANCES_NEGATIVE_INCOME).width, GetStringBoundingBox(STR_FINANCES_POSITIVE_INCOME).width) + padding.width; + size.width = std::max(GetStringBoundingBox(STR_FINANCES_NEGATIVE_INCOME).width, GetStringBoundingBox(STR_FINANCES_POSITIVE_INCOME).width) + padding.width; break; case WID_CF_INTEREST_RATE: - size->height = GetCharacterHeight(FS_NORMAL); + size.height = GetCharacterHeight(FS_NORMAL); break; } } @@ -761,7 +761,7 @@ public: } } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_SCL_SPACER_DROPDOWN: { @@ -779,7 +779,7 @@ public: } } - size->width = std::max(size->width, 5 + d.width + padding.width); + size.width = std::max(size.width, 5 + d.width + padding.width); break; } @@ -788,15 +788,15 @@ public: this->square = GetSpriteSize(SPR_SQUARE); this->line_height = std::max(this->square.height, (uint)GetCharacterHeight(FS_NORMAL)) + padding.height; - size->height = 5 * this->line_height; - resize->width = 1; - resize->height = this->line_height; + size.height = 5 * this->line_height; + resize.width = 1; + resize.height = this->line_height; break; } case WID_SCL_SEC_COL_DROPDOWN: if (!_loaded_newgrf_features.has_2CC) { - size->width = 0; + size.width = 0; break; } [[fallthrough]]; @@ -805,9 +805,9 @@ public: this->square = GetSpriteSize(SPR_SQUARE); int string_padding = this->square.width + WidgetDimensions::scaled.hsep_normal + padding.width; for (Colours colour = COLOUR_BEGIN; colour != COLOUR_END; colour++) { - size->width = std::max(size->width, GetStringBoundingBox(STR_COLOUR_DARK_BLUE + colour).width + string_padding); + size.width = std::max(size.width, GetStringBoundingBox(STR_COLOUR_DARK_BLUE + colour).width + string_padding); } - size->width = std::max(size->width, GetStringBoundingBox(STR_COLOUR_DEFAULT).width + string_padding); + size.width = std::max(size.width, GetStringBoundingBox(STR_COLOUR_DEFAULT).width + string_padding); break; } } @@ -1448,31 +1448,31 @@ public: this->number_dim = number_dim; } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_SCMF_HAS_MOUSTACHE_EARRING_TEXT: - *size = maxdim(*size, GetStringBoundingBox(STR_FACE_EARRING)); - *size = maxdim(*size, GetStringBoundingBox(STR_FACE_MOUSTACHE)); + size = maxdim(size, GetStringBoundingBox(STR_FACE_EARRING)); + size = maxdim(size, GetStringBoundingBox(STR_FACE_MOUSTACHE)); break; case WID_SCMF_TIE_EARRING_TEXT: - *size = maxdim(*size, GetStringBoundingBox(STR_FACE_EARRING)); - *size = maxdim(*size, GetStringBoundingBox(STR_FACE_TIE)); + size = maxdim(size, GetStringBoundingBox(STR_FACE_EARRING)); + size = maxdim(size, GetStringBoundingBox(STR_FACE_TIE)); break; case WID_SCMF_LIPS_MOUSTACHE_TEXT: - *size = maxdim(*size, GetStringBoundingBox(STR_FACE_LIPS)); - *size = maxdim(*size, GetStringBoundingBox(STR_FACE_MOUSTACHE)); + size = maxdim(size, GetStringBoundingBox(STR_FACE_LIPS)); + size = maxdim(size, GetStringBoundingBox(STR_FACE_MOUSTACHE)); break; case WID_SCMF_FACE: - *size = maxdim(*size, GetScaledSpriteSize(SPR_GRADIENT)); + size = maxdim(size, GetScaledSpriteSize(SPR_GRADIENT)); break; case WID_SCMF_HAS_MOUSTACHE_EARRING: case WID_SCMF_HAS_GLASSES: - *size = this->yesno_dim; + size = this->yesno_dim; break; case WID_SCMF_EYECOLOUR: @@ -1485,7 +1485,7 @@ public: case WID_SCMF_COLLAR: case WID_SCMF_TIE_EARRING: case WID_SCMF_GLASSES: - *size = this->number_dim; + size = this->number_dim; break; } } @@ -1876,7 +1876,7 @@ struct CompanyInfrastructureWindow : Window } } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { const Company *c = Company::Get((CompanyID)this->window_number); @@ -1884,24 +1884,24 @@ struct CompanyInfrastructureWindow : Window case WID_CI_DESC: { uint rail_lines = 1; // Starts at 1 because a line is also required for the section title - size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_RAIL_SECT).width); + size.width = std::max(size.width, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_RAIL_SECT).width); for (const auto &rt : _sorted_railtypes) { if (HasBit(this->railtypes, rt)) { rail_lines++; - size->width = std::max(size->width, GetStringBoundingBox(GetRailTypeInfo(rt)->strings.name).width + WidgetDimensions::scaled.hsep_indent); + size.width = std::max(size.width, GetStringBoundingBox(GetRailTypeInfo(rt)->strings.name).width + WidgetDimensions::scaled.hsep_indent); } } if (this->railtypes != RAILTYPES_NONE) { rail_lines++; - size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_SIGNALS).width + WidgetDimensions::scaled.hsep_indent); + size.width = std::max(size.width, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_SIGNALS).width + WidgetDimensions::scaled.hsep_indent); } uint road_lines = 1; // Starts at 1 because a line is also required for the section title uint tram_lines = 1; - size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_ROAD_SECT).width); - size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_TRAM_SECT).width); + size.width = std::max(size.width, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_ROAD_SECT).width); + size.width = std::max(size.width, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_TRAM_SECT).width); for (const auto &rt : _sorted_roadtypes) { if (HasBit(this->roadtypes, rt)) { @@ -1910,18 +1910,18 @@ struct CompanyInfrastructureWindow : Window } else { tram_lines++; } - size->width = std::max(size->width, GetStringBoundingBox(GetRoadTypeInfo(rt)->strings.name).width + WidgetDimensions::scaled.hsep_indent); + size.width = std::max(size.width, GetStringBoundingBox(GetRoadTypeInfo(rt)->strings.name).width + WidgetDimensions::scaled.hsep_indent); } } - size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_WATER_SECT).width); - size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_CANALS).width + WidgetDimensions::scaled.hsep_indent); + size.width = std::max(size.width, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_WATER_SECT).width); + size.width = std::max(size.width, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_CANALS).width + WidgetDimensions::scaled.hsep_indent); - size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_STATION_SECT).width); - size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_STATIONS).width + WidgetDimensions::scaled.hsep_indent); - size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_AIRPORTS).width + WidgetDimensions::scaled.hsep_indent); + size.width = std::max(size.width, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_STATION_SECT).width); + size.width = std::max(size.width, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_STATIONS).width + WidgetDimensions::scaled.hsep_indent); + size.width = std::max(size.width, GetStringBoundingBox(STR_COMPANY_INFRASTRUCTURE_VIEW_AIRPORTS).width + WidgetDimensions::scaled.hsep_indent); - size->width += padding.width; + size.width += padding.width; uint total_height = ((rail_lines + road_lines + tram_lines + 2 + 3) * GetCharacterHeight(FS_NORMAL)) + (4 * WidgetDimensions::scaled.vsep_sparse); @@ -1930,9 +1930,9 @@ struct CompanyInfrastructureWindow : Window this->vscroll->SetCount(total_height); - size->height = std::max(size->height, std::min(8 * GetCharacterHeight(FS_NORMAL), total_height)); + size.height = std::max(size.height, std::min(8 * GetCharacterHeight(FS_NORMAL), total_height)); uint target_height = std::min(40 * GetCharacterHeight(FS_NORMAL), total_height); - this->height_extra = (target_height > size->height) ? (target_height - size->height) : 0; + this->height_extra = (target_height > size.height) ? (target_height - size.height) : 0; break; } @@ -1967,13 +1967,13 @@ struct CompanyInfrastructureWindow : Window if (_settings_game.economy.infrastructure_maintenance) { SetDParamMaxValue(0, this->GetTotalMaintenanceCost() * 12); // Convert to per year this->total_width = GetStringBoundingBox(EconTime::UsingWallclockUnits() ? STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_PERIOD : STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_YEAR).width + WidgetDimensions::scaled.hsep_indent * 2; - size->width = std::max(size->width, this->total_width); + size.width = std::max(size.width, this->total_width); SetDParamMaxValue(0, max_cost * 12); // Convert to per year count_width += std::max(this->total_width, GetStringBoundingBox(EconTime::UsingWallclockUnits() ? STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_PERIOD : STR_COMPANY_INFRASTRUCTURE_VIEW_TOTAL_YEAR).width); } - size->width = std::max(size->width, count_width); + size.width = std::max(size.width, count_width); break; } } @@ -2356,11 +2356,11 @@ struct CompanyWindow : Window this->DrawWidgets(); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_C_FACE: - *size = maxdim(*size, GetScaledSpriteSize(SPR_GRADIENT)); + size = maxdim(size, GetScaledSpriteSize(SPR_GRADIENT)); break; case WID_C_DESC_COLOUR_SCHEME_EXAMPLE: { @@ -2368,31 +2368,31 @@ struct CompanyWindow : Window Dimension d = GetSpriteSize(SPR_VEH_BUS_SW_VIEW, &offset); d.width -= offset.x; d.height -= offset.y; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } case WID_C_DESC_COMPANY_VALUE: SetDParam(0, INT64_MAX); // Arguably the maximum company value - size->width = GetStringBoundingBox(STR_COMPANY_VIEW_COMPANY_VALUE).width; + size.width = GetStringBoundingBox(STR_COMPANY_VIEW_COMPANY_VALUE).width; break; case WID_C_DESC_VEHICLE_COUNTS: SetDParamMaxValue(0, 5000); // Maximum number of vehicles for (uint i = 0; i < lengthof(_company_view_vehicle_count_strings); i++) { - size->width = std::max(size->width, GetStringBoundingBox(_company_view_vehicle_count_strings[i]).width + padding.width); + size.width = std::max(size.width, GetStringBoundingBox(_company_view_vehicle_count_strings[i]).width + padding.width); } break; case WID_C_DESC_INFRASTRUCTURE_COUNTS: SetDParamMaxValue(0, UINT_MAX); - size->width = GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_RAIL).width; - size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_ROAD).width); - size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_WATER).width); - size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_STATION).width); - size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_AIRPORT).width); - size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_NONE).width); - size->width += padding.width; + size.width = GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_RAIL).width; + size.width = std::max(size.width, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_ROAD).width); + size.width = std::max(size.width, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_WATER).width); + size.width = std::max(size.width, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_STATION).width); + size.width = std::max(size.width, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_AIRPORT).width); + size.width = std::max(size.width, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_NONE).width); + size.width += padding.width; break; case WID_C_DESC_OWNERS: { @@ -2400,7 +2400,7 @@ struct CompanyWindow : Window SetDParamMaxValue(0, 75); SetDParam(1, c2->index); - size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_SHARES_OWNED_BY).width); + size.width = std::max(size.width, GetStringBoundingBox(STR_COMPANY_VIEW_SHARES_OWNED_BY).width); } break; } @@ -2413,20 +2413,20 @@ struct CompanyWindow : Window case WID_C_HOSTILE_TAKEOVER: case WID_C_COMPANY_PASSWORD: case WID_C_COMPANY_JOIN: - size->width = GetStringBoundingBox(STR_COMPANY_VIEW_VIEW_HQ_BUTTON).width; - size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_BUILD_HQ_BUTTON).width); - size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_RELOCATE_HQ).width); - size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_BUTTON).width); - size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_GIVE_MONEY_BUTTON).width); - size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_HOSTILE_TAKEOVER_BUTTON).width); - size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_PASSWORD).width); - size->width = std::max(size->width, GetStringBoundingBox(STR_COMPANY_VIEW_JOIN).width); - size->width += padding.width; + size.width = GetStringBoundingBox(STR_COMPANY_VIEW_VIEW_HQ_BUTTON).width; + size.width = std::max(size.width, GetStringBoundingBox(STR_COMPANY_VIEW_BUILD_HQ_BUTTON).width); + size.width = std::max(size.width, GetStringBoundingBox(STR_COMPANY_VIEW_RELOCATE_HQ).width); + size.width = std::max(size.width, GetStringBoundingBox(STR_COMPANY_VIEW_INFRASTRUCTURE_BUTTON).width); + size.width = std::max(size.width, GetStringBoundingBox(STR_COMPANY_VIEW_GIVE_MONEY_BUTTON).width); + size.width = std::max(size.width, GetStringBoundingBox(STR_COMPANY_VIEW_HOSTILE_TAKEOVER_BUTTON).width); + size.width = std::max(size.width, GetStringBoundingBox(STR_COMPANY_VIEW_PASSWORD).width); + size.width = std::max(size.width, GetStringBoundingBox(STR_COMPANY_VIEW_JOIN).width); + size.width += padding.width; break; case WID_C_HAS_PASSWORD: - if (_networking) *size = maxdim(*size, GetSpriteSize(SPR_LOCK)); + if (_networking) size = maxdim(size, GetSpriteSize(SPR_LOCK)); break; } } @@ -2807,18 +2807,18 @@ struct BuyCompanyWindow : Window { this->Window::Close(); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_BC_FACE: - *size = GetScaledSpriteSize(SPR_GRADIENT); + size = GetScaledSpriteSize(SPR_GRADIENT); break; case WID_BC_QUESTION: const Company *c = Company::Get((CompanyID)this->window_number); SetDParam(0, c->index); SetDParam(1, this->company_value); - size->height = GetStringHeight(this->hostile_takeover ? STR_BUY_COMPANY_HOSTILE_TAKEOVER : STR_BUY_COMPANY_MESSAGE, size->width); + size.height = GetStringHeight(this->hostile_takeover ? STR_BUY_COMPANY_HOSTILE_TAKEOVER : STR_BUY_COMPANY_MESSAGE, size.width); break; } } diff --git a/src/core/math_func.hpp b/src/core/math_func.hpp index 5ddaf6b852..0b8aa7579d 100644 --- a/src/core/math_func.hpp +++ b/src/core/math_func.hpp @@ -25,7 +25,7 @@ template constexpr T abs(const T a) { - return (a < (T)0) ? -a : a; + return (a < static_cast(0)) ? -a : a; } /** @@ -41,7 +41,7 @@ constexpr T Align(const T x, uint n) { assert((n & (n - 1)) == 0 && n != 0); n--; - return (T)((x + n) & ~((T)n)); + return static_cast((x + n) & ~static_cast(n)); } /** @@ -57,8 +57,8 @@ constexpr T Align(const T x, uint n) template constexpr T *AlignPtr(T *x, uint n) { - static_assert(sizeof(size_t) == sizeof(void *)); - return reinterpret_cast(Align((size_t)x, n)); + static_assert(sizeof(uintptr_t) == sizeof(void *)); + return reinterpret_cast(Align(reinterpret_cast(x), n)); } /** @@ -254,7 +254,7 @@ constexpr T Delta(const T a, const T b) template constexpr bool IsInsideBS(const T x, const size_t base, const size_t size) { - return (size_t)(x - base) < size; + return static_cast(x - base) < size; } /** @@ -271,9 +271,9 @@ template ) { - return (size_t)(x.base() - min) < (max - min); + return static_cast(x.base() - min) < (max - min); } else { - return (size_t)(x - min) < (max - min); + return static_cast(x - min) < (max - min); } } diff --git a/src/date_gui.cpp b/src/date_gui.cpp index bb458bc47b..5489166096 100644 --- a/src/date_gui.cpp +++ b/src/date_gui.cpp @@ -106,7 +106,7 @@ struct SetDateWindow : Window { ShowDropDownList(this, std::move(list), selected, widget); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { Dimension d = {0, 0}; switch (widget) { @@ -132,7 +132,7 @@ struct SetDateWindow : Window { d.width += padding.width; d.height += padding.height; - *size = d; + size = d; } void SetStringParameters(WidgetID widget) const override @@ -225,7 +225,7 @@ struct SetMinutesWindow : SetDateWindow ShowDropDownList(this, std::move(list), selected, widget); } - virtual void UpdateWidgetSize(WidgetID widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override + virtual void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override { Dimension d = {0, 0}; switch (widget) { @@ -248,7 +248,7 @@ struct SetMinutesWindow : SetDateWindow d.width += padding.width; d.height += padding.height; - *size = d; + size = d; } virtual void SetStringParameters(WidgetID widget) const override diff --git a/src/debug.cpp b/src/debug.cpp index cbbda99dd9..31007f1499 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -82,7 +82,7 @@ struct DebugLevel { }; #define DEBUG_LEVEL(x) { #x, &_debug_##x##_level } - static const DebugLevel debug_level[] = { +static const DebugLevel _debug_levels[] = { DEBUG_LEVEL(driver), DEBUG_LEVEL(grf), DEBUG_LEVEL(map), @@ -106,7 +106,7 @@ struct DebugLevel { DEBUG_LEVEL(random), DEBUG_LEVEL(statecsum), #endif - }; +}; #undef DEBUG_LEVEL /** @@ -117,20 +117,17 @@ struct DebugLevel { */ char *DumpDebugFacilityNames(char *buf, char *last) { - size_t length = 0; - for (const DebugLevel *i = debug_level; i != endof(debug_level); ++i) { - if (length == 0) { + bool written = false; + for (const auto &debug_level : _debug_levels) { + if (!written) { buf = strecpy(buf, "List of debug facility names:\n", last); } else { buf = strecpy(buf, ", ", last); - length += 2; } - buf = strecpy(buf, i->name, last); - length += strlen(i->name); - } - if (length > 0) { - buf = strecpy(buf, "\n\n", last); + buf = strecpy(buf, debug_level.name, last); + written = true; } + buf = strecpy(buf, "\n\n", last); return buf; } @@ -243,13 +240,11 @@ void SetDebugString(const char *s, void (*error_func)(const char *)) /* Global debugging level? */ if (*s >= '0' && *s <= '9') { - const DebugLevel *i; - v = std::strtoul(s, &end, 0); s = end; - for (i = debug_level; i != endof(debug_level); ++i) { - new_levels[i->name] = v; + for (const auto &debug_level : _debug_levels) { + new_levels[debug_level.name] = v; } } @@ -264,9 +259,9 @@ void SetDebugString(const char *s, void (*error_func)(const char *)) /* check debugging levels */ const DebugLevel *found = nullptr; - for (const DebugLevel *i = debug_level; i != endof(debug_level); ++i) { - if (s == t + strlen(i->name) && strncmp(t, i->name, s - t) == 0) { - found = i; + for (const auto &debug_level : _debug_levels) { + if (s == t + strlen(debug_level.name) && strncmp(t, debug_level.name, s - t) == 0) { + found = &debug_level; break; } } @@ -285,10 +280,10 @@ void SetDebugString(const char *s, void (*error_func)(const char *)) } /* Apply the changes after parse is successful */ - for (const DebugLevel *i = debug_level; i != endof(debug_level); ++i) { - const auto &nl = new_levels.find(i->name); + for (const auto &debug_level : _debug_levels) { + const auto &nl = new_levels.find(debug_level.name); if (nl != new_levels.end()) { - *i->level = nl->second; + *debug_level.level = nl->second; } } } @@ -301,8 +296,8 @@ void SetDebugString(const char *s, void (*error_func)(const char *)) std::string GetDebugString() { std::string result; - for (size_t i = 0; i < lengthof(debug_level); i++) { - result += stdstr_fmt("%s%s=%d", i == 0 ? "" : ", ", debug_level[i].name, *(debug_level[i].level)); + for (const auto &debug_level : _debug_levels) { + result += stdstr_fmt("%s%s=%d", result.empty() ? "" : ", ", debug_level.name, *(debug_level.level)); } return result; } diff --git a/src/departures_gui.cpp b/src/departures_gui.cpp index 03fc6711c6..b840cf1b40 100644 --- a/src/departures_gui.cpp +++ b/src/departures_gui.cpp @@ -302,13 +302,13 @@ public: } } - virtual void UpdateWidgetSize(WidgetID widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override + virtual void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override { switch (widget) { case WID_DB_LIST: - resize->height = DeparturesWindow::entry_height; - size->height = 2 * resize->height; - size->width = this->min_width; + resize.height = DeparturesWindow::entry_height; + size.height = 2 * resize.height; + size.width = this->min_width; break; } } diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp index 595f13fc0b..02bf04f220 100644 --- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -655,7 +655,7 @@ struct DepotWindow : Window { this->flag_size = maxdim(GetScaledSpriteSize(SPR_FLAG_VEH_STOPPED), GetScaledSpriteSize(SPR_FLAG_VEH_RUNNING)); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_D_MATRIX: { @@ -681,18 +681,18 @@ struct DepotWindow : Window { } int base_width = this->count_width + this->header_width + padding.width; - resize->height = std::max(this->cell_size.height, min_height + padding.height); + resize.height = std::max(this->cell_size.height, min_height + padding.height); if (this->type == VEH_TRAIN) { - resize->width = 1; - size->width = base_width + 2 * ScaleSpriteTrad(29); // about 2 parts - size->height = resize->height * 6; + resize.width = 1; + size.width = base_width + 2 * ScaleSpriteTrad(29); // about 2 parts + size.height = resize.height * 6; } else { - resize->width = base_width + this->cell_size.extend_left + this->cell_size.extend_right; - size->width = resize->width * (this->type == VEH_ROAD ? 5 : 3); - size->height = resize->height * (this->type == VEH_ROAD ? 5 : 3); + resize.width = base_width + this->cell_size.extend_left + this->cell_size.extend_right; + size.width = resize.width * (this->type == VEH_ROAD ? 5 : 3); + size.height = resize.height * (this->type == VEH_ROAD ? 5 : 3); } - fill->width = resize->width; - fill->height = resize->height; + fill.width = resize.width; + fill.height = resize.height; break; } } diff --git a/src/dock_gui.cpp b/src/dock_gui.cpp index 55f574a688..251e113528 100644 --- a/src/dock_gui.cpp +++ b/src/dock_gui.cpp @@ -529,13 +529,13 @@ public: UpdateDocksDirection(); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_BDD_X: case WID_BDD_Y: - size->width = ScaleGUITrad(96) + WidgetDimensions::scaled.fullbevel.Horizontal(); - size->height = ScaleGUITrad(64) + WidgetDimensions::scaled.fullbevel.Vertical(); + size.width = ScaleGUITrad(96) + WidgetDimensions::scaled.fullbevel.Horizontal(); + size.height = ScaleGUITrad(64) + WidgetDimensions::scaled.fullbevel.Vertical(); break; } } diff --git a/src/dropdown.cpp b/src/dropdown.cpp index 5861bd7283..c0f3f58da4 100644 --- a/src/dropdown.cpp +++ b/src/dropdown.cpp @@ -203,9 +203,9 @@ struct DropdownWindow : Window { if (this->position.y < button_rect.top && list_dim.height > widget_dim.height) this->vscroll->UpdatePosition(INT_MAX); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { - if (widget == WID_DM_ITEMS) *size = this->items_dim; + if (widget == WID_DM_ITEMS) size = this->items_dim; } Point OnInitialPosition([[maybe_unused]] int16_t sm_width, [[maybe_unused]] int16_t sm_height, [[maybe_unused]] int window_number) override diff --git a/src/engine_gui.cpp b/src/engine_gui.cpp index 3488b00cfd..374a39be3a 100644 --- a/src/engine_gui.cpp +++ b/src/engine_gui.cpp @@ -77,7 +77,7 @@ struct EnginePreviewWindow : Window { this->flags |= WF_STICKY; } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { if (widget != WID_EP_QUESTION) return; @@ -97,11 +97,11 @@ struct EnginePreviewWindow : Window { } this->vehicle_space = std::max(ScaleSpriteTrad(40), y - y_offs); - size->width = std::max(size->width, x + std::abs(x_offs)); + size.width = std::max(size.width, x + std::abs(x_offs)); SetDParam(0, GetEngineCategoryName(engine)); - size->height = GetStringHeight(STR_ENGINE_PREVIEW_MESSAGE, size->width) + WidgetDimensions::scaled.vsep_wide + GetCharacterHeight(FS_NORMAL) + this->vehicle_space; + size.height = GetStringHeight(STR_ENGINE_PREVIEW_MESSAGE, size.width) + WidgetDimensions::scaled.vsep_wide + GetCharacterHeight(FS_NORMAL) + this->vehicle_space; SetDParam(0, engine); - size->height += GetStringHeight(GetEngineInfoString(engine), size->width); + size.height += GetStringHeight(GetEngineInfoString(engine), size.width); } void DrawWidget(const Rect &r, WidgetID widget) const override diff --git a/src/engine_gui.h b/src/engine_gui.h index 0308c8b074..eb74cc2c70 100644 --- a/src/engine_gui.h +++ b/src/engine_gui.h @@ -11,6 +11,7 @@ #define ENGINE_GUI_H #include "engine_type.h" +#include "group_type.h" #include "sortlist_type.h" #include "gfx_type.h" #include "vehicle_type.h" @@ -40,9 +41,10 @@ struct GUIEngineListItem { EngineID engine_id; ///< Engine to display in build purchase list EngineID variant_id; ///< Variant group of the engine. EngineDisplayFlags flags; ///< Flags for toggling/drawing (un)folded status and controlling indentation. - int8_t indent; ///< Display indentation level. + uint8_t indent; ///< Display indentation level. + uint16_t level_mask; ///< Mask of level continuations. - GUIEngineListItem(EngineID engine_id, EngineID variant_id, EngineDisplayFlags flags, int indent) : engine_id(engine_id), variant_id(variant_id), flags(flags), indent(indent) {} + GUIEngineListItem(EngineID engine_id, EngineID variant_id, EngineDisplayFlags flags, uint8_t indent) : engine_id(engine_id), variant_id(variant_id), flags(flags), indent(indent), level_mask(0) {} /* Used when searching list only by engine_id. */ bool operator == (const EngineID &other) const { return this->engine_id == other; } @@ -70,7 +72,10 @@ extern bool _engine_sort_show_hidden_engines[]; extern const StringID _engine_sort_listing[][14]; extern EngList_SortTypeFunction * const _engine_sort_functions[][13]; +/* Functions in build_vehicle_gui.cpp */ uint GetEngineListHeight(VehicleType type); void DisplayVehicleSortDropDown(Window *w, VehicleType vehicle_type, int selected, WidgetID button); +void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_list, const class Scrollbar &sb, EngineID selected_id, bool show_count, GroupID selected_group); +void GUIEngineListAddChildren(GUIEngineList &dst, const GUIEngineList &src, EngineID parent = INVALID_ENGINE, uint8_t indent = 0); #endif /* ENGINE_GUI_H */ diff --git a/src/error_gui.cpp b/src/error_gui.cpp index b0de15bd16..0cf695ebca 100644 --- a/src/error_gui.cpp +++ b/src/error_gui.cpp @@ -178,27 +178,28 @@ public: this->InitNested(); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_EM_MESSAGE: { CopyInDParam(this->params); if (this->textref_stack_size > 0) StartTextRefStackUsage(this->textref_stack_grffile, this->textref_stack_size, this->textref_stack); - this->height_summary = GetStringHeight(this->summary_msg, size->width); - this->height_detailed = (this->detailed_msg == INVALID_STRING_ID) ? 0 : GetStringHeight(this->detailed_msg, size->width); - this->height_extra = (this->extra_msg == INVALID_STRING_ID) ? 0 : GetStringHeight(this->extra_msg, size->width); + this->height_summary = GetStringHeight(this->summary_msg, size.width); + this->height_detailed = (this->detailed_msg == INVALID_STRING_ID) ? 0 : GetStringHeight(this->detailed_msg, size.width); + this->height_extra = (this->extra_msg == INVALID_STRING_ID) ? 0 : GetStringHeight(this->extra_msg, size.width); if (this->textref_stack_size > 0) StopTextRefStackUsage(); uint panel_height = this->height_summary; if (this->detailed_msg != INVALID_STRING_ID) panel_height += this->height_detailed + WidgetDimensions::scaled.vsep_wide; if (this->extra_msg != INVALID_STRING_ID) panel_height += this->height_extra + WidgetDimensions::scaled.vsep_wide; - size->height = std::max(size->height, panel_height); + + size.height = std::max(size.height, panel_height); break; } case WID_EM_FACE: - *size = maxdim(*size, GetScaledSpriteSize(SPR_GRADIENT)); + size = maxdim(size, GetScaledSpriteSize(SPR_GRADIENT)); break; } } @@ -343,7 +344,7 @@ void ShowFirstError() */ void UnshowCriticalError() { - ErrmsgWindow *w = (ErrmsgWindow*)FindWindowById(WC_ERRMSG, 0); + ErrmsgWindow *w = dynamic_cast(FindWindowById(WC_ERRMSG, 0)); if (_window_system_initialized && w != nullptr) { if (w->IsCritical()) _error_list.push_front(*w); _window_system_initialized = false; @@ -399,7 +400,7 @@ void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel ErrorMessageData data(summary_msg, detailed_msg, no_timeout ? 0 : _settings_client.gui.errmsg_duration, x, y, textref_stack_grffile, textref_stack_size, textref_stack, extra_msg); data.CopyOutDParams(); - ErrmsgWindow *w = (ErrmsgWindow*)FindWindowById(WC_ERRMSG, 0); + ErrmsgWindow *w = dynamic_cast(FindWindowById(WC_ERRMSG, 0)); if (w != nullptr) { if (w->IsCritical()) { /* A critical error is currently shown. */ @@ -423,7 +424,7 @@ void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel */ bool HideActiveErrorMessage() { - ErrmsgWindow *w = (ErrmsgWindow*)FindWindowById(WC_ERRMSG, 0); + ErrmsgWindow *w = dynamic_cast(FindWindowById(WC_ERRMSG, 0)); if (w == nullptr) return false; w->Close(); return true; diff --git a/src/fios_gui.cpp b/src/fios_gui.cpp index 877688d3e1..2a10a046de 100644 --- a/src/fios_gui.cpp +++ b/src/fios_gui.cpp @@ -586,23 +586,23 @@ public: } } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_SL_BACKGROUND: - size->height = 2 * GetCharacterHeight(FS_NORMAL) + padding.height; + size.height = 2 * GetCharacterHeight(FS_NORMAL) + padding.height; break; case WID_SL_DRIVES_DIRECTORIES_LIST: - resize->height = GetCharacterHeight(FS_NORMAL); - size->height = resize->height * 10 + padding.height; + resize.height = GetCharacterHeight(FS_NORMAL); + size.height = resize.height * 10 + padding.height; break; case WID_SL_SORT_BYNAME: case WID_SL_SORT_BYDATE: { Dimension d = GetStringBoundingBox(this->GetWidget(widget)->widget_data); d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better. d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } } diff --git a/src/framerate_gui.cpp b/src/framerate_gui.cpp index f98faff96b..e96bc7cdbd 100644 --- a/src/framerate_gui.cpp +++ b/src/framerate_gui.cpp @@ -535,32 +535,32 @@ struct FramerateWindow : Window { } } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_FRW_RATE_GAMELOOP: SetDParam(0, STR_FRAMERATE_FPS_GOOD); SetDParam(1, 999999); SetDParam(2, 2); - *size = GetStringBoundingBox(STR_FRAMERATE_RATE_GAMELOOP); + size = GetStringBoundingBox(STR_FRAMERATE_RATE_GAMELOOP); break; case WID_FRW_RATE_DRAWING: SetDParam(0, STR_FRAMERATE_FPS_GOOD); SetDParam(1, 999999); SetDParam(2, 2); - *size = GetStringBoundingBox(STR_FRAMERATE_RATE_BLITTER); + size = GetStringBoundingBox(STR_FRAMERATE_RATE_BLITTER); break; case WID_FRW_RATE_FACTOR: SetDParam(0, 999999); SetDParam(1, 2); - *size = GetStringBoundingBox(STR_FRAMERATE_SPEED_FACTOR); + size = GetStringBoundingBox(STR_FRAMERATE_SPEED_FACTOR); break; case WID_FRW_TIMES_NAMES: { - size->width = 0; - size->height = GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal + MIN_ELEMENTS * GetCharacterHeight(FS_NORMAL); - resize->width = 0; - resize->height = GetCharacterHeight(FS_NORMAL); + size.width = 0; + size.height = GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal + MIN_ELEMENTS * GetCharacterHeight(FS_NORMAL); + resize.width = 0; + resize.height = GetCharacterHeight(FS_NORMAL); for (PerformanceElement e : DISPLAY_ORDER_PFE) { if (_pf_data[e].num_valid == 0) continue; Dimension line_size; @@ -571,7 +571,7 @@ struct FramerateWindow : Window { SetDParamStr(1, GetAIName(e - PFE_AI0)); line_size = GetStringBoundingBox(STR_FRAMERATE_AI); } - size->width = std::max(size->width, line_size.width); + size.width = std::max(size.width, line_size.width); } break; } @@ -579,14 +579,14 @@ struct FramerateWindow : Window { case WID_FRW_TIMES_CURRENT: case WID_FRW_TIMES_AVERAGE: case WID_FRW_ALLOCSIZE: { - *size = GetStringBoundingBox(STR_FRAMERATE_CURRENT + (widget - WID_FRW_TIMES_CURRENT)); + size = GetStringBoundingBox(STR_FRAMERATE_CURRENT + (widget - WID_FRW_TIMES_CURRENT)); SetDParam(0, 999999); SetDParam(1, 2); Dimension item_size = GetStringBoundingBox(STR_FRAMERATE_MS_GOOD); - size->width = std::max(size->width, item_size.width); - size->height += GetCharacterHeight(FS_NORMAL) * MIN_ELEMENTS + WidgetDimensions::scaled.vsep_normal; - resize->width = 0; - resize->height = GetCharacterHeight(FS_NORMAL); + size.width = std::max(size.width, item_size.width); + size.height += GetCharacterHeight(FS_NORMAL) * MIN_ELEMENTS + WidgetDimensions::scaled.vsep_normal; + resize.width = 0; + resize.height = GetCharacterHeight(FS_NORMAL); break; } } @@ -776,7 +776,7 @@ struct FrametimeGraphWindow : Window { } } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { if (widget == WID_FGW_GRAPH) { SetDParam(0, 100); @@ -788,10 +788,10 @@ struct FrametimeGraphWindow : Window { graph_size.height = std::max(100u, 10 * (size_ms_label.height + 1)); /* Always 2:1 graph area */ graph_size.width = 2 * graph_size.height; - *size = graph_size; + size = graph_size; - size->width += size_ms_label.width + 2; - size->height += size_s_label.height + 2; + size.width += size_ms_label.width + 2; + size.height += size_s_label.height + 2; } } @@ -813,8 +813,8 @@ struct FrametimeGraphWindow : Window { { TIMESTAMP_PRECISION * 3, 4 }, { TIMESTAMP_PRECISION * 1, 2 }, }; - for (const ScaleDef *sc = hscales; sc < hscales + lengthof(hscales); sc++) { - if (range < sc->range) this->horizontal_scale = sc->scale; + for (const auto &sc : hscales) { + if (range < sc.range) this->horizontal_scale = sc.scale; } } @@ -832,8 +832,8 @@ struct FrametimeGraphWindow : Window { TIMESTAMP_PRECISION / 50, TIMESTAMP_PRECISION / 200, }; - for (const TimingMeasurement *sc = vscales; sc < vscales + lengthof(vscales); sc++) { - if (range < *sc) this->vertical_scale = (int)*sc; + for (const auto &sc : vscales) { + if (range < sc) this->vertical_scale = (int)sc; } } @@ -1066,11 +1066,11 @@ void ConPrintFramerate() bool printed_anything = false; - for (const PerformanceElement *e = rate_elements; e < rate_elements + lengthof(rate_elements); e++) { - auto &pf = _pf_data[*e]; + for (const auto &e : rate_elements) { + auto &pf = _pf_data[e]; if (pf.num_valid == 0) continue; IConsolePrint(TC_GREEN, "{} rate: {:.2f}fps (expected: {:.2f}fps)", - MEASUREMENT_NAMES[*e], + MEASUREMENT_NAMES[e], pf.GetRate(), pf.expected_rate); printed_anything = true; diff --git a/src/game/game_gui.cpp b/src/game/game_gui.cpp index 4fa6b18279..5f096fb51a 100644 --- a/src/game/game_gui.cpp +++ b/src/game/game_gui.cpp @@ -143,19 +143,19 @@ struct GSConfigWindow : public Window { this->vscroll->SetCount(this->visible_settings.size()); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_GSC_SETTINGS: this->line_height = std::max(SETTING_BUTTON_HEIGHT, GetCharacterHeight(FS_NORMAL)) + padding.height; - resize->width = 1; - resize->height = this->line_height; - size->height = 5 * this->line_height; + resize.width = 1; + resize.height = this->line_height; + size.height = 5 * this->line_height; break; case WID_GSC_GSLIST: this->line_height = GetCharacterHeight(FS_NORMAL) + padding.height; - size->height = 1 * this->line_height; + size.height = 1 * this->line_height; break; } } diff --git a/src/genworld_gui.cpp b/src/genworld_gui.cpp index bcd125dfe0..ce5d85384c 100644 --- a/src/genworld_gui.cpp +++ b/src/genworld_gui.cpp @@ -644,15 +644,15 @@ struct GenerateLandscapeWindow : public Window { this->SetDirty(); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { Dimension d{0, (uint)GetCharacterHeight(FS_NORMAL)}; const StringID *strs = nullptr; switch (widget) { case WID_GL_TEMPERATE: case WID_GL_ARCTIC: case WID_GL_TROPICAL: case WID_GL_TOYLAND: - size->width += WidgetDimensions::scaled.fullbevel.Horizontal(); - size->height += WidgetDimensions::scaled.fullbevel.Vertical(); + size.width += WidgetDimensions::scaled.fullbevel.Horizontal(); + size.height += WidgetDimensions::scaled.fullbevel.Vertical(); break; case WID_GL_HEIGHTMAP_HEIGHT_TEXT: @@ -683,12 +683,12 @@ struct GenerateLandscapeWindow : public Window { case WID_GL_SNOW_LEVEL_TEXT: SetDParamMaxValue(0, MAX_TILE_HEIGHT); - *size = maxdim(*size, GetStringBoundingBox(STR_JUST_INT)); + size = maxdim(size, GetStringBoundingBox(STR_JUST_INT)); break; case WID_GL_RAINFOREST_LEVEL_TEXT: SetDParamMaxValue(0, MAX_RAINFOREST_HEIGHT); - *size = maxdim(*size, GetStringBoundingBox(STR_JUST_INT)); + size = maxdim(size, GetStringBoundingBox(STR_JUST_INT)); break; case WID_GL_HEIGHTMAP_SIZE_TEXT: @@ -737,7 +737,7 @@ struct GenerateLandscapeWindow : public Window { break; case WID_GL_HEIGHTMAP_NAME_TEXT: - size->width = 0; + size.width = 0; break; default: @@ -750,7 +750,7 @@ struct GenerateLandscapeWindow : public Window { } d.width += padding.width; d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); } void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override @@ -1271,14 +1271,14 @@ struct CreateScenarioWindow : public Window this->DrawWidgets(); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { StringID str = STR_JUST_INT; switch (widget) { case WID_CS_TEMPERATE: case WID_CS_ARCTIC: case WID_CS_TROPICAL: case WID_CS_TOYLAND: - size->width += WidgetDimensions::scaled.fullbevel.Horizontal(); - size->height += WidgetDimensions::scaled.fullbevel.Vertical(); + size.width += WidgetDimensions::scaled.fullbevel.Horizontal(); + size.height += WidgetDimensions::scaled.fullbevel.Vertical(); break; case WID_CS_START_DATE_TEXT: @@ -1301,7 +1301,7 @@ struct CreateScenarioWindow : public Window Dimension d = GetStringBoundingBox(str); d.width += padding.width; d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); } void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override @@ -1560,23 +1560,23 @@ struct GenerateProgressWindow : public Window { } } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_GP_PROGRESS_BAR: { SetDParamMaxValue(0, 100); - *size = GetStringBoundingBox(STR_GENERATION_PROGRESS); + size = GetStringBoundingBox(STR_GENERATION_PROGRESS); /* We need some spacing for the 'border' */ - size->height += WidgetDimensions::scaled.frametext.Horizontal(); - size->width += WidgetDimensions::scaled.frametext.Vertical(); + size.height += WidgetDimensions::scaled.frametext.Horizontal(); + size.width += WidgetDimensions::scaled.frametext.Vertical(); break; } case WID_GP_PROGRESS_TEXT: for (uint i = 0; i < GWP_CLASS_COUNT; i++) { - size->width = std::max(size->width, GetStringBoundingBox(_generation_class_table[i]).width + padding.width); + size.width = std::max(size.width, GetStringBoundingBox(_generation_class_table[i]).width + padding.width); } - size->height = GetCharacterHeight(FS_NORMAL) * 2 + WidgetDimensions::scaled.vsep_normal; + size.height = GetCharacterHeight(FS_NORMAL) * 2 + WidgetDimensions::scaled.vsep_normal; break; } } diff --git a/src/goal_gui.cpp b/src/goal_gui.cpp index def02cf583..535c51357c 100644 --- a/src/goal_gui.cpp +++ b/src/goal_gui.cpp @@ -168,18 +168,18 @@ struct GoalListWindow : public Window { return num; } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { if (widget != WID_GOAL_LIST) return; Dimension d = GetStringBoundingBox(STR_GOALS_NONE); - resize->width = 1; - resize->height = d.height; + resize.width = 1; + resize.height = d.height; d.height *= 5; d.width += WidgetDimensions::scaled.framerect.Horizontal(); d.height += WidgetDimensions::scaled.framerect.Vertical(); - *size = maxdim(*size, d); + size = maxdim(size, d); } /** @@ -388,12 +388,12 @@ struct GoalQuestionWindow : public Window { } } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { if (widget != WID_GQ_QUESTION) return; SetDParamStr(0, this->question); - size->height = GetStringHeight(STR_JUST_RAW_STRING, size->width); + size.height = GetStringHeight(STR_JUST_RAW_STRING, size.width); } void DrawWidget(const Rect &r, WidgetID widget) const override diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp index e7cbc878fa..6c3471639e 100644 --- a/src/graph_gui.cpp +++ b/src/graph_gui.cpp @@ -539,7 +539,7 @@ protected: } public: - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { if (widget != WID_GRAPH_GRAPH) return; @@ -570,9 +570,9 @@ public: SetDParam(1, INT64_MAX); uint y_label_width = GetStringBoundingBox(STR_GRAPH_Y_LABEL).width; - size->width = std::max(size->width, ScaleGUITrad(5) + y_label_width + this->num_vert_lines * (x_label_width + ScaleGUITrad(5)) + ScaleGUITrad(9)); - size->height = std::max(size->height, ScaleGUITrad(5) + (1 + MIN_GRAPH_NUM_LINES_Y * 2 + (this->draw_dates ? 3 : 1)) * GetCharacterHeight(FS_SMALL) + ScaleGUITrad(4)); - size->height = std::max(size->height, size->width / 3); + size.width = std::max(size.width, ScaleGUITrad(5) + y_label_width + this->num_vert_lines * (x_label_width + ScaleGUITrad(5)) + ScaleGUITrad(9)); + size.height = std::max(size.height, ScaleGUITrad(5) + (1 + MIN_GRAPH_NUM_LINES_Y * 2 + (this->draw_dates ? 3 : 1)) * GetCharacterHeight(FS_SMALL) + ScaleGUITrad(4)); + size.height = std::max(size.height, size.width / 3); } void DrawWidget(const Rect &r, WidgetID widget) const override @@ -805,7 +805,7 @@ struct ExcludingCargoBaseGraphWindow : BaseGraphWindow { this->legend_width = (GetCharacterHeight(FS_SMALL) - ScaleGUITrad(1)) * 9 / 6; } - virtual void UpdateWidgetSize(WidgetID widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override + virtual void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override { if (widget != WID_ECBG_MATRIX) { BaseGraphWindow::UpdateWidgetSize(widget, size, padding, fill, resize); @@ -818,13 +818,13 @@ struct ExcludingCargoBaseGraphWindow : BaseGraphWindow { d.width += this->legend_width + WidgetDimensions::scaled.hsep_normal; // colour field d.width += WidgetDimensions::scaled.framerect.Horizontal(); d.height += WidgetDimensions::scaled.framerect.Vertical(); - *size = maxdim(d, *size); + size = maxdim(d, size); } - this->line_height = size->height; - size->height = this->line_height * 11; /* Default number of cargo types in most climates. */ - resize->width = 0; - resize->height = this->line_height; + this->line_height = size.height; + size.height = this->line_height * 11; /* Default number of cargo types in most climates. */ + resize.width = 0; + resize.height = this->line_height; } virtual void DrawWidget(const Rect &r, WidgetID widget) const override @@ -1353,14 +1353,14 @@ struct PaymentRatesGraphWindow : BaseGraphWindow { } } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { if (widget != WID_CPR_MATRIX) { BaseGraphWindow::UpdateWidgetSize(widget, size, padding, fill, resize); return; } - size->height = GetCharacterHeight(FS_SMALL) + WidgetDimensions::scaled.framerect.Vertical(); + size.height = GetCharacterHeight(FS_SMALL) + WidgetDimensions::scaled.framerect.Vertical(); for (const CargoSpec *cs : _sorted_standard_cargo_specs) { SetDParam(0, cs->name); @@ -1368,13 +1368,13 @@ struct PaymentRatesGraphWindow : BaseGraphWindow { d.width += this->legend_width + WidgetDimensions::scaled.hsep_normal; // colour field d.width += WidgetDimensions::scaled.framerect.Horizontal(); d.height += WidgetDimensions::scaled.framerect.Vertical(); - *size = maxdim(d, *size); + size = maxdim(d, size); } - this->line_height = size->height; - size->height = this->line_height * 11; /* Default number of cargo types in most climates. */ - resize->width = 0; - resize->height = this->line_height; + this->line_height = size.height; + size.height = this->line_height * 11; /* Default number of cargo types in most climates. */ + resize.width = 0; + resize.height = this->line_height; } void DrawWidget(const Rect &r, WidgetID widget) const override @@ -1619,12 +1619,12 @@ struct PerformanceRatingDetailWindow : Window { uint score_detail_left; uint score_detail_right; - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_PRD_SCORE_FIRST: this->bar_height = GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.fullbevel.Vertical(); - size->height = this->bar_height + WidgetDimensions::scaled.matrix.Vertical(); + size.height = this->bar_height + WidgetDimensions::scaled.matrix.Vertical(); uint score_info_width = 0; for (uint i = SCORE_BEGIN; i < SCORE_END; i++) { @@ -1660,9 +1660,9 @@ struct PerformanceRatingDetailWindow : Window { SetDParam(1, max); uint score_detail_width = GetStringBoundingBox(STR_PERFORMANCE_DETAIL_AMOUNT_CURRENCY).width; - size->width = WidgetDimensions::scaled.frametext.Horizontal() + score_info_width + WidgetDimensions::scaled.hsep_wide + this->bar_width + WidgetDimensions::scaled.hsep_wide + score_detail_width; + size.width = WidgetDimensions::scaled.frametext.Horizontal() + score_info_width + WidgetDimensions::scaled.hsep_wide + this->bar_width + WidgetDimensions::scaled.hsep_wide + score_detail_width; uint left = WidgetDimensions::scaled.frametext.left; - uint right = size->width - WidgetDimensions::scaled.frametext.right; + uint right = size.width - WidgetDimensions::scaled.frametext.right; bool rtl = _current_text_dir == TD_RTL; this->score_info_left = rtl ? right - score_info_width : left; @@ -1942,7 +1942,7 @@ struct StationCargoGraphWindow final : BaseGraphWindow { } } - void UpdateWidgetSize(WidgetID widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override { if (widget < WID_SCG_MATRIX) { BaseGraphWindow::UpdateWidgetSize(widget, size, padding, fill, resize); @@ -1955,13 +1955,13 @@ struct StationCargoGraphWindow final : BaseGraphWindow { d.width += this->legend_width + 4; // color field d.width += WidgetDimensions::scaled.framerect.Horizontal(); d.height += WidgetDimensions::scaled.framerect.Vertical(); - *size = maxdim(d, *size); + size = maxdim(d, size); } - this->line_height = size->height; - size->height = this->line_height * 11; /* Default number of cargo types in most climates. */ - resize->width = 0; - resize->height = this->line_height; + this->line_height = size.height; + size.height = this->line_height * 11; /* Default number of cargo types in most climates. */ + resize.width = 0; + resize.height = this->line_height; } void DrawWidget(const Rect &r, WidgetID widget) const override diff --git a/src/group_gui.cpp b/src/group_gui.cpp index 2795fea5fc..71435048a3 100644 --- a/src/group_gui.cpp +++ b/src/group_gui.cpp @@ -491,54 +491,54 @@ public: this->Window::Close(); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_GL_LIST_GROUP: - size->width = this->ComputeGroupInfoSize(); - resize->height = this->tiny_step_height; - fill->height = this->tiny_step_height; + size.width = this->ComputeGroupInfoSize(); + resize.height = this->tiny_step_height; + fill.height = this->tiny_step_height; break; case WID_GL_ALL_VEHICLES: case WID_GL_DEFAULT_VEHICLES: - size->width = this->ComputeGroupInfoSize(); - size->height = this->tiny_step_height; + size.width = this->ComputeGroupInfoSize(); + size.height = this->tiny_step_height; break; case WID_GL_SORT_BY_ORDER: { Dimension d = GetStringBoundingBox(this->GetWidget(widget)->widget_data); d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better. d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } case WID_GL_LIST_VEHICLE: this->ComputeGroupInfoSize(); - resize->height = GetVehicleListHeight(this->vli.vtype, this->tiny_step_height); - size->height = 4 * resize->height; + resize.height = GetVehicleListHeight(this->vli.vtype, this->tiny_step_height); + size.height = 4 * resize.height; break; case WID_GL_GROUP_BY_DROPDOWN: - size->width = GetStringListWidth(this->vehicle_group_by_names) + padding.width; + size.width = GetStringListWidth(this->vehicle_group_by_names) + padding.width; break; case WID_GL_SORT_BY_DROPDOWN: - size->width = GetStringListWidth(this->vehicle_group_none_sorter_names); - size->width = std::max(size->width, GetStringListWidth(this->vehicle_group_shared_orders_sorter_names)); - size->width += padding.width; + size.width = GetStringListWidth(EconTime::UsingWallclockUnits() ? this->vehicle_group_none_sorter_names_wallclock : this->vehicle_group_none_sorter_names_calendar); + size.width = std::max(size.width, GetStringListWidth(EconTime::UsingWallclockUnits() ? this->vehicle_group_shared_orders_sorter_names_wallclock : this->vehicle_group_shared_orders_sorter_names_calendar)); + size.width += padding.width; break; case WID_GL_FILTER_BY_CARGO: - size->width = std::max(size->width, GetDropDownListDimension(this->BuildCargoDropDownList(true)).width + padding.width); + size.width = std::max(size.width, GetDropDownListDimension(this->BuildCargoDropDownList(true)).width + padding.width); break; case WID_GL_MANAGE_VEHICLES_DROPDOWN: { Dimension d = this->GetActionDropdownSize(true, true, this->vli.vtype == VEH_TRAIN); d.height += padding.height; d.width += padding.width; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } } @@ -1338,7 +1338,7 @@ void ShowCompanyGroupForVehicle(const Vehicle *v) */ static inline VehicleGroupWindow *FindVehicleGroupWindow(VehicleType vt, Owner owner) { - return (VehicleGroupWindow *)FindWindowById(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_GROUP_LIST, vt, owner).Pack()); + return dynamic_cast(FindWindowById(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_GROUP_LIST, vt, owner).Pack())); } /** diff --git a/src/hotkeys.cpp b/src/hotkeys.cpp index c38ea27a2d..2db2d6d03e 100644 --- a/src/hotkeys.cpp +++ b/src/hotkeys.cpp @@ -26,12 +26,12 @@ static std::vector *_hotkey_lists = nullptr; /** String representation of a keycode */ struct KeycodeNames { - const char *name; ///< Name of the keycode + const std::string_view name; ///< Name of the keycode WindowKeyCodes keycode; ///< The keycode }; /** Array of non-standard keycodes that can be used in the hotkeys config file. */ -static const KeycodeNames _keycode_to_name[] = { +static const std::initializer_list _keycode_to_name = { {"SHIFT", WKC_SHIFT}, {"CTRL", WKC_CTRL}, {"ALT", WKC_ALT}, @@ -103,9 +103,9 @@ static uint16_t ParseCode(const char *start, const char *end) while (start < end && *start == ' ') start++; while (end > start && *end == ' ') end--; std::string_view str{start, (size_t)(end - start)}; - for (uint i = 0; i < lengthof(_keycode_to_name); i++) { - if (StrEqualsIgnoreCase(str, _keycode_to_name[i].name)) { - return _keycode_to_name[i].keycode; + for (const auto &kn : _keycode_to_name) { + if (StrEqualsIgnoreCase(str, kn.name)) { + return kn.keycode; } } if (end - start == 1) { @@ -196,9 +196,9 @@ static std::string KeycodeToString(uint16_t keycode) if (!str.empty()) str += "+"; keycode = keycode & ~WKC_SPECIAL_KEYS; - for (uint i = 0; i < lengthof(_keycode_to_name); i++) { - if (_keycode_to_name[i].keycode == keycode) { - str += _keycode_to_name[i].name; + for (const auto &kn : _keycode_to_name) { + if (kn.keycode == keycode) { + str += kn.name; return str; } } diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index 68d0cd0c4d..7a92b0a0af 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -361,36 +361,34 @@ class BuildIndustryWindow : public Window { * @param prefixstr String to use for the first item * @return A formatted raw string */ - std::string MakeCargoListString(const CargoID *cargolist, const CargoSuffix *cargo_suffix, size_t cargolistlen, StringID prefixstr) const + std::string MakeCargoListString(const std::span cargolist, const std::span cargo_suffix, StringID prefixstr) const { - std::string cargostring; - size_t firstcargo = cargolistlen; + assert(cargolist.size() == cargo_suffix.size()); - size_t j = 0; - for (; j < cargolistlen; j++) { - if (cargolist[j] == INVALID_CARGO) continue; - if (firstcargo == cargolistlen) { + std::string cargostring; + size_t numcargo = 0; + size_t firstcargo; + + for (size_t j = 0; j < cargolist.size(); j++) { + if (!IsValidCargoID(cargolist[j])) continue; + numcargo++; + if (numcargo == 1) { firstcargo = j; - j++; - break; + continue; } + SetDParam(0, CargoSpec::Get(cargolist[j])->name); + SetDParamStr(1, cargo_suffix[j].text); + cargostring += GetString(STR_INDUSTRY_VIEW_CARGO_LIST_EXTENSION); } - if (firstcargo < cargolistlen) { + if (numcargo > 0) { SetDParam(0, CargoSpec::Get(cargolist[firstcargo])->name); SetDParamStr(1, cargo_suffix[firstcargo].text); - GetString(StringBuilder(cargostring), prefixstr); + cargostring = GetString(prefixstr) + cargostring; } else { SetDParam(0, STR_JUST_NOTHING); SetDParamStr(1, ""); - GetString(StringBuilder(cargostring), prefixstr); - } - - for (; j < cargolistlen; j++) { - if (cargolist[j] == INVALID_CARGO) continue; - SetDParam(0, CargoSpec::Get(cargolist[j])->name); - SetDParamStr(1, cargo_suffix[j].text); - GetString(StringBuilder(cargostring), STR_INDUSTRY_VIEW_CARGO_LIST_EXTENSION); + cargostring = GetString(prefixstr); } return cargostring; @@ -421,7 +419,7 @@ public: this->SetupArrays(); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_DPI_MATRIX_WIDGET: { @@ -429,10 +427,10 @@ public: for (const auto &indtype : this->list) { d = maxdim(d, GetStringBoundingBox(GetIndustrySpec(indtype)->name)); } - resize->height = std::max(this->legend.height, GetCharacterHeight(FS_NORMAL)) + padding.height; + resize.height = std::max(this->legend.height, GetCharacterHeight(FS_NORMAL)) + padding.height; d.width += this->legend.width + WidgetDimensions::scaled.hsep_wide + padding.width; - d.height = 5 * resize->height; - *size = maxdim(*size, d); + d.height = 5 * resize.height; + size = maxdim(size, d); break; } @@ -450,7 +448,7 @@ public: /* Measure the accepted cargoes, if any. */ GetAllCargoSuffixes(CARGOSUFFIX_IN, CST_FUND, nullptr, indtype, indsp, indsp->accepts_cargo, cargo_suffix); - std::string cargostring = this->MakeCargoListString(indsp->accepts_cargo.data(), cargo_suffix.data(), indsp->accepts_cargo.size(), STR_INDUSTRY_VIEW_REQUIRES_N_CARGO); + std::string cargostring = this->MakeCargoListString(indsp->accepts_cargo, cargo_suffix, STR_INDUSTRY_VIEW_REQUIRES_N_CARGO); Dimension strdim = GetStringBoundingBox(cargostring); if (strdim.width > max_minwidth) { extra_lines_req = std::max(extra_lines_req, strdim.width / max_minwidth + 1); @@ -460,7 +458,7 @@ public: /* Measure the produced cargoes, if any. */ GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_FUND, nullptr, indtype, indsp, indsp->produced_cargo, cargo_suffix); - cargostring = this->MakeCargoListString(indsp->produced_cargo.data(), cargo_suffix.data(), indsp->produced_cargo.size(), STR_INDUSTRY_VIEW_PRODUCES_N_CARGO); + cargostring = this->MakeCargoListString(indsp->produced_cargo, cargo_suffix, STR_INDUSTRY_VIEW_PRODUCES_N_CARGO); strdim = GetStringBoundingBox(cargostring); if (strdim.width > max_minwidth) { extra_lines_prd = std::max(extra_lines_prd, strdim.width / max_minwidth + 1); @@ -476,8 +474,8 @@ public: /* Set it to something more sane :) */ height += extra_lines_prd + extra_lines_req + extra_lines_newgrf; - size->height = height * GetCharacterHeight(FS_NORMAL) + padding.height; - size->width = d.width + padding.width; + size.height = height * GetCharacterHeight(FS_NORMAL) + padding.height; + size.width = d.width + padding.width; break; } @@ -487,7 +485,7 @@ public: d = maxdim(d, GetStringBoundingBox(STR_FUND_INDUSTRY_FUND_NEW_INDUSTRY)); d.width += padding.width; d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } } @@ -566,12 +564,12 @@ public: /* Draw the accepted cargoes, if any. Otherwise, will print "Nothing". */ GetAllCargoSuffixes(CARGOSUFFIX_IN, CST_FUND, nullptr, this->selected_type, indsp, indsp->accepts_cargo, cargo_suffix); - std::string cargostring = this->MakeCargoListString(indsp->accepts_cargo.data(), cargo_suffix.data(), indsp->accepts_cargo.size(), STR_INDUSTRY_VIEW_REQUIRES_N_CARGO); + std::string cargostring = this->MakeCargoListString(indsp->accepts_cargo, cargo_suffix, STR_INDUSTRY_VIEW_REQUIRES_N_CARGO); ir.top = DrawStringMultiLine(ir, cargostring); /* Draw the produced cargoes, if any. Otherwise, will print "Nothing". */ GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_FUND, nullptr, this->selected_type, indsp, indsp->produced_cargo, cargo_suffix); - cargostring = this->MakeCargoListString(indsp->produced_cargo.data(), cargo_suffix.data(), indsp->produced_cargo.size(), STR_INDUSTRY_VIEW_PRODUCES_N_CARGO); + cargostring = this->MakeCargoListString(indsp->produced_cargo, cargo_suffix, STR_INDUSTRY_VIEW_PRODUCES_N_CARGO); ir.top = DrawStringMultiLine(ir, cargostring); /* Get the additional purchase info text, if it has not already been queried. */ @@ -1038,9 +1036,9 @@ public: if (widget == WID_IV_CAPTION) SetDParam(0, this->window_number); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { - if (widget == WID_IV_INFO) size->height = this->info_height; + if (widget == WID_IV_INFO) size.height = this->info_height; } void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override @@ -1755,14 +1753,14 @@ public: } } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_ID_DROPDOWN_ORDER: { Dimension d = GetStringBoundingBox(this->GetWidget(widget)->widget_data); d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better. d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } @@ -1773,17 +1771,17 @@ public: } d.width += padding.width; d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } case WID_ID_INDUSTRY_LIST: { Dimension d = GetStringBoundingBox(STR_INDUSTRY_DIRECTORY_NONE); - resize->height = d.height; + resize.height = d.height; d.height *= 5; d.width += padding.width; d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } } @@ -2670,21 +2668,21 @@ struct IndustryCargoesWindow : public Window { CargoesField::cargo_field_width = CargoesField::cargo_border.width * 2 + CargoesField::cargo_line.width * CargoesField::max_cargoes + CargoesField::cargo_space.width * (CargoesField::max_cargoes - 1); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_IC_PANEL: - resize->height = CargoesField::normal_height; - size->width = CargoesField::industry_width * 3 + CargoesField::cargo_field_width * 2 + WidgetDimensions::scaled.frametext.Horizontal(); - size->height = CargoesField::small_height + 2 * resize->height + WidgetDimensions::scaled.frametext.Vertical(); + resize.height = CargoesField::normal_height; + size.width = CargoesField::industry_width * 3 + CargoesField::cargo_field_width * 2 + WidgetDimensions::scaled.frametext.Horizontal(); + size.height = CargoesField::small_height + 2 * resize.height + WidgetDimensions::scaled.frametext.Vertical(); break; case WID_IC_IND_DROPDOWN: - size->width = std::max(size->width, this->ind_textsize.width + padding.width); + size.width = std::max(size.width, this->ind_textsize.width + padding.width); break; case WID_IC_CARGO_DROPDOWN: - size->width = std::max(size->width, this->cargo_textsize.width + padding.width); + size.width = std::max(size.width, this->cargo_textsize.width + padding.width); break; } } diff --git a/src/intro_gui.cpp b/src/intro_gui.cpp index 7f5a8d179a..2e172b350b 100644 --- a/src/intro_gui.cpp +++ b/src/intro_gui.cpp @@ -298,13 +298,13 @@ struct SelectGameWindow : public Window { } } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_SGI_TEMPERATE_LANDSCAPE: case WID_SGI_ARCTIC_LANDSCAPE: case WID_SGI_TROPIC_LANDSCAPE: case WID_SGI_TOYLAND_LANDSCAPE: - size->width += WidgetDimensions::scaled.fullbevel.Horizontal(); - size->height += WidgetDimensions::scaled.fullbevel.Vertical(); + size.width += WidgetDimensions::scaled.fullbevel.Horizontal(); + size.height += WidgetDimensions::scaled.fullbevel.Vertical(); break; } } diff --git a/src/lang/afrikaans.txt b/src/lang/afrikaans.txt index 39c3d41dfa..ce69bbe327 100644 --- a/src/lang/afrikaans.txt +++ b/src/lang/afrikaans.txt @@ -3002,7 +3002,6 @@ STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT_RAIL_TYPE :Spoor tipe STR_NEWGRF_INSPECT_QUERY_CAPTION :{WHITE}NewGRF veranderlike 60+x parameter (heksadesimaal) # Sprite aligner window -STR_SPRITE_ALIGNER_CAPTION :{WHITE}Belyn sprite {COMMA} ({STRING}) STR_SPRITE_ALIGNER_NEXT_BUTTON :{BLACK}Volgende sprite STR_SPRITE_ALIGNER_NEXT_TOOLTIP :{BLACK}Gaan na die volgende "sprite", Ignoreer enige pseudo/her-kleur/font "sprites" en spring terug na die begin STR_SPRITE_ALIGNER_GOTO_BUTTON :{BLACK}Gaan na sprite diff --git a/src/lang/arabic_egypt.txt b/src/lang/arabic_egypt.txt index 9a0bbec625..184010a6a3 100644 --- a/src/lang/arabic_egypt.txt +++ b/src/lang/arabic_egypt.txt @@ -2859,7 +2859,6 @@ STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT_RAIL_TYPE :نوع سكة STR_NEWGRF_INSPECT_QUERY_CAPTION :{WHITE}متغير الاضافات الجديدة +60 * نمط (hexadecimal) # Sprite aligner window -STR_SPRITE_ALIGNER_CAPTION :{WHITE}موائمة صورة العفريتة {COMMA} ({STRING}) STR_SPRITE_ALIGNER_NEXT_BUTTON :{BLACK}العفريتة التالية STR_SPRITE_ALIGNER_NEXT_TOOLTIP :{BLACK}نابع للعفريتة الطبيعية التالية، تجاوز اي عفريتة موقوفة/ مصبوغة/مخطوطة و انهي المتاعة في النهاية. STR_SPRITE_ALIGNER_GOTO_BUTTON :{BLACK}اذهب الى العفريتة diff --git a/src/lang/basque.txt b/src/lang/basque.txt index bfbd18e830..7580ed6e94 100644 --- a/src/lang/basque.txt +++ b/src/lang/basque.txt @@ -2830,7 +2830,6 @@ STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT_RAIL_TYPE :Trenbide mota STR_NEWGRF_INSPECT_QUERY_CAPTION :{WHITE}NewGRF aldagaia 60+x parametroetan (hexadecimala) # Sprite aligner window -STR_SPRITE_ALIGNER_CAPTION :{WHITE}"Sprit"-a lerrokatu {COMMA} ({STRING}) STR_SPRITE_ALIGNER_NEXT_BUTTON :{BLACK}Urrengo "sprit"-a STR_SPRITE_ALIGNER_NEXT_TOOLTIP :{BLACK}Hurrengo grafiko arrunta erabili, pseudo/birkoloretu/grafiko tipoak desgaituz STR_SPRITE_ALIGNER_GOTO_BUTTON :{BLACK}Joan "sprit"-era diff --git a/src/lang/belarusian.txt b/src/lang/belarusian.txt index 7f2ed1e1b9..3a1de5eaf2 100644 --- a/src/lang/belarusian.txt +++ b/src/lang/belarusian.txt @@ -3817,7 +3817,6 @@ STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT_ROAD_TYPE :Тып даро STR_NEWGRF_INSPECT_QUERY_CAPTION :{WHITE}Парамэтр зьменнай NewGRF 60+x (шаснаццаткавы) # Sprite aligner window -STR_SPRITE_ALIGNER_CAPTION :{WHITE}Выраўноўваньне спрайта {COMMA} ({STRING}) STR_SPRITE_ALIGNER_NEXT_BUTTON :{BLACK}Наступны спрайт STR_SPRITE_ALIGNER_NEXT_TOOLTIP :{BLACK}Перайсьці да наступнага звычайнага спрайта, прапускаючы змяняючыя колер, шрыфтавыя, псэўдаспрайты. Пераход з канца сьпісу да першага спрайта. STR_SPRITE_ALIGNER_GOTO_BUTTON :{BLACK}Перайсьці да спрайта diff --git a/src/lang/brazilian_portuguese.txt b/src/lang/brazilian_portuguese.txt index e2a8bfcdd7..0c5f79b7fa 100644 --- a/src/lang/brazilian_portuguese.txt +++ b/src/lang/brazilian_portuguese.txt @@ -269,8 +269,8 @@ STR_UNITS_PERIODS :{NUM}{NBSP}per # Common window strings STR_LIST_FILTER_TITLE :{BLACK}Filtro: -STR_LIST_FILTER_OSKTITLE :{BLACK}Inserir uma ou mais palavras-chave para filtrar a lista -STR_LIST_FILTER_TOOLTIP :{BLACK}Introduza uma ou mais palavras-chave para procurar na lista +STR_LIST_FILTER_OSKTITLE :{BLACK}Introduza uma palavra-chave para filtrar a lista +STR_LIST_FILTER_TOOLTIP :{BLACK}Introduzir uma ou mais palavras-chave para procurar na lista STR_TOOLTIP_GROUP_ORDER :{BLACK}Escolher a ordem de agrupamento STR_TOOLTIP_SORT_ORDER :{BLACK}Escolher a ordenação (descendente/ascendente) @@ -384,7 +384,7 @@ STR_TOOLBAR_TOOLTIP_PAUSE_GAME :{BLACK}Pausar o STR_TOOLBAR_TOOLTIP_FORWARD :{BLACK}Avanço rápido do jogo STR_TOOLBAR_TOOLTIP_OPTIONS :{BLACK}Opções e configurações STR_TOOLBAR_TOOLTIP_SAVE_GAME_ABANDON_GAME :{BLACK}Salvar, abrir ou abandonar o jogo, sair do programa -STR_TOOLBAR_TOOLTIP_DISPLAY_MAP :{BLACK}Abrir mapa, visualização extra, fluxo de cargas ou lista de placas +STR_TOOLBAR_TOOLTIP_DISPLAY_MAP :{BLACK}Abrir mapa, visualização extra, fluxo de carga ou lista de placas STR_TOOLBAR_TOOLTIP_DISPLAY_TOWN_DIRECTORY :{BLACK}Abrir lista de localidades ou encontrar localidade STR_TOOLBAR_TOOLTIP_DISPLAY_SUBSIDIES :{BLACK}Abrir lista de subsídios STR_TOOLBAR_TOOLTIP_DISPLAY_LIST_OF_COMPANY_STATIONS :{BLACK}Abrir lista de estações da empresa @@ -410,7 +410,7 @@ STR_TOOLBAR_TOOLTIP_LANDSCAPING :{BLACK}Abrir me STR_TOOLBAR_TOOLTIP_SHOW_SOUND_MUSIC_WINDOW :{BLACK}Abrir janela de som/música STR_TOOLBAR_TOOLTIP_SHOW_LAST_MESSAGE_NEWS :{BLACK}Abrir última mensagem/notícia, histórico de mensagens ou apagar todas as mensagens STR_TOOLBAR_TOOLTIP_LAND_BLOCK_INFORMATION :{BLACK}Abrir informações do terreno, menu de captura de tela, créditos do OpenTTD ou ferramentas de desenvolvedor -STR_TOOLBAR_TOOLTIP_SWITCH_TOOLBAR :{BLACK}Trocar barras de ferramentas +STR_TOOLBAR_TOOLTIP_SWITCH_TOOLBAR :{BLACK}Trocar barra de ferramentas # Extra tooltips for the scenario editor toolbar STR_SCENEDIT_TOOLBAR_TOOLTIP_SAVE_SCENARIO_LOAD_SCENARIO :{BLACK}Salvar cenário, abrir cenário, abandonar editor de cenário, sair @@ -499,7 +499,7 @@ STR_INDUSTRY_MENU_FUND_NEW_INDUSTRY :Fundar nova ind STR_RAIL_MENU_RAILROAD_CONSTRUCTION :Construção de ferrovia STR_RAIL_MENU_ELRAIL_CONSTRUCTION :Construção de ferrovia eletrificada STR_RAIL_MENU_MONORAIL_CONSTRUCTION :Construção de monotrilho -STR_RAIL_MENU_MAGLEV_CONSTRUCTION :Construção de MagLev +STR_RAIL_MENU_MAGLEV_CONSTRUCTION :Construção de Maglev # Road construction menu STR_ROAD_MENU_ROAD_CONSTRUCTION :Construção de estrada @@ -732,7 +732,7 @@ STR_HIGHSCORE_PERFORMANCE_TITLE_ENTREPRENEUR :Empreendedor STR_HIGHSCORE_PERFORMANCE_TITLE_INDUSTRIALIST :Industrial STR_HIGHSCORE_PERFORMANCE_TITLE_CAPITALIST :Capitalista STR_HIGHSCORE_PERFORMANCE_TITLE_MAGNATE :Magnata -STR_HIGHSCORE_PERFORMANCE_TITLE_MOGUL :Mandachuva +STR_HIGHSCORE_PERFORMANCE_TITLE_MOGUL :Grande magnata STR_HIGHSCORE_PERFORMANCE_TITLE_TYCOON_OF_THE_CENTURY :Magnata do Século STR_HIGHSCORE_NAME :{PRESIDENT_NAME}, {COMPANY} STR_HIGHSCORE_STATS :{BIG_FONT}'{STRING}' ({COMMA}) @@ -836,11 +836,11 @@ STR_NEWS_FIRST_CARGO_TRAM_ARRIVAL :{BIG_FONT}{BLAC STR_NEWS_FIRST_SHIP_ARRIVAL :{BIG_FONT}{BLACK}Cidadãos celebram . . .{}Primeira embarcação chega em {STATION}! STR_NEWS_FIRST_AIRCRAFT_ARRIVAL :{BIG_FONT}{BLACK}Cidadãos celebram . . .{}Primeira aeronave chega em {STATION}! -STR_NEWS_TRAIN_CRASH :{BIG_FONT}{BLACK}Acidente de Trem!{}{COMMA} morrem na explosão após a colisão +STR_NEWS_TRAIN_CRASH :{BIG_FONT}{BLACK}Acidente de Trem!{}{COMMA} morre{P "" m} na explosão após a colisão STR_NEWS_ROAD_VEHICLE_CRASH_DRIVER :{BIG_FONT}{BLACK}Acidente Rodoviário!{}Condutor morre na explosão após a colisão com um trem -STR_NEWS_ROAD_VEHICLE_CRASH :{BIG_FONT}{BLACK}Acidente Rodoviário!{}{COMMA} morrem na explosão após a colisão com um trem -STR_NEWS_AIRCRAFT_CRASH :{BIG_FONT}{BLACK}Acidente Aéreo!{}{COMMA} morrem na explosão em {STATION} -STR_NEWS_PLANE_CRASH_OUT_OF_FUEL :{BIG_FONT}{BLACK}Acidente Aéreo!{}Aeronave ficou sem combustível, {COMMA} morrem na explosão +STR_NEWS_ROAD_VEHICLE_CRASH :{BIG_FONT}{BLACK}Acidente Rodoviário!{}{COMMA} morre{P "" m} na explosão após a colisão com um trem +STR_NEWS_AIRCRAFT_CRASH :{BIG_FONT}{BLACK}Acidente Aéreo!{}{COMMA} morre{P "" m} na explosão em {STATION} +STR_NEWS_PLANE_CRASH_OUT_OF_FUEL :{BIG_FONT}{BLACK}Acidente Aéreo!{}Aeronave ficou sem combustível, {COMMA} morre{P "" m} na explosão STR_NEWS_DISASTER_ZEPPELIN :{BIG_FONT}{BLACK}Desastre de Zepelim em {STATION}! STR_NEWS_DISASTER_SMALL_UFO :{BIG_FONT}{BLACK}Veículo rodoviário destruído em colisão com OVNI! @@ -988,7 +988,7 @@ STR_GAME_OPTIONS_CURRENCY_ISK :Coroa Islandesa STR_GAME_OPTIONS_CURRENCY_ITL :Lira Italiana STR_GAME_OPTIONS_CURRENCY_NLG :Florim Holandês STR_GAME_OPTIONS_CURRENCY_NOK :Coroa Norueguesa -STR_GAME_OPTIONS_CURRENCY_PLN :Złoty Polonês +STR_GAME_OPTIONS_CURRENCY_PLN :Zloty Polonês STR_GAME_OPTIONS_CURRENCY_RON :Leu Romeno STR_GAME_OPTIONS_CURRENCY_RUR :Rublo Russo STR_GAME_OPTIONS_CURRENCY_SIT :Tolar Esloveno @@ -1188,7 +1188,7 @@ STR_SUBSIDY_X4 :x4 ###length 4 STR_CLIMATE_TEMPERATE_LANDSCAPE :Clima temperado -STR_CLIMATE_SUB_ARCTIC_LANDSCAPE :Clima subárctico +STR_CLIMATE_SUB_ARCTIC_LANDSCAPE :Clima subártico STR_CLIMATE_SUB_TROPICAL_LANDSCAPE :Clima subtropical STR_CLIMATE_TOYLAND_LANDSCAPE :Terra dos Brinquedos @@ -1523,8 +1523,8 @@ STR_CONFIG_SETTING_AUTORENEW_MONTHS_HELPTEXT :Idade relativa STR_CONFIG_SETTING_AUTORENEW_MONTHS_VALUE_BEFORE :{COMMA} m{P 0 ês eses} antes STR_CONFIG_SETTING_AUTORENEW_MONTHS_VALUE_AFTER :{COMMA} m{P 0 ês eses} depois -STR_CONFIG_SETTING_AUTORENEW_MONEY :Quantia mínima de dinheiro necessária para fazer renovação automática: {STRING} -STR_CONFIG_SETTING_AUTORENEW_MONEY_HELPTEXT :Quantia mínima de dinheiro que deve existir na conta bancária para a renovação automática de veículos ser considerada +STR_CONFIG_SETTING_AUTORENEW_MONEY :Dinheiro mínimo necessário para fazer renovação automática: {STRING} +STR_CONFIG_SETTING_AUTORENEW_MONEY_HELPTEXT :Quantia mínima de dinheiro que deve permanecer no banco antes de considerar a renovação automática de veículos STR_CONFIG_SETTING_ERRMSG_DURATION :Duração da mensagem de erro: {STRING} STR_CONFIG_SETTING_ERRMSG_DURATION_HELPTEXT :Tempo de exibição de mensagens de erro numa janela vermelha. Algumas mensagens de erro (crítico) não são fechadas automaticamente após este tempo e precisam ser fechadas manualmente @@ -2461,8 +2461,8 @@ STR_NETWORK_CONNECTING_SPECIAL_2 :{BLACK}Obtendo STR_NETWORK_CONNECTION_DISCONNECT :{BLACK}Desconectar -STR_NETWORK_NEED_GAME_PASSWORD_CAPTION :{WHITE}Servidor protegido. Introduza a senha -STR_NETWORK_NEED_COMPANY_PASSWORD_CAPTION :{WHITE}Empresa protegida. Introduza a senha +STR_NETWORK_NEED_GAME_PASSWORD_CAPTION :{WHITE}Servidor protegido. Digite a senha +STR_NETWORK_NEED_COMPANY_PASSWORD_CAPTION :{WHITE}Empresa protegida. Digite a senha # Network company list added strings STR_NETWORK_COMPANY_LIST_CLIENT_LIST :Jogadores conectados @@ -3088,7 +3088,7 @@ STR_LAND_AREA_INFORMATION_BUILD_DATE :{BLACK}Constru STR_LAND_AREA_INFORMATION_STATION_CLASS :{BLACK}Classe da estação: {LTBLUE}{STRING} STR_LAND_AREA_INFORMATION_STATION_TYPE :{BLACK}Tipo de estação: {LTBLUE}{STRING} STR_LAND_AREA_INFORMATION_AIRPORT_CLASS :{BLACK}Classe do aeroporto: {LTBLUE}{STRING} -STR_LAND_AREA_INFORMATION_AIRPORT_NAME :{BLACK}Nome do aeroporto: {LTBLUE}{STRING} +STR_LAND_AREA_INFORMATION_AIRPORT_NAME :{BLACK}Tipo de aeroporto: {LTBLUE}{STRING} STR_LAND_AREA_INFORMATION_AIRPORTTILE_NAME :{BLACK}Nome do quadrado do aeroporto: {LTBLUE}{STRING} STR_LAND_AREA_INFORMATION_NEWGRF_NAME :{BLACK}NewGRF: {LTBLUE}{STRING} STR_LAND_AREA_INFORMATION_CARGO_ACCEPTED :{BLACK}Carga aceita: {LTBLUE} @@ -3390,7 +3390,7 @@ STR_SE_MAPGEN_FLAT_WORLD_HEIGHT_QUERY_CAPT :{WHITE}Modifica STR_GENERATION_WORLD :{WHITE}Gerando Mundo... STR_GENERATION_ABORT :{BLACK}Cancelar STR_GENERATION_ABORT_CAPTION :{WHITE}Cancelar Geração de Mundo -STR_GENERATION_ABORT_MESSAGE :{YELLOW}Você realmente deseja cancelar a geração? +STR_GENERATION_ABORT_MESSAGE :{YELLOW}Você quer mesmo cancelar a geração? STR_GENERATION_PROGRESS :{WHITE}{NUM}% completo STR_GENERATION_PROGRESS_NUM :{BLACK}{NUM} / {NUM} STR_GENERATION_WORLD_GENERATION :{BLACK}Geração de mundo @@ -3489,7 +3489,9 @@ STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT_ROAD_TYPE :Tipo de estrada STR_NEWGRF_INSPECT_QUERY_CAPTION :{WHITE}Parâmetro da variável 60+x do NewGRF (hexadecimal) # Sprite aligner window -STR_SPRITE_ALIGNER_CAPTION :{WHITE}Alinhando sprite {COMMA} ({STRING}) +STR_SPRITE_ALIGNER_CAPTION_NO_ACTION :{WHITE}Alinhando sprite: ({STRING}:{NUM}) +STR_SPRITE_ALIGNER_CAPTION_ACTIONA :{WHITE}Alinhando sprite: Ação 0xA, {COMMA} ({STRING}:{NUM}) +STR_SPRITE_ALIGNER_CAPTION_ACTION5 :{WHITE}Alinhando sprite: Ação 0x5, tipe {HEX}, {COMMA} ({STRING}:{NUM}) STR_SPRITE_ALIGNER_NEXT_BUTTON :{BLACK}Próximo sprite STR_SPRITE_ALIGNER_NEXT_TOOLTIP :{BLACK}Ir para o próximo sprite normal, pulando quaisquer sprites falsos/recoloridos/tipo de letra, retornando do último sprite para o primeiro STR_SPRITE_ALIGNER_GOTO_BUTTON :{BLACK}Ir para o sprite @@ -3498,6 +3500,7 @@ STR_SPRITE_ALIGNER_PREVIOUS_BUTTON :{BLACK}Sprite a STR_SPRITE_ALIGNER_PREVIOUS_TOOLTIP :{BLACK}Ir para o sprite normal anterior, pulando quaisquer sprites falsos/recoloridos/tipo de letra, retornando do primeiro sprite para o último STR_SPRITE_ALIGNER_SPRITE_TOOLTIP :{BLACK}Representação do sprite atualmente selecionado. O alinhamento é ignorado ao desenhar este sprite STR_SPRITE_ALIGNER_MOVE_TOOLTIP :{BLACK}Mover o sprite, alterando os deslocamentos X e Y. Ctrl+Clique para mover o sprite 8 unidades por vez +STR_SPRITE_ALIGNER_SPRITE :{STRING}:{NUM} ###length 2 STR_SPRITE_ALIGNER_CENTRE_OFFSET :{BLACK}Deslocamento centralizado @@ -3588,7 +3591,7 @@ STR_INVALID_VEHICLE :text_width = widest_width + WidgetDimensions::scaled.hsep_indent * 3; // Keep some extra spacing - size->width = WidgetDimensions::scaled.framerect.Horizontal() + this->ordinal_width + this->icon.width + this->text_width + WidgetDimensions::scaled.hsep_wide; - size->height = this->line_height * MAX_COMPANIES + WidgetDimensions::scaled.framerect.Vertical(); + size.width = WidgetDimensions::scaled.framerect.Horizontal() + this->ordinal_width + this->icon.width + this->text_width + WidgetDimensions::scaled.hsep_wide; + size.height = this->line_height * MAX_COMPANIES + WidgetDimensions::scaled.framerect.Vertical(); } void OnGameTick() override @@ -359,7 +359,7 @@ public: } } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { if (widget != WID_SLT_BACKGROUND) return; @@ -385,18 +385,18 @@ public: if (!show_icon_column) this->icon_size.width = 0; else this->icon_size.width += WidgetDimensions::scaled.hsep_wide; - size->width = this->rank_width + this->icon_size.width + this->text_width + this->score_width + WidgetDimensions::scaled.framerect.Horizontal() + WidgetDimensions::scaled.hsep_wide * 2; - size->height = this->line_height * std::max(3u, (unsigned)this->rows.size()) + WidgetDimensions::scaled.framerect.Vertical(); + size.width = this->rank_width + this->icon_size.width + this->text_width + this->score_width + WidgetDimensions::scaled.framerect.Horizontal() + WidgetDimensions::scaled.hsep_wide * 2; + size.height = this->line_height * std::max(3u, (unsigned)this->rows.size()) + WidgetDimensions::scaled.framerect.Vertical(); if (!lt->header.empty()) { SetDParamStr(0, lt->header); - this->header_height = GetStringHeight(STR_JUST_RAW_STRING, size->width - WidgetDimensions::scaled.framerect.Horizontal()) + WidgetDimensions::scaled.vsep_wide; - size->height += header_height; + this->header_height = GetStringHeight(STR_JUST_RAW_STRING, size.width - WidgetDimensions::scaled.framerect.Horizontal()) + WidgetDimensions::scaled.vsep_wide; + size.height += header_height; } else this->header_height = 0; if (!lt->footer.empty()) { SetDParamStr(0, lt->footer); - size->height += GetStringHeight(STR_JUST_RAW_STRING, size->width - WidgetDimensions::scaled.framerect.Horizontal()) + WidgetDimensions::scaled.vsep_wide; + size.height += GetStringHeight(STR_JUST_RAW_STRING, size.width - WidgetDimensions::scaled.framerect.Horizontal()) + WidgetDimensions::scaled.vsep_wide; } } diff --git a/src/linkgraph/linkgraph_gui.cpp b/src/linkgraph/linkgraph_gui.cpp index 57da7e45ae..4b69dc280f 100644 --- a/src/linkgraph/linkgraph_gui.cpp +++ b/src/linkgraph/linkgraph_gui.cpp @@ -840,7 +840,7 @@ void LinkGraphLegendWindow::SetOverlay(LinkGraphOverlay *overlay) } } -void LinkGraphLegendWindow::UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) +void LinkGraphLegendWindow::UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) { if (IsInsideMM(widget, WID_LGL_SATURATION_FIRST, WID_LGL_SATURATION_LAST + 1)) { StringID str = STR_NULL; @@ -855,7 +855,7 @@ void LinkGraphLegendWindow::UpdateWidgetSize(WidgetID widget, Dimension *size, [ Dimension dim = GetStringBoundingBox(str, FS_SMALL); dim.width += padding.width; dim.height += padding.height; - *size = maxdim(*size, dim); + size = maxdim(size, dim); } } if (IsInsideMM(widget, WID_LGL_CARGO_FIRST, WID_LGL_CARGO_LAST + 1)) { @@ -863,7 +863,7 @@ void LinkGraphLegendWindow::UpdateWidgetSize(WidgetID widget, Dimension *size, [ Dimension dim = GetStringBoundingBox(cargo->abbrev, FS_SMALL); dim.width += padding.width; dim.height += padding.height; - *size = maxdim(*size, dim); + size = maxdim(size, dim); } } diff --git a/src/linkgraph/linkgraph_gui.h b/src/linkgraph/linkgraph_gui.h index 9fa6c32914..000cf7bf0f 100644 --- a/src/linkgraph/linkgraph_gui.h +++ b/src/linkgraph/linkgraph_gui.h @@ -138,7 +138,7 @@ public: LinkGraphLegendWindow(WindowDesc *desc, int window_number); void SetOverlay(LinkGraphOverlay *overlay); - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override; + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override; void DrawWidget(const Rect &r, WidgetID widget) const override; bool OnTooltip([[maybe_unused]] Point pt, WidgetID widget, TooltipCloseCondition close_cond) override; void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override; diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 0a13b4ff61..7160cd4f93 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -90,23 +90,23 @@ public: } } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { if (widget != WID_LI_BACKGROUND) return; - size->height = WidgetDimensions::scaled.frametext.Vertical(); + size.height = WidgetDimensions::scaled.frametext.Vertical(); for (size_t i = 0; i < this->landinfo_data.size(); i++) { uint width = GetStringBoundingBox(this->landinfo_data[i]).width + WidgetDimensions::scaled.frametext.Horizontal(); - size->width = std::max(size->width, width); + size.width = std::max(size.width, width); - size->height += GetCharacterHeight(FS_NORMAL) + (i == 0 ? WidgetDimensions::scaled.vsep_wide : WidgetDimensions::scaled.vsep_normal); + size.height += GetCharacterHeight(FS_NORMAL) + (i == 0 ? WidgetDimensions::scaled.vsep_wide : WidgetDimensions::scaled.vsep_normal); } if (!this->cargo_acceptance.empty()) { uint width = GetStringBoundingBox(this->cargo_acceptance).width + WidgetDimensions::scaled.frametext.Horizontal(); - size->width = std::max(size->width, std::min(static_cast(ScaleGUITrad(300)), width)); + size.width = std::max(size.width, std::min(static_cast(ScaleGUITrad(300)), width)); SetDParamStr(0, cargo_acceptance); - size->height += GetStringHeight(STR_JUST_RAW_STRING, size->width - WidgetDimensions::scaled.frametext.Horizontal()); + size.height += GetStringHeight(STR_JUST_RAW_STRING, size.width - WidgetDimensions::scaled.frametext.Horizontal()); } } @@ -441,7 +441,7 @@ static WindowDesc _about_desc(__FILE__, __LINE__, std::begin(_nested_about_widgets), std::end(_nested_about_widgets) ); -static const char * const _credits[] = { +static const std::initializer_list _credits = { "Original design by Chris Sawyer", "Original graphics by Simon Foster", "", @@ -533,7 +533,7 @@ struct AboutWindow : public Window { if (widget == WID_A_COPYRIGHT) SetDParamStr(0, _openttd_revision_year); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { if (widget != WID_A_SCROLLING_TEXT) return; @@ -543,10 +543,10 @@ struct AboutWindow : public Window { d.height = this->line_height * num_visible_lines; d.width = 0; - for (uint i = 0; i < lengthof(_credits); i++) { - d.width = std::max(d.width, GetStringBoundingBox(_credits[i]).width); + for (const auto &str : _credits) { + d.width = std::max(d.width, GetStringBoundingBox(str).width); } - *size = maxdim(*size, d); + size = maxdim(size, d); /* Set scroll interval based on required speed. To keep scrolling smooth, * the interval is adjusted rather than the distance moved. */ @@ -560,9 +560,9 @@ struct AboutWindow : public Window { int y = this->text_position; /* Show all scrolling _credits */ - for (uint i = 0; i < lengthof(_credits); i++) { + for (const auto &str : _credits) { if (y >= r.top + 7 && y < r.bottom - this->line_height) { - DrawString(r.left, r.right, y, _credits[i], TC_BLACK, SA_LEFT | SA_FORCE); + DrawString(r.left, r.right, y, str, TC_BLACK, SA_LEFT | SA_FORCE); } y += this->line_height; } @@ -574,7 +574,7 @@ struct AboutWindow : public Window { if (count > 0) { this->text_position -= count; /* If the last text has scrolled start a new from the start */ - if (this->text_position < (int)(this->GetWidget(WID_A_SCROLLING_TEXT)->pos_y - lengthof(_credits) * this->line_height)) { + if (this->text_position < (int)(this->GetWidget(WID_A_SCROLLING_TEXT)->pos_y - std::size(_credits) * this->line_height)) { this->text_position = this->GetWidget(WID_A_SCROLLING_TEXT)->pos_y + this->GetWidget(WID_A_SCROLLING_TEXT)->current_y; } this->SetWidgetDirty(WID_A_SCROLLING_TEXT); @@ -755,21 +755,21 @@ struct TooltipsWindow : public Window return pt; } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { if (widget != WID_TT_BACKGROUND) return; if (this->params.size() == 0) { - size->width = std::min(GetStringBoundingBox(this->buffer).width, ScaleGUITrad(194)); - size->height = GetStringHeight(this->buffer, size->width); + size.width = std::min(GetStringBoundingBox(this->buffer).width, ScaleGUITrad(194)); + size.height = GetStringHeight(this->buffer, size.width); } else { CopyInDParam(this->params); - size->width = std::min(GetStringBoundingBox(this->string_id).width, ScaleGUITrad(194)); - size->height = GetStringHeight(this->string_id, size->width); + size.width = std::min(GetStringBoundingBox(this->string_id).width, ScaleGUITrad(194)); + size.height = GetStringHeight(this->string_id, size.width); } /* Increase slightly to have some space around the box. */ - size->width += WidgetDimensions::scaled.framerect.Horizontal() + WidgetDimensions::scaled.fullbevel.Horizontal(); - size->height += WidgetDimensions::scaled.framerect.Vertical() + WidgetDimensions::scaled.fullbevel.Vertical(); + size.width += WidgetDimensions::scaled.framerect.Horizontal() + WidgetDimensions::scaled.fullbevel.Horizontal(); + size.height += WidgetDimensions::scaled.framerect.Vertical() + WidgetDimensions::scaled.fullbevel.Vertical(); } void DrawWidget(const Rect &r, WidgetID widget) const override @@ -1061,17 +1061,17 @@ struct QueryStringWindow : public Window this->ReInit(); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { if (widget == WID_QS_DEFAULT && (this->flags & QSF_ENABLE_DEFAULT) == 0) { /* We don't want this widget to show! */ - fill->width = 0; - resize->width = 0; - size->width = 0; + fill.width = 0; + resize.width = 0; + size.width = 0; } if (widget == WID_QS_WARNING) { - *size = this->warning_size; + size = this->warning_size; } } @@ -1241,13 +1241,13 @@ struct QueryWindow : public Window { } } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { if (widget != WID_Q_TEXT) return; if (!this->precomposed) this->message_str = GetString(this->message); - *size = GetStringMultiLineBoundingBox(this->message_str, *size); + size = GetStringMultiLineBoundingBox(this->message_str, size); } void DrawWidget(const Rect &r, WidgetID widget) const override diff --git a/src/music_gui.cpp b/src/music_gui.cpp index 3ef07b7c33..ea2d2a3fe3 100644 --- a/src/music_gui.cpp +++ b/src/music_gui.cpp @@ -526,7 +526,7 @@ struct MusicTrackSelectionWindow : public Window { } } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_MTS_PLAYLIST: { @@ -538,7 +538,7 @@ struct MusicTrackSelectionWindow : public Window { } d.width += padding.width; d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } @@ -555,7 +555,7 @@ struct MusicTrackSelectionWindow : public Window { } d.width += padding.width; d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } } @@ -708,7 +708,7 @@ struct MusicWindow : public Window { ); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { /* Make sure that WID_M_SHUFFLE and WID_M_PROGRAMME have the same size. @@ -718,7 +718,7 @@ struct MusicWindow : public Window { Dimension d = maxdim(GetStringBoundingBox(STR_MUSIC_PROGRAM), GetStringBoundingBox(STR_MUSIC_SHUFFLE)); d.width += padding.width; d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } @@ -726,7 +726,7 @@ struct MusicWindow : public Window { Dimension d = GetStringBoundingBox(STR_MUSIC_TRACK_NONE); d.width += padding.width; d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } @@ -738,7 +738,7 @@ struct MusicWindow : public Window { } d.width += padding.width; d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } diff --git a/src/network/core/network_game_info.cpp b/src/network/core/network_game_info.cpp index 9d64bf87de..0c91bdd7a1 100644 --- a/src/network/core/network_game_info.cpp +++ b/src/network/core/network_game_info.cpp @@ -170,7 +170,7 @@ const NetworkServerGameInfo &GetCurrentNetworkServerGameInfo() * @param config The GRF to handle. * @param name The name of the NewGRF, empty when unknown. */ -static void HandleIncomingNetworkGameInfoGRFConfig(GRFConfig *config, std::string name) +static void HandleIncomingNetworkGameInfoGRFConfig(GRFConfig *config, std::string_view name) { /* Find the matching GRF file */ const GRFConfig *f = FindGRFConfig(config->ident.grfid, FGCM_EXACT, &config->ident.md5sum); diff --git a/src/network/network_content_gui.cpp b/src/network/network_content_gui.cpp index e62cf188b6..9a97e1fd7d 100644 --- a/src/network/network_content_gui.cpp +++ b/src/network/network_content_gui.cpp @@ -117,21 +117,21 @@ void BaseNetworkContentDownloadStatusWindow::Close([[maybe_unused]] int data) this->Window::Close(); } -void BaseNetworkContentDownloadStatusWindow::UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) +void BaseNetworkContentDownloadStatusWindow::UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) { switch (widget) { case WID_NCDS_PROGRESS_BAR: SetDParamMaxDigits(0, 8); SetDParamMaxDigits(1, 8); SetDParamMaxDigits(2, 8); - *size = GetStringBoundingBox(STR_CONTENT_DOWNLOAD_PROGRESS_SIZE); + size = GetStringBoundingBox(STR_CONTENT_DOWNLOAD_PROGRESS_SIZE); /* We need some spacing for the 'border' */ - size->height += WidgetDimensions::scaled.frametext.Horizontal(); - size->width += WidgetDimensions::scaled.frametext.Vertical(); + size.height += WidgetDimensions::scaled.frametext.Horizontal(); + size.width += WidgetDimensions::scaled.frametext.Vertical(); break; case WID_NCDS_PROGRESS_TEXT: - size->height = GetCharacterHeight(FS_NORMAL) * 2 + WidgetDimensions::scaled.vsep_normal; + size.height = GetCharacterHeight(FS_NORMAL) * 2 + WidgetDimensions::scaled.vsep_normal; break; } } @@ -589,25 +589,25 @@ public: this->checkbox_size = maxdim(maxdim(GetSpriteSize(SPR_BOX_EMPTY), GetSpriteSize(SPR_BOX_CHECKED)), GetSpriteSize(SPR_BLOT)); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_NCL_CHECKBOX: - size->width = this->checkbox_size.width + padding.width; + size.width = this->checkbox_size.width + padding.width; break; case WID_NCL_TYPE: { - Dimension d = *size; + Dimension d = size; for (int i = CONTENT_TYPE_BEGIN; i < CONTENT_TYPE_END; i++) { d = maxdim(d, GetStringBoundingBox(STR_CONTENT_TYPE_BASE_GRAPHICS + i - CONTENT_TYPE_BASE_GRAPHICS)); } - size->width = d.width + padding.width; + size.width = d.width + padding.width; break; } case WID_NCL_MATRIX: - resize->height = std::max(this->checkbox_size.height, (uint)GetCharacterHeight(FS_NORMAL)) + padding.height; - size->height = 10 * resize->height; + resize.height = std::max(this->checkbox_size.height, (uint)GetCharacterHeight(FS_NORMAL)) + padding.height; + size.height = 10 * resize.height; break; } } diff --git a/src/network/network_content_gui.h b/src/network/network_content_gui.h index 351b28ccc5..795dea9f31 100644 --- a/src/network/network_content_gui.h +++ b/src/network/network_content_gui.h @@ -33,7 +33,7 @@ public: BaseNetworkContentDownloadStatusWindow(WindowDesc *desc); void Close([[maybe_unused]] int data = 0) override; - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override; + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override; void DrawWidget(const Rect &r, WidgetID widget) const override; void OnDownloadProgress(const ContentInfo *ci, int bytes) override; }; diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index 152a6cdc25..082e5d0eb6 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -484,48 +484,48 @@ public: this->flag_offset = this->blot_offset + ScaleGUITrad(2) + GetSpriteSize(SPR_BLOT).width; } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_NG_MATRIX: - resize->height = std::max(GetSpriteSize(SPR_BLOT).height, (uint)GetCharacterHeight(FS_NORMAL)) + padding.height; - fill->height = resize->height; - size->height = 12 * resize->height; + resize.height = std::max(GetSpriteSize(SPR_BLOT).height, (uint)GetCharacterHeight(FS_NORMAL)) + padding.height; + fill.height = resize.height; + size.height = 12 * resize.height; break; case WID_NG_LASTJOINED: - size->height = std::max(GetSpriteSize(SPR_BLOT).height, (uint)GetCharacterHeight(FS_NORMAL)) + WidgetDimensions::scaled.matrix.Vertical(); + size.height = std::max(GetSpriteSize(SPR_BLOT).height, (uint)GetCharacterHeight(FS_NORMAL)) + WidgetDimensions::scaled.matrix.Vertical(); break; case WID_NG_LASTJOINED_SPACER: - size->width = NWidgetScrollbar::GetVerticalDimension().width; + size.width = NWidgetScrollbar::GetVerticalDimension().width; break; case WID_NG_NAME: - size->width += 2 * Window::SortButtonWidth(); // Make space for the arrow + size.width += 2 * Window::SortButtonWidth(); // Make space for the arrow break; case WID_NG_CLIENTS: - size->width += 2 * Window::SortButtonWidth(); // Make space for the arrow + size.width += 2 * Window::SortButtonWidth(); // Make space for the arrow SetDParamMaxValue(0, MAX_CLIENTS); SetDParamMaxValue(1, MAX_CLIENTS); SetDParamMaxValue(2, MAX_COMPANIES); SetDParamMaxValue(3, MAX_COMPANIES); - *size = maxdim(*size, GetStringBoundingBox(STR_NETWORK_SERVER_LIST_GENERAL_ONLINE)); + size = maxdim(size, GetStringBoundingBox(STR_NETWORK_SERVER_LIST_GENERAL_ONLINE)); break; case WID_NG_MAPSIZE: - size->width += 2 * Window::SortButtonWidth(); // Make space for the arrow + size.width += 2 * Window::SortButtonWidth(); // Make space for the arrow SetDParamMaxValue(0, MAX_MAP_SIZE); SetDParamMaxValue(1, MAX_MAP_SIZE); - *size = maxdim(*size, GetStringBoundingBox(STR_NETWORK_SERVER_LIST_MAP_SIZE_SHORT)); + size = maxdim(size, GetStringBoundingBox(STR_NETWORK_SERVER_LIST_MAP_SIZE_SHORT)); break; case WID_NG_DATE: case WID_NG_YEARS: - size->width += 2 * Window::SortButtonWidth(); // Make space for the arrow + size.width += 2 * Window::SortButtonWidth(); // Make space for the arrow SetDParamMaxValue(0, 5); - *size = maxdim(*size, GetStringBoundingBox(STR_JUST_INT)); + size = maxdim(size, GetStringBoundingBox(STR_JUST_INT)); break; } } @@ -1021,13 +1021,13 @@ struct NetworkStartServerWindow : public Window { } } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_NSS_CONNTYPE_BTN: - *size = maxdim(maxdim(GetStringBoundingBox(STR_NETWORK_SERVER_VISIBILITY_LOCAL), GetStringBoundingBox(STR_NETWORK_SERVER_VISIBILITY_PUBLIC)), GetStringBoundingBox(STR_NETWORK_SERVER_VISIBILITY_INVITE_ONLY)); - size->width += padding.width; - size->height += padding.height; + size = maxdim(maxdim(GetStringBoundingBox(STR_NETWORK_SERVER_VISIBILITY_LOCAL), GetStringBoundingBox(STR_NETWORK_SERVER_VISIBILITY_PUBLIC)), GetStringBoundingBox(STR_NETWORK_SERVER_VISIBILITY_INVITE_ONLY)); + size.width += padding.width; + size.height += padding.height; break; } } @@ -1684,7 +1684,7 @@ public: this->SetWidgetDisabledState(WID_CL_SERVER_NAME_EDIT, !_network_server); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_CL_SERVER_NAME: @@ -1695,14 +1695,14 @@ public: const NetworkClientInfo *own_ci = NetworkClientInfo::GetByClientID(_network_own_client_id); SetDParamStr(0, own_ci != nullptr ? own_ci->client_name : _settings_client.network.client_name); } - *size = GetStringBoundingBox(STR_JUST_RAW_STRING); - size->width = std::min(size->width, static_cast(ScaleGUITrad(200))); // By default, don't open the window too wide. + size = GetStringBoundingBox(STR_JUST_RAW_STRING); + size.width = std::min(size.width, static_cast(ScaleGUITrad(200))); // By default, don't open the window too wide. break; case WID_CL_SERVER_VISIBILITY: - *size = maxdim(maxdim(GetStringBoundingBox(STR_NETWORK_SERVER_VISIBILITY_LOCAL), GetStringBoundingBox(STR_NETWORK_SERVER_VISIBILITY_PUBLIC)), GetStringBoundingBox(STR_NETWORK_SERVER_VISIBILITY_INVITE_ONLY)); - size->width += padding.width; - size->height += padding.height; + size = maxdim(maxdim(GetStringBoundingBox(STR_NETWORK_SERVER_VISIBILITY_LOCAL), GetStringBoundingBox(STR_NETWORK_SERVER_VISIBILITY_PUBLIC)), GetStringBoundingBox(STR_NETWORK_SERVER_VISIBILITY_INVITE_ONLY)); + size.width += padding.width; + size.height += padding.height; break; case WID_CL_MATRIX: { @@ -1710,10 +1710,10 @@ public: height += WidgetDimensions::scaled.framerect.Vertical(); this->line_height = std::max(height, (uint)GetCharacterHeight(FS_NORMAL)) + padding.height; - resize->width = 1; - resize->height = this->line_height; - fill->height = this->line_height; - size->height = std::max(size->height, 5 * this->line_height); + resize.width = 1; + resize.height = this->line_height; + fill.height = this->line_height; + size.height = std::max(size.height, 5 * this->line_height); break; } } @@ -2173,28 +2173,28 @@ struct NetworkJoinStatusWindow : Window { } } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_NJS_PROGRESS_BAR: /* Account for the statuses */ for (uint i = 0; i < NETWORK_JOIN_STATUS_END; i++) { - *size = maxdim(*size, GetStringBoundingBox(STR_NETWORK_CONNECTING_1 + i)); + size = maxdim(size, GetStringBoundingBox(STR_NETWORK_CONNECTING_1 + i)); } /* For the number of waiting (other) players */ SetDParamMaxValue(0, MAX_CLIENTS); - *size = maxdim(*size, GetStringBoundingBox(STR_NETWORK_CONNECTING_WAITING)); + size = maxdim(size, GetStringBoundingBox(STR_NETWORK_CONNECTING_WAITING)); /* We need some spacing for the 'border' */ - size->height += WidgetDimensions::scaled.frametext.Horizontal(); - size->width += WidgetDimensions::scaled.frametext.Vertical(); + size.height += WidgetDimensions::scaled.frametext.Horizontal(); + size.width += WidgetDimensions::scaled.frametext.Vertical(); break; case WID_NJS_PROGRESS_TEXT: /* Account for downloading ~ 10 MiB */ SetDParamMaxDigits(0, 8); SetDParamMaxDigits(1, 8); - *size = maxdim(*size, GetStringBoundingBox(STR_NETWORK_CONNECTING_DOWNLOADING_1)); - *size = maxdim(*size, GetStringBoundingBox(STR_NETWORK_CONNECTING_DOWNLOADING_1)); + size = maxdim(size, GetStringBoundingBox(STR_NETWORK_CONNECTING_DOWNLOADING_1)); + size = maxdim(size, GetStringBoundingBox(STR_NETWORK_CONNECTING_DOWNLOADING_1)); break; } } @@ -2245,7 +2245,7 @@ void ShowJoinStatusWindow() void ShowNetworkNeedPassword(NetworkPasswordType npt, std::shared_ptr request) { - NetworkJoinStatusWindow *w = (NetworkJoinStatusWindow *)FindWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN); + NetworkJoinStatusWindow *w = dynamic_cast(FindWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN)); if (w == nullptr) return; w->request = request; @@ -2381,10 +2381,10 @@ struct NetworkAskRelayWindow : public Window { this->Window::Close(); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { if (widget == WID_NAR_TEXT) { - *size = GetStringBoundingBox(STR_NETWORK_ASK_RELAY_TEXT); + size = GetStringBoundingBox(STR_NETWORK_ASK_RELAY_TEXT); } } @@ -2484,10 +2484,10 @@ struct NetworkAskSurveyWindow : public Window { this->InitNested(0); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { if (widget == WID_NAS_TEXT) { - *size = GetStringBoundingBox(STR_NETWORK_ASK_SURVEY_TEXT); + size = GetStringBoundingBox(STR_NETWORK_ASK_SURVEY_TEXT); } } diff --git a/src/network/network_type.h b/src/network/network_type.h index 1a272b8fd9..14d50f1c09 100644 --- a/src/network/network_type.h +++ b/src/network/network_type.h @@ -11,6 +11,8 @@ #define NETWORK_TYPE_H #include "../core/enum_type.hpp" +#include +#include /** How many clients can we have */ static const uint MAX_CLIENTS = 255; diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 1a8a635fa7..b522f15053 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -14,6 +14,7 @@ #include "newgrf_internal.h" #include "core/container_func.hpp" #include "debug.h" +#include "debug_fmt.h" #include "fileio_func.h" #include "engine_func.h" #include "engine_base.h" @@ -30,6 +31,7 @@ #include "newgrf_station.h" #include "industrytype.h" #include "industry_map.h" +#include "newgrf_act5.h" #include "newgrf_canal.h" #include "newgrf_townname.h" #include "newgrf_industries.h" @@ -166,22 +168,15 @@ public: } } - const char *ReadString() + std::string_view ReadString() { char *string = reinterpret_cast(data); size_t string_length = ttd_strnlen(string, Remaining()); - if (string_length == Remaining()) { - /* String was not NUL terminated, so make sure it is now. */ - string[string_length - 1] = '\0'; - grfmsg(7, "String was not terminated with a zero byte."); - } else { - /* Increase the string length to include the NUL byte. */ - string_length++; - } - Skip(string_length); + /* Skip past the terminating NUL byte if it is present, but not more than remaining. */ + Skip(std::min(string_length + 1, Remaining())); - return string; + return std::string_view(string, string_length); } inline size_t Remaining() const @@ -307,6 +302,21 @@ void CDECL _intl_grfmsg(int severity, const char *str, ...) DEBUG(grf, severity, "[%s:%d] %s", _cur.grfconfig->GetDisplayPath(), _cur.nfo_line, buf); } +/** + * Debug() function dedicated to newGRF debugging messages + * Function is essentially the same as Debug(grf, severity, ...) with the + * addition of file:line information when parsing grf files. + * NOTE: for the above reason(s) GrfMsg() should ONLY be used for + * loading/parsing grf files, not for runtime debug messages as there + * is no file information available during that time. + * @param severity debugging severity level, see debug.h + * @param msg the message + */ +void GrfMsgI(int severity, const std::string &msg) +{ + Debug(grf, severity, "[{}:{}] {}", _cur.grfconfig->filename, _cur.nfo_line, msg); +} + /** * Obtain a NewGRF file by its grfID * @param grfid The grfID to obtain the file for @@ -458,7 +468,7 @@ static StringID TTDPStringIDToOTTDStringIDMapping(StringID str) if (str == STR_NULL) return STR_EMPTY; - DEBUG(grf, 0, "Unknown StringID 0x%04X remapped to STR_EMPTY. Please open a Feature Request if you need it", str); + Debug(grf, 0, "Unknown StringID 0x{:04X} remapped to STR_EMPTY. Please open a Feature Request if you need it", str); return STR_EMPTY; } @@ -507,7 +517,7 @@ static btree::btree_map _grf_id_overrides; static void SetNewGRFOverride(uint32_t source_grfid, uint32_t target_grfid) { _grf_id_overrides[source_grfid] = target_grfid; - grfmsg(5, "SetNewGRFOverride: Added override of 0x%X to 0x%X", BSWAP32(source_grfid), BSWAP32(target_grfid)); + GrfMsg(5, "SetNewGRFOverride: Added override of 0x{:X} to 0x{:X}", BSWAP32(source_grfid), BSWAP32(target_grfid)); } /** @@ -531,9 +541,9 @@ static Engine *GetNewEngine(const GRFFile *file, VehicleType type, uint16_t inte scope_grfid = override; const GRFFile *grf_match = GetFileByGRFID(override); if (grf_match == nullptr) { - grfmsg(5, "Tried mapping from GRFID %x to %x but target is not loaded", BSWAP32(file->grfid), BSWAP32(override)); + GrfMsg(5, "Tried mapping from GRFID {:x} to {:x} but target is not loaded", BSWAP32(file->grfid), BSWAP32(override)); } else { - grfmsg(5, "Mapping from GRFID %x to %x", BSWAP32(file->grfid), BSWAP32(override)); + GrfMsg(5, "Mapping from GRFID {:x} to {:x}", BSWAP32(file->grfid), BSWAP32(override)); } } @@ -553,7 +563,7 @@ static Engine *GetNewEngine(const GRFFile *file, VehicleType type, uint16_t inte if (e->grf_prop.grffile == nullptr) { e->grf_prop.grffile = file; - grfmsg(5, "Replaced engine at index %d for GRFID %x, type %d, index %d", e->index, BSWAP32(file->grfid), type, internal_id); + GrfMsg(5, "Replaced engine at index {} for GRFID {:x}, type {}, index {}", e->index, BSWAP32(file->grfid), type, internal_id); } /* Reserve the engine slot */ @@ -568,7 +578,7 @@ static Engine *GetNewEngine(const GRFFile *file, VehicleType type, uint16_t inte if (static_access) return nullptr; if (!Engine::CanAllocateItem()) { - grfmsg(0, "Can't allocate any more engines"); + GrfMsg(0, "Can't allocate any more engines"); return nullptr; } @@ -595,7 +605,7 @@ static Engine *GetNewEngine(const GRFFile *file, VehicleType type, uint16_t inte _gted[e->index].railtypelabel = GetRailTypeInfo(e->u.rail.railtype)->label; } - grfmsg(5, "Created new engine at index %d for GRFID %x, type %d, index %d", e->index, BSWAP32(file->grfid), type, internal_id); + GrfMsg(5, "Created new engine at index {} for GRFID {:x}, type {}, index {}", e->index, BSWAP32(file->grfid), type, internal_id); return e; } @@ -671,7 +681,7 @@ static TileLayoutFlags ReadSpriteLayoutSprite(ByteReader *buf, bool read_flags, /* Use sprite from Action 1 */ uint index = GB(grf_sprite->sprite, 0, 14); if (use_cur_spritesets && (!_cur.IsValidSpriteSet(feature, index) || _cur.GetNumEnts(feature, index) == 0)) { - grfmsg(1, "ReadSpriteLayoutSprite: Spritelayout uses undefined custom spriteset %d", index); + GrfMsg(1, "ReadSpriteLayoutSprite: Spritelayout uses undefined custom spriteset {}", index); grf_sprite->sprite = SPR_IMG_QUERY; grf_sprite->pal = PAL_NONE; } else { @@ -681,7 +691,7 @@ static TileLayoutFlags ReadSpriteLayoutSprite(ByteReader *buf, bool read_flags, SetBit(grf_sprite->sprite, SPRITE_MODIFIER_CUSTOM_SPRITE); } } else if ((flags & TLF_SPRITE_VAR10) && !(flags & TLF_SPRITE_REG_FLAGS)) { - grfmsg(1, "ReadSpriteLayoutSprite: Spritelayout specifies var10 value for non-action-1 sprite"); + GrfMsg(1, "ReadSpriteLayoutSprite: Spritelayout specifies var10 value for non-action-1 sprite"); DisableGrf(STR_NEWGRF_ERROR_INVALID_SPRITE_LAYOUT); return flags; } @@ -690,7 +700,7 @@ static TileLayoutFlags ReadSpriteLayoutSprite(ByteReader *buf, bool read_flags, /* Use palette from Action 1 */ uint index = GB(grf_sprite->pal, 0, 14); if (use_cur_spritesets && (!_cur.IsValidSpriteSet(feature, index) || _cur.GetNumEnts(feature, index) == 0)) { - grfmsg(1, "ReadSpriteLayoutSprite: Spritelayout uses undefined custom spriteset %d for 'palette'", index); + GrfMsg(1, "ReadSpriteLayoutSprite: Spritelayout uses undefined custom spriteset {} for 'palette'", index); grf_sprite->pal = PAL_NONE; } else { SpriteID sprite = use_cur_spritesets ? _cur.GetSprite(feature, index) : index; @@ -699,7 +709,7 @@ static TileLayoutFlags ReadSpriteLayoutSprite(ByteReader *buf, bool read_flags, SetBit(grf_sprite->pal, SPRITE_MODIFIER_CUSTOM_SPRITE); } } else if ((flags & TLF_PALETTE_VAR10) && !(flags & TLF_PALETTE_REG_FLAGS)) { - grfmsg(1, "ReadSpriteLayoutRegisters: Spritelayout specifies var10 value for non-action-1 palette"); + GrfMsg(1, "ReadSpriteLayoutRegisters: Spritelayout specifies var10 value for non-action-1 palette"); DisableGrf(STR_NEWGRF_ERROR_INVALID_SPRITE_LAYOUT); return flags; } @@ -741,7 +751,7 @@ static void ReadSpriteLayoutRegisters(ByteReader *buf, TileLayoutFlags flags, bo if (flags & TLF_SPRITE_VAR10) { regs.sprite_var10 = buf->ReadByte(); if (regs.sprite_var10 > TLR_MAX_VAR10) { - grfmsg(1, "ReadSpriteLayoutRegisters: Spritelayout specifies var10 (%d) exceeding the maximal allowed value %d", regs.sprite_var10, TLR_MAX_VAR10); + GrfMsg(1, "ReadSpriteLayoutRegisters: Spritelayout specifies var10 ({}) exceeding the maximal allowed value {}", regs.sprite_var10, TLR_MAX_VAR10); DisableGrf(STR_NEWGRF_ERROR_INVALID_SPRITE_LAYOUT); return; } @@ -750,7 +760,7 @@ static void ReadSpriteLayoutRegisters(ByteReader *buf, TileLayoutFlags flags, bo if (flags & TLF_PALETTE_VAR10) { regs.palette_var10 = buf->ReadByte(); if (regs.palette_var10 > TLR_MAX_VAR10) { - grfmsg(1, "ReadSpriteLayoutRegisters: Spritelayout specifies var10 (%d) exceeding the maximal allowed value %d", regs.palette_var10, TLR_MAX_VAR10); + GrfMsg(1, "ReadSpriteLayoutRegisters: Spritelayout specifies var10 ({}) exceeding the maximal allowed value {}", regs.palette_var10, TLR_MAX_VAR10); DisableGrf(STR_NEWGRF_ERROR_INVALID_SPRITE_LAYOUT); return; } @@ -786,7 +796,7 @@ static bool ReadSpriteLayout(ByteReader *buf, uint num_building_sprites, bool us if (_cur.skip_sprites < 0) return true; if (flags & ~(valid_flags & ~TLF_NON_GROUND_FLAGS)) { - grfmsg(1, "ReadSpriteLayout: Spritelayout uses invalid flag 0x%x for ground sprite", flags & ~(valid_flags & ~TLF_NON_GROUND_FLAGS)); + GrfMsg(1, "ReadSpriteLayout: Spritelayout uses invalid flag 0x{:X} for ground sprite", flags & ~(valid_flags & ~TLF_NON_GROUND_FLAGS)); DisableGrf(STR_NEWGRF_ERROR_INVALID_SPRITE_LAYOUT); return true; } @@ -801,7 +811,7 @@ static bool ReadSpriteLayout(ByteReader *buf, uint num_building_sprites, bool us if (_cur.skip_sprites < 0) return true; if (flags & ~valid_flags) { - grfmsg(1, "ReadSpriteLayout: Spritelayout uses unknown flag 0x%x", flags & ~valid_flags); + GrfMsg(1, "ReadSpriteLayout: Spritelayout uses unknown flag 0x{:X}", flags & ~valid_flags); DisableGrf(STR_NEWGRF_ERROR_INVALID_SPRITE_LAYOUT); return true; } @@ -868,7 +878,7 @@ static CargoTypes TranslateRefitMask(uint32_t refit_mask) CargoTypes result = 0; for (uint8_t bit : SetBitIterator(refit_mask)) { CargoID cargo = GetCargoTranslation(bit, _cur.grffile, true); - if (cargo != INVALID_CARGO) SetBit(result, cargo); + if (IsValidCargoID(cargo)) SetBit(result, cargo); } return result; } @@ -892,7 +902,7 @@ static void ConvertTTDBasePrice(uint32_t base_pointer, const char *error_locatio static const uint32_t size = 6; ///< Size of each base price record if (base_pointer < start || (base_pointer - start) % size != 0 || (base_pointer - start) / size >= PR_END) { - grfmsg(1, "%s: Unsupported running cost base 0x%04X, ignoring", error_location, base_pointer); + GrfMsg(1, "{}: Unsupported running cost base 0x{:04X}, ignoring", error_location, base_pointer); return; } @@ -1014,7 +1024,7 @@ static ChangeInfoResult RailVehicleChangeInfo(uint engine, int numinfo, int prop case 1: _gted[e->index].railtypelabel = RAILTYPE_LABEL_MONO; break; case 2: _gted[e->index].railtypelabel = RAILTYPE_LABEL_MAGLEV; break; default: - grfmsg(1, "RailVehicleChangeInfo: Invalid track type %d specified, ignoring", tracktype); + GrfMsg(1, "RailVehicleChangeInfo: Invalid track type {} specified, ignoring", tracktype); break; } break; @@ -1066,7 +1076,7 @@ static ChangeInfoResult RailVehicleChangeInfo(uint engine, int numinfo, int prop if (IsValidNewGRFImageIndex(spriteid)) { rvi->image_index = spriteid; } else { - grfmsg(1, "RailVehicleChangeInfo: Invalid Sprite %d specified, ignoring", orig_spriteid); + GrfMsg(1, "RailVehicleChangeInfo: Invalid Sprite {} specified, ignoring", orig_spriteid); rvi->image_index = 0; } break; @@ -1103,7 +1113,7 @@ static ChangeInfoResult RailVehicleChangeInfo(uint engine, int numinfo, int prop ei->cargo_type = ctype; } else { ei->cargo_type = INVALID_CARGO; - grfmsg(2, "RailVehicleChangeInfo: Invalid cargo type %d, using first refittable", ctype); + GrfMsg(2, "RailVehicleChangeInfo: Invalid cargo type {}, using first refittable", ctype); } ei->cargo_label = CT_INVALID; break; @@ -1118,7 +1128,7 @@ static ChangeInfoResult RailVehicleChangeInfo(uint engine, int numinfo, int prop break; case 0x18: // AI rank - grfmsg(2, "RailVehicleChangeInfo: Property 0x18 'AI rank' not used by NoAI, ignored."); + GrfMsg(2, "RailVehicleChangeInfo: Property 0x18 'AI rank' not used by NoAI, ignored."); buf->ReadByte(); break; @@ -1212,7 +1222,7 @@ static ChangeInfoResult RailVehicleChangeInfo(uint engine, int numinfo, int prop uint8_t weight = buf->ReadByte(); if (weight > 4) { - grfmsg(2, "RailVehicleChangeInfo: Nonsensical weight of %d tons, ignoring", weight << 8); + GrfMsg(2, "RailVehicleChangeInfo: Nonsensical weight of {} tons, ignoring", weight << 8); } else { SB(rvi->weight, 8, 8, weight); } @@ -1260,8 +1270,7 @@ static ChangeInfoResult RailVehicleChangeInfo(uint engine, int numinfo, int prop ctt = 0; while (count--) { CargoID ctype = GetCargoTranslation(buf->ReadByte(), _cur.grffile); - if (ctype == INVALID_CARGO) continue; - SetBit(ctt, ctype); + if (IsValidCargoID(ctype)) SetBit(ctt, ctype); } break; } @@ -1341,7 +1350,7 @@ static ChangeInfoResult RoadVehicleChangeInfo(uint engine, int numinfo, int prop if (IsValidNewGRFImageIndex(spriteid)) { rvi->image_index = spriteid; } else { - grfmsg(1, "RoadVehicleChangeInfo: Invalid Sprite %d specified, ignoring", orig_spriteid); + GrfMsg(1, "RoadVehicleChangeInfo: Invalid Sprite {} specified, ignoring", orig_spriteid); rvi->image_index = 0; } break; @@ -1366,7 +1375,7 @@ static ChangeInfoResult RoadVehicleChangeInfo(uint engine, int numinfo, int prop ei->cargo_type = ctype; } else { ei->cargo_type = INVALID_CARGO; - grfmsg(2, "RailVehicleChangeInfo: Invalid cargo type %d, using first refittable", ctype); + GrfMsg(2, "RailVehicleChangeInfo: Invalid cargo type {}, using first refittable", ctype); } ei->cargo_label = CT_INVALID; break; @@ -1471,8 +1480,7 @@ static ChangeInfoResult RoadVehicleChangeInfo(uint engine, int numinfo, int prop ctt = 0; while (count--) { CargoID ctype = GetCargoTranslation(buf->ReadByte(), _cur.grffile); - if (ctype == INVALID_CARGO) continue; - SetBit(ctt, ctype); + if (IsValidCargoID(ctype)) SetBit(ctt, ctype); } break; } @@ -1530,7 +1538,7 @@ static ChangeInfoResult ShipVehicleChangeInfo(uint engine, int numinfo, int prop if (IsValidNewGRFImageIndex(spriteid)) { svi->image_index = spriteid; } else { - grfmsg(1, "ShipVehicleChangeInfo: Invalid Sprite %d specified, ignoring", orig_spriteid); + GrfMsg(1, "ShipVehicleChangeInfo: Invalid Sprite {} specified, ignoring", orig_spriteid); svi->image_index = 0; } break; @@ -1563,7 +1571,7 @@ static ChangeInfoResult ShipVehicleChangeInfo(uint engine, int numinfo, int prop ei->cargo_type = ctype; } else { ei->cargo_type = INVALID_CARGO; - grfmsg(2, "ShipVehicleChangeInfo: Invalid cargo type %d, using first refittable", ctype); + GrfMsg(2, "ShipVehicleChangeInfo: Invalid cargo type {}, using first refittable", ctype); } ei->cargo_label = CT_INVALID; break; @@ -1656,8 +1664,7 @@ static ChangeInfoResult ShipVehicleChangeInfo(uint engine, int numinfo, int prop ctt = 0; while (count--) { CargoID ctype = GetCargoTranslation(buf->ReadByte(), _cur.grffile); - if (ctype == INVALID_CARGO) continue; - SetBit(ctt, ctype); + if (IsValidCargoID(ctype)) SetBit(ctt, ctype); } break; } @@ -1723,7 +1730,7 @@ static ChangeInfoResult AircraftVehicleChangeInfo(uint engine, int numinfo, int if (IsValidNewGRFImageIndex(spriteid)) { avi->image_index = spriteid; } else { - grfmsg(1, "AircraftVehicleChangeInfo: Invalid Sprite %d specified, ignoring", orig_spriteid); + GrfMsg(1, "AircraftVehicleChangeInfo: Invalid Sprite {} specified, ignoring", orig_spriteid); avi->image_index = 0; } break; @@ -1826,8 +1833,7 @@ static ChangeInfoResult AircraftVehicleChangeInfo(uint engine, int numinfo, int ctt = 0; while (count--) { CargoID ctype = GetCargoTranslation(buf->ReadByte(), _cur.grffile); - if (ctype == INVALID_CARGO) continue; - SetBit(ctt, ctype); + if (IsValidCargoID(ctype)) SetBit(ctt, ctype); } break; } @@ -1870,7 +1876,7 @@ static ChangeInfoResult StationChangeInfo(uint stid, int numinfo, int prop, cons ChangeInfoResult ret = CIR_SUCCESS; if (stid + numinfo > NUM_STATIONS_PER_GRF) { - grfmsg(1, "StationChangeInfo: Station %u is invalid, max %u, ignoring", stid + numinfo, NUM_STATIONS_PER_GRF); + GrfMsg(1, "StationChangeInfo: Station {} is invalid, max {}, ignoring", stid + numinfo, NUM_STATIONS_PER_GRF); return CIR_INVALID_ID; } @@ -1882,7 +1888,7 @@ static ChangeInfoResult StationChangeInfo(uint stid, int numinfo, int prop, cons /* Check that the station we are modifying is defined. */ if (statspec == nullptr && prop != 0x08) { - grfmsg(2, "StationChangeInfo: Attempt to modify undefined station %u, ignoring", stid + i); + GrfMsg(2, "StationChangeInfo: Attempt to modify undefined station {}, ignoring", stid + i); return CIR_INVALID_ID; } @@ -1944,7 +1950,7 @@ static ChangeInfoResult StationChangeInfo(uint stid, int numinfo, int prop, cons /* Number of layouts must be even, alternating X and Y */ if (statspec->renderdata.size() & 1) { - grfmsg(1, "StationChangeInfo: Station %u defines an odd number of sprite layouts, dropping the last item", stid + i); + GrfMsg(1, "StationChangeInfo: Station {} defines an odd number of sprite layouts, dropping the last item", stid + i); statspec->renderdata.pop_back(); } break; @@ -1955,7 +1961,7 @@ static ChangeInfoResult StationChangeInfo(uint stid, int numinfo, int prop, cons const StationSpec *srcstatspec = srcid >= _cur.grffile->stations.size() ? nullptr : _cur.grffile->stations[srcid].get(); if (srcstatspec == nullptr) { - grfmsg(1, "StationChangeInfo: Station %u is not defined, cannot copy sprite layout to %u.", srcid, stid + i); + GrfMsg(1, "StationChangeInfo: Station {} is not defined, cannot copy sprite layout to {}.", srcid, stid + i); continue; } @@ -1997,7 +2003,7 @@ static ChangeInfoResult StationChangeInfo(uint stid, int numinfo, int prop, cons /* Validate tile values are only the permitted 00, 02, 04 and 06. */ for (auto &tile : statspec->layouts[length - 1][number - 1]) { if ((tile & 6) != tile) { - grfmsg(1, "StationChangeInfo: Invalid tile %u in layout %ux%u", tile, length, number); + GrfMsg(1, "StationChangeInfo: Invalid tile {} in layout {}x{}", tile, length, number); tile &= 6; } } @@ -2009,7 +2015,7 @@ static ChangeInfoResult StationChangeInfo(uint stid, int numinfo, int prop, cons const StationSpec *srcstatspec = srcid >= _cur.grffile->stations.size() ? nullptr : _cur.grffile->stations[srcid].get(); if (srcstatspec == nullptr) { - grfmsg(1, "StationChangeInfo: Station %u is not defined, cannot copy tile layout to %u.", srcid, stid + i); + GrfMsg(1, "StationChangeInfo: Station {} is not defined, cannot copy tile layout to {}.", srcid, stid + i); continue; } @@ -2074,7 +2080,7 @@ static ChangeInfoResult StationChangeInfo(uint stid, int numinfo, int prop, cons /* Number of layouts must be even, alternating X and Y */ if (statspec->renderdata.size() & 1) { - grfmsg(1, "StationChangeInfo: Station %u defines an odd number of sprite layouts, dropping the last item", stid + i); + GrfMsg(1, "StationChangeInfo: Station {} defines an odd number of sprite layouts, dropping the last item", stid + i); statspec->renderdata.pop_back(); } break; @@ -2128,7 +2134,7 @@ static ChangeInfoResult CanalChangeInfo(uint id, int numinfo, int prop, const GR ChangeInfoResult ret = CIR_SUCCESS; if (id + numinfo > CF_END) { - grfmsg(1, "CanalChangeInfo: Canal feature 0x%02X is invalid, max %u, ignoring", id + numinfo, CF_END); + GrfMsg(1, "CanalChangeInfo: Canal feature 0x{:02X} is invalid, max {}, ignoring", id + numinfo, CF_END); return CIR_INVALID_ID; } @@ -2166,7 +2172,7 @@ static ChangeInfoResult BridgeChangeInfo(uint brid, int numinfo, int prop, const ChangeInfoResult ret = CIR_SUCCESS; if (brid + numinfo > MAX_BRIDGES) { - grfmsg(1, "BridgeChangeInfo: Bridge %u is invalid, max %u, ignoring", brid + numinfo, MAX_BRIDGES); + GrfMsg(1, "BridgeChangeInfo: Bridge {} is invalid, max {}, ignoring", brid + numinfo, MAX_BRIDGES); return CIR_INVALID_ID; } @@ -2210,7 +2216,7 @@ static ChangeInfoResult BridgeChangeInfo(uint brid, int numinfo, int prop, const for (; numtables-- != 0; tableid++) { if (tableid >= 7) { // skip invalid data - grfmsg(1, "BridgeChangeInfo: Table %d >= 7, skipping", tableid); + GrfMsg(1, "BridgeChangeInfo: Table {} >= 7, skipping", tableid); for (uint8_t sprite = 0; sprite < 32; sprite++) buf->ReadDWord(); continue; } @@ -2370,7 +2376,7 @@ static ChangeInfoResult TownHouseChangeInfo(uint hid, int numinfo, int prop, con ChangeInfoResult ret = CIR_SUCCESS; if (hid + numinfo > NUM_HOUSES_PER_GRF) { - grfmsg(1, "TownHouseChangeInfo: Too many houses loaded (%u), max (%u). Ignoring.", hid + numinfo, NUM_HOUSES_PER_GRF); + GrfMsg(1, "TownHouseChangeInfo: Too many houses loaded ({}), max ({}). Ignoring.", hid + numinfo, NUM_HOUSES_PER_GRF); return CIR_INVALID_ID; } @@ -2397,7 +2403,7 @@ static ChangeInfoResult TownHouseChangeInfo(uint hid, int numinfo, int prop, con continue; } else if (subs_id >= NEW_HOUSE_OFFSET) { /* The substitute id must be one of the original houses. */ - grfmsg(2, "TownHouseChangeInfo: Attempt to use new house %u as substitute house for %u. Ignoring.", subs_id, hid + i); + GrfMsg(2, "TownHouseChangeInfo: Attempt to use new house {} as substitute house for {}. Ignoring.", subs_id, hid + i); continue; } @@ -2499,7 +2505,7 @@ static ChangeInfoResult TownHouseChangeInfo(uint hid, int numinfo, int prop, con /* The house being overridden must be an original house. */ if (override >= NEW_HOUSE_OFFSET) { - grfmsg(2, "TownHouseChangeInfo: Attempt to override new house %u with house id %u. Ignoring.", override, hid + i); + GrfMsg(2, "TownHouseChangeInfo: Attempt to override new house {} with house id {}. Ignoring.", override, hid + i); continue; } @@ -2552,7 +2558,7 @@ static ChangeInfoResult TownHouseChangeInfo(uint hid, int numinfo, int prop, con uint8_t cargo_part = GB(cargotypes, 8 * j, 8); CargoID cargo = GetCargoTranslation(cargo_part, _cur.grffile); - if (cargo == INVALID_CARGO) { + if (!IsValidCargoID(cargo)) { /* Disable acceptance of invalid cargo type */ housespec->cargo_acceptance[j] = 0; } else { @@ -2570,7 +2576,7 @@ static ChangeInfoResult TownHouseChangeInfo(uint hid, int numinfo, int prop, con uint8_t count = buf->ReadByte(); for (uint8_t j = 0; j < count; j++) { CargoID cargo = GetCargoTranslation(buf->ReadByte(), _cur.grffile); - if (cargo != INVALID_CARGO) SetBit(housespec->watched_cargoes, cargo); + if (IsValidCargoID(cargo)) SetBit(housespec->watched_cargoes, cargo); } break; } @@ -2641,7 +2647,7 @@ template static ChangeInfoResult LoadTranslationTable(uint gvid, int numinfo, ByteReader *buf, std::vector &translation_table, const char *name) { if (gvid != 0) { - grfmsg(1, "LoadTranslationTable: %s translation table must start at zero", name); + GrfMsg(1, "LoadTranslationTable: {} translation table must start at zero", name); return CIR_INVALID_ID; } @@ -2705,7 +2711,7 @@ static ChangeInfoResult GlobalVarChangeInfo(uint gvid, int numinfo, int prop, co if (price < PR_END) { _cur.grffile->price_base_multipliers[price] = std::min(factor - 8, MAX_PRICE_MODIFIER); } else { - grfmsg(1, "GlobalVarChangeInfo: Price %d out of range, ignoring", price); + GrfMsg(1, "GlobalVarChangeInfo: Price {} out of range, ignoring", price); } break; } @@ -2731,7 +2737,7 @@ static ChangeInfoResult GlobalVarChangeInfo(uint gvid, int numinfo, int prop, co * to be compatible */ _currency_specs[curidx].rate = rate / 1000; } else { - grfmsg(1, "GlobalVarChangeInfo: Currency multipliers %d out of range, ignoring", curidx); + GrfMsg(1, "GlobalVarChangeInfo: Currency multipliers {} out of range, ignoring", curidx); } break; } @@ -2747,7 +2753,7 @@ static ChangeInfoResult GlobalVarChangeInfo(uint gvid, int numinfo, int prop, co * since newgrf specs said that only 0 and 1 can be set for symbol_pos */ _currency_specs[curidx].symbol_pos = GB(options, 8, 1); } else { - grfmsg(1, "GlobalVarChangeInfo: Currency option %d out of range, ignoring", curidx); + GrfMsg(1, "GlobalVarChangeInfo: Currency option {} out of range, ignoring", curidx); } break; } @@ -2759,7 +2765,7 @@ static ChangeInfoResult GlobalVarChangeInfo(uint gvid, int numinfo, int prop, co if (curidx < CURRENCY_END) { _currency_specs[curidx].prefix = prefix; } else { - grfmsg(1, "GlobalVarChangeInfo: Currency symbol %d out of range, ignoring", curidx); + GrfMsg(1, "GlobalVarChangeInfo: Currency symbol {} out of range, ignoring", curidx); } break; } @@ -2771,7 +2777,7 @@ static ChangeInfoResult GlobalVarChangeInfo(uint gvid, int numinfo, int prop, co if (curidx < CURRENCY_END) { _currency_specs[curidx].suffix = suffix; } else { - grfmsg(1, "GlobalVarChangeInfo: Currency symbol %d out of range, ignoring", curidx); + GrfMsg(1, "GlobalVarChangeInfo: Currency symbol {} out of range, ignoring", curidx); } break; } @@ -2783,16 +2789,16 @@ static ChangeInfoResult GlobalVarChangeInfo(uint gvid, int numinfo, int prop, co if (curidx < CURRENCY_END) { _currency_specs[curidx].to_euro = year_euro; } else { - grfmsg(1, "GlobalVarChangeInfo: Euro intro date %d out of range, ignoring", curidx); + GrfMsg(1, "GlobalVarChangeInfo: Euro intro date {} out of range, ignoring", curidx); } break; } case 0x10: // Snow line height table if (numinfo > 1 || IsSnowLineSet()) { - grfmsg(1, "GlobalVarChangeInfo: The snowline can only be set once (%d)", numinfo); + GrfMsg(1, "GlobalVarChangeInfo: The snowline can only be set once ({})", numinfo); } else if (buf->Remaining() < SNOW_LINE_MONTHS * SNOW_LINE_DAYS) { - grfmsg(1, "GlobalVarChangeInfo: Not enough entries set in the snowline table (" PRINTF_SIZE ")", buf->Remaining()); + GrfMsg(1, "GlobalVarChangeInfo: Not enough entries set in the snowline table ({})", buf->Remaining()); } else { uint8_t table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS]; @@ -2827,7 +2833,7 @@ static ChangeInfoResult GlobalVarChangeInfo(uint gvid, int numinfo, int prop, co uint curidx = gvid + i; // The current index, i.e. language. const LanguageMetadata *lang = curidx < MAX_LANG ? GetLanguage(curidx) : nullptr; if (lang == nullptr) { - grfmsg(1, "GlobalVarChangeInfo: Language %d is not known, ignoring", curidx); + GrfMsg(1, "GlobalVarChangeInfo: Language {} is not known, ignoring", curidx); /* Skip over the data. */ if (prop == 0x15) { buf->ReadByte(); @@ -2844,7 +2850,7 @@ static ChangeInfoResult GlobalVarChangeInfo(uint gvid, int numinfo, int prop, co if (prop == 0x15) { uint plural_form = buf->ReadByte(); if (plural_form >= LANGUAGE_MAX_PLURAL) { - grfmsg(1, "GlobalVarChanceInfo: Plural form %d is out of range, ignoring", plural_form); + GrfMsg(1, "GlobalVarChanceInfo: Plural form {} is out of range, ignoring", plural_form); } else { _cur.grffile->language_map[curidx].plural_form = plural_form; } @@ -2853,29 +2859,29 @@ static ChangeInfoResult GlobalVarChangeInfo(uint gvid, int numinfo, int prop, co uint8_t newgrf_id = buf->ReadByte(); // The NewGRF (custom) identifier. while (newgrf_id != 0) { - const char *name = buf->ReadString(); // The name for the OpenTTD identifier. + std::string_view name = buf->ReadString(); // The name for the OpenTTD identifier. /* We'll just ignore the UTF8 identifier character. This is (fairly) * safe as OpenTTD's strings gender/cases are usually in ASCII which * is just a subset of UTF8, or they need the bigger UTF8 characters * such as Cyrillic. Thus we will simply assume they're all UTF8. */ char32_t c; - size_t len = Utf8Decode(&c, name); - if (c == NFO_UTF8_IDENTIFIER) name += len; + size_t len = Utf8Decode(&c, name.data()); + if (c == NFO_UTF8_IDENTIFIER) name = name.substr(len); LanguageMap::Mapping map; map.newgrf_id = newgrf_id; if (prop == 0x13) { - map.openttd_id = lang->GetGenderIndex(name); + map.openttd_id = lang->GetGenderIndex(name.data()); if (map.openttd_id >= MAX_NUM_GENDERS) { - grfmsg(1, "GlobalVarChangeInfo: Gender name %s is not known, ignoring", name); + GrfMsg(1, "GlobalVarChangeInfo: Gender name {} is not known, ignoring", name); } else { _cur.grffile->language_map[curidx].gender_map.push_back(map); } } else { - map.openttd_id = lang->GetCaseIndex(name); + map.openttd_id = lang->GetCaseIndex(name.data()); if (map.openttd_id >= MAX_NUM_CASES) { - grfmsg(1, "GlobalVarChangeInfo: Case name %s is not known, ignoring", name); + GrfMsg(1, "GlobalVarChangeInfo: Case name {} is not known, ignoring", name); } else { _cur.grffile->language_map[curidx].case_map.push_back(map); } @@ -3019,7 +3025,7 @@ static ChangeInfoResult CargoChangeInfo(uint cid, int numinfo, int prop, const G ChangeInfoResult ret = CIR_SUCCESS; if (cid + numinfo > NUM_CARGO) { - grfmsg(2, "CargoChangeInfo: Cargo type %d out of range (max %d)", cid + numinfo, NUM_CARGO - 1); + GrfMsg(2, "CargoChangeInfo: Cargo type {} out of range (max {})", cid + numinfo, NUM_CARGO - 1); return CIR_INVALID_ID; } @@ -3117,7 +3123,7 @@ static ChangeInfoResult CargoChangeInfo(uint cid, int numinfo, int prop, const G case 0x09: cs->town_acceptance_effect = TAE_WATER; break; case 0x0B: cs->town_acceptance_effect = TAE_FOOD; break; default: - grfmsg(1, "CargoChangeInfo: Unknown town growth substitute value %d, setting to none.", substitute_type); + GrfMsg(1, "CargoChangeInfo: Unknown town growth substitute value {}, setting to none.", substitute_type); [[fallthrough]]; case 0xFF: cs->town_acceptance_effect = TAE_NONE; break; } @@ -3143,7 +3149,7 @@ static ChangeInfoResult CargoChangeInfo(uint cid, int numinfo, int prop, const G case 0x00: cs->town_production_effect = TPE_PASSENGERS; break; case 0x02: cs->town_production_effect = TPE_MAIL; break; default: - grfmsg(1, "CargoChangeInfo: Unknown town production substitute value %u, setting to none.", substitute_type); + GrfMsg(1, "CargoChangeInfo: Unknown town production substitute value {}, setting to none.", substitute_type); [[fallthrough]]; case 0xFF: cs->town_production_effect = TPE_NONE; break; } @@ -3177,12 +3183,12 @@ static ChangeInfoResult SoundEffectChangeInfo(uint sid, int numinfo, int prop, c ChangeInfoResult ret = CIR_SUCCESS; if (_cur.grffile->sound_offset == 0) { - grfmsg(1, "SoundEffectChangeInfo: No effects defined, skipping"); + GrfMsg(1, "SoundEffectChangeInfo: No effects defined, skipping"); return CIR_INVALID_ID; } if (sid + numinfo - ORIGINAL_SAMPLE_COUNT > _cur.grffile->num_sounds) { - grfmsg(1, "SoundEffectChangeInfo: Attempting to change undefined sound effect (%u), max (%u). Ignoring.", sid + numinfo, ORIGINAL_SAMPLE_COUNT + _cur.grffile->num_sounds); + GrfMsg(1, "SoundEffectChangeInfo: Attempting to change undefined sound effect ({}), max ({}). Ignoring.", sid + numinfo, ORIGINAL_SAMPLE_COUNT + _cur.grffile->num_sounds); return CIR_INVALID_ID; } @@ -3202,7 +3208,7 @@ static ChangeInfoResult SoundEffectChangeInfo(uint sid, int numinfo, int prop, c SoundID orig_sound = buf->ReadByte(); if (orig_sound >= ORIGINAL_SAMPLE_COUNT) { - grfmsg(1, "SoundEffectChangeInfo: Original sound %d not defined (max %d)", orig_sound, ORIGINAL_SAMPLE_COUNT); + GrfMsg(1, "SoundEffectChangeInfo: Original sound {} not defined (max {})", orig_sound, ORIGINAL_SAMPLE_COUNT); } else { SoundEntry *old_sound = GetSound(orig_sound); @@ -3272,7 +3278,7 @@ static ChangeInfoResult IndustrytilesChangeInfo(uint indtid, int numinfo, int pr ChangeInfoResult ret = CIR_SUCCESS; if (indtid + numinfo > NUM_INDUSTRYTILES_PER_GRF) { - grfmsg(1, "IndustryTilesChangeInfo: Too many industry tiles loaded (%u), max (%u). Ignoring.", indtid + numinfo, NUM_INDUSTRYTILES_PER_GRF); + GrfMsg(1, "IndustryTilesChangeInfo: Too many industry tiles loaded ({}), max ({}). Ignoring.", indtid + numinfo, NUM_INDUSTRYTILES_PER_GRF); return CIR_INVALID_ID; } @@ -3293,7 +3299,7 @@ static ChangeInfoResult IndustrytilesChangeInfo(uint indtid, int numinfo, int pr uint8_t subs_id = buf->ReadByte(); if (subs_id >= NEW_INDUSTRYTILEOFFSET) { /* The substitute id must be one of the original industry tile. */ - grfmsg(2, "IndustryTilesChangeInfo: Attempt to use new industry tile %u as substitute industry tile for %u. Ignoring.", subs_id, indtid + i); + GrfMsg(2, "IndustryTilesChangeInfo: Attempt to use new industry tile {} as substitute industry tile for {}. Ignoring.", subs_id, indtid + i); continue; } @@ -3323,7 +3329,7 @@ static ChangeInfoResult IndustrytilesChangeInfo(uint indtid, int numinfo, int pr /* The industry being overridden must be an original industry. */ if (ovrid >= NEW_INDUSTRYTILEOFFSET) { - grfmsg(2, "IndustryTilesChangeInfo: Attempt to override new industry tile %u with industry tile id %u. Ignoring.", ovrid, indtid + i); + GrfMsg(2, "IndustryTilesChangeInfo: Attempt to override new industry tile {} with industry tile id {}. Ignoring.", ovrid, indtid + i); continue; } @@ -3529,7 +3535,7 @@ static ChangeInfoResult IndustriesChangeInfo(uint indid, int numinfo, int prop, ChangeInfoResult ret = CIR_SUCCESS; if (indid + numinfo > NUM_INDUSTRYTYPES_PER_GRF) { - grfmsg(1, "IndustriesChangeInfo: Too many industries loaded (%u), max (%u). Ignoring.", indid + numinfo, NUM_INDUSTRYTYPES_PER_GRF); + GrfMsg(1, "IndustriesChangeInfo: Too many industries loaded ({}), max ({}). Ignoring.", indid + numinfo, NUM_INDUSTRYTYPES_PER_GRF); return CIR_INVALID_ID; } @@ -3555,7 +3561,7 @@ static ChangeInfoResult IndustriesChangeInfo(uint indid, int numinfo, int prop, continue; } else if (subs_id >= NEW_INDUSTRYOFFSET) { /* The substitute id must be one of the original industry. */ - grfmsg(2, "_industry_specs: Attempt to use new industry %u as substitute industry for %u. Ignoring.", subs_id, indid + i); + GrfMsg(2, "_industry_specs: Attempt to use new industry {} as substitute industry for {}. Ignoring.", subs_id, indid + i); continue; } @@ -3582,7 +3588,7 @@ static ChangeInfoResult IndustriesChangeInfo(uint indid, int numinfo, int prop, /* The industry being overridden must be an original industry. */ if (ovrid >= NEW_INDUSTRYOFFSET) { - grfmsg(2, "IndustriesChangeInfo: Attempt to override new industry %u with industry id %u. Ignoring.", ovrid, indid + i); + GrfMsg(2, "IndustriesChangeInfo: Attempt to override new industry {} with industry id {}. Ignoring.", ovrid, indid + i); continue; } indsp->grf_prop.override = ovrid; @@ -3602,7 +3608,7 @@ static ChangeInfoResult IndustriesChangeInfo(uint indid, int numinfo, int prop, for (uint k = 0;; k++) { if (bytes_read >= definition_size) { - grfmsg(3, "IndustriesChangeInfo: Incorrect size for industry tile layout definition for industry %u.", indid); + GrfMsg(3, "IndustriesChangeInfo: Incorrect size for industry tile layout definition for industry {}.", indid); /* Avoid warning twice */ definition_size = UINT32_MAX; } @@ -3620,12 +3626,12 @@ static ChangeInfoResult IndustriesChangeInfo(uint indid, int numinfo, int prop, bytes_read += 2; if (type >= lengthof(_origin_industry_specs)) { - grfmsg(1, "IndustriesChangeInfo: Invalid original industry number for layout import, industry %u", indid); + GrfMsg(1, "IndustriesChangeInfo: Invalid original industry number for layout import, industry {}", indid); DisableGrf(STR_NEWGRF_ERROR_INVALID_ID); return CIR_DISABLED; } if (laynbr >= _origin_industry_specs[type].layouts.size()) { - grfmsg(1, "IndustriesChangeInfo: Invalid original industry layout index for layout import, industry %u", indid); + GrfMsg(1, "IndustriesChangeInfo: Invalid original industry layout index for layout import, industry {}", indid); DisableGrf(STR_NEWGRF_ERROR_INVALID_ID); return CIR_DISABLED; } @@ -3654,7 +3660,7 @@ static ChangeInfoResult IndustriesChangeInfo(uint indid, int numinfo, int prop, int tempid = _industile_mngr.GetID(local_tile_id, _cur.grffile->grfid); if (tempid == INVALID_INDUSTRYTILE) { - grfmsg(2, "IndustriesChangeInfo: Attempt to use industry tile %u with industry id %u, not yet defined. Ignoring.", local_tile_id, indid); + GrfMsg(2, "IndustriesChangeInfo: Attempt to use industry tile {} with industry id {}, not yet defined. Ignoring.", local_tile_id, indid); } else { /* Declared as been valid, can be used */ it.gfx = tempid; @@ -3676,7 +3682,7 @@ static ChangeInfoResult IndustriesChangeInfo(uint indid, int numinfo, int prop, if (!ValidateIndustryLayout(layout)) { /* The industry layout was not valid, so skip this one. */ - grfmsg(1, "IndustriesChangeInfo: Invalid industry layout for industry id %u. Ignoring", indid); + GrfMsg(1, "IndustriesChangeInfo: Invalid industry layout for industry id {}. Ignoring", indid); new_num_layouts--; j--; } else { @@ -3940,7 +3946,7 @@ static ChangeInfoResult AirportChangeInfo(uint airport, int numinfo, int prop, c ChangeInfoResult ret = CIR_SUCCESS; if (airport + numinfo > NUM_AIRPORTS_PER_GRF) { - grfmsg(1, "AirportChangeInfo: Too many airports, trying id (%u), max (%u). Ignoring.", airport + numinfo, NUM_AIRPORTS_PER_GRF); + GrfMsg(1, "AirportChangeInfo: Too many airports, trying id ({}), max ({}). Ignoring.", airport + numinfo, NUM_AIRPORTS_PER_GRF); return CIR_INVALID_ID; } @@ -3951,7 +3957,7 @@ static ChangeInfoResult AirportChangeInfo(uint airport, int numinfo, int prop, c AirportSpec *as = _cur.grffile->airportspec[airport + i].get(); if (as == nullptr && prop != 0x08 && prop != 0x09) { - grfmsg(2, "AirportChangeInfo: Attempt to modify undefined airport %u, ignoring", airport + i); + GrfMsg(2, "AirportChangeInfo: Attempt to modify undefined airport {}, ignoring", airport + i); return CIR_INVALID_ID; } @@ -3965,7 +3971,7 @@ static ChangeInfoResult AirportChangeInfo(uint airport, int numinfo, int prop, c continue; } else if (subs_id >= NEW_AIRPORT_OFFSET) { /* The substitute id must be one of the original airports. */ - grfmsg(2, "AirportChangeInfo: Attempt to use new airport %u as substitute airport for %u. Ignoring.", subs_id, airport + i); + GrfMsg(2, "AirportChangeInfo: Attempt to use new airport {} as substitute airport for {}. Ignoring.", subs_id, airport + i); continue; } @@ -4027,7 +4033,7 @@ static ChangeInfoResult AirportChangeInfo(uint airport, int numinfo, int prop, c uint16_t tempid = _airporttile_mngr.GetID(local_tile_id, _cur.grffile->grfid); if (tempid == INVALID_AIRPORTTILE) { - grfmsg(2, "AirportChangeInfo: Attempt to use airport tile %u with airport id %u, not yet defined. Ignoring.", local_tile_id, airport + i); + GrfMsg(2, "AirportChangeInfo: Attempt to use airport tile {} with airport id {}, not yet defined. Ignoring.", local_tile_id, airport + i); } else { /* Declared as been valid, can be used */ att[k].gfx = tempid; @@ -4330,8 +4336,8 @@ static ChangeInfoResult ObjectChangeInfo(uint id, int numinfo, int prop, const G { ChangeInfoResult ret = CIR_SUCCESS; - if (id + numinfo > NUM_OBJECTS) { - grfmsg(1, "ObjectChangeInfo: Too many objects loaded (%u), max (%u). Ignoring.", id + numinfo, NUM_OBJECTS); + if (id + numinfo > NUM_OBJECTS_PER_GRF) { + GrfMsg(1, "ObjectChangeInfo: Too many objects loaded ({}), max ({}). Ignoring.", id + numinfo, NUM_OBJECTS_PER_GRF); return CIR_INVALID_ID; } @@ -4382,7 +4388,7 @@ static ChangeInfoResult ObjectChangeInfo(uint id, int numinfo, int prop, const G case 0x0C: // Size spec->size = buf->ReadByte(); if (GB(spec->size, 0, 4) == 0 || GB(spec->size, 4, 4) == 0) { - grfmsg(0, "ObjectChangeInfo: Invalid object size requested (0x%x) for object id %u. Ignoring.", spec->size, id + i); + GrfMsg(0, "ObjectChangeInfo: Invalid object size requested (0x{:X}) for object id {}. Ignoring.", spec->size, id + i); spec->size = OBJECT_SIZE_1X1; } break; @@ -4433,7 +4439,7 @@ static ChangeInfoResult ObjectChangeInfo(uint id, int numinfo, int prop, const G case 0x17: // Views spec->views = buf->ReadByte(); if (spec->views != 1 && spec->views != 2 && spec->views != 4) { - grfmsg(2, "ObjectChangeInfo: Invalid number of views (%u) for object id %u. Ignoring.", spec->views, id + i); + GrfMsg(2, "ObjectChangeInfo: Invalid number of views ({}) for object id {}. Ignoring.", spec->views, id + i); spec->views = 1; } break; @@ -4497,7 +4503,7 @@ static ChangeInfoResult RailTypeChangeInfo(uint id, int numinfo, int prop, const extern RailTypeInfo _railtypes[RAILTYPE_END]; if (id + numinfo > RAILTYPE_END) { - grfmsg(1, "RailTypeChangeInfo: Rail type %u is invalid, max %u, ignoring", id + numinfo, RAILTYPE_END); + GrfMsg(1, "RailTypeChangeInfo: Rail type {} is invalid, max {}, ignoring", id + numinfo, RAILTYPE_END); return CIR_INVALID_ID; } @@ -4657,7 +4663,7 @@ static ChangeInfoResult RailTypeReserveInfo(uint id, int numinfo, int prop, cons extern RailTypeInfo _railtypes[RAILTYPE_END]; if (id + numinfo > RAILTYPE_END) { - grfmsg(1, "RailTypeReserveInfo: Rail type %u is invalid, max %u, ignoring", id + numinfo, RAILTYPE_END); + GrfMsg(1, "RailTypeReserveInfo: Rail type {} is invalid, max {}, ignoring", id + numinfo, RAILTYPE_END); return CIR_INVALID_ID; } @@ -4698,7 +4704,7 @@ static ChangeInfoResult RailTypeReserveInfo(uint id, int numinfo, int prop, cons } break; } - grfmsg(1, "RailTypeReserveInfo: Ignoring property 1D for rail type %u because no label was set", id + i); + GrfMsg(1, "RailTypeReserveInfo: Ignoring property 1D for rail type {} because no label was set", id + i); [[fallthrough]]; case 0x0E: // Compatible railtype list @@ -4755,7 +4761,7 @@ static ChangeInfoResult RoadTypeChangeInfo(uint id, int numinfo, int prop, const RoadType *type_map = (rtt == RTT_TRAM) ? _cur.grffile->tramtype_map : _cur.grffile->roadtype_map; if (id + numinfo > ROADTYPE_END) { - grfmsg(1, "RoadTypeChangeInfo: Road type %u is invalid, max %u, ignoring", id + numinfo, ROADTYPE_END); + GrfMsg(1, "RoadTypeChangeInfo: Road type {} is invalid, max {}, ignoring", id + numinfo, ROADTYPE_END); return CIR_INVALID_ID; } @@ -4809,7 +4815,7 @@ static ChangeInfoResult RoadTypeChangeInfo(uint id, int numinfo, int prop, const if (GetRoadTramType(resolved_rt) == rtt) { SetBit(rti->powered_roadtypes, resolved_rt); } else { - grfmsg(1, "RoadTypeChangeInfo: Powered road type list: Road type %u road/tram type does not match road type %u, ignoring", resolved_rt, rt); + GrfMsg(1, "RoadTypeChangeInfo: Powered road type list: Road type {} road/tram type does not match road type {}, ignoring", resolved_rt, rt); } break; case 0x18: SetBit(rti->introduction_required_roadtypes, resolved_rt); break; @@ -4897,7 +4903,7 @@ static ChangeInfoResult RoadTypeReserveInfo(uint id, int numinfo, int prop, cons RoadType *type_map = (rtt == RTT_TRAM) ? _cur.grffile->tramtype_map : _cur.grffile->roadtype_map; if (id + numinfo > ROADTYPE_END) { - grfmsg(1, "RoadTypeReserveInfo: Road type %u is invalid, max %u, ignoring", id + numinfo, ROADTYPE_END); + GrfMsg(1, "RoadTypeReserveInfo: Road type {} is invalid, max {}, ignoring", id + numinfo, ROADTYPE_END); return CIR_INVALID_ID; } @@ -4912,7 +4918,7 @@ static ChangeInfoResult RoadTypeReserveInfo(uint id, int numinfo, int prop, cons /* Set up new road type */ rt = AllocateRoadType(rtl, rtt); } else if (GetRoadTramType(rt) != rtt) { - grfmsg(1, "RoadTypeReserveInfo: Road type %u is invalid type (road/tram), ignoring", id + numinfo); + GrfMsg(1, "RoadTypeReserveInfo: Road type {} is invalid type (road/tram), ignoring", id + numinfo); return CIR_INVALID_ID; } @@ -4939,7 +4945,7 @@ static ChangeInfoResult RoadTypeReserveInfo(uint id, int numinfo, int prop, cons } break; } - grfmsg(1, "RoadTypeReserveInfo: Ignoring property 1D for road type %u because no label was set", id + i); + GrfMsg(1, "RoadTypeReserveInfo: Ignoring property 1D for road type {} because no label was set", id + i); /* FALL THROUGH */ case 0x0F: // Powered roadtype list @@ -5115,7 +5121,7 @@ static ChangeInfoResult RoadStopChangeInfo(uint id, int numinfo, int prop, const ChangeInfoResult ret = CIR_SUCCESS; if (id + numinfo > NUM_ROADSTOPS_PER_GRF) { - grfmsg(1, "RoadStopChangeInfo: RoadStop %u is invalid, max %u, ignoring", id + numinfo, NUM_ROADSTOPS_PER_GRF); + GrfMsg(1, "RoadStopChangeInfo: RoadStop {} is invalid, max {}, ignoring", id + numinfo, NUM_ROADSTOPS_PER_GRF); return CIR_INVALID_ID; } @@ -5127,7 +5133,7 @@ static ChangeInfoResult RoadStopChangeInfo(uint id, int numinfo, int prop, const RoadStopSpec *rs = _cur.grffile->roadstops[id + i].get(); if (rs == nullptr && prop != 0x08 && prop != A0RPI_ROADSTOP_CLASS_ID) { - grfmsg(1, "RoadStopChangeInfo: Attempt to modify undefined road stop %u, ignoring", id + i); + GrfMsg(1, "RoadStopChangeInfo: Attempt to modify undefined road stop {}, ignoring", id + i); ChangeInfoResult cir = IgnoreRoadStopProperty(prop, buf); if (cir > ret) ret = cir; continue; @@ -5703,7 +5709,7 @@ static void SkipAct1(ByteReader *buf) _cur.skip_sprites = num_sets * num_ents; - grfmsg(3, "SkipAct1: Skipping %d sprites", _cur.skip_sprites); + GrfMsg(3, "SkipAct1: Skipping {} sprites", _cur.skip_sprites); } const CallbackResultSpriteGroup *NewCallbackResultSpriteGroupNoTransform(uint16_t result) @@ -5725,7 +5731,7 @@ static const CallbackResultSpriteGroup *NewCallbackResultSpriteGroup(uint16_t gr static const SpriteGroup *GetGroupFromGroupIDNoCBResult(uint16_t setid, uint8_t type, uint16_t groupid) { if ((size_t)groupid >= _cur.spritegroups.size() || _cur.spritegroups[groupid] == nullptr) { - grfmsg(1, "GetGroupFromGroupID(0x%04X:0x%02X): Groupid 0x%04X does not exist, leaving empty", setid, type, groupid); + GrfMsg(1, "GetGroupFromGroupID(0x{:02X}:0x{:02X}): Groupid 0x{:04X} does not exist, leaving empty", setid, type, groupid); return nullptr; } @@ -5768,7 +5774,7 @@ static const SpriteGroup *CreateGroupFromGroupID(uint8_t feature, uint16_t setid } if (!_cur.IsValidSpriteSet(feature, spriteid)) { - grfmsg(1, "CreateGroupFromGroupID(0x%04X:0x%02X): Sprite set %u invalid", setid, type, spriteid); + GrfMsg(1, "CreateGroupFromGroupID(0x{:02X}:0x{:02X}): Sprite set {} invalid", setid, type, spriteid); return nullptr; } @@ -6166,7 +6172,7 @@ static void NewSpriteGroup(ByteReader *buf) uint8_t num_loading = buf->ReadByte(); if (!_cur.HasValidSpriteSets(feature)) { - grfmsg(0, "NewSpriteGroup: No sprite set to work on! Skipping"); + GrfMsg(0, "NewSpriteGroup: No sprite set to work on! Skipping"); return; } @@ -6175,11 +6181,11 @@ static void NewSpriteGroup(ByteReader *buf) break; } - grfmsg(6, "NewSpriteGroup: New SpriteGroup 0x%02X, %u loaded, %u loading", + GrfMsg(6, "NewSpriteGroup: New SpriteGroup 0x{:02X}, {} loaded, {} loading", setid, num_loaded, num_loading); if (num_loaded + num_loading == 0) { - grfmsg(1, "NewSpriteGroup: no result, skipping invalid RealSpriteGroup"); + GrfMsg(1, "NewSpriteGroup: no result, skipping invalid RealSpriteGroup"); break; } @@ -6187,7 +6193,7 @@ static void NewSpriteGroup(ByteReader *buf) /* Avoid creating 'Real' sprite group if only one option. */ uint16_t spriteid = buf->ReadWord(); act_group = CreateGroupFromGroupID(feature, setid, type, spriteid); - grfmsg(8, "NewSpriteGroup: one result, skipping RealSpriteGroup = subset %u", spriteid); + GrfMsg(8, "NewSpriteGroup: one result, skipping RealSpriteGroup = subset {}", spriteid); break; } @@ -6196,12 +6202,12 @@ static void NewSpriteGroup(ByteReader *buf) for (uint i = 0; i < num_loaded; i++) { loaded.push_back(buf->ReadWord()); - grfmsg(8, "NewSpriteGroup: + rg->loaded[%i] = subset %u", i, loaded[i]); + GrfMsg(8, "NewSpriteGroup: + rg->loaded[{}] = subset {}", i, loaded[i]); } for (uint i = 0; i < num_loading; i++) { loading.push_back(buf->ReadWord()); - grfmsg(8, "NewSpriteGroup: + rg->loading[%i] = subset %u", i, loading[i]); + GrfMsg(8, "NewSpriteGroup: + rg->loading[{}] = subset {}", i, loading[i]); } bool loaded_same = !loaded.empty() && std::adjacent_find(loaded.begin(), loaded.end(), std::not_equal_to<>()) == loaded.end(); @@ -6209,7 +6215,7 @@ static void NewSpriteGroup(ByteReader *buf) if (loaded_same && loading_same && loaded[0] == loading[0]) { /* Both lists only contain the same value, so don't create 'Real' sprite group */ act_group = CreateGroupFromGroupID(feature, setid, type, loaded[0]); - grfmsg(8, "NewSpriteGroup: same result, skipping RealSpriteGroup = subset %u", loaded[0]); + GrfMsg(8, "NewSpriteGroup: same result, skipping RealSpriteGroup = subset {}", loaded[0]); break; } @@ -6254,7 +6260,7 @@ static void NewSpriteGroup(ByteReader *buf) case GSF_INDUSTRIES: { if (type > 2) { - grfmsg(1, "NewSpriteGroup: Unsupported industry production version %d, skipping", type); + GrfMsg(1, "NewSpriteGroup: Unsupported industry production version {}, skipping", type); break; } @@ -6294,7 +6300,7 @@ static void NewSpriteGroup(ByteReader *buf) for (uint i = 0; i < group->num_input; i++) { uint8_t rawcargo = buf->ReadByte(); CargoID cargo = GetCargoTranslation(rawcargo, _cur.grffile); - if (cargo == INVALID_CARGO) { + if (!IsValidCargoID(cargo)) { /* The mapped cargo is invalid. This is permitted at this point, * as long as the result is not used. Mark it invalid so this * can be tested later. */ @@ -6316,7 +6322,7 @@ static void NewSpriteGroup(ByteReader *buf) for (uint i = 0; i < group->num_output; i++) { uint8_t rawcargo = buf->ReadByte(); CargoID cargo = GetCargoTranslation(rawcargo, _cur.grffile); - if (cargo == INVALID_CARGO) { + if (!IsValidCargoID(cargo)) { /* Mark this result as invalid to use */ group->version = 0xFF; } else if (std::find(group->cargo_output, group->cargo_output + i, cargo) != group->cargo_output + i) { @@ -6357,41 +6363,41 @@ static CargoID TranslateCargo(uint8_t feature, uint8_t ctype) if (_cur.grffile->cargo_list.empty()) { /* No cargo table, so use bitnum values */ if (ctype >= 32) { - grfmsg(1, "TranslateCargo: Cargo bitnum %d out of range (max 31), skipping.", ctype); + GrfMsg(1, "TranslateCargo: Cargo bitnum {} out of range (max 31), skipping.", ctype); return INVALID_CARGO; } for (const CargoSpec *cs : CargoSpec::Iterate()) { if (cs->bitnum == ctype) { - grfmsg(6, "TranslateCargo: Cargo bitnum %d mapped to cargo type %d.", ctype, cs->Index()); + GrfMsg(6, "TranslateCargo: Cargo bitnum {} mapped to cargo type {}.", ctype, cs->Index()); return cs->Index(); } } - grfmsg(5, "TranslateCargo: Cargo bitnum %d not available in this climate, skipping.", ctype); + GrfMsg(5, "TranslateCargo: Cargo bitnum {} not available in this climate, skipping.", ctype); return INVALID_CARGO; } /* Check if the cargo type is out of bounds of the cargo translation table */ if (ctype >= _cur.grffile->cargo_list.size()) { - grfmsg(1, "TranslateCargo: Cargo type %d out of range (max %d), skipping.", ctype, (unsigned int)_cur.grffile->cargo_list.size() - 1); + GrfMsg(1, "TranslateCargo: Cargo type {} out of range (max {}), skipping.", ctype, (unsigned int)_cur.grffile->cargo_list.size() - 1); return INVALID_CARGO; } /* Look up the cargo label from the translation table */ CargoLabel cl = _cur.grffile->cargo_list[ctype]; - if (cl == CT_INVALID) { - grfmsg(5, "TranslateCargo: Cargo type %d not available in this climate, skipping.", ctype); + if (cl == CT_INVALID) { + GrfMsg(5, "TranslateCargo: Cargo type {} not available in this climate, skipping.", ctype); return INVALID_CARGO; } CargoID cid = GetCargoIDByLabel(cl); - if (cid == INVALID_CARGO) { - grfmsg(5, "TranslateCargo: Cargo '%c%c%c%c' unsupported, skipping.", GB(cl.base(), 24, 8), GB(cl.base(), 16, 8), GB(cl.base(), 8, 8), GB(cl.base(), 0, 8)); + if (!IsValidCargoID(cid)) { + GrfMsg(5, "TranslateCargo: Cargo '{:c}{:c}{:c}{:c}' unsupported, skipping.", GB(cl.base(), 24, 8), GB(cl.base(), 16, 8), GB(cl.base(), 8, 8), GB(cl.base(), 0, 8)); return INVALID_CARGO; } - grfmsg(6, "TranslateCargo: Cargo '%c%c%c%c' mapped to cargo type %d.", GB(cl.base(), 24, 8), GB(cl.base(), 16, 8), GB(cl.base(), 8, 8), GB(cl.base(), 0, 8), cid); + GrfMsg(6, "TranslateCargo: Cargo '{:c}{:c}{:c}{:c}' mapped to cargo type {}.", GB(cl.base(), 24, 8), GB(cl.base(), 16, 8), GB(cl.base(), 8, 8), GB(cl.base(), 0, 8), cid); return cid; } @@ -6399,7 +6405,7 @@ static CargoID TranslateCargo(uint8_t feature, uint8_t ctype) static bool IsValidGroupID(uint16_t groupid, const char *function) { if ((size_t)groupid >= _cur.spritegroups.size() || _cur.spritegroups[groupid] == nullptr) { - grfmsg(1, "%s: Spritegroup 0x%04X out of range or empty, skipping.", function, groupid); + GrfMsg(1, "{}: Spritegroup 0x{:04X} out of range or empty, skipping.", function, groupid); return false; } @@ -6419,11 +6425,11 @@ static void VehicleMapSpriteGroup(ByteReader *buf, uint8_t feature, uint8_t idco idcount = GB(idcount, 0, 7); if (last_engines_count == 0) { - grfmsg(0, "VehicleMapSpriteGroup: WagonOverride: No engine to do override with"); + GrfMsg(0, "VehicleMapSpriteGroup: WagonOverride: No engine to do override with"); return; } - grfmsg(6, "VehicleMapSpriteGroup: WagonOverride: %u engines, %u wagons", + GrfMsg(6, "VehicleMapSpriteGroup: WagonOverride: {} engines, {} wagons", last_engines_count, idcount); } else { if (last_engines_count != idcount) { @@ -6453,15 +6459,15 @@ static void VehicleMapSpriteGroup(ByteReader *buf, uint8_t feature, uint8_t idco uint16_t groupid = buf->ReadWord(); if (!IsValidGroupID(groupid, "VehicleMapSpriteGroup")) continue; - grfmsg(8, "VehicleMapSpriteGroup: * [%d] Cargo type 0x%X, group id 0x%02X", c, ctype, groupid); + GrfMsg(8, "VehicleMapSpriteGroup: * [{}] Cargo type 0x{:X}, group id 0x{:02X}", c, ctype, groupid); CargoID cid = TranslateCargo(feature, ctype); - if (cid == INVALID_CARGO) continue; + if (!IsValidCargoID(cid)) continue; for (uint i = 0; i < idcount; i++) { EngineID engine = engines[i]; - grfmsg(7, "VehicleMapSpriteGroup: [%d] Engine %d...", i, engine); + GrfMsg(7, "VehicleMapSpriteGroup: [{}] Engine {}...", i, engine); if (wagover) { SetWagonOverrideSprites(engine, cid, GetGroupByID(groupid), last_engines, last_engines_count); @@ -6474,7 +6480,7 @@ static void VehicleMapSpriteGroup(ByteReader *buf, uint8_t feature, uint8_t idco uint16_t groupid = buf->ReadWord(); if (!IsValidGroupID(groupid, "VehicleMapSpriteGroup")) return; - grfmsg(8, "-- Default group id 0x%04X", groupid); + GrfMsg(8, "-- Default group id 0x{:04X}", groupid); for (uint i = 0; i < idcount; i++) { EngineID engine = engines[i]; @@ -6506,7 +6512,7 @@ static void CanalMapSpriteGroup(ByteReader *buf, uint8_t idcount) uint16_t cf = cfs[i]; if (cf >= CF_END) { - grfmsg(1, "CanalMapSpriteGroup: Canal subset %d out of range, skipping", cf); + GrfMsg(1, "CanalMapSpriteGroup: Canal subset {} out of range, skipping", cf); continue; } @@ -6519,7 +6525,7 @@ static void CanalMapSpriteGroup(ByteReader *buf, uint8_t idcount) static void StationMapSpriteGroup(ByteReader *buf, uint8_t idcount) { if (_cur.grffile->stations.empty()) { - grfmsg(1, "StationMapSpriteGroup: No stations defined, skipping"); + GrfMsg(1, "StationMapSpriteGroup: No stations defined, skipping"); return; } @@ -6684,7 +6690,7 @@ static void CargoMapSpriteGroup(ByteReader *buf, uint8_t idcount) uint16_t cid = cargoes[i]; if (cid >= NUM_CARGO) { - grfmsg(1, "CargoMapSpriteGroup: Cargo ID %d out of range, skipping", cid); + GrfMsg(1, "CargoMapSpriteGroup: Cargo ID {} out of range, skipping", cid); continue; } @@ -6730,7 +6736,7 @@ static void SignalsMapSpriteGroup(ByteReader *buf, uint8_t idcount) static void ObjectMapSpriteGroup(ByteReader *buf, uint8_t idcount) { if (_cur.grffile->objectspec.empty()) { - grfmsg(1, "ObjectMapSpriteGroup: No object tiles defined, skipping"); + GrfMsg(1, "ObjectMapSpriteGroup: No object tiles defined, skipping"); return; } @@ -6747,7 +6753,7 @@ static void ObjectMapSpriteGroup(ByteReader *buf, uint8_t idcount) /* The only valid option here is purchase list sprite groups. */ if (ctype != 0xFF) { - grfmsg(1, "ObjectMapSpriteGroup: Invalid cargo bitnum %d for objects, skipping.", ctype); + GrfMsg(1, "ObjectMapSpriteGroup: Invalid cargo bitnum {} for objects, skipping.", ctype); continue; } @@ -7166,8 +7172,8 @@ static void FeatureNewName(ByteReader *buf) id, endid, GetFeatureString(feature), lang); for (; id < endid && buf->HasData(); id++) { - const char *name = buf->ReadString(); - grfmsg(8, "FeatureNewName: 0x%04X <- %s", id, name); + const std::string_view name = buf->ReadString(); + GrfMsg(8, "FeatureNewName: 0x{:04X} <- {}", id, name); switch (feature) { case GSF_TRAINS: @@ -7193,7 +7199,7 @@ static void FeatureNewName(ByteReader *buf) switch (GB(id, 8, 8)) { case 0xC4: // Station class name if (GB(id, 0, 8) >= _cur.grffile->stations.size() || _cur.grffile->stations[GB(id, 0, 8)] == nullptr) { - grfmsg(1, "FeatureNewName: Attempt to name undefined station 0x%X, ignoring", GB(id, 0, 8)); + GrfMsg(1, "FeatureNewName: Attempt to name undefined station 0x{:X}, ignoring", GB(id, 0, 8)); } else { StationClassID cls_id = _cur.grffile->stations[GB(id, 0, 8)]->cls_id; StationClass::Get(cls_id)->name = AddGRFString(_cur.grffile->grfid, id, lang, new_scheme, false, name, STR_UNDEFINED); @@ -7202,7 +7208,7 @@ static void FeatureNewName(ByteReader *buf) case 0xC5: // Station name if (GB(id, 0, 8) >= _cur.grffile->stations.size() || _cur.grffile->stations[GB(id, 0, 8)] == nullptr) { - grfmsg(1, "FeatureNewName: Attempt to name undefined station 0x%X, ignoring", GB(id, 0, 8)); + GrfMsg(1, "FeatureNewName: Attempt to name undefined station 0x{:X}, ignoring", GB(id, 0, 8)); } else { _cur.grffile->stations[GB(id, 0, 8)]->name = AddGRFString(_cur.grffile->grfid, id, lang, new_scheme, false, name, STR_UNDEFINED); } @@ -7210,7 +7216,7 @@ static void FeatureNewName(ByteReader *buf) case 0xC7: // Airporttile name if (GB(id, 0, 8) >= _cur.grffile->airtspec.size() || _cur.grffile->airtspec[GB(id, 0, 8)] == nullptr) { - grfmsg(1, "FeatureNewName: Attempt to name undefined airport tile 0x%X, ignoring", GB(id, 0, 8)); + GrfMsg(1, "FeatureNewName: Attempt to name undefined airport tile 0x{:X}, ignoring", GB(id, 0, 8)); } else { _cur.grffile->airtspec[GB(id, 0, 8)]->name = AddGRFString(_cur.grffile->grfid, id, lang, new_scheme, false, name, STR_UNDEFINED); } @@ -7218,14 +7224,14 @@ static void FeatureNewName(ByteReader *buf) case 0xC9: // House name if (GB(id, 0, 8) >= _cur.grffile->housespec.size() || _cur.grffile->housespec[GB(id, 0, 8)] == nullptr) { - grfmsg(1, "FeatureNewName: Attempt to name undefined house 0x%X, ignoring.", GB(id, 0, 8)); + GrfMsg(1, "FeatureNewName: Attempt to name undefined house 0x{:X}, ignoring.", GB(id, 0, 8)); } else { _cur.grffile->housespec[GB(id, 0, 8)]->building_name = AddGRFString(_cur.grffile->grfid, id, lang, new_scheme, false, name, STR_UNDEFINED); } break; default: - grfmsg(7, "FeatureNewName: Unsupported ID (0x%04X)", id); + GrfMsg(7, "FeatureNewName: Unsupported ID (0x{:04X})", id); break; } break; @@ -7241,18 +7247,18 @@ static void FeatureNewName(ByteReader *buf) * @param name Used for error warnings. * @return The number of sprites that is going to be skipped. */ -static uint16_t SanitizeSpriteOffset(uint16_t &num, uint16_t offset, int max_sprites, const char *name) +static uint16_t SanitizeSpriteOffset(uint16_t &num, uint16_t offset, int max_sprites, const std::string_view name) { if (offset >= max_sprites) { - grfmsg(1, "GraphicsNew: %s sprite offset must be less than %i, skipping", name, max_sprites); + GrfMsg(1, "GraphicsNew: {} sprite offset must be less than {}, skipping", name, max_sprites); uint orig_num = num; num = 0; return orig_num; } if (offset + num > max_sprites) { - grfmsg(4, "GraphicsNew: %s sprite overflow, truncating...", name); + GrfMsg(4, "GraphicsNew: {} sprite overflow, truncating...", name); uint orig_num = num; num = std::max(max_sprites - offset, 0); return orig_num - num; @@ -7261,8 +7267,9 @@ static uint16_t SanitizeSpriteOffset(uint16_t &num, uint16_t offset, int max_spr return 0; } + /** The information about action 5 types. */ -static const Action5Type _action5_types[] = { +static constexpr auto _action5_types = std::to_array({ /* Note: min_sprites should not be changed. Therefore these constants are directly here and not in sprites.h */ /* 0x00 */ { A5BLOCK_INVALID, 0, 0, 0, "Type 0x00" }, /* 0x01 */ { A5BLOCK_INVALID, 0, 0, 0, "Type 0x01" }, @@ -7289,7 +7296,16 @@ static const Action5Type _action5_types[] = { /* 0x16 */ { A5BLOCK_ALLOW_OFFSET, SPR_AIRPORT_PREVIEW_BASE, 1, SPR_AIRPORT_PREVIEW_COUNT, "Airport preview graphics" }, /* 0x17 */ { A5BLOCK_ALLOW_OFFSET, SPR_RAILTYPE_TUNNEL_BASE, 1, RAILTYPE_TUNNEL_BASE_COUNT, "Railtype tunnel base" }, /* 0x18 */ { A5BLOCK_ALLOW_OFFSET, SPR_PALETTE_BASE, 1, PALETTE_SPRITE_COUNT, "Palette" }, -}; +}); + +/** + * Get list of all action 5 types + * @return Read-only span of action 5 type information. + */ +std::span GetAction5Types() +{ + return _action5_types; +} /* Action 0x05 */ static void GraphicsNew(ByteReader *buf) @@ -7345,7 +7361,7 @@ static void GraphicsNew(ByteReader *buf) } /* Supported type? */ - if ((type >= lengthof(_action5_types)) || (_action5_types[type].block_type == A5BLOCK_INVALID)) { + if ((type >= std::size(_action5_types)) || (_action5_types[type].block_type == A5BLOCK_INVALID)) { grfmsg(2, "GraphicsNew: Custom graphics (type 0x%02X) sprite block of length %u (unimplemented, ignoring)", type, num); _cur.skip_sprites = num; return; @@ -7358,14 +7374,14 @@ static void GraphicsNew(ByteReader *buf) * except for the long version of the shore type: * Ignore offset if not allowed */ if ((action5_type->block_type != A5BLOCK_ALLOW_OFFSET) && (offset != 0)) { - grfmsg(1, "GraphicsNew: %s (type 0x%02X) do not allow an field. Ignoring offset.", action5_type->name, type); + GrfMsg(1, "GraphicsNew: {} (type 0x{:02X}) do not allow an field. Ignoring offset.", action5_type->name, type); offset = 0; } /* Ignore action5 if too few sprites are specified. (for TTDP compatibility) * This does not make sense, if is allowed */ if ((action5_type->block_type == A5BLOCK_FIXED) && (num < action5_type->min_sprites)) { - grfmsg(1, "GraphicsNew: %s (type 0x%02X) count must be at least %d. Only %d were specified. Skipping.", action5_type->name, type, action5_type->min_sprites, num); + GrfMsg(1, "GraphicsNew: {} (type 0x{:02X}) count must be at least {}. Only {} were specified. Skipping.", action5_type->name, type, action5_type->min_sprites, num); _cur.skip_sprites = num; return; } @@ -7375,7 +7391,7 @@ static void GraphicsNew(ByteReader *buf) SpriteID replace = action5_type->sprite_base + offset; /* Load sprites starting from , then skip sprites. */ - grfmsg(2, "GraphicsNew: Replacing sprites %d to %d of %s (type 0x%02X) at SpriteID 0x%04X", offset, offset + num - 1, action5_type->name, type, replace); + GrfMsg(2, "GraphicsNew: Replacing sprites {} to {} of {} (type 0x{:02X}) at SpriteID 0x{:04X}", offset, offset + num - 1, action5_type->name, type, replace); if (type == 0x0D) _loaded_newgrf_features.shore = SHORE_REPLACE_ACTION_5; @@ -7420,7 +7436,7 @@ static void SkipAct5(ByteReader *buf) /* Skip the sprites of this action */ _cur.skip_sprites = buf->ReadExtendedByte(); - grfmsg(3, "SkipAct5: Skipping %d sprites", _cur.skip_sprites); + GrfMsg(3, "SkipAct5: Skipping {} sprites", _cur.skip_sprites); } /** @@ -7621,7 +7637,7 @@ static uint32_t GetParamVal(uint8_t param, uint32_t *cond_val) if (param < 0x80) return _cur.grffile->GetParam(param); /* In-game variable. */ - grfmsg(1, "Unsupported in-game variable 0x%02X", param); + GrfMsg(1, "Unsupported in-game variable 0x{:02X}", param); return UINT_MAX; } } @@ -7648,7 +7664,7 @@ static void CfgApply(ByteReader *buf) /* Check if the sprite is a pseudo sprite. We can't operate on real sprites. */ if (type != 0xFF) { - grfmsg(2, "CfgApply: Ignoring (next sprite is real, unsupported)"); + GrfMsg(2, "CfgApply: Ignoring (next sprite is real, unsupported)"); /* Reset the file position to the start of the next sprite */ file.SeekTo(pos, SEEK_SET); @@ -7695,11 +7711,11 @@ static void CfgApply(ByteReader *buf) /* If the parameter is a GRF parameter (not an internal variable) check * if it (and all further sequential parameters) has been defined. */ if (param_num < 0x80 && (param_num + (param_size - 1) / 4) >= _cur.grffile->param_end) { - grfmsg(2, "CfgApply: Ignoring (param %d not set)", (param_num + (param_size - 1) / 4)); + GrfMsg(2, "CfgApply: Ignoring (param {} not set)", (param_num + (param_size - 1) / 4)); break; } - grfmsg(8, "CfgApply: Applying %u bytes from parameter 0x%02X at offset 0x%04X", param_size, param_num, offset); + GrfMsg(8, "CfgApply: Applying {} bytes from parameter 0x{:02X} at offset 0x{:04X}", param_size, param_num, offset); bool carry = false; for (i = 0; i < param_size && offset + i < num; i++) { @@ -7768,11 +7784,11 @@ static void SkipIf(ByteReader *buf) } if (param < 0x80 && _cur.grffile->param_end <= param) { - grfmsg(7, "SkipIf: Param %d undefined, skipping test", param); + GrfMsg(7, "SkipIf: Param {} undefined, skipping test", param); return; } - grfmsg(7, "SkipIf: Test condtype %d, param 0x%02X, condval 0x%08X", condtype, param, cond_val); + GrfMsg(7, "SkipIf: Test condtype {}, param 0x{:02X}, condval 0x{:08X}", condtype, param, cond_val); /* condtypes that do not use 'param' are always valid. * condtypes that use 'param' are either not valid for param 0x88, or they are only valid for param 0x88. @@ -7808,7 +7824,7 @@ static void SkipIf(ByteReader *buf) result = rt != INVALID_ROADTYPE && RoadTypeIsTram(rt); break; } - default: grfmsg(1, "SkipIf: Unsupported condition type %02X. Ignoring", condtype); return; + default: GrfMsg(1, "SkipIf: Unsupported condition type {:02X}. Ignoring", condtype); return; } } else if (param == 0x88) { /* GRF ID checks */ @@ -7821,7 +7837,7 @@ static void SkipIf(ByteReader *buf) } if (condtype != 10 && c == nullptr) { - grfmsg(7, "SkipIf: GRFID 0x%08X unknown, skipping test", BSWAP32(cond_val)); + GrfMsg(7, "SkipIf: GRFID 0x{:08X} unknown, skipping test", BSWAP32(cond_val)); return; } @@ -7848,7 +7864,7 @@ static void SkipIf(ByteReader *buf) result = c == nullptr || c->status == GCS_DISABLED || c->status == GCS_NOT_FOUND; break; - default: grfmsg(1, "SkipIf: Unsupported GRF condition type %02X. Ignoring", condtype); return; + default: GrfMsg(1, "SkipIf: Unsupported GRF condition type {:02X}. Ignoring", condtype); return; } } else if (param == 0x91 && (condtype == 0x02 || condtype == 0x03) && cond_val > 0) { const std::vector &values = _cur.grffile->var91_values; @@ -7873,12 +7889,12 @@ static void SkipIf(ByteReader *buf) break; case 0x05: result = (param_val & mask) > cond_val; break; - default: grfmsg(1, "SkipIf: Unsupported condition type %02X. Ignoring", condtype); return; + default: GrfMsg(1, "SkipIf: Unsupported condition type {:02X}. Ignoring", condtype); return; } } if (!result) { - grfmsg(2, "SkipIf: Not skipping sprites, test was false"); + GrfMsg(2, "SkipIf: Not skipping sprites, test was false"); return; } @@ -7902,13 +7918,13 @@ static void SkipIf(ByteReader *buf) } if (choice != nullptr) { - grfmsg(2, "SkipIf: Jumping to label 0x%0X at line %d, test was true", choice->label, choice->nfo_line); + GrfMsg(2, "SkipIf: Jumping to label 0x{:X} at line {}, test was true", choice->label, choice->nfo_line); _cur.file->SeekTo(choice->pos, SEEK_SET); _cur.nfo_line = choice->nfo_line; return; } - grfmsg(2, "SkipIf: Skipping %d sprites, test was true", numsprites); + GrfMsg(2, "SkipIf: Skipping {} sprites, test was true", numsprites); _cur.skip_sprites = numsprites; if (_cur.skip_sprites == 0) { /* Zero means there are no sprites to skip, so @@ -7929,13 +7945,13 @@ static void ScanInfo(ByteReader *buf) { uint8_t grf_version = buf->ReadByte(); uint32_t grfid = buf->ReadDWord(); - const char *name = buf->ReadString(); + std::string_view name = buf->ReadString(); _cur.grfconfig->ident.grfid = grfid; if (grf_version < 2 || grf_version > 8) { SetBit(_cur.grfconfig->flags, GCF_INVALID); - DEBUG(grf, 0, "%s: NewGRF \"%s\" (GRFID %08X) uses GRF version %d, which is incompatible with this version of OpenTTD.", _cur.grfconfig->GetDisplayPath(), name, BSWAP32(grfid), grf_version); + Debug(grf, 0, "{}: NewGRF \"{}\" (GRFID %08X) uses GRF version {}, which is incompatible with this version of OpenTTD.", _cur.grfconfig->GetDisplayPath(), name, BSWAP32(grfid), grf_version); } /* GRF IDs starting with 0xFF are reserved for internal TTDPatch use */ @@ -7944,7 +7960,7 @@ static void ScanInfo(ByteReader *buf) AddGRFTextToList(_cur.grfconfig->name, 0x7F, grfid, false, name); if (buf->HasData()) { - const char *info = buf->ReadString(); + std::string_view info = buf->ReadString(); AddGRFTextToList(_cur.grfconfig->info, 0x7F, grfid, true, info); } @@ -7964,7 +7980,7 @@ static void GRFInfo(ByteReader *buf) uint8_t version = buf->ReadByte(); uint32_t grfid = buf->ReadDWord(); - const char *name = buf->ReadString(); + std::string_view name = buf->ReadString(); if (_cur.stage < GLS_RESERVE && _cur.grfconfig->status != GCS_UNKNOWN) { DisableGrf(STR_NEWGRF_ERROR_MULTIPLE_ACTION_8); @@ -7972,7 +7988,7 @@ static void GRFInfo(ByteReader *buf) } if (_cur.grffile->grfid != grfid) { - DEBUG(grf, 0, "GRFInfo: GRFID %08X in FILESCAN stage does not match GRFID %08X in INIT/RESERVE/ACTIVATION stage", BSWAP32(_cur.grffile->grfid), BSWAP32(grfid)); + Debug(grf, 0, "GRFInfo: GRFID {:08X} in FILESCAN stage does not match GRFID {:08X} in INIT/RESERVE/ACTIVATION stage", BSWAP32(_cur.grffile->grfid), BSWAP32(grfid)); _cur.grffile->grfid = grfid; } @@ -7980,7 +7996,7 @@ static void GRFInfo(ByteReader *buf) _cur.grfconfig->status = _cur.stage < GLS_RESERVE ? GCS_INITIALISED : GCS_ACTIVATED; /* Do swap the GRFID for displaying purposes since people expect that */ - DEBUG(grf, 1, "GRFInfo: Loaded GRFv%d set %08X - %s (palette: %s, version: %i)", version, BSWAP32(grfid), name, (_cur.grfconfig->palette & GRFP_USE_MASK) ? "Windows" : "DOS", _cur.grfconfig->version); + Debug(grf, 1, "GRFInfo: Loaded GRFv{} set {:08X} - {} (palette: {}, version: {})", version, BSWAP32(grfid), name, (_cur.grfconfig->palette & GRFP_USE_MASK) ? "Windows" : "DOS", _cur.grfconfig->version); } /* Action 0x0A */ @@ -8000,7 +8016,7 @@ static void SpriteReplace(ByteReader *buf) uint8_t num_sprites = buf->ReadByte(); uint16_t first_sprite = buf->ReadWord(); - grfmsg(2, "SpriteReplace: [Set %d] Changing %d sprites, beginning with %d", + GrfMsg(2, "SpriteReplace: [Set {}] Changing {} sprites, beginning with {}", i, num_sprites, first_sprite ); @@ -8036,7 +8052,7 @@ static void SkipActA(ByteReader *buf) buf->ReadWord(); } - grfmsg(3, "SkipActA: Skipping %d sprites", _cur.skip_sprites); + GrfMsg(3, "SkipActA: Skipping {} sprites", _cur.skip_sprites); } /* Action 0x0B */ @@ -8084,13 +8100,13 @@ static void GRFLoadError(ByteReader *buf) /* Skip the error until the activation stage unless bit 7 of the severity * is set. */ if (!HasBit(severity, 7) && _cur.stage == GLS_INIT) { - grfmsg(7, "GRFLoadError: Skipping non-fatal GRFLoadError in stage %d", _cur.stage); + GrfMsg(7, "GRFLoadError: Skipping non-fatal GRFLoadError in stage {}", _cur.stage); return; } ClrBit(severity, 7); if (severity >= lengthof(sevstr)) { - grfmsg(7, "GRFLoadError: Invalid severity id %d. Setting to 2 (non-fatal error).", severity); + GrfMsg(7, "GRFLoadError: Invalid severity id {}. Setting to 2 (non-fatal error).", severity); severity = 2; } else if (severity == 3) { /* This is a fatal error, so make sure the GRF is deactivated and no @@ -8102,12 +8118,12 @@ static void GRFLoadError(ByteReader *buf) } if (message_id >= lengthof(msgstr) && message_id != 0xFF) { - grfmsg(7, "GRFLoadError: Invalid message id."); + GrfMsg(7, "GRFLoadError: Invalid message id."); return; } if (buf->Remaining() <= 1) { - grfmsg(7, "GRFLoadError: No message data supplied."); + GrfMsg(7, "GRFLoadError: No message data supplied."); return; } @@ -8120,11 +8136,11 @@ static void GRFLoadError(ByteReader *buf) if (message_id == 0xFF) { /* This is a custom error message. */ if (buf->HasData()) { - const char *message = buf->ReadString(); + std::string_view message = buf->ReadString(); error->custom_message = TranslateTTDPatchCodes(_cur.grffile->grfid, lang, true, message, SCC_RAW_STRING_POINTER); } else { - grfmsg(7, "GRFLoadError: No custom message supplied."); + GrfMsg(7, "GRFLoadError: No custom message supplied."); error->custom_message.clear(); } } else { @@ -8132,11 +8148,11 @@ static void GRFLoadError(ByteReader *buf) } if (buf->HasData()) { - const char *data = buf->ReadString(); + std::string_view data = buf->ReadString(); error->data = TranslateTTDPatchCodes(_cur.grffile->grfid, lang, true, data); } else { - grfmsg(7, "GRFLoadError: No message data supplied."); + GrfMsg(7, "GRFLoadError: No message data supplied."); error->data.clear(); } @@ -8156,8 +8172,8 @@ static void GRFComment(ByteReader *buf) if (!buf->HasData()) return; - const char *text = buf->ReadString(); - grfmsg(2, "GRFComment: %s", text); + std::string_view text = buf->ReadString(); + GrfMsg(2, "GRFComment: {}", text); } /* Action 0x0D (GLS_SAFETYSCAN) */ @@ -8252,7 +8268,7 @@ static uint32_t GetPatchVariable(uint8_t param) return _settings_game.game_creation.generation_seed; default: - grfmsg(2, "ParamSet: Unknown Patch variable 0x%02X.", param); + GrfMsg(2, "ParamSet: Unknown Patch variable 0x{:02X}.", param); return 0; } } @@ -8286,7 +8302,7 @@ static uint32_t PerformGRM(uint32_t *grm, uint16_t num_ids, uint16_t count, uint if (size == count) { /* Got the slot... */ if (op == 0 || op == 3) { - grfmsg(2, "ParamSet: GRM: Reserving %d %s at %d", count, type, start); + GrfMsg(2, "ParamSet: GRM: Reserving {} {} at {}", count, type, start); for (uint i = 0; i < count; i++) grm[start + i] = _cur.grffile->grfid; } return start; @@ -8295,12 +8311,12 @@ static uint32_t PerformGRM(uint32_t *grm, uint16_t num_ids, uint16_t count, uint /* Unable to allocate */ if (op != 4 && op != 5) { /* Deactivate GRF */ - grfmsg(0, "ParamSet: GRM: Unable to allocate %d %s, deactivating", count, type); + GrfMsg(0, "ParamSet: GRM: Unable to allocate {} {}, deactivating", count, type); DisableGrf(STR_NEWGRF_ERROR_GRM_FAILED); return UINT_MAX; } - grfmsg(1, "ParamSet: GRM: Unable to allocate %d %s", count, type); + GrfMsg(1, "ParamSet: GRM: Unable to allocate {} {}", count, type); return UINT_MAX; } @@ -8346,7 +8362,7 @@ static void ParamSet(ByteReader *buf) * an earlier action D */ if (HasBit(oper, 7)) { if (target < 0x80 && target < _cur.grffile->param_end) { - grfmsg(7, "ParamSet: Param %u already defined, skipping", target); + GrfMsg(7, "ParamSet: Param {} already defined, skipping", target); return; } @@ -8371,13 +8387,13 @@ static void ParamSet(ByteReader *buf) if (op == 0) { /* Check if the allocated sprites will fit below the original sprite limit */ if (_cur.spriteid + count >= 16384) { - grfmsg(0, "ParamSet: GRM: Unable to allocate %d sprites; try changing NewGRF order", count); + GrfMsg(0, "ParamSet: GRM: Unable to allocate {} sprites; try changing NewGRF order", count); DisableGrf(STR_NEWGRF_ERROR_GRM_FAILED); return; } /* Reserve space at the current sprite ID */ - grfmsg(4, "ParamSet: GRM: Allocated %d sprites at %d", count, _cur.spriteid); + GrfMsg(4, "ParamSet: GRM: Allocated {} sprites at {}", count, _cur.spriteid); _grm_sprites[GRFLocation(_cur.grffile->grfid, _cur.nfo_line)] = _cur.spriteid; _cur.spriteid += count; } @@ -8413,7 +8429,7 @@ static void ParamSet(ByteReader *buf) case 0: /* Return space reserved during reservation stage */ src1 = _grm_sprites[GRFLocation(_cur.grffile->grfid, _cur.nfo_line)]; - grfmsg(4, "ParamSet: GRM: Using pre-allocated sprites at %d", src1); + GrfMsg(4, "ParamSet: GRM: Using pre-allocated sprites at {}", src1); break; case 1: @@ -8421,7 +8437,7 @@ static void ParamSet(ByteReader *buf) break; default: - grfmsg(1, "ParamSet: GRM: Unsupported operation %d for general sprites", op); + GrfMsg(1, "ParamSet: GRM: Unsupported operation {} for general sprites", op); return; } break; @@ -8543,7 +8559,7 @@ static void ParamSet(ByteReader *buf) } break; - default: grfmsg(0, "ParamSet: Unknown operation %d, skipping", oper); return; + default: GrfMsg(0, "ParamSet: Unknown operation {}, skipping", oper); return; } switch (target) { @@ -8572,7 +8588,7 @@ static void ParamSet(ByteReader *buf) case 0x96: // Tile refresh offset downwards case 0x97: // Snow line height -- Better supported by feature 8 property 10h (snow line table) TODO: implement by filling the entire snow line table with the given value case 0x99: // Global ID offset -- Not necessary since IDs are remapped automatically - grfmsg(7, "ParamSet: Skipping unimplemented target 0x%02X", target); + GrfMsg(7, "ParamSet: Skipping unimplemented target 0x{:02X}", target); break; case 0x9E: // Miscellaneous GRF features @@ -8593,7 +8609,7 @@ static void ParamSet(ByteReader *buf) break; case 0x9F: // locale-dependent settings - grfmsg(7, "ParamSet: Skipping unimplemented target 0x%02X", target); + GrfMsg(7, "ParamSet: Skipping unimplemented target 0x{:02X}", target); break; default: @@ -8602,7 +8618,7 @@ static void ParamSet(ByteReader *buf) /* param is zeroed by default */ if (target + 1U > _cur.grffile->param_end) _cur.grffile->param_end = target + 1; } else { - grfmsg(7, "ParamSet: Skipping unknown target 0x%02X", target); + GrfMsg(7, "ParamSet: Skipping unknown target 0x{:02X}", target); } break; } @@ -8671,7 +8687,7 @@ static void FeatureTownName(ByteReader *buf) GRFTownName *townname = AddGRFTownName(grfid); uint8_t id = buf->ReadByte(); - grfmsg(6, "FeatureTownName: definition 0x%02X", id & 0x7F); + GrfMsg(6, "FeatureTownName: definition 0x{:02X}", id & 0x7F); if (HasBit(id, 7)) { /* Final definition */ @@ -8684,10 +8700,10 @@ static void FeatureTownName(ByteReader *buf) do { ClrBit(lang, 7); - const char *name = buf->ReadString(); + std::string_view name = buf->ReadString(); std::string lang_name = TranslateTTDPatchCodes(grfid, lang, false, name); - grfmsg(6, "FeatureTownName: lang 0x%X -> '%s'", lang, lang_name.c_str()); + GrfMsg(6, "FeatureTownName: lang 0x{:X} -> '{}'", lang, lang_name); style = AddGRFString(grfid, id, lang, new_scheme, false, name, STR_UNDEFINED); @@ -8697,7 +8713,7 @@ static void FeatureTownName(ByteReader *buf) } uint8_t parts = buf->ReadByte(); - grfmsg(6, "FeatureTownName: %u parts", parts); + GrfMsg(6, "FeatureTownName: {} parts", parts); townname->partlists[id].reserve(parts); for (uint partnum = 0; partnum < parts; partnum++) { @@ -8706,7 +8722,7 @@ static void FeatureTownName(ByteReader *buf) partlist.bitstart = buf->ReadByte(); partlist.bitcount = buf->ReadByte(); partlist.maxprob = 0; - grfmsg(6, "FeatureTownName: part %u contains %u texts and will use GB(seed, %u, %u)", partnum, texts, partlist.bitstart, partlist.bitcount); + GrfMsg(6, "FeatureTownName: part {} contains {} texts and will use GB(seed, {}, {})", partnum, texts, partlist.bitstart, partlist.bitcount); partlist.parts.reserve(texts); for (uint textnum = 0; textnum < texts; textnum++) { @@ -8716,21 +8732,21 @@ static void FeatureTownName(ByteReader *buf) if (HasBit(part.prob, 7)) { uint8_t ref_id = buf->ReadByte(); if (ref_id >= GRFTownName::MAX_LISTS || townname->partlists[ref_id].empty()) { - grfmsg(0, "FeatureTownName: definition 0x%02X doesn't exist, deactivating", ref_id); + GrfMsg(0, "FeatureTownName: definition 0x{:02X} doesn't exist, deactivating", ref_id); DelGRFTownName(grfid); DisableGrf(STR_NEWGRF_ERROR_INVALID_ID); return; } part.id = ref_id; - grfmsg(6, "FeatureTownName: part %u, text %u, uses intermediate definition 0x%02X (with probability %u)", partnum, textnum, ref_id, part.prob & 0x7F); + GrfMsg(6, "FeatureTownName: part {}, text {}, uses intermediate definition 0x{:02X} (with probability {})", partnum, textnum, ref_id, part.prob & 0x7F); } else { - const char *text = buf->ReadString(); + std::string_view text = buf->ReadString(); part.text = TranslateTTDPatchCodes(grfid, 0, false, text); - grfmsg(6, "FeatureTownName: part %u, text %u, '%s' (with probability %u)", partnum, textnum, part.text.c_str(), part.prob); + GrfMsg(6, "FeatureTownName: part {}, text {}, '{}' (with probability {})", partnum, textnum, part.text, part.prob); } partlist.maxprob += GB(part.prob, 0, 7); } - grfmsg(6, "FeatureTownName: part %u, total probability %u", partnum, partlist.maxprob); + GrfMsg(6, "FeatureTownName: part {}, total probability {}", partnum, partlist.maxprob); } } @@ -8746,7 +8762,7 @@ static void DefineGotoLabel(ByteReader *buf) _cur.grffile->labels.emplace_back(nfo_label, _cur.nfo_line, _cur.file->GetPos()); - grfmsg(2, "DefineGotoLabel: GOTO target with label 0x%02X", nfo_label); + GrfMsg(2, "DefineGotoLabel: GOTO target with label 0x{:02X}", nfo_label); } /** @@ -8761,16 +8777,16 @@ static void ImportGRFSound(SoundEntry *sound) file = GetFileByGRFID(grfid); if (file == nullptr || file->sound_offset == 0) { - grfmsg(1, "ImportGRFSound: Source file not available"); + GrfMsg(1, "ImportGRFSound: Source file not available"); return; } if (sound_id >= file->num_sounds) { - grfmsg(1, "ImportGRFSound: Sound effect %d is invalid", sound_id); + GrfMsg(1, "ImportGRFSound: Sound effect {} is invalid", sound_id); return; } - grfmsg(2, "ImportGRFSound: Copying sound %d (%d) from file %X", sound_id, file->sound_offset + sound_id, grfid); + GrfMsg(2, "ImportGRFSound: Copying sound {} ({}) from file {:x}", sound_id, file->sound_offset + sound_id, grfid); *sound = *GetSound(file->sound_offset + sound_id); @@ -8834,10 +8850,10 @@ static void GRFSound(ByteReader *buf) if (grf_container_version >= 2 && type == 0xFD) { /* Reference to sprite section. */ if (invalid) { - grfmsg(1, "GRFSound: Sound index out of range (multiple Action 11?)"); + GrfMsg(1, "GRFSound: Sound index out of range (multiple Action 11?)"); file.SkipBytes(len); } else if (len != 4) { - grfmsg(1, "GRFSound: Invalid sprite section import"); + GrfMsg(1, "GRFSound: Invalid sprite section import"); file.SkipBytes(len); } else { uint32_t id = file.ReadDword(); @@ -8847,14 +8863,14 @@ static void GRFSound(ByteReader *buf) } if (type != 0xFF) { - grfmsg(1, "GRFSound: Unexpected RealSprite found, skipping"); + GrfMsg(1, "GRFSound: Unexpected RealSprite found, skipping"); file.SkipBytes(7); SkipSpriteData(*_cur.file, type, len - 8); continue; } if (invalid) { - grfmsg(1, "GRFSound: Sound index out of range (multiple Action 11?)"); + GrfMsg(1, "GRFSound: Sound index out of range (multiple Action 11?)"); file.SkipBytes(len); } @@ -8864,7 +8880,7 @@ static void GRFSound(ByteReader *buf) /* Allocate sound only in init stage. */ if (_cur.stage == GLS_INIT) { if (grf_container_version >= 2) { - grfmsg(1, "GRFSound: Inline sounds are not supported for container version >= 2"); + GrfMsg(1, "GRFSound: Inline sounds are not supported for container version >= 2"); } else { LoadGRFSound(offs, sound + i); } @@ -8876,7 +8892,7 @@ static void GRFSound(ByteReader *buf) if (_cur.stage == GLS_ACTIVATION) { /* XXX 'Action 0xFE' isn't really specified. It is only mentioned for * importing sounds, so this is probably all wrong... */ - if (file.ReadByte() != 0) grfmsg(1, "GRFSound: Import type mismatch"); + if (file.ReadByte() != 0) GrfMsg(1, "GRFSound: Import type mismatch"); ImportGRFSound(sound + i); } else { file.SkipBytes(len - 1); // already read @@ -8884,7 +8900,7 @@ static void GRFSound(ByteReader *buf) break; default: - grfmsg(1, "GRFSound: Unexpected Action %x found, skipping", action); + GrfMsg(1, "GRFSound: Unexpected Action {:x} found, skipping", action); file.SkipBytes(len - 1); // already read break; } @@ -8900,7 +8916,7 @@ static void SkipAct11(ByteReader *buf) _cur.skip_sprites = buf->ReadWord(); - grfmsg(3, "SkipAct11: Skipping %d sprites", _cur.skip_sprites); + GrfMsg(3, "SkipAct11: Skipping {} sprites", _cur.skip_sprites); } /** Action 0x12 */ @@ -8921,10 +8937,10 @@ static void LoadFontGlyph(ByteReader *buf) uint16_t base_char = buf->ReadWord(); if (size >= FS_END) { - grfmsg(1, "LoadFontGlyph: Size %u is not supported, ignoring", size); + GrfMsg(1, "LoadFontGlyph: Size {} is not supported, ignoring", size); } - grfmsg(7, "LoadFontGlyph: Loading %u glyph(s) at 0x%04X for size %u", num_char, base_char, size); + GrfMsg(7, "LoadFontGlyph: Loading {} glyph(s) at 0x{:04X} for size {}", num_char, base_char, size); for (uint c = 0; c < num_char; c++) { if (size < FS_END) SetUnicodeGlyph(size, base_char + c, _cur.spriteid); @@ -8957,7 +8973,7 @@ static void SkipAct12(ByteReader *buf) buf->ReadWord(); } - grfmsg(3, "SkipAct12: Skipping %d sprites", _cur.skip_sprites); + GrfMsg(3, "SkipAct12: Skipping {} sprites", _cur.skip_sprites); } /** Action 0x13 */ @@ -8973,7 +8989,7 @@ static void TranslateGRFStrings(ByteReader *buf) uint32_t grfid = buf->ReadDWord(); const GRFConfig *c = GetGRFConfig(grfid); if (c == nullptr || (c->status != GCS_INITIALISED && c->status != GCS_ACTIVATED)) { - grfmsg(7, "TranslateGRFStrings: GRFID 0x%08x unknown, skipping action 13", BSWAP32(grfid)); + GrfMsg(7, "TranslateGRFStrings: GRFID 0x{:08X} unknown, skipping action 13", BSWAP32(grfid)); return; } @@ -8997,15 +9013,15 @@ static void TranslateGRFStrings(ByteReader *buf) uint16_t first_id = buf->ReadWord(); if (!((first_id >= 0xD000 && first_id + num_strings <= 0xD400) || (first_id >= 0xD800 && first_id + num_strings <= 0xE000))) { - grfmsg(7, "TranslateGRFStrings: Attempting to set out-of-range string IDs in action 13 (first: 0x%4X, number: 0x%2X)", first_id, num_strings); + GrfMsg(7, "TranslateGRFStrings: Attempting to set out-of-range string IDs in action 13 (first: 0x{:04X}, number: 0x{:02X})", first_id, num_strings); return; } for (uint i = 0; i < num_strings && buf->HasData(); i++) { - const char *string = buf->ReadString(); + std::string_view string = buf->ReadString(); - if (StrEmpty(string)) { - grfmsg(7, "TranslateGRFString: Ignoring empty string."); + if (string.empty()) { + GrfMsg(7, "TranslateGRFString: Ignoring empty string."); continue; } @@ -9014,21 +9030,21 @@ static void TranslateGRFStrings(ByteReader *buf) } /** Callback function for 'INFO'->'NAME' to add a translation to the newgrf name. */ -static bool ChangeGRFName(uint8_t langid, const char *str) +static bool ChangeGRFName(uint8_t langid, std::string_view str) { AddGRFTextToList(_cur.grfconfig->name, langid, _cur.grfconfig->ident.grfid, false, str); return true; } /** Callback function for 'INFO'->'DESC' to add a translation to the newgrf description. */ -static bool ChangeGRFDescription(uint8_t langid, const char *str) +static bool ChangeGRFDescription(uint8_t langid, std::string_view str) { AddGRFTextToList(_cur.grfconfig->info, langid, _cur.grfconfig->ident.grfid, true, str); return true; } /** Callback function for 'INFO'->'URL_' to set the newgrf url. */ -static bool ChangeGRFURL(uint8_t langid, const char *str) +static bool ChangeGRFURL(uint8_t langid, std::string_view str) { AddGRFTextToList(_cur.grfconfig->url, langid, _cur.grfconfig->ident.grfid, false, str); return true; @@ -9038,7 +9054,7 @@ static bool ChangeGRFURL(uint8_t langid, const char *str) static bool ChangeGRFNumUsedParams(size_t len, ByteReader *buf) { if (len != 1) { - grfmsg(2, "StaticGRFInfo: expected only 1 byte for 'INFO'->'NPAR' but got " PRINTF_SIZE ", ignoring this field", len); + GrfMsg(2, "StaticGRFInfo: expected only 1 byte for 'INFO'->'NPAR' but got {}, ignoring this field", len); buf->Skip(len); } else { _cur.grfconfig->num_valid_params = std::min(buf->ReadByte(), ClampTo(_cur.grfconfig->param.size())); @@ -9050,7 +9066,7 @@ static bool ChangeGRFNumUsedParams(size_t len, ByteReader *buf) static bool ChangeGRFPalette(size_t len, ByteReader *buf) { if (len != 1) { - grfmsg(2, "StaticGRFInfo: expected only 1 byte for 'INFO'->'PALS' but got " PRINTF_SIZE ", ignoring this field", len); + GrfMsg(2, "StaticGRFInfo: expected only 1 byte for 'INFO'->'PALS' but got {}, ignoring this field", len); buf->Skip(len); } else { char data = buf->ReadByte(); @@ -9061,7 +9077,7 @@ static bool ChangeGRFPalette(size_t len, ByteReader *buf) case 'W': pal = GRFP_GRF_WINDOWS; break; case 'D': pal = GRFP_GRF_DOS; break; default: - grfmsg(2, "StaticGRFInfo: unexpected value '%02x' for 'INFO'->'PALS', ignoring this field", data); + GrfMsg(2, "StaticGRFInfo: unexpected value '{:02X}' for 'INFO'->'PALS', ignoring this field", data); break; } if (pal != GRFP_GRF_UNSET) { @@ -9076,7 +9092,7 @@ static bool ChangeGRFPalette(size_t len, ByteReader *buf) static bool ChangeGRFBlitter(size_t len, ByteReader *buf) { if (len != 1) { - grfmsg(2, "StaticGRFInfo: expected only 1 byte for 'INFO'->'BLTR' but got " PRINTF_SIZE ", ignoring this field", len); + GrfMsg(2, "StaticGRFInfo: expected only 1 byte for 'INFO'->'BLTR' but got {}, ignoring this field", len); buf->Skip(len); } else { char data = buf->ReadByte(); @@ -9085,7 +9101,7 @@ static bool ChangeGRFBlitter(size_t len, ByteReader *buf) case '8': pal = GRFP_BLT_UNSET; break; case '3': pal = GRFP_BLT_32BPP; break; default: - grfmsg(2, "StaticGRFInfo: unexpected value '%02x' for 'INFO'->'BLTR', ignoring this field", data); + GrfMsg(2, "StaticGRFInfo: unexpected value '{:02X}' for 'INFO'->'BLTR', ignoring this field", data); return true; } _cur.grfconfig->palette &= ~GRFP_BLT_MASK; @@ -9098,7 +9114,7 @@ static bool ChangeGRFBlitter(size_t len, ByteReader *buf) static bool ChangeGRFVersion(size_t len, ByteReader *buf) { if (len != 4) { - grfmsg(2, "StaticGRFInfo: expected 4 bytes for 'INFO'->'VRSN' but got " PRINTF_SIZE ", ignoring this field", len); + GrfMsg(2, "StaticGRFInfo: expected 4 bytes for 'INFO'->'VRSN' but got {}, ignoring this field", len); buf->Skip(len); } else { /* Set min_loadable_version as well (default to minimal compatibility) */ @@ -9111,16 +9127,16 @@ static bool ChangeGRFVersion(size_t len, ByteReader *buf) static bool ChangeGRFMinVersion(size_t len, ByteReader *buf) { if (len != 4) { - grfmsg(2, "StaticGRFInfo: expected 4 bytes for 'INFO'->'MINV' but got " PRINTF_SIZE ", ignoring this field", len); + GrfMsg(2, "StaticGRFInfo: expected 4 bytes for 'INFO'->'MINV' but got {}, ignoring this field", len); buf->Skip(len); } else { _cur.grfconfig->min_loadable_version = buf->ReadDWord(); if (_cur.grfconfig->version == 0) { - grfmsg(2, "StaticGRFInfo: 'MINV' defined before 'VRSN' or 'VRSN' set to 0, ignoring this field"); + GrfMsg(2, "StaticGRFInfo: 'MINV' defined before 'VRSN' or 'VRSN' set to 0, ignoring this field"); _cur.grfconfig->min_loadable_version = 0; } if (_cur.grfconfig->version < _cur.grfconfig->min_loadable_version) { - grfmsg(2, "StaticGRFInfo: 'MINV' defined as %d, limiting it to 'VRSN'", _cur.grfconfig->min_loadable_version); + GrfMsg(2, "StaticGRFInfo: 'MINV' defined as {}, limiting it to 'VRSN'", _cur.grfconfig->min_loadable_version); _cur.grfconfig->min_loadable_version = _cur.grfconfig->version; } } @@ -9130,14 +9146,14 @@ static bool ChangeGRFMinVersion(size_t len, ByteReader *buf) static GRFParameterInfo *_cur_parameter; ///< The parameter which info is currently changed by the newgrf. /** Callback function for 'INFO'->'PARAM'->param_num->'NAME' to set the name of a parameter. */ -static bool ChangeGRFParamName(uint8_t langid, const char *str) +static bool ChangeGRFParamName(uint8_t langid, std::string_view str) { AddGRFTextToList(_cur_parameter->name, langid, _cur.grfconfig->ident.grfid, false, str); return true; } /** Callback function for 'INFO'->'PARAM'->param_num->'DESC' to set the description of a parameter. */ -static bool ChangeGRFParamDescription(uint8_t langid, const char *str) +static bool ChangeGRFParamDescription(uint8_t langid, std::string_view str) { AddGRFTextToList(_cur_parameter->desc, langid, _cur.grfconfig->ident.grfid, true, str); return true; @@ -9147,14 +9163,14 @@ static bool ChangeGRFParamDescription(uint8_t langid, const char *str) static bool ChangeGRFParamType(size_t len, ByteReader *buf) { if (len != 1) { - grfmsg(2, "StaticGRFInfo: expected 1 byte for 'INFO'->'PARA'->'TYPE' but got " PRINTF_SIZE ", ignoring this field", len); + GrfMsg(2, "StaticGRFInfo: expected 1 byte for 'INFO'->'PARA'->'TYPE' but got {}, ignoring this field", len); buf->Skip(len); } else { GRFParameterType type = (GRFParameterType)buf->ReadByte(); if (type < PTYPE_END) { _cur_parameter->type = type; } else { - grfmsg(3, "StaticGRFInfo: unknown parameter type %d, ignoring this field", type); + GrfMsg(3, "StaticGRFInfo: unknown parameter type {}, ignoring this field", type); } } return true; @@ -9164,10 +9180,10 @@ static bool ChangeGRFParamType(size_t len, ByteReader *buf) static bool ChangeGRFParamLimits(size_t len, ByteReader *buf) { if (_cur_parameter->type != PTYPE_UINT_ENUM) { - grfmsg(2, "StaticGRFInfo: 'INFO'->'PARA'->'LIMI' is only valid for parameters with type uint/enum, ignoring this field"); + GrfMsg(2, "StaticGRFInfo: 'INFO'->'PARA'->'LIMI' is only valid for parameters with type uint/enum, ignoring this field"); buf->Skip(len); } else if (len != 8) { - grfmsg(2, "StaticGRFInfo: expected 8 bytes for 'INFO'->'PARA'->'LIMI' but got " PRINTF_SIZE ", ignoring this field", len); + GrfMsg(2, "StaticGRFInfo: expected 8 bytes for 'INFO'->'PARA'->'LIMI' but got {}, ignoring this field", len); buf->Skip(len); } else { uint32_t min_value = buf->ReadDWord(); @@ -9176,7 +9192,7 @@ static bool ChangeGRFParamLimits(size_t len, ByteReader *buf) _cur_parameter->min_value = min_value; _cur_parameter->max_value = max_value; } else { - grfmsg(2, "StaticGRFInfo: 'INFO'->'PARA'->'LIMI' values are incoherent, ignoring this field"); + GrfMsg(2, "StaticGRFInfo: 'INFO'->'PARA'->'LIMI' values are incoherent, ignoring this field"); } } return true; @@ -9186,12 +9202,12 @@ static bool ChangeGRFParamLimits(size_t len, ByteReader *buf) static bool ChangeGRFParamMask(size_t len, ByteReader *buf) { if (len < 1 || len > 3) { - grfmsg(2, "StaticGRFInfo: expected 1 to 3 bytes for 'INFO'->'PARA'->'MASK' but got " PRINTF_SIZE ", ignoring this field", len); + GrfMsg(2, "StaticGRFInfo: expected 1 to 3 bytes for 'INFO'->'PARA'->'MASK' but got {}, ignoring this field", len); buf->Skip(len); } else { uint8_t param_nr = buf->ReadByte(); if (param_nr >= _cur.grfconfig->param.size()) { - grfmsg(2, "StaticGRFInfo: invalid parameter number in 'INFO'->'PARA'->'MASK', param %d, ignoring this field", param_nr); + GrfMsg(2, "StaticGRFInfo: invalid parameter number in 'INFO'->'PARA'->'MASK', param {}, ignoring this field", param_nr); buf->Skip(len - 1); } else { _cur_parameter->param_nr = param_nr; @@ -9207,7 +9223,7 @@ static bool ChangeGRFParamMask(size_t len, ByteReader *buf) static bool ChangeGRFParamDefault(size_t len, ByteReader *buf) { if (len != 4) { - grfmsg(2, "StaticGRFInfo: expected 4 bytes for 'INFO'->'PARA'->'DEFA' but got " PRINTF_SIZE ", ignoring this field", len); + GrfMsg(2, "StaticGRFInfo: expected 4 bytes for 'INFO'->'PARA'->'DEFA' but got {}, ignoring this field", len); buf->Skip(len); } else { _cur_parameter->def_value = buf->ReadDWord(); @@ -9216,9 +9232,9 @@ static bool ChangeGRFParamDefault(size_t len, ByteReader *buf) return true; } -typedef bool (*DataHandler)(size_t, ByteReader *); ///< Type of callback function for binary nodes -typedef bool (*TextHandler)(uint8_t, const char *str); ///< Type of callback function for text nodes -typedef bool (*BranchHandler)(ByteReader *); ///< Type of callback function for branch nodes +typedef bool (*DataHandler)(size_t, ByteReader *); ///< Type of callback function for binary nodes +typedef bool (*TextHandler)(uint8_t, std::string_view str); ///< Type of callback function for text nodes +typedef bool (*BranchHandler)(ByteReader *); ///< Type of callback function for branch nodes /** * Data structure to store the allowed id/type combinations for action 14. The @@ -9331,14 +9347,14 @@ static bool ChangeGRFParamValueNames(ByteReader *buf) while (type != 0) { uint32_t id = buf->ReadDWord(); if (type != 'T' || id > _cur_parameter->max_value) { - grfmsg(2, "StaticGRFInfo: all child nodes of 'INFO'->'PARA'->param_num->'VALU' should have type 't' and the value/bit number as id"); + GrfMsg(2, "StaticGRFInfo: all child nodes of 'INFO'->'PARA'->param_num->'VALU' should have type 't' and the value/bit number as id"); if (!SkipUnknownInfo(buf, type)) return false; type = buf->ReadByte(); continue; } uint8_t langid = buf->ReadByte(); - const char *name_string = buf->ReadString(); + std::string_view name_string = buf->ReadString(); auto val_name = _cur_parameter->value_names.find(id); if (val_name != _cur_parameter->value_names.end()) { @@ -9378,7 +9394,7 @@ static bool HandleParameterInfo(ByteReader *buf) while (type != 0) { uint32_t id = buf->ReadDWord(); if (type != 'C' || id >= _cur.grfconfig->num_valid_params) { - grfmsg(2, "StaticGRFInfo: all child nodes of 'INFO'->'PARA' should have type 'C' and their parameter number as id"); + GrfMsg(2, "StaticGRFInfo: all child nodes of 'INFO'->'PARA' should have type 'C' and their parameter number as id"); if (!SkipUnknownInfo(buf, type)) return false; type = buf->ReadByte(); continue; @@ -9458,17 +9474,17 @@ struct GRFFeatureTest { static GRFFeatureTest _current_grf_feature_test; /** Callback function for 'FTST'->'NAME' to set the name of the feature being tested. */ -static bool ChangeGRFFeatureTestName(uint8_t langid, const char *str) +static bool ChangeGRFFeatureTestName(uint8_t langid, std::string_view str) { extern const GRFFeatureInfo _grf_feature_list[]; for (const GRFFeatureInfo *info = _grf_feature_list; info->name != nullptr; info++) { - if (strcmp(info->name, str) == 0) { + if (str == info->name) { _current_grf_feature_test.feature = info; - grfmsg(2, "Action 14 feature test: found feature named: '%s' (version: %u) in 'FTST'->'NAME'", str, info->version); + GrfMsg(2, "Action 14 feature test: found feature named: '{}' (version: %u) in 'FTST'->'NAME'", str, info->version); return true; } } - grfmsg(2, "Action 14 feature test: could not find feature named: '%s' in 'FTST'->'NAME'", str); + GrfMsg(2, "Action 14 feature test: could not find feature named: '{}' in 'FTST'->'NAME'", str); _current_grf_feature_test.feature = nullptr; return true; } @@ -9795,7 +9811,7 @@ struct GRFPropertyMapAction { static GRFPropertyMapAction _current_grf_property_map_action; /** Callback function for ->'NAME' to set the name of the item to be mapped. */ -static bool ChangePropertyRemapName(uint8_t langid, const char *str) +static bool ChangePropertyRemapName(uint8_t langid, std::string_view str) { _current_grf_property_map_action.name = str; return true; @@ -10182,7 +10198,7 @@ static bool HandleNode(uint8_t type, uint32_t id, ByteReader *buf, AllowedSubtag } } } - grfmsg(2, "StaticGRFInfo: unknown type/id combination found, type=%c, id=%x", type, id); + GrfMsg(2, "StaticGRFInfo: unknown type/id combination found, type={:c}, id={:x}", type, id); return SkipUnknownInfo(buf, type); } @@ -10790,7 +10806,7 @@ static void CalculateRefitMasks() } /* Clear invalid cargoslots (from default vehicles or pre-NewCargo GRFs) */ - if (ei->cargo_type != INVALID_CARGO && !HasBit(_cargo_mask, ei->cargo_type)) ei->cargo_type = INVALID_CARGO; + if (IsValidCargoID(ei->cargo_type) && !HasBit(_cargo_mask, ei->cargo_type)) ei->cargo_type = INVALID_CARGO; /* Ensure that the vehicle is either not refittable, or that the default cargo is one of the refittable cargoes. * Note: Vehicles refittable to no cargo are handle differently to vehicle refittable to a single cargo. The latter might have subtypes. */ @@ -10800,7 +10816,7 @@ static void CalculateRefitMasks() /* Check if this engine's cargo type is valid. If not, set to the first refittable * cargo type. Finally disable the vehicle, if there is still no cargo. */ - if (ei->cargo_type == INVALID_CARGO && ei->refit_mask != 0) { + if (!IsValidCargoID(ei->cargo_type) && ei->refit_mask != 0) { /* Figure out which CTT to use for the default cargo, if it is 'first refittable'. */ const GRFFile *file = _gted[engine].defaultcargo_grf; if (file == nullptr) file = e->GetGRF(); @@ -10816,7 +10832,7 @@ static void CalculateRefitMasks() } } - if (ei->cargo_type == INVALID_CARGO) { + if (!IsValidCargoID(ei->cargo_type)) { /* Use first refittable cargo slot */ ei->cargo_type = (CargoID)FindFirstBit(ei->refit_mask); } @@ -10906,7 +10922,7 @@ static void FinaliseEngineArray() /* Engine looped back on itself, so clear the variant. */ e->info.variant_id = INVALID_ENGINE; - grfmsg(1, "FinaliseEngineArray: Variant of engine %X in '%s' loops back on itself", _engine_mngr[e->index].internal_id, e->GetGRF()->filename.c_str()); + GrfMsg(1, "FinaliseEngineArray: Variant of engine {:x} in '{}' loops back on itself", _engine_mngr[e->index].internal_id, e->GetGRF()->filename); break; } @@ -10955,7 +10971,7 @@ static bool IsHouseSpecValid(HouseSpec *hs, const HouseSpec *next1, const HouseS (next2 == nullptr || !next2->enabled || (next2->building_flags & BUILDING_HAS_1_TILE) != 0 || next3 == nullptr || !next3->enabled || (next3->building_flags & BUILDING_HAS_1_TILE) != 0))) { hs->enabled = false; - if (!filename.empty()) DEBUG(grf, 1, "FinaliseHouseArray: %s defines house %d as multitile, but no suitable tiles follow. Disabling house.", filename.c_str(), hs->grf_prop.local_id); + if (!filename.empty()) Debug(grf, 1, "FinaliseHouseArray: {} defines house {} as multitile, but no suitable tiles follow. Disabling house.", filename, hs->grf_prop.local_id); return false; } @@ -10965,7 +10981,7 @@ static bool IsHouseSpecValid(HouseSpec *hs, const HouseSpec *next1, const HouseS if (((hs->building_flags & BUILDING_HAS_2_TILES) != 0 && next1->population != 0) || ((hs->building_flags & BUILDING_HAS_4_TILES) != 0 && (next2->population != 0 || next3->population != 0))) { hs->enabled = false; - if (!filename.empty()) DEBUG(grf, 1, "FinaliseHouseArray: %s defines multitile house %d with non-zero population on additional tiles. Disabling house.", filename.c_str(), hs->grf_prop.local_id); + if (!filename.empty()) Debug(grf, 1, "FinaliseHouseArray: {} defines multitile house {} with non-zero population on additional tiles. Disabling house.", filename, hs->grf_prop.local_id); return false; } @@ -10973,14 +10989,14 @@ static bool IsHouseSpecValid(HouseSpec *hs, const HouseSpec *next1, const HouseS * This check should only be done for NewGRF houses because grf_prop.subst_id is not set for original houses.*/ if (!filename.empty() && (hs->building_flags & BUILDING_HAS_1_TILE) != (HouseSpec::Get(hs->grf_prop.subst_id)->building_flags & BUILDING_HAS_1_TILE)) { hs->enabled = false; - DEBUG(grf, 1, "FinaliseHouseArray: %s defines house %d with different house size then it's substitute type. Disabling house.", filename.c_str(), hs->grf_prop.local_id); + Debug(grf, 1, "FinaliseHouseArray: {} defines house {} with different house size then it's substitute type. Disabling house.", filename, hs->grf_prop.local_id); return false; } /* Make sure that additional parts of multitile houses are not available. */ if ((hs->building_flags & BUILDING_HAS_1_TILE) == 0 && (hs->building_availability & HZ_ZONALL) != 0 && (hs->building_availability & HZ_CLIMALL) != 0) { hs->enabled = false; - if (!filename.empty()) DEBUG(grf, 1, "FinaliseHouseArray: %s defines house %d without a size but marked it as available. Disabling house.", filename.c_str(), hs->grf_prop.local_id); + if (!filename.empty()) Debug(grf, 1, "FinaliseHouseArray: {} defines house {} without a size but marked it as available. Disabling house.", filename, hs->grf_prop.local_id); return false; } @@ -11260,7 +11276,7 @@ static void DecodeSpecialSprite(uint8_t *buf, uint num, GrfLoadingStage stage) } else { /* Use the preloaded sprite data. */ buf = it->second.get(); - grfmsg(7, "DecodeSpecialSprite: Using preloaded pseudo sprite data"); + GrfMsg(7, "DecodeSpecialSprite: Using preloaded pseudo sprite data"); /* Skip the real (original) content of this action. */ _cur.file->SeekTo(num, SEEK_CUR); @@ -11273,19 +11289,19 @@ static void DecodeSpecialSprite(uint8_t *buf, uint num, GrfLoadingStage stage) uint8_t action = bufp->ReadByte(); if (action == 0xFF) { - grfmsg(2, "DecodeSpecialSprite: Unexpected data block, skipping"); + GrfMsg(2, "DecodeSpecialSprite: Unexpected data block, skipping"); } else if (action == 0xFE) { - grfmsg(2, "DecodeSpecialSprite: Unexpected import block, skipping"); + GrfMsg(2, "DecodeSpecialSprite: Unexpected import block, skipping"); } else if (action >= lengthof(handlers)) { - grfmsg(7, "DecodeSpecialSprite: Skipping unknown action 0x%02X", action); + GrfMsg(7, "DecodeSpecialSprite: Skipping unknown action 0x{:02X}", action); } else if (handlers[action][stage] == nullptr) { - grfmsg(7, "DecodeSpecialSprite: Skipping action 0x%02X in stage %d", action, stage); + GrfMsg(7, "DecodeSpecialSprite: Skipping action 0x{:02X} in stage {}", action, stage); } else { - grfmsg(7, "DecodeSpecialSprite: Handling action 0x%02X in stage %d", action, stage); + GrfMsg(7, "DecodeSpecialSprite: Handling action 0x{:02X} in stage {}", action, stage); handlers[action][stage](bufp); } } catch (...) { - grfmsg(1, "DecodeSpecialSprite: Tried to read past end of pseudo-sprite data"); + GrfMsg(1, "DecodeSpecialSprite: Tried to read past end of pseudo-sprite data"); DisableGrf(STR_NEWGRF_ERROR_READ_BOUNDS); } } @@ -11305,7 +11321,7 @@ static void LoadNewGRFFileFromFile(GRFConfig *config, GrfLoadingStage stage, Spr uint8_t grf_container_version = file.GetContainerVersion(); if (grf_container_version == 0) { - DEBUG(grf, 7, "LoadNewGRFFile: Custom .grf has invalid format"); + Debug(grf, 7, "LoadNewGRFFile: Custom .grf has invalid format"); return; } @@ -11322,7 +11338,7 @@ static void LoadNewGRFFileFromFile(GRFConfig *config, GrfLoadingStage stage, Spr /* Read compression value. */ uint8_t compression = file.ReadByte(); if (compression != 0) { - DEBUG(grf, 7, "LoadNewGRFFile: Unsupported compression format"); + Debug(grf, 7, "LoadNewGRFFile: Unsupported compression format"); return; } } @@ -11334,7 +11350,7 @@ static void LoadNewGRFFileFromFile(GRFConfig *config, GrfLoadingStage stage, Spr if (num == 4 && file.ReadByte() == 0xFF) { file.ReadDword(); } else { - DEBUG(grf, 7, "LoadNewGRFFile: Custom .grf has invalid format"); + Debug(grf, 7, "LoadNewGRFFile: Custom .grf has invalid format"); return; } @@ -11359,7 +11375,7 @@ static void LoadNewGRFFileFromFile(GRFConfig *config, GrfLoadingStage stage, Spr } } else { if (_cur.skip_sprites == 0) { - grfmsg(0, "LoadNewGRFFile: Unexpected sprite, disabling"); + GrfMsg(0, "LoadNewGRFFile: Unexpected sprite, disabling"); DisableGrf(STR_NEWGRF_ERROR_UNEXPECTED_SPRITE); break; } @@ -11400,7 +11416,7 @@ void LoadNewGRFFile(GRFConfig *config, GrfLoadingStage stage, Subdirectory subdi * processed once at initialization. */ if (stage != GLS_FILESCAN && stage != GLS_SAFETYSCAN && stage != GLS_LABELSCAN) { _cur.grffile = GetFileByFilename(filename); - if (_cur.grffile == nullptr) usererror("File '%s' lost in cache.\n", filename.c_str()); + if (_cur.grffile == nullptr) UserError("File '{}' lost in cache.\n", filename); if (stage == GLS_RESERVE && config->status != GCS_INITIALISED) return; if (stage == GLS_ACTIVATION && !HasBit(config->flags, GCF_RESERVED)) return; } @@ -11512,7 +11528,7 @@ static void FinalisePriceBaseMultipliers() for (Price p = PR_BEGIN; p < PR_END; p++) { /* No price defined -> nothing to do */ if (!HasBit(features, _price_base_specs[p].grf_feature) || source->price_base_multipliers[p] == INVALID_PRICE_MODIFIER) continue; - DEBUG(grf, 3, "'%s' overrides price base multiplier %d of '%s'", source->filename.c_str(), p, dest->filename.c_str()); + Debug(grf, 3, "'{}' overrides price base multiplier {} of '{}'", source->filename, p, dest->filename); dest->price_base_multipliers[p] = source->price_base_multipliers[p]; } } @@ -11530,7 +11546,7 @@ static void FinalisePriceBaseMultipliers() for (Price p = PR_BEGIN; p < PR_END; p++) { /* Already a price defined -> nothing to do */ if (!HasBit(features, _price_base_specs[p].grf_feature) || dest->price_base_multipliers[p] != INVALID_PRICE_MODIFIER) continue; - DEBUG(grf, 3, "Price base multiplier %d from '%s' propagated to '%s'", p, source->filename.c_str(), dest->filename.c_str()); + Debug(grf, 3, "Price base multiplier {} from '{}' propagated to '{}'", p, source->filename, dest->filename); dest->price_base_multipliers[p] = source->price_base_multipliers[p]; } } @@ -11548,7 +11564,7 @@ static void FinalisePriceBaseMultipliers() for (Price p = PR_BEGIN; p < PR_END; p++) { if (!HasBit(features, _price_base_specs[p].grf_feature)) continue; if (source->price_base_multipliers[p] != dest->price_base_multipliers[p]) { - DEBUG(grf, 3, "Price base multiplier %d from '%s' propagated to '%s'", p, dest->filename.c_str(), source->filename.c_str()); + Debug(grf, 3, "Price base multiplier {} from '{}' propagated to '{}'", p, dest->filename, source->filename); } source->price_base_multipliers[p] = dest->price_base_multipliers[p]; } @@ -11790,7 +11806,7 @@ void LoadNewGRF(uint load_index, uint num_baseset) Subdirectory subdir = num_grfs < num_baseset ? BASESET_DIR : NEWGRF_DIR; if (!FioCheckFileExists(c->filename, subdir)) { - DEBUG(grf, 0, "NewGRF file is missing '%s'; disabling", c->filename.c_str()); + Debug(grf, 0, "NewGRF file is missing '{}'; disabling", c->filename); c->status = GCS_NOT_FOUND; continue; } @@ -11799,7 +11815,7 @@ void LoadNewGRF(uint load_index, uint num_baseset) if (!HasBit(c->flags, GCF_STATIC) && !HasBit(c->flags, GCF_SYSTEM)) { if (num_non_static == MAX_NON_STATIC_GRF_COUNT) { - DEBUG(grf, 0, "'%s' is not loaded as the maximum number of non-static GRFs has been reached", c->filename.c_str()); + Debug(grf, 0, "'{}' is not loaded as the maximum number of non-static GRFs has been reached", c->filename); c->status = GCS_DISABLED; c->error = {STR_NEWGRF_ERROR_MSG_FATAL, STR_NEWGRF_ERROR_TOO_MANY_NEWGRFS_LOADED}; continue; @@ -11818,7 +11834,7 @@ void LoadNewGRF(uint load_index, uint num_baseset) ClearTemporaryNewGRFData(_cur.grffile); BuildCargoTranslationMap(); HandleVarAction2OptimisationPasses(); - DEBUG(sprite, 2, "LoadNewGRF: Currently %i sprites are loaded", _cur.spriteid); + Debug(sprite, 2, "LoadNewGRF: Currently {} sprites are loaded", _cur.spriteid); } else if (stage == GLS_INIT && HasBit(c->flags, GCF_INIT_ONLY)) { /* We're not going to activate this, so free whatever data we allocated */ ClearTemporaryNewGRFData(_cur.grffile); diff --git a/src/newgrf.h b/src/newgrf.h index 33951ab4cd..a8ce150e50 100644 --- a/src/newgrf.h +++ b/src/newgrf.h @@ -15,6 +15,7 @@ #include "road_type.h" #include "fileio_type.h" #include "debug.h" +#include "newgrf_act5.h" #include "core/bitmath_func.hpp" #include "core/alloc_type.hpp" #include "core/mem_func.hpp" @@ -237,21 +238,6 @@ struct GRFVariableMapEntry { uint32_t output_param = 0; }; -/** The type of action 5 type. */ -enum Action5BlockType { - A5BLOCK_FIXED, ///< Only allow replacing a whole block of sprites. (TTDP compatible) - A5BLOCK_ALLOW_OFFSET, ///< Allow replacing any subset by specifiing an offset. - A5BLOCK_INVALID, ///< unknown/not-implemented type -}; -/** Information about a single action 5 type. */ -struct Action5Type { - Action5BlockType block_type; ///< How is this Action5 type processed? - SpriteID sprite_base; ///< Load the sprites starting from this sprite. - uint16_t min_sprites; ///< If the Action5 contains less sprites, the whole block will be ignored. - uint16_t max_sprites; ///< If the Action5 contains more sprites, only the first max_sprites sprites will be used. - const char *name; ///< Name for error messages. -}; - struct Action5TypeRemapDefinition { const char *name; // nullptr indicates the end of the list const Action5Type info; @@ -450,6 +436,9 @@ void ResetPersistentNewGRFData(); #define grfmsg(severity, ...) if ((severity) == 0 || _debug_grf_level >= (severity)) _intl_grfmsg(severity, __VA_ARGS__) void CDECL _intl_grfmsg(int severity, const char *str, ...) WARN_FORMAT(2, 3); +void GrfMsgI(int severity, const std::string &msg); +#define GrfMsg(severity, format_string, ...) GrfMsgI(severity, fmt::format(FMT_STRING(format_string), ## __VA_ARGS__)) + bool GetGlobalVariable(uint8_t param, uint32_t *value, const GRFFile *grffile); StringID MapGRFStringID(uint32_t grfid, StringID str); diff --git a/src/newgrf_act5.h b/src/newgrf_act5.h new file mode 100644 index 0000000000..16e4d0c587 --- /dev/null +++ b/src/newgrf_act5.h @@ -0,0 +1,31 @@ +/* + * This file is part of OpenTTD. + * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. + * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . + */ + +/** @file newgrf_act5.h Information about NewGRF Action 5. */ + +#ifndef NEWGRF_ACT5_H +#define NEWGRF_ACT5_H + +/** The type of action 5 type. */ +enum Action5BlockType { + A5BLOCK_FIXED, ///< Only allow replacing a whole block of sprites. (TTDP compatible) + A5BLOCK_ALLOW_OFFSET, ///< Allow replacing any subset by specifiing an offset. + A5BLOCK_INVALID, ///< unknown/not-implemented type +}; + +/** Information about a single action 5 type. */ +struct Action5Type { + Action5BlockType block_type; ///< How is this Action5 type processed? + SpriteID sprite_base; ///< Load the sprites starting from this sprite. + uint16_t min_sprites; ///< If the Action5 contains less sprites, the whole block will be ignored. + uint16_t max_sprites; ///< If the Action5 contains more sprites, only the first max_sprites sprites will be used. + const char *name; ///< Name for error messages. +}; + +std::span GetAction5Types(); + +#endif /* NEWGRF_ACT5_H */ diff --git a/src/newgrf_debug_gui.cpp b/src/newgrf_debug_gui.cpp index 216506d81a..f3a6497fbc 100644 --- a/src/newgrf_debug_gui.cpp +++ b/src/newgrf_debug_gui.cpp @@ -12,6 +12,7 @@ #include #include "core/backup_type.hpp" #include "core/container_func.hpp" +#include "core/geometry_func.hpp" #include "window_gui.h" #include "window_func.h" #include "random_access_file_type.h" @@ -35,6 +36,7 @@ #include "train.h" #include "roadveh.h" +#include "newgrf_act5.h" #include "newgrf_airport.h" #include "newgrf_airporttiles.h" #include "newgrf_debug.h" @@ -218,25 +220,14 @@ public: } /** - * Allows to know the size of the persistent storage. + * Gets the span containing the persistent storage. * @param index Index of the item. * @param grfid Parameter for the PSA. Only required for items with parameters. - * @return Size of the persistent storage in indices. + * @return Span of the storage array or an empty span when not present. */ - virtual uint GetPSASize(uint index, uint32_t grfid) const + virtual const std::span GetPSA([[maybe_unused]] uint index, [[maybe_unused]] uint32_t grfid) const { - return 0; - } - - /** - * Gets the first position of the array containing the persistent storage. - * @param index Index of the item. - * @param grfid Parameter for the PSA. Only required for items with parameters. - * @return Pointer to the first position of the storage array or nullptr if not present. - */ - virtual const int32_t *GetPSAFirstPosition(uint index, uint32_t grfid) const - { - return nullptr; + return {}; } virtual std::vector GetPSAGRFIDs(uint index) const @@ -459,25 +450,25 @@ struct NewGRFInspectWindow : Window { GetFeatureHelper(this->window_number)->SetStringParameters(this->GetFeatureIndex()); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_NGRFI_VEH_CHAIN: { assert(this->HasChainIndex()); GrfSpecFeature f = GetFeatureNum(this->window_number); if (f == GSF_SHIPS) { - size->height = GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.framerect.Vertical(); + size.height = GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.framerect.Vertical(); break; } - size->height = std::max(size->height, GetVehicleImageCellSize((VehicleType)(VEH_TRAIN + (f - GSF_TRAINS)), EIT_IN_DEPOT).height + 2 + WidgetDimensions::scaled.bevel.Vertical()); + size.height = std::max(size.height, GetVehicleImageCellSize((VehicleType)(VEH_TRAIN + (f - GSF_TRAINS)), EIT_IN_DEPOT).height + 2 + WidgetDimensions::scaled.bevel.Vertical()); break; } case WID_NGRFI_MAINPANEL: - resize->height = std::max(11, GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal); - resize->width = 1; + resize.height = std::max(11, GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal); + resize.width = 1; - size->height = 5 * resize->height + WidgetDimensions::scaled.frametext.Vertical(); + size.height = 5 * resize.height + WidgetDimensions::scaled.frametext.Vertical(); break; } } @@ -775,25 +766,24 @@ struct NewGRFInspectWindow : Window { std::vector psa_grfids = nih->GetPSAGRFIDs(index); for (const uint32_t grfid : psa_grfids) { - uint psa_size = nih->GetPSASize(index, grfid); - const int32_t *psa = nih->GetPSAFirstPosition(index, grfid); - if (psa_size != 0 && psa != nullptr) { + auto psa = nih->GetPSA(index, grfid); + if (!psa.empty()) { if (nih->PSAWithParameter()) { this->DrawString(r, i++, "Persistent storage [%08X]:", BSWAP32(grfid)); } else { this->DrawString(r, i++, "Persistent storage:"); } - assert(psa_size % 4 == 0); + assert(psa.size() % 4 == 0); uint last_non_blank = 0; - for (uint j = 0; j < psa_size; j++) { + for (uint j = 0; j < (uint)psa.size(); j++) { if (psa[j] != 0) last_non_blank = j + 1; } const uint psa_limit = (last_non_blank + 3) & ~3; - for (uint j = 0; j < psa_limit; j += 4, psa += 4) { - this->DrawString(r, i++, " %i: %i %i %i %i", j, psa[0], psa[1], psa[2], psa[3]); + for (uint j = 0; j < psa_limit; j += 44) { + this->DrawString(r, i++, " %i: %i %i %i %i", j, psa[j], psa[j + 1], psa[j + 2], psa[j + 3]); } - if (last_non_blank != psa_size) { - this->DrawString(r, i++, " %i to %i are all 0", psa_limit, psa_size - 1); + if (last_non_blank != (uint)psa.size()) { + this->DrawString(r, i++, " %i to %i are all 0", psa_limit, (uint)(psa.size() - 1)); } } } @@ -1399,7 +1389,6 @@ GrfSpecFeature GetGrfSpecFeature(VehicleType type) } - /**** Sprite Aligner ****/ /** Window used for aligning sprites. */ @@ -1413,6 +1402,7 @@ struct SpriteAlignerWindow : Window { static inline ZoomLevel zoom = ZOOM_LVL_END; static bool centre; static bool crosshair; + const Action5Type *act5_type = nullptr; ///< Sprite Area of current selected sprite. SpriteAlignerWindow(WindowDesc *desc, WindowNumber wno) : Window(desc) { @@ -1420,6 +1410,10 @@ struct SpriteAlignerWindow : Window { if (SpriteAlignerWindow::zoom == ZOOM_LVL_END) SpriteAlignerWindow::zoom = _gui_zoom; SpriteAlignerWindow::zoom = Clamp(SpriteAlignerWindow::zoom, _settings_client.gui.zoom_min, _settings_client.gui.zoom_max); + /* Oh yes, we assume there is at least one normal sprite! */ + while (GetSpriteType(this->current_sprite) != SpriteType::Normal) this->current_sprite++; + this->SelectAction5Type(); + this->CreateNestedTree(); this->vscroll = this->GetScrollbar(WID_SA_SCROLLBAR); this->vscroll->SetCount(_newgrf_debug_sprite_picker.sprites.size()); @@ -1428,9 +1422,6 @@ struct SpriteAlignerWindow : Window { this->SetWidgetLoweredState(WID_SA_CENTRE, SpriteAlignerWindow::centre); this->SetWidgetLoweredState(WID_SA_CROSSHAIR, SpriteAlignerWindow::crosshair); - /* Oh yes, we assume there is at least one normal sprite! */ - while (GetSpriteType(this->current_sprite) != SpriteType::Normal) this->current_sprite++; - this->InvalidateData(0, true); } @@ -1439,8 +1430,22 @@ struct SpriteAlignerWindow : Window { const Sprite *spr = GetSprite(this->current_sprite, SpriteType::Normal, ZoomMask(ZOOM_LVL_GUI)); switch (widget) { case WID_SA_CAPTION: - SetDParam(0, this->current_sprite); - SetDParamStr(1, GetOriginFile(this->current_sprite)->GetSimplifiedFilename()); + if (this->act5_type != nullptr) { + SetDParam(0, STR_SPRITE_ALIGNER_CAPTION_ACTION5); + SetDParam(1, this->act5_type - GetAction5Types().data()); + SetDParam(2, this->current_sprite - this->act5_type->sprite_base); + SetDParamStr(3, GetOriginFile(this->current_sprite)->GetSimplifiedFilename()); + SetDParam(4, GetSpriteLocalID(this->current_sprite)); + } else if (this->current_sprite < SPR_OPENTTD_BASE) { + SetDParam(0, STR_SPRITE_ALIGNER_CAPTION_ACTIONA); + SetDParam(1, this->current_sprite); + SetDParamStr(2, GetOriginFile(this->current_sprite)->GetSimplifiedFilename()); + SetDParam(3, GetSpriteLocalID(this->current_sprite)); + } else { + SetDParam(0, STR_SPRITE_ALIGNER_CAPTION_NO_ACTION); + SetDParamStr(1, GetOriginFile(this->current_sprite)->GetSimplifiedFilename()); + SetDParam(2, GetSpriteLocalID(this->current_sprite)); + } break; case WID_SA_OFFSETS_ABS: @@ -1468,19 +1473,27 @@ struct SpriteAlignerWindow : Window { } } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_SA_SPRITE: - size->height = ScaleGUITrad(200); + size.height = ScaleGUITrad(200); break; - case WID_SA_LIST: - SetDParamMaxDigits(0, 6); - size->width = GetStringBoundingBox(STR_JUST_COMMA).width + padding.width; - resize->height = GetCharacterHeight(FS_NORMAL) + padding.height; - resize->width = 1; - fill->height = resize->height; + + case WID_SA_LIST: { + Dimension d = {}; + for (const auto &spritefile : GetCachedSpriteFiles()) { + SetDParamStr(0, spritefile->GetSimplifiedFilename()); + SetDParamMaxDigits(1, 6); + d = maxdim(d, GetStringBoundingBox(STR_SPRITE_ALIGNER_SPRITE)); + } + size.width = d.width + padding.width; + resize.height = GetCharacterHeight(FS_NORMAL) + padding.height; + resize.width = 1; + fill.height = resize.height; break; + } + default: break; } @@ -1532,8 +1545,15 @@ struct SpriteAlignerWindow : Window { Rect ir = r.Shrink(WidgetDimensions::scaled.matrix); auto [first, last] = this->vscroll->GetVisibleRangeIterators(list); for (auto it = first; it != last; ++it) { - SetDParam(0, *it); - DrawString(ir, STR_JUST_COMMA, *it == this->current_sprite ? TC_WHITE : TC_BLACK, SA_RIGHT | SA_FORCE); + const SpriteFile *file = GetOriginFile(*it); + if (file == nullptr) { + SetDParam(0, *it); + DrawString(ir, STR_JUST_COMMA, *it == this->current_sprite ? TC_WHITE : (TC_GREY | TC_NO_SHADE), SA_RIGHT | SA_FORCE); + } else { + SetDParamStr(0, file->GetSimplifiedFilename()); + SetDParam(1, GetSpriteLocalID(*it)); + DrawString(ir, STR_SPRITE_ALIGNER_SPRITE, *it == this->current_sprite ? TC_WHITE : TC_BLACK); + } ir.top += step_size; } break; @@ -1548,6 +1568,7 @@ struct SpriteAlignerWindow : Window { do { this->current_sprite = (this->current_sprite == 0 ? GetMaxSpriteID() : this->current_sprite) - 1; } while (GetSpriteType(this->current_sprite) != SpriteType::Normal); + this->SelectAction5Type(); this->SetDirty(); break; @@ -1559,6 +1580,7 @@ struct SpriteAlignerWindow : Window { do { this->current_sprite = (this->current_sprite + 1) % GetMaxSpriteID(); } while (GetSpriteType(this->current_sprite) != SpriteType::Normal); + this->SelectAction5Type(); this->SetDirty(); break; @@ -1574,6 +1596,7 @@ struct SpriteAlignerWindow : Window { SpriteID spr = *it; if (GetSpriteType(spr) == SpriteType::Normal) this->current_sprite = spr; } + this->SelectAction5Type(); this->SetDirty(); break; } @@ -1656,6 +1679,7 @@ struct SpriteAlignerWindow : Window { while (GetSpriteType(this->current_sprite) != SpriteType::Normal) { this->current_sprite = (this->current_sprite + 1) % GetMaxSpriteID(); } + this->SelectAction5Type(); this->SetDirty(); } @@ -1684,6 +1708,19 @@ struct SpriteAlignerWindow : Window { { this->vscroll->SetCapacityFromWidget(this, WID_SA_LIST); } + +private: + void SelectAction5Type() + { + const auto act5types = GetAction5Types(); + for (auto it = std::begin(act5types); it != std::end(act5types); ++it) { + if (it->sprite_base <= this->current_sprite && this->current_sprite < it->sprite_base + it->max_sprites) { + this->act5_type = &*it; + return; + } + } + this->act5_type = nullptr; + } }; bool SpriteAlignerWindow::centre = true; @@ -1692,7 +1729,7 @@ bool SpriteAlignerWindow::crosshair = true; static constexpr NWidgetPart _nested_sprite_aligner_widgets[] = { NWidget(NWID_HORIZONTAL), NWidget(WWT_CLOSEBOX, COLOUR_GREY), - NWidget(WWT_CAPTION, COLOUR_GREY, WID_SA_CAPTION), SetDataTip(STR_SPRITE_ALIGNER_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS), + NWidget(WWT_CAPTION, COLOUR_GREY, WID_SA_CAPTION), SetDataTip(STR_JUST_STRING4, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS), NWidget(WWT_SHADEBOX, COLOUR_GREY), NWidget(WWT_STICKYBOX, COLOUR_GREY), EndContainer(), diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp index bb9d0e4a91..1a3bc1d416 100644 --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -223,13 +223,13 @@ struct NewGRFParametersWindow : public Window { return this->HasParameterInfo(nr) ? this->grf_config->param_info[nr].value() : GetDummyParameterInfo(nr); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_NP_NUMPAR_DEC: case WID_NP_NUMPAR_INC: { - size->width = std::max(SETTING_BUTTON_WIDTH / 2, GetCharacterHeight(FS_NORMAL)); - size->height = std::max(SETTING_BUTTON_HEIGHT, GetCharacterHeight(FS_NORMAL)); + size.width = std::max(SETTING_BUTTON_WIDTH / 2, GetCharacterHeight(FS_NORMAL)); + size.height = std::max(SETTING_BUTTON_HEIGHT, GetCharacterHeight(FS_NORMAL)); break; } @@ -238,16 +238,16 @@ struct NewGRFParametersWindow : public Window { Dimension d = GetStringBoundingBox(this->GetWidget(widget)->widget_data); d.width += padding.width; d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } case WID_NP_BACKGROUND: this->line_height = std::max(SETTING_BUTTON_HEIGHT, GetCharacterHeight(FS_NORMAL)) + padding.height; - resize->width = 1; - resize->height = this->line_height; - size->height = 5 * this->line_height; + resize.width = 1; + resize.height = this->line_height; + size.height = 5 * this->line_height; break; case WID_NP_DESCRIPTION: @@ -261,7 +261,7 @@ struct NewGRFParametersWindow : public Window { d.height += WidgetDimensions::scaled.frametext.Vertical(); suggestion = maxdim(d, suggestion); } - size->height = suggestion.height; + size.height = suggestion.height; break; } } @@ -759,34 +759,34 @@ struct NewGRFWindow : public Window, NewGRFScanCallback { } } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_NS_FILE_LIST: { Dimension d = maxdim(GetScaledSpriteSize(SPR_SQUARE), GetScaledSpriteSize(SPR_WARNING_SIGN)); - resize->height = std::max(d.height + 2U, GetCharacterHeight(FS_NORMAL)); - size->height = std::max(size->height, padding.height + 6 * resize->height); + resize.height = std::max(d.height + 2U, GetCharacterHeight(FS_NORMAL)); + size.height = std::max(size.height, padding.height + 6 * resize.height); break; } case WID_NS_AVAIL_LIST: { Dimension d = maxdim(GetScaledSpriteSize(SPR_SQUARE), GetScaledSpriteSize(SPR_WARNING_SIGN)); - resize->height = std::max(d.height + 2U, GetCharacterHeight(FS_NORMAL)); - size->height = std::max(size->height, padding.height + 8 * resize->height); + resize.height = std::max(d.height + 2U, GetCharacterHeight(FS_NORMAL)); + size.height = std::max(size.height, padding.height + 8 * resize.height); break; } case WID_NS_NEWGRF_INFO_TITLE: { Dimension dim = GetStringBoundingBox(STR_NEWGRF_SETTINGS_INFO_TITLE); - size->height = std::max(size->height, dim.height + WidgetDimensions::scaled.frametext.Vertical()); - size->width = std::max(size->width, dim.width + WidgetDimensions::scaled.frametext.Horizontal()); + size.height = std::max(size.height, dim.height + WidgetDimensions::scaled.frametext.Vertical()); + size.width = std::max(size.width, dim.width + WidgetDimensions::scaled.frametext.Horizontal()); break; } case WID_NS_NEWGRF_INFO: - size->height = std::max(size->height, WidgetDimensions::scaled.framerect.Vertical() + 10 * GetCharacterHeight(FS_NORMAL)); + size.height = std::max(size.height, WidgetDimensions::scaled.framerect.Vertical() + 10 * GetCharacterHeight(FS_NORMAL)); break; case WID_NS_PRESET_LIST: { @@ -796,16 +796,16 @@ struct NewGRFWindow : public Window, NewGRFScanCallback { d = maxdim(d, GetStringBoundingBox(STR_JUST_RAW_STRING)); } d.width += padding.width; - *size = maxdim(d, *size); + size = maxdim(d, size); break; } case WID_NS_CONTENT_DOWNLOAD: case WID_NS_CONTENT_DOWNLOAD2: { Dimension d = GetStringBoundingBox(STR_NEWGRF_SETTINGS_FIND_MISSING_CONTENT_BUTTON); - *size = maxdim(d, GetStringBoundingBox(STR_INTRO_ONLINE_CONTENT)); - size->width += padding.width; - size->height += padding.height; + size = maxdim(d, GetStringBoundingBox(STR_INTRO_ONLINE_CONTENT)); + size.width += padding.width; + size.height += padding.height; break; } } @@ -2136,18 +2136,18 @@ struct SavePresetWindow : public Window { if (initial_text != nullptr) this->presetname_editbox.text.Assign(initial_text); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override { switch (widget) { case WID_SVP_PRESET_LIST: { - resize->height = GetCharacterHeight(FS_NORMAL); - size->height = 0; + resize.height = GetCharacterHeight(FS_NORMAL); + size.height = 0; for (uint i = 0; i < this->presets.size(); i++) { Dimension d = GetStringBoundingBox(this->presets[i]); - size->width = std::max(size->width, d.width + padding.width); - resize->height = std::max(resize->height, d.height); + size.width = std::max(size.width, d.width + padding.width); + resize.height = std::max(resize.height, d.height); } - size->height = ClampU((uint)this->presets.size(), 5, 20) * resize->height + padding.height; + size.height = ClampU((uint)this->presets.size(), 5, 20) * resize.height + padding.height; break; } } @@ -2251,15 +2251,15 @@ struct ScanProgressWindow : public Window { this->InitNested(1); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_SP_PROGRESS_BAR: { SetDParamMaxValue(0, 100); - *size = GetStringBoundingBox(STR_GENERATION_PROGRESS); + size = GetStringBoundingBox(STR_GENERATION_PROGRESS); /* We need some spacing for the 'border' */ - size->height += WidgetDimensions::scaled.frametext.Horizontal(); - size->width += WidgetDimensions::scaled.frametext.Vertical(); + size.height += WidgetDimensions::scaled.frametext.Horizontal(); + size.width += WidgetDimensions::scaled.frametext.Vertical(); break; } @@ -2268,8 +2268,8 @@ struct ScanProgressWindow : public Window { SetDParamMaxDigits(1, 4); /* We really don't know the width. We could determine it by scanning the NewGRFs, * but this is the status window for scanning them... */ - size->width = std::max(size->width, GetStringBoundingBox(STR_NEWGRF_SCAN_STATUS).width + padding.width); - size->height = GetCharacterHeight(FS_NORMAL) * 2 + WidgetDimensions::scaled.vsep_normal; + size.width = std::max(size.width, GetStringBoundingBox(STR_NEWGRF_SCAN_STATUS).width + padding.width); + size.height = GetCharacterHeight(FS_NORMAL) * 2 + WidgetDimensions::scaled.vsep_normal; break; } } diff --git a/src/newgrf_text.cpp b/src/newgrf_text.cpp index 8d71952396..bcd27ed344 100644 --- a/src/newgrf_text.cpp +++ b/src/newgrf_text.cpp @@ -240,12 +240,12 @@ struct UnmappedChoiceList { * @param byte80 The control code to use as replacement for the 0x80-value. * @return The translated string. */ -std::string TranslateTTDPatchCodes(uint32_t grfid, uint8_t language_id, bool allow_newlines, const std::string &str, StringControlCode byte80) +std::string TranslateTTDPatchCodes(uint32_t grfid, uint8_t language_id, bool allow_newlines, std::string_view str, StringControlCode byte80) { /* Empty input string? Nothing to do here. */ - if (str.empty()) return str; + if (str.empty()) return {}; - std::string::const_iterator src = str.cbegin(); + std::string_view::const_iterator src = str.cbegin(); /* Is this an unicode string? */ bool unicode = false; @@ -494,7 +494,7 @@ string_end: * @param langid The The language of the new text. * @param text_to_add The text to add to the list. */ -static void AddGRFTextToList(GRFTextList &list, uint8_t langid, const std::string &text_to_add) +static void AddGRFTextToList(GRFTextList &list, uint8_t langid, std::string_view text_to_add) { /* Loop through all languages and see if we can replace a string */ for (auto &text : list) { @@ -505,7 +505,7 @@ static void AddGRFTextToList(GRFTextList &list, uint8_t langid, const std::strin } /* If a string wasn't replaced, then we must append the new string */ - list.push_back(GRFText{ langid, text_to_add }); + list.push_back(GRFText{ langid, std::string(text_to_add) }); } /** @@ -517,7 +517,7 @@ static void AddGRFTextToList(GRFTextList &list, uint8_t langid, const std::strin * @param text_to_add The text to add to the list. * @note All text-codes will be translated. */ -void AddGRFTextToList(GRFTextList &list, uint8_t langid, uint32_t grfid, bool allow_newlines, const char *text_to_add) +void AddGRFTextToList(GRFTextList &list, uint8_t langid, uint32_t grfid, bool allow_newlines, std::string_view text_to_add) { AddGRFTextToList(list, langid, TranslateTTDPatchCodes(grfid, langid, allow_newlines, text_to_add)); } @@ -531,7 +531,7 @@ void AddGRFTextToList(GRFTextList &list, uint8_t langid, uint32_t grfid, bool al * @param text_to_add The text to add to the list. * @note All text-codes will be translated. */ -void AddGRFTextToList(GRFTextWrapper &list, uint8_t langid, uint32_t grfid, bool allow_newlines, const char *text_to_add) +void AddGRFTextToList(GRFTextWrapper &list, uint8_t langid, uint32_t grfid, bool allow_newlines, std::string_view text_to_add) { if (!list) list.reset(new GRFTextList()); AddGRFTextToList(*list, langid, grfid, allow_newlines, text_to_add); @@ -543,7 +543,7 @@ void AddGRFTextToList(GRFTextWrapper &list, uint8_t langid, uint32_t grfid, bool * @param list The list where the text should be added to. * @param text_to_add The text to add to the list. */ -void AddGRFTextToList(GRFTextWrapper &list, const std::string &text_to_add) +void AddGRFTextToList(GRFTextWrapper &list, std::string_view text_to_add) { if (!list) list.reset(new GRFTextList()); AddGRFTextToList(*list, GRFLX_UNSPECIFIED, text_to_add); @@ -552,7 +552,7 @@ void AddGRFTextToList(GRFTextWrapper &list, const std::string &text_to_add) /** * Add the new read string into our structure. */ -StringID AddGRFString(uint32_t grfid, uint16_t stringid, uint8_t langid_to_add, bool new_scheme, bool allow_newlines, const char *text_to_add, StringID def_string) +StringID AddGRFString(uint32_t grfid, uint16_t stringid, uint8_t langid_to_add, bool new_scheme, bool allow_newlines, std::string_view text_to_add, StringID def_string) { /* When working with the old language scheme (grf_version is less than 7) and * English or American is among the set bits, simply add it as English in diff --git a/src/newgrf_text.h b/src/newgrf_text.h index 342dd69bd8..04d73845f5 100644 --- a/src/newgrf_text.h +++ b/src/newgrf_text.h @@ -31,7 +31,7 @@ typedef std::vector GRFTextList; /** Reference counted wrapper around a GRFText pointer. */ typedef std::shared_ptr GRFTextWrapper; -StringID AddGRFString(uint32_t grfid, uint16_t stringid, uint8_t langid, bool new_scheme, bool allow_newlines, const char *text_to_add, StringID def_string); +StringID AddGRFString(uint32_t grfid, uint16_t stringid, uint8_t langid, bool new_scheme, bool allow_newlines, std::string_view text_to_add, StringID def_string); StringID GetGRFStringID(uint32_t grfid, StringID stringid); const char *GetGRFStringFromGRFText(const GRFTextList &text_list); const char *GetGRFStringFromGRFText(const GRFTextWrapper &text); @@ -40,10 +40,10 @@ const char *GetDefaultLangGRFStringFromGRFText(const GRFTextWrapper &text); const char *GetGRFStringPtr(uint32_t stringid); void CleanUpStrings(); void SetCurrentGrfLangID(uint8_t language_id); -std::string TranslateTTDPatchCodes(uint32_t grfid, uint8_t language_id, bool allow_newlines, const std::string &str, StringControlCode byte80 = SCC_NEWGRF_PRINT_WORD_STRING_ID); -void AddGRFTextToList(GRFTextList &list, uint8_t langid, uint32_t grfid, bool allow_newlines, const char *text_to_add); -void AddGRFTextToList(GRFTextWrapper &list, uint8_t langid, uint32_t grfid, bool allow_newlines, const char *text_to_add); -void AddGRFTextToList(GRFTextWrapper &list, const std::string &text_to_add); +std::string TranslateTTDPatchCodes(uint32_t grfid, uint8_t language_id, bool allow_newlines, std::string_view str, StringControlCode byte80 = SCC_NEWGRF_PRINT_WORD_STRING_ID); +void AddGRFTextToList(GRFTextList &list, uint8_t langid, uint32_t grfid, bool allow_newlines, std::string_view text_to_add); +void AddGRFTextToList(GRFTextWrapper &list, uint8_t langid, uint32_t grfid, bool allow_newlines, std::string_view text_to_add); +void AddGRFTextToList(GRFTextWrapper &list, std::string_view text_to_add); bool CheckGrfLangID(uint8_t lang_id, uint8_t grf_version); diff --git a/src/news_gui.cpp b/src/news_gui.cpp index b716c90c50..5387943e0a 100644 --- a/src/news_gui.cpp +++ b/src/news_gui.cpp @@ -360,7 +360,7 @@ struct NewsWindow : Window { return pt; } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { StringID str = STR_NULL; switch (widget) { @@ -369,12 +369,12 @@ struct NewsWindow : Window { * thus it doesn't get the default sizing of a caption. */ Dimension d2 = GetStringBoundingBox(STR_NEWS_MESSAGE_CAPTION); d2.height += WidgetDimensions::scaled.captiontext.Vertical(); - *size = maxdim(*size, d2); + size = maxdim(size, d2); return; } case WID_N_MGR_FACE: - *size = maxdim(*size, GetScaledSpriteSize(SPR_GRADIENT)); + size = maxdim(size, GetScaledSpriteSize(SPR_GRADIENT)); break; case WID_N_MGR_NAME: @@ -408,15 +408,15 @@ struct NewsWindow : Window { Dimension d2 = GetStringBoundingBox(this->GetWidget(WID_N_SHOW_GROUP)->widget_data); d2.height += WidgetDimensions::scaled.captiontext.Vertical(); d2.width += WidgetDimensions::scaled.captiontext.Horizontal(); - *size = d2; + size = d2; } else { /* Hide 'Show group window' button if this news is not about a vehicle. */ - size->width = 0; - size->height = 0; - resize->width = 0; - resize->height = 0; - fill->width = 0; - fill->height = 0; + size.width = 0; + size.height = 0; + resize.width = 0; + resize.height = 0; + fill.width = 0; + fill.height = 0; } return; @@ -425,13 +425,13 @@ struct NewsWindow : Window { } /* Update minimal size with length of the multi-line string. */ - Dimension d = *size; + Dimension d = size; d.width = (d.width >= padding.width) ? d.width - padding.width : 0; d.height = (d.height >= padding.height) ? d.height - padding.height : 0; d = GetStringMultiLineBoundingBox(str, d); d.width += padding.width; d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); } void SetStringParameters(WidgetID widget) const override @@ -687,13 +687,14 @@ static bool ReadyForNextNewsItem() /** Move to the next ticker item */ static void MoveToNextTickerItem() { - assert(!std::empty(_news)); - /* There is no status bar, so no reason to show news; * especially important with the end game screen when * there is no status bar but possible news. */ if (FindWindowById(WC_STATUS_BAR, 0) == nullptr) return; + /* No news to move to. */ + if (std::empty(_news)) return; + /* if we're not at the latest item, then move on */ while (_statusbar_news != std::begin(_news)) { --_statusbar_news; @@ -721,8 +722,6 @@ static void MoveToNextTickerItem() /** Move to the next news item */ static void MoveToNextNewsItem() { - assert(!std::empty(_news)); - /* There is no status bar, so no reason to show news; * especially important with the end game screen when * there is no status bar but possible news. */ @@ -731,6 +730,9 @@ static void MoveToNextNewsItem() CloseWindowById(WC_NEWS_WINDOW, 0); // close the newspapers window if shown _forced_news = std::end(_news); + /* No news to move to. */ + if (std::empty(_news)) return; + /* if we're not at the latest item, then move on */ while (_current_news != std::begin(_news)) { --_current_news; @@ -757,28 +759,38 @@ static void MoveToNextNewsItem() /** Delete a news item from the queue */ static std::list::iterator DeleteNewsItem(std::list::iterator ni) { - if (_forced_news == ni || _current_news == ni) { - /* When we're the current news, go to the previous item first; - * we just possibly made that the last news item. */ - if (_current_news == ni) _current_news = (_current_news == std::begin(_news)) ? std::end(_news) : std::prev(_current_news); + bool updateCurrentNews = (_forced_news == ni || _current_news == ni); + bool updateStatusbarNews = (_statusbar_news == ni); + if (updateCurrentNews) { + /* When we're the current news, go to the next older item first; + * we just possibly made that the last news item. */ + if (_current_news == ni) ++_current_news; + if (_forced_news == ni) _forced_news = std::end(_news); + } + + if (updateStatusbarNews) { + /* When we're the current news, go to the next older item first; + * we just possibly made that the last news item. */ + ++_statusbar_news; + } + + /* Delete the news from the news queue. */ + ni = _news.erase(ni); + + if (updateCurrentNews) { /* About to remove the currently forced item (shown as newspapers) || * about to remove the currently displayed item (newspapers) */ MoveToNextNewsItem(); } - if (_statusbar_news == ni) { - /* When we're the current news, go to the previous item first; - * we just possibly made that the last news item. */ - if (_statusbar_news == ni) _statusbar_news = (_statusbar_news == std::begin(_news)) ? std::end(_news) : std::prev(_statusbar_news); - + if (updateStatusbarNews) { /* About to remove the currently displayed item (ticker, or just a reminder) */ InvalidateWindowData(WC_STATUS_BAR, 0, SBI_NEWS_DELETED); // invalidate the statusbar MoveToNextTickerItem(); } - /* Delete the news from the news queue. */ - return _news.erase(ni); + return ni; } /** @@ -1025,7 +1037,7 @@ static void ShowNewsMessage(NewsIterator ni) */ bool HideActiveNewsMessage() { - NewsWindow *w = (NewsWindow*)FindWindowById(WC_NEWS_WINDOW, 0); + NewsWindow *w = dynamic_cast(FindWindowById(WC_NEWS_WINDOW, 0)); if (w == nullptr) return false; w->Close(); return true; @@ -1107,19 +1119,19 @@ struct MessageHistoryWindow : Window { this->OnInvalidateData(0); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { if (widget == WID_MH_BACKGROUND) { this->line_height = GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal; - resize->height = this->line_height; + resize.height = this->line_height; /* Months are off-by-one, so it's actually 8. Not using * month 12 because the 1 is usually less wide. */ SetDParam(0, CalTime::ConvertYMDToDate(CalTime::ORIGINAL_MAX_YEAR, 7, 30)); this->date_width = GetStringBoundingBox(STR_JUST_DATE_TINY).width + WidgetDimensions::scaled.hsep_wide; - size->height = 4 * resize->height + WidgetDimensions::scaled.framerect.Vertical(); // At least 4 lines are visible. - size->width = std::max(200u, size->width); // At least 200 pixels wide. + size.height = 4 * resize.height + WidgetDimensions::scaled.framerect.Vertical(); // At least 4 lines are visible. + size.width = std::max(200u, size.width); // At least 200 pixels wide. } } diff --git a/src/object_gui.cpp b/src/object_gui.cpp index 25fb51f343..67c18ed81c 100644 --- a/src/object_gui.cpp +++ b/src/object_gui.cpp @@ -210,25 +210,25 @@ public: this->object_margin = ScaleGUITrad(4); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_BO_CLASS_LIST: { for (auto object_class_id : this->object_classes) { ObjectClass *objclass = ObjectClass::Get(object_class_id); if (objclass->GetUISpecCount() == 0) continue; - size->width = std::max(size->width, GetStringBoundingBox(objclass->name).width + padding.width); + size.width = std::max(size.width, GetStringBoundingBox(objclass->name).width + padding.width); } this->line_height = GetCharacterHeight(FS_NORMAL) + padding.height; - resize->height = this->line_height; - size->height = 5 * this->line_height; + resize.height = this->line_height; + size.height = 5 * this->line_height; break; } case WID_BO_OBJECT_NAME: case WID_BO_OBJECT_SIZE: /* We do not want the window to resize when selecting objects; better clip texts */ - size->width = 0; + size.width = 0; break; case WID_BO_OBJECT_MATRIX: { @@ -236,11 +236,11 @@ public: ObjectClass *objclass = ObjectClass::Get(_selected_object_class); const ObjectSpec *spec = objclass->GetSpec(_selected_object_index); if (spec != nullptr) { - if (spec->views >= 2) size->width += resize->width; - if (spec->views >= 4) size->height += resize->height; + if (spec->views >= 2) size.width += resize.width; + if (spec->views >= 4) size.height += resize.height; } - resize->width = 0; - resize->height = 0; + resize.width = 0; + resize.height = 0; break; } @@ -265,37 +265,37 @@ public: * we want these columns to be slightly less wide. When there are two rows, then * determine the size of the widgets based on the maximum size for a single row * of widgets, or just the twice the widget height of the two row ones. */ - size->height = std::max(height[0], height[1] * 2); + size.height = std::max(height[0], height[1] * 2); if (two_wide) { - size->width = (3 * ScaleGUITrad(TILE_PIXELS) + 2 * this->object_margin) * 2; + size.width = (3 * ScaleGUITrad(TILE_PIXELS) + 2 * this->object_margin) * 2; } else { - size->width = 4 * ScaleGUITrad(TILE_PIXELS) + 2 * this->object_margin; + size.width = 4 * ScaleGUITrad(TILE_PIXELS) + 2 * this->object_margin; } /* Get the right size for the single widget based on the current spec. */ ObjectClass *objclass = ObjectClass::Get(_selected_object_class); const ObjectSpec *spec = objclass->GetSpec(_selected_object_index); if (spec != nullptr) { - if (spec->views <= 1) size->width += WidgetDimensions::scaled.hsep_normal; - if (spec->views <= 2) size->height += WidgetDimensions::scaled.vsep_normal; - if (spec->views >= 2) size->width /= 2; - if (spec->views >= 4) size->height /= 2; + if (spec->views <= 1) size.width += WidgetDimensions::scaled.hsep_normal; + if (spec->views <= 2) size.height += WidgetDimensions::scaled.vsep_normal; + if (spec->views >= 2) size.width /= 2; + if (spec->views >= 4) size.height /= 2; } break; } case WID_BO_INFO: - size->height = this->info_height; + size.height = this->info_height; break; case WID_BO_SELECT_MATRIX: - fill->height = 1; - resize->height = 1; + fill.height = 1; + resize.height = 1; break; case WID_BO_SELECT_IMAGE: - size->width = ScaleGUITrad(64) + WidgetDimensions::scaled.fullbevel.Horizontal(); - size->height = ScaleGUITrad(58) + WidgetDimensions::scaled.fullbevel.Vertical(); + size.width = ScaleGUITrad(64) + WidgetDimensions::scaled.fullbevel.Horizontal(); + size.height = ScaleGUITrad(58) + WidgetDimensions::scaled.fullbevel.Vertical(); break; default: break; diff --git a/src/order_gui.cpp b/src/order_gui.cpp index 8ffe71bfb4..c7d52bd105 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -187,19 +187,19 @@ public: this->Window::Close(); } - virtual void UpdateWidgetSize(WidgetID widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override + virtual void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override { if (widget == WID_CTO_HEADER) { - (*size).height = std::max((*size).height, (uint) GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.framerect.Vertical()); + size.height = std::max(size.height, (uint) GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.framerect.Vertical()); } else if (WID_CTO_CARGO_LABEL_FIRST <= widget && widget <= WID_CTO_CARGO_LABEL_LAST) { - (*size).width = std::max((*size).width, WidgetDimensions::scaled.framerect.left + this->CARGO_ICON_WIDTH + WidgetDimensions::scaled.framerect.Horizontal() + this->max_cargo_name_width + padding.width); - (*size).height = std::max((*size).height, (uint) GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.framerect.Vertical()); + size.width = std::max(size.width, WidgetDimensions::scaled.framerect.left + this->CARGO_ICON_WIDTH + WidgetDimensions::scaled.framerect.Horizontal() + this->max_cargo_name_width + padding.width); + size.height = std::max(size.height, (uint) GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.framerect.Vertical()); } else if ((WID_CTO_CARGO_DROPDOWN_FIRST <= widget && widget <= WID_CTO_CARGO_DROPDOWN_LAST) || widget == WID_CTO_SET_TO_ALL_DROPDOWN) { - (*size).width = std::max((*size).width, WidgetDimensions::scaled.dropdowntext.Horizontal() + this->max_cargo_dropdown_width + NWidgetLeaf::GetDropdownBoxDimension().width); - (*size).height = std::max((*size).height, (uint) WidgetDimensions::scaled.dropdowntext.Vertical() + GetCharacterHeight(FS_NORMAL)); + size.width = std::max(size.width, WidgetDimensions::scaled.dropdowntext.Horizontal() + this->max_cargo_dropdown_width + NWidgetLeaf::GetDropdownBoxDimension().width); + size.height = std::max(size.height, (uint) WidgetDimensions::scaled.dropdowntext.Vertical() + GetCharacterHeight(FS_NORMAL)); } else if (widget == WID_CTO_SET_TO_ALL_LABEL) { - (*size).width = std::max((*size).width, this->max_cargo_name_width + WidgetDimensions::scaled.framerect.right + padding.width); - (*size).height = std::max((*size).height, (uint) GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.framerect.Vertical()); + size.width = std::max(size.width, this->max_cargo_name_width + WidgetDimensions::scaled.framerect.right + padding.width); + size.height = std::max(size.height, (uint) GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.framerect.Vertical()); } } @@ -1972,18 +1972,18 @@ public: this->GeneralVehicleWindow::Close(); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_O_OCCUPANCY_LIST: SetDParamMaxValue(0, 100); - size->width = GetStringBoundingBox(STR_ORDERS_OCCUPANCY_PERCENT).width + 10 + WidgetDimensions::unscaled.framerect.Horizontal(); + size.width = GetStringBoundingBox(STR_ORDERS_OCCUPANCY_PERCENT).width + 10 + WidgetDimensions::unscaled.framerect.Horizontal(); /* FALL THROUGH */ case WID_O_SEL_OCCUPANCY: case WID_O_ORDER_LIST: - resize->height = GetCharacterHeight(FS_NORMAL); - size->height = 6 * resize->height + padding.height; + resize.height = GetCharacterHeight(FS_NORMAL); + size.height = 6 * resize.height + padding.height; break; case WID_O_COND_VARIABLE: { @@ -1996,7 +1996,7 @@ public: } d.width += padding.width; d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } @@ -2007,13 +2007,13 @@ public: } d.width += padding.width; d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } case WID_O_OCCUPANCY_TOGGLE: SetDParamMaxValue(0, 100); - size->width = GetStringBoundingBox(STR_ORDERS_OCCUPANCY_PERCENT).width + 10 + WidgetDimensions::unscaled.framerect.Horizontal(); + size.width = GetStringBoundingBox(STR_ORDERS_OCCUPANCY_PERCENT).width + 10 + WidgetDimensions::unscaled.framerect.Horizontal(); break; case WID_O_TIMETABLE_VIEW: { @@ -2023,13 +2023,13 @@ public: d.height = std::max(d.height, spr_d.height); d.width += padding.width; d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } case WID_O_SHARED_ORDER_LIST: case WID_O_ADD_VEH_GROUP: - size->width = std::max(size->width, NWidgetLeaf::GetResizeBoxDimension().width); + size.width = std::max(size.width, NWidgetLeaf::GetResizeBoxDimension().width); break; } } diff --git a/src/plans_gui.cpp b/src/plans_gui.cpp index ea15bb18f6..2ad495de51 100644 --- a/src/plans_gui.cpp +++ b/src/plans_gui.cpp @@ -349,25 +349,25 @@ struct PlansWindow : Window { this->vscroll->SetCapacityFromWidget(this, WID_PLN_LIST, WidgetDimensions::scaled.framerect.Vertical()); } - virtual void UpdateWidgetSize(WidgetID widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override + virtual void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override { switch (widget) { case WID_PLN_LIST: this->company_icon_spr_dim = GetSpriteSize(SPR_COMPANY_ICON); - resize->height = std::max(GetCharacterHeight(FS_NORMAL), SETTING_BUTTON_HEIGHT); - size->height = resize->height * 5 + WidgetDimensions::scaled.framerect.Vertical(); + resize.height = std::max(GetCharacterHeight(FS_NORMAL), SETTING_BUTTON_HEIGHT); + size.height = resize.height * 5 + WidgetDimensions::scaled.framerect.Vertical(); break; case WID_PLN_NEW: - *size = adddim(maxdim(GetStringBoundingBox(STR_PLANS_NEW_PLAN), GetStringBoundingBox(STR_PLANS_ADDING_LINES)), padding); + size = adddim(maxdim(GetStringBoundingBox(STR_PLANS_NEW_PLAN), GetStringBoundingBox(STR_PLANS_ADDING_LINES)), padding); break; case WID_PLN_ADD_LINES: - *size = adddim(GetStringBoundingBox(STR_PLANS_ADD_LINES), padding); + size = adddim(GetStringBoundingBox(STR_PLANS_ADD_LINES), padding); break; case WID_PLN_VISIBILITY: - *size = adddim(maxdim(GetStringBoundingBox(STR_PLANS_VISIBILITY_PRIVATE), GetStringBoundingBox(STR_PLANS_VISIBILITY_PUBLIC)), padding); + size = adddim(maxdim(GetStringBoundingBox(STR_PLANS_VISIBILITY_PRIVATE), GetStringBoundingBox(STR_PLANS_VISIBILITY_PUBLIC)), padding); break; case WID_PLN_COLOUR: { @@ -375,20 +375,20 @@ struct PlansWindow : Window { for (uint8_t colour = COLOUR_BEGIN; colour != COLOUR_END; ++colour) { dim = maxdim(dim, GetStringBoundingBox(STR_COLOUR_DARK_BLUE + colour)); } - *size = adddim(dim, padding); + size = adddim(dim, padding); break; } case WID_PLN_DELETE: - *size = adddim(GetStringBoundingBox(STR_PLANS_DELETE), padding); + size = adddim(GetStringBoundingBox(STR_PLANS_DELETE), padding); break; case WID_PLN_RENAME: - *size = adddim(GetStringBoundingBox(STR_BUTTON_RENAME), padding); + size = adddim(GetStringBoundingBox(STR_BUTTON_RENAME), padding); break; case WID_PLN_TAKE_OWNERSHIP: - *size = adddim(GetStringBoundingBox(STR_PLANS_TAKE_OWNERSHIP), padding); + size = adddim(GetStringBoundingBox(STR_PLANS_TAKE_OWNERSHIP), padding); break; } } diff --git a/src/programmable_signals_gui.cpp b/src/programmable_signals_gui.cpp index 508eac943e..a12121f44a 100644 --- a/src/programmable_signals_gui.cpp +++ b/src/programmable_signals_gui.cpp @@ -600,12 +600,12 @@ public: } } - virtual void UpdateWidgetSize(WidgetID widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override + virtual void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override { switch (widget) { case PROGRAM_WIDGET_INSTRUCTION_LIST: - resize->height = GetCharacterHeight(FS_NORMAL); - size->height = 6 * resize->height + WidgetDimensions::scaled.framerect.Vertical(); + resize.height = GetCharacterHeight(FS_NORMAL); + size.height = 6 * resize.height + WidgetDimensions::scaled.framerect.Vertical(); break; } } diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp index 5a6a260cc2..d1aab76897 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -1454,7 +1454,7 @@ public: } } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_BRAS_NEWST_LIST: { @@ -1462,17 +1462,17 @@ public: for (auto station_class : this->station_classes) { d = maxdim(d, GetStringBoundingBox(StationClass::Get(station_class)->name)); } - size->width = std::max(size->width, d.width + padding.width); + size.width = std::max(size.width, d.width + padding.width); this->line_height = GetCharacterHeight(FS_NORMAL) + padding.height; - size->height = 5 * this->line_height; - resize->height = this->line_height; + size.height = 5 * this->line_height; + resize.height = this->line_height; break; } case WID_BRAS_SHOW_NEWST_TYPE: { if (!_railstation.newstations) { - size->width = 0; - size->height = 0; + size.width = 0; + size.height = 0; break; } @@ -1487,25 +1487,25 @@ public: d = maxdim(d, GetStringBoundingBox(str)); } } - size->width = std::max(size->width, d.width + padding.width); - size->width = std::min(size->width, ScaleGUITrad(400)); + size.width = std::max(size.width, d.width + padding.width); + size.width = std::min(size.width, ScaleGUITrad(400)); break; } case WID_BRAS_PLATFORM_DIR_X: case WID_BRAS_PLATFORM_DIR_Y: case WID_BRAS_IMAGE: - size->width = ScaleGUITrad(64) + WidgetDimensions::scaled.fullbevel.Horizontal(); - size->height = ScaleGUITrad(58) + WidgetDimensions::scaled.fullbevel.Vertical(); + size.width = ScaleGUITrad(64) + WidgetDimensions::scaled.fullbevel.Horizontal(); + size.height = ScaleGUITrad(58) + WidgetDimensions::scaled.fullbevel.Vertical(); break; case WID_BRAS_COVERAGE_TEXTS: - size->height = this->coverage_height; + size.height = this->coverage_height; break; case WID_BRAS_MATRIX: - fill->height = 1; - resize->height = 1; + fill.height = 1; + resize.height = 1; break; } } @@ -2056,16 +2056,16 @@ public: } } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { if (widget == WID_BS_DRAG_SIGNALS_DENSITY_LABEL) { /* Two digits for signals density. */ - size->width = std::max(size->width, 2 * GetDigitWidth() + padding.width + WidgetDimensions::scaled.framerect.Horizontal()); + size.width = std::max(size.width, 2 * GetDigitWidth() + padding.width + WidgetDimensions::scaled.framerect.Horizontal()); } else if (IsInsideMM(widget, WID_BS_SEMAPHORE_NORM, WID_BS_ELECTRIC_PBS_OWAY + 1)) { - size->width = std::max(size->width, this->sig_sprite_size.width + padding.width); - size->height = std::max(size->height, this->sig_sprite_size.height + padding.height); + size.width = std::max(size.width, this->sig_sprite_size.width + padding.width); + size.height = std::max(size.height, this->sig_sprite_size.height + padding.height); } else if (widget == WID_BS_CAPTION) { - size->width += WidgetDimensions::scaled.frametext.Horizontal(); + size.width += WidgetDimensions::scaled.frametext.Horizontal(); } } @@ -2399,12 +2399,12 @@ struct BuildRailDepotWindow : public PickerWindowBase { this->LowerWidget(WID_BRAD_DEPOT_NE + _build_depot_direction); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { if (!IsInsideMM(widget, WID_BRAD_DEPOT_NE, WID_BRAD_DEPOT_NW + 1)) return; - size->width = ScaleGUITrad(64) + WidgetDimensions::scaled.fullbevel.Horizontal(); - size->height = ScaleGUITrad(48) + WidgetDimensions::scaled.fullbevel.Vertical(); + size.width = ScaleGUITrad(64) + WidgetDimensions::scaled.fullbevel.Horizontal(); + size.height = ScaleGUITrad(48) + WidgetDimensions::scaled.fullbevel.Vertical(); } void DrawWidget(const Rect &r, WidgetID widget) const override @@ -2554,21 +2554,21 @@ struct BuildRailWaypointWindow : PickerWindowBase { this->PickerWindowBase::Close(data); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_BRW_WAYPOINT_MATRIX: /* Two blobs high and three wide. */ - size->width += resize->width * 2; - size->height += resize->height * 1; + size.width += resize.width * 2; + size.height += resize.height * 1; /* Resizing in X direction only at blob size, but at pixel level in Y. */ - resize->height = 1; + resize.height = 1; break; case WID_BRW_WAYPOINT: - size->width = ScaleGUITrad(64) + WidgetDimensions::scaled.fullbevel.Horizontal(); - size->height = ScaleGUITrad(58) + WidgetDimensions::scaled.fullbevel.Vertical(); + size.width = ScaleGUITrad(64) + WidgetDimensions::scaled.fullbevel.Horizontal(); + size.height = ScaleGUITrad(58) + WidgetDimensions::scaled.fullbevel.Vertical(); break; } } diff --git a/src/road_gui.cpp b/src/road_gui.cpp index 663da869a4..48eaffbf93 100644 --- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -1145,12 +1145,12 @@ struct BuildRoadDepotWindow : public PickerWindowBase { this->FinishInitNested(TRANSPORT_ROAD); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { if (!IsInsideMM(widget, WID_BROD_DEPOT_NE, WID_BROD_DEPOT_NW + 1)) return; - size->width = ScaleGUITrad(64) + WidgetDimensions::scaled.fullbevel.Horizontal(); - size->height = ScaleGUITrad(48) + WidgetDimensions::scaled.fullbevel.Vertical(); + size.width = ScaleGUITrad(64) + WidgetDimensions::scaled.fullbevel.Horizontal(); + size.height = ScaleGUITrad(48) + WidgetDimensions::scaled.fullbevel.Vertical(); } void DrawWidget(const Rect &r, WidgetID widget) const override @@ -1516,7 +1516,7 @@ public: } } - void UpdateWidgetSize(WidgetID widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_BROS_NEWST_LIST: { @@ -1524,10 +1524,10 @@ public: for (auto rs_class : this->roadstop_classes) { d = maxdim(d, GetStringBoundingBox(RoadStopClass::Get(rs_class)->name)); } - size->width = std::max(size->width, d.width + padding.width); + size.width = std::max(size.width, d.width + padding.width); this->line_height = GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.matrix.Vertical(); - size->height = 5 * this->line_height; - resize->height = this->line_height; + size.height = 5 * this->line_height; + resize.height = this->line_height; break; } @@ -1542,7 +1542,7 @@ public: d = maxdim(d, GetStringBoundingBox(str)); } } - size->width = std::max(size->width, d.width + padding.width); + size.width = std::max(size.width, d.width + padding.width); break; } @@ -1552,22 +1552,22 @@ public: case WID_BROS_STATION_NW: case WID_BROS_STATION_X: case WID_BROS_STATION_Y: - size->width = ScaleGUITrad(64) + WidgetDimensions::scaled.fullbevel.Horizontal(); - size->height = ScaleGUITrad(32 + (this->building_height * 8)) + WidgetDimensions::scaled.fullbevel.Vertical(); + size.width = ScaleGUITrad(64) + WidgetDimensions::scaled.fullbevel.Horizontal(); + size.height = ScaleGUITrad(32 + (this->building_height * 8)) + WidgetDimensions::scaled.fullbevel.Vertical(); break; case WID_BROS_IMAGE: - size->width = ScaleGUITrad(64) + WidgetDimensions::scaled.fullbevel.Horizontal(); - size->height = ScaleGUITrad(48) + WidgetDimensions::scaled.fullbevel.Vertical(); + size.width = ScaleGUITrad(64) + WidgetDimensions::scaled.fullbevel.Horizontal(); + size.height = ScaleGUITrad(48) + WidgetDimensions::scaled.fullbevel.Vertical(); break; case WID_BROS_MATRIX: - fill->height = 1; - resize->height = 1; + fill.height = 1; + resize.height = 1; break; case WID_BROS_ACCEPTANCE: - size->height = this->coverage_height; + size.height = this->coverage_height; break; } } @@ -2053,21 +2053,21 @@ struct BuildRoadWaypointWindow : PickerWindowBase { this->PickerWindowBase::Close(); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override { switch (widget) { case WID_BROW_WAYPOINT_MATRIX: /* Two blobs high and three wide. */ - size->width += resize->width * 2; - size->height += resize->height * 1; + size.width += resize.width * 2; + size.height += resize.height * 1; /* Resizing in X direction only at blob size, but at pixel level in Y. */ - resize->height = 1; + resize.height = 1; break; case WID_BROW_WAYPOINT: - size->width = ScaleGUITrad(64) + 2; - size->height = ScaleGUITrad(58) + 2; + size.width = ScaleGUITrad(64) + 2; + size.height = ScaleGUITrad(58) + 2; break; } } diff --git a/src/schdispatch_gui.cpp b/src/schdispatch_gui.cpp index d9d80fce07..7b853b4006 100644 --- a/src/schdispatch_gui.cpp +++ b/src/schdispatch_gui.cpp @@ -281,7 +281,7 @@ struct SchdispatchWindow : GeneralVehicleWindow { return nullptr; } - virtual void UpdateWidgetSize(WidgetID widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override + virtual void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override { switch (widget) { case WID_SCHDISPATCH_MATRIX: { @@ -303,22 +303,22 @@ struct SchdispatchWindow : GeneralVehicleWindow { this->header_width = std::max(this->delete_flag_width, this->arrow_flag_width); this->base_width = unumber.width + this->header_width + 4; - resize->height = min_height; - resize->width = base_width + WidgetDimensions::scaled.framerect.left + WidgetDimensions::scaled.framerect.right; - size->width = resize->width * 3; - size->height = resize->height * 3; + resize.height = min_height; + resize.width = base_width + WidgetDimensions::scaled.framerect.left + WidgetDimensions::scaled.framerect.right; + size.width = resize.width * 3; + size.height = resize.height * 3; - fill->width = resize->width; - fill->height = resize->height; + fill.width = resize.width; + fill.height = resize.height; break; } case WID_SCHDISPATCH_SUMMARY_PANEL: - size->height = (5 + this->extra_line_count) * GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.framerect.Vertical() + (WidgetDimensions::scaled.vsep_wide * 2); + size.height = (5 + this->extra_line_count) * GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.framerect.Vertical() + (WidgetDimensions::scaled.vsep_wide * 2); uint warning_count = this->warning_count; if (warning_count > 0) { const Dimension warning_dimensions = GetSpriteSize(SPR_WARNING_SIGN); - size->height += warning_count * std::max(warning_dimensions.height, GetCharacterHeight(FS_NORMAL)); + size.height += warning_count * std::max(warning_dimensions.height, GetCharacterHeight(FS_NORMAL)); } break; } @@ -1461,7 +1461,7 @@ struct ScheduledDispatchAddSlotsWindow : Window { return pt; } - virtual void UpdateWidgetSize(WidgetID widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override + virtual void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override { Dimension d = {0, 0}; switch (widget) { @@ -1496,7 +1496,7 @@ struct ScheduledDispatchAddSlotsWindow : Window { d.width += padding.width; d.height += padding.height; - *size = d; + size = d; } virtual void SetStringParameters(WidgetID widget) const override diff --git a/src/screenshot_gui.cpp b/src/screenshot_gui.cpp index 484d2ffdaa..8e4348f826 100644 --- a/src/screenshot_gui.cpp +++ b/src/screenshot_gui.cpp @@ -84,7 +84,7 @@ void ShowScreenshotWindow() void SetScreenshotWindowHidden(bool hidden) { - ScreenshotWindow *scw = (ScreenshotWindow *) FindWindowById(WC_SCREENSHOT, 0); + ScreenshotWindow *scw = dynamic_cast(FindWindowById(WC_SCREENSHOT, 0)); if (scw != nullptr) { if (hidden) { scw->SetDirtyAsBlocks(); diff --git a/src/script/script_gui.cpp b/src/script/script_gui.cpp index a7469a6f07..90f7d16826 100644 --- a/src/script/script_gui.cpp +++ b/src/script/script_gui.cpp @@ -105,15 +105,15 @@ struct ScriptListWindow : public Window { SetDParam(0, (this->slot == OWNER_DEITY) ? STR_AI_LIST_CAPTION_GAMESCRIPT : STR_AI_LIST_CAPTION_AI); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { if (widget != WID_SCRL_LIST) return; this->line_height = GetCharacterHeight(FS_NORMAL) + padding.height; - resize->width = 1; - resize->height = this->line_height; - size->height = 5 * this->line_height; + resize.width = 1; + resize.height = this->line_height; + size.height = 5 * this->line_height; } void DrawWidget(const Rect &r, WidgetID widget) const override @@ -357,15 +357,15 @@ struct ScriptSettingsWindow : public Window { SetDParam(0, (this->slot == OWNER_DEITY) ? STR_AI_SETTINGS_CAPTION_GAMESCRIPT : STR_AI_SETTINGS_CAPTION_AI); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { if (widget != WID_SCRS_BACKGROUND) return; this->line_height = std::max(SETTING_BUTTON_HEIGHT, GetCharacterHeight(FS_NORMAL)) + padding.height; - resize->width = 1; - resize->height = this->line_height; - size->height = 5 * this->line_height; + resize.width = 1; + resize.height = this->line_height; + size.height = 5 * this->line_height; } void DrawWidget(const Rect &r, WidgetID widget) const override @@ -841,11 +841,11 @@ struct ScriptDebugWindow : public Window { ScriptDebugWindow::initial_state = this->filter; } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { if (widget == WID_SCRD_LOG_PANEL) { - resize->height = GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal; - size->height = 14 * resize->height + WidgetDimensions::scaled.framerect.Vertical(); + resize.height = GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal; + size.height = 14 * resize.height + WidgetDimensions::scaled.framerect.Vertical(); } } diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index d7ab516cd3..0af0cc679e 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -195,7 +195,7 @@ static const std::map _volume_labels = { { 127, STR_GAME_OPTIONS_VOLUME_100 }, }; -static const NWidgetPart _nested_social_plugins_widgets[] = { +static constexpr NWidgetPart _nested_social_plugins_widgets[] = { NWidget(NWID_HORIZONTAL), NWidget(WWT_FRAME, COLOUR_GREY, WID_GO_SOCIAL_PLUGIN_TITLE), SetDataTip(STR_JUST_STRING2, STR_NULL), NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0), @@ -210,7 +210,7 @@ static const NWidgetPart _nested_social_plugins_widgets[] = { EndContainer(), }; -static const NWidgetPart _nested_social_plugins_none_widgets[] = { +static constexpr NWidgetPart _nested_social_plugins_none_widgets[] = { NWidget(NWID_HORIZONTAL), NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_SOCIAL_PLUGINS_NONE, STR_NULL), EndContainer(), @@ -669,7 +669,7 @@ struct GameOptionsWindow : Window { if (changed) this->ReInit(0, 0, this->flags & WF_CENTERED); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_GO_TEXT_SFX_VOLUME: @@ -677,7 +677,7 @@ struct GameOptionsWindow : Window { Dimension d = maxdim(GetStringBoundingBox(STR_GAME_OPTIONS_SFX_VOLUME), GetStringBoundingBox(STR_GAME_OPTIONS_MUSIC_VOLUME)); d.width += padding.width; d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } @@ -690,7 +690,7 @@ struct GameOptionsWindow : Window { case WID_GO_BASE_SFX_DROPDOWN: case WID_GO_BASE_MUSIC_DROPDOWN: { int selected; - size->width = std::max(size->width, GetDropDownListDimension(this->BuildDropDownList(widget, &selected)).width + padding.width); + size.width = std::max(size.width, GetDropDownListDimension(this->BuildDropDownList(widget, &selected)).width + padding.width); break; } } @@ -2846,14 +2846,14 @@ struct GameSettingsWindow : Window { _circle_size = maxdim(GetSpriteSize(SPR_CIRCLE_FOLDED), GetSpriteSize(SPR_CIRCLE_UNFOLDED)); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_GS_OPTIONSPANEL: - resize->height = SETTING_HEIGHT = std::max({(int)_circle_size.height, SETTING_BUTTON_HEIGHT, GetCharacterHeight(FS_NORMAL)}) + WidgetDimensions::scaled.vsep_normal; - resize->width = 1; + resize.height = SETTING_HEIGHT = std::max({(int)_circle_size.height, SETTING_BUTTON_HEIGHT, GetCharacterHeight(FS_NORMAL)}) + WidgetDimensions::scaled.vsep_normal; + resize.width = 1; - size->height = 5 * resize->height + WidgetDimensions::scaled.framerect.Vertical(); + size.height = 5 * resize.height + WidgetDimensions::scaled.framerect.Vertical(); break; case WID_GS_HELP_TEXT: { @@ -2864,16 +2864,16 @@ struct GameSettingsWindow : Window { }; for (uint i = 0; i < lengthof(setting_types); i++) { SetDParam(0, setting_types[i]); - size->width = std::max(size->width, GetStringBoundingBox(STR_CONFIG_SETTING_TYPE).width + padding.width); + size.width = std::max(size.width, GetStringBoundingBox(STR_CONFIG_SETTING_TYPE).width + padding.width); } - size->height = 2 * GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal + - std::max(size->height, GetSettingsTree().GetMaxHelpHeight(size->width)); + size.height = 2 * GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal + + std::max(size.height, GetSettingsTree().GetMaxHelpHeight(size.width)); break; } case WID_GS_RESTRICT_CATEGORY: case WID_GS_RESTRICT_TYPE: - size->width = std::max(GetStringBoundingBox(STR_CONFIG_SETTING_RESTRICT_CATEGORY).width, GetStringBoundingBox(STR_CONFIG_SETTING_RESTRICT_TYPE).width); + size.width = std::max(GetStringBoundingBox(STR_CONFIG_SETTING_RESTRICT_CATEGORY).width, GetStringBoundingBox(STR_CONFIG_SETTING_RESTRICT_TYPE).width); break; default: @@ -3551,7 +3551,7 @@ struct CustomCurrencyWindow : Window { } } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { /* Set the appropriate width for the up/down buttons. */ @@ -3559,21 +3559,21 @@ struct CustomCurrencyWindow : Window { case WID_CC_RATE_UP: case WID_CC_YEAR_DOWN: case WID_CC_YEAR_UP: - *size = maxdim(*size, {(uint)SETTING_BUTTON_WIDTH / 2, (uint)SETTING_BUTTON_HEIGHT}); + size = maxdim(size, {(uint)SETTING_BUTTON_WIDTH / 2, (uint)SETTING_BUTTON_HEIGHT}); break; /* Set the appropriate width for the edit buttons. */ case WID_CC_SEPARATOR_EDIT: case WID_CC_PREFIX_EDIT: case WID_CC_SUFFIX_EDIT: - *size = maxdim(*size, {(uint)SETTING_BUTTON_WIDTH, (uint)SETTING_BUTTON_HEIGHT}); + size = maxdim(size, {(uint)SETTING_BUTTON_WIDTH, (uint)SETTING_BUTTON_HEIGHT}); break; /* Make sure the window is wide enough for the widest exchange rate */ case WID_CC_RATE: SetDParam(0, 1); SetDParam(1, INT32_MAX); - *size = GetStringBoundingBox(STR_CURRENCY_EXCHANGE_RATE); + size = GetStringBoundingBox(STR_CURRENCY_EXCHANGE_RATE); break; } } diff --git a/src/signs_gui.cpp b/src/signs_gui.cpp index 208f2e239b..095e1d8e59 100644 --- a/src/signs_gui.cpp +++ b/src/signs_gui.cpp @@ -260,23 +260,23 @@ struct SignListWindow : Window, SignList { this->vscroll->SetCapacityFromWidget(this, WID_SIL_LIST, WidgetDimensions::scaled.framerect.Vertical()); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_SIL_LIST: { Dimension spr_dim = GetSpriteSize(SPR_COMPANY_ICON); this->text_offset = WidgetDimensions::scaled.frametext.left + spr_dim.width + 2; // 2 pixels space between icon and the sign text. - resize->height = std::max(GetCharacterHeight(FS_NORMAL), spr_dim.height + 2); - Dimension d = {(uint)(this->text_offset + WidgetDimensions::scaled.frametext.right), padding.height + 5 * resize->height}; - *size = maxdim(*size, d); + resize.height = std::max(GetCharacterHeight(FS_NORMAL), spr_dim.height + 2); + Dimension d = {(uint)(this->text_offset + WidgetDimensions::scaled.frametext.right), padding.height + 5 * resize.height}; + size = maxdim(size, d); break; } case WID_SIL_CAPTION: SetDParamMaxValue(0, Sign::GetPoolSize(), 3); - *size = GetStringBoundingBox(STR_SIGN_LIST_CAPTION); - size->height += padding.height; - size->width += padding.width; + size = GetStringBoundingBox(STR_SIGN_LIST_CAPTION); + size.height += padding.height; + size.width += padding.width; break; } } diff --git a/src/spritecache.cpp b/src/spritecache.cpp index 28f47b22cf..a869171f6f 100644 --- a/src/spritecache.cpp +++ b/src/spritecache.cpp @@ -76,6 +76,15 @@ static SpriteFile *GetCachedSpriteFileByName(const std::string &filename) return nullptr; } +/** + * Get the list of cached SpriteFiles. + * @return Read-only list of cache SpriteFiles. + */ +std::span> GetCachedSpriteFiles() +{ + return _sprite_files; +} + /** * Open/get the SpriteFile that is cached for use in the sprite cache. * @param filename Name of the file at the disk. diff --git a/src/spritecache.h b/src/spritecache.h index caa7e22619..32ce13418f 100644 --- a/src/spritecache.h +++ b/src/spritecache.h @@ -70,6 +70,7 @@ void GfxClearFontSpriteCache(); void IncreaseSpriteLRU(); SpriteFile &OpenCachedSpriteFile(const std::string &filename, Subdirectory subdir, bool palette_remap); +std::span> GetCachedSpriteFiles(); void ReadGRFSpriteOffsets(SpriteFile &file); size_t GetGRFSpriteOffset(uint32_t id); diff --git a/src/station_gui.cpp b/src/station_gui.cpp index 97ea9696c6..dcedc223cc 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -513,14 +513,14 @@ public: this->Window::Close(data); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_STL_SORTBY: { Dimension d = GetStringBoundingBox(this->GetWidget(widget)->widget_data); d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better. d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } @@ -531,13 +531,13 @@ public: } d.width += padding.width; d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } case WID_STL_LIST: - resize->height = std::max(GetCharacterHeight(FS_NORMAL), GetCharacterHeight(FS_SMALL) + ScaleGUITrad(3)); - size->height = padding.height + 5 * resize->height; + resize.height = std::max(GetCharacterHeight(FS_NORMAL), GetCharacterHeight(FS_SMALL) + ScaleGUITrad(3)); + size.height = padding.height + 5 * resize.height; /* Determine appropriate width for mini station rating graph */ this->rating_width = 0; @@ -1514,25 +1514,25 @@ struct StationViewWindow : public Window { data->Update(count); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_SV_WAITING: - resize->height = GetCharacterHeight(FS_NORMAL); - size->height = 4 * resize->height + padding.height; + resize.height = GetCharacterHeight(FS_NORMAL); + size.height = 4 * resize.height + padding.height; this->expand_shrink_width = std::max(GetStringBoundingBox("-").width, GetStringBoundingBox("+").width); break; case WID_SV_ACCEPT_RATING_LIST: - size->height = ((this->GetWidget(WID_SV_ACCEPTS_RATINGS)->widget_data == STR_STATION_VIEW_RATINGS_BUTTON) ? this->accepts_lines : this->rating_lines) * GetCharacterHeight(FS_NORMAL) + padding.height; + size.height = ((this->GetWidget(WID_SV_ACCEPTS_RATINGS)->widget_data == STR_STATION_VIEW_RATINGS_BUTTON) ? this->accepts_lines : this->rating_lines) * GetCharacterHeight(FS_NORMAL) + padding.height; break; case WID_SV_CLOSE_AIRPORT: if (!(Station::Get(this->window_number)->facilities & FACIL_AIRPORT)) { /* Hide 'Close Airport' button if no airport present. */ - size->width = 0; - resize->width = 0; - fill->width = 0; + size.width = 0; + resize.width = 0; + fill.width = 0; } break; @@ -1545,7 +1545,7 @@ struct StationViewWindow : public Window { for (const StringID *str = _sort_names; *str != INVALID_STRING_ID; str++) { width = std::max(width, GetStringBoundingBox(*str).width); } - size->width = width + padding.width; + size.width = width + padding.width; break; } } @@ -2572,7 +2572,7 @@ struct SelectStationWindow : Window { this->Window::Close(); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { if (widget != WID_JS_PANEL) return; @@ -2585,11 +2585,11 @@ struct SelectStationWindow : Window { d = maxdim(d, GetStringBoundingBox(T::EXPECTED_FACIL == FACIL_WAYPOINT ? STR_STATION_LIST_WAYPOINT : STR_STATION_LIST_STATION)); } - resize->height = d.height; + resize.height = d.height; d.height *= 5; d.width += padding.width; d.height += padding.height; - *size = d; + size = d; } void DrawWidget(const Rect &r, WidgetID widget) const override @@ -3059,11 +3059,11 @@ public: this->data[line_nr][0] = '\0'; } - void UpdateWidgetSize(WidgetID widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override { if (widget != 0) return; - size->height = WidgetDimensions::scaled.framerect.Vertical() + 2; + size.height = WidgetDimensions::scaled.framerect.Vertical() + 2; for (uint i = 0; i <= RATING_TOOLTIP_MAX_LINES; i++) { if (this->data[i].empty()) break; @@ -3072,11 +3072,11 @@ public: if (this->newgrf_rating_used && i >= 2 && i <= 4) { width += RATING_TOOLTIP_NEWGRF_INDENT; } - size->width = std::max(size->width, width); - size->height += GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal; + size.width = std::max(size.width, width); + size.height += GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal; } - size->height -= WidgetDimensions::scaled.vsep_normal; + size.height -= WidgetDimensions::scaled.vsep_normal; } void DrawWidget(const Rect &r, WidgetID widget) const override diff --git a/src/statusbar_gui.cpp b/src/statusbar_gui.cpp index 48e2874556..2fbd34b59b 100644 --- a/src/statusbar_gui.cpp +++ b/src/statusbar_gui.cpp @@ -112,7 +112,7 @@ struct StatusBarWindow : Window { } } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { Dimension d; switch (widget) { @@ -140,7 +140,7 @@ struct StatusBarWindow : Window { d.width += padding.width; d.height += padding.height; - *size = maxdim(d, *size); + size = maxdim(d, size); } void DrawWidget(const Rect &r, WidgetID widget) const override diff --git a/src/story_gui.cpp b/src/story_gui.cpp index 79291ad309..f77092822d 100644 --- a/src/story_gui.cpp +++ b/src/story_gui.cpp @@ -754,7 +754,7 @@ public: } } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { if (widget != WID_SB_SEL_PAGE && widget != WID_SB_PAGE_PANEL) return; @@ -783,14 +783,14 @@ public: d.width += padding.width; d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } case WID_SB_PAGE_PANEL: { d.height *= 5; d.height += padding.height + WidgetDimensions::scaled.frametext.Vertical(); - *size = maxdim(*size, d); + size = maxdim(size, d); break; } } diff --git a/src/strgen/strgen.cpp b/src/strgen/strgen.cpp index 1de2fdc83a..c1806c813f 100644 --- a/src/strgen/strgen.cpp +++ b/src/strgen/strgen.cpp @@ -532,25 +532,25 @@ int CDECL main(int argc, char *argv[]) switch (i) { case 'C': printf("args\tflags\tcommand\treplacement\n"); - for (const CmdStruct *cs = _cmd_structs; cs < endof(_cmd_structs); cs++) { + for (const auto &cs : _cmd_structs) { char flags; - if (cs->proc == EmitGender) { + if (cs.proc == EmitGender) { flags = 'g'; // Command needs number of parameters defined by number of genders - } else if (cs->proc == EmitPlural) { + } else if (cs.proc == EmitPlural) { flags = 'p'; // Command needs number of parameters defined by plural value - } else if (cs->flags & C_DONTCOUNT) { + } else if (cs.flags & C_DONTCOUNT) { flags = 'i'; // Command may be in the translation when it is not in base } else { flags = '0'; // Command needs no parameters } - printf("%i\t%c\t\"%s\"\t\"%s\"\n", cs->consumes, flags, cs->cmd, strstr(cs->cmd, "STRING") ? "STRING" : cs->cmd); + printf("%i\t%c\t\"%s\"\t\"%s\"\n", cs.consumes, flags, cs.cmd, strstr(cs.cmd, "STRING") ? "STRING" : cs.cmd); } return 0; case 'L': printf("count\tdescription\tnames\n"); - for (const PluralForm *pf = _plural_forms; pf < endof(_plural_forms); pf++) { - printf("%i\t\"%s\"\t%s\n", pf->plural_count, pf->description, pf->names); + for (const auto &pf : _plural_forms) { + printf("%i\t\"%s\"\t%s\n", pf.plural_count, pf.description, pf.names); } return 0; diff --git a/src/strgen/strgen_base.cpp b/src/strgen/strgen_base.cpp index e4eca51ab3..1863943460 100644 --- a/src/strgen/strgen_base.cpp +++ b/src/strgen/strgen_base.cpp @@ -416,8 +416,8 @@ void EmitGender(Buffer *buffer, char *buf, int) static const CmdStruct *FindCmd(const char *s, int len) { - for (const CmdStruct *cs = _cmd_structs; cs != endof(_cmd_structs); cs++) { - if (strncmp(cs->cmd, s, len) == 0 && cs->cmd[len] == '\0') return cs; + for (const auto &cs : _cmd_structs) { + if (strncmp(cs.cmd, s, len) == 0 && cs.cmd[len] == '\0') return &cs; } return nullptr; } diff --git a/src/subsidy_gui.cpp b/src/subsidy_gui.cpp index 9804ad3903..98cf1c4385 100644 --- a/src/subsidy_gui.cpp +++ b/src/subsidy_gui.cpp @@ -131,17 +131,17 @@ struct SubsidyListWindow : Window { return 3 + num_awarded + num_not_awarded; } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { if (widget != WID_SUL_PANEL) return; Dimension d = maxdim(GetStringBoundingBox(STR_SUBSIDIES_OFFERED_TITLE), GetStringBoundingBox(STR_SUBSIDIES_SUBSIDISED_TITLE)); - resize->height = GetCharacterHeight(FS_NORMAL); + resize.height = GetCharacterHeight(FS_NORMAL); d.height *= 5; d.width += WidgetDimensions::scaled.framerect.Horizontal(); d.height += WidgetDimensions::scaled.framerect.Vertical(); - *size = maxdim(*size, d); + size = maxdim(size, d); } void DrawCargoIcon(const Rect &r, int y_offset, CargoID cid) const diff --git a/src/table/newgrf_debug_data.h b/src/table/newgrf_debug_data.h index 1d0512e878..7790b1b8b6 100644 --- a/src/table/newgrf_debug_data.h +++ b/src/table/newgrf_debug_data.h @@ -1209,13 +1209,11 @@ class NIHIndustry : public NIHelper { return ro.GetScope(VSG_SCOPE_SELF)->GetVariable(var, param, extra); } - uint GetPSASize(uint index, uint32_t grfid) const override { return cpp_lengthof(PersistentStorage, storage); } - - const int32_t *GetPSAFirstPosition(uint index, uint32_t grfid) const override + const std::span GetPSA(uint index, uint32_t) const override { const Industry *i = (const Industry *)this->GetInstance(index); - if (i->psa == nullptr) return nullptr; - return (int32_t *)(&i->psa->storage); + if (i->psa == nullptr) return {}; + return i->psa->storage; } std::vector GetPSAGRFIDs(uint index) const override @@ -1927,13 +1925,11 @@ class NIHAirport : public NIHelper { return ro.GetScope(VSG_SCOPE_SELF)->GetVariable(var, param, extra); } - uint GetPSASize(uint, uint32_t) const override { return cpp_lengthof(PersistentStorage, storage); } - - const int32_t *GetPSAFirstPosition(uint index, uint32_t) const override + const std::span GetPSA(uint index, uint32_t) const override { const Station *st = (const Station *)this->GetInstance(index); - if (st->airport.psa == nullptr) return nullptr; - return (int32_t *)(&st->airport.psa->storage); + if (st->airport.psa == nullptr) return {}; + return st->airport.psa->storage; } }; @@ -1977,7 +1973,6 @@ class NIHTown : public NIHelper { void SetStringParameters(uint index) const override { this->SetSimpleStringParameters(STR_TOWN_NAME, index); } uint32_t GetGRFID(uint index) const override { return 0; } bool PSAWithParameter() const override { return true; } - uint GetPSASize(uint index, uint32_t grfid) const override { return cpp_lengthof(PersistentStorage, storage); } uint Resolve(uint index, uint var, uint param, GetVariableExtra *extra) const override { @@ -1985,15 +1980,15 @@ class NIHTown : public NIHelper { return ro.GetScope(VSG_SCOPE_SELF)->GetVariable(var, param, extra); } - const int32_t *GetPSAFirstPosition(uint index, uint32_t grfid) const override + const std::span GetPSA(uint index, uint32_t grfid) const override { Town *t = Town::Get(index); for (const auto &it : t->psa_list) { - if (it->grfid == grfid) return &it->storage[0]; + if (it->grfid == grfid) return it->storage; } - return nullptr; + return {}; } virtual std::vector GetPSAGRFIDs(uint index) const override diff --git a/src/tbtr_template_gui_main.cpp b/src/tbtr_template_gui_main.cpp index 66de16432b..9d252a7c52 100644 --- a/src/tbtr_template_gui_main.cpp +++ b/src/tbtr_template_gui_main.cpp @@ -258,18 +258,18 @@ public: this->Window::Close(); } - virtual void UpdateWidgetSize(WidgetID widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override + virtual void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override { switch (widget) { case TRW_WIDGET_TOP_MATRIX: - resize->height = GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.matrix.Vertical(); - size->height = 8 * resize->height; + resize.height = GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.matrix.Vertical(); + size.height = 8 * resize.height; break; case TRW_WIDGET_BOTTOM_MATRIX: { int base_resize = GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.matrix.Vertical(); int target_resize = WidgetDimensions::scaled.matrix.top + GetCharacterHeight(FS_NORMAL) + ScaleGUITrad(GetVehicleHeight(VEH_TRAIN)); - this->bottom_matrix_item_size = resize->height = CeilT(target_resize, base_resize); - size->height = 4 * resize->height; + this->bottom_matrix_item_size = resize.height = CeilT(target_resize, base_resize); + size.height = 4 * resize.height; int gap = ScaleGUITrad(TRW_GAP); @@ -284,7 +284,7 @@ public: /* use buy cost width as nominal width for name field */ uint left_side = ScaleGUITrad(TRW_LEFT_OFFSET) + this->buy_cost_width * 2; uint right_side = this->refit_text_width + this->depot_text_width + this->remainder_text_width + this->old_text_width + ScaleGUITrad(TRW_RIGHT_OFFSET); - size->width = std::max(size->width, left_side + gap + right_side); + size.width = std::max(size.width, left_side + gap + right_side); break; } case TRW_WIDGET_TRAIN_RAILTYPE_DROPDOWN: { @@ -297,15 +297,15 @@ public: } d.width += padding.width; d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } case TRW_WIDGET_TMPL_CONFIG_HEADER: - size->height = GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.framerect.Vertical(); + size.height = GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.framerect.Vertical(); break; case TRW_WIDGET_TMPL_BUTTONS_CONFIG_RIGHTPANEL: case TRW_WIDGET_TMPL_BUTTONS_EDIT_RIGHTPANEL: - size->width = std::max(size->width, NWidgetLeaf::GetResizeBoxDimension().width); + size.width = std::max(size.width, NWidgetLeaf::GetResizeBoxDimension().width); break; } } diff --git a/src/terraform_cmd.cpp b/src/terraform_cmd.cpp index 11db6890b4..0e7526bce0 100644 --- a/src/terraform_cmd.cpp +++ b/src/terraform_cmd.cpp @@ -139,8 +139,6 @@ static CommandCost TerraformTileHeight(TerraformerState *ts, TileIndex tile, int /* Recurse to neighboured corners if height difference is larger than 1 */ { - const TileIndexDiffC *ttm; - TileIndex orig_tile = tile; static const TileIndexDiffC _terraform_tilepos[] = { { 1, 0}, // move to tile in SE @@ -149,8 +147,8 @@ static CommandCost TerraformTileHeight(TerraformerState *ts, TileIndex tile, int { 0, -2} // undo last move, and move to tile in NE }; - for (ttm = _terraform_tilepos; ttm != endof(_terraform_tilepos); ttm++) { - tile += ToTileIndexDiff(*ttm); + for (const auto &ttm : _terraform_tilepos) { + tile += ToTileIndexDiff(ttm); if (tile >= MapSize()) continue; /* Make sure we don't wrap around the map */ diff --git a/src/terraform_gui.cpp b/src/terraform_gui.cpp index 9e8493b82d..7e17f60a12 100644 --- a/src/terraform_gui.cpp +++ b/src/terraform_gui.cpp @@ -628,12 +628,12 @@ struct ScenarioEditorLandscapeGenerationWindow : Window { } } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { if (widget != WID_ETT_DOTS) return; - size->width = std::max(size->width, ScaleGUITrad(59)); - size->height = std::max(size->height, ScaleGUITrad(31)); + size.width = std::max(size.width, ScaleGUITrad(59)); + size.height = std::max(size.height, ScaleGUITrad(31)); } void DrawWidget(const Rect &r, WidgetID widget) const override diff --git a/src/textfile_gui.cpp b/src/textfile_gui.cpp index 2c571cd57c..073a92da77 100644 --- a/src/textfile_gui.cpp +++ b/src/textfile_gui.cpp @@ -135,14 +135,14 @@ uint TextfileWindow::GetContentHeight() return this->lines.back().bottom; } -/* virtual */ void TextfileWindow::UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) +/* virtual */ void TextfileWindow::UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) { switch (widget) { case WID_TF_BACKGROUND: - resize->height = GetCharacterHeight(FS_MONO); + resize.height = GetCharacterHeight(FS_MONO); - size->height = 4 * resize->height + WidgetDimensions::scaled.frametext.Vertical(); // At least 4 lines are visible. - size->width = std::max(200u, size->width); // At least 200 pixels wide. + size.height = 4 * resize.height + WidgetDimensions::scaled.frametext.Vertical(); // At least 4 lines are visible. + size.width = std::max(200u, size.width); // At least 200 pixels wide. break; } } diff --git a/src/textfile_gui.h b/src/textfile_gui.h index 57cc16760e..79c3571544 100644 --- a/src/textfile_gui.h +++ b/src/textfile_gui.h @@ -30,7 +30,7 @@ struct TextfileWindow : public Window, MissingGlyphSearcher { Scrollbar *vscroll; ///< Vertical scrollbar. Scrollbar *hscroll; ///< Horizontal scrollbar. - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override; + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override; void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override; void DrawWidget(const Rect &r, WidgetID widget) const override; void OnResize() override; diff --git a/src/timetable_gui.cpp b/src/timetable_gui.cpp index 021aad3c6a..0325de2e58 100644 --- a/src/timetable_gui.cpp +++ b/src/timetable_gui.cpp @@ -399,7 +399,7 @@ struct TimetableWindow : GeneralVehicleWindow { return (travelling && v->lateness_counter < 0); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_VT_ARRIVAL_DEPARTURE_PANEL: @@ -412,18 +412,18 @@ struct TimetableWindow : GeneralVehicleWindow { } this->deparr_time_width = GetStringBoundingBox(STR_JUST_TT_TIME).width + 4; this->deparr_abbr_width = std::max(GetStringBoundingBox(STR_TIMETABLE_ARRIVAL_ABBREVIATION).width, GetStringBoundingBox(STR_TIMETABLE_DEPARTURE_ABBREVIATION).width); - size->width = this->deparr_abbr_width + WidgetDimensions::scaled.hsep_wide + this->deparr_time_width + padding.width; + size.width = this->deparr_abbr_width + WidgetDimensions::scaled.hsep_wide + this->deparr_time_width + padding.width; [[fallthrough]]; case WID_VT_ARRIVAL_DEPARTURE_SELECTION: case WID_VT_TIMETABLE_PANEL: - resize->height = std::max(GetCharacterHeight(FS_NORMAL), GetSpriteSize(SPR_LOCK).height); - size->height = 8 * resize->height + padding.height; + resize.height = std::max(GetCharacterHeight(FS_NORMAL), GetSpriteSize(SPR_LOCK).height); + size.height = 8 * resize.height + padding.height; break; case WID_VT_SUMMARY_PANEL: { Dimension d = GetSpriteSize(SPR_WARNING_SIGN); - size->height = 2 * GetCharacterHeight(FS_NORMAL) + std::min(MAX_SUMMARY_WARNINGS, this->summary_warnings) * std::max(d.height, GetCharacterHeight(FS_NORMAL)) + padding.height; + size.height = 2 * GetCharacterHeight(FS_NORMAL) + std::min(MAX_SUMMARY_WARNINGS, this->summary_warnings) * std::max(d.height, GetCharacterHeight(FS_NORMAL)) + padding.height; break; } } diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index 0f18fafcb0..e2c160b63b 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -2556,16 +2556,16 @@ struct ScenarioEditorToolbarWindow : Window { } } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_TE_SPACER: - size->width = std::max(GetStringBoundingBox(STR_SCENEDIT_TOOLBAR_OPENTTD).width, GetStringBoundingBox(STR_SCENEDIT_TOOLBAR_SCENARIO_EDITOR).width) + padding.width; + size.width = std::max(GetStringBoundingBox(STR_SCENEDIT_TOOLBAR_OPENTTD).width, GetStringBoundingBox(STR_SCENEDIT_TOOLBAR_SCENARIO_EDITOR).width) + padding.width; break; case WID_TE_DATE: SetDParam(0, CalTime::ConvertYMDToDate(CalTime::MAX_YEAR, 0, 1)); - *size = GetStringBoundingBox(STR_JUST_DATE_LONG); + size = GetStringBoundingBox(STR_JUST_DATE_LONG); break; } } diff --git a/src/town.h b/src/town.h index 0b82538ab2..81cd85e3ae 100644 --- a/src/town.h +++ b/src/town.h @@ -63,12 +63,14 @@ struct TownCache { /** Town setting override flags */ enum TownSettingOverrideFlags { + TSOF_OVERRIDE_BEGIN = 0, // Begin marker TSOF_OVERRIDE_BUILD_ROADS = 0, TSOF_OVERRIDE_BUILD_LEVEL_CROSSINGS = 1, TSOF_OVERRIDE_BUILD_TUNNELS = 2, TSOF_OVERRIDE_BUILD_INCLINED_ROADS = 3, TSOF_OVERRIDE_GROWTH = 4, TSOF_OVERRIDE_BUILD_BRIDGES = 5, + TSOF_OVERRIDE_END, // End marker }; /** Town data structure. */ diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 079b3099f3..9a0439eba8 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -1573,8 +1573,8 @@ static inline bool RoadTypesAllowHouseHere(TileIndex t) static const TileIndexDiffC tiles[] = { {-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1} }; bool allow = false; - for (const TileIndexDiffC *ptr = tiles; ptr != endof(tiles); ++ptr) { - TileIndex cur_tile = t + ToTileIndexDiff(*ptr); + for (const auto &ptr : tiles) { + TileIndex cur_tile = t + ToTileIndexDiff(ptr); if (!IsValidTile(cur_tile)) continue; if (!(IsTileType(cur_tile, MP_ROAD) || IsAnyRoadStopTile(cur_tile))) continue; @@ -2067,21 +2067,20 @@ static bool GrowTown(Town *t) TileIndex tile = t->xy; // The tile we are working with ATM /* Find a road that we can base the construction on. */ - const TileIndexDiffC *ptr; - for (ptr = _town_coord_mod; ptr != endof(_town_coord_mod); ++ptr) { + for (const auto &ptr : _town_coord_mod) { if (GetTownRoadBits(tile) != ROAD_NONE) { bool success = GrowTownAtRoad(t, tile); cur_company.Restore(); return success; } - tile = TileAdd(tile, ToTileIndexDiff(*ptr)); + tile = TileAdd(tile, ToTileIndexDiff(ptr)); } /* No road available, try to build a random road block by * clearing some land and then building a road there. */ if (TownAllowedToBuildRoads(t)) { tile = t->xy; - for (ptr = _town_coord_mod; ptr != endof(_town_coord_mod); ++ptr) { + for (const auto &ptr : _town_coord_mod) { /* Only work with plain land that not already has a house */ if (!IsTileType(tile, MP_HOUSE) && IsTileFlat(tile)) { if (DoCommand(tile, 0, 0, DC_AUTO | DC_NO_WATER | DC_TOWN, CMD_LANDSCAPE_CLEAR).Succeeded()) { @@ -2091,7 +2090,7 @@ static bool GrowTown(Town *t) return true; } } - tile = TileAdd(tile, ToTileIndexDiff(*ptr)); + tile = TileAdd(tile, ToTileIndexDiff(ptr)); } } diff --git a/src/town_gui.cpp b/src/town_gui.cpp index 9f8974dca9..4b22fedf25 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -239,67 +239,74 @@ public: } } + std::pair PrepareActionInfoString(int action_index) const + { + TextColour colour = TC_FROMSTRING; + StringID text = STR_NULL; + if (action_index >= 0x100) { + SetDParam(1, STR_EMPTY); + switch (action_index - 0x100) { + case TSOF_OVERRIDE_BUILD_ROADS: + SetDParam(1, STR_CONFIG_SETTING_ALLOW_TOWN_ROADS_HELPTEXT); + break; + case TSOF_OVERRIDE_BUILD_LEVEL_CROSSINGS: + SetDParam(1, STR_CONFIG_SETTING_ALLOW_TOWN_LEVEL_CROSSINGS_HELPTEXT); + break; + case TSOF_OVERRIDE_BUILD_TUNNELS: + SetDParam(1, STR_CONFIG_SETTING_TOWN_TUNNELS_HELPTEXT); + break; + case TSOF_OVERRIDE_BUILD_INCLINED_ROADS: + SetDParam(1, STR_CONFIG_SETTING_TOWN_MAX_ROAD_SLOPE_HELPTEXT); + break; + case TSOF_OVERRIDE_GROWTH: + SetDParam(1, STR_CONFIG_SETTING_TOWN_GROWTH_HELPTEXT); + break; + case TSOF_OVERRIDE_BUILD_BRIDGES: + SetDParam(1, STR_CONFIG_SETTING_ALLOW_TOWN_BRIDGES_HELPTEXT); + break; + } + text = STR_LOCAL_AUTHORITY_SETTING_OVERRIDE_TEXT; + SetDParam(0, STR_LOCAL_AUTHORITY_SETTING_OVERRIDE_ALLOW_ROADS + action_index - 0x100); + } else { + colour = TC_YELLOW; + switch (action_index) { + case 0: + text = STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_SMALL_ADVERTISING; + break; + case 1: + text = STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_MEDIUM_ADVERTISING; + break; + case 2: + text = STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_LARGE_ADVERTISING; + break; + case 3: + text = EconTime::UsingWallclockUnits() ? STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_ROAD_RECONSTRUCTION_MINUTES : STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_ROAD_RECONSTRUCTION_MONTHS; + break; + case 4: + text = STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_STATUE_OF_COMPANY; + break; + case 5: + text = STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_NEW_BUILDINGS; + break; + case 6: + text = EconTime::UsingWallclockUnits() ? STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_EXCLUSIVE_TRANSPORT_MINUTES : STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_EXCLUSIVE_TRANSPORT_MONTHS; + break; + case 7: + text = STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_BRIBE; + break; + } + SetDParam(0, _price[PR_TOWN_ACTION] * _town_action_costs[action_index] >> 8); + } + + return { text, colour }; + } + void DrawWidget(const Rect &r, WidgetID widget) const override { switch (widget) { case WID_TA_ACTION_INFO: if (this->sel_index != -1) { - TextColour colour = TC_FROMSTRING; - StringID text = STR_NULL; - if (this->sel_index >= 0x100) { - SetDParam(1, STR_EMPTY); - switch (this->sel_index - 0x100) { - case TSOF_OVERRIDE_BUILD_ROADS: - SetDParam(1, STR_CONFIG_SETTING_ALLOW_TOWN_ROADS_HELPTEXT); - break; - case TSOF_OVERRIDE_BUILD_LEVEL_CROSSINGS: - SetDParam(1, STR_CONFIG_SETTING_ALLOW_TOWN_LEVEL_CROSSINGS_HELPTEXT); - break; - case TSOF_OVERRIDE_BUILD_TUNNELS: - SetDParam(1, STR_CONFIG_SETTING_TOWN_TUNNELS_HELPTEXT); - break; - case TSOF_OVERRIDE_BUILD_INCLINED_ROADS: - SetDParam(1, STR_CONFIG_SETTING_TOWN_MAX_ROAD_SLOPE_HELPTEXT); - break; - case TSOF_OVERRIDE_GROWTH: - SetDParam(1, STR_CONFIG_SETTING_TOWN_GROWTH_HELPTEXT); - break; - case TSOF_OVERRIDE_BUILD_BRIDGES: - SetDParam(1, STR_CONFIG_SETTING_ALLOW_TOWN_BRIDGES_HELPTEXT); - break; - } - text = STR_LOCAL_AUTHORITY_SETTING_OVERRIDE_TEXT; - SetDParam(0, STR_LOCAL_AUTHORITY_SETTING_OVERRIDE_ALLOW_ROADS + this->sel_index - 0x100); - } else { - colour = TC_YELLOW; - switch (this->sel_index) { - case 0: - text = STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_SMALL_ADVERTISING; - break; - case 1: - text = STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_MEDIUM_ADVERTISING; - break; - case 2: - text = STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_LARGE_ADVERTISING; - break; - case 3: - text = EconTime::UsingWallclockUnits() ? STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_ROAD_RECONSTRUCTION_MINUTES : STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_ROAD_RECONSTRUCTION_MONTHS; - break; - case 4: - text = STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_STATUE_OF_COMPANY; - break; - case 5: - text = STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_NEW_BUILDINGS; - break; - case 6: - text = EconTime::UsingWallclockUnits() ? STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_EXCLUSIVE_TRANSPORT_MINUTES : STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_EXCLUSIVE_TRANSPORT_MONTHS; - break; - case 7: - text = STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_BRIBE; - break; - } - SetDParam(0, _price[PR_TOWN_ACTION] * _town_action_costs[this->sel_index] >> 8); - } + auto [text, colour] = this->PrepareActionInfoString(this->sel_index); DrawStringMultiLine(r.Shrink(WidgetDimensions::scaled.framerect), text, colour); } break; @@ -371,34 +378,38 @@ public: } } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_TA_ACTION_INFO: { - assert(size->width > padding.width && size->height > padding.height); + assert(size.width > padding.width && size.height > padding.height); Dimension d = {0, 0}; for (int i = 0; i < TACT_COUNT; i++) { - SetDParam(0, _price[PR_TOWN_ACTION] * _town_action_costs[i] >> 8); - d = maxdim(d, GetStringMultiLineBoundingBox(STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_SMALL_ADVERTISING + i, *size)); + auto [text, _] = this->PrepareActionInfoString(i); + d = maxdim(d, GetStringMultiLineBoundingBox(text, size)); + } + for (int i = TSOF_OVERRIDE_BEGIN; i < TSOF_OVERRIDE_END; i++) { + auto [text, _] = this->PrepareActionInfoString(i + 0x100); + d = maxdim(d, GetStringMultiLineBoundingBox(text, size)); } d.width += padding.width; d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } case WID_TA_COMMAND_LIST: - size->height = (5 + SETTING_OVERRIDE_COUNT) * GetCharacterHeight(FS_NORMAL) + padding.height; - size->width = GetStringBoundingBox(STR_LOCAL_AUTHORITY_ACTIONS_TITLE).width; + size.height = (5 + SETTING_OVERRIDE_COUNT) * GetCharacterHeight(FS_NORMAL) + padding.height; + size.width = GetStringBoundingBox(STR_LOCAL_AUTHORITY_ACTIONS_TITLE).width; for (uint i = 0; i < TACT_COUNT; i++ ) { - size->width = std::max(size->width, GetStringBoundingBox(STR_LOCAL_AUTHORITY_ACTION_SMALL_ADVERTISING_CAMPAIGN + i).width + padding.width); + size.width = std::max(size.width, GetStringBoundingBox(STR_LOCAL_AUTHORITY_ACTION_SMALL_ADVERTISING_CAMPAIGN + i).width + padding.width); } - size->width += padding.width; + size.width += padding.width; break; case WID_TA_RATING_INFO: - resize->height = std::max({this->icon_size.height + WidgetDimensions::scaled.vsep_normal, this->exclusive_size.height + WidgetDimensions::scaled.vsep_normal, (uint)GetCharacterHeight(FS_NORMAL)}); - size->height = 9 * resize->height + padding.height; + resize.height = std::max({this->icon_size.height + WidgetDimensions::scaled.vsep_normal, this->exclusive_size.height + WidgetDimensions::scaled.vsep_normal, (uint)GetCharacterHeight(FS_NORMAL)}); + size.height = 9 * resize.height + padding.height; break; } } @@ -714,11 +725,11 @@ public: } } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_TV_INFO: - size->height = GetDesiredInfoHeight(size->width) + padding.height; + size.height = GetDesiredInfoHeight(size.width) + padding.height; break; } } @@ -1077,14 +1088,14 @@ public: } } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_TD_SORT_ORDER: { Dimension d = GetStringBoundingBox(this->GetWidget(widget)->widget_data); d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better. d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } case WID_TD_SORT_CRITERIA: { @@ -1094,7 +1105,7 @@ public: } d.width += padding.width; d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } case WID_TD_LIST: { @@ -1111,11 +1122,11 @@ public: Dimension icon_size = GetSpriteSize(SPR_TOWN_RATING_GOOD); d.width += icon_size.width + 2; d.height = std::max(d.height, icon_size.height); - resize->height = d.height; + resize.height = d.height; d.height *= 5; d.width += padding.width; d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } case WID_TD_WORLD_POPULATION: { @@ -1125,7 +1136,7 @@ public: Dimension d = GetStringBoundingBox(STR_TOWN_DIRECTORY_INFO); d.width += padding.width; d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } } @@ -1868,7 +1879,7 @@ public: } } - virtual void UpdateWidgetSize(WidgetID widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override + virtual void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override { switch (widget) { case WID_HP_HOUSE_SETS: { @@ -1876,24 +1887,24 @@ public: for (uint i = 0; i < this->house_list.NumHouseSets(); i++) { max_w = std::max(max_w, GetStringBoundingBox(this->house_list.GetNameOfHouseSet(i)).width); } - size->width = std::max(size->width, max_w + padding.width); + size.width = std::max(size.width, max_w + padding.width); this->line_height = GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.matrix.Vertical(); - size->height = this->house_list.NumHouseSets() * this->line_height; + size.height = this->house_list.NumHouseSets() * this->line_height; break; } case WID_HP_HOUSE_NAME: - size->width = 120; // we do not want this window to get too wide, better clip + size.width = 120; // we do not want this window to get too wide, better clip break; case WID_HP_HISTORICAL_BUILDING: - size->width = std::max(size->width, GetStringBoundingBox(STR_HOUSE_BUILD_HISTORICAL_BUILDING).width + padding.width); + size.width = std::max(size.width, GetStringBoundingBox(STR_HOUSE_BUILD_HISTORICAL_BUILDING).width + padding.width); break; case WID_HP_HOUSE_POPULATION: SetDParam(0, 0); /* max popultion is 255 - 3 digits */ - size->width = std::max(size->width, GetStringBoundingBox(STR_HOUSE_BUILD_HOUSE_POPULATION).width + 3 * GetDigitWidth() + padding.width); + size.width = std::max(size.width, GetStringBoundingBox(STR_HOUSE_BUILD_HOUSE_POPULATION).width + 3 * GetDigitWidth() + padding.width); break; case WID_HP_HOUSE_ZONES: { @@ -1901,7 +1912,7 @@ public: SetDParam(2 * i, STR_HOUSE_BUILD_HOUSE_ZONE_ENABLED); // colour SetDParam(2 * i + 1, i + 1); // digit: 1(center)/2/3/4/5(edge) } - size->width = std::max(size->width, GetStringBoundingBox(STR_HOUSE_BUILD_HOUSE_ZONES).width + padding.width); + size.width = std::max(size.width, GetStringBoundingBox(STR_HOUSE_BUILD_HOUSE_ZONES).width + padding.width); break; } @@ -1914,7 +1925,7 @@ public: dim = maxdim(dim, GetStringBoundingBox(STR_HOUSE_BUILD_LANDSCAPE)); dim.width += padding.width; dim.height += padding.height; - *size = maxdim(*size, dim); + size = maxdim(size, dim); break; } @@ -1926,18 +1937,18 @@ public: Dimension dim = GetStringBoundingBox(STR_HOUSE_BUILD_YEARS); dim.width += 14 * GetDigitWidth() + padding.width; // space for about 16 digits (14 + two zeros) should be enough, don't make the window too wide dim.height += padding.height; - *size = maxdim(*size, dim); + size = maxdim(size, dim); break; } case WID_HP_HOUSE_SELECT_MATRIX: - resize->height = 1; // don't snap to rows of this matrix + resize.height = 1; // don't snap to rows of this matrix break; /* these texts can be long, better clip */ case WID_HP_HOUSE_ACCEPTANCE: case WID_HP_HOUSE_SUPPLY: - size->width = 0; + size.width = 0; break; default: break; @@ -2100,7 +2111,7 @@ struct SelectTownWindow : Window { this->FinishInitNested(); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override { if (widget != WID_ST_PANEL) return; @@ -2111,11 +2122,11 @@ struct SelectTownWindow : Window { d = maxdim(d, GetStringBoundingBox(STR_SELECT_TOWN_LIST_ITEM)); } - resize->height = d.height; + resize.height = d.height; d.height *= 5; d.width += WidgetDimensions::scaled.framerect.Horizontal(); d.height += WidgetDimensions::scaled.framerect.Vertical(); - *size = d; + size = d; } void DrawWidget(const Rect &r, WidgetID widget) const override diff --git a/src/townname.cpp b/src/townname.cpp index 1a64e6b5d3..f1fcba1ad5 100644 --- a/src/townname.cpp +++ b/src/townname.cpp @@ -162,9 +162,9 @@ bool GenerateTownName(Randomizer &randomizer, uint32_t *townnameparts, TownNames * @param seed seed * @return seed transformed to a number from given range */ -static inline uint32_t SeedChance(uint8_t shift_by, int max, uint32_t seed) +static inline uint32_t SeedChance(uint8_t shift_by, size_t max, uint32_t seed) { - return (GB(seed, shift_by, 16) * max) >> 16; + return (GB(seed, shift_by, 16) * ClampTo(max)) >> 16; } @@ -175,7 +175,7 @@ static inline uint32_t SeedChance(uint8_t shift_by, int max, uint32_t seed) * @param seed seed * @return seed transformed to a number from given range */ -static inline uint32_t SeedModChance(uint8_t shift_by, int max, uint32_t seed) +static inline uint32_t SeedModChance(uint8_t shift_by, size_t max, uint32_t seed) { /* This actually gives *MUCH* more even distribution of the values * than SeedChance(), which is absolutely horrible in that. If @@ -198,7 +198,7 @@ static inline uint32_t SeedModChance(uint8_t shift_by, int max, uint32_t seed) * @param bias minimum value that can be returned * @return seed transformed to a number from given range */ -static inline int32_t SeedChanceBias(uint8_t shift_by, int max, uint32_t seed, int bias) +static inline int32_t SeedChanceBias(uint8_t shift_by, size_t max, uint32_t seed, int bias) { return SeedChance(shift_by, max + bias, seed) - bias; } @@ -248,17 +248,17 @@ static void MakeEnglishOriginalTownName(StringBuilder builder, uint32_t seed) size_t start = builder.CurrentIndex(); /* optional first segment */ - int i = SeedChanceBias(0, lengthof(_name_original_english_1), seed, 50); + int i = SeedChanceBias(0, std::size(_name_original_english_1), seed, 50); if (i >= 0) builder += _name_original_english_1[i]; /* mandatory middle segments */ - builder += _name_original_english_2[SeedChance(4, lengthof(_name_original_english_2), seed)]; - builder += _name_original_english_3[SeedChance(7, lengthof(_name_original_english_3), seed)]; - builder += _name_original_english_4[SeedChance(10, lengthof(_name_original_english_4), seed)]; - builder += _name_original_english_5[SeedChance(13, lengthof(_name_original_english_5), seed)]; + builder += _name_original_english_2[SeedChance(4, std::size(_name_original_english_2), seed)]; + builder += _name_original_english_3[SeedChance(7, std::size(_name_original_english_3), seed)]; + builder += _name_original_english_4[SeedChance(10, std::size(_name_original_english_4), seed)]; + builder += _name_original_english_5[SeedChance(13, std::size(_name_original_english_5), seed)]; /* optional last segment */ - i = SeedChanceBias(15, lengthof(_name_original_english_6), seed, 60); + i = SeedChanceBias(15, std::size(_name_original_english_6), seed, 60); if (i >= 0) builder += _name_original_english_6[i]; /* Ce, Ci => Ke, Ki */ @@ -281,25 +281,25 @@ static void MakeEnglishAdditionalTownName(StringBuilder builder, uint32_t seed) size_t start = builder.CurrentIndex(); /* optional first segment */ - int i = SeedChanceBias(0, lengthof(_name_additional_english_prefix), seed, 50); + int i = SeedChanceBias(0, std::size(_name_additional_english_prefix), seed, 50); if (i >= 0) builder += _name_additional_english_prefix[i]; if (SeedChance(3, 20, seed) >= 14) { - builder += _name_additional_english_1a[SeedChance(6, lengthof(_name_additional_english_1a), seed)]; + builder += _name_additional_english_1a[SeedChance(6, std::size(_name_additional_english_1a), seed)]; } else { - builder += _name_additional_english_1b1[SeedChance(6, lengthof(_name_additional_english_1b1), seed)]; - builder += _name_additional_english_1b2[SeedChance(9, lengthof(_name_additional_english_1b2), seed)]; + builder += _name_additional_english_1b1[SeedChance(6, std::size(_name_additional_english_1b1), seed)]; + builder += _name_additional_english_1b2[SeedChance(9, std::size(_name_additional_english_1b2), seed)]; if (SeedChance(11, 20, seed) >= 4) { - builder += _name_additional_english_1b3a[SeedChance(12, lengthof(_name_additional_english_1b3a), seed)]; + builder += _name_additional_english_1b3a[SeedChance(12, std::size(_name_additional_english_1b3a), seed)]; } else { - builder += _name_additional_english_1b3b[SeedChance(12, lengthof(_name_additional_english_1b3b), seed)]; + builder += _name_additional_english_1b3b[SeedChance(12, std::size(_name_additional_english_1b3b), seed)]; } } - builder += _name_additional_english_2[SeedChance(14, lengthof(_name_additional_english_2), seed)]; + builder += _name_additional_english_2[SeedChance(14, std::size(_name_additional_english_2), seed)]; /* optional last segment */ - i = SeedChanceBias(15, lengthof(_name_additional_english_3), seed, 60); + i = SeedChanceBias(15, std::size(_name_additional_english_3), seed, 60); if (i >= 0) builder += _name_additional_english_3[i]; assert(builder.CurrentIndex() - start >= 4); @@ -315,7 +315,7 @@ static void MakeEnglishAdditionalTownName(StringBuilder builder, uint32_t seed) static void MakeAustrianTownName(StringBuilder builder, uint32_t seed) { /* Bad, Maria, Gross, ... */ - int i = SeedChanceBias(0, lengthof(_name_austrian_a1), seed, 15); + int i = SeedChanceBias(0, std::size(_name_austrian_a1), seed, 15); if (i >= 0) builder += _name_austrian_a1[i]; int j = 0; @@ -323,27 +323,27 @@ static void MakeAustrianTownName(StringBuilder builder, uint32_t seed) i = SeedChance(4, 6, seed); if (i >= 4) { /* Kaisers-kirchen */ - builder += _name_austrian_a2[SeedChance( 7, lengthof(_name_austrian_a2), seed)]; - builder += _name_austrian_a3[SeedChance(13, lengthof(_name_austrian_a3), seed)]; + builder += _name_austrian_a2[SeedChance( 7, std::size(_name_austrian_a2), seed)]; + builder += _name_austrian_a3[SeedChance(13, std::size(_name_austrian_a3), seed)]; } else if (i >= 2) { /* St. Johann */ - builder += _name_austrian_a5[SeedChance( 7, lengthof(_name_austrian_a5), seed)]; - builder += _name_austrian_a6[SeedChance( 9, lengthof(_name_austrian_a6), seed)]; + builder += _name_austrian_a5[SeedChance( 7, std::size(_name_austrian_a5), seed)]; + builder += _name_austrian_a6[SeedChance( 9, std::size(_name_austrian_a6), seed)]; j = 1; // More likely to have a " an der " or " am " } else { /* Zell */ - builder += _name_austrian_a4[SeedChance( 7, lengthof(_name_austrian_a4), seed)]; + builder += _name_austrian_a4[SeedChance( 7, std::size(_name_austrian_a4), seed)]; } i = SeedChance(1, 6, seed); if (i >= 4 - j) { /* an der Donau (rivers) */ - builder += _name_austrian_f1[SeedChance(4, lengthof(_name_austrian_f1), seed)]; - builder += _name_austrian_f2[SeedChance(5, lengthof(_name_austrian_f2), seed)]; + builder += _name_austrian_f1[SeedChance(4, std::size(_name_austrian_f1), seed)]; + builder += _name_austrian_f2[SeedChance(5, std::size(_name_austrian_f2), seed)]; } else if (i >= 2 - j) { /* am Dachstein (mountains) */ - builder += _name_austrian_b1[SeedChance(4, lengthof(_name_austrian_b1), seed)]; - builder += _name_austrian_b2[SeedChance(5, lengthof(_name_austrian_b2), seed)]; + builder += _name_austrian_b1[SeedChance(4, std::size(_name_austrian_b1), seed)]; + builder += _name_austrian_b2[SeedChance(5, std::size(_name_austrian_b2), seed)]; } } @@ -359,30 +359,30 @@ static void MakeGermanTownName(StringBuilder builder, uint32_t seed) /* optional prefix */ if (seed_derivative == 12 || seed_derivative == 19) { - uint i = SeedChance(2, lengthof(_name_german_pre), seed); + uint i = SeedChance(2, std::size(_name_german_pre), seed); builder += _name_german_pre[i]; } /* mandatory middle segments including option of hardcoded name */ - uint i = SeedChance(3, lengthof(_name_german_real) + lengthof(_name_german_1), seed); - if (i < lengthof(_name_german_real)) { + uint i = SeedChance(3, std::size(_name_german_real) + std::size(_name_german_1), seed); + if (i < std::size(_name_german_real)) { builder += _name_german_real[i]; } else { - builder += _name_german_1[i - lengthof(_name_german_real)]; + builder += _name_german_1[i - std::size(_name_german_real)]; - i = SeedChance(5, lengthof(_name_german_2), seed); + i = SeedChance(5, std::size(_name_german_2), seed); builder += _name_german_2[i]; } /* optional suffix */ if (seed_derivative == 24) { - i = SeedChance(9, lengthof(_name_german_4_an_der) + lengthof(_name_german_4_am), seed); - if (i < lengthof(_name_german_4_an_der)) { + i = SeedChance(9, std::size(_name_german_4_an_der) + std::size(_name_german_4_am), seed); + if (i < std::size(_name_german_4_an_der)) { builder += _name_german_3_an_der[0]; builder += _name_german_4_an_der[i]; } else { builder += _name_german_3_am[0]; - builder += _name_german_4_am[i - lengthof(_name_german_4_an_der)]; + builder += _name_german_4_am[i - std::size(_name_german_4_an_der)]; } } } @@ -395,7 +395,7 @@ static void MakeGermanTownName(StringBuilder builder, uint32_t seed) */ static void MakeSpanishTownName(StringBuilder builder, uint32_t seed) { - builder += _name_spanish_real[SeedChance(0, lengthof(_name_spanish_real), seed)]; + builder += _name_spanish_real[SeedChance(0, std::size(_name_spanish_real), seed)]; } @@ -406,7 +406,7 @@ static void MakeSpanishTownName(StringBuilder builder, uint32_t seed) */ static void MakeFrenchTownName(StringBuilder builder, uint32_t seed) { - builder += _name_french_real[SeedChance(0, lengthof(_name_french_real), seed)]; + builder += _name_french_real[SeedChance(0, std::size(_name_french_real), seed)]; } @@ -417,8 +417,8 @@ static void MakeFrenchTownName(StringBuilder builder, uint32_t seed) */ static void MakeSillyTownName(StringBuilder builder, uint32_t seed) { - builder += _name_silly_1[SeedChance( 0, lengthof(_name_silly_1), seed)]; - builder += _name_silly_2[SeedChance(16, lengthof(_name_silly_2), seed)]; + builder += _name_silly_1[SeedChance( 0, std::size(_name_silly_1), seed)]; + builder += _name_silly_2[SeedChance(16, std::size(_name_silly_2), seed)]; } @@ -430,19 +430,19 @@ static void MakeSillyTownName(StringBuilder builder, uint32_t seed) static void MakeSwedishTownName(StringBuilder builder, uint32_t seed) { /* optional first segment */ - int i = SeedChanceBias(0, lengthof(_name_swedish_1), seed, 50); + int i = SeedChanceBias(0, std::size(_name_swedish_1), seed, 50); if (i >= 0) builder += _name_swedish_1[i]; /* mandatory middle segments including option of hardcoded name */ if (SeedChance(4, 5, seed) >= 3) { - builder += _name_swedish_2[SeedChance( 7, lengthof(_name_swedish_2), seed)]; + builder += _name_swedish_2[SeedChance( 7, std::size(_name_swedish_2), seed)]; } else { - builder += _name_swedish_2a[SeedChance( 7, lengthof(_name_swedish_2a), seed)]; - builder += _name_swedish_2b[SeedChance(10, lengthof(_name_swedish_2b), seed)]; - builder += _name_swedish_2c[SeedChance(13, lengthof(_name_swedish_2c), seed)]; + builder += _name_swedish_2a[SeedChance( 7, std::size(_name_swedish_2a), seed)]; + builder += _name_swedish_2b[SeedChance(10, std::size(_name_swedish_2b), seed)]; + builder += _name_swedish_2c[SeedChance(13, std::size(_name_swedish_2c), seed)]; } - builder += _name_swedish_3[SeedChance(16, lengthof(_name_swedish_3), seed)]; + builder += _name_swedish_3[SeedChance(16, std::size(_name_swedish_3), seed)]; } @@ -454,18 +454,18 @@ static void MakeSwedishTownName(StringBuilder builder, uint32_t seed) static void MakeDutchTownName(StringBuilder builder, uint32_t seed) { /* optional first segment */ - int i = SeedChanceBias(0, lengthof(_name_dutch_1), seed, 50); + int i = SeedChanceBias(0, std::size(_name_dutch_1), seed, 50); if (i >= 0) builder += _name_dutch_1[i]; /* mandatory middle segments including option of hardcoded name */ if (SeedChance(6, 9, seed) > 4) { - builder += _name_dutch_2[SeedChance( 9, lengthof(_name_dutch_2), seed)]; + builder += _name_dutch_2[SeedChance( 9, std::size(_name_dutch_2), seed)]; } else { - builder += _name_dutch_3[SeedChance( 9, lengthof(_name_dutch_3), seed)]; - builder += _name_dutch_4[SeedChance(12, lengthof(_name_dutch_4), seed)]; + builder += _name_dutch_3[SeedChance( 9, std::size(_name_dutch_3), seed)]; + builder += _name_dutch_4[SeedChance(12, std::size(_name_dutch_4), seed)]; } - builder += _name_dutch_5[SeedChance(15, lengthof(_name_dutch_5), seed)]; + builder += _name_dutch_5[SeedChance(15, std::size(_name_dutch_5), seed)]; } @@ -480,7 +480,7 @@ static void MakeFinnishTownName(StringBuilder builder, uint32_t seed) /* Select randomly if town name should consists of one or two parts. */ if (SeedChance(0, 15, seed) >= 10) { - builder += _name_finnish_real[SeedChance(2, lengthof(_name_finnish_real), seed)]; + builder += _name_finnish_real[SeedChance(2, std::size(_name_finnish_real), seed)]; return; } @@ -488,7 +488,7 @@ static void MakeFinnishTownName(StringBuilder builder, uint32_t seed) /* A two-part name by combining one of _name_finnish_1 + "la"/"lä" * The reason for not having the contents of _name_finnish_{1,2} in the same table is * that the ones in _name_finnish_2 are not good for this purpose. */ - uint sel = SeedChance( 0, lengthof(_name_finnish_1), seed); + uint sel = SeedChance( 0, std::size(_name_finnish_1), seed); builder += _name_finnish_1[sel]; size_t last = builder.CurrentIndex() - 1; if (builder[last] == 'i') builder[last] = 'e'; @@ -504,14 +504,14 @@ static void MakeFinnishTownName(StringBuilder builder, uint32_t seed) /* A two-part name by combining one of _name_finnish_{1,2} + _name_finnish_3. * Why aren't _name_finnish_{1,2} just one table? See above. */ - uint sel = SeedChance(2, lengthof(_name_finnish_1) + lengthof(_name_finnish_2), seed); - if (sel >= lengthof(_name_finnish_1)) { - builder += _name_finnish_2[sel - lengthof(_name_finnish_1)]; + uint sel = SeedChance(2, std::size(_name_finnish_1) + std::size(_name_finnish_2), seed); + if (sel >= std::size(_name_finnish_1)) { + builder += _name_finnish_2[sel - std::size(_name_finnish_1)]; } else { builder += _name_finnish_1[sel]; } - builder += _name_finnish_3[SeedChance(10, lengthof(_name_finnish_3), seed)]; + builder += _name_finnish_3[SeedChance(10, std::size(_name_finnish_3), seed)]; } @@ -524,53 +524,53 @@ static void MakePolishTownName(StringBuilder builder, uint32_t seed) { /* optional first segment */ uint i = SeedChance(0, - lengthof(_name_polish_2_o) + lengthof(_name_polish_2_m) + - lengthof(_name_polish_2_f) + lengthof(_name_polish_2_n), + std::size(_name_polish_2_o) + std::size(_name_polish_2_m) + + std::size(_name_polish_2_f) + std::size(_name_polish_2_n), seed); uint j = SeedChance(2, 20, seed); - if (i < lengthof(_name_polish_2_o)) { - builder += _name_polish_2_o[SeedChance(3, lengthof(_name_polish_2_o), seed)]; + if (i < std::size(_name_polish_2_o)) { + builder += _name_polish_2_o[SeedChance(3, std::size(_name_polish_2_o), seed)]; return; } - if (i < lengthof(_name_polish_2_m) + lengthof(_name_polish_2_o)) { + if (i < std::size(_name_polish_2_m) + std::size(_name_polish_2_o)) { if (j < 4) { - builder += _name_polish_1_m[SeedChance(5, lengthof(_name_polish_1_m), seed)]; + builder += _name_polish_1_m[SeedChance(5, std::size(_name_polish_1_m), seed)]; } - builder += _name_polish_2_m[SeedChance(7, lengthof(_name_polish_2_m), seed)]; + builder += _name_polish_2_m[SeedChance(7, std::size(_name_polish_2_m), seed)]; if (j >= 4 && j < 16) { - builder += _name_polish_3_m[SeedChance(10, lengthof(_name_polish_3_m), seed)]; + builder += _name_polish_3_m[SeedChance(10, std::size(_name_polish_3_m), seed)]; } return; } - if (i < lengthof(_name_polish_2_f) + lengthof(_name_polish_2_m) + lengthof(_name_polish_2_o)) { + if (i < std::size(_name_polish_2_f) + std::size(_name_polish_2_m) + std::size(_name_polish_2_o)) { if (j < 4) { - builder += _name_polish_1_f[SeedChance(5, lengthof(_name_polish_1_f), seed)]; + builder += _name_polish_1_f[SeedChance(5, std::size(_name_polish_1_f), seed)]; } - builder += _name_polish_2_f[SeedChance(7, lengthof(_name_polish_2_f), seed)]; + builder += _name_polish_2_f[SeedChance(7, std::size(_name_polish_2_f), seed)]; if (j >= 4 && j < 16) { - builder += _name_polish_3_f[SeedChance(10, lengthof(_name_polish_3_f), seed)]; + builder += _name_polish_3_f[SeedChance(10, std::size(_name_polish_3_f), seed)]; } return; } if (j < 4) { - builder += _name_polish_1_n[SeedChance(5, lengthof(_name_polish_1_n), seed)]; + builder += _name_polish_1_n[SeedChance(5, std::size(_name_polish_1_n), seed)]; } - builder += _name_polish_2_n[SeedChance(7, lengthof(_name_polish_2_n), seed)]; + builder += _name_polish_2_n[SeedChance(7, std::size(_name_polish_2_n), seed)]; if (j >= 4 && j < 16) { - builder += _name_polish_3_n[SeedChance(10, lengthof(_name_polish_3_n), seed)]; + builder += _name_polish_3_n[SeedChance(10, std::size(_name_polish_3_n), seed)]; } return; @@ -586,7 +586,7 @@ static void MakeCzechTownName(StringBuilder builder, uint32_t seed) { /* 1:3 chance to use a real name. */ if (SeedModChance(0, 4, seed) == 0) { - builder += _name_czech_real[SeedModChance(4, lengthof(_name_czech_real), seed)]; + builder += _name_czech_real[SeedModChance(4, std::size(_name_czech_real), seed)]; return; } @@ -599,57 +599,57 @@ static void MakeCzechTownName(StringBuilder builder, uint32_t seed) /* IDs of the respective parts */ int prefix = 0, ending = 0, suffix = 0; - uint postfix = 0; - uint stem; + size_t postfix = 0; + size_t stem; /* The select criteria. */ CzechGender gender; CzechChoose choose; CzechAllow allow; - if (do_prefix) prefix = SeedModChance(5, lengthof(_name_czech_adj) * 12, seed) / 12; - if (do_suffix) suffix = SeedModChance(7, lengthof(_name_czech_suffix), seed); + if (do_prefix) prefix = SeedModChance(5, std::size(_name_czech_adj) * 12, seed) / 12; + if (do_suffix) suffix = SeedModChance(7, std::size(_name_czech_suffix), seed); /* 3:1 chance 3:1 to use dynamic substantive */ stem = SeedModChance(9, - lengthof(_name_czech_subst_full) + 3 * lengthof(_name_czech_subst_stem), + std::size(_name_czech_subst_full) + 3 * std::size(_name_czech_subst_stem), seed); - if (stem < lengthof(_name_czech_subst_full)) { + if (stem < std::size(_name_czech_subst_full)) { /* That was easy! */ dynamic_subst = false; gender = _name_czech_subst_full[stem].gender; choose = _name_czech_subst_full[stem].choose; allow = _name_czech_subst_full[stem].allow; } else { - uint map[lengthof(_name_czech_subst_ending)]; + uint map[std::size(_name_czech_subst_ending)]; int ending_start = -1, ending_stop = -1; /* Load the substantive */ dynamic_subst = true; - stem -= lengthof(_name_czech_subst_full); - stem %= lengthof(_name_czech_subst_stem); + stem -= std::size(_name_czech_subst_full); + stem %= std::size(_name_czech_subst_stem); gender = _name_czech_subst_stem[stem].gender; choose = _name_czech_subst_stem[stem].choose; allow = _name_czech_subst_stem[stem].allow; /* Load the postfix (1:1 chance that a postfix will be inserted) */ - postfix = SeedModChance(14, lengthof(_name_czech_subst_postfix) * 2, seed); + postfix = SeedModChance(14, std::size(_name_czech_subst_postfix) * 2, seed); if (choose & CZC_POSTFIX) { /* Always get a real postfix. */ - postfix %= lengthof(_name_czech_subst_postfix); + postfix %= std::size(_name_czech_subst_postfix); } if (choose & CZC_NOPOSTFIX) { /* Always drop a postfix. */ - postfix += lengthof(_name_czech_subst_postfix); + postfix += std::size(_name_czech_subst_postfix); } - if (postfix < lengthof(_name_czech_subst_postfix)) { + if (postfix < std::size(_name_czech_subst_postfix)) { choose |= CZC_POSTFIX; } else { choose |= CZC_NOPOSTFIX; } /* Localize the array segment containing a good gender */ - for (ending = 0; ending < (int)lengthof(_name_czech_subst_ending); ending++) { + for (ending = 0; ending < (int)std::size(_name_czech_subst_ending); ending++) { const CzechNameSubst *e = &_name_czech_subst_ending[ending]; if (gender == CZG_FREE || @@ -715,7 +715,7 @@ static void MakeCzechTownName(StringBuilder builder, uint32_t seed) if (dynamic_subst) { builder += _name_czech_subst_stem[stem].name; - if (postfix < lengthof(_name_czech_subst_postfix)) { + if (postfix < std::size(_name_czech_subst_postfix)) { const char *poststr = _name_czech_subst_postfix[postfix]; const char *endstr = _name_czech_subst_ending[ending].name; @@ -759,7 +759,7 @@ static void MakeCzechTownName(StringBuilder builder, uint32_t seed) */ static void MakeRomanianTownName(StringBuilder builder, uint32_t seed) { - builder += _name_romanian_real[SeedChance(0, lengthof(_name_romanian_real), seed)]; + builder += _name_romanian_real[SeedChance(0, std::size(_name_romanian_real), seed)]; } @@ -770,7 +770,7 @@ static void MakeRomanianTownName(StringBuilder builder, uint32_t seed) */ static void MakeSlovakTownName(StringBuilder builder, uint32_t seed) { - builder += _name_slovak_real[SeedChance(0, lengthof(_name_slovak_real), seed)]; + builder += _name_slovak_real[SeedChance(0, std::size(_name_slovak_real), seed)]; } @@ -785,14 +785,14 @@ static void MakeNorwegianTownName(StringBuilder builder, uint32_t seed) * have a real name 3/16 chance. Bit 0-3 */ if (SeedChance(0, 15, seed) < 3) { /* Use 7bit for the realname table index. Bit 4-10 */ - builder += _name_norwegian_real[SeedChance(4, lengthof(_name_norwegian_real), seed)]; + builder += _name_norwegian_real[SeedChance(4, std::size(_name_norwegian_real), seed)]; return; } /* Use 7bit for the first fake part. Bit 4-10 */ - builder += _name_norwegian_1[SeedChance(4, lengthof(_name_norwegian_1), seed)]; + builder += _name_norwegian_1[SeedChance(4, std::size(_name_norwegian_1), seed)]; /* Use 7bit for the last fake part. Bit 11-17 */ - builder += _name_norwegian_2[SeedChance(11, lengthof(_name_norwegian_2), seed)]; + builder += _name_norwegian_2[SeedChance(11, std::size(_name_norwegian_2), seed)]; } @@ -804,21 +804,21 @@ static void MakeNorwegianTownName(StringBuilder builder, uint32_t seed) static void MakeHungarianTownName(StringBuilder builder, uint32_t seed) { if (SeedChance(12, 15, seed) < 3) { - builder += _name_hungarian_real[SeedChance(0, lengthof(_name_hungarian_real), seed)]; + builder += _name_hungarian_real[SeedChance(0, std::size(_name_hungarian_real), seed)]; return; } /* optional first segment */ - uint i = SeedChance(3, lengthof(_name_hungarian_1) * 3, seed); - if (i < lengthof(_name_hungarian_1)) builder += _name_hungarian_1[i]; + uint i = SeedChance(3, std::size(_name_hungarian_1) * 3, seed); + if (i < std::size(_name_hungarian_1)) builder += _name_hungarian_1[i]; /* mandatory middle segments */ - builder += _name_hungarian_2[SeedChance(3, lengthof(_name_hungarian_2), seed)]; - builder += _name_hungarian_3[SeedChance(6, lengthof(_name_hungarian_3), seed)]; + builder += _name_hungarian_2[SeedChance(3, std::size(_name_hungarian_2), seed)]; + builder += _name_hungarian_3[SeedChance(6, std::size(_name_hungarian_3), seed)]; /* optional last segment */ - i = SeedChance(10, lengthof(_name_hungarian_4) * 3, seed); - if (i < lengthof(_name_hungarian_4)) { + i = SeedChance(10, std::size(_name_hungarian_4) * 3, seed); + if (i < std::size(_name_hungarian_4)) { builder += _name_hungarian_4[i]; } } @@ -831,7 +831,7 @@ static void MakeHungarianTownName(StringBuilder builder, uint32_t seed) */ static void MakeSwissTownName(StringBuilder builder, uint32_t seed) { - builder += _name_swiss_real[SeedChance(0, lengthof(_name_swiss_real), seed)]; + builder += _name_swiss_real[SeedChance(0, std::size(_name_swiss_real), seed)]; } @@ -843,12 +843,12 @@ static void MakeSwissTownName(StringBuilder builder, uint32_t seed) static void MakeDanishTownName(StringBuilder builder, uint32_t seed) { /* optional first segment */ - int i = SeedChanceBias(0, lengthof(_name_danish_1), seed, 50); + int i = SeedChanceBias(0, std::size(_name_danish_1), seed, 50); if (i >= 0) builder += _name_danish_1[i]; /* middle segments removed as this algorithm seems to create much more realistic names */ - builder += _name_danish_2[SeedChance( 7, lengthof(_name_danish_2), seed)]; - builder += _name_danish_3[SeedChance(16, lengthof(_name_danish_3), seed)]; + builder += _name_danish_2[SeedChance( 7, std::size(_name_danish_2), seed)]; + builder += _name_danish_3[SeedChance(16, std::size(_name_danish_3), seed)]; } @@ -863,24 +863,24 @@ static void MakeTurkishTownName(StringBuilder builder, uint32_t seed) switch (i) { case 0: - builder += _name_turkish_prefix[SeedModChance( 2, lengthof(_name_turkish_prefix), seed)]; + builder += _name_turkish_prefix[SeedModChance( 2, std::size(_name_turkish_prefix), seed)]; /* middle segment */ - builder += _name_turkish_middle[SeedModChance( 4, lengthof(_name_turkish_middle), seed)]; + builder += _name_turkish_middle[SeedModChance( 4, std::size(_name_turkish_middle), seed)]; /* optional suffix */ if (SeedModChance(0, 7, seed) == 0) { - builder += _name_turkish_suffix[SeedModChance( 10, lengthof(_name_turkish_suffix), seed)]; + builder += _name_turkish_suffix[SeedModChance( 10, std::size(_name_turkish_suffix), seed)]; } break; case 1: case 2: - builder += _name_turkish_prefix[SeedModChance( 2, lengthof(_name_turkish_prefix), seed)]; - builder += _name_turkish_suffix[SeedModChance( 4, lengthof(_name_turkish_suffix), seed)]; + builder += _name_turkish_prefix[SeedModChance( 2, std::size(_name_turkish_prefix), seed)]; + builder += _name_turkish_suffix[SeedModChance( 4, std::size(_name_turkish_suffix), seed)]; break; default: - builder += _name_turkish_real[SeedModChance( 4, lengthof(_name_turkish_real), seed)]; + builder += _name_turkish_real[SeedModChance( 4, std::size(_name_turkish_real), seed)]; break; } } @@ -894,7 +894,7 @@ static void MakeTurkishTownName(StringBuilder builder, uint32_t seed) static void MakeItalianTownName(StringBuilder builder, uint32_t seed) { if (SeedModChance(0, 6, seed) == 0) { // real city names - builder += _name_italian_real[SeedModChance(4, lengthof(_name_italian_real), seed)]; + builder += _name_italian_real[SeedModChance(4, std::size(_name_italian_real), seed)]; return; } @@ -904,29 +904,29 @@ static void MakeItalianTownName(StringBuilder builder, uint32_t seed) }; if (SeedModChance(0, 8, seed) == 0) { // prefix - builder += _name_italian_pref[SeedModChance(11, lengthof(_name_italian_pref), seed)]; + builder += _name_italian_pref[SeedModChance(11, std::size(_name_italian_pref), seed)]; } uint i = SeedChance(0, 2, seed); if (i == 0) { // masculine form - builder += _name_italian_1m[SeedModChance(4, lengthof(_name_italian_1m), seed)]; + builder += _name_italian_1m[SeedModChance(4, std::size(_name_italian_1m), seed)]; } else { // feminine form - builder += _name_italian_1f[SeedModChance(4, lengthof(_name_italian_1f), seed)]; + builder += _name_italian_1f[SeedModChance(4, std::size(_name_italian_1f), seed)]; } if (SeedModChance(3, 3, seed) == 0) { - builder += _name_italian_2[SeedModChance(11, lengthof(_name_italian_2), seed)]; + builder += _name_italian_2[SeedModChance(11, std::size(_name_italian_2), seed)]; builder += mascul_femin_italian[i]; } else { - builder += _name_italian_2i[SeedModChance(16, lengthof(_name_italian_2i), seed)]; + builder += _name_italian_2i[SeedModChance(16, std::size(_name_italian_2i), seed)]; } if (SeedModChance(15, 4, seed) == 0) { if (SeedModChance(5, 2, seed) == 0) { // generic suffix - builder += _name_italian_3[SeedModChance(4, lengthof(_name_italian_3), seed)]; + builder += _name_italian_3[SeedModChance(4, std::size(_name_italian_3), seed)]; } else { // river name suffix - builder += _name_italian_river1[SeedModChance(4, lengthof(_name_italian_river1), seed)]; - builder += _name_italian_river2[SeedModChance(16, lengthof(_name_italian_river2), seed)]; + builder += _name_italian_river1[SeedModChance(4, std::size(_name_italian_river1), seed)]; + builder += _name_italian_river2[SeedModChance(16, std::size(_name_italian_river2), seed)]; } } } @@ -940,28 +940,28 @@ static void MakeItalianTownName(StringBuilder builder, uint32_t seed) static void MakeCatalanTownName(StringBuilder builder, uint32_t seed) { if (SeedModChance(0, 3, seed) == 0) { // real city names - builder += _name_catalan_real[SeedModChance(4, lengthof(_name_catalan_real), seed)]; + builder += _name_catalan_real[SeedModChance(4, std::size(_name_catalan_real), seed)]; return; } if (SeedModChance(0, 2, seed) == 0) { // prefix - builder += _name_catalan_pref[SeedModChance(11, lengthof(_name_catalan_pref), seed)]; + builder += _name_catalan_pref[SeedModChance(11, std::size(_name_catalan_pref), seed)]; } uint i = SeedChance(0, 2, seed); if (i == 0) { // masculine form - builder += _name_catalan_1m[SeedModChance(4, lengthof(_name_catalan_1m), seed)]; - builder += _name_catalan_2m[SeedModChance(11, lengthof(_name_catalan_2m), seed)]; + builder += _name_catalan_1m[SeedModChance(4, std::size(_name_catalan_1m), seed)]; + builder += _name_catalan_2m[SeedModChance(11, std::size(_name_catalan_2m), seed)]; } else { // feminine form - builder += _name_catalan_1f[SeedModChance(4, lengthof(_name_catalan_1f), seed)]; - builder += _name_catalan_2f[SeedModChance(11, lengthof(_name_catalan_2f), seed)]; + builder += _name_catalan_1f[SeedModChance(4, std::size(_name_catalan_1f), seed)]; + builder += _name_catalan_2f[SeedModChance(11, std::size(_name_catalan_2f), seed)]; } if (SeedModChance(15, 5, seed) == 0) { if (SeedModChance(5, 2, seed) == 0) { // generic suffix - builder += _name_catalan_3[SeedModChance(4, lengthof(_name_catalan_3), seed)]; + builder += _name_catalan_3[SeedModChance(4, std::size(_name_catalan_3), seed)]; } else { // river name suffix - builder += _name_catalan_river1[SeedModChance(4, lengthof(_name_catalan_river1), seed)]; + builder += _name_catalan_river1[SeedModChance(4, std::size(_name_catalan_river1), seed)]; } } } @@ -1008,6 +1008,6 @@ static TownNameGenerator *_town_name_generators[] = { */ void GenerateTownNameString(StringBuilder builder, size_t lang, uint32_t seed) { - assert(lang < lengthof(_town_name_generators)); + assert(lang < std::size(_town_name_generators)); return _town_name_generators[lang](builder, seed); } diff --git a/src/tracerestrict_gui.cpp b/src/tracerestrict_gui.cpp index fc5aa9b120..ec344e6a1c 100644 --- a/src/tracerestrict_gui.cpp +++ b/src/tracerestrict_gui.cpp @@ -2593,16 +2593,16 @@ public: this->ResetObjectToPlaceAction(); } - virtual void UpdateWidgetSize(WidgetID widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override + virtual void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override { switch (widget) { case TR_WIDGET_INSTRUCTION_LIST: - resize->height = GetCharacterHeight(FS_NORMAL); - size->height = 6 * resize->height + WidgetDimensions::scaled.framerect.Vertical(); + resize.height = GetCharacterHeight(FS_NORMAL); + size.height = 6 * resize.height + WidgetDimensions::scaled.framerect.Vertical(); break; case TR_WIDGET_GOTO_SIGNAL: - size->width = std::max(12, NWidgetScrollbar::GetVerticalDimension().width); + size.width = std::max(12, NWidgetScrollbar::GetVerticalDimension().width); break; } } @@ -3882,15 +3882,15 @@ public: this->Window::Close(); } - virtual void UpdateWidgetSize(WidgetID widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override + virtual void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override { switch (widget) { case WID_TRSL_LIST_SLOTS: { - size->width = this->ComputeSlotInfoSize(); - resize->height = this->tiny_step_height; + size.width = this->ComputeSlotInfoSize(); + resize.height = this->tiny_step_height; /* Minimum height is the height of the list widget minus all vehicles... */ - size->height = 4 * GetVehicleListHeight(this->vli.vtype, this->tiny_step_height) - this->tiny_step_height; + size.height = 4 * GetVehicleListHeight(this->vli.vtype, this->tiny_step_height) - this->tiny_step_height; /* ... minus the buttons at the bottom ... */ uint max_icon_height = GetSpriteSize(this->GetWidget(WID_TRSL_CREATE_SLOT)->widget_data).height; @@ -3899,27 +3899,27 @@ public: max_icon_height = std::max(max_icon_height, GetSpriteSize(this->GetWidget(WID_TRSL_SET_SLOT_MAX_OCCUPANCY)->widget_data).height); /* Get a multiple of tiny_step_height of that amount */ - size->height = Ceil(size->height - max_icon_height, tiny_step_height); + size.height = Ceil(size.height - max_icon_height, tiny_step_height); break; } case WID_TRSL_ALL_VEHICLES: - size->width = this->ComputeSlotInfoSize(); - size->height = this->tiny_step_height; + size.width = this->ComputeSlotInfoSize(); + size.height = this->tiny_step_height; break; case WID_TRSL_SORT_BY_ORDER: { Dimension d = GetStringBoundingBox(this->GetWidget(widget)->widget_data); d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better. d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } case WID_TRSL_LIST_VEHICLE: this->ComputeSlotInfoSize(); - resize->height = GetVehicleListHeight(this->vli.vtype, this->tiny_step_height); - size->height = 4 * resize->height; + resize.height = GetVehicleListHeight(this->vli.vtype, this->tiny_step_height); + size.height = 4 * resize.height; break; } } @@ -3995,7 +3995,7 @@ public: WID_TRSL_CREATE_SLOT); /* Set text of sort by dropdown */ - this->GetWidget(WID_TRSL_SORT_BY_DROPDOWN)->widget_data = this->vehicle_group_none_sorter_names[this->vehgroups.SortType()]; + this->GetWidget(WID_TRSL_SORT_BY_DROPDOWN)->widget_data = this->GetVehicleSorterNames()[this->vehgroups.SortType()]; this->GetWidget(WID_TRSL_FILTER_BY_CARGO)->widget_data = this->GetCargoFilterLabel(this->cargo_filter_criteria); @@ -4052,7 +4052,7 @@ public: break; case WID_TRSL_SORT_BY_DROPDOWN: // Select sorting criteria dropdown menu - ShowDropDownMenu(this, this->vehicle_group_none_sorter_names, this->vehgroups.SortType(), WID_TRSL_SORT_BY_DROPDOWN, 0, + ShowDropDownMenu(this, this->GetVehicleSorterNames(), this->vehgroups.SortType(), WID_TRSL_SORT_BY_DROPDOWN, 0, this->GetSorterDisableMask(this->vli.vtype)); return; @@ -4473,13 +4473,13 @@ public: this->owner = this->ctr_company; } - virtual void UpdateWidgetSize(WidgetID widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override + virtual void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override { switch (widget) { case WID_TRCL_LIST_COUNTERS: { - size->width = std::max(size->width, this->ComputeInfoSize()); - resize->height = this->tiny_step_height; - size->height = std::max(size->height, 8 * resize->height); + size.width = std::max(size.width, this->ComputeInfoSize()); + resize.height = this->tiny_step_height; + size.height = std::max(size.height, 8 * resize.height); break; } } diff --git a/src/tree_gui.cpp b/src/tree_gui.cpp index f18c836ca1..fb767ba928 100644 --- a/src/tree_gui.cpp +++ b/src/tree_gui.cpp @@ -139,13 +139,13 @@ public: this->FinishInitNested(window_number); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { if (widget >= WID_BT_TYPE_BUTTON_FIRST) { /* Ensure tree type buttons are sized after the largest tree type */ Dimension d = GetMaxTreeSpriteSize(); - size->width = d.width + padding.width; - size->height = d.height + padding.height + ScaleGUITrad(BUTTON_BOTTOM_OFFSET); // we need some more space + size.width = d.width + padding.width; + size.height = d.height + padding.height + ScaleGUITrad(BUTTON_BOTTOM_OFFSET); // we need some more space } } diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 585efd580c..7e8897d6fb 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -134,7 +134,7 @@ BaseVehicleListWindow::VehicleGroupSortFunction * const BaseVehicleListWindow::v &VehicleIndividualToGroupSorterWrapper, }; -const StringID BaseVehicleListWindow::vehicle_group_none_sorter_names[] = { +const StringID BaseVehicleListWindow::vehicle_group_none_sorter_names_calendar[] = { STR_SORT_BY_NUMBER, STR_SORT_BY_NAME, STR_SORT_BY_AGE, @@ -154,6 +154,26 @@ const StringID BaseVehicleListWindow::vehicle_group_none_sorter_names[] = { INVALID_STRING_ID }; +const StringID BaseVehicleListWindow::vehicle_group_none_sorter_names_wallclock[] = { + STR_SORT_BY_NUMBER, + STR_SORT_BY_NAME, + STR_SORT_BY_AGE, + STR_SORT_BY_PROFIT_THIS_PERIOD, + STR_SORT_BY_PROFIT_LAST_PERIOD, + STR_SORT_BY_PROFIT_LIFETIME, + STR_SORT_BY_TOTAL_CAPACITY_PER_CARGOTYPE, + STR_SORT_BY_RELIABILITY, + STR_SORT_BY_MAX_SPEED, + STR_SORT_BY_MODEL, + STR_SORT_BY_VALUE, + STR_SORT_BY_LENGTH, + STR_SORT_BY_LIFE_TIME, + STR_SORT_BY_TIMETABLE_DELAY, + STR_SORT_BY_AVG_ORDER_OCCUPANCY, + STR_SORT_BY_MAX_SPEED_LOADED, + INVALID_STRING_ID +}; + BaseVehicleListWindow::VehicleGroupSortFunction * const BaseVehicleListWindow::vehicle_group_shared_orders_sorter_funcs[] = { &VehicleGroupLengthSorter, &VehicleGroupTotalProfitThisYearSorter, @@ -163,7 +183,7 @@ BaseVehicleListWindow::VehicleGroupSortFunction * const BaseVehicleListWindow::v &VehicleGroupAverageOrderOccupancySorter, }; -const StringID BaseVehicleListWindow::vehicle_group_shared_orders_sorter_names[] = { +const StringID BaseVehicleListWindow::vehicle_group_shared_orders_sorter_names_calendar[] = { STR_SORT_BY_NUM_VEHICLES, STR_SORT_BY_TOTAL_PROFIT_THIS_YEAR, STR_SORT_BY_TOTAL_PROFIT_LAST_YEAR, @@ -173,6 +193,16 @@ const StringID BaseVehicleListWindow::vehicle_group_shared_orders_sorter_names[] INVALID_STRING_ID }; +const StringID BaseVehicleListWindow::vehicle_group_shared_orders_sorter_names_wallclock[] = { + STR_SORT_BY_NUM_VEHICLES, + STR_SORT_BY_TOTAL_PROFIT_THIS_PERIOD, + STR_SORT_BY_TOTAL_PROFIT_LAST_PERIOD, + STR_SORT_BY_AVERAGE_PROFIT_THIS_PERIOD, + STR_SORT_BY_AVERAGE_PROFIT_LAST_PERIOD, + STR_SORT_BY_AVG_ORDER_OCCUPANCY, + INVALID_STRING_ID +}; + const StringID BaseVehicleListWindow::vehicle_group_by_names[] = { STR_GROUP_BY_NONE, STR_GROUP_BY_SHARED_ORDERS, @@ -990,20 +1020,20 @@ struct RefitWindow : public Window { this->DrawWidgets(); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_VR_MATRIX: - resize->height = GetCharacterHeight(FS_NORMAL) + padding.height; - size->height = resize->height * 8; + resize.height = GetCharacterHeight(FS_NORMAL) + padding.height; + size.height = resize.height * 8; break; case WID_VR_VEHICLE_PANEL_DISPLAY: - size->height = ScaleGUITrad(GetVehicleHeight(Vehicle::Get(this->window_number)->type)); + size.height = ScaleGUITrad(GetVehicleHeight(Vehicle::Get(this->window_number)->type)); break; case WID_VR_INFO: - size->width = this->information_width + padding.height; + size.width = this->information_width + padding.height; break; } } @@ -2298,20 +2328,20 @@ public: this->RefreshRouteOverlay(); } - void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_VL_LIST: - resize->height = GetVehicleListHeight(this->vli.vtype, 1); + resize.height = GetVehicleListHeight(this->vli.vtype, 1); switch (this->vli.vtype) { case VEH_TRAIN: case VEH_ROAD: - size->height = 6 * resize->height; + size.height = 6 * resize.height; break; case VEH_SHIP: case VEH_AIRCRAFT: - size->height = 4 * resize->height; + size.height = 4 * resize.height; break; default: NOT_REACHED(); } @@ -2321,22 +2351,22 @@ public: Dimension d = GetStringBoundingBox(this->GetWidget(widget)->widget_data); d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better. d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } case WID_VL_GROUP_BY_PULLDOWN: - size->width = GetStringListWidth(this->vehicle_group_by_names) + padding.width; + size.width = GetStringListWidth(this->vehicle_group_by_names) + padding.width; break; case WID_VL_SORT_BY_PULLDOWN: - size->width = GetStringListWidth(this->vehicle_group_none_sorter_names); - size->width = std::max(size->width, GetStringListWidth(this->vehicle_group_shared_orders_sorter_names)); - size->width += padding.width; + size.width = GetStringListWidth(EconTime::UsingWallclockUnits() ? this->vehicle_group_none_sorter_names_wallclock : this->vehicle_group_none_sorter_names_calendar); + size.width = std::max(size.width, GetStringListWidth(EconTime::UsingWallclockUnits() ? this->vehicle_group_shared_orders_sorter_names_wallclock : this->vehicle_group_shared_orders_sorter_names_calendar)); + size.width += padding.width; break; case WID_VL_FILTER_BY_CARGO: - size->width = std::max(size->width, GetDropDownListDimension(this->BuildCargoDropDownList(true)).width + padding.width); + size.width = std::max(size.width, GetDropDownListDimension(this->BuildCargoDropDownList(true)).width + padding.width); break; case WID_VL_MANAGE_VEHICLES_DROPDOWN: { @@ -2344,7 +2374,7 @@ public: this->vli.vtype == VEH_TRAIN, this->GetChangeOrderStringID()); d.height += padding.height; d.width += padding.width; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } } @@ -3033,7 +3063,7 @@ struct VehicleDetailsWindow : Window { return slots; } - void UpdateWidgetSize(WidgetID widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { switch (widget) { case WID_VD_TOP_DETAILS: { @@ -3050,7 +3080,7 @@ struct VehicleDetailsWindow : Window { if (this->vehicle_slots_line_shown) lines++; if (this->vehicle_speed_restriction_line_shown) lines++; if (this->vehicle_speed_adaptation_exempt_line_shown) lines++; - size->height = lines * GetCharacterHeight(FS_NORMAL) + padding.height; + size.height = lines * GetCharacterHeight(FS_NORMAL) + padding.height; for (uint i = 0; i < 5; i++) SetDParamMaxValue(i, INT16_MAX); static const StringID info_strings[] = { @@ -3088,7 +3118,7 @@ struct VehicleDetailsWindow : Window { } SetDParam(0, STR_VEHICLE_INFO_AGE); dim = maxdim(dim, GetStringBoundingBox(this->GetRunningCostString())); - size->width = dim.width + padding.width; + size.width = dim.width + padding.width; break; } @@ -3097,11 +3127,11 @@ struct VehicleDetailsWindow : Window { switch (v->type) { case VEH_ROAD: case VEH_SHIP: - size->height = this->GetRoadOrShipVehDetailsHeight(v) + padding.height; + size.height = this->GetRoadOrShipVehDetailsHeight(v) + padding.height; break; case VEH_AIRCRAFT: - size->height = 5 * GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal * 2 + padding.height; + size.height = 5 * GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal * 2 + padding.height; break; default: @@ -3111,8 +3141,8 @@ struct VehicleDetailsWindow : Window { } case WID_VD_MATRIX: - resize->height = std::max(ScaleGUITrad(14), GetCharacterHeight(FS_NORMAL) + padding.height); - size->height = 4 * resize->height; + resize.height = std::max(ScaleGUITrad(14), GetCharacterHeight(FS_NORMAL) + padding.height); + size.height = 4 * resize.height; break; case WID_VD_SERVICE_INTERVAL_DROPDOWN: { @@ -3125,7 +3155,7 @@ struct VehicleDetailsWindow : Window { } d.width += padding.width; d.height += padding.height; - *size = maxdim(*size, d); + size = maxdim(size, d); break; } @@ -3142,11 +3172,11 @@ struct VehicleDetailsWindow : Window { /* Vehicle was last serviced at year 0, and we're at max year */ SetDParamMaxValue(2, EconTime::DateAtStartOfYear(EconTime::MAX_YEAR)); } - size->width = std::max( + size.width = std::max( GetStringBoundingBox(STR_VEHICLE_DETAILS_SERVICING_INTERVAL_PERCENT).width, GetStringBoundingBox(STR_VEHICLE_DETAILS_SERVICING_INTERVAL_DAYS).width ) + padding.width; - size->height = GetCharacterHeight(FS_NORMAL) + padding.height; + size.height = GetCharacterHeight(FS_NORMAL) + padding.height; break; } } @@ -3919,24 +3949,24 @@ public: } } - void UpdateWidgetSize(WidgetID widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override { const Vehicle *v = Vehicle::Get(this->window_number); switch (widget) { case WID_VV_START_STOP: - size->height = std::max({size->height, (uint)GetCharacterHeight(FS_NORMAL), GetScaledSpriteSize(SPR_WARNING_SIGN).height, GetScaledSpriteSize(SPR_FLAG_VEH_STOPPED).height, GetScaledSpriteSize(SPR_FLAG_VEH_RUNNING).height}) + padding.height; + size.height = std::max({size.height, (uint)GetCharacterHeight(FS_NORMAL), GetScaledSpriteSize(SPR_WARNING_SIGN).height, GetScaledSpriteSize(SPR_FLAG_VEH_STOPPED).height, GetScaledSpriteSize(SPR_FLAG_VEH_RUNNING).height}) + padding.height; break; case WID_VV_FORCE_PROCEED: if (v->type != VEH_TRAIN) { - size->height = 0; - size->width = 0; + size.height = 0; + size.width = 0; } break; case WID_VV_VIEWPORT: - size->width = VV_INITIAL_VIEWPORT_WIDTH; - size->height = (v->type == VEH_TRAIN) ? VV_INITIAL_VIEWPORT_HEIGHT_TRAIN : VV_INITIAL_VIEWPORT_HEIGHT; + size.width = VV_INITIAL_VIEWPORT_WIDTH; + size.height = (v->type == VEH_TRAIN) ? VV_INITIAL_VIEWPORT_HEIGHT_TRAIN : VV_INITIAL_VIEWPORT_HEIGHT; break; } } diff --git a/src/vehicle_gui_base.h b/src/vehicle_gui_base.h index 22647a64fd..390734e4dd 100644 --- a/src/vehicle_gui_base.h +++ b/src/vehicle_gui_base.h @@ -120,8 +120,10 @@ public: static const StringID vehicle_depot_sell_name[]; static const StringID vehicle_group_by_names[]; - static const StringID vehicle_group_none_sorter_names[]; - static const StringID vehicle_group_shared_orders_sorter_names[]; + static const StringID vehicle_group_none_sorter_names_calendar[]; + static const StringID vehicle_group_none_sorter_names_wallclock[]; + static const StringID vehicle_group_shared_orders_sorter_names_calendar[]; + static const StringID vehicle_group_shared_orders_sorter_names_wallclock[]; static VehicleGroupSortFunction * const vehicle_group_none_sorter_funcs[]; static VehicleGroupSortFunction * const vehicle_group_shared_orders_sorter_funcs[]; @@ -151,9 +153,9 @@ public: { switch (this->grouping) { case GB_NONE: - return vehicle_group_none_sorter_names; + return EconTime::UsingWallclockUnits() ? vehicle_group_none_sorter_names_wallclock : vehicle_group_none_sorter_names_calendar; case GB_SHARED_ORDERS: - return vehicle_group_shared_orders_sorter_names; + return EconTime::UsingWallclockUnits() ? vehicle_group_shared_orders_sorter_names_wallclock : vehicle_group_shared_orders_sorter_names_calendar; default: NOT_REACHED(); } diff --git a/src/video/allegro_v.cpp b/src/video/allegro_v.cpp index 52eea85d08..c24b7cb5b4 100644 --- a/src/video/allegro_v.cpp +++ b/src/video/allegro_v.cpp @@ -250,8 +250,8 @@ struct AllegroVkMapping { uint8_t map_to; }; -#define AS(x, z) {x, 0, z} -#define AM(x, y, z, w) {x, y - x, z} +#define AS(x, z) {x, 1, z} +#define AM(x, y, z, w) {x, y - x + 1, z} static const AllegroVkMapping _vk_mapping[] = { /* Pageup stuff + up/down */ @@ -311,12 +311,11 @@ static uint32_t ConvertAllegroKeyIntoMy(char32_t *character) int scancode; int unicode = ureadkey(&scancode); - const AllegroVkMapping *map; uint key = 0; - for (map = _vk_mapping; map != endof(_vk_mapping); ++map) { - if ((uint)(scancode - map->vk_from) <= map->vk_count) { - key = scancode - map->vk_from + map->map_to; + for (const auto &map : _vk_mapping) { + if (IsInsideBS(scancode, map.vk_from, map.vk_count)) { + key = scancode - map.vk_from + map.map_to; break; } } diff --git a/src/video/sdl2_v.cpp b/src/video/sdl2_v.cpp index 2f1bc4b9d4..5ac99c7f8a 100644 --- a/src/video/sdl2_v.cpp +++ b/src/video/sdl2_v.cpp @@ -524,7 +524,7 @@ struct SDLVkMapping { const bool unprintable; constexpr SDLVkMapping(SDL_Keycode vk_first, SDL_Keycode vk_last, uint8_t map_first, [[maybe_unused]] uint8_t map_last, bool unprintable) - : vk_from(vk_first), vk_count(vk_last - vk_first), map_to(map_first), unprintable(unprintable) + : vk_from(vk_first), vk_count(vk_last - vk_first + 1), map_to(map_first), unprintable(unprintable) { assert((vk_last - vk_first) == (map_last - map_first)); } @@ -600,14 +600,13 @@ static constexpr SDLVkMapping _vk_mapping[] = { static uint ConvertSdlKeyIntoMy(SDL_Keysym *sym, char32_t *character) { - const SDLVkMapping *map; uint key = 0; bool unprintable = false; - for (map = _vk_mapping; map != endof(_vk_mapping); ++map) { - if ((uint)(sym->sym - map->vk_from) <= map->vk_count) { - key = sym->sym - map->vk_from + map->map_to; - unprintable = map->unprintable; + for (const auto &map : _vk_mapping) { + if (IsInsideBS(sym->sym, map.vk_from, map.vk_count)) { + key = sym->sym - map.vk_from + map.map_to; + unprintable = map.unprintable; break; } } @@ -640,12 +639,11 @@ static uint ConvertSdlKeyIntoMy(SDL_Keysym *sym, char32_t *character) */ static uint ConvertSdlKeycodeIntoMy(SDL_Keycode kc) { - const SDLVkMapping *map; uint key = 0; - for (map = _vk_mapping; map != endof(_vk_mapping); ++map) { - if ((uint)(kc - map->vk_from) <= map->vk_count) { - key = kc - map->vk_from + map->map_to; + for (const auto &map : _vk_mapping) { + if (IsInsideBS(kc, map.vk_from, map.vk_count)) { + key = kc - map.vk_from + map.map_to; break; } } diff --git a/src/video/sdl_v.cpp b/src/video/sdl_v.cpp index 52aabda419..3fb20e8770 100644 --- a/src/video/sdl_v.cpp +++ b/src/video/sdl_v.cpp @@ -383,7 +383,7 @@ struct SDLVkMapping { const uint8_t map_to; constexpr SDLVkMapping(SDL_Keycode vk_first, SDL_Keycode vk_last, uint8_t map_first, [[maybe_unused]] uint8_t map_last) - : vk_from(vk_first), vk_count(vk_last - vk_first), map_to(map_first) + : vk_from(vk_first), vk_count(vk_last - vk_first + 1), map_to(map_first) { assert((vk_last - vk_first) == (map_last - map_first)); } @@ -447,12 +447,11 @@ static constexpr SDLVkMapping _vk_mapping[] = { static uint ConvertSdlKeyIntoMy(SDL_keysym *sym, char32_t *character) { - const SDLVkMapping *map; uint key = 0; - for (map = _vk_mapping; map != endof(_vk_mapping); ++map) { - if ((uint)(sym->sym - map->vk_from) <= map->vk_count) { - key = sym->sym - map->vk_from + map->map_to; + for (const auto &map : _vk_mapping) { + if (IsInsideBS(sym->sym, map.vk_from, map.vk_count)) { + key = sym->sym - map.vk_from + map.map_to; break; } } diff --git a/src/video/win32_v.cpp b/src/video/win32_v.cpp index 1460792cc0..de48ddbcb2 100644 --- a/src/video/win32_v.cpp +++ b/src/video/win32_v.cpp @@ -62,8 +62,8 @@ struct Win32VkMapping { uint8_t map_to; }; -#define AS(x, z) {x, 0, z} -#define AM(x, y, z, w) {x, y - x, z} +#define AS(x, z) {x, 1, z} +#define AM(x, y, z, w) {x, y - x + 1, z} static const Win32VkMapping _vk_mapping[] = { /* Pageup stuff + up/down */ @@ -108,12 +108,11 @@ static const Win32VkMapping _vk_mapping[] = { static uint MapWindowsKey(uint sym) { - const Win32VkMapping *map; uint key = 0; - for (map = _vk_mapping; map != endof(_vk_mapping); ++map) { - if ((uint)(sym - map->vk_from) <= map->vk_count) { - key = sym - map->vk_from + map->map_to; + for (const auto &map : _vk_mapping) { + if (IsInsideBS(sym, map.vk_from, map.vk_count)) { + key = sym - map.vk_from + map.map_to; break; } } diff --git a/src/viewport.cpp b/src/viewport.cpp index 60043d7ca4..ab8cb5cc25 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -1953,7 +1953,7 @@ void ViewportAddString(ViewportDrawerDynamic *vdd, const DrawPixelInfo *dpi, Zoo int right = left + dpi->width; int bottom = top + dpi->height; - int sign_height = ScaleByZoom(WidgetDimensions::scaled.fullbevel.top + GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.fullbevel.bottom, dpi->zoom); + int sign_height = ScaleByZoom(WidgetDimensions::scaled.fullbevel.top + GetCharacterHeight(small ? FS_SMALL : FS_NORMAL) + WidgetDimensions::scaled.fullbevel.bottom, dpi->zoom); int sign_half_width = ScaleByZoom((small ? sign->width_small : sign->width_normal) / 2, dpi->zoom); if (bottom < sign->top || @@ -1978,8 +1978,7 @@ void ViewportAddString(ViewportDrawerDynamic *vdd, const DrawPixelInfo *dpi, Zoo static Rect ExpandRectWithViewportSignMargins(Rect r, ZoomLevel zoom) { - /* Pessimistically always use normal font, but also assume small font is never larger in either dimension */ - const int fh = GetCharacterHeight(FS_NORMAL); + const int fh = std::max(GetCharacterHeight(FS_NORMAL), GetCharacterHeight(FS_SMALL)); const int max_tw = _viewport_sign_maxwidth / 2 + 1; const int expand_y = ScaleByZoom(WidgetDimensions::scaled.fullbevel.top + fh + WidgetDimensions::scaled.fullbevel.bottom, zoom); const int expand_x = ScaleByZoom(WidgetDimensions::scaled.fullbevel.left + max_tw + WidgetDimensions::scaled.fullbevel.right, zoom); @@ -2132,13 +2131,16 @@ void ViewportSign::MarkDirty(ZoomLevel maxzoom) const Rect zoomlevels[ZOOM_LVL_END]; + const uint small_height = WidgetDimensions::scaled.fullbevel.top + GetCharacterHeight(FS_SMALL) + WidgetDimensions::scaled.fullbevel.bottom + 1; + const uint normal_height = WidgetDimensions::scaled.fullbevel.top + GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.fullbevel.bottom + 1; + for (ZoomLevel zoom = ZOOM_LVL_BEGIN; zoom != ZOOM_LVL_END; zoom++) { const ZoomLevel small_from = (maxzoom == ZOOM_LVL_OUT_2X) ? ZOOM_LVL_OUT_2X : ZOOM_LVL_OUT_4X; - const int width = (zoom >= small_from) ? this->width_small : this->width_normal ; + const int width = (zoom >= small_from) ? this->width_small : this->width_normal; zoomlevels[zoom].left = this->center - ScaleByZoom(width / 2 + 1, zoom); zoomlevels[zoom].top = this->top - ScaleByZoom(1, zoom); zoomlevels[zoom].right = this->center + ScaleByZoom(width / 2 + 1, zoom); - zoomlevels[zoom].bottom = this->top + ScaleByZoom(WidgetDimensions::scaled.fullbevel.top + GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.fullbevel.bottom + 1, zoom); + zoomlevels[zoom].bottom = this->top + ScaleByZoom((zoom >= small_from) ? small_height : normal_height, zoom); } for (Viewport *vp : _viewport_window_cache) { @@ -2463,7 +2465,7 @@ static void ViewportDrawStrings(ViewportDrawerDynamic *vdd, ZoomLevel zoom, cons int w = GB(ss.width, 0, 15); int x = UnScaleByZoom(ss.x, zoom); int y = UnScaleByZoom(ss.y, zoom); - int h = WidgetDimensions::scaled.fullbevel.Vertical() + (small ? GetCharacterHeight(FS_SMALL) : GetCharacterHeight(FS_NORMAL)); + int h = WidgetDimensions::scaled.fullbevel.Vertical() + GetCharacterHeight(small ? FS_SMALL : FS_NORMAL); SetDParam(0, ss.params[0]); SetDParam(1, ss.params[1]); @@ -5013,7 +5015,7 @@ static bool CheckClickOnViewportSign(const Viewport *vp, int x, int y, const Vie { bool small = (vp->zoom >= ZOOM_LVL_OUT_4X); int sign_half_width = ScaleByZoom((small ? sign->width_small : sign->width_normal) / 2, vp->zoom); - int sign_height = ScaleByZoom(WidgetDimensions::scaled.fullbevel.top + (small ? GetCharacterHeight(FS_SMALL) : GetCharacterHeight(FS_NORMAL)) + WidgetDimensions::scaled.fullbevel.bottom, vp->zoom); + int sign_height = ScaleByZoom(WidgetDimensions::scaled.fullbevel.top + GetCharacterHeight(small ? FS_SMALL : FS_NORMAL) + WidgetDimensions::scaled.fullbevel.bottom, vp->zoom); return y >= sign->top && y < sign->top + sign_height && x >= sign->center - sign_half_width && x < sign->center + sign_half_width; @@ -5117,7 +5119,7 @@ ViewportSignKdtreeItem ViewportSignKdtreeItem::MakeStation(StationID id) item.top = st->sign.top; /* Assume the sign can be a candidate for drawing, so measure its width */ - _viewport_sign_maxwidth = std::max(_viewport_sign_maxwidth, st->sign.width_normal); + _viewport_sign_maxwidth = std::max({_viewport_sign_maxwidth, st->sign.width_normal, st->sign.width_small}); return item; } @@ -5134,7 +5136,7 @@ ViewportSignKdtreeItem ViewportSignKdtreeItem::MakeWaypoint(StationID id) item.top = st->sign.top; /* Assume the sign can be a candidate for drawing, so measure its width */ - _viewport_sign_maxwidth = std::max(_viewport_sign_maxwidth, st->sign.width_normal); + _viewport_sign_maxwidth = std::max({_viewport_sign_maxwidth, st->sign.width_normal, st->sign.width_small}); return item; } @@ -5151,7 +5153,7 @@ ViewportSignKdtreeItem ViewportSignKdtreeItem::MakeTown(TownID id) item.top = town->cache.sign.top; /* Assume the sign can be a candidate for drawing, so measure its width */ - _viewport_sign_maxwidth = std::max(_viewport_sign_maxwidth, town->cache.sign.width_normal); + _viewport_sign_maxwidth = std::max({_viewport_sign_maxwidth, town->cache.sign.width_normal, town->cache.sign.width_small}); return item; } @@ -5168,7 +5170,7 @@ ViewportSignKdtreeItem ViewportSignKdtreeItem::MakeSign(SignID id) item.top = sign->sign.top; /* Assume the sign can be a candidate for drawing, so measure its width */ - _viewport_sign_maxwidth = std::max(_viewport_sign_maxwidth, sign->sign.width_normal); + _viewport_sign_maxwidth = std::max({_viewport_sign_maxwidth, sign->sign.width_normal, sign->sign.width_small}); return item; } diff --git a/src/widget.cpp b/src/widget.cpp index decbaf9bed..0532b51d9a 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -1234,7 +1234,7 @@ void NWidgetStacked::SetupSmallestSize(Window *w) Dimension fill = {(this->shown_plane == SZSP_HORIZONTAL), (this->shown_plane == SZSP_VERTICAL)}; Dimension resize = {(this->shown_plane == SZSP_HORIZONTAL), (this->shown_plane == SZSP_VERTICAL)}; /* Here we're primarily interested in the value of resize */ - if (this->index >= 0) w->UpdateWidgetSize(this->index, &size, padding, &fill, &resize); + if (this->index >= 0) w->UpdateWidgetSize(this->index, size, padding, fill, resize); this->smallest_x = size.width; this->smallest_y = size.height; @@ -1881,7 +1881,7 @@ void NWidgetMatrix::SetupSmallestSize(Window *w) Dimension fill = {0, 0}; Dimension resize = {this->pip_inter + this->children.front()->smallest_x, this->pip_inter + this->children.front()->smallest_y}; - if (this->index >= 0) w->UpdateWidgetSize(this->index, &size, padding, &fill, &resize); + if (this->index >= 0) w->UpdateWidgetSize(this->index, size, padding, fill, resize); this->smallest_x = size.width; this->smallest_y = size.height; @@ -2166,7 +2166,7 @@ void NWidgetBackground::SetupSmallestSize(Window *w) case WWT_FRAME: padding = {WidgetDimensions::scaled.frametext.Horizontal(), WidgetDimensions::scaled.frametext.Vertical()}; break; case WWT_INSET: padding = {WidgetDimensions::scaled.inset.Horizontal(), WidgetDimensions::scaled.inset.Vertical()}; break; } - w->UpdateWidgetSize(this->index, &d, padding, &fill, &resize); + w->UpdateWidgetSize(this->index, d, padding, fill, resize); } } this->smallest_x = d.width; @@ -2808,7 +2808,7 @@ void NWidgetLeaf::SetupSmallestSize(Window *w) NOT_REACHED(); } - if (this->index >= 0) w->UpdateWidgetSize(this->index, &size, padding, &fill, &resize); + if (this->index >= 0) w->UpdateWidgetSize(this->index, size, padding, fill, resize); this->smallest_x = size.width; this->smallest_y = size.height; diff --git a/src/window_gui.h b/src/window_gui.h index 733a01d0ba..c3b60c6bd7 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -651,12 +651,12 @@ public: * and \a resize is taken to contain the resize steps. For the convenience of the callee, \a padding contains the amount of * padding between the content and the edge of the widget. This should be added to the returned size. * @param widget Widget number. - * @param size Size of the widget. + * @param[in,out] size Size of the widget. * @param padding Recommended amount of space between the widget content and the widget edge. - * @param fill Fill step of the widget. - * @param resize Resize step of the widget. + * @param[in,out] fill Fill step of the widget. + * @param[in,out] resize Resize step of the widget. */ - virtual void UpdateWidgetSize([[maybe_unused]] WidgetID widget, [[maybe_unused]] Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) {} + virtual void UpdateWidgetSize([[maybe_unused]] WidgetID widget, [[maybe_unused]] Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) {} /** * Initialize string parameters for a widget. diff --git a/src/zoning_gui.cpp b/src/zoning_gui.cpp index c6c0bb6926..03b4fe7c23 100644 --- a/src/zoning_gui.cpp +++ b/src/zoning_gui.cpp @@ -139,22 +139,22 @@ struct ZoningWindow : public Window { } } - void UpdateWidgetSize(WidgetID widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override + void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override { switch (widget) { case ZTW_OUTER_DROPDOWN: case ZTW_INNER_DROPDOWN: for (const ZoningModeInfo &info : _zone_modes) { SetDParamStr(0, info.param); - *size = maxdim(*size, GetStringBoundingBox(info.str)); + size = maxdim(size, GetStringBoundingBox(info.str)); } break; default: return; } - size->width += padding.width; - size->height = GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.dropdowntext.Vertical(); + size.width += padding.width; + size.height = GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.dropdowntext.Vertical(); } };