Merge remote-tracking branch 'origin/gi' into large-worlds

# Conflicts:
#	Source/Engine/Core/Math/Vector3.h
This commit is contained in:
Wojtek Figat
2022-05-21 19:45:13 +02:00
280 changed files with 7660 additions and 2355 deletions

View File

@@ -4,7 +4,6 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using FlaxEditor.CustomEditors.Editors;
using FlaxEditor.Scripting;
using FlaxEngine;
@@ -13,8 +12,6 @@ namespace FlaxEditor.CustomEditors
{
internal static class CustomEditorsUtil
{
private static readonly StringBuilder CachedSb = new StringBuilder(256);
internal static readonly Dictionary<Type, string> InBuildTypeNames = new Dictionary<Type, string>()
{
{ typeof(bool), "bool" },
@@ -46,51 +43,6 @@ namespace FlaxEditor.CustomEditors
return result;
}
/// <summary>
/// Gets the property name for UI. Removes unnecessary characters and filters text. Makes it more user-friendly.
/// </summary>
/// <param name="name">The name.</param>
/// <returns>The result.</returns>
public static string GetPropertyNameUI(string name)
{
int length = name.Length;
StringBuilder sb = CachedSb;
sb.Clear();
sb.EnsureCapacity(length + 8);
int startIndex = 0;
// Skip some prefixes
if (name.StartsWith("g_") || name.StartsWith("m_"))
startIndex = 2;
// Filter text
for (int i = startIndex; i < length; i++)
{
var c = name[i];
// Space before word starting with uppercase letter
if (char.IsUpper(c) && i > 0)
{
if (i + 1 < length && !char.IsUpper(name[i + 1]))
sb.Append(' ');
}
// Space instead of underscore
else if (c == '_')
{
if (sb.Length > 0)
sb.Append(' ');
continue;
}
// Space before digits sequence
else if (i > 1 && char.IsDigit(c) && !char.IsDigit(name[i - 1]))
sb.Append(' ');
sb.Append(c);
}
return sb.ToString();
}
internal static CustomEditor CreateEditor(ValueContainer values, CustomEditor overrideEditor, bool canUseRefPicker = true)
{
// Check if use provided editor

View File

@@ -209,13 +209,13 @@ namespace FlaxEditor.CustomEditors.Dedicated
if (editor is RemovedScriptDummy removed)
{
node.TextColor = Color.OrangeRed;
node.Text = CustomEditorsUtil.GetPropertyNameUI(removed.PrefabObject.GetType().Name);
node.Text = Utilities.Utils.GetPropertyNameUI(removed.PrefabObject.GetType().Name);
}
// Actor or Script
else if (editor.Values[0] is SceneObject sceneObject)
{
node.TextColor = sceneObject.HasPrefabLink ? FlaxEngine.GUI.Style.Current.ProgressNormal : FlaxEngine.GUI.Style.Current.BackgroundSelected;
node.Text = CustomEditorsUtil.GetPropertyNameUI(sceneObject.GetType().Name);
node.Text = Utilities.Utils.GetPropertyNameUI(sceneObject.GetType().Name);
}
// Array Item
else if (editor.ParentEditor?.Values?.Type.IsArray ?? false)
@@ -225,7 +225,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
// Common type
else if (editor.Values.Info != ScriptMemberInfo.Null)
{
node.Text = CustomEditorsUtil.GetPropertyNameUI(editor.Values.Info.Name);
node.Text = Utilities.Utils.GetPropertyNameUI(editor.Values.Info.Name);
}
// Custom type
else if (editor.Values[0] != null)

View File

@@ -26,6 +26,26 @@ namespace FlaxEditor.CustomEditors.Dedicated
}
}
private object ParameterGet(object instance, GraphParameter parameter, object tag)
{
if (instance is ParticleEffect particleEffect && particleEffect && parameter && tag is ParticleEffectParameter effectParameter)
return particleEffect.GetParameterValue(effectParameter.TrackName, parameter.Name);
return null;
}
private void ParameterSet(object instance, object value, GraphParameter parameter, object tag)
{
if (instance is ParticleEffect particleEffect && particleEffect && parameter && tag is ParticleEffectParameter effectParameter)
particleEffect.SetParameterValue(effectParameter.TrackName, parameter.Name, value);
}
private object ParameterDefaultValue(object instance, GraphParameter parameter, object tag)
{
if (tag is ParticleEffectParameter effectParameter)
return effectParameter.DefaultValue;
return null;
}
/// <inheritdoc />
public override void Initialize(LayoutElementsContainer layout)
{
@@ -48,11 +68,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
group.Panel.Open(false);
var data = SurfaceUtils.InitGraphParameters(parametersGroup);
SurfaceUtils.DisplayGraphParameters(group, data,
(instance, parameter, tag) => ((ParticleEffect)instance).GetParameterValue(trackName, parameter.Name),
(instance, value, parameter, tag) => ((ParticleEffect)instance).SetParameterValue(trackName, parameter.Name, value),
Values,
(instance, parameter, tag) => ((ParticleEffectParameter)tag).DefaultValue);
SurfaceUtils.DisplayGraphParameters(group, data, ParameterGet, ParameterSet, Values, ParameterDefaultValue);
}
}

