rename attribute and fix parsing
This commit is contained in:
@@ -4,7 +4,7 @@ using System;
|
||||
using System.Linq;
|
||||
using FlaxEditor.CustomEditors.Elements;
|
||||
using FlaxEngine;
|
||||
using Utils = FlaxEditor.Utilities.Utils;
|
||||
using Utils = FlaxEngine.Utils;
|
||||
|
||||
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
|
||||
var attributes = Values.GetAttributes();
|
||||
var categoryAttribute = attributes.FirstOrDefault(x => x is ValueCategoryAttribute);
|
||||
var valueCategory = ((ValueCategoryAttribute)categoryAttribute)?.Category ?? Utils.ValueCategory.None;
|
||||
var categoryAttribute = attributes.FirstOrDefault(x => x is NumberCategoryAttribute);
|
||||
var valueCategory = ((NumberCategoryAttribute)categoryAttribute)?.Category ?? Utils.ValueCategory.None;
|
||||
if (attributes != null)
|
||||
{
|
||||
var limit = attributes.FirstOrDefault(x => x is LimitAttribute);
|
||||
|
||||
@@ -4,7 +4,7 @@ using System;
|
||||
using System.Linq;
|
||||
using FlaxEditor.CustomEditors.Elements;
|
||||
using FlaxEngine;
|
||||
using Utils = FlaxEditor.Utilities.Utils;
|
||||
using Utils = FlaxEngine.Utils;
|
||||
|
||||
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
|
||||
var attributes = Values.GetAttributes();
|
||||
var categoryAttribute = attributes.FirstOrDefault(x => x is ValueCategoryAttribute);
|
||||
var valueCategory = ((ValueCategoryAttribute)categoryAttribute)?.Category ?? Utils.ValueCategory.None;
|
||||
var categoryAttribute = attributes.FirstOrDefault(x => x is NumberCategoryAttribute);
|
||||
var valueCategory = ((NumberCategoryAttribute)categoryAttribute)?.Category ?? Utils.ValueCategory.None;
|
||||
if (attributes != null)
|
||||
{
|
||||
var range = attributes.FirstOrDefault(x => x is RangeAttribute);
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.Linq;
|
||||
using FlaxEditor.CustomEditors.Elements;
|
||||
using FlaxEngine;
|
||||
using FlaxEngine.GUI;
|
||||
using Utils = FlaxEditor.Utilities.Utils;
|
||||
using Utils = FlaxEngine.Utils;
|
||||
|
||||
namespace FlaxEditor.CustomEditors.Editors
|
||||
{
|
||||
@@ -75,7 +75,7 @@ namespace FlaxEditor.CustomEditors.Editors
|
||||
if (attributes != null)
|
||||
{
|
||||
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)
|
||||
category = categoryAttribute.Category;
|
||||
}
|
||||
@@ -261,7 +261,7 @@ namespace FlaxEditor.CustomEditors.Editors
|
||||
if (attributes != null)
|
||||
{
|
||||
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)
|
||||
category = categoryAttribute.Category;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ using System.Reflection;
|
||||
using FlaxEditor.GUI.Input;
|
||||
using FlaxEngine;
|
||||
using FlaxEngine.GUI;
|
||||
using Utils = FlaxEditor.Utilities.Utils;
|
||||
using Utils = FlaxEngine.Utils;
|
||||
|
||||
namespace FlaxEditor.CustomEditors.Elements
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@ using System.Reflection;
|
||||
using FlaxEditor.GUI.Input;
|
||||
using FlaxEngine;
|
||||
using FlaxEngine.GUI;
|
||||
using Utils = FlaxEditor.Utilities.Utils;
|
||||
using Utils = FlaxEngine.Utils;
|
||||
|
||||
namespace FlaxEditor.CustomEditors.Elements
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
using System;
|
||||
using FlaxEditor.Utilities;
|
||||
using FlaxEngine;
|
||||
using Utils = FlaxEditor.Utilities.Utils;
|
||||
using Utils = FlaxEngine.Utils;
|
||||
|
||||
namespace FlaxEditor.GUI.Input
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@ using System;
|
||||
using System.Globalization;
|
||||
using FlaxEditor.Utilities;
|
||||
using FlaxEngine;
|
||||
using Utils = FlaxEditor.Utilities.Utils;
|
||||
using Utils = FlaxEngine.Utils;
|
||||
|
||||
namespace FlaxEditor.GUI.Input
|
||||
{
|
||||
|
||||
@@ -243,6 +243,11 @@ namespace FlaxEditor.Utilities
|
||||
}
|
||||
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
|
||||
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
|
||||
if (stack.Count > 1)
|
||||
{
|
||||
var stackContent = string.Join(",", stack.ToList());
|
||||
Debug.Log($"parsing numbers, stack is {stackContent}");
|
||||
var v1 = stack.Pop();
|
||||
Debug.Log($"first on stack: {v1}");
|
||||
while (stack.Count > 0)
|
||||
v1 *= stack.Pop();
|
||||
return v1;
|
||||
|
||||
@@ -58,16 +58,6 @@ namespace FlaxEditor.Utilities
|
||||
/// </summary>
|
||||
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>
|
||||
/// 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.
|
||||
@@ -1187,11 +1177,11 @@ namespace FlaxEditor.Utilities
|
||||
/// <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>
|
||||
/// <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)
|
||||
{
|
||||
case ValueCategory.Distance:
|
||||
case FlaxEngine.Utils.ValueCategory.Distance:
|
||||
var absValue = Mathf.Abs(value);
|
||||
// in case a unit != cm this would be (value / Maters2Units * 100)
|
||||
if (absValue < Units.Meters2Units)
|
||||
@@ -1199,8 +1189,8 @@ namespace FlaxEditor.Utilities
|
||||
if (absValue < Units.Meters2Units * 1000)
|
||||
return (value / Units.Meters2Units).ToString("g7", CultureInfo.InvariantCulture) + "m";
|
||||
return (value / 1000 / Units.Meters2Units).ToString("g7", CultureInfo.InvariantCulture) + "km";
|
||||
case ValueCategory.Angle: return value.ToString("g7", CultureInfo.InvariantCulture) + "°";
|
||||
case ValueCategory.None:
|
||||
case FlaxEngine.Utils.ValueCategory.Angle: return value.ToString("g7", CultureInfo.InvariantCulture) + "°";
|
||||
case FlaxEngine.Utils.ValueCategory.None:
|
||||
default:
|
||||
return FormatFloat(value);
|
||||
}
|
||||
@@ -1212,11 +1202,11 @@ namespace FlaxEditor.Utilities
|
||||
/// <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>
|
||||
/// <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)
|
||||
{
|
||||
case ValueCategory.Distance:
|
||||
case FlaxEngine.Utils.ValueCategory.Distance:
|
||||
var absValue = Mathf.Abs(value);
|
||||
// in case a unit != cm this would be (value / Maters2Units * 100)
|
||||
if (absValue < Units.Meters2Units)
|
||||
@@ -1224,8 +1214,8 @@ namespace FlaxEditor.Utilities
|
||||
if (absValue < Units.Meters2Units * 1000)
|
||||
return (value / Units.Meters2Units).ToString("g17", CultureInfo.InvariantCulture) + "m";
|
||||
return (value / 1000 / Units.Meters2Units).ToString("g17", CultureInfo.InvariantCulture) + "km";
|
||||
case ValueCategory.Angle: return value.ToString("g17", CultureInfo.InvariantCulture) + "°";
|
||||
case ValueCategory.None:
|
||||
case FlaxEngine.Utils.ValueCategory.Angle: return value.ToString("g17", CultureInfo.InvariantCulture) + "°";
|
||||
case FlaxEngine.Utils.ValueCategory.None:
|
||||
default:
|
||||
return FormatFloat(value);
|
||||
}
|
||||
|
||||
@@ -11,23 +11,23 @@ namespace FlaxEngine
|
||||
/// <seealso cref="System.Attribute" />
|
||||
[Serializable]
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
|
||||
public sealed class ValueCategoryAttribute : Attribute
|
||||
public sealed class NumberCategoryAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// The value category used for formatting.
|
||||
/// </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>
|
||||
/// Initializes a new instance of the <see cref="ValueCategoryAttribute"/> class.
|
||||
/// Initializes a new instance of the <see cref="NumberCategoryAttribute"/> class.
|
||||
/// </summary>
|
||||
/// <param name="category">The value category.</param>
|
||||
public ValueCategoryAttribute(FlaxEditor.Utilities.Utils.ValueCategory category)
|
||||
public NumberCategoryAttribute(Utils.ValueCategory category)
|
||||
{
|
||||
Category = category;
|
||||
}
|
||||
@@ -1038,5 +1038,15 @@ namespace FlaxEngine
|
||||
parameterTypes = Array.Empty<Type>();
|
||||
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