void OnGUI()
    {
        scrollPosition0 = GUILayout.BeginScrollView(
            scrollPosition0);
        GUILayout.BeginHorizontal();
        GUILayout.Label("Languages Editor", EditorStyles.boldLabel);
        if (languageListObj != null)
        {
            if (GUILayout.Button("Show Language List"))
            {
                EditorUtility.FocusProjectWindow();
                Selection.activeObject = languageListObj;
            }
        }
        if (GUILayout.Button("Open Language List"))
        {
            OpenItemList();
        }
        GUILayout.EndHorizontal();

        if (languageListObj == null)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Space(10);
            if (GUILayout.Button("Open Existing Item List", GUILayout.ExpandWidth(false)))
            {
                OpenItemList();
            }
            GUILayout.EndHorizontal();
        }

        GUILayout.Space(20);

        if (languageListObj != null)
        {
            GUILayout.BeginHorizontal();

            GUILayout.Space(10);

            if (GUILayout.Button("Prev", GUILayout.ExpandWidth(false)))
            {
                confirmDelete  = false;
                confirmDeleteE = false;
                if (viewIndex > 1)
                {
                    viewIndex--;
                }
            }
            GUILayout.Space(5);
            if (GUILayout.Button("Next", GUILayout.ExpandWidth(false)))
            {
                confirmDelete  = false;
                confirmDeleteE = false;
                if (viewIndex < languageListObj.languageList.Count)
                {
                    viewIndex++;
                }
            }

            GUILayout.Space(60);

            if (GUILayout.Button("Add Language", GUILayout.ExpandWidth(false)))
            {
                AddItem();
                confirmDelete  = false;
                confirmDeleteE = false;
            }
            if (confirmDelete)
            {
                if (GUILayout.Button("Confirm delete", GUILayout.ExpandWidth(false)))
                {
                    confirmDelete  = false;
                    confirmDeleteE = false;
                    DeleteItem(viewIndex - 1);
                }
            }
            else
            {
                if (GUILayout.Button("Delete Language", GUILayout.ExpandWidth(false)))
                {
                    confirmDelete  = true;
                    confirmDeleteE = false;
                }
            }
            GUILayout.EndHorizontal();

            if (languageListObj.languageList == null)
            {
                Debug.Log("Gone wrong");
            }
            if (languageListObj.languageList.Count > 0)
            {
                GUILayout.BeginHorizontal();
                viewIndex = Mathf.Clamp(EditorGUILayout.IntField("Current Item", viewIndex, GUILayout.ExpandWidth(false)), 1, languageListObj.languageList.Count);
                EditorGUILayout.LabelField("of   " + languageListObj.languageList.Count.ToString() + "  items", "", GUILayout.ExpandWidth(false));
                GUILayout.EndHorizontal();
                GUILayout.Space(10);

                languageListObj.languageList[viewIndex - 1].itemName = EditorGUILayout.TextField("Language Name", languageListObj.languageList[viewIndex - 1].itemName as string);

                GUILayout.Space(20);
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Inspect", GUILayout.ExpandWidth(false)))
                {
                    mode           = 1;
                    confirmDeleteE = false;
                    confirmDelete  = false;
                }
                if (GUILayout.Button("Edit", GUILayout.ExpandWidth(false)))
                {
                    mode           = 0;
                    confirmDeleteE = false;
                    confirmDelete  = false;
                }
                GUILayout.EndHorizontal();

                // Sync Languages
                //for (int i = 1; i < languageListObj.languageList.Count; ++i)
                //{
                //    foreach (var entity in languageListObj.languageList[0].words)
                //    {
                //        try
                //        {
                //            languageListObj.languageList[i].words.Add(entity.Key, "");
                //        }
                //        catch { }
                //    }
                //}

                if (mode == 0)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Change entities:", EditorStyles.boldLabel);
                    if (GUILayout.Button("+", GUILayout.ExpandWidth(false)) && new_key != null)
                    {
                        confirmDelete  = false;
                        confirmDeleteE = false;
                        for (int i = 0; i < languageListObj.languageList.Count; ++i)
                        {
                            try
                            {
                                languageListObj.languageList[i].words.Add(new_key, new_value);
                            }
                            catch
                            {
                                languageListObj.languageList[viewIndex - 1].words[new_key] = new_value;
                            }
                        }
                    }
                    if (confirmDeleteE)
                    {
                        GUILayout.EndHorizontal();
                        GUILayout.BeginHorizontal();
                        if (GUILayout.Button(
                                "Yes, I want to delete this key from ALL languages permanently",
                                GUILayout.ExpandWidth(true)))
                        {
                            confirmDeleteE = false;
                            confirmDelete  = false;
                            for (int i = 0; i < languageListObj.languageList.Count; ++i)
                            {
                                try
                                {
                                    languageListObj.languageList[i].words.Remove(new_key);
                                }
                                catch { }
                            }
                            new_key   = "";
                            new_value = "";
                            autocompleteSearchField.searchString = "";
                        }
                    }
                    else
                    {
                        if (GUILayout.Button("x", GUILayout.ExpandWidth(false)))
                        {
                            confirmDeleteE = true;
                            confirmDelete  = false;
                        }
                    }
                    GUILayout.EndHorizontal();

                    GUILayout.Space(10);

                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Key:");
                    new_key = EditorGUILayout.TextArea(new_key as string, GUILayout.Width(200));
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Value:");
                    new_value = EditorGUILayout.TextArea(new_value as string, GUILayout.Width(200));
                    GUILayout.EndHorizontal();

                    GUILayout.Label("Search key");
                    autocompleteSearchField.OnGUI();

                    GUILayout.Space(20);
                }
                else if (mode == 1)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Language dictionary", EditorStyles.boldLabel);
                    GUILayout.EndHorizontal();

                    GUILayout.Space(10);

                    scrollPosition = GUILayout.BeginScrollView(
                        scrollPosition);
                    if (languageListObj.languageList[viewIndex - 1].words.Count == 0)
                    {
                        GUILayout.Label("No words");
                    }
                    else
                    {
                        List <string> keys = new List <string>();
                        foreach (KeyValuePair <string, string> p in languageListObj.languageList[viewIndex - 1].words)
                        {
                            keys.Add(p.Key);
                        }

                        keys.Sort();
                        foreach (string key in keys)
                        {
                            string value = languageListObj.languageList[viewIndex - 1].words[key];
                            GUILayout.Label(string.Format("{0}: {1}", key, value));
                        }
                    }
                    GUILayout.EndScrollView();

                    GUILayout.Space(10);
                }
            }
            else
            {
                GUILayout.Label("This Language List is Empty.");
            }
        }

        if (GUI.changed)
        {
            EditorUtility.SetDirty(languageListObj);
        }
        GUILayout.EndScrollView();
    }
Beispiel #2
0
 void OnGUI()
 {
     GUILayout.Label("Search key");
     autocompleteSearchField.OnGUI();
 }