public override void OnBindData(params object[] param)
    {
        _currentInfo = param[0] as BuildingInfo;
        if (_currentInfo == null)
        {
            return;
        }

        int costValue = 0;

        if (_currentInfo.IsInBuilding())
        {
            costValue    = _currentInfo.GetQuickLevelUpCost(true);
            _title.text  = Str.Get("UI_MSG_QUICK_UPGRADE_TITLE");
            _detail.text = string.Format(Str.Get("UI_MSG_QUICK_UPGRADE_DETAIL"), costValue, _currentInfo.Cfg.BuildingName);
            _cost.text   = _currentInfo.GetQuickLevelUpCost(true).ToString();
        }
        else if (_currentInfo.BuildingType == CityBuildingType.TRAIN)
        {
            // 快速升级兵种
            TrainBuildingInfo tbinfo = _currentInfo as TrainBuildingInfo;
            if (tbinfo != null && tbinfo.IsTrainingSoldier())
            {
                costValue   = tbinfo.GetQuickTrainCost();
                _title.text = Str.Get("UI_MSG_QUICK_UPGRADE_TITLE");
                SoldierConfig cfg = SoldierConfigLoader.GetConfig(tbinfo.TrainSoldierCfgID);
                _detail.text = string.Format(Str.Get("UI_MSG_QUICK_UPGRADE_DETAIL"), costValue, cfg.SoldierName);
                _cost.text   = tbinfo.GetQuickTrainCost().ToString();
            }
        }
        else if (_currentInfo.BuildingType == CityBuildingType.TROOP)
        {
            // 快速生产士兵
            TroopBuildingInfo tbinfo = _currentInfo as TroopBuildingInfo;
            if (tbinfo != null && tbinfo.IsProducingSoldier())
            {
                costValue    = tbinfo.GetQuickProducingCost();
                _title.text  = Str.Get("UI_MSG_QUICK_PRODUCE_SOLDIER");
                _detail.text = string.Format(Str.Get("UI_MSG_QUICK_PRODUCE_SOLDIER_DETAIL"), costValue, tbinfo.SoldierCfg.SoldierName);
                _cost.text   = tbinfo.GetQuickProducingCost().ToString();
            }
        }

        RectTransform rc = _imgFlag.transform as RectTransform;

        if (rc)
        {
            rc.anchoredPosition = new Vector2(-(_imgFlag.preferredWidth + _cost.preferredWidth) / 2 - 2, rc.anchoredPosition.y);
        }

        if (costValue <= 0)
        {
            CloseWindow();
        }
    }
Exemple #2
0
    // 请求快速升级士兵
    public void RequestQuickTrainSoldier(int soldierCfgID, bool costRes)
    {
        PCMInt data = new PCMInt();

        data.arg = soldierCfgID;

        Net.Send(eCommand.TRAIN_SOLIDER_RIGHT_NOW, data, (buffer) => {
            PBuildInfo ret = Net.Deserialize <PBuildInfo>(buffer);

            if (!Net.CheckErrorCode(ret.errorCode, eCommand.TRAIN_SOLIDER_RIGHT_NOW))
            {
                return;
            }

            TrainBuildingInfo tbinfo = GetBuildingByType(CityBuildingType.TRAIN) as TrainBuildingInfo;
            if (tbinfo != null)
            {
                if (costRes)
                {
                    // 扣去相应资源(先减再升级)
                    UserManager.Instance.CostMoney(tbinfo.GetTrainCost(soldierCfgID), PriceType.MONEY);
                }

                // 无论哪种情况都要把黄金扣了
                UserManager.Instance.CostMoney(tbinfo.GetQuickTrainCost(), PriceType.GOLD);

                tbinfo.Deserialize(ret);
                RefreshUI(tbinfo.EntityID);

                UIManager.Instance.RefreshWindow <UICityTrainSelectView>();
            }
        });
    }
Exemple #3
0
    private void SetInfo(BuildingInfo info)
    {
        _currentInfo = info;
        if (_currentInfo == null)
        {
            return;
        }

        if (_currentInfo.IsInBuilding())
        {
            // 建筑正在升级
            _leftIcon.sprite = _levelUpIcon;
            _cost.text       = _currentInfo.GetQuickLevelUpCost(true).ToString();
        }
        else if (_currentInfo.BuildingType == CityBuildingType.TROOP)
        {
            // 如果是兵营的话
            TroopBuildingInfo tbinfo = _currentInfo as TroopBuildingInfo;
            if (tbinfo != null && tbinfo.IsProducingSoldier())
            {
                // 如果正在生产士兵,则显示士兵头像
                _leftIcon.sprite = ResourceManager.Instance.GetSoldierIcon(tbinfo.SoldierConfigID);
                _cost.text       = tbinfo.GetQuickProducingCost().ToString();
            }
        }
        else if (_currentInfo.BuildingType == CityBuildingType.TRAIN)
        {
            TrainBuildingInfo tbinfo = _currentInfo as TrainBuildingInfo;
            if (tbinfo != null && tbinfo.IsTrainingSoldier())
            {
                _leftIcon.sprite = ResourceManager.Instance.GetSoldierIcon(tbinfo.TrainSoldierCfgID);
                _cost.text       = tbinfo.GetQuickTrainCost().ToString();
            }
        }

        RectTransform rc = _imgFlag.transform as RectTransform;

        if (rc)
        {
            rc.anchoredPosition = new Vector2(-(_imgFlag.preferredWidth + _cost.preferredWidth) / 2 - 2, rc.anchoredPosition.y);
        }

        InvokeRepeating("UpdateTime", 0, 1);
    }