AbsorbentItemStatus.xaml.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System.Linq;
  2. using Content.Client.UserInterface.Controls;
  3. using Content.Shared.Fluids;
  4. using Robust.Client.AutoGenerated;
  5. using Robust.Client.UserInterface;
  6. using Robust.Client.UserInterface.XAML;
  7. using Robust.Shared.Timing;
  8. using Robust.Shared.Utility;
  9. namespace Content.Client.Fluids.UI
  10. {
  11. [GenerateTypedNameReferences]
  12. public sealed partial class AbsorbentItemStatus : SplitBar
  13. {
  14. private readonly IEntityManager _entManager;
  15. private readonly EntityUid _uid;
  16. private Dictionary<Color, float> _progress = new();
  17. public AbsorbentItemStatus(EntityUid uid, IEntityManager entManager)
  18. {
  19. RobustXamlLoader.Load(this);
  20. _uid = uid;
  21. _entManager = entManager;
  22. }
  23. protected override void FrameUpdate(FrameEventArgs args)
  24. {
  25. base.FrameUpdate(args);
  26. if (!_entManager.TryGetComponent<AbsorbentComponent>(_uid, out var absorbent))
  27. return;
  28. var oldProgress = _progress.ShallowClone();
  29. _progress.Clear();
  30. foreach (var item in absorbent.Progress)
  31. {
  32. _progress[item.Key] = item.Value;
  33. }
  34. if (oldProgress.OrderBy(x => x.Key.ToArgb()).SequenceEqual(_progress))
  35. return;
  36. Bar.Clear();
  37. foreach (var (key, value) in absorbent.Progress)
  38. {
  39. Bar.AddEntry(value, key);
  40. }
  41. }
  42. }
  43. }