コード例 #1
0
    public void ShowCardItem(UserCardItem card)
    {
        if (card == null)
        {
            return;
        }

        GameObject newItem = CardListItemPool.Instance.GetListItem("CardSellItem");//(GameObject)Instantiate(cardPrefab);

        if (newItem == null)
        {
            return;
        }

        newItem.transform.parent        = listParent.transform;
        newItem.transform.localPosition = new Vector3(0, 0, -1);
        newItem.transform.localScale    = new Vector3(1, 1, 1);
        newItem.name = card.cardID.ToString();
        items.Add(newItem);
        //			UIEventListener.Get(newItem).onClick +=

        Tab_Card tabCard = TableManager.GetCardByID(card.templateID);

        Transform labNameTrans = newItem.transform.FindChild("Labels/Label-Name");

        if (labNameTrans != null &&
            tabCard != null)
        {
            Tab_Appearance tabAppearance = TableManager.GetAppearanceByID(tabCard.Appearance);
            if (tabAppearance != null)
            {
                UILabel nameLabel = labNameTrans.GetComponent <UILabel>();
                if (nameLabel != null)
                {
                    int nameLangId = tabAppearance.Name;
                    nameLabel.text = LanguageManger.GetWords(nameLangId);
                }
            }
        }


        //------------------------卡牌背景及外框--------------------------------
        //2013-10-12 Jack Wen
        Transform tranSpBg = newItem.transform.FindChild("CardIcon/CardIconBtn/Sprite-BG");

        if (tranSpBg != null &&
            tabCard != null)
        {
            UISprite icon_bg = tranSpBg.GetComponent <UISprite>();
            if (icon_bg != null)
            {
                icon_bg.spriteName = UserCardItem.littleCardFrameName[tabCard.Star];
            }
        }

        Transform tranSp_Outside = newItem.transform.FindChild("CardIcon/CardIconBtn/sp-Outside");

        if (tranSp_Outside != null &&
            tabCard != null)
        {
            UISprite icon_border = tranSp_Outside.GetComponent <UISprite>();
            icon_border.spriteName = UserCardItem.littleCardBorderName[tabCard.Star];
        }
        //--------------------------------------------------------------------

        Transform transLabel_lev_value = newItem.transform.FindChild("Labels/Label-Level-Value");

        if (transLabel_lev_value != null)
        {
            UILabel cardLevelLabel = transLabel_lev_value.GetComponent <UILabel>();
            if (cardLevelLabel != null)
            {
                cardLevelLabel.text = card.level.ToString();
            }
        }
        //UILabel cardLevelLabel = newItem.transform.FindChild("Labels/Label-Level-Value").GetComponent<UILabel>();


        Transform tranLab_Hp_Val = newItem.transform.FindChild("Labels/Label-Hp-Value");

        if (tranLab_Hp_Val != null)
        {
            UILabel cardHPLabel = tranLab_Hp_Val.GetComponent <UILabel>();
            if (cardHPLabel != null)
            {
                cardHPLabel.text = card.GetHp().ToString();
            }
        }

        Transform tranLab_Att_Val = newItem.transform.FindChild("Labels/Label-Attack-Value");

        if (tranLab_Att_Val != null)
        {
            UILabel cardAttackValueLabel = tranLab_Att_Val.GetComponent <UILabel>();
            if (cardAttackValueLabel != null)
            {
                cardAttackValueLabel.text = card.GetAttack().ToString();
            }
        }

        Transform tranLab_Mony_Val = newItem.transform.FindChild("Labels/Label-Money-Value");

        if (tranLab_Mony_Val != null)
        {
            UILabel cardMoneyValueLabel = tranLab_Mony_Val.GetComponent <UILabel>();
            if (cardMoneyValueLabel != null)
            {
                cardMoneyValueLabel.text = card.GetMoneyValue().ToString();
            }
        }


        Transform tranSp_Icon = newItem.transform.FindChild("CardIcon/CardIconBtn/Sprite-Icon");

        if (tranSp_Icon != null)
        {
            UISprite       icon          = tranSp_Icon.GetComponent <UISprite>();
            Tab_Appearance tabAppearance = TableManager.GetAppearanceByID(tabCard.Appearance);
            if (icon != null &&
                tabAppearance != null)
            {
                icon.spriteName = tabAppearance.HeadIcon;
            }
        }


        //星级显示
        Transform transformStars = newItem.transform.FindChild("Stars");

        if (transformStars != null)
        {
            for (int j = 1; j <= 7; j++)
            {
                if (j <= card.quality)
                {
                    Transform tranStar = transformStars.FindChild("star_" + j);
                    if (tranStar != null)
                    {
                        tranStar.gameObject.SetActive(true);
                    }
                }
                else
                {
                    Transform tranStar = transformStars.FindChild("star_" + j);
                    if (tranStar != null)
                    {
                        tranStar.gameObject.SetActive(false);
                    }
                }
            }
        }


        Transform tranSp_Selected = newItem.transform.FindChild("Sprites/Sprite-Selected");

        if (tranSp_Selected != null)
        {
            UISprite selectSprite = tranSp_Selected.GetComponent <UISprite>();
            //设置显示状态
            if (CheckIfChooseItem(card))
            {
                if (selectSprite != null)
                {
                    selectSprite.gameObject.SetActive(true);
                }
            }
            else
            {
                if (selectSprite != null)
                {
                    selectSprite.gameObject.SetActive(false);
                }
            }
        }



        //五行图标显示
        Transform tranSpAttribut = newItem.transform.FindChild("Sprite-Attribute");

        if (tranSpAttribut != null)
        {
            UISprite sttributeIcon = tranSpAttribut.GetComponent <UISprite>();
            if (sttributeIcon != null)
            {
                sttributeIcon.spriteName = card.GetAttributeIconName();
            }
        }



//         UISprite selectSprite = newItem.transform.FindChild("Sprites/Sprite-Selected").GetComponent<UISprite>();
//         selectSprite.gameObject.SetActive(false);

        UIEventListener.Get(newItem).onClick += OnSelectItem;
        Transform tranCardIconBtn = newItem.transform.FindChild("CardIcon/CardIconBtn");

        if (tranCardIconBtn != null)
        {
            GameObject CardIconBtn = tranCardIconBtn.gameObject;
            UIEventListener.Get(CardIconBtn).onClick += ShowCardInfo;
        }
    }