mirror of
https://github.com/rmroc451/TweaksAndThings.git
synced 2025-12-16 09:19:37 -06:00
fixes #48; resurrect the context menu backgrounds!
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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<TweaksAndThingsPlugin>.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<Canvas>();
|
||||
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<TweaksAndThingsPlugin>.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<TweaksAndThingsPlugin>.Shared;
|
||||
if (!tweaksAndThings.IsEnabled()) return true;
|
||||
|
||||
|
||||
List<ContextMenuItem> list = __instance._quadrants[(int)quadrant];
|
||||
int index = list.Count;
|
||||
ContextMenuItem contextMenuItem = UnityEngine.Object.Instantiate<ContextMenuItem>(__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<LayoutElement>().preferredHeight = 30f;
|
||||
list.Add(contextMenuItem);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -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<TweaksAndThingsPlugin>.Shared;
|
||||
if (!tweaksAndThings.IsEnabled()) return;
|
||||
|
||||
vh.Clear(); //clear the image backgrounds for now.
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user