Event refactor (#9589)

* Station event refactor

* Remove clientside `IStationEventManager`

we can just use prototypes

* Basic API idea

* Cruft

* first attempt at epicness

* okay yeah this shit is really clean

* sort out minor stuff

* Convert `BreakerFlip`

* `BureaucraticError` + general cleanup

* `DiseaseOutbreak`

* `FalseAlarm`

* `GasLeak`

* `KudzuGrowth`

* `MeteorSwarm`

* `MouseMigration`

* misc errors

* `PowerGridCheck`

* `RandomSentience`

* `VentClog`

* `VentCritters`

* `ZombieOutbreak`

* Rewrite basic event scheduler

* Minor fixes and logging

* ooooops

* errors + fix

* linter

* completions, `RuleStarted` property, update loop fixes

* Tweaks

* Fix #9462

* Basic scheduler update fix, and fixes #8174

* Add test

* UI cleanup

* really this was just for testing
This commit is contained in:
Kara
2022-07-10 18:48:41 -07:00
committed by GitHub
parent f28cdaaa7c
commit b9a0894d7c
55 changed files with 1095 additions and 1582 deletions

View File

@@ -12,6 +12,5 @@
<Button Name="LoadGamePrototypeButton" Text="{Loc 'load-game-prototype'}"/>
<cc:UICommandButton Name="LoadBlueprintsButton" Command="loadbp" Text="{Loc 'load-blueprints'}" WindowType="{x:Type abt:LoadBlueprintsWindow}"/>
<cc:CommandButton Command="deleteewc Singularity" Name="DeleteSingulos" Text="{Loc 'delete-singularities'}"/>
<cc:UICommandButton Command="events" Text="{Loc 'open-station-events'}" WindowType="{x:Type abt:StationEventsWindow}" />
</GridContainer>
</Control>

View File

@@ -1,13 +0,0 @@
<DefaultWindow
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" Disabled="True" />
</BoxContainer>
<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>
</DefaultWindow>

View File

@@ -1,86 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using Content.Client.StationEvents.Managers;
using JetBrains.Annotations;
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;
namespace Content.Client.Administration.UI.Tabs.AdminbusTab
{
[GenerateTypedNameReferences]
[UsedImplicitly]
public sealed partial class StationEventsWindow : DefaultWindow
{
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()
{
_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;
SubmitButton.OnPressed += SubmitButtonOnOnPressed;
}
private static void PauseButtonOnOnPressed(BaseButton.ButtonEventArgs obj)
{
IoCManager.Resolve<IClientConsoleHost>().ExecuteCommand("events pause");
}
private static void ResumeButtonOnOnPressed(BaseButton.ButtonEventArgs obj)
{
IoCManager.Resolve<IClientConsoleHost>().ExecuteCommand("events resume");
}
private void SubmitButtonOnOnPressed(BaseButton.ButtonEventArgs obj)
{
if (_data == null)
return;
// random is always last option
var id = EventsOptions.SelectedId;
var selectedEvent = id < _data.Count ? _data[id] : "random";
IoCManager.Resolve<IClientConsoleHost>().ExecuteCommand($"events run \"{selectedEvent}\"");
}
}
}

View File

@@ -17,11 +17,10 @@ using Content.Client.MobState.Overlays;
using Content.Client.Parallax;
using Content.Client.Parallax.Managers;
using Content.Client.Preferences;
using Content.Client.Radiation;
using Content.Client.Sandbox;
using Content.Client.Screenshot;
using Content.Client.Singularity;
using Content.Client.StationEvents;
using Content.Client.StationEvents.Managers;
using Content.Client.Stylesheets;
using Content.Client.Viewport;
using Content.Client.Voting;
@@ -192,7 +191,6 @@ namespace Content.Client.Entry
IoCManager.Resolve<IChatManager>().Initialize();
IoCManager.Resolve<IClientPreferencesManager>().Initialize();
IoCManager.Resolve<IStationEventManager>().Initialize();
IoCManager.Resolve<EuiManager>().Initialize();
IoCManager.Resolve<IVoteManager>().Initialize();
IoCManager.Resolve<IGamePrototypeLoadManager>().Initialize();

View File

@@ -13,7 +13,6 @@ using Content.Client.Module;
using Content.Client.Parallax.Managers;
using Content.Client.Preferences;
using Content.Client.Screenshot;
using Content.Client.StationEvents.Managers;
using Content.Client.Stylesheets;
using Content.Client.Viewport;
using Content.Client.Voting;
@@ -37,7 +36,6 @@ namespace Content.Client.IoC
IoCManager.Register<IStylesheetManager, StylesheetManager>();
IoCManager.Register<IScreenshotHook, ScreenshotHook>();
IoCManager.Register<IClickMapManager, ClickMapManager>();
IoCManager.Register<IStationEventManager, StationEventManager>();
IoCManager.Register<IClientAdminManager, ClientAdminManager>();
IoCManager.Register<EuiManager, EuiManager>();
IoCManager.Register<IVoteManager, VoteManager>();

View File

@@ -1,8 +1,6 @@
using System;
using Content.Shared.Radiation;
using Robust.Shared.GameObjects;
namespace Content.Client.StationEvents
namespace Content.Client.Radiation
{
[RegisterComponent]
[ComponentReference(typeof(SharedRadiationPulseComponent))]

View File

@@ -1,16 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Robust.Client.Graphics;
using Robust.Shared.Enums;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
namespace Content.Client.StationEvents
namespace Content.Client.Radiation
{
public sealed class RadiationPulseOverlay : Overlay
{

View File

@@ -1,13 +0,0 @@
using System;
using System.Collections.Generic;
namespace Content.Client.StationEvents.Managers
{
public interface IStationEventManager
{
public IReadOnlyList<string> StationEvents { get; }
public void Initialize();
public event Action OnStationEventsReceived;
public void RequestEvents();
}
}

View File

@@ -1,41 +0,0 @@
using System;
using System.Collections.Generic;
using Content.Shared.StationEvents;
using Robust.Shared.IoC;
using Robust.Shared.Network;
namespace Content.Client.StationEvents.Managers
{
internal sealed class StationEventManager : IStationEventManager
{
[Dependency] private readonly IClientNetManager _netManager = default!;
private readonly List<string> _events = new();
public IReadOnlyList<string> StationEvents => _events;
public event Action? OnStationEventsReceived;
public void Initialize()
{
_netManager.RegisterNetMessage<MsgRequestStationEvents>();
_netManager.RegisterNetMessage<MsgStationEvents>(RxStationEvents);
_netManager.Disconnect += OnNetManagerOnDisconnect;
}
private void OnNetManagerOnDisconnect(object? sender, NetDisconnectedArgs msg)
{
_events.Clear();
}
private void RxStationEvents(MsgStationEvents msg)
{
_events.Clear();
_events.AddRange(msg.Events);
OnStationEventsReceived?.Invoke();
}
public void RequestEvents()
{
_netManager.ClientSendMessage(_netManager.CreateNetMessage<MsgRequestStationEvents>());
}
}
}