Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions COTL_API/CustomWorldMapNode/CustomWorldMapNode.cs
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
}
23 changes: 23 additions & 0 deletions COTL_API/CustomWorldMapNode/CustomWorldMapNodeManager.cs
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 COTL_API/CustomWorldMapNode/CustomWorldMapNodePatches.cs
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)
Comment thread
InfernoDragon0 marked this conversation as resolved.
{
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);
}
}
3 changes: 3 additions & 0 deletions COTL_API/Debug/DebugManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using COTL_API.CustomStructures;
using COTL_API.CustomTarotCard;
using COTL_API.CustomTasks;
using COTL_API.CustomWorldMapNode;
using FoodPlus.CustomTraits;
using I2.Loc;
using Lamb.UI;
Expand Down Expand Up @@ -142,7 +143,7 @@

internal static void ShowPatches(Type a)
{
var harmony = Plugin.Instance._harmony;

Check warning on line 146 in COTL_API/Debug/DebugManager.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Dereference of a possibly null reference.

Check warning on line 146 in COTL_API/Debug/DebugManager.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Dereference of a possibly null reference.
var patchedMethods = harmony.GetPatchedMethods().Where(methodBase => methodBase.DeclaringType == a);

foreach (var method in a.GetMethods())
Expand Down Expand Up @@ -241,6 +242,8 @@

CustomTaskManager.Add(new DebugTask());

CustomWorldMapNodeManager.Add(new DebugWorldMapNode());

var test = CustomObjectiveManager.BedRest("Test");
test.InitialQuestText = "This is my custom quest text for this objective.";

Expand Down
13 changes: 13 additions & 0 deletions COTL_API/Debug/DebugWorldMapNode.cs
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;
}
Loading