Beispiel #1
0
 void UpdateTime()
 {
     if (_currentInfo.IsInBuilding())
     {
         // 建筑正在升级
         int cd = _currentInfo.GetLevelUpCD();
         _prgTime.fillAmount = 1.0f * cd / Utils.GetSeconds(_currentInfo.CfgLevel.UpgradeTime);
         _textTime.text      = Utils.GetCountDownString(cd);
     }
     else if (_currentInfo.BuildingType == CityBuildingType.TROOP)
     {
         // 如果是兵营的话
         TroopBuildingInfo tbinfo = _currentInfo as TroopBuildingInfo;
         if (tbinfo != null && tbinfo.IsProducingSoldier())
         {
             // 如果正在生产士兵,则显示士兵头像
             int cd = tbinfo.GetProducingCD();
             _prgTime.fillAmount = 1.0f * cd / tbinfo.GetMaxProduceTime();
             _textTime.text      = Utils.GetCountDownString(cd);
         }
     }
     else if (_currentInfo.BuildingType == CityBuildingType.TRAIN)
     {
         TrainBuildingInfo tbinfo = _currentInfo as TrainBuildingInfo;
         if (tbinfo != null && tbinfo.IsTrainingSoldier())
         {
             int cd = tbinfo.GetTrainCD();
             _prgTime.fillAmount = 1.0f * cd / tbinfo.GetMaxTrainTime();
             _textTime.text      = Utils.GetCountDownString(cd);
         }
     }
 }
Beispiel #2
0
 public void OnClickOK()
 {
     if (_currentInfo.IsInBuilding())
     {
         // 立刻升级建筑
         CityManager.Instance.RequestQuickUpgradeBuilding(_currentInfo.EntityID, false);
         CloseWindow();
     }
     else if (_currentInfo.BuildingType == CityBuildingType.TRAIN)
     {
         // 快速升级兵种
         TrainBuildingInfo tbinfo = _currentInfo as TrainBuildingInfo;
         if (tbinfo != null && tbinfo.IsTrainingSoldier())
         {
             CityManager.Instance.RequestQuickTrainSoldier(tbinfo.TrainSoldierCfgID, false);
             CloseWindow();
         }
     }
     else if (_currentInfo.BuildingType == CityBuildingType.TROOP)
     {
         // 快速生产士兵
         TroopBuildingInfo tbinfo = _currentInfo as TroopBuildingInfo;
         if (tbinfo != null && tbinfo.IsProducingSoldier())
         {
             CityManager.Instance.RequestQuickProduceSoldier(_currentInfo.EntityID, tbinfo.SoldierConfigID);
             CloseWindow();
         }
     }
     else
     {
         CloseWindow();
     }
 }
Beispiel #3
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);
            }
        }
    }
Beispiel #4
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();
        }
    }
Beispiel #5
0
    private void UpdateList()
    {
        List <SoldierConfig> list = new List <SoldierConfig>();

        foreach (var item in SoldierConfigLoader.Data)
        {
            list.Add(item.Value);
        }

        TrainBuildingInfo tbinfo = CityManager.Instance.GetBuildingByType(CityBuildingType.TRAIN) as TrainBuildingInfo;

        if (tbinfo == null)
        {
            return;                 // 尚未解锁校场
        }
        // 设置数据源
        _listView.MaxCount          = SoldierConfigLoader.Data.Count;
        _listView.OnListItemAtIndex = (index) => {
            SoldierConfig cfg   = list[index];
            int           level = CityManager.Instance.GetSoldierLevel(cfg.SoldierId);
            if (level <= 0)
            {
                // 未解锁兵种
                SoldierTrainNotHaveWidget go = _listView.CreateListItemWidget <SoldierTrainNotHaveWidget>(1);
                go.SetInfo(cfg.SoldierId);
                return(go);
            }
            else
            {
                SoldierLevelConfig cfgLevel = SoldierLevelConfigLoader.GetConfig(cfg.SoldierId, level, false);
                if (cfgLevel == null || tbinfo.IsInBuilding() || // 校场正在升级
                    cfgLevel.UpgradeMilitaryLevelDemand > tbinfo.Level || // 不能升级,校场等级不足
                    (tbinfo.IsTrainingSoldier() && tbinfo.TrainSoldierCfgID == cfg.SoldierId))
                {
                    // 不能升级或者正在升级
                    SoldierTrainNotHaveWidget go = _listView.CreateListItemWidget <SoldierTrainNotHaveWidget>(1);
                    go.SetInfo(cfg.SoldierId);
                    return(go);
                }
                else
                {
                    // 已解锁
                    SoldierTrainHaveWidget go = _listView.CreateListItemWidget <SoldierTrainHaveWidget>(0);
                    go.SetInfo(cfg.SoldierId);
                    return(go);
                }
            }
        };

        // 进行刷新
        _listView.Refresh();
    }
