2021-07-12 01:32:10 -07:00
|
|
|
using System;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Client.Items.Components;
|
|
|
|
|
using Content.Client.Stylesheets;
|
2021-12-05 16:23:47 +13:00
|
|
|
using Content.Shared.Containers.ItemSlots;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Weapons.Ranged.Barrels.Components;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Client.Graphics;
|
2020-08-27 16:31:29 +02:00
|
|
|
using Robust.Client.UserInterface;
|
|
|
|
|
using Robust.Client.UserInterface.Controls;
|
|
|
|
|
using Robust.Shared.GameObjects;
|
2021-07-12 01:32:10 -07:00
|
|
|
using Robust.Shared.GameStates;
|
2020-08-27 16:31:29 +02:00
|
|
|
using Robust.Shared.Maths;
|
2021-12-05 16:23:47 +13:00
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2020-08-27 16:31:29 +02:00
|
|
|
using Robust.Shared.ViewVariables;
|
2021-07-18 18:39:31 +02:00
|
|
|
using static Robust.Client.UserInterface.Controls.BoxContainer;
|
2020-08-27 16:31:29 +02:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Client.Weapons.Ranged.Barrels.Components
|
2020-08-27 16:31:29 +02:00
|
|
|
{
|
|
|
|
|
[RegisterComponent]
|
2021-07-12 01:32:10 -07:00
|
|
|
[NetworkedComponent()]
|
2020-08-27 16:31:29 +02:00
|
|
|
public class ClientBatteryBarrelComponent : Component, IItemStatus
|
|
|
|
|
{
|
|
|
|
|
public override string Name => "BatteryBarrel";
|
|
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
private StatusControl? _statusControl;
|
2020-08-27 16:31:29 +02:00
|
|
|
|
2021-12-05 16:23:47 +13:00
|
|
|
[DataField("cellSlot", required: true)]
|
|
|
|
|
public ItemSlot CellSlot = default!;
|
|
|
|
|
|
2020-08-27 16:31:29 +02:00
|
|
|
/// <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-12-05 16:23:47 +13:00
|
|
|
protected override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
2021-12-07 17:48:49 +01:00
|
|
|
EntitySystem.Get<ItemSlotsSystem>().AddItemSlot(Owner, $"{Name}-powercell-container", CellSlot);
|
2021-12-05 16:23:47 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnRemove()
|
|
|
|
|
{
|
|
|
|
|
base.OnRemove();
|
2021-12-07 17:48:49 +01:00
|
|
|
EntitySystem.Get<ItemSlotsSystem>().RemoveItemSlot(Owner, CellSlot);
|
2021-12-05 16:23:47 +13:00
|
|
|
}
|
|
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
2020-08-27 16:31:29 +02:00
|
|
|
{
|
2020-11-26 14:33:31 +01:00
|
|
|
base.HandleComponentState(curState, nextState);
|
|
|
|
|
|
|
|
|
|
if (curState is not BatteryBarrelComponentState cast)
|
2020-08-27 16:31:29 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
MagazineCount = cast.Magazine;
|
|
|
|
|
_statusControl?.Update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
private readonly ClientBatteryBarrelComponent _parent;
|
2021-07-18 18:39:31 +02:00
|
|
|
private readonly BoxContainer _bulletsList;
|
2020-08-27 16:31:29 +02:00
|
|
|
private readonly Label _noBatteryLabel;
|
|
|
|
|
private readonly Label _ammoCount;
|
|
|
|
|
|
|
|
|
|
public StatusControl(ClientBatteryBarrelComponent parent)
|
|
|
|
|
{
|
2021-02-21 12:38:56 +01:00
|
|
|
MinHeight = 15;
|
2020-08-27 16:31:29 +02:00
|
|
|
_parent = parent;
|
2021-02-21 12:38:56 +01:00
|
|
|
HorizontalExpand = true;
|
|
|
|
|
VerticalAlignment = VAlignment.Center;
|
2020-08-27 16:31:29 +02:00
|
|
|
|
2021-07-18 18:39:31 +02:00
|
|
|
AddChild(new BoxContainer
|
2020-08-27 16:31:29 +02:00
|
|
|
{
|
2021-07-18 18:39:31 +02:00
|
|
|
Orientation = LayoutOrientation.Horizontal,
|
2021-02-21 12:38:56 +01:00
|
|
|
HorizontalExpand = true,
|
2020-08-27 16:31:29 +02:00
|
|
|
Children =
|
|
|
|
|
{
|
|
|
|
|
new Control
|
|
|
|
|
{
|
2021-02-21 12:38:56 +01:00
|
|
|
HorizontalExpand = true,
|
2020-08-27 16:31:29 +02:00
|
|
|
Children =
|
|
|
|
|
{
|
2021-07-18 18:39:31 +02:00
|
|
|
(_bulletsList = new BoxContainer
|
2020-08-27 16:31:29 +02: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-27 16:31:29 +02:00
|
|
|
SeparationOverride = 4
|
|
|
|
|
}),
|
|
|
|
|
(_noBatteryLabel = new Label
|
|
|
|
|
{
|
|
|
|
|
Text = "No Battery!",
|
|
|
|
|
StyleClasses = {StyleNano.StyleClassItemStatus}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
2021-02-21 12:38:56 +01:00
|
|
|
new Control() { MinSize = (5,0) },
|
2020-08-27 16:31:29 +02:00
|
|
|
(_ammoCount = new Label
|
|
|
|
|
{
|
|
|
|
|
StyleClasses = {StyleNano.StyleClassItemStatus},
|
2021-02-21 12:38:56 +01:00
|
|
|
HorizontalAlignment = HAlignment.Right,
|
2020-08-27 16:31:29 +02:00
|
|
|
}),
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update()
|
|
|
|
|
{
|
|
|
|
|
_bulletsList.RemoveAllChildren();
|
|
|
|
|
|
|
|
|
|
if (_parent.MagazineCount == null)
|
|
|
|
|
{
|
|
|
|
|
_noBatteryLabel.Visible = true;
|
|
|
|
|
_ammoCount.Visible = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var (count, capacity) = _parent.MagazineCount.Value;
|
|
|
|
|
|
|
|
|
|
_noBatteryLabel.Visible = false;
|
|
|
|
|
_ammoCount.Visible = true;
|
|
|
|
|
|
|
|
|
|
_ammoCount.Text = $"x{count:00}";
|
|
|
|
|
capacity = Math.Min(capacity, 8);
|
|
|
|
|
FillBulletRow(_bulletsList, count, capacity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void FillBulletRow(Control container, int count, int capacity)
|
|
|
|
|
{
|
|
|
|
|
var colorGone = Color.FromHex("#000000");
|
|
|
|
|
var color = Color.FromHex("#E00000");
|
|
|
|
|
|
|
|
|
|
// Draw the empty ones
|
|
|
|
|
for (var i = count; i < capacity; i++)
|
|
|
|
|
{
|
|
|
|
|
container.AddChild(new PanelContainer
|
|
|
|
|
{
|
|
|
|
|
PanelOverride = new StyleBoxFlat()
|
|
|
|
|
{
|
|
|
|
|
BackgroundColor = colorGone,
|
|
|
|
|
},
|
2021-02-21 12:38:56 +01:00
|
|
|
MinSize = (10, 15),
|
2020-08-27 16:31:29 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Draw the full ones, but limit the count to the capacity
|
|
|
|
|
count = Math.Min(count, capacity);
|
|
|
|
|
for (var i = 0; i < count; i++)
|
|
|
|
|
{
|
|
|
|
|
container.AddChild(new PanelContainer
|
|
|
|
|
{
|
|
|
|
|
PanelOverride = new StyleBoxFlat()
|
|
|
|
|
{
|
|
|
|
|
BackgroundColor = color,
|
|
|
|
|
},
|
2021-02-21 12:38:56 +01:00
|
|
|
MinSize = (10, 15),
|
2020-08-27 16:31:29 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|