/// <summary>
        /// Initializes the drop down window by creating the necessary GUI. Must be called after construction and before
        /// use.
        /// </summary>
        /// <param name="parent">Scene window that this drop down window is a part of.</param>
        /// <param name="cameraOptions">Reference to the current scene camera options.</param>
        internal void Initialize(SceneWindow parent)
        {
            this.Parent = parent;

            GUIEnumField cameraProjectionTypeField = new GUIEnumField(typeof(ProjectionType), new LocEdString("Projection type"));

            cameraProjectionTypeField.Value = (ulong)Parent.ProjectionType;
            cameraProjectionTypeField.OnSelectionChanged += SetCameraProjectionType;

            nearClipPlaneInput            = new GUIFloatField(new LocEdString("Near plane"));
            nearClipPlaneInput.Value      = Parent.NearClipPlane;
            nearClipPlaneInput.OnChanged += OnNearClipPlaneChanged;
            nearClipPlaneInput.SetRange(SceneCameraOptions.MinNearClipPlane, SceneCameraOptions.MaxNearClipPlane);

            farClipPlaneInput            = new GUIFloatField(new LocEdString("Far plane"));
            farClipPlaneInput.Value      = Parent.FarClipPlane;
            farClipPlaneInput.OnChanged += OnFarClipPlaneChanged;
            farClipPlaneInput.SetRange(SceneCameraOptions.MinFarClipPlane, SceneCameraOptions.MaxFarClipPlane);

            cameraFieldOfView            = new GUISliderField(1, 360, new LocEdString("Field of view"));
            cameraFieldOfView.Value      = Parent.FieldOfView.Degrees;
            cameraFieldOfView.OnChanged += SetFieldOfView;

            cameraOrthographicSize            = new GUIFloatField(new LocEdString("Orthographic size"));
            cameraOrthographicSize.Value      = Parent.OrthographicSize;
            cameraOrthographicSize.OnChanged += SetOrthographicSize;

            GUISliderField cameraScrollSpeed = new GUISliderField(SceneCameraOptions.MinScrollSpeed, SceneCameraOptions.MaxScrollSpeed,
                                                                  new LocEdString("Scroll speed"));

            cameraScrollSpeed.Value      = Parent.ScrollSpeed;
            cameraScrollSpeed.OnChanged += SetScrollSpeed;

            GUILayoutY vertLayout = GUI.AddLayoutY();

            vertLayout.AddSpace(10);

            GUILayoutX cameraOptionsLayoutX = vertLayout.AddLayoutX();

            cameraOptionsLayoutX.AddSpace(10);

            GUILayoutY cameraOptionsLayoutY = cameraOptionsLayoutX.AddLayoutY();

            cameraOptionsLayoutY.AddElement(cameraProjectionTypeField);
            cameraOptionsLayoutY.AddElement(nearClipPlaneInput);
            cameraOptionsLayoutY.AddElement(farClipPlaneInput);
            cameraOptionsLayoutY.AddElement(cameraFieldOfView);
            cameraOptionsLayoutY.AddElement(cameraOrthographicSize);
            cameraOptionsLayoutY.AddElement(cameraScrollSpeed);
            cameraOptionsLayoutX.AddSpace(10);

            vertLayout.AddSpace(10);

            ToggleTypeSpecificFields((ProjectionType)cameraProjectionTypeField.Value);
        }
Beispiel #2
0
        private void BuildGUI()
        {
            progressBar  = new GUIProgressBar();
            messageLabel = new GUILabel("");

            GUILayoutY layoutY = GUI.AddLayoutY();

            layoutY.AddFlexibleSpace();
            GUILayoutX messageLayout = layoutY.AddLayoutX();

            messageLayout.AddFlexibleSpace();
            messageLayout.AddElement(messageLabel);
            messageLayout.AddFlexibleSpace();

            layoutY.AddSpace(10);

            GUILayoutX barLayout = layoutY.AddLayoutX();

            barLayout.AddSpace(30);
            barLayout.AddElement(progressBar);
            barLayout.AddSpace(30);

            layoutY.AddFlexibleSpace();

            Percent = percent;
            messageLabel.SetContent(message);
        }
Beispiel #3
0
            /// <inheritdoc/>
            public override void BuildGUI()
            {
                main     = Layout.AddPanel(0, 1, 1, GUIOption.FixedHeight(ENTRY_HEIGHT));
                overlay  = main.AddPanel(-1, 0, 0, GUIOption.FixedHeight(ENTRY_HEIGHT));
                underlay = main.AddPanel(1, 0, 0, GUIOption.FixedHeight(ENTRY_HEIGHT));

                GUILayoutX mainLayout     = main.AddLayoutX();
                GUILayoutY overlayLayout  = overlay.AddLayoutY();
                GUILayoutY underlayLayout = underlay.AddLayoutY();

                icon          = new GUITexture(null, GUIOption.FixedWidth(32), GUIOption.FixedHeight(32));
                messageLabel  = new GUILabel(new LocEdString(""), EditorStyles.MultiLineLabel, GUIOption.FixedHeight(MESSAGE_HEIGHT));
                functionLabel = new GUILabel(new LocEdString(""), GUIOption.FixedHeight(CALLER_LABEL_HEIGHT));

                mainLayout.AddSpace(PADDING);
                GUILayoutY iconLayout = mainLayout.AddLayoutY();

                iconLayout.AddFlexibleSpace();
                iconLayout.AddElement(icon);
                iconLayout.AddFlexibleSpace();

                mainLayout.AddSpace(PADDING);
                GUILayoutY messageLayout = mainLayout.AddLayoutY();

                messageLayout.AddSpace(PADDING);
                messageLayout.AddElement(messageLabel);
                messageLayout.AddElement(functionLabel);
                messageLayout.AddSpace(PADDING);
                mainLayout.AddFlexibleSpace();
                mainLayout.AddSpace(PADDING);

                background = new GUITexture(Builtin.WhiteTexture, GUIOption.FixedHeight(ENTRY_HEIGHT));
                underlayLayout.AddElement(background);

                GUIButton button = new GUIButton(new LocEdString(""), EditorStyles.Blank, GUIOption.FixedHeight(ENTRY_HEIGHT));

                overlayLayout.AddElement(button);

                button.OnClick       += OnClicked;
                button.OnDoubleClick += OnDoubleClicked;
            }
Beispiel #4
0
        private void BuildGUI()
        {
            progressBar           = new GUIProgressBar();
            messageLabel          = new GUILabel("", EditorStyles.MultiLineLabelCentered, GUIOption.FixedHeight(60));
            cancelImport          = new GUIButton(new LocEdString("Cancel import"));
            cancelImport.OnClick += () =>
            {
                ProjectLibrary.CancelImport();
                cancelImport.Disabled = true;
            };

            GUILayoutY layoutY = GUI.AddLayoutY();

            layoutY.AddFlexibleSpace();
            GUILayoutX messageLayout = layoutY.AddLayoutX();

            messageLayout.AddSpace(15);
            messageLayout.AddElement(messageLabel);
            messageLayout.AddSpace(15);

            layoutY.AddSpace(10);

            GUILayoutX barLayout = layoutY.AddLayoutX();

            barLayout.AddSpace(30);
            barLayout.AddElement(progressBar);
            barLayout.AddSpace(30);

            layoutY.AddSpace(20);

            GUILayoutX buttonLayout = layoutY.AddLayoutX();

            buttonLayout.AddFlexibleSpace();
            buttonLayout.AddElement(cancelImport);
            buttonLayout.AddFlexibleSpace();

            layoutY.AddFlexibleSpace();

            messageLabel.SetContent(new LocEdString("Resource import is still in progress. You can wait until it " +
                                                    "finishes or cancel import. \n\nNote that even when cancelling you will need to wait for active import threads to finish."));
        }
Beispiel #5
0
        /// <inheritdoc/>
        protected internal override void Initialize(int index)
        {
            guiLayout = layout.AddLayoutY(index);

            GUILayoutX guiTitleLayout = guiLayout.AddLayoutX();

            GUIToggle guiFoldout = new GUIToggle(title, EditorStyles.Foldout);

            guiFoldout.Value           = isExpanded;
            guiFoldout.AcceptsKeyFocus = false;
            guiFoldout.OnToggled      += OnFoldoutToggled;
            guiTitleLayout.AddElement(guiFoldout);

            GUILayoutX categoryContentLayout = guiLayout.AddLayoutX();

            categoryContentLayout.AddSpace(IndentAmount);

            guiContentPanel = categoryContentLayout.AddPanel();
            GUILayoutX guiIndentLayoutX = guiContentPanel.AddLayoutX();

            guiIndentLayoutX.AddSpace(IndentAmount);
            GUILayoutY guiIndentLayoutY = guiIndentLayoutX.AddLayoutY();

            guiIndentLayoutY.AddSpace(IndentAmount);
            ChildLayout = guiIndentLayoutY.AddLayoutY();
            guiIndentLayoutY.AddSpace(IndentAmount);
            guiIndentLayoutX.AddSpace(IndentAmount);
            categoryContentLayout.AddSpace(IndentAmount);

            short  backgroundDepth = (short)(Inspector.START_BACKGROUND_DEPTH - depth - 1);
            string bgPanelStyle    = depth % 2 == 0
                ? EditorStylesInternal.InspectorContentBgAlternate
                : EditorStylesInternal.InspectorContentBg;
            GUIPanel   backgroundPanel    = guiContentPanel.AddPanel(backgroundDepth);
            GUITexture inspectorContentBg = new GUITexture(null, bgPanelStyle);

            backgroundPanel.AddElement(inspectorContentBg);

            guiContentPanel.Active = isExpanded;
        }
