/*private void RemoveAllDrivers() * { * if (!Application.Current.Dispatcher.CheckAccess()) * { * Application.Current.Dispatcher.Invoke(RemoveAllDrivers); * return; * } * * lock (_lockObject) * { * _driverNameTimingMap.Clear(); * DriversViewModels.Clear(); * }; * }*/ public void AddDriver(DriverTiming driver) { if (!Application.Current.Dispatcher.CheckAccess()) { Application.Current.Dispatcher.Invoke(() => AddDriver(driver)); return; } DriverTimingViewModel newViewModel = new DriverTimingViewModel(driver) { ClassIndicationBrush = GetClassColor(driver.DriverInfo) }; lock (_lockObject) { //If possible, rebind - do not create new if (_driverNameTimingMap.ContainsKey(driver.Name)) { _driverNameTimingMap[driver.Name] = driver; RebindViewModel(DriversViewModels.First(x => x.Name == driver.Name), driver); return; } _driverNameTimingMap[driver.Name] = driver; newViewModel.OutLineColor = GetDriverOutline(driver.Name); DriversViewModels.Add(newViewModel); } }
private void UpdateGapsSize(SimulatorDataSet dataSet) { if (dataSet?.SessionInfo == null || dataSet.SessionInfo.SessionType != SessionType.Race || DriversOrdering != DisplayModeEnum.Relative) { return; } bool isVisualizationEnabled = _displaySettingsViewModel.IsGapVisualizationEnabled; double minimalGap = _displaySettingsViewModel.MinimalGapForVisualization; double heightPerSecond = _displaySettingsViewModel.GapHeightForOneSecond; double maximumGap = _displaySettingsViewModel.MaximumGapHeight; DriverTimingViewModel previousViewModel = null; foreach (DriverTimingViewModel driverTimingViewModel in DriversViewModels) { if (previousViewModel == null) { previousViewModel = driverTimingViewModel; continue; } double gapInSeconds = Math.Abs(driverTimingViewModel.GapToPlayer.TotalSeconds - previousViewModel.GapToPlayer.TotalSeconds) - minimalGap; if (!isVisualizationEnabled || gapInSeconds < 0) { previousViewModel.GapHeight = 0; previousViewModel = driverTimingViewModel; continue; } previousViewModel.GapHeight = Math.Min(gapInSeconds * heightPerSecond, maximumGap); previousViewModel = driverTimingViewModel; } }
public void UpdateProperties(SimulatorDataSet dataSet) { if (_loadIndex > 0) { return; } lock (_lockObject) { List <DriverTiming> orderedTimings = (DriversOrdering == DisplayModeEnum.Absolute ? _driverNameTimingMap.Values.OrderBy(x => x.Position) : _driverNameTimingMap.Values.OrderBy(x => x.DistanceToPlayer)).ToList(); for (int i = 0; i < orderedTimings.Count; i++) { RebindViewModel(DriversViewModels[i], orderedTimings[i]); if (DriversViewModels[i].IsPlayer) { PlayerViewModel = DriversViewModels[i]; } } DriversViewModels.ForEach(x => x.RefreshProperties()); if (_refreshGapWatch.ElapsedMilliseconds < 500) { return; } UpdateGapsSize(dataSet); _refreshGapWatch.Restart(); } }
private void Rebind(DriverLapsWindow window, DriverTimingViewModel newViewModel) { if (!(window.DataContext is DriverLapsViewModel oldDriverLapsViewModel)) { return; } oldDriverLapsViewModel.UnRegisterOnGui(); window.DataContext = new DriverLapsViewModel(newViewModel, window, _driverPresentationsManager); }
private void RebindViewModel(DriverTimingViewModel driverTimingViewModel, DriverTiming driverTiming) { if (driverTimingViewModel.DriverTiming == driverTiming) { return; } if (driverTimingViewModel.DriverTiming.CarClassId != driverTiming.CarClassId) { driverTimingViewModel.ClassIndicationBrush = _classColorProvider.GetColorForClass(driverTiming.CarClassId); } driverTimingViewModel.DriverTiming = driverTiming; }
private void OpenWindow(DriverTimingViewModel driverTiming, Window ownerWindow) { if (driverTiming == null) { return; } DriverLapsWindow lapsWindow = new DriverLapsWindow() { Owner = ownerWindow, WindowStartupLocation = WindowStartupLocation.CenterOwner, }; new DriverLapsViewModel(driverTiming, lapsWindow, _driverPresentationsManager); _openedWindows.Add(lapsWindow); lapsWindow.Closed += LapsWindow_Closed; lapsWindow.Show(); }
public DriverLapsViewModel(DriverTimingViewModel driverTiming, DriverLapsWindow gui, DriverPresentationsManager driverPresentationsManager) { _driverTiming = driverTiming; Laps = new ObservableCollection <LapViewModel>(); BuildLapsViewModel(); _driverTiming.DriverTiming.NewLapStarted += DriverTimingOnNewLapStarted; DriverName = _driverTiming.Name; IsPlayer = _driverTiming.IsPlayer; _gui = gui; _driverPresentationsManager = driverPresentationsManager; _gui.Closed += GuiOnClosed; _gui.MouseLeave += GuiOnMouseLeave; _gui.DataContext = this; HasCustomOutline = _driverPresentationsManager.IsCustomOutlineEnabled(DriverName); OutLineColor = _driverPresentationsManager.TryGetOutLineColor(DriverName, out ColorDto color) ? color : null; }
public void RemoveDriver(DriverTiming driver) { if (!Application.Current.Dispatcher.CheckAccess()) { Application.Current.Dispatcher.Invoke(() => RemoveDriver(driver)); return; } lock (_lockObject) { DriverTimingViewModel toRemove = DriversViewModels.FirstOrDefault(x => x.DriverTiming == driver); if (toRemove == null) { return; } _driverNameTimingMap.Remove(driver.Name); DriversViewModels.Remove(toRemove); } }
public void Rebind(DriverTimingViewModel driverTiming) { _openedWindows.FindAll(p => ((DriverLapsViewModel)p.DataContext).DriverTiming.Name == driverTiming.Name).ForEach(p => Rebind(p, driverTiming)); }