void ShowCost(BUILDING configData)
    {
        int count = 0;

        //show gold & elec
        if (configData.GoldCost > 0)
        {
            int    costNum = configData.GoldCost;
            double curNum  = itemPackage.GetGoldNumber();
            costCellList[count].title.text = "黄金消耗: ";
            costCellList[count].value.text = string.Format("{0} / {1}", GlobalFunction.NumberFormat(costNum), GlobalFunction.NumberFormat(curNum));
            costCellList[count].go.SetActive(true);
            if ((double)costNum > curNum)
            {
                costCellList[count].title.color = Color.red;
                costCellList[count].value.color = Color.red;
            }
            else
            {
                costCellList[count].title.color = Color.white;
                costCellList[count].value.color = Color.white;
            }
            count++;
        }
        if (configData.ElecCost > 0)
        {
            int    costNum = configData.ElecCost;
            double curNum  = itemPackage.GetElecNumber();
            costCellList[count].title.text = "电力消耗: ";
            costCellList[count].value.text = string.Format("{0} / {1}", GlobalFunction.NumberFormat(costNum), GlobalFunction.NumberFormat(curNum));
            costCellList[count].go.SetActive(true);
            if ((double)costNum > curNum)
            {
                costCellList[count].title.color = Color.red;
                costCellList[count].value.color = Color.red;
            }
            else
            {
                costCellList[count].title.color = Color.white;
                costCellList[count].value.color = Color.white;
            }
            count++;
        }
        for (int i = 0; i < configData.CostTableCount; i++)
        {
            int itemConfigId = configData.GetCostTable(i).CostId;
            if (itemConfigId == 0)
            {
                continue;
            }
            int       num      = configData.GetCostTable(i).CostQty;
            ITEM_RES  itemData = itemPackage.GetItemDataByConfigID(itemConfigId);
            NItemInfo itemInfo = itemPackage.GetItemInfo(itemConfigId);
            int       curNum   = itemInfo == null ? 0 : itemInfo.number;
            costCellList[count].title.text = itemData.MinName + ": ";
            costCellList[count].value.text = string.Format("{0} / {1}", num.ToString(), curNum);
            costCellList[count].go.SetActive(true);
            if (itemInfo == null || itemInfo.number < num)
            {
                costCellList[count].title.color = Color.red;
                costCellList[count].value.color = Color.red;
            }
            else
            {
                costCellList[count].title.color = Color.white;
                costCellList[count].value.color = Color.white;
            }
            count++;
        }
        for (; count < 5; count++)
        {
            costCellList[count].go.SetActive(false);
        }
    }
Esempio n. 2
0
    public override void DrawCell(int index, int count = 0)
    {
        base.DrawCell(index, count);
        var      dataList = sanctuaryPackage.GetBuildingCostList();
        NCostDef cost     = dataList[index];
        bool     isEnough = true;

        if (cost.configID == 1)
        {
            nameLabel.text  = string.Format("庄园等级限制:");
            valueLabel.text = string.Format("{0}/{1}", cost.value, userPackage.GetManorLevel());
            if (userPackage.GetManorLevel() < cost.value)
            {
                isEnough = false;
            }
        }
        else if (cost.configID == 2)
        {
            nameLabel.text  = string.Format("黄金:");
            valueLabel.text = string.Format("{0}/{1}", cost.value, GlobalFunction.NumberFormat(itemPackage.GetGoldNumber()));
            if (itemPackage.GetGoldNumber() < cost.value)
            {
                isEnough = false;
            }
        }
        else if (cost.configID == 3)
        {
            nameLabel.text  = string.Format("电力:");
            valueLabel.text = string.Format("{0}/{1}", cost.value, GlobalFunction.NumberFormat(itemPackage.GetElecNumber()));
            if (itemPackage.GetElecNumber() < cost.value)
            {
                isEnough = false;
            }
        }
        else
        {
            ITEM_RES itemData = itemPackage.GetItemDataByConfigID(cost.configID);
            if (itemData == null)
            {
                return;
            }
            nameLabel.text = string.Format("{0}:", itemData.MinName);
            NItemInfo itemInfo = itemPackage.GetItemInfo(cost.configID);
            if (itemInfo == null)
            {
                valueLabel.text = string.Format("{0}/{1}", cost.value, 0);
                isEnough        = false;
            }
            else
            {
                valueLabel.text = string.Format("{0}/{1}", cost.value, GlobalFunction.NumberFormat(itemInfo.number));
                if (itemInfo.number < cost.value)
                {
                    isEnough = false;
                }
            }
        }
        if (isEnough)
        {
            nameLabel.color  = Color.white;
            valueLabel.color = Color.white;
        }
        else
        {
            nameLabel.color  = Color.red;
            valueLabel.color = Color.red;
        }
    }