Ejemplo n.º 1
0
        /// <inheritdoc />
        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch, IProjector projector)
        {
            if (Effect != null && Effect.Duration < gameTime.TotalGameTime - Effect.CreationTime)
            {
                Effect = null;
            }

            if (Effect is GlowEffect glowEffect)
            {
                var effectLocalSize = projector.ScaleToLocal(new Vector2(glowEffect.PixelSize, glowEffect.PixelSize));
                spriteBatch.ProjectionDraw(projector, CommonTextures.CardBorder, effectLocalSize * -1, (_size + 2 * effectLocalSize) / _size, Color.Yellow * 0.5f);
            }
            else if (Effect is PulsingGlowEffect pulsingGlowEffect)
            {
                var elapsedTime = gameTime.TotalGameTime - pulsingGlowEffect.CreationTime;

                var singleDuration = Effect.Duration.Ticks / pulsingGlowEffect.Times;
                var ratio          = (elapsedTime.Ticks % singleDuration) / (float)singleDuration;

                var opacity         = (1 - ratio) * pulsingGlowEffect.MaxOpacity;
                var effectSize      = ratio * pulsingGlowEffect.PixelSize;
                var effectLocalSize = projector.ScaleToLocal(new Vector2(effectSize, effectSize));

                spriteBatch.ProjectionDraw(projector, CommonTextures.CardBorder, effectLocalSize * -1, (_size + 2 * effectLocalSize) / _size, Color.Red * opacity);
            }

            spriteBatch.ProjectionDraw(projector, CommonTextures.CardBorder, Vector2.Zero, Color.Black);
            spriteBatch.ProjectionDraw(projector, Image, _textureOffset);
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        public void Update(GameTime gameTime, ref bool captureEvents, IProjector projector)
        {
            if (!captureEvents)
            {
                return;
            }

            if (InputService.LeftMousePressed)
            {
                if (!InputService.IsDragging)
                {
                    var mousePosition = InputService.MousePosition.ToVector2();
                    var selectedItem  = Items.LastOrDefault(i => i.Contains(mousePosition, projector));
                    SelectedItem = selectedItem;
                    foreach (var item in Items)
                    {
                        item.Value.RemoveEffect(EffectType.Glow);
                    }
                    if (SelectedItem != null)
                    {
                        SelectedItem.Value.CreateEffect(EffectType.Glow, gameTime, TimeSpan.MaxValue);
                    }
                }
                else if (SelectedItem != null)
                {
                    var dragDelta = projector.ScaleToLocal(InputService.DragDelta.ToVector2());
                    SelectedItem._translate += dragDelta;
                    captureEvents            = false;
                }
            }
            else
            {
                if (InputService.DoubleClicked)
                {
                    if (SelectedItem != null)
                    {
                        SelectedItem.Value.CreateEffect(EffectType.PulsingGlow, gameTime, TimeSpan.FromSeconds(1));
                    }
                }
                else
                {
                    var mousePosition = InputService.MousePosition.ToVector2();
                    HoveredCard = Items.Where(i => i.Value is Card).LastOrDefault(i => i.Contains(mousePosition, projector));
                }
            }
            return;
        }