Example #1
0
        protected virtual void  OnGUI()
        {
            if (HQ.Settings == null)
            {
                GUILayout.Label(string.Format(LC.G("RequiringConfigurationFile"), NGSyncFoldersWindow.Title));
                if (GUILayout.Button(LC.G("ShowPreferencesWindow")) == true)
                {
                    Utility.ShowPreferencesWindowAt(Constants.PreferenceTitle);
                }
                return;
            }

            FreeLicenseOverlay.First(this, NGAssemblyInfo.Name + " Pro", NGSyncFoldersWindow.FreeAdContent);

            SyncFoldersSettings settings = HQ.Settings.Get <SyncFoldersSettings>();

            // Guarantee there is always one in the list.
            if (settings.syncProfiles.Count == 0)
            {
                settings.syncProfiles.Add(new Profile()
                {
                    name = "Profile 1"
                });
            }

            this.currentProfile = Mathf.Clamp(this.currentProfile, 0, settings.syncProfiles.Count - 1);
            this.profile        = settings.syncProfiles[this.currentProfile];

            Rect r = default(Rect);

            if (NGSyncFoldersWindow.cachePath == null)
            {
                NGSyncFoldersWindow.cachePath = Path.Combine(Application.persistentDataPath, Path.Combine(Constants.InternalPackageTitle, string.Format(NGSyncFoldersWindow.CachedHashedFile, this.currentProfile)));
            }

            this.slavesList.list  = this.profile.slaves;
            this.filtersList.list = this.profile.filters;

            r.width  = this.position.width;
            r.height = Constants.SingleLineHeight;
            GUI.Box(r, string.Empty, GeneralStyles.Toolbar);

            r.width = 20F;
            if (GUI.Button(r, "", GeneralStyles.ToolbarDropDown) == true)
            {
                GenericMenu menu = new GenericMenu();

                for (int i = 0; i < settings.syncProfiles.Count; i++)
                {
                    menu.AddItem(new GUIContent((i + 1) + " - " + settings.syncProfiles[i].name), i == this.currentProfile, this.SwitchProfile, i);
                }

                menu.AddSeparator("");
                menu.AddItem(new GUIContent(LC.G("Add")), false, this.AddProfile);
                menu.DropDown(r);

                GUI.FocusControl(null);
            }
            r.x += r.width + 4F;

            r.width = this.position.width - 20F - 100F - 4F;
            EditorGUI.BeginChangeCheck();
            r.y += 2F;
            string name = EditorGUI.TextField(r, this.profile.name, GeneralStyles.ToolbarTextField);

            if (EditorGUI.EndChangeCheck() == true)
            {
                Undo.RecordObject(settings, "Rename profile");
                this.profile.name = name;
                HQ.InvalidateSettings();
            }
            r.y -= 2F;
            r.x += r.width;

            r.width = 100F;
            EditorGUI.BeginDisabledGroup(settings.syncProfiles.Count <= 1);
            {
                if (GUI.Button(r, LC.G("Erase"), GeneralStyles.ToolbarButton) == true &&
                    ((Event.current.modifiers & Constants.ByPassPromptModifier) != 0 ||
                     EditorUtility.DisplayDialog(LC.G("NGSyncFolders_EraseSave"), string.Format(LC.G("NGSyncFolders_EraseSaveQuestion"), this.profile.name), LC.G("Yes"), LC.G("No")) == true))
                {
                    this.EraseProfile();
                    this.Focus();
                    return;
                }
            }
            EditorGUI.EndDisabledGroup();

            r.x     = 0F;
            r.y    += r.height + 5F;
            r.width = this.position.width;

            using (LabelWidthRestorer.Get(85F))
            {
                EditorGUI.BeginChangeCheck();
                string folderPath = NGEditorGUILayout.OpenFolderField(r, "Master Folder", this.profile.master.folderPath);
                if (EditorGUI.EndChangeCheck() == true)
                {
                    Undo.RecordObject(settings, "Alter master path");
                    this.profile.master.folderPath = folderPath;
                    HQ.InvalidateSettings();
                }
                r.y += r.height + NGSyncFoldersWindow.Spacing;

                EditorGUI.BeginChangeCheck();
                string relativePath = NGEditorGUILayout.OpenFolderField(r, "Relative Path", this.profile.relativePath, this.profile.master.folderPath, NGEditorGUILayout.FieldButtons.Open);
                if (EditorGUI.EndChangeCheck() == true)
                {
                    Undo.RecordObject(settings, "Alter relative path");
                    this.profile.relativePath = relativePath;
                    HQ.InvalidateSettings();
                }
                r.y += r.height + NGSyncFoldersWindow.Spacing;

                this.PreviewPath(r, this.profile.master.GetFullPath(this.profile.relativePath));
                r.y += r.height + NGSyncFoldersWindow.Spacing;

                r.height = this.slavesList.GetHeight();
                this.slavesList.DoList(r);

                if (this.showSlaves == false)
                {
                    r.y -= 16F;
                }

                r.y += r.height + NGSyncFoldersWindow.Spacing;
            }

            r.height = this.filtersList.GetHeight();
            this.filtersList.DoList(r);

            if (this.showFilters == false)
            {
                if (Event.current.type == EventType.Repaint)
                {
                    Rect r2 = r;
                    r2.y     += r2.height - 14F;
                    r2.height = 16F;
                    r2.width  = 16F;
                    EditorGUI.DrawRect(r2, EditorGUIUtility.isProSkin == true ? new Color(55F / 255F, 55F / 255F, 55F / 255F, 1F) : new Color(162F / 255F, 162F / 255F, 162F / 255F, 1F));
                }

                r.y -= 16F;
            }

            r.y += r.height + NGSyncFoldersWindow.Spacing;

            if (string.IsNullOrEmpty(this.cacheFileSize) == true)
            {
                this.UpdateCacheFileSize();
            }

            EditorGUI.BeginChangeCheck();
            r.width -= 200F;
            r.height = 20F;
            bool useCache = EditorGUI.Toggle(r, this.cacheFileSize, this.profile.useCache);

            if (EditorGUI.EndChangeCheck() == true)
            {
                Undo.RecordObject(settings, "Toggle use cache");
                this.profile.useCache = useCache;
                HQ.InvalidateSettings();
            }

            if (this.cacheFileSize != "Use Cache")
            {
                r.x += r.width;

                r.width = 100F;
                if (GUI.Button(r, "Open", "ButtonLeft") == true)
                {
                    EditorUtility.RevealInFinder(NGSyncFoldersWindow.cachePath);
                }
                r.x += r.width;
                if (GUI.Button(r, "Clear", "ButtonRight") == true)
                {
                    System.IO.File.Delete(NGSyncFoldersWindow.cachePath);
                    this.UpdateCacheFileSize();
                }
            }
            r.y += r.height + NGSyncFoldersWindow.Spacing;

            bool hasActiveSlaves = false;

            for (int i = 0; i < this.profile.slaves.Count; i++)
            {
                if (this.profile.slaves[i].active == true)
                {
                    hasActiveSlaves = true;
                    break;
                }
            }

            EditorGUI.BeginDisabledGroup(hasActiveSlaves == false);
            {
                using (BgColorContentRestorer.Get(GeneralStyles.HighlightActionButton))
                {
                    r.x      = 10F;
                    r.width  = 150F;
                    r.height = 32F;
                    if (GUI.Button(r, this.mode == ButtonMode.Scan ? "Scan" : "Scan & Watch", "Button" /*"ButtonLeft"*/) == true)
                    {
                        this.Scan();
                    }

                    //if (GUILayout.Button("☰", "ButtonRight", GUILayoutOptionPool.Height(32F), GUILayoutOptionPool.ExpandWidthFalse) == true)
                    //{
                    //	GenericMenu	menu = new GenericMenu();
                    //	menu.AddItem(new GUIContent("Scan"), this.mode == ButtonMode.Scan, () => this.mode = ButtonMode.Scan);
                    //	menu.AddItem(new GUIContent("Scan and Watch"), this.mode == ButtonMode.ScanAndWatch, () => this.mode = ButtonMode.ScanAndWatch);
                    //	menu.ShowAsContext();
                    //}
                }
            }
            EditorGUI.EndDisabledGroup();

            if (this.profile.master.IsScanned == true)
            {
                using (BgColorContentRestorer.Get(GeneralStyles.HighlightResultButton))
                {
                    r.x = this.position.width - r.width - 10F;
                    if (GUI.Button(r, "Sync All", "Button") == true)
                    {
                        this.SyncAll();
                    }
                    r.y += r.height + NGSyncFoldersWindow.Spacing;
                }
            }

            //if (this.mode == ButtonMode.ScanAndWatch)
            //	EditorGUILayout.HelpBox("Scan and Watch may induce huge freeze after a compilation when watching a lot of files. This mode is not recommended for programmers.", MessageType.Warning);

            if (this.profile.master.IsScanned == true)
            {
                r.x     = 0F;
                r.width = this.position.width;

                Rect bodyRect = r;
                bodyRect.height = this.position.height - r.y;

                Rect viewRect = new Rect {
                    height = this.profile.master.GetHeight()
                };

                for (int i = 0; i < this.profile.slaves.Count; i++)
                {
                    if (this.profile.slaves[i].active == true)
                    {
                        viewRect.height += this.profile.slaves[i].GetHeight(this.profile.master);
                    }
                }

                this.scrollPositionScan = GUI.BeginScrollView(bodyRect, this.scrollPositionScan, viewRect);
                {
                    r.y      = 0F;
                    r.height = this.profile.master.GetHeight();

                    if (viewRect.height > r.height)
                    {
                        r.width -= 15F;
                    }

                    if (r.yMax > this.scrollPositionScan.y)
                    {
                        this.profile.master.OnGUI(r, 0, this.scrollPositionScan.y, this.scrollPositionScan.y + bodyRect.height);
                    }

                    r.y += r.height;

                    for (int i = 0; i < this.profile.slaves.Count; i++)
                    {
                        if (this.profile.slaves[i].active == false)
                        {
                            continue;
                        }

                        r.height = this.profile.slaves[i].GetHeight(this.profile.master);

                        if (r.yMax > this.scrollPositionScan.y)
                        {
                            this.profile.slaves[i].OnGUI(r, i + 1, this.scrollPositionScan.y, this.scrollPositionScan.y + bodyRect.height, this.profile.master);
                        }

                        r.y += r.height;

                        if (r.y - this.scrollPositionScan.y > bodyRect.height)
                        {
                            break;
                        }
                    }
                }
                GUI.EndScrollView();
            }

            FreeLicenseOverlay.Last(NGAssemblyInfo.Name + " Pro");
        }
