#32 swap from integration set that was giving inconsistent results, and adding in a panel.reubuildOnInterval when an observed value changes.

This commit is contained in:
2024-07-27 22:25:23 -05:00
parent 92317b29b2
commit cf1d5e32e5
2 changed files with 8 additions and 8 deletions

View File

@@ -43,7 +43,7 @@ internal class CarInspector_PopulateCarPanel_Patch
if (!tweaksAndThings.IsEnabled) return true;
bool buttonsHaveCost = tweaksAndThings.EndGearHelpersRequirePayment();
var consist = __instance._car._set.Cars;
var consist = __instance._car.EnumerateCoupled();
builder = AddCarConsistRebuildObservers(builder, consist);
builder.HStack(delegate (UIPanelBuilder hstack)
@@ -122,8 +122,8 @@ internal class CarInspector_PopulateCarPanel_Patch
{
try
{
builder.Rebuild();
if (car.TagCallout != null) tagController.UpdateTags(CameraSelector.shared._currentCamera.GroundPosition, true); //tagController.UpdateTag(car, car.TagCallout, OpsController.Shared);
builder.RebuildOnInterval(.01f);
if (car.TagCallout != null) tagController.UpdateTags(CameraSelector.shared._currentCamera.GroundPosition, true);
if (ContextMenu.IsShown && ContextMenu.Shared.centerLabel.text == car.DisplayName) CarPickable.HandleShowContextMenu(car);
}
catch (Exception ex)
@@ -151,7 +151,7 @@ internal class CarInspector_PopulateCarPanel_Patch
public static void MrocConsistHelper(Model.Car car, MrocHelperType mrocHelperType, bool buttonsHaveCost)
{
TrainController tc = UnityEngine.Object.FindObjectOfType<TrainController>();
IEnumerable<Model.Car> consist = car._set.Cars;
IEnumerable<Model.Car> consist = car.EnumerateCoupled();
_log.ForContext("car", car).Verbose($"{car} => {mrocHelperType} => {string.Join("/", consist.Select(c => c.ToString()))}");
CalculateCostIfEnabled(car, mrocHelperType, buttonsHaveCost, consist);
@@ -232,7 +232,7 @@ internal class CarInspector_PopulateCarPanel_Patch
carIdsCheckedAlready.Add(car.id);
//check consist, for cabeese
IEnumerable<Car> consist = car._set.Cars;
IEnumerable<Car> consist = car.EnumerateCoupled();
output = consist.FirstOrDefault(c => c.CabooseWithSufficientCrewHours(timeNeeded, carIdsCheckedAlready, decrement));
if (output != null) return output; //short out if we are good
carIdsCheckedAlready.UnionWith(consist.Select(c => c.id));

View File

@@ -22,12 +22,12 @@ internal class CarPickable_HandleShowContextMenu_Patch
bool buttonsHaveCost = tweaksAndThings.EndGearHelpersRequirePayment();
ContextMenu shared = ContextMenu.Shared;
shared.AddButton(ContextMenuQuadrant.Unused2, $"{(car._set.Cars.Any(c => c.HandbrakeApplied()) ? "Release " : "Set ")} Consist", SpriteName.Handbrake, delegate
shared.AddButton(ContextMenuQuadrant.Unused2, $"{(car.EnumerateCoupled().Any(c => c.HandbrakeApplied()) ? "Release " : "Set ")} Consist", SpriteName.Handbrake, delegate
{
CarInspector_PopulateCarPanel_Patch.MrocConsistHelper(car, MrocHelperType.Handbrake, buttonsHaveCost);
});
if (car._set.Cars.Any(c => c.EndAirSystemIssue()))
if (car.EnumerateCoupled().Any(c => c.EndAirSystemIssue()))
{
shared.AddButton(ContextMenuQuadrant.Unused2, $"Air Up Consist", SpriteName.Select, delegate
{
@@ -35,7 +35,7 @@ internal class CarPickable_HandleShowContextMenu_Patch
});
}
if (car._set.Cars.Any(c => c.SupportsBleed()))
if (car.EnumerateCoupled().Any(c => c.SupportsBleed()))
{
shared.AddButton(ContextMenuQuadrant.Unused2, $"Bleed Consist", SpriteName.Bleed, delegate
{