Пример #1
0
        /// <summary>
        ///     Selects a new select map/mapset.
        /// </summary>
        public void SelectMap(int mapsetIndex, Map map, bool forceSelect = false)
        {
            var currentMapsetIndex = SelectedMapsetIndex;

            // Check if the same mapset is being selected.
            if (currentMapsetIndex == mapsetIndex && !forceSelect)
            {
                Logger.Debug("Changing to same mapset.", LogType.Runtime);
                return;
            }

            // Find the currently selected mapset.
            var selectedMapsetIndex = MapsetBuffer.Find(x => x.MapsetIndex == SelectedMapsetIndex);
            var selectedMapset      = Screen.AvailableMapsets[SelectedMapsetIndex];

            var nextMapsetIndex = MapsetBuffer.Find(x => x.MapsetIndex == mapsetIndex);
            var nextMapset      = Screen.AvailableMapsets[mapsetIndex];

            // Set the new mapset.
            SelectedMapsetIndex = mapsetIndex;

            // Grab a reference to the previous map.
            var previousMap = MapManager.Selected.Value;

            // Update the newly selected map.
            MapManager.Selected.Value = map;

            // Set the preferred map to this, so that if the user switches back and forth sets,
            // it'll be on the same one.
            nextMapset.PreferredMap = map;

            // Grab a reference to the difficulty scroll container.
            var diffContainer = View.DifficultyScrollContainer;

            // Grab the new selected map index.
            diffContainer.SelectedMapIndex = map.Mapset.Maps.FindIndex(x => x == map);

            // Grab the currently active scroll container before switching.
            var activeContainer = View.ActiveContainer;

            // Switching to a different mapset so we need to reinitialize difficulties.
            if (selectedMapset != nextMapset)
            {
                diffContainer.Visible = false;
                diffContainer.ContentContainer.Visible = false;
                diffContainer.X = diffContainer.Width;
                View.SwitchToContainer(SelectContainerStatus.Mapsets);

                // Since we're changing sets, initailize the new difficulties for the set.
                diffContainer.ReInitializeDifficulties();
            }
            // Switching to a different map in the set, so all that's needed is just scrolling to it.
            else
            {
                var targetDifficultyScroll = (-diffContainer.SelectedMapIndex - 3) * DrawableDifficulty.HEIGHT + (-diffContainer.SelectedMapIndex - 3)
                                             * diffContainer.YSpacing + diffContainer.YSpaceBeforeFirstDifficulty;

                // Scroll to the focused difficulty position
                diffContainer.ScrollTo(targetDifficultyScroll, 2100);
                diffContainer.UpdateButtonSelectedStatus();
            }

            selectedMapsetIndex?.DisplayAsDeselected();
            nextMapsetIndex?.DisplayAsSelected(MapManager.Selected.Value);

            // Scroll the the place where the map is.
            var targetScroll = (-SelectedMapsetIndex - 3) * DrawableMapset.HEIGHT + (-SelectedMapsetIndex - 3)
                               * YSpacing + YSpaceBeforeFirstSet;

            ScrollTo(targetScroll, activeContainer == SelectContainerStatus.Mapsets ? 2100 : 1800);

            LoadNewAudioTrackIfNecessary(previousMap);
            LoadNewBackgroundIfNecessary(previousMap);
            View.Leaderboard.LoadNewScores();
        }