Exemplo n.º 1
0
    // 立即升级
    public void OnClickLevupNow()
    {
        int level = CityManager.Instance.GetSoldierLevel(_currentSoldierCfgID);

        if (level <= 0)
        {
            return;
        }

        SoldierConfig      cfg      = SoldierConfigLoader.GetConfig(_currentSoldierCfgID);
        SoldierLevelConfig cfgLevel = SoldierLevelConfigLoader.GetConfig(_currentSoldierCfgID, level);

        // 检查金钱
        if (UserManager.Instance.Money < cfgLevel.UpgradeCost)
        {
            UIUtil.ShowMsgFormat("MSG_CITY_BUILDING_MONEY_LIMIT");
            return;
        }

        // 检查元宝
        if (UserManager.Instance.Gold < Formula.GetLevelUpQuickCost(Utils.GetSeconds(cfgLevel.UpgradeTime)))
        {
            UIUtil.ShowMsgFormat("MSG_CITY_BUILDING_GOLD_LIMIT");
            return;
        }

        CityManager.Instance.RequestQuickTrainSoldier(_currentSoldierCfgID, true);
        UIManager.Instance.CloseWindow <UICityTrainSelectView>();
        CloseWindow();
    }
Exemplo n.º 2
0
    public override void OnBindData(params object[] param)
    {
        _currentInfo = param[0] as BuildingInfo;
        if (_currentInfo == null)
        {
            return;
        }

        if (_currentInfo.IsInBuilding())
        {
            _title.text  = Str.Get("UI_MSG_CANCEL");
            _detail.text = string.Format(Str.Get("UI_MSG_CANCEL_DETAIL"), _currentInfo.Cfg.BuildingName);
        }
        else if (_currentInfo.BuildingType == CityBuildingType.TRAIN)
        {
            // 快速升级兵种
            TrainBuildingInfo tbinfo = _currentInfo as TrainBuildingInfo;
            if (tbinfo != null && tbinfo.IsTrainingSoldier())
            {
                _title.text = Str.Get("UI_MSG_CANCEL");
                SoldierConfig cfg = SoldierConfigLoader.GetConfig(tbinfo.TrainSoldierCfgID);
                _detail.text = string.Format(Str.Get("UI_MSG_CANCEL_DETAIL"), cfg.SoldierName);
            }
        }
        else if (_currentInfo.BuildingType == CityBuildingType.TROOP)
        {
            // 快速生产士兵
            TroopBuildingInfo tbinfo = _currentInfo as TroopBuildingInfo;
            if (tbinfo != null && tbinfo.IsProducingSoldier())
            {
                _title.text  = Str.Get("UI_MSG_CANCEL_SOLDIER");
                _detail.text = string.Format(Str.Get("UI_MSG_CANCEL_SOLDIER_DETAIL"), tbinfo.SoldierCfg.SoldierName);
            }
        }
    }
Exemplo n.º 3
0
    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();
        }
    }
Exemplo n.º 4
0
    public void SetInfo(int soldierCfgID, BuildingInfo buildingInfo)
    {
        _currentSoldierCfgID = soldierCfgID;
        int level = CityManager.Instance.GetSoldierLevel(soldierCfgID);

        _levelupCfg = SoldierLevelConfigLoader.GetConfig(soldierCfgID, level);
        if (_levelupCfg == null)
        {
            return;
        }

        _soldierIcon.sprite = ResourceManager.Instance.GetSoldierIcon(_currentSoldierCfgID);

        // 兵营界面
        _currentBuildingInfo = buildingInfo as TroopBuildingInfo;
        if (_currentBuildingInfo == null)
        {
            return;
        }

        int           maxCount = _currentBuildingInfo.CfgLevel.MaxStorage;
        SoldierConfig cfg      = SoldierConfigLoader.GetConfig(_currentSoldierCfgID);

        if (cfg == null)
        {
            return;
        }

        _maxCount   = maxCount / cfg.States;
        _count.text = "x" + (maxCount / cfg.States);

        int count = _currentBuildingInfo.GetMaxSoldierCount(_currentSoldierCfgID);

        _costValue = _currentBuildingInfo.GetSwitchCost(_currentSoldierCfgID);
        int timeValue = Utils.GetSeconds(cfg.Producetime * count);

        _cost.text = Mathf.Max(0, _costValue).ToString();

        // 银两不足,显示红色
        if (UserManager.Instance.Money >= _costValue)
        {
            _cost.color = Color.white;
        }
        else
        {
            _cost.color = Color.red;
        }

        _time.text = Utils.GetCountDownString(timeValue);

        // 士兵生产数目
        _count.gameObject.SetActive(true);

        _soldierLevel.text = "Lv" + level;
    }
