diff --git a/Source/Editor/CustomEditors/Editors/TerrainLayerEditor.cs b/Source/Editor/CustomEditors/Editors/TerrainLayerEditor.cs new file mode 100644 index 000000000..6e6f876b0 --- /dev/null +++ b/Source/Editor/CustomEditors/Editors/TerrainLayerEditor.cs @@ -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 +{ + /// + /// 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. + /// + public sealed class TerrainLayerEditor : CustomEditor + { + private ComboBoxElement element; + + /// + public override DisplayStyle Style => DisplayStyle.Inline; + + /// + 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); + } + + /// + public override void Refresh() + { + base.Refresh(); + + element.ComboBox.SelectedIndex = (int)Values[0]; + } + } +} diff --git a/Source/Editor/Surface/Archetypes/Material.cs b/Source/Editor/Surface/Archetypes/Material.cs index f1da861c1..9da0ec067 100644 --- a/Source/Editor/Surface/Archetypes/Material.cs +++ b/Source/Editor/Surface/Archetypes/Material.cs @@ -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), } }, diff --git a/Source/Editor/Tools/Terrain/Paint/SingleLayerMode.cs b/Source/Editor/Tools/Terrain/Paint/SingleLayerMode.cs index 5581eeb66..9cf550f5c 100644 --- a/Source/Editor/Tools/Terrain/Paint/SingleLayerMode.cs +++ b/Source/Editor/Tools/Terrain/Paint/SingleLayerMode.cs @@ -60,7 +60,7 @@ namespace FlaxEditor.Tools.Terrain.Paint /// /// The layer to paint with it. /// - [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; /// diff --git a/Source/Engine/Core/Config/LayersAndTagsSettings.cs b/Source/Engine/Core/Config/LayersAndTagsSettings.cs index 9346efee7..ddee29e88 100644 --- a/Source/Engine/Core/Config/LayersAndTagsSettings.cs +++ b/Source/Engine/Core/Config/LayersAndTagsSettings.cs @@ -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 _); } + /// + /// The layers names. + /// + [EditorOrder(10), EditorDisplay("Terrain Layers", EditorDisplayAttribute.InlineStyle), Collection(CanResize = false, Display = CollectionAttribute.DisplayType.Inline)] + public string[] TerrainLayers = new string[8]; + + /// + /// Gets the current terrain layer names. Returns "Layer" + index for layers without a name. + /// + /// The layer names. + public static string[] GetCurrentTerrainLayers() + { + string[] layerNames = GameSettings.Load().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);