/// <summary> /// Method called whenever a gear is modified. This method will move the gear /// to the Forward or Reverse gear depending. /// </summary> /// <param name="oldGear">The gear before the changes</param> /// <param name="newGear">The new gear values</param> /// <param name="index">The index the oldGear is at in its corresponding list</param> /// <returns></returns> private bool OnGearEdit(TransmissionGear oldGear, TransmissionGear newGear, int index) { // Are we switching from forward to reverse (or vise-versa)? if (oldGear.IsReverse != newGear.IsReverse) { if (newGear.IsReverse) { ReverseGears.Add(newGear); ForwardGears.RemoveAt(index); } else { ForwardGears.Add(newGear); ReverseGears.RemoveAt(index); } } else { var list = (newGear.IsReverse) ? ReverseGears : ForwardGears; list[index] = newGear; } return(true); }
private void importButton_Click(object sender, EventArgs e) { // Request the user supply the steam library path OpenFileDialog Dialog = new OpenFileDialog(); Dialog.Title = "Transmission SII File Import"; Dialog.Filter = "SiiNunit|*.sii"; if (Dialog.ShowDialog() == DialogResult.OK) { try { // Create document var document = new SiiDocument(typeof(AccessoryTransmissionData), typeof(TransmissionNames)); using (FileStream stream = File.OpenRead(Dialog.FileName)) using (StreamReader reader = new StreamReader(stream)) { // Read the file contents string contents = reader.ReadToEnd().Trim(); document.Load(contents); // Grab the engine object List <string> objects = new List <string>(document.Definitions.Keys); if (objects.Count == 0) { MessageBox.Show("Unable to find any transmission data in this sii document!", "Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning ); return; } // Grab the transmission var transmission = document.GetDefinition <AccessoryTransmissionData>(objects[0]); // === Set form values unitNameBox.Text = Path.GetFileNameWithoutExtension(Dialog.FileName); transNameBox.Text = transmission.Name; unlockBox.SetValueInRange(transmission.UnlockLevel); priceBox.SetValueInRange(transmission.Price); diffRatio.SetValueInRange(transmission.DifferentialRatio); if (transmission.StallTorqueRatio > 0m) { stallRatio.SetValueInRange(transmission.StallTorqueRatio); hasTorqueConverter.Checked = true; } if (transmission.Retarder > 0) { retardPositions.SetValueInRange(transmission.Retarder); hasRetarder.Checked = true; } fileDefaultsTextBox.Lines = transmission.Defaults; filenameTextBox.Text = Path.GetFileName(Dialog.FileName); conflictsTextBox.Lines = transmission.Conflicts; suitablesTextBox.Lines = transmission.Suitables; // Clear chart points and gears chart1.Series[0].Points.Clear(); gearListView.Items.Clear(); ForwardGears.Clear(); ReverseGears.Clear(); // Set gear ratios var nameList = transmission.GearNames?.Reverse?.ToList(); int i = 0; foreach (var item in transmission.ReverseRatios) { string name = (nameList != null && i < nameList.Count) ? nameList[i] : string.Empty; ReverseGears.Add(new TransmissionGear() { Name = name, Ratio = item, GearIndex = i++ }); } nameList = transmission.GearNames?.Forward?.ToList(); i = 0; foreach (var item in transmission.ForwardRatios) { string name = (nameList != null && i < nameList.Count) ? nameList[i] : string.Empty; ForwardGears.Add(new TransmissionGear() { Name = name, Ratio = item, GearIndex = i++ }); } // Fill ratio view PopulateGears(); // Flag GearsChanged = true; // Defaults (skip sounds) if (transmission.Defaults != null) { fileDefaultsTextBox.Lines = transmission.Defaults; } // Alert the user MessageBox.Show( $"Successfully imported the transmission \"{transmission.Name}\"! You must now select a series for this transmission.", "Import Successful", MessageBoxButtons.OK, MessageBoxIcon.Information ); } } catch (SiiSyntaxException ex) { StringBuilder builder = new StringBuilder("A Syntax error occured while parsing the sii file!"); builder.AppendLine(); builder.AppendLine(); builder.AppendLine($"Message: {ex.Message.Replace("\0", "\\0")}"); builder.AppendLine(); builder.AppendLine($"Line: {ex.Span.Start.Line}"); builder.AppendLine($"Column: {ex.Span.Start.Column}"); MessageBox.Show(builder.ToString(), "Sii Syntax Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (SiiException ex) { StringBuilder builder = new StringBuilder("Failed to parse the sii file."); builder.AppendLine(); builder.AppendLine($"Message: {ex.Message}"); MessageBox.Show(builder.ToString(), "Sii Exception", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { MessageBox.Show(ex.Message, "An Error Occured", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }