Пример #1
0
                public virtual void OnNotAvailableLayout(LayoutElementsContainer layout)
                {
                    layout.Label("Missing platform data tools for the target platform.", TextAlignment.Center);
                    if (FlaxEditor.Editor.IsOfficialBuild())
                    {
                        switch (BuildPlatform)
                        {
                        case BuildPlatform.Windows32:
                        case BuildPlatform.Windows64:
                        case BuildPlatform.UWPx86:
                        case BuildPlatform.UWPx64:
                        case BuildPlatform.LinuxX64:
                        case BuildPlatform.AndroidARM64:
                            layout.Label("Use Flax Launcher and download the required package.", TextAlignment.Center);
                            break;

                        default:
                            layout.Label("Engine source is required to target this platform.", TextAlignment.Center);
                            break;
                        }
                    }
                    else
                    {
                        var label = layout.Label("To target this platform separate engine source package is required.\nTo get access please contact via https://flaxengine.com/contact", TextAlignment.Center);
                        label.Label.AutoHeight = true;
                    }
                }
Пример #2
0
        public override void Initialize(LayoutElementsContainer layout)
        {
            DevAccount devAccount = ToolAuthentication.LoadLastSignedInUser();

            layout.Header("Account");
            if (devAccount != null)
            {
                layout.Label("Username: "******"Id: " + devAccount.Id);
                layout.Label("Type: " + devAccount.AccountType);
            }

            else
            {
                layout.Label("Not logged in");
            }

            layout.Header("Sandbox");

            var sb    = layout.TextBox();
            var setSb = layout.Button("Set Sandbox");

            setSb.Button.Clicked += () => SandboxHelper.SetSandbox(sb.Text);
            var retail = layout.Button("Switch to retail");

            setSb.Button.Clicked += () => SandboxHelper.SetSandbox("RETAIL");
        }
Пример #3
0
            public override void Initialize(LayoutElementsContainer layout)
            {
                _proxy = (PropertiesProxy)Values[0];
                if (_proxy?.DefaultValues == null)
                {
                    layout.Label("Loading...", TextAlignment.Center);
                    return;
                }

                var isPlayModeActive = _proxy.Window.Editor.StateMachine.IsPlayMode;

                if (isPlayModeActive)
                {
                    layout.Label("Play mode is active. Editing runtime values.", TextAlignment.Center);
                    layout.Space(10);

                    foreach (var e in _proxy.DefaultValues)
                    {
                        var name           = e.Key;
                        var value          = _proxy.Asset.GetValue(name);
                        var valueContainer = new VariableValueContainer(_proxy, name, value, false);
                        var propertyLabel  = new PropertyNameLabel(name)
                        {
                            Tag = name,
                        };
                        string tooltip = null;
                        if (_proxy.DefaultValues.TryGetValue(name, out var defaultValue))
                        {
                            tooltip = "Default value: " + defaultValue;
                        }
                        layout.Object(propertyLabel, valueContainer, null, tooltip);
                    }
                }
                else
                {
                    foreach (var e in _proxy.DefaultValues)
                    {
                        var name           = e.Key;
                        var value          = e.Value;
                        var valueContainer = new VariableValueContainer(_proxy, name, value, true);
                        var propertyLabel  = new ClickablePropertyNameLabel(name)
                        {
                            Tag = name,
                        };
                        propertyLabel.MouseLeftDoubleClick += (label, location) => StartParameterRenaming(name, label);
                        propertyLabel.SetupContextMenu     += OnPropertyLabelSetupContextMenu;
                        layout.Object(propertyLabel, valueContainer, null, "Type: " + CustomEditorsUtil.GetTypeNameUI(value.GetType()));
                    }

                    // TODO: improve the UI
                    layout.Space(40);
                    var addParamType = layout.ComboBox().ComboBox;
                    addParamType.Items         = AllowedTypes.Select(CustomEditorsUtil.GetTypeNameUI).ToList();
                    addParamType.SelectedIndex = 0;
                    _addParamType = addParamType;
                    var addParamButton = layout.Button("Add").Button;
                    addParamButton.Clicked += OnAddParamButtonClicked;
                }
            }
 public virtual void OnNotAvailableLayout(LayoutElementsContainer layout)
 {
     layout.Label("Missing platform data tools for the target platform.", TextAlignment.Center);
     if (FlaxEditor.Editor.IsDevInstance())
     {
         layout.Label("Build engine for this platform.", TextAlignment.Center);
     }
     else
     {
         layout.Label("Use Flax Launcher and download the required package.", TextAlignment.Center);
     }
 }
Пример #5
0
                public override void Initialize(LayoutElementsContainer layout)
                {
                    var proxy = (BuildTabProxy)Values[0];

                    _platform = proxy.Selector.Selected;
                    var platformObj = proxy.PerPlatformOptions[_platform];

                    if (!platformObj.IsSupported)
                    {
                        layout.Label("This platform is not supported on this system.", TextAlignment.Center);
                    }
                    else if (platformObj.IsAvailable)
                    {
                        string name;
                        switch (_platform)
                        {
                        case PlatformType.Windows:
                            name = "Windows";
                            break;

                        case PlatformType.XboxOne:
                            name = "Xbox One";
                            break;

                        case PlatformType.UWP:
                            name = "Windows Store";
                            break;

                        case PlatformType.Linux:
                            name = "Linux";
                            break;

                        case PlatformType.PS4:
                            name = "PlayStation 4";
                            break;

                        case PlatformType.XboxScarlett:
                            name = "Xbox Scarlett";
                            break;

                        case PlatformType.Android:
                            name = "Android";
                            break;

                        default:
                            name = CustomEditorsUtil.GetPropertyNameUI(_platform.ToString());
                            break;
                        }
                        var group = layout.Group(name);

                        group.Object(new ReadOnlyValueContainer(platformObj));

                        _buildButton          = layout.Button("Build").Button;
                        _buildButton.Clicked += OnBuildClicked;
                    }
                    else
                    {
                        platformObj.OnNotAvailableLayout(layout);
                    }
                }
Пример #6
0
            /// <inheritdoc />
            public override void Initialize(LayoutElementsContainer layout)
            {
                _infoLabel = layout.Label("Editor restart is required to apply style changes.", TextAlignment.Center);
                _infoLabel.Label.Visible = false;

                base.Initialize(layout);
            }