Beispiel #6
0
        /// <summary>
        /// Updates the contents of the details panel according to the currently selected element.
        /// </summary>
        private void RefreshDetailsPanel()
        {
            detailsArea.Layout.Clear();

            if (sSelectedElementIdx != -1)
            {
                GUILayoutX paddingX = detailsArea.Layout.AddLayoutX();
                paddingX.AddSpace(5);
                GUILayoutY paddingY = paddingX.AddLayoutY();
                paddingX.AddSpace(5);

                paddingY.AddSpace(5);
                GUILayoutY mainLayout = paddingY.AddLayoutY();
                paddingY.AddSpace(5);

                ConsoleEntryData entry = filteredEntries[sSelectedElementIdx];

                LocString message      = new LocEdString(entry.message);
                GUILabel  messageLabel = new GUILabel(message, EditorStyles.MultiLineLabel, GUIOption.FlexibleHeight());
                mainLayout.AddElement(messageLabel);
                mainLayout.AddSpace(10);

                if (entry.callstack != null)
                {
                    foreach (var call in entry.callstack)
                    {
                        string fileName = Path.GetFileName(call.file);

                        string callMessage;
                        if (string.IsNullOrEmpty(call.method))
                        {
                            callMessage = "\tin " + fileName + ":" + call.line;
                        }
                        else
                        {
                            callMessage = "\t" + call.method + " in " + fileName + ":" + call.line;
                        }

                        GUIButton callBtn = new GUIButton(new LocEdString(callMessage));
                        mainLayout.AddElement(callBtn);

                        CallStackEntry hoistedCall = call;
                        callBtn.OnClick += () =>
                        {
                            CodeEditor.OpenFile(hoistedCall.file, hoistedCall.line);
                        };
                    }
                }

                mainLayout.AddFlexibleSpace();
            }
            else
            {
                GUILayoutX centerX = detailsArea.Layout.AddLayoutX();
                centerX.AddFlexibleSpace();
                GUILayoutY centerY = centerX.AddLayoutY();
                centerX.AddFlexibleSpace();

                centerY.AddFlexibleSpace();
                GUILabel nothingSelectedLbl = new GUILabel(new LocEdString("(No entry selected)"));
                centerY.AddElement(nothingSelectedLbl);
                centerY.AddFlexibleSpace();
            }
        }
Beispiel #7
0
        private void OnInitialize()
        {
            GUILabel title    = new GUILabel(new LocEdString("Banshee Engine v0.4"), EditorStyles.TitleLabel);
            GUILabel subTitle = new GUILabel(new LocEdString("A modern open-source game development toolkit"),
                                             EditorStyles.LabelCentered);
            GUILabel license = new GUILabel(new LocEdString(
                                                "This program is licensed under the GNU Lesser General Public License V3"), EditorStyles.LabelCentered);
            GUILabel copyright = new GUILabel(new LocEdString("Copyright (C) 2015 Marko Pintera. All rights reserved."),
                                              EditorStyles.LabelCentered);

            GUILabel authorLabel = new GUILabel(new LocEdString("Banshee was created, and is being actively developed by Marko Pintera."));
            GUILabel emailTitle  = new GUILabel(new LocEdString("E-mail"), GUIOption.FixedWidth(150));

            emailLabel = new GUITextBox();
            GUILabel  linkedInTitle = new GUILabel(new LocEdString("LinkedIn"), GUIOption.FixedWidth(150));
            GUIButton linkedInBtn   = new GUIButton(new LocEdString("Profile"));

            GUIToggleGroup foldoutGroup         = new GUIToggleGroup(true);
            GUIToggle      contactFoldout       = new GUIToggle(new LocEdString("Author"), foldoutGroup, EditorStyles.Foldout);
            GUIToggle      thirdPartyFoldout    = new GUIToggle(new LocEdString("Used third party libraries"), foldoutGroup, EditorStyles.Foldout);
            GUIToggle      noticesFoldout       = new GUIToggle(new LocEdString("Third party notices"), foldoutGroup, EditorStyles.Foldout);
            GUIToggle      collaboratorsFoldout = new GUIToggle(new LocEdString("Collaborators"), foldoutGroup, EditorStyles.Foldout);

            contactFoldout.AcceptsKeyFocus       = false;
            thirdPartyFoldout.AcceptsKeyFocus    = false;
            noticesFoldout.AcceptsKeyFocus       = false;
            collaboratorsFoldout.AcceptsKeyFocus = false;

            GUILabel freeTypeNotice = new GUILabel(new LocEdString(
                                                       "Portions of this software are copyright (C) 2015 The FreeType Project (www.freetype.org). " +
                                                       "All rights reserved."), EditorStyles.MultiLineLabelCentered,
                                                   GUIOption.FlexibleHeight(), GUIOption.FixedWidth(380));

            GUILabel fbxSdkNotice = new GUILabel(new LocEdString(
                                                     "This software contains Autodesk(R) FBX(R) code developed by Autodesk, Inc. Copyright 2013 Autodesk, Inc. " +
                                                     "All rights, reserved. Such code is provided \"as is\" and Autodesk, Inc. disclaims any and all warranties, " +
                                                     "whether express or implied, including without limitation the implied warranties of merchantability, " +
                                                     "fitness for a particular purpose or non-infringement of third party rights. In no event shall Autodesk, " +
                                                     "Inc. be liable for any direct, indirect, incidental, special, exemplary, or consequential damages " +
                                                     "(including, but not limited to, procurement of substitute goods or services; loss of use, data, or " +
                                                     "profits; or business interruption) however caused and on any theory of liability, whether in contract, " +
                                                     "strict liability, or tort (including negligence or otherwise) arising in any way out of such code."),
                                                 EditorStyles.MultiLineLabelCentered, GUIOption.FlexibleHeight(), GUIOption.FixedWidth(380));

            GUILayoutY mainLayout = GUI.AddLayoutY();

            mainLayout.AddSpace(10);
            mainLayout.AddElement(title);
            mainLayout.AddElement(subTitle);
            mainLayout.AddSpace(10);
            mainLayout.AddElement(license);
            mainLayout.AddElement(copyright);
            mainLayout.AddSpace(10);
            mainLayout.AddElement(contactFoldout);

            GUILayoutY contactLayout = mainLayout.AddLayoutY();

            contactLayout.AddSpace(15);
            GUILayout authorLayout = contactLayout.AddLayoutX();

            authorLayout.AddFlexibleSpace();
            authorLayout.AddElement(authorLabel);
            authorLayout.AddFlexibleSpace();
            contactLayout.AddSpace(15);
            GUILayout emailLayout = contactLayout.AddLayoutX();

            emailLayout.AddSpace(10);
            emailLayout.AddElement(emailTitle);
            emailLayout.AddElement(emailLabel);
            emailLayout.AddSpace(10);
            GUILayout linkedInLayout = contactLayout.AddLayoutX();

            linkedInLayout.AddSpace(10);
            linkedInLayout.AddElement(linkedInTitle);
            linkedInLayout.AddElement(linkedInBtn);
            linkedInLayout.AddSpace(10);

            mainLayout.AddSpace(5);
            mainLayout.AddElement(thirdPartyFoldout);
            GUILayoutY thirdPartyLayout = mainLayout.AddLayoutY();

            CreateThirdPartyGUI(thirdPartyLayout, "Autodesk FBX SDK",
                                "http://usa.autodesk.com/adsk/servlet/pc/item?siteID=123112&id=10775847");
            CreateThirdPartyGUI(thirdPartyLayout, "FreeImage", "http://freeimage.sourceforge.net/");
            CreateThirdPartyGUI(thirdPartyLayout, "FreeType", "http://www.freetype.org/");
            CreateThirdPartyGUI(thirdPartyLayout, "Mono", "http://www.mono-project.com/");
            CreateThirdPartyGUI(thirdPartyLayout, "NVIDIA Texture Tools",
                                "https://github.com/castano/nvidia-texture-tools");
            CreateThirdPartyGUI(thirdPartyLayout, "libFLAC", "https://xiph.org/flac/");
            CreateThirdPartyGUI(thirdPartyLayout, "libOgg", "https://www.xiph.org/ogg/");
            CreateThirdPartyGUI(thirdPartyLayout, "libVorbis", "http://www.vorbis.com/");
            CreateThirdPartyGUI(thirdPartyLayout, "OpenAL Soft", "http://kcat.strangesoft.net/openal.html");

            mainLayout.AddSpace(5);
            mainLayout.AddElement(noticesFoldout);
            GUILayout noticesLayout = mainLayout.AddLayoutY();

            noticesLayout.AddElement(freeTypeNotice);
            noticesLayout.AddSpace(10);
            noticesLayout.AddElement(fbxSdkNotice);

            mainLayout.AddSpace(5);
            mainLayout.AddElement(collaboratorsFoldout);
            GUILayoutY collaboratorsLayout = mainLayout.AddLayoutY();

            CreateCollaboratorGUI(collaboratorsLayout, "Danijel Ribic", "Logo, UI icons, 3D models & textures");
            CreateCollaboratorGUI(collaboratorsLayout, "Marco Bellan", "Bugfixes, editor enhancements");

            mainLayout.AddFlexibleSpace();

            contactLayout.Active      = false;
            contactFoldout.OnToggled += x =>
            {
                contactLayout.Active = x;
            };

            thirdPartyLayout.Active      = false;
            thirdPartyFoldout.OnToggled += x => thirdPartyLayout.Active = x;

            noticesLayout.Active      = false;
            noticesFoldout.OnToggled += x => noticesLayout.Active = x;

            collaboratorsLayout.Active      = false;
            collaboratorsFoldout.OnToggled += x => collaboratorsLayout.Active = x;

            emailLabel.Text      = "*****@*****.**";
            linkedInBtn.OnClick += () => { System.Diagnostics.Process.Start("http://hr.linkedin.com/in/markopintera"); };
        }
