-
-
Notifications
You must be signed in to change notification settings - Fork 9
Add support for custom world map nodes #114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0731181
added custom world map nodes
Stedee8722 ff15f75
simplified delegate.combine
Stedee8722 08362a2
forgot to set layerToPutMarker
Stedee8722 f3b9138
changed show conditions logic
Stedee8722 fc52e35
removed redundant show conditions
Stedee8722 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| using Lamb.UI; | ||
| using UnityEngine; | ||
|
|
||
| namespace COTL_API.CustomWorldMapNode; | ||
| public abstract class CustomWorldMapNode | ||
| { | ||
| internal string ModPrefix = ""; | ||
| internal WorldMapIcon.WorldMapRegion MapRegion { get; set; } | ||
|
|
||
| public abstract string InternalName { get; } | ||
| public virtual FollowerLocation Location => FollowerLocation.None; | ||
| public virtual string? SceneToLoad => "Base Biome 1"; // unused if change OnLocationSelected | ||
|
|
||
| public virtual string LayerLocation => "Base"; | ||
| public virtual Vector3 Position => new(0, 0, 0); | ||
| public virtual Vector2 ParallaxPosition => new(0, 0); | ||
|
|
||
| public virtual Action<WorldMapIcon>? OnLocationSelected => null; // use default if null | ||
| public virtual Func<bool>? ShowConditions => null; // use default if null | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| using COTL_API.Guid; | ||
| using HarmonyLib; | ||
| using Lamb.UI; | ||
| using System.Reflection; | ||
|
|
||
| namespace COTL_API.CustomWorldMapNode; | ||
| [HarmonyPatch] | ||
| public partial class CustomWorldMapNodeManager | ||
| { | ||
| internal static Dictionary<WorldMapIcon.WorldMapRegion, CustomWorldMapNode> CustomWorldMapNodes { get; } = []; | ||
| public static WorldMapIcon.WorldMapRegion Add(CustomWorldMapNode node) | ||
| { | ||
| var guid = TypeManager.GetModIdFromCallstack(Assembly.GetCallingAssembly()); | ||
|
|
||
| var mapRegion = GuidManager.GetEnumValue<WorldMapIcon.WorldMapRegion>(guid, node.InternalName); | ||
| node.MapRegion = mapRegion; | ||
| node.ModPrefix = guid; | ||
|
|
||
| CustomWorldMapNodes.Add(node.MapRegion, node); | ||
|
|
||
| return mapRegion; | ||
| } | ||
| } |
114 changes: 114 additions & 0 deletions
114
COTL_API/CustomWorldMapNode/CustomWorldMapNodePatches.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| using HarmonyLib; | ||
| using Lamb.UI; | ||
| using UnityEngine; | ||
| using Object = UnityEngine.Object; | ||
|
|
||
| namespace COTL_API.CustomWorldMapNode; | ||
| [HarmonyPatch] | ||
| public partial class CustomWorldMapNodeManager | ||
| { | ||
| private static GameObject? NodeTemplate; | ||
| private static readonly Dictionary<WorldMapIcon.WorldMapRegion, GameObject> CustomWorldMapNodeList = []; | ||
|
|
||
| [HarmonyPatch(typeof(UIWorldMapMenuController), nameof(UIWorldMapMenuController.Start))] | ||
| [HarmonyPostfix] | ||
| public static void UIWorldMapMenuController_Start(UIWorldMapMenuController __instance) | ||
| { | ||
| var mapContainerTransform = __instance._mapContainer.transform; | ||
| NodeTemplate = mapContainerTransform.Find("Locations/Base").gameObject; | ||
| } | ||
|
|
||
| [HarmonyPatch(typeof(UIWorldMapMenuController), nameof(UIWorldMapMenuController.OnShowStarted))] | ||
| [HarmonyPrefix] | ||
| public static void UIWorldMapMenuController_OnShowStarted(UIWorldMapMenuController __instance) | ||
| { | ||
| CustomWorldMapNodeList.Clear(); | ||
| var mapContainerTransform = __instance._mapContainer.transform; | ||
| var locationsTransfrom = mapContainerTransform.Find("Locations"); | ||
| var layersTransform = mapContainerTransform.Find("Layers"); | ||
| if (layersTransform is null) | ||
| { | ||
| Log(BepInEx.Logging.LogLevel.Error, "Can't find Layers"); | ||
| return; | ||
| } | ||
| if (NodeTemplate is null) | ||
| { | ||
| Log(BepInEx.Logging.LogLevel.Error, "Can't find base node."); | ||
| return; | ||
| } | ||
|
|
||
| var isOriginalObjectActive = NodeTemplate.activeSelf; | ||
| NodeTemplate.SetActive(false); | ||
|
|
||
| foreach (var customWorldMapNode in CustomWorldMapNodes.Select(x => x.Value)) | ||
| { | ||
| var newWorldMapNode = Object.Instantiate(NodeTemplate, locationsTransfrom); | ||
| newWorldMapNode.name = customWorldMapNode.InternalName; | ||
|
|
||
| var worldMapIcon = newWorldMapNode.GetComponent<WorldMapIcon>() ?? throw new Exception("WorldMapIcon not found!"); | ||
| worldMapIcon._location = customWorldMapNode.Location; | ||
| worldMapIcon._locationTerm = "NAMES/Places/" + customWorldMapNode.InternalName; | ||
| worldMapIcon._mapRegion = customWorldMapNode.MapRegion; | ||
| worldMapIcon._parallaxPosition = customWorldMapNode.ParallaxPosition; | ||
| var newScene = new InspectorScene | ||
| { | ||
| SceneName = customWorldMapNode.SceneToLoad, | ||
| }; | ||
| worldMapIcon._scene = newScene; | ||
| var layerToPutMarker = layersTransform.Find(customWorldMapNode.LayerLocation); | ||
| if (layerToPutMarker is null) | ||
| { | ||
| layerToPutMarker = layersTransform.Find("Base"); | ||
| Log(BepInEx.Logging.LogLevel.Warning, "Can't find layer to put marker, check the layer name"); | ||
| } | ||
| if (layerToPutMarker is null) throw new Exception("Something gone horribly wrong"); | ||
| worldMapIcon._layer = layerToPutMarker.GetComponent<ParallaxLayer>(); | ||
| var nodeMarker = new GameObject(customWorldMapNode.InternalName + "_Marker"); | ||
| var nodeMarkerTransform = nodeMarker.AddComponent<RectTransform>(); | ||
| nodeMarker.transform.SetParent(layerToPutMarker); | ||
| nodeMarkerTransform.localPosition = customWorldMapNode.Position; | ||
| worldMapIcon._localPoint = nodeMarkerTransform; | ||
| if (customWorldMapNode.OnLocationSelected is null) | ||
| { | ||
| worldMapIcon.OnLocationSelected += new Action<WorldMapIcon>(__instance.OnLocationSelected); | ||
| } | ||
| else | ||
| { | ||
| worldMapIcon.OnLocationSelected = new Action<WorldMapIcon>(worldMapIcon => | ||
| { | ||
| if (__instance.isLoadingAssets) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| if (worldMapIcon.Location != DataManager.Instance.CurrentLocation) | ||
| { | ||
| DataManager.Instance.CurrentLocation = worldMapIcon.Location; | ||
| __instance._canvasGroup.interactable = false; | ||
| __instance.Hide(true); | ||
| SaveAndLoad.Save(); | ||
| if (!DataManager.Instance.VisitedLocations.Contains(worldMapIcon.Location)) | ||
| { | ||
| DataManager.Instance.VisitedLocations.Add(worldMapIcon.Location); | ||
| } | ||
| } | ||
| }); | ||
| worldMapIcon.OnLocationSelected += customWorldMapNode.OnLocationSelected; | ||
| } | ||
| if (customWorldMapNode.ShowConditions is null) | ||
| { | ||
| if (DataManager.Instance.DiscoveredLocations.Contains(worldMapIcon.Location) || __instance._revealLocation == worldMapIcon.Location) | ||
| { | ||
| worldMapIcon.gameObject.SetActive(true); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| if (customWorldMapNode.ShowConditions()) worldMapIcon.gameObject.SetActive(true); | ||
| } | ||
| CustomWorldMapNodeList.Add(customWorldMapNode.MapRegion, newWorldMapNode); | ||
| } | ||
|
|
||
| NodeTemplate.SetActive(true); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| using UnityEngine; | ||
|
|
||
| namespace COTL_API.Debug; | ||
| internal class DebugWorldMapNode : CustomWorldMapNode.CustomWorldMapNode | ||
| { | ||
| public override string InternalName => "Graveyard_Test"; | ||
| public override FollowerLocation Location => FollowerLocation.Graveyard_Location; | ||
| public override string? SceneToLoad => "Graveyard"; | ||
| public override string LayerLocation => "Shore Front"; | ||
| public override Vector2 ParallaxPosition => new(58, 118); | ||
| public override Vector3 Position => new (826f, -840f, 0f); | ||
| public override Func<bool>? ShowConditions => () => true; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.