Esempio n. 1
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, 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()
                );
        }
Esempio n. 2
0
        public IEnumerable <float> BufferText(string text, float adjustment, Matrix4 transform)
        {
            float textWidth  = measureWidth(text);
            float charOffset = textWidth * adjustment;

            foreach (char c in text)
            {
                if (!char.IsWhiteSpace(c))
                {
                    var charInfo = this.characterInfos[c];

                    for (int v = 0; v < 6; v++)
                    {
                        var charPos = Vector4.Transform(
                            new Vector4(unitQuadTriangles[v].X * charInfo.Aspect + charOffset, unitQuadTriangles[v].Y, 0, 1),
                            transform
                            );
                        foreach (var dataBit in SpriteHelpers.TexturedVertexData(charPos.X, charPos.Y, charInfo.TextureCoords[v].X, charInfo.TextureCoords[v].Y))
                        {
                            yield return(dataBit);
                        }
                    }
                    charOffset += charInfo.Aspect;
                }
                else if (c == ' ')
                {
                    charOffset += SpaceUnitWidth;
                }
            }
        }
Esempio n. 3
0
        protected override SceneObject makeSceneObject()
        {
            var pressOffset = this.isPressed && this.isHovered ? new Vector2(PressOffsetX, PressOffsetY) : new Vector2(0, 0);

            var background = this.isHovered ? this.BackgroundHover : this.mBackgroundNormal;
            var soBuilder  = new SceneObjectBuilder().
                             PixelSize(1 / SettingsWinforms.Get.GuiScale).
                             Clip(this.Position.ClipArea).    //TODO(v0.8) add press offset to clip area
                             StartSprite(this.Z0, background.Sprite.Id, Color.White).
                             Translate(this.Position.Center + pressOffset).
                             AddVertices(SpriteHelpers.GuiBackground(background, this.Position.Size.X, this.Position.Size.Y));

            if (!string.IsNullOrWhiteSpace(this.Text))
            {
                soBuilder.StartText(this.Text, -0.5f, 0.5f, this.Z0 - this.ZRange / 2, this.ZRange / 2, this.TextColor).
                Scale(this.TextHeight).
                Translate(this.Position.Center + new Vector2(0, this.textSize.Y / 2f * this.TextHeight));
            }

            if (this.mForgroundImage.HasValue)
            {
                soBuilder.
                StartSimpleSprite(this.Z0 - this.ZRange / 2, this.mForgroundImage.Value, Color.White).
                Scale(this.Position.Size - new Vector2(2 * this.paddingX, 2 * this.paddingY)).
                Translate(this.Position.Center);
            }

            return(soBuilder.Build());
        }
Esempio n. 4
0
        protected override SceneObject makeSceneObject()
        {
            var pressOffset = this.isPressed && this.isHovered ? new Vector2(PressOffsetX, PressOffsetY) : new Vector2(0, 0);

            var background = this.isHovered ? this.BackgroundHover : this.mBackgroundNormal;
            var soBuilder  = new SceneObjectBuilder().
                             Clip(this.Position.ClipArea).    //TODO(v0.8) add press offset to clip area
                             StartSprite(this.Z0, background.Sprite.Id, Color.White).
                             Translate(this.Position.Center + pressOffset).
                             AddVertices(SpriteHelpers.GuiBackground(background, this.Position.Size.X, this.Position.Size.Y));

            if (!string.IsNullOrWhiteSpace(this.Text))
            {
                //TODO(later) split single line if it doesn't fit
                var lines = this.Text.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
                for (int i = 0; i < lines.Length; i++)
                {
                    soBuilder.StartText(lines[i], this.fontSize(), -0.5f, this.Z0 - this.ZRange / 2, TextRenderUtil.Get.TextureId, this.TextColor, Matrix4.Identity).
                    Scale(this.fontHeight, this.fontHeight).
                    Translate(this.Position.Center + new Vector2(0, (lines.Length / 2f - i) * this.fontHeight));
                }
            }

            if (this.mForgroundImage.HasValue)
            {
                soBuilder.
                StartSimpleSprite(this.Z0 - this.ZRange / 2, this.mForgroundImage.Value, Color.White).
                Scale(this.Position.Size - new Vector2(2 * this.paddingX, 2 * this.paddingY)).
                Translate(this.Position.Center);
            }

            return(soBuilder.Build());
        }