Beispiel #8
0
        /// <summary>
        /// Creates all of the GUI elements required for the specified type of dialog box.
        /// </summary>
        private void SetupGUI()
        {
            messageLabel = new GUILabel("", EditorStyles.MultiLineLabel,
                                        GUIOption.FixedWidth(260), GUIOption.FlexibleHeight(0, 600));

            GUILayoutY layoutY = GUI.AddLayoutY();

            layoutY.AddSpace(10);
            GUILayoutX messageLayout = layoutY.AddLayoutX();

            messageLayout.AddFlexibleSpace();
            messageLayout.AddElement(messageLabel);
            messageLayout.AddFlexibleSpace();

            layoutY.AddSpace(10);

            GUILayoutX btnLayout = layoutY.AddLayoutX();

            btnLayout.AddFlexibleSpace();

            switch (type)
            {
            case Type.OK:
            {
                GUIButton okBtn = new GUIButton(new LocEdString("OK"));
                okBtn.OnClick += () => ButtonClicked(ResultType.OK);

                btnLayout.AddElement(okBtn);
            }
            break;

            case Type.OKCancel:
            {
                GUIButton okBtn = new GUIButton(new LocEdString("OK"));
                okBtn.OnClick += () => ButtonClicked(ResultType.OK);

                GUIButton cancelBtn = new GUIButton(new LocEdString("Cancel"));
                cancelBtn.OnClick += () => ButtonClicked(ResultType.Cancel);

                btnLayout.AddElement(okBtn);
                btnLayout.AddSpace(20);
                btnLayout.AddElement(cancelBtn);
            }
            break;

            case Type.RetryAbortIgnore:
            {
                GUIButton retryBtn = new GUIButton(new LocEdString("Retry"));
                retryBtn.OnClick += () => ButtonClicked(ResultType.Retry);

                GUIButton abortBtn = new GUIButton(new LocEdString("Abort"));
                abortBtn.OnClick += () => ButtonClicked(ResultType.Abort);

                GUIButton ignoreBtn = new GUIButton(new LocEdString("Ignore"));
                ignoreBtn.OnClick += () => ButtonClicked(ResultType.Ignore);

                btnLayout.AddElement(retryBtn);
                btnLayout.AddSpace(20);
                btnLayout.AddElement(abortBtn);
                btnLayout.AddSpace(20);
                btnLayout.AddElement(ignoreBtn);
            }
            break;

            case Type.RetryCancel:
            {
                GUIButton retryBtn = new GUIButton(new LocEdString("Retry"));
                retryBtn.OnClick += () => ButtonClicked(ResultType.Retry);

                GUIButton cancelBtn = new GUIButton(new LocEdString("Cancel"));
                cancelBtn.OnClick += () => ButtonClicked(ResultType.Cancel);

                btnLayout.AddElement(retryBtn);
                btnLayout.AddSpace(20);
                btnLayout.AddElement(cancelBtn);
            }
            break;

            case Type.TryCancelContinue:
            {
                GUIButton tryBtn = new GUIButton(new LocEdString("Try"));
                tryBtn.OnClick += () => ButtonClicked(ResultType.Try);

                GUIButton cancelBtn = new GUIButton(new LocEdString("Cancel"));
                cancelBtn.OnClick += () => ButtonClicked(ResultType.Cancel);

                GUIButton continueBtn = new GUIButton(new LocEdString("Continue"));
                continueBtn.OnClick += () => ButtonClicked(ResultType.Continue);

                btnLayout.AddElement(tryBtn);
                btnLayout.AddSpace(20);
                btnLayout.AddElement(cancelBtn);
                btnLayout.AddSpace(20);
                btnLayout.AddElement(continueBtn);
            }
            break;

            case Type.YesNo:
            {
                GUIButton yesBtn = new GUIButton(new LocEdString("Yes"));
                yesBtn.OnClick += () => ButtonClicked(ResultType.Yes);

                GUIButton noBtn = new GUIButton(new LocEdString("No"));
                noBtn.OnClick += () => ButtonClicked(ResultType.No);

                btnLayout.AddElement(yesBtn);
                btnLayout.AddSpace(20);
                btnLayout.AddElement(noBtn);
            }
            break;

            case Type.YesNoCancel:
            {
                GUIButton yesBtn = new GUIButton(new LocEdString("Yes"));
                yesBtn.OnClick += () => ButtonClicked(ResultType.Yes);

                GUIButton noBtn = new GUIButton(new LocEdString("No"));
                noBtn.OnClick += () => ButtonClicked(ResultType.No);

                GUIButton cancelBtn = new GUIButton(new LocEdString("Cancel"));
                cancelBtn.OnClick += () => ButtonClicked(ResultType.Cancel);

                btnLayout.AddElement(yesBtn);
                btnLayout.AddSpace(20);
                btnLayout.AddElement(noBtn);
                btnLayout.AddSpace(20);
                btnLayout.AddElement(cancelBtn);
            }
            break;
            }

            btnLayout.AddFlexibleSpace();
            layoutY.AddFlexibleSpace();
        }
Beispiel #9
0
        /// <summary>
        /// Recreates all the GUI elements used by this inspector.
        /// </summary>
        private void BuildGUI()
        {
            Layout.Clear();

            Animation animation = InspectedObject as Animation;

            if (animation == null)
            {
                return;
            }

            animationClipField.OnChanged += x =>
            {
                AnimationClip clip = Resources.Load <AnimationClip>(x.UUID);

                animation.DefaultClip = clip;
                MarkAsModified();
                ConfirmModify();
            };

            wrapModeField.OnSelectionChanged += x =>
            {
                animation.WrapMode = (AnimWrapMode)x;
                MarkAsModified();
                ConfirmModify();
            };

            speedField.OnChanged   += x => { animation.Speed = x; MarkAsModified(); };
            speedField.OnConfirmed += ConfirmModify;
            speedField.OnFocusLost += ConfirmModify;

            cullingField.OnChanged        += x => { animation.Cull = x; MarkAsModified(); ConfirmModify(); };
            overrideBoundsField.OnChanged += x => { animation.UseBounds = x; MarkAsModified(); ConfirmModify(); };
            centerField.OnChanged         += x =>
            {
                AABox   bounds = animation.Bounds;
                Vector3 min    = x - bounds.Size * 0.5f;
                Vector3 max    = x + bounds.Size * 0.5f;

                animation.Bounds = new AABox(min, max);
                MarkAsModified();
            };
            centerField.OnConfirmed += ConfirmModify;
            centerField.OnFocusLost += ConfirmModify;

            sizeField.OnChanged += x =>
            {
                AABox   bounds = animation.Bounds;
                Vector3 min    = bounds.Center - x * 0.5f;
                Vector3 max    = bounds.Center + x * 0.5f;

                animation.Bounds = new AABox(min, max);
                MarkAsModified();
            };
            sizeField.OnConfirmed += ConfirmModify;
            sizeField.OnFocusLost += ConfirmModify;

            Layout.AddElement(animationClipField);
            Layout.AddElement(wrapModeField);
            Layout.AddElement(speedField);
            Layout.AddElement(cullingField);
            Layout.AddElement(overrideBoundsField);

            GUILayoutX boundsLayout = Layout.AddLayoutX();

            boundsLayout.AddElement(new GUILabel(new LocEdString("Bounds"), GUIOption.FixedWidth(100)));

            GUILayoutY boundsContent = boundsLayout.AddLayoutY();

            boundsContent.AddElement(centerField);
            boundsContent.AddElement(sizeField);

            // Morph shapes
            Renderable  renderable  = animation.SceneObject.GetComponent <Renderable>();
            MorphShapes morphShapes = renderable?.Mesh.Value?.MorphShapes;

            if (morphShapes != null)
            {
                GUIToggle morphShapesToggle = new GUIToggle(new LocEdString("Morph shapes"), EditorStyles.Foldout);

                Layout.AddElement(morphShapesToggle);
                GUILayoutY channelsLayout = Layout.AddLayoutY();

                morphShapesToggle.OnToggled += x =>
                {
                    channelsLayout.Active = x;
                    Persistent.SetBool("Channels_Expanded", x);
                };

                channelsLayout.Active = Persistent.GetBool("Channels_Expanded");

                MorphChannel[] channels = morphShapes.Channels;
                for (int i = 0; i < channels.Length; i++)
                {
                    GUILayoutY channelLayout = channelsLayout.AddLayoutY();

                    GUILayoutX channelTitleLayout = channelLayout.AddLayoutX();
                    channelLayout.AddSpace(5);
                    GUILayoutY channelContentLayout = channelLayout.AddLayoutY();

                    string    channelName      = channels[i].Name;
                    GUIToggle channelNameField = new GUIToggle(channelName, EditorStyles.Expand, GUIOption.FlexibleWidth());

                    channelTitleLayout.AddSpace(15); // Indent
                    channelTitleLayout.AddElement(channelNameField);
                    channelTitleLayout.AddFlexibleSpace();

                    channelNameField.OnToggled += x =>
                    {
                        channelContentLayout.Active = x;

                        Persistent.SetBool(channelName + "_Expanded", x);
                    };

                    channelContentLayout.Active = Persistent.GetBool(channelName + "_Expanded");

                    MorphShape[] shapes = channels[i].Shapes;
                    for (int j = 0; j < shapes.Length; j++)
                    {
                        GUILayoutX shapeLayout = channelContentLayout.AddLayoutX();
                        channelContentLayout.AddSpace(5);

                        LocString nameString = new LocString("[{0}]. {1}");
                        nameString.SetParameter(0, j.ToString());
                        nameString.SetParameter(1, shapes[j].Name);
                        GUILabel shapeNameField = new GUILabel(shapes[j].Name);

                        LocString weightString = new LocEdString("Weight: {0}");
                        weightString.SetParameter(0, shapes[j].Weight.ToString());
                        GUILabel weightField = new GUILabel(weightString);

                        shapeLayout.AddSpace(30); // Indent
                        shapeLayout.AddElement(shapeNameField);
                        shapeLayout.AddFlexibleSpace();
                        shapeLayout.AddElement(weightField);
                    }
                }
            }
        }
Beispiel #10
0
        private void OnInitialize()
        {
            GUILayoutX splitLayout        = GUI.AddLayoutX();
            GUIPanel   platformPanel      = splitLayout.AddPanel();
            GUIPanel   platformForeground = platformPanel.AddPanel();
            GUILayoutY platformLayout     = platformForeground.AddLayoutY();
            GUIPanel   platformBackground = platformPanel.AddPanel(1);
            GUITexture background         = new GUITexture(Builtin.WhiteTexture);

            background.SetTint(PLATFORM_BG_COLOR);

            splitLayout.AddSpace(5);
            GUILayoutY optionsLayout = splitLayout.AddLayoutY();

            GUILabel platformsLabel = new GUILabel(new LocEdString("Platforms"), EditorStyles.LabelCentered);

            platformLayout.AddSpace(5);
            platformLayout.AddElement(platformsLabel);
            platformLayout.AddSpace(5);

            GUIToggleGroup platformToggleGroup = new GUIToggleGroup();

            PlatformType[] availablePlatforms = BuildManager.AvailablePlatforms;
            platformButtons = new GUIToggle[availablePlatforms.Length];
            for (int i = 0; i < availablePlatforms.Length; i++)
            {
                PlatformType currentPlatform = availablePlatforms[i];
                bool         isActive        = currentPlatform == BuildManager.ActivePlatform;

                string platformName = Enum.GetName(typeof(PlatformType), currentPlatform);
                if (isActive)
                {
                    platformName += " (Active)";
                }

                GUIToggle platformToggle = new GUIToggle(new LocEdString(platformName), platformToggleGroup, EditorStyles.Button);
                platformToggle.OnToggled += x => OnSelectedPlatformChanged(currentPlatform, x);
                platformLayout.AddElement(platformToggle);

                platformButtons[i] = platformToggle;

                if (isActive)
                {
                    platformToggle.Value = true;
                    selectedPlatform     = currentPlatform;
                }
            }

            platformLayout.AddFlexibleSpace();

            GUIButton changePlatformBtn = new GUIButton(new LocEdString("Set active"));

            platformLayout.AddElement(changePlatformBtn);
            changePlatformBtn.OnClick += ChangeActivePlatform;

            platformBackground.AddElement(background);

            optionsScrollArea = new GUIScrollArea();
            optionsLayout.AddElement(optionsScrollArea);

            GUIButton buildButton = new GUIButton(new LocEdString("Build"));

            optionsLayout.AddFlexibleSpace();
            optionsLayout.AddElement(buildButton);

            buildButton.OnClick += TryStartBuild;

            BuildPlatformOptionsGUI();
        }
