Example #1
0
    void Start()
    {
        MenuSkin = Resources.Load("GUI/UI Skin") as GUISkin;

        Exit = false;
        Load = false;

        CamWidth = Camera.main.pixelWidth;

        GUIPanel.Pannels.Clear();

        MenuPanel = new GUIPanel();

        MenuPanel.Enabled = true;
        if (Logo == null)
            return;

        MenuPanel.Bounds = new Rect(0, 50, Logo.width, Logo.height * 2);
        MenuPanel.HAlignement = GUIPanel.Alignments.Center;
        MenuPanel.VAlignement = GUIPanel.Alignments.Absolute;

        MenuPanel.NewImage(GUIPanel.Alignments.Center, 0, GUIPanel.Alignments.Absolute, 0, Logo);

        MenuPanel.NewImageButton(GUIPanel.Alignments.Center, 0, GUIPanel.Alignments.Absolute, Logo.height, NewGameButton, NewGameClick);
        MenuPanel.NewImageButton(GUIPanel.Alignments.Center, 0, GUIPanel.Alignments.Absolute, Logo.height + NewGameButton.height, NewGamePlusButton, NewGame2Click);
        MenuPanel.NewImageButton(GUIPanel.Alignments.Center, 0, GUIPanel.Alignments.Absolute, Logo.height + 2 * NewGameButton.height, ControlsButton, ControlsClick);

        if (Application.platform != RuntimePlatform.OSXWebPlayer && Application.platform != RuntimePlatform.WindowsWebPlayer)
            MenuPanel.NewImageButton(GUIPanel.Alignments.Center, 0, GUIPanel.Alignments.Absolute, Logo.height + 3 * NewGameButton.height, ExitButton, ExitClick);

        MenuPanel.Skin = MenuSkin;

        ControlsPanel = new GUIPanel();
        ControlsPanel.Enabled = false;

        ControlsPanel.Bounds = new Rect(0, 50, ConrolsWindow.width, ConrolsWindow.height);
        ControlsPanel.Background = ConrolsWindow;
        ControlsPanel.HAlignement = GUIPanel.Alignments.Center;
        ControlsPanel.VAlignement = GUIPanel.Alignments.Absolute;
        ControlsPanel.Skin = MenuSkin;

        ControlsPanel.NewImageButton(GUIPanel.Alignments.Absolute, 12, GUIPanel.Alignments.Max, 6, BackButton, ControlBack);
    }
Example #2
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
                    ? EditorStyles.InspectorContentBgAlternate
                    : EditorStyles.InspectorContentBg;

                GUIToggle  foldout            = new GUIToggle(new LocEdString("Style"), EditorStyles.Foldout);
                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);

                    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;
            }
Example #3
0
        /// <summary>
        /// Refreshes the contents of the content area. Must be called at least once after construction.
        /// </summary>
        /// <param name="viewType">Determines how to display the resource tiles.</param>
        /// <param name="entriesToDisplay">Project library entries to display.</param>
        /// <param name="bounds">Bounds within which to lay out the content entries.</param>
        public void Refresh(ProjectViewType viewType, LibraryEntry[] entriesToDisplay, Rect2I bounds)
        {
            if (mainPanel != null)
            {
                mainPanel.Destroy();
            }

            entries.Clear();
            entryLookup.Clear();

            mainPanel = parent.Layout.AddPanel();

            GUIPanel contentPanel = mainPanel.AddPanel(1);

            overlay       = mainPanel.AddPanel(0);
            underlay      = mainPanel.AddPanel(2);
            deepUnderlay  = mainPanel.AddPanel(3);
            renameOverlay = mainPanel.AddPanel(-1);

            main = contentPanel.AddLayoutY();

            List <ResourceToDisplay> resourcesToDisplay = new List <ResourceToDisplay>();

            foreach (var entry in entriesToDisplay)
            {
                if (entry.Type == LibraryEntryType.Directory)
                {
                    resourcesToDisplay.Add(new ResourceToDisplay(entry.Path, LibraryGUIEntryType.Single));
                }
                else
                {
                    FileEntry      fileEntry = (FileEntry)entry;
                    ResourceMeta[] metas     = fileEntry.ResourceMetas;

                    if (metas.Length > 0)
                    {
                        if (metas.Length == 1)
                        {
                            resourcesToDisplay.Add(new ResourceToDisplay(entry.Path, LibraryGUIEntryType.Single));
                        }
                        else
                        {
                            resourcesToDisplay.Add(new ResourceToDisplay(entry.Path, LibraryGUIEntryType.MultiFirst));

                            for (int i = 1; i < metas.Length - 1; i++)
                            {
                                string path = Path.Combine(entry.Path, metas[i].SubresourceName);
                                resourcesToDisplay.Add(new ResourceToDisplay(path, LibraryGUIEntryType.MultiElement));
                            }

                            string lastPath = Path.Combine(entry.Path, metas[metas.Length - 1].SubresourceName);
                            resourcesToDisplay.Add(new ResourceToDisplay(lastPath, LibraryGUIEntryType.MultiLast));
                        }
                    }
                }
            }

            if (viewType == ProjectViewType.List16)
            {
                tileSize           = 16;
                gridLayout         = false;
                elementsPerRow     = 1;
                horzElementSpacing = 0;
                int elemWidth  = bounds.width;
                int elemHeight = tileSize;

                main.AddSpace(TOP_MARGIN);

                for (int i = 0; i < resourcesToDisplay.Count; i++)
                {
                    ResourceToDisplay entry = resourcesToDisplay[i];

                    LibraryGUIEntry guiEntry = new LibraryGUIEntry(this, main, entry.path, i, elemWidth, elemHeight,
                                                                   entry.type);
                    entries.Add(guiEntry);
                    entryLookup[guiEntry.path] = guiEntry;

                    if (i != resourcesToDisplay.Count - 1)
                    {
                        main.AddSpace(LIST_ENTRY_SPACING);
                    }
                }

                main.AddFlexibleSpace();
            }
            else
            {
                int elemWidth       = 0;
                int elemHeight      = 0;
                int vertElemSpacing = 0;

                switch (viewType)
                {
                case ProjectViewType.Grid64:
                    tileSize           = 64;
                    elemWidth          = tileSize;
                    elemHeight         = tileSize + 36;
                    horzElementSpacing = 10;
                    vertElemSpacing    = 12;
                    break;

                case ProjectViewType.Grid48:
                    tileSize           = 48;
                    elemWidth          = tileSize;
                    elemHeight         = tileSize + 36;
                    horzElementSpacing = 8;
                    vertElemSpacing    = 10;
                    break;

                case ProjectViewType.Grid32:
                    tileSize           = 32;
                    elemWidth          = tileSize + 16;
                    elemHeight         = tileSize + 48;
                    horzElementSpacing = 6;
                    vertElemSpacing    = 10;
                    break;
                }

                gridLayout = true;

                int availableWidth = bounds.width;

                elementsPerRow = MathEx.FloorToInt((availableWidth - horzElementSpacing) / (float)(elemWidth + horzElementSpacing));
                elementsPerRow = Math.Max(elementsPerRow, 1);

                int numRows      = MathEx.CeilToInt(resourcesToDisplay.Count / (float)elementsPerRow);
                int neededHeight = numRows * elemHeight + TOP_MARGIN;
                if (numRows > 0)
                {
                    neededHeight += (numRows - 1) * vertElemSpacing;
                }

                bool requiresScrollbar = neededHeight > bounds.height;
                if (requiresScrollbar)
                {
                    availableWidth -= parent.ScrollBarWidth;
                    elementsPerRow  = MathEx.FloorToInt((availableWidth - horzElementSpacing) / (float)(elemWidth + horzElementSpacing));
                    elementsPerRow  = Math.Max(elementsPerRow, 1);
                }

                int extraRowSpace = availableWidth - (elementsPerRow * (elemWidth + horzElementSpacing) + horzElementSpacing);

                main.AddSpace(TOP_MARGIN);
                GUILayoutX rowLayout = main.AddLayoutX();
                rowLayout.AddSpace(horzElementSpacing);

                int elemsInRow = 0;
                for (int i = 0; i < resourcesToDisplay.Count; i++)
                {
                    if (elemsInRow == elementsPerRow && elemsInRow > 0)
                    {
                        main.AddSpace(vertElemSpacing);
                        rowLayout.AddSpace(extraRowSpace);
                        rowLayout = main.AddLayoutX();
                        rowLayout.AddSpace(horzElementSpacing);

                        elemsInRow = 0;
                    }

                    ResourceToDisplay entry = resourcesToDisplay[i];

                    LibraryGUIEntry guiEntry = new LibraryGUIEntry(this, rowLayout, entry.path, i, elemWidth, elemHeight,
                                                                   entry.type);
                    entries.Add(guiEntry);
                    entryLookup[guiEntry.path] = guiEntry;

                    rowLayout.AddSpace(horzElementSpacing);

                    elemsInRow++;
                }

                int extraElements = elementsPerRow - elemsInRow;
                rowLayout.AddSpace((elemWidth + horzElementSpacing) * extraElements + extraRowSpace);

                main.AddFlexibleSpace();
            }

            for (int i = 0; i < entries.Count; i++)
            {
                LibraryGUIEntry guiEntry = entries[i];
                guiEntry.Initialize();
            }
        }
Example #4
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();
        }
        /// <summary>
        /// Creates GUI elements required for displaying <see cref="SceneObject"/> fields like name, prefab data and
        /// transform (position, rotation, scale). Assumes that necessary inspector scroll area layout has already been
        /// created.
        /// </summary>
        private void CreateSceneObjectFields()
        {
            GUIPanel sceneObjectPanel = inspectorLayout.AddPanel();

            sceneObjectPanel.SetHeight(GetTitleBounds().height);

            GUILayoutY sceneObjectLayout = sceneObjectPanel.AddLayoutY();

            sceneObjectLayout.SetPosition(PADDING, PADDING);

            GUIPanel sceneObjectBgPanel = sceneObjectPanel.AddPanel(1);

            GUILayoutX nameLayout = sceneObjectLayout.AddLayoutX();

            soActiveToggle            = new GUIToggle("");
            soActiveToggle.OnToggled += OnSceneObjectActiveStateToggled;
            GUILabel nameLbl = new GUILabel(new LocEdString("Name"), GUIOption.FixedWidth(50));

            soNameInput              = new GUITextBox(false, GUIOption.FlexibleWidth(180));
            soNameInput.Text         = activeSO.Name;
            soNameInput.OnChanged   += OnSceneObjectRename;
            soNameInput.OnConfirmed += () =>
            {
                OnModifyConfirm();
                StartUndo("name");
            };
            soNameInput.OnFocusGained += () => StartUndo("name");
            soNameInput.OnFocusLost   += OnModifyConfirm;

            nameLayout.AddElement(soActiveToggle);
            nameLayout.AddSpace(3);
            nameLayout.AddElement(nameLbl);
            nameLayout.AddElement(soNameInput);
            nameLayout.AddFlexibleSpace();

            GUILayoutX mobilityLayout = sceneObjectLayout.AddLayoutX();
            GUILabel   mobilityLbl    = new GUILabel(new LocEdString("Mobility"), GUIOption.FixedWidth(50));

            soMobility       = new GUIEnumField(typeof(ObjectMobility), "", 0, GUIOption.FixedWidth(85));
            soMobility.Value = (ulong)activeSO.Mobility;
            soMobility.OnSelectionChanged += value => activeSO.Mobility = (ObjectMobility)value;
            mobilityLayout.AddElement(mobilityLbl);
            mobilityLayout.AddElement(soMobility);

            soPrefabLayout = sceneObjectLayout.AddLayoutX();

            soPos = new GUIVector3Field(new LocEdString("Position"), 50);
            sceneObjectLayout.AddElement(soPos);

            soPos.OnComponentChanged += OnPositionChanged;
            soPos.OnConfirm          += x =>
            {
                OnModifyConfirm();
                StartUndo("position." + x.ToString());
            };
            soPos.OnComponentFocusChanged += (focus, comp) =>
            {
                if (focus)
                {
                    StartUndo("position." + comp.ToString());
                }
                else
                {
                    OnModifyConfirm();
                }
            };

            soRot = new GUIVector3Field(new LocEdString("Rotation"), 50);
            sceneObjectLayout.AddElement(soRot);

            soRot.OnComponentChanged += OnRotationChanged;
            soRot.OnConfirm          += x =>
            {
                OnModifyConfirm();
                StartUndo("rotation." + x.ToString());
            };
            soRot.OnComponentFocusChanged += (focus, comp) =>
            {
                if (focus)
                {
                    StartUndo("rotation." + comp.ToString());
                }
                else
                {
                    OnModifyConfirm();
                }
            };

            soScale = new GUIVector3Field(new LocEdString("Scale"), 50);
            sceneObjectLayout.AddElement(soScale);

            soScale.OnComponentChanged += OnScaleChanged;
            soScale.OnConfirm          += x =>
            {
                OnModifyConfirm();
                StartUndo("scale." + x.ToString());
            };
            soScale.OnComponentFocusChanged += (focus, comp) =>
            {
                if (focus)
                {
                    StartUndo("scale." + comp.ToString());
                }
                else
                {
                    OnModifyConfirm();
                }
            };

            sceneObjectLayout.AddFlexibleSpace();

            GUITexture titleBg = new GUITexture(null, EditorStylesInternal.InspectorTitleBg);

            sceneObjectBgPanel.AddElement(titleBg);
        }
        /// <summary>
        /// Sets a resource whose GUI is to be displayed in the inspector. Clears any previous contents of the window.
        /// </summary>
        /// <param name="resourcePath">Resource path relative to the project of the resource to inspect.</param>
        private void SetObjectToInspect(string resourcePath)
        {
            activeResourcePath = resourcePath;
            if (!ProjectLibrary.Exists(resourcePath))
            {
                return;
            }

            ResourceMeta meta = ProjectLibrary.GetMeta(resourcePath);

            if (meta == null)
            {
                return;
            }

            Type resourceType = meta.Type;

            currentType = InspectorType.Resource;

            inspectorScrollArea = new GUIScrollArea(ScrollBarType.ShowIfDoesntFit, ScrollBarType.NeverShow);
            GUI.AddElement(inspectorScrollArea);
            inspectorLayout = inspectorScrollArea.Layout;

            GUIPanel titlePanel = inspectorLayout.AddPanel();

            titlePanel.SetHeight(RESOURCE_TITLE_HEIGHT);

            GUILayoutY titleLayout = titlePanel.AddLayoutY();

            titleLayout.SetPosition(PADDING, PADDING);

            string name = Path.GetFileNameWithoutExtension(resourcePath);
            string type = resourceType.Name;

            LocString title      = new LocEdString(name + " (" + type + ")");
            GUILabel  titleLabel = new GUILabel(title);

            titleLayout.AddFlexibleSpace();
            GUILayoutX titleLabelLayout = titleLayout.AddLayoutX();

            titleLabelLayout.AddElement(titleLabel);
            titleLayout.AddFlexibleSpace();

            GUIPanel titleBgPanel = titlePanel.AddPanel(1);

            GUITexture titleBg = new GUITexture(null, EditorStylesInternal.InspectorTitleBg);

            titleBgPanel.AddElement(titleBg);

            inspectorLayout.AddSpace(COMPONENT_SPACING);

            inspectorResource           = new InspectorResource();
            inspectorResource.mainPanel = inspectorLayout.AddPanel();
            inspectorLayout.AddFlexibleSpace();
            inspectorResource.previewPanel = inspectorLayout.AddPanel();

            var persistentProperties = persistentData.GetProperties(meta.UUID.ToString());

            inspectorResource.inspector = InspectorUtility.GetInspector(resourceType);
            inspectorResource.inspector.Initialize(inspectorResource.mainPanel, inspectorResource.previewPanel,
                                                   activeResourcePath, persistentProperties);
        }
