Beispiel #1
0
            /// <inheritdoc />
            public override void Initialize(LayoutElementsContainer layout)
            {
                _scripts.Clear();

                // Area for drag&drop scripts
                var dragArea = layout.Custom <DragAreaControl>();

                dragArea.CustomControl.ScriptsEditor = this;

                // No support to show scripts for more than one actor selected
                if (Values.Count != 1)
                {
                    return;
                }

                // Scripts
                var scripts = (Script[])Values[0];

                _scripts.AddRange(scripts);
                var elementType = typeof(Script);

                for (int i = 0; i < scripts.Length; i++)
                {
                    var script = scripts[i];
                    if (script == null)
                    {
                        layout.Group("Missing script");
                        continue;
                    }
                    var values = new ListValueContainer(elementType, i, Values);
                    var type   = script.GetType();
                    var editor = CustomEditorsUtil.CreateEditor(type, false);

                    // Create group
                    var title = CustomEditorsUtil.GetPropertyNameUI(type.Name);
                    var group = layout.Group(title);
                    group.Panel.Open(false);

                    // Add settings button to the group
                    const float settingsButtonSize = 14;
                    var         settingsButton     = new Image(group.Panel.Width - settingsButtonSize, 0, settingsButtonSize, settingsButtonSize)
                    {
                        CanFocus     = true,
                        AnchorStyle  = AnchorStyle.UpperRight,
                        IsScrollable = false,
                        Color        = new Color(0.7f),
                        Margin       = new Margin(1),
                        ImageSource  = new SpriteImageSource(FlaxEngine.GUI.Style.Current.Settings),
                        Tag          = script,
                        Parent       = group.Panel
                    };
                    settingsButton.Clicked += SettingsButtonOnClicked;

                    group.Object(values, editor);
                }

                base.Initialize(layout);
            }
Beispiel #2
0
        /// <inheritdoc />
        public override void Initialize(LayoutElementsContainer layout)
        {
            _scripts.Clear();

            // Area for drag&drop scripts
            var dragArea = layout.CustomContainer <DragAreaControl>();

            dragArea.CustomControl.ScriptsEditor = this;

            // No support to show scripts for more than one actor selected
            // TODO: support showing scripts from objects that has the same scripts layout
            if (Values.Count != 1)
            {
                return;
            }

            // Scripts arrange bar
            var dragBar = layout.Custom <ScriptArrangeBar>();

            dragBar.CustomControl.Init(0, this);

            // Scripts
            var scripts = (Script[])Values[0];

            _scripts.AddRange(scripts);
            var elementType = typeof(Script);

            for (int i = 0; i < scripts.Length; i++)
            {
                var script = scripts[i];
                if (script == null)
                {
                    AddMissingScript(i, layout);
                    continue;
                }

                var values = new ListValueContainer(elementType, i, Values);
                var type   = script.GetType();
                var editor = CustomEditorsUtil.CreateEditor(type, false);

                // Create group
                var title = CustomEditorsUtil.GetPropertyNameUI(type.Name);
                var group = layout.Group(title);
                group.Panel.Open(false);

                // Customize
                var typeAttributes = type.GetCustomAttributes(true);
                var tooltip        = (TooltipAttribute)typeAttributes.FirstOrDefault(x => x is TooltipAttribute);
                if (tooltip != null)
                {
                    group.Panel.TooltipText = tooltip.Text;
                }

                // Add toggle button to the group
                var scriptToggle = new CheckBox(2, 0, script.Enabled)
                {
                    TooltipText  = "If checked, script will be enabled",
                    IsScrollable = false,
                    Size         = new Vector2(14, 14),
                    BoxSize      = 12.0f,
                    Tag          = script,
                    Parent       = group.Panel
                };
                scriptToggle.StateChanged += ScriptToggleOnCheckChanged;

                // Add drag button to the group
                const float dragIconSize = 14;
                var         scriptDrag   = new ScriptDragIcon(this, script, scriptToggle.Right, 0.5f, dragIconSize)
                {
                    TooltipText  = "Script reference",
                    CanFocus     = true,
                    IsScrollable = false,
                    Color        = new Color(0.7f),
                    Margin       = new Margin(1),
                    ImageSource  = new SpriteImageSource(Editor.Instance.UI.DragBar12),
                    Tag          = script,
                    Parent       = group.Panel
                };

                // Add settings button to the group
                const float settingsButtonSize = 14;
                var         settingsButton     = new Image(group.Panel.Width - settingsButtonSize, 0, settingsButtonSize, settingsButtonSize)
                {
                    TooltipText  = "Settings",
                    CanFocus     = true,
                    AnchorStyle  = AnchorStyle.UpperRight,
                    IsScrollable = false,
                    Color        = new Color(0.7f),
                    Margin       = new Margin(1),
                    ImageSource  = new SpriteImageSource(FlaxEngine.GUI.Style.Current.Settings),
                    Tag          = script,
                    Parent       = group.Panel
                };
                settingsButton.Clicked += SettingsButtonOnClicked;

                group.Panel.HeaderTextMargin = new Margin(scriptDrag.Right, 15, 2, 2);
                group.Object(values, editor);

                // Scripts arrange bar
                dragBar = layout.Custom <ScriptArrangeBar>();
                dragBar.CustomControl.Init(i + 1, this);
            }

            base.Initialize(layout);
        }