View File

@@ -273,7 +273,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
cm.AddItem(item);
}
cm.ItemClicked += item => action((string)item.Tag);
cm.SortChildren();
cm.SortItems();
cm.Show(button.Parent, button.BottomLeft);
}

View File

@@ -71,7 +71,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
cm.AddItem(new TypeSearchPopup.TypeItemView(scripts[i]));
}
cm.ItemClicked += item => AddScript((ScriptType)item.Tag);
cm.SortChildren();
cm.SortItems();
cm.Show(this, button.BottomLeft);
}
@@ -611,7 +611,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
var editor = CustomEditorsUtil.CreateEditor(scriptType, false);
// Create group
var title = CustomEditorsUtil.GetPropertyNameUI(scriptType.Name);
var title = Utilities.Utils.GetPropertyNameUI(scriptType.Name);
var group = layout.Group(title, editor);
if ((Presenter.Features & FeatureFlags.CacheExpandedGroups) != 0)
{

View File

@@ -32,7 +32,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
if (_presets != value)
{
_presets = value;
TooltipText = CustomEditorsUtil.GetPropertyNameUI(_presets.ToString());
TooltipText = Utilities.Utils.GetPropertyNameUI(_presets.ToString());
}
}
}
@@ -642,7 +642,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
cm.AddItem(new TypeSearchPopup.TypeItemView(controlTypes[i]));
}
cm.ItemClicked += controlType => SetType((ScriptType)controlType.Tag);
cm.SortChildren();
cm.SortItems();
cm.Show(button.Parent, button.BottomLeft);
}

View File

@@ -1,5 +1,6 @@
// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved.
using System;
using System.Linq;
using FlaxEditor.CustomEditors.Elements;
using FlaxEngine;
@@ -66,7 +67,13 @@ namespace FlaxEditor.CustomEditors.Editors
}
else
{
_element.Value = (double)Values[0];
var value = Values[0];
if (value is double asDouble)
_element.Value = (float)asDouble;
else if (value is float asFloat)
_element.Value = asFloat;
else
throw new Exception(string.Format("Invalid value type {0}.", value?.GetType().ToString() ?? "<null>"));
}
}
}

View File

