Пример #1
0
 public void InitializeShowroomPresets()
 {
     if (ShowroomPresets == null)
     {
         ShowroomPresets = _helper.Create(CarOpenInShowroomDialog.PresetableKeyValue, p => {
             CarOpenInShowroomDialog.RunPreset(p.Filename, SelectedObject, SelectedObject.SelectedSkin?.Id);
         });
     }
 }
Пример #2
0
 public void InitializeQuickDrivePresets()
 {
     if (QuickDrivePresets == null)
     {
         QuickDrivePresets = _helper.Create(QuickDrive.PresetableKeyValue, p => {
             QuickDrive.RunPreset(p.Filename, track: SelectedTrackConfiguration);
         });
     }
 }
 private void InitializePreviews()
 {
     if (UpdatePreviewsPresets == null)
     {
         UpdatePreviewsPresets = _helper.Create(
             SettingsHolder.CustomShowroom.CustomShowroomPreviews
                         ? CmPreviewsSettings.DefaultPresetableKeyValue : CarUpdatePreviewsDialog.PresetableKeyValue,
             p => {
             if (_runButtonClicked)
             {
                 Run(p.Filename).Forget();
             }
             else
             {
                 SelectDifferent(p.Filename).Forget();
             }
         });
     }
 }
Пример #4
0
        public RaceGridViewModel(bool ignoreStartingPosition = false, [CanBeNull] string keySaveable = KeySaveable)
        {
            IgnoreStartingPosition = ignoreStartingPosition;

            _saveable = new SaveHelper <SaveableData>(keySaveable, () => {
                var data = new SaveableData {
                    ModeId                = Mode.Id,
                    FilterValue           = FilterValue,
                    ShuffleCandidates     = ShuffleCandidates,
                    AiLevelFixed          = AiLevelFixed,
                    AiLevelArrangeRandom  = AiLevelArrangeRandom,
                    AiLevelArrangeReverse = AiLevelArrangeReverse,
                    AiLevel               = AiLevel,
                    AiLevelMin            = AiLevelMin,
                    OpponentsNumber       = OpponentsNumber,
                    StartingPosition      = StartingPosition,
                };

                if (Mode == BuiltInGridMode.CandidatesManual)
                {
                    var priority = false;
                    data.CarIds  = NonfilteredList.Select(x => {
                        if (x.CandidatePriority != 1)
                        {
                            priority = true;
                        }
                        return(x.Car.Id);
                    }).ToArray();

                    if (priority)
                    {
                        data.CandidatePriorities = NonfilteredList.Select(x => x.CandidatePriority).ToArray();
                    }
                }
                else if (Mode == BuiltInGridMode.Custom)
                {
                    data.CarIds = NonfilteredList.Where(x => !x.SpecialEntry).Select(x => x.Car.Id).ToArray();
                }

                if (data.CarIds != null)
                {
                    var filtered = NonfilteredList.Where(x => !x.SpecialEntry).ToList();

                    if (filtered.Any(x => x.AiLevel.HasValue))
                    {
                        data.AiLevels = filtered.Select(x => x.AiLevel ?? -1).ToArray();
                    }

                    if (filtered.Any(x => x.Name != null))
                    {
                        data.Names = filtered.Select(x => x.Name).ToArray();
                    }

                    if (filtered.Any(x => x.Nationality != null))
                    {
                        data.Nationalities = filtered.Select(x => x.Nationality).ToArray();
                    }

                    if (filtered.Any(x => x.CarSkin != null))
                    {
                        data.SkinIds = filtered.Select(x => x.CarSkin?.Id).ToArray();
                    }
                }

                return(data);
            }, data => {
                ShuffleCandidates    = data.ShuffleCandidates ?? true;
                AiLevelFixed         = data.AiLevelFixed ?? false;
                AiLevelArrangeRandom = data.AiLevelArrangeRandomly.HasValue ? (data.AiLevelArrangeRandomly.Value ? 1d : 0d) :
                                       data.AiLevelArrangeRandom ?? 0.1d;
                AiLevelArrangeReverse = data.AiLevelArrangeReverse ?? false;
                AiLevel    = data.AiLevel ?? 95;
                AiLevelMin = data.AiLevelMin ?? 85;

                FilterValue  = data.FilterValue;
                ErrorMessage = null;

                var mode = Modes.GetByIdOrDefault <IRaceGridMode>(data.ModeId);
                if (mode == null)
                {
                    NonfatalError.NotifyBackground(ToolsStrings.RaceGrid_GridModeIsMissing,
                                                   string.Format(ToolsStrings.RaceGrid_GridModeIsMissing_Commentary, data.ModeId));
                    Mode = BuiltInGridMode.SameCar;
                }
                else
                {
                    Mode = mode;
                }

                if (Mode.CandidatesMode)
                {
                    if (Mode == BuiltInGridMode.CandidatesManual && data.CarIds != null)
                    {
                        // TODO: Async?
                        NonfilteredList.ReplaceEverythingBy(data.CarIds.Select(x => CarsManager.Instance.GetById(x)).Select((x, i) => {
                            if (x == null)
                            {
                                return(null);
                            }

                            var aiLevel   = data.AiLevels?.ElementAtOrDefault(i);
                            var carSkinId = data.SkinIds?.ElementAtOrDefault(i);
                            return(new RaceGridEntry(x)
                            {
                                CandidatePriority = data.CandidatePriorities?.ElementAtOr(i, 1) ?? 1,
                                AiLevel = aiLevel >= 0 ? aiLevel : (int?)null,
                                Name = data.Names?.ElementAtOrDefault(i),
                                Nationality = data.Nationalities?.ElementAtOrDefault(i),
                                CarSkin = carSkinId != null ? x.GetSkinById(carSkinId) : null,
                            });
                        }).NonNull());
                    }
                    else
                    {
                        NonfilteredList.Clear();
                    }

                    SetOpponentsNumberInternal(data.OpponentsNumber ?? 7);
                }
                else
                {
                    NonfilteredList.ReplaceEverythingBy(data.CarIds?.Select(x => CarsManager.Instance.GetById(x)).Select((x, i) => {
                        if (x == null)
                        {
                            return(null);
                        }

                        var aiLevel   = data.AiLevels?.ElementAtOrDefault(i);
                        var carSkinId = data.SkinIds?.ElementAtOrDefault(i);

                        return(new RaceGridEntry(x)
                        {
                            AiLevel = aiLevel >= 0 ? aiLevel : null,
                            Name = data.Names?.ElementAtOrDefault(i),
                            Nationality = data.Nationalities?.ElementAtOrDefault(i),
                            CarSkin = carSkinId != null ? x.GetSkinById(carSkinId) : null,
                        });
                    }).NonNull() ?? new RaceGridEntry[0]);
                }

                StartingPosition = data.StartingPosition ?? 7;
                FinishLoading();
            }, Reset);

            _presetsHelper = new PresetsMenuHelper();

            _randomGroup = new HierarchicalGroup(ToolsStrings.RaceGrid_Random);
            UpdateRandomModes();

            Modes = new HierarchicalGroup {
                BuiltInGridMode.SameCar,
                _randomGroup,
                BuiltInGridMode.Custom,
                _presetsHelper.Create(PresetableKeyValue, p => {
                    ImportFromPresetData(p.ReadData());
                }, ControlsStrings.Common_Presets)
            };

            NonfilteredList.CollectionChanged   += OnCollectionChanged;
            NonfilteredList.ItemPropertyChanged += OnItemPropertyChanged;
            FilteredView = new BetterListCollectionView(NonfilteredList)
            {
                CustomSort = this
            };

            // _saveable.Initialize();
            FilesStorage.Instance.Watcher(ContentCategory.GridTypes).Update += OnGridTypesUpdate;
        }