Example #7
0
        private void OnInitialize()
        {
            mainLayout = GUI.AddLayoutY();

            GUIContent viewIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.View),
                                                 new LocEdString("View"));
            GUIContent moveIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.Move),
                                                 new LocEdString("Move"));
            GUIContent rotateIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.Rotate),
                                                   new LocEdString("Rotate"));
            GUIContent scaleIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.Scale),
                                                  new LocEdString("Scale"));

            GUIContent localIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.Local),
                                                  new LocEdString("Local"));
            GUIContent worldIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.World),
                                                  new LocEdString("World"));

            GUIContent pivotIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.Pivot),
                                                  new LocEdString("Pivot"));
            GUIContent centerIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.Center),
                                                   new LocEdString("Center"));

            GUIContent moveSnapIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.MoveSnap),
                                                     new LocEdString("Move snap"));
            GUIContent rotateSnapIcon = new GUIContent(EditorBuiltin.GetSceneWindowIcon(SceneWindowIcon.RotateSnap),
                                                       new LocEdString("Rotate snap"));

            GUIToggleGroup handlesTG = new GUIToggleGroup();

            viewButton   = new GUIToggle(viewIcon, handlesTG, EditorStyles.Button, GUIOption.FlexibleWidth(35));
            moveButton   = new GUIToggle(moveIcon, handlesTG, EditorStyles.Button, GUIOption.FlexibleWidth(35));
            rotateButton = new GUIToggle(rotateIcon, handlesTG, EditorStyles.Button, GUIOption.FlexibleWidth(35));
            scaleButton  = new GUIToggle(scaleIcon, handlesTG, EditorStyles.Button, GUIOption.FlexibleWidth(35));

            GUIToggleGroup coordModeTG = new GUIToggleGroup();

            localCoordButton = new GUIToggle(localIcon, coordModeTG, EditorStyles.Button, GUIOption.FlexibleWidth(75));
            worldCoordButton = new GUIToggle(worldIcon, coordModeTG, EditorStyles.Button, GUIOption.FlexibleWidth(75));

            GUIToggleGroup pivotModeTG = new GUIToggleGroup();

            pivotButton  = new GUIToggle(pivotIcon, pivotModeTG, EditorStyles.Button, GUIOption.FlexibleWidth(35));
            centerButton = new GUIToggle(centerIcon, pivotModeTG, EditorStyles.Button, GUIOption.FlexibleWidth(35));

            moveSnapButton = new GUIToggle(moveSnapIcon, EditorStyles.Button, GUIOption.FlexibleWidth(35));
            moveSnapInput  = new GUIFloatField("", GUIOption.FlexibleWidth(35));

            rotateSnapButton = new GUIToggle(rotateSnapIcon, EditorStyles.Button, GUIOption.FlexibleWidth(35));
            rotateSnapInput  = new GUIFloatField("", GUIOption.FlexibleWidth(35));

            viewButton.OnClick   += () => OnSceneToolButtonClicked(SceneViewTool.View);
            moveButton.OnClick   += () => OnSceneToolButtonClicked(SceneViewTool.Move);
            rotateButton.OnClick += () => OnSceneToolButtonClicked(SceneViewTool.Rotate);
            scaleButton.OnClick  += () => OnSceneToolButtonClicked(SceneViewTool.Scale);

            localCoordButton.OnClick += () => OnCoordinateModeButtonClicked(HandleCoordinateMode.Local);
            worldCoordButton.OnClick += () => OnCoordinateModeButtonClicked(HandleCoordinateMode.World);

            pivotButton.OnClick  += () => OnPivotModeButtonClicked(HandlePivotMode.Pivot);
            centerButton.OnClick += () => OnPivotModeButtonClicked(HandlePivotMode.Center);

            moveSnapButton.OnToggled += (bool active) => OnMoveSnapToggled(active);
            moveSnapInput.OnChanged  += (float value) => OnMoveSnapValueChanged(value);

            rotateSnapButton.OnToggled += (bool active) => OnRotateSnapToggled(active);
            rotateSnapInput.OnChanged  += (float value) => OnRotateSnapValueChanged(value);

            GUILayout handlesLayout = mainLayout.AddLayoutX();

            handlesLayout.AddElement(viewButton);
            handlesLayout.AddElement(moveButton);
            handlesLayout.AddElement(rotateButton);
            handlesLayout.AddElement(scaleButton);
            handlesLayout.AddSpace(10);
            handlesLayout.AddElement(localCoordButton);
            handlesLayout.AddElement(worldCoordButton);
            handlesLayout.AddSpace(10);
            handlesLayout.AddElement(pivotButton);
            handlesLayout.AddElement(centerButton);
            handlesLayout.AddFlexibleSpace();
            handlesLayout.AddElement(moveSnapButton);
            handlesLayout.AddElement(moveSnapInput);
            handlesLayout.AddSpace(10);
            handlesLayout.AddElement(rotateSnapButton);
            handlesLayout.AddElement(rotateSnapInput);

            GUIPanel mainPanel = mainLayout.AddPanel();

            rtPanel = mainPanel.AddPanel();

            selectionPanel = mainPanel.AddPanel(-1);

            GUIPanel sceneAxesPanel = mainPanel.AddPanel(-1);

            sceneAxesGUI = new SceneAxesGUI(this, sceneAxesPanel, HandleAxesGUISize, HandleAxesGUISize, ProjectionType.Perspective);

            focusCatcher = new GUIButton("", EditorStyles.Blank);
            focusCatcher.OnFocusGained += () => hasContentFocus = true;
            focusCatcher.OnFocusLost   += () => hasContentFocus = false;

            GUIPanel focusPanel = GUI.AddPanel(-2);

            focusPanel.AddElement(focusCatcher);

            toggleProfilerOverlayKey = new VirtualButton(ToggleProfilerOverlayBinding);
            viewToolKey   = new VirtualButton(ViewToolBinding);
            moveToolKey   = new VirtualButton(MoveToolBinding);
            rotateToolKey = new VirtualButton(RotateToolBinding);
            scaleToolKey  = new VirtualButton(ScaleToolBinding);
            frameKey      = new VirtualButton(FrameBinding);

            UpdateRenderTexture(Width, Height - HeaderHeight);
            UpdateProfilerOverlay();
        }
Example #8
0
    public void OnGUI()
    {
        if (globalGUISkin == null)
        {
            globalGUISkin = guiSkin;
        }
        GUI.skin = globalGUISkin;

        if (Input.touchCount == 1)
        {
            Touch touch = Input.GetTouch(0);
            if (touch.phase == TouchPhase.Began)
            {
                touchStartPos = touch.position;
                if (PanelContainsPoint(touch.position))
                {
                    scrollVelocity = Vector2.zero;
                    panelSlide     = true;
                }
                else if (!holdOpen)
                {
                    GUIPanel touchedPanel = PanelContainingPoint(touch.position);
                    // if the panel is behind this one
                    if (openPanels.IndexOf(touchedPanel) < openPanels.IndexOf(this))
                    {
                        Destroy(this);
                    }
                }
            }
            if (panelSlide && !verticalSlide && Mathf.Abs((touch.position - touchStartPos).x) > Screen.height * .06)
            {
                horizontalSlide = true;
            }
            if (panelSlide && !horizontalSlide && Mathf.Abs((touch.position - touchStartPos).y) > Screen.height * .06)
            {
                verticalSlide = true;
            }
        }
        else
        {
            panelSlide      = false;
            horizontalSlide = false;
            verticalSlide   = false;
        }

        if (Input.GetButtonDown("Cancel") && !holdOpen)
        {
            if (IsFocused())
            {
                Destroy(this);
            }
        }

        scaleFactor = Screen.height / targetHeight;
        GUI.matrix  = Matrix4x4.Scale(new Vector3(scaleFactor, scaleFactor, 1));
        float scaledScreenWidth = Screen.width / scaleFactor;

        Rect newPanelRect = GetRect(scaledScreenWidth, targetHeight);

        if (newPanelRect.width == 0)
        {
            newPanelRect.width = panelRect.width;
        }
        if (newPanelRect.height == 0)
        {
            newPanelRect.height = panelRect.height;
        }
        panelRect = newPanelRect;
        panelRect = GUILayout.Window(GetHashCode(), panelRect, _WindowGUI, "", GetStyle(), GUILayout.ExpandHeight(true));
    }
        /// <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));
        }
 /// <summary>
 /// Constructs a new object.
 /// </summary>
 /// <param name="mainPanel">Root panel in which all the child GUI elements of this object belong to.</param>
 /// <param name="layout">Content layout that's to be provided to the user.</param>
 private GUILayoutWithBackground(GUIPanel mainPanel, GUILayout layout)
 {
     MainPanel = mainPanel;
     Layout    = layout;
 }
        private void OnInitialize()
        {
            guiOK     = new GUIButton(new LocEdString("OK"));
            guiCancel = new GUIButton(new LocEdString("Cancel"));

            guiOK.OnClick     += OnOK;
            guiCancel.OnClick += OnCancel;

            GUILayout mainVertLayout = GUI.AddLayoutY();

            mainVertLayout.AddSpace(10);

            GUILayout editorHorzLayout = mainVertLayout.AddLayoutX();

            editorHorzLayout.AddSpace(EDITOR_HORZ_PADDING);
            GUIPanel gradientEditorPanel = editorHorzLayout.AddPanel();

            editorHorzLayout.AddSpace(EDITOR_HORZ_PADDING);

            mainVertLayout.AddSpace(15);

            GUILayout buttonHorzLayout = mainVertLayout.AddLayoutX();

            buttonHorzLayout.AddFlexibleSpace();
            buttonHorzLayout.AddElement(guiOK);
            buttonHorzLayout.AddSpace(10);
            buttonHorzLayout.AddElement(guiCancel);
            buttonHorzLayout.AddFlexibleSpace();

            mainVertLayout.AddFlexibleSpace();

            editorPanel = gradientEditorPanel.AddPanel(0);
            GUIPanel editorOverlay = gradientEditorPanel.AddPanel(-1);

            overlayCanvas = new GUICanvas();
            editorOverlay.AddElement(overlayCanvas);

            GUILayout editorVertLayout = editorPanel.AddLayoutY();

            GUILayout guiGradientLayout = editorVertLayout.AddLayoutX();

            guiGradientLayout.AddSpace(GradientKeyEditor.RECT_WIDTH / 2);

            texture       = Texture.Create2D(TEX_WIDTH, TEX_HEIGHT);
            spriteTexture = new SpriteTexture(texture);

            guiGradientTexture = new GUITexture(spriteTexture, GUITextureScaleMode.StretchToFit);
            guiGradientTexture.SetHeight(30);

            UpdateTexture();

            guiGradientLayout.AddElement(guiGradientTexture);
            guiGradientLayout.AddSpace(GradientKeyEditor.RECT_WIDTH / 2);

            editorVertLayout.AddSpace(10);

            editor = new GradientKeyEditor(editorVertLayout, gradient.GetKeys(), Width - EDITOR_HORZ_PADDING * 2, 20);
            editor.OnGradientModified += colorGradient =>
            {
                gradient = colorGradient;

                UpdateTexture();
                UpdateKeyLines();
            };

            editorVertLayout.AddFlexibleSpace();

            GUITexture containerBg     = new GUITexture(null, EditorStylesInternal.ContainerBg);
            Rect2I     containerBounds = editor.GetBounds(GUI);

            containerBounds.x      -= 2;
            containerBounds.y      -= 2;
            containerBounds.width  += 4;
            containerBounds.height += 6;
            containerBg.Bounds      = containerBounds;

            GUIPanel editorUnderlay = GUI.AddPanel(1);

            editorUnderlay.AddElement(containerBg);

            UpdateKeyLines();

            EditorInput.OnPointerPressed     += OnPointerPressed;
            EditorInput.OnPointerDoubleClick += OnPointerDoubleClicked;
            EditorInput.OnPointerMoved       += OnPointerMoved;
            EditorInput.OnPointerReleased    += OnPointerReleased;
            EditorInput.OnButtonUp           += OnButtonUp;
        }
        /// <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"));
                    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 += OnFoldoutToggled;
                guiInternalTitleLayout.AddElement(guiFoldout);

                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
                           ? EditorStyles.InspectorContentBgAlternate
                           : EditorStyles.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.Inspectable)
                            {
                                continue;
                            }

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

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

                            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();
                    BuildFilledGUI();
                    state = State.Filled;
                }
            }
            else if (state == State.Filled)
            {
                foreach (var child in children)
                {
                    child.Destroy();
                }

                children.Clear();
                guiInternalTitleLayout.Destroy();

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

                if (propertyValue == null)
                {
                    BuildEmptyGUI();
                    state = State.Empty;
                }
                else
                {
                    BuildFilledGUI();
                }
            }
        }
        /// <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 (!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;
                        }

                        children = CreateFields(serializableObject, parent, path, depth + 1, guiContentLayout);
                    }
                }
                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)
            {
                foreach (var child in children)
                {
                    child.Destroy();
                }

                children.Clear();

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

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

                if (propertyValue == null)
                {
                    BuildEmptyGUI();
                    state = State.Empty;
                }
                else
                {
                    BuildFilledGUI();
                }
            }
        }
