private void PrepareTrackOutlineTexture([NotNull] JToken cmTextures, [CanBeNull] TrackObjectBase track) { var outline = cmTextures.GetStringValueOnly("trackOutline"); if (outline != null) { SetTrackOutlineTexture(track?.OutlineImage, outline, cmTextures.GetStringValueOnly("trackOutlineEffect")); } }
public SelectTrackDialog(TrackObjectBase selectedTrackConfiguration) { _instance = new WeakReference<SelectTrackDialog>(this); DataContext = new ViewModel(selectedTrackConfiguration); InitializeComponent(); Model.PropertyChanged += Model_PropertyChanged; BackgroundImage0.Source = UriToCachedImageConverter.Convert(Model.CurrentPreviewImage); Buttons = new[] { OkButton, CancelButton }; }
public TrackGeoTagsDialog(TrackObjectBase track) { DataContext = new ViewModel(track); InitializeComponent(); Buttons = new[] { CreateExtraDialogButton(ToolsStrings.TrackGeoTags_FindIt, new DelegateCommand(() => { MapWebBrowser.InvokeScript(@"moveTo", GetQuery(Model.Track)); })), CreateExtraDialogButton(FirstFloor.ModernUI.UiStrings.Ok, new CombinedCommand(Model.SaveCommand, CloseCommand)), CancelButton }; MapWebBrowser.ObjectForScripting = new ScriptProvider(Model); MapWebBrowser.Navigate(GetMapAddress(track)); Model.PropertyChanged += Model_PropertyChanged; }
public static async Task Run(TrackObjectBase track) { var modelsFilename = track.ModelsFilename; string kn5Filename = null; if (!File.Exists(modelsFilename)) { modelsFilename = null; kn5Filename = Path.Combine(track.Location, track.Id + ".kn5"); if (!File.Exists(kn5Filename)) { ModernDialog.ShowMessage("Model not found"); return; } } Kn5 kn5; using (var waiting = new WaitingDialog()) { waiting.Report("Loading model…"); kn5 = await Task.Run(() => modelsFilename != null ? Kn5.FromModelsIniFile(modelsFilename) : Kn5.FromFile(kn5Filename)); } using (var renderer = new TrackMapPreparationRenderer(kn5)) { var wrapper = new TrackMapRendererWrapper(track, renderer); wrapper.Form.Icon = AppIconService.GetAppIcon(); wrapper.Run(); } }
public ViewModel(TrackObjectBase selectedTrackConfiguration) { _selectedTrackConfiguration = new DelayedPropertyWrapper<TrackObjectBase>(v => { if (v == null) return; v.MainTrackObject.SelectedLayout = v; CurrentPreviewImage = v.PreviewImage; OnPropertyChanged(nameof(SelectedTrackConfiguration)); OnPropertyChanged(nameof(SelectedTrack)); }); SelectedTrackConfiguration = selectedTrackConfiguration; }
public override void OnSelectedUpdated(CarObject selectedCar, TrackObjectBase selectedTrack) { RaceGridViewModel.PlayerCar = selectedCar; RaceGridViewModel.PlayerTrack = selectedTrack; }
private static string GetMapAddress(TrackObjectBase track) { var tags = track.GeoTags; return CmHelpersProvider.GetAddress("map") + @"?t#" + (tags?.IsEmptyOrInvalid == false ? $"{tags.LatitudeValue};{tags.LongitudeValue}" : GetQuery(track)); }
public TrackMapRendererWrapper(TrackObjectBase track, TrackMapPreparationRenderer renderer) : base(renderer, track.Name, 680, 680) { _helper = new AttachedHelper(this, new TrackMapRendererTools(track, renderer), 240); }
public UserChampionshipRoundExtended(TrackObjectBase track) { TrackId = track.KunosIdWithLayout; Track = track; }
public TrackMapEditorT(TrackObjectBase track) { DataContext = new TrackMapEditorViewModel(); InitializeComponent(); Buttons = new[] { OkButton, CancelButton }; }
public static void Show(CarObject car = null, string carSkinId = null, TrackObjectBase track = null) { var mainWindow = Application.Current.MainWindow as MainWindow; if (mainWindow == null) return; _selectNextCar = car; _selectNextCarSkinId = carSkinId; _selectNextTrack = track; NavigateToPage(); }
public static bool RunPreset(string presetFilename, CarObject car = null, string carSkinId = null, TrackObjectBase track = null, string carSetupId = null) { return new ViewModel(File.ReadAllText(presetFilename), false, car, carSkinId, track, carSetupId).Run(); }
public static async Task<bool> RunAsync(CarObject car = null, string carSkinId = null, TrackObjectBase track = null, string carSetupId = null, string weatherId = null, int? time = null) { var model = new ViewModel(string.Empty, false, car, carSkinId, track, carSetupId, weatherId, time); if (!model.GoCommand.CanExecute(null)) return false; await model.Go(); return true; }
public static bool Run(CarObject car = null, string carSkinId = null, TrackObjectBase track = null, string carSetupId = null) { return new ViewModel(string.Empty, false, car, carSkinId, track, carSetupId).Run(); }
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(); }
public static TrackObjectBase Show(TrackObjectBase track) { var dialog = new SelectTrackDialog(track); dialog.ShowDialog(); return !dialog.IsResultOk || dialog.Model.SelectedTrackConfiguration == null ? track : dialog.Model.SelectedTrackConfiguration; }
public void Show(ServerEntry server) { ServerEntry = server; if (!ReferenceEquals(DataContext, this)) { DataContext = this; InitializeComponent(); Show(); Owner = Application.Current.MainWindow; _timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(1), IsEnabled = true }; _timer.Tick += OnTick; } Car = server.SelectedCarEntry?.CarObject; Track = server.Track; try { _ignoreSkinChange = true; Skin = server.GetSelectedCarSkin(); } finally { _ignoreSkinChange = false; } Buttons = new[] { CreateExtraStyledDialogButton("Go.Button", AppStrings.Common_Go, () => ServerEntry?.JoinCommand.Execute(ServerEntry.ActualJoin), () => Ready), CancelButton }; }
public virtual void OnSelectedUpdated(CarObject selectedCar, TrackObjectBase selectedTrack) { }
public ViewModel(TrackObjectBase track) { Track = track; if (track.GeoTags != null) { Latitude = track.GeoTags.Latitude; Longitude = track.GeoTags.Longitude; } else { Latitude = null; Longitude = null; } }
private static string GetQuery(TrackObjectBase track) { return string.IsNullOrEmpty(track.City) && string.IsNullOrEmpty(track.Country) ? track.Name : new[] { track.City, track.Country }.Where(x => x != null).JoinToString(@", "); }
private async Task<Tuple<string, string>> LoadData() { Car = null; CarSkin = null; Track = null; string uri; if (EventId.Contains(@"/")) { var splitted = EventId.Split('/'); uri = $"http://www.radiators-champ.com/RSRLiveTiming/index.php?page=rank&track={splitted[0]}&car={splitted[1]}"; } else { uri = $"http://www.radiators-champ.com/RSRLiveTiming/index.php?page=event_rank&eventId={EventId}"; } string page; using (var client = new WebClient { Headers = { [HttpRequestHeader.UserAgent] = InternalUtils.GetKunosUserAgent(), [@"X-User-Agent"] = CmApiProvider.UserAgent } }) { page = await client.DownloadStringTaskAsync(uri); } var carIdMatch = Regex.Match(page, @"\bdata-car=""([\w-]+)"""); var trackIdMatch = Regex.Match(page, @"\bdata-track=""([\w-]+)"""); var trackLayoutIdMatch = Regex.Match(page, @"\bdata-track-layout=""([\w-]+)"""); if (!carIdMatch.Success || !trackIdMatch.Success) return null; var carId = carIdMatch.Groups[1].Value; var trackId = trackIdMatch.Groups[1].Value; var trackLayoutId = trackLayoutIdMatch.Success ? trackLayoutIdMatch.Groups[1].Value : null; if (trackLayoutId == trackId) { trackLayoutId = null; // TODO: temporary fix } Car = CarsManager.Instance.GetById(carId); CarSkin = Car?.SelectedSkin; Track = TracksManager.Instance.GetLayoutById(trackId, trackLayoutId); return new Tuple<string, string>(carId, trackId); }