private bool DrawRowHeader()
        {
            bool changed = false;

            EditorGUILayout.BeginVertical();
            changed |= EditorGUILayoutUtil.ObjectField <UITableCell>(ref table.defaultPrefab, true, W_Option, H_Option);
            EditorGUILayout.LabelField("Align", EditorStyles.boldLabel, H_Option);
            EditorGUILayout.LabelField("Size", EditorStyles.boldLabel, H_Option);
            EditorGUILayout.LabelField("Index", EditorStyles.boldLabel, H_Option);
            int row = table.isVertical? table.GetMaxPerLine(): table.rowCount;

            table.InitArray();
            for (int r = 0; r < row; r++)
            {
                EditorGUILayout.BeginHorizontal();
                changed |= EditorGUILayoutUtil.ObjectField <UITableCell>(ref table.rowPrefab[r], true, GUILayout.Width(WIDTH - 20), H_Option);
                changed |= EditorGUILayoutUtil.Popup <UITableLayout.VAlign>(ref table.valigns[r], EnumUtil.Values <UITableLayout.VAlign>(), GUILayout.Width(40), H_Option);
                changed |= EditorGUILayoutUtil.IntField(null, ref table.rowHeight[r], GUILayout.Width(WIDTH - 30), H_Option);
                EditorGUILayout.LabelField((r + 1).ToString(), EditorStyles.boldLabel, GUILayout.Width(20), H_Option);
                EditorGUILayout.EndHorizontal();
            }
            if (!IsHorizontal())
            {
                EditorGUILayout.LabelField("", W_Option);
                EditorGUILayout.LabelField("", W_Option);
                EditorGUILayout.LabelField("", W_Option);
            }
            EditorGUILayout.EndVertical();
            if (changed)
            {
                table.InitArray();
            }
            return(changed);
        }
 public override void OnInspectorGUI()
 {
     GUI.enabled = true;
     EditorGUILayout.BeginHorizontal();
     if (EditorGUILayoutUtil.ObjectField <UIRoot>("Root", ref root, true))
     {
         Classify(ref root);
     }
     if (GUILayout.Button("Refresh", GUILayout.ExpandWidth(false)) || root == null)
     {
         Classify(ref root);
     }
     GUI.enabled = root != null;
     if (GUILayout.Button("Rename", GUILayout.ExpandWidth(false)))
     {
         Rename();
     }
     GUI.enabled = true;
     EditorGUILayout.EndHorizontal();
     scroll = EditorGUILayout.BeginScrollView(scroll);
     VisualizeGroup();
     EditorGUILayoutUtil.DrawSeparator();
     VisualizeDups();
     EditorGUILayout.EndScrollView();
 }
 public void OnInspectorGUI()
 {
     if (EditorGUILayoutUtil.ObjectField <GameObject>("Empty Obj", ref grid.emptyObj, true))
     {
         EditorUtil.SetDirty(grid.emptyObj);
     }
     OnGridGUI();
 }
        private bool DrawColumn()
        {
            bool changed     = false;
            int  columnSize  = table.isHorizontal? table.GetMaxPerLine(): table.columnCount;
            int  contentSize = table.columnCount;

            for (int c = 0; c < columnSize; c++)
            {
                EditorGUILayout.BeginVertical();
                changed |= EditorGUILayoutUtil.ObjectField <UITableCell>(ref table.columnPrefab[c], true, GUILayout.ExpandWidth(false), H_Option);
                changed |= EditorGUILayoutUtil.Popup <UITableLayout.HAlign>(ref table.haligns[c], EnumUtil.Values <UITableLayout.HAlign>(), GUILayout.Width(WIDTH - 20), H_Option);
                changed |= EditorGUILayoutUtil.IntField(null, ref table.columnWidth[c], GUILayout.Width(WIDTH - 20), H_Option);
                EditorGUILayout.LabelField(c.ToString(), EditorStyles.boldLabel, W_Option, H_Option);
                int row = table.rowCount;
                if (c < contentSize)
                {
                    for (int r = 0; r < row; r++)
                    {
                        changed |= DrawCell(r, c);
                    }

                    // Draw Column +/- buttons
                    EditorGUILayout.BeginHorizontal();
                    if (GUILayout.Button(new GUIContent("A", "Add Selected"), GUILayout.ExpandWidth(false), H_Option))
                    {
                        AddSelected(c, UITableLayout.Arrangement.Vertical);
                        changed = true;
                    }
                    if (GUILayout.Button("+", GUILayout.ExpandWidth(false), H_Option))
                    {
                        #pragma warning disable 0618
                        table.AddColumn(c + 1, new UITableCell[table.rowCount]);
                        #pragma warning restore 0618
                        changed = true;
                    }
                    GUI.enabled = c >= table.columnHeader;
                    if (GUILayout.Button("-", GUILayout.ExpandWidth(false), H_Option))
                    {
                        if (EditorUtility.DisplayDialog("Confirm", "Delete column " + (c + 1), "OK", "Cancel"))
                        {
                            #pragma warning disable 0618
                            table.RemoveColumn(c);
                            #pragma warning restore 0618
                            table.Reposition();
                            changed = true;
                        }
                    }
                    GUI.enabled = true;
                    EditorGUILayout.EndHorizontal();
                }

                EditorGUILayout.EndVertical();
            }
            return(changed);
        }
        private bool DrawCell(int r, int c)
        {
            bool        changed = false;
            UITableCell cell    = table.GetCell(r, c);

            if (EditorGUILayoutUtil.ObjectField <UITableCell>(ref cell, true, W_Option, GUILayout.Height(HEIGHT - 1)))
            {
                table.SetCell(r, c, cell);
                changed = true;
            }
            return(changed);
        }
        public override void OnHeaderGUI()
        {
            bool changed = EditorGUILayoutUtil.ObjectField <GameObject>("Scene Root", ref sceneRoot, true);

            changed |= EditorGUILayoutUtil.ObjectField <UIAtlas>("From", ref atlasFrom, false);
            changed |= EditorGUILayoutUtil.ObjectField <UIAtlas>("To", ref atlasTo, false);
            NGUIEditorTools.DrawSeparator();

            if (changed && atlasFrom != null && atlasTo != null)
            {
                duplicateSprites = FindDuplicate(atlasFrom, atlasTo);
            }
        }
        private bool DrawAddColumn()
        {
            showAddColumn = EditorGUILayout.Foldout(showAddColumn, "Add Column");
            if (showAddColumn)
            {
                if (!grid.isHorizontal)
                {
                    EditorGUILayout.HelpBox("Currently only Horizontal grid type is supported", MessageType.Warning);
                    return(false);
                }
                EditorGUILayoutUtil.ObjectField <UILabel>("Title Label(Prefab)", ref titleLabelPrefab, true, GUILayout.ExpandWidth(false));
                if (EditorGUILayoutUtil.PopupNullable <GridStyle>(null, ref currentStyle, gridStyles))
                {
                    selectedColumn = null;
                    return(true);
                }
                if (GUILayout.Button("Apply"))
                {
                    grid.totalWidth = currentStyle.width;
                    Vector2 minSize = grid.cellMinSize;
                    minSize.y        = currentStyle.rowHeight;
                    grid.cellMinSize = minSize;
                }
                if (currentStyle != null)
                {
                    EditorGUILayoutUtil.PopupNullable <ColumnWidth>(null, ref selectedColumn, currentStyle.columnWidth);
                    GUI.enabled = titleLabelPrefab != null && selectedColumn != null;
                    if (GUILayout.Button("Add"))
                    {
                        int lastCol = GetLastColumn();

                        for (int r = 1, max = grid.rowHeader; r < max; r++)
                        {
                            UITableCell cell = null;
                            #pragma warning disable 0618
                            grid.Insert((lastCol + 1) * r - 1, cell);
                            #pragma warning restore 0618
                        }
                        grid.maxPerLine = Math.Max(lastCol + 1, grid.maxPerLine);
                        grid.InitArray();
                        grid.columnWidth[lastCol] = selectedColumn.width;
                        grid.SetCell(grid.rowHeader - 1, lastCol, CreateLabel(selectedColumn.name, lastCol + 1));
                        return(true);
                    }
                }
            }
            return(false);
        }
 public override void OnHeaderGUI()
 {
     EditorGUILayoutUtil.ObjectField <GameObject>("Scene Root", ref sceneRoot, true);
     GUI.enabled = sceneRoot != null;
     ComponentSelector.Draw("Select", NGUISettings.atlas, OnSelectAtlas, true);
     EditorGUILayoutUtil.TextField("Filter", ref filter);
     if (EditorGUILayoutUtil.Toggle("Expand", ref expand))
     {
         foreach (string s in spriteMap.Keys)
         {
             foldMap[s] = expand;
         }
     }
     GUI.enabled = true;
     NGUIEditorTools.DrawSeparator();
 }
