1
0

SwappableInstrumentSystem.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using Content.Shared.Instruments;
  2. using Content.Shared.Popups;
  3. using Content.Shared.Verbs;
  4. using Robust.Shared.Player;
  5. namespace Content.Server.Instruments;
  6. public sealed class SwappableInstrumentSystem : EntitySystem
  7. {
  8. [Dependency] private readonly SharedInstrumentSystem _sharedInstrument = default!;
  9. [Dependency] private readonly SharedPopupSystem _popup = default!;
  10. public override void Initialize()
  11. {
  12. base.Initialize();
  13. SubscribeLocalEvent<SwappableInstrumentComponent, GetVerbsEvent<AlternativeVerb>>(AddStyleVerb);
  14. }
  15. private void AddStyleVerb(EntityUid uid, SwappableInstrumentComponent component, GetVerbsEvent<AlternativeVerb> args)
  16. {
  17. if (!args.CanInteract || !args.CanAccess || component.InstrumentList.Count <= 1)
  18. return;
  19. if (!TryComp<InstrumentComponent>(uid, out var instrument))
  20. return;
  21. var priority = 0;
  22. foreach (var entry in component.InstrumentList)
  23. {
  24. AlternativeVerb selection = new()
  25. {
  26. Text = entry.Key,
  27. Category = VerbCategory.InstrumentStyle,
  28. Priority = priority,
  29. Act = () =>
  30. {
  31. _sharedInstrument.SetInstrumentProgram(uid, instrument, entry.Value.Item1, entry.Value.Item2);
  32. _popup.PopupEntity(Loc.GetString("swappable-instrument-component-style-set", ("style", entry.Key)),
  33. args.User, args.User);
  34. }
  35. };
  36. priority--;
  37. args.Verbs.Add(selection);
  38. }
  39. }
  40. }