示例#1
0
        private void addPointButton_Click(object sender, EventArgs e)
        {
            using (TorqueCurveForm frm = new TorqueCurveForm((int)torqueBox.Value))
            {
                var result = frm.ShowDialog();
                if (result == DialogResult.Yes)
                {
                    // Create the new Ratio
                    TorqueRatio ratio = frm.GetRatio();
                    Ratios.Add(ratio);

                    // Flag change
                    RatiosChanged = true;

                    // Force Points Redraw
                    PopulateTorqueRatios();

                    // Force a chart redraw
                    torqueBox_ValueChanged(this, EventArgs.Empty);
                }
            }
        }
示例#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);
                }
            }
        }
示例#3
0
        public EngineForm(Engine engine = null)
        {
            // Create form controls
            InitializeComponent();
            headerPanel.BackColor = Color.FromArgb(51, 53, 53);
            chart1.ChartAreas[0].AxisX.Interval = 300;

            NewEngine = engine == null;
            Engine    = engine ?? new Engine();
            Sorter    = new ListViewColumnSorter(truckListView)
            {
                Order = SortOrder.Ascending
            };

            // Setup metrics
            if (Program.Config.UnitSystem == UnitSystem.Metric)
            {
                labelTorque.Text                 = "Newton Metres:";
                labelPeakTorque.Text             = "Peak N·m RPM:";
                chart1.ChartAreas[0].AxisY.Title = "Newton Metres";
                maxTorqueLabel.Text              = "Max Newton Metres:";
            }

            // Add each sound to the lists
            using (AppDatabase db = new AppDatabase())
            {
                foreach (EngineSeries model in db.EngineSeries.OrderBy(x => x.ToString()))
                {
                    engineModelBox.Items.Add(model);
                    if (!NewEngine && model.Id == Engine.SeriesId)
                    {
                        engineModelBox.SelectedIndex = engineModelBox.Items.Count - 1;
                    }
                }

                if (!NewEngine)
                {
                    Ratios.AddRange(engine.TorqueRatios);
                }
                else
                {
                    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
                    });
                }

                // Grab a list of trucks that use this engine
                List <int> trucks = new List <int>();
                if (!NewEngine)
                {
                    trucks.AddRange(engine.ItemOf.Select(x => x.TruckId));
                }

                // Add trucks to the truck list
                foreach (var truck in db.Trucks)
                {
                    ListViewItem item = new ListViewItem(truck.Name);
                    item.Tag     = truck.Id;
                    item.Checked = trucks.Contains(truck.Id);
                    truckListView.Items.Add(item);
                }
            }

            // Are we editing an engine?
            if (!NewEngine)
            {
                // Set form values
                unitNameBox.Text            = engine.UnitName;
                engineNameBox.Text          = engine.Name;
                unlockBox.Value             = engine.Unlock;
                priceBox.Value              = engine.Price;
                horsepowerBox.Value         = engine.Horsepower;
                peakRPMBox.Value            = engine.PeakRpm;
                idleRpmBox.Value            = engine.IdleRpm;
                rpmLimitBox.Value           = engine.RpmLimit;
                neutralRpmBox.Value         = engine.RpmLimitNeutral;
                brakeStrengthBox.Value      = engine.BrakeStrength;
                brakePositionsBox.Value     = engine.BrakePositions;
                automaticDSCheckBox.Checked = engine.BrakeDownshift;
                rpmRangeBox1.Value          = engine.MinRpmRange_LowGear;
                rpmRangeBox2.Value          = engine.MaxRpmRange_LowGear;
                rpmRangeBox3.Value          = engine.MinRpmRange_HighGear;
                rpmRangeBox4.Value          = engine.MaxRpmRange_HighGear;
                rpmRangeBox5.Value          = engine.LowRpmRange_PowerBoost;
                rpmRangeBox6.Value          = engine.HighRpmRange_PowerBoost;
                fileDefaultsTextBox.Lines   = engine.Defaults;
                fileOverridesTextBox.Lines  = engine.Overrides;
                fileCommentTextBox.Lines    = engine.Comment;
                filenameTextBox.Text        = engine.FileName;
                conflictsTextBox.Lines      = engine.Conflicts;
                engineBrakeLow.Value        = engine.LowRpmRange_EngineBrake;
                engineBrakeHigh.Value       = engine.HighRpmRange_EngineBrake;
                resistanceBox.Value         = engine.ResistanceTorque;
                consumptionBox.Value        = engine.FuelConsumption * 100;
                adBlueConsumption.Value     = engine.AdblueConsumption;
                adBlueNoPowerLimit.Value    = engine.NoAdbluePowerLimit;

                // Set torque last, to update the chart
                torqueBox.Value = (Program.Config.UnitSystem == UnitSystem.Imperial)
                    ? engine.Torque
                    : engine.NewtonMetres;
            }

            // Fill torque ratios
            PopulateTorqueRatios();

            // Fill Conflicts
            PopulateTransmissions();

            if (NewEngine)
            {
                // Force change to update graph
                torqueBox.Value = (Program.Config.UnitSystem == UnitSystem.Imperial)
                    ? 1650 :
                                  Metrics.TorqueToNewtonMeters(1650m);
            }
        }
示例#4
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;
        }