private void DisplayNodePanelPart(Type _type, int _typeIndex)
        {
            BaseCreateNodePanelPart newPart = null;

            if (_type == typeof(VisualVariable)) //variable
            {
                newPart = new VisualVariableCreatePanelPart(variablesToShow[_typeIndex]);
            }
            else if (_type == typeof(VisualFunction)) //Function
            {
                newPart = new VisualFunctionCreatePanelPart(functionsToShow[_typeIndex]);
            }
            else //Basic node
            {
                newPart = new VisualNodeCreatePanelPart(nodesToShow[_typeIndex]);
            }
            this.Controls.Add(newPart);
            newPart.Location      = new Point(0, 20 + (this.Controls.Count - 2) * 15);
            newPart.panelPressed += PanelPressed;

            this.Size = new Size(200, (this.Controls.Count - 1) * 15 + 20); //Keep size dynamic
        }
Exemple #2
0
        public void SpawnNode(Point _position, BaseCreateNodePanelPart _panel) //Spawn node
        {
            BaseNodePanel newNodePanel = null;

            var CheckNode     = _panel as VisualNodeCreatePanelPart;
            var CheckVariable = _panel as VisualVariableCreatePanelPart;
            var CheckFunction = _panel as VisualFunctionCreatePanelPart;

            if (CheckNode != null) //Node selected
            {
                VisualNodeCreatePanelPart node = (VisualNodeCreatePanelPart)_panel;
                VisualNode newNode             = (VisualNode)Activator.CreateInstance(node.nodeType);
                newNodePanel            = new BaseNodePanel(newNode);
                newNodePanel.visualNode = newNode;
                newNode.baseNodePanel   = newNodePanel;
                visualFunction.visualNodes.Add(newNode);
            }
            else if (CheckVariable != null) //variable selected
            {
                VisualVariableCreatePanelPart variablePanel = (VisualVariableCreatePanelPart)_panel;
                VisualVariableNodePanel       node          = new VisualVariableNodePanel(new VisualNode(), variablePanel.visualVariable);
                newNodePanel = new VisualVariableNodePanel(variablePanel.visualVariable, variablePanel.visualVariable);
                variablePanel.visualVariable.baseNodePanel = newNodePanel;
            }
            else if (CheckFunction != null)
            {
                VisualFunctionCreatePanelPart functionPanel = (VisualFunctionCreatePanelPart)_panel;
                VisualFunctionNodePanel       node          = new VisualFunctionNodePanel(new VisualNode(), functionPanel.visualFunction);
                newNodePanel = new VisualFunctionNodePanel(functionPanel.visualFunction, functionPanel.visualFunction);
                functionPanel.visualFunction.baseNodePanel = newNodePanel;
            }

            form.MainScriptingPanel.Controls.Add(newNodePanel);
            newNodePanel.Location = _position;

            currentNodesPanels.Add(newNodePanel);
            newNodePanel.myMouseDown += StartMovingNode;
            newNodePanel.myMouseUp   += StopMovingNode;
            newNodePanel.myMouseMove += MainScriptingPanel_MouseMove;

            newNodePanel.pinPressed += PinPressed;

            if (createNodeSearchBar != null)
            {
                createNodeSearchBar.Dispose();
            }

            if (firstSelectedPin != null)
            {
                if (firstSelectedPin.visualPin.pinRole == PinRole.Input) //Selected input
                {
                    foreach (VisualPin p in newNodePanel.visualNode.visualOutputs)
                    {
                        if (p.pinType == firstSelectedPin.visualPin.pinType)
                        {
                            p.otherConnectedPin = firstSelectedPin.visualPin;
                            firstSelectedPin.visualPin.otherConnectedPin = p;
                            firstSelectedPin = null;
                            break;
                        }
                    }
                }
                else //Selected output
                {
                    foreach (VisualPin p in newNodePanel.visualNode.visualInputs)
                    {
                        if (p.pinType == firstSelectedPin.visualPin.pinType)
                        {
                            p.otherConnectedPin = firstSelectedPin.visualPin;
                            firstSelectedPin.visualPin.otherConnectedPin = p;
                            firstSelectedPin = null;
                            break;
                        }
                    }
                }
            }
            form.MainScriptingPanel.Refresh();
        }