@@ -137,7 +137,7 @@ namespace FlaxEditor.CustomEditors.Editors
ExpandGroups = attributes.FirstOrDefault(x => x is ExpandGroupsAttribute) != null;
IsReadOnly |= !info.HasSet;
DisplayName = Display?.Name ?? CustomEditorsUtil.GetPropertyNameUI(info.Name);
DisplayName = Display?.Name ?? Utilities.Utils.GetPropertyNameUI(info.Name);
var editor = Editor.Instance;
TooltipText = editor.CodeDocs.GetTooltip(info, attributes);
_membersOrder = editor.Options.Options.General.ScriptMembersOrder;
@@ -229,6 +229,7 @@ namespace FlaxEditor.CustomEditors.Editors
}
}
private static HashSet<PropertiesList> _visibleIfPropertiesListsCache;
private VisibleIfCache[] _visibleIfCaches;
private bool _isNull;
@@ -761,8 +762,13 @@ namespace FlaxEditor.CustomEditors.Editors
if (_visibleIfCaches != null)
{
if (_visibleIfPropertiesListsCache == null)
_visibleIfPropertiesListsCache = new HashSet<PropertiesList>();
else
_visibleIfPropertiesListsCache.Clear();
try
{
// Update VisibleIf rules
for (int i = 0; i < _visibleIfCaches.Length; i++)
{
ref var c = ref _visibleIfCaches[i];
@@ -798,6 +804,21 @@ namespace FlaxEditor.CustomEditors.Editors
{
c.Group.Panel.Visible = visible;
}
if (c.PropertiesList != null)
_visibleIfPropertiesListsCache.Add(c.PropertiesList.Properties);
}
// Hide properties lists with all labels being hidden
foreach (var propertiesList in _visibleIfPropertiesListsCache)
{
propertiesList.Visible = propertiesList.Children.Any(c => c.Visible);
}
// Hide group panels with all properties lists hidden
foreach (var propertiesList in _visibleIfPropertiesListsCache)
{
if (propertiesList.Parent is DropPanel dropPanel)
dropPanel.Visible = propertiesList.Visible || !dropPanel.Children.All(c => c is PropertiesList && !c.Visible);
}
}
catch (Exception ex)

View File

@@ -16,26 +16,6 @@ namespace FlaxEditor.CustomEditors.Elements
/// </summary>
public readonly Button Button = new Button();
/// <summary>
/// Initializes the element.
/// </summary>
/// <param name="text">The text.</param>
public void Init(string text)
{
Button.Text = text;
}
/// <summary>
/// Initializes the element.
/// </summary>
/// <param name="text">The text.</param>
/// <param name="color">The color.</param>
public void Init(string text, Color color)
{
Button.Text = text;
Button.SetColors(color);
}
/// <inheritdoc />
public override Control Control => Button;
}

View File

@@ -1,5 +1,8 @@
// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved.
using System;
using FlaxEditor.GUI;
using FlaxEditor.GUI.ContextMenu;
using FlaxEngine;
using FlaxEngine.GUI;
@@ -11,23 +14,49 @@ namespace FlaxEditor.CustomEditors.Elements
/// <seealso cref="FlaxEditor.CustomEditors.LayoutElement" />
public class LabelElement : LayoutElement
{
private Action<ContextMenu> _customContextualOptions;
/// <summary>
/// The label.
/// </summary>
public readonly Label Label;
public readonly ClickableLabel Label;
/// <summary>
/// Initializes a new instance of the <see cref="CheckBoxElement"/> class.
/// </summary>
public LabelElement()
{
Label = new Label(0, 0, 100, 18)
Label = new ClickableLabel
{
HorizontalAlignment = TextAlignment.Near
Size = new Vector2(100, 18),
HorizontalAlignment = TextAlignment.Near,
};
// TODO: auto height for label
}
/// <summary>
/// Adds a simple context menu with utility to copy label text. Can be extended with more options.
/// </summary>
public LabelElement AddCopyContextMenu(Action<ContextMenu> customOptions = null)
{
Label.RightClick += OnRightClick;
_customContextualOptions = customOptions;
return this;
}
private void OnRightClick()
{
var menu = new ContextMenu();
menu.AddButton("Copy text").Clicked += OnCopyText;
_customContextualOptions?.Invoke(menu);
menu.Show(Label, Label.PointFromScreen(Input.MouseScreenPosition));
}
private void OnCopyText()
{
Clipboard.Text = Label.Text;
}
/// <inheritdoc />
public override Control Control => Label;
}

View File

@@ -133,11 +133,13 @@ namespace FlaxEditor.CustomEditors
/// Adds new button element.
/// </summary>
/// <param name="text">The text.</param>
/// <param name="tooltip">The tooltip text.</param>
/// <returns>The created element.</returns>
public ButtonElement Button(string text)
public ButtonElement Button(string text, string tooltip = null)
{
var element = new ButtonElement();
element.Init(text);
element.Button.Text = text;
element.Button.TooltipText = tooltip;
OnAddElement(element);
return element;
}
@@ -147,11 +149,14 @@ namespace FlaxEditor.CustomEditors
/// </summary>
/// <param name="text">The text.</param>
/// <param name="color">The color.</param>
/// <param name="tooltip">The tooltip text.</param>
/// <returns>The created element.</returns>
public ButtonElement Button(string text, Color color)
public ButtonElement Button(string text, Color color, string tooltip = null)
{
ButtonElement element = new ButtonElement();
element.Init(text, color);
element.Button.Text = text;
element.Button.TooltipText = tooltip;
element.Button.SetColors(color);
OnAddElement(element);
return element;
}