Example #14
0
        public override void Init()
        {
            // GUIHandler
            _guiHandler = new GUIHandler();
            _guiHandler.AttachToContext(RC);

            // font + text
            _guiFontCabin18 = RC.LoadFont("Assets/Cabin.ttf", 18);
            _guiFontCabin24 = RC.LoadFont("Assets/Cabin.ttf", 24);

            _guiText = new GUIText("Spot all seven differences!", _guiFontCabin24, 310, 35);
            _guiText.TextColor = new float4(1, 1, 1, 1);

            _guiHandler.Add(_guiText);

            // image
            _guiImage = new GUIImage("Assets/spot_the_diff.png", 0, 0, -5, 600, 650);
            _guiHandler.Add(_guiImage);

            // buttons / rectangles
            _guiUDiffs = new GUIButton[7];
            _guiBDiffs = new GUIButton[7];

            _guiUDiffs[0] = new GUIButton(240, 3, 40, 40);
            _guiBDiffs[0] = new GUIButton(240, 328, 40, 40);

            _guiUDiffs[1] = new GUIButton(3, 270, 40, 40);
            _guiBDiffs[1] = new GUIButton(3, 595, 40, 40);

            _guiUDiffs[2] = new GUIButton(220, 255, 40, 40);
            _guiBDiffs[2] = new GUIButton(220, 580, 40, 40);

            _guiUDiffs[3] = new GUIButton(325, 170, 40, 40);
            _guiBDiffs[3] = new GUIButton(325, 495, 40, 40);

            _guiUDiffs[4] = new GUIButton(265, 110, 40, 40);
            _guiBDiffs[4] = new GUIButton(265, 435, 40, 40);

            _guiUDiffs[5] = new GUIButton(490, 215, 40, 40);
            _guiBDiffs[5] = new GUIButton(490, 540, 40, 40);

            _guiUDiffs[6] = new GUIButton(495, 280, 40, 40);
            _guiBDiffs[6] = new GUIButton(495, 605, 40, 40);

            for (int i = 0; i < 7; i++)
            {
                _guiUDiffs[i].ButtonColor = new float4(0, 0, 0, 0);
                _guiBDiffs[i].ButtonColor = new float4(0, 0, 0, 0);

                _guiUDiffs[i].BorderColor = new float4(0, 0, 0, 1);
                _guiBDiffs[i].BorderColor = new float4(0, 0, 0, 1);

                _guiUDiffs[i].BorderWidth = 0;
                _guiBDiffs[i].BorderWidth = 0;

                _guiUDiffs[i].Tag = _guiBDiffs[i];
                _guiBDiffs[i].Tag = _guiUDiffs[i];

                _guiBDiffs[i].OnGUIButtonDown += OnDiffButtonDown;
                _guiUDiffs[i].OnGUIButtonDown += OnDiffButtonDown;

                _guiHandler.Add(_guiUDiffs[i]);
                _guiHandler.Add(_guiBDiffs[i]);
            }

            // panel
            _guiPanel = new GUIPanel("Menu", _guiFontCabin18, 10, 10, 150, 110);
            _guiHandler.Add(_guiPanel);

            // reset button
            _guiResetButton = new GUIButton("Reset", _guiFontCabin18, 25, 40, 100, 25);

            _guiResetButton.OnGUIButtonDown += OnMenuButtonDown;
            _guiResetButton.OnGUIButtonUp += OnMenuButtonUp;
            _guiResetButton.OnGUIButtonEnter += OnMenuButtonEnter;
            _guiResetButton.OnGUIButtonLeave += OnMenuButtonLeave;

            _guiPanel.ChildElements.Add(_guiResetButton);

            // solve button
            _guiSolveButton = new GUIButton("Solve", _guiFontCabin18, 25, 70, 100, 25);

            _guiSolveButton.OnGUIButtonDown += OnMenuButtonDown;
            _guiSolveButton.OnGUIButtonUp += OnMenuButtonUp;
            _guiSolveButton.OnGUIButtonEnter += OnMenuButtonEnter;
            _guiSolveButton.OnGUIButtonLeave += OnMenuButtonLeave;

            _guiPanel.ChildElements.Add(_guiSolveButton);
        }
Example #15
0
        /// <summary>
        /// Creates a new curve editor GUI elements.
        /// </summary>
        /// <param name="window">Parent window of the GUI element.</param>
        /// <param name="gui">GUI layout into which to place the GUI element.</param>
        /// <param name="width">Width in pixels.</param>
        /// <param name="height">Height in pixels.</param>
        public GUICurveEditor(AnimationWindow window, GUILayout gui, int width, int height)
        {
            this.window = window;
            this.gui    = gui;

            this.width  = width;
            this.height = height;

            blankContextMenu = new ContextMenu();
            blankContextMenu.AddItem("Add keyframe", AddKeyframeAtPosition);

            blankEventContextMenu = new ContextMenu();
            blankEventContextMenu.AddItem("Add event", AddEventAtPosition);

            keyframeContextMenu = new ContextMenu();
            keyframeContextMenu.AddItem("Delete", DeleteSelectedKeyframes);
            keyframeContextMenu.AddItem("Edit", EditSelectedKeyframe);
            keyframeContextMenu.AddItem("Tangents/Auto", () => { ChangeSelectionTangentMode(TangentMode.Auto); });
            keyframeContextMenu.AddItem("Tangents/Free", () => { ChangeSelectionTangentMode(TangentMode.Free); });
            keyframeContextMenu.AddItem("Tangents/In/Auto", () => { ChangeSelectionTangentMode(TangentMode.InAuto); });
            keyframeContextMenu.AddItem("Tangents/In/Free", () => { ChangeSelectionTangentMode(TangentMode.InFree); });
            keyframeContextMenu.AddItem("Tangents/In/Linear", () => { ChangeSelectionTangentMode(TangentMode.InLinear); });
            keyframeContextMenu.AddItem("Tangents/In/Step", () => { ChangeSelectionTangentMode(TangentMode.InStep); });
            keyframeContextMenu.AddItem("Tangents/Out/Auto", () => { ChangeSelectionTangentMode(TangentMode.OutAuto); });
            keyframeContextMenu.AddItem("Tangents/Out/Free", () => { ChangeSelectionTangentMode(TangentMode.OutFree); });
            keyframeContextMenu.AddItem("Tangents/Out/Linear", () => { ChangeSelectionTangentMode(TangentMode.OutLinear); });
            keyframeContextMenu.AddItem("Tangents/Out/Step", () => { ChangeSelectionTangentMode(TangentMode.OutStep); });

            eventContextMenu = new ContextMenu();
            eventContextMenu.AddItem("Delete", DeleteSelectedEvents);
            eventContextMenu.AddItem("Edit", EditSelectedEvent);

            GUIPanel timelinePanel = gui.AddPanel();

            guiTimeline = new GUIGraphTime(timelinePanel, width, TIMELINE_HEIGHT);

            GUIPanel timelineBgPanel = gui.AddPanel(1);

            GUITexture timelineBackground = new GUITexture(null, EditorStyles.Header);

            timelineBackground.Bounds = new Rect2I(0, 0, width, TIMELINE_HEIGHT + VERT_PADDING);
            timelineBgPanel.AddElement(timelineBackground);

            eventsPanel = gui.AddPanel();
            eventsPanel.SetPosition(0, TIMELINE_HEIGHT + VERT_PADDING);
            guiEvents = new GUIAnimEvents(eventsPanel, width, EVENTS_HEIGHT);

            GUIPanel eventsBgPanel = eventsPanel.AddPanel(1);

            GUITexture eventsBackground = new GUITexture(null, EditorStyles.Header);

            eventsBackground.Bounds = new Rect2I(0, 0, width, EVENTS_HEIGHT + VERT_PADDING);
            eventsBgPanel.AddElement(eventsBackground);

            drawingPanel = gui.AddPanel();
            drawingPanel.SetPosition(0, TIMELINE_HEIGHT + EVENTS_HEIGHT + VERT_PADDING);

            guiCurveDrawing = new GUICurveDrawing(drawingPanel, width, height - TIMELINE_HEIGHT - EVENTS_HEIGHT - VERT_PADDING * 2, curveInfos);
            guiCurveDrawing.SetRange(60.0f, 20.0f);

            GUIPanel sidebarPanel = gui.AddPanel(-10);

            sidebarPanel.SetPosition(0, TIMELINE_HEIGHT + EVENTS_HEIGHT + VERT_PADDING);

            guiSidebar = new GUIGraphValues(sidebarPanel, SIDEBAR_WIDTH, height - TIMELINE_HEIGHT - EVENTS_HEIGHT - VERT_PADDING * 2);
            guiSidebar.SetRange(-10.0f, 10.0f);
        }
Example #16
0
 /// <summary>
 /// Returns the bounds of the GUI element relative to the provided panel.
 /// </summary>
 public Rect2I GetBounds(GUIPanel relativeTo)
 {
     return(GUIUtility.CalculateBounds(canvas, relativeTo));
 }
