mirror of
https://github.com/rmroc451/TweaksAndThings.git
synced 2025-12-17 01:39:38 -06:00
Compare commits
1 Commits
v1.2.3_Exp
...
v1.2.4_Exp
| Author | SHA1 | Date | |
|---|---|---|---|
| 80f0847587 |
@@ -2,6 +2,6 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<MajorVersion>1</MajorVersion>
|
<MajorVersion>1</MajorVersion>
|
||||||
<MinorVersion>2</MinorVersion>
|
<MinorVersion>2</MinorVersion>
|
||||||
<PatchVersion>3</PatchVersion>
|
<PatchVersion>4</PatchVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -47,7 +47,6 @@ internal class CarPickable_HandleShowContextMenu_Patch
|
|||||||
{
|
{
|
||||||
CameraSelector.shared.FollowCar(car);
|
CameraSelector.shared.FollowCar(car);
|
||||||
});
|
});
|
||||||
shared.radius = 200f;
|
|
||||||
shared.BuildItemAngles();
|
shared.BuildItemAngles();
|
||||||
shared.StartCoroutine(shared.AnimateButtonsShown());
|
shared.StartCoroutine(shared.AnimateButtonsShown());
|
||||||
}
|
}
|
||||||
|
|||||||
25
TweaksAndThings/Patches/ContextMenu_PositionForItem_Patch.cs
Normal file
25
TweaksAndThings/Patches/ContextMenu_PositionForItem_Patch.cs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
using HarmonyLib;
|
||||||
|
using Railloader;
|
||||||
|
using System;
|
||||||
|
using UI.ContextMenu;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
|
||||||
|
namespace RMROC451.TweaksAndThings.Patches;
|
||||||
|
|
||||||
|
[HarmonyPatch(typeof(UI.ContextMenu.ContextMenu))]
|
||||||
|
//ContextMenuQuadrant quadrant, int index, float normalizedRadius = 1f
|
||||||
|
[HarmonyPatch(nameof(UI.ContextMenu.ContextMenu.PositionForItem), typeof(ContextMenuQuadrant), typeof(int), typeof(float))]
|
||||||
|
[HarmonyPatchCategory("RMROC451TweaksAndThings")]
|
||||||
|
internal class ContextMenu_PositionForItem_Patch
|
||||||
|
{
|
||||||
|
static void Postfix(UI.ContextMenu.ContextMenu __instance, ref Vector2 __result, ContextMenuQuadrant quadrant, int index, float normalizedRadius = 1f)
|
||||||
|
{
|
||||||
|
TweaksAndThingsPlugin tweaksAndThings = SingletonPluginBase<TweaksAndThingsPlugin>.Shared;
|
||||||
|
if (!tweaksAndThings.IsEnabled) return;
|
||||||
|
|
||||||
|
float num = __instance._itemAngles[(quadrant, index)] * ((float)Math.PI / 180f);
|
||||||
|
float num2 = __instance.radius * normalizedRadius;
|
||||||
|
__result = new Vector2(1.3f * Mathf.Sin(num) * num2, Mathf.Cos(num) * num2);
|
||||||
|
}
|
||||||
|
}
|
||||||
127
TweaksAndThings/Patches/ContextMenu_Show_Patch.cs
Normal file
127
TweaksAndThings/Patches/ContextMenu_Show_Patch.cs
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
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();
|
||||||
|
__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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user