Пример #7
0
                public override void Initialize(LayoutElementsContainer layout)
                {
                    var window = ((PropertiesProxy)Values[0])._window;

                    if (window == null)
                    {
                        layout.Label("Loading...", TextAlignment.Center);
                        return;
                    }

                    // Audio properties
                    {
                        var audio = window.Asset;
                        AudioClip.AudioDataInfo info;
                        audio.GetInfo(out info);
                        int originalSize, importedSize;
                        Editor.Internal_GetAudioClipMetadata(audio.unmanagedPtr, out originalSize, out importedSize);

                        var group = layout.Group("General");
                        group.Label("Format: " + audio.Format);
                        group.Label("Length: " + (Mathf.CeilToInt(audio.Length * 100.0f) / 100.0f) + "s");
                        group.Label(string.Format("{0}kHz, channels: {1}, bit depth: {2}", info.SampleRate / 1000, info.NumChannels, info.BitDepth));
                        group.Label("Original size: " + Utilities.Utils.FormatBytesCount((ulong)originalSize));
                        group.Label("Imported size: " + Utilities.Utils.FormatBytesCount((ulong)importedSize));
                        group.Label("Compression ratio: " + Mathf.CeilToInt((float)importedSize / originalSize * 100.0f) + "%");
                    }

                    base.Initialize(layout);

                    layout.Space(10);
                    var reimportButton = layout.Button("Reimport");

                    reimportButton.Button.Clicked += () => ((PropertiesProxy)Values[0]).Reimport();
                }
Пример #8
0
            public override void Initialize(LayoutElementsContainer layout)
            {
                layout.Label("Scene Animation Rendering Utility", TextAlignment.Center);
                layout.Space(10.0f);

                base.Initialize(layout);
            }
Пример #9
0
                public override void Initialize(LayoutElementsContainer layout)
                {
                    var window = ((PropertiesProxy)Values[0])._window;

                    if (window == null)
                    {
                        layout.Label("Loading...", TextAlignment.Center);
                        return;
                    }

                    // Texture properties
                    {
                        var texture = window.Asset;

                        var group = layout.Group("General");
                        group.Label("Format: " + texture.Format);
                        group.Label(string.Format("Size: {0}x{1}", texture.Width, texture.Height));
                        group.Label("Mip levels: " + texture.MipLevels);
                        group.Label("Memory usage: " + Utilities.Utils.FormatBytesCount(texture.TotalMemoryUsage));
                    }

                    base.Initialize(layout);

                    layout.Space(10);
                    var reimportButton = layout.Button("Reimport");

                    reimportButton.Button.Clicked += () => ((PropertiesProxy)Values[0]).Reimport();
                }
Пример #10
0
        /// <inheritdoc />
        public override void Initialize(LayoutElementsContainer layout)
        {
            // Set control type button
            var   space = layout.Space(20);
            float setTypeButtonWidth = 60.0f;
            var   setTypeButton      = new Button((layout.ContainerControl.Width - setTypeButtonWidth) / 2, 1, setTypeButtonWidth, 18)
            {
                TooltipText = "Sets the control to the given type",
                AnchorStyle = AnchorStyle.UpperCenter,
                Text        = "Set Type",
                Parent      = space.Spacer
            };

            setTypeButton.ButtonClicked += OnSetTypeButtonClicked;

            // Don't show editor if any control is invalid
            if (Values.HasNull)
            {
                var label = layout.Label("Select control type to create", TextAlignment.Center);
                label.Label.Enabled = false;
                return;
            }

            // Add control type helper label
            {
                var type  = Values[0].GetType();
                var label = layout.AddPropertyItem("Type", "The type of the created control.");
                label.Label(type.FullName);
            }

            // Show control properties
            base.Initialize(layout);
        }
Пример #11
0
        /// <inheritdoc />
        public override void Initialize(LayoutElementsContainer layout)
        {
            _readOnly        = false;
            _canReorderItems = true;
            _notNullItems    = false;

            // No support for different collections for now
            if (HasDifferentValues || HasDifferentTypes)
            {
                return;
            }

            var type = Values.Type;
            var size = Count;

            // Try get MemberCollectionAttribute for collection editor meta
            var attributes = Values.GetAttributes();

            if (attributes != null)
            {
                var memberCollection = (MemberCollectionAttribute)attributes.FirstOrDefault(x => x is MemberCollectionAttribute);
                if (memberCollection != null)
                {
                    // TODO: handle ReadOnly and NotNullItems by filtering child editors SetValue
                    // TODO: handle CanReorderItems

                    _readOnly        = memberCollection.ReadOnly;
                    _canReorderItems = memberCollection.CanReorderItems;
                    _notNullItems    = memberCollection.NotNullItems;
                }
            }

            // Size
            if (_readOnly)
            {
                layout.Label("Size", size.ToString());
            }
            else
            {
                _size = layout.IntegerValue("Size");
                _size.IntValue.MinValue      = 0;
                _size.IntValue.MaxValue      = ushort.MaxValue;
                _size.IntValue.Value         = size;
                _size.IntValue.ValueChanged += OnSizeChanged;
            }

            // Elements
            if (size > 0)
            {
                var elementType = ElementType;
                for (int i = 0; i < size; i++)
                {
                    layout.Object("Element " + i, new ListValueContainer(elementType, i, Values));
                }
            }
            _elementsCount = size;
        }
Пример #12
0
                /// <inheritdoc />
                public override void Initialize(LayoutElementsContainer layout)
                {
                    var proxy = (PropertiesProxy)Values[0];

                    if (proxy.Asset == null || !proxy.Asset.IsLoaded)
                    {
                        layout.Label("Loading...");
                        return;
                    }

                    base.Initialize(layout);
                }
Пример #13
0
        /// <inheritdoc />
        public override void Initialize(LayoutElementsContainer layout)
        {
            _labels.Clear();

            base.Initialize(layout);

            // Add info box
            if (IsSingleObject && Values[0] is RigidBody && Editor.IsPlayMode)
            {
                _infoLabel            = layout.Label(string.Empty).Label;
                _infoLabel.AutoHeight = true;
            }
        }
