LoadoutContainer.xaml.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using Content.Shared.Clothing;
  2. using Content.Shared.Preferences.Loadouts;
  3. using Robust.Client.AutoGenerated;
  4. using Robust.Client.UserInterface.Controls;
  5. using Robust.Client.UserInterface.CustomControls;
  6. using Robust.Client.UserInterface.XAML;
  7. using Robust.Shared.Map;
  8. using Robust.Shared.Prototypes;
  9. using Robust.Shared.Utility;
  10. namespace Content.Client.Lobby.UI.Loadouts;
  11. [GenerateTypedNameReferences]
  12. public sealed partial class LoadoutContainer : BoxContainer
  13. {
  14. [Dependency] private readonly IEntityManager _entManager = default!;
  15. [Dependency] private readonly IPrototypeManager _protoManager = default!;
  16. private readonly EntityUid? _entity;
  17. public Button Select => SelectButton;
  18. public LoadoutContainer(ProtoId<LoadoutPrototype> proto, bool disabled, FormattedMessage? reason)
  19. {
  20. RobustXamlLoader.Load(this);
  21. IoCManager.InjectDependencies(this);
  22. SelectButton.Disabled = disabled;
  23. if (disabled && reason != null)
  24. {
  25. var tooltip = new Tooltip();
  26. tooltip.SetMessage(reason);
  27. SelectButton.TooltipSupplier = _ => tooltip;
  28. }
  29. if (_protoManager.TryIndex(proto, out var loadProto))
  30. {
  31. var ent = loadProto.DummyEntity ?? _entManager.System<LoadoutSystem>().GetFirstOrNull(loadProto);
  32. if (ent == null)
  33. return;
  34. _entity = _entManager.SpawnEntity(ent, MapCoordinates.Nullspace);
  35. Sprite.SetEntity(_entity);
  36. var spriteTooltip = new Tooltip();
  37. spriteTooltip.SetMessage(FormattedMessage.FromUnformatted(_entManager.GetComponent<MetaDataComponent>(_entity.Value).EntityDescription));
  38. TooltipSupplier = _ => spriteTooltip;
  39. }
  40. }
  41. protected override void Dispose(bool disposing)
  42. {
  43. base.Dispose(disposing);
  44. if (!disposing)
  45. return;
  46. _entManager.DeleteEntity(_entity);
  47. }
  48. public bool Pressed
  49. {
  50. get => SelectButton.Pressed;
  51. set => SelectButton.Pressed = value;
  52. }
  53. public string? Text
  54. {
  55. get => SelectButton.Text;
  56. set => SelectButton.Text = value;
  57. }
  58. }