コード例 #1
0
    private void OnClickProduce()
    {
        ProduceBuildingInfo pbinfo = _currentInfo as ProduceBuildingInfo;

        if (pbinfo == null)
        {
            return;
        }

        if (!pbinfo.IsProduceFull() && pbinfo.GetCurrentProduceValue() > 0 && !pbinfo.IsInBuilding())
        {
            // 如果资源未满,并且有产出 则请求收货
            Log.Info("收集资源: {0}", pbinfo.GetCurrentProduceValue());
            CityManager.Instance.RequestHarvest(_currentInfo.EntityID);

            if (pbinfo.BuildingType == CityBuildingType.WOOD)
            {
                EventDispatcher.TriggerEvent(EventID.EVENT_CITY_AWARD_WOOD);
            }
            else if (pbinfo.BuildingType == CityBuildingType.STONE)
            {
                EventDispatcher.TriggerEvent(EventID.EVENT_CITY_AWARD_STONE);
            }
        }
        else
        {
            // 点击界面,则隐藏资源收获图标
            EventDispatcher.TriggerEvent(EventID.EVENT_CITY_BUILDING_SHOW_PRODUCE_PANEL, pbinfo.EntityID, false);

            // 如果没有产出,则打开信息界面,此为升级等功能入口
            UIManager.Instance.OpenWindow <UICityBuildingUplevelView>(_currentInfo);
        }
    }
コード例 #2
0
    // 执行收获逻辑
    private void DoHarvest(long buildingID, int value)
    {
        ProduceBuildingInfo info = GetBuilding(buildingID) as ProduceBuildingInfo;

        if (info == null)
        {
            return;
        }

        // 实际增加资产
        switch (info.BuildingType)
        {
        case CityBuildingType.HOUSE:
            UserManager.Instance.Money += value;
            UIUtil.AddFloatingMsg(Str.Get("UI_CITY_BUILDING_MONEY") + "+" + value.ToString());
            break;

        case CityBuildingType.WOOD:
            UserManager.Instance.Wood += value;
            UIUtil.AddFloatingMsg(Str.Get("UI_CITY_BUILDING_WOOD") + "+" + value.ToString());
            break;

        case CityBuildingType.STONE:
            UserManager.Instance.Stone += value;
            UIUtil.AddFloatingMsg(Str.Get("UI_CITY_BUILDING_STONE") + "+" + value.ToString());
            break;
        }

        // 收获完清理建筑的产值
        info.ClearProduceValue();
    }
コード例 #3
0
    public void OnClick()
    {
        if (gameObject.activeInHierarchy)
        {
            _currentInfo.LastClickTime.SetTime(0);
        }

        Show(false);

        ProduceBuildingInfo pbinfo = _currentInfo as ProduceBuildingInfo;

        if (pbinfo == null)
        {
            return;
        }

        if (!pbinfo.IsProduceFull() && pbinfo.GetCurrentProduceValue() > 0)
        {
            // 如果资源未满,并且有产出 则请求收货
            CityManager.Instance.RequestHarvest(_currentInfo.EntityID);
            if (pbinfo.BuildingType == CityBuildingType.WOOD)
            {
                EventDispatcher.TriggerEvent(EventID.EVENT_CITY_AWARD_WOOD);
            }
            else if (pbinfo.BuildingType == CityBuildingType.STONE)
            {
                EventDispatcher.TriggerEvent(EventID.EVENT_CITY_AWARD_STONE);
            }
        }
        else
        {
            // 资源已满
            UIUtil.ShowMsgFormat("UI_MSG_RES_FULL", _currentInfo.GetContainerBuildingName(), _currentInfo.GetResName());
        }
    }
コード例 #4
0
    public void SetInfo(BuildingInfo info)
    {
        _currentInfo = info as ProduceBuildingInfo;

        if (_currentInfo == null)
        {
            return;
        }

        if (_currentInfo.BuildingType == CityBuildingType.HOUSE)
        {
            _imageIcon.sprite = ResourceManager.Instance.GetResIcon(ResourceType.MONEY);
        }
        else if (_currentInfo.BuildingType == CityBuildingType.WOOD)
        {
            _imageIcon.sprite = ResourceManager.Instance.GetResIcon(ResourceType.WOOD);
        }
        else if (_currentInfo.BuildingType == CityBuildingType.STONE)
        {
            _imageIcon.sprite = ResourceManager.Instance.GetResIcon(ResourceType.STONE);
        }

        // 点击会隐藏资源图标,无论有没有收集完毕,即使没有收集完毕,在一定时间内也不会重复显示图标
        if (_currentInfo.IsInBuilding() || _currentInfo.LastClickTime.IsValid() && _currentInfo.LastClickTime.GetTime() <= GameConfig.PRODUCE_REWARD_INTERVAL)
        {
            gameObject.SetActive(false);
        }
        else
        {
            gameObject.SetActive(_currentInfo.GetCurrentProduceValue() > 0);
        }

        UpdateIconColor();
    }
