private void UpdateTrailerPanelLicensePlate() { UserTrailerDictionary.TryGetValue(comboBoxUserTrailerCompanyTrailers.SelectedValue.ToString(), out UserCompanyTruckData SelectedUserCompanyTrailer); string LicensePlate = SelectedUserCompanyTrailer.Parts.Find(xp => xp.PartType == "trailerdata").PartData.Find(xl => xl.StartsWith(" license_plate:")).Split(new char[] { '"' })[1]; SCS.SCSLicensePlate thisLP = new SCS.SCSLicensePlate(LicensePlate, SCS.SCSLicensePlate.LPtype.Truck); //Find label control Label lpText = groupBoxUserTrailerTrailerDetails.Controls.Find("labelLicensePlateTrailer", true).FirstOrDefault() as Label; if (lpText != null) { lpText.Text = thisLP.LicensePlateTXT + " | "; string value = null; CountriesLngDict.TryGetValue(thisLP.SourceLPCountry, out value); if (value != null && value != "") { lpText.Text += value; } else { string CapName = CultureInfo.InvariantCulture.TextInfo.ToTitleCase(thisLP.SourceLPCountry); lpText.Text += CapName; } } // Panel lpPanel = groupBoxUserTrailerTrailerDetails.Controls.Find("TrailerLicensePlateIMG", true).FirstOrDefault() as Panel; if (lpPanel != null) { lpPanel.BackgroundImage = Utilities.TS_Graphics.ResizeImage(thisLP.LicensePlateIMG, LicensePlateWidth[GameType], 32); //ETS - 128x32 or ATS - 128x64 | 64x32 } }
private void UpdateTrailerPanelProgressBars() { UserTrailerDictionary.TryGetValue(comboBoxUserTrailerCompanyTrailers.SelectedValue.ToString(), out UserCompanyTruckData SelectedUserCompanyTrailer); if (SelectedUserCompanyTrailer == null) { return; } for (int i = 0; i < 4; i++) { Panel pnl = null; string pnlname = "progressbarTrailerPart" + i.ToString(); if (groupBoxUserTrailerTrailerDetails.Controls.ContainsKey(pnlname)) { pnl = groupBoxUserTrailerTrailerDetails.Controls[pnlname] as Panel; } if (pnl != null) { UserCompanyTruckDataPart tempPart = null; switch (i) { case 0: tempPart = SelectedUserCompanyTrailer.Parts.Find(xp => xp.PartType == "trailerdata"); break; case 1: tempPart = SelectedUserCompanyTrailer.Parts.Find(xp => xp.PartType == "body"); break; case 2: tempPart = SelectedUserCompanyTrailer.Parts.Find(xp => xp.PartType == "chassis"); break; case 3: tempPart = SelectedUserCompanyTrailer.Parts.Find(xp => xp.PartType == "tire"); break; } string wear = "0"; decimal _wear = 0; if (tempPart != null) { try { List <string> TruckDataPart = tempPart.PartData; wear = TruckDataPart.Find(xl => xl.StartsWith(" wear:") || xl.StartsWith(" cargo_damage:")).Split(new char[] { ' ' })[2]; } catch { } } if (wear != "0" && wear != "1") { try { _wear = Utilities.NumericUtilities.HexFloatToDecimalFloat(wear); } catch { _wear = 1; } } else if (wear == "1") { _wear = 1; } SolidBrush ppen = new SolidBrush(GetProgressbarColor(_wear)); int x = 0, y = 0, pnlwidth = (int)(pnl.Width * (1 - _wear)); Bitmap progress = new Bitmap(pnl.Width, pnl.Height); Graphics g = Graphics.FromImage(progress); g.FillRectangle(ppen, x, y, pnlwidth, pnl.Height); int fontSize = 12; StringFormat sf = new StringFormat(); sf.LineAlignment = StringAlignment.Center; sf.Alignment = StringAlignment.Center; GraphicsPath p = new GraphicsPath(); p.AddString( ((int)((1 - _wear) * 100)).ToString() + " %", // text to draw FontFamily.GenericSansSerif, // or any other font family (int)FontStyle.Bold, // font style (bold, italic, etc.) g.DpiY * fontSize / 72, // em size new Rectangle(0, 0, pnl.Width, pnl.Height), // location where to draw text sf); // set options here (e.g. center alignment) g.SmoothingMode = SmoothingMode.AntiAlias; g.FillPath(Brushes.Black, p); g.DrawPath(Pens.Black, p); pnl.BackgroundImage = progress; } } string lctxt = ""; labelLicensePlateTr.Text = ""; int stindex = 0, endindex = 0; string LicensePlate = SelectedUserCompanyTrailer.Parts.Find(xp => xp.PartType == "trailerdata").PartData.Find(xl => xl.StartsWith(" license_plate:")).Split(new char[] { '"' })[1]; for (int i = 0; i < LicensePlate.Length; i++)//SelectedUserCompanyTruck.LicensePlate.Length; i++) { if (LicensePlate[i] == '<') { endindex = i; lctxt += LicensePlate.Substring(stindex, endindex - stindex); } else if (LicensePlate[i] == '>') { stindex = i + 1; } else if (i == LicensePlate.Length - 1) { endindex = i + 1; lctxt += LicensePlate.Substring(stindex, endindex - stindex); } } if (lctxt.Split(new char[] { '|' }).Length > 1) { labelLicensePlateTr.Text = lctxt.Split(new char[] { '|' })[0] + " Country " + lctxt.Split(new char[] { '|' })[1]; } else { labelLicensePlateTr.Text = lctxt.Split(new char[] { '|' })[0]; } }
private void UpdateTrailerPanelProgressBar(byte _number) { UserTrailerDictionary.TryGetValue(comboBoxUserTrailerCompanyTrailers.SelectedValue.ToString(), out UserCompanyTruckData SelectedUserCompanyTrailer); if (SelectedUserCompanyTrailer == null) { return; } string pnlname = "progressbarTrailerPart" + _number.ToString(), labelPartName = "labelTrailerPartDataName" + _number.ToString(); //Progres bar Panel pbPanel = groupBoxUserTrailerTrailerDetails.Controls.Find(pnlname, true).FirstOrDefault() as Panel; //Part name Label pnLabel = groupBoxUserTrailerTrailerDetails.Controls.Find(labelPartName, true).FirstOrDefault() as Label; //Repair button Button repairButton = groupBoxUserTrailerTrailerDetails.Controls.Find("buttonTrailerElRepair" + _number, true).FirstOrDefault() as Button; if (pbPanel != null) { List <UserCompanyTruckDataPart> DataPart = null; try { switch (_number) { case 0: { DataPart = SelectedUserCompanyTrailer.Parts.FindAll(xp => xp.PartType == "trailerdata"); break; } case 1: DataPart = SelectedUserCompanyTrailer.Parts.FindAll(xp => xp.PartType == "body"); break; case 2: DataPart = SelectedUserCompanyTrailer.Parts.FindAll(xp => xp.PartType == "chassis"); break; case 3: DataPart = SelectedUserCompanyTrailer.Parts.FindAll(xp => xp.PartType == "tire"); break; } } catch { repairButton.Enabled = false; return; } decimal _wear = 0; byte partCount = 0; if (DataPart != null && DataPart.Count > 0) { if (pnLabel != null) { if (_number != 0) { pnLabel.Text = DataPart[0].PartData.Find(xl => xl.StartsWith(" data_path:")).Split(new char[] { '"' })[1].Split(new char[] { '/' }).Last().Split(new char[] { '.' })[0]; } else { var tmp = UserDriverDictionary.Select(tx => tx.Value) .Where(tX => tX.AssignedTrailer == comboBoxUserTrailerCompanyTrailers.SelectedValue.ToString()).ToList(); if (tmp != null && tmp.Count > 0) { string tmpCargo = tmp[0].DriverJob.Cargo; if (CargoLngDict.TryGetValue(tmpCargo, out string value)) { if (value != null && value != "") { pnLabel.Text = value; } else { string CapName = CultureInfo.InvariantCulture.TextInfo.ToTitleCase(value); pnLabel.Text = CapName; } } } else { repairButton.Enabled = false; pbPanel.BackgroundImage = null; pnLabel.Text = ""; return; } } } foreach (UserCompanyTruckDataPart tmpPartData in DataPart) { try { string tmpWear = tmpPartData.PartData.Find(xl => xl.StartsWith(" wear:") || xl.StartsWith(" cargo_damage:")).Split(new char[] { ' ' })[2]; decimal _tmpWear = 0; if (tmpWear != "0" && tmpWear != "1") { _tmpWear = Utilities.NumericUtilities.HexFloatToDecimalFloat(tmpWear); } else if (tmpWear == "1") { _tmpWear = 1; } _wear += _tmpWear; partCount++; } catch { } } } else { pnLabel.Text = "none"; repairButton.Enabled = false; return; } _wear = _wear / partCount; if (_wear == 0) { repairButton.Enabled = false; } else { repairButton.Enabled = true; } // SolidBrush ppen = new SolidBrush(GetProgressbarColor(_wear)); int x = 0, y = 0, pnlwidth = (int)(pbPanel.Width * (1 - _wear)); Bitmap progress = new Bitmap(pbPanel.Width, pbPanel.Height); Graphics g = Graphics.FromImage(progress); g.FillRectangle(ppen, x, y, pnlwidth, pbPanel.Height); int fontSize = 12; StringFormat sf = new StringFormat(); sf.LineAlignment = StringAlignment.Center; sf.Alignment = StringAlignment.Center; GraphicsPath p = new GraphicsPath(); p.AddString( ((int)((1 - _wear) * 100)).ToString() + " %", // text to draw FontFamily.GenericSansSerif, // or any other font family (int)FontStyle.Bold, // font style (bold, italic, etc.) g.DpiY * fontSize / 72, // em size new Rectangle(0, 0, pbPanel.Width, pbPanel.Height), // location where to draw text sf); // set options here (e.g. center alignment) g.SmoothingMode = SmoothingMode.AntiAlias; g.FillPath(Brushes.Black, p); g.DrawPath(Pens.Black, p); pbPanel.BackgroundImage = progress; } }