MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / MakeTreeTypeButtons

Function MakeTreeTypeButtons

src/tree_gui.cpp:259–286  ·  view source on GitHub ↗

* Make widgets for the current available tree types. * This does not use a NWID_MATRIX or WWT_MATRIX control as those are more difficult to * get producing the correct result than dynamically building the widgets is. * @see NWidgetFunctionType */

Source from the content-addressed store, hash-verified

257 * @see NWidgetFunctionType
258 */
259static std::unique_ptr<NWidgetBase> MakeTreeTypeButtons()
260{
261 const uint8_t type_base = _tree_base_by_landscape[to_underlying(_settings_game.game_creation.landscape)];
262 const uint8_t type_count = _tree_count_by_landscape[to_underlying(_settings_game.game_creation.landscape)];
263
264 /* Toyland has 9 tree types, which look better in 3x3 than 4x3 */
265 const int num_columns = type_count == 9 ? 3 : 4;
266 const int num_rows = CeilDiv(type_count, num_columns);
267 uint8_t cur_type = type_base;
268
269 auto vstack = std::make_unique<NWidgetVertical>(NWidContainerFlag::EqualSize);
270 vstack->SetPIP(0, 1, 0);
271
272 for (int row = 0; row < num_rows; row++) {
273 auto hstack = std::make_unique<NWidgetHorizontal>(NWidContainerFlag::EqualSize);
274 hstack->SetPIP(0, 1, 0);
275 for (int col = 0; col < num_columns; col++) {
276 if (cur_type > type_base + type_count) break;
277 auto button = std::make_unique<NWidgetBackground>(WWT_PANEL, COLOUR_GREY, WID_BT_TYPE_BUTTON_FIRST + cur_type);
278 button->SetToolTip(STR_PLANT_TREE_TOOLTIP);
279 hstack->Add(std::move(button));
280 cur_type++;
281 }
282 vstack->Add(std::move(hstack));
283 }
284
285 return vstack;
286}
287
288static constexpr std::initializer_list<NWidgetPart> _nested_build_trees_widgets = {
289 NWidget(NWID_HORIZONTAL),

Callers

nothing calls this directly

Calls 5

to_underlyingFunction · 0.85
CeilDivFunction · 0.85
SetPIPMethod · 0.80
SetToolTipMethod · 0.80
AddMethod · 0.45

Tested by

no test coverage detected