From 2713247895fb4dd73895961eb74d1d0b91aa15e2 Mon Sep 17 00:00:00 2001 From: RMROC451 Date: Sun, 24 Aug 2025 17:35:55 -0500 Subject: [PATCH] fixes #48; resurrect the context menu backgrounds! --- ...CarPickable_HandleShowContextMenu_Patch.cs | 9 +- .../Patches/ContextMenu_Show_Patch.cs | 128 ------------------ .../Patches/WedgeImage_OnPopulateMesh.cs | 20 --- 3 files changed, 5 insertions(+), 152 deletions(-) delete mode 100644 TweaksAndThings/Patches/ContextMenu_Show_Patch.cs delete mode 100644 TweaksAndThings/Patches/WedgeImage_OnPopulateMesh.cs diff --git a/TweaksAndThings/Patches/CarPickable_HandleShowContextMenu_Patch.cs b/TweaksAndThings/Patches/CarPickable_HandleShowContextMenu_Patch.cs index 0b36b59..5cfde76 100644 --- a/TweaksAndThings/Patches/CarPickable_HandleShowContextMenu_Patch.cs +++ b/TweaksAndThings/Patches/CarPickable_HandleShowContextMenu_Patch.cs @@ -4,6 +4,7 @@ using Railloader; using RMROC451.TweaksAndThings.Enums; using RMROC451.TweaksAndThings.Extensions; using RollingStock; +using System; using System.Linq; using UI; using UI.ContextMenu; @@ -35,8 +36,6 @@ internal class CarPickable_HandleShowContextMenu_Patch }); if (GameInput.IsShiftDown) { - - if (!car.EnumerateCoupled().Any(c => !c.SupportsBleed())) { shared.AddButton(ContextMenuQuadrant.Brakes, $"Bleed Consist", SpriteName.Bleed, delegate @@ -52,7 +51,7 @@ internal class CarPickable_HandleShowContextMenu_Patch if (car.EnumerateCoupled().Any(c => c.EndAirSystemIssue())) { - shared.AddButton(ContextMenuQuadrant.Unused2, $"Air Up Consist", SpriteName.Select, delegate + shared.AddButton(ContextMenuQuadrant.General, $"Air Up Consist", SpriteName.Select, delegate { CarInspector_PopulateCarPanel_Patch.MrocConsistHelper(car, MrocHelperType.GladhandAndAnglecock, buttonsHaveCost); }); @@ -76,7 +75,9 @@ internal class CarPickable_HandleShowContextMenu_Patch CameraSelector.shared.FollowCar(car); }); - shared.Show(car.DisplayName); + string secondaryLine = car.Waybill.HasValue ? $"{Environment.NewLine}{car.Waybill.Value.Destination.DisplayName}" : string.Empty; + secondaryLine = secondaryLine.Length > 10 + Environment.NewLine.Length ? $"{secondaryLine.Substring(0, 7+ Environment.NewLine.Length)}..." : secondaryLine; + shared.Show($"{car.DisplayName}{secondaryLine}"); shared.BuildItemAngles(); shared.StartCoroutine(shared.AnimateButtonsShown()); return false; diff --git a/TweaksAndThings/Patches/ContextMenu_Show_Patch.cs b/TweaksAndThings/Patches/ContextMenu_Show_Patch.cs deleted file mode 100644 index 007c018..0000000 --- a/TweaksAndThings/Patches/ContextMenu_Show_Patch.cs +++ /dev/null @@ -1,128 +0,0 @@ -using HarmonyLib; -using Helpers; -using Railloader; -using Serilog; -using System; -using System.Collections.Generic; -using UI; -using UI.ContextMenu; -using UnityEngine; -using UnityEngine.UI; - -namespace RMROC451.TweaksAndThings.Patches; - -[HarmonyPatch(typeof(UI.ContextMenu.ContextMenu))] -[HarmonyPatch(nameof(UI.ContextMenu.ContextMenu.Show), typeof(string))] -[HarmonyPatchCategory("RMROC451TweaksAndThings")] -internal class ContextMenu_Show_Patch -{ - static bool Prefix(UI.ContextMenu.ContextMenu __instance, string centerText) - { - TweaksAndThingsPlugin tweaksAndThings = SingletonPluginBase.Shared; - if (!tweaksAndThings.IsEnabled()) return true; - - if (!__instance.GetRootCanvas(out var rootCanvas)) - { - Log.Warning("Couldn't get root canvas"); - return true; - } - __instance.CancelHideCoroutine(); - if (__instance.contentRectTransform.childCount >= 1) __instance.contentRectTransform.GetChild(0).DestroyAllChildren(); //YOINK DEM CIRCLES! - __instance.SetupTemplate(rootCanvas); - __instance.centerLabel.text = centerText; - Canvas componentInParent = ((Component)__instance.contentRectTransform).GetComponentInParent(); - Vector3 mousePosition = Input.mousePosition; - Vector2 val = componentInParent.ScreenToCanvasPosition(mousePosition).XY(); - Vector2 renderingDisplaySize = rootCanvas.renderingDisplaySize; - float num = __instance.radius + 50f; - if (val.x < num) - { - val.x = num; - } - if (val.x > renderingDisplaySize.x - num) - { - val.x = renderingDisplaySize.x - num; - } - if (val.y < num) - { - val.y = num; - } - if (val.y > renderingDisplaySize.y - num) - { - val.y = renderingDisplaySize.y - num; - } - __instance.contentRectTransform.anchoredPosition = val; - __instance.BuildItemAngles(); - - ((MonoBehaviour)__instance).StartCoroutine(__instance.AnimateButtonsShown()); - ((Component)__instance.contentRectTransform).gameObject.SetActive(true); - UI.ContextMenu.ContextMenu.IsShown = true; - __instance._blocker = __instance.CreateBlocker(rootCanvas); - GameInput.RegisterEscapeHandler(GameInput.EscapeHandler.Transient, delegate - { - __instance.Hide(); - return true; - }); - - return false; - } -} - - -[HarmonyPatch(typeof(UI.ContextMenu.ContextMenu))] -[HarmonyPatch(nameof(UI.ContextMenu.ContextMenu.DefaultAngleForItem), typeof(ContextMenuQuadrant), typeof(int), typeof(int))] -[HarmonyPatchCategory("RMROC451TweaksAndThings")] -internal class ContextMenu_DefaultAngleForItem_Patch -{ - static bool Prefix(UI.ContextMenu.ContextMenu __instance, ref float __result, ContextMenuQuadrant quadrant, int index, int quadrantItemCount) - { - TweaksAndThingsPlugin tweaksAndThings = SingletonPluginBase.Shared; - if (!tweaksAndThings.IsEnabled()) return true; - - - int num = quadrant switch - { - ContextMenuQuadrant.General => 0, - ContextMenuQuadrant.Unused1 => 90, - ContextMenuQuadrant.Brakes => 180, - ContextMenuQuadrant.Unused2 => -90, - _ => throw new ArgumentOutOfRangeException("quadrant", quadrant, null), - }; - if (quadrantItemCount <= 1) - { - __result = num; - return false; - } - int num2 = ((quadrantItemCount <= 3) ? 30 : (90 / (quadrantItemCount - 1))); - __result = (float)num + -0.5f * (float)((quadrantItemCount - 1) * num2) + (float)(num2 * index); - return false; - } -} - - -[HarmonyPatch(typeof(UI.ContextMenu.ContextMenu))] -[HarmonyPatch(nameof(UI.ContextMenu.ContextMenu.AddButton), typeof(ContextMenuQuadrant), typeof(string), typeof(Sprite), typeof(Action))] -[HarmonyPatchCategory("RMROC451TweaksAndThings")] -internal class ContextMenu_AddButton_Patch -{ - static bool Prefix(UI.ContextMenu.ContextMenu __instance, ContextMenuQuadrant quadrant, string title, Sprite sprite, Action action) - { - TweaksAndThingsPlugin tweaksAndThings = SingletonPluginBase.Shared; - if (!tweaksAndThings.IsEnabled()) return true; - - - List list = __instance._quadrants[(int)quadrant]; - int index = list.Count; - ContextMenuItem contextMenuItem = UnityEngine.Object.Instantiate(__instance.itemPrefab, (Transform)(object)__instance.contentRectTransform); - contextMenuItem.image.sprite = sprite; - contextMenuItem.label.text = title; - contextMenuItem.OnClick = delegate - { - action(); - __instance.Hide((quadrant, index)); - }; - ((Component)contextMenuItem).gameObject.AddComponent().preferredHeight = 30f; - list.Add(contextMenuItem); - return false; - } -} \ No newline at end of file diff --git a/TweaksAndThings/Patches/WedgeImage_OnPopulateMesh.cs b/TweaksAndThings/Patches/WedgeImage_OnPopulateMesh.cs deleted file mode 100644 index dcc7121..0000000 --- a/TweaksAndThings/Patches/WedgeImage_OnPopulateMesh.cs +++ /dev/null @@ -1,20 +0,0 @@ -using HarmonyLib; -using Railloader; -using UI.ContextMenu; -using UnityEngine.UI; - -namespace RMROC451.TweaksAndThings.Patches; - -[HarmonyPatch(typeof(WedgeImage))] -[HarmonyPatch(nameof(WedgeImage.OnPopulateMesh), typeof(VertexHelper))] -[HarmonyPatchCategory("RMROC451TweaksAndThings")] -internal class WedgeImage_OnPopulateMesh_Patch -{ - private static void Postfix(VertexHelper vh) - { - TweaksAndThingsPlugin tweaksAndThings = SingletonPluginBase.Shared; - if (!tweaksAndThings.IsEnabled()) return; - - vh.Clear(); //clear the image backgrounds for now. - } -}