Esempio n. 5
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)
                       ));
        }
Esempio n. 6
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()
                );
        }
Esempio n. 7
0
        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()
                       ));
        }
Esempio n. 8
0
 private void setupStarSprites()
 {
     this.UpdateScene(
         ref this.starSprites,
         this.currentPlayer.Stars.Select(star => new SceneObject(
                                             new [] {
         new PolygonData(
             StarColorZ,
             new SpriteData(Matrix4.Identity, GalaxyTextures.Get.StarColor.Id, star.Color),
             SpriteHelpers.TexturedRectVertexData(convert(star.Position), 1, 1, GalaxyTextures.Get.StarColor)
             ),
         new PolygonData(
             StarSaturationZ,
             new SpriteData(Matrix4.Identity, GalaxyTextures.Get.StarGlow.Id, Color.White),
             SpriteHelpers.TexturedRectVertexData(convert(star.Position), 1, 1, GalaxyTextures.Get.StarGlow)
             ),
         new PolygonData(
             StarNameZ,
             new SpriteData(Matrix4.Identity, TextRenderUtil.Get.TextureId, starNameColor(star)),
             TextRenderUtil.Get.BufferText(
                 star.Name.ToText(LocalizationManifest.Get.CurrentLanguage),
                 -0.5f,
                 Matrix4.CreateScale(StarNameScale) * Matrix4.CreateTranslation((float)star.Position.X, (float)star.Position.Y - 0.5f, 0)
                 ).ToList()
             )
     },
                                             new PhysicalData(convert(star.Position), new Vector2(0, 0)),
                                             star
                                             )).ToList()
         );
 }
Esempio n. 9
0
        //TODO(later) try to remove the need transform parameter
        private IEnumerable <float> bufferText(string text, Dictionary <char, CharTextureInfo> characters, float textWidth, float adjustment, Matrix4 transform)
        {
            float charOffsetX = textWidth * adjustment;
            float charOffsetY = 0;

            foreach (char c in text)
            {
                if (!char.IsWhiteSpace(c))
                {
                    var charInfo = characters[c];

                    for (int v = 0; v < 6; v++)
                    {
                        var charPos = Vector4.Transform(
                            new Vector4(unitQuadTriangles[v].X * charInfo.Aspect + charOffsetX, unitQuadTriangles[v].Y + charOffsetY, 0, 1),
                            transform
                            );
                        foreach (var dataBit in SpriteHelpers.TexturedVertex(charPos.X, charPos.Y, charInfo.TextureCoords[v].X, charInfo.TextureCoords[v].Y))
                        {
                            yield return(dataBit);
                        }
                    }
                    charOffsetX += charInfo.Aspect;
                }
                else if (c == ' ')
                {
                    charOffsetX += SpaceUnitWidth;
                }
                else if (c == '\n')
                {
                    charOffsetX = textWidth * adjustment;
                    charOffsetY--;
                }
            }
        }
Esempio n. 10
0
        protected override SceneObject makeSceneObject()
        {
            var background = this.mBackgroundNormal;

            if (this.isHovered)
            {
                background = this.mBackgroundHover;
            }
            if (this.isToggled)
            {
                background = this.mBackgroundToggled;
            }

            var soBuilder = new SceneObjectBuilder().
                            Clip(this.Position.ClipArea).
                            StartSprite(this.Z0, background.Sprite.Id, Color.White).
                            Translate(this.Position.Center).
                            AddVertices(SpriteHelpers.GuiBackground(background, this.Position.Size.X, this.Position.Size.Y));

            if (this.mForgroundImage != null)
            {
                soBuilder.
                StartSprite(this.Z0 - this.ZRange / 2, this.mForgroundImage.Sprite.Id, Color.White).
                Translate(this.Position.Center).
                AddVertices(SpriteHelpers.GuiBackground(this.mForgroundImage, this.Position.Size.X, this.Position.Size.Y));
            }

            return(soBuilder.Build());
        }
