示例#1
0
        /// <see cref="SpriteGroup.Load_i"/>
        protected override List <UISprite> Load_i()
        {
            /// Load the image of the sprite palette in order to be able to create the combined FOW-sprites.
            UISprite spritePaletteImg = UIRoot.Instance.GraphicsPlatform.SpriteManager.LoadSprite(this.spritePalette.ImageData, UIWorkspace.Instance.PixelScaling);

            spritePaletteImg.TransparentColor = this.spritePalette.TransparentColor;

            /// Create the sprites of this sprite-group.
            List <UISprite> retList = new List <UISprite>();
            Dictionary <FOWTileFlagsEnum, UISprite> fowSprites = new Dictionary <FOWTileFlagsEnum, UISprite>();

            for (FOWTileFlagsEnum flags = FOWTileFlagsEnum.None; flags < FOWTileFlagsEnum.All; flags++)
            {
                FOWTileFlagsEnum simplifiedFlags = this.SimplifyFlags(flags);
                if (!fowSprites.ContainsKey(simplifiedFlags))
                {
                    fowSprites[simplifiedFlags] = this.CreateFowSprite(simplifiedFlags, spritePaletteImg);
                }
                retList.Add(fowSprites[simplifiedFlags]);
            }

            /// Destroy the image of the sprite palette as it is no longer needed and return with the created sprite list.
            UIRoot.Instance.GraphicsPlatform.SpriteManager.DestroySprite(spritePaletteImg);
            return(retList);
        }
示例#2
0
        /// <summary>
        /// Creates a Fog Of War sprite for the given flags.
        /// </summary>
        /// <param name="flags">The FOW-flags.</param>
        /// <param name="spritePaletteImg">The image of the sprite palette.</param>
        /// <returns>The created Fog Of War sprite or null if no sprite needs to be created for the given flags.</returns>
        private UISprite CreateFowSprite(FOWTileFlagsEnum flags, UISprite spritePaletteImg)
        {
            if (flags == FOWTileFlagsEnum.None)
            {
                return(null);
            }

            /// Create a new empty sprite and open a render context to it.
            UISprite retSprite =
                UIRoot.Instance.GraphicsPlatform.SpriteManager.CreateSprite(
                    this.spritePalette.TransparentColor,
                    this.spritePalette.GetSection(this.spriteIndices[FOWTileFlagsEnum.Current]).Size,
                    UIWorkspace.Instance.PixelScaling);
            IUIRenderContext renderCtx = UIRoot.Instance.GraphicsPlatform.SpriteManager.CreateRenderContext(retSprite);

            /// Draw the sprites from the sprite palette to the created sprite according to the incoming flags.
            foreach (FOWTileFlagsEnum flag in this.spriteIndices.Keys)
            {
                if (flags.HasFlag(flag))
                {
                    this.CombineFowFlag(flag, spritePaletteImg, renderCtx);
                }
            }

            /// Close the render context of the created sprite and set its transparent color.
            UIRoot.Instance.GraphicsPlatform.SpriteManager.CloseRenderContext(retSprite);
            retSprite.TransparentColor = this.spritePalette.TransparentColor;
            retSprite.Upload();
            return(retSprite);
        }
示例#3
0
        /// <summary>
        /// Combine the given FOW-flag into the given target render context from the given source sprite.
        /// </summary>
        /// <param name="flag">The FOW-flag to combine into the target render context.</param>
        /// <param name="spritePaletteImg">The image of the sprite palette.</param>
        /// <param name="targetRenderCtx">The target render context.</param>
        private void CombineFowFlag(FOWTileFlagsEnum flag, UISprite spritePaletteImg, IUIRenderContext targetRenderCtx)
        {
            int            spriteIndex   = this.spriteIndices[flag];
            RCIntRectangle sourceSection = this.spritePalette.GetSection(spriteIndex);
            RCIntVector    sourceOffset  = this.spritePalette.GetOffset(spriteIndex);

            targetRenderCtx.RenderSprite(spritePaletteImg, sourceOffset, sourceSection);
        }
示例#4
0
 /// <summary>
 /// Collects the full Fog Of War tiles to update into the given list.
 /// </summary>
 /// <param name="targetList">The target list.</param>
 private void CollectFullFOWTiles(ref List <SpriteRenderInfo> targetList)
 {
     foreach (IQuadTile quadTile in this.fogOfWarBC.GetQuadTilesToUpdate())
     {
         FOWTileFlagsEnum fullFowFlags = this.fogOfWarBC.GetFullFowTileFlags(quadTile.MapCoords);
         if (fullFowFlags != FOWTileFlagsEnum.None)
         {
             targetList.Add(
                 new SpriteRenderInfo()
             {
                 SpriteGroup   = SpriteGroupEnum.FullFogOfWarSpriteGroup,
                 Index         = (int)fullFowFlags,
                 DisplayCoords = this.MapWindowBC.AttachedWindow.QuadToWindowRect(new RCIntRectangle(quadTile.MapCoords, new RCIntVector(1, 1))).Location,
                 Section       = RCIntRectangle.Undefined
             });
         }
     }
 }
