tweaks to engine roster to show who has engines selected and throttling on AE Waypoint picker to 60fps.

This commit is contained in:
2025-09-02 22:19:41 -05:00
parent a7ae1d479c
commit 32f3e8b2db
2 changed files with 48 additions and 6 deletions

View File

@@ -1,16 +1,14 @@
using HarmonyLib;
using Helpers;
using Model.AI;
using Railloader;
using Serilog;
using System.Collections;
using Track;
using UI;
using UnityEngine;
using static Game.Messages.RequestOps;
using static UI.AutoEngineerDestinationPicker;
namespace RMROC451.TweaksAndThings;
namespace RMROC451.TweaksAndThings.Patches;
[HarmonyPatch(typeof(AutoEngineerDestinationPicker))]
[HarmonyPatch(nameof(AutoEngineerDestinationPicker.Loop))]
@@ -31,7 +29,7 @@ internal class AutoEngineerDestinationPicker_Loop_Patch
{
Hit valueOrDefault;
Location location;
WaitForSecondsRealtime wait = new WaitForSecondsRealtime(.1f);
WaitForSecondsRealtime wait = new WaitForSecondsRealtime(1/60);
while (true)
{
Location? currentOrdersGotoLocation = __instance.GetCurrentOrdersGotoLocation();

View File

@@ -15,6 +15,7 @@ using UI.EngineRoster;
using UI.Tooltips;
using UnityEngine;
using Game.State;
using Game;
namespace RMROC451.TweaksAndThings.Patches;
@@ -34,6 +35,8 @@ internal class EngineRosterRow_Refresh_Patch
string fuelInfoText = string.Empty;
string fuelInfoTooltip = string.Empty;
TweakyTweakTweakers(__instance);
if (tweaksAndThings == null ||
rosterFuelColumnSettings == null ||
!tweaksAndThings.IsEnabled() ||
@@ -131,13 +134,54 @@ internal class EngineRosterRow_Refresh_Patch
default:
break;
}
} catch (Exception ex)
}
catch (Exception ex)
{
rosterFuelColumnSettings.EngineRosterFuelStatusColumn = EngineRosterFuelDisplayColumn.None;
Log.Error(ex, "Error Detecting fuel status for engine roster");
}
}
private static void TweakyTweakTweakers(EngineRosterRow __instance)
{
var helperData = EngineTextHelper(__instance._engine);
if (helperData.HasValue)
{
__instance.nameLabel.text = helperData.Value.nameLabel;
__instance.nameTooltip.tooltipText += helperData.Value.nameTooltip;
}
__instance.crewLabel.text = string.Empty;
for (int i = __instance._crewComponents.Count - 1; i >= 0; i--)
{
string str = __instance._crewComponents[i];
if ((new[] { "MU", "AE" }).Contains(str))
str = $"<sup>{str} </sup>";
__instance.crewLabel.text = $"{str}{__instance.crewLabel.text}";
}
}
internal static (string nameLabel, string nameTooltip, int selectedCount)? EngineTextHelper(Car loco, bool mapIcon = false)
{
(string nameLabel, string nameTooltip, int selectedCount)? output = null;
int selectedCount = 0;
Dictionary<PlayerId, IPlayer> dictionary = StateManager.Shared.PlayersManager.AllPlayers.ToDictionary((IPlayer p) => p.PlayerId, (IPlayer p) => p);
List<string> usersSelected = new();
foreach (var kvp in dictionary)
{
if (new PlayerProperties(PlayerPropertiesManager.Shared._object[kvp.Key.ToString()]).SelectedCarId == loco.id)
{
usersSelected.Add(kvp.Value.Name);
selectedCount++;
}
}
if (selectedCount > 0 && dictionary.Count > 1)
output = ($"{(mapIcon && loco is BaseLocomotive ? loco.Ident.RoadNumber : loco.DisplayName)}<sub>{selectedCount}</sub>", $"{Environment.NewLine}Selected by: {string.Join(", ", usersSelected)}", selectedCount);
return output;
}
private static void SetLabelAndTooltip(ref TMP_Text label, ref UITooltipProvider tooltip, string fuelInfoText, string fuelInfoTooltip)
{
label.text = $" {fuelInfoText} {label.text}";