Пример #14
0
        private void ShowJoin()
        {
            _layout.ContainerControl.DisposeChildren();
            //_layout.ContainerControl.AnchorStyle = AnchorStyle.Upper;
            EditingSessionPlugin.Instance.SessionState = EditingSessionPlugin.State.Join;
            _layout.ClearLayout();
            _layout.Space(5);
            var label         = _layout.Label("Joining Session", TextAlignment.Center);
            var fontReference = label.Label.Font;

            fontReference.Size = 11;
            label.Label.Font   = fontReference;
            _layout.Space(5);

            var clientSettingsEditor = new CustomEditorPresenter(null);

            clientSettingsEditor.Panel.Parent = _layout.ContainerControl;
            clientSettingsEditor.Select(_clientSettings);

            var button       = _layout.Button("Join");
            var returnButton = _layout.Button("Return");

            button.Button.Clicked += async() =>
            {
                button.Button.Enabled = false;
                var  session   = new ClientSession();
                bool connected = await session.Start(_clientSettings);

                button.Button.Enabled = true;
                if (connected)
                {
                    EditingSessionPlugin.Instance.Session = session;
                    ShowSession();
                }
            };

            returnButton.Button.Clicked += () => ShowNoSession();
        }
Пример #15
0
            public override void Initialize(LayoutElementsContainer layout)
            {
                var window  = ((PropertiesProxy)Values[0])._window;
                var texture = window?.Asset;

                if (texture == null || !texture.IsLoaded)
                {
                    layout.Label("Loading...", TextAlignment.Center);
                    return;
                }

                // Texture info
                var general = layout.Group("General");

                general.Label("Format: " + texture.Format);
                general.Label(string.Format("Size: {0}x{1}", texture.Width, texture.Height));
                general.Label("Mip levels: " + texture.MipLevels);
                general.Label("Memory usage: " + Utilities.Utils.FormatBytesCount(texture.TotalMemoryUsage));

                // Texture properties
                var properties   = layout.Group("Properties");
                var textureGroup = new CustomValueContainer(new ScriptType(typeof(int)), texture.TextureGroup,
                                                            (instance, index) => texture.TextureGroup,
                                                            (instance, index, value) =>
                {
                    texture.TextureGroup = (int)value;
                    window.MarkAsEdited();
                });

                properties.Property("Texture Group", textureGroup, new TextureGroupEditor(), "The texture group used by this texture.");

                // Import settings
                base.Initialize(layout);

                // Reimport
                layout.Space(10);
                var reimportButton = layout.Button("Reimport");

                reimportButton.Button.Clicked += () => ((PropertiesProxy)Values[0]).Reimport();
            }
Пример #16
0
                /// <inheritdoc />
                public override void Initialize(LayoutElementsContainer layout)
                {
                    var proxy = (PropertiesProxy)Values[0];

                    if (proxy.Asset == null || !proxy.Asset.IsLoaded)
                    {
                        layout.Label("Loading...");
                        return;
                    }

                    base.Initialize(layout);

                    // General properties
                    {
                        var group = layout.Group("General");

                        Animation.Info info;
                        proxy.Asset.GetInfo(out info);
                        group.Label("Length: " + info.Length + "s");
                        group.Label("Frames: " + info.FramesCount);
                        group.Label("Chanels: " + info.ChannelsCount);
                        group.Label("Keyframes: " + info.KeyframesCount);
                    }

                    // Import Settings
                    {
                        var group = layout.Group("Import Settings");

                        var importSettingsField  = typeof(PropertiesProxy).GetField("ImportSettings", BindingFlags.NonPublic | BindingFlags.Instance);
                        var importSettingsValues = new ValueContainer(importSettingsField)
                        {
                            proxy.ImportSettings
                        };
                        group.Object(importSettingsValues);

                        layout.Space(5);
                        var reimportButton = group.Button("Reimport");
                        reimportButton.Button.Clicked += () => ((PropertiesProxy)Values[0]).Reimport();
                    }
                }
Пример #17
0
        /// <inheritdoc />
        public override void Initialize(LayoutElementsContainer layout)
        {
            var layers = LayersAndTagsSettings.GetCurrentLayers();

            if (layers == null || layers.Length == 0)
            {
                layout.Label("Missing layers and tags settings");
                return;
            }

            _checkBoxes = new CheckBox[layers.Length];
            for (int i = 0; i < layers.Length; i++)
            {
                var layer    = layers[i];
                var property = layout.AddPropertyItem(layer);
                var checkbox = property.Checkbox().CheckBox;
                UpdateCheckbox(checkbox, i);
                checkbox.Tag           = i;
                checkbox.StateChanged += OnCheckboxStateChanged;
                _checkBoxes[i]         = checkbox;
            }
        }
