Exemple #1
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);
        }
Exemple #2
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);
        }