55using Celeste . Mod . Core ;
66using Celeste . Mod . UI ;
77using Microsoft . Xna . Framework ;
8+ using Monocle ;
89using MonoMod ;
910using System ;
1011using System . Collections . Generic ;
@@ -29,17 +30,15 @@ class patch_OuiMainMenu : OuiMainMenu {
2930 }
3031
3132 private bool needsRebuild = false ;
32- private int selectedIndex ;
33- private int offsetFactor ;
34- private Vector2 regularButtonOffset ;
33+ private float regularButtonOffset ;
3534
3635 public extern void orig_CreateButtons ( ) ;
3736 public new void CreateButtons ( ) {
3837 orig_CreateButtons ( ) ;
3938
4039 // assume the second button have a regular height
4140 // only the Climb button is taller
42- regularButtonOffset = buttons [ 1 ] . ButtonHeight * - Vector2 . UnitY ;
41+ regularButtonOffset = buttons [ 1 ] . ButtonHeight ;
4342
4443 Everest . Events . MainMenu . CreateButtons ( this , buttons ) ;
4544
@@ -60,34 +59,28 @@ public void NeedsRebuild() {
6059
6160 // no mode -> vanilla menu, only apply scroll in vanilla menu
6261 if ( CoreModule . Settings . MainMenuMode == "" ) {
63- ScrollButtonsIfNeeded ( ) ;
62+ ScrollButtons ( ) ;
6463 }
6564
6665 orig_Update ( ) ;
6766 }
6867
69- //TODO: scrolling is not smooth, implement smooth scrolling
70- private void ScrollButtonsIfNeeded ( ) {
71- int newSelectedIndex = 0 ;
68+ private void ScrollButtons ( ) {
69+ int selectedIndex = 0 ;
7270 for ( int i = 0 ; i < buttons . Count ; i ++ ) {
7371 if ( buttons [ i ] . Selected ) {
74- newSelectedIndex = i ;
72+ selectedIndex = i ;
7573 break ;
7674 }
7775 }
7876
79- // only attempt to scroll if selection changed
80- if ( selectedIndex != newSelectedIndex ) {
81- int newOffsetFactor = Math . Max ( 0 , newSelectedIndex - 6 ) ;
82- // only scroll if needed (7th or further button selected)
83- if ( offsetFactor != newOffsetFactor ) {
84- foreach ( MenuButton button in buttons ) {
85- // handle wrapping from last to first button, which resets position
86- button . Position += regularButtonOffset * ( newOffsetFactor - offsetFactor ) ;
87- }
88- offsetFactor = newOffsetFactor ;
89- }
90- selectedIndex = newSelectedIndex ;
77+ // only scroll if needed (7th or further button selected)
78+ float offsetTarget = Math . Max ( 0 , selectedIndex - 6 ) * regularButtonOffset ;
79+ float buttonYPosition = 160f ; // start of menu
80+ foreach ( MenuButton button in buttons ) {
81+ float targetPosition = buttonYPosition - offsetTarget ;
82+ buttonYPosition += button . ButtonHeight ;
83+ button . Position . Y += ( targetPosition - button . Position . Y ) * ( 1f - ( float ) Math . Pow ( 0.009999999776482582 , Engine . DeltaTime ) ) ;
9184 }
9285 }
9386
0 commit comments