Example #2
0
        protected virtual void  OnGUI()
        {
            if (this.initialized == false)
            {
                // Prevent initialization message after entering play mode.
                if (Time.frameCount <= 2)
                {
                    return;
                }

                GUILayout.Label(string.Format(LC.G("RequiringConfigurationFile"), NGHubWindow.Title), GeneralStyles.CenterText, GUILayoutOptionPool.Height(this.height));

                if (this.dockedAsMenu == false)
                {
                    GUILayout.BeginHorizontal();
                    {
                        if (GUILayout.Button(LC.G("ShoWPreferencesWindow")) == true)
                        {
                            Utility.ShowPreferencesWindowAt(Constants.PreferenceTitle);
                        }

                        // Especially for NG Hub, we need to add a way to manually close the window when the dock mode is failing.
                        if (GUILayout.Button("X", GUILayoutOptionPool.Width(16F)) == true)
                        {
                            this.Close();
                        }
                    }
                    GUILayout.EndHorizontal();
                }

                return;
            }

            FreeLicenseOverlay.First(this, NGAssemblyInfo.Name + " Pro", NGHubWindow.FreeAdContent);

            if (Event.current.type == EventType.Repaint)
            {
                if (this.backgroundColor.a > 0F)
                {
                    EditorGUI.DrawRect(new Rect(0F, 0F, this.position.width, this.position.height), this.backgroundColor);
                }
                else
                {
                    EditorGUI.DrawRect(new Rect(0F, 0F, this.position.width, this.position.height), NGHubWindow.DockBackgroundColor);
                }
            }

            EditorGUILayout.BeginHorizontal(GUILayoutOptionPool.Height(this.height));
            {
                if (this.errorPopup.exception != null)
                {
                    if (this.dockedAsMenu == true)
                    {
                        Rect r = GUILayoutUtility.GetRect(0F, 0F, GUILayoutOptionPool.Width(115F), GUILayoutOptionPool.Height(this.height + 3F));
                        r.x += 1F;
                        r.y += 1F;
                        this.errorPopup.OnGUIRect(r);
                    }
                    else
                    {
                        this.errorPopup.OnGUILayout();
                    }
                }

                bool      isDragging  = this.HandleDrop();
                bool      overflow    = false;
                EventType catchedType = EventType.Used;

                if (this.components.Count == 0)
                {
                    if (isDragging == false)
                    {
                        Rect r = this.position;
                        r.x       = 1F;
                        r.y       = 1F;
                        r.width  -= 1F;
                        r.height -= 1F;

                        if (this.dockedAsMenu == true && Event.current.type == EventType.Repaint)
                        {
                            Utility.DrawRectDotted(r, this.position, Color.grey, .02F, 0F);
                        }

                        GUI.Label(r, "Right-click to add Component" + (this.dockedAsMenu == true && Application.platform == RuntimePlatform.OSXEditor? " (Dock mode is buggy under OSX)" : ""), GeneralStyles.CenterText);
                    }
                }
                else
                {
                    Rect miseryRect = default(Rect);
                    int  lastMinI   = this.extensionWindow != null ? this.extensionWindow.minI : 0;

                    if (this.dockedAsMenu == true &&
                        this.extensionWindow != null &&
                        this.maxWidth > 0F)
                    {
                        miseryRect = new Rect(this.maxWidth, 0F, this.position.width - this.maxWidth, this.height + 4F);
                        GUI.Label(miseryRect, GUIContent.none);

                        if (miseryRect.Contains(Event.current.mousePosition) == true)
                        {
                            GUIUtility.hotControl = 0;
                        }
                    }

                    for (int i = 0; i < this.components.Count; i++)
                    {
                        // Catch event from the cropped component.
                        if (this.dockedAsMenu == true &&
                            Event.current.type != EventType.Repaint &&
                            Event.current.type != EventType.Layout &&
                            this.extensionWindow != null)
                        {
                            if (this.extensionWindow.minI == i)
                            {
                                // Simulate context click, because MouseUp is used, therefore ContextClick is not sent.
                                if (Event.current.type == EventType.MouseUp &&
                                    Event.current.button == 1)
                                {
                                    catchedType = EventType.ContextClick;
                                }
                                else
                                {
                                    catchedType = Event.current.type;
                                }
                                Event.current.Use();
                            }
                        }

                        EditorGUILayout.BeginHorizontal();
                        {
                            try
                            {
                                this.components[i].OnGUI();
                            }
                            catch (Exception ex)
                            {
                                this.errorPopup.exception = ex;
                            }
                        }
                        EditorGUILayout.EndHorizontal();

                        if (this.dockedAsMenu == true && Event.current.type == EventType.Repaint)
                        {
                            Rect r = GUILayoutUtility.GetLastRect();

                            if (r.xMax >= this.position.width)
                            {
                                if (this.extensionWindow == null)
                                {
                                    this.extensionWindow = ScriptableObject.CreateInstance <NGHubExtensionWindow>();
                                    this.extensionWindow.Init(this);
                                    this.extensionWindow.ShowPopup();
                                    this.Repaint();
                                }

                                this.maxWidth             = r.xMin;
                                this.extensionWindow.minI = i;
                                overflow = true;
                                break;
                            }
                            else if (this.position.width - r.xMax <= 16F && i + 1 < this.components.Count)                             // Prevent drawing next component if the space is obviously too small.
                            {
                                if (this.extensionWindow == null)
                                {
                                    this.extensionWindow = ScriptableObject.CreateInstance <NGHubExtensionWindow>();
                                    this.extensionWindow.Init(this);
                                    this.extensionWindow.ShowPopup();
                                    this.Repaint();
                                }

                                this.maxWidth             = r.xMax;
                                this.extensionWindow.minI = i + 1;
                                overflow = true;
                                break;
                            }
                            else
                            {
                                this.maxWidth = 0F;
                            }
                        }
                    }

                    if (this.dockedAsMenu == true)
                    {
                        if (this.extensionWindow != null &&
                            this.maxWidth > 0F)
                        {
                            if (lastMinI != this.extensionWindow.minI)
                            {
                                this.Repaint();
                            }

                            // Hide the miserable trick...
                            if (Event.current.type == EventType.Repaint)
                            {
                                if (this.backgroundColor.a > 0F)
                                {
                                    EditorGUI.DrawRect(miseryRect, this.backgroundColor);
                                }
                                else
                                {
                                    EditorGUI.DrawRect(miseryRect, NGHubWindow.DockBackgroundColor);
                                }
                            }
                        }
                        else
                        {
                            Rect r = GUILayoutUtility.GetLastRect();

                            r.xMin  = r.xMax + 1F;
                            r.width = this.position.width - r.x;
                            r.yMin -= 3F;
                            r.yMax += 3F;

                            if (Event.current.type == EventType.Repaint)
                            {
                                if (this.backgroundColor.a > 0F)
                                {
                                    EditorGUI.DrawRect(r, this.backgroundColor);
                                }
                                else
                                {
                                    EditorGUI.DrawRect(r, NGHubWindow.DockBackgroundColor);
                                }
                            }
                        }
                    }
                }

                if (this.dockedAsMenu == true &&
                    Event.current.type == EventType.Repaint &&
                    overflow == false &&
                    this.extensionWindow != null)
                {
                    this.extensionWindow.Close();
                    this.extensionWindow = null;
                    base.Repaint();
                }

                if (Event.current.type == EventType.ContextClick ||
                    catchedType == EventType.ContextClick)
                {
                    this.OpenContextMenu();
                }
            }

            GUILayout.FlexibleSpace();

            EditorGUILayout.EndHorizontal();

            FreeLicenseOverlay.Last(NGAssemblyInfo.Name + " Pro");
        }
