Utility class for menu navigation. It clamps a new selection index within bounds, triggers optional selector animations (move or wobble), plays a menu blip sound effect and a haptic tick, and returns the updated index.
using System;
namespace BlockParty;
/// <summary>
/// One vertical step through a fixed, small menu (title / level-select / options rows / the score
/// screen's bottom buttons): clamp the index to the list, play the selector cube's slide (or an
/// end-of-list wobble when it can't move), and fire the standard nav blip sfx + haptic.
///
/// This is the single source for how those menus navigate and feel. Each stage used to hand-roll the
/// identical body and they had drifted apart — the score-screen buttons were missing the haptic tick.
/// The scrolling leaderboard/replay lists are a separate shared path (<see cref="VirtualListPanel"/>)
/// because they pitch the blip by row index and cycle through a BACK pseudo-item.
/// </summary>
public static class MenuNav
{
/// <summary>Move <paramref name="current"/> by <paramref name="delta"/> within [0, count) and
/// return the new index, animating <paramref name="selector"/> and playing the blip. Selector is
/// optional: the title menu's image-button row has no cube but shares the nav feel.</summary>
public static int Step( int current, int delta, int count, MenuSelectorAnim selector = null )
{
int next = Math.Clamp( current + delta, 0, count - 1 );
if ( next != current )
selector?.PlayMove();
else
selector?.PlayWobble(); // bumped the top/bottom of the list
Audio.PlaySfx( SfxType.MenuBlip );
Haptics.MenuBlip();
return next;
}
}