public CExecuteCustomFunctionNode(CCustomFunctionGraph functionGraph) { TargetFunctionGuid = functionGraph.Guid; Name = functionGraph.Name; CExecutionPin inPin = new CExecutionPin("In"); InExecutionPins.Add(inPin); CExecutionPin execPin = new CExecutionPin("Next"); OutExecutionPins.Add(execPin); foreach (var inputParameter in functionGraph.InputParameters) { CInputPin input = new CInputPin(inputParameter.Name, inputParameter.Type); InputPins.Add(input); } foreach (var returnParameter in functionGraph.OutputParameters) { COutputPin output = new COutputPin(returnParameter.Name, returnParameter.Type); OutputPins.Add(output); } }
public CExecuteInterfaceFunctionNode(CKlaxScriptInterfaceFunction targetFunction) { TargetFunctionGuid = targetFunction.Guid; Name = targetFunction.Name; CExecutionPin inPin = new CExecutionPin("In"); InExecutionPins.Add(inPin); CExecutionPin execPin = new CExecutionPin("Next"); OutExecutionPins.Add(execPin); CInputPin targetInput = new CInputPin("Target", typeof(CEntity)); InputPins.Add(targetInput); foreach (var inputParameter in targetFunction.InputParameters) { CInputPin input = new CInputPin(inputParameter.Name, inputParameter.Type); InputPins.Add(input); } foreach (var returnParameter in targetFunction.OutputParameters) { COutputPin output = new COutputPin(returnParameter.Name, returnParameter.Type); OutputPins.Add(output); } }
private void ResolveScriptNodeConnections(IEnumerable <CNode> nodes, Dictionary <CNode, CScriptNodeViewmodel> nodeToViewModel) { foreach (CNode graphNode in nodes) { CScriptNodeViewmodel sourceViewModel = nodeToViewModel[graphNode]; for (int i = 0; i < graphNode.OutExecutionPins.Count; i++) { CExecutionPin inExecutionPin = graphNode.OutExecutionPins[i]; if (inExecutionPin.TargetNode == null) { continue; } CScriptNodeViewmodel targetViewModel = nodeToViewModel[inExecutionPin.TargetNode]; if (targetViewModel.InExecutionPins.Count > 0) { CNodeConnectionViewModel newConnection = new CNodeConnectionViewModel(sourceViewModel.OutExecutionPins[i], targetViewModel.InExecutionPins[inExecutionPin.TargetPinIndex], this); newConnection.Connect(); } else { inExecutionPin.TargetNode = null; LogUtility.Log("[ScriptLoadError] node {0} tried to connect to {1} but the target does not have an in execution pin", sourceViewModel.Name, targetViewModel.Name); } } for (int i = 0; i < graphNode.InputPins.Count; i++) { CInputPin inputPin = graphNode.InputPins[i]; if (inputPin.SourceNode == null) { continue; } CScriptNodeViewmodel inputSourceVm = nodeToViewModel[inputPin.SourceNode]; if (inputSourceVm.OutputPins.Count > inputPin.SourceParameterIndex) { COutputPinViewModel sourcePinVM = inputSourceVm.OutputPins[inputPin.SourceParameterIndex]; if (inputPin.Type.IsAssignableFrom(sourcePinVM.ValueType)) { CNodeConnectionViewModel newConnection = new CNodeConnectionViewModel(sourcePinVM, sourceViewModel.InputPins[i], this); newConnection.Connect(); } else { inputPin.SourceNode = null; inputPin.SourceParameterIndex = -1; LogUtility.Log("[ScriptLoadWarning] Node {0} tried to connect to {1} at output pin index {2} but the pin types are not compatible, connection removed", sourceViewModel.Name, inputSourceVm.Name, inputPin.SourceParameterIndex); } } else { inputPin.SourceNode = null; inputPin.SourceParameterIndex = -1; LogUtility.Log("[ScriptLoadError] node {0} tried to connect to {1} at output pin index {2} but there are not enough pins", sourceViewModel.Name, inputSourceVm.Name, inputPin.SourceParameterIndex); } } } }
public CInputPinViewModel(CInputPin inputPin, CScriptNodeViewmodel nodeViewModel, int pinIndex) : base(nodeViewModel, pinIndex) { m_pin = inputPin; Name = inputPin.Name; Tooltip = EditorKlaxScriptUtility.GetTypeName(inputPin.Type); m_pinColor = PinColorHelpers.GetColorForType(inputPin.Type); m_nodeViewmodel = nodeViewModel; m_literal = inputPin.Literal; m_valueType = inputPin.Type; m_bIsLiteralOnly = inputPin.bIsLiteralOnly; }
public override void OnInputLiteralChanged(CNodeChangeContext context, CInputPin pin) { if (pin == InputPins[0]) { CKlaxScriptTypeInfo targetType = ((CKlaxScriptTypeInfo)pin.Literal); ChangePinType(context, OutputPins[0], targetType == null ? typeof(object) : targetType.Type); if (targetType != null) { ChangeNodeName(context, "Cast to " + targetType.Name); } } }
protected override void OnSourceVariableChanged() { OutputPins.Clear(); InputPins.Clear(); Name = "Set " + SourceVariable.Name; CInputPin input = new CInputPin(SourceVariable.Name, SourceVariable.Type); InputPins.Add(input); COutputPin output = new COutputPin("NewValue", SourceVariable.Type); OutputPins.Add(output); }
public override void OnInputLiteralChanged(CNodeChangeContext context, CInputPin pin) { if (pin == InputPins[0]) { CKlaxScriptTypeInfo newType = pin.Literal as CKlaxScriptTypeInfo; if (newType != null) { OutExecutionPins.RemoveRange(1, OutExecutionPins.Count - 1); context.Actions.Add(new CSwitchNodeTypeChangeAction(newType.Type)); ChangePinType(context, InputPins[1], newType.Type); ChangeNodeName(context, $"Switch ({newType.Name})"); InputPins[1].Literal = newType.Type.GetDefaultValue(); } } }
public CFunctionGraphReturnNode(List <CKlaxVariable> returnParameters) { AllowDelete = false; AllowCopy = false; Name = "Return"; CExecutionPin inPin = new CExecutionPin("Return"); InExecutionPins.Add(inPin); foreach (var returnParameter in returnParameters) { CInputPin input = new CInputPin(returnParameter.Name, returnParameter.Type); InputPins.Add(input); } }
public CBranchNode() { Name = "Branch"; CExecutionPin inPin = new CExecutionPin("In"); InExecutionPins.Add(inPin); CExecutionPin truePin = new CExecutionPin("True"); OutExecutionPins.Add(truePin); CExecutionPin falsePin = new CExecutionPin("False"); OutExecutionPins.Add(falsePin); CInputPin conditionPin = new CInputPin("Condition", typeof(bool)); InputPins.Add(conditionPin); }
public void RebuildNode(List <CKlaxVariable> returnParameters) { // Adjust the nodes input pins to the new return parameters // Note the editor has to take care of adjusting pin connections if (returnParameters.Count >= InputPins.Count) { for (int i = 0; i < returnParameters.Count; i++) { CKlaxVariable returnParameter = returnParameters[i]; if (InputPins.Count > i) { CInputPin pin = InputPins[i]; pin.Name = returnParameter.Name; pin.Type = returnParameter.Type; } else { InputPins.Add(new CInputPin(returnParameter.Name, returnParameter.Type)); } } } else { for (int i = InputPins.Count - 1; i >= 0; i--) { if (returnParameters.Count > i) { CKlaxVariable returnParameter = returnParameters[i]; CInputPin pin = InputPins[i]; pin.Name = returnParameter.Name; pin.Type = returnParameter.Type; } else { InputPins.RemoveAt(i); } } } RaiseNodeRebuildEvent(); }
public CSwitchNode() { Name = "Switch"; CanAddOutputPins = true; CExecutionPin execute = new CExecutionPin() { Name = "In", TargetNode = null }; InExecutionPins.Add(execute); CExecutionPin defaultOutExec = new CExecutionPin() { Name = "Default", TargetNode = null }; OutExecutionPins.Add(defaultOutExec); CInputPin typePin = new CInputPin() { Name = "Type", bIsLiteralOnly = true, Type = typeof(CKlaxScriptTypeInfo), Literal = typeof(string) }; InputPins.Add(typePin); CInputPin objectPin = new CInputPin() { Name = "Object", Type = typeof(object) }; InputPins.Add(objectPin); }
public override void OnInputConnectionChanged(CNodeChangeContext context, CInputPin pin, COutputPin otherpin) { if (otherpin == null) { ChangePinType(context, OutputPins[1], typeof(object)); } else { Type type = otherpin.Type; if (type.IsGenericType) { if (type.GetGenericTypeDefinition() == typeof(List <>)) { Type outputType = type.GenericTypeArguments[0]; if (outputType != OutputPins[1].Type) { ChangePinType(context, OutputPins[1], outputType); } } } } }
public CBaseCastNode() { Name = "Cast"; CInputPin targetTypeInput = new CInputPin { Name = "Target Type", Type = typeof(CKlaxScriptTypeInfo), Literal = null, SourceNode = null, SourceParameterIndex = -1, StackIndex = -1 }; InputPins.Add(targetTypeInput); CInputPin targetObjectInput = new CInputPin { Name = "Target", Type = typeof(object), Literal = null, SourceNode = null, SourceParameterIndex = -1, StackIndex = -1 }; InputPins.Add(targetObjectInput); COutputPin convertedObjectOutput = new COutputPin { Name = "Result", Type = typeof(object) }; OutputPins.Add(convertedObjectOutput); }
public void OnNodeRebuilt() { if (m_inputPins.Count <= ScriptNode.InputPins.Count) { for (int i = 0; i < ScriptNode.InputPins.Count; i++) { CInputPin scriptInput = ScriptNode.InputPins[i]; if (m_inputPins.Count > i) { CInputPinViewModel inputViewModel = m_inputPins[i]; inputViewModel.Name = scriptInput.Name; if (inputViewModel.ValueType != scriptInput.Type) { inputViewModel.ValueType = scriptInput.Type; inputViewModel.Literal = scriptInput.Type.IsValueType ? Activator.CreateInstance(scriptInput.Type) : null; } } else { m_inputPins.Add(new CInputPinViewModel(scriptInput, this, i)); } } } else { for (int i = m_inputPins.Count - 1; i >= 0; i--) { if (ScriptNode.InputPins.Count > i) { CInputPin scriptInput = ScriptNode.InputPins[i]; CInputPinViewModel inputViewModel = m_inputPins[i]; inputViewModel.Name = scriptInput.Name; if (inputViewModel.ValueType != scriptInput.Type) { inputViewModel.ValueType = scriptInput.Type; inputViewModel.Literal = scriptInput.Type.IsValueType ? Activator.CreateInstance(scriptInput.Type) : null; } } else { m_inputPins[i].DisconnectAll(); m_inputPins.RemoveAt(i); } } } if (m_outputPins.Count <= ScriptNode.OutputPins.Count) { for (int i = 0; i < ScriptNode.OutputPins.Count; i++) { COutputPin scriptOutput = ScriptNode.OutputPins[i]; if (m_outputPins.Count > i) { COutputPinViewModel outputViewModel = m_outputPins[i]; outputViewModel.Name = scriptOutput.Name; outputViewModel.ValueType = scriptOutput.Type; } else { m_outputPins.Add(new COutputPinViewModel(scriptOutput, this, i)); } } } else { for (int i = m_outputPins.Count - 1; i >= 0; i--) { if (ScriptNode.OutputPins.Count > i) { COutputPin scriptOutput = ScriptNode.OutputPins[i]; COutputPinViewModel outputViewModel = m_outputPins[i]; outputViewModel.Name = scriptOutput.Name; outputViewModel.ValueType = scriptOutput.Type; } else { m_outputPins[i].DisconnectAll(); m_outputPins.RemoveAt(i); } } } }