private void UpdateTruckPanelFuel() { UserTruckDictionary.TryGetValue(comboBoxUserTruckCompanyTrucks.SelectedValue.ToString(), out UserCompanyTruckData SelectedUserCompanyTruck); string pnlnamefuel = "progressbarTruckFuel"; Panel pnlfuel = groupBoxUserTruckTruckDetails.Controls.Find(pnlnamefuel, true).FirstOrDefault() as Panel; Button refuelTruck = tableLayoutPanelUserTruckControls.Controls.Find("buttonTruckReFuel", true).FirstOrDefault() as Button; if (pnlfuel != null) { string fuel = SelectedUserCompanyTruck.Parts.Find(xp => xp.PartType == "truckdata").PartData.Find(xl => xl.StartsWith(" fuel_relative:")).Split(new char[] { ' ' })[2];//SelectedUserCompanyTruck.Fuel; decimal _fuel = 0; if (fuel != "0" && fuel != "1") { refuelTruck.Enabled = true; _fuel = Utilities.NumericUtilities.HexFloatToDecimalFloat(fuel); } else if (fuel == "1") { refuelTruck.Enabled = false; _fuel = 1; } else { refuelTruck.Enabled = true; } SolidBrush ppen = new SolidBrush(GetProgressbarColor(1 - _fuel)); int pnlheight = (int)(pnlfuel.Height * (_fuel)), x = 0, y = pnlfuel.Height - pnlheight; Bitmap progress = new Bitmap(pnlfuel.Width, pnlfuel.Height); Graphics g = Graphics.FromImage(progress); g.FillRectangle(ppen, x, y, pnlfuel.Width, pnlheight); int fontSize = 10; StringFormat sf = new StringFormat(); sf.LineAlignment = StringAlignment.Center; sf.Alignment = StringAlignment.Center; GraphicsPath p = new GraphicsPath(); p.AddString( ((int)(_fuel * 100)).ToString() + " %", // text to draw FontFamily.GenericSansSerif, // or any other font family (int)FontStyle.Regular, // font style (bold, italic, etc.) g.DpiY * fontSize / 72, // em size new Rectangle(0, 0, pnlfuel.Width, pnlfuel.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); pnlfuel.BackgroundImage = progress; } }
private void UpdateTruckPanelLicensePlate() { UserTruckDictionary.TryGetValue(comboBoxUserTruckCompanyTrucks.SelectedValue.ToString(), out UserCompanyTruckData SelectedUserCompanyTruck); string LicensePlate = SelectedUserCompanyTruck.Parts.Find(xp => xp.PartType == "truckdata").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 = groupBoxUserTruckTruckDetails.Controls.Find("labelLicensePlate", 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 = groupBoxUserTruckTruckDetails.Controls.Find("TruckLicensePlateIMG", 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 UpdateTruckPanelProgressBars() { UserTruckDictionary.TryGetValue(comboBoxUserTruckCompanyTrucks.SelectedValue.ToString(), out UserCompanyTruckData SelectedUserCompanyTruck); for (int i = 0; i < 5; i++) { Panel pnl = null; Label labelPart = null; string pnlname = "progressbarTruckPart" + i.ToString(), labelPartName = "labelTruckPartDataName" + i.ToString(); if (groupBoxUserTruckTruckDetails.Controls.ContainsKey(pnlname)) { pnl = groupBoxUserTruckTruckDetails.Controls[pnlname] as Panel; } if (groupBoxUserTruckTruckDetails.Controls.ContainsKey(labelPartName)) { labelPart = groupBoxUserTruckTruckDetails.Controls[labelPartName] as Label; } if (pnl != null) { List <string> TruckDataPart = null; switch (i) { case 0: TruckDataPart = SelectedUserCompanyTruck.Parts.Find(xp => xp.PartType == "engine").PartData; break; case 1: TruckDataPart = SelectedUserCompanyTruck.Parts.Find(xp => xp.PartType == "transmission").PartData; break; case 2: TruckDataPart = SelectedUserCompanyTruck.Parts.Find(xp => xp.PartType == "chassis").PartData; break; case 3: TruckDataPart = SelectedUserCompanyTruck.Parts.Find(xp => xp.PartType == "cabin").PartData; break; case 4: TruckDataPart = SelectedUserCompanyTruck.Parts.Find(xp => xp.PartType == "tire").PartData; break; } string wear = "0"; if (TruckDataPart != null) { if (labelPart != null) { labelPart.Text = TruckDataPart.Find(xl => xl.StartsWith(" data_path:")).Split(new char[] { '"' })[1].Split(new char[] { '/' }).Last().Split(new char[] { '.' })[0]; } wear = TruckDataPart.Find(xl => xl.StartsWith(" wear:")).Split(new char[] { ' ' })[2]; } else { labelPart.Text = "!! Part not found !!"; } labelPart.Location = new Point(pnl.Location.X + (pnl.Width - labelPart.Width) / 2, labelPart.Location.Y); decimal _wear = 0; if (wear != "0" && wear != "1") { _wear = Utilities.NumericUtilities.HexFloatToDecimalFloat(wear); } 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; } } Panel pnlfuel = null; string pnlnamefuel = "progressbarTruckFuel"; if (groupBoxUserTruckTruckDetails.Controls.ContainsKey(pnlnamefuel)) { pnlfuel = groupBoxUserTruckTruckDetails.Controls[pnlnamefuel] as Panel; } if (pnlfuel != null) { string fuel = SelectedUserCompanyTruck.Parts.Find(xp => xp.PartType == "truckdata").PartData.Find(xl => xl.StartsWith(" fuel_relative:")).Split(new char[] { ' ' })[2];//SelectedUserCompanyTruck.Fuel; decimal _fuel = 0; if (fuel != "0" && fuel != "1") { _fuel = Utilities.NumericUtilities.HexFloatToDecimalFloat(fuel); } else if (fuel == "1") { _fuel = 1; } SolidBrush ppen = new SolidBrush(GetProgressbarColor(1 - _fuel)); int pnlheight = (int)(pnlfuel.Height * (_fuel)), x = 0, y = pnlfuel.Height - pnlheight; Bitmap progress = new Bitmap(pnlfuel.Width, pnlfuel.Height); Graphics g = Graphics.FromImage(progress); g.FillRectangle(ppen, x, y, pnlfuel.Width, pnlheight); int fontSize = 10; StringFormat sf = new StringFormat(); sf.LineAlignment = StringAlignment.Center; sf.Alignment = StringAlignment.Center; GraphicsPath p = new GraphicsPath(); p.AddString( ((int)(_fuel * 100)).ToString() + " %", // text to draw FontFamily.GenericSansSerif, // or any other font family (int)FontStyle.Regular, // font style (bold, italic, etc.) g.DpiY * fontSize / 72, // em size new Rectangle(0, 0, pnlfuel.Width, pnlfuel.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); pnlfuel.BackgroundImage = progress; } string lctxt = ""; labelLicensePlate.Text = ""; int stindex = 0, endindex = 0; string LicensePlate = SelectedUserCompanyTruck.Parts.Find(xp => xp.PartType == "truckdata").PartData.Find(xl => xl.StartsWith(" license_plate:")).Split(new char[] { '"' })[1]; for (int i = 0; i < 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) { labelLicensePlate.Text = lctxt.Split(new char[] { '|' })[0] + " Country " + lctxt.Split(new char[] { '|' })[1]; } else { labelLicensePlate.Text = lctxt.Split(new char[] { '|' })[0]; } }
private void UpdateTruckPanelProgressBar(byte _number) { UserTruckDictionary.TryGetValue(comboBoxUserTruckCompanyTrucks.SelectedValue.ToString(), out UserCompanyTruckData SelectedUserCompanyTruck); if (SelectedUserCompanyTruck == null) { return; } string pnlname = "progressbarTruckPart" + _number.ToString(), labelPartName = "labelTruckPartDataName" + _number.ToString(); //Progres bar Panel pbPanel = groupBoxUserTruckTruckDetails.Controls.Find(pnlname, true).FirstOrDefault() as Panel; //Part name Label pnLabel = groupBoxUserTruckTruckDetails.Controls.Find(labelPartName, true).FirstOrDefault() as Label; //Repair button Button repairButton = groupBoxUserTruckTruckDetails.Controls.Find("buttonTruckElRepair" + _number, true).FirstOrDefault() as Button; if (pbPanel != null) { List <UserCompanyTruckDataPart> TruckDataPart = null; try { switch (_number) { case 0: TruckDataPart = SelectedUserCompanyTruck.Parts.FindAll(xp => xp.PartType == "engine"); break; case 1: TruckDataPart = SelectedUserCompanyTruck.Parts.FindAll(xp => xp.PartType == "transmission"); break; case 2: TruckDataPart = SelectedUserCompanyTruck.Parts.FindAll(xp => xp.PartType == "chassis"); break; case 3: TruckDataPart = SelectedUserCompanyTruck.Parts.FindAll(xp => xp.PartType == "cabin"); break; case 4: TruckDataPart = SelectedUserCompanyTruck.Parts.FindAll(xp => xp.PartType == "tire"); break; } } catch { repairButton.Enabled = false; return; } decimal _wear = 0; byte partCount = 0; if (TruckDataPart != null && TruckDataPart.Count > 0) { if (pnLabel != null) { pnLabel.Text = TruckDataPart[0].PartData.Find(xl => xl.StartsWith(" data_path:")).Split(new char[] { '"' })[1].Split(new char[] { '/' }).Last().Split(new char[] { '.' })[0]; } foreach (UserCompanyTruckDataPart tmpPartData in TruckDataPart) { try { string tmpWear = tmpPartData.PartData.Find(xl => xl.StartsWith(" wear:")).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 = "!! Part not found !!"; } _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; } }