Fix Unsigned Integer value field to prevent negative values

This commit is contained in:
Wojtek Figat
2021-01-24 13:30:48 +01:00
parent 47bff456e0
commit b04e1381dc
6 changed files with 38 additions and 2 deletions

View File

@@ -143,6 +143,8 @@ namespace FlaxEditor.GUI.Input
try
{
var value = ShuntingYard.Parse(Text);
if (value < 0)
value = 0;
Value = (uint)value;
}
catch (Exception ex)

View File

@@ -379,7 +379,7 @@ namespace FlaxEditor.Surface.Archetypes
Elements = new[]
{
NodeElementArchetype.Factory.Output(0, "Value", typeof(uint), 0),
NodeElementArchetype.Factory.Integer(0, 0, 0)
NodeElementArchetype.Factory.UnsignedInteger(0, 0, 0, -1, 0, int.MaxValue)
}
},
};

View File

@@ -85,7 +85,7 @@ namespace FlaxEditor.Surface.Elements
else if (value is Vector4 valueVec4)
result = (uint)(arch.BoxID == 0 ? valueVec4.X : arch.BoxID == 1 ? valueVec4.Y : arch.BoxID == 2 ? valueVec4.Z : valueVec4.W);
else
result = 0;
result = 0u;
return result;
}

View File

@@ -239,6 +239,32 @@ namespace FlaxEditor.Surface
};
}
/// <summary>
/// Creates new Unsigned Integer value element description.
/// </summary>
/// <param name="x">The x location (in node area space).</param>
/// <param name="y">The y location (in node area space).</param>
/// <param name="valueIndex">The index of the node variable linked as the input. Useful to make a physical connection between input box and default value for it.</param>
/// <param name="component">The index of the component to edit. For vectors this can be set to modify only single component of it. Eg. for vec2 value component set to 1 will edit only Y component. Default value -1 will be used to edit whole value.</param>
/// <param name="valueMin">The minimum value range.</param>
/// <param name="valueMax">The maximum value range.</param>
/// <returns>The archetype.</returns>
public static NodeElementArchetype UnsignedInteger(float x, float y, int valueIndex = -1, int component = -1, uint valueMin = 0, uint valueMax = 1000000)
{
return new NodeElementArchetype
{
Type = NodeElementType.UnsignedIntegerValue,
Position = new Vector2(Constants.NodeMarginX + x, Constants.NodeMarginY + Constants.NodeHeaderSize + y),
Text = null,
Single = false,
ValueIndex = valueIndex,
ValueMin = valueMin,
ValueMax = valueMax,
BoxID = -1,
ConnectionsType = ScriptType.Null
};
}
/// <summary>
/// Creates new Float value element description.
/// </summary>

View File

@@ -94,5 +94,10 @@ namespace FlaxEditor.Surface
/// The actor picker.
/// </summary>
Actor = 19,
/// <summary>
/// The unsigned integer value.
/// </summary>
UnsignedIntegerValue = 20,
}
}

View File

@@ -267,6 +267,9 @@ namespace FlaxEditor.Surface
case NodeElementType.Actor:
element = new ActorSelect(this, arch);
break;
case NodeElementType.UnsignedIntegerValue:
element = new UnsignedIntegerValue(this, arch);
break;
//default: throw new NotImplementedException("Unknown node element type: " + arch.Type);
}
if (element != null)