/// <summary> /// Attach a preexisting GameNode to this GameNode. /// </summary> /// <param name="node">GameNode to attach.</param> public void attachChildNode(GameNode node) { // Form the parent-child relationship node._parent = this; _children.Add(node.Name, node); // Tell current children about the new child NodeEventArgs e = new NodeEventArgs(this, node); if (ChildAttached != null) { ChildAttached(e); } // Tell the new child about future children node.subscribe(this); }
/// <summary> /// Verify that this GameNode's parent tile is the tile directly underneath it. /// This functionality is essential for corrent draw order of objects. /// </summary> private void checkForNewParentTile() { // Node must already have a parent if (_parent == null) { return; } GameNode newParent = _gameLevelMgr.tileAtIsoCoords(_positionIsometric).Node; // If no node was found, we can't do anything if (newParent == null) { return; } // If we do have a parent, make sure we didn't grab the same one if (_parent == newParent) { return; } // We have a new parent, make the switch _parent.Entity.Color = Color.White; _parent.detachChildNode(_name); newParent.attachChildNode(this); _parent.Entity.Color = Color.Gold; // Fire parent changed event NodeEventArgs e = new NodeEventArgs(this); if (ParentChange != null) { ParentChange(e); } }
/// <summary> /// This function is fired whenever one of this node's subscriptions detaches a child node. /// </summary> /// <param name="sender">Node which detached a child</param> /// <param name="child">The child which was attached</param> /// <param name="e">Event args</param> private void parentDetachedChild(NodeEventArgs e) { Console.WriteLine(_name + " (received event: Parent Detached Child) Sender: " + e.Sender.Name + " Child: " + e.Child.Name); }
/// <summary> /// Verify that this GameNode's parent tile is the tile directly underneath it. /// This functionality is essential for corrent draw order of objects. /// </summary> private void checkForNewParentTile() { // Node must already have a parent if (_parent == null) return; GameNode newParent = _gameLevelMgr.tileAtIsoCoords(_positionIsometric).Node; // If no node was found, we can't do anything if (newParent == null) return; // If we do have a parent, make sure we didn't grab the same one if (_parent == newParent) return; // We have a new parent, make the switch _parent.Entity.Color = Color.White; _parent.detachChildNode(_name); newParent.attachChildNode(this); _parent.Entity.Color = Color.Gold; // Fire parent changed event NodeEventArgs e = new NodeEventArgs(this); if (ParentChange != null) ParentChange(e); }
/// <summary> /// Detach a specified child node and return it /// </summary> /// <param name="name">Name of the previously created node</param> /// <returns>Newly detached node</returns> public GameNode detachChildNode(String name) { // Grab the child GameNode child = getChildNode(name); if (child == null) return null; // Remove the parent-child relationship _children.Remove(name); child._parent = null; // Stop telling this child about future children child.unsubscribe(this); // Tell all children about the node we just detached NodeEventArgs e = new NodeEventArgs(this, child); if (ChildDetached != null) ChildDetached(e); // Pass the detached node to caller return child; }
/// <summary> /// Attach a preexisting GameNode to this GameNode. /// </summary> /// <param name="node">GameNode to attach.</param> public void attachChildNode(GameNode node) { // Form the parent-child relationship node._parent = this; _children.Add(node.Name, node); // Tell current children about the new child NodeEventArgs e = new NodeEventArgs(this, node); if (ChildAttached != null) ChildAttached(e); // Tell the new child about future children node.subscribe(this); }