PowerChargeWindow.xaml.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using Content.Client.UserInterface.Controls;
  2. using Content.Shared.Power;
  3. using Robust.Client.AutoGenerated;
  4. using Robust.Client.UserInterface.Controls;
  5. using Robust.Client.UserInterface.XAML;
  6. namespace Content.Client.Power.PowerCharge;
  7. [GenerateTypedNameReferences]
  8. public sealed partial class PowerChargeWindow : FancyWindow
  9. {
  10. private readonly ButtonGroup _buttonGroup = new();
  11. public PowerChargeWindow()
  12. {
  13. RobustXamlLoader.Load(this);
  14. OnButton.Group = _buttonGroup;
  15. OffButton.Group = _buttonGroup;
  16. }
  17. public void UpdateWindow(PowerChargeBoundUserInterface bui, string title)
  18. {
  19. Title = title;
  20. OnButton.OnPressed += _ => bui.SetPowerSwitch(true);
  21. OffButton.OnPressed += _ => bui.SetPowerSwitch(false);
  22. EntityView.SetEntity(bui.Owner);
  23. }
  24. public void UpdateState(PowerChargeState state)
  25. {
  26. if (state.On)
  27. OnButton.Pressed = true;
  28. else
  29. OffButton.Pressed = true;
  30. PowerLabel.Text = Loc.GetString(
  31. "power-charge-window-power-label",
  32. ("draw", state.PowerDraw),
  33. ("max", state.PowerDrawMax));
  34. PowerLabel.SetOnlyStyleClass(MathHelper.CloseTo(state.PowerDraw, state.PowerDrawMax) ? "Good" : "Caution");
  35. ChargeBar.Value = state.Charge;
  36. ChargeText.Text = (state.Charge / 255f).ToString("P0");
  37. StatusLabel.Text = Loc.GetString(state.PowerStatus switch
  38. {
  39. PowerChargePowerStatus.Off => "power-charge-window-status-off",
  40. PowerChargePowerStatus.Discharging => "power-charge-window-status-discharging",
  41. PowerChargePowerStatus.Charging => "power-charge-window-status-charging",
  42. PowerChargePowerStatus.FullyCharged => "power-charge-window-status-fully-charged",
  43. _ => throw new ArgumentOutOfRangeException()
  44. });
  45. StatusLabel.SetOnlyStyleClass(state.PowerStatus switch
  46. {
  47. PowerChargePowerStatus.Off => "Danger",
  48. PowerChargePowerStatus.Discharging => "Caution",
  49. PowerChargePowerStatus.Charging => "Caution",
  50. PowerChargePowerStatus.FullyCharged => "Good",
  51. _ => throw new ArgumentOutOfRangeException()
  52. });
  53. EtaLabel.Text = state.EtaSeconds >= 0
  54. ? Loc.GetString("power-charge-window-eta-value", ("left", TimeSpan.FromSeconds(state.EtaSeconds)))
  55. : Loc.GetString("power-charge-window-eta-none");
  56. EtaLabel.SetOnlyStyleClass(state.EtaSeconds >= 0 ? "Caution" : "Disabled");
  57. }
  58. }