Beispiel #11
0
        private void OnInitialize()
        {
            GUILabel title    = new GUILabel(new LocEdString("Banshee Editor " + EngineVersion.GetFullVersionString()), EditorStyles.TitleLabel);
            GUILabel subTitle = new GUILabel(new LocEdString("A modern open-source game development toolkit"),
                                             EditorStyles.LabelCentered);
            GUILabel bsfVersion = new GUILabel(new LocEdString("Powered by bs::framework " + FrameworkVersion.GetFullVersionString()), EditorStyles.LabelCentered);
            GUILabel license    = new GUILabel(new LocEdString(
                                                   "This program is licensed under the GNU Lesser General Public License V3 or later"), EditorStyles.LabelCentered);
            GUILabel copyright = new GUILabel(new LocEdString("Copyright (C) 2014 - " + EngineVersion.GetCurrentReleaseYearNumber() + " Jonathan Harrison and contributors. All rights reserved."),
                                              EditorStyles.LabelCentered);

            GUILabel editorContributorsLabel    = new GUILabel(new LocEdString("Editor contributors"), EditorStyles.TitleLabel);
            GUILabel frameworkContributorsLabel = new GUILabel(new LocEdString("Framework contributors"), EditorStyles.TitleLabel);
            GUILabel engineLabel    = new GUILabel(new LocEdString("Editor and engine"), EditorStyles.TitleLabel);
            GUILabel frameworkLabel = new GUILabel(new LocEdString("Framework"), EditorStyles.TitleLabel);


            GUILabel authorLabel = new GUILabel(new LocEdString("Banshee was created, and is being actively developed by Jonathan Harrison."));
            GUILabel emailTitle  = new GUILabel(new LocEdString("E-mail"), GUIOption.FixedWidth(150));

            emailLabel = new GUITextBox();
            GUILabel  linkedInTitle = new GUILabel(new LocEdString("LinkedIn"), GUIOption.FixedWidth(150));
            GUIButton linkedInBtn   = new GUIButton(new LocEdString("Profile"));
            GUIButton patreonBtn    = new GUIButton(new LocEdString("Support us on Patreon!"), GUIOption.FixedWidth(210));
            GUIButton paypalBtn     = new GUIButton(new LocEdString("Donate via PayPal!"), GUIOption.FixedWidth(210));

            GUIScrollArea  scrollArea          = new GUIScrollArea();
            GUIToggleGroup foldoutGroup        = new GUIToggleGroup(true);
            GUIToggle      contactFoldout      = new GUIToggle(new LocEdString("Main author"), foldoutGroup, EditorStyles.Foldout);
            GUIToggle      thirdPartyFoldout   = new GUIToggle(new LocEdString("Used third party libraries"), foldoutGroup, EditorStyles.Foldout);
            GUIToggle      noticesFoldout      = new GUIToggle(new LocEdString("Third party notices"), foldoutGroup, EditorStyles.Foldout);
            GUIToggle      contributorsFoldout = new GUIToggle(new LocEdString("Contributors"), foldoutGroup, EditorStyles.Foldout);
            GUIToggle      socialFoldout       = new GUIToggle(new LocEdString("Social"), foldoutGroup, EditorStyles.Foldout);

            contactFoldout.AcceptsKeyFocus      = false;
            thirdPartyFoldout.AcceptsKeyFocus   = false;
            noticesFoldout.AcceptsKeyFocus      = false;
            contributorsFoldout.AcceptsKeyFocus = false;
            socialFoldout.AcceptsKeyFocus       = false;

            GUILabel freeTypeNotice = new GUILabel(new LocEdString(
                                                       "Portions of this software are copyright (C) 2019 The FreeType Project (www.freetype.org). " +
                                                       "All rights reserved."), EditorStyles.MultiLineLabelCentered,
                                                   GUIOption.FlexibleHeight(), GUIOption.FixedWidth(380));

            GUILabel fbxSdkNotice = new GUILabel(new LocEdString(
                                                     "This software contains Autodesk(R) FBX(R) code developed by Autodesk, Inc. Copyright 2019 Autodesk, Inc. " +
                                                     "All rights, reserved. Such code is provided \"as is\" and Autodesk, Inc. disclaims any and all warranties, " +
                                                     "whether express or implied, including without limitation the implied warranties of merchantability, " +
                                                     "fitness for a particular purpose or non-infringement of third party rights. In no event shall Autodesk, " +
                                                     "Inc. be liable for any direct, indirect, incidental, special, exemplary, or consequential damages " +
                                                     "(including, but not limited to, procurement of substitute goods or services; loss of use, data, or " +
                                                     "profits; or business interruption) however caused and on any theory of liability, whether in contract, " +
                                                     "strict liability, or tort (including negligence or otherwise) arising in any way out of such code."),
                                                 EditorStyles.MultiLineLabelCentered, GUIOption.FlexibleHeight(), GUIOption.FixedWidth(380));

            string[ , ] contributorListEditor = new string[, ]
            {
                { "Danijel Ribic", "Logo, UI icons, 3D models & textures" },
                { "Marco Bellan", "Bugfixes, editor enhancements" },
                { "Robert Campbell", "Editor enhancements" },
                { "James Mitchell", "Build enhancements" },
                { "Patrick Recko", "Minor enhancements" }
            };

            string[] contributorListFramework = new string[]
            {
                "Marc Legendre",
                "Florian Will",
                "Marco Bellan",
                "Artur K. (@nemerle)",
                "Michael Jones",
                "Connor Fitzgerald",
                "Paolo Paoletto",
                "Patrick Recko",
                "Guillaume Meunier",
                "Andre Taulien",
                "James Mitchell",
                "and others..."
            };

            GUILayoutY mainLayout = GUI.AddLayoutY();

            mainLayout.AddSpace(10);
            mainLayout.AddElement(title);
            mainLayout.AddElement(subTitle);
            mainLayout.AddSpace(10);
            mainLayout.AddElement(bsfVersion);
            mainLayout.AddSpace(10);
            mainLayout.AddElement(license);
            mainLayout.AddSpace(5);
            mainLayout.AddElement(copyright);
            mainLayout.AddSpace(10);
            GUILayoutX donateButtonLayoutX = mainLayout.AddLayoutX();

            donateButtonLayoutX.AddSpace(10);
            donateButtonLayoutX.AddElement(patreonBtn);
            donateButtonLayoutX.AddSpace(10);
            donateButtonLayoutX.AddElement(paypalBtn);
            donateButtonLayoutX.AddSpace(10);
            mainLayout.AddSpace(10);

            mainLayout.AddElement(scrollArea);
            scrollArea.Layout.AddElement(contactFoldout);
            GUILayoutY contactLayout = scrollArea.Layout.AddLayoutY();

            contactLayout.AddSpace(15);
            GUILayout authorLayout = contactLayout.AddLayoutX();

            authorLayout.AddFlexibleSpace();
            authorLayout.AddElement(authorLabel);
            authorLayout.AddFlexibleSpace();
            contactLayout.AddSpace(15);
            GUILayout emailLayout = contactLayout.AddLayoutX();

            emailLayout.AddSpace(10);
            emailLayout.AddElement(emailTitle);
            emailLayout.AddElement(emailLabel);
            emailLayout.AddSpace(10);
            GUILayout linkedInLayout = contactLayout.AddLayoutX();

            linkedInLayout.AddSpace(10);
            linkedInLayout.AddElement(linkedInTitle);
            linkedInLayout.AddElement(linkedInBtn);
            linkedInLayout.AddSpace(10);

            scrollArea.Layout.AddSpace(5);
            scrollArea.Layout.AddElement(thirdPartyFoldout);
            GUILayoutY thirdPartyLayout = scrollArea.Layout.AddLayoutY();

            thirdPartyLayout.AddSpace(5);
            CreateNameURLBtnPair(thirdPartyLayout, "Autodesk FBX SDK",
                                 "https://www.autodesk.com/products/fbx/overview", "Website");
            CreateNameURLBtnPair(thirdPartyLayout, "FreeImage", "http://freeimage.sourceforge.net/", "Website");
            CreateNameURLBtnPair(thirdPartyLayout, "FreeType", "http://www.freetype.org/", "Website");
            CreateNameURLBtnPair(thirdPartyLayout, "Mono", "http://www.mono-project.com/", "Website");
            CreateNameURLBtnPair(thirdPartyLayout, "NVIDIA Texture Tools",
                                 "https://github.com/castano/nvidia-texture-tools", "Website");
            CreateNameURLBtnPair(thirdPartyLayout, "libFLAC", "https://xiph.org/flac/", "Website");
            CreateNameURLBtnPair(thirdPartyLayout, "libOgg", "https://www.xiph.org/ogg/", "Website");
            CreateNameURLBtnPair(thirdPartyLayout, "libVorbis", "http://www.vorbis.com/", "Website");
            CreateNameURLBtnPair(thirdPartyLayout, "OpenAL Soft", "http://kcat.strangesoft.net/openal.html", "Website");
            CreateNameURLBtnPair(thirdPartyLayout, "NVIDIA PhysX", "https://developer.nvidia.com/physx-sdk", "Website");

            scrollArea.Layout.AddSpace(5);
            scrollArea.Layout.AddElement(noticesFoldout);
            GUILayout noticesLayout = scrollArea.Layout.AddLayoutY();

            noticesLayout.AddSpace(5);
            noticesLayout.AddElement(freeTypeNotice);
            noticesLayout.AddSpace(10);
            noticesLayout.AddElement(fbxSdkNotice);

            scrollArea.Layout.AddSpace(5);
            scrollArea.Layout.AddElement(contributorsFoldout);
            GUILayoutY contributorsLayout = scrollArea.Layout.AddLayoutY();

            contributorsLayout.AddSpace(5);
            contributorsLayout.AddElement(editorContributorsLabel);
            contributorsLayout.AddSpace(5);
            for (int i = 0; i < contributorListEditor.Length / 2; i++)
            {
                CreateEditorContributorGUI(contributorsLayout, contributorListEditor[i, 0], contributorListEditor[i, 1]);
                contributorsLayout.AddSpace(5);
            }
            contributorsLayout.AddSpace(10);
            contributorsLayout.AddElement(frameworkContributorsLabel);
            contributorsLayout.AddSpace(5);
            for (int i = 0; i < contributorListFramework.Length; i++)
            {
                CreateFrameworkContributorGUI(contributorsLayout, contributorListFramework[i]);
                contributorsLayout.AddSpace(5);
            }

            scrollArea.Layout.AddSpace(5);
            scrollArea.Layout.AddElement(socialFoldout);
            GUILayoutY socialLayout = scrollArea.Layout.AddLayoutY();

            socialLayout.AddSpace(10);
            CreateNameURLBtnPair(socialLayout, "Discord", "https://discord.gg/8Xyf5gF", "Enter");
            socialLayout.AddSpace(10);
            socialLayout.AddElement(engineLabel);
            socialLayout.AddSpace(5);
            CreateNameURLBtnPair(socialLayout, "Website", "http://www.banshee3d.com", "Enter");
            CreateNameURLBtnPair(socialLayout, "Repository", "https://github.com/BearishSun/BansheeEngine", "Enter");
            CreateNameURLBtnPair(socialLayout, "Forums", "https://forum.banshee3d.com", "Enter");
            CreateNameURLBtnPair(socialLayout, "Twitter", "https://twitter.com/Banshee3D", "Enter");
            CreateNameURLBtnPair(socialLayout, "Facebook", "https://www.facebook.com/Banshee3D", "Enter");
            socialLayout.AddSpace(10);
            socialLayout.AddElement(frameworkLabel);
            socialLayout.AddSpace(5);
            CreateNameURLBtnPair(socialLayout, "Website", "http://www.bsframework.io", "Enter");
            CreateNameURLBtnPair(socialLayout, "Repository", "https://github.com/GameFoundry/bsf", "Enter");
            CreateNameURLBtnPair(socialLayout, "Forums", "https://discourse.bsframework.io/", "Enter");
            CreateNameURLBtnPair(socialLayout, "Twitter", "https://twitter.com/thebsframework", "Enter");
            CreateNameURLBtnPair(socialLayout, "Facebook", "https://www.facebook.com/bsframework", "Enter");
            mainLayout.AddFlexibleSpace();

            contactLayout.Active      = false;
            contactFoldout.OnToggled += x => contactLayout.Active = x;

            thirdPartyLayout.Active      = false;
            thirdPartyFoldout.OnToggled += x => thirdPartyLayout.Active = x;

            noticesLayout.Active      = false;
            noticesFoldout.OnToggled += x => noticesLayout.Active = x;

            contributorsLayout.Active      = false;
            contributorsFoldout.OnToggled += x => contributorsLayout.Active = x;

            socialLayout.Active      = false;
            socialFoldout.OnToggled += x => socialLayout.Active = x;

            emailLabel.Text      = "*****@*****.**";
            linkedInBtn.OnClick += () => { System.Diagnostics.Process.Start("https://www.linkedin.com/in/markopintera"); };
            patreonBtn.OnClick  += () => { System.Diagnostics.Process.Start("https://www.patreon.com/bsf"); };
            paypalBtn.OnClick   += () => { System.Diagnostics.Process.Start("https://www.paypal.me/MarkoPintera/10"); };
        }
