Beispiel #1
0
        protected override void Create(ISpriteFactory spriteFactory, DataSource dataSource)
        {
            uint spriteIndex = (uint)objectType - 8;

            var spriteInfo = dataSource.GetSpriteInfo(Data.Resource.MapObject, spriteIndex);
            var shadowInfo = dataSource.GetSpriteInfo(Data.Resource.MapShadow, spriteIndex);

            sprite       = spriteFactory.Create(spriteInfo.Width, spriteInfo.Height, 0, 0, false, false);
            shadowSprite = spriteFactory.Create(shadowInfo.Width, shadowInfo.Height, 0, 0, false, false);
        }
Beispiel #2
0
        protected override void Create(ISpriteFactory spriteFactory, DataSource dataSource)
        {
            sprite         = spriteFactory.Create(RenderMap.TILE_WIDTH, RenderMap.TILE_RENDER_MAX_HEIGHT, 0, 0, false, false);
            sprite.Visible = true;

            UpdateAppearance();
        }
Beispiel #3
0
        List <SpriteInfo> AddCharacterSprites(int number, TextRenderType renderType)
        {
            var characterSprites      = renderType == TextRenderType.NewUI ? characterSpritesNew : characterSpritesLegacy;
            var characterSize         = renderType == TextRenderType.NewUI ? characterSizeNew : characterSizeLegacy;
            List <SpriteInfo> sprites = new List <SpriteInfo>(number);

            for (int i = 0; i < number; ++i)
            {
                var spriteInfo = new SpriteInfo()
                {
                    Sprite = spriteFactory.Create(characterSize.Width, characterSize.Height, 0, 0, false, true, 0) as ILayerSprite,
                    InUse  = false
                };

                spriteInfo.Sprite.Layer = renderType == TextRenderType.NewUI ? layerNewFont : layerLegacy;

                sprites.Add(spriteInfo);
            }

            characterSprites.AddRange(sprites);

            return(sprites);
        }
Beispiel #4
0
    public GameObject CreateSceneNode(ref SceneData.SceneNodeData data)
    {
        GameObject node;
        string     nodePath = data.parentname + "/" + data.name;

        node = GameObject.Find(nodePath);
        if (node == null)
        {
            node = GameObject.Find(data.texturePath);
        }
        Vector3    pos = new Vector3(data.posX, data.posY, data.posZ);
        Vector3    scl = new Vector3(data.sclX, data.sclY, data.sclZ);
        GameObject pr  = GameObject.Find(data.parentname);

        if (spriteFactory != null)
        {
            node = spriteFactory.Create(ref data, node, pos, scl, pr);
        }
        if (node != null)
        {
            data.name = node.name;
        }
        return(node);
    }
Beispiel #5
0
        public RenderMap(uint numColumns, uint numRows, Map map,
                         ITriangleFactory triangleFactory, ISpriteFactory spriteFactory,
                         ITextureAtlas textureAtlasTiles, ITextureAtlas textureAtlasWaves,
                         DataSource dataSource)
        {
            CoordinateSpace = new CoordinateSpace(map, this);

            columnRowFactor = (map.Size % 2 == 0) ? 4 : 2;

            ScrollX                = 0;
            ScrollY                = 0;
            this.numColumns        = numColumns;
            this.numRows           = numRows;
            this.map               = map;
            this.textureAtlasTiles = textureAtlasTiles;
            this.textureAtlasWaves = textureAtlasWaves;

            // store map sprite offsets
            for (uint i = 0; i < 81; ++i)
            {
                var spriteInfo = dataSource.GetSpriteInfo(Data.Resource.MapMaskUp, i);

                if (spriteInfo != null)
                {
                    maskOffsets.Add(i, new Position(spriteInfo.OffsetX, spriteInfo.OffsetY));
                }

                spriteInfo = dataSource.GetSpriteInfo(Data.Resource.MapMaskDown, i);

                if (spriteInfo != null)
                {
                    maskOffsets.Add(81u + i, new Position(spriteInfo.OffsetX, spriteInfo.OffsetY));
                }
            }

            uint numTriangles = (numColumns + ADDITIONAL_X_TILES) * (numRows + ADDITIONAL_Y_TILES) * 2u;

            triangles = new List <ITriangle>((int)numTriangles);
            waves     = new List <IMaskedSprite>((int)numTriangles / 2);

            for (uint column = 0; column < numColumns + ADDITIONAL_X_TILES; ++column)
            {
                for (int i = 0; i < 2; ++i) // up and down row
                {
                    for (uint row = 0; row < numRows + ADDITIONAL_Y_TILES; ++row)
                    {
                        // the triangles are created with the max mask height of 41.
                        // also see comments in TextureAtlasManager.AddAll for further details.

                        var triangle = triangleFactory.Create(TILE_WIDTH, TILE_RENDER_MAX_HEIGHT, 0, 0);

                        triangle.X       = (int)(column * TILE_WIDTH) - TILE_WIDTH / 2 + i * TILE_WIDTH / 2;
                        triangle.Y       = (int)(row * TILE_HEIGHT);
                        triangle.Visible = true;

                        triangles.Add(triangle);
                    }
                }
            }

            for (uint column = 0; column < numColumns + ADDITIONAL_X_TILES; ++column)
            {
                for (uint row = 0; row < numRows + ADDITIONAL_Y_TILES; ++row)
                {
                    var wave = spriteFactory.Create(48, 19, 0, 0, true, false) as IMaskedSprite;

                    wave.X       = (int)(column * TILE_WIDTH) - TILE_WIDTH / 2;
                    wave.Y       = (int)(row * TILE_HEIGHT);
                    wave.Visible = false;

                    waves.Add(wave);
                }
            }

            UpdatePosition();
        }