Example #3
0
        protected virtual void  OnGUI()
        {
            FreeLicenseOverlay.First(this, NGAssemblyInfo.Name + " Pro", NGShaderFinderWindow.FreeAdContent);

            Rect r = this.position;

            r.x      = 0F;
            r.y      = 0F;
            r.height = NGShaderFinderWindow.SearchButtonHeight;

            EditorGUI.BeginDisabledGroup(this.isSearching);
            {
                r.height = Constants.SingleLineHeight;
                using (LabelWidthRestorer.Get(100F))
                {
                    r.width = this.position.width - NGShaderFinderWindow.FindButtonWidth - NGShaderFinderWindow.FindButtonLeftSpacing;
                    EditorGUI.BeginChangeCheck();
                    Shader newTarget = EditorGUI.ObjectField(r, "Find Shader", this.targetShader, typeof(Shader), false) as Shader;
                    if (EditorGUI.EndChangeCheck() == true)
                    {
                        this.targetShader = newTarget;
                    }
                }
                r.y += r.height + NGShaderFinderWindow.Spacing;

                r.width         = NGShaderFinderWindow.TargetReplaceLabelWidth;
                this.canReplace = GUI.Toggle(r, this.canReplace, "Replace With");
                r.x            += r.width;

                EditorGUI.BeginDisabledGroup(!this.canReplace);
                {
                    r.width            = this.position.width - r.x - NGShaderFinderWindow.SwitchShaderButtonWidth - NGShaderFinderWindow.FindButtonWidth - NGShaderFinderWindow.FindButtonLeftSpacing;
                    this.replaceShader = EditorGUI.ObjectField(r, this.replaceShader, typeof(Shader), false) as Shader;
                }
                EditorGUI.EndDisabledGroup();

                r.x    += r.width;
                r.width = NGShaderFinderWindow.SwitchShaderButtonWidth;
                if (GUI.Button(r, "⇅", GeneralStyles.BigFontToolbarButton) == true)
                {
                    Shader tmp = this.replaceShader;
                    this.replaceShader = this.targetShader;
                    this.targetShader  = tmp;
                }

                r.yMin -= r.height + NGShaderFinderWindow.Spacing;
                r.width = NGShaderFinderWindow.FindButtonWidth;
                r.x     = this.position.width - NGShaderFinderWindow.FindButtonWidth;

                EditorGUI.BeginDisabledGroup(this.targetShader == null || this.isSearching == true);
                {
                    using (BgColorContentRestorer.Get(GeneralStyles.HighlightActionButton))
                    {
                        if (GUI.Button(r, "Find") == true)
                        {
                            this.FindReferences();
                        }
                    }
                }
                EditorGUI.EndDisabledGroup();

                r.y += r.height + NGShaderFinderWindow.Spacing;
            }
            EditorGUI.EndDisabledGroup();

            if (this.canReplace == true)
            {
                EditorGUI.BeginDisabledGroup(this.isSearching == true || this.hasResult == false);
                {
                    using (BgColorContentRestorer.Get(GeneralStyles.HighlightActionButton))
                    {
                        r.x     = 0F;
                        r.width = this.position.width * .5F;
                        if (GUI.Button(r, "Replace") == true)
                        {
                            this.ReplaceReferences(true);
                        }
                        r.x += r.width;

                        if (GUI.Button(r, "Set all") == true)
                        {
                            this.ReplaceReferences(false);
                        }
                        r.y += r.height + NGShaderFinderWindow.Spacing + NGShaderFinderWindow.Spacing;
                    }
                }
                EditorGUI.EndDisabledGroup();
            }

            r.x     = 0F;
            r.width = this.position.width;

            if (this.hasResult == true)
            {
                r.height = Constants.SingleLineHeight;
                GUI.Box(r, string.Empty, GeneralStyles.Toolbar);
                GUI.Label(r, this.resultsHeaderLabel);

                using (BgColorContentRestorer.Get(GeneralStyles.HighlightResultButton))
                {
                    r.xMin = r.xMax - NGShaderFinderWindow.ClearButtonWidth;
                    if (GUI.Button(r, "Clear", GeneralStyles.ToolbarButton) == true)
                    {
                        this.ClearResults();
                    }
                }
                r.y += r.height + NGShaderFinderWindow.Spacing;

                r.x     = 0F;
                r.width = this.position.width;

                Rect bodyRect = r;
                bodyRect.height = this.position.height - r.y;

                Rect viewRect = new Rect(0F, 0F, 0F, (Constants.SingleLineHeight + NGShaderFinderWindow.Spacing) * this.results.Count - NGShaderFinderWindow.Spacing);

                this.scrollPosition = GUI.BeginScrollView(bodyRect, this.scrollPosition, viewRect);
                {
                    float w = r.width - (viewRect.height > bodyRect.height ? 16F : 0F);

                    r.y      = 0F;
                    r.height = Constants.SingleLineHeight;

                    for (int i = 0; i < this.results.Count; i++)
                    {
                        if (r.y + r.height + NGShaderFinderWindow.Spacing <= this.scrollPosition.y)
                        {
                            r.y += r.height + NGShaderFinderWindow.Spacing;
                            continue;
                        }

                        r.x     = 0F;
                        r.width = w - NGShaderFinderWindow.PingButtonWidth;

                        EditorGUI.BeginChangeCheck();
                        Shader o = EditorGUI.ObjectField(r, this.resultsName[i], this.results[i].shader, typeof(Shader), false) as Shader;
                        if (EditorGUI.EndChangeCheck() == true)
                        {
                            Undo.RecordObject(this.results[i], "Replace Material shader");
                            this.results[i].shader = o;
                            EditorUtility.SetDirty(this.results[i]);
                        }

                        r.x    += r.width;
                        r.width = NGShaderFinderWindow.PingButtonWidth;
                        NGEditorGUILayout.PingObject(r, LC.G("Ping"), this.results[i]);
                        r.y += r.height + NGShaderFinderWindow.Spacing;

                        if (r.y - this.scrollPosition.y > bodyRect.height)
                        {
                            break;
                        }
                    }
                }
                GUI.EndScrollView();
            }

            FreeLicenseOverlay.Last(NGAssemblyInfo.Name + " Pro");
        }
