/// <summary> /// Paint starting line candidate so that user knows where to start /// </summary> private void PaintStartingLineCandidate() { uint startingLineYCoordinate = GridLinePainter.GetMiddleGridRowYCoordinate(xMyCanvas); uint startingLineXRightGridPoint = GridLinePainter.GetMiddleGridPointX(xMyCanvas); double startingLineXRightCoordinate = startingLineXRightGridPoint * GridBackgroundHelper.gridDistance; mStartingLineCandidateLeftPoint.X = 0.0; mStartingLineCandidateLeftPoint.Y = startingLineYCoordinate; mStartingLineCandidateRightPoint.X = startingLineXRightCoordinate; mStartingLineCandidateRightPoint.Y = startingLineYCoordinate; Line startingLineCandidate = new Line(); startingLineCandidate.Stroke = TrackBrushDefs.startingLineBrush; startingLineCandidate.StrokeThickness = 3; startingLineCandidate.X1 = mStartingLineCandidateLeftPoint.X; startingLineCandidate.Y1 = mStartingLineCandidateLeftPoint.Y; startingLineCandidate.X1 = mStartingLineCandidateRightPoint.X; startingLineCandidate.Y2 = mStartingLineCandidateRightPoint.Y; Canvas.SetZIndex(startingLineCandidate, ZIndexValues.startingLine); xMyCanvas.Children.Add(startingLineCandidate); }
/// <summary> /// Get the track that was chosen and paint that /// </summary> /// <param name="e"></param> protected async override void OnNavigatedTo(NavigationEventArgs e) { // first paint the track int?trackNumber = e.Parameter as int?; if (trackNumber != null) { try { if (trackNumber != LOAD_TRACK_NR) { // a predefined track was chosen, get this track mActiveTrack = TrackProvider.GetTrack((uint)trackNumber); } else { // user chose "Load Track" // FileBrowseDialog string filePath = await MyFilePicker.LetUserPickFile2Open(); if (filePath != null) { try { // load track mActiveTrack = await TrackLoader.LoadTrack(filePath); } catch (Exception) { MessageDialog dialog = new MessageDialog("Please choose another track file, because the selected file is invalid: " + Environment.NewLine + "'" + filePath + "'.", "Error"); await dialog.ShowAsync(); // an exception occurred, return to main page Back2Main(); } } } if (mActiveTrack != null) { mActiveTrack.PaintTrack(xMyCanvas.Children, xMyCanvas.Width, xMyCanvas.Height, GridLinePainter.GetMiddleGridRowYCoordinate(xMyCanvas)); // highscore SetHighscoreInGUI(); InitRace(); } else { // loading track failed, navigate back to main Back2Main(); } } catch (Exception) { MessageDialog dialog = new MessageDialog("Problem with loading the track", "Error"); await dialog.ShowAsync(); // an exception occurred, return to main page Back2Main(); } } }