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/Editor/Tools/Terrain/PaintTerrainGizmoMode.cs b/Source/Editor/Tools/Terrain/PaintTerrainGizmoMode.cs index 0be0fe41c..f9cf12fc1 100644 --- a/Source/Editor/Tools/Terrain/PaintTerrainGizmoMode.cs +++ b/Source/Editor/Tools/Terrain/PaintTerrainGizmoMode.cs @@ -21,21 +21,6 @@ namespace FlaxEditor.Tools.Terrain [HideInEditor] public class PaintTerrainGizmoMode : EditorGizmoMode { - /// - /// The terrain layer names. - /// - 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; diff --git a/Source/Engine/Core/Config/LayersAndTagsSettings.cs b/Source/Engine/Core/Config/LayersAndTagsSettings.cs index 9346efee7..4086ec657 100644 --- a/Source/Engine/Core/Config/LayersAndTagsSettings.cs +++ b/Source/Engine/Core/Config/LayersAndTagsSettings.cs @@ -16,7 +16,7 @@ namespace FlaxEditor.Content.Settings public List Tags = new List(); /// - /// The layers names. + /// The layer names. /// [EditorOrder(10), EditorDisplay("Layers", EditorDisplayAttribute.InlineStyle), Collection(CanResize = false, Display = CollectionAttribute.DisplayType.Inline)] public string[] Layers = new string[32]; @@ -30,6 +30,31 @@ namespace FlaxEditor.Content.Settings return GetCurrentLayers(out int _); } + /// + /// The layer 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() + { +#if FLAX_TESTS + return System.Array.Empty(); +#else + string[] layerNames = GameSettings.Load().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);