コード例 #5
0
    public void OnClickProduceIcon()
    {
        ProduceBuildingInfo pbinfo = _currentInfo as ProduceBuildingInfo;

        if (pbinfo == null)
        {
            return;
        }

        if (!pbinfo.IsProduceFull() && pbinfo.GetCurrentProduceValue() > 0)
        {
            // 如果资源未满,并且有产出 则请求收货
            CityManager.Instance.RequestHarvest(_currentInfo.EntityID);
        }
        else
        {
            // 资源已满
            UIUtil.ShowMsgFormat("UI_MSG_RES_FULL", _currentInfo.GetContainerBuildingName(), _currentInfo.GetResName());
        }
    }
コード例 #6
0
    public void UpdatePanel()
    {
        BuildingInfo        info   = CityManager.Instance.GetBuildingByConfigID(_buildingCfgID);
        ProduceBuildingInfo pbinfo = info as ProduceBuildingInfo;

        if (pbinfo == null)
        {
            return;
        }

        if (_produceInfoPanel != null)
        {
            if (!_produceInfoPanel.gameObject.activeInHierarchy && !info.IsInBuilding() && pbinfo.GetCurrentProduceValue() > 0 && (!_currentInfo.LastClickTime.IsValid() || pbinfo.LastClickTime.GetTime() >= GameConfig.PRODUCE_REWARD_INTERVAL))
            {
                _produceInfoPanel.Show(true);
            }

            _produceInfoPanel.UpdateIconColor();
        }
    }
コード例 #7
0
    private void SetInfo(BuildingInfo info)
    {
        _currentInfo = info;
        if (_currentInfo == null)
        {
            return;
        }

        _title.text           = info.Cfg.BuildingName;
        _txtLevel.text        = Str.Format("UI_LEVEL", info.Level);
        _desc.text            = info.Cfg.BuildingDescription;
        _buildingImage.sprite = ResourceManager.Instance.GetBuildingIcon(info.ConfigID);

        // 如果建筑正在升级,不显示升级按钮
        _btnLevelUp.gameObject.SetActive(!_currentInfo.IsInBuilding());

        _maxContainValue.text = _currentInfo.GetMaxContainValue().ToString();
        _levelupTime.text     = Utils.GetCountDownString(Utils.GetSeconds(_currentInfo.CfgLevel.UpgradeTime));

        switch (_currentInfo.BuildingType)
        {
        case CityBuildingType.HOUSE:
            _imageMaxContain.sprite = ResourceManager.Instance.GetResIcon(ResourceType.MONEY);
            _imageProduce.sprite    = ResourceManager.Instance.GetResIcon(ResourceType.MONEY);
            break;

        case CityBuildingType.STONE:
            _imageMaxContain.sprite = ResourceManager.Instance.GetResIcon(ResourceType.STONE);
            _imageProduce.sprite    = ResourceManager.Instance.GetResIcon(ResourceType.STONE);
            break;

        case CityBuildingType.WOOD:
            _imageMaxContain.sprite = ResourceManager.Instance.GetResIcon(ResourceType.WOOD);
            _imageProduce.sprite    = ResourceManager.Instance.GetResIcon(ResourceType.WOOD);
            break;

        case CityBuildingType.MONEY_STORAGE:
            _imageMaxContain.sprite = ResourceManager.Instance.GetResIcon(ResourceType.MONEY);
            break;

        case CityBuildingType.STONE_STORAGE:
            _imageMaxContain.sprite = ResourceManager.Instance.GetResIcon(ResourceType.STONE);
            break;

        case CityBuildingType.WOOD_STORAGE:
            _imageMaxContain.sprite = ResourceManager.Instance.GetResIcon(ResourceType.WOOD);
            break;
        }

        ProduceBuildingInfo pbinfo = _currentInfo as ProduceBuildingInfo;

        if (pbinfo != null)
        {
            _produceValue.text = pbinfo.GetUnitProduceValue().ToString();

            if (pbinfo.IsProduceFull())
            {
                // 资源满了,提示升级建筑
                _txtFull.text = Str.Format("UI_MSG_RES_FULL", _currentInfo.GetContainerBuildingName(), _currentInfo.GetResName());
                _txtFull.gameObject.SetActive(true);
            }
            else
            {
                _txtFull.gameObject.SetActive(false);
            }

            _txtMaxContain.text = Str.Get("UI_CITY_BUILDING_MAX_CONTAIN");
            _txtProduceText.gameObject.SetActive(true);
        }
        else
        {
            _txtProduceText.gameObject.SetActive(false);
            _txtFull.gameObject.SetActive(false);
            _txtMaxContain.text = Str.Get("UI_CITY_BUILDING_CONTAIN");
        }
    }
