Skip to content

Commit

Permalink
Allow NodeOperator even with NodeRef.value == null
Browse files Browse the repository at this point in the history
This may be the case on artificial nodes,
such as the artificial roots on
reflexion cities.
  • Loading branch information
falko17 committed Oct 5, 2023
1 parent c455922 commit 813e2bb
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 14 deletions.
9 changes: 6 additions & 3 deletions Assets/SEE/Controls/Actions/ShowLabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,12 @@ private void On()
/// <seealso cref="SelectionOn"/>
private void Off()
{
LabelAttributes settings = GetLabelSettings(nodeOperator.Node, nodeOperator.City);
nodeOperator.FadeLabel(0f, settings.AnimationFactor);
DisplayedLabelOperators.Remove(nodeOperator);
if (nodeOperator.Node != null)
{
LabelAttributes settings = GetLabelSettings(nodeOperator.Node, nodeOperator.City);
nodeOperator.FadeLabel(0f, settings.AnimationFactor);
DisplayedLabelOperators.Remove(nodeOperator);
}
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions Assets/SEE/Game/HolisticMetrics/WidgetsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ internal void Create(WidgetConfig widgetConfiguration)
{
ShowNotification.Error("Metric-board error",
"There was an error when displaying the metric on the newly created "
+ $"widget, this is the exception: {exception.Message}");
throw exception;
+ $"widget, this is the exception: {exception.Message}", log: false);
throw;
}
}
}
Expand Down
16 changes: 13 additions & 3 deletions Assets/SEE/Game/LabelAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ namespace SEE.Game
[HideReferenceObjectPicker]
public class LabelAttributes
{
/// <summary>
/// The default value for <see cref="Show"/>.
/// </summary>
public const float DEFAULT_FONT_SIZE = 0.4f;

/// <summary>
/// The default value for <see cref="Distance"/>.
/// </summary>
public const float DEFAULT_DISTANCE = 0.2f;

/// <summary>
/// If true, a label with the node's SourceName will be displayed above each node.
/// </summary>
Expand All @@ -24,13 +34,13 @@ public class LabelAttributes
/// The distance between the top of the node and its label.
/// </summary>
[Tooltip("The distance between the top of the node and its label.")]
public float Distance = 0.2f;
public float Distance = DEFAULT_DISTANCE;

/// <summary>
/// The font size of the node's label.
/// </summary>
[Tooltip("The font size of the label.")]
public float FontSize = 0.4f;
public float FontSize = DEFAULT_FONT_SIZE;

/// <summary>
/// How fast the label should (dis)appear.
Expand Down Expand Up @@ -90,4 +100,4 @@ internal void Restore(Dictionary<string, object> attributes, string label)
}
}
}
}
}
9 changes: 5 additions & 4 deletions Assets/SEE/Game/Operator/LabelOperator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private void PrepareLabel()
Color textColor = UnityEngine.Color.white;
Color lineColor = UnityEngine.Color.white;

string shownText = Node.SourceName;
string shownText = Node?.SourceName ?? gameObject.name;

nodeLabel = transform.Find(labelPrefix + shownText)?.gameObject;
if (nodeLabel == null)
Expand All @@ -71,9 +71,10 @@ private void PrepareLabel()
// First we create the label.
// We define starting and ending positions for the animation.
Vector3 startLabelPosition = gameObject.GetTop();
float fontSize = Node != null ? City.NodeTypes[Node.Type].LabelSettings.FontSize : LabelAttributes.DEFAULT_FONT_SIZE;
nodeLabel = TextFactory.GetTextWithSize(shownText,
startLabelPosition,
City.NodeTypes[Node.Type].LabelSettings.FontSize,
fontSize,
lift: true,
textColor: textColor);
nodeLabel.name = labelPrefix + shownText;
Expand Down Expand Up @@ -132,7 +133,7 @@ private Vector3 DesiredLabelTextPosition
if (labelAlpha.TargetValue > 0)
{
// Only put line and label up if the label should actually be shown.
endLabelPosition.y += City.NodeTypes[Node.Type].LabelSettings.Distance;
endLabelPosition.y += Node != null ? City.NodeTypes[Node.Type].LabelSettings.Distance : LabelAttributes.DEFAULT_DISTANCE;
}

return endLabelPosition;
Expand Down Expand Up @@ -185,4 +186,4 @@ private Vector3 DesiredLabelEndLinePosition
nodeLabel.transform.DOMove(position, duration).Play()
};
}
}
}
7 changes: 5 additions & 2 deletions Assets/SEE/Game/Operator/NodeOperator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public partial class NodeOperator : GraphElementOperator<Color>

/// <summary>
/// The node to which this node operator belongs.
///
/// <em>Be aware that this may be null if the node operator is attached to an artificial node.</em>
/// </summary>
public Node Node
{
Expand Down Expand Up @@ -461,7 +463,8 @@ Tween[] BlinkAction(int count, float duration)

static Node GetNode(GameObject gameObject)
{
if (!gameObject.TryGetComponent(out NodeRef nodeRef) || nodeRef.Value == null)
// We allow a null value for artificial nodes, but at least a NodeRef must be attached.
if (!gameObject.TryGetComponent(out NodeRef nodeRef))
{
throw new InvalidOperationException($"NodeOperator-operated object {gameObject.FullName()} must have {nameof(NodeRef)} attached!");
}
Expand Down Expand Up @@ -525,4 +528,4 @@ private void Update()
}
}
}
}
}

0 comments on commit 813e2bb

Please sign in to comment.