mirror of
https://github.com/rmroc451/TweaksAndThings.git
synced 2025-12-17 17:59:39 -06:00
#24 adding consist info to non motive power cars, that have a caboose, when Caboose Use mod setting is enabled.
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
using Game.Messages;
|
using Core;
|
||||||
|
using Game.Messages;
|
||||||
using Game.State;
|
using Game.State;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using KeyValue.Runtime;
|
using KeyValue.Runtime;
|
||||||
using Model;
|
using Model;
|
||||||
using Model.OpsNew;
|
|
||||||
using Network;
|
using Network;
|
||||||
using Railloader;
|
using Railloader;
|
||||||
using RMROC451.TweaksAndThings.Enums;
|
using RMROC451.TweaksAndThings.Enums;
|
||||||
@@ -13,6 +13,7 @@ using Serilog;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using UI;
|
||||||
using UI.Builder;
|
using UI.Builder;
|
||||||
using UI.CarInspector;
|
using UI.CarInspector;
|
||||||
using UI.ContextMenu;
|
using UI.ContextMenu;
|
||||||
@@ -40,36 +41,61 @@ internal class CarInspector_PopulateCarPanel_Patch
|
|||||||
|
|
||||||
TweaksAndThingsPlugin tweaksAndThings = SingletonPluginBase<TweaksAndThingsPlugin>.Shared;
|
TweaksAndThingsPlugin tweaksAndThings = SingletonPluginBase<TweaksAndThingsPlugin>.Shared;
|
||||||
if (!tweaksAndThings.IsEnabled) return true;
|
if (!tweaksAndThings.IsEnabled) return true;
|
||||||
bool buttonsHaveCost = tweaksAndThings?.settings?.EndGearHelpersRequirePayment ?? false;
|
bool buttonsHaveCost = tweaksAndThings.EndGearHelpersRequirePayment();
|
||||||
|
|
||||||
var consist = __instance._car.EnumerateCoupled(LogicalEnd.A);
|
var consist = __instance._car._set.Cars;
|
||||||
builder = AddCarConsistRebuildObservers(builder, consist);
|
builder = AddCarConsistRebuildObservers(builder, consist);
|
||||||
|
|
||||||
builder.HStack(delegate (UIPanelBuilder hstack)
|
builder.HStack(delegate (UIPanelBuilder hstack)
|
||||||
{
|
{
|
||||||
var buttonName = $"{(consist.Any(c => c.HandbrakeApplied()) ? "Release " : "Set ")} {TextSprites.HandbrakeWheel}";
|
var buttonName = $"{(consist.Any(c => c.HandbrakeApplied()) ? "Release " : "Set ")} {TextSprites.HandbrakeWheel}";
|
||||||
hstack.AddButtonCompact(buttonName, delegate {
|
hstack.AddButtonCompact(buttonName, delegate
|
||||||
|
{
|
||||||
MrocConsistHelper(__instance._car, MrocHelperType.Handbrake, buttonsHaveCost);
|
MrocConsistHelper(__instance._car, MrocHelperType.Handbrake, buttonsHaveCost);
|
||||||
hstack.Rebuild();
|
hstack.Rebuild();
|
||||||
}).Tooltip(buttonName, $"Iterates over cars in this consist and {(consist.Any(c => c.HandbrakeApplied()) ? "releases" : "sets")} {TextSprites.HandbrakeWheel}.");
|
}).Tooltip(buttonName, $"Iterates over cars in this consist and {(consist.Any(c => c.HandbrakeApplied()) ? "releases" : "sets")} {TextSprites.HandbrakeWheel}.");
|
||||||
|
|
||||||
if (consist.Any(c => c.EndAirSystemIssue()))
|
if (consist.Any(c => c.EndAirSystemIssue()))
|
||||||
{
|
{
|
||||||
hstack.AddButtonCompact("Connect Air", delegate {
|
hstack.AddButtonCompact("Connect Air", delegate
|
||||||
|
{
|
||||||
MrocConsistHelper(__instance._car, MrocHelperType.GladhandAndAnglecock, buttonsHaveCost);
|
MrocConsistHelper(__instance._car, MrocHelperType.GladhandAndAnglecock, buttonsHaveCost);
|
||||||
hstack.Rebuild();
|
hstack.Rebuild();
|
||||||
}).Tooltip("Connect Consist Air", "Iterates over each car in this consist and connects gladhands and opens anglecocks.");
|
}).Tooltip("Connect Consist Air", "Iterates over each car in this consist and connects gladhands and opens anglecocks.");
|
||||||
}
|
}
|
||||||
|
|
||||||
hstack.AddButtonCompact("Bleed Consist", delegate {
|
hstack.AddButtonCompact("Bleed Consist", delegate
|
||||||
|
{
|
||||||
MrocConsistHelper(__instance._car, MrocHelperType.BleedAirSystem, buttonsHaveCost);
|
MrocConsistHelper(__instance._car, MrocHelperType.BleedAirSystem, buttonsHaveCost);
|
||||||
hstack.Rebuild();
|
hstack.Rebuild();
|
||||||
}).Tooltip("Bleed Air Lines", "Iterates over each car in this consist and bleeds the air out of the lines.");
|
}).Tooltip("Bleed Air Lines", "Iterates over each car in this consist and bleeds the air out of the lines.");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
CabooseUiEnhancer(__instance, builder, consist, tweaksAndThings);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void CabooseUiEnhancer(CarInspector __instance, UIPanelBuilder builder, IEnumerable<Car> consist, TweaksAndThingsPlugin plugin)
|
||||||
|
{
|
||||||
|
if (plugin.CabooseNonMotiveAllowedSetting(__instance._car))
|
||||||
|
{
|
||||||
|
builder.HStack(delegate (UIPanelBuilder hstack)
|
||||||
|
{
|
||||||
|
hstack.AddField("Consist Info", hstack.HStack(delegate (UIPanelBuilder field)
|
||||||
|
{
|
||||||
|
int consistLength = consist.Count();
|
||||||
|
int tonnage = LocomotiveControlsHoverArea.CalculateTonnage(consist);
|
||||||
|
int lengthInMeters = UnityEngine.Mathf.CeilToInt(LocomotiveControlsHoverArea.CalculateLengthInMeters(consist.ToList()) * 3.28084f);
|
||||||
|
var newSubTitle = () => string.Format("{0}, {1:N0}T, {2:N0}ft, {3:0.0} mph", consistLength.Pluralize("car"), tonnage, lengthInMeters, __instance._car.VelocityMphAbs);
|
||||||
|
|
||||||
|
field.AddLabel(() => newSubTitle(), UIPanelBuilder.Frequency.Fast)
|
||||||
|
.Tooltip("Consist Info", "Reflects info about consist.").FlexibleWidth();
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static UIPanelBuilder AddCarConsistRebuildObservers(UIPanelBuilder builder, IEnumerable<Model.Car> consist)
|
private static UIPanelBuilder AddCarConsistRebuildObservers(UIPanelBuilder builder, IEnumerable<Model.Car> consist)
|
||||||
{
|
{
|
||||||
TagController tagController = UnityEngine.Object.FindFirstObjectByType<TagController>();
|
TagController tagController = UnityEngine.Object.FindFirstObjectByType<TagController>();
|
||||||
@@ -100,7 +126,7 @@ internal class CarInspector_PopulateCarPanel_Patch
|
|||||||
if (car.TagCallout != null) tagController.UpdateTags(CameraSelector.shared._currentCamera.GroundPosition, true); //tagController.UpdateTag(car, car.TagCallout, OpsController.Shared);
|
if (car.TagCallout != null) tagController.UpdateTags(CameraSelector.shared._currentCamera.GroundPosition, true); //tagController.UpdateTag(car, car.TagCallout, OpsController.Shared);
|
||||||
if (ContextMenu.IsShown && ContextMenu.Shared.centerLabel.text == car.DisplayName) CarPickable.HandleShowContextMenu(car);
|
if (ContextMenu.IsShown && ContextMenu.Shared.centerLabel.text == car.DisplayName) CarPickable.HandleShowContextMenu(car);
|
||||||
}
|
}
|
||||||
catch(Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_log.ForContext("car", car).Warning(ex, $"{nameof(AddObserver)} {car} Exception logged for {key}");
|
_log.ForContext("car", car).Warning(ex, $"{nameof(AddObserver)} {car} Exception logged for {key}");
|
||||||
}
|
}
|
||||||
@@ -125,7 +151,7 @@ internal class CarInspector_PopulateCarPanel_Patch
|
|||||||
public static void MrocConsistHelper(Model.Car car, MrocHelperType mrocHelperType, bool buttonsHaveCost)
|
public static void MrocConsistHelper(Model.Car car, MrocHelperType mrocHelperType, bool buttonsHaveCost)
|
||||||
{
|
{
|
||||||
TrainController tc = UnityEngine.Object.FindObjectOfType<TrainController>();
|
TrainController tc = UnityEngine.Object.FindObjectOfType<TrainController>();
|
||||||
IEnumerable<Model.Car> consist = car.EnumerateCoupled(LogicalEnd.A);
|
IEnumerable<Model.Car> consist = car._set.Cars;
|
||||||
_log.ForContext("car", car).Verbose($"{car} => {mrocHelperType} => {string.Join("/", consist.Select(c => c.ToString()))}");
|
_log.ForContext("car", car).Verbose($"{car} => {mrocHelperType} => {string.Join("/", consist.Select(c => c.ToString()))}");
|
||||||
|
|
||||||
CalculateCostIfEnabled(car, mrocHelperType, buttonsHaveCost, consist);
|
CalculateCostIfEnabled(car, mrocHelperType, buttonsHaveCost, consist);
|
||||||
@@ -206,7 +232,7 @@ internal class CarInspector_PopulateCarPanel_Patch
|
|||||||
carIdsCheckedAlready.Add(car.id);
|
carIdsCheckedAlready.Add(car.id);
|
||||||
|
|
||||||
//check consist, for cabeese
|
//check consist, for cabeese
|
||||||
IEnumerable<Car> consist = car.EnumerateCoupled(LogicalEnd.A);
|
IEnumerable<Car> consist = car._set.Cars;
|
||||||
output = consist.FirstOrDefault(c => c.CabooseWithSufficientCrewHours(timeNeeded, carIdsCheckedAlready, decrement));
|
output = consist.FirstOrDefault(c => c.CabooseWithSufficientCrewHours(timeNeeded, carIdsCheckedAlready, decrement));
|
||||||
if (output != null) return output; //short out if we are good
|
if (output != null) return output; //short out if we are good
|
||||||
carIdsCheckedAlready.UnionWith(consist.Select(c => c.id));
|
carIdsCheckedAlready.UnionWith(consist.Select(c => c.id));
|
||||||
|
|||||||
@@ -91,4 +91,7 @@ public static class SettingsExtensions
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool CabooseNonMotiveAllowedSetting(this TweaksAndThingsPlugin input, Car car) =>
|
||||||
|
input.EndGearHelpersRequirePayment() && car.set.Cars.CabooseInConsist() && car.NotMotivePower();
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user