public static Building Load(XElement xElement, Game game) { Building building = new Building(game); building.name = xElement.Element("Name").Value; building.handle = xElement.Attribute("Handle").Value; building.initiallyAvailable = (xElement.Element("InitiallyAvailable") != null); building.requirements = Requirements.Load(xElement.Element("Requirements")); building.buildingIcon = game.Content.Load<Texture2D>(xElement.Element("Icon").Value); building.size.X = Int32.Parse(xElement.Element("Size").Value.Substring(0, xElement.Element("Size").Value.IndexOf("x"))); building.size.Y = Int32.Parse(xElement.Element("Size").Value.Substring(xElement.Element("Size").Value.IndexOf("x") + 1)); building.description = xElement.Element("Description").Value; string[] validTerrainTypes = xElement.Element("Requirements").Element("Terrain").Value.Split(new char[] { ',' }); foreach (string terrainType in validTerrainTypes) building.validTerrainTypes |= (Terrain)Enum.Parse(typeof(Terrain), terrainType); foreach (XElement textureElement in xElement.Element("Textures").Elements("Texture")) { Color color = Color.TransparentWhite; if (textureElement.Attribute("Color") != null) { string[] pieces = textureElement.Attribute("Color").Value.Split(','); color = new Color(int.Parse(pieces[0]), int.Parse(pieces[1]), int.Parse(pieces[2])); } building.buildingTextures.Add(new Vector2(int.Parse(textureElement.Attribute("X").Value), int.Parse(textureElement.Attribute("Y").Value)), new Texture2DReference(game.Content.Load<Texture2D>(textureElement.Value), color)); } building.benefits = Benefits.Load(xElement.Element("Benefits"), building.handle); return building; }
private void OpenBuildingDialog(Building building) { ScreenItemDialog buildingDialog = new ScreenItemDialog(controls.Game, skin, building.Name, true); buildingDialog.AttachedInformation = building; ScreenItemImage buildingIcon = new ScreenItemImage(controls.Game, skin, 5, 5, building.BuildingIcon); buildingDialog.Items.Add(buildingIcon); ScreenItemLabel buildingDescription = new ScreenItemLabel(controls.Game, skin, 10 + (int)buildingIcon.Width, 5, 10, 240, building.Description); buildingDialog.Items.Add(buildingDescription); ScreenItemButton placeBuilding = new ScreenItemButton(controls.Game, skin, 5 + (buildingIcon.Width - 75) / 2, buildingIcon.Height + 5, 75, 20, "Build"); placeBuilding.Enabled = building.Requirements.AreMet(_playerGame); placeBuilding.OnClick += delegate(ScreenItem item, MouseEventArgs args) { Map currentMap = null; switch (_currentMap) { case SimulationScreenMap.Urban: currentMap = _playerGame.UrbanMap; break; case SimulationScreenMap.Country: currentMap = _playerGame.CountryMap; break; case SimulationScreenMap.Ocean: currentMap = _playerGame.OceanMap; break; } buildingDialog.Close(); currentMap.BeginBuildingPlacement(building); }; buildingDialog.Items.Add(placeBuilding); // Requirements float requirementsHeight = (int)buildingDescription.Height + 10; ScreenItemLabel requirementsLabel = new ScreenItemLabel(controls.Game, skin, 20 + (int)buildingIcon.Width, (int)requirementsHeight, 13, "Requirements"); requirementsHeight += requirementsLabel.Height; buildingDialog.Items.Add(requirementsLabel); if (building.Requirements.Money > 0) { ScreenItemLabel requirementsMoneyLabel = new ScreenItemLabel(controls.Game, skin, 36 + (int)buildingIcon.Width, (int)requirementsHeight, 10, "$" + building.Requirements.Money.ToString()); requirementsMoneyLabel.FontColor = (building.Requirements.Money <= _playerGame.Money ? Color.Black : Color.Red); ScreenItemImage requirementsMoneyIcon = new ScreenItemImage(controls.Game, skin, 20 + (int)buildingIcon.Width, (int)requirementsHeight, 16, 16, "MoneyIcon"); requirementsHeight += requirementsMoneyLabel.Height; requirementsMoneyIcon.Tooltip = "Money"; requirementsMoneyLabel.Tooltip = "Money"; buildingDialog.Items.Add(requirementsMoneyLabel); buildingDialog.Items.Add(requirementsMoneyIcon); } if (building.Requirements.Food > 0) { ScreenItemLabel requirementsFoodLabel = new ScreenItemLabel(controls.Game, skin, 36 + (int)buildingIcon.Width, (int)requirementsHeight, 10, building.Requirements.Food.ToString() + " bushels"); requirementsFoodLabel.FontColor = (building.Requirements.Food <= _playerGame.Food ? Color.Black : Color.Red); ScreenItemImage requirementsFoodIcon = new ScreenItemImage(controls.Game, skin, 20 + (int)buildingIcon.Width, (int)requirementsHeight, 16, 16, "FoodIcon"); requirementsHeight += requirementsFoodLabel.Height; requirementsFoodIcon.Tooltip = "Food"; requirementsFoodLabel.Tooltip = "Food"; buildingDialog.Items.Add(requirementsFoodLabel); buildingDialog.Items.Add(requirementsFoodIcon); } if (building.Requirements.Oil > 0) { ScreenItemLabel requirementsOilLabel = new ScreenItemLabel(controls.Game, skin, 36 + (int)buildingIcon.Width, (int)requirementsHeight, 10, building.Requirements.Oil.ToString() + " barrels"); requirementsOilLabel.FontColor = (building.Requirements.Oil <= _playerGame.Oil ? Color.Black : Color.Red); ScreenItemImage requirementsOilIcon = new ScreenItemImage(controls.Game, skin, 20 + (int)buildingIcon.Width, (int)requirementsHeight, 16, 16, "OilIcon"); requirementsHeight += requirementsOilLabel.Height; requirementsOilIcon.Tooltip = "Oil"; requirementsOilLabel.Tooltip = "Oil"; buildingDialog.Items.Add(requirementsOilLabel); buildingDialog.Items.Add(requirementsOilIcon); } if (building.Requirements.Electricity > 0) { ScreenItemLabel requirementsElectricityLabel = new ScreenItemLabel(controls.Game, skin, 36 + (int)buildingIcon.Width, (int)requirementsHeight, 10, building.Requirements.Electricity.ToString() + " kwh"); requirementsElectricityLabel.FontColor = (building.Requirements.Electricity <= _playerGame.Electricity - _playerGame.ConsumedElectricity ? Color.Black : Color.Red); ScreenItemImage requirementsElectricityIcon = new ScreenItemImage(controls.Game, skin, 20 + (int)buildingIcon.Width, (int)requirementsHeight, 16, 16, "ElectricityIcon"); requirementsHeight += requirementsElectricityLabel.Height; requirementsElectricityIcon.Tooltip = "Electricity"; requirementsElectricityLabel.Tooltip = "Electricity"; buildingDialog.Items.Add(requirementsElectricityLabel); buildingDialog.Items.Add(requirementsElectricityIcon); } // Benefits float benefitsHeight = (int)buildingDescription.Height + 10; ScreenItemLabel benefitsLabel = new ScreenItemLabel(controls.Game, skin, 160 + (int)buildingIcon.Width, (int)benefitsHeight, 13, "Outputs"); benefitsHeight += benefitsLabel.Height; buildingDialog.Items.Add(benefitsLabel); if (building.Benefits.Income.Value > 0) { ScreenItemLabel benefitsIncomeLabel = new ScreenItemLabel(controls.Game, skin, 176 + (int)buildingIcon.Width, (int)benefitsHeight, 10, "$" + building.Benefits.Income.Value.ToString() + " / minute"); ScreenItemImage benefitsIncomeIcon = new ScreenItemImage(controls.Game, skin, 160 + (int)buildingIcon.Width, (int)benefitsHeight, 16, 16, "MoneyIcon"); benefitsHeight += benefitsIncomeLabel.Height; benefitsIncomeIcon.Tooltip = "Income"; benefitsIncomeLabel.Tooltip = "Income"; buildingDialog.Items.Add(benefitsIncomeLabel); buildingDialog.Items.Add(benefitsIncomeIcon); } if (building.Benefits.Food.Value > 0) { ScreenItemLabel benefitsFoodLabel = new ScreenItemLabel(controls.Game, skin, 176 + (int)buildingIcon.Width, (int)benefitsHeight, 10, building.Benefits.Food.Value.ToString() + " bushels / minute"); ScreenItemImage benefitsFoodIcon = new ScreenItemImage(controls.Game, skin, 160 + (int)buildingIcon.Width, (int)benefitsHeight, 16, 16, "FoodIcon"); benefitsHeight += benefitsFoodLabel.Height; benefitsFoodIcon.Tooltip = "Food"; benefitsFoodLabel.Tooltip = "Food"; buildingDialog.Items.Add(benefitsFoodLabel); buildingDialog.Items.Add(benefitsFoodIcon); } if (building.Benefits.Oil.Value > 0) { ScreenItemLabel benefitsOilLabel = new ScreenItemLabel(controls.Game, skin, 176 + (int)buildingIcon.Width, (int)benefitsHeight, 10, building.Benefits.Oil.Value.ToString() + " barrels / minute"); ScreenItemImage benefitsOilIcon = new ScreenItemImage(controls.Game, skin, 160 + (int)buildingIcon.Width, (int)benefitsHeight, 16, 16, "OilIcon"); benefitsHeight += benefitsOilLabel.Height; benefitsOilIcon.Tooltip = "Oil"; benefitsOilLabel.Tooltip = "Oil"; buildingDialog.Items.Add(benefitsOilLabel); buildingDialog.Items.Add(benefitsOilIcon); } if (building.Benefits.Electricity.Value > 0) { ScreenItemLabel benefitsElectricityLabel = new ScreenItemLabel(controls.Game, skin, 176 + (int)buildingIcon.Width, (int)benefitsHeight, 10, building.Benefits.Electricity.Value.ToString() + " kwh"); ScreenItemImage benefitsElectricityIcon = new ScreenItemImage(controls.Game, skin, 160 + (int)buildingIcon.Width, (int)benefitsHeight, 16, 16, "ElectricityIcon"); benefitsHeight += benefitsElectricityLabel.Height; benefitsElectricityIcon.Tooltip = "Electricity"; benefitsElectricityLabel.Tooltip = "Electricity"; buildingDialog.Items.Add(benefitsElectricityLabel); buildingDialog.Items.Add(benefitsElectricityIcon); } controls.OpenDialog = buildingDialog; buildingDialog.Closed += delegate() { controls.OpenDialog = null; }; }
private void BuildingPlacementEnds(Building building, Map map) { foreach (ScreenItemButton button in controls.BuildingListButtons) button.Enabled = true; controls.BuildingDropdown.Enabled = true; controls.TechnologyList.Enabled = true; ShiftBuildingList(0); _playerGame.Detract(building.Requirements); _playerGame.ApplyBenefits(building.Benefits); }
private void BuildingSelected(Building building, Map map) { controls.SelectedBuilding.Building = building; }
private void BuildingPlacementBegins(Building building, Map map) { foreach (ScreenItemButton button in controls.BuildingListButtons) button.Enabled = false; controls.BuildingDropdown.Enabled = false; controls.TechnologyList.Enabled = false; controls.BuildingListRight.Enabled = false; controls.BuildingListLeft.Enabled = false; }