示例#1
0
        private void UpdatePlayerEntry()
        {
            if (_playerCar != _playerEntry?.Car)
            {
                if (_playerEntry != null)
                {
                    NonfilteredList.Remove(_playerEntry);
                    _playerEntry = null;
                }

                if (Mode != BuiltInGridMode.Custom || IgnoreStartingPosition)
                {
                    return;
                }
                _playerEntry = _playerCar == null ? null : new RaceGridPlayerEntry(_playerCar);
            }

            if (_playerEntry == null)
            {
                return;
            }
            if (Mode == BuiltInGridMode.Custom)
            {
                var index = NonfilteredList.IndexOf(_playerEntry);
                var pos   = StartingPosition - 1;

                if (index == -1)
                {
                    if (pos > NonfilteredList.Count)
                    {
                        NonfilteredList.Add(_playerEntry);
                    }
                    else if (pos >= 0)
                    {
                        NonfilteredList.Insert(pos, _playerEntry);
                    }
                }
                else
                {
                    if (pos < 0)
                    {
                        NonfilteredList.RemoveAt(index);
                    }
                    else if (pos != index)
                    {
                        NonfilteredList.Move(index, pos);
                    }
                }
            }
            else if (NonfilteredList.Contains(_playerEntry))
            {
                NonfilteredList.Remove(_playerEntry);
                _playerEntry = null;
            }
        }
示例#2
0
        public void InsertEntry(int index, [NotNull] RaceGridEntry entry)
        {
            var oldIndex = NonfilteredList.IndexOf(entry);

            var count = NonfilteredList.Count;
            var isNew = oldIndex == -1;
            var limit = isNew ? count : count - 1;

            if (index < 0 || index > limit)
            {
                index = limit;
            }

            if (oldIndex == index)
            {
                return;
            }
            if (Mode.CandidatesMode)
            {
                if (isNew)
                {
                    Mode = BuiltInGridMode.CandidatesManual;

                    var existed = NonfilteredList.FirstOrDefault(x => x.Same(entry));
                    if (existed != null)
                    {
                        existed.CandidatePriority++;
                    }
                    else
                    {
                        NonfilteredList.Add(entry);
                    }

                    return;
                }

                NonfilteredList.ReplaceEverythingBy(NonfilteredList.Sort(Compare));
                NonfilteredList.Move(oldIndex, index);

                try {
                    _modeKeepOrder = true;
                    Mode           = BuiltInGridMode.Custom;
                } finally {
                    _modeKeepOrder = false;
                }
            }
            else if (isNew)
            {
                if (index == count)
                {
                    NonfilteredList.Add(entry);
                }
                else
                {
                    NonfilteredList.Insert(index, entry);
                }

                UpdateOpponentsNumber();
            }
            else if (index != oldIndex)
            {
                NonfilteredList.Move(oldIndex, index);
            }

            if (StartingPosition != 0)
            {
                StartingPositionLimited = NonfilteredList.IndexOf(_playerEntry) + 1;
            }

            UpdateExceeded();
        }