Skip to content

Commit 1a614bc

Browse files
committed
System Trailer integrity Display&Fix for 1.49 [update]
1 parent 78f9d47 commit 1a614bc

1 file changed

Lines changed: 136 additions & 25 deletions

File tree

TS SE Tool/Forms/MainTabs/FormMethodsTrailerTab.cs.cs

Lines changed: 136 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ limitations under the License.
2626
using TS_SE_Tool.Global;
2727
using TS_SE_Tool.Utilities;
2828
using System.Threading;
29+
using TS_SE_Tool.Save;
2930

3031
namespace TS_SE_Tool
3132
{
@@ -422,7 +423,9 @@ private void UpdateTrailerPanelProgressBar(byte _number)
422423

423424
if (progressBarPanel != null)
424425
{
425-
float _wear = 0;
426+
float _wear = 0,
427+
_unfixableWear = 0,
428+
_permanentWear = 0;
426429
string partType = "";
427430

428431
// Get part type
@@ -433,19 +436,42 @@ private void UpdateTrailerPanelProgressBar(byte _number)
433436
case 0:
434437
partType = "cargo";
435438
_wear = SelectedUserCompanyTrailer.TrailerMainData.cargo_damage;
436-
break;
439+
break;
440+
437441
case 1:
438442
partType = "body";
439443
_wear = SelectedUserCompanyTrailer.TrailerMainData.trailer_body_wear;
444+
445+
if (MainSaveFileInfoData.Version > (byte)saveVTV.v148)
446+
{
447+
_unfixableWear = SelectedUserCompanyTrailer.TrailerMainData.trailer_body_wear_unfixable;
448+
}
449+
440450
break;
451+
441452
case 2:
442453
partType = "chassis";
443454
_wear = SelectedUserCompanyTrailer.TrailerMainData.chassis_wear;
455+
456+
if (MainSaveFileInfoData.Version > (byte)saveVTV.v148)
457+
{
458+
_unfixableWear = SelectedUserCompanyTrailer.TrailerMainData.chassis_wear_unfixable;
459+
}
460+
444461
break;
462+
445463
case 3:
446464
partType = "tire";
447465
if (SelectedUserCompanyTrailer.TrailerMainData.wheels_wear.Count > 0)
448466
_wear = SelectedUserCompanyTrailer.TrailerMainData.wheels_wear.Sum() / SelectedUserCompanyTrailer.TrailerMainData.wheels_wear.Count;
467+
468+
if (MainSaveFileInfoData.Version > (byte)saveVTV.v148)
469+
{
470+
if (SelectedUserCompanyTrailer.TrailerMainData.wheels_wear_unfixable.Count > 0)
471+
_unfixableWear = SelectedUserCompanyTrailer.TrailerMainData.wheels_wear_unfixable.Sum() /
472+
SelectedUserCompanyTrailer.TrailerMainData.wheels_wear_unfixable.Count;
473+
}
474+
449475
break;
450476
}
451477
}
@@ -455,7 +481,14 @@ private void UpdateTrailerPanelProgressBar(byte _number)
455481
return;
456482
}
457483

