Skip to content
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

Allow Overwriting Map Note Marker Model #2721

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
78 changes: 69 additions & 9 deletions Assets/Scripts/Game/Automap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ public enum AutomapFocusObject
int idOfUserMarkerNoteToBeChanged; // used to identify id of last double-clicked user note marker when changing note text
DaggerfallInputMessageBox messageboxUserNote;
GameObject gameObjectUserNoteMarkers = null; // container object for custom user notes markers
GameObject customGameObjectUserNoteMarker = null;


/// <summary>
Expand Down Expand Up @@ -368,6 +369,18 @@ public static bool IsCreatingDungeonAutomapBaseGameObjects
get { return isCreatingDungeonAutomapBaseGameObjects; }
}

/// <summary>
/// Used to overwrite the gameObjectUserNoteMarker to a custom prefab.
/// Only overwrites if not null.
/// Default: null.
/// Note: The Prefab must contain at least 1 collider for it to be edited/removed.
/// </summary>
public GameObject CustomGameObjectUserNoteMarker
{
set { customGameObjectUserNoteMarker = value; }
get { return customGameObjectUserNoteMarker; }
}

#endregion

#region Public Methods
Expand Down Expand Up @@ -811,11 +824,16 @@ public bool TryToRemoveUserNoteMarkerOnDungeonSegmentAtScreenPosition(Vector2 sc
if (nearestHit.HasValue)
{
if (nearestHit.Value.transform.name.StartsWith(NameGameobjectUserNoteMarkerSubStringStart)) // if user note marker was hit
{
{
int id = System.Convert.ToInt32(nearestHit.Value.transform.name.Replace(NameGameobjectUserNoteMarkerSubStringStart, ""));
if (listUserNoteMarkers.ContainsKey(id))
listUserNoteMarkers.Remove(id); // remove it from list
GameObject.Destroy(nearestHit.Value.transform.gameObject); // and destroy gameobject

if (customGameObjectUserNoteMarker == null){
GameObject.Destroy(nearestHit.Value.transform.gameObject); // and destroy gameobject
} else {
GameObject.Destroy(GetHighestAncestorBelowAncestor(nearestHit.Value.transform.gameObject, NameGameobjectUserMarkerNotes));
}
return true;
}
}
Expand Down Expand Up @@ -1574,15 +1592,24 @@ private GameObject CreateUserMarker(int id, Vector3 spawningPosition)
gameObjectUserNoteMarkers.transform.SetParent(gameobjectAutomap.transform);
gameObjectUserNoteMarkers.layer = layerAutomap;
}
GameObject gameObjectUserNoteMarker = CreateDiamondShapePrimitive();

GameObject gameObjectUserNoteMarker;
if (customGameObjectUserNoteMarker == null){
gameObjectUserNoteMarker = CreateDiamondShapePrimitive();
gameObjectUserNoteMarker.name = NameGameobjectUserNoteMarkerSubStringStart + id;
gameObjectUserNoteMarker.layer = layerAutomap;
Material materialUserNoteMarker = new Material(Shader.Find("Standard"));
materialUserNoteMarker.color = new Color(1.0f, 0.55f, 0.0f);
gameObjectUserNoteMarker.GetComponent<MeshRenderer>().material = materialUserNoteMarker;
gameObjectUserNoteMarker.transform.localScale = new Vector3(0.6f, 0.6f, 0.6f);
}else{
gameObjectUserNoteMarker = Instantiate(customGameObjectUserNoteMarker);
SetLayerRecursively(gameObjectUserNoteMarker, layerAutomap);
SetNameRecursively(gameObjectUserNoteMarker, NameGameobjectUserNoteMarkerSubStringStart + id);
}

gameObjectUserNoteMarker.transform.SetParent(gameObjectUserNoteMarkers.transform);
gameObjectUserNoteMarker.transform.position = spawningPosition;
gameObjectUserNoteMarker.name = NameGameobjectUserNoteMarkerSubStringStart + id;
Material materialUserNoteMarker = new Material(Shader.Find("Standard"));
materialUserNoteMarker.color = new Color(1.0f, 0.55f, 0.0f);
gameObjectUserNoteMarker.GetComponent<MeshRenderer>().material = materialUserNoteMarker;
gameObjectUserNoteMarker.layer = layerAutomap;
gameObjectUserNoteMarker.transform.localScale = new Vector3(0.6f, 0.6f, 0.6f);
return gameObjectUserNoteMarker;
}

Expand Down Expand Up @@ -1716,6 +1743,39 @@ private static void SetLayerRecursively(GameObject obj, int layer)
}
}

/// <summary>
/// sets name of a GameObject and all of its childs recursively
/// </summary>
/// <param name="obj"> the target GameObject </param>
/// <param name="name"> the name to be set </param>
private static void SetNameRecursively(GameObject obj, string name)
{
obj.name = name;

foreach (Transform child in obj.transform)
{
SetNameRecursively(child.gameObject, name);
}
}

/// <summary>
/// Gets the highest ancestor which is below a specified ancestor.
/// Returns null if specified ancestor cannot be found.
/// </summary>
/// <param name="child"> the child from which the search begins </param>
/// <param name="name"> the name of the ancestor </param>
private static GameObject GetHighestAncestorBelowAncestor(GameObject child, string name){
if (child.transform.parent == null){
return null;
}

if (child.transform.parent.name == name){
return child.transform.gameObject;
}

return GetHighestAncestorBelowAncestor(child.transform.parent.gameObject, name);
}

/// <summary>
/// updates the micro map texture
/// </summary>
Expand Down