/// <summary>
        /// Creates a dictionary GUI field containing GUI elements required for displaying the provided dictionary.
        /// </summary>
        /// <typeparam name="RowType">Type of rows that are used to handle GUI for individual dictionary elements.</typeparam>
        /// <param name="title">Label to display on the list GUI title.</param>
        /// <param name="dictionary">Object containing the data. Can be null.</param>
        /// <param name="layout">Layout to which to append the list GUI elements to.</param>
        /// <param name="depth">Determines at which depth to render the background. Useful when you have multiple
        ///                     nested containers whose backgrounds are overlaping. Also determines background style,
        ///                     depths divisible by two will use an alternate style.</param>
        /// <returns>New instance of dictionary GUI field.</returns>
        public static GUIDictionaryField <Key, Value, RowType> Create(LocString title, Dictionary <Key, Value> dictionary,
                                                                      GUILayout layout, int depth = 0)

        {
            GUIDictionaryField <Key, Value, RowType> guiDictionary = new GUIDictionaryField <Key, Value, RowType>(
                title, dictionary, layout, depth);

            guiDictionary.BuildGUI();
            return(guiDictionary);
        }
Esempio n. 2
0
        /// <summary>
        /// Recreates all the GUI elements used by this inspector.
        /// </summary>
        private void BuildGUI()
        {
            Layout.Clear();
            strings.Clear();

            StringTable stringTable = InspectedObject as StringTable;

            if (stringTable == null)
            {
                return;
            }

            string[] identifiers = stringTable.Identifiers;
            foreach (var identifier in identifiers)
            {
                strings[identifier] = stringTable.GetString(identifier);
            }

            languageField = new GUIEnumField(typeof(Language));
            languageField.OnSelectionChanged += x =>
            {
                StringTables.ActiveLanguage = (Language)x;
                BuildGUI();
                Refresh();
            };

            Layout.AddElement(languageField);

            valuesField = GUIDictionaryField <string, string, StringTableEntry> .Create(
                new LocEdString("Strings"), strings, Layout);

            valuesField.IsExpanded = Persistent.GetBool("valuesField_Expanded");
            valuesField.OnExpand  += x => Persistent.SetBool("valuesField_Expanded", x);

            valuesField.OnChanged += x =>
            {
                if (x != null)
                {
                    foreach (var KVP in x)
                    {
                        if (stringTable.Contains(KVP.Key))
                        {
                            string oldValue = stringTable.GetString(KVP.Key);
                            if (oldValue != KVP.Value)
                            {
                                stringTable.SetString(KVP.Key, KVP.Value);
                            }
                        }
                        else
                        {
                            stringTable.SetString(KVP.Key, KVP.Value);
                        }
                    }

                    string[] oldIdentifiers = stringTable.Identifiers;
                    foreach (var identifier in oldIdentifiers)
                    {
                        if (!x.ContainsKey(identifier))
                        {
                            stringTable.RemoveString(identifier);
                        }
                    }

                    strings = x;
                }
                else
                {
                    foreach (var KVP in strings)
                    {
                        stringTable.RemoveString(KVP.Key);
                    }

                    strings.Clear();
                }

                EditorApplication.SetDirty(stringTable);
            };

            valuesField.OnValueChanged += x =>
            {
                stringTable.SetString(x, strings[x]);
                EditorApplication.SetDirty(stringTable);
            };

            valuesField.OnValueRemoved += x =>
            {
                stringTable.RemoveString(x);
                EditorApplication.SetDirty(stringTable);
            };

            Layout.AddSpace(10);
        }
Esempio n. 3
0
        /// <summary>
        /// Recreates all the GUI elements used by this inspector.
        /// </summary>
        private void BuildGUI()
        {
            Layout.Clear();
            styles.Clear();

            GUISkin guiSkin = InspectedObject as GUISkin;

            if (guiSkin == null)
            {
                return;
            }

            string[] styleNames = guiSkin.StyleNames;
            foreach (var styleName in styleNames)
            {
                styles[styleName] = guiSkin.GetStyle(styleName);
            }

            valuesField = GUIDictionaryField <string, GUIElementStyle, GUIElementStyleEntry> .Create
                              (new LocEdString("Styles"), styles, Layout);

            valuesField.IsExpanded = Persistent.GetBool("valuesField_Expanded");
            valuesField.OnExpand  += x => Persistent.SetBool("valuesField_Expanded", x);

            valuesField.OnChanged += x =>
            {
                if (x != null)
                {
                    foreach (var KVP in x)
                    {
                        if (guiSkin.HasStyle(KVP.Key))
                        {
                            GUIElementStyle oldValue = guiSkin.GetStyle(KVP.Key);
                            if (oldValue != KVP.Value)
                            {
                                guiSkin.SetStyle(KVP.Key, KVP.Value);
                            }
                        }
                        else
                        {
                            guiSkin.SetStyle(KVP.Key, KVP.Value);
                        }
                    }

                    string[] oldStyleNames = guiSkin.StyleNames;
                    foreach (var styleName in oldStyleNames)
                    {
                        if (!x.ContainsKey(styleName))
                        {
                            guiSkin.RemoveStyle(styleName);
                        }
                    }

                    styles = x;
                }
                else
                {
                    foreach (var KVP in styles)
                    {
                        guiSkin.RemoveStyle(KVP.Key);
                    }

                    styles.Clear();
                }

                EditorApplication.SetDirty(guiSkin);
            };

            valuesField.OnValueChanged += x =>
            {
                guiSkin.SetStyle(x, styles[x]);
                EditorApplication.SetDirty(guiSkin);
            };

            valuesField.OnValueRemoved += x =>
            {
                guiSkin.RemoveStyle(x);
                EditorApplication.SetDirty(guiSkin);
            };

            Layout.AddSpace(10);
        }