Skip to content

Commit

Permalink
Merge branch 'master' into fix-jittering
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepyyapril authored Dec 12, 2024
2 parents 02d9cb9 + 478e159 commit ad956c2
Show file tree
Hide file tree
Showing 544 changed files with 6,350 additions and 478 deletions.
121 changes: 121 additions & 0 deletions Content.Client/Emoting/AnimatedEmotesSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
using Robust.Client.Animations;
using Robust.Shared.Animations;
using Robust.Shared.GameStates;
using Robust.Client.GameObjects;
using Content.Shared.Emoting;
using System.Numerics;
using Robust.Shared.Prototypes;
using Content.Shared.Chat.Prototypes;

namespace Content.Client.Emoting;

public sealed partial class AnimatedEmotesSystem : SharedAnimatedEmotesSystem
{
[Dependency] private readonly AnimationPlayerSystem _anim = default!;
[Dependency] private readonly IPrototypeManager _prot = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<AnimatedEmotesComponent, ComponentHandleState>(OnHandleState);

SubscribeLocalEvent<AnimatedEmotesComponent, AnimationFlipEmoteEvent>(OnFlip);
SubscribeLocalEvent<AnimatedEmotesComponent, AnimationSpinEmoteEvent>(OnSpin);
SubscribeLocalEvent<AnimatedEmotesComponent, AnimationJumpEmoteEvent>(OnJump);
}

public void PlayEmote(EntityUid uid, Animation anim, string animationKey = "emoteAnimKeyId")
{
if (_anim.HasRunningAnimation(uid, animationKey))
return;

_anim.Play(uid, anim, animationKey);
}

private void OnHandleState(EntityUid uid, AnimatedEmotesComponent component, ref ComponentHandleState args)
{
if (args.Current is not AnimatedEmotesComponentState state
|| !_prot.TryIndex<EmotePrototype>(state.Emote, out var emote))
return;

if (emote.Event != null)
RaiseLocalEvent(uid, emote.Event);
}

