|
| 1 | +using Content.Client.UserInterface.Controls; |
| 2 | +using Content.Shared._Emberfall.Planetside; |
| 3 | +using Content.Shared._Emberfall.Planetside.Components; |
| 4 | +using Content.Shared.Shuttles.Systems; |
| 5 | +using Content.Shared.Timing; |
| 6 | +using Robust.Client.AutoGenerated; |
| 7 | +using Robust.Client.Graphics; |
| 8 | +using Robust.Client.UserInterface.XAML; |
| 9 | +using Robust.Shared.Timing; |
| 10 | + |
| 11 | +namespace Content.Client._Emberfall.Planetside.UI; |
| 12 | + |
| 13 | +[GenerateTypedNameReferences] |
| 14 | +public sealed partial class SpaceElevatorConsoleWindow : FancyWindow |
| 15 | +{ |
| 16 | + [Dependency] private readonly IEntityManager _entMan = default!; |
| 17 | + [Dependency] private readonly IGameTiming _timing = default!; |
| 18 | + |
| 19 | + public event Action<int>? OnFTL; |
| 20 | + |
| 21 | + private readonly Dictionary<FTLState, (string Color, string Loc)> _stateData = new() |
| 22 | + { |
| 23 | + { FTLState.Available, ("#80C71F", "shuttle-console-ftl-state-Available") }, |
| 24 | + { FTLState.Starting, ("#169C9C", "shuttle-console-ftl-state-Starting") }, |
| 25 | + { FTLState.Travelling, ("#8932B8", "shuttle-console-ftl-state-Travelling") }, |
| 26 | + { FTLState.Arriving, ("#F9801D", "shuttle-console-ftl-state-Arriving") }, |
| 27 | + }; |
| 28 | + |
| 29 | + private readonly StyleBoxFlat _ftlStyle; |
| 30 | + private FTLState _state; |
| 31 | + private int? _selected; |
| 32 | + private StartEndTime _ftlTime; |
| 33 | + |
| 34 | + public SpaceElevatorConsoleWindow(EntityUid owner) |
| 35 | + { |
| 36 | + RobustXamlLoader.Load(this); |
| 37 | + IoCManager.InjectDependencies(this); |
| 38 | + |
| 39 | + _ftlStyle = new StyleBoxFlat() |
| 40 | + { |
| 41 | + BackgroundColor = Color.FromHex("#80C71F"), |
| 42 | + ContentMarginLeftOverride = 4, |
| 43 | + ContentMarginRightOverride = 4 |
| 44 | + }; |
| 45 | + FTLBar.ForegroundStyleBoxOverride = _ftlStyle; |
| 46 | + |
| 47 | + if (!_entMan.TryGetComponent<SpaceElevatorConsoleComponent>(owner, out var comp)) |
| 48 | + return; |
| 49 | + |
| 50 | + if (!comp.HasPlatform) |
| 51 | + { |
| 52 | + MapFTLState.Text = Loc.GetString("docking-console-no-shuttle"); |
| 53 | + _ftlStyle.BackgroundColor = Color.FromHex("#B02E26"); |
| 54 | + } |
| 55 | + |
| 56 | + SetupEventHandlers(); |
| 57 | + } |
| 58 | + |
| 59 | + private void SetupEventHandlers() |
| 60 | + { |
| 61 | + Destinations.OnItemSelected += args => |
| 62 | + { |
| 63 | + _selected = args.ItemIndex; |
| 64 | + UpdateButton(); |
| 65 | + }; |
| 66 | + |
| 67 | + Destinations.OnItemDeselected += _ => |
| 68 | + { |
| 69 | + _selected = null; |
| 70 | + UpdateButton(); |
| 71 | + }; |
| 72 | + |
| 73 | + FTLButton.OnPressed += _ => |
| 74 | + { |
| 75 | + if (_selected is { } index) |
| 76 | + { |
| 77 | + OnFTL?.Invoke(index); |
| 78 | + FTLButton.Disabled = true; |
| 79 | + } |
| 80 | + }; |
| 81 | + } |
| 82 | + |
| 83 | + public void UpdateState(SpaceElevatorConsoleState state) |
| 84 | + { |
| 85 | + _state = state.FTLState; |
| 86 | + _ftlTime = state.FTLTime; |
| 87 | + |
| 88 | + var (color, locString) = _stateData.GetValueOrDefault(_state, |
| 89 | + ("#B02E26", "shuttle-console-ftl-state-Cooldown")); |
| 90 | + |
| 91 | + MapFTLState.Text = Loc.GetString(locString); |
| 92 | + _ftlStyle.BackgroundColor = Color.FromHex(color); |
| 93 | + |
| 94 | + if (Destinations.Count != state.Destinations.Count) |
| 95 | + { |
| 96 | + UpdateDestinations(state.Destinations); |
| 97 | + } |
| 98 | + |
| 99 | + UpdateButton(); |
| 100 | + } |
| 101 | + |
| 102 | + private void UpdateDestinations(List<ElevatorDestination> destinations) |
| 103 | + { |
| 104 | + Destinations.Clear(); |
| 105 | + foreach (var dest in destinations) |
| 106 | + { |
| 107 | + Destinations.AddItem(dest.Name); |
| 108 | + } |
| 109 | + } |
| 110 | + |
| 111 | + protected override void FrameUpdate(FrameEventArgs args) |
| 112 | + { |
| 113 | + base.FrameUpdate(args); |
| 114 | + |
| 115 | + var progress = _ftlTime.ProgressAt(_timing.CurTime); |
| 116 | + FTLBar.Value = float.IsFinite(progress) ? progress : 1; |
| 117 | + |
| 118 | + UpdateButton(); |
| 119 | + } |
| 120 | + |
| 121 | + private void UpdateButton() |
| 122 | + { |
| 123 | + FTLButton.Disabled = _selected == null || _state != FTLState.Available; |
| 124 | + } |
| 125 | +} |
0 commit comments