Пример #18
0
        /// <inheritdoc />
        public override void Initialize(LayoutElementsContainer layout)
        {
            var settings = GameSettings.Load <NavigationSettings>();

            if (settings.NavMeshes == null || settings.NavMeshes.Length == 0)
            {
                layout.Label("Missing navmesh settings");
                return;
            }

            _checkBoxes = new CheckBox[settings.NavMeshes.Length];
            for (int i = 0; i < settings.NavMeshes.Length; i++)
            {
                ref var navmesh  = ref settings.NavMeshes[i];
                var     property = layout.AddPropertyItem(navmesh.Name, navmesh.Agent.ToString());
                property.Labels.Last().TextColorHighlighted = navmesh.Color;
                var checkbox = property.Checkbox().CheckBox;
                UpdateCheckbox(checkbox, i);
                checkbox.Tag           = i;
                checkbox.StateChanged += OnCheckboxStateChanged;
                _checkBoxes[i]         = checkbox;
            }
Пример #19
0
        /// <inheritdoc />
        public override void Initialize(LayoutElementsContainer layout)
        {
            base.Initialize(layout);

            // Add info box
            if (IsSingleObject && Values[0] is Terrain terrain)
            {
                var    patchesCount = terrain.PatchesCount;
                var    chunkSize    = terrain.ChunkSize;
                var    resolution   = terrain.Scale;
                var    totalSize    = terrain.Box.Size;
                string text         = string.Format("Patches: {0}\nTotal Chunks: {1}\nChunk Size: {2}\nResolution: {3}m x {4}m\nTotal size: {5}km x {6}km",
                                                    patchesCount,
                                                    patchesCount * 16,
                                                    chunkSize,
                                                    1.0f / (resolution.X + 1e-9f),
                                                    1.0f / (resolution.Z + 1e-9f),
                                                    totalSize.X * 0.00001f,
                                                    totalSize.Z * 0.00001f
                                                    );
                var label = layout.Label(text);
                label.Label.AutoHeight = true;
            }
        }
Пример #20
0
        /// <inheritdoc />
        public override void Initialize(LayoutElementsContainer layout)
        {
            // Collect items to edit
            List <ItemInfo> items;

            if (!HasDiffrentTypes)
            {
                var value = Values[0];
                if (value == null)
                {
                    layout.Label("<null>");
                    return;
                }

                items = GetItemsForType(value.GetType());
            }
            else
            {
                var types = ValuesTypes;
                items = new List <ItemInfo>(GetItemsForType(types[0]));
                for (int i = 1; i < types.Length && items.Count > 0; i++)
                {
                    var otherItems = GetItemsForType(types[i]);

                    // Merge items
                    for (int j = 0; j < items.Count && items.Count > 0; j++)
                    {
                        bool isInvalid = true;
                        for (int k = 0; k < otherItems.Count; k++)
                        {
                            var a = items[j];
                            var b = otherItems[k];

                            if (ItemInfo.CanMerge(a, b))
                            {
                                isInvalid = false;
                                break;
                            }
                        }

                        if (isInvalid)
                        {
                            items.RemoveAt(j--);
                        }
                    }
                }
            }

            // Sort items
            items.Sort();

            // Add items
            GroupElement lastGroup = null;

            for (int i = 0; i < items.Count; i++)
            {
                var item = items[i];

                // Check if use group
                LayoutElementsContainer itemLayout;
                if (item.UseGroup)
                {
                    if (lastGroup == null || lastGroup.Panel.Name != item.Display.Group)
                    {
                        lastGroup = layout.Group(item.Display.Group);
                    }
                    itemLayout = lastGroup;
                }
                else
                {
                    lastGroup  = null;
                    itemLayout = layout;
                }

                // Space
                if (item.Space != null)
                {
                    itemLayout.Space(item.Space.Height);
                }

                // Header
                if (item.Header != null)
                {
                    itemLayout.Header(item.Header.Text);
                }

                // Peek values
                ValueContainer itemValues;
                try
                {
                    itemValues = item.GetValues(Values);
                }
                catch (Exception ex)
                {
                    Editor.LogWarning("Failed to get object values for item " + item);
                    Editor.LogWarning(ex.Message);
                    Editor.LogWarning(ex.StackTrace);
                    return;
                }

                // Spawn property editor
                SpawnProperty(itemLayout, itemValues, item);
            }
        }
Пример #21
0
        /// <inheritdoc />
        public override void Initialize(LayoutElementsContainer layout)
        {
            _visibleIfCaches = null;

            // Collect items to edit
            List <ItemInfo> items;

            if (!HasDifferentTypes)
            {
                var value = Values[0];
                if (value == null)
                {
                    // Check if it's an object type that can be created in editor
                    var type = Values.Type;
                    if (type != null && type.GetConstructor(Type.EmptyTypes) != null)
                    {
                        layout = layout.Space(20);

                        const float ButtonSize = 14.0f;
                        var         button     = new Button
                        {
                            Text        = "+",
                            TooltipText = "Create a new instance of the object",
                            Height      = ButtonSize,
                            Width       = ButtonSize,
                            X           = layout.ContainerControl.Width - ButtonSize - 4,
                            AnchorStyle = AnchorStyle.CenterRight,
                            Parent      = layout.ContainerControl
                        };
                        button.Clicked += () =>
                        {
                            var newType = Values.Type;
                            SetValue(Activator.CreateInstance(newType));
                            RebuildLayoutOnRefresh();
                        };
                    }

                    layout.Label("<null>");
                    return;
                }

                items = GetItemsForType(value.GetType());
            }
            else
            {
                var types = ValuesTypes;
                items = new List <ItemInfo>(GetItemsForType(types[0]));
                for (int i = 1; i < types.Length && items.Count > 0; i++)
                {
                    var otherItems = GetItemsForType(types[i]);

                    // Merge items
                    for (int j = 0; j < items.Count && items.Count > 0; j++)
                    {
                        bool isInvalid = true;
                        for (int k = 0; k < otherItems.Count; k++)
                        {
                            var a = items[j];
                            var b = otherItems[k];

                            if (ItemInfo.CanMerge(a, b))
                            {
                                isInvalid = false;
                                break;
                            }
                        }

                        if (isInvalid)
                        {
                            items.RemoveAt(j--);
                        }
                    }
                }
            }

            // Sort items
            items.Sort();

            // Add items
            GroupElement lastGroup = null;

            for (int i = 0; i < items.Count; i++)
            {
                var item = items[i];

                // Check if use group
                LayoutElementsContainer itemLayout;
                if (item.UseGroup)
                {
                    if (lastGroup == null || lastGroup.Panel.HeaderText != item.Display.Group)
                    {
                        lastGroup = layout.Group(item.Display.Group);
                    }
                    itemLayout = lastGroup;
                }
                else
                {
                    lastGroup  = null;
                    itemLayout = layout;
                }

                // Space
                if (item.Space != null)
                {
                    itemLayout.Space(item.Space.Height);
                }

                // Header
                if (item.Header != null)
                {
                    itemLayout.Header(item.Header.Text);
                }

                // Peek values
                ValueContainer itemValues;
                try
                {
                    itemValues = item.GetValues(Values);
                }
                catch (Exception ex)
                {
                    Editor.LogWarning("Failed to get object values for item " + item);
                    Editor.LogWarning(ex.Message);
                    Editor.LogWarning(ex.StackTrace);
                    return;
                }

                // Spawn property editor
                SpawnProperty(itemLayout, itemValues, item);

                // Expand all parent groups if need to
                if (item.ExpandGroups)
                {
                    var c = itemLayout.ContainerControl;
                    do
                    {
                        if (c is DropPanel dropPanel)
                        {
                            dropPanel.Open(false);
                        }
                        else if (c is CustomEditorPresenter.PresenterPanel)
                        {
                            break;
                        }
                        c = c.Parent;
                    } while (c != null);
                }
            }
        }
Пример #22
0
 public virtual void OnNotAvailableLayout(LayoutElementsContainer layout)
 {
     layout.Label("Missing platform data tools for the target platform.", TextAlignment.Center);
     layout.Label("Use Flax Launcher and download the required package.", TextAlignment.Center);
 }
Пример #23
0
        /// <inheritdoc />
        public override void Initialize(LayoutElementsContainer layout)
        {
            var window = Values[0] as IVisjectSurfaceWindow;
            var asset  = window?.VisjectAsset;

            if (asset == null)
            {
                layout.Label("No parameters");
                return;
            }
            if (asset.LastLoadFailed)
            {
                layout.Label("Failed to load asset");
                return;
            }
            if (!asset.IsLoaded)
            {
                layout.Label("Loading...");
                return;
            }
            var          parameters = window.VisjectSurface.Parameters;
            GroupElement lastGroup  = null;

            for (int i = 0; i < parameters.Count; i++)
            {
                var p = parameters[i];
                if (!p.IsPublic)
                {
                    continue;
                }

                var pIndex     = i;
                var pValue     = p.Value;
                var attributes = p.Meta.GetAttributes();
                if (attributes == null || attributes.Length == 0)
                {
                    attributes = DefaultAttributes;
                }
                var itemLayout = layout;
                var name       = p.Name;

                // Editor Display
                var editorDisplay = (EditorDisplayAttribute)attributes.FirstOrDefault(x => x is EditorDisplayAttribute);
                if (editorDisplay?.Group != null)
                {
                    if (lastGroup == null || lastGroup.Panel.HeaderText != editorDisplay.Group)
                    {
                        lastGroup = layout.Group(editorDisplay.Group);
                        lastGroup.Panel.Open(false);
                    }
                    itemLayout = lastGroup;
                }
                else
                {
                    lastGroup  = null;
                    itemLayout = layout;
                }
                if (editorDisplay?.Name != null)
                {
                    name = editorDisplay.Name;
                }

                // Space
                var space = (SpaceAttribute)attributes.FirstOrDefault(x => x is SpaceAttribute);
                if (space != null)
                {
                    itemLayout.Space(space.Height);
                }

                // Header
                var header = (HeaderAttribute)attributes.FirstOrDefault(x => x is HeaderAttribute);
                if (header != null)
                {
                    itemLayout.Header(header.Text);
                }

                var propertyValue = new CustomValueContainer
                                    (
                    p.Type,
                    pValue,
                    (instance, index) => ((IVisjectSurfaceWindow)instance).GetParameter(pIndex),
                    (instance, index, value) => ((IVisjectSurfaceWindow)instance).SetParameter(pIndex, value),
                    attributes
                                    );

                var propertyLabel = new DraggablePropertyNameLabel(name)
                {
                    Tag  = pIndex,
                    Drag = OnDragParameter
                };
                var tooltip = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute);
                propertyLabel.MouseLeftDoubleClick += (label, location) => StartParameterRenaming(pIndex, label);
                propertyLabel.SetupContextMenu     += OnPropertyLabelSetupContextMenu;
                var property = itemLayout.AddPropertyItem(propertyLabel, tooltip?.Text);
                property.Object(propertyValue);
            }

            // Parameters creating
            var newParameterTypes = window.NewParameterTypes;

            if (newParameterTypes != null)
            {
                layout.Space(parameters.Count > 0 ? 10 : 4);
                var newParam = layout.Button("Add parameter...");
                newParam.Button.ButtonClicked += OnAddParameterButtonClicked;
                layout.Space(10);
            }
        }