Beispiel #12
0
        private void OnInitialize()
        {
            Title = "Project Manager";

            Width  = 500;
            Height = 290;

            GUILayout vertLayout = GUI.AddLayoutY();

            vertLayout.AddSpace(5);
            GUILayout firstRow = vertLayout.AddLayoutX();

            vertLayout.AddFlexibleSpace();
            GUILayout secondRow = vertLayout.AddLayoutX();

            vertLayout.AddSpace(5);
            GUILayout thirdRow = vertLayout.AddLayoutX();

            vertLayout.AddFlexibleSpace();
            GUILayout fourthRow = vertLayout.AddLayoutX();

            vertLayout.AddSpace(5);

            projectInputBox       = new GUITextField(new LocEdString("Project path"), 70, false, "", GUIOption.FixedWidth(398));
            projectInputBox.Value = EditorSettings.LastOpenProject;

            GUIButton openBtn = new GUIButton(new LocEdString("Open"), GUIOption.FixedWidth(75));

            openBtn.OnClick += OpenProject;

            firstRow.AddSpace(5);
            firstRow.AddElement(projectInputBox);
            firstRow.AddSpace(15);
            firstRow.AddElement(openBtn);
            firstRow.AddSpace(5);

            GUILabel recentProjectsLabel = new GUILabel(new LocEdString("Recent projects:"));

            secondRow.AddSpace(5);
            secondRow.AddElement(recentProjectsLabel);
            secondRow.AddFlexibleSpace();
            GUIButton browseBtn = new GUIButton(new LocEdString("Browse"), GUIOption.FixedWidth(75));

            browseBtn.OnClick += BrowseClicked;
            secondRow.AddElement(browseBtn);
            secondRow.AddSpace(5);

            thirdRow.AddSpace(5);
            GUIPanel recentProjectsPanel = thirdRow.AddPanel();

            thirdRow.AddSpace(15);
            GUILayoutY thirdRowVertical = thirdRow.AddLayoutY();
            GUIButton  createBtn        = new GUIButton(new LocEdString("Create new"), GUIOption.FixedWidth(75));

            createBtn.OnClick += CreateClicked;
            thirdRowVertical.AddElement(createBtn);
            thirdRowVertical.AddFlexibleSpace();
            thirdRow.AddSpace(5);

            recentProjectsArea = new GUIScrollArea(GUIOption.FixedWidth(385), GUIOption.FixedHeight(170));
            GUILayoutX recentProjectsLayout = recentProjectsPanel.AddLayoutX();

            recentProjectsLayout.AddSpace(10);
            GUILayoutY recentProjectsPanelY = recentProjectsLayout.AddLayoutY();

            recentProjectsPanelY.AddSpace(5);
            recentProjectsPanelY.AddElement(recentProjectsArea);
            recentProjectsPanelY.AddSpace(5);
            recentProjectsLayout.AddFlexibleSpace();

            GUIPanel   scrollAreaBgPanel = recentProjectsPanel.AddPanel(1);
            GUITexture scrollAreaBgTex   = new GUITexture(null, true, EditorStylesInternal.ScrollAreaBg);

            scrollAreaBgPanel.AddElement(scrollAreaBgTex);

            autoLoadToggle       = new GUIToggle("");
            autoLoadToggle.Value = EditorSettings.AutoLoadLastProject;

            GUILabel autoLoadLabel = new GUILabel(new LocEdString("Automatically load last open project"));

            GUIButton cancelBtn = new GUIButton(new LocEdString("Cancel"), GUIOption.FixedWidth(75));

            cancelBtn.OnClick += CancelClicked;

            fourthRow.AddSpace(5);
            fourthRow.AddElement(autoLoadToggle);
            fourthRow.AddElement(autoLoadLabel);
            fourthRow.AddFlexibleSpace();
            fourthRow.AddElement(cancelBtn);
            fourthRow.AddSpace(5);

            RefreshRecentProjects();
        }
        /// <inheritdoc/>
        protected internal override void Initialize()
        {
            Animation animation = (Animation)InspectedObject;

            drawer.AddDefault(animation);

            // Morph shapes
            Renderable  renderable  = animation.SceneObject.GetComponent <Renderable>();
            MorphShapes morphShapes = renderable?.Mesh.Value?.MorphShapes;

            if (morphShapes != null)
            {
                GUIToggle morphShapesToggle = new GUIToggle(new LocEdString("Morph shapes"), EditorStyles.Foldout);

                Layout.AddElement(morphShapesToggle);
                GUILayoutY channelsLayout = Layout.AddLayoutY();

                morphShapesToggle.OnToggled += x =>
                {
                    channelsLayout.Active = x;
                    Persistent.SetBool("Channels_Expanded", x);
                };

                channelsLayout.Active = Persistent.GetBool("Channels_Expanded");

                MorphChannel[] channels = morphShapes.Channels;
                for (int i = 0; i < channels.Length; i++)
                {
                    GUILayoutY channelLayout = channelsLayout.AddLayoutY();

                    GUILayoutX channelTitleLayout = channelLayout.AddLayoutX();
                    channelLayout.AddSpace(5);
                    GUILayoutY channelContentLayout = channelLayout.AddLayoutY();

                    string    channelName      = channels[i].Name;
                    GUIToggle channelNameField = new GUIToggle(channelName, EditorStyles.Expand, GUIOption.FlexibleWidth());

                    channelTitleLayout.AddSpace(15); // Indent
                    channelTitleLayout.AddElement(channelNameField);
                    channelTitleLayout.AddFlexibleSpace();

                    channelNameField.OnToggled += x =>
                    {
                        channelContentLayout.Active = x;

                        Persistent.SetBool(channelName + "_Expanded", x);
                    };

                    channelContentLayout.Active = Persistent.GetBool(channelName + "_Expanded");

                    MorphShape[] shapes = channels[i].Shapes;
                    for (int j = 0; j < shapes.Length; j++)
                    {
                        GUILayoutX shapeLayout = channelContentLayout.AddLayoutX();
                        channelContentLayout.AddSpace(5);

                        LocString nameString = new LocString("[{0}]. {1}");
                        nameString.SetParameter(0, j.ToString());
                        nameString.SetParameter(1, shapes[j].Name);
                        GUILabel shapeNameField = new GUILabel(shapes[j].Name);

                        LocString weightString = new LocEdString("Weight: {0}");
                        weightString.SetParameter(0, shapes[j].Weight.ToString());
                        GUILabel weightField = new GUILabel(weightString);

                        shapeLayout.AddSpace(30); // Indent
                        shapeLayout.AddElement(shapeNameField);
                        shapeLayout.AddFlexibleSpace();
                        shapeLayout.AddElement(weightField);
                    }
                }
            }
        }