Example #17
0
        public override void Init()
        {
            // Set ToonShaderEffect
            _shaderEffect.AttachToContext(RC);

            // Setup GUI

            // GUIHandler
            _guiHandler = new GUIHandler();
            _guiHandler.AttachToContext(RC);

            // font + text
            _guiFontCabin18 = RC.LoadFont("Assets/Cabin.ttf", 18);
            _guiFontCabin24 = RC.LoadFont("Assets/Cabin.ttf", 24);

            _guiText = new GUIText("FUSEE Shader Demo", _guiFontCabin24, 30, Height - 30)
            {
                TextColor = new float4(1, 1, 1, 1)
            };

            _guiHandler.Add(_guiText);

            // image
            _guiImage = new GUIImage("Assets/repbg.jpg", 0, 0, -5, Width, Height);
            _guiHandler.Add(_guiImage);
            _borderImage = new GUIImage("Assets/redbg.png", 0, 0, -4, 230, 32);
            //_guiHandler.Add(_borderImage);

            //* Menu1: Select Shader
            _panelSelectShader = new GUIPanel("Select Shader", _guiFontCabin24, 10, 10, 230, 230);
            _panelSelectShader.ChildElements.Add(_borderImage);
            _guiHandler.Add(_panelSelectShader);

            //** Possible Shader Buttons
            _btnDiffuseColorShader       = new GUIButton("Diffuse Color", _guiFontCabin18, 25, 40, 180, 25);
            _btnTextureShader            = new GUIButton("Texture Only", _guiFontCabin18, 25, 70, 180, 25);
            _btnDiffuseTextureShader     = new GUIButton("Diffuse Texture", _guiFontCabin18, 25, 100, 180, 25);
            _btnDiffuseBumpTextureShader = new GUIButton("Diffuse Bump Texture", _guiFontCabin18, 25, 130, 180, 25);
            _btnSpecularTexture          = new GUIButton("Specular Texture", _guiFontCabin18, 25, 160, 180, 25);
            _btnToon = new GUIButton("Toon", _guiFontCabin18, 25, 190, 180, 25);

            //*** Add Handlers
            _btnDiffuseColorShader.OnGUIButtonDown  += OnMenuButtonDown;
            _btnDiffuseColorShader.OnGUIButtonUp    += OnMenuButtonUp;
            _btnDiffuseColorShader.OnGUIButtonEnter += OnMenuButtonEnter;
            _btnDiffuseColorShader.OnGUIButtonLeave += OnMenuButtonLeave;

            _btnTextureShader.OnGUIButtonDown  += OnMenuButtonDown;
            _btnTextureShader.OnGUIButtonUp    += OnMenuButtonUp;
            _btnTextureShader.OnGUIButtonEnter += OnMenuButtonEnter;
            _btnTextureShader.OnGUIButtonLeave += OnMenuButtonLeave;

            _btnDiffuseTextureShader.OnGUIButtonDown  += OnMenuButtonDown;
            _btnDiffuseTextureShader.OnGUIButtonUp    += OnMenuButtonUp;
            _btnDiffuseTextureShader.OnGUIButtonEnter += OnMenuButtonEnter;
            _btnDiffuseTextureShader.OnGUIButtonLeave += OnMenuButtonLeave;

            _btnDiffuseBumpTextureShader.OnGUIButtonDown  += OnMenuButtonDown;
            _btnDiffuseBumpTextureShader.OnGUIButtonUp    += OnMenuButtonUp;
            _btnDiffuseBumpTextureShader.OnGUIButtonEnter += OnMenuButtonEnter;
            _btnDiffuseBumpTextureShader.OnGUIButtonLeave += OnMenuButtonLeave;

            _btnSpecularTexture.OnGUIButtonDown  += OnMenuButtonDown;
            _btnSpecularTexture.OnGUIButtonUp    += OnMenuButtonUp;
            _btnSpecularTexture.OnGUIButtonEnter += OnMenuButtonEnter;
            _btnSpecularTexture.OnGUIButtonLeave += OnMenuButtonLeave;

            _btnToon.OnGUIButtonDown  += OnMenuButtonDown;
            _btnToon.OnGUIButtonUp    += OnMenuButtonUp;
            _btnToon.OnGUIButtonEnter += OnMenuButtonEnter;
            _btnToon.OnGUIButtonLeave += OnMenuButtonLeave;

            //**** Add Buttons to Panel
            _panelSelectShader.ChildElements.Add(_btnDiffuseColorShader);
            _panelSelectShader.ChildElements.Add(_btnTextureShader);
            _panelSelectShader.ChildElements.Add(_btnDiffuseTextureShader);
            _panelSelectShader.ChildElements.Add(_btnDiffuseBumpTextureShader);
            _panelSelectShader.ChildElements.Add(_btnSpecularTexture);
            _panelSelectShader.ChildElements.Add(_btnToon);

            //* Menu3: Select Mesh
            _panelSelectMesh = new GUIPanel("Select Mesh", _guiFontCabin24, 270, 10, 230, 130);
            _panelSelectMesh.ChildElements.Add(_borderImage);
            _guiHandler.Add(_panelSelectMesh);

            //** Possible Meshes
            _btnCube   = new GUIButton("Cube", _guiFontCabin18, 25, 40, 180, 25);
            _btnSphere = new GUIButton("Sphere", _guiFontCabin18, 25, 70, 180, 25);
            _btnTeapot = new GUIButton("Teapot", _guiFontCabin18, 25, 100, 180, 25);
            _panelSelectMesh.ChildElements.Add(_btnCube);
            _panelSelectMesh.ChildElements.Add(_btnSphere);
            _panelSelectMesh.ChildElements.Add(_btnTeapot);

            //** Add handlers
            _btnCube.OnGUIButtonDown  += OnMenuButtonDown;
            _btnCube.OnGUIButtonUp    += OnMenuButtonUp;
            _btnCube.OnGUIButtonEnter += OnMenuButtonEnter;
            _btnCube.OnGUIButtonLeave += OnMenuButtonLeave;

            _btnSphere.OnGUIButtonDown  += OnMenuButtonDown;
            _btnSphere.OnGUIButtonUp    += OnMenuButtonUp;
            _btnSphere.OnGUIButtonEnter += OnMenuButtonEnter;
            _btnSphere.OnGUIButtonLeave += OnMenuButtonLeave;

            _btnTeapot.OnGUIButtonDown  += OnMenuButtonDown;
            _btnTeapot.OnGUIButtonUp    += OnMenuButtonUp;
            _btnTeapot.OnGUIButtonEnter += OnMenuButtonEnter;
            _btnTeapot.OnGUIButtonLeave += OnMenuButtonLeave;

            //* Menu2: Light Settings
            _panelLightSettings = new GUIPanel("Light Settings", _guiFontCabin24, 530, 10, 230, 130);
            _panelLightSettings.ChildElements.Add(_borderImage);
            _guiHandler.Add(_panelLightSettings);

            //** Possible Light Settings
            _btnDirectionalLight = new GUIButton("Directional Light", _guiFontCabin18, 25, 40, 180, 25);
            _btnPointLight       = new GUIButton("Point Light", _guiFontCabin18, 25, 70, 180, 25);
            _btnSpotLight        = new GUIButton("Spot Light", _guiFontCabin18, 25, 100, 180, 25);
            _panelLightSettings.ChildElements.Add(_btnDirectionalLight);
            _panelLightSettings.ChildElements.Add(_btnPointLight);
            _panelLightSettings.ChildElements.Add(_btnSpotLight);

            //*** Add Handlers
            _btnDirectionalLight.OnGUIButtonDown  += OnMenuButtonDown;
            _btnDirectionalLight.OnGUIButtonUp    += OnMenuButtonUp;
            _btnDirectionalLight.OnGUIButtonEnter += OnMenuButtonEnter;
            _btnDirectionalLight.OnGUIButtonLeave += OnMenuButtonLeave;

            _btnPointLight.OnGUIButtonDown  += OnMenuButtonDown;
            _btnPointLight.OnGUIButtonUp    += OnMenuButtonUp;
            _btnPointLight.OnGUIButtonEnter += OnMenuButtonEnter;
            _btnPointLight.OnGUIButtonLeave += OnMenuButtonLeave;

            _btnSpotLight.OnGUIButtonDown  += OnMenuButtonDown;
            _btnSpotLight.OnGUIButtonUp    += OnMenuButtonUp;
            _btnSpotLight.OnGUIButtonEnter += OnMenuButtonEnter;
            _btnSpotLight.OnGUIButtonLeave += OnMenuButtonLeave;

            // Setup 3D Scene
            // Load Images and Assign iTextures
            var imgTexture     = RC.LoadImage("Assets/crateTexture.jpg");
            var imgBumpTexture = RC.LoadImage("Assets/crateNormal.jpg");

            _texCube     = RC.CreateTexture(imgTexture);
            _texBumpCube = RC.CreateTexture(imgBumpTexture);

            imgTexture     = RC.LoadImage("Assets/earthTexture.jpg");
            imgBumpTexture = RC.LoadImage("Assets/earthNormal.jpg");
            _texSphere     = RC.CreateTexture(imgTexture);
            _texBumpSphere = RC.CreateTexture(imgBumpTexture);

            imgTexture     = RC.LoadImage("Assets/porcelainTexture.png");
            imgBumpTexture = RC.LoadImage("Assets/normalRust.jpg");
            _texTeapot     = RC.CreateTexture(imgTexture);
            _texBumpTeapot = RC.CreateTexture(imgBumpTexture);

            _currentTexture     = _texCube;
            _currentBumpTexture = _texBumpCube;

            // Load Meshes
            _meshCube   = MeshReader.LoadMesh(@"Assets/Cube.obj.model");
            _meshSphere = MeshReader.LoadMesh(@"Assets/Sphere.obj.model");
            _meshTeapot = MeshReader.LoadMesh(@"Assets/Teapot.obj.model");

            // Set current Mesh and Update GUI
            _currentMesh         = _meshCube;
            _btnCube.ButtonColor = ColorHighlightedButton;

            // Setup Shaderprograms and Update GUI
            _shaderDiffuseColor                = Shaders.GetDiffuseColorShader(RC);
            _shaderDiffuseTexture              = Shaders.GetDiffuseTextureShader(RC);
            _shaderTexture                     = Shaders.GetTextureShader(RC);
            _shaderDiffuseBumpTexture          = Shaders.GetBumpDiffuseShader(RC);
            _shaderSpecularTexture             = Shaders.GetSpecularShader(RC);
            _btnDiffuseColorShader.ButtonColor = ColorHighlightedButton;
            _currentShader                     = _shaderDiffuseColor;
            RC.SetShader(_shaderDiffuseColor);

            // Setup ShaderParams
            _paramColor = _shaderDiffuseColor.GetShaderParam("color");

            // Setup Light and Update GUI
            RC.SetLightActive(0, 1);
            RC.SetLightPosition(0, new float3(5.0f, 0.0f, -2.0f));
            RC.SetLightAmbient(0, new float4(0.2f, 0.2f, 0.2f, 1.0f));
            RC.SetLightSpecular(0, new float4(0.1f, 0.1f, 0.1f, 1.0f));
            RC.SetLightDiffuse(0, new float4(0.8f, 0.8f, 0.8f, 1.0f));
            RC.SetLightDirection(0, new float3(-1.0f, 0.0f, 0.0f));
            RC.SetLightSpotAngle(0, 10);

            _btnDirectionalLight.ButtonColor = ColorHighlightedButton;
        }
Example #18
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);
        }
Example #19
0
        /// <summary>
        /// Creates GUI elements required for displaying <see cref="SceneObject"/> fields like name, prefab data and
        /// transform (position, rotation, scale). Assumes that necessary inspector scroll area layout has already been
        /// created.
        /// </summary>
        private void CreateSceneObjectFields()
        {
            GUIPanel sceneObjectPanel = inspectorLayout.AddPanel();

            sceneObjectPanel.SetHeight(GetTitleBounds().height);

            GUILayoutY sceneObjectLayout = sceneObjectPanel.AddLayoutY();

            sceneObjectLayout.SetPosition(PADDING, PADDING);

            GUIPanel sceneObjectBgPanel = sceneObjectPanel.AddPanel(1);

            GUILayoutX nameLayout = sceneObjectLayout.AddLayoutX();

            soActiveToggle            = new GUIToggle("");
            soActiveToggle.OnToggled += OnSceneObjectActiveStateToggled;
            GUILabel nameLbl = new GUILabel(new LocEdString("Name"), GUIOption.FixedWidth(50));

            soNameInput              = new GUITextBox(false, GUIOption.FlexibleWidth(180));
            soNameInput.Text         = activeSO.Name;
            soNameInput.OnChanged   += OnSceneObjectRename;
            soNameInput.OnConfirmed += OnModifyConfirm;
            soNameInput.OnFocusLost += OnModifyConfirm;

            nameLayout.AddElement(soActiveToggle);
            nameLayout.AddSpace(3);
            nameLayout.AddElement(nameLbl);
            nameLayout.AddElement(soNameInput);
            nameLayout.AddFlexibleSpace();

            GUILayoutX mobilityLayout = sceneObjectLayout.AddLayoutX();
            GUILabel   mobilityLbl    = new GUILabel(new LocEdString("Mobility"), GUIOption.FixedWidth(50));

            soMobility       = new GUIEnumField(typeof(ObjectMobility), "", 0, GUIOption.FixedWidth(85));
            soMobility.Value = (ulong)activeSO.Mobility;
            soMobility.OnSelectionChanged += value => activeSO.Mobility = (ObjectMobility)value;
            mobilityLayout.AddElement(mobilityLbl);
            mobilityLayout.AddElement(soMobility);

            soPrefabLayout = sceneObjectLayout.AddLayoutX();

            GUILayoutX positionLayout = sceneObjectLayout.AddLayoutX();
            GUILabel   positionLbl    = new GUILabel(new LocEdString("Position"), GUIOption.FixedWidth(50));

            soPosX = new GUIFloatField(new LocEdString("X"), 10, "", GUIOption.FixedWidth(60));
            soPosY = new GUIFloatField(new LocEdString("Y"), 10, "", GUIOption.FixedWidth(60));
            soPosZ = new GUIFloatField(new LocEdString("Z"), 10, "", GUIOption.FixedWidth(60));

            soPosX.OnChanged += (x) => OnPositionChanged(0, x);
            soPosY.OnChanged += (y) => OnPositionChanged(1, y);
            soPosZ.OnChanged += (z) => OnPositionChanged(2, z);

            soPosX.OnConfirmed += OnModifyConfirm;
            soPosY.OnConfirmed += OnModifyConfirm;
            soPosZ.OnConfirmed += OnModifyConfirm;

            soPosX.OnFocusLost += OnModifyConfirm;
            soPosY.OnFocusLost += OnModifyConfirm;
            soPosZ.OnFocusLost += OnModifyConfirm;

            positionLayout.AddElement(positionLbl);
            positionLayout.AddElement(soPosX);
            positionLayout.AddSpace(10);
            positionLayout.AddFlexibleSpace();
            positionLayout.AddElement(soPosY);
            positionLayout.AddSpace(10);
            positionLayout.AddFlexibleSpace();
            positionLayout.AddElement(soPosZ);
            positionLayout.AddFlexibleSpace();

            GUILayoutX rotationLayout = sceneObjectLayout.AddLayoutX();
            GUILabel   rotationLbl    = new GUILabel(new LocEdString("Rotation"), GUIOption.FixedWidth(50));

            soRotX = new GUIFloatField(new LocEdString("X"), 10, "", GUIOption.FixedWidth(60));
            soRotY = new GUIFloatField(new LocEdString("Y"), 10, "", GUIOption.FixedWidth(60));
            soRotZ = new GUIFloatField(new LocEdString("Z"), 10, "", GUIOption.FixedWidth(60));

            soRotX.OnChanged += (x) => OnRotationChanged(0, x);
            soRotY.OnChanged += (y) => OnRotationChanged(1, y);
            soRotZ.OnChanged += (z) => OnRotationChanged(2, z);

            soRotX.OnConfirmed += OnModifyConfirm;
            soRotY.OnConfirmed += OnModifyConfirm;
            soRotZ.OnConfirmed += OnModifyConfirm;

            soRotX.OnFocusLost += OnModifyConfirm;
            soRotY.OnFocusLost += OnModifyConfirm;
            soRotZ.OnFocusLost += OnModifyConfirm;

            rotationLayout.AddElement(rotationLbl);
            rotationLayout.AddElement(soRotX);
            rotationLayout.AddSpace(10);
            rotationLayout.AddFlexibleSpace();
            rotationLayout.AddElement(soRotY);
            rotationLayout.AddSpace(10);
            rotationLayout.AddFlexibleSpace();
            rotationLayout.AddElement(soRotZ);
            rotationLayout.AddFlexibleSpace();

            GUILayoutX scaleLayout = sceneObjectLayout.AddLayoutX();
            GUILabel   scaleLbl    = new GUILabel(new LocEdString("Scale"), GUIOption.FixedWidth(50));

            soScaleX = new GUIFloatField(new LocEdString("X"), 10, "", GUIOption.FixedWidth(60));
            soScaleY = new GUIFloatField(new LocEdString("Y"), 10, "", GUIOption.FixedWidth(60));
            soScaleZ = new GUIFloatField(new LocEdString("Z"), 10, "", GUIOption.FixedWidth(60));

            soScaleX.OnChanged += (x) => OnScaleChanged(0, x);
            soScaleY.OnChanged += (y) => OnScaleChanged(1, y);
            soScaleZ.OnChanged += (z) => OnScaleChanged(2, z);

            soScaleX.OnConfirmed += OnModifyConfirm;
            soScaleY.OnConfirmed += OnModifyConfirm;
            soScaleZ.OnConfirmed += OnModifyConfirm;

            soScaleX.OnFocusLost += OnModifyConfirm;
            soScaleY.OnFocusLost += OnModifyConfirm;
            soScaleZ.OnFocusLost += OnModifyConfirm;

            scaleLayout.AddElement(scaleLbl);
            scaleLayout.AddElement(soScaleX);
            scaleLayout.AddSpace(10);
            scaleLayout.AddFlexibleSpace();
            scaleLayout.AddElement(soScaleY);
            scaleLayout.AddSpace(10);
            scaleLayout.AddFlexibleSpace();
            scaleLayout.AddElement(soScaleZ);
            scaleLayout.AddFlexibleSpace();

            sceneObjectLayout.AddFlexibleSpace();

            GUITexture titleBg = new GUITexture(null, EditorStylesInternal.InspectorTitleBg);

            sceneObjectBgPanel.AddElement(titleBg);
        }
Example #20
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();
        }
Example #21
0
    void Update()
    {
        if (cam == null)
        {
            // TODO: don't use Camera.current!
            cam = Camera.current; // sometimes null for a few cycles
            if (cam != null && cam.tag == "DeathCamera")
            {
                cam = null;
            }
        }
        if (cam == null)
        {
            return; // sometimes null for a few cycles
        }
        bool setAxes = false;

        for (int i = 0; i < Input.touchCount; i++)
        {
            Touch touch = Input.GetTouch(i);
            if (touch.phase == TouchPhase.Began &&
                !EventSystem.current.IsPointerOverGameObject(touch.fingerId) &&
                GUIPanel.PanelContainingPoint(touch.position) == null)
            {
                if (touchedTapComponent != null)
                {
                    touchedTapComponent.TapEnd();
                }
                lookTouchId = touch.fingerId;

                RaycastHit hit;
                if (Physics.Raycast(cam.ScreenPointToRay(touch.position), out hit))
                {
                    TapComponent hitTapComponent = hit.transform.GetComponent <TapComponent>();
                    if (hitTapComponent != null)
                    {
                        touchedTapComponent = hitTapComponent;
                        touchedTapComponent.TapStart(PlayerComponent.instance, hit.distance);
                    }
                }
            }
            // don't move joystick and camera with same touch
            if (lookTouchId == joystick.dragTouchId)
            {
                lookTouchId = -1;
                if (touchedTapComponent != null)
                {
                    touchedTapComponent.TapEnd();
                    touchedTapComponent = null;
                }
            }
            if (touch.fingerId == lookTouchId)
            {
                setAxes = true;
                hAxis.Update(touch.deltaPosition.x * 150f / cam.pixelHeight);
                vAxis.Update(touch.deltaPosition.y * 150f / cam.pixelHeight);
                if (touch.phase == TouchPhase.Ended && touchedTapComponent != null)
                {
                    touchedTapComponent.TapEnd();
                    touchedTapComponent = null;
                }
            }
        }
        if (!setAxes)
        {
            lookTouchId = -1;
            hAxis.Update(0);
            vAxis.Update(0);
        }
    }