Example #9
0
 public override void OnHeaderGUI()
 {
     EditorGUILayoutUtil.ObjectField <LexiconRegistry>("Lexicon Registry", ref lexReg, false);
     if (lexReg == null)
     {
         return;
     }
     EditorGUILayoutUtil.PopupEnum <SystemLanguage>("Mother language", ref motherLang);
     EditorGUILayoutUtil.PopupEnum <SystemLanguage>("Language", ref lang);
     fold = EditorGUILayout.Foldout(fold, "Translate All");
     if (fold)
     {
         if (GUILayout.Button("Convert all Scene and prefab") && EditorUtility.DisplayDialog("Confirm", "Convert All?", "OK", "Cancel"))
         {
             Lexicon.SetMotherLanguage(motherLang);
             Lexicon.SetLanguage(lang);
             TranslateLanguage();
         }
     }
     EditorGUILayoutUtil.Toggle("Lock", ref locked);
     if (EditorGUILayoutUtil.Toggle("Visible Only", ref visibleOnly))
     {
         roots = null;
     }
     EditorGUILayout.BeginHorizontal();
     if (GUILayout.Button("Reload Table", GUILayout.Height(30)))
     {
         ReloadTable();
         ApplyTableToText();
     }
     if (GUILayout.Button("Apply table to text", GUILayout.Height(30)))
     {
         ApplyTableToText();
     }
     if (GUILayout.Button("Revert", GUILayout.Height(30)))
     {
         Clear();
     }
     EditorGUILayout.EndHorizontal();
     DrawFindLexiconGUI();
 }