Пример #24
0
        /// <inheritdoc />
        public override void Initialize(LayoutElementsContainer layout)
        {
            _readOnly     = false;
            _notNullItems = false;

            // No support for different collections for now
            if (HasDifferentValues || HasDifferentTypes)
            {
                return;
            }

            var type      = Values.Type;
            var size      = Count;
            var argTypes  = type.GetGenericArguments();
            var keyType   = argTypes[0];
            var valueType = argTypes[1];

            _canEditKeys = keyType == typeof(string) || keyType.IsPrimitive || keyType.IsEnum;

            // Try get CollectionAttribute for collection editor meta
            var   attributes         = Values.GetAttributes();
            Type  overrideEditorType = null;
            float spacing            = 0.0f;

            if (attributes != null)
            {
                var collection = (CollectionAttribute)attributes.FirstOrDefault(x => x is CollectionAttribute);
                if (collection != null)
                {
                    // TODO: handle ReadOnly and NotNullItems by filtering child editors SetValue

                    _readOnly          = collection.ReadOnly;
                    _notNullItems      = collection.NotNullItems;
                    overrideEditorType = TypeUtils.GetType(collection.OverrideEditorTypeName).Type;
                    spacing            = collection.Spacing;
                }
            }

            // Size
            if (_readOnly || !_canEditKeys)
            {
                layout.Label("Size", size.ToString());
            }
            else
            {
                _size = layout.IntegerValue("Size");
                _size.IntValue.MinValue      = 0;
                _size.IntValue.MaxValue      = ushort.MaxValue;
                _size.IntValue.Value         = size;
                _size.IntValue.ValueChanged += OnSizeChanged;
            }

            // Elements
            if (size > 0)
            {
                var keysEnumerable = ((IDictionary)Values[0]).Keys.OfType <object>();
                var keys           = keysEnumerable as object[] ?? keysEnumerable.ToArray();
                for (int i = 0; i < size; i++)
                {
                    if (i != 0 && spacing > 0f)
                    {
                        if (layout.Children.Count > 0 && layout.Children[layout.Children.Count - 1] is PropertiesListElement propertiesListElement)
                        {
                            if (propertiesListElement.Labels.Count > 0)
                            {
                                var label  = propertiesListElement.Labels[propertiesListElement.Labels.Count - 1];
                                var margin = label.Margin;
                                margin.Bottom += spacing;
                                label.Margin   = margin;
                            }
                            propertiesListElement.Space(spacing);
                        }
                        else
                        {
                            layout.Space(spacing);
                        }
                    }

                    var key            = keys.ElementAt(i);
                    var overrideEditor = overrideEditorType != null ? (CustomEditor)Activator.CreateInstance(overrideEditorType) : null;
                    layout.Object(new DictionaryItemLabel(this, key), new DictionaryValueContainer(new ScriptType(valueType), key, Values), overrideEditor);
                }
            }
            _elementsCount = size;

            // Add/Remove buttons
            if (!_readOnly && _canEditKeys)
            {
                var area      = layout.Space(20);
                var addButton = new Button(area.ContainerControl.Width - (16 + 16 + 2 + 2), 2, 16, 16)
                {
                    Text         = "+",
                    TooltipText  = "Add new item",
                    AnchorPreset = AnchorPresets.TopRight,
                    Parent       = area.ContainerControl
                };
                addButton.Clicked += () =>
                {
                    if (IsSetBlocked)
                    {
                        return;
                    }

                    Resize(Count + 1);
                };
                var removeButton = new Button(addButton.Right + 2, addButton.Y, 16, 16)
                {
                    Text         = "-",
                    TooltipText  = "Remove last item",
                    AnchorPreset = AnchorPresets.TopRight,
                    Parent       = area.ContainerControl,
                    Enabled      = size > 0
                };
                removeButton.Clicked += () =>
                {
                    if (IsSetBlocked)
                    {
                        return;
                    }

                    Resize(Count - 1);
                };
            }
        }
