Exemple #1
0
        /// <summary>
        /// Loads from XML node.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <returns>The PList data constructed from the xml node.</returns>
        public static IPListElement LoadFromXmlNode(XmlNode node)
        {
            switch (node.Name.ToLower())
            {
                case "string":
                    return new PListString(node.InnerText);

                case "real":
                    return new PListReal(decimal.Parse(node.InnerText));

                case "integer":
                    return new PListInteger(int.Parse(node.InnerText));

                case "true":
                    return new PListBoolean(true);

                case "false":
                    return new PListBoolean(false);

                case "date":
                    return new PListDate(DateTime.Parse(node.InnerText));

                case "data":
                    return new PListData(Convert.FromBase64String(node.InnerText));

                case "array":
                    {
                        var array = new PListArray();

                        foreach (XmlNode child in node.ChildNodes)
                        {
                            array.Add(LoadFromXmlNode(child));
                        }

                        return array;
                    }

                case "dict":
                    {
                        var dict = new PListDictionary();

                        for (int i = 0; i < node.ChildNodes.Count; i += 2)
                        {
                            var keyNode = node.ChildNodes[i];
                            var key = keyNode.InnerText;

                            dict.Add(key, LoadFromXmlNode(node.ChildNodes[i + 1]));
                        }

                        return dict;
                    }

                default:
                    return null;
            }
        }
    void DrawEnumEntry(PListDictionary dic)
    {
        var enumDic = dic.DictionaryValue(VALUE_KEY);

        if (enumDic == null)
        {
            EditorGUILayout.LabelField("NO VALUES DEFINED", GUILayout.MaxWidth(600));
        }
        else
        {
            List <string> entries = new List <string>();

            foreach (var kvp in enumDic)
            {
                entries.Add(kvp.Key + " | " + kvp.Value);
            }

            int selectedIndex = dic.IntValue(DEFAULT_INDEX);
            EditorGUILayout.Popup(selectedIndex, entries.ToArray(), GUILayout.MaxWidth(600));
        }
    }
Exemple #3
0
        protected void UpdateDictionaryKey(PListDictionary dict, string oldKey, string newKey)
        {
            if (oldKey == newKey)
            {
                return;
            }

            if (string.IsNullOrEmpty(newKey))
            {
                return;
            }

            if (dict.ContainsKey(newKey))
            {
                return;
            }

            var element = dict[oldKey];

            dict.Remove(oldKey);
            dict.Add(newKey, element);
        }
Exemple #4
0
 internal abstract bool DrawEntry(PListDictionary dic);
 public CustomStringBuildSettingEntry(PListDictionary dic)
     : base(dic)
 {
 }
Exemple #6
0
 public void DrawPList(PListDictionary dic)
 {
     DrawHeader(dic.Count);
     DrawDictionaryCommon(dic);
     GUILayout.Space(4);
 }
Exemple #7
0
 protected abstract void DrawDictionaryCommon(PListDictionary dic);
Exemple #8
0
 public FileEntry(PListDictionary dic)
     : base(dic)
 {
 }
 public StringBuildSettingEntry(PListDictionary dic)
     : base(dic)
 {
     Value = dic.StringValue(VALUE_KEY);
 }
Exemple #10
0
 protected override void DrawDictionary(PListDictionary dic)
 {
     GUILayout.FlexibleSpace();
     Style.MinWidthLabel("(" + dic.Count + (dic.Count == 1 ? " item)" : " items)"), PADDING);
     EditorGUILayout.Space();
 }
