public void SetChoices(BaseStructure structure1, BaseStructure structure2) { CurrentSelectionModeState = SelectionMode.Double; towerType1 = structure1.GetType(); towerType2 = structure2.GetType(); StructureChoice1.DisplayChoice(structure1); StructureChoice2.DisplayChoice(structure2); StructureChoice1.HasEvents = true; StructureChoice1.ExposeChildrenEvents = false; StructureChoice2.HasEvents = true; StructureChoice2.ExposeChildrenEvents = false; structure1.X = StructureChoice1.X; structure1.Y = StructureChoice1.Y - 260; structure1.Z = 2; structure1.IsBeingPlaced = false; structure2.X = StructureChoice2.X; structure2.Y = StructureChoice2.Y - 260; structure2.Z = 2; structure2.IsBeingPlaced = false; StructureChoice1.Click += StructureChoice1_Click; StructureChoice2.Click += StructureChoice2_Click; ConfirmButton.Click += (unused) => ConfirmTowerSelection?.Invoke(this); }
public StructureInfoSaveState(BaseStructure structure) { this.StructureName = structure.DisplayName; this.AttackDamageType = structure.AttackDamage.ToString(); this.MinRange = structure.MinimumRangeRadius.ToString(); this.MaxRange = structure.RangedRadius.ToString(); this.AttackSpeed = structure.SecondsBetweenFiring.ToString() + " sec"; this.PointOrSplash = structure.HasSplashDamage ? "Group" : "Single"; SatoshiCost = structure.SatoshiCost; SatoshiCostString = structure.SatoshiCost.ToString(); this.TowerType = structure.GetType(); }
public void DisplayChoice(BaseStructure structure) { structureShown = structure; structureShown.RangePreviewSprite.Visible = false; StructureName = structureShown.DisplayName; SatoshiCost = structureShown.SatoshiCost.ToString(); AttackDamageType.ResistanceText = structure.AttackDamage.ToString(); MinRange.AttributeText = structure.MinimumRangeRadius.ToString(); MaxRange.AttributeText = structure.RangedRadius.ToString(); AttackSpeed.AttributeText = structure.SecondsBetweenFiring.ToString() + " sec"; PointOrSplash.AttributeText = structure.HasSplashDamage ? "Group" : "Single"; SetIcon(structure.GetType()); CurrentUpgradeAvailabilityState = UpgradeAvailability.NotAvailable; CurrentCostInfoState = CostInfo.Shown; }
public void SetOnlyChoice(BaseStructure structure1) { CurrentSelectionModeState = SelectionMode.Single; towerType1 = structure1.GetType(); StructureTypeChosen = towerType1; StructureChoice1.DisplayChoice(structure1); StructureChoice1.HasEvents = false; StructureChoice1.ExposeChildrenEvents = false; structure1.X = StructureChoice1.X; structure1.Y = StructureChoice1.Y - 260; structure1.Z = 2; structure1.IsBeingPlaced = false; ConfirmButton.Click += (unused) => ConfirmTowerSelection?.Invoke(this); ConfirmButton.Visible = true; }
private void SetDisplayFor(BaseStructure structure, int currentSatoshis, bool allowUpgrades) { Visible = true; FirstUpgradeCost = (int)(structure.SatoshiCost * 0.5); SecondUpgradeCost = (int)(structure.SatoshiCost * 1.25); FinalUpgradeCost = (int)(structure.SatoshiCost * 2); structureShown = structure; var minMaxX = (CameraZoomManager.OriginalOrthogonalWidth - GetAbsoluteWidth()) / 2; var minMaxY = (CameraZoomManager.OriginalOrthogonalHeight - GetAbsoluteHeight()) / 2; var newX = (structureShown.X - Camera.Main.X) * CameraZoomManager.GumCoordOffset; var newY = (structureShown.Y - Camera.Main.Y) * CameraZoomManager.GumCoordOffset + GetAbsoluteHeight() / 2; X = MathHelper.Clamp(newX, -minMaxX, minMaxX); Y = MathHelper.Clamp(newY, -minMaxY, minMaxY); StructureName = structureShown.DisplayName; AttackDamageType.ResistanceText = structure.AttackDamage.ToString(); SatoshiCost = structure.SatoshiCost.ToString(); MinRange.AttributeText = structure.MinimumRangeRadius.ToString(); MaxRange.AttributeText = structure.RangedRadius.ToString(); AttackSpeed.AttributeText = structure.SecondsBetweenFiring + " sec"; PointOrSplash.AttributeText = structure.HasSplashDamage ? "Group" : "Single"; SetIcon(structure.GetType()); var structureUpgrades = structure.GetCurrentlyAppliedUpgrades(); MaxRange.CurrentUpgradedState = structureUpgrades.Contains(UpgradeTypes.Range) ? AttributeDisplayRuntime.Upgraded.IsUpgraded : AttributeDisplayRuntime.Upgraded.NotUpgraded; MinRange.CurrentUpgradedState = structureUpgrades.Contains(UpgradeTypes.Range) ? AttributeDisplayRuntime.Upgraded.IsUpgradedNoArrow : AttributeDisplayRuntime.Upgraded.NotUpgraded; AttackSpeed.CurrentUpgradedState = structureUpgrades.Contains(UpgradeTypes.Speed) ? AttributeDisplayRuntime.Upgraded.IsUpgraded : AttributeDisplayRuntime.Upgraded.NotUpgraded; AttackDamageType.CurrentUpgradedState = structureUpgrades.Contains(UpgradeTypes.Damage) ? ResistanceDisplayRuntime.Upgraded.IsUpgraded : ResistanceDisplayRuntime.Upgraded.NotUpgraded; var upgradeCount = structureUpgrades.Count; var upgradeCost = upgradeCount == 0 ? FirstUpgradeCost : upgradeCount == 1 ? SecondUpgradeCost : FinalUpgradeCost; if (upgradeCount == 3) { if (UpgradeInfoInstance.PulseAnimation.IsPlaying()) { UpgradeInfoInstance.PulseAnimation.Stop(); } CurrentUpgradeAvailabilityState = UpgradeAvailability.NotAvailable; } else { var canAffordUpgrade = currentSatoshis >= upgradeCost; var hasSpeedUpgrade = structureUpgrades.Contains(UpgradeTypes.Speed); var hasRangeUpgrade = structureUpgrades.Contains(UpgradeTypes.Range); var hasDamageUpgrade = structureUpgrades.Contains(UpgradeTypes.Damage); UpgradeInfoInstance.SatoshiCostText = upgradeCost.ToString(); UpgradeInfoInstance.CurrentOptionsAvailabilityState = upgradeCount == 2 ? UpgradeInfoRuntime.OptionsAvailability.OneOption : UpgradeInfoRuntime.OptionsAvailability.TwoOptions; if (upgradeCount == 0) { SetBothUpgradeButtonsFor(UpgradeTypes.Range, UpgradeTypes.Speed, upgradeCost, canAffordUpgrade); } else if (upgradeCount == 2) { UpgradeTypes upgradeRemaining; if (hasDamageUpgrade && hasSpeedUpgrade) { upgradeRemaining = UpgradeTypes.Range; } else if (hasDamageUpgrade && hasRangeUpgrade) { upgradeRemaining = UpgradeTypes.Speed; } else { upgradeRemaining = UpgradeTypes.Damage; } SetSingleUpgradeButtonFor(upgradeRemaining, upgradeCost, canAffordUpgrade); } else { var upgradeRemaining = hasSpeedUpgrade ? UpgradeTypes.Range : UpgradeTypes.Speed; SetBothUpgradeButtonsFor(UpgradeTypes.Damage, upgradeRemaining, upgradeCost, canAffordUpgrade); } if (canAffordUpgrade) { CurrentUpgradeAvailabilityState = UpgradeAvailability.Available; UpgradeInfoInstance.CurrentAffordabilityState = UpgradeInfoRuntime.Affordability.CanAfford; UpgradeInfoInstance.PulseAnimation.Play(); } else { CurrentUpgradeAvailabilityState = UpgradeAvailability.AvailableCantAfford; if (UpgradeInfoInstance.PulseAnimation.IsPlaying()) { UpgradeInfoInstance.PulseAnimation.Stop(); } UpgradeInfoInstance.CurrentAffordabilityState = UpgradeInfoRuntime.Affordability.CantAfford; UpgradeInfoInstance.OnUpgradeButton1Click = null; UpgradeInfoInstance.OnUpgradeButton2Click = null; } } if (!allowUpgrades) { if (UpgradeInfoInstance.PulseAnimation.IsPlaying()) { UpgradeInfoInstance.PulseAnimation.Stop(); } CurrentUpgradeAvailabilityState = UpgradeAvailability.NotAvailable; } CurrentCostInfoState = CostInfo.NotShown; }
public void UpdateFromStructure(BaseStructure structure, IEntityFactory factory, int currentSatoshis) { BuildingFactory = factory; RangeTuple = new Tuple <int, int>((int)structure.RangedRadius, (int)structure.MinimumRangeRadius); RangeXOffset = structure.PivotPoint.RelativeX; RangeYOffset = structure.SpriteInstance.RelativeY; BuildingType = structure.GetType(); structureInfo = new StructureInfoRuntime.StructureInfoSaveState(structure); UpdateAffordability(currentSatoshis); RenderTarget2D renderTarget = null; var renderName = BuildingType.FullName + ".png"; var contentManagerName = FlatRedBallServices.GlobalContentManager; if (FlatRedBallServices .GetContentManagerByName(contentManagerName) .IsAssetLoadedByName <RenderTarget2D>(renderName)) { renderTarget = FlatRedBallServices .GetContentManagerByName(contentManagerName) .GetDisposable <RenderTarget2D>(renderName); } var baseHeight = structure.SpriteInstance.Height; var baseWidth = structure.SpriteInstance.Width; if (renderTarget == null) { structure.LightSpriteInstance.Visible = false; structure.LightAimSpriteInstance.Visible = false; structure.AimSpriteInstance.RelativeRotationZ = MathHelper.ToRadians(0); structure.Collision.Visible = false; structure.LightSpriteInstance.Visible = false; var relativeY = structure.SpriteInstance.RelativeY; structure.SpriteInstance.RelativeY = 0; relativeY = structure.SpriteInstance.RelativeY - relativeY; structure.PivotPoint.RelativeY += relativeY; structure.ForceUpdateDependenciesDeep(); var aimHeight = structure.AimSpriteInstance.Height; var aimWidth = structure.AimSpriteInstance.Width; var aimRelativeX = structure.PivotPoint.RelativeX + structure.AimSpriteInstance.RelativeX; var aimRelativeY = structure.PivotPoint.RelativeY + structure.AimSpriteInstance.RelativeY; var structureTop = Math.Min(-baseHeight / 2, -aimRelativeY - aimHeight / 2); var structureBottom = Math.Max(baseHeight / 2, -aimRelativeY + aimHeight / 2); var structureLeft = Math.Min(-baseWidth / 2, aimRelativeX - aimWidth / 2); var structureRight = Math.Max((baseWidth / 2), aimRelativeX + aimWidth / 2); var structureHeight = (int)Math.Abs(structureTop - structureBottom); var structureWidth = (int)Math.Abs(structureRight - structureLeft); // This layer holds whatever we want drawn var temporaryLayer = new Layer(); // Define the layer. This uses the current game's resolution, but it could be any size renderTarget = new RenderTarget2D( FlatRedBallServices.GraphicsDevice, structureWidth, structureHeight); temporaryLayer.RenderTarget = renderTarget; structure.MoveToLayer(temporaryLayer); structure.Y = -structureHeight / 2 + structure.SpriteInstance.Height / 2; structure.ForceUpdateDependenciesDeep(); // Rendering requires a camera. We'll create a temporary one (don't add it to the SpriteManager) var temporaryCamera = new Camera(null, structureWidth, structureHeight) { DrawsWorld = false, Z = 40 }; // We only want the camera to draw the layer temporaryCamera.UsePixelCoordinates(); temporaryCamera.AddLayer(temporaryLayer); Renderer.DrawCamera(temporaryCamera, null); //using (var fileStream = File.Create("test.png")) //{ // structureTexture.SaveAsPng(fileStream, structureTexture.Width, structureTexture.Height); //} FlatRedBallServices.AddDisposable( renderName, renderTarget, contentManagerName); } StructureSprite.SourceFile = renderTarget; StructureSprite.TextureHeight = renderTarget.Height; StructureSprite.TextureWidth = renderTarget.Width; StructureSprite.TextureLeft = 0; StructureSprite.TextureTop = 0; if (renderTarget.Width > renderTarget.Height) { StructureSprite.WidthUnits = DimensionUnitType.Percentage; StructureSprite.HeightUnits = DimensionUnitType.PercentageOfOtherDimension; StructureSprite.Width = 100; StructureSprite.Height = baseHeight / baseWidth * 100; } else { StructureSprite.HeightUnits = DimensionUnitType.Percentage; StructureSprite.WidthUnits = DimensionUnitType.PercentageOfOtherDimension; StructureSprite.Height = 100; StructureSprite.Width = baseWidth / baseHeight * 100; } }