BountyEntry.xaml.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using Content.Client.Message;
  2. using Content.Shared.Cargo;
  3. using Content.Shared.Cargo.Prototypes;
  4. using Content.Shared.Random;
  5. using Robust.Client.AutoGenerated;
  6. using Robust.Client.UserInterface.Controls;
  7. using Robust.Client.UserInterface.XAML;
  8. using Robust.Shared.Prototypes;
  9. using Robust.Shared.Timing;
  10. using Serilog;
  11. namespace Content.Client.Cargo.UI;
  12. [GenerateTypedNameReferences]
  13. public sealed partial class BountyEntry : BoxContainer
  14. {
  15. [Dependency] private readonly IPrototypeManager _prototype = default!;
  16. public Action? OnLabelButtonPressed;
  17. public Action? OnSkipButtonPressed;
  18. public TimeSpan EndTime;
  19. public TimeSpan UntilNextSkip;
  20. public BountyEntry(CargoBountyData bounty, TimeSpan untilNextSkip)
  21. {
  22. RobustXamlLoader.Load(this);
  23. IoCManager.InjectDependencies(this);
  24. UntilNextSkip = untilNextSkip;
  25. if (!_prototype.TryIndex<CargoBountyPrototype>(bounty.Bounty, out var bountyPrototype))
  26. return;
  27. var items = new List<string>();
  28. foreach (var entry in bountyPrototype.Entries)
  29. {
  30. items.Add(Loc.GetString("bounty-console-manifest-entry",
  31. ("amount", entry.Amount),
  32. ("item", Loc.GetString(entry.Name))));
  33. }
  34. ManifestLabel.SetMarkup(Loc.GetString("bounty-console-manifest-label", ("item", string.Join(", ", items))));
  35. RewardLabel.SetMarkup(Loc.GetString("bounty-console-reward-label", ("reward", bountyPrototype.Reward)));
  36. DescriptionLabel.SetMarkup(Loc.GetString("bounty-console-description-label", ("description", Loc.GetString(bountyPrototype.Description))));
  37. IdLabel.SetMarkup(Loc.GetString("bounty-console-id-label", ("id", bounty.Id)));
  38. PrintButton.OnPressed += _ => OnLabelButtonPressed?.Invoke();
  39. SkipButton.OnPressed += _ => OnSkipButtonPressed?.Invoke();
  40. }
  41. private void UpdateSkipButton(float deltaSeconds)
  42. {
  43. UntilNextSkip -= TimeSpan.FromSeconds(deltaSeconds);
  44. if (UntilNextSkip > TimeSpan.Zero)
  45. {
  46. SkipButton.Label.Text = UntilNextSkip.ToString("mm\\:ss");
  47. SkipButton.Disabled = true;
  48. return;
  49. }
  50. SkipButton.Label.Text = Loc.GetString("bounty-console-skip-button-text");
  51. SkipButton.Disabled = false;
  52. }
  53. protected override void FrameUpdate(FrameEventArgs args)
  54. {
  55. base.FrameUpdate(args);
  56. UpdateSkipButton(args.DeltaSeconds);
  57. }
  58. }