Пример #25
0
        /// <inheritdoc />
        public override void Initialize(LayoutElementsContainer layout)
        {
            _readOnly        = false;
            _canReorderItems = true;
            _notNullItems    = false;

            // No support for different collections for now
            if (HasDifferentValues || HasDifferentTypes)
            {
                return;
            }

            var size = Count;

            // Try get MemberCollectionAttribute for collection editor meta
            var attributes = Values.GetAttributes();

            if (attributes != null)
            {
                var memberCollection = (MemberCollectionAttribute)attributes.FirstOrDefault(x => x is MemberCollectionAttribute);
                if (memberCollection != null)
                {
                    // TODO: handle NotNullItems by filtering child editors SetValue

                    _readOnly        = memberCollection.ReadOnly;
                    _canReorderItems = memberCollection.CanReorderItems;
                    _notNullItems    = memberCollection.NotNullItems;
                }
            }

            // Size
            if (_readOnly)
            {
                layout.Label("Size", size.ToString());
            }
            else
            {
                _size = layout.IntegerValue("Size");
                _size.IntValue.MinValue      = 0;
                _size.IntValue.MaxValue      = ushort.MaxValue;
                _size.IntValue.Value         = size;
                _size.IntValue.ValueChanged += OnSizeChanged;
            }

            // Elements
            if (size > 0)
            {
                var elementType = ElementType;
                if (_canReorderItems)
                {
                    for (int i = 0; i < size; i++)
                    {
                        layout.Object(new CollectionItemLabel(this, i), new ListValueContainer(elementType, i, Values));
                    }
                }
                else
                {
                    for (int i = 0; i < size; i++)
                    {
                        layout.Object("Element " + i, new ListValueContainer(elementType, i, Values));
                    }
                }
            }
            _elementsCount = size;

            // Add/Remove buttons
            if (!_readOnly)
            {
                var area      = layout.Space(20);
                var addButton = new Button(area.ContainerControl.Width - (16 + 16 + 2 + 2), 2, 16, 16)
                {
                    Text        = "+",
                    TooltipText = "Add new item",
                    AnchorStyle = AnchorStyle.UpperRight,
                    Parent      = area.ContainerControl
                };
                addButton.Clicked += () =>
                {
                    if (IsSetBlocked)
                    {
                        return;
                    }

                    Resize(Count + 1);
                };
                var removeButton = new Button(addButton.Right + 2, addButton.Y, 16, 16)
                {
                    Text        = "-",
                    TooltipText = "Remove last item",
                    AnchorStyle = AnchorStyle.UpperRight,
                    Parent      = area.ContainerControl,
                    Enabled     = size > 0
                };
                removeButton.Clicked += () =>
                {
                    if (IsSetBlocked)
                    {
                        return;
                    }

                    Resize(Count - 1);
                };
            }
        }
Пример #26
0
                public override void Initialize(LayoutElementsContainer layout)
                {
                    var proxy = (SkeletonPropertiesProxy)Values[0];

                    if (proxy.Asset == null || !proxy.Asset.IsLoaded)
                    {
                        layout.Label("Loading...");
                        return;
                    }
                    var lods       = proxy.Asset.LODs;
                    var loadedLODs = proxy.Asset.LoadedLODs;
                    var nodes      = proxy.Asset.Nodes;
                    var bones      = proxy.Asset.Bones;

                    // Skeleton Bones
                    {
                        var group = layout.Group("Skeleton Bones");

                        var tree = group.Tree();
                        for (int i = 0; i < bones.Length; i++)
                        {
                            if (bones[i].ParentIndex == -1)
                            {
                                var node = tree.Node(nodes[bones[i].NodeIndex].Name);
                                BuildSkeletonBonesTree(nodes, bones, node, i);
                                node.TreeNode.ExpandAll(true);
                            }
                        }
                    }

                    // Skeleton Nodes
                    {
                        var group = layout.Group("Skeleton Nodes");

                        var tree = group.Tree();
                        for (int i = 0; i < nodes.Length; i++)
                        {
                            if (nodes[i].ParentIndex == -1)
                            {
                                var node = tree.Node(nodes[i].Name);
                                BuildSkeletonNodesTree(nodes, node, i);
                                node.TreeNode.ExpandAll(true);
                            }
                        }
                    }

                    // Blend Shapes
                    var blendShapes = proxy.Asset.BlendShapes;

                    if (blendShapes.Length != 0)
                    {
                        var group = layout.Group("Blend Shapes");
                        proxy.Window._preview.PreviewActor.ClearBlendShapeWeights();

                        for (int i = 0; i < blendShapes.Length; i++)
                        {
                            var blendShape = blendShapes[i];
                            var label      = new PropertyNameLabel(blendShape);
                            label.SetupContextMenu += (nameLabel, menu, linkedEditor) => { menu.AddButton("Copy name", () => Clipboard.Text = blendShape); };
                            var property = group.AddPropertyItem(label);
                            var editor   = property.FloatValue();
                            editor.FloatValue.Value         = 0.0f;
                            editor.FloatValue.MinValue      = -1;
                            editor.FloatValue.MaxValue      = 1;
                            editor.FloatValue.SlideSpeed    = 0.01f;
                            editor.FloatValue.ValueChanged += () => { proxy.Window._preview.PreviewActor.SetBlendShapeWeight(blendShape, editor.FloatValue.Value); };
                        }
                    }
                }