Example #10
0
        public override void OnHeaderGUI()
        {
            Validate();
            EditorGUILayout.BeginHorizontal();
            if (EditorGUILayoutUtil.ObjectField <GameObject>("Root", ref root, true))
            {
                Refresh();
            }
            GUI.enabled = root != null;
            if (GUILayout.Button("Refresh", GUILayout.ExpandWidth(false)))
            {
                Refresh();
            }
            GUI.enabled = true;
            EditorGUILayout.EndHorizontal();
            UIPanel[] panels = root != null?root.GetComponentsInChildren <UIPanel>(true) : new UIPanel[0];

            EditorGUILayout.BeginHorizontal();
            if (EditorGUILayoutUtil.PopupNullable("Panel", ref panelSel, panels, ObjToString.DefaultToString))
            {
                Refresh();
                if (panelSel != null)
                {
                    EditorGUIUtility.PingObject(panelSel);
                    Selection.activeGameObject = panelSel.gameObject;
                }
            }
            EditorGUILayoutUtil.Toggle("Show Active Only", ref showActiveOnly);
            EditorGUILayout.EndHorizontal();
            INGUIAtlas[] atlases = GetAtlases(widgets);
            INGUIFont[]  fonts   = GetFonts(widgets);
            if (EditorGUILayoutUtil.PopupNullable("Select Atlas", ref atlasSel, atlases, ObjToString.DefaultToString))
            {
                if (atlasSel != null)
                {
                    fontSel = null;
                }
            }
            if (EditorGUILayoutUtil.PopupNullable("Select Font", ref fontSel, fonts, ObjToString.DefaultToString))
            {
                if (fontSel != null)
                {
                    atlasSel = null;
                }
            }
            EditorGUILayout.BeginHorizontal();
            int index = Array.FindIndex(widgets, w => w.gameObject == Selection.activeGameObject);

            GUI.enabled = index >= 0;
            if (GUI.enabled)
            {
                if (GUILayout.Button("+1 over selection"))
                {
                    for (int i = 0; i <= index; ++i)
                    {
                        widgets[i].depth = widgets[i].depth + 1;
                        EditorUtil.SetDirty(widgets[i]);
                    }
                }
                if (GUILayout.Button("-1 under selection"))
                {
                    for (int i = index; i < widgets.Length; ++i)
                    {
                        widgets[i].depth = widgets[i].depth - 1;
                        EditorUtil.SetDirty(widgets[i]);
                    }
                }
                // TODOM key handling
                var e = Event.current;
                if (e.type == EventType.KeyUp)
                {
                    if (e.keyCode == KeyCode.UpArrow)
                    {
                        index--;
                        if (index >= 0)
                        {
                            Select(widgets[index]);
                        }
                    }
                    else if (e.keyCode == KeyCode.DownArrow)
                    {
                        index++;
                        if (index < widgets.Length)
                        {
                            Select(widgets[index]);
                        }
                    }
                }
            }
            GUI.enabled = true;
            EditorGUILayout.EndHorizontal();
        }
        private bool DrawTest()
        {
            showTest = EditorGUILayout.Foldout(showTest, "Test");
            bool changed = false;

            if (showTest)
            {
                EditorGUI.indentLevel += 2;
                EditorGUILayoutUtil.ObjectField <UIFont>("Font", ref testFont, true);
                int row = grid.rowCount;
                int col = grid.columnCount;
                if (EditorGUILayoutUtil.IntField("Font Size", ref fontSize, GUILayout.ExpandWidth(false)))
                {
                    for (int r = 0; r < row; r++)
                    {
                        for (int c = 0; c < col; c++)
                        {
                            UILabel label = grid.GetCell(r, c).GetComponent <UILabel>();
                            if (label != null)
                            {
                                label.transform.localScale = new Vector3(fontSize, fontSize, 1);
                            }
                        }
                    }
                }
                if (EditorGUILayoutUtil.ColorField("Font Color", ref fontColor, GUILayout.ExpandWidth(false)))
                {
                    for (int r = grid.rowHeader; r < row; r++)
                    {
                        for (int c = grid.columnHeader; c < col; c++)
                        {
                            UILabel label = grid.GetCell(r, c).GetComponent <UILabel>();
                            if (label != null)
                            {
                                label.color = fontColor;
                                label.MarkAsChanged();
                            }
                        }
                    }
                }
                Array.Resize(ref testStrings, grid.maxPerLine);
                for (int i = 0; i < grid.maxPerLine; i++)
                {
                    EditorGUILayoutUtil.TextField(i.ToString(), ref testStrings[i], GUILayout.ExpandWidth(false));
                }
                GUI.enabled = testFont != null;
                if (GUILayout.Button("Fill Data"))
                {
                    for (int r = grid.rowHeader; r < row; r++)
                    {
                        for (int c = grid.columnHeader; c < col; c++)
                        {
                            UITableCell cell = grid.GetCell(r, c);
                            if (cell == null)
                            {
                                UILabel label = NGUITools.AddWidget <UILabel>(grid.gameObject);
                                label.bitmapFont = testFont;
                                label.name       = "__TEST__";
                                label.SetText(testStrings[grid.isHorizontal?c:r]);
                                label.transform.localScale = new Vector3(fontSize, fontSize, 1);
                                label.color = fontColor;
                                label.MarkAsChanged();
                                UILabelCell lc = label.gameObject.AddComponent <UILabelCell>();
                                lc.label = label;
                                grid.SetCell(r, c, lc);
                            }
                        }
                    }
                    changed = true;
                }
                GUI.enabled            = true;
                EditorGUI.indentLevel -= 2;
            }
            return(changed);
        }
