TargetingControl.xaml.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // SPDX-FileCopyrightText: 2024 Piras314 <p1r4s@proton.me>
  2. // SPDX-FileCopyrightText: 2024 gluesniffler <159397573+gluesniffler@users.noreply.github.com>
  3. // SPDX-FileCopyrightText: 2025 Aiden <28298836+Aidenkrz@users.noreply.github.com>
  4. //
  5. // SPDX-License-Identifier: AGPL-3.0-or-later
  6. using System.Linq;
  7. using Content.Shared._Shitmed.Targeting;
  8. using Robust.Client.AutoGenerated;
  9. using Robust.Client.UserInterface.Controls;
  10. using Robust.Client.UserInterface.XAML;
  11. namespace Content.Client._Shitmed.UserInterface.Systems.Targeting.Widgets;
  12. [GenerateTypedNameReferences]
  13. public sealed partial class TargetingControl : UIWidget
  14. {
  15. private readonly TargetingUIController _controller;
  16. private readonly Dictionary<TargetBodyPart, TextureButton> _bodyPartControls;
  17. public TargetingControl()
  18. {
  19. RobustXamlLoader.Load(this);
  20. _controller = UserInterfaceManager.GetUIController<TargetingUIController>();
  21. _bodyPartControls = new Dictionary<TargetBodyPart, TextureButton>
  22. {
  23. // TODO: ADD EYE AND MOUTH TARGETING
  24. { TargetBodyPart.Head, HeadButton },
  25. { TargetBodyPart.Torso, ChestButton },
  26. { TargetBodyPart.Groin, GroinButton },
  27. { TargetBodyPart.LeftArm, LeftArmButton },
  28. { TargetBodyPart.LeftHand, LeftHandButton },
  29. { TargetBodyPart.RightArm, RightArmButton },
  30. { TargetBodyPart.RightHand, RightHandButton },
  31. { TargetBodyPart.LeftLeg, LeftLegButton },
  32. { TargetBodyPart.LeftFoot, LeftFootButton },
  33. { TargetBodyPart.RightLeg, RightLegButton },
  34. { TargetBodyPart.RightFoot, RightFootButton },
  35. };
  36. foreach (var bodyPartButton in _bodyPartControls)
  37. {
  38. bodyPartButton.Value.MouseFilter = MouseFilterMode.Stop;
  39. bodyPartButton.Value.OnPressed += _ => SetActiveBodyPart(bodyPartButton.Key);
  40. TargetDoll.Texture = Theme.ResolveTexture("target_doll");
  41. }
  42. }
  43. private void SetActiveBodyPart(TargetBodyPart bodyPart) => _controller.CycleTarget(bodyPart);
  44. public void SetBodyPartsVisible(TargetBodyPart bodyPart)
  45. {
  46. foreach (var bodyPartButton in _bodyPartControls)
  47. bodyPartButton.Value.Children.First().Visible = bodyPartButton.Key == bodyPart;
  48. }
  49. protected override void OnThemeUpdated() => TargetDoll.Texture = Theme.ResolveTexture("target_doll");
  50. public void SetTargetDollVisible(bool visible) => Visible = visible;
  51. }