Merge branch 'TerrainLayerNames' of https://github.com/xxSeys1/FlaxEngine into xxSeys1-TerrainLayerNames

This commit is contained in:
Wojtek Figat
2024-11-26 15:59:01 +01:00
5 changed files with 75 additions and 17 deletions

View File

@@ -0,0 +1,45 @@
// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
using FlaxEditor.Content.Settings;
using FlaxEditor.CustomEditors.Elements;
using FlaxEditor.GUI;
namespace FlaxEditor.CustomEditors.Editors
{
/// <summary>
/// Custom editor for picking terrain layers. Instead of choosing bit mask or layer index it shows a combo box with simple layer picking by name.
/// </summary>
public sealed class TerrainLayerEditor : CustomEditor
{
private ComboBoxElement element;
/// <inheritdoc />
public override DisplayStyle Style => DisplayStyle.Inline;
/// <inheritdoc />
public override void Initialize(LayoutElementsContainer layout)
{
element = layout.ComboBox();
element.ComboBox.SetItems(LayersAndTagsSettings.GetCurrentTerrainLayers());
element.ComboBox.SelectedIndex = (int)Values[0];
element.ComboBox.SelectedIndexChanged += OnSelectedIndexChanged;
}
private void OnSelectedIndexChanged(ComboBox comboBox)
{
int value = comboBox.SelectedIndex;
if (value == -1)
value = 0;
SetValue(value);
}
/// <inheritdoc />
public override void Refresh()
{
base.Refresh();
element.ComboBox.SelectedIndex = (int)Values[0];
}
}
}

View File

@@ -1,6 +1,7 @@
// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
using System;
using FlaxEditor.Content.Settings;
using FlaxEditor.Scripting;
using FlaxEditor.Surface.Elements;
using FlaxEditor.Windows.Assets;
@@ -590,7 +591,7 @@ namespace FlaxEditor.Surface.Archetypes
},
Elements = new[]
{
NodeElementArchetype.Factory.ComboBox(0, 0, 70.0f, 0, FlaxEditor.Tools.Terrain.PaintTerrainGizmoMode.TerrainLayerNames),
NodeElementArchetype.Factory.ComboBox(0, 0, 70.0f, 0, LayersAndTagsSettings.GetCurrentTerrainLayers()),
NodeElementArchetype.Factory.Output(0, "", typeof(float), 0),
}
},

View File

@@ -60,7 +60,7 @@ namespace FlaxEditor.Tools.Terrain.Paint
/// <summary>
/// The layer to paint with it.
/// </summary>
[EditorOrder(10), Tooltip("The layer to paint with it. Terrain material can access per-layer blend weight to perform materials or textures blending.")]
[EditorOrder(10), Tooltip("The layer to paint on. Terrain material can access a per-layer blend weight to perform material or texture blending."), CustomEditorAlias("FlaxEditor.CustomEditors.Editors.TerrainLayerEditor")]
public Layers Layer = Layers.Layer0;
/// <inheritdoc />

View File

@@ -21,21 +21,6 @@ namespace FlaxEditor.Tools.Terrain
[HideInEditor]
public class PaintTerrainGizmoMode : EditorGizmoMode
{
/// <summary>
/// The terrain layer names.
/// </summary>
public static readonly string[] TerrainLayerNames =
{
"Layer 0",
"Layer 1",
"Layer 2",
"Layer 3",
"Layer 4",
"Layer 5",
"Layer 6",
"Layer 7",
};
private struct SplatmapData
{
public IntPtr DataPtr;

View File

@@ -30,6 +30,33 @@ namespace FlaxEditor.Content.Settings
return GetCurrentLayers(out int _);
}
/// <summary>
/// The layers names.
/// </summary>
[EditorOrder(10), EditorDisplay("Terrain Layers", EditorDisplayAttribute.InlineStyle), Collection(CanResize = false, Display = CollectionAttribute.DisplayType.Inline)]
public string[] TerrainLayers = new string[8];
/// <summary>
/// Gets the current terrain layer names. Returns "Layer" + index for layers without a name.
/// </summary>
/// <returns>The layer names.</returns>
public static string[] GetCurrentTerrainLayers()
{
#if FLAX_TESTS
return System.Array.Empty<string>();
#else
string[] layerNames = GameSettings.Load<LayersAndTagsSettings>().TerrainLayers;
for (int i = 0; i < layerNames.Length; i++)
{
if (string.IsNullOrEmpty(layerNames[i]))
layerNames[i] = $"Layer {i}";
}
return layerNames;
#endif
}
[LibraryImport("FlaxEngine", EntryPoint = "LayersAndTagsSettingsInternal_GetCurrentLayers", StringMarshalling = StringMarshalling.Custom, StringMarshallingCustomType = typeof(FlaxEngine.Interop.StringMarshaller))]
[return: MarshalUsing(typeof(FlaxEngine.Interop.ArrayMarshaller<,>), CountElementName = "layerCount")]
internal static partial string[] GetCurrentLayers(out int layerCount);