private static Vector4 GetValueVector4(SurfaceNode parentNode, NodeElementArchetype archetype) { Vector4 value = Vector4.Zero; var v = parentNode.Values[archetype.ValueIndex]; if (v is Vector2 vec2) { value = new Vector4(vec2, 0.0f, 0.0f); } else if (v is Vector3 vec3) { value = new Vector4(vec3, 0.0f); } else if (v is Vector4 vec4) { value = vec4; } else if (v is Color col) { value = col; } else if (v is float f) { value = new Vector4(f); } else if (v is int i) { value = new Vector4(i); } return(value); }
private static Vector2 GetValueVector2(SurfaceNode parentNode, NodeElementArchetype archetype) { Vector2 value = Vector2.Zero; var v = parentNode.Values[archetype.ValueIndex]; if (v is Vector2 vec2) { value = vec2; } else if (v is Vector3 vec3) { value = new Vector2(vec3); } else if (v is Vector4 vec4) { value = new Vector2(vec4); } else if (v is Color col) { value = new Vector2(col.R, col.G); } else if (v is float f) { value = new Vector2(f); } else if (v is int i) { value = new Vector2(i); } return(value); }
private static Color Get(SurfaceNode parentNode, NodeElementArchetype arch) { if (arch.ValueIndex < 0) { return(Color.White); } Color result; var value = parentNode.Values[arch.ValueIndex]; if (value is Color valueColor) { result = valueColor; } else if (value is Vector3 valueVec3) { result = valueVec3; } else if (value is Vector4 valueVec4) { result = valueVec4; } else { result = Color.White; } return(result); }
private void AddOutput(NodeElementArchetype arch) { var element = new OutputBox(this, arch); AddElement(element); _dynamicChildren.Add(element); }
private void TryRestoreConnections(Box box, Box[] prevBoxes, ref NodeElementArchetype arch) { if (prevBoxes == null) { return; } for (int j = 0; j < prevBoxes.Length; j++) { var prevBox = prevBoxes[j]; if (prevBox != null && prevBox.HasAnyConnection && prevBox.Archetype.Text == arch.Text && box.CanUseType(prevBox.Connections[0].CurrentType)) { box.Connections.AddRange(prevBox.Connections); prevBox.Connections.Clear(); foreach (var connection in box.Connections) { connection.Connections.Remove(prevBox); connection.Connections.Add(box); } box.ConnectionTick(); prevBox.ConnectionTick(); foreach (var connection in box.Connections) { connection.ConnectionTick(); } break; } } }
/// <summary> /// Initializes a new instance of the <see cref="AssetSelect"/> class. /// </summary> /// <param name="parentNode">The parent node.</param> /// <param name="archetype">The archetype.</param> public AssetSelect(SurfaceNode parentNode, NodeElementArchetype archetype) : base(Utilities.Utils.GetType((ContentDomain)archetype.BoxID), archetype.ActualPosition) { SelectedID = (Guid)parentNode.Values[archetype.ValueIndex]; ParentNode = parentNode; Archetype = archetype; }
/// <inheritdoc /> public IntegerValue(SurfaceNode parentNode, NodeElementArchetype archetype) : base(Get(parentNode, archetype), archetype.Position.X, archetype.Position.Y, 50, (int)archetype.ValueMin, (int)archetype.ValueMax, 0.05f) { ParentNode = parentNode; Archetype = archetype; ParentNode.ValuesChanged += OnNodeValuesChanged; }
/// <inheritdoc /> public ColorValue(SurfaceNode parentNode, NodeElementArchetype archetype) : base(Get(parentNode, archetype), archetype.Position.X, archetype.Position.Y) { ParentNode = parentNode; Archetype = archetype; ParentNode.ValuesChanged += OnNodeValuesChanged; }
/// <inheritdoc /> public InputBox(SurfaceNode parentNode, NodeElementArchetype archetype) : base(parentNode, archetype, archetype.Position) { // Check if use inlined default value editor if (Archetype.ValueIndex != -1) { ParentNode.ValuesChanged += UpdateDefaultValue; } }
/// <summary> /// Initializes a new instance of the <see cref="AssetSelect"/> class. /// </summary> /// <param name="parentNode">The parent node.</param> /// <param name="archetype">The archetype.</param> public AssetSelect(SurfaceNode parentNode, NodeElementArchetype archetype) : base(Scripting.TypeUtils.GetType(archetype.Text), archetype.ActualPosition) { ParentNode = parentNode; Archetype = archetype; ParentNode.ValuesChanged += OnNodeValuesChanged; OnNodeValuesChanged(); }
/// <summary> /// Initializes a new instance of the <see cref="AssetSelect"/> class. /// </summary> /// <param name="parentNode">The parent node.</param> /// <param name="archetype">The archetype.</param> public AssetSelect(SurfaceNode parentNode, NodeElementArchetype archetype) : base(Utilities.Utils.GetType((ContentDomain)archetype.BoxID), archetype.ActualPosition) { ParentNode = parentNode; Archetype = archetype; ParentNode.ValuesChanged += OnNodeValuesChanged; OnNodeValuesChanged(); }
/// <inheritdoc /> public EnumValue(SurfaceNode parentNode, NodeElementArchetype archetype) : base(Scripting.TypeUtils.GetType(archetype.Text).Type) { X = archetype.ActualPositionX; Y = archetype.ActualPositionY; Width = archetype.Size.X; ParentNode = parentNode; Archetype = archetype; Value = (int)ParentNode.Values[Archetype.ValueIndex]; }
/// <summary> /// Initializes a new instance of the <see cref="ActorSelect"/> class. /// </summary> /// <param name="parentNode">The parent node.</param> /// <param name="archetype">The archetype.</param> public ActorSelect(SurfaceNode parentNode, NodeElementArchetype archetype) { ParentNode = parentNode; Archetype = archetype; Bounds = new Rectangle(Archetype.ActualPosition, archetype.Size); Type = Scripting.TypeUtils.GetType(archetype.Text); ParentNode.ValuesChanged += OnNodeValuesChanged; OnNodeValuesChanged(); }
/// <summary> /// Gets the floating point value from the specified parent node. Handles type casting and components gather. /// </summary> /// <param name="parentNode">The parent node.</param> /// <param name="arch">The node element archetype.</param> /// <param name="customValue">The custom value override (optional).</param> /// <returns>The result value.</returns> public static float Get(SurfaceNode parentNode, NodeElementArchetype arch, object customValue = null) { if (arch.ValueIndex < 0 && customValue == null) { return(0); } float result; var value = customValue ?? parentNode.Values[arch.ValueIndex]; // Note: this value box may edit on component of the vector like Vector3.Y, BoxID from Archetype tells which component pick if (value is int asInt) { result = (float)asInt; } else if (value is float asFloat) { result = asFloat; } else if (value is double asDouble) { result = (float)asDouble; } else if (value is Vector2 asVector2) { result = (float)(arch.BoxID == 0 ? asVector2.X : asVector2.Y); } else if (value is Vector3 asVector3) { result = (float)(arch.BoxID == 0 ? asVector3.X : arch.BoxID == 1 ? asVector3.Y : asVector3.Z); } else if (value is Vector4 asVector4) { result = (float)(arch.BoxID == 0 ? asVector4.X : arch.BoxID == 1 ? asVector4.Y : arch.BoxID == 2 ? asVector4.Z : asVector4.W); } else if (value is Float2 asFloat2) { result = (arch.BoxID == 0 ? asFloat2.X : asFloat2.Y); } else if (value is Float3 asFloat3) { result = (arch.BoxID == 0 ? asFloat3.X : arch.BoxID == 1 ? asFloat3.Y : asFloat3.Z); } else if (value is Float4 asFloat4) { result = (arch.BoxID == 0 ? asFloat4.X : arch.BoxID == 1 ? asFloat4.Y : arch.BoxID == 2 ? asFloat4.Z : asFloat4.W); } else { result = 0; } return(result); }
/// <summary> /// Sets all the values to the given value (eg. all components of the vector). /// </summary> /// <param name="parentNode">The parent node.</param> /// <param name="arch">The node element archetype.</param> /// <param name="toSet">The value to assign.</param> public static void SetAllValues(SurfaceNode parentNode, NodeElementArchetype arch, float toSet) { if (arch.ValueIndex < 0) { return; } var value = parentNode.Values[arch.ValueIndex]; if (value is int) { value = (int)toSet; } else if (value is float) { value = toSet; } else if (value is double) { value = (double)toSet; } else if (value is Vector2) { value = new Vector2(toSet); } else if (value is Vector3) { value = new Vector3(toSet); } else if (value is Vector4) { value = new Vector4(toSet); } else if (value is Float2) { value = new Float2(toSet); } else if (value is Float3) { value = new Float3(toSet); } else if (value is Float4) { value = new Float4(toSet); } else { value = 0; } parentNode.SetValue(arch.ValueIndex, value); }
/// <inheritdoc /> public TextBoxView(SurfaceNode parentNode, NodeElementArchetype archetype) : base(archetype.BoxID == 1, archetype.Position.X, archetype.Position.Y, archetype.Size.X) { ParentNode = parentNode; Archetype = archetype; Size = archetype.Size; if (archetype.ValueIndex >= 0) { Text = (string)parentNode.Values[archetype.ValueIndex]; EditEnd += () => ParentNode.SetValue(Archetype.ValueIndex, Text); } }
/// <summary> /// Gets the integer value from the specified parent node. Handles type casting and components gather. /// </summary> /// <param name="parentNode">The parent node.</param> /// <param name="arch">The node element archetype.</param> /// <returns>The result value.</returns> public static int Get(SurfaceNode parentNode, NodeElementArchetype arch) { if (arch.ValueIndex < 0) { return(0); } int result; var value = parentNode.Values[arch.ValueIndex]; // Note: this value box may edit on component of the vector like Vector3.Y, BoxID from Archetype tells which component pick if (value is int valueInt) { result = valueInt; } else if (value is uint valueUint) { result = (int)valueUint; } else if (value is long valueLong) { result = (int)valueLong; } else if (value is ulong valueUlong) { result = (int)valueUlong; } else if (value is float valueFloat) { result = (int)valueFloat; } else if (value is Vector2 valueVec2) { result = (int)(arch.BoxID == 0 ? valueVec2.X : valueVec2.Y); } else if (value is Vector3 valueVec3) { result = (int)(arch.BoxID == 0 ? valueVec3.X : arch.BoxID == 1 ? valueVec3.Y : valueVec3.Z); } else if (value is Vector4 valueVec4) { result = (int)(arch.BoxID == 0 ? valueVec4.X : arch.BoxID == 1 ? valueVec4.Y : arch.BoxID == 2 ? valueVec4.Z : valueVec4.W); } else { result = 0; } return(result); }
/// <inheritdoc /> public TextBoxView(SurfaceNode parentNode, NodeElementArchetype archetype) : base(archetype.BoxID == 1, archetype.Position.X, archetype.Position.Y, archetype.Size.X) { ParentNode = parentNode; Archetype = archetype; Size = archetype.Size; if (archetype.ValueIndex >= 0) { OnNodeValuesChanged(); EditEnd += () => ParentNode.SetValue(Archetype.ValueIndex, Text); ParentNode.ValuesChanged += OnNodeValuesChanged; } }
/// <inheritdoc /> public SkeletonNodeSelectElement(SurfaceNode parentNode, NodeElementArchetype archetype) : base(parentNode, archetype) { _isAutoSelect = true; UpdateComboBox(); // Select saved value _selectedIndices.Clear(); if (Archetype.ValueIndex != -1) { _selectedIndices.Add((int)ParentNode.Values[Archetype.ValueIndex]); } }
/// <inheritdoc /> public SkeletonNodeNameSelectElement(SurfaceNode parentNode, NodeElementArchetype archetype) : base(parentNode, archetype) { _isAutoSelect = true; UpdateComboBox(); // Select saved value _selectedIndices.Clear(); if (Archetype.ValueIndex != -1) { SelectedNodeName = (string)ParentNode.Values[Archetype.ValueIndex]; ParentNode.ValuesChanged += OnNodeValuesChanged; } }
/// <inheritdoc /> public SkeletonNodeSelectElement(SurfaceNode parentNode, NodeElementArchetype archetype) : base(parentNode, archetype) { _isAutoSelect = true; UpdateComboBox(); // Select saved value _selectedIndices.Clear(); if (Archetype.ValueIndex != -1) { var selectedIndex = (int)ParentNode.Values[Archetype.ValueIndex]; if (selectedIndex > -1 && selectedIndex < _items.Count) { SelectedIndex = selectedIndex; } } }
/// <inheritdoc /> public ComboBoxElement(SurfaceNode parentNode, NodeElementArchetype archetype) : base(archetype.ActualPositionX, archetype.ActualPositionY, archetype.Size.X) { ParentNode = parentNode; Archetype = archetype; // Check if combo box will use auto select feature // Note: used provided items we should auto update saved node value on closed _isAutoSelect = Archetype.Text != null; if (Archetype.Text != null) { var items = Archetype.Text.Split('\n'); AddItems(items); OnNodeValuesChanged(); ParentNode.ValuesChanged += OnNodeValuesChanged; } }
/// <summary> /// Gets the floating point value from the specified parent node. Handles type casting and components gather. /// </summary> /// <param name="parentNode">The parent node.</param> /// <param name="arch">The node element archetype.</param> /// <param name="customValue">The custom value override (optional).</param> /// <returns>The result value.</returns> public static float Get(SurfaceNode parentNode, NodeElementArchetype arch, object customValue = null) { if (arch.ValueIndex < 0 && customValue == null) { return(0); } float result; var value = customValue ?? parentNode.Values[arch.ValueIndex]; // Note: this value box may edit on component of the vector like Vector3.Y, BoxID from Archetype tells which component pick if (value is int valueInt) { result = (float)valueInt; } else if (value is float valueFloat) { result = valueFloat; } else if (value is double valueDouble) { result = (float)valueDouble; } else if (value is Vector2 valueVec2) { result = (arch.BoxID == 0 ? valueVec2.X : valueVec2.Y); } else if (value is Vector3 valueVec3) { result = (arch.BoxID == 0 ? valueVec3.X : arch.BoxID == 1 ? valueVec3.Y : valueVec3.Z); } else if (value is Vector4 valueVec4) { result = (arch.BoxID == 0 ? valueVec4.X : arch.BoxID == 1 ? valueVec4.Y : arch.BoxID == 2 ? valueVec4.Z : valueVec4.W); } else { result = 0; } return(result); }
/// <inheritdoc /> public ComboBoxElement(SurfaceNode parentNode, NodeElementArchetype archetype) : base(archetype.ActualPositionX, archetype.ActualPositionY, archetype.Size.X) { ParentNode = parentNode; Archetype = archetype; // Check if combo box will use auto select feature // Note: used provided items we should auto update saved node value on closed _isAutoSelect = Archetype.Text != null; if (Archetype.Text != null) { // Get the f*****g items xD var items = Archetype.Text.Split('\n'); AddItems(items); // Select saved value _selectedIndicies.Clear(); _selectedIndicies.Add((int)ParentNode.Values[Archetype.ValueIndex]); } }
private static void Set(SurfaceNode parentNode, NodeElementArchetype arch, ref Color toSet) { if (arch.ValueIndex < 0) { return; } var value = parentNode.Values[arch.ValueIndex]; if (value is Color) { value = toSet; } else if (value is Vector3) { value = (Vector3)toSet; } else if (value is Vector4) { value = (Vector4)toSet; } parentNode.SetValue(arch.ValueIndex, value); }
/// <inheritdoc /> public InteagerValue(SurfaceNode parentNode, NodeElementArchetype archetype) : base(Get(parentNode, archetype), archetype.Position.X, archetype.Position.Y, 50) { ParentNode = parentNode; Archetype = archetype; }
/// <inheritdoc /> public OutputBox(SurfaceNode parentNode, NodeElementArchetype archetype) : base(parentNode, archetype, archetype.Position + new Vector2(parentNode.Archetype.Size.X, 0)) { }
/// <summary> /// Sets the integer value of the specified parent node. Handles type casting and components assignment. /// </summary> /// <param name="parentNode">The parent node.</param> /// <param name="arch">The node element archetype.</param> /// <param name="toSet">The value to set.</param> public static void Set(SurfaceNode parentNode, NodeElementArchetype arch, int toSet) { if (arch.ValueIndex < 0) { return; } var value = parentNode.Values[arch.ValueIndex]; float toSetF = (float)toSet; if (value is int) { value = toSet; } else if (value is uint) { value = (uint)toSet; } else if (value is long) { value = (long)toSet; } else if (value is ulong) { value = (ulong)toSet; } else if (value is float) { value = toSetF; } else if (value is Vector2 asVector2) { if (arch.BoxID == 0) { asVector2.X = toSetF; } else { asVector2.Y = toSetF; } value = asVector2; } else if (value is Vector3 asVector3) { if (arch.BoxID == 0) { asVector3.X = toSetF; } else if (arch.BoxID == 1) { asVector3.Y = toSetF; } else { asVector3.Z = toSetF; } value = asVector3; } else if (value is Vector4 asVector4) { if (arch.BoxID == 0) { asVector4.X = toSetF; } else if (arch.BoxID == 1) { asVector4.Y = toSetF; } else if (arch.BoxID == 2) { asVector4.Z = toSetF; } else { asVector4.W = toSetF; } value = asVector4; } else { value = 0; } parentNode.SetValue(arch.ValueIndex, value); }
/// <summary> /// Sets the floating point value of the specified parent node. Handles type casting and components assignment. /// </summary> /// <param name="parentNode">The parent node.</param> /// <param name="arch">The node element archetype.</param> /// <param name="toSet">The value to set.</param> public static void Set(SurfaceNode parentNode, NodeElementArchetype arch, float toSet) { if (arch.ValueIndex < 0) { return; } var value = parentNode.Values[arch.ValueIndex]; if (value is int) { value = (int)toSet; } else if (value is float) { value = toSet; } else if (value is Vector2 valueVec2) { if (arch.BoxID == 0) { valueVec2.X = toSet; } else { valueVec2.Y = toSet; } value = valueVec2; } else if (value is Vector3 valueVec3) { if (arch.BoxID == 0) { valueVec3.X = toSet; } else if (arch.BoxID == 1) { valueVec3.Y = toSet; } else { valueVec3.Z = toSet; } value = valueVec3; } else if (value is Vector4 valueVec4) { if (arch.BoxID == 0) { valueVec4.X = toSet; } else if (arch.BoxID == 1) { valueVec4.Y = toSet; } else if (arch.BoxID == 2) { valueVec4.Z = toSet; } else { valueVec4.W = toSet; } value = valueVec4; } else { value = 0; } parentNode.SetValue(arch.ValueIndex, value); }
/// <inheritdoc /> public TextView(SurfaceNode parentNode, NodeElementArchetype archetype) : base(parentNode, archetype, 100, 16, false) { }