add named terrain layers

This commit is contained in:
xxSeys1
2024-10-25 15:30:54 +02:00
parent 425382f7d2
commit a0aee15267
4 changed files with 72 additions and 2 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

@@ -1,6 +1,7 @@
// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;
using FlaxEngine;
@@ -30,6 +31,29 @@ 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()
{
string[] layerNames = GameSettings.Load<LayersAndTagsSettings>().TerrainLayers.ToArray();
for (int i = 0; i < layerNames.Length; i++)
{
if (string.IsNullOrEmpty(layerNames[i]))
layerNames[i] = $"Terrain Layer {i}";
}
return layerNames;
}
[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);