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

Function BadgeClassMovePrevious

src/newgrf_badge_gui.cpp:403–425  ·  view source on GitHub ↗

* Move the badge class to the previous position. * @param feature Feature being used. * @param class_badge Class badge. */

Source from the content-addressed store, hash-verified

401 * @param class_badge Class badge.
402 */
403static void BadgeClassMovePrevious(GrfSpecFeature feature, Badge &class_badge)
404{
405 GUIBadgeClasses gui_classes(feature);
406 if (gui_classes.GetClasses().empty()) return;
407
408 auto config = GetBadgeClassConfiguration(feature);
409 auto it = std::ranges::find(config, class_badge.label, &BadgeClassConfigItem::label);
410 if (it == std::end(config)) return;
411
412 auto pos_cur = std::ranges::find(gui_classes.GetClasses(), class_badge.class_index, &GUIBadgeClasses::Element::class_index);
413 if (pos_cur == std::begin(gui_classes.GetClasses())) {
414 if (it->column > 0) --it->column;
415 return;
416 }
417
418 auto pos_prev = std::ranges::find(config, std::prev(pos_cur)->label, &BadgeClassConfigItem::label);
419 if (it->column > pos_prev->column) {
420 --it->column;
421 } else {
422 /* Rotate elements right so that it is placed before pos_prev, maintaining order of non-visible elements. */
423 std::rotate(pos_prev, it, std::next(it));
424 }
425}
426
427/**
428 * Move the badge class to the next position.

Callers 1

Calls 6

GetClassesMethod · 0.80
findFunction · 0.50
endFunction · 0.50
beginFunction · 0.50
emptyMethod · 0.45

Tested by

no test coverage detected