public CathodeEditorGUI_AddNode(CathodeFlowgraph _flow, List <CathodeFlowgraph> _flows)
        {
            flow              = _flow;
            availableFlows    = _flows.OrderBy(o => o.name).ToList();
            availableEntities = CathodeEntityDatabase.GetEntities();
            InitializeComponent();

            //quick hack to reload dropdown
            createDatatypeEntity.Checked = true;
            createFunctionEntity.Checked = true;
        }
        private void AutoSelectDataType()
        {
            param_datatype.Enabled = true;
            switch (node.variant)
            {
            case EntityVariant.FUNCTION:
                if (!loadedParamsFromDB)
                {
                    return;
                }
                CathodeEntityDatabase.ParameterDefinition def = CathodeEntityDatabase.GetParameterFromEntity(((FunctionEntity)node).function, param_name.Text);
                if (def.name == null)
                {
                    return;
                }
                if (def.usage == CathodeEntityDatabase.ParameterUsage.TARGET)
                {
                    //"TARGET" usage type does not have a datatype since it is not data, it's an event trigger.
                    //The FLOAT datatype is a placeholder for this.
                    param_datatype.Text = "FLOAT";
                }
                else
                {
                    CathodeParameter param = CathodeEntityDatabase.ParameterDefinitionToParameter(def);
                    if (param == null)
                    {
                        return;
                    }
                    param_datatype.Text = param.dataType.ToString();
                }
                param_datatype.Enabled = false;
                break;

            default:
                return;
            }
        }
        private void createEntity(object sender, EventArgs e)
        {
            cGUID thisID = Utilities.GenerateGUID(DateTime.Now.ToString("G"));

            if (createDatatypeEntity.Checked)
            {
                //Make the DatatypeEntity
                DatatypeEntity newEntity = new DatatypeEntity(thisID);
                newEntity.type      = (CathodeDataType)entityVariant.SelectedIndex;
                newEntity.parameter = Utilities.GenerateGUID(textBox1.Text);

                //Make the parameter to give this DatatypeEntity a value (the only time you WOULDN'T want this is if the val is coming from a linked entity)
                CathodeParameter thisParam = null;
                switch (newEntity.type)
                {
                case CathodeDataType.POSITION:
                    thisParam = new CathodeTransform();
                    break;

                case CathodeDataType.FLOAT:
                    thisParam = new CathodeFloat();
                    break;

                case CathodeDataType.FILEPATH:
                case CathodeDataType.STRING:
                    thisParam = new CathodeString();
                    break;

                case CathodeDataType.SPLINE_DATA:
                    thisParam = new CathodeSpline();
                    break;

                case CathodeDataType.ENUM:
                    thisParam = new CathodeEnum();
                    ((CathodeEnum)thisParam).enumID = new cGUID("4C-B9-82-48");     //ALERTNESS_STATE is the first alphabetically
                    break;

                case CathodeDataType.SHORT_GUID:
                    thisParam = new CathodeResource();
                    ((CathodeResource)thisParam).resourceID = new cGUID("00-00-00-00");
                    break;

                case CathodeDataType.BOOL:
                    thisParam = new CathodeBool();
                    break;

                case CathodeDataType.DIRECTION:
                    thisParam = new CathodeVector3();
                    break;

                case CathodeDataType.INTEGER:
                    thisParam = new CathodeInteger();
                    break;
                }
                newEntity.parameters.Add(new CathodeLoadedParameter(newEntity.parameter, thisParam));

                //Add to flowgraph & save name
                flow.datatypes.Add(newEntity);
                if (NodeDB.GetCathodeName(newEntity.parameter) == newEntity.parameter.ToString())
                {
                    NodeDBEx.AddNewParameterName(newEntity.parameter, textBox1.Text);
                }
                NewEntity = newEntity;
            }
            else if (createFunctionEntity.Checked)
            {
                //Create FunctionEntity
                FunctionEntity newEntity = new FunctionEntity(thisID);
                switch (entityVariant.Text)
                {
                //TODO: find a nicer way of auto selecting this (E.G. can we reflect to class names?)
                case "CAGEAnimation":
                    newEntity = new CAGEAnimation(thisID);
                    break;

                case "TriggerSequence":
                    newEntity = new TriggerSequence(thisID);
                    break;
                }
                newEntity.function = CathodeEntityDatabase.GetEntityAtIndex(entityVariant.SelectedIndex).guid;
                //TODO: auto populate params here

                //Add to flowgraph & save name
                flow.functions.Add(newEntity);
                NodeDBEx.AddNewNodeName(thisID, textBox1.Text);
                NewEntity = newEntity;
            }
            else if (createFlowgraphEntity.Checked)
            {
                //Create FunctionEntity
                FunctionEntity   newEntity         = new FunctionEntity(thisID);
                CathodeFlowgraph selectedFlowgraph = availableFlows.FirstOrDefault(o => o.name == entityVariant.Text);
                if (selectedFlowgraph == null)
                {
                    MessageBox.Show("Failed to look up flowgraph!\nPlease report this issue on GitHub.\n\n" + entityVariant.Text, "Could not find flowgraph!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                newEntity.function = selectedFlowgraph.nodeID;

                //Add to flowgraph & save name
                flow.functions.Add(newEntity);
                NodeDBEx.AddNewNodeName(thisID, textBox1.Text);
                NewEntity = newEntity;
            }

            this.Close();
        }
Пример #4
0
        /* Utility: generate a list of suggested parameters for an entity */
        public static List <string> GenerateParameterList(CathodeEntity entity, out bool didGenerateFromDB)
        {
            didGenerateFromDB = false;
            List <string> items = new List <string>();

            if (CurrentInstance.commandsPAK == null)
            {
                return(items);
            }
            switch (entity.variant)
            {
            case EntityVariant.FUNCTION:
                cGUID function = ((FunctionEntity)entity).function;
                List <CathodeEntityDatabase.ParameterDefinition> parameters = CathodeEntityDatabase.GetParametersFromEntity(function);
                if (parameters != null)
                {
                    didGenerateFromDB = true;
                    for (int i = 0; i < parameters.Count; i++)
                    {
                        items.Add(parameters[i].name);
                    }
                }
                else
                {
                    string[] options = NodeDB.GetEntityParameterList(NodeDBEx.GetParameterName(function));
                    items.Add("trigger"); items.Add("reference");     //TODO: populate all params from EntityMethodInterface?
                    if (options == null)
                    {
                        CathodeFlowgraph flow = CurrentInstance.commandsPAK.GetFlowgraph(function);
                        if (flow == null)
                        {
                            break;
                        }
                        for (int i = 0; i < flow.datatypes.Count; i++)
                        {
                            string to_add = NodeDBEx.GetParameterName(flow.datatypes[i].parameter);
                            //TODO: also return datatype here
                            if (!items.Contains(to_add))
                            {
                                items.Add(to_add);
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < options.Length; i++)
                        {
                            if (!items.Contains(options[i]))
                            {
                                items.Add(options[i]);
                            }
                        }
                    }
                }
                break;

            case EntityVariant.DATATYPE:
                items.Add(NodeDBEx.GetParameterName(((DatatypeEntity)entity).parameter));
                break;
                //TODO: support other types here
            }
            items.Sort();
            return(items);
        }