Beispiel #6
0
    public void SetInfo(BuildingInfo info)
    {
        _currentInfo = info;

        if (_currentInfo == null)
        {
            return;
        }

        bool refresh = false;

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

        if (refresh)
        {
            // 开启倒计时
            gameObject.SetActive(true);
            InvokeRepeating("UpdateTime", 0, 0.1f);
        }
        else
        {
            // 没有需要倒计时的
            gameObject.SetActive(false);
            CancelInvoke("UpdateTime");
        }
    }
Beispiel #7
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);
    }
    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;
                }
            }
        }
    }
    public override void OnClick()
    {
        int level = CityManager.Instance.GetSoldierLevel(_currentSoldierCfgID);

        TrainBuildingInfo tbinfo = CityManager.Instance.GetBuildingByType(CityBuildingType.TRAIN) as TrainBuildingInfo;

        if (tbinfo != null && tbinfo.IsTrainingSoldier())
        {
            UIUtil.ShowMsgFormat("UI_CITY_BUILDING_TRAIN_NOW");
            return;
        }

        // 最大等级
        if (SoldierLevelConfigLoader.GetConfig(_currentSoldierCfgID, level + 1, false) == null)
        {
            UIUtil.ShowMsgFormat("UI_CITY_BUILDING_TRAIN_MAX");
            return;
        }

        UIManager.Instance.OpenWindow <UICitySoldierUplevelView>(_currentSoldierCfgID);
    }
Beispiel #10
0
    public void OnClick()
    {
        if (_currentInfo == null)
        {
            // 如果尚未获得此建筑,建筑尚未解锁,则提示解锁等级
            BuildingConstConfig cfg = BuildingConstConfigLoader.GetConfig(_buildingCfgID);
            if (cfg != null)
            {
                UIUtil.ShowMsgFormat("MSG_CITY_BUILDING_UNLOCK", cfg.UnlockHomeLevelDemand);
            }
        }
        else
        {
            if (_currentInfo.IsInBuilding())
            {
                UIManager.Instance.OpenWindow <UICityBuildingMenuView>(_currentInfo, this, Parent);
                return;
            }

            if (_currentInfo.BuildingType == CityBuildingType.TRAIN)
            {
                TrainBuildingInfo tbinfo = _currentInfo as TrainBuildingInfo;
                if (tbinfo != null && tbinfo.IsTrainingSoldier())
                {
                    // 校场正在训练士兵
                    UIManager.Instance.OpenWindow <UICityTrainMenuView>(_currentInfo, this, Parent);
                    return;
                }
            }
            else if (_currentInfo.BuildingType == CityBuildingType.TROOP)
            {
                // 兵营正在生产士兵
                TroopBuildingInfo tbinfo = _currentInfo as TroopBuildingInfo;
                if (tbinfo != null && tbinfo.IsProducingSoldier())
                {
                    UIManager.Instance.OpenWindow <UICityBuildingMenuView>(_currentInfo, this, Parent);
                    return;
                }
            }

            // 正常逻辑
            switch (_currentInfo.BuildingType)
            {
            case CityBuildingType.HOUSE:
            case CityBuildingType.WOOD:
            case CityBuildingType.STONE:
                OnClickProduce();
                break;

            case CityBuildingType.MONEY_STORAGE:
            case CityBuildingType.STONE_STORAGE:
            case CityBuildingType.WOOD_STORAGE:
                OnClickBuilding();
                break;

            case CityBuildingType.PALACE:
                OnClickPalace();
                break;

            case CityBuildingType.TRAIN:
                OnClickTrain();
                break;

            case CityBuildingType.TROOP:
                OnClickTroop();
                break;

            case CityBuildingType.SMITHY:
                OnClickSmithy();
                break;

            case CityBuildingType.COLLEGE:
                OnClickCollege();
                break;
            }
        }
    }