Skip to content

Commit e458797

Browse files
committed
Couplers and vertical scroll improvements.
1 parent e92be5a commit e458797

File tree

4 files changed

+64
-44
lines changed

4 files changed

+64
-44
lines changed

Source/RunActivity/Viewer3D/Cameras.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,12 +1061,12 @@ public override void Reset()
10611061
protected override void OnActivate(bool sameCamera)
10621062
{
10631063
BrowseMode = BrowseForwards = BrowseBackwards = false;
1064-
1065-
var carPosition = Viewer.TrainCarOperationsViewerWindow.CarPosition;
1064+
var trainCars = GetCameraCars();
1065+
var TrainCarViewer = Viewer.TrainCarOperationsViewerWindow;
1066+
var carPosition = !(TrainCarViewer.CarPosition < trainCars.Count()) ? TrainCarViewer.CarPosition - 1 : TrainCarViewer.CarPosition;
10661067
var isDownCameraOutsideFront = UserInput.IsDown(UserCommand.CameraOutsideFront);
10671068
var isDownCameraOutsideRear = UserInput.IsDown(UserCommand.CameraOutsideRear);
1068-
var isVisibleTrainCarViewer = Viewer.TrainCarOperationsViewerWindow.Visible;
1069-
var trainCars = GetCameraCars();
1069+
var isVisibleTrainCarViewer = Viewer.TrainCarOperationsViewerWindow.Visible;
10701070

10711071
if (attachedCar == null || attachedCar.Train != Viewer.SelectedTrain || carPosition != oldCarPosition || isDownCameraOutsideFront || isDownCameraOutsideRear)
10721072
{
@@ -1077,8 +1077,8 @@ protected override void OnActivate(bool sameCamera)
10771077
SetCameraCar(GetCameraCars().First());
10781078
oldCarPosition = 0;
10791079
}
1080-
else if (isVisibleTrainCarViewer && carPosition >= 0 && carPosition < trainCars.Count())
1081-
{
1080+
else if (isVisibleTrainCarViewer && carPosition >= 0)
1081+
{
10821082
SetCameraCar(trainCars[carPosition]);
10831083
oldCarPosition = carPosition;
10841084
}
@@ -1097,7 +1097,7 @@ protected override void OnActivate(bool sameCamera)
10971097
SetCameraCar(GetCameraCars().Last());
10981098
oldCarPosition = 0;
10991099
}
1100-
else if (isVisibleTrainCarViewer && carPosition >= 0 && carPosition < trainCars.Count())
1100+
else if (isVisibleTrainCarViewer && carPosition >= 0)
11011101
{
11021102
SetCameraCar(trainCars[carPosition]);
11031103
oldCarPosition = carPosition;

Source/RunActivity/Viewer3D/Popups/TrainCarOperationsViewerWindow.cs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,16 @@ public class TrainCarOperationsViewerWindow : Window
8383
public int locoRowCount;
8484
public int rowsCount;
8585
const int SymbolWidth = 32;
86-
8786
public static bool FontChanged;
8887
public static bool FontToBold;
8988
public int windowHeight { get; set; } //required by TrainCarWindow
90-
89+
9190
public int CarPosition
9291
{
9392
set;
9493
get;
9594
}
96-
public int YPosition
95+
public int NewCarPosition
9796
{
9897
set;
9998
get;
@@ -113,6 +112,11 @@ public bool RearBrakeHoseChanged
113112
set;
114113
get;
115114
}
115+
public bool CouplerChanged
116+
{
117+
set;
118+
get;
119+
} = false;
116120
public struct ListLabel
117121
{
118122
public string CarID;
@@ -124,7 +128,7 @@ public struct ListLabel
124128
int LastPlayerTrainCars;
125129
bool LastPlayerLocomotiveFlippedState;
126130
int carPosition;
127-
bool couplerFront = false;
131+
128132
public TrainCarOperationsViewerWindow(WindowManager owner)
129133
: base(owner, Window.DecorationSize.X + CarListPadding + ((owner.TextFontDefault.Height + 12) * 20), Window.DecorationSize.Y + ((owner.TextFontDefault.Height + 12) * 2), Viewer.Catalog.GetString("Train Operations Viewer"))
130134
{
@@ -365,13 +369,13 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
365369
var carOperations = Owner.Viewer.CarOperationsWindow;
366370
var trainCarOperations = Owner.Viewer.TrainCarOperationsWindow;
367371

368-
if (couplerFront || PlayerTrain != Owner.Viewer.PlayerTrain || Owner.Viewer.PlayerTrain.Cars.Count != LastPlayerTrainCars || (Owner.Viewer.PlayerLocomotive != null &&
372+
if (CouplerChanged || PlayerTrain != Owner.Viewer.PlayerTrain || Owner.Viewer.PlayerTrain.Cars.Count != LastPlayerTrainCars || (Owner.Viewer.PlayerLocomotive != null &&
369373
LastPlayerLocomotiveFlippedState != Owner.Viewer.PlayerLocomotive.Flipped))
370374
{
371-
couplerFront = false;
375+
CouplerChanged = false;
372376
PlayerTrain = Owner.Viewer.PlayerTrain;
373377

374-
if (LastPlayerTrainCars != Owner.Viewer.PlayerTrain.Cars.Count){ Visible = false; }
378+
//if (LastPlayerTrainCars != Owner.Viewer.PlayerTrain.Cars.Count){ Visible = false; }
375379

376380
LastPlayerTrainCars = Owner.Viewer.PlayerTrain.Cars.Count;
377381
CarPosition = CarPosition >= LastPlayerTrainCars? LastPlayerTrainCars - 1: CarPosition;
@@ -385,9 +389,12 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
385389
bool isElectricDieselLocomotive = (trainCar is MSTSElectricLocomotive) || (trainCar is MSTSDieselLocomotive);
386390

387391
if (carPosition != CarPosition || TrainCarOperationsChanged || carOperations.CarOperationChanged
388-
|| trainCarOperations.modifiedSetting || carOperations.RearBrakeHoseChanged || carOperations.FrontBrakeHoseChanged)
392+
|| trainCarOperations.carIdClicked || carOperations.RearBrakeHoseChanged || carOperations.FrontBrakeHoseChanged)
389393
{
390-
if (carPosition != CarPosition)
394+
// Updates CarPosition
395+
CarPosition = CouplerChanged ? NewCarPosition : CarPosition;
396+
397+
if (carPosition != CarPosition || (trainCarOperations.carIdClicked && CarPosition == 0))
391398
{
392399
Owner.Viewer.FrontCamera.Activate();
393400
}
@@ -459,7 +466,8 @@ void TrainCarOperationsCouplerFront_Click(Control arg1, Point arg2)
459466
else
460467
{
461468
new UncoupleCommand(Viewer.Log, CarPosition - 1);
462-
TrainCarViewer.couplerFront = true;
469+
TrainCarViewer.CouplerChanged = true;
470+
TrainCarViewer.NewCarPosition = CarPosition - 1;
463471
if (Viewer.CarOperationsWindow.CarPosition > CarPosition - 1)
464472
Viewer.CarOperationsWindow.Visible = false;
465473
}

Source/RunActivity/Viewer3D/Popups/TrainCarOperationsWindow.cs

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public class TrainCarOperationsWindow : Window
117117
public bool updatingPowerSupply = false;
118118

119119
public bool warningEnabled = false;
120-
120+
public bool carIdClicked = false;
121121
public bool modifiedSetting
122122
{
123123
set;
@@ -440,29 +440,21 @@ public void topCarPositionVisible()
440440
{ // Allows to find the last carposition, visible at the window bottom.
441441
if ((!lastRowVisible && labelTop >= 0) || labelTop > DisplaySizeY)
442442
{
443-
if (DisplaySizeY > desiredHeight)
444-
{
445-
lastRowVisible = true;
446-
carPositionVisible = rowsCount;
447-
oldPositionHeight = vbox.Position.Height;
448-
}
449-
else
443+
for (int carPosition = 0; carPosition < rowsCount; carPosition++)
450444
{
451-
for (int carPosition = 0; carPosition < rowsCount; carPosition++)
445+
var labelTop = carPosition * rowHeight;
446+
if (labelTop > vbox.Position.Height - Owner.TextFontDefault.Height)
452447
{
453-
var labelTop = carPosition * rowHeight;
454-
if (labelTop > vbox.Position.Height - Owner.TextFontDefault.Height)
448+
if (!lastRowVisible && labelTop > 0)
455449
{
456-
if (!lastRowVisible && labelTop > 0)
457-
{
458-
lastRowVisible = true;
459-
carPositionVisible = carPosition - 1;
460-
oldPositionHeight = vbox.Position.Height;
461-
break;
462-
}
450+
lastRowVisible = true;
451+
carPositionVisible = carPosition - 1;
452+
oldPositionHeight = vbox.Position.Height;
453+
var carid = PlayerTrain.Cars[carPositionVisible].CarID;
454+
break;
463455
}
464456
}
465-
}
457+
}
466458
}
467459
}
468460
public void localScrollLayout(int selectedCarPosition)
@@ -512,7 +504,7 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
512504
trainCarViewer.TrainCarOperationsChanged = !trainCarViewer.Visible && trainCarViewer.TrainCarOperationsChanged ? false : trainCarViewer.TrainCarOperationsChanged;
513505

514506
currentDisplaySizeY = DisplaySizeY;
515-
if (Owner.Viewer.DisplaySize.Y != DisplaySizeY || modifiedSetting)
507+
if (Owner.Viewer.DisplaySize.Y != DisplaySizeY || modifiedSetting || trainCarViewer.CouplerChanged)
516508
{
517509
lastRowVisible = false;
518510
supplyStatusChanged = false;
@@ -568,13 +560,14 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
568560
}
569561
}
570562
}
571-
if (trainCarViewer.TrainCarOperationsChanged || trainCarViewer.RearBrakeHoseChanged
572-
|| trainCarViewer.FrontBrakeHoseChanged || modifiedSetting || carOperations.CarOperationChanged)
563+
if (trainCarViewer.TrainCarOperationsChanged || trainCarViewer.TrainCarOperationsChanged || trainCarViewer.RearBrakeHoseChanged
564+
|| trainCarViewer.FrontBrakeHoseChanged || modifiedSetting || carIdClicked || carOperations.CarOperationChanged)
573565
{
574566
Layout();
575567
localScrollLayout(selectedCarPosition);
576568
updateLayoutSize();
577569
modifiedSetting = false;
570+
carIdClicked = false;
578571
// Avoids bug
579572
trainCarViewer.TrainCarOperationsChanged = warningEnabled;
580573
carOperations.CarOperationChanged = carOperations.Visible && carOperations.CarOperationChanged;
@@ -613,7 +606,17 @@ public buttonArrowRight(int x, int y, int size, Viewer viewer, int carPosition)
613606
TrainCarViewer = Viewer.TrainCarOperationsViewerWindow;
614607
CarPosition = carPosition;
615608

616-
Texture = TrainCarViewer.Visible && TrainCarViewer.CarPosition == CarPosition ? Viewer.TrainCarOperationsWindow.allSymbolsMode ? ArrowRight : ArrowLeft : Empty;
609+
// Coupler changed requires to modify the arrow position
610+
var trainCarViewerCarPosition = TrainCarViewer.CouplerChanged ? TrainCarViewer.NewCarPosition : TrainCarViewer.CarPosition;
611+
if (TrainCarViewer.CouplerChanged && trainCarViewerCarPosition == CarPosition)
612+
{
613+
Texture = TrainCarViewer.Visible ? Viewer.TrainCarOperationsWindow.allSymbolsMode ? ArrowRight : ArrowLeft : Empty;
614+
Viewer.TrainCarOperationsWindow.carIdClicked = true;
615+
TrainCarViewer.CarPosition = trainCarViewerCarPosition;
616+
}
617+
else
618+
Texture = TrainCarViewer.Visible && trainCarViewerCarPosition == CarPosition? Viewer.TrainCarOperationsWindow.allSymbolsMode ? ArrowRight : ArrowLeft : Empty;
619+
617620
Source = new Rectangle(0, 0, size, size);
618621
Click += new Action<Control, Point>(buttonArrowRight_Click);
619622
}
@@ -639,7 +642,17 @@ public buttonArrowLeft(int x, int y, int size, Viewer viewer, int carPosition)
639642
TrainCarViewer = Viewer.TrainCarOperationsViewerWindow;
640643
CarPosition = carPosition;
641644
Texture = Empty;
642-
Texture = TrainCarViewer.CarPosition == CarPosition ? ArrowLeft : Empty;
645+
// Coupler changed requires to modify arrow position
646+
var trainCarViewerCarPosition = TrainCarViewer.CouplerChanged ? TrainCarViewer.NewCarPosition : TrainCarViewer.CarPosition;
647+
if (TrainCarViewer.CouplerChanged && trainCarViewerCarPosition == CarPosition)
648+
{
649+
Texture = trainCarViewerCarPosition == CarPosition ? ArrowLeft : Empty;
650+
Viewer.TrainCarOperationsWindow.carIdClicked = true;
651+
TrainCarViewer.CarPosition = trainCarViewerCarPosition;
652+
}
653+
else
654+
Texture = trainCarViewerCarPosition == CarPosition ? ArrowLeft : Empty;
655+
643656
Source = new Rectangle(0, 0, size, size);
644657
Click += new Action<Control, Point>(buttonArrowLeft_Click);
645658
}
@@ -700,10 +713,9 @@ public void buttonLabel_Click(Control arg1, Point arg2)
700713
Control control = arg1;
701714

702715
TrainCar.carLabelText = Text;
703-
TrainCarViewer.YPosition = control.Position.Y;
704716
TrainCarViewer.CarPosition = CarPosition;
705717
TrainCarViewer.Visible = true;
706-
TrainCar.modifiedSetting = true;
718+
TrainCar.carIdClicked = true;
707719

708720
// required by localScrollLayout()
709721
TrainCar.selectedCarPosition = CarPosition;

Source/RunActivity/Viewer3D/Viewer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ internal void Initialize()
493493
SwitchWindow = new SwitchWindow(WindowManager);
494494
TrainOperationsWindow = new TrainOperationsWindow(WindowManager);
495495
TrainCarOperationsWindow = new TrainCarOperationsWindow(WindowManager);
496-
TrainCarOperationsViewerWindow = new TrainCarOperationsViewerWindow(WindowManager); MultiPlayerWindow = new MultiPlayerWindow(WindowManager);
496+
TrainCarOperationsViewerWindow = new TrainCarOperationsViewerWindow(WindowManager);
497497
MultiPlayerWindow = new MultiPlayerWindow(WindowManager);
498498
CarOperationsWindow = new CarOperationsWindow(WindowManager);
499499
TrainDpuWindow = new TrainDpuWindow(WindowManager);

0 commit comments

Comments
 (0)