public void UpdateToList() { bool hasAnythingChanged = false; #region If there is no list watching, then return if (mListOfAttachables == null) { return; } #endregion #region Add nodes to the dictionary if there are any in the list that aren't in the dictionary for(int i = 0; i < mListOfAttachables.Count; i++) { IAttachable iAttachable = (IAttachable)mListOfAttachables[i]; if (iAttachable == null) { throw new Exception(); } if (!IsNodeCreatedForAttachable(iAttachable)) { HierarchyNode hierarchyNode = new HierarchyNode(VisibleRepresentationType.Sprite); hierarchyNode.TextRed = mTextColor.R; hierarchyNode.TextGreen = mTextColor.G; hierarchyNode.TextBlue = mTextColor.B; if (LayerUsing != null) { hierarchyNode.AddToLayer(LayerUsing); } mNodes.Add(iAttachable, hierarchyNode); hierarchyNode.ObjectRepresenting = iAttachable; mNodesAsList.Add(hierarchyNode); hasAnythingChanged = true; } } #endregion #region Remove nodes if necessary if (mListOfAttachables.Count < this.mNodesAsList.Count) { for (int i = 0; i < mNodesAsList.Count; i++) { HierarchyNode node = mNodesAsList[i]; if (!this.mListOfAttachables.Contains(node.ObjectRepresenting)) { // Remove this node mNodes.Remove(node.ObjectRepresenting); node.Destroy(); hasAnythingChanged = true; } } //There are nodes in the dictionary that have to be removed } #endregion #region Update the element visibility of each node foreach (HierarchyNode node in mNodesAsList) { HierarchyNode parentNode = null; IAttachable nodeParent = GetParent( node.ObjectRepresenting); if ( nodeParent != null) { parentNode = GetNodeFromAttachable(nodeParent); } hasAnythingChanged |= node.UpdateElementVisibility(parentNode); } #endregion if (hasAnythingChanged) { AutoPosition(); } }
private void MouseControlOverObjects(float worldX, float worldY) { Cursor cursor = GuiManager.Cursor; if (cursor.PrimaryPush) { mNodeGrabbed = GetNodeOver(worldX, worldY); } if (cursor.PrimaryClick) { mNodeGrabbed = null; } if (mNodeGrabbed != null) { PositionedObjectMover.MouseMoveObject<HierarchyNode>(mNodeGrabbed); } }
public bool UpdateElementVisibility(HierarchyNode parentNode) { bool didChange = false; if (mCircleVisibleRepresentation != null) { mCircleVisibleRepresentation.Position = this.Position; } else { mSpriteVisibleRepresentation.Position = this.Position; } mText.Position = this.Position; #region Update the attachment visibility bool shouldConnectionBeVisible = parentNode != null; if (shouldConnectionBeVisible != mParentLine.Visible) { mParentLine.Visible = shouldConnectionBeVisible; mParentAttachmentPoint.Visible = mParentLine.Visible; didChange = true; } #endregion #region If visible, update the position of the line itself if (mParentLine.Visible) { Vector3 vectorToParent = this.Position - parentNode.Position; if (vectorToParent.X == 0 && vectorToParent.Y == 0 && vectorToParent.Z == 0) { return didChange; } float radius = 0; if (mCircleVisibleRepresentation != null) { radius = mCircleVisibleRepresentation.Radius; } else { radius = mSpriteVisibleRepresentation.ScaleX; } vectorToParent.Normalize(); Vector3 endPoint1 = this.Position - vectorToParent * radius; Vector3 endPoint2 = parentNode.Position + vectorToParent * radius; if (mParentAttachmentPoint.Position != endPoint2) { didChange = true; } mParentAttachmentPoint.Position = endPoint2; mParentLine.SetFromAbsoluteEndpoints(endPoint1, endPoint2); } #endregion return didChange; }