diff --git a/Assembly.version b/Assembly.version new file mode 100644 index 0000000..691d1be --- /dev/null +++ b/Assembly.version @@ -0,0 +1,7 @@ + + + 1 + 2 + 6 + + \ No newline at end of file diff --git a/Directory.Build.props b/Directory.Build.props index fe5e246..1d15827 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,5 +1,6 @@  + net48 latest diff --git a/Directory.Build.targets b/Directory.Build.targets index 920a7a7..c6e889f 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -39,7 +39,7 @@ ../bin - $(PublishPath)/$(AssemblyName)_$(AssemblyVersion).zip + $(PublishPath)/$(AssemblyName)_$(AssemblyVersion)_Experimental.zip diff --git a/Paths.user.example b/Paths.user.example new file mode 100644 index 0000000..f5786ad --- /dev/null +++ b/Paths.user.example @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/TweaksAndThings.sln b/TweaksAndThings.sln index da34e15..b4b596c 100644 --- a/TweaksAndThings.sln +++ b/TweaksAndThings.sln @@ -6,6 +6,7 @@ MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{452A23A6-81C8-49C6-A7EE-95FD9377F896}" ProjectSection(SolutionItems) = preProject .gitignore = .gitignore + Assembly.version = Assembly.version Directory.Build.props = Directory.Build.props Directory.Build.targets = Directory.Build.targets Paths.user = Paths.user diff --git a/TweaksAndThings/Commands/CrewUpdateCommand.cs b/TweaksAndThings/Commands/CrewUpdateCommand.cs index d204df2..b24bd0b 100644 --- a/TweaksAndThings/Commands/CrewUpdateCommand.cs +++ b/TweaksAndThings/Commands/CrewUpdateCommand.cs @@ -1,6 +1,6 @@ using Game.State; using Helpers; -using Model.OpsNew; +using Model.Ops; using Network; using RMROC451.TweaksAndThings.Extensions; using System.Linq; diff --git a/TweaksAndThings/Definition.json b/TweaksAndThings/Definition.json index 5d66ba7..a29b876 100644 --- a/TweaksAndThings/Definition.json +++ b/TweaksAndThings/Definition.json @@ -5,10 +5,17 @@ "version": "$(AssemblyVersion)", "requires": [ { - "id": "railloader", - "notBefore": "1.8.1" + "id": "railroader", + "notBefore": "2024.6" }, - "Zamu.StrangeCustoms" + { + "id": "railloader", + "notBefore": "1.9.6.14" + }, + { + "id": "Zamu.StrangeCustoms", + "notBefore": "1.10.25017.313" + } ], "assemblies": [ "RMROC451.TweaksAndThings" ], "mixintos": { diff --git a/TweaksAndThings/Extensions/Car_Extensions.cs b/TweaksAndThings/Extensions/Car_Extensions.cs index 5e70ad7..2fb2a63 100644 --- a/TweaksAndThings/Extensions/Car_Extensions.cs +++ b/TweaksAndThings/Extensions/Car_Extensions.cs @@ -3,7 +3,7 @@ using Game.State; using Helpers; using Model; using Model.Definition.Data; -using Model.OpsNew; +using Model.Ops; using Serilog; using System; using System.Collections.Generic; @@ -109,8 +109,7 @@ public static class Car_Extensions { Vector3 position = car.GetMotionSnapshot().Position; Vector3 center = WorldTransformer.WorldToGame(position); - Rect rect = new Rect(new Vector2(center.x - 30f, center.z - 30f), Vector2.one * 30f * 2f); - var cars = tc.CarIdsInRect(rect); + var cars = tc.CarIdsInRadius(center, 60f); Log.Information($"{nameof(HuntingForCabeeseNearCar)} => {cars.Count()}"); List<(string carId, float distance)> source = cars diff --git a/TweaksAndThings/Patches/CarPickable_HandleShowContextMenu_Patch.cs b/TweaksAndThings/Patches/CarPickable_HandleShowContextMenu_Patch.cs index 69eee66..5ceff11 100644 --- a/TweaksAndThings/Patches/CarPickable_HandleShowContextMenu_Patch.cs +++ b/TweaksAndThings/Patches/CarPickable_HandleShowContextMenu_Patch.cs @@ -22,20 +22,20 @@ internal class CarPickable_HandleShowContextMenu_Patch bool buttonsHaveCost = tweaksAndThings.EndGearHelpersRequirePayment(); ContextMenu shared = ContextMenu.Shared; - shared.AddButton(ContextMenuQuadrant.Unused2, $"{(car.EnumerateCoupled().Any(c => c.HandbrakeApplied()) ? "Release " : "Set ")} Consist", SpriteName.Handbrake, delegate + shared.AddButton(ContextMenuQuadrant.Unused1, $"{(car.EnumerateCoupled().Any(c => c.HandbrakeApplied()) ? "Release " : "Set ")} Consist", SpriteName.Handbrake, delegate { CarInspector_PopulateCarPanel_Patch.MrocConsistHelper(car, MrocHelperType.Handbrake, buttonsHaveCost); }); if (car.EnumerateCoupled().Any(c => c.EndAirSystemIssue())) { - shared.AddButton(ContextMenuQuadrant.Unused2, $"Air Up Consist", SpriteName.Select, delegate + shared.AddButton(ContextMenuQuadrant.Unused1, $"Air Up Consist", SpriteName.Select, delegate { CarInspector_PopulateCarPanel_Patch.MrocConsistHelper(car, MrocHelperType.GladhandAndAnglecock, buttonsHaveCost); }); } - if (car.EnumerateCoupled().Any(c => c.SupportsBleed())) + if (!car.EnumerateCoupled().Any(c => !c.SupportsBleed())) { shared.AddButton(ContextMenuQuadrant.Unused2, $"Bleed Consist", SpriteName.Bleed, delegate { @@ -43,11 +43,10 @@ internal class CarPickable_HandleShowContextMenu_Patch }); } - shared.AddButton(ContextMenuQuadrant.Unused2, $"Follow", SpriteName.Inspect, delegate + shared.AddButton(ContextMenuQuadrant.General, $"Follow", SpriteName.Inspect, delegate { CameraSelector.shared.FollowCar(car); }); - shared.BuildItemAngles(); shared.StartCoroutine(shared.AnimateButtonsShown()); } diff --git a/TweaksAndThings/Patches/ContextMenu_PositionForItem_Patch.cs b/TweaksAndThings/Patches/ContextMenu_PositionForItem_Patch.cs new file mode 100644 index 0000000..1bef1ed --- /dev/null +++ b/TweaksAndThings/Patches/ContextMenu_PositionForItem_Patch.cs @@ -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.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); + } +} diff --git a/TweaksAndThings/Patches/ContextMenu_Show_Patch.cs b/TweaksAndThings/Patches/ContextMenu_Show_Patch.cs new file mode 100644 index 0000000..94f4406 --- /dev/null +++ b/TweaksAndThings/Patches/ContextMenu_Show_Patch.cs @@ -0,0 +1,128 @@ +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/EngineRosterRow_Refresh_Patch.cs b/TweaksAndThings/Patches/EngineRosterRow_Refresh_Patch.cs index 4b14fb2..7eacd0b 100644 --- a/TweaksAndThings/Patches/EngineRosterRow_Refresh_Patch.cs +++ b/TweaksAndThings/Patches/EngineRosterRow_Refresh_Patch.cs @@ -1,7 +1,7 @@ using HarmonyLib; using Model; using Model.Definition.Data; -using Model.OpsNew; +using Model.Ops; using Railloader; using RMROC451.TweaksAndThings.Extensions; using Serilog; diff --git a/TweaksAndThings/Patches/OpsController_AnnounceCoalescedPayments_Patch.cs b/TweaksAndThings/Patches/OpsController_AnnounceCoalescedPayments_Patch.cs index 19a22cc..e35bca4 100644 --- a/TweaksAndThings/Patches/OpsController_AnnounceCoalescedPayments_Patch.cs +++ b/TweaksAndThings/Patches/OpsController_AnnounceCoalescedPayments_Patch.cs @@ -4,7 +4,7 @@ using HarmonyLib; using Model; using Model.Definition.Data; using Model.Ops.Definition; -using Model.OpsNew; +using Model.Ops; using Network; using Railloader; using RMROC451.TweaksAndThings.Extensions; @@ -50,7 +50,8 @@ internal class CarPrototypeLibrary_LoadForId_Patch [HarmonyPatchCategory("RMROC451TweaksAndThings")] internal class OpsController_AnnounceCoalescedPayments_Patch { - static Dictionary CrewCarDict = []; + static Dictionary CrewCarDict = new(); + public static (bool spotted, bool filling) CrewCarStatus(Car car) { bool found = CrewCarDict.TryGetValue(car.id, out (bool spotted, bool filling) val); @@ -61,12 +62,13 @@ internal class OpsController_AnnounceCoalescedPayments_Patch } static GameDateTime dateTime = TimeWeather.Now; - static readonly IEnumerable refillLocations = [ + static readonly IEnumerable refillLocations = + new List() { typeof(PassengerStop), typeof(SimplePassengerStop), typeof(TeamTrack), typeof(RepairTrack) - ]; + }; public static Load CrewHoursLoad() { @@ -116,7 +118,7 @@ internal class OpsController_AnnounceCoalescedPayments_Patch //Log.Information($"{nameof(OpsController_AnnounceCoalescedPayments_Patch)} => Caboose Helper => PassengerStops => {string.Join(",", passengerStops)}"); var cabeese = passengerStops - .SelectMany(t => t.TrackSpans?.Select(s => (tc.CarsOnSpan(s) ?? []).Where(c => c.IsCaboose()))?.SelectMany(c => c?.Select(c2 => (t, c2)))); + .SelectMany(t => t.TrackSpans?.Select(s => (tc.CarsOnSpan(s) ?? Enumerable.Empty()).Where(c => c.IsCaboose()))?.SelectMany(c => c?.Select(c2 => (t, c2)))); //Log.Information($"{nameof(OpsController_AnnounceCoalescedPayments_Patch)} => Caboose Helper => PassengerStops Cabeese => {string.Join(",", cabeese?.Select(c => $"{c.t} : {c.c2}") ?? [])}"); CrewCarDict = CrewCarDict.Where(kvp => cabeese.Select(c => c.c2.id).Contains(kvp.Key)).ToDictionary(k => k.Key, v => v.Value); diff --git a/TweaksAndThings/Patches/TagController_UpdateTag_Patch.cs b/TweaksAndThings/Patches/TagController_UpdateTag_Patch.cs index 5fda423..9e9ca89 100644 --- a/TweaksAndThings/Patches/TagController_UpdateTag_Patch.cs +++ b/TweaksAndThings/Patches/TagController_UpdateTag_Patch.cs @@ -1,6 +1,6 @@ using HarmonyLib; using Model; -using Model.OpsNew; +using Model.Ops; using Railloader; using RMROC451.TweaksAndThings.Extensions; using System.Collections.Generic; @@ -34,7 +34,7 @@ internal class TagController_UpdateTag_Patch private static void ProceedWithPostFix(Car car, TagCallout tagCallout) { tagCallout.callout.Title = string.Format(tagTitleFormat, "{0}", car.DisplayName); - List tags = []; + List tags = new(); if (OpsController_AnnounceCoalescedPayments_Patch.CrewCarStatus(car).spotted) tags.Add("+"); if (car.HasHotbox) tags.Add(TextSprites.Hotbox); diff --git a/TweaksAndThings/Patches/WedgeImage_OnPopulateMesh.cs b/TweaksAndThings/Patches/WedgeImage_OnPopulateMesh.cs new file mode 100644 index 0000000..c9904c3 --- /dev/null +++ b/TweaksAndThings/Patches/WedgeImage_OnPopulateMesh.cs @@ -0,0 +1,20 @@ +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. + } +}