Example #4
0
        protected virtual void  OnGUI()
        {
            FreeLicenseOverlay.First(this, NGAssemblyInfo.Name + " Pro", NGRenamerWindow.FreeAdContent);

            float halfWidth = this.position.width * .5F - 25F;

            this.errorPopup.OnGUILayout();

            for (int i = 0; i < this.filters.Count; i++)
            {
                EditorGUI.BeginDisabledGroup(NGLicensesManager.Check(i < NGRenamerWindow.MaxRenamerFilters, NGAssemblyInfo.Name + " Pro") == false);
                this.filters[i].OnHeaderGUI();
                if (this.filters[i].open == true)
                {
                    try
                    {
                        this.filters[i].OnGUI();
                    }
                    catch (Exception ex)
                    {
                        this.errorPopup.exception = ex;
                    }
                }
                EditorGUI.EndDisabledGroup();
            }

            if (this.objects.Count > 0 || this.paths.Count > 0 || Selection.activeObject != null)
            {
                using (BgColorContentRestorer.Get(GeneralStyles.HighlightActionButton))
                {
                    if (GUILayout.Button("Replace All") == true)
                    {
                        this.ReplaceAll();
                    }
                }

                if (this.objects.Count > 0)
                {
                    EditorGUILayout.BeginHorizontal(GeneralStyles.Toolbar);
                    {
                        GUILayout.Label("Assets (" + this.objects.Count + ")", GeneralStyles.Title1);
                    }
                    EditorGUILayout.EndHorizontal();

                    this.assetsScrollPosition = EditorGUILayout.BeginScrollView(this.assetsScrollPosition, GUILayoutOptionPool.ExpandHeightTrue);
                    {
                        for (int i = 0; i < this.objects.Count; i++)
                        {
                            NGRenamerWindow.drawingIndex = i;

                            EditorGUILayout.BeginHorizontal();
                            {
                                Texture2D icon = Utility.GetIcon(this.objects[i].GetInstanceID());

                                Rect r = GUILayoutUtility.GetRect(16F, 16F);
                                GUI.DrawTexture(r, icon);
                                r.width += halfWidth - 32F;
                                if (GUI.Button(r, "", GUI.skin.label) == true)
                                {
                                    NGEditorGUILayout.PingObject(this.objects[i]);
                                    return;
                                }

                                this.DrawElement(Path.GetFileName(this.objects[i].name), halfWidth - 32F, (s) => this.RenameAsset(this.objects[i], s));

                                if (GUILayout.Button("X", GeneralStyles.ToolbarCloseButton) == true)
                                {
                                    this.objects.RemoveAt(i);
                                    return;
                                }
                            }
                            EditorGUILayout.EndHorizontal();
                        }
                    }
                    EditorGUILayout.EndScrollView();

                    GUILayout.Space(5F);
                }

                for (int i = 0; i < this.paths.Count; i++)
                {
                    EditorGUILayout.BeginHorizontal(GeneralStyles.Toolbar);
                    {
                        Rect r = GUILayoutUtility.GetRect(0F, 24F, GUILayoutOptionPool.ExpandWidthTrue);
                        GUI.Label(r, "Path " + this.paths[i].path + " (" + (this.paths[i].directories.Length + this.paths[i].files.Length) + ")", GeneralStyles.Title1);

                        Utility.content.text    = "↻";
                        Utility.content.tooltip = "Refresh folder's content";
                        if (GUILayout.Button(Utility.content, GeneralStyles.ToolbarAltButton, GUILayoutOptionPool.Width(20F)) == true)
                        {
                            try
                            {
                                this.paths[i].Update();
                            }
                            catch (Exception ex)
                            {
                                this.errorPopup.exception = ex;
                            }
                            return;
                        }
                        Utility.content.tooltip = string.Empty;

                        if (GUILayout.Button("X", GeneralStyles.ToolbarCloseButton, GUILayoutOptionPool.Width(20F)) == true)
                        {
                            this.paths.RemoveAt(i);
                            return;
                        }
                    }
                    EditorGUILayout.EndHorizontal();

                    try
                    {
                        this.paths[i].scrollPosition = EditorGUILayout.BeginScrollView(this.paths[i].scrollPosition, GUILayoutOptionPool.ExpandHeightTrue);
                        {
                            for (int j = 0; j < this.paths[i].directories.Length; j++)
                            {
                                NGRenamerWindow.drawingIndex = j;

                                this.DrawElement(Path.GetFileName(this.paths[i].directories[j]), halfWidth, (s) => {
                                    try
                                    {
                                        // To ensure different letter case will work.
                                        string tmp = Path.Combine(this.paths[i].path, Path.GetRandomFileName());
                                        Directory.Move(this.paths[i].absolutePathDirectories[j], tmp);
                                        Directory.Move(tmp, Path.Combine(this.paths[i].path, s));
                                        this.paths[i].directories[j] = s;
                                    }
                                    catch (Exception ex)
                                    {
                                        Debug.LogException(ex);
                                    }
                                });
                            }

                            for (int j = 0; j < this.paths[i].files.Length; j++)
                            {
                                NGRenamerWindow.drawingIndex = j;

                                this.DrawElement(Path.GetFileName(this.paths[i].files[j]), halfWidth, (s) => {
                                    try
                                    {
                                        File.Move(this.paths[i].absolutePathFiles[j], Path.Combine(this.paths[i].path, s));
                                        this.paths[i].files[j] = s;
                                    }
                                    catch (Exception ex)
                                    {
                                        Debug.LogException(ex);
                                    }
                                });
                            }
                        }
                        EditorGUILayout.EndScrollView();
                    }
                    catch (Exception ex)
                    {
                        this.paths.RemoveAt(i);
                        Debug.LogException(ex);
                    }

                    GUILayout.Space(5F);
                }

                if (Selection.objects.Length > 0)
                {
                    EditorGUILayout.BeginHorizontal(GeneralStyles.Toolbar);
                    {
                        GUILayout.Label("Selection", GeneralStyles.Title1);
                    }
                    EditorGUILayout.EndHorizontal();

                    this.selectionScrollPosition = EditorGUILayout.BeginScrollView(this.selectionScrollPosition, GUILayoutOptionPool.ExpandHeightTrue);
                    {
                        for (int i = 0; i < Selection.objects.Length; i++)
                        {
                            NGRenamerWindow.drawingIndex = i;

                            this.DrawElement(Selection.objects[i].name, halfWidth, (s) => this.RenameAsset(Selection.objects[i], s));
                        }
                    }
                    EditorGUILayout.EndScrollView();
                }

                using (BgColorContentRestorer.Get(GeneralStyles.HighlightActionButton))
                {
                    if (GUILayout.Button("Replace All") == true)
                    {
                        this.ReplaceAll();
                    }
                }

                GUILayout.FlexibleSpace();
            }
            else
            {
                Rect r = GUILayoutUtility.GetRect(this.position.width, 16F, GUILayoutOptionPool.ExpandHeightTrue);

                r.x      += 2F;
                r.y      += 2F;
                r.width  -= 4F;
                r.height -= 4F;

                if (Event.current.type == EventType.Repaint)
                {
                    Utility.DrawUnfillRect(r, Color.grey);
                }

                GUI.Label(r, "Select assets from Hierarchy or Project\n\nDrop any files or folders from\n" + (Application.platform == RuntimePlatform.WindowsEditor ? "Explorer, " : (Application.platform == RuntimePlatform.OSXEditor ? "Finder, " : "")) + "Hierarchy or Project", GeneralStyles.CenterText);
            }

            if (Event.current.type == EventType.DragUpdated)
            {
                if (DragAndDrop.objectReferences.Length > 0 || DragAndDrop.paths.Length > 0)
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Move;
                }
                else
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Rejected;
                }
            }
            else if (Event.current.type == EventType.DragPerform)
            {
                DragAndDrop.AcceptDrag();

                try
                {
                    if (DragAndDrop.objectReferences.Length > 0)
                    {
                        for (int i = 0; i < DragAndDrop.objectReferences.Length; i++)
                        {
                            Object obj = DragAndDrop.objectReferences[i];

                            if (typeof(Behaviour).IsAssignableFrom(obj.GetType()) == true)
                            {
                                obj = (obj as Behaviour).gameObject;
                            }

                            if (this.objects.Contains(obj) == false)
                            {
                                this.objects.Add(obj);
                            }
                        }
                    }
                    else if (DragAndDrop.paths.Length > 0)
                    {
                        for (int i = 0; i < DragAndDrop.paths.Length; i++)
                        {
                            string path = DragAndDrop.paths[i];
                            if (Directory.Exists(path) == false)
                            {
                                path = new DirectoryInfo(path).Parent.FullName;
                            }

                            if (string.IsNullOrEmpty(path) == false && this.paths.Exists((p) => p.path == path) == false)
                            {
                                this.paths.Add(new PathFiles(path));
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    this.errorPopup.exception = ex;
                }

                Event.current.Use();
            }
            else if (Event.current.type == EventType.Repaint && DragAndDrop.visualMode == DragAndDropVisualMode.Move)
            {
                Utility.DropZone(new Rect(0F, 0F, this.position.width, this.position.height), "Drop folder or asset to rename");
            }

            FreeLicenseOverlay.Last(NGAssemblyInfo.Name + " Pro");
        }
Example #5
0
        protected virtual void  OnGUI()
        {
            if (HQ.Settings == null)
            {
                GUILayout.Label(string.Format(LC.G("RequiringConfigurationFile"), NGFavWindow.Title));
                if (GUILayout.Button(LC.G("ShowPreferencesWindow")) == true)
                {
                    Utility.ShowPreferencesWindowAt(Constants.PreferenceTitle);
                }
                return;
            }

            FreeLicenseOverlay.First(this, NGAssemblyInfo.Name + " Pro", NGFavWindow.FreeAdContent);

            FavSettings settings = HQ.Settings.Get <FavSettings>();

            // Guarantee there is always one in the list.
            if (settings.favorites.Count == 0)
            {
                settings.favorites.Add(new Favorites()
                {
                    name = "default"
                });
            }

            this.currentSave = Mathf.Clamp(this.currentSave, 0, settings.favorites.Count - 1);

            Favorites fav = settings.favorites[this.currentSave];

            this.list.list = fav.favorites;

            EditorGUILayout.BeginHorizontal(GeneralStyles.Toolbar);
            {
                if (GUILayout.Button("", GeneralStyles.ToolbarDropDown, GUILayoutOptionPool.Width(20F)) == true)
                {
                    GenericMenu menu = new GenericMenu();

                    for (int i = 0; i < settings.favorites.Count; i++)
                    {
                        menu.AddItem(new GUIContent((i + 1) + " - " + settings.favorites[i].name), i == this.currentSave, this.SwitchFavorite, i);
                    }

                    menu.AddSeparator("");
                    menu.AddItem(new GUIContent(LC.G("Add")), false, this.AddFavorite);

                    Rect r = GUILayoutUtility.GetLastRect();
                    r.y += 16F;
                    menu.DropDown(r);
                    GUI.FocusControl(null);
                }

                EditorGUI.BeginChangeCheck();
                fav.name = EditorGUILayout.TextField(fav.name, GeneralStyles.ToolbarTextField, GUILayoutOptionPool.ExpandWidthTrue);
                if (EditorGUI.EndChangeCheck() == true)
                {
                    HQ.InvalidateSettings();
                }

                if (GUILayout.Button(LC.G("Clear"), GeneralStyles.ToolbarButton) == true && ((Event.current.modifiers & Constants.ByPassPromptModifier) != 0 || EditorUtility.DisplayDialog(LC.G("NGFav_ClearSave"), string.Format(LC.G("NGFav_ClearSaveQuestion"), fav.name), LC.G("Yes"), LC.G("No")) == true))
                {
                    Undo.RecordObject(settings, "Clear favorite");
                    fav.favorites.Clear();
                    HQ.InvalidateSettings();
                    this.Focus();
                    return;
                }

                EditorGUI.BeginDisabledGroup(settings.favorites.Count <= 1);
                if (GUILayout.Button(LC.G("Erase"), GeneralStyles.ToolbarButton) == true && ((Event.current.modifiers & Constants.ByPassPromptModifier) != 0 || EditorUtility.DisplayDialog(LC.G("NGFav_EraseSave"), string.Format(LC.G("NGFav_EraseSaveQuestion"), fav.name), LC.G("Yes"), LC.G("No")) == true))
                {
                    Undo.RecordObject(settings, "Erase favorite");
                    settings.favorites.RemoveAt(this.currentSave);
                    this.currentSave = Mathf.Clamp(this.currentSave, 0, settings.favorites.Count - 1);
                    this.list.list   = fav.favorites;
                    HQ.InvalidateSettings();
                    this.Focus();
                    return;
                }
                EditorGUI.EndDisabledGroup();

                Rect r2 = GUILayoutUtility.GetRect(40F, 16F);
                r2.x += 5F;
                this.backgroundColor = EditorGUI.ColorField(r2, this.backgroundColor);
            }
            EditorGUILayout.EndHorizontal();

            Rect overallDropZone = this.position;

            overallDropZone.x = 0F;
            overallDropZone.y = 0F;

            if (Event.current.type == EventType.Repaint && this.backgroundColor.a > 0F)
            {
                overallDropZone.y       = 16F;
                overallDropZone.height -= 16F;
                EditorGUI.DrawRect(overallDropZone, this.backgroundColor);
                overallDropZone.y = 0;
            }

            overallDropZone.height = 16F;

            // Drop zone to add a new selection.
            if (Event.current.type == EventType.Repaint &&
                DragAndDrop.objectReferences.Length > 0)
            {
                Utility.DropZone(overallDropZone, "Create new selection");
                this.Repaint();
            }
            else if (Event.current.type == EventType.DragUpdated &&
                     overallDropZone.Contains(Event.current.mousePosition) == true)
            {
                if (DragAndDrop.objectReferences.Length > 0)
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                }
                else
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Rejected;
                }
            }
            else if (Event.current.type == EventType.DragPerform &&
                     overallDropZone.Contains(Event.current.mousePosition) == true)
            {
                DragAndDrop.AcceptDrag();

                this.CreateSelection(DragAndDrop.objectReferences);

                DragAndDrop.PrepareStartDrag();
                Event.current.Use();
            }

            this.errorPopup.OnGUILayout();

            if (this.currentSave >= 0)
            {
                this.scrollPosition = EditorGUILayout.BeginScrollView(this.scrollPosition);
                {
                    try
                    {
                        while (this.horizontalScrolls.Count < fav.favorites.Count)
                        {
                            this.horizontalScrolls.Add(new HorizontalScrollbar(0F, 0F, this.position.width, 4F, 0F));
                        }

                        this.list.DoLayoutList();
                    }
                    catch (Exception ex)
                    {
                        this.errorPopup.exception = ex;
                        InternalNGDebug.LogFileException(ex);
                    }
                    finally
                    {
                        Utility.content.tooltip = string.Empty;
                    }
                }
                EditorGUILayout.EndScrollView();

                if (this.delayToDelete != -1)
                {
                    Undo.RecordObject(settings, "Delete favorite");
                    fav.favorites.RemoveAt(this.delayToDelete);
                    HQ.InvalidateSettings();
                    this.delayToDelete = -1;
                }
            }

            if (Event.current.type == EventType.MouseDown)
            {
                DragAndDrop.PrepareStartDrag();
                this.dragOriginPosition = Vector2.zero;
            }

            FreeLicenseOverlay.Last(NGAssemblyInfo.Name + " Pro");
        }