Example #22
0
        /// <summary>
        /// Refreshes the contents of the content area. Must be called at least once after construction.
        /// </summary>
        /// <param name="viewType">Determines how to display the resource tiles.</param>
        /// <param name="entriesToDisplay">Project library entries to display.</param>
        /// <param name="bounds">Bounds within which to lay out the content entries.</param>
        public void Refresh(ProjectViewType viewType, LibraryEntry[] entriesToDisplay, Rect2I bounds)
        {
            if (mainPanel != null)
            {
                mainPanel.Destroy();
            }

            entries.Clear();
            entryLookup.Clear();

            mainPanel = parent.Layout.AddPanel();

            GUIPanel contentPanel = mainPanel.AddPanel(1);

            overlay       = mainPanel.AddPanel(0);
            underlay      = mainPanel.AddPanel(2);
            deepUnderlay  = mainPanel.AddPanel(3);
            renameOverlay = mainPanel.AddPanel(-1);

            main = contentPanel.AddLayoutY();

            List <ResourceToDisplay> resourcesToDisplay = new List <ResourceToDisplay>();

            foreach (var entry in entriesToDisplay)
            {
                if (entry.Type == LibraryEntryType.Directory)
                {
                    resourcesToDisplay.Add(new ResourceToDisplay(entry.Path, LibraryGUIEntryType.Single));
                }
                else
                {
                    FileEntry      fileEntry = (FileEntry)entry;
                    ResourceMeta[] metas     = fileEntry.ResourceMetas;

                    if (metas.Length > 0)
                    {
                        if (metas.Length == 1)
                        {
                            resourcesToDisplay.Add(new ResourceToDisplay(entry.Path, LibraryGUIEntryType.Single));
                        }
                        else
                        {
                            resourcesToDisplay.Add(new ResourceToDisplay(entry.Path, LibraryGUIEntryType.MultiFirst));

                            for (int i = 1; i < metas.Length - 1; i++)
                            {
                                string path = Path.Combine(entry.Path, metas[i].SubresourceName);
                                resourcesToDisplay.Add(new ResourceToDisplay(path, LibraryGUIEntryType.MultiElement));
                            }

                            string lastPath = Path.Combine(entry.Path, metas[metas.Length - 1].SubresourceName);
                            resourcesToDisplay.Add(new ResourceToDisplay(lastPath, LibraryGUIEntryType.MultiLast));
                        }
                    }
                }
            }

            int minHorzElemSpacing = 0;

            if (viewType == ProjectViewType.List16)
            {
                tileSize           = 16;
                gridLayout         = false;
                elementsPerRow     = 1;
                minHorzElemSpacing = 0;
                int elemWidth  = bounds.width;
                int elemHeight = tileSize;

                main.AddSpace(TOP_MARGIN);

                for (int i = 0; i < resourcesToDisplay.Count; i++)
                {
                    ResourceToDisplay entry = resourcesToDisplay[i];

                    LibraryGUIEntry guiEntry = new LibraryGUIEntry(this, main, entry.path, i, elemWidth, elemHeight, 0,
                                                                   entry.type);
                    entries.Add(guiEntry);
                    entryLookup[guiEntry.path] = guiEntry;

                    if (i != resourcesToDisplay.Count - 1)
                    {
                        main.AddSpace(LIST_ENTRY_SPACING);
                    }
                }

                main.AddFlexibleSpace();
            }
            else
            {
                int elemWidth       = 0;
                int elemHeight      = 0;
                int vertElemSpacing = 0;

                switch (viewType)
                {
                case ProjectViewType.Grid64:
                    tileSize           = 64;
                    elemWidth          = tileSize;
                    elemHeight         = tileSize + 36;
                    minHorzElemSpacing = 10;
                    vertElemSpacing    = 12;
                    break;

                case ProjectViewType.Grid48:
                    tileSize           = 48;
                    elemWidth          = tileSize;
                    elemHeight         = tileSize + 36;
                    minHorzElemSpacing = 8;
                    vertElemSpacing    = 10;
                    break;

                case ProjectViewType.Grid32:
                    tileSize           = 32;
                    elemWidth          = tileSize + 16;
                    elemHeight         = tileSize + 48;
                    minHorzElemSpacing = 6;
                    vertElemSpacing    = 10;
                    break;
                }

                gridLayout = true;

                int availableWidth = bounds.width;
                elementsPerRow = MathEx.FloorToInt((availableWidth - minHorzElemSpacing) / (float)(elemWidth + minHorzElemSpacing));

                int numRows      = MathEx.CeilToInt(resourcesToDisplay.Count / (float)Math.Max(elementsPerRow, 1));
                int neededHeight = numRows * elemHeight + TOP_MARGIN;
                if (numRows > 0)
                {
                    neededHeight += (numRows - 1) * vertElemSpacing;
                }

                bool requiresScrollbar = neededHeight > bounds.height;
                if (requiresScrollbar)
                {
                    availableWidth -= parent.ScrollBarWidth;
                    elementsPerRow  = MathEx.FloorToInt((availableWidth - minHorzElemSpacing) / (float)(elemWidth + minHorzElemSpacing));
                }

                int extraRowSpace = availableWidth - minHorzElemSpacing * 2 - elementsPerRow * elemWidth;

                paddingLeft  = minHorzElemSpacing;
                paddingRight = minHorzElemSpacing;
                float horzSpacing = 0.0f;

                // Distribute the spacing to the padding, as there are not in-between spaces to apply it to
                if (extraRowSpace > 0 && elementsPerRow < 2)
                {
                    int extraPadding = extraRowSpace / 2;
                    paddingLeft  += extraPadding;
                    paddingRight += (extraRowSpace - extraPadding);

                    extraRowSpace = 0;
                }
                else
                {
                    horzSpacing = extraRowSpace / (float)(elementsPerRow - 1);
                }

                elementsPerRow = Math.Max(elementsPerRow, 1);

                main.AddSpace(TOP_MARGIN);
                GUILayoutX rowLayout = main.AddLayoutX();
                rowLayout.AddSpace(paddingLeft);

                float spacingCounter = 0.0f;
                int   elemsInRow     = 0;
                for (int i = 0; i < resourcesToDisplay.Count; i++)
                {
                    if (elemsInRow == elementsPerRow && elemsInRow > 0)
                    {
                        main.AddSpace(vertElemSpacing);
                        rowLayout = main.AddLayoutX();
                        rowLayout.AddSpace(paddingLeft);

                        elemsInRow     = 0;
                        spacingCounter = 0.0f;
                    }

                    ResourceToDisplay entry = resourcesToDisplay[i];
                    elemsInRow++;

                    if (elemsInRow != elementsPerRow)
                    {
                        spacingCounter += horzSpacing;
                    }

                    int spacing = (int)spacingCounter;
                    spacingCounter -= spacing;

                    LibraryGUIEntry guiEntry = new LibraryGUIEntry(this, rowLayout, entry.path, i, elemWidth, elemHeight,
                                                                   spacing, entry.type);
                    entries.Add(guiEntry);
                    entryLookup[guiEntry.path] = guiEntry;

                    if (elemsInRow == elementsPerRow)
                    {
                        rowLayout.AddSpace(paddingRight);
                    }

                    rowLayout.AddSpace(spacing);
                }

                int extraElements = elementsPerRow - elemsInRow;
                int extraSpacing  = 0;

                if (extraElements > 1)
                {
                    spacingCounter += (extraElements - 1) * horzSpacing;
                    extraSpacing   += (int)spacingCounter;
                }

                if (extraElements > 0)
                {
                    rowLayout.AddSpace(elemWidth * extraElements + extraSpacing + paddingRight);
                }

                main.AddFlexibleSpace();
            }

            // Fix bounds as that makes GUI updates faster
            underlay.Bounds      = main.Bounds;
            overlay.Bounds       = main.Bounds;
            deepUnderlay.Bounds  = main.Bounds;
            renameOverlay.Bounds = main.Bounds;

            for (int i = 0; i < entries.Count; i++)
            {
                LibraryGUIEntry guiEntry = entries[i];
                guiEntry.Initialize();
            }
        }
        /// <summary>
        /// Sets a scene object whose GUI is to be displayed in the inspector. Clears any previous contents of the window.
        /// </summary>
        /// <param name="so">Scene object to inspect.</param>
        private void SetObjectToInspect(SceneObject so)
        {
            if (so == null)
            {
                return;
            }

            currentType = InspectorType.SceneObject;
            activeSO    = so;

            inspectorScrollArea = new GUIScrollArea(ScrollBarType.ShowIfDoesntFit, ScrollBarType.NeverShow);
            scrollAreaHighlight = new GUITexture(Builtin.WhiteTexture);
            scrollAreaHighlight.SetTint(HIGHLIGHT_COLOR);
            scrollAreaHighlight.Active = false;

            GUI.AddElement(inspectorScrollArea);
            GUIPanel inspectorPanel = inspectorScrollArea.Layout.AddPanel();

            inspectorLayout = inspectorPanel.AddLayoutY();
            highlightPanel  = inspectorPanel.AddPanel(-1);
            highlightPanel.AddElement(scrollAreaHighlight);

            // SceneObject fields
            CreateSceneObjectFields();
            RefreshSceneObjectFields(true);

            // Components
            Component[] allComponents = so.GetComponents();
            for (int i = 0; i < allComponents.Length; i++)
            {
                inspectorLayout.AddSpace(COMPONENT_SPACING);

                InspectorComponent data = new InspectorComponent();
                data.uuid   = allComponents[i].UUID;
                data.folded = false;

                data.foldout = new GUIToggle(allComponents[i].GetType().Name, EditorStyles.Foldout);
                data.foldout.AcceptsKeyFocus = false;

                SpriteTexture xBtnIcon = EditorBuiltin.GetEditorIcon(EditorIcon.X);
                data.removeBtn = new GUIButton(new GUIContent(xBtnIcon), GUIOption.FixedWidth(30));

                data.title = inspectorLayout.AddLayoutX();
                data.title.AddElement(data.foldout);
                data.title.AddElement(data.removeBtn);
                data.panel = inspectorLayout.AddPanel();

                var persistentProperties = persistentData.GetProperties(allComponents[i].InstanceId);

                data.inspector = InspectorUtility.GetInspector(allComponents[i].GetType());
                data.inspector.Initialize(data.panel, allComponents[i], persistentProperties);

                bool isExpanded = data.inspector.Persistent.GetBool(data.uuid + "_Expanded", true);
                data.foldout.Value = isExpanded;

                if (!isExpanded)
                {
                    data.inspector.SetVisible(false);
                }

                Type curComponentType = allComponents[i].GetType();
                data.foldout.OnToggled += (bool expanded) => OnComponentFoldoutToggled(data, expanded);
                data.removeBtn.OnClick += () => OnComponentRemoveClicked(curComponentType);

                inspectorComponents.Add(data);
            }

            inspectorLayout.AddFlexibleSpace();

            UpdateDropAreas();
        }
Example #24
0
    public GUIElement NewImage(GUIPanel.Alignments hAlign, float x, GUIPanel.Alignments vAlign, float y, Texture image)
    {
        GUIElement element = new GUIElement();

        element.HAlignement = hAlign;
        element.VAlignement = vAlign;
        element.Bounds = new Rect(x, y, image.width, image.height);
        element.BackgroundImage = image;
        element.ElementType = GUIElement.ElementTypes.Image;

        Children.Add(element);
        return element;
    }
Example #25
0
    void Update()
    {
        if (ScreenSize.x != Camera.main.pixelWidth || ScreenSize.y != Camera.main.pixelHeight)
        {
            GUIPanel.RebuildAll();
            ScreenSize = new Vector2(Camera.main.pixelWidth, Camera.main.pixelHeight);
        }

        if (StatusWindow != null && ThePlayer != null)
        {
            if (ThePlayer.HitPoints != 0)
            {
                StatusWindow.SetHealth(ThePlayer.Damage / (float)ThePlayer.HitPoints);
            }

            if (ThePlayer.ManaSpent != 0)
            {
                StatusWindow.SetMana(ThePlayer.ManaSpent / (float)ThePlayer.MagicPower);
            }
            else
            {
                StatusWindow.SetMana(0);
            }
        }

        if (ThePlayer != null && ThePlayer.Alive && Input.GetKeyDown(KeyCode.Escape))
        {
            if (InMenu)
            {
                InMenu           = false;
                GameMenu.Enabled = false;
            }
            else
            {
                InMenu           = true;
                GameMenu.Enabled = true;
            }
        }

        // check for clicks
        if (Input.GetMouseButtonDown(0) && !InMenu)
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            RaycastHit hit;

            // turn ourselves off so we don't get us
            ThePlayer.WorldObject.collider.enabled = false;

            if (Physics.Raycast(ray, out hit, 100))
            {
                //    Debug.Log(hit.transform.gameObject);
                //    Debug.Log(hit.transform.gameObject.tag);

                if (hit.transform.gameObject.tag == "Mob")
                {
                    GameState.Instance.SelectMob(hit.transform.gameObject);
                }
                else if (hit.transform.gameObject.tag == "LootDrop")
                {
                    if (Vector3.Distance(hit.transform.gameObject.transform.position, ThePlayer.WorldObject.transform.position) < LootAutoCloseDistance)
                    {
                        GameState.Instance.SelectMob(null);
                        Loot.Show(hit.transform.gameObject.GetComponent <ItemContainer>());
                    }
                }
            }

            ThePlayer.WorldObject.collider.enabled = true;
        }

        if (Input.GetKeyDown(KeyCode.Space))
        {
            SkillScreen.BuildSkills();
        }

        if (Loot != null && Loot.Container != null)
        {
            if (Vector3.Distance(Loot.Container.gameObject.transform.position, ThePlayer.WorldObject.transform.position) > LootAutoCloseDistance)
            {
                Loot.Show(null);
            }
        }
    }