Beispiel #14
0
        /// <summary>
        /// Creates inspectable fields all the fields/properties of the specified object.
        /// </summary>
        /// <param name="obj">Object whose fields the GUI will be drawn for.</param>
        /// <param name="parent">Parent Inspector to draw in.</param>
        /// <param name="path">Full path to the field this provided object was retrieved from.</param>
        /// <param name="depth">
        /// Determines how deep within the inspector nesting hierarchy is this objects. Some fields may contain other
        /// fields, in which case you should increase this value by one.
        /// </param>
        /// <param name="layout">Parent layout that all the field GUI elements will be added to.</param>
        /// <param name="overrideCallback">
        /// Optional callback that allows you to override the look of individual fields in the object. If non-null the
        /// callback will be called with information about every field in the provided object. If the callback returns
        /// non-null that inspectable field will be used for drawing the GUI, otherwise the default inspector field type
        /// will be used.
        /// </param>
        public static List <InspectableField> CreateFields(SerializableObject obj, Inspector parent, string path,
                                                           int depth, GUILayoutY layout, FieldOverrideCallback overrideCallback = null)
        {
            // Retrieve fields and sort by order
            SerializableField[] fields = obj.Fields;
            Array.Sort(fields,
                       (x, y) =>
            {
                int orderX = x.Flags.HasFlag(SerializableFieldAttributes.Order) ? x.Style.Order : 0;
                int orderY = y.Flags.HasFlag(SerializableFieldAttributes.Order) ? y.Style.Order : 0;

                return(orderX.CompareTo(orderY));
            });

            // Generate per-field GUI while grouping by category
            Dictionary <string, Tuple <int, GUILayoutY> > categories = new Dictionary <string, Tuple <int, GUILayoutY> >();

            int rootIndex = 0;
            List <InspectableField> inspectableFields = new List <InspectableField>();

            foreach (var field in fields)
            {
                if (!field.Flags.HasFlag(SerializableFieldAttributes.Inspectable))
                {
                    continue;
                }

                string category = null;
                if (field.Flags.HasFlag(SerializableFieldAttributes.Category))
                {
                    category = field.Style.CategoryName;
                }

                Tuple <int, GUILayoutY> categoryInfo = null;
                if (!string.IsNullOrEmpty(category))
                {
                    if (!categories.TryGetValue(category, out categoryInfo))
                    {
                        InspectableFieldLayout fieldLayout        = new InspectableFieldLayout(layout);
                        GUILayoutY             categoryRootLayout = fieldLayout.AddLayoutY(rootIndex);
                        GUILayoutX             guiTitleLayout     = categoryRootLayout.AddLayoutX();

                        bool isExpanded = parent.Persistent.GetBool(path + "/[" + category + "]_Expanded");

                        GUIToggle guiFoldout = new GUIToggle(category, EditorStyles.Foldout);
                        guiFoldout.Value           = isExpanded;
                        guiFoldout.AcceptsKeyFocus = false;
                        guiFoldout.OnToggled      += x =>
                        {
                            parent.Persistent.SetBool(path + "/[" + category + "]_Expanded", x);
                        };
                        guiTitleLayout.AddElement(guiFoldout);

                        GUILayoutX categoryContentLayout = categoryRootLayout.AddLayoutX();
                        categoryContentLayout.AddSpace(IndentAmount);

                        GUIPanel   guiContentPanel  = categoryContentLayout.AddPanel();
                        GUILayoutX guiIndentLayoutX = guiContentPanel.AddLayoutX();
                        guiIndentLayoutX.AddSpace(IndentAmount);
                        GUILayoutY guiIndentLayoutY = guiIndentLayoutX.AddLayoutY();
                        guiIndentLayoutY.AddSpace(IndentAmount);
                        GUILayoutY categoryLayout = guiIndentLayoutY.AddLayoutY();
                        guiIndentLayoutY.AddSpace(IndentAmount);
                        guiIndentLayoutX.AddSpace(IndentAmount);
                        categoryContentLayout.AddSpace(IndentAmount);

                        short  backgroundDepth = (short)(Inspector.START_BACKGROUND_DEPTH - depth - 1);
                        string bgPanelStyle    = depth % 2 == 0
                            ? EditorStylesInternal.InspectorContentBgAlternate
                            : EditorStylesInternal.InspectorContentBg;
                        GUIPanel   backgroundPanel    = guiContentPanel.AddPanel(backgroundDepth);
                        GUITexture inspectorContentBg = new GUITexture(null, bgPanelStyle);
                        backgroundPanel.AddElement(inspectorContentBg);

                        categories[category] = new Tuple <int, GUILayoutY>(0, categoryLayout);
                        rootIndex++;
                    }
                }

                int        currentIndex;
                GUILayoutY parentLayout;
                if (categoryInfo != null)
                {
                    currentIndex = categoryInfo.Item1;
                    parentLayout = categoryInfo.Item2;
                }
                else
                {
                    currentIndex = rootIndex;
                    parentLayout = layout;
                }

                string fieldName = field.Name;
                string childPath = string.IsNullOrEmpty(path) ? fieldName : path + "/" + fieldName;

                InspectableField inspectableField = null;

                if (overrideCallback != null)
                {
                    inspectableField = overrideCallback(field, parent, path, new InspectableFieldLayout(parentLayout),
                                                        currentIndex, depth);
                }

                if (inspectableField == null)
                {
                    inspectableField = CreateField(parent, fieldName, childPath,
                                                   currentIndex, depth, new InspectableFieldLayout(parentLayout), field.GetProperty(),
                                                   InspectableFieldStyle.Create(field));
                }

                inspectableFields.Add(inspectableField);
                currentIndex += inspectableField.GetNumLayoutElements();

                if (categoryInfo != null)
                {
                    categories[category] = new Tuple <int, GUILayoutY>(currentIndex, parentLayout);
                }
                else
                {
                    rootIndex = currentIndex;
                }
            }

            return(inspectableFields);
        }
Beispiel #15
0
            /// <summary>
            /// Builds GUI for the specified GUI element style.
            /// </summary>
            /// <param name="layout">Layout to append the GUI elements to.</param>
            /// <param name="depth">Determines the depth at which the element is rendered.</param>
            public void BuildGUI(GUILayout layout, int depth)
            {
                short  backgroundDepth = (short)(Inspector.START_BACKGROUND_DEPTH - depth - 1);
                string bgPanelStyle    = depth % 2 == 0
                    ? EditorStylesInternal.InspectorContentBgAlternate
                    : EditorStylesInternal.InspectorContentBg;

                GUIToggle foldout = new GUIToggle(new LocEdString("Style"), EditorStyles.Foldout);

                foldout.AcceptsKeyFocus = false;

                GUITexture inspectorContentBg = new GUITexture(null, bgPanelStyle);

                layout.AddElement(foldout);
                GUIPanel panel           = layout.AddPanel();
                GUIPanel backgroundPanel = panel.AddPanel(backgroundDepth);

                backgroundPanel.AddElement(inspectorContentBg);

                GUILayoutX guiIndentLayoutX = panel.AddLayoutX();

                guiIndentLayoutX.AddSpace(IndentAmount);
                GUILayoutY guiIndentLayoutY = guiIndentLayoutX.AddLayoutY();

                guiIndentLayoutY.AddSpace(IndentAmount);
                GUILayoutY contentLayout = guiIndentLayoutY.AddLayoutY();

                guiIndentLayoutY.AddSpace(IndentAmount);
                guiIndentLayoutX.AddSpace(IndentAmount);

                fontField          = new GUIResourceField(typeof(Font), new LocEdString("Font"));
                fontSizeField      = new GUIIntField(new LocEdString("Font size"));
                horzAlignField     = new GUIEnumField(typeof(TextHorzAlign), new LocEdString("Horizontal alignment"));
                vertAlignField     = new GUIEnumField(typeof(TextVertAlign), new LocEdString("Vertical alignment"));
                imagePositionField = new GUIEnumField(typeof(GUIImagePosition), new LocEdString("Image position"));
                wordWrapField      = new GUIToggleField(new LocEdString("Word wrap"));

                contentLayout.AddElement(fontField);
                contentLayout.AddElement(fontSizeField);
                contentLayout.AddElement(horzAlignField);
                contentLayout.AddElement(vertAlignField);
                contentLayout.AddElement(imagePositionField);
                contentLayout.AddElement(wordWrapField);

                normalGUI.BuildGUI(new LocEdString("Normal"), contentLayout);
                hoverGUI.BuildGUI(new LocEdString("Hover"), contentLayout);
                activeGUI.BuildGUI(new LocEdString("Active"), contentLayout);
                focusedGUI.BuildGUI(new LocEdString("Focused"), contentLayout);
                normalOnGUI.BuildGUI(new LocEdString("NormalOn"), contentLayout);
                hoverOnGUI.BuildGUI(new LocEdString("HoverOn"), contentLayout);
                activeOnGUI.BuildGUI(new LocEdString("ActiveOn"), contentLayout);
                focusedOnGUI.BuildGUI(new LocEdString("FocusedOn"), contentLayout);

                borderGUI        = new RectOffsetGUI(new LocEdString("Border"), contentLayout);
                marginsGUI       = new RectOffsetGUI(new LocEdString("Margins"), contentLayout);
                contentOffsetGUI = new RectOffsetGUI(new LocEdString("Content offset"), contentLayout);

                fixedWidthField = new GUIToggleField(new LocEdString("Fixed width"));
                widthField      = new GUIIntField(new LocEdString("Width"));
                minWidthField   = new GUIIntField(new LocEdString("Min. width"));
                maxWidthField   = new GUIIntField(new LocEdString("Max. width"));

                fixedHeightField = new GUIToggleField(new LocEdString("Fixed height"));
                heightField      = new GUIIntField(new LocEdString("Height"));
                minHeightField   = new GUIIntField(new LocEdString("Min. height"));
                maxHeightField   = new GUIIntField(new LocEdString("Max. height"));

                contentLayout.AddElement(fixedWidthField);
                contentLayout.AddElement(widthField);
                contentLayout.AddElement(minWidthField);
                contentLayout.AddElement(maxWidthField);

                contentLayout.AddElement(fixedHeightField);
                contentLayout.AddElement(heightField);
                contentLayout.AddElement(minHeightField);
                contentLayout.AddElement(maxHeightField);

                foldout.OnToggled += x =>
                {
                    panel.Active = x;
                    isExpanded   = x;
                };

                fontField.OnChanged += x =>
                {
                    Font font = Resources.Load <Font>(x.UUID);

                    GetStyle().Font = font;
                    MarkAsModified();
                    ConfirmModify();
                };
                fontSizeField.OnChanged           += x => { GetStyle().FontSize = x; MarkAsModified(); };
                fontSizeField.OnFocusLost         += ConfirmModify;
                fontSizeField.OnConfirmed         += ConfirmModify;
                horzAlignField.OnSelectionChanged += x =>
                {
                    GetStyle().TextHorzAlign = (TextHorzAlign)x;
                    MarkAsModified();
                    ConfirmModify();
                };
                vertAlignField.OnSelectionChanged += x =>
                {
                    GetStyle().TextVertAlign = (TextVertAlign)x;
                    MarkAsModified();
                    ConfirmModify();
                };
                imagePositionField.OnSelectionChanged += x =>
                {
                    GetStyle().ImagePosition = (GUIImagePosition)x;
                    MarkAsModified();
                    ConfirmModify();
                };
                wordWrapField.OnChanged += x => { GetStyle().WordWrap = x; MarkAsModified(); ConfirmModify(); };

                normalGUI.OnChanged    += x => { GetStyle().Normal = x; MarkAsModified(); ConfirmModify(); };
                hoverGUI.OnChanged     += x => { GetStyle().Hover = x; MarkAsModified(); ConfirmModify(); };
                activeGUI.OnChanged    += x => { GetStyle().Active = x; MarkAsModified(); ConfirmModify(); };
                focusedGUI.OnChanged   += x => { GetStyle().Focused = x; MarkAsModified(); ConfirmModify(); };
                normalOnGUI.OnChanged  += x => { GetStyle().NormalOn = x; MarkAsModified(); ConfirmModify(); };
                hoverOnGUI.OnChanged   += x => { GetStyle().HoverOn = x; MarkAsModified(); ConfirmModify(); };
                activeOnGUI.OnChanged  += x => { GetStyle().ActiveOn = x; MarkAsModified(); ConfirmModify(); };
                focusedOnGUI.OnChanged += x => { GetStyle().FocusedOn = x; MarkAsModified(); ConfirmModify(); };

                borderGUI.OnChanged        += x => { GetStyle().Border = x; MarkAsModified(); };
                marginsGUI.OnChanged       += x => { GetStyle().Margins = x; MarkAsModified(); };
                contentOffsetGUI.OnChanged += x => { GetStyle().ContentOffset = x; MarkAsModified(); };

                borderGUI.OnConfirmed        += ConfirmModify;
                marginsGUI.OnConfirmed       += ConfirmModify;
                contentOffsetGUI.OnConfirmed += ConfirmModify;

                fixedWidthField.OnChanged += x => { GetStyle().FixedWidth = x; MarkAsModified(); ConfirmModify(); };
                widthField.OnChanged      += x => GetStyle().Width = x;
                widthField.OnFocusLost    += ConfirmModify;
                widthField.OnConfirmed    += ConfirmModify;
                minWidthField.OnChanged   += x => GetStyle().MinWidth = x;
                minWidthField.OnFocusLost += ConfirmModify;
                minWidthField.OnConfirmed += ConfirmModify;
                maxWidthField.OnChanged   += x => GetStyle().MaxWidth = x;
                maxWidthField.OnFocusLost += ConfirmModify;
                maxWidthField.OnConfirmed += ConfirmModify;

                fixedHeightField.OnChanged += x => { GetStyle().FixedHeight = x; MarkAsModified(); ConfirmModify(); };
                heightField.OnChanged      += x => GetStyle().Height = x;
                heightField.OnFocusLost    += ConfirmModify;
                heightField.OnConfirmed    += ConfirmModify;
                minHeightField.OnChanged   += x => GetStyle().MinHeight = x;
                minHeightField.OnFocusLost += ConfirmModify;
                minHeightField.OnConfirmed += ConfirmModify;
                maxHeightField.OnChanged   += x => GetStyle().MaxHeight = x;
                maxHeightField.OnFocusLost += ConfirmModify;
                maxHeightField.OnConfirmed += ConfirmModify;

                foldout.Value = isExpanded;
                panel.Active  = isExpanded;
            }
