Janitor trashbag upgrade + FANCY ANIMATIONS (#3058)

* Janitor trashbag upgrade + FANCY ANIMATIONS

* Review, Bug fixes and Sounds
- Fixed hand-pickup animation playing if the entity originated from inside a container (e.g. bag on the ground) or from inside ourselves (e.g. something in our own inventory)

* Fix/Change. Just log if AnimateEntityPickup is called with an entity that has no SpriteComponent.

* More explicit log message. Error log.

* Merge. Fix.
This commit is contained in:
Remie Richards
2021-02-03 22:07:13 +00:00
committed by GitHub
parent 861271ea44
commit d45835e863
21 changed files with 309 additions and 23 deletions

View File

@@ -0,0 +1,56 @@
using Robust.Client.Animations;
using Robust.Client.GameObjects;
using Robust.Client.GameObjects.Components.Animations;
using Robust.Shared.Animations;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.GameObjects.Components;
using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using System;
namespace Content.Client.Animations
{
public static class ReusableAnimations
{
public static void AnimateEntityPickup(IEntity entity, EntityCoordinates initialPosition, Vector2 finalPosition)
{
var animatableClone = entity.EntityManager.SpawnEntity("clientsideclone", initialPosition);
animatableClone.Name = entity.Name;
if(!entity.TryGetComponent(out SpriteComponent sprite0))
{
Logger.Error($"Entity ({0}) couldn't be animated for pickup since it doesn't have a {1}!", entity.Name, nameof(SpriteComponent));
return;
}
var sprite = animatableClone.GetComponent<SpriteComponent>();
sprite.CopyFrom(sprite0);
var animations = animatableClone.GetComponent<AnimationPlayerComponent>();
animations.AnimationCompleted += (s) => {
animatableClone.Delete();
};
animations.Play(new Animation
{
Length = TimeSpan.FromMilliseconds(125),
AnimationTracks =
{
new AnimationTrackComponentProperty
{
ComponentType = typeof(ITransformComponent),
Property = nameof(ITransformComponent.WorldPosition),
InterpolationMode = AnimationInterpolationMode.Linear,
KeyFrames =
{
new AnimationTrackComponentProperty.KeyFrame(initialPosition.Position, 0),
new AnimationTrackComponentProperty.KeyFrame(finalPosition, 0.125f)
}
}
}
}, "fancy_pickup_anim");
}
}
}

View File

@@ -1,14 +1,23 @@
#nullable enable
#nullable enable
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Content.Client.Animations;
using Content.Client.UserInterface;
using Content.Shared.GameObjects.Components.Items;
using Robust.Client.Animations;
using Robust.Client.GameObjects;
using Robust.Client.GameObjects.Components.Animations;
using Robust.Client.Interfaces.GameObjects.Components;
using Robust.Shared.Animations;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.GameObjects.Components;
using Robust.Shared.Interfaces.Network;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Players;
using Robust.Shared.ViewVariables;
namespace Content.Client.GameObjects.Components.Items
@@ -244,6 +253,23 @@ namespace Content.Client.GameObjects.Components.Items
}
}
public override void HandleNetworkMessage(ComponentMessage message, INetChannel netChannel, ICommonSession? session = null)
{
base.HandleNetworkMessage(message, netChannel, session);
switch (message)
{
case AnimatePickupEntityMessage msg:
{
if (Owner.EntityManager.TryGetEntity(msg.EntityId, out var entity))
{
ReusableAnimations.AnimateEntityPickup(entity, msg.EntityPosition, Owner.Transform.WorldPosition);
}
break;
}
}
}
public void SendChangeHand(string index)
{
SendNetworkMessage(new ClientChangedHandMsg(index));

View File

@@ -1,17 +1,23 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using Content.Client.Animations;
using Content.Client.GameObjects.Components.Items;
using Content.Shared.GameObjects.Components.Storage;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Client.Animations;
using Robust.Client.GameObjects;
using Robust.Client.GameObjects.Components.Animations;
using Robust.Client.Graphics.Drawing;
using Robust.Client.Interfaces.GameObjects.Components;
using Robust.Client.Player;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.Animations;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.GameObjects.Components;
using Robust.Shared.Interfaces.Network;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
@@ -77,6 +83,9 @@ namespace Content.Client.GameObjects.Components.Storage
case CloseStorageUIMessage _:
CloseUI();
break;
case AnimateInsertingEntitiesMessage msg:
HandleAnimatingInsertingEntities(msg);
break;
}
}
@@ -92,6 +101,24 @@ namespace Content.Client.GameObjects.Components.Storage
Window.BuildEntityList();
}
/// <summary>
/// Animate the newly stored entities in <paramref name="msg"/> flying towards this storage's position
/// </summary>
/// <param name="msg"></param>
private void HandleAnimatingInsertingEntities(AnimateInsertingEntitiesMessage msg)
{
for (var i = 0; msg.StoredEntities.Count > i; i++)
{
var entityId = msg.StoredEntities[i];
var initialPosition = msg.EntityPositions[i];
if (Owner.EntityManager.TryGetEntity(entityId, out var entity))
{
ReusableAnimations.AnimateEntityPickup(entity, initialPosition, Owner.Transform.WorldPosition);
}
}
}
/// <summary>
/// Opens the storage UI if closed. Closes it if opened.
/// </summary>