private PolygonData planetSpriteData(CombatPlanetInfo planet) { var sprite = new TextureInfo(); switch (planet.Type) { case PlanetType.Asteriod: sprite = GalaxyTextures.Get.Asteroids; break; case PlanetType.GasGiant: sprite = GalaxyTextures.Get.GasGiant; break; case PlanetType.Rock: sprite = GalaxyTextures.Get.RockPlanet; break; } return(new PolygonData( PlanetZ, new SpriteData(planetTransform(planet.OrdinalPosition), sprite.Id, Color.White, null, true), SpriteHelpers.UnitRect(sprite).ToList() )); }
private void setupBodies() { var starTransform = Matrix4.CreateScale(StarScale); this.UpdateScene( ref this.starSprite, new SceneObject(new PolygonData( StarColorZ, new SpriteData(starTransform, GalaxyTextures.Get.SystemStar.Id, controller.Star.Color, null, true), SpriteHelpers.UnitRect(GalaxyTextures.Get.SystemStar).ToList() )) ); this.UpdateScene( ref this.planetSprites, this.controller.Planets.Select(planet => new SceneObject(planetSpriteData(planet))).ToList() ); this.UpdateScene( ref this.planetOrbits, this.controller.Planets.Select( planet => { var orbitR = planet.OrdinalPosition * OrbitStep + OrbitOffset; var color = planet.Owner != null ? planet.Owner.Color : Color.FromArgb(64, 64, 64); return(new SceneObject(new PolygonData( OrbitZ, new OrbitData(orbitR - OrbitWidth / 2, orbitR + OrbitWidth / 2, color, Matrix4.Identity, GalaxyTextures.Get.PathLine), OrbitHelpers.PlanetOrbit(orbitR, OrbitWidth, OrbitPieces).ToList() ))); } ).ToList() ); }
private void setupColonizationMarkers() { this.UpdateScene( ref this.colonizationMarkers, this.controller.Planets.Where(x => this.controller.IsColonizing(x.Position)).Select( planet => { var markTransform = Matrix4.CreateScale(0.4f, 0.4f, 1) * Matrix4.CreateTranslation(0.6f, 0.5f, 0) * planetTransform(planet.Position); return(new SceneObject( new [] { new PolygonData( MarkZ, new SpriteData(markTransform, GalaxyTextures.Get.ColonizationMark.Id, Color.White, null, true), SpriteHelpers.UnitRect(GalaxyTextures.Get.ColonizationMark).ToList() ), new PolygonData( MarkColorZ, new SpriteData(markTransform, GalaxyTextures.Get.ColonizationMarkColor.Id, this.currentPlayer.Info.Color, null, true), SpriteHelpers.UnitRect(GalaxyTextures.Get.ColonizationMarkColor).ToList() ) })); }).ToList() ); }
private IEnumerable<PolygonData> planetSpriteData(CombatPlanetInfo planet) { var planetTransform = Matrix4.CreateTranslation(hexX(planet.Position), hexY(planet.Position), 0); var sprite = new TextureInfo(); switch(planet.Type) { case PlanetType.Asteriod: sprite = GalaxyTextures.Get.Asteroids; break; case PlanetType.GasGiant: sprite = GalaxyTextures.Get.GasGiant; break; case PlanetType.Rock: sprite = GalaxyTextures.Get.RockPlanet; break; } yield return new PolygonData( PlanetColorZ, new SpriteData(planetTransform, sprite.Id, Color.White, null, true), SpriteHelpers.UnitRect(sprite).ToList() ); if (planet.Population > 0) yield return new PolygonData( MoreCombatantsZ, new SpriteData(PopulationTransform * planetTransform, TextRenderUtil.Get.TextureId, planet.Owner != null ? planet.Owner.Color : Color.Gray, null, true), TextRenderUtil.Get.BufferRaster(new ThousandsFormatter().Format(planet.Population), -1, Matrix4.Identity).ToList() ); }
private IEnumerable <PolygonData> projectileSpriteData(IGrouping <Vector2D, ProjectileInfo> hex) { var hexTransform = Matrix4.CreateTranslation(hexX(hex.Key), hexY(hex.Key), 0); var shownProjectile = hex.Aggregate((a, b) => a.Count > b.Count ? a : b); var unitSprite = GalaxyTextures.Get.Sprite(shownProjectile.ImagePath); yield return(new PolygonData( ProjectileZ, new SpriteData(Matrix4.CreateScale(ProjectileScale, ProjectileScale, 1) * hexTransform, unitSprite.Id, shownProjectile.Owner.Color, null), SpriteHelpers.UnitRect(unitSprite).ToList() )); var formatter = new ThousandsFormatter(); foreach (var layer in TextRenderUtil.Get.BufferText(formatter.Format(shownProjectile.Count), -1, 0, ProjectileZ, 1 / Layers)) { //TODO(v0.9) text as sprite data? should be SDF yield return(new PolygonData( layer.Key, new SpriteData( Matrix4.CreateScale(0.2f, 0.2f, 1) * Matrix4.CreateTranslation(0.5f, -0.5f * ProjectileScale, 0) * hexTransform, TextRenderUtil.Get.TextureId, Color.Gray, null ), layer.Value.ToList() )); } }
private SceneObject unitSprite(IGrouping<Vector2D, CombatantInfo> hex, IEnumerable<PlayerInfo> players) { var polygons = new List<PolygonData>(); IAnimator animator = null; var hexTransform = Matrix4.CreateTranslation(hexX(hex.Key), hexY(hex.Key), 0); var unitSelected = (this.currentUnit != null && this.currentUnit.Position == hex.Key); var unit = unitSelected ? this.currentUnit : biggestStack(hex); var unitSprite = GalaxyTextures.Get.Sprite(unit.Design.ImagePath); var alpha = players.All(x => unit.CloakedFor(x) || x == unit.Owner) ? 0.65 : 1; var unitDrawable = new PolygonData( CombatantZ, new SpriteData(hexTransform, unitSprite.Id, Color.FromArgb((int)(alpha * 255), unit.Owner.Color), null, true), SpriteHelpers.UnitRect(unitSprite).ToList() ); if (unitSelected) { animator = new OscillatingAlpha( unitDrawable, AnimationPeriod, 0.6, x => (x + 0.4) * alpha, unit.Owner.Color); } polygons.Add(unitDrawable); var otherUnits = hex.Where(x => x != unit).Select(x => x.Owner).Distinct().ToList(); for(int i = 0; i < otherUnits.Count; i++) polygons.Add(new PolygonData( CombatantZ, new SpriteData( Matrix4.CreateScale(0.2f, 0.2f, 1) * Matrix4.CreateTranslation(0.5f, 0.2f * i + 0.5f, 0) * hexTransform, GalaxyTextures.Get.FleetIndicator.Id, otherUnits[i].Color, null, true ), SpriteHelpers.UnitRect(GalaxyTextures.Get.FleetIndicator).ToList() )); polygons.Add(new PolygonData( CombatantZ, new SpriteData( Matrix4.CreateScale(0.2f, 0.2f, 1) * Matrix4.CreateTranslation(0.5f, -0.5f, 0) * hexTransform, TextRenderUtil.Get.TextureId, Color.Gray, null, true ), TextRenderUtil.Get.BufferRaster(new ThousandsFormatter().Format(unit.Count), -1, Matrix4.Identity).ToList() )); return new SceneObject(polygons, animator: animator); }
public SceneObjectBuilder StartSimpleSprite(float z, TextureInfo sprite, Color color) { this.applyPolygonData(); this.currentPolygonType = PolygonType.Sprite; this.vertexData[z] = new List <float>(SpriteHelpers.UnitRect(sprite)); this.textureId = sprite.Id; this.color = color; return(this); }
public SceneObjectBuilder StartSimpleSprite(float z, TextureInfo sprite, Color color) { this.applyPolygonData(); this.currentPolygonType = PolygonType.Sprite; this.z = z; this.vertexData.AddRange(SpriteHelpers.UnitRect(sprite)); this.textureId = sprite.Id; this.color = color; this.linearFiltering = true; return(this); }
private void setupSelectionMarker() { var transform = (selectedBody == StarSystemController.StarIndex) ? Matrix4.CreateScale(StarSelectorScale) * Matrix4.CreateScale(StarScale) : Matrix4.CreateScale(PlanetSelectorScale) * planetTransform(selectedBody); this.UpdateScene( ref this.selectionMarker, new SceneObject(new PolygonData( SelectionZ, new SpriteData(transform, GalaxyTextures.Get.SelectedStar.Id, Color.White, null, true), SpriteHelpers.UnitRect(GalaxyTextures.Get.SelectedStar).ToList() )) ); }
private void setupBodies() { this.UpdateScene( ref this.starSprite, new SceneObject(new PolygonData( StarColorZ, new SpriteData(Matrix4.Identity, GalaxyTextures.Get.StarColor.Id, this.Controller.HostStar.Color, null, true), SpriteHelpers.UnitRect(GalaxyTextures.Get.SystemStar).ToList() )) ); this.UpdateScene( ref this.planetSprites, this.Controller.Planets.Select(planet => new SceneObject(planetSpriteData(planet))).ToList() ); }
private IEnumerable <PolygonData> planetSpriteData(CombatPlanetInfo planet) { var planetTransform = Matrix4.CreateTranslation(hexX(planet.Position), hexY(planet.Position), 0); var sprite = new TextureInfo(); switch (planet.Type) { case PlanetType.Asteriod: sprite = GalaxyTextures.Get.Asteroids; break; case PlanetType.GasGiant: sprite = GalaxyTextures.Get.GasGiant; break; case PlanetType.Rock: sprite = GalaxyTextures.Get.RockPlanet; break; } yield return(new PolygonData( PlanetColorZ, new SpriteData(planetTransform, sprite.Id, Color.White, null), SpriteHelpers.UnitRect(sprite).ToList() )); var formatter = new ThousandsFormatter(); if (planet.Population > 0) { foreach (var layer in TextRenderUtil.Get.BufferText(formatter.Format(planet.Population), -1, 0, MoreCombatantsZ, 1 / Layers)) { //TODO(v0.9) text as sprite data? should be SDF yield return(new PolygonData( layer.Key, new SpriteData(PopulationTransform * planetTransform, TextRenderUtil.Get.TextureId, planet.Owner != null ? planet.Owner.Color : Color.Gray, null), layer.Value.ToList() )); } } }
private void setupUi() { var formatter = new ThousandsFormatter(); this.UpdateScene( ref this.colonyInfos, this.controller.Planets.Where(x => x.Owner != null).Select( planet => new SceneObject(new PolygonData( PopCountZ, new SpriteData(Matrix4.Identity, TextRenderUtil.Get.TextureId, Color.White, null, true), TextRenderUtil.Get.BufferRaster( LocalizationManifest.Get.CurrentLanguage["FormMain"]["Population"].Text() + ": " + formatter.Format(planet.Population), -0.5f, Matrix4.CreateScale(TextScale) * Matrix4.CreateTranslation(planet.OrdinalPosition * OrbitStep + OrbitOffset, -PlanetScale / 2 - PopCountTopMargin, 0) ).ToList() )) ).ToList() ); this.UpdateScene( ref this.bombButtons, this.controller.Targets.Select( colony => { var xOffset = colony.OrdinalPosition * OrbitStep + OrbitOffset; return(new SceneObject( new PolygonData( PopCountZ, new SpriteData(Matrix4.CreateScale(ButtonSize) * Matrix4.CreateTranslation(xOffset, ButtonY, 0), GalaxyTextures.Get.BombButton.Id, Color.White, null, true), SpriteHelpers.UnitRect(GalaxyTextures.Get.BombButton).ToList() ), new PhysicalData(new Vector2(xOffset, ButtonY), new Vector2(ButtonSize, ButtonSize)), colony.OrdinalPosition )); }).ToList() ); }
private void setupValidMoves() { var center = new Vector2(hexX(this.currentUnit.Position), hexY(this.currentUnit.Position)); var arrowData = new List<SpriteData>(); foreach(var move in this.currentUnit.ValidMoves) { var moveTransform = Matrix4.CreateTranslation(hexX(move), hexY(move), 0); var direction = new Vector2(hexX(move), hexY(move)) - center; if (direction.LengthSquared > 0) { direction.Normalize(); moveTransform = new Matrix4( direction.X, direction.Y, 0, 0, direction.Y, -direction.X, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ) * moveTransform; } arrowData.Add(new SpriteData( Matrix4.CreateScale(0.4f, 0.4f, 1) * Matrix4.CreateTranslation(-0.25f, 0, 0) * moveTransform, GalaxyTextures.Get.MoveToArrow.Id, Methods.HexDistance(move) <= SpaceBattleController.BattlefieldRadius ? Color.Green : Color.White, null, true )); } this.UpdateScene( ref this.movementSprites, arrowData.Select(arrow => new SceneObject(new PolygonData( MovemenentZ, arrow, SpriteHelpers.UnitRect(GalaxyTextures.Get.MoveToArrow).ToList() ))).ToList() ); }
private IEnumerable<PolygonData> projectileSpriteData(IGrouping<Vector2D, ProjectileInfo> hex) { var hexTransform = Matrix4.CreateTranslation(hexX(hex.Key), hexY(hex.Key), 0); var shownProjectile = hex.Aggregate((a, b) => a.Count > b.Count ? a : b); var unitSprite = GalaxyTextures.Get.Sprite(shownProjectile.ImagePath); yield return new PolygonData( ProjectileZ, new SpriteData(Matrix4.CreateScale(ProjectileScale, ProjectileScale, 1) * hexTransform, unitSprite.Id, shownProjectile.Owner.Color, null, true), SpriteHelpers.UnitRect(unitSprite).ToList() ); yield return new PolygonData( ProjectileZ, new SpriteData( Matrix4.CreateScale(0.2f, 0.2f, 1) * Matrix4.CreateTranslation(0.5f, -0.5f * ProjectileScale, 0) * hexTransform, TextRenderUtil.Get.TextureId, Color.Gray, null, true ), TextRenderUtil.Get.BufferRaster(new ThousandsFormatter().Format(shownProjectile.Count), -1, Matrix4.Identity).ToList() ); }