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),
                             SpriteHelpers.UnitRectVertexData(sprite)
                             ));

            if (planet.Population > 0)
            {
                yield return(new PolygonData(
                                 MoreCombatantsZ,
                                 new SpriteData(PopulationTransform * planetTransform, TextRenderUtil.Get.TextureId, planet.Owner != null ? planet.Owner.Color : Color.Gray),
                                 TextRenderUtil.Get.BufferText(new ThousandsFormatter().Format(planet.Population), -1, Matrix4.Identity).ToList()
                                 ));
            }
        }
Пример #2
0
        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),
                        SpriteHelpers.UnitRectVertexData(GalaxyTextures.Get.ColonizationMark)
                        ),
                    new PolygonData(
                        MarkColorZ,
                        new SpriteData(markTransform, GalaxyTextures.Get.ColonizationMarkColor.Id, this.currentPlayer.Info.Color),
                        SpriteHelpers.UnitRectVertexData(GalaxyTextures.Get.ColonizationMarkColor)
                        )
                }));
            }).ToList()
                );
        }
Пример #3
0
        private PolygonData planetSpriteData(Planet 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.Position), sprite.Id, Color.White),
                       SpriteHelpers.UnitRectVertexData(sprite)
                       ));
        }
Пример #4
0
        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),
                                    SpriteHelpers.UnitRectVertexData(GalaxyTextures.Get.SystemStar)
                                    ))
                );

            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()
                );
        }
Пример #5
0
        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),
                                    SpriteHelpers.UnitRectVertexData(GalaxyTextures.Get.SelectedStar)
                                    ))
                );
        }
        private void setupBodies()
        {
            this.UpdateScene(
                ref this.starSprite,
                new SceneObject(new PolygonData(
                                    StarColorZ,
                                    new SpriteData(Matrix4.Identity, GalaxyTextures.Get.StarColor.Id, this.Controller.Star.Color),
                                    SpriteHelpers.UnitRectVertexData(GalaxyTextures.Get.SystemStar)
                                    ))
                );

            this.UpdateScene(
                ref this.planetSprites,
                this.Controller.Planets.Select(planet => new SceneObject(planetSpriteData(planet))).ToList()
                );
        }
        private IEnumerable <PolygonData> unitSpriteData(IGrouping <Vector2D, CombatantInfo> hex, IEnumerable <PlayerInfo> players)
        {
            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)),
                SpriteHelpers.UnitRectVertexData(unitSprite)
                );

            if (unitSelected)
            {
                this.currentUnitDrawable = unitDrawable;
            }

            yield return(unitDrawable);

            var otherUnits = hex.Where(x => x != unit).Select(x => x.Owner).Distinct().ToList();

            for (int i = 0; i < otherUnits.Count; i++)
            {
                yield return(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
                                     ),
                                 SpriteHelpers.UnitRectVertexData(GalaxyTextures.Get.FleetIndicator)
                                 ));
            }

            yield return(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
                                 ),
                             TextRenderUtil.Get.BufferText(new ThousandsFormatter().Format(unit.Count), -1, Matrix4.Identity).ToList()
                             ));
        }
Пример #8
0
        private void setupUi()
        {
            var formatter = new ThousandsFormatter();
            var colonies  = this.controller.Planets.Where(x => x.Owner != null).ToList();

            this.UpdateScene(
                ref this.colonyInfos,
                colonies.Select(
                    planet =>
            {
                var xOffset = planet.OrdinalPosition * OrbitStep + OrbitOffset;

                return(new SceneObject(new PolygonData(
                                           PopCountZ,
                                           new SpriteData(Matrix4.Identity, TextRenderUtil.Get.TextureId, Color.White),
                                           TextRenderUtil.Get.BufferText(
                                               LocalizationManifest.Get.CurrentLanguage["FormMain"]["Population"].Text() + ": " + formatter.Format(planet.Population),
                                               -0.5f,
                                               Matrix4.CreateScale(TextScale) * Matrix4.CreateTranslation(xOffset, -PlanetScale / 2 - PopCountTopMargin, 0)
                                               ).ToList()
                                           )));
            }
                    ).ToList()
                );


            const float yOffset = -PlanetScale / 2 - PopCountTopMargin - TextScale - ButtonTopMargin - ButtonSize / 2;

            //TODO(v0.6) buttons for only hostile colonies
            this.UpdateScene(
                ref this.bombButtons,
                colonies.Select(
                    colony =>
            {
                var xOffset = colony.OrdinalPosition * OrbitStep + OrbitOffset;

                //TODO(v0.6) Use scene object physical shape
                return(new SceneObject(new PolygonData(
                                           PopCountZ,
                                           new SpriteData(Matrix4.CreateScale(ButtonSize) * Matrix4.CreateTranslation(xOffset, yOffset, 0), GalaxyTextures.Get.BombButton.Id, Color.White),
                                           SpriteHelpers.UnitRectVertexData(GalaxyTextures.Get.BombButton)
                                           )));
            }).ToList()
                );
        }
Пример #9
0
        private void setupSelectionMarkers()
        {
            var transform = new Matrix4();

            if (this.currentSelection == GalaxySelectionType.Star)
            {
                transform = Matrix4.CreateTranslation((float)this.lastSelectedStarPosition.X, (float)this.lastSelectedStarPosition.Y, 0);
            }
            else if (this.currentSelection == GalaxySelectionType.Fleet)
            {
                transform = Matrix4.CreateScale(FleetSelectorScale) * Matrix4.CreateTranslation(this.fleetDisplayPosition(this.lastSelectedIdleFleet));
            }

            this.UpdateScene(
                ref this.selectionMarkers,
                new SceneObject(new PolygonData(
                                    SelectionIndicatorZ,
                                    new SpriteData(transform, GalaxyTextures.Get.SelectedStar.Id, Color.White),
                                    SpriteHelpers.UnitRectVertexData(GalaxyTextures.Get.SelectedStar)
                                    ))
                );
        }
Пример #10
0
        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
                                  ));
            }

            this.UpdateScene(
                ref this.movementSprites,
                arrowData.Select(arrow => new SceneObject(new PolygonData(
                                                              MovemenentZ,
                                                              arrow,
                                                              SpriteHelpers.UnitRectVertexData(GalaxyTextures.Get.MoveToArrow)
                                                              ))).ToList()
                );
        }
Пример #11
0
 private void setupFleetMarkers()
 {
     this.UpdateScene(
         ref this.fleetMarkers,
         this.currentPlayer.Fleets.Select(
             fleet =>
     {
         var displayPosition = fleetDisplayPosition(fleet);
         return(new SceneObject(
                    new PolygonData(
                        FleetZ,
                        new SpriteData(
                            Matrix4.CreateScale(FleetSelectorScale) * Matrix4.CreateTranslation(displayPosition),
                            GalaxyTextures.Get.FleetIndicator.Id,
                            fleet.Owner.Color
                            ),
                        SpriteHelpers.UnitRectVertexData(GalaxyTextures.Get.FleetIndicator)
                        ),
                    new PhysicalData(displayPosition.Xy, new Vector2(0, 0)),
                    fleet
                    ));
     }).ToList()
         );
 }