Skip to content

Commit 2eb7441

Browse files
Merge pull request #1143 from sweiland-openrails/WorkOrdersStatusDoneFix
Status in Work Orders popup set too fast
2 parents ede96ba + 36327c4 commit 2eb7441

File tree

3 files changed

+56
-22
lines changed

3 files changed

+56
-22
lines changed

Source/Orts.Simulation/Simulation/Activity.cs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,13 +1325,16 @@ override public Boolean Triggered(Activity activity)
13251325
}
13261326
break;
13271327
case EventType.DropOffWagonsAtLocation:
1328-
// Dropping off of wagons should only count once disconnected from player train.
1329-
// A better name than DropOffWagonsAtLocation would be ArriveAtSidingWithWagons.
1330-
// To recognize the dropping off of the cars before the event is activated, this method is used.
1331-
if (atSiding(OriginalPlayerTrain.FrontTDBTraveller, OriginalPlayerTrain.RearTDBTraveller, this.SidingEnd1, this.SidingEnd2))
1328+
consistTrain = matchesConsistNoOrder(ChangeWagonIdList);
1329+
if (consistTrain != null)
13321330
{
1333-
consistTrain = matchesConsistNoOrder(ChangeWagonIdList);
1334-
triggered = consistTrain != null;
1331+
if (consistTrain.TrainType == Train.TRAINTYPE.STATIC)
1332+
{
1333+
if (atSiding(consistTrain.FrontTDBTraveller, consistTrain.RearTDBTraveller, this.SidingEnd1, this.SidingEnd2))
1334+
{
1335+
triggered = true;
1336+
}
1337+
}
13351338
}
13361339
break;
13371340
case EventType.PickUpPassengers:
@@ -1377,33 +1380,30 @@ private Train matchesConsist(List<string> wagonIdList)
13771380
return null;
13781381
}
13791382
/// <summary>
1380-
/// Finds the train that contains exactly the wagons (and maybe loco) in the list. Exact order is not required.
1383+
/// Finds the train that contains the wagons in the list.
1384+
/// Exact order is not required.
1385+
/// Some lists may only contain the first and last wagon. Check that first and last wagon match with those two wagons in the activity list.
13811386
/// </summary>
13821387
/// <param name="wagonIdList"></param>
13831388
/// <returns>train or null</returns>
13841389
private Train matchesConsistNoOrder(List<string> wagonIdList)
13851390
{
13861391
foreach (var trainItem in Simulator.Trains)
13871392
{
1388-
int nCars = 0;//all cars other than WagonIdList.
1389-
int nWagonListCars = 0;//individual wagon drop.
1393+
int nWagonListCars = 0;
13901394
foreach (var item in trainItem.Cars)
13911395
{
1392-
if (!wagonIdList.Contains(item.CarID)) nCars++;
1393-
if (wagonIdList.Contains(item.CarID)) nWagonListCars++;
1394-
}
1395-
// Compare two lists to make sure wagons are present.
1396-
bool listsMatch = true;
1397-
//support individual wagonIdList drop
1398-
if (trainItem.Cars.Count - nCars == (wagonIdList.Count == nWagonListCars ? wagonIdList.Count : nWagonListCars))
1399-
{
1400-
if (excludesWagons(trainItem, wagonIdList)) listsMatch = false;//all wagons dropped
1401-
1402-
if (listsMatch) return trainItem;
1403-
1396+
if (wagonIdList.Contains(item.CarID))
1397+
{
1398+
nWagonListCars++;
1399+
}
1400+
if (nWagonListCars == wagonIdList.Count)
1401+
{
1402+
return trainItem;
1403+
}
14041404
}
1405-
14061405
}
1406+
14071407
return null;
14081408
}
14091409
/// <summary>

Source/RunActivity/Viewer3D/Popups/HelpWindow.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,18 @@ public override void TabAction()
14191419

14201420
protected override ControlLayout Layout(ControlLayout layout)
14211421
{
1422+
int scrollPosition = 0;
1423+
if (Tabs[ActiveTab].Vbox != null)
1424+
{
1425+
foreach (var control in Tabs[ActiveTab].Vbox.Controls)
1426+
{
1427+
if (control is ControlLayoutScrollboxVertical controlLayoutScrollboxVertical)
1428+
{
1429+
scrollPosition = controlLayoutScrollboxVertical.GetScrollPosition();
1430+
}
1431+
}
1432+
}
1433+
14221434
var vbox = base.Layout(layout).AddLayoutVertical();
14231435

14241436
if (Tabs.Count > 0)
@@ -1434,8 +1446,17 @@ protected override ControlLayout Layout(ControlLayout layout)
14341446
}
14351447
vbox.AddHorizontalSeparator();
14361448
Tabs[ActiveTab].Layout(vbox);
1449+
1450+
foreach (var control in vbox.Controls)
1451+
{
1452+
if (control is ControlLayoutScrollboxVertical controlLayoutScrollboxVertical)
1453+
{
1454+
controlLayoutScrollboxVertical.SetScrollPosition(scrollPosition);
1455+
}
1456+
}
14371457
}
14381458

1459+
Tabs[ActiveTab].Vbox = vbox;
14391460
return vbox;
14401461
}
14411462

@@ -1462,12 +1483,14 @@ class TabData
14621483
public readonly Tab Tab;
14631484
public readonly string TabLabel;
14641485
public readonly Action<ControlLayout> Layout;
1486+
public Orts.Viewer3D.Popups.ControlLayoutVertical Vbox;
14651487

14661488
public TabData(Tab tab, string tabLabel, Action<ControlLayout> layout)
14671489
{
14681490
Tab = tab;
14691491
TabLabel = tabLabel;
14701492
Layout = layout;
1493+
Vbox = null;
14711494
}
14721495
}
14731496

Source/RunActivity/Viewer3D/Popups/WindowControls.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@ protected ControlLayoutScrollbox(int width, int height)
587587

588588
public abstract int ScrollSize { get; }
589589

590+
public abstract int GetScrollPosition();
590591
public abstract void SetScrollPosition(int position);
591592

592593
internal RasterizerState ScissorTestEnable = new RasterizerState { ScissorTestEnable = true };
@@ -707,6 +708,11 @@ public override int ScrollSize
707708
}
708709
}
709710

711+
public override int GetScrollPosition()
712+
{
713+
return ScrollPosition;
714+
}
715+
710716
public override void SetScrollPosition(int position)
711717
{
712718
position = Math.Max(0, Math.Min(Math.Max(0, ScrollSize), position));
@@ -841,6 +847,11 @@ public override int ScrollSize
841847
}
842848
}
843849

850+
public override int GetScrollPosition()
851+
{
852+
return(ScrollPosition);
853+
}
854+
844855
public override void SetScrollPosition(int position)
845856
{
846857
position = Math.Max(0, Math.Min(Math.Max(0, ScrollSize), position));

0 commit comments

Comments
 (0)