SalvageExpeditionConsoleBoundUserInterface.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. using System.Linq;
  2. using Content.Client.Stylesheets;
  3. using Content.Shared.CCVar;
  4. using Content.Shared.Procedural;
  5. using Content.Shared.Salvage.Expeditions;
  6. using Content.Shared.Salvage.Expeditions.Modifiers;
  7. using JetBrains.Annotations;
  8. using Robust.Client.UserInterface;
  9. using Robust.Client.UserInterface.Controls;
  10. using Robust.Shared.Configuration;
  11. using Robust.Shared.Prototypes;
  12. namespace Content.Client.Salvage.UI;
  13. [UsedImplicitly]
  14. public sealed class SalvageExpeditionConsoleBoundUserInterface : BoundUserInterface
  15. {
  16. [ViewVariables]
  17. private OfferingWindow? _window;
  18. [Dependency] private readonly IConfigurationManager _cfgManager = default!;
  19. [Dependency] private readonly IEntityManager _entManager = default!;
  20. [Dependency] private readonly IPrototypeManager _protoManager = default!;
  21. public SalvageExpeditionConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
  22. {
  23. IoCManager.InjectDependencies(this);
  24. }
  25. protected override void Open()
  26. {
  27. base.Open();
  28. _window = this.CreateWindowCenteredLeft<OfferingWindow>();
  29. _window.Title = Loc.GetString("salvage-expedition-window-title");
  30. }
  31. protected override void UpdateState(BoundUserInterfaceState state)
  32. {
  33. base.UpdateState(state);
  34. if (state is not SalvageExpeditionConsoleState current || _window == null)
  35. return;
  36. _window.Progression = null;
  37. _window.Cooldown = TimeSpan.FromSeconds(_cfgManager.GetCVar(CCVars.SalvageExpeditionCooldown));
  38. _window.NextOffer = current.NextOffer;
  39. _window.Claimed = current.Claimed;
  40. _window.ClearOptions();
  41. var salvage = _entManager.System<SalvageSystem>();
  42. for (var i = 0; i < current.Missions.Count; i++)
  43. {
  44. var missionParams = current.Missions[i];
  45. var offering = new OfferingWindowOption();
  46. offering.Title = Loc.GetString($"salvage-expedition-type");
  47. var difficultyId = "Moderate";
  48. var difficultyProto = _protoManager.Index<SalvageDifficultyPrototype>(difficultyId);
  49. // TODO: Selectable difficulty soon.
  50. var mission = salvage.GetMission(difficultyProto, missionParams.Seed);
  51. // Difficulty
  52. // Details
  53. offering.AddContent(new Label()
  54. {
  55. Text = Loc.GetString("salvage-expedition-window-difficulty")
  56. });
  57. var difficultyColor = difficultyProto.Color;
  58. offering.AddContent(new Label
  59. {
  60. Text = Loc.GetString("salvage-expedition-difficulty-Moderate"),
  61. FontColorOverride = difficultyColor,
  62. HorizontalAlignment = Control.HAlignment.Left,
  63. Margin = new Thickness(0f, 0f, 0f, 5f),
  64. });
  65. offering.AddContent(new Label
  66. {
  67. Text = Loc.GetString("salvage-expedition-difficulty-players"),
  68. HorizontalAlignment = Control.HAlignment.Left,
  69. });
  70. offering.AddContent(new Label
  71. {
  72. Text = difficultyProto.RecommendedPlayers.ToString(),
  73. FontColorOverride = StyleNano.NanoGold,
  74. HorizontalAlignment = Control.HAlignment.Left,
  75. Margin = new Thickness(0f, 0f, 0f, 5f),
  76. });
  77. // Details
  78. offering.AddContent(new Label
  79. {
  80. Text = Loc.GetString("salvage-expedition-window-hostiles")
  81. });
  82. var faction = mission.Faction;
  83. offering.AddContent(new Label
  84. {
  85. Text = string.IsNullOrWhiteSpace(Loc.GetString(_protoManager.Index<SalvageFactionPrototype>(faction).Description))
  86. ? LogAndReturnDefaultFactionDescription(faction)
  87. : Loc.GetString(_protoManager.Index<SalvageFactionPrototype>(faction).Description),
  88. FontColorOverride = StyleNano.NanoGold,
  89. HorizontalAlignment = Control.HAlignment.Left,
  90. Margin = new Thickness(0f, 0f, 0f, 5f),
  91. });
  92. string LogAndReturnDefaultFactionDescription(string faction)
  93. {
  94. Logger.Error($"Description is null or white space for SalvageFactionPrototype: {faction}");
  95. return Loc.GetString(_protoManager.Index<SalvageFactionPrototype>(faction).ID);
  96. }
  97. // Duration
  98. offering.AddContent(new Label
  99. {
  100. Text = Loc.GetString("salvage-expedition-window-duration")
  101. });
  102. offering.AddContent(new Label
  103. {
  104. Text = mission.Duration.ToString(),
  105. FontColorOverride = StyleNano.NanoGold,
  106. HorizontalAlignment = Control.HAlignment.Left,
  107. Margin = new Thickness(0f, 0f, 0f, 5f),
  108. });
  109. // Biome
  110. offering.AddContent(new Label
  111. {
  112. Text = Loc.GetString("salvage-expedition-window-biome")
  113. });
  114. var biome = mission.Biome;
  115. offering.AddContent(new Label
  116. {
  117. Text = string.IsNullOrWhiteSpace(Loc.GetString(_protoManager.Index<SalvageBiomeModPrototype>(biome).Description))
  118. ? LogAndReturnDefaultBiomDescription(biome)
  119. : Loc.GetString(_protoManager.Index<SalvageBiomeModPrototype>(biome).Description),
  120. FontColorOverride = StyleNano.NanoGold,
  121. HorizontalAlignment = Control.HAlignment.Left,
  122. Margin = new Thickness(0f, 0f, 0f, 5f),
  123. });
  124. string LogAndReturnDefaultBiomDescription(string biome)
  125. {
  126. Logger.Error($"Description is null or white space for SalvageBiomeModPrototype: {biome}");
  127. return Loc.GetString(_protoManager.Index<SalvageBiomeModPrototype>(biome).ID);
  128. }
  129. // Modifiers
  130. offering.AddContent(new Label
  131. {
  132. Text = Loc.GetString("salvage-expedition-window-modifiers")
  133. });
  134. var mods = mission.Modifiers;
  135. offering.AddContent(new Label
  136. {
  137. Text = string.Join("\n", mods.Select(o => "- " + o)).TrimEnd(),
  138. FontColorOverride = StyleNano.NanoGold,
  139. HorizontalAlignment = Control.HAlignment.Left,
  140. Margin = new Thickness(0f, 0f, 0f, 5f),
  141. });
  142. offering.ClaimPressed += args =>
  143. {
  144. SendMessage(new ClaimSalvageMessage()
  145. {
  146. Index = missionParams.Index,
  147. });
  148. };
  149. offering.Claimed = current.ActiveMission == missionParams.Index;
  150. offering.Disabled = current.Claimed || current.Cooldown;
  151. _window.AddOption(offering);
  152. }
  153. }
  154. }