Merge remote-tracking branch 'origin/master' into gi

This commit is contained in:
Wojciech Figat
2022-04-21 12:57:08 +02:00
78 changed files with 604 additions and 311 deletions

View File

@@ -689,6 +689,30 @@ namespace FlaxEditor.Content.GUI
return base.OnKeyDown(key);
}
/// <inheritdoc />
public override bool OnCharInput(char c)
{
if (base.OnCharInput(c))
return true;
if (char.IsLetterOrDigit(c) && _items.Count != 0)
{
// Jump to the item starting with this character
c = char.ToLowerInvariant(c);
for (int i = 0; i < _items.Count; i++)
{
var name = _items[i].ShortName;
if (!string.IsNullOrEmpty(name) && char.ToLowerInvariant(name[0]) == c)
{
Select(_items[i]);
break;
}
}
}
return false;
}
/// <inheritdoc />
protected override void PerformLayoutBeforeChildren()
{

View File

@@ -29,7 +29,7 @@ namespace FlaxEditor.CustomEditors
/// Enables using prefab-related features of the properties editor (eg. revert to prefab option).
/// </summary>
UsePrefab = 1 << 1,
/// <summary>
/// Enables using default-value-related features of the properties editor (eg. revert to default option).
/// </summary>
@@ -88,7 +88,6 @@ namespace FlaxEditor.CustomEditors
/// <seealso cref="FlaxEditor.CustomEditors.SyncPointEditor" />
protected class RootEditor : SyncPointEditor
{
private readonly string _noSelectionText;
private CustomEditor _overrideEditor;
/// <summary>
@@ -109,13 +108,18 @@ namespace FlaxEditor.CustomEditors
}
}
/// <summary>
/// The text to show when no object is selected.
/// </summary>
public string NoSelectionText;
/// <summary>
/// Initializes a new instance of the <see cref="RootEditor"/> class.
/// </summary>
/// <param name="noSelectionText">The text to show when no item is selected.</param>
public RootEditor(string noSelectionText)
{
_noSelectionText = noSelectionText ?? "No selection";
NoSelectionText = noSelectionText ?? "No selection";
}
/// <summary>
@@ -154,7 +158,7 @@ namespace FlaxEditor.CustomEditors
}
else
{
var label = layout.Label(_noSelectionText, TextAlignment.Center);
var label = layout.Label(NoSelectionText, TextAlignment.Center);
label.Label.Height = 20.0f;
}
@@ -251,6 +255,20 @@ namespace FlaxEditor.CustomEditors
/// </summary>
public object Owner;
/// <summary>
/// Gets or sets the text to show when no object is selected.
/// </summary>
public string NoSelectionText
{
get => Editor.NoSelectionText;
set
{
Editor.NoSelectionText = value;
if (SelectionCount == 0)
BuildLayoutOnUpdate();
}
}
private bool _buildOnUpdate;
/// <summary>

View File

@@ -49,10 +49,10 @@ namespace FlaxEditor.CustomEditors.Dedicated
Parent = this,
Bounds = new Rectangle((Width - addScriptButtonWidth) / 2, 1, addScriptButtonWidth, 18),
};
addScriptButton.ButtonClicked += AddScriptButtonOnClicked;
addScriptButton.ButtonClicked += OnAddScriptButtonClicked;
}
private void AddScriptButtonOnClicked(Button button)
private void OnAddScriptButtonClicked(Button button)
{
var scripts = Editor.Instance.CodeEditing.Scripts.Get();
if (scripts.Count == 0)

View File

@@ -716,7 +716,7 @@ namespace FlaxEditor.CustomEditors.Editors
// Header
if (item.Header != null)
itemLayout.Header(item.Header.Text);
itemLayout.Header(item.Header);
try
{

View File

@@ -279,6 +279,16 @@ namespace FlaxEditor.CustomEditors
return element;
}
internal LabelElement Header(HeaderAttribute header)
{
var element = Header(header.Text);
if (header.FontSize != -1)
element.Label.Font = new FontReference(element.Label.Font.Font, header.FontSize);
if (header.Color != 0)
element.Label.TextColor = Color.FromRGBA(header.Color);
return element;
}
/// <summary>
/// Adds new text box element.
/// </summary>

View File

@@ -258,6 +258,24 @@ namespace FlaxEditor.Surface.Archetypes
NodeElementArchetype.Factory.Output(0, string.Empty, null, 1)
}
},
new NodeArchetype
{
TypeID = 14,
Title = "Array Add Unique",
Description = "Adds the unique item to the array (to the end). Does nothing it specified item was already added.",
Flags = NodeFlags.VisualScriptGraph | NodeFlags.AnimGraph,
Size = new Vector2(170, 40),
ConnectionsHints = ConnectionsHint.Array,
IndependentBoxes = new int[] { 0 },
DependentBoxes = new int[] { 1, 2 },
DependentBoxFilter = GetArrayItemType,
Elements = new[]
{
NodeElementArchetype.Factory.Input(0, "Array", true, null, 0),
NodeElementArchetype.Factory.Input(1, "Item", true, typeof(object), 1),
NodeElementArchetype.Factory.Output(0, string.Empty, null, 2)
}
},
// first 100 IDs reserved for arrays
};
}

View File