Beispiel #6
0
 protected override void Create(ISpriteFactory spriteFactory, DataSource dataSource)
 {
     // max sprite size is 16x19 pixels but we use 16x20 for better base line matching
     sprite       = spriteFactory.Create(16, 20, 0, 0, false, false);
     shadowSprite = spriteFactory.Create(16, 20, 0, 0, false, false);
 }
Beispiel #7
0
        public void Update(uint tick, RenderMap map, MapPos position)
        {
            var  textureAtlas = TextureAtlasManager.Instance.GetOrCreate(Layer.Objects);
            uint offset       = (tick >> 3) & 3;
            uint spriteIndex  = 128u + offset;

            uint flagSpriteIndex = spriteIndex + flag.Player * 16u; // player colors

            var renderPosition = map.CoordinateSpace.TileSpaceToViewSpace(position);

            sprite.X       = renderPosition.X + spriteOffsets[(int)offset].X;
            sprite.Y       = renderPosition.Y + spriteOffsets[(int)offset].Y;
            shadowSprite.X = renderPosition.X + shadowSpriteOffsets[(int)offset].X;
            shadowSprite.Y = renderPosition.Y + shadowSpriteOffsets[(int)offset].Y;

            sprite.TextureAtlasOffset       = textureAtlas.GetOffset(flagSpriteIndex);
            shadowSprite.TextureAtlasOffset = textureAtlas.GetOffset(1000u + spriteIndex);

            int baseLine = sprite.Y + sprite.Height;

            if (baseLine > maxBaseLine)
            {
                maxBaseLine = baseLine;
            }
            else if (baseLine < maxBaseLine)
            {
                sprite.BaseLineOffset = maxBaseLine - baseLine;
            }

            // resources
            for (int i = 0; i < 8; ++i)
            {
                var resource = flag.GetResourceAtSlot(i);

                if (resource != Resource.Type.None)
                {
                    int baselineOffset = (i < 3) ? -2 : 2;
                    var info           = resourceSpriteInfos[(int)resource];

                    if (resources[i] == null)
                    {
                        var spriteOffset = textureAtlas.GetOffset(2000u + (uint)resource);
                        resources[i] = spriteFactory.Create(info.Size.Width, info.Size.Height, spriteOffset.X, spriteOffset.Y, false, false);
                    }

                    // resource at slot 2 may be hidden by castle/stock so adjust baseline in this case
                    if (i == 2 && flag.HasBuilding)
                    {
                        switch (flag.Building.BuildingType)
                        {
                        case Building.Type.Castle:
                        case Building.Type.Stock:
                            baselineOffset += 4;
                            break;
                        }
                    }

                    resources[i].X              = renderPosition.X + info.Position.X + ResPos[i * 2];
                    resources[i].Y              = renderPosition.Y + info.Position.Y + ResPos[i * 2 + 1];
                    resources[i].Layer          = sprite.Layer;
                    resources[i].BaseLineOffset = baselineOffset;
                    resources[i].Visible        = true;
                }
                else
                {
                    resources[i]?.Delete();
                    resources[i] = null;
                }
            }
        }