Example #12
0
        public override void OnInspectorGUI()
        {
            if (EditorUI.DrawHeader("Sprite -> Texture"))
            {
                EditorUI.BeginContents();
                EditorGUILayout.BeginHorizontal();
                EditorGUILayoutUtil.ObjectField <Object>("Folder", ref texFolder, false);
                if (GUILayout.Button("Sprite -> Texture") && EditorUtility.DisplayDialog("Warning", "BackUp?", "OK", "Cancel"))
                {
                    ConvertToTexture(texFolder);
                }
                EditorGUILayout.EndHorizontal();
                var drawer = new ListDrawer <UITexture>(texList, new ObjListItemDrawer <UITexture>());
                drawer.Draw();
                EditorUI.EndContents();
            }
            if (EditorUI.DrawHeader("Texture -> Sprite"))
            {
                EditorUI.BeginContents();
                EditorGUILayout.BeginHorizontal();
                ComponentSelector.Draw <NGUIAtlas>("Atlas", atlasToAdd, OnSelectAtlas, true, GUILayout.MinWidth(80f));
                if (GUILayout.Button("Add Selected"))
                {
                    foreach (Object o in Selection.objects)
                    {
                        if (o is GameObject)
                        {
                            OnSelectAtlas((o as GameObject).GetComponent <NGUIAtlas>());
                        }
                    }
                }
                EditorGUILayout.EndHorizontal();
                EditorGUILayoutUtil.TextField("Search sprite", ref searchSpriteName);
                if (!searchSpriteName.IsEmpty())
                {
                    List <NGUIAtlas> filtered = new List <NGUIAtlas>();
                    foreach (NGUIAtlas a in atlasRefs)
                    {
                        if (a.GetSprite(searchSpriteName) != null)
                        {
                            filtered.Add(a);
                        }
                    }
                    var drawer = new ListDrawer <NGUIAtlas>(filtered, new ObjListItemDrawer <NGUIAtlas>());
                    drawer.Draw();
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayoutUtil.Popup("Change to", ref changeAtlas, filtered);
                    if (GUILayout.Button("Apply"))
                    {
                        EditorTraversal.ForEachAsset <GameObject>(FileType.Prefab, (path, prefab) => {
                            ChangeAtlas(prefab, filtered, changeAtlas);
                        });
                        EditorTraversal.ForEachScene(s => {
                            foreach (var r in s.GetRootGameObjects())
                            {
                                ChangeAtlas(r.gameObject, filtered, changeAtlas);
                            }
                            return(null);
                        });
                    }
                    EditorGUILayout.EndHorizontal();
                    var spriteDrawer = new ListDrawer <UISprite>(spriteList, new ObjListItemDrawer <UISprite>());
                    spriteDrawer.Draw();
                }
                else
                {
                    var drawer = new ListDrawer <NGUIAtlas>(atlasRefs, new ObjListItemDrawer <NGUIAtlas>());
                    if (drawer.Draw())
                    {
                        SaveAtlasRefs();
                    }
                }
                if (!dupSprites.IsEmpty())
                {
                    if (EditorUI.DrawHeader("Duplicate sprites"))
                    {
                        EditorUI.BeginContents();
                        float cellWidth = 200f;
                        float width     = GetWidth();
                        int   column    = Mathf.Max((int)(width / cellWidth), 1);
                        int   i         = 0;
                        foreach (string d in dupSprites)
                        {
                            if (i == 0)
                            {
                                EditorGUILayout.BeginHorizontal();
                            }
                            if (GUILayout.Button(d, GUILayout.Width(200)))
                            {
                                searchSpriteName = d;
                            }
                            i = i + 1;
                            if (i == column)
                            {
                                EditorGUILayout.EndHorizontal();
                                i = 0;
                            }
                        }
                        if (i != 0)
                        {
                            EditorGUILayout.EndHorizontal();
                        }
                        EditorUI.EndContents();
                    }
                }
                EditorGUILayout.BeginHorizontal();
                EditorGUILayoutUtil.ObjectField("Target", ref targetObj, true);
                GUI.enabled = targetObj != null;
                if (GUILayout.Button("Convert to Sprite") && EditorUtility.DisplayDialog("Warning", "BackUp?", "OK"))
                {
                    ConvertToSprite();
                }
                if (GUILayout.Button("Set TexSetter"))
                {
                    foreach (UITexture tex in targetObj.GetComponentsInChildren <UITexture>(true))
                    {
                        TexSetterInspector.SetIfCdn(tex);
                    }
                }
                GUI.enabled = true;
                EditorGUILayout.EndHorizontal();
                // collect atlas
                GUI.enabled = targetObj != null;
                if (EditorUI.DrawHeader("Member Atlases"))
                {
                    EditorUI.BeginContents();
                    if (targetObj != null)
                    {
                        MultiMap <NGUIAtlas, UISprite> collect = new MultiMap <NGUIAtlas, UISprite>();
                        foreach (UISprite s in targetObj.GetComponentsInChildren <UISprite>(true))
                        {
                            collect.Add(s.atlas as NGUIAtlas, s);
                        }
                        foreach (KeyValuePair <NGUIAtlas, List <UISprite> > pair in collect)
                        {
                            if (EditorGUILayout.Foldout(folding.Contains(pair.Key), pair.Key.name()))
                            {
                                folding.Add(pair.Key);
                                EditorGUI.indentLevel++;
                                foreach (UISprite s in pair.Value)
                                {
                                    EditorGUILayout.ObjectField(s.gameObject, typeof(GameObject), true);
                                }
                                EditorGUI.indentLevel--;
                            }
                            else
                            {
                                folding.Remove(pair.Key);
                            }
                        }
                    }
                    EditorUI.EndContents();
                }
                if (EditorUI.DrawHeader("Orphan Texture"))
                {
                    EditorUI.BeginContents();
                    if (targetObj != null)
                    {
                        foreach (UITexture tex in targetObj.GetComponentsInChildren <UITexture>(true))
                        {
                            if (tex.GetComponent <TexLoader>() == null)
                            {
                                EditorGUILayout.BeginHorizontal();
                                EditorGUILayout.ObjectField(tex.gameObject, typeof(GameObject), true);
                                EditorGUILayout.ObjectField(tex.mainTexture, typeof(Texture), false);
                                EditorGUILayout.EndHorizontal();
                            }
                        }
                    }
                    EditorUI.EndContents();
                }
                GUI.enabled = true;

                EditorUI.EndContents();
            }
            if (EditorUI.DrawHeader("Find All Sprites"))
            {
                EditorUI.BeginContents();
                EditorGUILayout.BeginHorizontal();
                ComponentSelector.Draw <NGUIAtlas>("Atlas", atlas4Sprite, OnSelectAtlasForSprite, true, GUILayout.MinWidth(80f));
                if (GUILayout.Button("Find"))
                {
                    var list = Resources.FindObjectsOfTypeAll <UISprite>().ToList(i => i as UISprite);
                    s4a.Clear();
                    foreach (var s in list)
                    {
                        if (s.atlas == atlas4Sprite)
                        {
                            s4a.Add(s);
                        }
                    }
                }
                EditorGUILayout.EndHorizontal();
                EditorUI.EndContents();
            }
            GUI.enabled = true;
        }