Exemple #11
0
        protected override void DrawDictionaryCommon(PListDictionary dic)
        {
            _indentLevel++;
            string        entryToRemove    = "";
            string        keyToUpdate      = "";
            string        newKeyValue      = "";
            string        valueToUpdateKey = "";
            IPListElement valueToUpdate    = null;
            Color         original         = GUI.color;

            foreach (var kvp in dic)
            {
                Style.IndentedHorizontalLine(Styling.ROW_COLOR, _indentLevel * INDENT_AMOUNT);
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(_indentLevel * INDENT_AMOUNT);
                bool open = DrawFoldout(kvp.Value);

                try
                {
                    //draw the key
                    EditorGUI.BeginChangeCheck();
                    string key = EditorGUILayout.TextField(kvp.Key, GUILayout.MinWidth(KEY_WIDTH), GUILayout.MaxWidth(KEY_WIDTH));

                    if (EditorGUI.EndChangeCheck())
                    {
                        keyToUpdate = kvp.Key;
                        newKeyValue = key;
                        IsDirty     = true;
                    }

                    //draw type selector
                    IPListElement value = TypeSelector(kvp.Value);

                    if (value != kvp.Value)
                    {
                        valueToUpdateKey = key;
                        valueToUpdate    = value;
                        IsDirty          = true;
                    }
                }
                catch
                {
                    Debug.LogError("EgoXproject: Failed to update key: " + kvp.Key);
                }

                //draw the value
                DrawElement(kvp.Value);

                if (RemoveElement(kvp.Key))
                {
                    entryToRemove = kvp.Key;
                    IsDirty       = true;
                }

                EditorGUILayout.EndHorizontal();

                if (!open)
                {
                    continue;
                }

                //if element is a dictionary or an array, draw its entries
                if (kvp.Value is PListDictionary)
                {
                    DrawDictionaryCommon(kvp.Value as PListDictionary);
                }
                else if (kvp.Value is PListArray)
                {
                    DrawArrayContent(kvp.Value as PListArray);
                }
            }

            GUI.color = original;

            //perform dictionary maintenance
            if (!string.IsNullOrEmpty(keyToUpdate))
            {
                UpdateDictionaryKey(dic, keyToUpdate, newKeyValue);
            }

            if (!string.IsNullOrEmpty(valueToUpdateKey))
            {
                RemoveFoldoutEntry(dic [valueToUpdateKey]);
                dic [valueToUpdateKey] = valueToUpdate;
            }

            if (!string.IsNullOrEmpty(entryToRemove))
            {
                RemoveFoldoutEntry(dic [entryToRemove]);
                dic.Remove(entryToRemove);
            }

            if (AddElement())
            {
                string newKeyName = "New Key";
                int    count      = 1;

                while (dic.ContainsKey(newKeyName))
                {
                    newKeyName = "New Key " + count;
                    count++;
                }

                dic.Add(newKeyName, new PListString());
                IsDirty = true;
            }

            _indentLevel--;
        }
 void DrawRootDictionary(PListDictionary dict)
 {
     EditorGUILayout.BeginVertical();
     DrawPList(dict);
     EditorGUILayout.EndVertical();
 }
Exemple #13
0
 public void SetUp()
 {
     _element = new PListDictionary();
 }
 void AddBoolValue(PListDictionary dic)
 {
     dic.Add(VALUE_KEY, _boolDefaultValue);
 }
 void DrawBoolEntry(PListDictionary dic)
 {
     EditorGUILayout.LabelField(dic.BoolValue(VALUE_KEY) ? "Yes" : "No", GUILayout.MaxWidth(600));
 }
    EntryAction DrawEntry(PListDictionary dic, int index)
    {
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField(dic.StringValue(DISPLAY_NAME_KEY), GUILayout.MaxWidth(400));
        EditorGUILayout.LabelField(dic.StringValue(SETTING_KEY), GUILayout.MaxWidth(400));
        var type = (SettingType)System.Enum.Parse(typeof(SettingType), dic.StringValue(TYPE_KEY));

        EditorGUILayout.LabelField(type.ToString(), GUILayout.MaxWidth(200));

        switch (type)
        {
        case SettingType.Bool:
            DrawBoolEntry(dic);
            break;

        case SettingType.String:
            DrawStringEntry(dic);
            break;

        case SettingType.Enum:
            DrawEnumEntry(dic);
            break;

        case SettingType.Array:
        case SettingType.StringList:
            DrawArrayEntry(dic);
            break;

        default:
            EditorGUILayout.LabelField("UNKNOWN", GUILayout.MaxWidth(600));
            break;
        }

        EditorGUILayout.Space();
        EditorGUILayout.LabelField(index.ToString(), GUILayout.MaxWidth(40));
        EntryAction action = EntryAction.None;

        if (GUILayout.Button("^", GUILayout.MaxWidth(40)))
        {
            action = EntryAction.MoveUp;
        }

        if (GUILayout.Button("v", GUILayout.MaxWidth(40)))
        {
            action = EntryAction.MoveDown;
        }

        if (GUILayout.Button("e", GUILayout.MaxWidth(40)))
        {
            action = EntryAction.Edit;
        }

        if (GUILayout.Button("-", GUILayout.MaxWidth(40)))
        {
            if (EditorUtility.DisplayDialog("Remove Entry?", "Remove entry: " + dic.StringValue(DISPLAY_NAME_KEY) + " - " + dic.StringValue(SETTING_KEY), "Remove", "Cancel"))
            {
                action = EntryAction.Remove;
            }
        }

        EditorGUILayout.EndHorizontal();
        return(action);
    }