Example #26
0
    public GUIElement NewImageButton(GUIPanel.Alignments hAlign, float x, GUIPanel.Alignments vAlign, float y, Texture image, EventHandler handler)
    {
        GUIElement element = new GUIElement();

        element.HAlignement = hAlign;
        element.VAlignement = vAlign;
        element.Bounds = new Rect(x, y, image.width, image.height);
        element.BackgroundImage = image;
        element.ElementType = GUIElement.ElementTypes.Button;

        element.Clicked += handler;

        Children.Add(element);
        return element;
    }
        private void Rebuild()
        {
            scrollArea.Layout.Clear();
            fields = null;

            if (fieldInfos == null || root == null)
            {
                return;
            }

            GUILabel header = new GUILabel(new LocEdString("Properties"), EditorStyles.Header);

            scrollArea.Layout.AddElement(header);

            layouts = new GUIAnimFieldLayouts();
            GUIPanel rootPanel       = scrollArea.Layout.AddPanel();
            GUIPanel mainPanel       = rootPanel.AddPanel();
            GUIPanel underlayPanel   = rootPanel.AddPanel(1);
            GUIPanel overlayPanel    = rootPanel.AddPanel(-1);
            GUIPanel backgroundPanel = rootPanel.AddPanel(2);

            layouts.main       = mainPanel.AddLayoutY();
            layouts.underlay   = underlayPanel.AddLayoutY();
            layouts.overlay    = overlayPanel.AddLayoutY();
            layouts.background = backgroundPanel.AddLayoutY();

            GUIButton catchAll = new GUIButton("", EditorStyles.Blank);

            catchAll.Bounds   = new Rect2I(0, 0, width, height - header.Bounds.height);
            catchAll.OnClick += () => OnEntrySelected(null);

            underlayPanel.AddElement(catchAll);

            layouts.main.AddSpace(5);
            layouts.underlay.AddSpace(5);
            layouts.overlay.AddSpace(5);
            layouts.background.AddSpace(3); // Minor hack: Background starts heigher to get it to center better

            fields = new GUIAnimFieldEntry[fieldInfos.Count];
            for (int i = 0; i < fieldInfos.Count; i++)
            {
                if (string.IsNullOrEmpty(fieldInfos[i].path))
                {
                    continue;
                }

                bool entryIsMissing;
                if (fieldInfos[i].isUserCurve)
                {
                    string pathSuffix;
                    SerializableProperty property = Animation.FindProperty(root, fieldInfos[i].path, out pathSuffix);
                    entryIsMissing = property == null;
                }
                else
                {
                    entryIsMissing = false;
                }

                if (!entryIsMissing)
                {
                    Color[] colors = new Color[fieldInfos[i].curveGroup.curveInfos.Length];
                    for (int j = 0; j < fieldInfos[i].curveGroup.curveInfos.Length; j++)
                    {
                        colors[j] = fieldInfos[i].curveGroup.curveInfos[j].color;
                    }

                    switch (fieldInfos[i].curveGroup.type)
                    {
                    case SerializableProperty.FieldType.Vector2:
                        fields[i] = new GUIAnimVec2Entry(layouts, fieldInfos[i].path, colors);
                        break;

                    case SerializableProperty.FieldType.Vector3:
                        fields[i] = new GUIAnimVec3Entry(layouts, fieldInfos[i].path, colors);
                        break;

                    case SerializableProperty.FieldType.Vector4:
                        fields[i] = new GUIAnimVec4Entry(layouts, fieldInfos[i].path, colors);
                        break;

                    case SerializableProperty.FieldType.Color:
                        fields[i] = new GUIAnimColorEntry(layouts, fieldInfos[i].path, colors);
                        break;

                    case SerializableProperty.FieldType.Bool:
                    case SerializableProperty.FieldType.Int:
                    case SerializableProperty.FieldType.Float:
                    {
                        Color color;
                        if (colors.Length > 0)
                        {
                            color = colors[0];
                        }
                        else
                        {
                            color = Color.White;
                        }

                        fields[i] = new GUIAnimSimpleEntry(layouts, fieldInfos[i].path, color);
                        break;
                    }
                    }
                }
                else
                {
                    fields[i] = new GUIAnimMissingEntry(layouts, fieldInfos[i].path);
                }

                if (fields[i] != null)
                {
                    fields[i].OnEntrySelected += OnEntrySelected;
                }
            }

            if (fieldInfos.Count == 0)
            {
                GUILabel warningLbl = new GUILabel(new LocEdString("No properties. Add a new property to begin animating."));

                GUILayoutY vertLayout = layouts.main.AddLayoutY();
                vertLayout.AddFlexibleSpace();
                GUILayoutX horzLayout = vertLayout.AddLayoutX();
                vertLayout.AddFlexibleSpace();

                horzLayout.AddFlexibleSpace();
                horzLayout.AddElement(warningLbl);
                horzLayout.AddFlexibleSpace();
            }

            layouts.main.AddSpace(5);
            layouts.underlay.AddSpace(5);
            layouts.overlay.AddSpace(5);
            layouts.background.AddSpace(5);

            layouts.main.AddFlexibleSpace();
            layouts.underlay.AddFlexibleSpace();
            layouts.overlay.AddFlexibleSpace();
            layouts.background.AddFlexibleSpace();
        }
Example #28
0
    public GUIElement NewLabel(GUIPanel.Alignments hAlign, float x, GUIPanel.Alignments vAlign, float y, float width, float height, string text)
    {
        GUIElement element = new GUIElement();

        element.HAlignement = hAlign;
        element.VAlignement = vAlign;
        element.Bounds = new Rect(x, y, width, height);
        element.Name = text;
        element.ElementType = GUIElement.ElementTypes.Label;

        Children.Add(element);
        return element;
    }
        /// <summary>
        /// Rebuilds the GUI dictionary 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);

                guiFoldout                 = new GUIToggle(title, EditorStyles.Foldout);
                guiFoldout.Value           = isExpanded;
                guiFoldout.AcceptsKeyFocus = false;
                guiFoldout.OnToggled      += x => ToggleFoldout(x, false);

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

                GUIContent addIcon = new GUIContent(EditorBuiltin.GetInspectorWindowIcon(InspectorWindowIcon.Add),
                                                    new LocEdString("Add"));
                GUIButton guiAddBtn = new GUIButton(addIcon, GUIOption.FixedWidth(30));
                guiAddBtn.OnClick += OnAddButtonClicked;

                guiInternalTitleLayout.AddElement(guiFoldout);
                guiInternalTitleLayout.AddElement(guiAddBtn);
                guiInternalTitleLayout.AddElement(guiClearBtn);

                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);

                ToggleFoldout(isExpanded, false);
            };

            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;
                }
            }
        }
Example #30
0
    void Update()
    {
        if (Input.touchCount == 0)
        {
            if (currentTouchOperation == TouchOperation.SELECT)
            {
                voxelArray.TouchUp();
            }
            if (currentTouchOperation == TouchOperation.MOVE)
            {
                movingAxis.TouchUp();
            }
            currentTouchOperation = TouchOperation.NONE;
        }
        else if (Input.touchCount == 1)
        {
            Touch touch = Input.GetTouch(0);

            RaycastHit hit;
            if (currentTouchOperation != TouchOperation.SELECT)
            {
                selectingXRay = true;
            }
            bool rayHitSomething = Physics.Raycast(cam.ScreenPointToRay(Input.GetTouch(0).position),
                                                   out hit, Mathf.Infinity, selectingXRay ? Physics.DefaultRaycastLayers : NO_XRAY_MASK);
            Voxel         hitVoxel         = null;
            int           hitFaceI         = -1;
            TransformAxis hitTransformAxis = null;
            ObjectMarker  hitMarker        = null;
            if (rayHitSomething)
            {
                GameObject hitObject = hit.transform.gameObject;
                if (hitObject.tag == "Voxel")
                {
                    hitVoxel = hitObject.GetComponent <Voxel>();
                    hitFaceI = Voxel.FaceIForDirection(hit.normal);
                    if (hitFaceI == -1)
                    {
                        hitVoxel = null;
                    }
                }
                else if (hitObject.tag == "ObjectMarker")
                {
                    hitMarker = hitObject.GetComponent <ObjectMarker>();
                }
                else if (hitObject.tag == "MoveAxis")
                {
                    hitTransformAxis = hitObject.GetComponent <TransformAxis>();
                }

                if ((hitVoxel != null && hitVoxel.substance != null && hitVoxel.substance.xRay) ||
                    (hitMarker != null && (hitMarker.gameObject.layer == 8 || hitMarker.gameObject.layer == 10)))     // xray or SelectedObject layer
                {
                    // allow moving axes through xray substances
                    RaycastHit newHit;
                    if (Physics.Raycast(cam.ScreenPointToRay(Input.GetTouch(0).position),
                                        out newHit, Mathf.Infinity, NO_TRANSPARENT_MASK))
                    {
                        if (newHit.transform.tag == "MoveAxis")
                        {
                            hitVoxel         = null;
                            hitFaceI         = -1;
                            hitMarker        = null;
                            hitTransformAxis = newHit.transform.GetComponent <TransformAxis>();
                        }
                    }
                }
            }
            if (hitVoxel != null)
            {
                lastHitVoxel = hitVoxel;
                lastHitFaceI = hitFaceI;
            }
            else if (hitMarker != null)
            {
                lastHitVoxel = null;
                lastHitFaceI = -1;
            }

            if (touch.phase == TouchPhase.Began)
            {
                if (currentTouchOperation == TouchOperation.SELECT)
                {
                    voxelArray.TouchUp();
                }
                // this seems to improve the reliability of double-taps when things are running slowly.
                // I think it's because there's not always a long enough gap between taps
                // for the touch operation to be cleared.
                currentTouchOperation = TouchOperation.NONE;
            }

            if (currentTouchOperation == TouchOperation.NONE)
            {
                if (GUIPanel.PanelContainingPoint(touch.position) != null)
                {
                    currentTouchOperation = TouchOperation.GUI;
                }
                else if (touch.phase != TouchPhase.Moved && touch.phase != TouchPhase.Ended && touch.tapCount == 1)
                {
                }   // wait until moved or released, in case a multitouch operation is about to begin
                else if (!rayHitSomething)
                {
                    voxelArray.TouchDown(null);
                }
                else if (hitVoxel != null)
                {
                    if (touch.tapCount == 1)
                    {
                        currentTouchOperation = TouchOperation.SELECT;
                        voxelArray.TouchDown(hitVoxel, hitFaceI);
                        selectingXRay = hitVoxel.substance != null && hitVoxel.substance.xRay;
                    }
                    else if (touch.tapCount == 2)
                    {
                        voxelArray.DoubleTouch(hitVoxel, hitFaceI);
                    }
                    else if (touch.tapCount == 3)
                    {
                        voxelArray.TripleTouch(hitVoxel, hitFaceI);
                    }
                    UpdateZoomDepth();
                }
                else if (hitMarker != null)
                {
                    currentTouchOperation = TouchOperation.SELECT;
                    voxelArray.TouchDown(hitMarker);
                    selectingXRay = hitMarker.objectEntity.xRay;
                    UpdateZoomDepth();
                }
                else if (hitTransformAxis != null)
                {
                    if (touch.tapCount == 1)
                    {
                        currentTouchOperation = TouchOperation.MOVE;
                        movingAxis            = hitTransformAxis;
                        movingAxis.TouchDown(touch);
                    }
                    else if (touch.tapCount == 2 && lastHitVoxel != null)
                    {
                        voxelArray.DoubleTouch(lastHitVoxel, lastHitFaceI);
                    }
                    else if (touch.tapCount == 3 && lastHitVoxel != null)
                    {
                        voxelArray.TripleTouch(lastHitVoxel, lastHitFaceI);
                    }
                    UpdateZoomDepth();
                }
            } // end if currentTouchOperation == NONE

            else if (currentTouchOperation == TouchOperation.SELECT)
            {
                if (hitVoxel != null)
                {
                    voxelArray.TouchDrag(hitVoxel, hitFaceI);
                }
                if (hitMarker != null)
                {
                    voxelArray.TouchDrag(hitMarker);
                }
            }
            else if (currentTouchOperation == TouchOperation.MOVE)
            {
                movingAxis.TouchDrag(touch);
            }
        } // end if touch count is 1
        else if (Input.touchCount == 2)
        {
            if (currentTouchOperation == TouchOperation.NONE)
            {
                currentTouchOperation = TouchOperation.CAMERA;
                UpdateZoomDepth();
            }
            if (currentTouchOperation != TouchOperation.CAMERA)
            {
                return;
            }

            Touch touchZero = Input.GetTouch(0);
            Touch touchOne  = Input.GetTouch(1);

            Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;
            Vector2 touchOnePrevPos  = touchOne.position - touchOne.deltaPosition;

            float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude;
            float touchDeltaMag     = (touchZero.position - touchOne.position).magnitude;

            float deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag;

            float scaleFactor = Mathf.Pow(1.005f, deltaMagnitudeDiff / cam.pixelHeight * 700f);
            if (scaleFactor != 1)
            {
                pivot.localScale *= scaleFactor;
                if (pivot.localScale.x > MAX_ZOOM)
                {
                    pivot.localScale = new Vector3(MAX_ZOOM, MAX_ZOOM, MAX_ZOOM);
                }
                if (pivot.localScale.x < MIN_ZOOM)
                {
                    pivot.localScale = new Vector3(MIN_ZOOM, MIN_ZOOM, MIN_ZOOM);
                }
            }

            Vector3 move = (touchZero.deltaPosition + touchOne.deltaPosition) / 2;
            move *= 300f;
            move /= cam.pixelHeight;
            Vector3 pivotRotationEuler = pivot.rotation.eulerAngles;
            pivotRotationEuler.y += move.x;
            pivotRotationEuler.x -= move.y;
            if (pivotRotationEuler.x > 90 && pivotRotationEuler.x < 180)
            {
                pivotRotationEuler.x = 90;
            }
            if (pivotRotationEuler.x < -90 || (pivotRotationEuler.x > 180 && pivotRotationEuler.x < 270))
            {
                pivotRotationEuler.x = -90;
            }
            pivot.rotation = Quaternion.Euler(pivotRotationEuler);
        }
        else if (Input.touchCount == 3)
        {
            if (currentTouchOperation == TouchOperation.NONE)
            {
                currentTouchOperation = TouchOperation.CAMERA;
                UpdateZoomDepth();
            }
            if (currentTouchOperation != TouchOperation.CAMERA)
            {
                return;
            }

            Vector2 move = new Vector2(0, 0);
            for (int i = 0; i < 3; i++)
            {
                move += Input.GetTouch(i).deltaPosition;
            }
            move           *= 4.0f;
            move           /= cam.pixelHeight;
            pivot.position -= move.x * pivot.right * pivot.localScale.z;
            pivot.position -= move.y * pivot.up * pivot.localScale.z;
        }
    }
 public static void CreatePanel(ref CuiElementContainer container, string Parent, string Name, GUIPanel panel, bool CursorEnabled = false) =>
 CreatePanel(ref container, Parent, Name, panel.Color, panel.Amin, panel.Amax, CursorEnabled);