示例#5
0
        /// <summary>
        /// Simplifies the given FOW-flags.
        /// </summary>
        /// <param name="originalFlags">The FOW-flags to simplify.</param>
        /// <returns>The simplified FOW-flags.</returns>
        private FOWTileFlagsEnum SimplifyFlags(FOWTileFlagsEnum originalFlags)
        {
            if (originalFlags == FOWTileFlagsEnum.None)
            {
                return(FOWTileFlagsEnum.None);
            }
            if (originalFlags.HasFlag(FOWTileFlagsEnum.Current))
            {
                return(FOWTileFlagsEnum.Current);
            }

            /// Remove the north-east flag if necessary.
            if (originalFlags.HasFlag(FOWTileFlagsEnum.NorthEast) && (originalFlags.HasFlag(FOWTileFlagsEnum.North) || originalFlags.HasFlag(FOWTileFlagsEnum.East)))
            {
                originalFlags &= ~FOWTileFlagsEnum.NorthEast;
            }

            /// Remove the south-east flag if necessary.
            if (originalFlags.HasFlag(FOWTileFlagsEnum.SouthEast) && (originalFlags.HasFlag(FOWTileFlagsEnum.East) || originalFlags.HasFlag(FOWTileFlagsEnum.South)))
            {
                originalFlags &= ~FOWTileFlagsEnum.SouthEast;
            }

            /// Remove the south-west flag if necessary.
            if (originalFlags.HasFlag(FOWTileFlagsEnum.SouthWest) && (originalFlags.HasFlag(FOWTileFlagsEnum.West) || originalFlags.HasFlag(FOWTileFlagsEnum.South)))
            {
                originalFlags &= ~FOWTileFlagsEnum.SouthWest;
            }

            /// Remove the north-west flag if necessary.
            if (originalFlags.HasFlag(FOWTileFlagsEnum.NorthWest) && (originalFlags.HasFlag(FOWTileFlagsEnum.North) || originalFlags.HasFlag(FOWTileFlagsEnum.West)))
            {
                originalFlags &= ~FOWTileFlagsEnum.NorthWest;
            }

            return(originalFlags);
        }
