/// <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); } }
/// <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; } }
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); }
/// <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); }
/// <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 double) { value = (double)toSet; } else if (value is Vector2 asVector2) { if (arch.BoxID == 0) { asVector2.X = toSet; } else { asVector2.Y = toSet; } value = asVector2; } else if (value is Vector3 asVector3) { if (arch.BoxID == 0) { asVector3.X = toSet; } else if (arch.BoxID == 1) { asVector3.Y = toSet; } else { asVector3.Z = toSet; } value = asVector3; } else if (value is Vector4 asVector4) { if (arch.BoxID == 0) { asVector4.X = toSet; } else if (arch.BoxID == 1) { asVector4.Y = toSet; } else if (arch.BoxID == 2) { asVector4.Z = toSet; } else { asVector4.W = toSet; } value = asVector4; } else if (value is Float2 asFloat2) { if (arch.BoxID == 0) { asFloat2.X = toSet; } else { asFloat2.Y = toSet; } value = asFloat2; } else if (value is Float3 asFloat3) { if (arch.BoxID == 0) { asFloat3.X = toSet; } else if (arch.BoxID == 1) { asFloat3.Y = toSet; } else { asFloat3.Z = toSet; } value = asFloat3; } else if (value is Float4 asFloat4) { if (arch.BoxID == 0) { asFloat4.X = toSet; } else if (arch.BoxID == 1) { asFloat4.Y = toSet; } else if (arch.BoxID == 2) { asFloat4.Z = toSet; } else { asFloat4.W = toSet; } value = asFloat4; } else { value = 0; } parentNode.SetValue(arch.ValueIndex, value); }