Esempio n. 11
0
        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 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()
                                 ));
            }
        }
Esempio n. 13
0
        public Dictionary <float, IEnumerable <float> > BufferText(string text, float adjustment, float alignment, float z0, float zRange)
        {
            this.prepare(text);
            float textWidth = this.measureSize(text).X;

            float charOffsetX = textWidth * adjustment;
            float charOffsetY = 0;
            var   layers      = new List <float> [4];
            int   row         = 0;
            int   colunm      = 0;

            for (int i = 0; i < layers.Length; i++)
            {
                layers[i] = new List <float>();
            }

            foreach (var line in text.Split('\n'))
            {
                var lineWidth = line.Sum(c =>
                                         c == ' ' ? SpaceUnitWidth :
                                         !char.IsWhiteSpace(c) ? this.characterInfos[c].Width :
                                         0
                                         );
                charOffsetX = textWidth * adjustment + (textWidth - lineWidth) * alignment;

                foreach (char c in line)
                {
                    if (!char.IsWhiteSpace(c))
                    {
                        var charInfo = this.characterInfos[c];
                        var layer    = 2 * (row % 2) + colunm % 2;

                        for (int v = 0; v < 6; v++)
                        {
                            layers[layer].AddRange(SpriteHelpers.TexturedVertex(
                                                       charInfo.VertexCoords[v].X + charOffsetX,
                                                       charInfo.VertexCoords[v].Y + charOffsetY,
                                                       charInfo.TextureCoords[v].X, charInfo.TextureCoords[v].Y));
                        }

                        charOffsetX += charInfo.Width;
                        colunm++;
                    }
                    else if (c == ' ')
                    {
                        charOffsetX += SpaceUnitWidth;
                    }
                }

                charOffsetY -= this.lineScale;
                row++;
                colunm = 0;
            }

            return(Enumerable.Range(0, layers.Length).
                   ToDictionary(i => z0 - i * zRange / 4, i => (IEnumerable <float>)layers[i]));
        }
Esempio n. 14
0
        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);
		}
Esempio n. 15
0
        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);
        }
Esempio n. 16
0
        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);
        }
Esempio n. 17
0
        private IEnumerable <Vector2> fleetMovementPathVertices(FleetInfo fleet, IEnumerable <Vector2> waypoints)
        {
            var lastPosition = fleetDisplayPosition(fleet);

            foreach (var nextPosition in waypoints)
            {
                foreach (var v in SpriteHelpers.PathRect(lastPosition, nextPosition, PathWidth, GalaxyTextures.Get.PathLine))
                {
                    yield return(v);
                }

                lastPosition = nextPosition;
            }
        }
Esempio n. 18
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()
                );
        }
Esempio n. 20
0
 protected override SceneObject makeSceneObject()
 {
     if (this.mBackground != null)
     {
         return(new SceneObjectBuilder().
                Clip(this.Position.ClipArea).
                StartSprite(this.Z0, this.mBackground.Sprite.Id, Color.White).
                Translate(this.Position.Center).
                AddVertices(SpriteHelpers.GuiBackground(this.mBackground, this.Position.Size.X, this.Position.Size.Y)).
                Build());
     }
     else
     {
         return(null);
     }
 }
Esempio n. 21
0
 private void setupWormholeSprites()
 {
     this.UpdateScene(
         ref this.wormholeSprites,
         new SceneObjectBuilder().
         StartSprite(WormholeZ, GalaxyTextures.Get.PathLine.Id, Color.Blue).
         AddVertices(
             this.currentPlayer.Wormholes.SelectMany(wormhole => SpriteHelpers.PathRect(
                                                         convert(wormhole.Endpoints.First.Position),
                                                         convert(wormhole.Endpoints.Second.Position),
                                                         0.8f * PathWidth,
                                                         GalaxyTextures.Get.PathLine
                                                         ))).
         Build()
         );
 }
        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()
                             ));
        }
