CharacterPickerButton.xaml.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using System.Linq;
  2. using Content.Client.Humanoid;
  3. using Content.Shared.Clothing;
  4. using Content.Shared.Humanoid;
  5. using Content.Shared.Humanoid.Prototypes;
  6. using Content.Shared.Preferences;
  7. using Content.Shared.Preferences.Loadouts;
  8. using Content.Shared.Roles;
  9. using Robust.Client.AutoGenerated;
  10. using Robust.Client.UserInterface.Controls;
  11. using Robust.Client.UserInterface.XAML;
  12. using Robust.Shared.Map;
  13. using Robust.Shared.Prototypes;
  14. namespace Content.Client.Lobby.UI;
  15. /// <summary>
  16. /// Holds character data on the side of the setup GUI.
  17. /// </summary>
  18. [GenerateTypedNameReferences]
  19. public sealed partial class CharacterPickerButton : ContainerButton
  20. {
  21. private IEntityManager _entManager;
  22. private EntityUid _previewDummy;
  23. /// <summary>
  24. /// Invoked if we should delete the attached character
  25. /// </summary>
  26. public event Action? OnDeletePressed;
  27. public CharacterPickerButton(
  28. IEntityManager entityManager,
  29. IPrototypeManager prototypeManager,
  30. ButtonGroup group,
  31. ICharacterProfile profile,
  32. bool isSelected)
  33. {
  34. RobustXamlLoader.Load(this);
  35. _entManager = entityManager;
  36. AddStyleClass(StyleClassButton);
  37. ToggleMode = true;
  38. Group = group;
  39. var description = profile.Name;
  40. if (profile is not HumanoidCharacterProfile humanoid)
  41. {
  42. _previewDummy = entityManager.SpawnEntity(prototypeManager.Index<SpeciesPrototype>(SharedHumanoidAppearanceSystem.DefaultSpecies).DollPrototype, MapCoordinates.Nullspace);
  43. }
  44. else
  45. {
  46. _previewDummy = UserInterfaceManager.GetUIController<LobbyUIController>()
  47. .LoadProfileEntity(humanoid, null, true);
  48. var highPriorityJob = humanoid.JobPriorities.SingleOrDefault(p => p.Value == JobPriority.High).Key;
  49. if (highPriorityJob != default)
  50. {
  51. var jobName = prototypeManager.Index(highPriorityJob).LocalizedName;
  52. description = $"{description}\n{jobName}";
  53. }
  54. }
  55. Pressed = isSelected;
  56. DeleteButton.Visible = !isSelected;
  57. View.SetEntity(_previewDummy);
  58. DescriptionLabel.Text = description;
  59. ConfirmDeleteButton.OnPressed += _ =>
  60. {
  61. Parent?.RemoveChild(this);
  62. Parent?.RemoveChild(ConfirmDeleteButton);
  63. OnDeletePressed?.Invoke();
  64. };
  65. DeleteButton.OnPressed += _ =>
  66. {
  67. DeleteButton.Visible = false;
  68. ConfirmDeleteButton.Visible = true;
  69. };
  70. }
  71. protected override void Dispose(bool disposing)
  72. {
  73. base.Dispose(disposing);
  74. if (!disposing)
  75. return;
  76. _entManager.DeleteEntity(_previewDummy);
  77. _previewDummy = default;
  78. }
  79. }