Beispiel #16
0
        /// <summary>
        /// Rebuilds the GUI object header if needed.
        /// </summary>
        /// <param name="layoutIndex">Index at which to insert the GUI elements.</param>
        protected void BuildGUI(int layoutIndex)
        {
            Action BuildEmptyGUI = () =>
            {
                guiInternalTitleLayout = guiTitleLayout.InsertLayoutX(0);

                guiInternalTitleLayout.AddElement(new GUILabel(title));
                guiInternalTitleLayout.AddElement(new GUILabel("Empty", GUIOption.FixedWidth(100)));

                if (!property.IsValueType)
                {
                    GUIContent createIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Create),
                                                           new LocEdString("Create"));
                    guiCreateBtn          = new GUIButton(createIcon, GUIOption.FixedWidth(30));
                    guiCreateBtn.OnClick += OnCreateButtonClicked;
                    guiInternalTitleLayout.AddElement(guiCreateBtn);
                }
            };

            Action BuildFilledGUI = () =>
            {
                guiInternalTitleLayout = guiTitleLayout.InsertLayoutX(0);

                GUIToggle guiFoldout = new GUIToggle(title, EditorStyles.Foldout);
                guiFoldout.Value           = isExpanded;
                guiFoldout.AcceptsKeyFocus = false;
                guiFoldout.OnToggled      += OnFoldoutToggled;
                guiInternalTitleLayout.AddElement(guiFoldout);

                if (!style.StyleFlags.HasFlag(InspectableFieldStyleFlags.NotNull))
                {
                    GUIContent clearIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Clear),
                                                          new LocEdString("Clear"));
                    GUIButton clearBtn = new GUIButton(clearIcon, GUIOption.FixedWidth(20));
                    clearBtn.OnClick += OnClearButtonClicked;
                    guiInternalTitleLayout.AddElement(clearBtn);
                }

                if (isExpanded)
                {
                    SerializableObject  serializableObject = property.GetObject();
                    SerializableField[] fields             = serializableObject.Fields;

                    if (fields.Length > 0)
                    {
                        guiChildLayout = guiLayout.AddLayoutX();
                        guiChildLayout.AddSpace(IndentAmount);

                        GUIPanel   guiContentPanel  = guiChildLayout.AddPanel();
                        GUILayoutX guiIndentLayoutX = guiContentPanel.AddLayoutX();
                        guiIndentLayoutX.AddSpace(IndentAmount);
                        GUILayoutY guiIndentLayoutY = guiIndentLayoutX.AddLayoutY();
                        guiIndentLayoutY.AddSpace(IndentAmount);
                        GUILayoutY guiContentLayout = guiIndentLayoutY.AddLayoutY();
                        guiIndentLayoutY.AddSpace(IndentAmount);
                        guiIndentLayoutX.AddSpace(IndentAmount);
                        guiChildLayout.AddSpace(IndentAmount);

                        short  backgroundDepth = (short)(Inspector.START_BACKGROUND_DEPTH - depth - 1);
                        string bgPanelStyle    = depth % 2 == 0
                           ? EditorStylesInternal.InspectorContentBgAlternate
                           : EditorStylesInternal.InspectorContentBg;
                        GUIPanel   backgroundPanel    = guiContentPanel.AddPanel(backgroundDepth);
                        GUITexture inspectorContentBg = new GUITexture(null, bgPanelStyle);
                        backgroundPanel.AddElement(inspectorContentBg);

                        int currentIndex = 0;
                        foreach (var field in fields)
                        {
                            if (!field.Flags.HasFlag(SerializableFieldAttributes.Inspectable))
                            {
                                continue;
                            }

                            string childPath = path + "/" + field.Name;

                            InspectableField inspectable = CreateInspectable(parent, field.Name, childPath,
                                                                             currentIndex, depth + 1, new InspectableFieldLayout(guiContentLayout), field.GetProperty(), InspectableFieldStyle.Create(field));

                            children.Add(inspectable);
                            currentIndex += inspectable.GetNumLayoutElements();
                        }
                    }
                }
                else
                {
                    guiChildLayout = null;
                }
            };

            if (state == State.None)
            {
                if (propertyValue != null)
                {
                    BuildFilledGUI();
                    state = State.Filled;
                }
                else
                {
                    BuildEmptyGUI();

                    state = State.Empty;
                }
            }
            else if (state == State.Empty)
            {
                if (propertyValue != null)
                {
                    guiInternalTitleLayout.Destroy();
                    guiCreateBtn = null;

                    BuildFilledGUI();
                    state = State.Filled;
                }
            }
            else if (state == State.Filled)
            {
                foreach (var child in children)
                {
                    child.Destroy();
                }

                children.Clear();
                guiInternalTitleLayout.Destroy();
                guiCreateBtn = null;

                if (guiChildLayout != null)
                {
                    guiChildLayout.Destroy();
                    guiChildLayout = null;
                }

                if (propertyValue == null)
                {
                    BuildEmptyGUI();
                    state = State.Empty;
                }
                else
                {
                    BuildFilledGUI();
                }
            }
        }
