Skip to content

Commit

Permalink
#717 Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
TimDinh-hub committed Jul 1, 2024
1 parent 28d8f19 commit 4ab52c1
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 80 deletions.
2 changes: 1 addition & 1 deletion Assets/SEE/Controls/Actions/ActionStateTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ static ActionStateTypes()
AcceptDivergenceAction.CreateReversibleAction);

Notes =
new("Notes", "Show Nodes and Edges that have Notes.",
new("Notes", "Hide or highlight notes",
Color.blue, "Materials/ModernUIPack/Document",
NoteAction.CreateReversibleAction);

Expand Down
95 changes: 42 additions & 53 deletions Assets/SEE/Controls/Actions/NoteAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,19 @@

namespace SEE.Controls.Actions
{
/// <summary>
/// Manages actions related to notes, including highlighting and hiding nodes and edges with notes.
/// </summary>
internal class NoteAction : AbstractPlayerAction
{
/// <summary>
/// Instance of the <see cref="NoteManager"/> class.
/// </summary>
private NoteManager noteManager;

private WindowSpace manager;

/// <summary>
/// Window for handling note buttons.
/// </summary>
private NoteButtonWindow noteButtonWindow;

/// <summary>
Expand Down Expand Up @@ -52,22 +59,27 @@ public override ActionStateType GetActionStateType()
return ActionStateTypes.Notes;
}

/// <summary>
/// Initializes the note action, setting up necessary references.
/// </summary>
public override void Start()
{
noteManager = NoteManager.Instance;
//noteButtonWindow = new();
//GameObject.Find("NoteManager").AddComponent<NoteButtonWindow>();

manager = WindowSpaceManager.ManagerInstance[WindowSpaceManager.LocalPlayer];

}

/// <summary>
/// Cleans up when the note action is stopped.
/// </summary>
public override void Stop()
{
base.Stop();
noteButtonWindow.DestroyWindow();
}

/// <summary>
/// Updates the state of the note action, handling user inputs for hiding and highlighting notes.
/// </summary>
/// <returns>True if an action was performed, otherwise false.</returns>
public override bool Update()
{
//Hide all Outlines when 'P' is pressed
Expand Down Expand Up @@ -114,66 +126,43 @@ private void HideAllNotes()
/// It hides them if they have an outline active.
/// It highlights the GameObject if they have a note but no outline active.
/// </summary>
/// <param name="gameObject">gameObject that </param>
/// <param name="gameObject">The game object to toggle the outline for.</param>
private void HideOrHightlight(GameObject gameObject)
{
MeshRenderer meshRenderer = gameObject.GetComponent<MeshRenderer>();

if (gameObject.IsNode())
{
MeshRenderer meshRenderer = gameObject.GetComponent<MeshRenderer>();

string oldMaterialName = meshRenderer.materials[meshRenderer.materials.Length - 1].name;
string newName = oldMaterialName.Replace(" (Instance)", "");
//GameObject has no outline
if (newName != noteMaterial.name)
{
Material[] materialsArray = new Material[meshRenderer.materials.Length + 1];
Array.Copy(meshRenderer.materials, materialsArray, meshRenderer.materials.Length);
materialsArray[meshRenderer.materials.Length] = noteMaterial;
meshRenderer.materials = materialsArray;
}
//GameObject has outline
else
{
Material[] gameObjects = new Material[meshRenderer.materials.Length - 1];
Array.Copy(meshRenderer.materials, gameObjects, meshRenderer.materials.Length - 1);
meshRenderer.materials = gameObjects;
}
ToggleOutline(meshRenderer, noteMaterial);
}
else
{
MeshRenderer meshRenderer = gameObject.GetComponent<MeshRenderer>();

string oldMaterialName = meshRenderer.materials[meshRenderer.materials.Length - 1].name;
string newName = oldMaterialName.Replace(" (Instance)", "");
//GameObject has no outline
if (newName != noteMaterialEdge.name)
{
Material[] materialsArray = new Material[meshRenderer.materials.Length + 1];
Array.Copy(meshRenderer.materials, materialsArray, meshRenderer.materials.Length);
materialsArray[meshRenderer.materials.Length] = noteMaterialEdge;
meshRenderer.materials = materialsArray;
}
//GameObject has outline
else
{
Material[] gameObjects = new Material[meshRenderer.materials.Length - 1];
Array.Copy(meshRenderer.materials, gameObjects, meshRenderer.materials.Length - 1);
meshRenderer.materials = gameObjects;
}
ToggleOutline(meshRenderer, noteMaterialEdge);
}
}

public void RemoveOutline(GameObject gameObject)
/// <summary>
/// Toggles the outline material for the specified mesh renderer.
/// </summary>
/// <param name="meshRenderer">The mesh renderer to toggle the outline for.</param>
/// <param name="outlineMaterial">The outline material to use.</param>
private void ToggleOutline(MeshRenderer meshRenderer, Material outlineMaterial)
{
Material noteMaterial = Resources.Load<Material>("Materials/Outliner_MAT");
MeshRenderer meshRenderer = gameObject.GetComponent<MeshRenderer>();
string oldMaterialName = meshRenderer.materials[meshRenderer.materials.Length - 1].name;
string newName = oldMaterialName.Replace(" (Instance)", "");
if (newName == noteMaterial.name)

if (newName != outlineMaterial.name)
{
Material[] materialsArray = new Material[meshRenderer.materials.Length + 1];
Array.Copy(meshRenderer.materials, materialsArray, meshRenderer.materials.Length);
materialsArray[meshRenderer.materials.Length] = outlineMaterial;
meshRenderer.materials = materialsArray;
}
else
{
Material[] gameObjects = new Material[meshRenderer.materials.Length - 1];
Array.Copy(meshRenderer.materials, gameObjects, meshRenderer.materials.Length - 1);
meshRenderer.materials = gameObjects;
Material[] materialsArray = new Material[meshRenderer.materials.Length - 1];
Array.Copy(meshRenderer.materials, materialsArray, meshRenderer.materials.Length - 1);
meshRenderer.materials = materialsArray;
}
}

Expand Down
40 changes: 38 additions & 2 deletions Assets/SEE/UI/Window/NoteButtonWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@

namespace SEE.UI.Window
{
/// <summary>
/// Manages the note button window, allowing for display and interaction with note-related UI elements.
/// </summary>
public class NoteButtonWindow : MonoBehaviour
{
private static NoteButtonWindow instance;

/// <summary>
/// Gets the singleton instance of the <see cref="NoteButtonWindow"/> class.
/// </summary>
public static NoteButtonWindow Instance
{
get
Expand All @@ -34,12 +40,39 @@ public static NoteButtonWindow Instance
}
}

/// <summary>
/// Path to the prefab for the NoteButtonWindow UI.
/// </summary>
private string windowPrefab = "Prefabs/UI/NoteButtonWindow";

/// <summary>
/// Instance of the instantiated NoteButtonWindow GameObject.
/// </summary>
private GameObject noteButtonWindow;

/// <summary>
/// Text content of the note.
/// </summary>
public string contentText;

/// <summary>
/// Toggle to set the note as public or private.
/// </summary>
public Toggle publicToggle;
public bool flag = false;

/// <summary>
/// Flag indicating whether the NoteButtonWindow is open.
/// </summary>
public bool isOpen = false;

/// <summary>
/// Opens the note button window and assigns actions to the buttons and toggle.
/// </summary>
/// <param name="saveButtonAction">Action to be performed when the save button is clicked.</param>
/// <param name="loadButtonAction">Action to be performed when the load button is clicked.</param>
/// <param name="deleteButtonAction">Action to be performed when the delete button is clicked.</param>
/// <param name="refreshButtonAction">Action to be performed when the refresh button is clicked.</param>
/// <param name="publicToggleAction">Action to be performed when the public/private toggle is changed.</param>
public void OpenWindow(UnityAction saveButtonAction, UnityAction loadButtonAction, UnityAction deleteButtonAction, UnityAction refreshButtonAction,
UnityAction<bool> publicToggleAction)
{
Expand All @@ -60,9 +93,12 @@ public void OpenWindow(UnityAction saveButtonAction, UnityAction loadButtonActio
publicToggle = noteButtonWindow.transform.Find("Content/PublicToggle").gameObject.MustGetComponent<Toggle>();
publicToggle.onValueChanged.AddListener(publicToggleAction);

flag = true;
isOpen = true;
}

/// <summary>
/// Destroys the note button window.
/// </summary>
public void DestroyWindow()
{
Destroyer.Destroy(noteButtonWindow);
Expand Down
29 changes: 15 additions & 14 deletions Assets/SEE/UI/Window/NoteWindow/NoteManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
namespace SEE.UI.Window.NoteWindow
{
/// <summary>
/// This class manages to save and load the notes.
/// Manages notes, including storage, and retrieval.
/// This class also handles the outlining of nodes and edges in the game.
/// </summary>
public class NoteManager : MonoBehaviour
{
Expand Down Expand Up @@ -48,11 +49,11 @@ public static NoteManager Instance
public List<GameObject> objectList = new List<GameObject>();

/// <summary>
/// Finds the GameObject for the <see cref="graphElement"/>.
/// And it marks it with an outliner.
/// Finds the <see cref="GameObject"/> associated with the specified <paramref name="graphElementRef"/>
/// and marks it with an outline.
/// </summary>
/// <param name="GraphID"></param>
private void FindGameObjects(GraphElementRef graphElementRef)
/// <param name="graphElementRef">Reference to the graph element.</param>
private void OutlineGameObject(GraphElementRef graphElementRef)
{
GameObject gameObject = graphElementRef.gameObject;
if (gameObject != null)
Expand All @@ -71,30 +72,30 @@ private void FindGameObjects(GraphElementRef graphElementRef)
}

/// <summary>
/// Saves the note by putting it into <see cref="notesDictionary"/>.
/// Saves a note in the <see cref="notesDictionary"/>.
/// </summary>
/// <param name="graphElementRef">the node/edge to save</param>
/// <param name="isPublic">flag whether it should be saved public or private</param>
/// <param name="content">the content to save</param>
/// <param name="graphElementRef">Reference to the graph element (node/edge).</param>
/// <param name="isPublic">Specifies whether the note is public or private.</param>
/// <param name="content">Content of the note to save.</param>
public void SaveNote(GraphElementRef graphElementRef, bool isPublic, string content)
{
GraphElement graphElement = graphElementRef.Elem;
if (!string.IsNullOrEmpty(graphElement.ID))
{
KeyValuePair<string, bool> keyPair = new KeyValuePair<string, bool>(graphElement.ID, isPublic);
notesDictionary[keyPair] = content;
FindGameObjects(graphElementRef);
OutlineGameObject(graphElementRef);
}
//Debug.Log("graphRef + isPublic + content " + graphElementRef + isPublic +content);
//Debug.Log("notesDictionary.length: " + notesDictionary.Count);
}

/// <summary>
/// Loads the note.
/// Loads a note from the <see cref="notesDictionary"/>.
/// </summary>
/// <param name="title">the node/edge to load</param>
/// <param name="isPublic">flag whether it should load the public or private note</param>
/// <returns>the content for the note</returns>
/// <param name="title">Identifier of the node/edge.</param>
/// <param name="isPublic">Specifies whether to load the public or private note.</param>
/// <returns>Content of the loaded note.</returns>
public string LoadNote(string title, bool isPublic)
{
KeyValuePair<string, bool> keyPair = new KeyValuePair<string, bool>(title, isPublic);
Expand Down
Loading

0 comments on commit 4ab52c1

Please sign in to comment.