/// <inheritdoc />
        /// <summary>
        /// </summary>
        public override void Destroy()
        {
            BackgroundHelper.Loaded  -= OnBackgroundLoaded;
            BackgroundHelper.Blurred -= OnBackgroundBlurred;

            MapsetBuffer.ForEach(x => x.Destroy());
            base.Destroy();
        }
Пример #2
0
 /// <summary>
 ///     Updates all the buttons in the buffer and makes it so that they display
 ///     the correct display status.
 /// </summary>
 private void UpdateButtonSelectedStatus() => MapsetBuffer.ForEach(x =>
 {
     if (x.MapsetIndex == SelectedMapsetIndex)
     {
         x.DisplayAsSelected(MapManager.Selected.Value);
     }
     else
     {
         x.DisplayAsDeselected();
     }
 });
Пример #3
0
        /// <summary>
        ///     Initializes the container with new mapsets.
        /// </summary>
        public void InitializeWithNewSets()
        {
            lock (MapsetBuffer)
            {
                MapsetBuffer.ForEach(x => x.Destroy());
                MapsetBuffer.Clear();

                var selectedMapIndex = Screen.AvailableMapsets.FindIndex(x => x.Maps.Contains(MapManager.Selected.Value));

                if (selectedMapIndex != -1)
                {
                    SelectedMapsetIndex = selectedMapIndex;
                    SetPoolStartingIndex();

                    if (View.ActiveContainer == SelectContainerStatus.Mapsets)
                    {
                        ClearAnimations();
                        X = Width;
                        MoveToX(-28, Easing.OutBounce, 1200);
                    }

                    InitializeMapsetBuffer();

                    return;
                }

                if (Screen.AvailableMapsets.Count <= 0)
                {
                    return;
                }

                SelectedMapsetIndex = 0;
                SetPoolStartingIndex();

                if (View.ActiveContainer == SelectContainerStatus.Mapsets)
                {
                    ClearAnimations();
                    X = Width;
                    MoveToX(-28, Easing.OutBounce, 1200);
                }

                InitializeMapsetBuffer();

                var mapset = Screen.AvailableMapsets[SelectedMapsetIndex];
                SelectMap(SelectedMapsetIndex, mapset.PreferredMap ?? mapset.Maps.First(), true);
            }
        }
Пример #4
0
        /// <summary>
        ///     Handles shifting of the pool when scrolling.
        /// </summary>
        /// <param name="direction"></param>
        private void HandlePoolShifting(Direction direction)
        {
            switch (direction)
            {
            case Direction.Forward:
                // If there are no available mapsets then there's no need to do anything.
                if (Screen.AvailableMapsets.ElementAtOrDefault(PoolStartingIndex) == null ||
                    Screen.AvailableMapsets.ElementAtOrDefault(PoolStartingIndex + MAX_MAPSETS_SHOWN) == null)
                {
                    return;
                }

                var firstMapset = MapsetBuffer.First();

                // Check if the object is in the rect of the ScrollContainer.
                // If it is, then there's no updating that needs to happen.
                if (!Rectangle.Intersect(firstMapset.ScreenRectangle, ScreenRectangle).IsEmpty)
                {
                    return;
                }

                // Update the mapset's information and y position.
                firstMapset.Y = (PoolStartingIndex + MAX_MAPSETS_SHOWN) * DrawableMapset.HEIGHT +
                                (PoolStartingIndex + MAX_MAPSETS_SHOWN) * YSpacing + YSpaceBeforeFirstSet;

                lock (Screen.AvailableMapsets)
                    firstMapset.UpdateWithNewMapset(Screen.AvailableMapsets[PoolStartingIndex + MAX_MAPSETS_SHOWN],
                                                    PoolStartingIndex + MAX_MAPSETS_SHOWN);

                // Circuluarly Shift the list forward one.
                MapsetBuffer.Remove(firstMapset);
                MapsetBuffer.Add(firstMapset);

                // Make sure the set is corrected selected/deselected
                if (PoolStartingIndex + MAX_MAPSETS_SHOWN == SelectedMapsetIndex)
                {
                    firstMapset.DisplayAsSelected(MapManager.Selected.Value);
                }
                else
                {
                    firstMapset.DisplayAsDeselected();
                }

                PoolStartingIndex++;
                break;

            case Direction.Backward:
                // If there are no previous available user then there's no need to shift.
                if (Screen.AvailableMapsets.ElementAtOrDefault(PoolStartingIndex - 1) == null)
                {
                    return;
                }

                var lastMapset = MapsetBuffer.Last();

                // Check if the object is in the rect of the ScrollContainer.
                // If it is, then there's no updating that needs to happen.
                if (!Rectangle.Intersect(lastMapset.ScreenRectangle, ScreenRectangle).IsEmpty)
                {
                    return;
                }

                lastMapset.Y = (PoolStartingIndex - 1) * DrawableMapset.HEIGHT + (PoolStartingIndex - 1) * YSpacing + YSpaceBeforeFirstSet;

                lock (Screen.AvailableMapsets)
                    lastMapset.UpdateWithNewMapset(Screen.AvailableMapsets[PoolStartingIndex - 1], PoolStartingIndex - 1);

                MapsetBuffer.Remove(lastMapset);
                MapsetBuffer.Insert(0, lastMapset);

                // Make sure the set is correctly selected/deselected.
                if (PoolStartingIndex - 1 == SelectedMapsetIndex)
                {
                    lastMapset.DisplayAsSelected(MapManager.Selected.Value);
                }
                else
                {
                    lastMapset.DisplayAsDeselected();
                }

                PoolStartingIndex--;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(direction), direction, null);
            }
        }
Пример #5
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();
        }