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

497 onboarding timdinh #653

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 6 additions & 0 deletions Assets/SEE/Controls/Actions/ActionStateTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ static ActionStateTypes()
Color.blue.Darker(), "Materials/ModernUIPack/Document",
SaveBoardAction.CreateReversibleAction,
parent: MetricBoard);
Mark =
new("Mark", "Mark a node",
Color.gray, "Materials/ModernUIPack/Pencil",
MarkAction.CreateReversibleAction,
parent: MetricBoard);
}


Expand All @@ -192,6 +197,7 @@ static ActionStateTypes()
public readonly static ActionStateType DeleteWidget;
public readonly static ActionStateType LoadBoard;
public readonly static ActionStateType SaveBoard;
public readonly static ActionStateType Mark;

#endregion

Expand Down
164 changes: 164 additions & 0 deletions Assets/SEE/Controls/Actions/MarkAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
using SEE.Utils.History;
using System.Collections.Generic;
using UnityEngine;
using SEE.GO;
using SEE.Utils;
using SEE.Game.Scenemanipulation;
using SEE.Net.Actions;
using SEE.Audio;
using SEE.Game.SceneManipulation;

namespace SEE.Controls.Actions {
public class MarkAction : AbstractPlayerAction
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation is missing.

{
/// <summary>
/// Returns a new instance of <see cref="MarkAction"/>.
/// </summary>
/// <returns>new instance</returns>
public static IReversibleAction CreateReversibleAction()
{
return new MarkAction();
}

/// <summary>
/// Returns the <see cref="ActionStateType"/> of this action.
/// </summary>
/// <returns><see cref="ActionStateTypes.Mark"/></returns>
public override ActionStateType GetActionStateType()
{
return ActionStateTypes.Mark;
}

/// <summary>
/// If the user clicks with the mouse hitting a game object representing a graph node,
/// will be marked. A sphere will appear above the marked node.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing it in front of will be marked.

/// <see cref="IReversibleAction.Update"/>.
/// </summary>
/// <returns>true if completed</returns>
public override bool Update()
{
bool result = false;

// FIXME: Needs adaptation for VR where no mouse is available.
if (Input.GetMouseButtonDown(0)
&& Raycasting.RaycastGraphElement(out RaycastHit raycastHit, out GraphElementRef _) == HitGraphElement.Node)
{
// the hit object is the parent in which to create the sphere
GameObject parent = raycastHit.collider.gameObject;
Vector3 position = parent.transform.position;
Vector3 scale = parent.transform.lossyScale;
// create or delete the sphere
addedSphere = GameNodeMarker.CreateOrDeleteSphere(parent, scale);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why passing scale as a parameter? Position and scale can be retrieved by GameNodeMarker.CreateOrDeleteSphere.

memento = new Memento(parent, position: position, scale: scale);
memento.NodeID = addedSphere.name;
new MarkNetAction(memento.Parent, memento.Position, memento.Scale).Execute();
result = true;
CurrentState = IReversibleAction.Progress.Completed;
AudioManagerImpl.EnqueueSoundEffect(IAudioManager.SoundEffect.NewNodeSound, parent);
}
return result;
}

/// <summary>
/// The node that was added when this action was executed. It is saved so
/// that it can be removed on Undo().
/// </summary>
private GameObject addedSphere;

/// <summary>
/// Memento capturing the data necessary to re-do this action.
/// </summary>
private Memento memento;

/// <summary>
/// The information we need to re-add a node whose addition was undone.
/// </summary>
private struct Memento
{
/// <summary>
/// The parent of the new node.
/// </summary>
public readonly GameObject Parent;

/// <summary>
/// The position of the new node in world space.
/// </summary>
public readonly Vector3 Position;

/// <summary>
/// The scale of the new node in world space.
/// </summary>
public readonly Vector3 Scale;

/// <summary>
/// The node ID for the added node. It must be kept to re-use the
/// original name of the node in Redo().
/// </summary>
public string NodeID;

/// <summary>
/// Constructor setting the information necessary to re-do this action.
/// </summary>
/// <param name="markedNode">The marked node</param>
public Memento(GameObject parent, Vector3 position, Vector3 scale)
{
Parent = parent;
Position = position;
Scale = scale;
NodeID = null;
}
}

/// <summary>
/// Returns all IDs of gameObjects manipulated by this action.
/// </summary>
/// <returns>all IDs of gameObjects manipulated by this action</returns>
public override HashSet<string> GetChangedObjects()
{
return new HashSet<string>
{
memento.Parent.name,
memento.NodeID
};
}

/// <summary>
/// Returns a new instance of <see cref="MarkAction"/>.
/// </summary>
/// <returns>new instance</returns>
public override IReversibleAction NewInstance()
{
return CreateReversibleAction();
}

/// <summary>
/// Undoes this MarkAction.
/// </summary>
public override void Undo()
{
base.Undo();
if (addedSphere != null)
{
new DeleteNetAction(addedSphere.name).Execute();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not work because your sphere is neither a node nor an edge and hence will not be added to GraphElementIDMap.

Destroyer.Destroy(addedSphere);
addedSphere = null;
}
}

/// <summary>
/// Redoes this MarkAction.
/// </summary>
public override void Redo()
{
base.Redo();
addedSphere = GameNodeAdder.AddChild(memento.Parent, worldSpacePosition: memento.Position, worldSpaceScale: memento.Scale, nodeID: memento.NodeID);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong. You must use GameNodeMarker.CreateOrDeleteSphere.

if (addedSphere != null)
{
new MarkNetAction(memento.Parent, memento.Position, memento.Scale).Execute();
}
}
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this blank line?

}


11 changes: 11 additions & 0 deletions Assets/SEE/Controls/Actions/MarkAction.cs.meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e3343ced081912e4ea17588e0f757233
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
54 changes: 54 additions & 0 deletions Assets/SEE/Game/SceneManipulation/GameNodeMarker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using SEE.Game.City;
using SEE.GO;
using SEE.Utils;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace SEE.Game.Scenemanipulation
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scenemanipulation must be SceneManipulation. Note that C# is case-sensitive.

{
/// <summary>
/// Creates or deletes sphere to mark certain nodes.
/// </summary>
public static class GameNodeMarker
{
/// <summary>
/// Creates a sphere above the selected node or deletes if a sphere exist.
/// </summary>
/// <param name="parent">selected node</param>
/// <param name="scale">scale of the node</param>
/// <returns></returns>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return is undocumented.

public static GameObject CreateOrDeleteSphere(GameObject parent, Vector3 scale)
{
GameObject sphere = null;
//Search for sphere
foreach(Transform child in parent.transform)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could replace the loop by parent.transform.Find("Sphere").

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blank after foreach.

{
if(child.name == "Sphere")
{
sphere = child.gameObject;
break;
}
}
//Delete sphere if one existed
if(sphere != null)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blank after if.

{
Destroyer.Destroy(sphere);
return null;
}
//Create and scale sphere
else
{
sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
sphere.transform.position = GameObjectExtensions.GetTop(parent);
sphere.transform.localScale = scale;
sphere.transform.SetParent(parent.transform);
sphere.SetColor(parent.GetColor().Darker());

return sphere;
}
}
}
}

11 changes: 11 additions & 0 deletions Assets/SEE/Game/SceneManipulation/GameNodeMarker.cs.meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cf226ed20a94fa348ba99cc4ec89cd26
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
71 changes: 71 additions & 0 deletions Assets/SEE/Net/Actions/MarkNetAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using SEE.Game.Scenemanipulation;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;


namespace SEE.Net.Actions
{
/// <summary>
/// This class is responsible for marking a node via network from one client to all others and
/// to the server.
/// </summary>
public class MarkNetAction : AbstractNetAction
{
// Note: All attributes are made public so that they will be serialized
// for the network transfer.

/// <summary>
/// The Parent gameObject.
/// </summary>
public GameObject Parent;

/// <summary>
/// The position of the node.
/// </summary>
public Vector3 Position;

/// <summary>
/// The scale of the node.
/// </summary>
public Vector3 Scale;

/// <summary>
/// Constructor.
/// </summary>
/// <param name="parent">parent in which to mark the new node</param>
/// <param name="position">the position for the parent node</param>
/// <param name="scale">the scale of the parent node in world space</param>
public MarkNetAction
(GameObject parent,
Vector3 position,
Vector3 scale)
: base()
{
this.Parent = parent;
this.Position = position;
this.Scale = scale;
}

/// <summary>
/// Marks a new GameObject on each client.
/// </summary>
protected override void ExecuteOnClient()
{
if (!IsRequester())
{
GameObject markSphere = GameNodeMarker.CreateOrDeleteSphere(Parent, Scale);
}
}

/// <summary>
/// Things to execute on the server (none for this class). Necessary because it is abstract
/// in the superclass.
/// </summary>
protected override void ExecuteOnServer()
{
// Intentionally left blank.
}
}
}

11 changes: 11 additions & 0 deletions Assets/SEE/Net/Actions/MarkNetAction.cs.meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 80bd75152c10e0342b05382bcda6b095
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Loading