2021-07-12 01:32:10 -07:00
|
|
|
using System;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Client.IoC;
|
|
|
|
|
using Content.Client.Items.Components;
|
|
|
|
|
using Content.Client.Resources;
|
|
|
|
|
using Content.Client.Stylesheets;
|
|
|
|
|
using Content.Shared.Weapons.Ranged.Barrels.Components;
|
2020-01-09 00:27:52 +01:00
|
|
|
using Robust.Client.Animations;
|
|
|
|
|
using Robust.Client.Graphics;
|
|
|
|
|
using Robust.Client.UserInterface;
|
|
|
|
|
using Robust.Client.UserInterface.Controls;
|
|
|
|
|
using Robust.Shared.Animations;
|
|
|
|
|
using Robust.Shared.GameObjects;
|
2021-07-12 01:32:10 -07:00
|
|
|
using Robust.Shared.GameStates;
|
2020-01-09 00:27:52 +01:00
|
|
|
using Robust.Shared.Maths;
|
2021-03-05 01:08:38 +01:00
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2020-01-09 00:27:52 +01:00
|
|
|
using Robust.Shared.ViewVariables;
|
2021-07-18 18:39:31 +02:00
|
|
|
using static Robust.Client.UserInterface.Controls.BoxContainer;
|
2020-01-09 00:27:52 +01:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Client.Weapons.Ranged.Barrels.Components
|
2020-01-09 00:27:52 +01:00
|
|
|
{
|
|
|
|
|
[RegisterComponent]
|
2021-07-12 01:32:10 -07:00
|
|
|
[NetworkedComponent()]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class ClientMagazineBarrelComponent : Component, IItemStatus
|
2020-01-09 00:27:52 +01:00
|
|
|
{
|
2020-11-27 11:00:49 +01:00
|
|
|
private static readonly Animation AlarmAnimationSmg = new()
|
2020-01-09 00:27:52 +01:00
|
|
|
{
|
|
|
|
|
Length = TimeSpan.FromSeconds(1.4),
|
|
|
|
|
AnimationTracks =
|
|
|
|
|
{
|
|
|
|
|
new AnimationTrackControlProperty
|
|
|
|
|
{
|
|
|
|
|
// These timings match the SMG audio file.
|
|
|
|
|
Property = nameof(Label.FontColorOverride),
|
|
|
|
|
InterpolationMode = AnimationInterpolationMode.Previous,
|
|
|
|
|
KeyFrames =
|
|
|
|
|
{
|
|
|
|
|
new AnimationTrackProperty.KeyFrame(Color.Red, 0.1f),
|
2021-03-10 14:48:29 +01:00
|
|
|
new AnimationTrackProperty.KeyFrame(null!, 0.3f),
|
2020-01-09 00:27:52 +01:00
|
|
|
new AnimationTrackProperty.KeyFrame(Color.Red, 0.2f),
|
2021-03-10 14:48:29 +01:00
|
|
|
new AnimationTrackProperty.KeyFrame(null!, 0.3f),
|
2020-01-09 00:27:52 +01:00
|
|
|
new AnimationTrackProperty.KeyFrame(Color.Red, 0.2f),
|
2021-03-10 14:48:29 +01:00
|
|
|
new AnimationTrackProperty.KeyFrame(null!, 0.3f),
|
2020-01-09 00:27:52 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-11-27 11:00:49 +01:00
|
|
|
private static readonly Animation AlarmAnimationLmg = new()
|
2020-01-09 00:27:52 +01:00
|
|
|
{
|
|
|
|
|
Length = TimeSpan.FromSeconds(0.75),
|
|
|
|
|
AnimationTracks =
|
|
|
|
|
{
|
|
|
|
|
new AnimationTrackControlProperty
|
|
|
|
|
{
|
|
|
|
|
// These timings match the SMG audio file.
|
|
|
|
|
Property = nameof(Label.FontColorOverride),
|
|
|
|
|
InterpolationMode = AnimationInterpolationMode.Previous,
|
|
|
|
|
KeyFrames =
|
|
|
|
|
{
|
|
|
|
|
new AnimationTrackProperty.KeyFrame(Color.Red, 0.0f),
|
2021-03-10 14:48:29 +01:00
|
|
|
new AnimationTrackProperty.KeyFrame(null!, 0.15f),
|
2020-01-09 00:27:52 +01:00
|
|
|
new AnimationTrackProperty.KeyFrame(Color.Red, 0.15f),
|
2021-03-10 14:48:29 +01:00
|
|
|
new AnimationTrackProperty.KeyFrame(null!, 0.15f),
|
2020-01-09 00:27:52 +01:00
|
|
|
new AnimationTrackProperty.KeyFrame(Color.Red, 0.15f),
|
2021-03-10 14:48:29 +01:00
|
|
|
new AnimationTrackProperty.KeyFrame(null!, 0.15f),
|
2020-01-09 00:27:52 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
2021-03-10 14:48:29 +01:00
|
|
|
private StatusControl? _statusControl;
|
2020-01-09 00:27:52 +01:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// True if a bullet is chambered.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ViewVariables]
|
|
|
|
|
public bool Chambered { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Count of bullets in the magazine.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// Null if no magazine is inserted.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
[ViewVariables]
|
|
|
|
|
public (int count, int max)? MagazineCount { get; private set; }
|
|
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
[ViewVariables(VVAccess.ReadWrite)] [DataField("lmg_alarm_animation")] private bool _isLmgAlarmAnimation = default;
|
2020-01-09 00:27:52 +01:00
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
2020-01-09 00:27:52 +01:00
|
|
|
{
|
2020-11-26 14:33:31 +01:00
|
|
|
base.HandleComponentState(curState, nextState);
|
|
|
|
|
|
|
|
|
|
if (curState is not MagazineBarrelComponentState cast)
|
2020-02-09 02:28:47 -08:00
|
|
|
return;
|
2020-01-09 00:27:52 +01:00
|
|
|
|
|
|
|
|
Chambered = cast.Chambered;
|
2020-06-22 05:47:15 +10:00
|
|
|
MagazineCount = cast.Magazine;
|
2020-01-09 00:27:52 +01:00
|
|
|
_statusControl?.Update();
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-30 17:39:46 +11:00
|
|
|
public void PlayAlarmAnimation()
|
2020-01-09 00:27:52 +01:00
|
|
|
{
|
2022-01-30 17:39:46 +11:00
|
|
|
_statusControl?.PlayAlarmAnimation();
|
2020-01-09 00:27:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Control MakeControl()
|
|
|
|
|
{
|
|
|
|
|
_statusControl = new StatusControl(this);
|
|
|
|
|
_statusControl.Update();
|
|
|
|
|
return _statusControl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DestroyControl(Control control)
|
|
|
|
|
{
|
|
|
|
|
if (_statusControl == control)
|
|
|
|
|
{
|
|
|
|
|
_statusControl = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private sealed class StatusControl : Control
|
|
|
|
|
{
|
2020-06-22 05:47:15 +10:00
|
|
|
private readonly ClientMagazineBarrelComponent _parent;
|
2021-07-18 18:39:31 +02:00
|
|
|
private readonly BoxContainer _bulletsList;
|
2020-01-09 00:27:52 +01:00
|
|
|
private readonly TextureRect _chamberedBullet;
|
|
|
|
|
private readonly Label _noMagazineLabel;
|
2020-08-24 13:13:26 +02:00
|
|
|
private readonly Label _ammoCount;
|
2020-01-09 00:27:52 +01:00
|
|
|
|
2020-06-22 05:47:15 +10:00
|
|
|
public StatusControl(ClientMagazineBarrelComponent parent)
|
2020-01-09 00:27:52 +01:00
|
|
|
{
|
2021-02-21 12:38:56 +01:00
|
|
|
MinHeight = 15;
|
2020-01-09 00:27:52 +01:00
|
|
|
_parent = parent;
|
2021-02-21 12:38:56 +01:00
|
|
|
HorizontalExpand = true;
|
|
|
|
|
VerticalAlignment = VAlignment.Center;
|
2020-08-24 13:13:26 +02:00
|
|
|
|
2021-07-18 18:39:31 +02:00
|
|
|
AddChild(new BoxContainer
|
2020-01-09 00:27:52 +01:00
|
|
|
{
|
2021-07-18 18:39:31 +02:00
|
|
|
Orientation = LayoutOrientation.Horizontal,
|
2021-02-21 12:38:56 +01:00
|
|
|
HorizontalExpand = true,
|
2020-01-09 00:27:52 +01:00
|
|
|
Children =
|
|
|
|
|
{
|
2020-08-24 13:13:26 +02:00
|
|
|
(_chamberedBullet = new TextureRect
|
|
|
|
|
{
|
|
|
|
|
Texture = StaticIoC.ResC.GetTexture("/Textures/Interface/ItemStatus/Bullets/chambered_rotated.png"),
|
2021-02-21 12:38:56 +01:00
|
|
|
VerticalAlignment = VAlignment.Center,
|
|
|
|
|
HorizontalAlignment = HAlignment.Right,
|
2020-08-24 13:13:26 +02:00
|
|
|
}),
|
2021-02-21 12:38:56 +01:00
|
|
|
new Control() { MinSize = (5,0) },
|
2020-08-24 13:13:26 +02:00
|
|
|
new Control
|
2020-01-09 00:27:52 +01:00
|
|
|
{
|
2021-02-21 12:38:56 +01:00
|
|
|
HorizontalExpand = true,
|
2020-01-09 00:27:52 +01:00
|
|
|
Children =
|
|
|
|
|
{
|
2021-07-18 18:39:31 +02:00
|
|
|
(_bulletsList = new BoxContainer
|
2020-01-09 00:27:52 +01:00
|
|
|
{
|
2021-07-18 18:39:31 +02:00
|
|
|
Orientation = LayoutOrientation.Horizontal,
|
2021-02-21 12:38:56 +01:00
|
|
|
VerticalAlignment = VAlignment.Center,
|
2020-08-24 13:13:26 +02:00
|
|
|
SeparationOverride = 0
|
|
|
|
|
}),
|
|
|
|
|
(_noMagazineLabel = new Label
|
|
|
|
|
{
|
|
|
|
|
Text = "No Magazine!",
|
|
|
|
|
StyleClasses = {StyleNano.StyleClassItemStatus}
|
2020-01-09 00:27:52 +01:00
|
|
|
})
|
|
|
|
|
}
|
2020-08-24 13:13:26 +02:00
|
|
|
},
|
2021-02-21 12:38:56 +01:00
|
|
|
new Control() { MinSize = (5,0) },
|
2020-08-24 13:13:26 +02:00
|
|
|
(_ammoCount = new Label
|
|
|
|
|
{
|
|
|
|
|
StyleClasses = {StyleNano.StyleClassItemStatus},
|
2021-02-21 12:38:56 +01:00
|
|
|
HorizontalAlignment = HAlignment.Right,
|
2020-08-24 13:13:26 +02:00
|
|
|
}),
|
2020-01-09 00:27:52 +01:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update()
|
|
|
|
|
{
|
|
|
|
|
_chamberedBullet.ModulateSelfOverride =
|
|
|
|
|
_parent.Chambered ? Color.FromHex("#d7df60") : Color.Black;
|
|
|
|
|
|
2020-08-24 13:13:26 +02:00
|
|
|
_bulletsList.RemoveAllChildren();
|
2020-01-09 00:27:52 +01:00
|
|
|
|
|
|
|
|
if (_parent.MagazineCount == null)
|
|
|
|
|
{
|
|
|
|
|
_noMagazineLabel.Visible = true;
|
2020-08-24 13:13:26 +02:00
|
|
|
_ammoCount.Visible = false;
|
2020-01-09 00:27:52 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var (count, capacity) = _parent.MagazineCount.Value;
|
|
|
|
|
|
|
|
|
|
_noMagazineLabel.Visible = false;
|
2020-08-24 13:13:26 +02:00
|
|
|
_ammoCount.Visible = true;
|
2020-01-09 00:27:52 +01:00
|
|
|
|
2020-08-24 13:13:26 +02:00
|
|
|
var texturePath = "/Textures/Interface/ItemStatus/Bullets/normal.png";
|
2020-06-22 05:47:15 +10:00
|
|
|
var texture = StaticIoC.ResC.GetTexture(texturePath);
|
2020-01-09 00:27:52 +01:00
|
|
|
|
2020-08-24 13:13:26 +02:00
|
|
|
_ammoCount.Text = $"x{count:00}";
|
|
|
|
|
capacity = Math.Min(capacity, 20);
|
|
|
|
|
FillBulletRow(_bulletsList, count, capacity, texture);
|
2020-01-09 00:27:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void FillBulletRow(Control container, int count, int capacity, Texture texture)
|
|
|
|
|
{
|
|
|
|
|
var colorA = Color.FromHex("#b68f0e");
|
|
|
|
|
var colorB = Color.FromHex("#d7df60");
|
|
|
|
|
var colorGoneA = Color.FromHex("#000000");
|
|
|
|
|
var colorGoneB = Color.FromHex("#222222");
|
|
|
|
|
|
|
|
|
|
var altColor = false;
|
|
|
|
|
|
2020-08-24 13:13:26 +02:00
|
|
|
// Draw the empty ones
|
2020-01-09 00:27:52 +01:00
|
|
|
for (var i = count; i < capacity; i++)
|
|
|
|
|
{
|
|
|
|
|
container.AddChild(new TextureRect
|
|
|
|
|
{
|
|
|
|
|
Texture = texture,
|
2020-08-24 13:13:26 +02:00
|
|
|
ModulateSelfOverride = altColor ? colorGoneA : colorGoneB,
|
|
|
|
|
Stretch = TextureRect.StretchMode.KeepCentered
|
2020-01-09 00:27:52 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
altColor ^= true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-24 13:13:26 +02:00
|
|
|
// Draw the full ones, but limit the count to the capacity
|
|
|
|
|
count = Math.Min(count, capacity);
|
2020-01-09 00:27:52 +01:00
|
|
|
for (var i = 0; i < count; i++)
|
|
|
|
|
{
|
|
|
|
|
container.AddChild(new TextureRect
|
|
|
|
|
{
|
|
|
|
|
Texture = texture,
|
2020-08-24 13:13:26 +02:00
|
|
|
ModulateSelfOverride = altColor ? colorA : colorB,
|
|
|
|
|
Stretch = TextureRect.StretchMode.KeepCentered
|
2020-01-09 00:27:52 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
altColor ^= true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void PlayAlarmAnimation()
|
|
|
|
|
{
|
|
|
|
|
var animation = _parent._isLmgAlarmAnimation ? AlarmAnimationLmg : AlarmAnimationSmg;
|
|
|
|
|
_noMagazineLabel.PlayAnimation(animation, "alarm");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-24 13:13:26 +02:00
|
|
|
}
|