1
0

MagicMirrorBoundUserInterface.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using Content.Shared.Humanoid.Markings;
  2. using Content.Shared.MagicMirror;
  3. using Robust.Client.GameObjects;
  4. using Robust.Client.UserInterface;
  5. namespace Content.Client.MagicMirror;
  6. public sealed class MagicMirrorBoundUserInterface : BoundUserInterface
  7. {
  8. [ViewVariables]
  9. private MagicMirrorWindow? _window;
  10. public MagicMirrorBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
  11. {
  12. }
  13. protected override void Open()
  14. {
  15. base.Open();
  16. _window = this.CreateWindow<MagicMirrorWindow>();
  17. _window.OnHairSelected += tuple => SelectHair(MagicMirrorCategory.Hair, tuple.id, tuple.slot);
  18. _window.OnHairColorChanged += args => ChangeColor(MagicMirrorCategory.Hair, args.marking, args.slot);
  19. _window.OnHairSlotAdded += delegate () { AddSlot(MagicMirrorCategory.Hair); };
  20. _window.OnHairSlotRemoved += args => RemoveSlot(MagicMirrorCategory.Hair, args);
  21. _window.OnFacialHairSelected += tuple => SelectHair(MagicMirrorCategory.FacialHair, tuple.id, tuple.slot);
  22. _window.OnFacialHairColorChanged +=
  23. args => ChangeColor(MagicMirrorCategory.FacialHair, args.marking, args.slot);
  24. _window.OnFacialHairSlotAdded += delegate () { AddSlot(MagicMirrorCategory.FacialHair); };
  25. _window.OnFacialHairSlotRemoved += args => RemoveSlot(MagicMirrorCategory.FacialHair, args);
  26. }
  27. private void SelectHair(MagicMirrorCategory category, string marking, int slot)
  28. {
  29. SendMessage(new MagicMirrorSelectMessage(category, marking, slot));
  30. }
  31. private void ChangeColor(MagicMirrorCategory category, Marking marking, int slot)
  32. {
  33. SendMessage(new MagicMirrorChangeColorMessage(category, new(marking.MarkingColors), slot));
  34. }
  35. private void RemoveSlot(MagicMirrorCategory category, int slot)
  36. {
  37. SendMessage(new MagicMirrorRemoveSlotMessage(category, slot));
  38. }
  39. private void AddSlot(MagicMirrorCategory category)
  40. {
  41. SendMessage(new MagicMirrorAddSlotMessage(category));
  42. }
  43. protected override void UpdateState(BoundUserInterfaceState state)
  44. {
  45. base.UpdateState(state);
  46. if (state is not MagicMirrorUiState data || _window == null)
  47. {
  48. return;
  49. }
  50. _window.UpdateState(data);
  51. }
  52. }