@@ -192,7 +192,7 @@ namespace FlaxEditor.Surface.Archetypes
GetBox(MaterialNodeBoxes.SubsurfaceColor).Enabled = false;
break;
}
default: throw new ArgumentOutOfRangeException();
default: throw new ArgumentOutOfRangeException();
}
}
@@ -807,7 +807,26 @@ namespace FlaxEditor.Surface.Archetypes
NodeElementArchetype.Factory.Input(0, "RGB", true, typeof(Vector3), 0, 0),
NodeElementArchetype.Factory.Output(0, "HSV", typeof(Vector3), 1),
}
}
},
new NodeArchetype
{
TypeID = 38,
Title = "Custom Global Code",
Description = "Custom global HLSL shader code expression (placed before material shader code). Can contain includes to shader utilities or declare functions to reuse later.",
Flags = NodeFlags.MaterialGraph,
Size = new Vector2(300, 220),
DefaultValues = new object[]
{
"// Here you can add HLSL code\nfloat4 GetCustomColor()\n{\n\treturn float4(1, 0, 0, 1);\n}",
true,
},
Elements = new[]
{
NodeElementArchetype.Factory.Bool(0, 0, 1),
NodeElementArchetype.Factory.Text(20, 0, "Enabled"),
NodeElementArchetype.Factory.TextBox(0, 20, 300, 200, 0),
}
},
};
}
}

View File

@@ -317,7 +317,7 @@ namespace FlaxEditor.Surface
// Header
if (e.Header != null)
itemLayout.Header(e.Header.Text);
itemLayout.Header(e.Header);
// Values container
var valueType = new ScriptType(e.Type);

View File

@@ -410,7 +410,7 @@ namespace FlaxEditor.Surface
// Header
var header = (HeaderAttribute)attributes.FirstOrDefault(x => x is HeaderAttribute);
if (header != null)
itemLayout.Header(header.Text);
itemLayout.Header(header);
var propertyValue = new CustomValueContainer
(

View File

@@ -1,5 +1,6 @@
// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved.
using System;
using FlaxEditor.Content;
using FlaxEditor.CustomEditors;
using FlaxEditor.GUI;
@@ -106,13 +107,36 @@ namespace FlaxEditor.Windows.Assets
/// <inheritdoc />
protected override void OnAssetLoaded()
{
_object = Asset.CreateInstance();
_object = Asset.Instance;
if (_object == null)
{
// Hint developer about cause of failure
var dataTypeName = Asset.DataTypeName;
var type = Type.GetType(dataTypeName);
if (type != null)
{
try
{
var obj = Activator.CreateInstance(type);
var data = Asset.Data;
FlaxEngine.Json.JsonSerializer.Deserialize(obj, data);
}
catch (Exception ex)
{
_presenter.NoSelectionText = "Failed to load asset. See log for more. " + ex.Message.Replace('\n', ' ');
}
}
else
{
_presenter.NoSelectionText = string.Format("Missing type '{0}'.", dataTypeName);
}
}
_presenter.Select(_object);
_undo.Clear();
ClearEditedFlag();
// Auto-close on scripting reload if json asset is from game scripts (it might be reloaded)
if (_object != null && FlaxEngine.Scripting.IsTypeFromGameScripts(_object.GetType()) && !_isRegisteredForScriptsReload)
if ((_object == null || FlaxEngine.Scripting.IsTypeFromGameScripts(_object.GetType())) && !_isRegisteredForScriptsReload)
{
_isRegisteredForScriptsReload = true;
ScriptsBuilder.ScriptsReloadBegin += OnScriptsReloadBegin;
@@ -121,6 +145,14 @@ namespace FlaxEditor.Windows.Assets
base.OnAssetLoaded();
}
/// <inheritdoc />
protected override void OnAssetLoadFailed()
{
_presenter.NoSelectionText = "Failed to load the asset.";
base.OnAssetLoadFailed();
}
/// <inheritdoc />
public override void OnItemReimported(ContentItem item)
{

View File

@@ -77,6 +77,10 @@ namespace FlaxEditor.Windows.Assets
[EditorOrder(200), DefaultValue(true), EditorDisplay("Transparency"), Tooltip("Enables reflections when rendering material.")]
public bool EnableReflections;
[VisibleIf(nameof(EnableReflections))]
[EditorOrder(210), DefaultValue(false), EditorDisplay("Transparency"), Tooltip("Enables Screen Space Reflections when rendering material.")]
public bool EnableScreenSpaceReflections;
[EditorOrder(210), DefaultValue(true), EditorDisplay("Transparency"), Tooltip("Enables fog effects when rendering material.")]
public bool EnableFog;
@@ -142,6 +146,7 @@ namespace FlaxEditor.Windows.Assets
DepthTest = (info.FeaturesFlags & MaterialFeaturesFlags.DisableDepthTest) == 0;
DepthWrite = (info.FeaturesFlags & MaterialFeaturesFlags.DisableDepthWrite) == 0;
EnableReflections = (info.FeaturesFlags & MaterialFeaturesFlags.DisableReflections) == 0;
EnableScreenSpaceReflections = (info.FeaturesFlags & MaterialFeaturesFlags.ScreenSpaceReflections) != 0;
EnableFog = (info.FeaturesFlags & MaterialFeaturesFlags.DisableFog) == 0;
EnableDistortion = (info.FeaturesFlags & MaterialFeaturesFlags.DisableDistortion) == 0;
PixelNormalOffsetRefraction = (info.FeaturesFlags & MaterialFeaturesFlags.PixelNormalOffsetRefraction) != 0;
@@ -177,6 +182,8 @@ namespace FlaxEditor.Windows.Assets
info.FeaturesFlags |= MaterialFeaturesFlags.DisableDepthWrite;
if (!EnableReflections)
info.FeaturesFlags |= MaterialFeaturesFlags.DisableReflections;
if (EnableScreenSpaceReflections)
info.FeaturesFlags |= MaterialFeaturesFlags.ScreenSpaceReflections;
if (!EnableFog)
info.FeaturesFlags |= MaterialFeaturesFlags.DisableFog;
if (!EnableDistortion)