Esempio n. 23
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()
                );
        }
Esempio n. 24
0
        protected override SceneObject makeSceneObject()
        {
            var railWidth   = this.Position.Size.X - this.knobSize;
            var knobColor   = this.mReadOnly ? Color.White : Color.DarkGray;
            var panelSprite = new BackgroundTexture(GalaxyTextures.Get.PanelBackground, 2);

            //TODO(v0.8) maybe make readonly mode have no knob but a fill from 0 to value

            return(new SceneObjectBuilder().
                   Clip(this.Position.ClipArea).
                   StartSimpleSprite(this.Z0, GalaxyTextures.Get.PanelBackground, Color.White).
                   Translate(this.Position.Center).
                   AddVertices(SpriteHelpers.GuiBackground(panelSprite, railWidth, this.Position.Size.Y - 4)).

                   StartSprite(this.Z0 - this.ZRange / 2, GalaxyTextures.Get.PanelBackground.Id, knobColor).
                   Translate(this.Position.Center + new Vector2(railWidth * (this.mValue - 0.5f), 0)).
                   AddVertices(SpriteHelpers.GuiBackground(panelSprite, this.knobSize, this.knobSize)).
                   Build());
        }
Esempio n. 25
0
        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()
                                     ));
                }
            }
        }
Esempio n. 26
0
        protected override SceneObject makeSceneObject()
        {
            var pressOffset = this.isPressed && this.isHovered ? new Vector2(PressOffsetX, PressOffsetY) : new Vector2(0, 0);

            var background = this.isHovered ? this.BackgroundHover : this.mBackgroundNormal;
            var soBuilder  = new SceneObjectBuilder().
                             Clip(this.Position.ClipArea).    //TODO(v0.8) add press offset to clip area
                             StartSprite(this.Z0, background.Sprite.Id, Color.White).
                             Translate(this.Position.Center + pressOffset).
                             AddVertices(SpriteHelpers.GuiBackground(background, this.Position.Size.X, this.Position.Size.Y));

            if (this.forgroundImage.HasValue)
            {
                soBuilder.
                StartSimpleSprite(this.Z0 - this.ZRange / 2, this.forgroundImage.Value, Color.White).
                Scale(this.Position.Size - new Vector2(2 * this.mPadding, 2 * this.mPadding)).
                Translate(this.Position.Center);
            }

            return(soBuilder.Build());
        }
Esempio n. 27
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)
                                    ))
                );
        }
Esempio n. 28
0
        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()
                );
        }
Esempio n. 29
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, 
					null, true
				));
			}
			
			this.UpdateScene(
				ref this.movementSprites,
				arrowData.Select(arrow => new SceneObject(new PolygonData(
					MovemenentZ,
					arrow,
					SpriteHelpers.UnitRect(GalaxyTextures.Get.MoveToArrow).ToList()
				))).ToList()
			);
		}
        public DragDropPointerEffects HandleDataDropped(DragDropInfo dragDropInfo)
        {
            Microsoft.VisualStudio.Text.SnapshotPoint position = dragDropInfo.VirtualBufferPosition.Position;
            var doc = SpriteDocument.FromJSON(_view.TextBuffer.CurrentSnapshot.GetText(), _documentFileName);

            string ident = SpriteHelpers.GetIdentifier(_draggedFileName);
            string file  = SpriteHelpers.MakeRelative(_documentFileName, _draggedFileName);

            if (doc.Images.ContainsKey(ident))
            {
                ident += "_" + Guid.NewGuid().ToString().Replace("-", string.Empty);
            }

            doc.Images.Add(new KeyValuePair <string, string>(ident, file));

            using (Microsoft.VisualStudio.Text.ITextEdit edit = _view.TextBuffer.CreateEdit())
            {
                edit.Replace(0, _view.TextBuffer.CurrentSnapshot.Length, doc.ToJsonString());
                edit.Apply();
            }

            return(DragDropPointerEffects.Copy);
        }