public CityBuildingInfo(ECityBuildingKey key, int level) { ConstructionCompletionTimestamp = -1; Key = key; Level = level; }
private void ConstructionComplete(ECityBuildingKey buildingKey) { if (buildingKey == _buildingKey) { Setup(buildingKey); } }
public CBBaseData GetBuildingData(ECityBuildingKey buildingKey) { switch (buildingKey) { case ECityBuildingKey.TownHall: return(_townHall); case ECityBuildingKey.Barracks: return(_barracks); case ECityBuildingKey.Market: return(_market); case ECityBuildingKey.Warehouse: return(_warehouse); case ECityBuildingKey.Fort: return(_fort); case ECityBuildingKey.HeroesHall: return(_heroesHall); } return(null); }
public void Show(ECityBuildingKey buildingKey) { _buildingKey = buildingKey; //TODO: setup labels SetupLabel(); gameObject.SetActive(true); }
public CityBuildingInfo GetBuilding(ECityBuildingKey buildingKey) { for (int i = 0; i < _buildings.Length; i++) { if (_buildings[i].Key == buildingKey) { return _buildings[i]; } } return null; }
private void StartConstructionInternal(ECityBuildingKey buildingKey, int constructionCompleteTimestamp) { EventsAggregator.City.Broadcast<ECityBuildingKey>(ECityEvent.ConstructionStart, buildingKey); if (constructionCompleteTimestamp - Utils.UnixTimestamp > 0) { GameTimer.Instance.AddListener(constructionCompleteTimestamp - Utils.UnixTimestamp, delegate() { OnConstructionComplete(buildingKey); }); } else { OnConstructionComplete(buildingKey); } }
private void OnConstructionComplete(ECityBuildingKey buildingKey) { CityBuildingInfo bInfo = GetBuilding(buildingKey); bInfo.Level++; bInfo.ConstructionCompletionTimestamp = -1; EventsAggregator.City.Broadcast <ECityBuildingKey>(ECityEvent.ConstructionEnd, buildingKey); }
public void Show(ECityBuildingKey buildingKey) { _buildingKey = buildingKey; //TODO: setup labels SetupLabel(); gameObject.SetActive(true); }
private void UpdateBuildingImage(ECityBuildingKey buildingKey, bool isFirstLoad) { if (buildingKey == ECityBuildingKey.Idle) { return; } CBConstructionRequirement cr = CityConfig.Instance.GetBuildingData(buildingKey).GetConstructionRequirements(Global.Instance.Player.City.GetBuilding(buildingKey).Level); if (cr != null) { Sprite spriteResource = UIResourcesManager.Instance.GetResource <Sprite>(string.Format("{0}/{1}", GameConstants.Paths.UI_CITY_BUILDINGS_RESOURCES, cr.IconPath)); UICityBuildingIcon buildingIcon = null; if (spriteResource != null) { switch (buildingKey) { case ECityBuildingKey.TownHall: buildingIcon = _cbiTownHall; break; case ECityBuildingKey.Barracks: buildingIcon = _cbiBarracks; break; case ECityBuildingKey.Fort: buildingIcon = _cbiFort; break; case ECityBuildingKey.HeroesHall: buildingIcon = _cbiHeroesHall; break; case ECityBuildingKey.Market: buildingIcon = _cbiMarket; break; case ECityBuildingKey.Warehouse: buildingIcon = _cbiWarehouse; break; } if (buildingIcon != null) { if (!isFirstLoad && buildingIcon.ImgBuilding.sprite != null) { Sprite s = buildingIcon.ImgBuilding.sprite; buildingIcon.ImgBuilding.sprite = null; UIResourcesManager.Instance.FreeResource(s); } buildingIcon.ImgBuilding.sprite = spriteResource; } } } }
public CityBuildingInfo GetBuilding(ECityBuildingKey buildingKey) { for (int i = 0; i < _buildings.Length; i++) { if (_buildings[i].Key == buildingKey) { return(_buildings[i]); } } return(null); }
private void StartConstructionInternal(ECityBuildingKey buildingKey, int constructionCompleteTimestamp) { EventsAggregator.City.Broadcast <ECityBuildingKey>(ECityEvent.ConstructionStart, buildingKey); if (constructionCompleteTimestamp - Utils.UnixTimestamp > 0) { GameTimer.Instance.AddListener(constructionCompleteTimestamp - Utils.UnixTimestamp, delegate() { OnConstructionComplete(buildingKey); }); } else { OnConstructionComplete(buildingKey); } }
public void OnDestroy() { StopAllCoroutines(); _imgBuilding.sprite = null; if (CityConfig.Instance != null) { UIResourcesManager.Instance.FreeResource(string.Format("{0}/{1}", GameConstants.Paths.UI_CITY_BUILDINGS_RESOURCES, CityConfig.Instance.GetBuildingData(_buildingKey).GetConstructionRequirements(_buildngLevel).IconPath)); } _buildingKey = ECityBuildingKey.Idle; EventsAggregator.City.RemoveListener<ECityBuildingKey>(ECityEvent.ConstructionEnd, ConstructionComplete); }
public void OnDestroy() { StopAllCoroutines(); _imgBuilding.sprite = null; if (CityConfig.Instance != null) { UIResourcesManager.Instance.FreeResource(string.Format("{0}/{1}", GameConstants.Paths.UI_CITY_BUILDINGS_RESOURCES, CityConfig.Instance.GetBuildingData(_buildingKey).GetConstructionRequirements(_buildngLevel).IconPath)); } _buildingKey = ECityBuildingKey.Idle; EventsAggregator.City.RemoveListener <ECityBuildingKey>(ECityEvent.ConstructionEnd, ConstructionComplete); }
public void StartConstruction(ECityBuildingKey buildingKey) { CityBuildingInfo bInfo = GetBuilding(buildingKey); //check level if (bInfo.IsLevelMaxed) { return; } //check current building is not under construction if (bInfo.IsUnderCoustruction) { return; } CBConstructionRequirement requirements = CityConfig.Instance.GetBuildingData(buildingKey).GetConstructionRequirements(bInfo.Level + 1); //check resources requirements if (Global.Instance.Player.Resources.Credits < requirements.CostCredits || Global.Instance.Player.Resources.Minerals < requirements.CostMinerals || Global.Instance.Player.Resources.Fuel < requirements.CostFuel) { return; } //check necessary buildings requirements for (int i = 0; i < requirements.BuildingRequirements.Length; i++) { if (GetBuilding(requirements.BuildingRequirements[i].Key).Level < requirements.BuildingRequirements[i].Level) { return; } } //all conditions match: remove resources and start construction Global.Instance.Player.Resources.Credits -= requirements.CostCredits; Global.Instance.Player.Resources.Minerals -= requirements.CostMinerals; Global.Instance.Player.Resources.Fuel -= requirements.CostFuel; bInfo.ConstructionCompletionTimestamp = Utils.UnixTimestamp + requirements.BuildTime; StartConstructionInternal(buildingKey, bInfo.ConstructionCompletionTimestamp); }
public void StartConstruction(ECityBuildingKey buildingKey) { CityBuildingInfo bInfo = GetBuilding(buildingKey); //check level if (bInfo.IsLevelMaxed) { return; } //check current building is not under construction if (bInfo.IsUnderCoustruction) { return; } CBConstructionRequirement requirements = CityConfig.Instance.GetBuildingData(buildingKey).GetConstructionRequirements(bInfo.Level + 1); //check resources requirements if (Global.Instance.Player.Resources.Credits < requirements.CostCredits || Global.Instance.Player.Resources.Minerals < requirements.CostMinerals || Global.Instance.Player.Resources.Fuel < requirements.CostFuel) { return; } //check necessary buildings requirements for (int i = 0; i < requirements.BuildingRequirements.Length; i++) { if (GetBuilding(requirements.BuildingRequirements[i].Key).Level < requirements.BuildingRequirements[i].Level) { return; } } //all conditions match: remove resources and start construction Global.Instance.Player.Resources.Credits -= requirements.CostCredits; Global.Instance.Player.Resources.Minerals -= requirements.CostMinerals; Global.Instance.Player.Resources.Fuel -= requirements.CostFuel; bInfo.ConstructionCompletionTimestamp = Utils.UnixTimestamp + requirements.BuildTime; StartConstructionInternal(buildingKey, bInfo.ConstructionCompletionTimestamp); }
public void Setup(ECityBuildingKey buildingKey) { StopAllCoroutines(); if (_imgBuilding.sprite != null) { _imgBuilding.sprite = null; UIResourcesManager.Instance.FreeResource(string.Format("{0}/{1}", GameConstants.Paths.UI_CITY_BUILDINGS_RESOURCES, CityConfig.Instance.GetBuildingData(_buildingKey).GetConstructionRequirements(_buildngLevel).IconPath)); } _imgBuilding.enabled = false; _buildingKey = buildingKey; bool canUpgrade = false; CBBaseData buildingData = CityConfig.Instance.GetBuildingData(_buildingKey); if (buildingData != null) { CityBuildingInfo playerBuildingInfo = Global.Instance.Player.City.GetBuilding(_buildingKey); if (playerBuildingInfo != null) { _buildngLevel = playerBuildingInfo.Level; //setup image Sprite sprResource = UIResourcesManager.Instance.GetResource<Sprite>(string.Format("{0}/{1}", GameConstants.Paths.UI_CITY_BUILDINGS_RESOURCES, buildingData.GetConstructionRequirements(_buildngLevel).IconPath)); if (sprResource != null) { _imgBuilding.sprite = sprResource; _imgBuilding.enabled = true; } if (playerBuildingInfo.IsLevelMaxed) { //TODO: set correct text _lblCaption.text = "Building has maximum level"; _lblFuelCost.text = "-"; _lblMineralsCost.text = "-"; _lblCreditsCost.text = "-"; _lblTimeCost.text = "-"; } else { if (playerBuildingInfo.IsUnderCoustruction) { StartCoroutine(UpdateConstriuctionTime(playerBuildingInfo.ConstructionCompletionTimestamp - Utils.UnixTimestamp)); _lblFuelCost.text = "-"; _lblMineralsCost.text = "-"; _lblCreditsCost.text = "-"; _lblTimeCost.text = "-"; } else { _lblCaption.text = string.Format("Ready to upgrade {0} to {1} lvl?", GetBuildingName(), (_buildngLevel + 1)); CBConstructionRequirement nextLevelRequirenemts = buildingData.GetConstructionRequirements(_buildngLevel + 1); _lblFuelCost.text = nextLevelRequirenemts.CostFuel.ToString(); _lblMineralsCost.text = nextLevelRequirenemts.CostMinerals.ToString(); _lblCreditsCost.text = nextLevelRequirenemts.CostCredits.ToString(); _lblTimeCost.text = nextLevelRequirenemts.BuildTime == 0 ? "instant" : Utils.FormatTime(nextLevelRequirenemts.BuildTime); //TODO: setup correct "instant" text canUpgrade = true; if (Global.Instance.Player.Resources.Fuel < nextLevelRequirenemts.CostFuel) { _lblFuelCost.color = Color.red; canUpgrade = false; } else { _lblFuelCost.color = Color.white; } if (Global.Instance.Player.Resources.Minerals < nextLevelRequirenemts.CostMinerals) { _lblMineralsCost.color = Color.red; canUpgrade = false; } else { _lblMineralsCost.color = Color.white; } if (Global.Instance.Player.Resources.Credits < nextLevelRequirenemts.CostCredits) { _lblCreditsCost.color = Color.red; canUpgrade = false; } else { _lblCreditsCost.color = Color.white; } } } } } _btnUpgrade.interactable = canUpgrade; }
private void OnConstructionComplete(ECityBuildingKey buildingKey) { CityBuildingInfo bInfo = GetBuilding(buildingKey); bInfo.Level++; bInfo.ConstructionCompletionTimestamp = -1; EventsAggregator.City.Broadcast<ECityBuildingKey>(ECityEvent.ConstructionEnd, buildingKey); }
private void UpdateBuildingImage(ECityBuildingKey buildingKey, bool isFirstLoad) { if (buildingKey == ECityBuildingKey.Idle) { return; } CBConstructionRequirement cr = CityConfig.Instance.GetBuildingData(buildingKey).GetConstructionRequirements(Global.Instance.Player.City.GetBuilding(buildingKey).Level); if (cr != null) { Sprite spriteResource = UIResourcesManager.Instance.GetResource<Sprite>(string.Format("{0}/{1}", GameConstants.Paths.UI_CITY_BUILDINGS_RESOURCES, cr.IconPath)); UICityBuildingIcon buildingIcon = null; if (spriteResource != null) { switch (buildingKey) { case ECityBuildingKey.TownHall: buildingIcon = _cbiTownHall; break; case ECityBuildingKey.Barracks: buildingIcon = _cbiBarracks; break; case ECityBuildingKey.Fort: buildingIcon = _cbiFort; break; case ECityBuildingKey.HeroesHall: buildingIcon = _cbiHeroesHall; break; case ECityBuildingKey.Market: buildingIcon = _cbiMarket; break; case ECityBuildingKey.Warehouse: buildingIcon = _cbiWarehouse; break; } if (buildingIcon != null) { if (!isFirstLoad && buildingIcon.ImgBuilding.sprite != null) { Sprite s = buildingIcon.ImgBuilding.sprite; buildingIcon.ImgBuilding.sprite = null; UIResourcesManager.Instance.FreeResource(s); } buildingIcon.ImgBuilding.sprite = spriteResource; } } } }
public void Setup(ECityBuildingKey buildingKey) { StopAllCoroutines(); if (_imgBuilding.sprite != null) { _imgBuilding.sprite = null; UIResourcesManager.Instance.FreeResource(string.Format("{0}/{1}", GameConstants.Paths.UI_CITY_BUILDINGS_RESOURCES, CityConfig.Instance.GetBuildingData(_buildingKey).GetConstructionRequirements(_buildngLevel).IconPath)); } _imgBuilding.enabled = false; _buildingKey = buildingKey; bool canUpgrade = false; CBBaseData buildingData = CityConfig.Instance.GetBuildingData(_buildingKey); if (buildingData != null) { CityBuildingInfo playerBuildingInfo = Global.Instance.Player.City.GetBuilding(_buildingKey); if (playerBuildingInfo != null) { _buildngLevel = playerBuildingInfo.Level; //setup image Sprite sprResource = UIResourcesManager.Instance.GetResource <Sprite>(string.Format("{0}/{1}", GameConstants.Paths.UI_CITY_BUILDINGS_RESOURCES, buildingData.GetConstructionRequirements(_buildngLevel).IconPath)); if (sprResource != null) { _imgBuilding.sprite = sprResource; _imgBuilding.enabled = true; } if (playerBuildingInfo.IsLevelMaxed) { //TODO: set correct text _lblCaption.text = "Building has maximum level"; _lblFuelCost.text = "-"; _lblMineralsCost.text = "-"; _lblCreditsCost.text = "-"; _lblTimeCost.text = "-"; } else { if (playerBuildingInfo.IsUnderCoustruction) { StartCoroutine(UpdateConstriuctionTime(playerBuildingInfo.ConstructionCompletionTimestamp - Utils.UnixTimestamp)); _lblFuelCost.text = "-"; _lblMineralsCost.text = "-"; _lblCreditsCost.text = "-"; _lblTimeCost.text = "-"; } else { _lblCaption.text = string.Format("Ready to upgrade {0} to {1} lvl?", GetBuildingName(), (_buildngLevel + 1)); CBConstructionRequirement nextLevelRequirenemts = buildingData.GetConstructionRequirements(_buildngLevel + 1); _lblFuelCost.text = nextLevelRequirenemts.CostFuel.ToString(); _lblMineralsCost.text = nextLevelRequirenemts.CostMinerals.ToString(); _lblCreditsCost.text = nextLevelRequirenemts.CostCredits.ToString(); _lblTimeCost.text = nextLevelRequirenemts.BuildTime == 0 ? "instant" : Utils.FormatTime(nextLevelRequirenemts.BuildTime); //TODO: setup correct "instant" text canUpgrade = true; if (Global.Instance.Player.Resources.Fuel < nextLevelRequirenemts.CostFuel) { _lblFuelCost.color = Color.red; canUpgrade = false; } else { _lblFuelCost.color = Color.white; } if (Global.Instance.Player.Resources.Minerals < nextLevelRequirenemts.CostMinerals) { _lblMineralsCost.color = Color.red; canUpgrade = false; } else { _lblMineralsCost.color = Color.white; } if (Global.Instance.Player.Resources.Credits < nextLevelRequirenemts.CostCredits) { _lblCreditsCost.color = Color.red; canUpgrade = false; } else { _lblCreditsCost.color = Color.white; } } } } } _btnUpgrade.interactable = canUpgrade; }
public void Show(ECityBuildingKey buildingKey) { Show(); Setup(buildingKey); }
private void ConstructionComplete(ECityBuildingKey buildingKey) { if (buildingKey == _buildingKey) { Setup(buildingKey); } }
public CityBuildingInfo(ECityBuildingKey key, int level) { ConstructionCompletionTimestamp = -1; Key = key; Level = level; }
private void OnBuildingConstructionComplete(ECityBuildingKey buildingKey) { UpdateBuildingImage(buildingKey, false); }
public void Show(ECityBuildingKey buildingKey) { Show(); Setup(buildingKey); }
private void OnBuildingConstructionComplete(ECityBuildingKey buildingKey) { UpdateBuildingImage(buildingKey, false); }