rename attribute and fix parsing
This commit is contained in:
@@ -4,7 +4,7 @@ using System;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using FlaxEditor.CustomEditors.Elements;
|
using FlaxEditor.CustomEditors.Elements;
|
||||||
using FlaxEngine;
|
using FlaxEngine;
|
||||||
using Utils = FlaxEditor.Utilities.Utils;
|
using Utils = FlaxEngine.Utils;
|
||||||
|
|
||||||
namespace FlaxEditor.CustomEditors.Editors
|
namespace FlaxEditor.CustomEditors.Editors
|
||||||
{
|
{
|
||||||
@@ -26,8 +26,8 @@ namespace FlaxEditor.CustomEditors.Editors
|
|||||||
|
|
||||||
// Try get limit attribute for value min/max range setting and slider speed
|
// Try get limit attribute for value min/max range setting and slider speed
|
||||||
var attributes = Values.GetAttributes();
|
var attributes = Values.GetAttributes();
|
||||||
var categoryAttribute = attributes.FirstOrDefault(x => x is ValueCategoryAttribute);
|
var categoryAttribute = attributes.FirstOrDefault(x => x is NumberCategoryAttribute);
|
||||||
var valueCategory = ((ValueCategoryAttribute)categoryAttribute)?.Category ?? Utils.ValueCategory.None;
|
var valueCategory = ((NumberCategoryAttribute)categoryAttribute)?.Category ?? Utils.ValueCategory.None;
|
||||||
if (attributes != null)
|
if (attributes != null)
|
||||||
{
|
{
|
||||||
var limit = attributes.FirstOrDefault(x => x is LimitAttribute);
|
var limit = attributes.FirstOrDefault(x => x is LimitAttribute);
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ using System;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using FlaxEditor.CustomEditors.Elements;
|
using FlaxEditor.CustomEditors.Elements;
|
||||||
using FlaxEngine;
|
using FlaxEngine;
|
||||||
using Utils = FlaxEditor.Utilities.Utils;
|
using Utils = FlaxEngine.Utils;
|
||||||
|
|
||||||
namespace FlaxEditor.CustomEditors.Editors
|
namespace FlaxEditor.CustomEditors.Editors
|
||||||
{
|
{
|
||||||
@@ -31,8 +31,8 @@ namespace FlaxEditor.CustomEditors.Editors
|
|||||||
|
|
||||||
// Try get limit attribute for value min/max range setting and slider speed
|
// Try get limit attribute for value min/max range setting and slider speed
|
||||||
var attributes = Values.GetAttributes();
|
var attributes = Values.GetAttributes();
|
||||||
var categoryAttribute = attributes.FirstOrDefault(x => x is ValueCategoryAttribute);
|
var categoryAttribute = attributes.FirstOrDefault(x => x is NumberCategoryAttribute);
|
||||||
var valueCategory = ((ValueCategoryAttribute)categoryAttribute)?.Category ?? Utils.ValueCategory.None;
|
var valueCategory = ((NumberCategoryAttribute)categoryAttribute)?.Category ?? Utils.ValueCategory.None;
|
||||||
if (attributes != null)
|
if (attributes != null)
|
||||||
{
|
{
|
||||||
var range = attributes.FirstOrDefault(x => x is RangeAttribute);
|
var range = attributes.FirstOrDefault(x => x is RangeAttribute);
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ using System.Linq;
|
|||||||
using FlaxEditor.CustomEditors.Elements;
|
using FlaxEditor.CustomEditors.Elements;
|
||||||
using FlaxEngine;
|
using FlaxEngine;
|
||||||
using FlaxEngine.GUI;
|
using FlaxEngine.GUI;
|
||||||
using Utils = FlaxEditor.Utilities.Utils;
|
using Utils = FlaxEngine.Utils;
|
||||||
|
|
||||||
namespace FlaxEditor.CustomEditors.Editors
|
namespace FlaxEditor.CustomEditors.Editors
|
||||||
{
|
{
|
||||||
@@ -75,7 +75,7 @@ namespace FlaxEditor.CustomEditors.Editors
|
|||||||
if (attributes != null)
|
if (attributes != null)
|
||||||
{
|
{
|
||||||
limit = (LimitAttribute)attributes.FirstOrDefault(x => x is LimitAttribute);
|
limit = (LimitAttribute)attributes.FirstOrDefault(x => x is LimitAttribute);
|
||||||
var categoryAttribute = (ValueCategoryAttribute)attributes.FirstOrDefault(x => x is ValueCategoryAttribute);
|
var categoryAttribute = (NumberCategoryAttribute)attributes.FirstOrDefault(x => x is NumberCategoryAttribute);
|
||||||
if (categoryAttribute != null)
|
if (categoryAttribute != null)
|
||||||
category = categoryAttribute.Category;
|
category = categoryAttribute.Category;
|
||||||
}
|
}
|
||||||
@@ -261,7 +261,7 @@ namespace FlaxEditor.CustomEditors.Editors
|
|||||||
if (attributes != null)
|
if (attributes != null)
|
||||||
{
|
{
|
||||||
limit = (LimitAttribute)attributes.FirstOrDefault(x => x is LimitAttribute);
|
limit = (LimitAttribute)attributes.FirstOrDefault(x => x is LimitAttribute);
|
||||||
var categoryAttribute = (ValueCategoryAttribute)attributes.FirstOrDefault(x => x is ValueCategoryAttribute);
|
var categoryAttribute = (NumberCategoryAttribute)attributes.FirstOrDefault(x => x is NumberCategoryAttribute);
|
||||||
if (categoryAttribute != null)
|
if (categoryAttribute != null)
|
||||||
category = categoryAttribute.Category;
|
category = categoryAttribute.Category;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ using System.Reflection;
|
|||||||
using FlaxEditor.GUI.Input;
|
using FlaxEditor.GUI.Input;
|
||||||
using FlaxEngine;
|
using FlaxEngine;
|
||||||
using FlaxEngine.GUI;
|
using FlaxEngine.GUI;
|
||||||
using Utils = FlaxEditor.Utilities.Utils;
|
using Utils = FlaxEngine.Utils;
|
||||||
|
|
||||||
namespace FlaxEditor.CustomEditors.Elements
|
namespace FlaxEditor.CustomEditors.Elements
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ using System.Reflection;
|
|||||||
using FlaxEditor.GUI.Input;
|
using FlaxEditor.GUI.Input;
|
||||||
using FlaxEngine;
|
using FlaxEngine;
|
||||||
using FlaxEngine.GUI;
|
using FlaxEngine.GUI;
|
||||||
using Utils = FlaxEditor.Utilities.Utils;
|
using Utils = FlaxEngine.Utils;
|
||||||
|
|
||||||
namespace FlaxEditor.CustomEditors.Elements
|
namespace FlaxEditor.CustomEditors.Elements
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using FlaxEditor.Utilities;
|
using FlaxEditor.Utilities;
|
||||||
using FlaxEngine;
|
using FlaxEngine;
|
||||||
using Utils = FlaxEditor.Utilities.Utils;
|
using Utils = FlaxEngine.Utils;
|
||||||
|
|
||||||
namespace FlaxEditor.GUI.Input
|
namespace FlaxEditor.GUI.Input
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ using System;
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using FlaxEditor.Utilities;
|
using FlaxEditor.Utilities;
|
||||||
using FlaxEngine;
|
using FlaxEngine;
|
||||||
using Utils = FlaxEditor.Utilities.Utils;
|
using Utils = FlaxEngine.Utils;
|
||||||
|
|
||||||
namespace FlaxEditor.GUI.Input
|
namespace FlaxEditor.GUI.Input
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -243,6 +243,11 @@ namespace FlaxEditor.Utilities
|
|||||||
}
|
}
|
||||||
else if (type == TokenType.Variable)
|
else if (type == TokenType.Variable)
|
||||||
{
|
{
|
||||||
|
if (previous == TokenType.Number)
|
||||||
|
{
|
||||||
|
previous = TokenType.Operator;
|
||||||
|
yield return new Token(TokenType.Operator, "*");
|
||||||
|
}
|
||||||
// Continue till the end of the variable
|
// Continue till the end of the variable
|
||||||
while (i + 1 < text.Length && DetermineType(text[i + 1]) == TokenType.Variable)
|
while (i + 1 < text.Length && DetermineType(text[i + 1]) == TokenType.Variable)
|
||||||
{
|
{
|
||||||
@@ -379,10 +384,7 @@ namespace FlaxEditor.Utilities
|
|||||||
// we assume the remaining values are all factors to be multiplied
|
// we assume the remaining values are all factors to be multiplied
|
||||||
if (stack.Count > 1)
|
if (stack.Count > 1)
|
||||||
{
|
{
|
||||||
var stackContent = string.Join(",", stack.ToList());
|
|
||||||
Debug.Log($"parsing numbers, stack is {stackContent}");
|
|
||||||
var v1 = stack.Pop();
|
var v1 = stack.Pop();
|
||||||
Debug.Log($"first on stack: {v1}");
|
|
||||||
while (stack.Count > 0)
|
while (stack.Count > 0)
|
||||||
v1 *= stack.Pop();
|
v1 *= stack.Pop();
|
||||||
return v1;
|
return v1;
|
||||||
|
|||||||
@@ -58,16 +58,6 @@ namespace FlaxEditor.Utilities
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly string FlaxEngineAssemblyName = "FlaxEngine.CSharp";
|
public static readonly string FlaxEngineAssemblyName = "FlaxEngine.CSharp";
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// A category of number values used for formatting and input boxes
|
|
||||||
/// </summary>
|
|
||||||
public enum ValueCategory
|
|
||||||
{
|
|
||||||
None,
|
|
||||||
Distance,
|
|
||||||
Angle
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tries to parse number in the name brackets at the end of the value and then increment it to create a new name.
|
/// Tries to parse number in the name brackets at the end of the value and then increment it to create a new name.
|
||||||
/// Supports numbers at the end without brackets.
|
/// Supports numbers at the end without brackets.
|
||||||
@@ -1187,11 +1177,11 @@ namespace FlaxEditor.Utilities
|
|||||||
/// <param name="value">the value to format</param>
|
/// <param name="value">the value to format</param>
|
||||||
/// <param name="category">the value type: none means just a number, distance will format in cm/m/km, angle with an appended degree sign</param>
|
/// <param name="category">the value type: none means just a number, distance will format in cm/m/km, angle with an appended degree sign</param>
|
||||||
/// <returns>the formatted string</returns>
|
/// <returns>the formatted string</returns>
|
||||||
public static string FormatFloat(float value, ValueCategory category)
|
public static string FormatFloat(float value, FlaxEngine.Utils.ValueCategory category)
|
||||||
{
|
{
|
||||||
switch (category)
|
switch (category)
|
||||||
{
|
{
|
||||||
case ValueCategory.Distance:
|
case FlaxEngine.Utils.ValueCategory.Distance:
|
||||||
var absValue = Mathf.Abs(value);
|
var absValue = Mathf.Abs(value);
|
||||||
// in case a unit != cm this would be (value / Maters2Units * 100)
|
// in case a unit != cm this would be (value / Maters2Units * 100)
|
||||||
if (absValue < Units.Meters2Units)
|
if (absValue < Units.Meters2Units)
|
||||||
@@ -1199,8 +1189,8 @@ namespace FlaxEditor.Utilities
|
|||||||
if (absValue < Units.Meters2Units * 1000)
|
if (absValue < Units.Meters2Units * 1000)
|
||||||
return (value / Units.Meters2Units).ToString("g7", CultureInfo.InvariantCulture) + "m";
|
return (value / Units.Meters2Units).ToString("g7", CultureInfo.InvariantCulture) + "m";
|
||||||
return (value / 1000 / Units.Meters2Units).ToString("g7", CultureInfo.InvariantCulture) + "km";
|
return (value / 1000 / Units.Meters2Units).ToString("g7", CultureInfo.InvariantCulture) + "km";
|
||||||
case ValueCategory.Angle: return value.ToString("g7", CultureInfo.InvariantCulture) + "°";
|
case FlaxEngine.Utils.ValueCategory.Angle: return value.ToString("g7", CultureInfo.InvariantCulture) + "°";
|
||||||
case ValueCategory.None:
|
case FlaxEngine.Utils.ValueCategory.None:
|
||||||
default:
|
default:
|
||||||
return FormatFloat(value);
|
return FormatFloat(value);
|
||||||
}
|
}
|
||||||
@@ -1212,11 +1202,11 @@ namespace FlaxEditor.Utilities
|
|||||||
/// <param name="value">the value to format</param>
|
/// <param name="value">the value to format</param>
|
||||||
/// <param name="category">the value type: none means just a number, distance will format in cm/m/km, angle with an appended degree sign</param>
|
/// <param name="category">the value type: none means just a number, distance will format in cm/m/km, angle with an appended degree sign</param>
|
||||||
/// <returns>the formatted string</returns>
|
/// <returns>the formatted string</returns>
|
||||||
public static string FormatFloat(double value, ValueCategory category)
|
public static string FormatFloat(double value, FlaxEngine.Utils.ValueCategory category)
|
||||||
{
|
{
|
||||||
switch (category)
|
switch (category)
|
||||||
{
|
{
|
||||||
case ValueCategory.Distance:
|
case FlaxEngine.Utils.ValueCategory.Distance:
|
||||||
var absValue = Mathf.Abs(value);
|
var absValue = Mathf.Abs(value);
|
||||||
// in case a unit != cm this would be (value / Maters2Units * 100)
|
// in case a unit != cm this would be (value / Maters2Units * 100)
|
||||||
if (absValue < Units.Meters2Units)
|
if (absValue < Units.Meters2Units)
|
||||||
@@ -1224,8 +1214,8 @@ namespace FlaxEditor.Utilities
|
|||||||
if (absValue < Units.Meters2Units * 1000)
|
if (absValue < Units.Meters2Units * 1000)
|
||||||
return (value / Units.Meters2Units).ToString("g17", CultureInfo.InvariantCulture) + "m";
|
return (value / Units.Meters2Units).ToString("g17", CultureInfo.InvariantCulture) + "m";
|
||||||
return (value / 1000 / Units.Meters2Units).ToString("g17", CultureInfo.InvariantCulture) + "km";
|
return (value / 1000 / Units.Meters2Units).ToString("g17", CultureInfo.InvariantCulture) + "km";
|
||||||
case ValueCategory.Angle: return value.ToString("g17", CultureInfo.InvariantCulture) + "°";
|
case FlaxEngine.Utils.ValueCategory.Angle: return value.ToString("g17", CultureInfo.InvariantCulture) + "°";
|
||||||
case ValueCategory.None:
|
case FlaxEngine.Utils.ValueCategory.None:
|
||||||
default:
|
default:
|
||||||
return FormatFloat(value);
|
return FormatFloat(value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,23 +11,23 @@ namespace FlaxEngine
|
|||||||
/// <seealso cref="System.Attribute" />
|
/// <seealso cref="System.Attribute" />
|
||||||
[Serializable]
|
[Serializable]
|
||||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
|
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
|
||||||
public sealed class ValueCategoryAttribute : Attribute
|
public sealed class NumberCategoryAttribute : Attribute
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The value category used for formatting.
|
/// The value category used for formatting.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public FlaxEditor.Utilities.Utils.ValueCategory Category;
|
public Utils.ValueCategory Category;
|
||||||
|
|
||||||
private ValueCategoryAttribute()
|
private NumberCategoryAttribute()
|
||||||
{
|
{
|
||||||
Category = FlaxEditor.Utilities.Utils.ValueCategory.None;
|
Category = Utils.ValueCategory.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="ValueCategoryAttribute"/> class.
|
/// Initializes a new instance of the <see cref="NumberCategoryAttribute"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="category">The value category.</param>
|
/// <param name="category">The value category.</param>
|
||||||
public ValueCategoryAttribute(FlaxEditor.Utilities.Utils.ValueCategory category)
|
public NumberCategoryAttribute(Utils.ValueCategory category)
|
||||||
{
|
{
|
||||||
Category = category;
|
Category = category;
|
||||||
}
|
}
|
||||||
@@ -1038,5 +1038,15 @@ namespace FlaxEngine
|
|||||||
parameterTypes = Array.Empty<Type>();
|
parameterTypes = Array.Empty<Type>();
|
||||||
return parameterTypes;
|
return parameterTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A category of number values used for formatting and input boxes
|
||||||
|
/// </summary>
|
||||||
|
public enum ValueCategory
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
Distance,
|
||||||
|
Angle
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user