void Building_OnSelected(object sender, EventArgs e) { RemoveConstructionPanel(); BaseConstruction construction = ((BaseConstruction)sender); constructionPanel = new ConstructionPanel(this.Game, construction); constructionPanel.StackOrder = stackOrder_slots + 15; UpdateConstructionPanelPosition(); AddChild(constructionPanel); constructionPanel.IsVisible = true; constructionPanel.Enabled = true; }
public void CreateBuilding(Slot slot, Construction building, int year) { BuildingsBaseProperties properties = new BuildingsBaseProperties(); BaseConstruction newBuilding; if (slot.ConstructionType != ConstructionType.Population) { newBuilding = new BaseConstruction(this.Game, slot.XSlotCenter, slot.YSlotCenter, false, false); } else { newBuilding = new BaseConstruction(this.Game, slot.XSlotCenter, slot.YSlotCenter, true, false); } newBuilding.ConstructionName = building; newBuilding.ConstructionYear = year; newBuilding.ConstructionType = slot.ConstructionType; newBuilding.ConstructionLifetime = properties.BuildingBaseProperties(building, year, 0, year).Lifetime; newBuilding.ConstructingPeriod = properties.BuildingBaseProperties(building, year, 0, year).ConstructingPeriod; newBuilding.DegradationPeriod = properties.BuildingBaseProperties(building, year, 0, year).DestructionPeriod; newBuilding.StackOrder = stackOrder_slots + 1; newBuilding.ChangeGraphics(); newBuilding.Slot = slot; AddChild(newBuilding); slot.CurrentConstruction = newBuilding; slot.MakeReservation(year, newBuilding.ConstructionLifetime, building); changesMade = true; GUI.ClearSelectedBuildingIcon(); newBuilding.OnSelected += new EventHandler(Building_OnSelected); RemoveConstructionPanel(); }
/// <summary> /// Attach a new building to a slot. /// </summary> /// <param name="slot"></param> private void SetNewBuilding(Slot slot) { BuildingsBaseProperties properties = new BuildingsBaseProperties(); BaseConstruction building; if (slot.ConstructionType != ConstructionType.Population) { building = new BaseConstruction(this.Game, slot.XSlotCenter, slot.YSlotCenter, false, false); } else { building = new BaseConstruction(this.Game, slot.XSlotCenter, slot.YSlotCenter, true, slot.GetReservation(GameManager.CurrentYear).IsPopulationUpgraded); } building.ConstructionName = slot.GetReservation(GameManager.CurrentYear).ConstructionName; building.ConstructionYear = slot.GetReservation(GameManager.CurrentYear).StartingYear; building.ConstructionLifetime = slot.GetReservation(GameManager.CurrentYear).Duration; building.ConstructionType = slot.ConstructionType; if (slot.GetReservation(GameManager.CurrentYear).IsDestroyed) { building.DegradationPeriod = 0; } else { building.DegradationPeriod = 1; //properties.BuildingBaseProperties(building.ConstructionName, building.ConstructionYear, building.UpgradeYear, GameManager.CurrentYear).DestructionPeriod; } building.ConstructingPeriod = properties.BuildingBaseProperties(building.ConstructionName, building.ConstructionYear, building.UpgradeYear, GameManager.CurrentYear).ConstructingPeriod; building.StackOrder = stackOrder_slots + 1; AddChild(building); building.ChangeGraphics(); slot.CurrentConstruction = building; building.Slot = slot; building.OnSelected += new EventHandler(Building_OnSelected); RemoveConstructionPanel(); }
public ConstructionPanel(Game game, BaseConstruction construction) : base(game) { frame = new Sprite(game, GraphicsCollection.GetPack("construction-panel-frame")); frame.StackOrder = 1; AddChild(frame); selectedConstruction = construction; if (Destroyable()) { destroy = new ConstructionPanelButton(game, ConstructionPanelButtonType.Destroy); destroy.StackOrder = 2; destroy.XRelative = buttonsXposition; destroy.YRelative = 45; destroy.OnMouseRelease += new EventHandler <Operation_Cronos.Input.MouseEventArgs>(destroy_OnMouseRelease); destroy.OnMouseOver += new EventHandler <ButtonEventArgs>(Button_OnMouseOver); destroy.OnMouseLeave += new EventHandler <ButtonEventArgs>(Button_OnMouseLeave); AddChild(destroy); } if (GeneralConstructionUpgradeable()) { upgrade = new ConstructionPanelButton(game, ConstructionPanelButtonType.Upgrade); upgrade.StackOrder = 2; upgrade.XRelative = buttonsXposition; upgrade.YRelative = 173; upgrade.OnMouseRelease += new EventHandler <Operation_Cronos.Input.MouseEventArgs>(upgrade_OnMouseRelease); upgrade.OnMouseOver += new EventHandler <ButtonEventArgs>(Button_OnMouseOver); upgrade.OnMouseLeave += new EventHandler <ButtonEventArgs>(Button_OnMouseLeave); AddChild(upgrade); textUpgradeCost = new SpriteText(game, FontsCollection.GetPack("Calibri 10").Font); textUpgradeCost.StackOrder = 2; textUpgradeCost.XRelative = 95; textUpgradeCost.YRelative = 225; textUpgradeCost.Tint = Color.Green; textUpgradeCost.Text = GetUpgradeText() + GetUpgradeCost().ToString(); AddChild(textUpgradeCost); } if (PopulationConstructionUpgradeable()) { upgrade = new ConstructionPanelButton(game, ConstructionPanelButtonType.Upgrade); upgrade.StackOrder = 2; upgrade.XRelative = buttonsXposition; upgrade.YRelative = 173; upgrade.OnMousePress += new EventHandler <Operation_Cronos.Input.MouseEventArgs>(upgrade_OnMouseRelease); upgrade.OnMouseOver += new EventHandler <ButtonEventArgs>(Button_OnMouseOver); upgrade.OnMouseLeave += new EventHandler <ButtonEventArgs>(Button_OnMouseLeave); AddChild(upgrade); textUpgradeCost = new SpriteText(game, FontsCollection.GetPack("Calibri 10").Font); textUpgradeCost.XRelative = 95; textUpgradeCost.YRelative = 225; textUpgradeCost.StackOrder = 2; textUpgradeCost.Tint = Color.Green; textUpgradeCost.Text = GetUpgradeText() + GetUpgradeCost().ToString(); AddChild(textUpgradeCost); } if (Repairable()) { repair = new ConstructionPanelButton(game, ConstructionPanelButtonType.Repair); repair.StackOrder = 2; repair.XRelative = buttonsXposition; repair.YRelative = 108; repair.OnMouseRelease += new EventHandler <Operation_Cronos.Input.MouseEventArgs>(repair_OnMouseRelease); repair.OnMouseOver += new EventHandler <ButtonEventArgs>(Button_OnMouseOver); repair.OnMouseLeave += new EventHandler <ButtonEventArgs>(Button_OnMouseLeave); AddChild(repair); textRepairCost = new SpriteText(game, FontsCollection.GetPack("Calibri 10").Font); textRepairCost.XRelative = 323; textRepairCost.YRelative = 225; textRepairCost.StackOrder = 2; textRepairCost.Tint = Color.Green; textRepairCost.Text = "Repair price: " + GetRepairCost().ToString(); AddChild(textRepairCost); } else //not repairable { if (AlreadyRepairedInCurrentYear()) { textRepairCost = new SpriteText(game, FontsCollection.GetPack("Calibri 10").Font); textRepairCost.XRelative = 323; textRepairCost.YRelative = 225; textRepairCost.Tint = Color.Green; textRepairCost.StackOrder = 2; textRepairCost.Text = "Repaired this year"; AddChild(textRepairCost); } } close = new ConstructionPanelButton(game, ConstructionPanelButtonType.Close); close.StackOrder = 2; close.XRelative = 430; close.YRelative = 7; close.OnMouseRelease += new EventHandler <Operation_Cronos.Input.MouseEventArgs>(close_OnMouseRelease); AddChild(close); textBuildingNameAndStage = new SpriteText(game, FontsCollection.GetPack("Calibri 10").Font); textBuildingNameAndStage.XRelative = 95; textBuildingNameAndStage.YRelative = 20; textBuildingNameAndStage.Tint = Color.Gray; textBuildingNameAndStage.StackOrder = 2; textBuildingNameAndStage.Text = GetDescriptionFromEnum(selectedConstruction.ConstructionName, 0); if (selectedConstruction.ConstructionType != ConstructionType.Population) { textBuildingNameAndStage.Text += " - " + GetDescriptionFromEnum((selectedConstruction.Slot.GetReservation(GameManager.CurrentYear).Status(GameManager.CurrentYear)), 0); } AddChild(textBuildingNameAndStage); textGeneralInfo = new SpriteText(game, FontsCollection.GetPack("Calibri 10").Font); textGeneralInfo.XRelative = 95; textGeneralInfo.YRelative = 60; textGeneralInfo.StackOrder = 2; textGeneralInfo.Tint = Color.White; textGeneralInfo.Text = GetConstructionYear() + "\n" + GetLifetimeLeft() + "\n" + GetConstructionParameters(); AddChild(textGeneralInfo); selectedConstruction.SelectConstruction = true; if (selectedConstruction.ConstructionType == ConstructionType.Education || selectedConstruction.ConstructionType == ConstructionType.Health || selectedConstruction.ConstructionType == ConstructionType.Population || selectedConstruction.ConstructionType == ConstructionType.Energy) { SoundManager.PlaySound((Sounds)Enum.Parse(typeof(Sounds), selectedConstruction.ConstructionType.ToString())); } else { SoundManager.PlaySound((Sounds)Enum.Parse(typeof(Sounds), selectedConstruction.ConstructionName.ToString())); } }
public void CreateBuilding(Slot slot, Construction building, int year) { BuildingsBaseProperties properties = new BuildingsBaseProperties(); BaseConstruction newBuilding; if (slot.ConstructionType != ConstructionType.Population) newBuilding = new BaseConstruction(this.Game, slot.XSlotCenter, slot.YSlotCenter, false, false); else newBuilding = new BaseConstruction(this.Game, slot.XSlotCenter, slot.YSlotCenter, true, false); newBuilding.ConstructionName = building; newBuilding.ConstructionYear = year; newBuilding.ConstructionType = slot.ConstructionType; newBuilding.ConstructionLifetime = properties.BuildingBaseProperties(building, year, 0, year).Lifetime; newBuilding.ConstructingPeriod = properties.BuildingBaseProperties(building, year, 0, year).ConstructingPeriod; newBuilding.DegradationPeriod = properties.BuildingBaseProperties(building, year, 0, year).DestructionPeriod; newBuilding.StackOrder = stackOrder_slots + 1; newBuilding.ChangeGraphics(); newBuilding.Slot = slot; AddChild(newBuilding); slot.CurrentConstruction = newBuilding; slot.MakeReservation(year, newBuilding.ConstructionLifetime, building); changesMade = true; GUI.ClearSelectedBuildingIcon(); newBuilding.OnSelected += new EventHandler(Building_OnSelected); RemoveConstructionPanel(); }