示例#6
0
        /// <summary>
        /// Calculates the FOW-flags for the given quadratic tile.
        /// </summary>
        /// <param name="quadCoords">The quadratic coordinates of the tile.</param>
        private void CalculateFowFlags(RCIntVector quadCoords)
        {
            FOWTypeEnum fowAtQuadCoords = this.GetFowStateAtQuadTile(quadCoords);

            if (fowAtQuadCoords == FOWTypeEnum.Full)
            {
                /// Full FOW-state -> draw only full FOW.
                this.fowCacheMatrix[quadCoords.X, quadCoords.Y].FullFowFlags    = FOWTileFlagsEnum.Current;
                this.fowCacheMatrix[quadCoords.X, quadCoords.Y].PartialFowFlags = FOWTileFlagsEnum.None;
            }
            else if (fowAtQuadCoords == FOWTypeEnum.Partial)
            {
                /// Partial FOW-state -> draw partial FOW and calculate full FOW-flags based on the neighbours.
                FOWTileFlagsEnum fullFowFlags = FOWTileFlagsEnum.None;
                if (this.GetFowStateAtQuadTile(quadCoords + new RCIntVector(0, -1)) == FOWTypeEnum.Full)
                {
                    fullFowFlags |= FOWTileFlagsEnum.North;
                }
                if (this.GetFowStateAtQuadTile(quadCoords + new RCIntVector(1, -1)) == FOWTypeEnum.Full)
                {
                    fullFowFlags |= FOWTileFlagsEnum.NorthEast;
                }
                if (this.GetFowStateAtQuadTile(quadCoords + new RCIntVector(1, 0)) == FOWTypeEnum.Full)
                {
                    fullFowFlags |= FOWTileFlagsEnum.East;
                }
                if (this.GetFowStateAtQuadTile(quadCoords + new RCIntVector(1, 1)) == FOWTypeEnum.Full)
                {
                    fullFowFlags |= FOWTileFlagsEnum.SouthEast;
                }
                if (this.GetFowStateAtQuadTile(quadCoords + new RCIntVector(0, 1)) == FOWTypeEnum.Full)
                {
                    fullFowFlags |= FOWTileFlagsEnum.South;
                }
                if (this.GetFowStateAtQuadTile(quadCoords + new RCIntVector(-1, 1)) == FOWTypeEnum.Full)
                {
                    fullFowFlags |= FOWTileFlagsEnum.SouthWest;
                }
                if (this.GetFowStateAtQuadTile(quadCoords + new RCIntVector(-1, 0)) == FOWTypeEnum.Full)
                {
                    fullFowFlags |= FOWTileFlagsEnum.West;
                }
                if (this.GetFowStateAtQuadTile(quadCoords + new RCIntVector(-1, -1)) == FOWTypeEnum.Full)
                {
                    fullFowFlags |= FOWTileFlagsEnum.NorthWest;
                }
                this.fowCacheMatrix[quadCoords.X, quadCoords.Y].FullFowFlags    = fullFowFlags;
                this.fowCacheMatrix[quadCoords.X, quadCoords.Y].PartialFowFlags = FOWTileFlagsEnum.Current;
            }
            else if (fowAtQuadCoords == FOWTypeEnum.None)
            {
                /// No FOW -> calculate full & partial FOW-flags based on the neighbours.
                FOWTileFlagsEnum fullFowFlags = FOWTileFlagsEnum.None;
                if (this.GetFowStateAtQuadTile(quadCoords + new RCIntVector(0, -1)) == FOWTypeEnum.Full)
                {
                    fullFowFlags |= FOWTileFlagsEnum.North;
                }
                if (this.GetFowStateAtQuadTile(quadCoords + new RCIntVector(1, -1)) == FOWTypeEnum.Full)
                {
                    fullFowFlags |= FOWTileFlagsEnum.NorthEast;
                }
                if (this.GetFowStateAtQuadTile(quadCoords + new RCIntVector(1, 0)) == FOWTypeEnum.Full)
                {
                    fullFowFlags |= FOWTileFlagsEnum.East;
                }
                if (this.GetFowStateAtQuadTile(quadCoords + new RCIntVector(1, 1)) == FOWTypeEnum.Full)
                {
                    fullFowFlags |= FOWTileFlagsEnum.SouthEast;
                }
                if (this.GetFowStateAtQuadTile(quadCoords + new RCIntVector(0, 1)) == FOWTypeEnum.Full)
                {
                    fullFowFlags |= FOWTileFlagsEnum.South;
                }
                if (this.GetFowStateAtQuadTile(quadCoords + new RCIntVector(-1, 1)) == FOWTypeEnum.Full)
                {
                    fullFowFlags |= FOWTileFlagsEnum.SouthWest;
                }
                if (this.GetFowStateAtQuadTile(quadCoords + new RCIntVector(-1, 0)) == FOWTypeEnum.Full)
                {
                    fullFowFlags |= FOWTileFlagsEnum.West;
                }
                if (this.GetFowStateAtQuadTile(quadCoords + new RCIntVector(-1, -1)) == FOWTypeEnum.Full)
                {
                    fullFowFlags |= FOWTileFlagsEnum.NorthWest;
                }
                this.fowCacheMatrix[quadCoords.X, quadCoords.Y].FullFowFlags = fullFowFlags;

                FOWTileFlagsEnum partialFowFlags = FOWTileFlagsEnum.None;
                if (this.GetFowStateAtQuadTile(quadCoords + new RCIntVector(0, -1)) != FOWTypeEnum.None)
                {
                    partialFowFlags |= FOWTileFlagsEnum.North;
                }
                if (this.GetFowStateAtQuadTile(quadCoords + new RCIntVector(1, -1)) != FOWTypeEnum.None)
                {
                    partialFowFlags |= FOWTileFlagsEnum.NorthEast;
                }
                if (this.GetFowStateAtQuadTile(quadCoords + new RCIntVector(1, 0)) != FOWTypeEnum.None)
                {
                    partialFowFlags |= FOWTileFlagsEnum.East;
                }
                if (this.GetFowStateAtQuadTile(quadCoords + new RCIntVector(1, 1)) != FOWTypeEnum.None)
                {
                    partialFowFlags |= FOWTileFlagsEnum.SouthEast;
                }
                if (this.GetFowStateAtQuadTile(quadCoords + new RCIntVector(0, 1)) != FOWTypeEnum.None)
                {
                    partialFowFlags |= FOWTileFlagsEnum.South;
                }
                if (this.GetFowStateAtQuadTile(quadCoords + new RCIntVector(-1, 1)) != FOWTypeEnum.None)
                {
                    partialFowFlags |= FOWTileFlagsEnum.SouthWest;
                }
                if (this.GetFowStateAtQuadTile(quadCoords + new RCIntVector(-1, 0)) != FOWTypeEnum.None)
                {
                    partialFowFlags |= FOWTileFlagsEnum.West;
                }
                if (this.GetFowStateAtQuadTile(quadCoords + new RCIntVector(-1, -1)) != FOWTypeEnum.None)
                {
                    partialFowFlags |= FOWTileFlagsEnum.NorthWest;
                }
                this.fowCacheMatrix[quadCoords.X, quadCoords.Y].PartialFowFlags = partialFowFlags;
            }
        }