private void OnFlip(Entity<AnimatedEmotesComponent> ent, ref AnimationFlipEmoteEvent args)
{
var a = new Animation
{
Length = TimeSpan.FromMilliseconds(500),
AnimationTracks =
{
new AnimationTrackComponentProperty
{
ComponentType = typeof(SpriteComponent),
Property = nameof(SpriteComponent.Rotation),
InterpolationMode = AnimationInterpolationMode.Linear,
KeyFrames =
{
new AnimationTrackProperty.KeyFrame(Angle.Zero, 0f),
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(180), 0.25f),
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(360), 0.25f),
}
}
}
};
PlayEmote(ent, a);
}
private void OnSpin(Entity<AnimatedEmotesComponent> ent, ref AnimationSpinEmoteEvent args)
{
var a = new Animation
{
Length = TimeSpan.FromMilliseconds(600),
AnimationTracks =
{
new AnimationTrackComponentProperty
{
ComponentType = typeof(TransformComponent),
Property = nameof(TransformComponent.LocalRotation),
InterpolationMode = AnimationInterpolationMode.Linear,
KeyFrames =
{
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(0), 0f),
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(90), 0.075f),
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(180), 0.075f),
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(270), 0.075f),
new AnimationTrackProperty.KeyFrame(Angle.Zero, 0.075f),
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(90), 0.075f),
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(180), 0.075f),
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(270), 0.075f),
new AnimationTrackProperty.KeyFrame(Angle.Zero, 0.075f),
}
}
}
};
PlayEmote(ent, a, "emoteAnimSpin");
}
private void OnJump(Entity<AnimatedEmotesComponent> ent, ref AnimationJumpEmoteEvent args)
{
var a = new Animation
{
Length = TimeSpan.FromMilliseconds(250),
AnimationTracks =
{
new AnimationTrackComponentProperty
{
ComponentType = typeof(SpriteComponent),
Property = nameof(SpriteComponent.Offset),
InterpolationMode = AnimationInterpolationMode.Cubic,
KeyFrames =
{
new AnimationTrackProperty.KeyFrame(Vector2.Zero, 0f),
new AnimationTrackProperty.KeyFrame(new Vector2(0, .35f), 0.125f),
new AnimationTrackProperty.KeyFrame(Vector2.Zero, 0.125f),
}
}
}
};
PlayEmote(ent, a);
}
}
2 changes: 1 addition & 1 deletion Content.Client/ListViewSelector/ListViewSelectorBUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private void PopulateWindow(List<ListViewSelectorEntry> items)
{
var itemName = item.Name;
var itemDesc = item.Description;
if (_prototypeManager.TryIndex(item.Id, out var itemPrototype))
if (_prototypeManager.TryIndex(item.Id, out var itemPrototype, false))
{
itemName = itemPrototype.Name;
itemDesc = itemPrototype.Description;
Expand Down
10 changes: 10 additions & 0 deletions Content.Client/Weapons/Melee/MeleeWeaponSystem.Effects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ private Animation GetThrustAnimation(SpriteComponent sprite, float distance, Ang
{
const float thrustEnd = 0.05f;
const float length = 0.15f;
var rotation = sprite.Rotation + spriteRotation;
var startOffset = sprite.Rotation.RotateVec(new Vector2(0f, -distance / 5f));
var endOffset = sprite.Rotation.RotateVec(new Vector2(0f, -distance));

Expand All @@ -144,6 +145,15 @@ private Animation GetThrustAnimation(SpriteComponent sprite, float distance, Ang
Length = TimeSpan.FromSeconds(length),
AnimationTracks =
{
new AnimationTrackComponentProperty()
{
ComponentType = typeof(SpriteComponent),
Property = nameof(SpriteComponent.Rotation),
KeyFrames =
{
new AnimationTrackProperty.KeyFrame(rotation, 0f),
}
},
new AnimationTrackComponentProperty()
{
ComponentType = typeof(SpriteComponent),
Expand Down
37 changes: 21 additions & 16 deletions Content.Client/Weapons/Melee/MeleeWeaponSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Content.Shared.Weapons.Melee;
using Content.Shared.Weapons.Melee.Events;
using Content.Shared.Weapons.Ranged.Components;
using Content.Shared.Wieldable.Components;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.Input;
Expand Down Expand Up @@ -71,34 +72,36 @@ public override void Update(float frameTime)
return;
}

var useDown = _inputSystem.CmdStates.GetState(EngineKeyFunctions.Use);
var altDown = _inputSystem.CmdStates.GetState(EngineKeyFunctions.UseSecondary);
var useDown = _inputSystem.CmdStates.GetState(EngineKeyFunctions.Use) == BoundKeyState.Down;
var altDown = _inputSystem.CmdStates.GetState(EngineKeyFunctions.UseSecondary) == BoundKeyState.Down;

if (weapon.AutoAttack || useDown != BoundKeyState.Down && altDown != BoundKeyState.Down)
// Disregard inputs to the shoot binding
if (TryComp<GunComponent>(weaponUid, out var gun) &&
// Except if can't shoot due to being unwielded
(!HasComp<GunRequiresWieldComponent>(weaponUid) ||
(TryComp<WieldableComponent>(weaponUid, out var wieldable) && wieldable.Wielded)))
{
if (gun.UseKey)
useDown = false;
else
altDown = false;
}

if (weapon.AutoAttack || !useDown && !altDown)
{
if (weapon.Attacking)
{
RaisePredictiveEvent(new StopAttackEvent(GetNetEntity(weaponUid)));
}
}

if (weapon.Attacking || weapon.NextAttack > Timing.CurTime)
if (weapon.Attacking || weapon.NextAttack > Timing.CurTime || (!useDown && !altDown))
{
return;
}

// TODO using targeted actions while combat mode is enabled should NOT trigger attacks.

// TODO: Need to make alt-fire melee its own component I guess?
// Melee and guns share a lot in the middle but share virtually nothing at the start and end so
// it's kinda tricky.
// I think as long as we make secondaries their own component it's probably fine
// as long as guncomp has an alt-use key then it shouldn't be too much of a PITA to deal with.
if (TryComp<GunComponent>(weaponUid, out var gun) && gun.UseKey)
{
return;
}

var mousePos = _eyeManager.PixelToMap(_inputManager.MouseScreenPosition);

if (mousePos.MapId == MapId.Nullspace)
Expand All @@ -118,7 +121,8 @@ public override void Update(float frameTime)
}

// Heavy attack.
if (altDown == BoundKeyState.Down)
if (!weapon.DisableHeavy &&
(!weapon.SwapKeys ? altDown : useDown))
{
// If it's an unarmed attack then do a disarm
if (weapon.AltDisarm && weaponUid == entity)
Expand All @@ -139,7 +143,8 @@ public override void Update(float frameTime)
}

// Light attack
if (useDown == BoundKeyState.Down)
if (!weapon.DisableClick &&
(!weapon.SwapKeys ? useDown : altDown))
{
var attackerPos = Transform(entity).MapPosition;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using Content.Shared.WhiteDream.BloodCult.Constructs.PhaseShift;

namespace Content.Client.WhiteDream.BloodCult.PhaseShift;

public sealed class PhaseShiftSystem : SharedPhaseShiftSystem;
61 changes: 29 additions & 32 deletions Content.Client/WhiteDream/BloodCult/Runes/UI/RuneDrawerBUI.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Linq;
using System.Numerics;
using System.Numerics;
using Content.Client.UserInterface.Controls;
using Content.Shared.WhiteDream.BloodCult.Runes;
using JetBrains.Annotations;
Expand All @@ -23,71 +22,72 @@ public sealed class RuneDrawerBUI : BoundUserInterface
[Dependency] private readonly IInputManager _inputManager = default!;

private readonly SpriteSystem _spriteSystem;

private RadialMenu? _menu;
private readonly RadialMenu _menu;

public RuneDrawerBUI(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
_spriteSystem = _entManager.System<SpriteSystem>();
_menu = new()
{
HorizontalExpand = true,
VerticalExpand = true,
BackButtonStyleClass = "RadialMenuBackButton",
CloseButtonStyleClass = "RadialMenuCloseButton"
};
}

protected override void Open()
{
_menu = FormMenu();
_menu.OnClose += Close;
_menu.OpenCenteredAt(_inputManager.MouseScreenPosition.Position / _displayManager.ScreenSize);
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
_menu?.Dispose();
_menu.Close();
}

private RadialMenu FormMenu()
protected override void UpdateState(BoundUserInterfaceState state)
{
var menu = new RadialMenu
{
HorizontalExpand = true,
VerticalExpand = true,
BackButtonStyleClass = "RadialMenuBackButton",
CloseButtonStyleClass = "RadialMenuCloseButton"
};

if (!_entManager.HasComponent<RuneDrawerComponent>(Owner))
return menu;
if (state is RuneDrawerMenuState runeDrawerState)
FillMenu(runeDrawerState.AvailalbeRunes);
}

var runeSelectorArray = _protoManager.EnumeratePrototypes<RuneSelectorPrototype>().OrderBy(r => r.ID).ToArray();
private void FillMenu(List<ProtoId<RuneSelectorPrototype>>? runes = null)
{
if (runes is null)
return;

var mainContainer = new RadialContainer
var container = new RadialContainer
{
Radius = 36f / (runeSelectorArray.Length == 1
? 1
: MathF.Sin(MathF.PI / runeSelectorArray.Length))
Radius = 48f + 24f * MathF.Log(runes.Count)
};

foreach (var runeSelector in runeSelectorArray)
_menu.AddChild(container);

foreach (var runeSelector in runes)
{
if (!_protoManager.TryIndex(runeSelector.Prototype, out var proto))
if (!_protoManager.TryIndex(runeSelector, out var runeSelectorProto) ||
!_protoManager.TryIndex(runeSelectorProto.Prototype, out var runeProto))
continue;

var itemSize = new Vector2(64f, 64f);
var button = new RadialMenuTextureButton
{
ToolTip = Loc.GetString(proto.Name),
ToolTip = Loc.GetString(runeProto.Name),
StyleClasses = { "RadialMenuButton" },
SetSize = itemSize
};

var runeIcon = _spriteSystem.Frame0(proto);
var runeIcon = _spriteSystem.Frame0(runeProto);
var runeScale = itemSize / runeIcon.Size;

var texture = new TextureRect
{
VerticalAlignment = Control.VAlignment.Center,
HorizontalAlignment = Control.HAlignment.Center,
Texture = _spriteSystem.Frame0(proto),
Texture = _spriteSystem.Frame0(runeProto),
TextureScale = runeScale
};

Expand All @@ -99,10 +99,7 @@ private RadialMenu FormMenu()
Close();
};

mainContainer.AddChild(button);
container.AddChild(button);
}

menu.AddChild(mainContainer);
return menu;
}
}
2 changes: 1 addition & 1 deletion Content.Server/Chat/Systems/ChatSystem.Emote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private void TryEmoteChatInput(EntityUid uid, string textInput)
private void InvokeEmoteEvent(EntityUid uid, EmotePrototype proto)
{
var ev = new EmoteEvent(proto);
RaiseLocalEvent(uid, ref ev);
RaiseLocalEvent(uid, ref ev, true); // goob edit
}
}

Expand Down
28 changes: 28 additions & 0 deletions Content.Server/Emoting/AnimatedEmotesSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Robust.Shared.GameStates;
using Content.Server.Chat.Systems;
using Content.Shared.Chat.Prototypes;
using Content.Shared.Emoting;
using Robust.Shared.Prototypes;

namespace Content.Server.Emoting;

public sealed partial class AnimatedEmotesSystem : SharedAnimatedEmotesSystem
{
public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<AnimatedEmotesComponent, EmoteEvent>(OnEmote);
}

private void OnEmote(EntityUid uid, AnimatedEmotesComponent component, ref EmoteEvent args)
{
PlayEmoteAnimation(uid, component, args.Emote.ID);
}

public void PlayEmoteAnimation(EntityUid uid, AnimatedEmotesComponent component, ProtoId<EmotePrototype> prot)
{
component.Emote = prot;
Dirty(uid, component);
}
}
Loading

0 comments on commit ad956c2

Please sign in to comment.