/// <summary> /// Shows the specified named variable in the DataGridView. /// </summary> /// <param name="variable">The named variable to show.</param> private void ShowVariable(NamedVariable variable) { Debug.Assert(variable != null, "Variable cannot be null."); StringVar nameVar = new StringVar() { Value = variable.Name }; nameVar.ValueChanged += (object sender, EventArgs e) => { if (IsNameValid(nameVar.Value, variable)) { variable.Name = nameVar.Value; } }; DataGridViewRow row = new DataGridViewRow() { Tag = variable }; row.Cells.Add(nameVar.GetGridCell()); row.Cells.Add(variable.Value.GetGridCell()); row.Cells.Add(new DataGridViewTextBoxCell() { Value = VariableTypeHelper.FriendlyName(variable.Value.VariableType) }); row.Cells.Add(new DataGridViewButtonCell() { Value = "X" }); row.Cells.Add(new DataGridViewButtonCell() { Value = ">" }); settingsView.table.Rows.Add(row); }
/// <summary> /// Creates the tree representing all scripting variables. /// </summary> /// <param name="treeNodes">Collection where to store scripting variables.</param> private void CreateTreeOfVariablesNodes(TreeNodeCollection treeNodes) { TreeNode variablesCategory = new TreeNode("Variables") { Tag = null }; foreach (VariableType variableType in Enum.GetValues(typeof(VariableType))) { Variable variableNode = new Variable(null, variableType); if (variableType == VariableType.String) { variableNode.Value.SetValue("string"); } variablesCategory.Nodes.Add(new TreeNode(VariableTypeHelper.FriendlyName(variableType)) { Tag = variableNode }); } treeNodes.Add(variablesCategory); }
/// <inheritdoc /> public void ShowSettings(DataGridViewRowCollection rows) { // title DataGridViewRow row = new DataGridViewRow(); row.Cells.Add(new DataGridViewTitleCell() { LeftColumn = 0, RightColumn = 3, Title = Node.Name }); row.Cells[row.Cells.Count - 1].ReadOnly = true; row.Cells.Add(new DataGridViewTitleCell() { LeftColumn = 0, RightColumn = 3 }); row.Cells[row.Cells.Count - 1].ReadOnly = true; row.Cells.Add(new DataGridViewTitleCell() { LeftColumn = 0, RightColumn = 3 }); row.Cells[row.Cells.Count - 1].ReadOnly = true; row.Cells.Add(new DataGridViewTitleCell() { LeftColumn = 0, RightColumn = 3 }); row.Cells[row.Cells.Count - 1].ReadOnly = true; rows.Add(row); // variable sockets foreach (NodeSocketView nodeSocketView in variableSockets) { nodeSocketView.IEditSettings.ShowSettings(rows); } // comment if (commentVar == null) { commentVar = new StringVar() { Value = Node.Comment }; commentVar.ValueChanged += (object sender, EventArgs e) => { Node.Comment = commentVar.Value; }; } row = new DataGridViewRow(); row.Cells.Add(new DataGridViewDisableCheckBoxCell() { Enabled = false }); row.Cells.Add(new DataGridViewTextBoxCell() { Value = "Comment" }); row.Cells.Add(commentVar.GetGridCell()); row.Cells.Add(new DataGridViewTextBoxCell() { Value = VariableTypeHelper.FriendlyName(commentVar.VariableType) }); rows.Add(row); }
/// <summary> /// Loads all scripting data and stores them sorted at the tree structure. /// </summary> private void CreateRoot() { root = new CategoryData(); bool isAction, isEvent; foreach (Type type in typeof(GameEngine.Scripting.ScriptNode).Assembly.GetTypes()) { isAction = isEvent = false; if (type.IsSubclassOf(typeof(GameEngine.Scripting.Actions.ActionNode))) { isAction = true; } else if (type.IsSubclassOf(typeof(GameEngine.Scripting.Events.EventNode))) { isEvent = true; } // get all subclasses from ActionNode or EventNode if ((isAction || isEvent) && !type.IsAbstract && type.IsPublic) { // script node (event or action) NodeData scriptNode = new NodeData(); scriptNode.Name = GetFriendlyName(type, type.Name); scriptNode.RealName = type.FullName; scriptNode.Description = GetDescription(type); scriptNode.Type = isAction ? NodeType.Action : NodeType.Event; // add script node to the correct category CreateCategory(root, GetCategory(type)).Items.Add(scriptNode); // get all public non-static fields from class foreach (FieldInfo fieldInfo in type.GetFields(BindingFlags.Public | BindingFlags.Instance)) { // variable socket is an array of generic class GameEngine.Variable<T> // or generic variable GameEngine.Variable<T> if ((fieldInfo.FieldType.IsArray && fieldInfo.FieldType.HasElementType && fieldInfo.FieldType.GetElementType().IsGenericType&& fieldInfo.FieldType.GetElementType().GetGenericTypeDefinition() == typeof(GameEngine.Scripting.Variable <>)) || (fieldInfo.FieldType.IsGenericType && fieldInfo.FieldType.GetGenericTypeDefinition() == typeof(GameEngine.Scripting.Variable <>))) { // get argument for GameEngine.Variable<T> Type[] arguments = fieldInfo.FieldType.IsArray ? fieldInfo.FieldType.GetElementType().GetGenericArguments() : fieldInfo.FieldType.GetGenericArguments(); if (arguments != null && arguments.Length == 1) { // try to get VariableSocketTypeAttribute GameEngine.Scripting.VariableSocketAttribute variableSocketAttribute = (GameEngine.Scripting.VariableSocketAttribute)Attribute.GetCustomAttribute(fieldInfo, typeof(GameEngine.Scripting.VariableSocketAttribute)); if (variableSocketAttribute != null) { // variable socket NodeSocketData variableSocket = new NodeSocketData(); variableSocket.Name = GetFriendlyName(fieldInfo, fieldInfo.Name); variableSocket.RealName = fieldInfo.Name; variableSocket.Description = GetDescription(fieldInfo); variableSocket.Type = variableSocketAttribute.Type == GameEngine.Scripting.VariableSocketType.In ? NodeSocketType.VariableIn : NodeSocketType.VariableOut; variableSocket.VariableType = VariableTypeHelper.FromType(arguments[0]); variableSocket.IsArray = fieldInfo.FieldType.IsArray; variableSocket.DefaultValue = GetDefaultValue(fieldInfo); variableSocket.Visible = variableSocketAttribute.Visible; variableSocket.CanBeEmpty = variableSocketAttribute.CanBeEmpty; // variable out socket must be an array if (variableSocket.Type == NodeSocketType.VariableOut && !variableSocket.IsArray) { continue; } scriptNode.Sockets.Add(variableSocket); } } } // signal out socket is ScriptSocketHandler delegate else if (fieldInfo.FieldType.IsSubclassOf(typeof(Delegate)) && fieldInfo.FieldType == typeof(GameEngine.Scripting.ScriptSocketHandler)) { // signal out socket NodeSocketData signalOutSocket = new NodeSocketData(); signalOutSocket.Name = GetFriendlyName(fieldInfo, fieldInfo.Name); signalOutSocket.RealName = fieldInfo.Name; signalOutSocket.Description = GetDescription(fieldInfo); signalOutSocket.Type = NodeSocketType.SignalOut; scriptNode.Sockets.Add(signalOutSocket); } } // get all public non-static method from class foreach (MethodInfo methodInfo in type.GetMethods(BindingFlags.Public | BindingFlags.Instance)) { // signal in socket is method with none parameter, returns void, // is defined in script node (event or action, not base classes) and it is not Update and Connect method (from event) if (methodInfo.GetParameters().Length == 0 && methodInfo.ReturnType == typeof(void) && methodInfo.Name != "Update" && methodInfo.Name != "Connect") { // signal in socket NodeSocketData signalInSocket = new NodeSocketData(); signalInSocket.Name = GetFriendlyName(methodInfo, methodInfo.Name); signalInSocket.RealName = methodInfo.Name; signalInSocket.Description = GetDescription(methodInfo); signalInSocket.Type = NodeSocketType.SignalIn; scriptNode.Sockets.Add(signalInSocket); } } } } SortCategory(root); }
/// <inheritdoc /> public void ShowSettings(DataGridViewRowCollection rows) { row = new DataGridViewRow(); DataGridViewDisableCheckBoxCell visibleCell = new DataGridViewDisableCheckBoxCell() { Value = VariableNodeSocket.Visible, Enabled = VariableNodeSocket.Connections.Count == 0 }; visibleCell.ValueChanged += (object sender, EventArgs e) => { VariableNodeSocket.Visible = (bool)visibleCell.Value; if (!VariableNodeSocket.Visible && VariableNodeSocket.Connections.Count != 0) { VariableNodeSocket.Visible = true; } else { Node.Refresh(); } }; row.Cells.Add(visibleCell); row.Cells.Add(new DataGridViewTextBoxCell() { Value = VariableNodeSocket.Name }); // variable in if (VariableNodeSocket.Type == NodeSocketType.VariableIn) { if (VariableNodeSocket.Connections.Count == 0) { // edit value if (!VariableNodeSocket.NodeSocketData.CanBeEmpty) { row.Cells.Add(VariableNodeSocket.Value.GetGridCell()); } // only connection is possible else { row.Cells.Add(new DataGridViewTextBoxCell() { Value = "(connection-only)" }); row.Cells[row.Cells.Count - 1].ReadOnly = true; } } // socket used else { row.Cells.Add(new DataGridViewTextBoxCell() { Value = "(socket used)" }); row.Cells[row.Cells.Count - 1].ReadOnly = true; } } // variable out else { row.Cells.Add(new DataGridViewTextBoxCell() { Value = "(read-only)" }); row.Cells[row.Cells.Count - 1].ReadOnly = true; } row.Cells.Add(new DataGridViewTextBoxCell() { Value = VariableTypeHelper.FriendlyName(VariableNodeSocket.VariableType) }); rows.Add(row); }
/// <inheritdoc /> public void ShowSettings(DataGridViewRowCollection rows) { // title DataGridViewRow row = new DataGridViewRow(); row.Cells.Add(new DataGridViewTitleCell() { LeftColumn = 0, RightColumn = 3, Title = String.Format("Varible of {0}", VariableTypeHelper.FriendlyName(Variable.VariableType)) }); row.Cells[row.Cells.Count - 1].ReadOnly = true; row.Cells.Add(new DataGridViewTitleCell() { LeftColumn = 0, RightColumn = 3 }); row.Cells[row.Cells.Count - 1].ReadOnly = true; row.Cells.Add(new DataGridViewTitleCell() { LeftColumn = 0, RightColumn = 3 }); row.Cells[row.Cells.Count - 1].ReadOnly = true; row.Cells.Add(new DataGridViewTitleCell() { LeftColumn = 0, RightColumn = 3 }); row.Cells[row.Cells.Count - 1].ReadOnly = true; rows.Add(row); // name if (Variable.NamedVariable != null) { if (nameVar == null) { nameVar = new StringVar() { Value = Variable.NamedVariable.Name }; } row = new DataGridViewRow(); row.Cells.Add(new DataGridViewDisableCheckBoxCell() { Enabled = false }); row.Cells.Add(new DataGridViewTextBoxCell() { Value = "Name" }); row.Cells.Add(nameVar.GetGridCell()); row.Cells[row.Cells.Count - 1].ReadOnly = true; row.Cells.Add(new DataGridViewTextBoxCell() { Value = "" }); rows.Add(row); } // value row = new DataGridViewRow(); row.Cells.Add(new DataGridViewDisableCheckBoxCell() { Enabled = false }); row.Cells.Add(new DataGridViewTextBoxCell() { Value = "Value" }); row.Cells.Add(Variable.Value.GetGridCell()); row.Cells.Add(new DataGridViewTextBoxCell() { Value = VariableTypeHelper.FriendlyName(Variable.VariableType) }); rows.Add(row); // comment if (commentVar == null) { commentVar = new StringVar() { Value = Variable.Comment }; commentVar.ValueChanged += (object sender, EventArgs e) => { Variable.Comment = commentVar.Value; }; } row = new DataGridViewRow(); row.Cells.Add(new DataGridViewDisableCheckBoxCell() { Enabled = false }); row.Cells.Add(new DataGridViewTextBoxCell() { Value = "Comment" }); row.Cells.Add(commentVar.GetGridCell()); row.Cells.Add(new DataGridViewTextBoxCell() { Value = VariableTypeHelper.FriendlyName(commentVar.VariableType) }); rows.Add(row); }
/// <inheritdoc /> /// <summary> /// Returns a friendly name of the variable type. /// </summary> public override string ToString() { return(VariableTypeHelper.FriendlyName(VariableType)); }