Exemplo n.º 1
0
    private void AddChild(ItemTree.Item item, ItemTree.Options options, string childName)
    {
        if (string.IsNullOrEmpty(childName))
        {
            Debug.LogError("no name specified");
            return;
        }
        if (childName == item.Name)
        {
            Debug.LogError("can't add self as parent");
            return;
        }
        if (!_recipes.itemTree.HasItem(childName))
        {
            Debug.LogError("no such item");
            return;
        }
        var child = _recipes.itemTree.GetItem(childName);

        if (child == null)
        {
            Debug.LogError("child is null");
            return;
        }
        if (options.Items.Contains(child))
        {
            Debug.LogError("child already added");
            return;
        }
        options.Items.Add(child);
        _dirty = true;
    }
Exemplo n.º 2
0
 private void RemoveOptions(ItemTree.Item item, ItemTree.Options options)
 {
     if (!item.Options.Contains(options))
     {
         return;
     }
     item.Options.Remove(options);
     _dirty = true;
 }
Exemplo n.º 3
0
    private void AddOption(ItemTree.Item item, string optionName)
    {
        if (optionName == item.Name)
        {
            Debug.LogError("can't add self as parent");
            return;
        }
        if (!_recipes.itemTree.HasItem(optionName))
        {
            Debug.LogError("no such item");
            return;
        }
        var child = _recipes.itemTree.GetItem(optionName);

        item.AddOption(child);
        _dirty = true;
    }
Exemplo n.º 4
0
    private string ItemJSON(ItemTree.Item item)
    {
        string ret = "\"" + item.Name + "\":";

        if (item.Options.Count == 0)
        {
            return(ret + "null");
        }
        List <ItemTree.Item> items = item.Options.ElementAt(0).Items;

        if (items.Count == 0)
        {
            return(ret + "null");
        }
        ret += "{";
        foreach (var i in items)
        {
            ret += ItemJSON(i) + ",";
        }
        return(ret.Substring(0, ret.Length - 1) + "}");
    }
Exemplo n.º 5
0
    private void AddRecipe()
    {
        var item = _recipes.itemTree.GetItem(_itemNames[_recipeToAdd]);

        if (item == null)
        {
            return;
        }
        if (_recipes.recipeRoots == null || _recipes.recipeRoots.Length == 0)
        {
            _recipes.recipeRoots = new ItemTree.Item[] { item };
            return;
        }
        var existing = _recipes.recipeRoots;
        var expanded = new ItemTree.Item[existing.Length + 1];

        existing.CopyTo(expanded, 0);
        _recipes.recipeRoots = expanded;
        _recipes.recipeRoots[_recipes.recipeRoots.Length - 1] = item;
        _dirty = true;
    }
Exemplo n.º 6
0
 private void AddItemToIngredients(ItemTree.Item item, List <ItemTree.Item> ingredients, bool onlyWithAssets)
 {
     if (item == null)
     {
         return;
     }
     item = itemTree.GetItem(item.Name);
     if (!ingredients.Contains(item))
     {
         if (!onlyWithAssets || item.HasAsset)
         {
             ingredients.Add(item);
         }
     }
     foreach (var option in item.Options)
     {
         foreach (var child in option.Items)
         {
             AddItemToIngredients(child, ingredients, onlyWithAssets);
         }
     }
 }
Exemplo n.º 7
0
 private void RemoveChild(ItemTree.Item parent, ItemTree.Options options, ItemTree.Item child)
 {
     if (parent == null)
     {
         if (EditorUtility.DisplayDialog("Delete?", "Really delete recipe?", "Bye Bye Forever", "Cancel"))
         {
             _recipes.itemTree.RemoveFromRoot(child);
         }
     }
     else
     {
         if (options.Items.Contains(child))
         {
             options.Items.Remove(child);
         }
         if (options.Items.Count == 0)
         {
             parent.Options.Remove(options);
         }
     }
     _dirty = true;
 }
Exemplo n.º 8
0
    private void DrawItem(ItemTree.Item item, ItemTree.Item parent, ItemTree.Options options, int depth)
    {
        if (depth > 5)
        {
            return;
        }
        EditorGUI.indentLevel = 2 * (depth - 1);

        if (depth == 2 || depth == 1)
        {
            GUILayout.BeginHorizontal();
            if (depth == 1)
            {
                var prevItemName = item.Name;
                item.Name = EditorGUILayout.TextField(item.Name);
                if (prevItemName != item.Name)
                {
                    _dirty = true;
                }
                var prevHasAsset = item.HasAsset;
                item.HasAsset = EditorGUILayout.Toggle(item.HasAsset, GUILayout.Width(50));
                if (prevHasAsset != item.HasAsset)
                {
                    _dirty = true;
                }
            }
            else
            {
                EditorGUILayout.LabelField(item.Name);
            }
            if (GUILayout.Button("-"))
            {
                RemoveChild(parent, options, item);
            }
            GUILayout.EndHorizontal();
        }
        else
        {
            EditorGUILayout.LabelField(item.Name);
        }
        for (var i = item.Options.Count - 1; i >= 0; i--)
        {
            EditorGUI.indentLevel = 2 * depth;
            var option = item.Options[i];
            if (item.Options.Count > 1)
            {
                GUILayout.BeginHorizontal();
                EditorGUI.indentLevel = 2 * depth - 1;
                EditorGUILayout.LabelField(string.Format("Option {0}", i + 1));
                if (GUILayout.Button("-"))
                {
                    RemoveOptions(item, option);
                }
                GUILayout.EndHorizontal();
            }
            for (var j = option.Items.Count - 1; j >= 0; j--)
            {
                var childName = option.Items[j].Name;
                var child     = _recipes.itemTree.GetItem(childName);
                if (child != null)
                {
                    DrawItem(child, item, option, depth + 1);
                }
            }

            if (depth == 1)
            {
                EditorGUI.indentLevel = 2 * depth;
                GUILayout.BeginHorizontal();
                if (!_selectedItems.ContainsKey(item.Name))
                {
                    _selectedItems[item.Name] = 0;
                }
                _selectedItems[item.Name] = EditorGUILayout.Popup(_selectedItems[item.Name], _itemNames);
                if (GUILayout.Button("+"))
                {
                    AddChild(item, option, _itemNames[_selectedItems[item.Name]]);
                }
                GUILayout.EndHorizontal();
            }
        }

        if (depth == 1)
        {
            GUILayout.Space(8);
            EditorGUI.indentLevel = 2 * depth;
            var key = string.Format("{0}-Or", item.Name);
            GUILayout.BeginHorizontal();
            if (!_selectedItems.ContainsKey(key))
            {
                _selectedItems[key] = 0;
            }
            _selectedItems[key] = EditorGUILayout.Popup(_selectedItems[key], _itemNames);
            var label = "+";
            if (item.Options.Count > 0)
            {
                label = "+OR";
            }
            if (GUILayout.Button(label))
            {
                AddOption(item, _itemNames[_selectedItems[key]]);
            }
            GUILayout.EndHorizontal();
        }
    }