コード例 #8
0
    private void SetInfo(BuildingInfo info)
    {
        _currentInfo = info;
        if (_currentInfo == null)
        {
            return;
        }

        _title.text           = _currentInfo.Cfg.BuildingName;// string.Format(Str.Get("UI_CITY_BUILDING_LEVELUP"), _currentInfo.Cfg.BuildingName, _currentInfo.Level + 1);
        _maxContainValue.text = _currentInfo.GetMaxContainValue().ToString();
        _txtLevel.text        = Str.Format("UI_LEVEL", info.Level);
        _desc.text            = _currentInfo.Cfg.BuildingDescription;
        _buildingImage.sprite = ResourceManager.Instance.GetBuildingIcon(info.ConfigID);

        if (info.BuildingType == CityBuildingType.TROOP)
        {
            // 如果是兵营的话 显示最大人口
            _maxContainText.text = Str.Get("UI_CITY_BUILDING_MAX_SPACE");
        }
        else
        {
            // 显示最大容量
            _maxContainText.text = Str.Get("UI_CITY_BUILDING_MAX_CONTAIN");
        }

        int maxContainAddValue = _currentInfo.GetNextMaxContainValue();

        if (maxContainAddValue > 0)
        {
            _maxContainAddValue.gameObject.SetActive(true);
            _maxContainAddValue.text = string.Format("(+{0})", maxContainAddValue);
        }
        else
        {
            _maxContainAddValue.gameObject.SetActive(false);
        }

        _levupTime.text = Utils.GetCountDownString(_currentInfo.GetLevelUpCD());

        int quickCost = _currentInfo.GetQuickLevelUpCost(false);

        _levupNowCost.text  = quickCost.ToString();
        _levupNowCost.color = UserManager.Instance.Gold < quickCost ? Color.red : Color.white;

        _levupStoneCost.text  = _currentInfo.CfgLevel.CostStone.ToString();
        _levupStoneCost.color = UserManager.Instance.Stone < _currentInfo.CfgLevel.CostStone ? Color.red : Color.white;
        _levupWoodCost.text   = _currentInfo.CfgLevel.CostWood.ToString();
        _levupWoodCost.color  = UserManager.Instance.Wood < _currentInfo.CfgLevel.CostWood ? Color.red : Color.white;

        switch (_currentInfo.BuildingType)
        {
        case CityBuildingType.HOUSE:
            _maxContainImage.sprite = ResourceManager.Instance.GetResIcon(ResourceType.MONEY);
            _produceImage.sprite    = ResourceManager.Instance.GetResIcon(ResourceType.MONEY);
            break;

        case CityBuildingType.STONE:
            _maxContainImage.sprite = ResourceManager.Instance.GetResIcon(ResourceType.STONE);
            _produceImage.sprite    = ResourceManager.Instance.GetResIcon(ResourceType.STONE);
            break;

        case CityBuildingType.WOOD:
            _maxContainImage.sprite = ResourceManager.Instance.GetResIcon(ResourceType.WOOD);
            _produceImage.sprite    = ResourceManager.Instance.GetResIcon(ResourceType.WOOD);
            break;

        case CityBuildingType.MONEY_STORAGE:
            _maxContainImage.sprite = ResourceManager.Instance.GetResIcon(ResourceType.MONEY);
            break;

        case CityBuildingType.STONE_STORAGE:
            _maxContainImage.sprite = ResourceManager.Instance.GetResIcon(ResourceType.STONE);
            break;

        case CityBuildingType.WOOD_STORAGE:
            _maxContainImage.sprite = ResourceManager.Instance.GetResIcon(ResourceType.WOOD);
            break;

        case CityBuildingType.TROOP:
            _maxContainImage.sprite = ResourceManager.Instance.GetResIcon(ResourceType.SOLDIER);
            break;
        }
        _maxContainImage.SetNativeSize();
        _produceImage.SetNativeSize();

        ProduceBuildingInfo pbinfo = _currentInfo as ProduceBuildingInfo;

        if (pbinfo != null)
        {
            // 资源生产建筑
            _productValue.text = pbinfo.GetUnitProduceValue().ToString();

            int produceAddValue = pbinfo.GetNextProduceValue();
            if (produceAddValue > 0)
            {
                _productAddValue.gameObject.SetActive(true);
                _productAddValue.text = string.Format("(+{0})", produceAddValue);
            }
            else
            {
                _productAddValue.gameObject.SetActive(false);
            }
        }
        else
        {
            _txtProductText.gameObject.SetActive(false);
            _levelUpText.transform.position = _txtProductText.transform.position;
        }
    }