Example #32
0
        // Init is called on startup.
        public override void Init()
        {
            Width  = 1295;
            Height = 760;

            listTowers = new Dictionary <int, Tower>();
            listWuggys = new List <Wuggy>();

            isTowerSelected = false;
            isUgradeMode    = false;
            towerCosts      = 100;

            // Load the scene
            _scene = AssetStorage.Get <SceneContainer>("TDMAPinWuggyFINAL.fus");
            _tower = AssetStorage.Get <SceneContainer>("TowerRed.fus");
            _wuggy = AssetStorage.Get <SceneContainer>("WuggyFromLand.fus");

            _sceneScale = float4x4.CreateScale(0.04f);

            listWuggys.Add(new Wuggy(DeepCopy(_wuggy), new float3(0, 0, 750), 8, new float3(0.2f, 0.9f, 0.2f), 0, 1, 100));

            // Instantiate our self-written renderer
            _renderer = new Renderer(RC);

            redColor    = new float4(1.0f, 0.0f, 0.2f, 1.0f);
            greenColor  = new float4(0.4f, 1.0f, 0.0f, 1.0f);
            blueColor   = new float4(0.0f, 0.4f, 1.0f, 1.0f);
            yellowColor = new float4(1.0f, 0.9f, 0.0f, 1.0f);
            whiteColor  = new float4(1.0f, 1.0f, 1.0f, 1.0f);
            cyanColor   = new float4(0.0f, 0.7f, 0.7f, 1.0f);

#if GUI_SIMPLE
            guiHandler = new GUIHandler();
            guiHandler.AttachToContext(RC);

            fontCabin            = AssetStorage.Get <Font>("AmericanCaptain.ttf");
            fontCabin.UseKerning = true;
            _guiCabinBlack       = new FontMap(fontCabin, 18);
            _guiCabinBlackBig    = new FontMap(fontCabin, 25);

            guiText           = new GUIText("Defend!", _guiCabinBlack, 310, 35);
            guiText.TextColor = new float4(0.05f, 0.25f, 0.15f, 0.8f);
            guiHandler.Add(guiText);

            guiPanelStatus             = new GUIPanel("Defend the Village", _guiCabinBlack, 880, 0, 400, 120);
            guiPanelStatus.PanelColor  = new float4(0.0f, 0.38f, 0.69f, 1.0f);
            guiPanelStatus.BorderWidth = 0;
            guiHandler.Add(guiPanelStatus);

            healthText           = new GUIText("Health Village: 10", _guiCabinBlackBig, 900, 60);
            healthText.TextColor = new float4(0.9f, 0.0f, 0.0f, 1.0f);
            guiHandler.Add(healthText);

            moneyText           = new GUIText("Money: 1000", _guiCabinBlackBig, 900, 90);
            moneyText.TextColor = new float4(0.0f, 0.9f, 0.1f, 1.0f);
            guiHandler.Add(moneyText);

            guiPanelShop             = new GUIPanel("Shop", _guiCabinBlack, 880, 370, 400, 250);
            guiPanelShop.PanelColor  = new float4(0.0f, 0.38f, 0.69f, 1.0f);
            guiPanelShop.BorderWidth = 0;
            guiHandler.Add(guiPanelShop);

            guiPanelWaves             = new GUIPanel("Wave", _guiCabinBlack, 880, 620, 400, 100);
            guiPanelWaves.PanelColor  = new float4(0.0f, 0.38f, 0.69f, 1.0f);
            guiPanelWaves.BorderWidth = 0;
            guiHandler.Add(guiPanelWaves);

            startButton = new GUIButton("Start Wave", _guiCabinBlack, 900, 650, 360, 50);
            startButton.OnGUIButtonDown  += startButtonClicked;
            startButton.OnGUIButtonEnter += shopButtonEnter;
            startButton.OnGUIButtonLeave += shopButtonLeave;
            guiHandler.Add(startButton);

            mapButtons = new List <GUIButton>();

            for (int i = 0; i < 146; i++)
            {
                mapButtons.Add(new GUIButton(500, 500, 8, 8));
                mapButtons[i].ButtonColor       = blueColor;
                mapButtons[i].BorderWidth       = 0;
                mapButtons[i].OnGUIButtonDown  += mapOnGUIButtonDown;
                mapButtons[i].OnGUIButtonEnter += mapOnGUIButtonEnter;
                mapButtons[i].OnGUIButtonLeave += mapOnGUIButtonLeave;
            }

            #region MapButtons
            //mapButtons[136].ButtonColor = new float4(0, 0, 1.0f, 1.0f);


            setButtonPosition(mapButtons[0], 945, 219);
            setButtonPosition(mapButtons[1], 932, 219);
            setButtonPosition(mapButtons[2], 957, 219);
            setButtonPosition(mapButtons[3], 969, 219);
            setButtonPosition(mapButtons[4], 981, 219);
            setButtonPosition(mapButtons[5], 981, 197);
            setButtonPosition(mapButtons[6], 967, 197);
            setButtonPosition(mapButtons[7], 953, 197);
            setButtonPosition(mapButtons[8], 939, 197);
            setButtonPosition(mapButtons[9], 979, 290);
            setButtonPosition(mapButtons[10], 967, 290);
            setButtonPosition(mapButtons[11], 955, 290);
            setButtonPosition(mapButtons[12], 942, 290);
            setButtonPosition(mapButtons[13], 942, 314);
            setButtonPosition(mapButtons[14], 955, 314);
            setButtonPosition(mapButtons[15], 967, 314);
            setButtonPosition(mapButtons[16], 979, 314);
            setButtonPosition(mapButtons[17], 1044, 314);
            setButtonPosition(mapButtons[18], 1032, 314);
            setButtonPosition(mapButtons[19], 1020, 314);
            setButtonPosition(mapButtons[20], 1008, 314);
            setButtonPosition(mapButtons[21], 1057, 314);
            setButtonPosition(mapButtons[22], 1069, 314);
            setButtonPosition(mapButtons[23], 1081, 314);
            setButtonPosition(mapButtons[24], 1175, 282);
            setButtonPosition(mapButtons[25], 1163, 282);
            setButtonPosition(mapButtons[26], 1151, 282);
            setButtonPosition(mapButtons[27], 1103, 282);
            setButtonPosition(mapButtons[28], 1115, 282);
            setButtonPosition(mapButtons[29], 1127, 282);
            setButtonPosition(mapButtons[30], 1139, 282);
            setButtonPosition(mapButtons[31], 1149, 307);
            setButtonPosition(mapButtons[32], 1137, 307);
            setButtonPosition(mapButtons[33], 1125, 307);
            setButtonPosition(mapButtons[34], 1113, 307);
            setButtonPosition(mapButtons[35], 1161, 307);
            setButtonPosition(mapButtons[36], 1173, 307);
            setButtonPosition(mapButtons[37], 1185, 307);
            setButtonPosition(mapButtons[38], 1081, 337);
            setButtonPosition(mapButtons[39], 1069, 337);
            setButtonPosition(mapButtons[40], 1057, 337);
            setButtonPosition(mapButtons[41], 1008, 337);
            setButtonPosition(mapButtons[42], 1020, 337);
            setButtonPosition(mapButtons[43], 1032, 337);
            setButtonPosition(mapButtons[44], 1044, 337);
            setButtonPosition(mapButtons[45], 1059, 259);
            setButtonPosition(mapButtons[46], 1047, 259);
            setButtonPosition(mapButtons[47], 1035, 259);
            setButtonPosition(mapButtons[48], 1023, 259);
            setButtonPosition(mapButtons[49], 1071, 259);
            setButtonPosition(mapButtons[50], 1091, 242);
            setButtonPosition(mapButtons[51], 1103, 242);
            setButtonPosition(mapButtons[52], 1127, 242);
            setButtonPosition(mapButtons[53], 1115, 242);
            setButtonPosition(mapButtons[54], 1167, 222);
            setButtonPosition(mapButtons[55], 1179, 222);
            setButtonPosition(mapButtons[56], 1155, 222);
            setButtonPosition(mapButtons[57], 1143, 222);
            setButtonPosition(mapButtons[58], 1143, 194);
            setButtonPosition(mapButtons[59], 1155, 194);
            setButtonPosition(mapButtons[60], 1182, 194);
            setButtonPosition(mapButtons[61], 1168, 194);
            setButtonPosition(mapButtons[62], 1102, 216);
            setButtonPosition(mapButtons[63], 1114, 216);
            setButtonPosition(mapButtons[64], 1090, 216);
            setButtonPosition(mapButtons[65], 1078, 216);
            setButtonPosition(mapButtons[66], 1023, 236);
            setButtonPosition(mapButtons[67], 1035, 236);
            setButtonPosition(mapButtons[68], 1047, 236);
            setButtonPosition(mapButtons[69], 1059, 236);
            setButtonPosition(mapButtons[70], 1008, 301);
            setButtonPosition(mapButtons[71], 1008, 287);
            setButtonPosition(mapButtons[72], 999, 243);
            setButtonPosition(mapButtons[73], 999, 258);
            setButtonPosition(mapButtons[74], 1058, 183);
            setButtonPosition(mapButtons[75], 1046, 183);
            setButtonPosition(mapButtons[76], 1034, 183);
            setButtonPosition(mapButtons[77], 1022, 183);
            setButtonPosition(mapButtons[78], 1070, 183);
            setButtonPosition(mapButtons[79], 1082, 183);
            setButtonPosition(mapButtons[80], 1147, 176);
            setButtonPosition(mapButtons[81], 1070, 157);
            setButtonPosition(mapButtons[82], 1022, 157);
            setButtonPosition(mapButtons[83], 1034, 157);
            setButtonPosition(mapButtons[84], 1046, 157);
            setButtonPosition(mapButtons[85], 1058, 157);
            setButtonPosition(mapButtons[86], 1135, 176);
            setButtonPosition(mapButtons[87], 1099, 176);
            setButtonPosition(mapButtons[88], 1111, 176);
            setButtonPosition(mapButtons[89], 1123, 176);
            setButtonPosition(mapButtons[90], 1113, 151);
            setButtonPosition(mapButtons[91], 1101, 151);
            setButtonPosition(mapButtons[92], 1089, 151);
            setButtonPosition(mapButtons[93], 1125, 151);
            setButtonPosition(mapButtons[94], 1137, 151);
            setButtonPosition(mapButtons[95], 1206, 146);
            setButtonPosition(mapButtons[96], 1194, 146);
            setButtonPosition(mapButtons[97], 1158, 146);
            setButtonPosition(mapButtons[98], 1170, 146);
            setButtonPosition(mapButtons[99], 1182, 146);
            setButtonPosition(mapButtons[100], 1179, 237);
            setButtonPosition(mapButtons[101], 1179, 252);
            setButtonPosition(mapButtons[102], 1206, 252);
            setButtonPosition(mapButtons[103], 1206, 237);
            setButtonPosition(mapButtons[104], 1206, 222);
            setButtonPosition(mapButtons[105], 1200, 278);
            setButtonPosition(mapButtons[106], 1200, 292);
            setButtonPosition(mapButtons[107], 1195, 194);
            setButtonPosition(mapButtons[108], 1182, 168);
            setButtonPosition(mapButtons[109], 1252, 194);
            setButtonPosition(mapButtons[110], 1264, 194);
            setButtonPosition(mapButtons[111], 1240, 194);
            setButtonPosition(mapButtons[112], 1228, 194);
            setButtonPosition(mapButtons[113], 1228, 168);
            setButtonPosition(mapButtons[114], 1240, 168);
            setButtonPosition(mapButtons[115], 1252, 168);
            setButtonPosition(mapButtons[116], 1264, 168);
            setButtonPosition(mapButtons[117], 1170, 168);
            setButtonPosition(mapButtons[118], 1194, 168);
            setButtonPosition(mapButtons[119], 1158, 168);
            setButtonPosition(mapButtons[120], 1023, 202);
            setButtonPosition(mapButtons[121], 1023, 216);
            setButtonPosition(mapButtons[122], 999, 194);
            setButtonPosition(mapButtons[123], 999, 179);
            setButtonPosition(mapButtons[124], 942, 276);
            setButtonPosition(mapButtons[125], 942, 261);
            setButtonPosition(mapButtons[126], 915, 209);
            setButtonPosition(mapButtons[127], 915, 227);
            setButtonPosition(mapButtons[128], 915, 245);
            setButtonPosition(mapButtons[129], 915, 191);
            setButtonPosition(mapButtons[130], 889, 191);
            setButtonPosition(mapButtons[131], 889, 245);
            setButtonPosition(mapButtons[132], 889, 227);
            setButtonPosition(mapButtons[133], 889, 209);
            setButtonPosition(mapButtons[134], 912, 276);
            setButtonPosition(mapButtons[135], 912, 290);
            setButtonPosition(mapButtons[136], 928, 314);
            setButtonPosition(mapButtons[137], 912, 305);
            setButtonPosition(mapButtons[138], 928, 245);
            setButtonPosition(mapButtons[139], 915, 161);
            setButtonPosition(mapButtons[140], 928, 161);
            setButtonPosition(mapButtons[141], 901, 161);
            setButtonPosition(mapButtons[142], 889, 174);
            setButtonPosition(mapButtons[143], 939, 178);
            setButtonPosition(mapButtons[144], 899, 276);
            setButtonPosition(mapButtons[145], 886, 276);
            #endregion

            foreach (GUIButton gb in mapButtons)
            {
                guiHandler.Add(gb);
            }



            guiHandlerTowers = new GUIHandler();
            guiHandlerTowers.AttachToContext(RC);
            buyButton = new GUIButton("Buy Tower (100)", _guiCabinBlack, 900, 400, 360, 50);
            buyButton.OnGUIButtonDown  += buyTower;
            buyButton.OnGUIButtonEnter += shopButtonEnter;
            buyButton.OnGUIButtonLeave += shopButtonLeave;
            guiHandlerTowers.Add(buyButton);

            guiHandlerTowersUpgrade = new GUIHandler();
            guiHandlerTowersUpgrade.AttachToContext(RC);

            speedUpgradeText             = new GUIButton("Shot Frequency: 1", _guiCabinBlack, 900, 400, 180, 50);
            speedUpgradeText.ButtonColor = new float4(0.0f, 0.38f, 0.69f, 1.0f);
            speedUpgradeText.TextColor   = new float4(1.0f, 1.0f, 1.0f, 1.0f);
            speedUpgradeText.BorderWidth = 0;
            guiHandlerTowersUpgrade.Add(speedUpgradeText);

            speedUpgradeButton = new GUIButton("Speed Upgrade", _guiCabinBlack, 1080, 400, 180, 50);
            //mapButtons[i].OnGUIButtonDown += mapOnGUIButtonDown;
            speedUpgradeButton.OnGUIButtonEnter += shopButtonEnter;
            speedUpgradeButton.OnGUIButtonLeave += shopButtonLeave;
            guiHandlerTowersUpgrade.Add(speedUpgradeButton);

            rangeUpgradeText             = new GUIButton("Range: 1", _guiCabinBlack, 900, 475, 180, 50);
            rangeUpgradeText.ButtonColor = new float4(0.0f, 0.38f, 0.69f, 1.0f);
            rangeUpgradeText.TextColor   = new float4(1.0f, 1.0f, 1.0f, 1.0f);
            rangeUpgradeText.BorderWidth = 0;
            guiHandlerTowersUpgrade.Add(rangeUpgradeText);

            rangeUpgradeButton = new GUIButton("Range Upgrade", _guiCabinBlack, 1080, 475, 180, 50);
            //mapButtons[i].OnGUIButtonDown += mapOnGUIButtonDown;
            rangeUpgradeButton.OnGUIButtonEnter += shopButtonEnter;
            rangeUpgradeButton.OnGUIButtonLeave += shopButtonLeave;
            guiHandlerTowersUpgrade.Add(rangeUpgradeButton);

            damageUpgradeText             = new GUIButton("Damage: 1", _guiCabinBlack, 900, 550, 180, 50);
            damageUpgradeText.ButtonColor = new float4(0.0f, 0.38f, 0.69f, 1.0f);
            damageUpgradeText.TextColor   = new float4(1.0f, 1.0f, 1.0f, 1.0f);
            damageUpgradeText.BorderWidth = 0;
            guiHandlerTowersUpgrade.Add(damageUpgradeText);

            damageUpgradeButton = new GUIButton("Damage Upgrade", _guiCabinBlack, 1080, 550, 180, 50);
            //mapButtons[i].OnGUIButtonDown += mapOnGUIButtonDown;
            damageUpgradeButton.OnGUIButtonEnter += shopButtonEnter;
            damageUpgradeButton.OnGUIButtonLeave += shopButtonLeave;
            guiHandlerTowersUpgrade.Add(damageUpgradeButton);
#endif

            // Set the clear color for the backbuffer
            RC.ClearColor = new float4(1, 1, 1, 1);
        }
