Пример #1
0
        public override void Render(SpriteBatch spriteBatch, ViewController view)
        {
            World.System system = ChapterMaster.Sector.Systems[systemId];
            World.Planet planet = ChapterMaster.Sector.Systems[systemId].Planets[planetId];
            Rect = align.GetRect(view);
            // background
            spriteBatch.Draw(Assets.UITextures[backgroundTexture], Rect, Color.White);
            // disposition height
            string disposition = "Disposition ???/100 ";
            int    dH          = (int)Assets.CaslonAntiqueRegular.MeasureString(disposition).Y;
            // planet type texture
            Vector2 pos = MathUtil.Add(Rect.Location, new Vector2(8, 8 + dH + 2));

            spriteBatch.Draw(Assets.PlanetTypeTextures[planet.GetTypeTexture()], pos, Color.Gray);
            RenderHelper.PrimitiveBuddy.Rectangle(MathUtil.VectorToRectangle(pos, new Vector2(128, 128)), Color.Gray);
            //disposition
            spriteBatch.DrawString(Assets.CourierNew, disposition,
                                   MathUtil.Add(Rect.Location, new Vector2(123, 9)), Color.White);
            RenderHelper.PrimitiveBuddy.Rectangle(MathUtil.VectorToRectangle(new Vector2(pos.X, Rect.Location.Y + 8), new Vector2(290, dH)), Color.Gray);
            // title
            Vector2 titlePos = MathUtil.Add(Rect.Location, new Vector2(128 + 8 + 1, 8 + dH + 2 + 2));
            string  title    = planet.GetName();

            spriteBatch.DrawString(Assets.CaslonAntiqueBold, title, titlePos, Color.Gray);
            int     tH            = (int)Assets.CaslonAntiqueRegular.MeasureString(title).Y;               // title height
            int     cH            = (int)Assets.CaslonAntiqueRegular.MeasureString(planet.FactionOwner).Y; // controller name height
            Vector2 controllerPos = MathUtil.Offset(titlePos, 0, tH);

            spriteBatch.DrawString(Assets.CaslonAntiqueBold, planet.FactionOwner, controllerPos, Color.Gray);
            // population
            spriteBatch.DrawString(Assets.CaslonAntiqueRegular, "Population: " + planet.Population, MathUtil.Offset(controllerPos, 0, cH + 2), Color.Gray);
            // defense force
            spriteBatch.DrawString(Assets.CaslonAntiqueRegular, "Defense Force: " + planet.Population, MathUtil.Offset(controllerPos, 0, cH + cH + 2), Color.Gray);
            foreach (Button button in Buttons)
            {
                button.Render(spriteBatch, view);
            }
        }
Пример #2
0
    public void DrawVisualisations(World.Sys sys)
    {
        Vector2 canvasDiam = canvasRect.sizeDelta;

        star    = new VisImage();
        planets = new List <VisImage>();

        #region Init
        //Star
        World.Star starObj = sys.star;

        star.type   = starObj.type;
        star.id     = starObj.id;
        star.color  = starObj.visColor;
        star.sprite = starSprite;
        star.size   = starObj.visSize;

        //Planets
        foreach (World.Planet planet in sys.planets)
        {
            Sprite sprite;
            if (!planet.field)
            {
                sprite = planetSprite;
            }
            else
            {
                sprite = fieldSprite;
            }

            VisImage planetVis = new VisImage
            {
                type   = planet.type,
                id     = planet.id,
                color  = planet.visColor,
                sprite = sprite,
                field  = planet.field
            };

            planets.Add(planetVis);
        }
        #endregion

        #region Positions
        float paddingFromStar = (star.size / 2) * 1.5f;

        star.posX = 0;

        float planetsTotalWidth = 0;
        foreach (VisImage planet in planets)
        {
            planetsTotalWidth += planet.size;
        }
        float canvasTotal = (canvasDiam.x / 2) - paddingFromStar;

        float planetsTotalSpace = canvasTotal - planetsTotalWidth;

        float planetsSpace = planetsTotalSpace / planets.Count;


        for (int i = 0; i <= planets.Count - 1; i++)
        {
            VisImage planet = planets[i];

            float virtPosX = ((planet.size + planetsSpace) * i) + paddingFromStar;
            planet.virtPosX = virtPosX;

            if (virtPosX > canvasDiam.x / 2)
            {
                virtPosX = (canvasDiam.x / 2) - planet.size;
            }

            if (!planet.field)
            {
                planet.posX = virtPosX;
            }
            else
            {
                planet.posX = 0;
            }
        }

        #endregion

        #region Sizes
        for (int i = 0; i <= planets.Count - 1; i++)
        {
            VisImage     planetVis = planets[i];
            World.Planet planet    = World.GetLocation().sys.planets[i];

            if (!planetVis.field)
            {
                planetVis.size = planet.visSize;
            }
            else
            {
                planetVis.size = planetVis.virtPosX * 2;
            }
        }
        #endregion

        #region Render
        DrawVisualisation(star);

        foreach (VisImage planet in planets)
        {
            DrawVisualisation(planet);

            if (!planet.field)
            {
                DrawOrbit(planet);
            }

            //Set a random orbit point
            planet.rect.RotateAround(star.rect.position, Vector3.right, Random.Range(0, 360));
        }
        #endregion

        displaying = true;
    }