Beispiel #17
0
        /// <summary>
        /// Rebuilds the GUI object header if needed.
        /// </summary>
        /// <param name="layoutIndex">Index at which to insert the GUI elements.</param>
        protected void BuildGUI(int layoutIndex)
        {
            Action BuildEmptyGUI = () =>
            {
                if (isInline)
                {
                    return;
                }

                guiInternalTitleLayout = guiTitleLayout.InsertLayoutX(0);

                guiInternalTitleLayout.AddElement(new GUILabel(title));
                guiInternalTitleLayout.AddElement(new GUILabel("Empty", GUIOption.FixedWidth(100)));

                if (!property.IsValueType)
                {
                    GUIContent createIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Create),
                                                           new LocEdString("Create"));
                    guiCreateBtn          = new GUIButton(createIcon, GUIOption.FixedWidth(30));
                    guiCreateBtn.OnClick += OnCreateButtonClicked;
                    guiInternalTitleLayout.AddElement(guiCreateBtn);
                }
            };

            Action BuildFilledGUI = () =>
            {
                if (!isInline)
                {
                    guiInternalTitleLayout = guiTitleLayout.InsertLayoutX(0);

                    GUIToggle guiFoldout = new GUIToggle(title, EditorStyles.Foldout);
                    guiFoldout.Value           = isExpanded;
                    guiFoldout.AcceptsKeyFocus = false;
                    guiFoldout.OnToggled      += OnFoldoutToggled;
                    guiInternalTitleLayout.AddElement(guiFoldout);

                    if (!property.IsValueType && (style == null || !style.StyleFlags.HasFlag(InspectableFieldStyleFlags.NotNull)))
                    {
                        GUIContent clearIcon = new GUIContent(
                            EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Clear),
                            new LocEdString("Clear"));
                        GUIButton clearBtn = new GUIButton(clearIcon, GUIOption.FixedWidth(20));
                        clearBtn.OnClick += OnClearButtonClicked;
                        guiInternalTitleLayout.AddElement(clearBtn);
                    }
                }

                if (isExpanded || isInline)
                {
                    SerializableObject  serializableObject = property.GetObject();
                    SerializableField[] fields             = serializableObject.Fields;

                    if (fields.Length > 0)
                    {
                        GUILayoutY guiContentLayout;
                        if (!isInline)
                        {
                            guiChildLayout = guiLayout.AddLayoutX();
                            guiChildLayout.AddSpace(IndentAmount);

                            GUIPanel   guiContentPanel  = guiChildLayout.AddPanel();
                            GUILayoutX guiIndentLayoutX = guiContentPanel.AddLayoutX();
                            guiIndentLayoutX.AddSpace(IndentAmount);
                            GUILayoutY guiIndentLayoutY = guiIndentLayoutX.AddLayoutY();
                            guiIndentLayoutY.AddSpace(IndentAmount);
                            guiContentLayout = guiIndentLayoutY.AddLayoutY();
                            guiIndentLayoutY.AddSpace(IndentAmount);
                            guiIndentLayoutX.AddSpace(IndentAmount);
                            guiChildLayout.AddSpace(IndentAmount);

                            short  backgroundDepth = (short)(Inspector.START_BACKGROUND_DEPTH - depth - 1);
                            string bgPanelStyle    = depth % 2 == 0
                                ? EditorStylesInternal.InspectorContentBgAlternate
                                : EditorStylesInternal.InspectorContentBg;
                            GUIPanel   backgroundPanel    = guiContentPanel.AddPanel(backgroundDepth);
                            GUITexture inspectorContentBg = new GUITexture(null, bgPanelStyle);
                            backgroundPanel.AddElement(inspectorContentBg);
                        }
                        else
                        {
                            guiContentLayout = guiLayout;
                        }

                        drawer = new InspectorFieldDrawer(context, guiContentLayout, path, depth + 1);
                        drawer.AddDefault(serializableObject);

                        if (!active)
                        {
                            foreach (var field in drawer.Fields)
                            {
                                field.Active = false;
                            }
                        }
                    }
                }
                else
                {
                    guiChildLayout = null;
                }
            };

            if (state == State.None)
            {
                if (propertyValue != null)
                {
                    BuildFilledGUI();
                    state = State.Filled;
                }
                else
                {
                    BuildEmptyGUI();

                    state = State.Empty;
                }
            }
            else if (state == State.Empty)
            {
                if (propertyValue != null)
                {
                    guiInternalTitleLayout?.Destroy();
                    guiInternalTitleLayout = null;
                    guiCreateBtn           = null;

                    BuildFilledGUI();
                    state = State.Filled;
                }
            }
            else if (state == State.Filled)
            {
                drawer?.Clear();

                guiInternalTitleLayout?.Destroy();
                guiInternalTitleLayout = null;
                guiCreateBtn           = null;

                if (guiChildLayout != null)
                {
                    guiChildLayout.Destroy();
                    guiChildLayout = null;
                }

                if (propertyValue == null)
                {
                    BuildEmptyGUI();
                    state = State.Empty;
                }
                else
                {
                    BuildFilledGUI();
                }
            }
        }
Beispiel #18
0
        /// <summary>
        /// Rebuilds the GUI list header if needed.
        /// </summary>
        protected void UpdateHeaderGUI()
        {
            Action BuildEmptyGUI = () =>
            {
                guiInternalTitleLayout = guiTitleLayout.InsertLayoutX(0);

                guiInternalTitleLayout.AddElement(new GUILabel(title));
                guiInternalTitleLayout.AddElement(new GUILabel("Empty", GUIOption.FixedWidth(100)));

                GUIContent createIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Create),
                                                       new LocEdString("Create"));
                GUIButton createBtn = new GUIButton(createIcon, GUIOption.FixedWidth(30));
                createBtn.OnClick += OnCreateButtonClicked;
                guiInternalTitleLayout.AddElement(createBtn);
            };

            Action BuildFilledGUI = () =>
            {
                guiInternalTitleLayout = guiTitleLayout.InsertLayoutX(0);

                GUIToggle guiFoldout = new GUIToggle(title, EditorStyles.Foldout);
                guiFoldout.Value      = isExpanded;
                guiFoldout.OnToggled += ToggleFoldout;
                guiSizeField          = new GUIIntField("", GUIOption.FixedWidth(50));
                guiSizeField.SetRange(0, int.MaxValue);

                GUIContent resizeIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Resize),
                                                       new LocEdString("Resize"));
                GUIButton guiResizeBtn = new GUIButton(resizeIcon, GUIOption.FixedWidth(30));
                guiResizeBtn.OnClick += OnResizeButtonClicked;

                GUIContent clearIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Clear),
                                                      new LocEdString("Clear"));
                GUIButton guiClearBtn = new GUIButton(clearIcon, GUIOption.FixedWidth(30));
                guiClearBtn.OnClick += OnClearButtonClicked;

                guiInternalTitleLayout.AddElement(guiFoldout);
                guiInternalTitleLayout.AddElement(guiSizeField);
                guiInternalTitleLayout.AddElement(guiResizeBtn);
                guiInternalTitleLayout.AddElement(guiClearBtn);

                guiSizeField.Value = GetNumRows();

                guiChildLayout = guiLayout.AddLayoutX();
                guiChildLayout.AddSpace(IndentAmount);
                guiChildLayout.Active = isExpanded;

                GUIPanel   guiContentPanel  = guiChildLayout.AddPanel();
                GUILayoutX guiIndentLayoutX = guiContentPanel.AddLayoutX();
                guiIndentLayoutX.AddSpace(IndentAmount);
                GUILayoutY guiIndentLayoutY = guiIndentLayoutX.AddLayoutY();
                guiIndentLayoutY.AddSpace(IndentAmount);
                guiContentLayout = guiIndentLayoutY.AddLayoutY();
                guiIndentLayoutY.AddSpace(IndentAmount);
                guiIndentLayoutX.AddSpace(IndentAmount);
                guiChildLayout.AddSpace(IndentAmount);

                short  backgroundDepth = (short)(Inspector.START_BACKGROUND_DEPTH - depth - 1);
                string bgPanelStyle    = depth % 2 == 0
                    ? EditorStyles.InspectorContentBgAlternate
                    : EditorStyles.InspectorContentBg;

                GUIPanel   backgroundPanel    = guiContentPanel.AddPanel(backgroundDepth);
                GUITexture inspectorContentBg = new GUITexture(null, bgPanelStyle);
                backgroundPanel.AddElement(inspectorContentBg);
            };

            if (state == State.None)
            {
                if (!IsNull())
                {
                    BuildFilledGUI();
                    state = State.Filled;
                }
                else
                {
                    BuildEmptyGUI();

                    state = State.Empty;
                }
            }
            else if (state == State.Empty)
            {
                if (!IsNull())
                {
                    guiInternalTitleLayout.Destroy();
                    BuildFilledGUI();
                    state = State.Filled;
                }
            }
            else if (state == State.Filled)
            {
                if (IsNull())
                {
                    guiInternalTitleLayout.Destroy();
                    guiChildLayout.Destroy();
                    BuildEmptyGUI();

                    state = State.Empty;
                }
            }
        }
        /// <summary>
        /// Creates a new GUI layout of the specified type, with a texture background.
        /// </summary>
        /// <typeparam name="T">Type of layout to create.</typeparam>
        /// <param name="layout">Parent layout to add the layout to.</param>
        /// <param name="background">Texture to display on the background.</param>
        /// <param name="backgroundColor">Color to apply to the background texture.</param>
        /// <param name="padding">Optional padding to apply between element borders and content.</param>
        /// <returns>New GUI layout with background object.</returns>
        public static GUILayoutWithBackground Create <T>(GUILayout layout, SpriteTexture background, Color backgroundColor,
                                                         RectOffset padding = new RectOffset()) where T : GUILayout, new()
        {
            GUIPanel   mainPanel  = layout.AddPanel();
            GUILayoutX mainLayout = mainPanel.AddLayoutX();

            GUILayout contentLayout;

            if (padding.top > 0 || padding.bottom > 0)
            {
                GUILayoutY paddingVertLayout = mainLayout.AddLayoutY();

                if (padding.top > 0)
                {
                    paddingVertLayout.AddSpace(padding.top);
                }

                if (padding.left > 0 || padding.right > 0)
                {
                    GUILayoutX paddingHorzLayout = paddingVertLayout.AddLayoutX();

                    if (padding.left > 0)
                    {
                        paddingHorzLayout.AddSpace(padding.left);
                    }

                    contentLayout = new T();
                    paddingHorzLayout.AddElement(contentLayout);

                    if (padding.right > 0)
                    {
                        paddingHorzLayout.AddSpace(padding.right);
                    }
                }
                else
                {
                    contentLayout = new T();
                    paddingVertLayout.AddElement(contentLayout);
                }

                if (padding.bottom > 0)
                {
                    paddingVertLayout.AddSpace(padding.bottom);
                }
            }
            else
            {
                if (padding.left > 0 || padding.right > 0)
                {
                    GUILayoutX paddingHorzLayout = mainLayout.AddLayoutX();

                    if (padding.left > 0)
                    {
                        paddingHorzLayout.AddSpace(padding.left);
                    }

                    contentLayout = new T();
                    paddingHorzLayout.AddElement(contentLayout);

                    if (padding.right > 0)
                    {
                        paddingHorzLayout.AddSpace(padding.right);
                    }
                }
                else
                {
                    contentLayout = new T();
                    mainLayout.AddElement(contentLayout);
                }
            }

            GUIPanel   bgPanel   = mainPanel.AddPanel(1);
            GUITexture bgTexture = new GUITexture(Builtin.WhiteTexture);

            bgTexture.SetTint(backgroundColor);
            bgPanel.AddElement(bgTexture);

            return(new GUILayoutWithBackground(mainPanel, contentLayout));
        }