Exemplo n.º 5
0
    // 获取当前兵营兵种的最大数量
    public int GetMaxSoldierCount(int soldierCfgID)
    {
        SoldierConfig cfg = SoldierConfigLoader.GetConfig(soldierCfgID);

        if (cfg != null)
        {
            return(CfgLevel.MaxStorage / cfg.States);
        }

        return(0);
    }
Exemplo n.º 6
0
    // 获取士兵头像
    public Sprite GetSoldierIcon(int soldierID)
    {
        SoldierConfig cfg = SoldierConfigLoader.GetConfig(soldierID);

        if (cfg == null || string.IsNullOrEmpty(cfg.SoldierIcon))
        {
            return(GetSprite("Texture/ItemIcon/UI_zhuangbeitubiao_lan_1"));
        }

        return(GetSprite("Texture/SoldierIcon/" + cfg.SoldierIcon));
    }
Exemplo n.º 7
0
    private void SetInfo(BuildingInfo info)
    {
        _currentInfo = info as TroopBuildingInfo;
        if (_currentInfo == null)
        {
            return;
        }

        int           cfgID = _currentInfo.SoldierConfigID;
        SoldierConfig cfg   = SoldierConfigLoader.GetConfig(cfgID);
        int           level = Mathf.Max(CityManager.Instance.GetSoldierLevel(cfgID), 1);

        SoldierLevelConfig cfgLevel = SoldierLevelConfigLoader.GetConfig(cfgID, level);

        _title.text          = cfg.SoldierName + " Lv" + level;
        _soldierImage.sprite = ResourceManager.Instance.GetSoldierImage(cfgID);
        _textDesc.text       = cfg.SoldierDescription;

        _soldierIcon1.sprite = ResourceManager.Instance.GetSoldierIcon(cfgID);
        _soldierIcon2.sprite = ResourceManager.Instance.GetSoldierIcon(cfgID);
        _soldierCount1.text  = _currentInfo.SoldierCount.ToString();

        int addCount = _currentInfo.GetMaxSoldierCount(cfgID) - _currentInfo.SoldierCount;

        if (addCount > 0)
        {
            _soldierCount2.text = addCount.ToString();
            _textCost.text      = (addCount * cfgLevel.ProduceCost).ToString();
            _textTime.text      = Utils.GetCountDownString(addCount * Utils.GetSeconds(_currentInfo.SoldierCfg.Producetime));

            _soldierIcon2.gameObject.SetActive(true);
            _textCost.gameObject.SetActive(true);
            _textTime.gameObject.SetActive(true);
            _text3.gameObject.SetActive(true);
            _imageCostFlag.gameObject.SetActive(true);
            _imageTimeFlag.gameObject.SetActive(true);
            _btnAddSoldier.gameObject.SetActive(true);
        }
        else
        {
            // 兵营满了,不需要补充
            _soldierIcon2.gameObject.SetActive(false);
            _textCost.gameObject.SetActive(false);
            _textTime.gameObject.SetActive(false);
            _text3.gameObject.SetActive(false);
            _imageCostFlag.gameObject.SetActive(false);
            _imageTimeFlag.gameObject.SetActive(false);
            _btnAddSoldier.gameObject.SetActive(false);
        }
    }
