Example #1
0
 /// <summary>
 /// Adds the element to the node.
 /// </summary>
 /// <param name="element">The element.</param>
 public void AddElement(ISurfaceNodeElement element)
 {
     Elements.Add(element);
     if (element is Control control)
     {
         AddChild(control);
     }
 }
Example #2
0
 /// <summary>
 /// Removes the element from the node.
 /// </summary>
 /// <param name="element">The element.</param>
 /// <param name="dispose">if set to <c>true</c> dispose control after removing, otherwise false.</param>
 public void RemoveElement(ISurfaceNodeElement element, bool dispose = true)
 {
     if (element == null)
         return;
     if (element is Box box)
         box.RemoveConnections();
     Elements.Remove(element);
     if (element is Control control)
     {
         RemoveChild(control);
         if (dispose)
             control.Dispose();
     }
 }
Example #3
0
 internal void RemoveElement(ISurfaceNodeElement element, bool dispose = true)
 {
     if (element is Box box)
     {
         box.RemoveConnections();
     }
     Elements.Remove(element);
     if (element is Control control)
     {
         RemoveChild(control);
         if (dispose)
         {
             control.Dispose();
         }
     }
 }
Example #4
0
        /// <summary>
        /// Creates an element from the archetype and adds the element to the node.
        /// </summary>
        /// <param name="arch">The element archetype.</param>
        /// <returns>The created element. Null if the archetype is invalid.</returns>
        public ISurfaceNodeElement AddElement(NodeElementArchetype arch)
        {
            ISurfaceNodeElement element = null;

            switch (arch.Type)
            {
            case NodeElementType.Input:
                element = new InputBox(this, arch);
                break;

            case NodeElementType.Output:
                element = new OutputBox(this, arch);
                break;

            case NodeElementType.BoolValue:
                element = new BoolValue(this, arch);
                break;

            case NodeElementType.FloatValue:
                element = new FloatValue(this, arch);
                break;

            case NodeElementType.IntegerValue:
                element = new IntegerValue(this, arch);
                break;

            case NodeElementType.ColorValue:
                element = new ColorValue(this, arch);
                break;

            case NodeElementType.ComboBox:
                element = new ComboBoxElement(this, arch);
                break;

            case NodeElementType.Asset:
                element = new AssetSelect(this, arch);
                break;

            case NodeElementType.Text:
                element = new TextView(this, arch);
                break;

            case NodeElementType.TextBox:
                element = new TextBoxView(this, arch);
                break;

            case NodeElementType.SkeletonNodeSelect:
                element = new SkeletonNodeSelectElement(this, arch);
                break;

            case NodeElementType.BoxValue:
                element = new BoxValue(this, arch);
                break;

            case NodeElementType.EnumValue:
                element = new EnumValue(this, arch);
                break;
            }
            if (element != null)
            {
                AddElement(element);
            }

            return(element);
        }
        /// <summary>
        /// Creates an element from the archetype and adds the element to the node.
        /// </summary>
        /// <param name="arch">The element archetype.</param>
        /// <returns>The created element. Null if the archetype is invalid.</returns>
        public ISurfaceNodeElement AddElement(NodeElementArchetype arch)
        {
            ISurfaceNodeElement element = null;

            switch (arch.Type)
            {
            case NodeElementType.Input:
                element = new InputBox(this, arch);
                break;

            case NodeElementType.Output:
                element = new OutputBox(this, arch);
                break;

            case NodeElementType.BoolValue:
                element = new BoolValue(this, arch);
                break;

            case NodeElementType.FloatValue:
                element = new FloatValue(this, arch);
                break;

            case NodeElementType.IntegerValue:
                element = new IntegerValue(this, arch);
                break;

            case NodeElementType.ColorValue:
                element = new ColorValue(this, arch);
                break;

            case NodeElementType.ComboBox:
                element = new ComboBoxElement(this, arch);
                break;

            case NodeElementType.Asset:
                element = new AssetSelect(this, arch);
                break;

            case NodeElementType.Text:
                element = new TextView(this, arch);
                break;

            case NodeElementType.TextBox:
                element = new TextBoxView(this, arch);
                break;

            case NodeElementType.SkeletonBoneIndexSelect:
                element = new SkeletonBoneIndexSelectElement(this, arch);
                break;

            case NodeElementType.BoxValue:
                element = new BoxValue(this, arch);
                break;

            case NodeElementType.EnumValue:
                element = new EnumValue(this, arch);
                break;

            case NodeElementType.SkeletonNodeNameSelect:
                element = new SkeletonNodeNameSelectElement(this, arch);
                break;
                //default: throw new NotImplementedException("Unknown node element type: " + arch.Type);
            }
            if (element != null)
            {
                AddElement(element);
            }

            return(element);
        }
        /// <summary>
        /// Called when node gets loaded and should be added to the surface. Creates node elements from the archetype.
        /// </summary>
        /// <param name="node">The node.</param>
        public virtual void OnNodeLoaded(SurfaceNode node)
        {
            // Create child elements of the node based on it's archetype
            int elementsCount = node.Archetype.Elements?.Length ?? 0;

            for (int i = 0; i < elementsCount; i++)
            {
                // ReSharper disable once PossibleNullReferenceException
                var arch = node.Archetype.Elements[i];
                ISurfaceNodeElement element = null;
                switch (arch.Type)
                {
                case NodeElementType.Input:
                    element = new InputBox(node, arch);
                    break;

                case NodeElementType.Output:
                    element = new OutputBox(node, arch);
                    break;

                case NodeElementType.BoolValue:
                    element = new BoolValue(node, arch);
                    break;

                case NodeElementType.FloatValue:
                    element = new FloatValue(node, arch);
                    break;

                case NodeElementType.IntegerValue:
                    element = new IntegerValue(node, arch);
                    break;

                case NodeElementType.ColorValue:
                    element = new ColorValue(node, arch);
                    break;

                case NodeElementType.ComboBox:
                    element = new ComboBoxElement(node, arch);
                    break;

                case NodeElementType.Asset:
                    element = new AssetSelect(node, arch);
                    break;

                case NodeElementType.Text:
                    element = new TextView(node, arch);
                    break;

                case NodeElementType.TextBox:
                    element = new TextBoxView(node, arch);
                    break;

                case NodeElementType.SkeletonNodeSelect:
                    element = new SkeletonNodeSelectElement(node, arch);
                    break;
                }
                if (element != null)
                {
                    // Link element
                    node.AddElement(element);
                }
            }

            // Load metadata
            var meta = node.Meta.GetEntry(11);

            if (meta.Data != null)
            {
                var meta11 = Utils.ByteArrayToStructure <VisjectSurface.Meta11>(meta.Data);
                node.Location = meta11.Position;
                //node.IsSelected = meta11.Selected;
            }
        }