Exemplo n.º 1
0
        private void removeAllButton_Click(object sender, EventArgs e)
        {
            var result = MessageBox.Show(
                "Are you sure you want to remove all torque curve points? "
                + "Any changes made to the current power curves will be undone.",
                "Remove All Torque Curves", MessageBoxButtons.YesNo, MessageBoxIcon.Warning
                );

            // If yes is not selected, get outta here!
            if (result != DialogResult.Yes)
            {
                return;
            }

            // Remove all ratios
            Ratios.Clear();

            // Flag change
            RatiosChanged = true;

            // Clear out any old items
            ratioListView.Items.Clear();

            // Force a chart redraw
            torqueBox_ValueChanged(this, EventArgs.Empty);
        }
Exemplo n.º 2
0
        private void importButton_Click(object sender, EventArgs e)
        {
            // Request the user supply the steam library path
            var dialog = new OpenFileDialog();

            dialog.Title  = "Engine SII File Import";
            dialog.Filter = "SiiNunit|*.sii";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    var document = new SiiDocument(typeof(AccessoryEngineData));

                    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 engine data in this sii document!",
                                                "Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning
                                                );
                                return;
                            }

                            // Grab the engine
                            var engine = document.GetDefinition <AccessoryEngineData>(objects[0]);

                            // === Set form values
                            int len = objects[0].IndexOf('.');
                            unitNameBox.Text     = objects[0].Substring(0, len);
                            engineNameBox.Text   = engine.Name;
                            filenameTextBox.Text = Path.GetFileName(dialog.FileName);
                            unlockBox.SetValueInRange(engine.UnlockLevel);
                            priceBox.SetValueInRange(engine.Price);
                            neutralRpmBox.SetValueInRange(engine?.RpmLimitNeutral ?? 2200);
                            rpmLimitBox.SetValueInRange((decimal)engine.RpmLimit);
                            idleRpmBox.SetValueInRange(engine?.IdleRpm ?? 650);
                            brakeStrengthBox.SetValueInRange((decimal)engine.BrakeStrength);
                            brakePositionsBox.SetValueInRange(engine.BrakePositions);
                            automaticDSCheckBox.Checked = engine.BrakeDownshift == 1;

                            // Misc
                            if (engine.RpmRangeEngineBrake.X > 0f)
                            {
                                engineBrakeLow.SetValueInRange((int)engine.RpmRangeEngineBrake.X);
                                engineBrakeHigh.SetValueInRange((int)engine.RpmRangeEngineBrake.Y);
                            }
                            consumptionBox.SetValueInRange((decimal)engine.FuelConsumption * 100);
                            adBlueConsumption.SetValueInRange((decimal)engine.AdblueConsumption);
                            adBlueNoPowerLimit.SetValueInRange((decimal)engine.NoAdbluePowerLimit);
                            conflictsTextBox.Lines = engine?.Conflicts ?? new string[] { };

                            // Tab 3
                            if (engine.RpmRange_LowGear.X > 0f)
                            {
                                rpmRangeBox1.SetValueInRange((int)engine.RpmRange_LowGear.X);
                                rpmRangeBox2.SetValueInRange((int)engine.RpmRange_LowGear.Y);
                            }
                            if (engine.RpmRange_HighGear.X > 0f)
                            {
                                rpmRangeBox3.SetValueInRange((int)engine.RpmRange_HighGear.X);
                                rpmRangeBox4.SetValueInRange((int)engine.RpmRange_HighGear.Y);
                            }
                            if (engine.RpmRange_PowerBoost.X > 0f)
                            {
                                rpmRangeBox5.SetValueInRange((int)engine.RpmRange_PowerBoost.X);
                                rpmRangeBox6.SetValueInRange((int)engine.RpmRange_PowerBoost.Y);
                            }

                            // Parse Horsepower
                            Regex reg = new Regex("^(?<hp>[0-9]+)", RegexOptions.Multiline);
                            if (reg.IsMatch(engine.Info[0]))
                            {
                                horsepowerBox.SetValueInRange(Int32.Parse(reg.Match(engine.Info[0]).Groups["hp"].Value));
                            }

                            if (engine.TorqueCurves?.Length > 0)
                            {
                                // Clear torque curves
                                chart1.Series[0].Points.Clear();
                                ratioListView.Items.Clear();
                                Ratios.Clear();

                                // Set new torque curves
                                foreach (Vector2 vector in engine.TorqueCurves)
                                {
                                    TorqueRatio ratio = new TorqueRatio();
                                    ratio.RpmLevel = (int)vector.X;
                                    ratio.Ratio    = Math.Round(vector.Y, 4);
                                    Ratios.Add(ratio);
                                }

                                // Fill ratio view
                                PopulateTorqueRatios();
                            }

                            // Set torque value
                            torqueBox.SetValueInRange((Program.Config.UnitSystem == UnitSystem.Imperial)
                            ? Metrics.NewtonMetersToTorque((decimal)engine.Torque, torqueBox.DecimalPlaces)
                            : Math.Round((decimal)engine.Torque, torqueBox.DecimalPlaces)
                                                      );

                            // Defaults (skip sounds)
                            if (engine.Defaults != null)
                            {
                                fileDefaultsTextBox.Lines = (from x in engine.Defaults where !x.Contains("/sound/") select x).ToArray();
                            }

                            // Overrides (skip sounds)
                            if (engine.Overrides != null)
                            {
                                fileOverridesTextBox.Lines = (from x in engine.Overrides where !x.Contains("/sound/") select x).ToArray();
                            }

                            // Alert the user
                            MessageBox.Show(
                                $"Successfully imported the engine \"{engine.Name}\"! You must now select an engine series for this engine.",
                                "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);
                }
            }
        }
Exemplo n.º 3
0
        private void resetPointsButton_Click(object sender, EventArgs e)
        {
            if (Ratios.Count > 0)
            {
                var result = MessageBox.Show(
                    "Are you sure you want to reset the torque curve points to the default values? "
                    + "Any changes made to the current power curves will be undone.",
                    "Reset Torque Curve", MessageBoxButtons.YesNo, MessageBoxIcon.Warning
                    );

                // If yes is not selected, get outta here!
                if (result != DialogResult.Yes)
                {
                    return;
                }

                // Remove all ratios
                Ratios.Clear();

                // Flag change
                RatiosChanged = true;
            }

            // Lock button
            resetPointsButton.Enabled = false;

            // Add default ratios
            Ratios.Add(new TorqueRatio()
            {
                Ratio = 0, RpmLevel = 300
            });
            Ratios.Add(new TorqueRatio()
            {
                Ratio = 0.5, RpmLevel = 440
            });
            Ratios.Add(new TorqueRatio()
            {
                Ratio = 1, RpmLevel = 1100
            });
            Ratios.Add(new TorqueRatio()
            {
                Ratio = 1, RpmLevel = 1400
            });
            Ratios.Add(new TorqueRatio()
            {
                Ratio = 0.77, RpmLevel = 1900
            });
            Ratios.Add(new TorqueRatio()
            {
                Ratio = 0.5, RpmLevel = 2400
            });
            Ratios.Add(new TorqueRatio()
            {
                Ratio = 0, RpmLevel = 2600
            });

            // Force Points Redraw
            PopulateTorqueRatios();

            // Force a chart redraw
            torqueBox_ValueChanged(this, EventArgs.Empty);

            // Enable Button
            resetPointsButton.Enabled = true;
        }