458-
//=== Label
484+
// 1.49
485+
486+
_permanentWear = (float)SelectedUserCompanyTrailer.TrailerMainData.integrity_odometer / 5000000;
487+
488+
//
489+
490+
// Part name
491+
459492
if (partLabel != null)
460493
{
461494
string pnlText = SetTrailerPartLabelText(trailerNameless, SelectedUserCompanyTrailer.TrailerMainData, partType);
@@ -477,38 +510,105 @@ private void UpdateTrailerPanelProgressBar(byte _number)
477510
//===
478511

479512
//=== Repair button
480-
if (_wear == 0)
513+
514+
if (_wear == 0 && _unfixableWear == 0 && _permanentWear == 0)
481515
repairButton.Enabled = false;
482516
else
483517
repairButton.Enabled = true;
518+
484519
//===
485520

521+
float totalWear = _wear + _unfixableWear + _permanentWear;
522+
486523
//=== Progress bar
487-
SolidBrush ppen = new SolidBrush(Graphics_TSSET.GetProgressbarColor(_wear));
488524

489-
int x = 0, y = 0, pnlwidth = (int)(progressBarPanel.Width * (1 - _wear));
525+
SolidBrush ppen = new SolidBrush(Graphics_TSSET.GetProgressbarColor(totalWear));
526+
527+
int x = 0, y = 0,
528+
pnlWidth = (int)(progressBarPanel.Width * (1 - (totalWear)));
490529

491530
Bitmap progress = new Bitmap(progressBarPanel.Width, progressBarPanel.Height);
492531

493-
Graphics g = Graphics.FromImage(progress);
494-
g.FillRectangle(ppen, x, y, pnlwidth, progressBarPanel.Height);
495-
496-
int fontSize = 12;
497-
StringFormat sf = new StringFormat();
498-
sf.LineAlignment = StringAlignment.Center;
499-
sf.Alignment = StringAlignment.Center;
500-
501-
GraphicsPath p = new GraphicsPath();
502-
p.AddString(
503-
((int)((1 - _wear) * 100)).ToString() + " %", // text to draw
504-
FontFamily.GenericSansSerif, // or any other font family
505-
(int)FontStyle.Bold, // font style (bold, italic, etc.)
506-
g.DpiY * fontSize / 72, // em size
507-
new Rectangle(0, 0, progressBarPanel.Width, progressBarPanel.Height), // location where to draw text
508-
sf); // set options here (e.g. center alignment)
509-
g.SmoothingMode = SmoothingMode.AntiAlias;
510-
g.FillPath(Brushes.Black, p);
511-
g.DrawPath(Pens.Black, p);
532+
using (Graphics g = Graphics.FromImage(progress))
533+
{
534+
g.SmoothingMode = SmoothingMode.HighQuality;
535+
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
536+
537+
g.FillRectangle(ppen, x, y, pnlWidth, progressBarPanel.Height);
538+
539+
int pnlWidthFixable = (int)(progressBarPanel.Width * _wear);
540+
541+
using (TextureBrush brush = new TextureBrush(VehicleIntegrityPBImg[0], WrapMode.Tile))
542+
{
543+
SolidBrush wearPen = new SolidBrush(Color.Yellow);
544+
g.FillRectangle(wearPen, pnlWidth, 0, pnlWidthFixable, progressBarPanel.Height);
545+
546+
brush.TranslateTransform(pnlWidth, -4);
547+
g.FillRectangle(brush, pnlWidth, 0, pnlWidthFixable, progressBarPanel.Height);
548+
}
549+
550+
if (MainSaveFileInfoData.Version > (byte)saveVTV.v148)
551+
{
552+
//1.49
553+
554+
int pnlWidthUnfixable = (int)(progressBarPanel.Width * _unfixableWear);
555+
556+
using (TextureBrush brush = new TextureBrush(VehicleIntegrityPBImg[1], WrapMode.Tile))
557+
{
558+
SolidBrush wearPen = new SolidBrush(Color.Orange);
559+
g.FillRectangle(wearPen, pnlWidth + pnlWidthFixable, 0, pnlWidthUnfixable, progressBarPanel.Height);
560+
561+
brush.TranslateTransform(pnlWidth + pnlWidthFixable, 0);
562+
g.FillRectangle(brush, pnlWidth + pnlWidthFixable, 0, pnlWidthUnfixable, progressBarPanel.Height);
563+
}
564+
565+
566+
int pnlWidthPermanent = (int)(progressBarPanel.Width * _permanentWear);
567+
568+
using (TextureBrush brush = new TextureBrush(VehicleIntegrityPBImg[2], WrapMode.Tile))
569+
{
570+
SolidBrush wearPen = new SolidBrush(Color.Red);
571+
g.FillRectangle(wearPen, pnlWidth + pnlWidthFixable + pnlWidthUnfixable, 0, pnlWidthPermanent, progressBarPanel.Height);
572+
573+
brush.TranslateTransform(progressBarPanel.Width - (pnlWidthPermanent), 0);
574+
g.FillRectangle(brush, progressBarPanel.Width - (pnlWidthPermanent), 0, pnlWidthPermanent, progressBarPanel.Height);
575+
}
576+
577+
//1.49
578+
}
579+
580+
int fontSize = 14;
581+
582+
string textPercent = ((int)((1 - totalWear) * 100)).ToString() + " %";
583+
Font percentFont = new Font(FontFamily.GenericSansSerif, fontSize, FontStyle.Bold);
584+
585+
var textSize = g.MeasureString(textPercent, percentFont);
586+
587+
// Percent background
588+
589+
SolidBrush pbPen = new SolidBrush(Color.FromArgb(200, Color.White));
590+
g.FillRectangle(pbPen, (progressBarPanel.ClientRectangle.Width - textSize.Width) / 2,
591+
(progressBarPanel.ClientRectangle.Height - textSize.Height) / 2, textSize.Width, textSize.Height);
592+
593+
//
594+
595+
StringFormat sf = new StringFormat();
596+
sf.LineAlignment = StringAlignment.Center;
597+
sf.Alignment = StringAlignment.Center;
598+
599+
GraphicsPath p = new GraphicsPath();
600+
601+
p.AddString(
602+
textPercent, // text to draw
603+
percentFont.FontFamily, // or any other font family
604+
(int)percentFont.Style, // font style (bold, italic, etc.)
605+
fontSize, // em size
606+
new Rectangle(0, 0, progressBarPanel.Width, progressBarPanel.Height), // location where to draw text
607+
sf); // set options here (e.g. center alignment)
608+
609+
g.FillPath(Brushes.Black, p);
610+
g.DrawPath(Pens.Black, p);
611+
}
512612

513613
progressBarPanel.BackgroundImage = progress;
514614
//===
@@ -829,6 +929,13 @@ public void buttonTrailerRepair_Click(object sender, EventArgs e)
829929
selectedTrailerData.chassis_wear = 0;
830930
selectedTrailerData.wheels_wear = new List<Save.DataFormat.SCS_Float>();
831931

932+
selectedTrailerData.trailer_body_wear_unfixable = 0;
933+
selectedTrailerData.chassis_wear_unfixable = 0;
934+
selectedTrailerData.wheels_wear_unfixable = new List<Save.DataFormat.SCS_Float>();
935+
936+
selectedTrailerData.integrity_odometer = 0;
937+
selectedTrailerData.integrity_odometer_float_part = 0;
938+
832939
slaveTrailerNameless = selectedTrailerData.slave_trailer;
833940

834941
if (slaveTrailerNameless == "null")
@@ -882,14 +989,18 @@ public void buttonTrailerElRepair_Click(object sender, EventArgs e)
882989

883990
case 1:
884991
selectedTrailerData.trailer_body_wear = 0;
992+
selectedTrailerData.trailer_body_wear_unfixable = 0;
993+
885994
break;
886995

887996
case 2:
888997
selectedTrailerData.chassis_wear = 0;
998+
selectedTrailerData.chassis_wear_unfixable = 0;
889999
break;
8901000

8911001
case 3:
8921002
selectedTrailerData.wheels_wear = new List<Save.DataFormat.SCS_Float>();
1003+
selectedTrailerData.wheels_wear_unfixable = new List<Save.DataFormat.SCS_Float>();
8931004
break;
8941005
}
8951006

0 commit comments

Comments
 (0)