Esempio n. 1
0
        /// <summary>
        /// Change the selected mod index of this button.
        /// </summary>
        /// <param name="newIndex">The new index.</param>
        /// <param name="resetSettings">Whether any settings applied to the mod should be reset on selection.</param>
        /// <returns>Whether the selection changed.</returns>
        private bool changeSelectedIndex(int newIndex, bool resetSettings = true)
        {
            if (newIndex == selectedIndex)
            {
                return(false);
            }

            int direction = newIndex < selectedIndex ? -1 : 1;

            bool beforeSelected = Selected;

            Mod previousSelection = SelectedMod ?? Mods[0];

            if (newIndex >= Mods.Length)
            {
                newIndex = -1;
            }
            else if (newIndex < -1)
            {
                newIndex = Mods.Length - 1;
            }

            if (newIndex >= 0 && !Mods[newIndex].HasImplementation)
            {
                return(false);
            }

            selectedIndex = newIndex;

            Mod newSelection = SelectedMod ?? Mods[0];

            if (resetSettings)
            {
                newSelection.ResetSettingsToDefaults();
            }

            Schedule(() =>
            {
                if (beforeSelected != Selected)
                {
                    iconsContainer.RotateTo(Selected ? 5f : 0f, 300, Easing.OutElastic);
                    iconsContainer.ScaleTo(Selected ? 1.1f : 1f, 300, Easing.OutElastic);
                }

                if (previousSelection != newSelection)
                {
                    const float rotate_angle = 16;

                    foregroundIcon.RotateTo(rotate_angle * direction, mod_switch_duration, mod_switch_easing);
                    backgroundIcon.RotateTo(-rotate_angle * direction, mod_switch_duration, mod_switch_easing);

                    backgroundIcon.Mod = newSelection;

                    using (BeginDelayedSequence(mod_switch_duration, true))
                    {
                        foregroundIcon
                        .RotateTo(-rotate_angle * direction)
                        .RotateTo(0f, mod_switch_duration, mod_switch_easing);

                        backgroundIcon
                        .RotateTo(rotate_angle * direction)
                        .RotateTo(0f, mod_switch_duration, mod_switch_easing);

                        Schedule(() => displayMod(newSelection));
                    }
                }

                foregroundIcon.Selected.Value = Selected;
            });

            SelectionChanged?.Invoke(SelectedMod);

            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Change the selected mod index of this button.
        /// </summary>
        /// <param name="newIndex">The new index.</param>
        /// <returns>Whether the selection changed.</returns>
        private bool changeSelectedIndex(int newIndex)
        {
            if (newIndex == selectedIndex)
            {
                return(false);
            }

            int  direction      = newIndex < selectedIndex ? -1 : 1;
            bool beforeSelected = Selected;

            Mod modBefore = SelectedMod ?? Mods[0];

            if (newIndex >= Mods.Length)
            {
                newIndex = -1;
            }
            else if (newIndex < -1)
            {
                newIndex = Mods.Length - 1;
            }

            if (newIndex >= 0 && !Mods[newIndex].HasImplementation)
            {
                return(false);
            }

            selectedIndex = newIndex;
            Mod modAfter = SelectedMod ?? Mods[0];

            if (beforeSelected != Selected)
            {
                iconsContainer.RotateTo(Selected ? 5f : 0f, 300, Easing.OutElastic);
                iconsContainer.ScaleTo(Selected ? 1.1f : 1f, 300, Easing.OutElastic);
            }

            if (modBefore != modAfter)
            {
                const float rotate_angle = 16;

                foregroundIcon.RotateTo(rotate_angle * direction, mod_switch_duration, mod_switch_easing);
                backgroundIcon.RotateTo(-rotate_angle * direction, mod_switch_duration, mod_switch_easing);

                backgroundIcon.Icon = modAfter.Icon;

                using (BeginDelayedSequence(mod_switch_duration, true))
                {
                    foregroundIcon
                    .RotateTo(-rotate_angle * direction)
                    .RotateTo(0f, mod_switch_duration, mod_switch_easing);

                    backgroundIcon
                    .RotateTo(rotate_angle * direction)
                    .RotateTo(0f, mod_switch_duration, mod_switch_easing);

                    Schedule(() => displayMod(modAfter));
                }
            }

            foregroundIcon.Highlighted.Value = Selected;

            SelectionChanged?.Invoke(SelectedMod);
            return(true);
        }