mirror of
https://github.com/rmroc451/TweaksAndThings.git
synced 2025-12-16 01:09:38 -06:00
tweaks to engine roster to show who has engines selected and throttling on AE Waypoint picker to 60fps.
This commit is contained in:
@@ -1,16 +1,14 @@
|
|||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using Helpers;
|
using Helpers;
|
||||||
using Model.AI;
|
|
||||||
using Railloader;
|
using Railloader;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using Track;
|
using Track;
|
||||||
using UI;
|
using UI;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using static Game.Messages.RequestOps;
|
|
||||||
using static UI.AutoEngineerDestinationPicker;
|
using static UI.AutoEngineerDestinationPicker;
|
||||||
|
|
||||||
namespace RMROC451.TweaksAndThings;
|
namespace RMROC451.TweaksAndThings.Patches;
|
||||||
|
|
||||||
[HarmonyPatch(typeof(AutoEngineerDestinationPicker))]
|
[HarmonyPatch(typeof(AutoEngineerDestinationPicker))]
|
||||||
[HarmonyPatch(nameof(AutoEngineerDestinationPicker.Loop))]
|
[HarmonyPatch(nameof(AutoEngineerDestinationPicker.Loop))]
|
||||||
@@ -31,7 +29,7 @@ internal class AutoEngineerDestinationPicker_Loop_Patch
|
|||||||
{
|
{
|
||||||
Hit valueOrDefault;
|
Hit valueOrDefault;
|
||||||
Location location;
|
Location location;
|
||||||
WaitForSecondsRealtime wait = new WaitForSecondsRealtime(.1f);
|
WaitForSecondsRealtime wait = new WaitForSecondsRealtime(1/60);
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
Location? currentOrdersGotoLocation = __instance.GetCurrentOrdersGotoLocation();
|
Location? currentOrdersGotoLocation = __instance.GetCurrentOrdersGotoLocation();
|
||||||
@@ -15,6 +15,7 @@ using UI.EngineRoster;
|
|||||||
using UI.Tooltips;
|
using UI.Tooltips;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Game.State;
|
using Game.State;
|
||||||
|
using Game;
|
||||||
|
|
||||||
|
|
||||||
namespace RMROC451.TweaksAndThings.Patches;
|
namespace RMROC451.TweaksAndThings.Patches;
|
||||||
@@ -34,6 +35,8 @@ internal class EngineRosterRow_Refresh_Patch
|
|||||||
string fuelInfoText = string.Empty;
|
string fuelInfoText = string.Empty;
|
||||||
string fuelInfoTooltip = string.Empty;
|
string fuelInfoTooltip = string.Empty;
|
||||||
|
|
||||||
|
TweakyTweakTweakers(__instance);
|
||||||
|
|
||||||
if (tweaksAndThings == null ||
|
if (tweaksAndThings == null ||
|
||||||
rosterFuelColumnSettings == null ||
|
rosterFuelColumnSettings == null ||
|
||||||
!tweaksAndThings.IsEnabled() ||
|
!tweaksAndThings.IsEnabled() ||
|
||||||
@@ -52,7 +55,7 @@ internal class EngineRosterRow_Refresh_Patch
|
|||||||
bool cabooseRequirementFulfilled =
|
bool cabooseRequirementFulfilled =
|
||||||
!tweaksAndThings.RequireConsistCabooseForOilerAndHotboxSpotter()
|
!tweaksAndThings.RequireConsistCabooseForOilerAndHotboxSpotter()
|
||||||
|| consist.ConsistNoFreight()
|
|| consist.ConsistNoFreight()
|
||||||
|| (bool)engineOrTender.FindMyCabooseSansLoadRequirement();
|
|| (bool)engineOrTender.FindMyCabooseSansLoadRequirement();
|
||||||
float offendingPercentage = 100f;
|
float offendingPercentage = 100f;
|
||||||
|
|
||||||
foreach (Car loco in locos)
|
foreach (Car loco in locos)
|
||||||
@@ -131,13 +134,54 @@ internal class EngineRosterRow_Refresh_Patch
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (Exception ex)
|
}
|
||||||
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
rosterFuelColumnSettings.EngineRosterFuelStatusColumn = EngineRosterFuelDisplayColumn.None;
|
rosterFuelColumnSettings.EngineRosterFuelStatusColumn = EngineRosterFuelDisplayColumn.None;
|
||||||
Log.Error(ex, "Error Detecting fuel status for engine roster");
|
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)
|
private static void SetLabelAndTooltip(ref TMP_Text label, ref UITooltipProvider tooltip, string fuelInfoText, string fuelInfoTooltip)
|
||||||
{
|
{
|
||||||
label.text = $" {fuelInfoText} {label.text}";
|
label.text = $" {fuelInfoText} {label.text}";
|
||||||
|
|||||||
Reference in New Issue
Block a user