Fix admin events UI (#4530)

This commit is contained in:
Alex Evgrashin
2021-08-26 12:45:05 +03:00
committed by GitHub
parent 50bc156d82
commit 18a1178654
2 changed files with 42 additions and 9 deletions

View File

@@ -1,13 +1,13 @@
<SS14Window <SS14Window
xmlns="https://spacestation14.io" Title="Kick"> xmlns="https://spacestation14.io" Title="{Loc Events}">
<BoxContainer Orientation="Vertical"> <BoxContainer Orientation="Vertical">
<BoxContainer Orientation="Horizontal"> <BoxContainer Orientation="Horizontal">
<Label Text="{Loc Event}" MinSize="100 0" /> <Label Text="{Loc Event}" MinSize="100 0" />
<Control MinSize="50 0" /> <Control MinSize="50 0" />
<OptionButton Name="EventsOptions" MinSize="100 0" HorizontalExpand="True" /> <OptionButton Name="EventsOptions" MinSize="100 0" HorizontalExpand="True" Disabled="True" />
</BoxContainer> </BoxContainer>
<Button Name="PauseButton" Text="{Loc Pause}" /> <Button Name="PauseButton" Text="{Loc Pause}" Disabled="True" />
<Button Name="ResumeButton" Text="{Loc Resume}" /> <Button Name="ResumeButton" Text="{Loc Resume}" Disabled="True" />
<Button Name="SubmitButton" Text="{Loc Run}" /> <Button Name="SubmitButton" Text="{Loc Run}" Disabled="True" />
</BoxContainer> </BoxContainer>
</SS14Window> </SS14Window>

View File

@@ -6,6 +6,7 @@ using Robust.Client.AutoGenerated;
using Robust.Client.Console; using Robust.Client.Console;
using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls; using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Localization; using Robust.Shared.Localization;
@@ -17,15 +18,43 @@ namespace Content.Client.Administration.UI.Tabs.AdminbusTab
{ {
private List<string>? _data; private List<string>? _data;
[Dependency]
private readonly IStationEventManager _eventManager = default!;
public StationEventsWindow()
{
IoCManager.InjectDependencies(this);
MinSize = SetSize = (300, 200);
RobustXamlLoader.Load(this);
}
protected override void EnteredTree() protected override void EnteredTree()
{ {
_data = IoCManager.Resolve<IStationEventManager>().StationEvents.ToList(); _eventManager.OnStationEventsReceived += OnStationEventsReceived;
_data.Add(_data.Any() ? Loc.GetString("station-events-window-not-loaded-text") : Loc.GetString("station-events-window-random-text")); _eventManager.RequestEvents();
EventsOptions.AddItem(Loc.GetString("station-events-window-not-loaded-text"));
}
private void OnStationEventsReceived()
{
// fill events dropdown
_data = _eventManager.StationEvents.ToList();
EventsOptions.Clear();
foreach (var stationEvent in _data) foreach (var stationEvent in _data)
{ {
EventsOptions.AddItem(stationEvent); EventsOptions.AddItem(stationEvent);
} }
EventsOptions.AddItem(Loc.GetString("station-events-window-random-text"));
// Enable all UI elements
EventsOptions.Disabled = false;
PauseButton.Disabled = false;
ResumeButton.Disabled = false;
SubmitButton.Disabled = false;
// Subscribe to UI events
EventsOptions.OnItemSelected += eventArgs => EventsOptions.SelectId(eventArgs.Id); EventsOptions.OnItemSelected += eventArgs => EventsOptions.SelectId(eventArgs.Id);
PauseButton.OnPressed += PauseButtonOnOnPressed; PauseButton.OnPressed += PauseButtonOnOnPressed;
ResumeButton.OnPressed += ResumeButtonOnOnPressed; ResumeButton.OnPressed += ResumeButtonOnOnPressed;
@@ -46,7 +75,11 @@ namespace Content.Client.Administration.UI.Tabs.AdminbusTab
{ {
if (_data == null) if (_data == null)
return; return;
var selectedEvent = _data[EventsOptions.SelectedId];
// random is always last option
var id = EventsOptions.SelectedId;
var selectedEvent = id < _data.Count ? _data[id] : "random";
IoCManager.Resolve<IClientConsoleHost>().ExecuteCommand($"events run \"{selectedEvent}\""); IoCManager.Resolve<IClientConsoleHost>().ExecuteCommand($"events run \"{selectedEvent}\"");
} }
} }