/*public static void Run(CarObject carObject, string[] skinIds, string presetFilename) { * new CarUpdatePreviewsDialog(carObject, skinIds, DialogMode.Start).ShowDialog(); * } * * public static void RunPreset(CarObject carObject, string[] skinIds, string presetFilename) { * new CarUpdatePreviewsDialog(carObject, skinIds, DialogMode.Start, presetFilename).ShowDialog(); * }*/ private void OnLoaded(object sender, RoutedEventArgs e) { if (_loadPreset == null) { if (_saveable.HasSavedData || UserPresetsControl.CurrentUserPreset != null) { _saveable.Initialize(); } else { _saveable.Reset(); UserPresetsControl.CurrentUserPreset = UserPresetsControl.SavedPresets.FirstOrDefault(x => x.ToString() == @"Kunos"); } } else { _saveable.Reset(); UserPresetsControl.CurrentUserPreset = UserPresetsControl.SavedPresets.FirstOrDefault(x => x.Filename == _loadPreset); } if (_mode == UpdatePreviewMode.Options) { SelectPhase(Phase.Options); } else { RunShootingProcess(_mode == UpdatePreviewMode.StartManual).Forget(); } }
public ViewModel(string serializedPreset, CarObject carObject, string selectedSkinId) { ShowroomsManager.Instance.EnsureLoaded(); PpFiltersManager.Instance.EnsureLoaded(); SelectedCar = carObject; SelectedSkinId = selectedSkinId ?? SelectedCar.SelectedSkin?.Id; _saveable = new SaveHelper<SaveableData>("__CarOpenInShowroom", () => new SaveableData { ShowroomId = SelectedShowroom?.Id, FilterId = SelectedFilter?.Id, CameraFov = CameraFov, DisableSweetFx = DisableSweetFx, DisableWatermark = DisableWatermark, }, o => { if (o.ShowroomId != null) SelectedShowroom = ShowroomsManager.Instance.GetById(o.ShowroomId) ?? SelectedShowroom; if (o.FilterId != null) SelectedFilter = PpFiltersManager.Instance.GetById(o.FilterId) ?? SelectedFilter; CameraFov = o.CameraFov; DisableWatermark = o.DisableWatermark; DisableSweetFx = o.DisableSweetFx; }, () => { SelectedShowroom = ShowroomsManager.Instance.GetDefault(); SelectedFilter = PpFiltersManager.Instance.GetDefault(); CameraFov = 30; DisableWatermark = false; DisableSweetFx = false; }); if (string.IsNullOrEmpty(serializedPreset)) { _saveable.Initialize(); } else { _saveable.Reset(); _saveable.FromSerializedString(serializedPreset); } }
public ViewModel(string serializedPreset, CarObject carObject, string selectedSkinId) { ShowroomsManager.Instance.EnsureLoaded(); PpFiltersManager.Instance.EnsureLoaded(); SelectedCar = carObject; SelectedSkinId = selectedSkinId ?? SelectedCar.SelectedSkin?.Id; VideoPresets = _helper.CreateGroup(AcSettingsHolder.VideoPresetsCategory, "", "Default"); _saveable = new SaveHelper <SaveableData>("__CarOpenInShowroom", () => new SaveableData { ShowroomId = SelectedShowroom?.Id, FilterId = SelectedFilter?.Id, CameraFov = CameraFov, DisableSweetFx = DisableSweetFx, DisableWatermark = DisableWatermark, VideoPresetFilename = VideoPresetFilename, }, o => { if (o.ShowroomId != null) { SelectedShowroom = ShowroomsManager.Instance.GetById(o.ShowroomId) ?? SelectedShowroom; } if (o.FilterId != null) { SelectedFilter = PpFiltersManager.Instance.GetById(o.FilterId) ?? SelectedFilter; } CameraFov = o.CameraFov; DisableWatermark = o.DisableWatermark; DisableSweetFx = o.DisableSweetFx; VideoPresetFilename = o.VideoPresetFilename; }, () => { SelectedShowroom = ShowroomsManager.Instance.GetDefault(); SelectedFilter = PpFiltersManager.Instance.GetDefault(); CameraFov = 30; DisableWatermark = false; DisableSweetFx = false; VideoPresetFilename = null; }); if (string.IsNullOrEmpty(serializedPreset)) { _saveable.Initialize(); } else { _saveable.Reset(); _saveable.FromSerializedString(serializedPreset); } }
/// <summary> /// Don’t forget to call it in overrided versions. /// </summary> protected void Initialize(bool reset) { // ReSharper disable once VirtualMemberCallInConstructor _saveable = CreateSaveable(); if (reset) { _saveable.Reset(); } else { _saveable.Initialize(); } UpdateColors(); SyncAll(); Renderer.PropertyChanged += OnRendererPropertyChanged; }
public ViewModel([CanBeNull] string serializedPreset, ServerPresetObject server) { Server = server; _saveable = new SaveHelper <SaveableData>("__PackServer", () => new SaveableData { Mode = Mode, IncludeExecutable = IncludeExecutable, PackIntoSingle = PackIntoSingle, }, o => { Mode = o.Mode; IncludeExecutable = o.IncludeExecutable; PackIntoSingle = o.PackIntoSingle; }); if (string.IsNullOrEmpty(serializedPreset)) { _saveable.Initialize(); } else { _saveable.Reset(); _saveable.FromSerializedString(serializedPreset); } }
internal ViewModel(string serializedPreset, bool uiMode, CarObject carObject = null, string carSkinId = null, TrackObjectBase trackObject = null, string carSetupId = null, string weatherId = null, int?time = null, bool savePreset = false) { _uiMode = uiMode; _carSetupId = carSetupId; _weatherId = weatherId; _forceTime = time; _saveable = new SaveHelper <SaveableData>(KeySaveable, () => new SaveableData { RealConditions = RealConditions, RealConditionsLocalWeather = RealConditionsLocalWeather, RealConditionsTimezones = RealConditionsTimezones, RealConditionsManualTime = RealConditionsManualTime, Mode = SelectedMode, ModeData = SelectedModeViewModel?.ToSerializedString(), CarId = SelectedCar?.Id, TrackId = SelectedTrack?.IdWithLayout, WeatherId = SelectedWeather?.Id, // TODO TrackPropertiesData = TrackState.ExportToPresetData(), TrackPropertiesPresetFilename = UserPresetsControl.GetCurrentFilename(TrackState.PresetableKey), Temperature = Temperature, Time = Time, TimeMultipler = TimeMultipler, }, o => { TimeMultipler = o.TimeMultipler; RealConditions = _weatherId == null && o.RealConditions; RealConditionsTimezones = o.RealConditionsTimezones ?? true; RealConditionsLocalWeather = o.RealConditionsLocalWeather ?? false; RealConditionsManualTime = o.RealConditionsManualTime ?? false; Temperature = o.Temperature; Time = o.Time; if (RealConditions) { UpdateConditions(); } try { _skipLoading = o.ModeData != null; if (o.Mode != null && o.Mode.OriginalString.Contains('_')) { SelectedMode = o.Mode; } if (o.ModeData != null) { SelectedModeViewModel?.FromSerializedString(o.ModeData); } } finally { _skipLoading = false; } if (o.CarId != null) { SelectedCar = CarsManager.Instance.GetById(o.CarId) ?? SelectedCar; } if (o.TrackId != null) { SelectedTrack = TracksManager.Instance.GetLayoutById(o.TrackId) ?? SelectedTrack; } if (_weatherId != null) { SelectedWeather = WeatherManager.Instance.GetById(_weatherId); } else if (o.WeatherId != null) { SelectedWeather = WeatherManager.Instance.GetById(o.WeatherId) ?? SelectedWeather; } if (o.TrackPropertiesPresetFilename != null && File.Exists(o.TrackPropertiesPresetFilename)) { UserPresetsControl.LoadPreset(TrackState.PresetableKey, o.TrackPropertiesPresetFilename); } else if (o.TrackPropertiesData != null) { UserPresetsControl.LoadSerializedPreset(TrackState.PresetableKey, o.TrackPropertiesData); } else if (o.ObsTrackPropertiesPreset != null) { UserPresetsControl.LoadBuiltInPreset(TrackState.PresetableKey, TrackStateViewModelBase.PresetableCategory, o.ObsTrackPropertiesPreset); } }, () => { RealConditions = false; RealConditionsTimezones = true; RealConditionsManualTime = false; RealConditionsLocalWeather = false; SelectedMode = new Uri("/Pages/Drive/QuickDrive_Race.xaml", UriKind.Relative); SelectedCar = CarsManager.Instance.GetDefault(); SelectedTrack = TracksManager.Instance.GetDefault(); SelectedWeather = WeatherManager.Instance.GetDefault(); UserPresetsControl.LoadBuiltInPreset(TrackState.PresetableKey, TrackStateViewModelBase.PresetableCategory, "Green"); Temperature = 12.0; Time = 12 * 60 * 60; TimeMultipler = 1; }); if (string.IsNullOrEmpty(serializedPreset)) { _saveable.LoadOrReset(); } else { _saveable.Reset(); if (savePreset) { _saveable.FromSerializedString(serializedPreset); } else { _saveable.FromSerializedStringWithoutSaving(serializedPreset); } } if (carObject != null) { SelectedCar = carObject; // TODO: skin? } if (trackObject != null) { SelectedTrack = trackObject; } UpdateConditions(); }
internal ViewModel(string serializedPreset, bool uiMode, CarObject carObject = null, string carSkinId = null, TrackObjectBase trackObject = null, string carSetupId = null, string weatherId = null, int? time = null, bool savePreset = false) { _uiMode = uiMode; _carSetupId = carSetupId; _weatherId = weatherId; _forceTime = time; _saveable = new SaveHelper<SaveableData>(KeySaveable, () => new SaveableData { RealConditions = RealConditions, RealConditionsLocalWeather = RealConditionsLocalWeather, RealConditionsTimezones = RealConditionsTimezones, RealConditionsManualTime = RealConditionsManualTime, Mode = SelectedMode, ModeData = SelectedModeViewModel?.ToSerializedString(), CarId = SelectedCar?.Id, TrackId = SelectedTrack?.IdWithLayout, WeatherId = SelectedWeather?.Id, TrackPropertiesPreset = SelectedTrackPropertiesPreset.Name, Temperature = Temperature, Time = Time, TimeMultipler = TimeMultipler, }, o => { TimeMultipler = o.TimeMultipler; RealConditions = _weatherId == null && o.RealConditions; RealConditionsTimezones = o.RealConditionsTimezones ?? true; RealConditionsLocalWeather = o.RealConditionsLocalWeather ?? false; RealConditionsManualTime = o.RealConditionsManualTime ?? false; Temperature = o.Temperature; Time = o.Time; if (RealConditions) { UpdateConditions(); } try { _skipLoading = o.ModeData != null; if (o.Mode != null && o.Mode.OriginalString.Contains('_')) SelectedMode = o.Mode; if (o.ModeData != null) SelectedModeViewModel?.FromSerializedString(o.ModeData); } finally { _skipLoading = false; } if (o.CarId != null) SelectedCar = CarsManager.Instance.GetById(o.CarId) ?? SelectedCar; if (o.TrackId != null) SelectedTrack = TracksManager.Instance.GetLayoutById(o.TrackId) ?? SelectedTrack; if (_weatherId != null) { SelectedWeather = WeatherManager.Instance.GetById(_weatherId); } else if (o.WeatherId != null) { SelectedWeather = WeatherManager.Instance.GetById(o.WeatherId) ?? SelectedWeather; } if (o.TrackPropertiesPreset != null) { SelectedTrackPropertiesPreset = Game.DefaultTrackPropertiesPresets.FirstOrDefault(x => x.Name == o.TrackPropertiesPreset) ?? SelectedTrackPropertiesPreset; } }, () => { RealConditions = false; RealConditionsTimezones = true; RealConditionsManualTime = false; RealConditionsLocalWeather = false; SelectedMode = new Uri("/Pages/Drive/QuickDrive_Race.xaml", UriKind.Relative); SelectedCar = CarsManager.Instance.GetDefault(); SelectedTrack = TracksManager.Instance.GetDefault(); SelectedWeather = WeatherManager.Instance.GetDefault(); SelectedTrackPropertiesPreset = Game.GetDefaultTrackPropertiesPreset(); Temperature = 12.0; Time = 12 * 60 * 60; TimeMultipler = 1; }); if (string.IsNullOrEmpty(serializedPreset)) { _saveable.LoadOrReset(); } else { _saveable.Reset(); if (savePreset) { _saveable.FromSerializedString(serializedPreset); } else { _saveable.FromSerializedStringWithoutSaving(serializedPreset); } } if (carObject != null) { SelectedCar = carObject; // TODO: skin? } if (trackObject != null) { SelectedTrack = trackObject; } UpdateConditions(); }