Ejemplo n.º 1
0
        private static ArgumentHandleResult ProcessSharedRaceGridPreset(SharedEntry shared, byte[] data)
        {
            var result = ShowDialog(shared);

            switch (result)
            {
            case Choise.Save:
            case Choise.ApplyAndSave:
                var filename = FileUtils.EnsureUnique(Path.Combine(
                                                          PresetsManager.Instance.GetDirectory(RaceGridViewModel.PresetableKeyValue), @"Loaded", shared.GetFileName()));
                Directory.CreateDirectory(Path.GetDirectoryName(filename) ?? "");
                File.WriteAllBytes(filename, data);
                if (result == Choise.ApplyAndSave)
                {
                    RaceGridViewModel.LoadPreset(filename);
                    QuickDrive.NavigateToPage();
                }
                return(ArgumentHandleResult.SuccessfulShow);

            case Choise.Apply:
                RaceGridViewModel.LoadSerializedPreset(data.ToUtf8String());
                QuickDrive.NavigateToPage();
                return(ArgumentHandleResult.SuccessfulShow);

            default:
                return(ArgumentHandleResult.Failed);
            }
        }
Ejemplo n.º 2
0
        public SetupRaceGridDialog(RaceGridViewModel model)
        {
            Model       = model;
            DataContext = model;
            InitializeComponent();

            // TODO: Buttons = new[] { OkButton, CancelButton };
            Buttons = new[] { CloseButton };
        }
            private async Task UpdateSerializedRaceGridDataLaterAsync()
            {
                if (SelectedObject.IsStarted)
                {
                    return;
                }

                if (UpdatingSerializedRaceGridData)
                {
                    if (_updatingSerializedRaceGridDataTokenSource != null)
                    {
                        _updatingSerializedRaceGridDataTokenSource.Cancel();
                    }
                    else
                    {
                        return;
                    }
                }

                UpdatingSerializedRaceGridData = true;
                CancellationTokenSource tokenSource = null;

                try {
                    using (tokenSource = new CancellationTokenSource()) {
                        _updatingSerializedRaceGridDataTokenSource = tokenSource;

                        await Task.Delay(300, tokenSource.Token);

                        if (tokenSource.IsCancellationRequested)
                        {
                            return;
                        }

                        SetSerializedRaceGridData(RaceGridViewModel.ExportToPresetData());

                        var generated = await RaceGridViewModel.GenerateGameEntries(tokenSource.Token);

                        if (generated == null)
                        {
                            return;
                        }

                        SetDrivers(generated.Select(x => new UserChampionshipDriver(x.DriverName, x.CarId, x.SkinId)
                        {
                            AiLevel     = x.AiLevel,
                            Nationality = x.Nationality
                        }).Prepend(new UserChampionshipDriver(UserChampionshipDriver.PlayerName, SelectedObject.PlayerCarId,
                                                              SelectedObject.PlayerCarSkinId)).ToArray());
                    }
                } finally {
                    if (ReferenceEquals(tokenSource, _updatingSerializedRaceGridDataTokenSource))
                    {
                        _updatingSerializedRaceGridDataTokenSource = null;
                        UpdatingSerializedRaceGridData             = false;
                    }
                }
            }
Ejemplo n.º 4
0
            private string SetQuickDriveRaceGrid()
            {
                var parsed   = Parsed;
                var players  = parsed?.Players;
                var sessions = parsed?.Sessions;

                if (players == null || sessions == null || players.Length == 0)
                {
                    return(null);
                }

                var opponents = players.Skip(1).Select(x => new {
                    x.Name,
                    Car    = CarsManager.Instance.GetById(x.CarId ?? ""),
                    SkinId = x.CarSkinId
                }).Where(x => x.Car != null).ToList();

                if (opponents.Count <= 0)
                {
                    return(null);
                }

                var vm = new RaceGridViewModel(keySaveable: null)
                {
                    LoadingFromOutside = true,
                    Mode              = BuiltInGridMode.Custom,
                    FilterValue       = null,
                    RandomSkinsFilter = null
                };

                vm.NonfilteredList.ReplaceEverythingBy(opponents.Select(x => {
                    var match = Regex.Match(x.Name, @"^(.+) \((\d+(?:[,\.]\d+)?)%(?:, (\d+(?:[,\.]\d+)?)?%\))$");
                    if (match.Success)
                    {
                        var cleanName    = match.Groups[1].Value;
                        var aiLevel      = match.Groups[2].Value.As <double>();
                        var aiAggression = match.Groups[3].Success ? match.Groups[3].Value.As <double>() : (double?)null;
                        return(new RaceGridEntry(x.Car)
                        {
                            CarSkin = x.Car.GetSkinById(x.SkinId),
                            Name = cleanName,
                            AiLevel = aiLevel,
                            AiAggression = aiAggression,
                        });
                    }

                    return(new RaceGridEntry(x.Car)
                    {
                        CarSkin = x.Car.GetSkinById(x.SkinId),
                        Name = x.Name
                    });
                }));

                return(vm.ExportToPresetData());
            }
Ejemplo n.º 5
0
            public ViewModel([NotNull] UserChampionshipObject acObject) : base(acObject)
            {
                Points = new BetterObservableCollection <PlacePoints>();
                UpdatePointsArray();

                acObject.PropertyChanged += OnAcObjectPropertyChanged;

                RaceGridViewModel = new RaceGridViewModel(true);
                LoadRaceGrid();
                RaceGridViewModel.Changed += OnRaceGridViewModelChanged;
            }
Ejemplo n.º 6
0
            public ViewModel(bool initialize = true)
            {
                // ReSharper disable once VirtualMemberCallInConstructor
                RaceGridViewModel          = new RaceGridViewModel(IgnoreStartingPosition);
                RaceGridViewModel.Changed += RaceGridViewModel_Changed;

                // ReSharper disable once VirtualMemberCallInContructor
                InitializeSaveable();

                if (initialize)
                {
                    Saveable.LoadOrReset();
                }
                else
                {
                    Saveable.Reset();
                }
            }
Ejemplo n.º 7
0
 public override void Unload()
 {
     base.Unload();
     RaceGridViewModel.Dispose();
     SelectedObject.PropertyChanged -= OnAcObjectPropertyChanged;
 }