Пример #27
0
                public override void Initialize(LayoutElementsContainer layout)
                {
                    var proxy = (MeshesPropertiesProxy)Values[0];

                    if (proxy.Asset == null || !proxy.Asset.IsLoaded)
                    {
                        layout.Label("Loading...");
                        return;
                    }
                    proxy._materialSlotComboBoxes.Clear();
                    proxy._isolateCheckBoxes.Clear();
                    proxy._highlightCheckBoxes.Clear();
                    var lods       = proxy.Asset.LODs;
                    var loadedLODs = proxy.Asset.LoadedLODs;
                    var nodes      = proxy.Asset.Nodes;
                    var bones      = proxy.Asset.Bones;

                    // General properties
                    {
                        var group = layout.Group("General");

                        var minScreenSize = group.FloatValue("Min Screen Size", "The minimum screen size to draw model (the bottom limit). Used to cull small models. Set to 0 to disable this feature.");
                        minScreenSize.FloatValue.MinValue      = 0.0f;
                        minScreenSize.FloatValue.MaxValue      = 1.0f;
                        minScreenSize.FloatValue.Value         = proxy.Asset.MinScreenSize;
                        minScreenSize.FloatValue.ValueChanged += () =>
                        {
                            proxy.Asset.MinScreenSize = minScreenSize.FloatValue.Value;
                            proxy.Window.MarkAsEdited();
                        };
                    }

                    // Group per LOD
                    for (int lodIndex = 0; lodIndex < lods.Length; lodIndex++)
                    {
                        var group = layout.Group("LOD " + lodIndex);
                        if (lodIndex < lods.Length - loadedLODs)
                        {
                            group.Label("Loading LOD...");
                            continue;
                        }
                        var lod    = lods[lodIndex];
                        var meshes = lod.Meshes;

                        int triangleCount = 0, vertexCount = 0;
                        for (int meshIndex = 0; meshIndex < meshes.Length; meshIndex++)
                        {
                            var mesh = meshes[meshIndex];
                            triangleCount += mesh.TriangleCount;
                            vertexCount   += mesh.VertexCount;
                        }

                        group.Label(string.Format("Triangles: {0:N0}   Vertices: {1:N0}", triangleCount, vertexCount));
                        group.Label("Size: " + lod.Box.Size);
                        var screenSize = group.FloatValue("Screen Size", "The screen size to switch LODs. Bottom limit of the model screen size to render this LOD.");
                        screenSize.FloatValue.MinValue      = 0.0f;
                        screenSize.FloatValue.MaxValue      = 10.0f;
                        screenSize.FloatValue.Value         = lod.ScreenSize;
                        screenSize.FloatValue.ValueChanged += () =>
                        {
                            lod.ScreenSize = screenSize.FloatValue.Value;
                            proxy.Window.MarkAsEdited();
                        };

                        // Every mesh properties
                        for (int meshIndex = 0; meshIndex < meshes.Length; meshIndex++)
                        {
                            var mesh = meshes[meshIndex];
                            group.Label($"Mesh {meshIndex} (tris: {mesh.TriangleCount:N0}, verts: {mesh.VertexCount:N0})");

                            // Material Slot
                            var materialSlot = group.ComboBox("Material Slot", "Material slot used by this mesh during rendering");
                            materialSlot.ComboBox.Tag = mesh;
                            materialSlot.ComboBox.SelectedIndexChanged += comboBox => proxy.SetMaterialSlot((SkinnedMesh)comboBox.Tag, comboBox.SelectedIndex);
                            proxy._materialSlotComboBoxes.Add(materialSlot.ComboBox);

                            // Isolate
                            var isolate = group.Checkbox("Isolate", "Shows only this mesh (and meshes using the same material slot)");
                            isolate.CheckBox.Tag           = mesh;
                            isolate.CheckBox.StateChanged += (box) => proxy.SetIsolate(box.Checked ? (SkinnedMesh)box.Tag : null);
                            proxy._isolateCheckBoxes.Add(isolate.CheckBox);

                            // Highlight
                            var highlight = group.Checkbox("Highlight", "Highlights this mesh with a tint color (and meshes using the same material slot)");
                            highlight.CheckBox.Tag           = mesh;
                            highlight.CheckBox.StateChanged += (box) => proxy.SetHighlight(box.Checked ? (SkinnedMesh)box.Tag : null);
                            proxy._highlightCheckBoxes.Add(highlight.CheckBox);
                        }
                    }

                    // Refresh UI
                    proxy.UpdateMaterialSlotsUI();
                }
Пример #28
0
                /// <inheritdoc />
                public override void Initialize(LayoutElementsContainer layout)
                {
                    var materialWin = Values[0] as MaterialWindow;
                    var material    = materialWin?.Asset;

                    if (material == null)
                    {
                        _parametersHash = -1;
                        layout.Label("No parameters");
                        return;
                    }
                    if (!material.IsLoaded)
                    {
                        _parametersHash = -2;
                        layout.Label("Loading...");
                        return;
                    }
                    _parametersHash = material._parametersHash;
                    var parameters = material.Parameters;

                    for (int i = 0; i < parameters.Length; i++)
                    {
                        var p = parameters[i];
                        if (!p.IsPublic)
                        {
                            continue;
                        }

                        var  pIndex    = i;
                        var  pValue    = p.Value;
                        var  pGuidType = false;
                        Type pType;
                        switch (p.Type)
                        {
                        case MaterialParameterType.CubeTexture:
                            pType     = typeof(CubeTexture);
                            pGuidType = true;
                            break;

                        case MaterialParameterType.Texture:
                        case MaterialParameterType.NormalMap:
                            pType     = typeof(Texture);
                            pGuidType = true;
                            break;

                        case MaterialParameterType.RenderTarget:
                            pType     = typeof(RenderTarget);
                            pGuidType = true;
                            break;

                        default:
                            pType = p.Value.GetType();
                            break;
                        }

                        var propertyValue = new CustomValueContainer(
                            pType,
                            pValue,
                            (instance, index) =>
                        {
                            // Get material parameter
                            var win = (MaterialWindow)instance;
                            return(win.Asset.Parameters[pIndex].Value);
                        },
                            (instance, index, value) =>
                        {
                            // Set material parameter and surface parameter
                            var win = (MaterialWindow)instance;

                            // Visject surface paramaters are only value type objects so convert value if need to (eg. instead of texture ref write texture id)
                            var surfaceParam = value;
                            if (pGuidType)
                            {
                                surfaceParam = (value as FlaxEngine.Object)?.ID ?? Guid.Empty;
                            }

                            win.Asset.Parameters[pIndex].Value   = value;
                            win.Surface.Parameters[pIndex].Value = surfaceParam;
                            win._paramValueChange = true;
                        }
                            );

                        var propertyLabel = new DragablePropertyNameLabel(p.Name);
                        propertyLabel.Tag = pIndex;
                        propertyLabel.MouseLeftDoubleClick += (label, location) => StartParameterRenaming(pIndex, label);
                        propertyLabel.MouseRightClick      += (label, location) => ShowParameterMenu(pIndex, label, ref location);
                        propertyLabel.Drag = DragParameter;
                        var property = layout.AddPropertyItem(propertyLabel);
                        property.Object(propertyValue);
                    }

                    if (parameters.Length > 0)
                    {
                        layout.Space(10);
                    }

                    // Parameters creating
                    var paramType = layout.Enum(typeof(NewParameterType));

                    paramType.Value = (int)NewParameterType.Float;
                    var newParam = layout.Button("Add parameter");

                    newParam.Button.Clicked += () => AddParameter((ParameterType)paramType.Value);
                }
