/// <summary> /// Update timer tick event /// </summary> /// <param name="sender">Sender</param> /// <param name="e">Event arguments</param> private void updateTimer_Tick(object sender, EventArgs e) { if (takeScreenshot) { takeScreenshot = false; TakeScreenshot(); } if (api != null) { Ets2Telemetry data = telemetryData; if ((data != null) && updateTelemetryData) { bool game_running = Utils.IsAGameRunning && (data.TruckId.Length > 0); dataPanel.Visible = game_running; healthPanel.Visible = game_running; speedPanel.Visible = game_running; speedChart.Visible = game_running; gameNameLabel.Text = Utils.IsAGameRunning ? Utils.RunningGameName : startGameNowTranslated; if (game_running) { speedLabel.Text = (Configuration.UseMetricUnit ? (Math.Round(Math.Abs(data.Drivetrain.SpeedKmh)) + " km/h") : (Math.Round(Math.Abs(data.Drivetrain.SpeedMph)) + " mph")) + (data.Drivetrain.CruiseControl ? ("; " + cruiseControlTranslated + ": " + (Configuration.UseMetricUnit ? (Math.Round(data.Drivetrain.CruiseControlSpeedKmh) + " km/h") : (Math.Round(data.Drivetrain.CruiseControlSpeedMph) + " mph"))) : ""); float delta_speed_limit = data.Drivetrain.Speed - data.Job.SpeedLimit; speedLabel.ForeColor = ((data.Job.SpeedLimit <= 0.0f) ? Color.White : Utils.ColorGradient(Color.White, Color.Red, delta_speed_limit / 1.4f)); speedLimitLabel.Text = speedLimitTranslated + ": " + ((data.Job.SpeedLimit == -1.0f) ? unlimitedTranslated : Math.Round(Utils.ConvertSpeed(data.Job.SpeedLimit)) + (Configuration.UseMetricUnit ? " km/h" : " mph")); vehicleLabel.Text = vehicleTranslated + ": " + data.Manufacturer + " " + data.Truck; if (data.Job.OnJob) { statusLabel.Text = statusTranslated + ": " + deliverCargoTranslated; cargoLabel.Text = cargoTranslated + ": " + data.Job.Cargo; sourceLabel.Text = sourceTranslated + ": " + data.Job.CompanySource + " " + inTranslated + " " + Cities.GetFullCityName(data.Job.CitySource); destinationLabel.Text = destinationTranslated + ": " + data.Job.CompanyDestination + " " + inTranslated + " " + Cities.GetFullCityName(data.Job.CityDestination); routeLabel.Text = routeTranslated + ": " + Utils.HumanReadableLength(Utils.Clamp(api.Distance - data.Job.NavigationDistanceLeft, 0.0f, api.Distance)) + " " + ofTranslated + " " + Utils.HumanReadableLength(api.Distance) + " (" + ((api.Distance > float.Epsilon) ? Math.Round(((api.Distance - data.Job.NavigationDistanceLeft) * 100.0f) / api.Distance) : 100.0f) + "%)"; remainingTimeLabel.Text = remainingTimeTranslated + ": " + Utils.HumanReadableTime(data.Job.NavigationTimeLeft); //timeLabel.Text = timeTranslated + ": " + Utils.HumanReadableTime(data.Job.NavigationTimeLeft) + " " + ofTranslated + " " + Utils.HumanReadableTime(api.Time); yieldLabel.Text = yieldTranslated + ": " + data.Job.Income.ToString("N0") + "€"; weightLabel.Text = weightTranslated + ": " + Utils.HumanReadableWeight(data.Job.Mass); deadlineLabel.Text = deadlineTranslated + ": " + ((data.Job.Deadline == -1) ? unlimitedTranslated : deadlineAvailableTranslated); } else { statusLabel.Text = statusTranslated + ": " + idleTranslated; cargoLabel.Text = ""; sourceLabel.Text = ""; destinationLabel.Text = ""; routeLabel.Text = ""; remainingTimeLabel.Text = ""; yieldLabel.Text = ""; weightLabel.Text = ""; deadlineLabel.Text = ""; } totalRouteLabel.Text = totalRouteTranslated + ": " + Utils.HumanReadableLength(totalRoute); totalWeightLabel.Text = totalWeightTranslated + ": " + Utils.HumanReadableWeight(totalWeight); totalYieldLabel.Text = totalYieldTranslated + ": " + totalYield + "€"; cabinLabel.Text = cabinTranslated + ": " + Math.Round(data.Damage.WearCabin * 100.0f) + "%"; chassisLabel.Text = chassisTranslated + ": " + Math.Round(data.Damage.WearChassis * 100.0f) + "%"; engineLabel.Text = engineTranslated + ": " + Math.Round(data.Damage.WearEnigne * 100.0f) + "%"; transmissionLabel.Text = transmissionTranslated + ": " + Math.Round(data.Damage.WearTransmission * 100.0f) + "%"; wheelsLabel.Text = wheelsTranslated + ": " + Math.Round(data.Damage.WearWheels * 100.0f) + "%"; trailerLabel.Text = (data.Job.TrailerAttached) ? (trailerTranslated + ": " + Math.Round(data.Damage.WearTrailer * 100.0f) + "%") : ""; averageLabel.Text = averageTranslated + ": " + Math.Round((data.Damage.WearCabin + data.Damage.WearChassis + data.Damage.WearEnigne + data.Damage.WearTransmission + data.Damage.WearWheels) * 20.0f) + "%"; float max_damage = Math.Max(data.Damage.WearCabin, Math.Max(data.Damage.WearChassis, Math.Max(data.Damage.WearEnigne, Math.Max(data.Damage.WearTransmission, data.Damage.WearWheels)))); int image_id = 0; if (max_damage >= 0.9f) { image_id = 4; } else if (max_damage >= 0.7f) { image_id = 3; } else if (max_damage >= 0.5f) { image_id = 2; } else if (max_damage >= 0.3f) { image_id = 1; } else if (max_damage >= 0.0f) { image_id = 0; } drivetrainPanel.BackgroundImage = drivetrainImages[image_id]; max_damage = data.Damage.WearTrailer; if (data.Job.TrailerAttached) { if (max_damage >= 0.9f) { image_id = 5; } else if (max_damage >= 0.7f) { image_id = 4; } else if (max_damage >= 0.5f) { image_id = 3; } else if (max_damage >= 0.3f) { image_id = 2; } else if (max_damage >= 0.0f) { image_id = 1; } } else { image_id = 0; } cargoPictureBox.Image = cargoImages[image_id]; double fuel_part = data.Drivetrain.Fuel / (double)(data.Drivetrain.FuelMax); double fuel_percentage = Math.Round(fuel_part * 100.0); fuelLabel.Text = fuelTranslated + ": " + Math.Round(data.Drivetrain.Fuel) + " l " + ofTranslated + " " + Math.Round(data.Drivetrain.FuelMax) + " l (" + Math.Round(data.Drivetrain.FuelAvgConsumption * 100.0f, 2) + " l / 100 km); " + fuel_percentage + "%"; fuelRemainingDistanceLabel.Text = fuelRemainingDistanceTranslated + ": " + Math.Round(data.Drivetrain.FuelRange) + (Configuration.UseMetricUnit ? " km" : " ml"); fuelStatusLabel.Text = fuelStatusTranslated + ": " + ((fuel_percentage <= 15.0) ? pleaseRefillFuelTranslated : (data.Job.OnJob ? ((data.Drivetrain.FuelRange < (data.Job.NavigationDistanceLeft * 0.001f)) ? refillLaterTranslated : enoughFuelTranslated) : ((fuel_percentage < 30.0) ? lowFuelTranslated : enoughFuelTranslated))); fuelStatusLabel.ForeColor = ((fuel_percentage <= 15.0) ? Color.Red : Color.White); if ((currentGameTime != data.Time) && isJobRunning) { currentGameTime = data.Time; ++chartUpdateTickCounter; if ((chartUpdateTickCounter % 400) == 0) { chartUpdateTickCounter = 0; lock (currentSpeedData) { currentSpeedData.Add(Math.Round(Configuration.UseMetricUnit ? data.Drivetrain.SpeedKmh : data.Drivetrain.SpeedMph, 2)); speedChart.Series[0].Points.DataBindY(currentSpeedData); } lock (speedLimitData) { speedLimitData.Add(Math.Abs(Utils.ConvertSpeed((data.Job.SpeedLimit == -1.0f) ? 0.0f : data.Job.SpeedLimit))); speedChart.Series[1].Points.DataBindY(speedLimitData); } } } fuelGaugeNeedlePictureBox.Location = new Point(fuelGaugeNeedleOffset + (int)(fuelGaugeNeedleRange * fuel_part), fuelGaugeNeedlePictureBox.Location.Y); updateTelemetryData = false; } } } }
/// <summary> /// Update rows /// </summary> private void UpdateRows() { UserData[] users = MainForm.Instance.Users; usersDataTable.Rows.Clear(); foreach (UserData user in users) { DataRow row = usersDataTable.NewRow(); object[] data = new object[11]; data[0] = user.Name; data[1] = Math.Round(Math.Abs(Utils.ConvertSpeed(user.Speed))) + (Configuration.UseMetricUnit ? " km/h" : " mph"); data[2] = (user.SpeedLimit < 0.0f) ? unlimitedTranslated : (Math.Round(Math.Abs(Utils.ConvertSpeed(user.SpeedLimit))) + (Configuration.UseMetricUnit ? " km/h" : " mph")); data[3] = user.Manufacturer + " " + user.Truck; data[4] = user.OnJob ? user.Cargo : notAvailableTranslated; data[5] = user.OnJob ? (user.CompanySource + " " + inTranslated + " " + Cities.GetFullCityName(user.CitySource)) : notAvailableTranslated; data[6] = user.OnJob ? (user.CompanyDestination + " " + inTranslated + " " + Cities.GetFullCityName(user.CityDestination)) : notAvailableTranslated; data[7] = user.OnJob ? (Utils.HumanReadableLength(Utils.Clamp(user.Distance - user.NavigationDistanceLeft, 0.0f, user.Distance)) + " " + ofTranslated + " " + Utils.HumanReadableLength(user.Distance) + " (" + ((user.Distance > float.Epsilon) ? Math.Round(((user.Distance - user.NavigationDistanceLeft) * 100.0f) / user.Distance) : 100.0f) + "%)") : notAvailableTranslated; data[8] = user.OnJob ? (Utils.HumanReadableTime(user.NavigationTimeLeft)) : notAvailableTranslated; data[9] = user.OnJob ? (user.Income.ToString("N0") + "€") : notAvailableTranslated; data[10] = user.OnJob ? Utils.HumanReadableWeight(user.Mass) : notAvailableTranslated; row.ItemArray = data; usersDataTable.Rows.Add(row); } }