private void _setCellOutfits(int index, PropertyChar property)
    {
        bool isOwn   = property != null;
        bool isEquip = property != null && property.EquipSlot != -1;

        controlPropertys.SetItemCaption(index, isOwn, isEquip);
    }
    public PropertyChar AddItem(SerializablePropertys propertys, string slug)
    {
        var v_slug = propertys.PropertyBySlug(slug);

        if (v_slug == null)
        {
            InputFieldHelper.Instance.ShowNoti(string.Format("Item {0} not found (check propertys list)", slug));
            return(null);
        }
        ShouldUpdateGUIContent = true;
        countNewItem++;
        if (v_slug.StackInBag)
        {
            for (int i = 0; i < PropertysChar.Count; i++)
            {
                var p = PropertysChar[i];
                if (p.Slug == slug)
                {
                    p.Count = p.Count + 1;
                    return(p);
                }
            }
        }
        var p_new = PropertyChar.CreateFromSlug(v_slug, slug);

        PropertysChar.Add(p_new);
        return(p_new);
    }
    private void _refreshPets(SerializablePropertys propertys, bool isBeginShow)
    {
        int lastSelectedIndex = controlPropertys.ListItem.selectedIndex;

        controlPropertys.ResetListItem();
        controlPropertys.ResetSelectItem();
        for (int i = 0; i < propertys.Count; i++)
        {
            var propertyData = propertys.PropertyByIndex(i);
            if (propertyData.IsPet)
            {
                PropertyChar propertyOwn = GetPet(propertyData);
                var          bt          = controlPropertys.AddItem(propertyData.Name, () =>
                {
                    _showPet(propertys, propertyData, propertyOwn);
                });
                bool isOwn   = propertyOwn != null;
                bool isEquip = false;
                if (propertyOwn != null)
                {
                    isEquip = propertyOwn.IsActive;
                }
                controlPropertys.SetItemCaption(bt, isOwn, isEquip);
                if (isBeginShow && isEquip)
                {
                    lastSelectedIndex = i;
                }
            }
        }
        controlPropertys.SetSelectedIndex(lastSelectedIndex);
    }
        public static PropertyChar CreateFromSlug(SerializablePropertys.Property propertyBase, string slug)
        {
            PropertyChar pc = new PropertyChar();

            pc.Slug         = slug;
            pc.PropertyBase = propertyBase;
            return(pc);
        }
    private void _showCertificates(SerializablePropertys.Property propertyData, PropertyChar propertyOwn)
    {
        controlPropertys.ResetSelectItem();

        controlPropertys.SetItemName(propertyData.Name);

        controlPropertys.SetItemDes(propertyData.Des);

        controlPropertys.LoadImageItem(propertyData.RefIcon);
    }
    private void _refreshListOutfits(ItemChar.Items items)
    {
        var l = items.ItemList;

        for (int i = 0; i < l.Length; i++)
        {
            Item         item     = l[i];
            PropertyChar property = GetOutfit(item);
            _setCellOutfits(i, property);
        }
    }
    public void EquipPet(PropertyChar p)
    {
        if (!p.PropertyBase.IsPet)
        {
            InputFieldHelper.Instance.ShowNoti("Item it not the Pet");
            return;
        }
        UnquipCurrentPet();
        p.IsActive = true;
        BasicMecanimControl basicMecanimControl = AutoTileMap_Editor.Instance.Agent.GetComponentInChildren <BasicMecanimControl>();

        basicMecanimControl.Pet = "pets/" + p.PropertyBase.RefSlug;
    }
 public void UsingItem(PropertyChar p)
 {
     if (p.Count > 0)
     {
         p.Count = p.Count - 1;
     }
     FlagAction.DoFlagAction(TriggerGame.Instance.WorldFlag, AutoTileMap_Editor.Instance.MapsData.ListFlagAction, p.PropertyBase.ActionUsing);
     if (p.Count <= 0)
     {
         PropertysChar.Remove(p);
     }
     ShouldUpdateGUIContent = true;
 }
    private void _showOutfits4(CharGame charGame, ItemChar.Items items, Item item, PropertyChar property)
    {
        var tryItem = AutoTileMap_Editor.Instance.ItemCharData.FetchItemByGlobalSlug(item.SlugGlobal);

        if (tryItem == null)
        {
            InputFieldHelper.Instance.ShowNoti("Item not found in database");
            return;
        }

        controlPropertys.ResetSelectItem();

        controlPropertys.LoadModelItem(tryItem.ItemPrefab);

        if (tryItem.SlugChar != charGame.SlugChar)
        {
            controlPropertys.SetItemDes("Your character can't use this item.");
            return;
        }

        if (property == null)
        {
            controlPropertys.SetItemName(item.Slug);
            controlPropertys.SetItemDes("You don't own this item.");
            return;
        }
        else
        {
            controlPropertys.SetItemName(property.NameUI);
        }
        if (property.EquipSlot == -1)
        {
            controlPropertys.AddAction("Equip", () =>
            {
                this.Equip(charGame, property);
                this._showOutfits4(charGame, items, item, property);
                this._refreshListOutfits(items);
            });
        }
        else
        {
            controlPropertys.SetItemDes("Item is equipped");
            controlPropertys.AddAction("Unequip", () =>
            {
                this.UnEquip(charGame, property);
                this._showOutfits4(charGame, items, item, property);
                this._refreshListOutfits(items);
            });
        }
    }
    private void _showOutfits3(CharGame charGame, ItemChar.Items items, SerializablePropertys propertys)
    {
        var l = items.ItemList;

        for (int i = 0; i < l.Length; i++)
        {
            Item         item        = l[i];
            PropertyChar propertyOwn = GetOutfit(item);
            var          bt          = controlPropertys.AddItem(item.Slug, () =>
            {
                _showOutfits4(charGame, items, item, propertyOwn);
            });
            _setCellOutfits(i, propertyOwn);
        }
    }
    private void _onUsingItem(PropertyChar property)
    {
        controlPropertys.contentPane.visible = false;
        string name_item = property.NameUI;
        // string last_text = InputFieldHelper.Instance.LastTextChatBottom();
        string text = string.Format("{0} used!", name_item);

        text += "\n" + property.PropertyBase.Des;
        text += "\n" + property.PropertyBase.ActionUsing;
        InputFieldHelper.Instance.ShowChatBottom(text, true, (TypingEffectByLine ty) =>
        {
            controlPropertys.contentPane.visible = true;
            InputFieldHelper.Instance.HideChatBottom();
            this.UsingItem(property);
            _refreshListItems();
        });
    }
    private void _refreshListItems()
    {
        int lastSelectedIndex = controlPropertys.ListItem.selectedIndex;

        controlPropertys.ResetListItem();
        controlPropertys.ResetSelectItem();
        for (int i = 0; i < PropertysChar.Count; i++)
        {
            PropertyChar property = PropertysChar[i];
            if (property.PropertyBase.IsItem)
            {
                var bt = controlPropertys.AddItem(property.NameUI, () =>
                {
                    _showItems2(property);
                });
                controlPropertys.SetItemUsing(i, property.PropertyBase.StackInBag, property.Count);
            }
        }
        controlPropertys.SetSelectedIndex(lastSelectedIndex);
    }
    public void Equip(CharGame charGame, PropertyChar p)
    {
        if (!p.PropertyBase.IsOutfit)
        {
            InputFieldHelper.Instance.ShowNoti("ItemEquip it not the Outfit");
            return;
        }
        if (p.PropertyBase.RefSlug == null || p.PropertyBase.RefSlug == "")
        {
            InputFieldHelper.Instance.ShowNoti("ItemEquip empty");
            return;
        }
        var item = AutoTileMap_Editor.Instance.ItemCharData.FetchItemByGlobalSlug(p.PropertyBase.RefSlug);

        if (item == null)
        {
            InputFieldHelper.Instance.ShowNoti("ItemEquip not found");
            return;
        }
        if (charGame == null)
        {
            charGame = AutoTileMap_Editor.Instance.Agent.GetComponentInChildren <CharGame>();
        }
        if (charGame.SlugChar != item.SlugChar)
        {
            InputFieldHelper.Instance.ShowNoti("Your character can't use this item.");
            return;
        }
        ShopGame.Instance.UnTryCostume(charGame);
        UnEquip(charGame, item.ItemType);
        CheckItemBeforeEquip(charGame, item.ItemType);
        string error = "";

        if (charGame.AddEquipment(item, ref error) == false)
        {
            // m_tip = error;
            return;
        }
        p.EquipSlot            = (int)item.ItemType;
        ShouldUpdateGUIContent = true;
    }
    private void _refreshCertificates(SerializablePropertys propertys)
    {
        int lastSelectedIndex = controlPropertys.ListItem.selectedIndex;

        controlPropertys.ResetListItem();
        controlPropertys.ResetSelectItem();
        for (int i = 0; i < propertys.Count; i++)
        {
            var propertyData = propertys.PropertyByIndex(i);
            if (propertyData.IsCertificates)
            {
                PropertyChar propertyOwn = GetCertificates(propertyData);
                var          bt          = controlPropertys.AddItem(propertyData.Name, () =>
                {
                    _showCertificates(propertyData, propertyOwn);
                });
                controlPropertys.SetItemOwn(bt, propertyOwn != null);
            }
        }
        controlPropertys.SetSelectedIndex(lastSelectedIndex);
    }
    private void _showItems2(PropertyChar property)
    {
        controlPropertys.ResetSelectItem();

        controlPropertys.SetItemName(property.NameUI);

        controlPropertys.LoadImageItem(property.PropertyBase.RefIcon);

        if (property.EquipSlot != -1)
        {
            controlPropertys.SetItemDes("Item is equipped");
            return;
        }

        controlPropertys.SetItemDes(property.PropertyBase.Des);

        controlPropertys.AddAction("Use", () =>
        {
            _onUsingItem(property);
        });
    }
    public bool UnEquip(CharGame charGame, PropertyChar p)
    {
        if (p.PropertyBase.RefSlug == null || p.PropertyBase.RefSlug == "")
        {
            InputFieldHelper.Instance.ShowNoti("ItemEquip empty");
            return(false);
        }
        var item = AutoTileMap_Editor.Instance.ItemCharData.FetchItemByGlobalSlug(p.PropertyBase.RefSlug);

        if (item == null)
        {
            InputFieldHelper.Instance.ShowNoti("ItemEquip not found");
            return(false);
        }
        if (charGame == null)
        {
            charGame = AutoTileMap_Editor.Instance.Agent.GetComponentInChildren <CharGame>();
        }
        ShopGame.Instance.UnTryCostume(charGame);
        charGame.RemoveEquipment(item);
        p.EquipSlot            = -1;
        ShouldUpdateGUIContent = true;
        return(true);
    }
    private void _showPet(SerializablePropertys propertys, SerializablePropertys.Property propertyData, PropertyChar propertyOwn)
    {
        controlPropertys.ResetSelectItem();

        controlPropertys.SetItemName(propertyData.Name);

        controlPropertys.SetItemDes(propertyData.Des);

        if (string.IsNullOrEmpty(propertyData.RefSlug))
        {
            InputFieldHelper.Instance.ShowNoti("Item model is null");
            return;
        }
        controlPropertys.LoadModelItem("pets/" + propertyData.RefSlug);

        if (propertyOwn != null)
        {
            bool isEquip = propertyOwn.IsActive;
            if (!isEquip)
            {
                controlPropertys.AddAction("Equip", () =>
                {
                    // basicMecanimControl.Pet = propertyData.RefSlug;
                    EquipPet(propertyOwn);
                    _refreshPets(propertys, false);
                });
            }
            else
            {
                controlPropertys.SetItemDes("Item is equipped");
                controlPropertys.AddAction("Unequip", () =>
                {
                    // basicMecanimControl.Pet = "";
                    UnquipCurrentPet();
                    _refreshPets(propertys, false);
                });
            }
        }
    }