Exemplo n.º 8
0
    public void OnTrainFinish(int newLevel)
    {
        CityManager.Instance.SoldierLevelList[TrainSoldierCfgID] = newLevel;
        SoldierConfig cfg = SoldierConfigLoader.GetConfig(TrainSoldierCfgID);

        // 消息提示
        if (cfg != null)
        {
            UIUtil.ShowMsgFormat("MSG_CITY_BUILDING_FINISH", cfg.SoldierName, newLevel);
        }

        TrainRemainTime   = 0;
        TrainSyncTime     = 0;
        TrainSoldierCfgID = 0;

        EventDispatcher.TriggerEvent(EventID.EVENT_CITY_BUILDING_REFRESH, EntityID);
        UIManager.Instance.RefreshWindow <UICityTrainSelectView>();
    }
Exemplo n.º 9
0
    private void SetInfo(int soldierCfgID)
    {
        _currentSoldierCfgID = soldierCfgID;
        int level = CityManager.Instance.GetSoldierLevel(soldierCfgID);

        if (level <= 0)
        {
            return;
        }

        SoldierConfig cfg = SoldierConfigLoader.GetConfig(_currentSoldierCfgID);

        _title.text = string.Format(Str.Get("UI_CITY_BUILDING_LEVELUP"), cfg.SoldierName, level + 1);

        SoldierLevelConfig cfgLevel     = SoldierLevelConfigLoader.GetConfig(_currentSoldierCfgID, level);
        SoldierLevelConfig cfgNextLevel = SoldierLevelConfigLoader.GetConfig(_currentSoldierCfgID, level + 1);

        _hpValue.text      = cfgLevel.SoldierHp.ToString();
        _trainCost.text    = cfgLevel.ProduceCost.ToString();
        _attackValue.text  = cfgLevel.SoldierAttack.ToString();
        _imgSoldier.sprite = ResourceManager.Instance.GetSoldierImage(soldierCfgID);

        if (cfgNextLevel != null)
        {
            // 增加变化的数值
            _hpAddValue.gameObject.SetActive(true);
            _attackAddValue.gameObject.SetActive(true);
            _trainCostAdd.gameObject.SetActive(true);
            _hpAddValue.text     = string.Format("(+{0})", cfgNextLevel.SoldierHp - cfgLevel.SoldierHp);
            _attackAddValue.text = string.Format("(+{0})", cfgNextLevel.SoldierAttack - cfgLevel.SoldierAttack);
            _trainCostAdd.text   = string.Format("(+{0})", cfgNextLevel.ProduceCost - cfgLevel.ProduceCost);
        }
        else
        {
            _hpAddValue.gameObject.SetActive(false);
            _attackAddValue.gameObject.SetActive(false);
            _trainCostAdd.gameObject.SetActive(false);
        }

        _uplevTime.text    = Utils.GetCountDownString(Utils.GetSeconds(cfgLevel.UpgradeTime));
        _uplevNowCost.text = Formula.GetLevelUpQuickCost(Utils.GetSeconds(cfgLevel.UpgradeTime)).ToString();
        _uplevCost.text    = cfgLevel.UpgradeCost.ToString();
    }
