From a9e65802588eb47bb5de207c58ea23f1dd818977 Mon Sep 17 00:00:00 2001 From: Ryan Mroczenski Date: Mon, 17 Jun 2024 20:54:05 -0500 Subject: [PATCH 1/2] work in progress attempts to resolve text overlapping on car tag titles. --- ...ch.cs => TagController_UpdateTag_Patch.cs} | 39 +++++++------------ .../RMROC451.TweaksAndThings.csproj | 8 +--- 2 files changed, 15 insertions(+), 32 deletions(-) rename TweaksAndThings/Patches/{TagConroller_UpdateTag_Patch.cs => TagController_UpdateTag_Patch.cs} (69%) diff --git a/TweaksAndThings/Patches/TagConroller_UpdateTag_Patch.cs b/TweaksAndThings/Patches/TagController_UpdateTag_Patch.cs similarity index 69% rename from TweaksAndThings/Patches/TagConroller_UpdateTag_Patch.cs rename to TweaksAndThings/Patches/TagController_UpdateTag_Patch.cs index 38d85e6..b7a44be 100644 --- a/TweaksAndThings/Patches/TagConroller_UpdateTag_Patch.cs +++ b/TweaksAndThings/Patches/TagController_UpdateTag_Patch.cs @@ -1,48 +1,35 @@ using HarmonyLib; -using JetBrains.Annotations; using Model; -using Model.AI; using Model.OpsNew; using Railloader; -using Serilog; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Sockets; -using System.Text; -using System.Threading.Tasks; -using Track; -using TweaksAndThings; using UI; -using UI.Builder; -using UI.CarInspector; using UI.Tags; using UnityEngine; -using static Model.Car; -using tat = TweaksAndThings.TweaksAndThings; namespace TweaksAndThings.Patches; [HarmonyPatch(typeof(TagController))] [HarmonyPatch(nameof(TagController.UpdateTag), typeof(Car), typeof(TagCallout), typeof(OpsController))] [HarmonyPatchCategory("RMROC451TweaksAndThings")] -public class TagConroller_UpdateTag_Patch +public class TagController_UpdateTag_Patch { private static void Postfix(Car car, TagCallout tagCallout) { TagController tagController = UnityEngine.Object.FindObjectOfType(); TweaksAndThings tweaksAndThings = SingletonPluginBase.Shared; - tagCallout.callout.Title = $"{car.DisplayName}"; + bool concatOnly = car.DisplayName.Length > 6; + string delimiter = concatOnly ? " " : "\n"; if (!tweaksAndThings.IsEnabled || !tweaksAndThings.settings.HandBrakeAndAirTagModifiers) { return; } - + tagCallout.callout.Title = concatOnly ? $"{car.DisplayName} " : $"{car.DisplayName}"; tagCallout.gameObject.SetActive( tagCallout.gameObject.activeSelf && (!GameInput.IsShiftDown || (GameInput.IsShiftDown && car.CarOrEndGearIssue())) ); + if (tagCallout.gameObject.activeSelf && GameInput.IsShiftDown && car.CarOrEndGearIssue()) { tagController.ApplyImageColor(tagCallout, Color.black); @@ -50,17 +37,17 @@ public class TagConroller_UpdateTag_Patch if (car.CarAndEndGearIssue()) { - tagCallout.callout.Title = - $"{tagCallout.callout.Title}\n{TextSprites.CycleWaybills}{TextSprites.HandbrakeWheel}"; + tagCallout.callout.Title = $"{tagCallout.callout.Title}{delimiter}{TextSprites.CycleWaybills}{TextSprites.HandbrakeWheel}"; } else if (car.EndAirSystemIssue()) - tagCallout.callout.Title = - $"{tagCallout.callout.Title}\n{TextSprites.CycleWaybills}"; - else if (car.HandbrakeApplied()) - tagCallout.callout.Title = - $"{tagCallout.callout.Title}\n{TextSprites.HandbrakeWheel}"; - + { + tagCallout.callout.Title = $"{tagCallout.callout.Title}{delimiter}{TextSprites.CycleWaybills}"; + } + else if (car.HandbrakeApplied()) + { + tagCallout.callout.Title = $"{tagCallout.callout.Title}{delimiter}{TextSprites.HandbrakeWheel}"; + } return; } } diff --git a/TweaksAndThings/RMROC451.TweaksAndThings.csproj b/TweaksAndThings/RMROC451.TweaksAndThings.csproj index 47d737c..af81fa5 100644 --- a/TweaksAndThings/RMROC451.TweaksAndThings.csproj +++ b/TweaksAndThings/RMROC451.TweaksAndThings.csproj @@ -13,6 +13,8 @@ + + @@ -27,10 +29,4 @@ - - - - D:\SteamLibrary\steamapps\common\Railroader\Mods\ForYourConvenience\ForYourConvenience.dll - - From 9d9cc96283f22bbea864af5fcb62add27886a46e Mon Sep 17 00:00:00 2001 From: RMROC451 Date: Tue, 18 Jun 2024 00:26:20 -0500 Subject: [PATCH 2/2] resolve #3 overlapping callout titles with the right floating icons. Switching from SHIFT to LEFT ALT key for hiding car callouts that have no issues. --- .../CarInspector_PopulateCarPanel_Patch.cs | 24 ++++++++-- .../Patches/TagController_UpdateTag_Patch.cs | 47 ++++++++++--------- TweaksAndThings/TweaksAndThings.cs | 2 +- 3 files changed, 47 insertions(+), 26 deletions(-) diff --git a/TweaksAndThings/Patches/CarInspector_PopulateCarPanel_Patch.cs b/TweaksAndThings/Patches/CarInspector_PopulateCarPanel_Patch.cs index b9f7654..42efc20 100644 --- a/TweaksAndThings/Patches/CarInspector_PopulateCarPanel_Patch.cs +++ b/TweaksAndThings/Patches/CarInspector_PopulateCarPanel_Patch.cs @@ -62,18 +62,34 @@ public class CarInspector_PopulateCarPanel_Patch { foreach (Model.Car car in consist) { - builder.AddObserver(car.KeyValueObject.Observe(PropertyChange.KeyForControl(PropertyChange.Control.Handbrake), delegate (Value value) { builder.Rebuild(); }, false)); + builder = AddObserver(builder, car, PropertyChange.KeyForControl(PropertyChange.Control.Handbrake)); foreach (LogicalEnd logicalEnd in ends) { - builder.AddObserver(car.KeyValueObject.Observe(KeyValueKeyFor(EndGearStateKey.IsCoupled, car.LogicalToEnd(logicalEnd)), delegate (Value value) { builder.Rebuild(); }, false)); - builder.AddObserver(car.KeyValueObject.Observe(KeyValueKeyFor(EndGearStateKey.IsAirConnected, car.LogicalToEnd(logicalEnd)), delegate (Value value) { builder.Rebuild(); }, false)); - builder.AddObserver(car.KeyValueObject.Observe(KeyValueKeyFor(EndGearStateKey.Anglecock, car.LogicalToEnd(logicalEnd)), delegate (Value value) { builder.Rebuild(); }, false)); + builder = AddObserver(builder, car, KeyValueKeyFor(EndGearStateKey.IsCoupled, car.LogicalToEnd(logicalEnd))); + builder = AddObserver(builder, car, KeyValueKeyFor(EndGearStateKey.IsAirConnected, car.LogicalToEnd(logicalEnd))); + builder = AddObserver(builder, car, KeyValueKeyFor(EndGearStateKey.Anglecock, car.LogicalToEnd(logicalEnd))); } } return builder; } + private static UIPanelBuilder AddObserver(UIPanelBuilder builder, Model.Car car, string key) + { + builder.AddObserver( + car.KeyValueObject.Observe( + key, + delegate (Value value) + { + builder.Rebuild(); + }, + false + ) + ); + + return builder; + } + public static void MrocConsistHelper(Model.Car car, MrocHelperType mrocHelperType) { IEnumerable consist = car.EnumerateCoupled(LogicalEnd.A); diff --git a/TweaksAndThings/Patches/TagController_UpdateTag_Patch.cs b/TweaksAndThings/Patches/TagController_UpdateTag_Patch.cs index b7a44be..c123f3c 100644 --- a/TweaksAndThings/Patches/TagController_UpdateTag_Patch.cs +++ b/TweaksAndThings/Patches/TagController_UpdateTag_Patch.cs @@ -13,42 +13,46 @@ namespace TweaksAndThings.Patches; [HarmonyPatchCategory("RMROC451TweaksAndThings")] public class TagController_UpdateTag_Patch { + private const string tagTitleAndIconDelimeter = "\n"; + private const string tagTitleFormat = "{1}"; + private static void Postfix(Car car, TagCallout tagCallout) { TagController tagController = UnityEngine.Object.FindObjectOfType(); TweaksAndThings tweaksAndThings = SingletonPluginBase.Shared; - bool concatOnly = car.DisplayName.Length > 6; - string delimiter = concatOnly ? " " : "\n"; if (!tweaksAndThings.IsEnabled || !tweaksAndThings.settings.HandBrakeAndAirTagModifiers) { return; } - tagCallout.callout.Title = concatOnly ? $"{car.DisplayName} " : $"{car.DisplayName}"; + + ProceedWithPostFix(car, tagCallout, tagController); + + return; + } + + private static void ProceedWithPostFix(Car car, TagCallout tagCallout, TagController tagController) + { + bool isAltDownWithCarIssue = GameInput.IsAltDown && car.CarOrEndGearIssue(); + tagCallout.callout.Title = string.Format(tagTitleFormat, "{0}", car.DisplayName); tagCallout.gameObject.SetActive( - tagCallout.gameObject.activeSelf && - (!GameInput.IsShiftDown || (GameInput.IsShiftDown && car.CarOrEndGearIssue())) + tagCallout.gameObject.activeSelf && + (!GameInput.IsAltDown || isAltDownWithCarIssue) ); - if (tagCallout.gameObject.activeSelf && GameInput.IsShiftDown && car.CarOrEndGearIssue()) { - + if (tagCallout.gameObject.activeSelf && isAltDownWithCarIssue) + { tagController.ApplyImageColor(tagCallout, Color.black); } - if (car.CarAndEndGearIssue()) - { - tagCallout.callout.Title = $"{tagCallout.callout.Title}{delimiter}{TextSprites.CycleWaybills}{TextSprites.HandbrakeWheel}"; - } - else if (car.EndAirSystemIssue()) - { - tagCallout.callout.Title = $"{tagCallout.callout.Title}{delimiter}{TextSprites.CycleWaybills}"; - - } - else if (car.HandbrakeApplied()) - { - tagCallout.callout.Title = $"{tagCallout.callout.Title}{delimiter}{TextSprites.HandbrakeWheel}"; - } - return; + tagCallout.callout.Title = + (car.CarAndEndGearIssue(), car.EndAirSystemIssue(), car.HandbrakeApplied()) switch + { + (true, _, _) => $"{tagCallout.callout.Title}{tagTitleAndIconDelimeter}{TextSprites.CycleWaybills}{TextSprites.HandbrakeWheel}".Replace("{0}", "2"), + (_, true, _) => $"{tagCallout.callout.Title}{tagTitleAndIconDelimeter}{TextSprites.CycleWaybills}".Replace("{0}", "1"), + (_, _, true) => $"{tagCallout.callout.Title}{tagTitleAndIconDelimeter}{TextSprites.HandbrakeWheel}".Replace("{0}", "1"), + _ => car.DisplayName + }; } } @@ -67,6 +71,7 @@ public static class ModelCarExtensions public static bool CarOrEndGearIssue(this Model.Car car) => car.EndAirSystemIssue() || car.HandbrakeApplied(); + public static bool CarAndEndGearIssue(this Model.Car car) => car.EndAirSystemIssue() && car.HandbrakeApplied(); } diff --git a/TweaksAndThings/TweaksAndThings.cs b/TweaksAndThings/TweaksAndThings.cs index abdf47e..7c0d939 100644 --- a/TweaksAndThings/TweaksAndThings.cs +++ b/TweaksAndThings/TweaksAndThings.cs @@ -94,7 +94,7 @@ namespace TweaksAndThings builder.Rebuild(); } ) - ).Tooltip("Enable Tag Updates", $"Will add {TextSprites.CycleWaybills} to the car tag title having Air System issues. Also prepends {TextSprites.HandbrakeWheel} if there is a handbrake set.\n\nHolding Shift while tags are displayed only shows tag titles that have issues."); + ).Tooltip("Enable Tag Updates", $"Will add {TextSprites.CycleWaybills} to the car tag title having Air System issues. Also prepends {TextSprites.HandbrakeWheel} if there is a handbrake set.\n\nHolding Left Alt while tags are displayed only shows tag titles that have issues."); }); }