Beispiel #1
0
        public static void FolderField(EditorWindowFolder folder, LanguageTemplate lang, Action <EditorWindowFolder> OnDrop, Action AllIn, Action RemoveSelf, Action <EditorWindowFolder> DropSubFolder, Action <EditorWindowFolder> OnSelect)
        {
            var defaultColor = GUI.backgroundColor;

            if (folder.Selected)
            {
                GUI.backgroundColor = Color.gray;
            }

            var e = Event.current;

            Rect itemRect;

            using (var scope = new EditorGUILayout.VerticalScope(GUI.skin.box))
            {
                using (new EditorGUILayout.HorizontalScope())
                {
                    if (folder.ParentFolder is null)
                    {
                        if (folder.NameEdittable)
                        {
                            folder.Name = EditorGUILayout.TextField(folder.Name);

                            if ((GUILayout.Button(lang.ok, GUILayout.Width(50f)) ||
                                 e.Equals(Event.KeyboardEvent("return"))) &&
                                !string.IsNullOrEmpty(folder.Name))
                            {
                                folder.NameEdittable = false;
                                GUI.changed          = true;
                            }
                        }
                        else
                        {
                            EditorGUILayout.LabelField(folder.Name, EditorStyles.boldLabel);
                        }
                    }
                    else
                    {
                        folder.Foldout = EditorGUILayout.Foldout(folder.Foldout, folder.Name);

                        if (GUILayout.Button(lang.drop))
                        {
                            DropSubFolder(folder);
                        }
                    }
                }

                using (var itemsScope = new EditorGUILayout.VerticalScope())
                {
                    itemRect = itemsScope.rect;

                    if (folder.Foldout || folder.ParentFolder is null)
                    {
                        foreach (var editorWindowfolder in folder.EditorWindowFolderList.ToArray())
                        {
                            FolderField(editorWindowfolder, lang, OnDrop, AllIn, RemoveSelf, DropSubFolder, OnSelect);
                        }

                        foreach (var editorWindowInfo in folder.EditorWindowList.ToList())
                        {
                            FileField(editorWindowInfo, lang);
                        }
                    }
                }

                if (!folder.EditorWindowFolderList.Any() && !folder.EditorWindowList.Any())
                {
                    using (new EditorGUI.DisabledScope(folder.NameEdittable))
                    {
                        if (GUILayout.Button(lang.allIn))
                        {
                            AllIn();
                        }
                    }

                    if (GUILayout.Button(lang.remove))
                    {
                        RemoveSelf();
                    }
                }

                GUI.backgroundColor = defaultColor;

                if (folder.ParentFolder is null)
                {
                    GUILayout.FlexibleSpace();
                }

                if (scope.rect.Contains(e.mousePosition) && !itemRect.Contains(e.mousePosition))
                {
                    if (e.type == EventType.MouseDown)
                    {
                        GUI.changed = true;
                        OnSelect(folder);
                        Highlighter.Stop();
                    }
                    else if (e.type == EventType.MouseUp)
                    {
                        GUI.changed = true;
                        OnDrop(folder);
                        Highlighter.Stop();
                        GUIUtility.ExitGUI();
                    }
                    else if (e.type == EventType.MouseDrag)
                    {
                        GUI.changed = true;
                        // TODO: 本当はFolder全体が囲まれるようにしたい
                        // Highlighter.HighlightIdentifierはうまくいかない
                        Highlighter.Highlight(nameof(MenuSimplifier), folder.Name);
                        GUIUtility.ExitGUI();
                    }
                }
            }
        }
