Пример #1
0
 /// <summary>
 /// Gets the <see cref="GrhData"/> for a set.
 /// </summary>
 /// <param name="bodyName">The name of the body (determines the category to use).</param>
 /// <param name="setName">The name of the set (the sprite categorization title).</param>
 /// <returns>The <see cref="GrhData"/> for the given body and set, or null if not found.</returns>
 GrhData GetSetGrhData(string bodyName, string setName)
 {
     return(GrhInfo.GetData(_rootCategory + SpriteCategorization.Delimiter + bodyName, setName));
 }
Пример #2
0
        /// <summary>
        /// Draws the <see cref="ICharacterSprite"/>.
        /// </summary>
        /// <param name="spriteBatch">The <see cref="ISpriteBatch"/> to draw with.</param>
        /// <param name="position">The position to draw the sprite.</param>
        /// <param name="heading">The character's heading.</param>
        /// <param name="color">The color of the sprite.</param>
        public void Draw(ISpriteBatch spriteBatch, Vector2 position, Direction heading, Color color)
        {
            // If we have a body modifier being used, invalidate it if:
            // 1. The heading has changed.
            // 2. The animation has ended.
            //
            // If we don't have a body modifier being used, just ensure we have the correct Set being used.
            //
            // If we are moving, always use the walking animation.

            _currentHeading = heading;

            // If the body modifier is set, check if it needs to be unset
            if (_currentBodyModifier != null)
            {
                if (_bodyGrh.AnimType == AnimType.None || _bodyModifierDirection != heading)
                {
                    _currentBodyModifier = null;
                }
            }

            // If we are moving, the body modifier is not set, or the sprite is invalid, use the non-modifier set
            if (Character.Velocity != Vector2.Zero || _currentBodyModifier == null || _bodyGrh.GrhData == null)
            {
                var prefix          = (Character.Velocity == Vector2.Zero ? string.Empty : "Walk ");
                var directionSuffix = GetDirectionSetName(heading);

                _currentBodyModifier = null;
                InternalSetSet(prefix + directionSuffix);
            }

            // Ensure the sprite is valid before trying to update and draw it
            if (_bodyGrh.GrhData == null)
            {
                return;
            }

            // Update
            _bodyGrh.Update(_currentTime);

            position += new Vector2(Character.Size.X / 2f, Character.Size.Y - _bodyGrh.Size.Y);

            // Get the GrhDatas to draw, along with their draw order
            List <Tuple <int, GrhData, PaperDollLayerType> > grhDatas = new List <Tuple <int, GrhData, PaperDollLayerType> >();

            grhDatas.Add(new Tuple <int, GrhData, PaperDollLayerType>(GetLayerOrder(PaperDollLayerType.Body, heading), _bodyGrh.GrhData, PaperDollLayerType.Body));

            if (Paperdoll)
            {
                string setSuffix = !string.IsNullOrEmpty(_currentSet) ? "." + _currentSet : "";
                if (_layers != null)
                {
                    foreach (var layerName in _layers)
                    {
                        GrhData gd = GrhInfo.GetData(new SpriteCategorization("Character." + layerName + setSuffix));
                        if (gd == null)
                        {
                            continue;
                        }

                        PaperDollLayerType layerType = GetPaperDollLayerType(layerName);
                        int layerOrder = GetLayerOrder(layerType, heading);
                        grhDatas.Add(new Tuple <int, GrhData, PaperDollLayerType>(layerOrder, gd, layerType));
                    }
                }
            }

            // Sort by layer order
            grhDatas = grhDatas.OrderBy(x => x.Item1).ToList();

            // Draw in order
            var drawingGrh = _bodyGrh.DeepCopy();

            for (int i = 0; i < grhDatas.Count; i++)
            {
                GrhData gd = grhDatas[i].Item2;

                // Set frame
                GrhData gdFrame = gd.GetFrame((int)Math.Floor(_bodyGrh.Frame)) ?? gd.Frames.LastOrDefault();
                if (gdFrame == null)
                {
                    continue;
                }

                drawingGrh.SetGrh(gdFrame);

                // Get offset
                Vector2 sizeXOffset = new Vector2(drawingGrh.Size.X / -2f, 0);
                Vector2 layerOffset = GetPaperDollLayerOffset(grhDatas[i].Item3);

                // Draw
                drawingGrh.Draw(spriteBatch, position + layerOffset + sizeXOffset, color);
            }
        }