Example #1
0
        public bool CanReorder(ScenPart part, ReorderDirection dir)
        {
            if (!part.def.PlayerAddRemovable)
            {
                return(false);
            }
            int num = parts.IndexOf(part);

            switch (dir)
            {
            case ReorderDirection.Up:
                if (num == 0)
                {
                    return(false);
                }
                if (num > 0 && !parts[num - 1].def.PlayerAddRemovable)
                {
                    return(false);
                }
                return(true);

            case ReorderDirection.Down:
                return(num != parts.Count - 1);

            default:
                throw new NotImplementedException();
            }
        }
Example #2
0
        public bool CanReorder(ScenPart part, ReorderDirection dir)
        {
            bool result;

            if (!part.def.PlayerAddRemovable)
            {
                result = false;
            }
            else
            {
                int num = this.parts.IndexOf(part);
                if (dir == ReorderDirection.Up)
                {
                    result = (num != 0 && (num <= 0 || this.parts[num - 1].def.PlayerAddRemovable));
                }
                else
                {
                    if (dir != ReorderDirection.Down)
                    {
                        throw new NotImplementedException();
                    }
                    result = (num != this.parts.Count - 1);
                }
            }
            return(result);
        }
Example #3
0
        public static IList <int> Reorder(IList <int> indicies, int length, ReorderDirection moveDirection)
        {
            Contract.Requires(indicies != null, "indicies cannot be null");
            Contract.Requires(length >= 0, "the target length cannot be negative");
            Contract.Requires(indicies.Count <= length, "cannot have more indicies than the target length");
            Contract.Requires(Contract.ForAll(indicies, i => i >= 0), "All indicies must be non-negative");
            Contract.Requires(Contract.ForAll(indicies, i => i < length), "All indicies must be less than the target length");
            Debug.Assert(indicies.TrueForAllAdjacentPairs((a, b) => a < b), "indicies should be sorted (and unique)");

            if (indicies.Count > 0 && indicies.Count < length)
            {
                // a bit silly, but I hate doing math in comparisons
                int lastPossibleIndex = length - 1;

                // Two cases: bunched and unbunched
                // 1 - Unbunched: two or more selected items that are not packed together
                //     Can always move unbunched items
                // TODO: unbunched not supported at this time

                // 2 - Bunched: one or more items, all together
                //     If items are bunched, can only move if there is room to move them in the desired direction

                var bunched = indicies.TrueForAllAdjacentPairs((a, b) => (b - a) == 1);
                if (bunched)
                {
                    if (moveDirection == ReorderDirection.Beginning)
                    {
                        int leadIndex = indicies.First();
                        if (leadIndex == 0)
                        {
                            // already at the beginning
                            // cannot move
                            return(null);
                        }
                        else
                        {
                            // not at the beginning!
                            // move everything towards beginning!
                            return(indicies.Select(initial => initial - 1).ToArray());
                        }
                    }
                    else
                    {
                        Debug.Assert(moveDirection == ReorderDirection.End);
                        int leadIndex = indicies.Last();
                        if (leadIndex == lastPossibleIndex)
                        {
                            // already at the end
                            // cannot move
                            return(null);
                        }
                        else
                        {
                            return(indicies.Select(initial => initial + 1).ToArray());
                        }
                    }
                }
            }
            return(null);
        }
Example #4
0
        public void Reorder(ScenPart part, ReorderDirection dir)
        {
            int num = parts.IndexOf(part);

            parts.RemoveAt(num);
            if (dir == ReorderDirection.Up)
            {
                parts.Insert(num - 1, part);
            }
            if (dir == ReorderDirection.Down)
            {
                parts.Insert(num + 1, part);
            }
        }
        public void Reorder(Guid id, ReorderDirection direction)
        {
            var modelToMove = GetModel(id);

            if (modelToMove == null)
            {
                throw new NullReferenceException(string.Format("No ContentProvider model found with id = {0}", id));
            }

            if (direction == ReorderDirection.Up)
            {
                MoveModelUp(modelToMove);
            }

            if (direction == ReorderDirection.Down)
            {
                MoveModelDown(modelToMove);
            }

            return;
        }
Example #6
0
        public static bool CanReorder(IList <int> indicies, int length, ReorderDirection direction)
        {
            var result = Reorder(indicies, length, direction);

            return(result != null);
        }
Example #7
0
        public static IList<int> Reorder(IList<int> indicies, int length, ReorderDirection moveDirection)
        {
            Contract.Requires(indicies != null, "indicies cannot be null");
            Contract.Requires(length >= 0, "the target length cannot be negative");
            Contract.Requires(indicies.Count <= length, "cannot have more indicies than the target length");
            Contract.Requires(Contract.ForAll(indicies, i => i >= 0), "All indicies must be non-negative");
            Contract.Requires(Contract.ForAll(indicies, i => i < length), "All indicies must be less than the target length");
            Debug.Assert(indicies.TrueForAllAdjacentPairs((a, b) => a < b), "indicies should be sorted (and unique)");

            if (indicies.Count > 0 && indicies.Count < length)
            {
                // a bit silly, but I hate doing math in comparisons
                int lastPossibleIndex = length - 1;

                // Two cases: bunched and unbunched
                // 1 - Unbunched: two or more selected items that are not packed together
                //     Can always move unbunched items
                // 2 - Bunched: one or more items, all together
                //     If items are bunched, can only move if there is room to move them in the desired direction

                var bunched = indicies.TrueForAllAdjacentPairs((a, b) => (b - a) == 1);
                if (bunched)
                {
                    if (moveDirection == ReorderDirection.Beginning)
                    {
                        int leadIndex = indicies.First();
                        if (leadIndex == 0)
                        {
                            // already at the beginning
                            // cannot move
                            return null;
                        }
                        else
                        {
                            // not at the beginning!
                            // move everything towards beginning!
                            return indicies.Select(initial => initial - 1).ToArray();
                        }
                    }
                    else
                    {
                        Debug.Assert(moveDirection == ReorderDirection.End);
                        int leadIndex = indicies.Last();
                        if (leadIndex == lastPossibleIndex)
                        {
                            // already at the end
                            // cannot move
                            return null;
                        }
                        else
                        {
                            return indicies.Select(initial => initial + 1).ToArray();
                        }
                    }
                }
                else
                {
                    Debug.Assert(indicies.Count > 1);
                    var slices = Slice(indicies);
                    if (moveDirection == ReorderDirection.Beginning)
                    {
                        var subSlice = slices.Last();
                        slices.Remove(subSlice);

                        // reorder just the subSlice
                        subSlice = Reorder(subSlice, length, moveDirection);
                        slices.Add(subSlice);
                    }
                    else
                    {
                        Debug.Assert(moveDirection == ReorderDirection.End);
                        var subSlice = slices.First();
                        slices.Remove(subSlice);

                        // reorder just the subSlice
                        subSlice = Reorder(subSlice, length, moveDirection);
                        slices.Insert(0, subSlice);
                    }
                    return slices.SelectMany(s => s).ToList();
                }
            }
            return null;
        }
Example #8
0
 public static bool CanReorder(IList<int> indicies, int length, ReorderDirection direction)
 {
     var result = Reorder(indicies, length, direction);
     return result != null;
 }