Пример #29
0
            /// <inheritdoc />
            public override void Initialize(LayoutElementsContainer layout)
            {
                var window = Values[0] as VisjectSurfaceWindow <TAsset, TSurface, TPreview>;
                var asset  = window?.Asset;

                if (asset == null)
                {
                    layout.Label("No parameters");
                    return;
                }
                if (!asset.IsLoaded)
                {
                    layout.Label("Loading...");
                    return;
                }
                var parameters = window.Surface.Parameters;

                for (int i = 0; i < parameters.Count; i++)
                {
                    var p = parameters[i];
                    if (!p.IsPublic)
                    {
                        continue;
                    }

                    var      pIndex = i;
                    var      pValue = p.Value;
                    Type     pType;
                    object[] attributes = null;
                    switch (p.Type)
                    {
                    case ParameterType.CubeTexture:
                        pType = typeof(CubeTexture);
                        break;

                    case ParameterType.Texture:
                    case ParameterType.NormalMap:
                        pType = typeof(Texture);
                        break;

                    case ParameterType.RenderTarget:
                    case ParameterType.RenderTargetArray:
                    case ParameterType.RenderTargetCube:
                    case ParameterType.RenderTargetVolume:
                        pType = typeof(RenderTarget);
                        break;

                    default:
                        pType = p.Value.GetType();
                        // TODO: support custom attributes with defined value range for parameter (min, max)
                        attributes = DefaultAttributes;
                        break;
                    }

                    var propertyValue = new CustomValueContainer
                                        (
                        pType,
                        pValue,
                        (instance, index) => ((VisjectSurfaceWindow <TAsset, TSurface, TPreview>)instance).GetParameter(pIndex),
                        (instance, index, value) => ((VisjectSurfaceWindow <TAsset, TSurface, TPreview>)instance).SetParameter(pIndex, value),
                        attributes
                                        );

                    var propertyLabel = new DragablePropertyNameLabel(p.Name)
                    {
                        Tag  = pIndex,
                        Drag = DragParameter
                    };
                    propertyLabel.MouseLeftDoubleClick += (label, location) => StartParameterRenaming(pIndex, label);
                    propertyLabel.MouseRightClick      += (label, location) => ShowParameterMenu(pIndex, label, ref location);
                    var property = layout.AddPropertyItem(propertyLabel);
                    property.Object(propertyValue);
                }

                // Parameters creating
                var newParameterTypes = window.NewParameterTypes;

                if (newParameterTypes != null)
                {
                    if (parameters.Count > 0)
                    {
                        layout.Space(10);
                    }

                    var paramType = layout.Enum(newParameterTypes);
                    paramType.Value = (int)ParameterType.Float;
                    var newParam = layout.Button("Add parameter");
                    newParam.Button.Clicked += () => AddParameter((ParameterType)paramType.Value);
                }
            }
Пример #30
0
        /// <inheritdoc />
        public override void Initialize(LayoutElementsContainer layout)
        {
            _readOnly        = false;
            _canReorderItems = true;
            _notNullItems    = false;

            // No support for different collections for now
            if (HasDiffrentValues || HasDiffrentTypes)
            {
                return;
            }

            var type = Values.Type;
            var size = Count;

            // Try get MemberCollectionAttribute for collection editor meta
            if (Values.Info != null)
            {
                var attributes       = Values.Info.GetCustomAttributes(true);
                var memberCollection = (MemberCollectionAttribute)attributes.FirstOrDefault(x => x is MemberCollectionAttribute);
                if (memberCollection != null)
                {
                    // TODO: handle ReadOnly and NotNullItems by filtering child editors SetValue
                    // TODO: handle CanReorderItems

                    _readOnly        = memberCollection.ReadOnly;
                    _canReorderItems = memberCollection.CanReorderItems;
                    _notNullItems    = memberCollection.NotNullItems;
                }
            }

            // Size
            if (_readOnly)
            {
                layout.Label("Size", size.ToString());
            }
            else
            {
                _size = layout.IntegerValue("Size");
                _size.IntValue.MinValue      = 0;
                _size.IntValue.MaxValue      = ushort.MaxValue;
                _size.IntValue.Value         = size;
                _size.IntValue.ValueChanged += OnSizeChanged;
            }

            // Elements
            if (size > 0)
            {
                var argTypes       = type.GetGenericArguments();
                var keyType        = argTypes[0];
                var valueType      = argTypes[1];
                var keysEnumerable = ((IDictionary)Values[0]).Keys.OfType <object>();
                var keys           = keysEnumerable as object[] ?? keysEnumerable.ToArray();
                for (int i = 0; i < size; i++)
                {
                    var item     = layout.CustomContainer <UniformGridPanel>();
                    var itemGrid = item.CustomControl;
                    itemGrid.Height            = TextBox.DefaultHeight;// TODO: make slots auto sizable instead of fixed height
                    itemGrid.SlotsHorizontally = 2;
                    itemGrid.SlotsVertically   = 1;

                    // Key
                    // TODO: allow edit keys
                    var key = keys.ElementAt(i);
                    item.Label(key.ToString());

                    // Value
                    item.Object(new DictionaryValueContainer(valueType, key, Values));
                }
            }
            _elementsCount = size;
        }