AmeWindow.xaml.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System.Linq;
  2. using Content.Client.UserInterface;
  3. using Content.Shared.Ame.Components;
  4. using Robust.Client.AutoGenerated;
  5. using Robust.Client.UserInterface.CustomControls;
  6. using Robust.Client.UserInterface.XAML;
  7. namespace Content.Client.Ame.UI
  8. {
  9. [GenerateTypedNameReferences]
  10. public sealed partial class AmeWindow : DefaultWindow
  11. {
  12. public event Action<UiButton>? OnAmeButton;
  13. public AmeWindow()
  14. {
  15. RobustXamlLoader.Load(this);
  16. IoCManager.InjectDependencies(this);
  17. EjectButton.OnPressed += _ => OnAmeButton?.Invoke(UiButton.Eject);
  18. ToggleInjection.OnPressed += _ => OnAmeButton?.Invoke(UiButton.ToggleInjection);
  19. IncreaseFuelButton.OnPressed += _ => OnAmeButton?.Invoke(UiButton.IncreaseFuel);
  20. DecreaseFuelButton.OnPressed += _ => OnAmeButton?.Invoke(UiButton.DecreaseFuel);
  21. }
  22. /// <summary>
  23. /// Update the UI state when new state data is received from the server.
  24. /// </summary>
  25. /// <param name="state">State data sent by the server.</param>
  26. public void UpdateState(BoundUserInterfaceState state)
  27. {
  28. var castState = (AmeControllerBoundUserInterfaceState) state;
  29. // Disable all buttons if not powered
  30. if (Contents.Children.Any())
  31. {
  32. ButtonHelpers.SetButtonDisabledRecursive(Contents, !castState.HasPower);
  33. EjectButton.Disabled = false;
  34. }
  35. if (!castState.HasFuelJar)
  36. {
  37. EjectButton.Disabled = true;
  38. ToggleInjection.Disabled = true;
  39. FuelAmount.Text = Loc.GetString("ame-window-fuel-not-inserted-text");
  40. }
  41. else
  42. {
  43. EjectButton.Disabled = false;
  44. ToggleInjection.Disabled = false;
  45. FuelAmount.Text = $"{castState.FuelAmount}";
  46. }
  47. if (!castState.IsMaster)
  48. {
  49. ToggleInjection.Disabled = true;
  50. }
  51. if (!castState.Injecting)
  52. {
  53. InjectionStatus.Text = Loc.GetString("ame-window-engine-injection-status-not-injecting-label") + " ";
  54. }
  55. else
  56. {
  57. InjectionStatus.Text = Loc.GetString("ame-window-engine-injection-status-injecting-label") + " ";
  58. }
  59. CoreCount.Text = $"{castState.CoreCount}";
  60. InjectionAmount.Text = $"{castState.InjectionAmount}";
  61. // format power statistics to pretty numbers
  62. CurrentPowerSupply.Text = $"{castState.CurrentPowerSupply:N1}";
  63. TargetedPowerSupply.Text = $"{castState.TargetedPowerSupply:N1}";
  64. }
  65. }
  66. }