public static void createNewRacer(Panel parent, racerUpdatedHandler returnHandler) { RacerDetails creator = new RacerDetails(WindowType.Create); creator.onUpdatedRacer += returnHandler; try { creator.imgCarPicture.Source = new BitmapImage(DataManager.getAbsoluteUri(DataManager.Settings.DefaltCarImageUri)); } catch (Exception ex2) { DataManager.MessageProvider.showError("Could Not Load Defalt Car's Picture.", ex2.Message); } try { creator.imgCreatorPicture.Source = new BitmapImage(DataManager.getAbsoluteUri(DataManager.Settings.DefaltMakerImageUri)); } catch (Exception ex2) { DataManager.MessageProvider.showError("Could Not Load Defalt Creator's Picture", ex2.Message); } creator.raceData.Children.Clear(); creator.raceData.ColumnDefinitions.Clear(); MakeDialog(parent, creator, WindowType.Create); }
private void btnCreateRacer_Click(object sender, RoutedEventArgs e) { RacerDetails.createNewRacer(HostGrid, delegate() { updateRacerList(); }); }
private void createCarTiles(Panel host, List <Racer> racers) { int i = 0; foreach (Racer racer in racers) { i++; CarTile tile = CarTile.createTile(racer, true, delegate() { addRacer(DataManager.Competition.Racers.IndexOf(racer)); }); tile.MouseUp += delegate { RacerDetails.editOldRacer(HostGrid, racer, delegate() { updateRacerList(); }, delegate() { lastResults = null; lastRaceList.Children.Clear(); forgetRace(); }); }; tile.Cursor = Cursors.Hand; tile.Margin = new Thickness(8, 8, 0, 0); tile.AnimateIn(i * 250); host.Children.Add(tile); } }
private void addCarListItem(Panel host, Racer racer, int delay) { CarList listItem = CarList.createListItem(racer); listItem.MouseUp += delegate { RacerDetails.editOldRacer(HostGrid, racer, delegate() { updateRacerList(); }, delegate() { forgetRace(); }); }; listItem.Margin = new Thickness(0, 0, 0, 8); listItem.AnimateIn(delay); host.Children.Add(listItem); }
public static void editOldRacer(Panel parent, Racer racer, racerUpdatedHandler returnHandler, racerDeletedHandler deleteHandler) { RacerDetails editor = new RacerDetails(WindowType.Display); editor.onUpdatedRacer += returnHandler; editor.onDeletedRacer += deleteHandler; editor._racer = racer; try { editor.imgCarPicture.Source = DataManager.loadImage(DataManager.getAbsoluteUri(racer.Car.ImageUri)); } catch (Exception ex1) { DataManager.MessageProvider.showError("Could Not Load Car's Picture. Falling Back to defalt.", ex1.Message); try { editor.imgCarPicture.Source = new BitmapImage(DataManager.getAbsoluteUri(DataManager.Settings.DefaltCarImageUri)); } catch (Exception ex2) { DataManager.MessageProvider.showError("Could Not Load Defalt Car's Picture.", ex2.Message); } } try { editor.imgCreatorPicture.Source = DataManager.loadImage(DataManager.getAbsoluteUri(racer.Maker.ImageUri)); } catch (Exception ex1) { DataManager.MessageProvider.showError("Could Not Load Creator's Picture. Falling Back to defalt.", ex1.Message); try { editor.imgCreatorPicture.Source = new BitmapImage(DataManager.getAbsoluteUri(DataManager.Settings.DefaltMakerImageUri)); } catch (Exception ex2) { DataManager.MessageProvider.showError("Could Not Load Defalt Creator's Picture", ex2.Message); } } editor.tbCarName.Text = racer.Car.Name; editor.tbCreatorName.Text = racer.Maker.Name; editor.tbBarcode.Text = racer.Barcode; editor.cboClass.Text = racer.Class; editor.passedInspect.IsChecked = racer.PassedInspection; editor.raceData.Children.Clear(); editor.raceData.ColumnDefinitions.Clear(); if (racer.Times.Count > 0) { editor.scores.Visibility = Visibility.Visible; double totalTime = 0; int totalAmount = 0; double bestTime = 10; editor.lbNoRaceData.Visibility = Visibility.Collapsed; for (int i = 0; i < DataManager.Settings.NumberOfLanes; i++) { editor.raceData.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }); //<Label Grid.Column="5" Content="6" FontSize="30" HorizontalAlignment="Center" VerticalAlignment="Center"/> Label lbLaneHeader = new Label(); lbLaneHeader.Content = (i + 1).ToString(); lbLaneHeader.FontSize = 30; lbLaneHeader.HorizontalAlignment = HorizontalAlignment.Center; lbLaneHeader.VerticalAlignment = VerticalAlignment.Center; lbLaneHeader.SetValue(Grid.RowProperty, 0); lbLaneHeader.SetValue(Grid.ColumnProperty, i); editor.raceData.Children.Add(lbLaneHeader); //<Border Grid.Column="6" Grid.Row="1" Grid.RowSpan="2" BorderThickness="0.5, 0, 1, 0" BorderBrush="{DynamicResource MaterialDesignDivider}" Margin="0, 16, 0, 8"/> Border border = new Border(); border.HorizontalAlignment = HorizontalAlignment.Stretch; border.VerticalAlignment = VerticalAlignment.Stretch; border.Margin = new Thickness(0, 8, 0, 8); border.BorderBrush = editor.FindResource("MaterialDesignDivider") as Brush; border.BorderThickness = new Thickness((i == 0 ? 0 : 0.5), 0, (i == DataManager.Settings.NumberOfLanes - 1 ? 0 : 0.5), 0); border.SetValue(Grid.RowProperty, 0); border.SetValue(Grid.RowSpanProperty, 2); border.SetValue(Grid.ColumnProperty, i); editor.raceData.Children.Add(border); StackPanel stp = new StackPanel(); stp.HorizontalAlignment = HorizontalAlignment.Center; stp.VerticalAlignment = VerticalAlignment.Top; stp.Orientation = Orientation.Vertical; stp.SetValue(Grid.RowProperty, 1); stp.SetValue(Grid.ColumnProperty, i); List <double> times = new List <double>(); foreach (Time time in racer.Times) { if (time.Lane == i + 1) { times.Add(time.Speed); } } times.Sort(); for (int t = 0; t < times.Count; t++) { Label lbTime = new Label(); lbTime.Content = String.Format("{0:0.000}", times[t]) + "s"; lbTime.FontSize = 18; if (t == 0) { totalTime += times[t]; totalAmount++; if (bestTime > times[t]) { bestTime = times[t]; } } else { lbTime.Opacity = 0.5; } lbTime.HorizontalAlignment = HorizontalAlignment.Center; lbTime.VerticalAlignment = VerticalAlignment.Top; lbTime.SetValue(Grid.RowProperty, 1); lbTime.SetValue(Grid.ColumnProperty, i); stp.Children.Add(lbTime); } editor.timeAverage.Text = String.Format("{0:0.000}", (totalTime / totalAmount)) + "s"; editor.timeBest.Text = String.Format("{0:0.000}", bestTime) + "s"; editor.raceData.Children.Add(stp); } } MakeDialog(parent, editor, WindowType.Display); }
private static void MakeDialog(Panel parent, RacerDetails content, WindowType type) { content._dialogHost = new Dialog(parent, content, false, false, true, delegate() { if (content._type == WindowType.Display) //only allow saving after clicking of dialog, if not creating a new car { if (content.createSaveRacer()) { return(DialogButton.ReturnEvent.Close); } else { return(DialogButton.ReturnEvent.DoNothing); } } else { return(DialogButton.ReturnEvent.DoNothing); } }, (type == WindowType.Display ? new DialogButton("Delete", DialogButton.Alignment.Left, DialogButton.Style.Flat, delegate() { DialogBox.showOptionBox(parent, "This will completly remove \"" + content.tbCarName.Text + "\" from the competition. All of its history will be deleted. The current race will also be reset.", "Delete \"" + content.tbCarName.Text + "\"?", "Keep", "Delete", delegate(DialogBox.DialogResult result) { if (result == DialogBox.DialogResult.MainOption) { DataManager.Competition.Racers.Remove(content._racer); content.triggerUpdatedRacer(); content.triggerDeletedRacer(); content._dialogHost.Close(); //close this host dialog } }); return(DialogButton.ReturnEvent.DoNothing); }) : null), new DialogButton((type == WindowType.Display ? "Revert" : "Forget"), DialogButton.Alignment.Right, DialogButton.Style.Flat, delegate() { if (type == WindowType.Display) { string changes = ""; if (content._racer.Car.Name != content.tbCarName.Text) { changes += Environment.NewLine + "Car's Name: " + content._racer.Car.Name + " -> " + content.tbCarName.Text; } if (content._racer.Car.ImageUri != DataManager.getRelativePath(content.imgCarPicture.Source.ToString())) { changes += Environment.NewLine + "Car's Image"; } if (content._racer.Maker.Name != content.tbCreatorName.Text) { changes += Environment.NewLine + "Creator's Name: " + content._racer.Maker.Name + " -> " + content.tbCreatorName.Text; } if (content._racer.Maker.ImageUri != DataManager.getRelativePath(content.imgCreatorPicture.Source.ToString())) { changes += Environment.NewLine + "Creator's Name"; } if (content._racer.Barcode != content.tbBarcode.Text) { changes += Environment.NewLine + "Barcode: " + content._racer.Barcode + " -> " + content.tbBarcode.Text; } if (content._racer.Class != content.cboClass.Text) { changes += Environment.NewLine + "Class: " + content._racer.Class + " -> " + content.cboClass.Text; } if (content._racer.PassedInspection != (content.passedInspect.IsChecked == true)) { changes += Environment.NewLine + "Passed Inspection: " + (content._racer.PassedInspection ? "Yes" : "No") + " -> " + ((content.passedInspect.IsChecked == true)?"Yes":"No"); } //no nothing, this will act like a revert if (changes.Length > 0) { DialogBox.showOptionBox(parent, "This will revert the following changes" + changes, "Revert Changes Made To \"" + content.tbCarName.Text + "\"?", "Keep", "Revert", delegate(DialogBox.DialogResult result) { if (result == DialogBox.DialogResult.MainOption) { content._dialogHost.Close(); //close this host dialog } }); } else { return(DialogButton.ReturnEvent.Close); } } else { bool changed = false; if ("" != content.tbCarName.Text) { changed = true; } if (DataManager.Settings.DefaltCarImageUri != DataManager.getRelativePath(content.imgCarPicture.Source.ToString())) { changed = true; } if ("" != content.tbCreatorName.Text) { changed = true; } if (DataManager.Settings.DefaltMakerImageUri != DataManager.getRelativePath(content.imgCreatorPicture.Source.ToString())) { changed = true; } if ("" != content.tbBarcode.Text) { changed = true; } if ("" != content.cboClass.Text) { changed = true; } if (false != (content.passedInspect.IsChecked == true)) { changed = true; } if (changed) { DialogBox.showOptionBox(parent, "This will erase all data entered for " + content.tbCarName.Text + ".", "Forget \"" + content.tbCarName.Text + "\"?", "Keep", "Forget", delegate(DialogBox.DialogResult result) { if (result == DialogBox.DialogResult.MainOption) { content._dialogHost.Close(); //close this host dialog } }); } else { return(DialogButton.ReturnEvent.Close); } } return(DialogButton.ReturnEvent.DoNothing); }), new DialogButton("Save", DialogButton.Alignment.Right, DialogButton.Style.Normal, delegate() { if (content.createSaveRacer()) //save racer on save button click { return(DialogButton.ReturnEvent.Close); } else { return(DialogButton.ReturnEvent.DoNothing); } })); }
public static void editOldRacer(Panel parent, Racer racer, racerUpdatedHandler returnHandler, racerDeletedHandler deleteHandler) { RacerDetails editor = new RacerDetails(WindowType.Display); editor.onUpdatedRacer += returnHandler; editor.onDeletedRacer += deleteHandler; editor._racer = racer; try { editor.imgCarPicture.Source = DataManager.loadImage(DataManager.getAbsoluteUri(racer.Car.ImageUri)); } catch (Exception ex1) { DataManager.MessageProvider.showError("Could Not Load Car's Picture. Falling Back to defalt.", ex1.Message); try { editor.imgCarPicture.Source = new BitmapImage(DataManager.getAbsoluteUri(DataManager.Settings.DefaltCarImageUri)); } catch (Exception ex2) { DataManager.MessageProvider.showError("Could Not Load Defalt Car's Picture.", ex2.Message); } } try { editor.imgCreatorPicture.Source = DataManager.loadImage(DataManager.getAbsoluteUri(racer.Maker.ImageUri)); } catch (Exception ex1) { DataManager.MessageProvider.showError("Could Not Load Creator's Picture. Falling Back to defalt.", ex1.Message); try { editor.imgCreatorPicture.Source = new BitmapImage(DataManager.getAbsoluteUri(DataManager.Settings.DefaltMakerImageUri)); } catch (Exception ex2) { DataManager.MessageProvider.showError("Could Not Load Defalt Creator's Picture", ex2.Message); } } editor.tbCarName.Text = racer.Car.Name; editor.tbCreatorName.Text = racer.Maker.Name; editor.tbBarcode.Text = racer.Barcode; editor.cboClass.Text = racer.Class; editor.passedInspect.IsChecked = racer.PassedInspection; editor.raceData.Children.Clear(); editor.raceData.ColumnDefinitions.Clear(); if (racer.Times.Count > 0) { editor.scores.Visibility = Visibility.Visible; double totalTime = 0; int totalAmount = 0; double bestTime = 10; editor.lbNoRaceData.Visibility = Visibility.Collapsed; for (int i = 0; i < DataManager.Settings.NumberOfLanes; i++) { editor.raceData.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }); //<Label Grid.Column="5" Content="6" FontSize="30" HorizontalAlignment="Center" VerticalAlignment="Center"/> Label lbLaneHeader = new Label(); lbLaneHeader.Content = (i + 1).ToString(); lbLaneHeader.FontSize = 30; lbLaneHeader.HorizontalAlignment = HorizontalAlignment.Center; lbLaneHeader.VerticalAlignment = VerticalAlignment.Center; lbLaneHeader.SetValue(Grid.RowProperty, 0); lbLaneHeader.SetValue(Grid.ColumnProperty, i); editor.raceData.Children.Add(lbLaneHeader); //<Border Grid.Column="6" Grid.Row="1" Grid.RowSpan="2" BorderThickness="0.5, 0, 1, 0" BorderBrush="{DynamicResource MaterialDesignDivider}" Margin="0, 16, 0, 8"/> Border border = new Border(); border.HorizontalAlignment = HorizontalAlignment.Stretch; border.VerticalAlignment = VerticalAlignment.Stretch; border.Margin = new Thickness(0, 8, 0, 8); border.BorderBrush = editor.FindResource("MaterialDesignDivider") as Brush; border.BorderThickness = new Thickness((i == 0 ? 0 : 0.5), 0, (i == DataManager.Settings.NumberOfLanes - 1 ? 0 : 0.5), 0); border.SetValue(Grid.RowProperty, 0); border.SetValue(Grid.RowSpanProperty, 2); border.SetValue(Grid.ColumnProperty, i); editor.raceData.Children.Add(border); StackPanel stp = new StackPanel(); stp.HorizontalAlignment = HorizontalAlignment.Center; stp.VerticalAlignment = VerticalAlignment.Top; stp.Orientation = Orientation.Vertical; stp.SetValue(Grid.RowProperty, 1); stp.SetValue(Grid.ColumnProperty, i); List<double> times = new List<double>(); foreach (Time time in racer.Times) { if (time.Lane == i + 1) { times.Add(time.Speed); } } times.Sort(); for (int t = 0; t < times.Count; t++) { Label lbTime = new Label(); lbTime.Content = String.Format("{0:0.000}", times[t]) + "s"; lbTime.FontSize = 18; if (t == 0) { totalTime += times[t]; totalAmount++; if (bestTime > times[t]) { bestTime = times[t]; } } else { lbTime.Opacity = 0.5; } lbTime.HorizontalAlignment = HorizontalAlignment.Center; lbTime.VerticalAlignment = VerticalAlignment.Top; lbTime.SetValue(Grid.RowProperty, 1); lbTime.SetValue(Grid.ColumnProperty, i); stp.Children.Add(lbTime); } editor.timeAverage.Text = String.Format("{0:0.000}", (totalTime / totalAmount)) + "s"; editor.timeBest.Text = String.Format("{0:0.000}", bestTime) + "s"; editor.raceData.Children.Add(stp); } } MakeDialog(parent, editor, WindowType.Display); }
private static void MakeDialog(Panel parent, RacerDetails content, WindowType type) { content._dialogHost = new Dialog(parent, content, false, false, true, delegate () { if (content._type == WindowType.Display)//only allow saving after clicking of dialog, if not creating a new car { if (content.createSaveRacer()) { return DialogButton.ReturnEvent.Close; } else { return DialogButton.ReturnEvent.DoNothing; } } else { return DialogButton.ReturnEvent.DoNothing; } }, (type == WindowType.Display ? new DialogButton("Delete", DialogButton.Alignment.Left, DialogButton.Style.Flat, delegate () { DialogBox.showOptionBox(parent, "This will completly remove \"" + content.tbCarName.Text + "\" from the competition. All of its history will be deleted. The current race will also be reset.", "Delete \"" + content.tbCarName.Text + "\"?", "Keep", "Delete", delegate (DialogBox.DialogResult result) { if (result == DialogBox.DialogResult.MainOption) { DataManager.Competition.Racers.Remove(content._racer); content.triggerUpdatedRacer(); content.triggerDeletedRacer(); content._dialogHost.Close();//close this host dialog } }); return DialogButton.ReturnEvent.DoNothing; }) : null), new DialogButton((type == WindowType.Display ? "Revert" : "Forget"), DialogButton.Alignment.Right, DialogButton.Style.Flat, delegate () { if(type == WindowType.Display) { string changes = ""; if (content._racer.Car.Name != content.tbCarName.Text) { changes += Environment.NewLine + "Car's Name: " + content._racer.Car.Name + " -> " + content.tbCarName.Text; } if (content._racer.Car.ImageUri != DataManager.getRelativePath(content.imgCarPicture.Source.ToString())) { changes += Environment.NewLine + "Car's Image"; } if (content._racer.Maker.Name != content.tbCreatorName.Text) { changes += Environment.NewLine + "Creator's Name: " + content._racer.Maker.Name + " -> " + content.tbCreatorName.Text; } if (content._racer.Maker.ImageUri != DataManager.getRelativePath(content.imgCreatorPicture.Source.ToString())) { changes += Environment.NewLine + "Creator's Name"; } if (content._racer.Barcode != content.tbBarcode.Text) { changes += Environment.NewLine + "Barcode: " + content._racer.Barcode + " -> " + content.tbBarcode.Text; } if (content._racer.Class != content.cboClass.Text) { changes += Environment.NewLine + "Class: " + content._racer.Class + " -> " + content.cboClass.Text; } if (content._racer.PassedInspection != (content.passedInspect.IsChecked == true)) { changes += Environment.NewLine + "Passed Inspection: " + (content._racer.PassedInspection ? "Yes" : "No") + " -> " + ((content.passedInspect.IsChecked == true)?"Yes":"No"); } //no nothing, this will act like a revert if (changes.Length > 0) { DialogBox.showOptionBox(parent, "This will revert the following changes" + changes, "Revert Changes Made To \"" + content.tbCarName.Text + "\"?", "Keep", "Revert", delegate (DialogBox.DialogResult result) { if (result == DialogBox.DialogResult.MainOption) { content._dialogHost.Close();//close this host dialog } }); } else { return DialogButton.ReturnEvent.Close; } } else { bool changed = false; if ("" != content.tbCarName.Text) { changed = true; } if (DataManager.Settings.DefaltCarImageUri != DataManager.getRelativePath(content.imgCarPicture.Source.ToString())) { changed = true; } if ("" != content.tbCreatorName.Text) { changed = true; } if (DataManager.Settings.DefaltMakerImageUri != DataManager.getRelativePath(content.imgCreatorPicture.Source.ToString())) { changed = true; } if ("" != content.tbBarcode.Text) { changed = true; } if ("" != content.cboClass.Text) { changed = true; } if (false != (content.passedInspect.IsChecked == true)) { changed = true; } if (changed) { DialogBox.showOptionBox(parent, "This will erase all data entered for " + content.tbCarName.Text + ".", "Forget \"" + content.tbCarName.Text + "\"?", "Keep", "Forget", delegate (DialogBox.DialogResult result) { if (result == DialogBox.DialogResult.MainOption) { content._dialogHost.Close();//close this host dialog } }); } else { return DialogButton.ReturnEvent.Close; } } return DialogButton.ReturnEvent.DoNothing; }), new DialogButton("Save", DialogButton.Alignment.Right, DialogButton.Style.Normal, delegate () { if (content.createSaveRacer())//save racer on save button click { return DialogButton.ReturnEvent.Close; } else { return DialogButton.ReturnEvent.DoNothing; } })); }