Fix admin events UI (#4530)
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
<SS14Window
|
||||
xmlns="https://spacestation14.io" Title="Kick">
|
||||
<SS14Window
|
||||
xmlns="https://spacestation14.io" Title="{Loc Events}">
|
||||
<BoxContainer Orientation="Vertical">
|
||||
<BoxContainer Orientation="Horizontal">
|
||||
<Label Text="{Loc Event}" MinSize="100 0" />
|
||||
<Control MinSize="50 0" />
|
||||
<OptionButton Name="EventsOptions" MinSize="100 0" HorizontalExpand="True" />
|
||||
<OptionButton Name="EventsOptions" MinSize="100 0" HorizontalExpand="True" Disabled="True" />
|
||||
</BoxContainer>
|
||||
<Button Name="PauseButton" Text="{Loc Pause}" />
|
||||
<Button Name="ResumeButton" Text="{Loc Resume}" />
|
||||
<Button Name="SubmitButton" Text="{Loc Run}" />
|
||||
<Button Name="PauseButton" Text="{Loc Pause}" Disabled="True" />
|
||||
<Button Name="ResumeButton" Text="{Loc Resume}" Disabled="True" />
|
||||
<Button Name="SubmitButton" Text="{Loc Run}" Disabled="True" />
|
||||
</BoxContainer>
|
||||
</SS14Window>
|
||||
|
||||
@@ -6,6 +6,7 @@ using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.Console;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
|
||||
@@ -17,15 +18,43 @@ namespace Content.Client.Administration.UI.Tabs.AdminbusTab
|
||||
{
|
||||
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()
|
||||
{
|
||||
_data = IoCManager.Resolve<IStationEventManager>().StationEvents.ToList();
|
||||
_data.Add(_data.Any() ? Loc.GetString("station-events-window-not-loaded-text") : Loc.GetString("station-events-window-random-text"));
|
||||
_eventManager.OnStationEventsReceived += OnStationEventsReceived;
|
||||
_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)
|
||||
{
|
||||
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);
|
||||
PauseButton.OnPressed += PauseButtonOnOnPressed;
|
||||
ResumeButton.OnPressed += ResumeButtonOnOnPressed;
|
||||
@@ -46,7 +75,11 @@ namespace Content.Client.Administration.UI.Tabs.AdminbusTab
|
||||
{
|
||||
if (_data == null)
|
||||
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}\"");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user