Exemple #1
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);
            }
        }