Example #33
0
        private void OnInitialize()
        {
            guiColor          = new GUIColorField("", GUIOption.FixedWidth(100));
            guiSlider2DTex    = new GUITexture(null, GUIOption.FixedHeight(ColorBoxHeight), GUIOption.FixedWidth(ColorBoxWidth));
            guiSliderVertTex  = new GUITexture(null, GUIOption.FixedHeight(SliderSideHeight), GUIOption.FixedWidth(SliderSideWidth));
            guiSliderRHorzTex = new GUITexture(null, GUIOption.FixedHeight(SliderIndividualHeight));
            guiSliderGHorzTex = new GUITexture(null, GUIOption.FixedHeight(SliderIndividualHeight));
            guiSliderBHorzTex = new GUITexture(null, GUIOption.FixedHeight(SliderIndividualHeight));
            guiSliderAHorzTex = new GUITexture(null, GUIOption.FixedHeight(SliderIndividualHeight));

            guiColorBoxBtn  = new GUIButton(colorBoxMode.ToString());
            guiColorModeBtn = new GUIButton(sliderMode.ToString());

            guiSliderVert     = new GUISliderV(EditorStylesInternal.ColorSliderVert);
            guiSliderRHorz    = new GUISliderH(EditorStylesInternal.ColorSliderHorz);
            guiSliderGHorz    = new GUISliderH(EditorStylesInternal.ColorSliderHorz);
            guiSliderBHorz    = new GUISliderH(EditorStylesInternal.ColorSliderHorz);
            guiSliderAHorz    = new GUISliderH(EditorStylesInternal.ColorSliderHorz);
            guiSlider2DHandle = new GUITexture(null, EditorStylesInternal.ColorSlider2DHandle);

            guiLabelR = new GUILabel(new LocEdString("R"));
            guiLabelG = new GUILabel(new LocEdString("G"));
            guiLabelB = new GUILabel(new LocEdString("B"));
            guiLabelA = new GUILabel(new LocEdString("A"));

            guiInputR = new GUIIntField();
            guiInputG = new GUIIntField();
            guiInputB = new GUIIntField();
            guiInputA = new GUIIntField();

            guiOK     = new GUIButton(new LocEdString("OK"));
            guiCancel = new GUIButton(new LocEdString("Cancel"));

            guiColorBoxBtn.OnClick  += OnColorBoxModeChanged;
            guiColorModeBtn.OnClick += OnSliderModeChanged;

            guiSliderVert.OnChanged  += OnSliderVertChanged;
            guiSliderRHorz.OnChanged += OnSliderRHorzChanged;
            guiSliderGHorz.OnChanged += OnSliderGHorzChanged;
            guiSliderBHorz.OnChanged += OnSliderBHorzChanged;
            guiSliderAHorz.OnChanged += OnSliderAHorzChanged;

            guiInputR.OnChanged += OnInputRChanged;
            guiInputG.OnChanged += OnInputGChanged;
            guiInputB.OnChanged += OnInputBChanged;
            guiInputA.OnChanged += OnInputAChanged;

            guiOK.OnClick     += OnOK;
            guiCancel.OnClick += OnCancel;

            GUIPanel  mainPanel = GUI.AddPanel(0);
            GUILayout v0        = mainPanel.AddLayoutY();

            v0.AddSpace(5);

            GUILayout h0 = v0.AddLayoutX();

            h0.AddSpace(10);
            h0.AddElement(guiColor);
            h0.AddFlexibleSpace();
            h0.AddElement(guiColorBoxBtn);
            h0.AddElement(guiColorModeBtn);
            h0.AddSpace(10);

            v0.AddSpace(10);

            GUILayout h1 = v0.AddLayoutX();

            h1.AddSpace(10);
            h1.AddElement(guiSlider2DTex);
            h1.AddFlexibleSpace();
            h1.AddElement(guiSliderVertTex);
            h1.AddSpace(10);

            v0.AddSpace(10);

            GUILayout h2 = v0.AddLayoutX();

            h2.AddSpace(10);
            h2.AddElement(guiLabelR);
            h2.AddFlexibleSpace();
            h2.AddElement(guiSliderRHorzTex);
            h2.AddFlexibleSpace();
            h2.AddElement(guiInputR);
            h2.AddSpace(10);

            v0.AddSpace(5);

            GUILayout h3 = v0.AddLayoutX();

            h3.AddSpace(10);
            h3.AddElement(guiLabelG);
            h3.AddFlexibleSpace();
            h3.AddElement(guiSliderGHorzTex);
            h3.AddFlexibleSpace();
            h3.AddElement(guiInputG);
            h3.AddSpace(10);

            v0.AddSpace(5);

            GUILayout h4 = v0.AddLayoutX();

            h4.AddSpace(10);
            h4.AddElement(guiLabelB);
            h4.AddFlexibleSpace();
            h4.AddElement(guiSliderBHorzTex);
            h4.AddFlexibleSpace();
            h4.AddElement(guiInputB);
            h4.AddSpace(10);

            v0.AddSpace(5);

            GUILayout h5 = v0.AddLayoutX();

            h5.AddSpace(10);
            h5.AddElement(guiLabelA);
            h5.AddFlexibleSpace();
            h5.AddElement(guiSliderAHorzTex);
            h5.AddFlexibleSpace();
            h5.AddElement(guiInputA);
            h5.AddSpace(10);

            v0.AddSpace(10);

            GUILayout h6 = v0.AddLayoutX();

            h6.AddFlexibleSpace();
            h6.AddElement(guiOK);
            h6.AddSpace(10);
            h6.AddElement(guiCancel);
            h6.AddFlexibleSpace();

            v0.AddSpace(5);

            GUIPanel overlay = GUI.AddPanel(-1);

            overlay.SetWidth(Width);
            overlay.SetHeight(Height);

            overlay.AddElement(guiSliderVert);
            overlay.AddElement(guiSliderRHorz);
            overlay.AddElement(guiSliderGHorz);
            overlay.AddElement(guiSliderBHorz);
            overlay.AddElement(guiSliderAHorz);
            overlay.AddElement(guiSlider2DHandle);

            colorBox   = new ColorSlider2D(guiSlider2DTex, guiSlider2DHandle, ColorBoxWidth, ColorBoxHeight);
            sideSlider = new ColorSlider1DVert(guiSliderVertTex, guiSliderVert, SliderSideWidth, SliderSideHeight);

            sliderR = new ColorSlider1DHorz(guiSliderRHorzTex, guiSliderRHorz, SliderIndividualWidth, SliderIndividualHeight);
            sliderG = new ColorSlider1DHorz(guiSliderGHorzTex, guiSliderGHorz, SliderIndividualWidth, SliderIndividualHeight);
            sliderB = new ColorSlider1DHorz(guiSliderBHorzTex, guiSliderBHorz, SliderIndividualWidth, SliderIndividualHeight);
            sliderA = new ColorSlider1DHorz(guiSliderAHorzTex, guiSliderAHorz, SliderIndividualWidth, SliderIndividualHeight);

            colorBox.OnValueChanged += OnColorBoxValueChanged;

            Color startA = new Color(0, 0, 0, 1);
            Color stepA  = new Color(1, 1, 1, 0);

            sliderA.UpdateTexture(startA, stepA, false);
            guiInputA.SetRange(0, 255);
            guiInputA.Value        = 255;
            guiSliderAHorz.Percent = 1.0f;

            guiColor.Value = SelectedColor;
            UpdateInputBoxValues();
            Update2DSliderValues();
            Update1DSliderValues();
            UpdateSliderMode();
            Update2DSliderTextures();
            Update1DSliderTextures();
        }
Example #34
0
        /// <summary>
        /// Refreshes the contents of the content area. Must be called at least once after construction.
        /// </summary>
        /// <param name="viewType">Determines how to display the resource tiles.</param>
        /// <param name="entriesToDisplay">Project library entries to display.</param>
        public void Refresh(ProjectViewType viewType, LibraryEntry[] entriesToDisplay)
        {
            if (mainPanel != null)
            {
                mainPanel.Destroy();
            }

            entries = new LibraryGUIEntry[entriesToDisplay.Length];
            entryLookup.Clear();

            mainPanel = parent.Layout.AddPanel();

            GUIPanel contentPanel = mainPanel.AddPanel(1);

            overlay       = mainPanel.AddPanel(0);
            underlay      = mainPanel.AddPanel(2);
            renameOverlay = mainPanel.AddPanel(-1);

            main = contentPanel.AddLayoutY();

            if (viewType == ProjectViewType.List16)
            {
                tileSize       = 16;
                gridLayout     = false;
                elementsPerRow = 1;
            }
            else
            {
                switch (viewType)
                {
                case ProjectViewType.Grid64:
                    tileSize = 64;
                    break;

                case ProjectViewType.Grid48:
                    tileSize = 48;
                    break;

                case ProjectViewType.Grid32:
                    tileSize = 32;
                    break;
                }

                gridLayout = true;

                Rect2I scrollBounds   = parent.Bounds;
                int    availableWidth = scrollBounds.width;

                int elemSize = tileSize + GRID_ENTRY_SPACING;
                elementsPerRow = (availableWidth - GRID_ENTRY_SPACING * 2) / elemSize;
                elementsPerRow = Math.Max(elementsPerRow, 1);

                int numRows      = MathEx.CeilToInt(entriesToDisplay.Length / (float)elementsPerRow);
                int neededHeight = numRows * (elemSize);

                bool requiresScrollbar = neededHeight > scrollBounds.height;
                if (requiresScrollbar)
                {
                    availableWidth -= parent.ScrollBarWidth;
                    elementsPerRow  = (availableWidth - GRID_ENTRY_SPACING * 2) / elemSize;
                }

                if (elementsPerRow > 0)
                {
                    labelWidth = (availableWidth - (elementsPerRow + 1) * MIN_HORZ_SPACING) / elementsPerRow;
                }
                else
                {
                    labelWidth = 0;
                }
            }

            if (viewType == ProjectViewType.List16)
            {
                for (int i = 0; i < entriesToDisplay.Length; i++)
                {
                    LibraryGUIEntry guiEntry = new LibraryGUIEntry(this, main, entriesToDisplay[i], i, labelWidth);
                    entries[i] = guiEntry;
                    entryLookup[guiEntry.path] = guiEntry;

                    if (i != entriesToDisplay.Length - 1)
                    {
                        main.AddSpace(LIST_ENTRY_SPACING);
                    }
                }

                main.AddFlexibleSpace();
            }
            else
            {
                main.AddSpace(GRID_ENTRY_SPACING / 2);
                GUILayoutX rowLayout = main.AddLayoutX();
                main.AddSpace(GRID_ENTRY_SPACING);
                rowLayout.AddFlexibleSpace();

                int elemsInRow = 0;

                for (int i = 0; i < entriesToDisplay.Length; i++)
                {
                    if (elemsInRow == elementsPerRow && elemsInRow > 0)
                    {
                        rowLayout = main.AddLayoutX();
                        main.AddSpace(GRID_ENTRY_SPACING);

                        rowLayout.AddFlexibleSpace();
                        elemsInRow = 0;
                    }

                    LibraryGUIEntry guiEntry = new LibraryGUIEntry(this, rowLayout, entriesToDisplay[i], i, labelWidth);
                    entries[i] = guiEntry;
                    entryLookup[guiEntry.path] = guiEntry;

                    rowLayout.AddFlexibleSpace();

                    elemsInRow++;
                }

                int extraElements = elementsPerRow - elemsInRow;
                for (int i = 0; i < extraElements; i++)
                {
                    rowLayout.AddSpace(labelWidth);
                    rowLayout.AddFlexibleSpace();
                }

                main.AddFlexibleSpace();
            }

            for (int i = 0; i < entries.Length; i++)
            {
                LibraryGUIEntry guiEntry = entries[i];
                guiEntry.Initialize();
            }
        }