Exemplo n.º 10
0
    public void SetInfo(int soldierCfgID)
    {
        _currentSoldierCfgID = soldierCfgID;
        int level = CityManager.Instance.GetSoldierLevel(soldierCfgID);

        _soldierIcon.sprite = ResourceManager.Instance.GetSoldierIcon(soldierCfgID);

        _uplevelLimit.text = "";

        if (level == 0)
        {
            // 尚未获得该兵种
            SoldierConfig cfg = SoldierConfigLoader.GetConfig(soldierCfgID);
            if (cfg != null)
            {
                // 提示解锁 MSG_CITY_TRAIN_UNLOCK={0}级校场解锁
                _textLimit         = string.Format(Str.Get("MSG_CITY_TRAIN_UNLOCK"), cfg.UnlockMilitaryDemand);
                _uplevelLimit.text = _textLimit;
            }
        }
        else
        {
            TrainBuildingInfo  tpinfo = CityManager.Instance.GetBuildingByType(CityBuildingType.TRAIN) as TrainBuildingInfo;
            SoldierLevelConfig cfg    = SoldierLevelConfigLoader.GetConfig(soldierCfgID, level);
            if (cfg != null && tpinfo != null)
            {
                if (tpinfo.IsTrainingSoldier() && tpinfo.TrainSoldierCfgID == soldierCfgID)
                {
                    // 提示正在升级
                    _textLimit         = Str.Get("UI_CITY_BUILDING_TRAIN_NOW");
                    _uplevelLimit.text = _textLimit;
                }
                else
                {
                    // 提示升级 MSG_CITY_TRAIN_LIMIT=需要{0}级校场
                    _textLimit         = string.Format(Str.Get("MSG_CITY_TRAIN_LIMIT"), cfg.UpgradeMilitaryLevelDemand);
                    _uplevelLimit.text = _textLimit;
                }
            }
        }
    }
Exemplo n.º 11
0
    public override void OnBindData(params object[] param)
    {
        int soldierCfgID = (int)param[0];
        int level        = (int)param[1];

        if (level <= 0)
        {
            return;
        }

        SoldierConfig      cfg      = SoldierConfigLoader.GetConfig(soldierCfgID);
        SoldierLevelConfig cfgLevel = SoldierLevelConfigLoader.GetConfig(soldierCfgID, level);

        _title.text        = cfg.SoldierName;
        _txtLevel.text     = Str.Format("UI_LEVEL", level);
        _hp.text           = cfgLevel.SoldierHp.ToString();
        _space.text        = cfg.States.ToString();
        _trainCost.text    = cfgLevel.ProduceCost.ToString();
        _trainTime.text    = Utils.GetCountDownString(Utils.GetSeconds(cfg.Producetime));
        _imgSoldier.sprite = ResourceManager.Instance.GetSoldierImage(soldierCfgID);
        _txtAttack.text    = cfg.Attack.ToString();
    }
Exemplo n.º 12
0
    public void SetInfo(int soldierCfgID, bool isSameSoldier)
    {
        _currentSoldierCfgID = soldierCfgID;
        _soldierIcon.sprite  = ResourceManager.Instance.GetSoldierIcon(soldierCfgID);

        if (isSameSoldier)
        {
            // 当前兵种
            _textLimit         = Str.Get("UI_CITY_TROOP_SAME_SOLDIER");
            _uplevelLimit.text = _textLimit;
        }
        else
        {
            // 尚未获得该兵种
            SoldierConfig cfg = SoldierConfigLoader.GetConfig(soldierCfgID);
            if (cfg != null)
            {
                // 提示解锁 MSG_CITY_TRAIN_UNLOCK={0}级校场解锁
                _textLimit         = string.Format(Str.Get("MSG_CITY_TRAIN_UNLOCK"), cfg.UnlockMilitaryDemand);
                _uplevelLimit.text = _textLimit;
            }
        }
    }
Exemplo n.º 13
0
    // 升级
    public void OnClickLevup()
    {
        int level = CityManager.Instance.GetSoldierLevel(_currentSoldierCfgID);

        if (level <= 0)
        {
            return;
        }

        SoldierConfig      cfg      = SoldierConfigLoader.GetConfig(_currentSoldierCfgID);
        SoldierLevelConfig cfgLevel = SoldierLevelConfigLoader.GetConfig(_currentSoldierCfgID, level);

        // 检查金钱
        if (UserManager.Instance.Money < cfgLevel.UpgradeCost)
        {
            UIUtil.ShowMsgFormat("MSG_CITY_BUILDING_MONEY_LIMIT");
            return;
        }

        CityManager.Instance.RequestTrainSoldier(_currentSoldierCfgID, cfgLevel.UpgradeCost);

        UIManager.Instance.CloseWindow <UICityTrainSelectView>();
        CloseWindow();
    }