|
1 |
| -using System; |
2 | 1 | using Content.Client.Items.Components;
|
3 | 2 | using Content.Client.Stylesheets;
|
4 |
| -using Content.Shared.Containers.ItemSlots; |
5 | 3 | using Content.Shared.Weapons.Ranged.Barrels.Components;
|
6 | 4 | using Robust.Client.Graphics;
|
7 | 5 | using Robust.Client.UserInterface;
|
8 | 6 | using Robust.Client.UserInterface.Controls;
|
9 |
| -using Robust.Shared.GameObjects; |
10 | 7 | using Robust.Shared.GameStates;
|
11 |
| -using Robust.Shared.Maths; |
12 |
| -using Robust.Shared.Serialization.Manager.Attributes; |
13 |
| -using Robust.Shared.ViewVariables; |
14 | 8 | using static Robust.Client.UserInterface.Controls.BoxContainer;
|
15 | 9 |
|
16 | 10 | namespace Content.Client.Weapons.Ranged.Barrels.Components
|
17 | 11 | {
|
18 | 12 | [RegisterComponent]
|
19 | 13 | [NetworkedComponent()]
|
20 |
| - public class ClientBatteryBarrelComponent : Component, IItemStatus |
| 14 | + public sealed class ClientBatteryBarrelComponent : Component, IItemStatus |
21 | 15 | {
|
22 |
| - private StatusControl? _statusControl; |
23 |
| - |
24 |
| - /// <summary> |
25 |
| - /// Count of bullets in the magazine. |
26 |
| - /// </summary> |
27 |
| - /// <remarks> |
28 |
| - /// Null if no magazine is inserted. |
29 |
| - /// </remarks> |
30 |
| - [ViewVariables] |
31 |
| - public (int count, int max)? MagazineCount { get; private set; } |
32 |
| - |
33 |
| - public override void HandleComponentState(ComponentState? curState, ComponentState? nextState) |
34 |
| - { |
35 |
| - base.HandleComponentState(curState, nextState); |
36 |
| - |
37 |
| - if (curState is not BatteryBarrelComponentState cast) |
38 |
| - return; |
39 |
| - |
40 |
| - MagazineCount = cast.Magazine; |
41 |
| - _statusControl?.Update(); |
42 |
| - } |
| 16 | + public StatusControl? ItemStatus; |
43 | 17 |
|
44 | 18 | public Control MakeControl()
|
45 | 19 | {
|
46 |
| - _statusControl = new StatusControl(this); |
47 |
| - _statusControl.Update(); |
48 |
| - return _statusControl; |
| 20 | + ItemStatus = new StatusControl(this); |
| 21 | + |
| 22 | + if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out AppearanceComponent appearance)) |
| 23 | + ItemStatus.Update(appearance); |
| 24 | + |
| 25 | + return ItemStatus; |
49 | 26 | }
|
50 | 27 |
|
51 | 28 | public void DestroyControl(Control control)
|
52 | 29 | {
|
53 |
| - if (_statusControl == control) |
| 30 | + if (ItemStatus == control) |
54 | 31 | {
|
55 |
| - _statusControl = null; |
| 32 | + ItemStatus = null; |
56 | 33 | }
|
57 | 34 | }
|
58 | 35 |
|
59 |
| - private sealed class StatusControl : Control |
| 36 | + public sealed class StatusControl : Control |
60 | 37 | {
|
61 | 38 | private readonly ClientBatteryBarrelComponent _parent;
|
62 | 39 | private readonly BoxContainer _bulletsList;
|
@@ -104,18 +81,19 @@ public StatusControl(ClientBatteryBarrelComponent parent)
|
104 | 81 | });
|
105 | 82 | }
|
106 | 83 |
|
107 |
| - public void Update() |
| 84 | + public void Update(AppearanceComponent appearance) |
108 | 85 | {
|
109 | 86 | _bulletsList.RemoveAllChildren();
|
110 | 87 |
|
111 |
| - if (_parent.MagazineCount == null) |
| 88 | + if (!appearance.TryGetData(MagazineBarrelVisuals.MagLoaded, out bool loaded) || !loaded) |
112 | 89 | {
|
113 | 90 | _noBatteryLabel.Visible = true;
|
114 | 91 | _ammoCount.Visible = false;
|
115 | 92 | return;
|
116 | 93 | }
|
117 | 94 |
|
118 |
| - var (count, capacity) = _parent.MagazineCount.Value; |
| 95 | + appearance.TryGetData(AmmoVisuals.AmmoCount, out int count); |
| 96 | + appearance.TryGetData(AmmoVisuals.AmmoMax, out int capacity); |
119 | 97 |
|
120 | 98 | _noBatteryLabel.Visible = false;
|
121 | 99 | _ammoCount.Visible = true;
|
|
0 commit comments