Beispiel #2
0
        private void OnGUI()
        {
            if (editorWindowInfoList != null)
            {
                EditorGUILayout.Space();

                using (new EditorGUILayout.HorizontalScope())
                {
                    GUILayout.FlexibleSpace();

                    layoutType = (LayoutType)EditorGUILayout.EnumPopup(layoutType);

                    using (var check = new EditorGUI.ChangeCheckScope())
                    {
                        lang = (Language)EditorGUILayout.EnumPopup(lang);

                        if (check.changed)
                        {
                            LoadLanguage(lang);
                        }
                    }

                    if (GUILayout.Button(langLibrary.allResetToDefault))
                    {
                        ReplaceMenuItem(editorWindowInfoList, true);
                    }
                }

                EditorGUILayout.Space();

                if (layoutType == LayoutType.Simple)
                {
                    SimpleLayout();
                }
                else
                {
                    AdvancedLayout();
                }

                EditorGUILayout.Space();

                if (GUILayout.Button(langLibrary.addFolder))
                {
                    folderListScrollPos.x = folderRect.width;

                    var newFolder = new EditorWindowFolder()
                    {
                        NameEdittable = true
                    };
                    folderList.Add(newFolder);
                }

                if (layoutType == LayoutType.Advanced)
                {
                    using (var check = new EditorGUI.ChangeCheckScope())
                    {
                        if (GatoGUILayout.DropArea(langLibrary.dropSubFolder, langLibrary, EditorGUIUtility.singleLineHeight * 4f))
                        {
                            if (!(selectedItem is null) &&
                                !(selectedItem.ParentFolder is null) &&
                                selectedItem is EditorWindowFolder selectedFolder)
                            {
                                DropSubFolder(selectedFolder);
                                GUI.changed = true;
                            }
                        }

                        if (check.changed)
                        {
                            Repaint();
                        }
                    }
                }

                // ファイルだけの移動はできなくてもよいので一時削除
                //EditorGUILayout.Space();

                //EditorGUILayout.LabelField("Unallocated", EditorStyles.boldLabel);

                //using (var scroll = new EditorGUILayout.ScrollViewScope(unallocatedListScrollPos))
                //{
                //    unallocatedListScrollPos = scroll.scrollPosition;

                //    foreach (var editorWindowInfo in editorWindowInfoList)
                //    {
                //        if (!string.IsNullOrEmpty(editorWindowInfo.DestMenuItemPath)) continue;

                //        using (var check = new EditorGUI.ChangeCheckScope())
                //        {
                //            editorWindowInfo.Selected = GatoGUILayout.ToggleLabelArea(
                //                                            editorWindowInfo.Name,
                //                                            editorWindowInfo.Selected,
                //                                            Color.white, Color.grey);

                //            if (check.changed) Repaint();
                //        }
                //    }
                //}

                EditorGUILayout.Space();

                using (new EditorGUI.DisabledScope(!editorWindowInfoList.Any(x => x.HasChanged)))
                {
                    if (GUILayout.Button(langLibrary.showChanged))
                    {
                        foreach (var file in editorWindowInfoList.Where(x => x.HasChanged))
                        {
                            file.ParentFolder.ShowChildren();
                        }
                    }

                    if (GUILayout.Button(langLibrary.apply))
                    {
                        ReplaceMenuItem(editorWindowInfoList);
                    }

                    EditorGUILayout.Space();

                    if (GUILayout.Button(langLibrary.allRevert))
                    {
                        RevertAllMenuItem();
                    }
                }

                // マウスドラッグが終わったのですべて選択解除
                if (Event.current.type == EventType.MouseUp &&
                    !(selectedItem is null))
                {
                    selectedItem.Selected = false;
                    selectedItem          = null;
                }
            }
        }
Beispiel #3
0
        public static void FolderRowField(EditorWindowFolder folder, LanguageTemplate lang, Action <EditorWindowFolder> DropSubFolder, Action AllIn, Action RemoveSelf)
        {
            var e = Event.current;

            using (new EditorGUILayout.VerticalScope(GUI.skin.box))
            {
                using (new EditorGUILayout.HorizontalScope())
                {
                    if (folder.NameEdittable)
                    {
                        folder.Name = EditorGUILayout.TextField(folder.Name);

                        if ((GUILayout.Button(lang.ok, GUILayout.Width(50f)) ||
                             e.Equals(Event.KeyboardEvent("return"))) &&
                            !string.IsNullOrEmpty(folder.Name))
                        {
                            folder.NameEdittable = false;
                            GUI.changed          = true;
                        }
                    }
                    else
                    {
                        folder.Foldout = EditorGUILayout.Foldout(folder.Foldout, folder.Name);
                    }

                    if (!folder.EditorWindowFolderList.Any() && !folder.EditorWindowList.Any())
                    {
                        using (new EditorGUI.DisabledScope(folder.NameEdittable))
                        {
                            if (GUILayout.Button(lang.allIn))
                            {
                                AllIn();
                            }
                        }

                        if (GUILayout.Button(lang.remove))
                        {
                            RemoveSelf();
                        }
                    }

                    if (!(folder.ParentFolder is null))
                    {
                        if (GUILayout.Button(lang.drop, GUILayout.Width(80f)))
                        {
                            DropSubFolder(folder);
                        }
                    }
                }

                if (folder.Foldout)
                {
                    using (new EditorGUI.IndentLevelScope())
                    {
                        foreach (var subFolder in folder.EditorWindowFolderList.ToArray())
                        {
                            FolderRowField(subFolder, lang, DropSubFolder, AllIn, RemoveSelf);
                        }

                        foreach (var info in folder.EditorWindowList.ToArray())
                        {
                            FileField(info, lang);
                        }
                    }
                }
            }
        }