Convert almost all IActivate instances that open UIs to ActivatableUI (#7028)
* Chem master * Drone support for handhelds * Vending machines, scanners * Cloners, R&D computers * make research a little less sussy * Unfuck wires * PA control computer * Unfuck merge * Clean up git gore for good * Disposals * Microwaves * paper * Magic mirror * More vendors for drones * Solar computer whitelist * EFR review updates
This commit is contained in:
@@ -1,18 +1,40 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using Content.Server.Arcade.Components;
|
||||
using Content.Server.UserInterface;
|
||||
using Content.Shared.Arcade;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Server.GameObjects;
|
||||
|
||||
|
||||
namespace Content.Server.Arcade
|
||||
{
|
||||
// ReSharper disable once ClassNeverInstantiated.Global
|
||||
public sealed class BlockGameSystem : EntitySystem
|
||||
public sealed class ArcadeSystem : EntitySystem
|
||||
{
|
||||
private readonly List<BlockGameMessages.HighScoreEntry> _roundHighscores = new();
|
||||
private readonly List<BlockGameMessages.HighScoreEntry> _globalHighscores = new();
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<BlockGameArcadeComponent, AfterActivatableUIOpenEvent>(OnAfterUIOpen);
|
||||
SubscribeLocalEvent<SpaceVillainArcadeComponent, AfterActivatableUIOpenEvent>(OnAfterUIOpenSV);
|
||||
}
|
||||
|
||||
private void OnAfterUIOpen(EntityUid uid, BlockGameArcadeComponent component, AfterActivatableUIOpenEvent args)
|
||||
{
|
||||
var actor = Comp<ActorComponent>(args.User);
|
||||
if (component.UserInterface?.SessionHasOpen(actor.PlayerSession) == true)
|
||||
{
|
||||
component.RegisterPlayerSession(actor.PlayerSession);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAfterUIOpenSV(EntityUid uid, SpaceVillainArcadeComponent component, AfterActivatableUIOpenEvent args)
|
||||
{
|
||||
component.Game ??= new SpaceVillainArcadeComponent.SpaceVillainGame(component);
|
||||
}
|
||||
|
||||
public HighScorePlacement RegisterHighScore(string name, int score)
|
||||
{
|
||||
var entry = new BlockGameMessages.HighScoreEntry(name, score);
|
||||
@@ -1,29 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.UserInterface;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Arcade;
|
||||
using Content.Shared.Interaction;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Server.Arcade.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(IActivate))]
|
||||
public sealed class BlockGameArcadeComponent : Component, IActivate
|
||||
public sealed class BlockGameArcadeComponent : Component
|
||||
{
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
|
||||
private bool Powered => _entityManager.TryGetComponent<ApcPowerReceiverComponent>(Owner, out var powerReceiverComponent) && powerReceiverComponent.Powered;
|
||||
private BoundUserInterface? UserInterface => Owner.GetUIOrNull(BlockGameUiKey.Key);
|
||||
public bool Powered => _entityManager.TryGetComponent<ApcPowerReceiverComponent>(Owner, out var powerReceiverComponent) && powerReceiverComponent.Powered;
|
||||
public BoundUserInterface? UserInterface => Owner.GetUIOrNull(BlockGameUiKey.Key);
|
||||
|
||||
private BlockGame? _game;
|
||||
|
||||
@@ -44,19 +37,7 @@ namespace Content.Server.Arcade.Components
|
||||
}
|
||||
}
|
||||
|
||||
void IActivate.Activate(ActivateEventArgs eventArgs)
|
||||
{
|
||||
if(!Powered || !IoCManager.Resolve<IEntityManager>().TryGetComponent(eventArgs.User, out ActorComponent? actor))
|
||||
return;
|
||||
|
||||
UserInterface?.Toggle(actor.PlayerSession);
|
||||
if (UserInterface?.SessionHasOpen(actor.PlayerSession) == true)
|
||||
{
|
||||
RegisterPlayerSession(actor.PlayerSession);
|
||||
}
|
||||
}
|
||||
|
||||
private void RegisterPlayerSession(IPlayerSession session)
|
||||
public void RegisterPlayerSession(IPlayerSession session)
|
||||
{
|
||||
if (_player == null) _player = session;
|
||||
else _spectators.Add(session);
|
||||
@@ -233,7 +214,7 @@ namespace Content.Server.Arcade.Components
|
||||
}
|
||||
private int _internalPoints;
|
||||
|
||||
private BlockGameSystem.HighScorePlacement? _highScorePlacement = null;
|
||||
private ArcadeSystem.HighScorePlacement? _highScorePlacement = null;
|
||||
|
||||
private void SendPointsUpdate()
|
||||
{
|
||||
@@ -292,13 +273,13 @@ namespace Content.Server.Arcade.Components
|
||||
|
||||
private void SendHighscoreUpdate()
|
||||
{
|
||||
var entitySystem = EntitySystem.Get<BlockGameSystem>();
|
||||
var entitySystem = EntitySystem.Get<ArcadeSystem>();
|
||||
_component.UserInterface?.SendMessage(new BlockGameMessages.BlockGameHighScoreUpdateMessage(entitySystem.GetLocalHighscores(), entitySystem.GetGlobalHighscores()));
|
||||
}
|
||||
|
||||
private void SendHighscoreUpdate(IPlayerSession session)
|
||||
{
|
||||
var entitySystem = EntitySystem.Get<BlockGameSystem>();
|
||||
var entitySystem = EntitySystem.Get<ArcadeSystem>();
|
||||
_component.UserInterface?.SendMessage(new BlockGameMessages.BlockGameHighScoreUpdateMessage(entitySystem.GetLocalHighscores(), entitySystem.GetGlobalHighscores()), session);
|
||||
}
|
||||
|
||||
@@ -656,7 +637,7 @@ namespace Content.Server.Arcade.Components
|
||||
|
||||
if (_component._player?.AttachedEntity is {Valid: true} playerEntity)
|
||||
{
|
||||
var blockGameSystem = EntitySystem.Get<BlockGameSystem>();
|
||||
var blockGameSystem = EntitySystem.Get<ArcadeSystem>();
|
||||
|
||||
_highScorePlacement = blockGameSystem.RegisterHighScore(IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(playerEntity).EntityName, Points);
|
||||
SendHighscoreUpdate();
|
||||
|
||||
@@ -1,32 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.UserInterface;
|
||||
using Content.Server.VendingMachines;
|
||||
using Content.Server.WireHacking;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Arcade;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Sound;
|
||||
using Content.Shared.Wires;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.Arcade.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(IActivate))]
|
||||
public sealed class SpaceVillainArcadeComponent : SharedSpaceVillainArcadeComponent, IActivate, IWires
|
||||
public sealed class SpaceVillainArcadeComponent : SharedSpaceVillainArcadeComponent, IWires
|
||||
{
|
||||
[Dependency] private readonly IRobustRandom _random = null!;
|
||||
|
||||
@@ -37,7 +27,7 @@ namespace Content.Server.Arcade.Components
|
||||
[ViewVariables] private bool _overflowFlag;
|
||||
[ViewVariables] private bool _playerInvincibilityFlag;
|
||||
[ViewVariables] private bool _enemyInvincibilityFlag;
|
||||
[ViewVariables] private SpaceVillainGame _game = null!;
|
||||
[ViewVariables] public SpaceVillainGame Game = null!;
|
||||
|
||||
[DataField("newGameSound")] private SoundSpecifier _newGameSound = new SoundPathSpecifier("/Audio/Effects/Arcade/newgame.ogg");
|
||||
[DataField("playerAttackSound")] private SoundSpecifier _playerAttackSound = new SoundPathSpecifier("/Audio/Effects/Arcade/player_attack.ogg");
|
||||
@@ -72,22 +62,6 @@ namespace Content.Server.Arcade.Components
|
||||
"ToyPhazon", "ToyFireRipley", "ToyReticence", "ToyRipley", "ToySeraph", "ToyDurand", "ToySkeleton"
|
||||
};
|
||||
|
||||
void IActivate.Activate(ActivateEventArgs eventArgs)
|
||||
{
|
||||
if (!Powered || !IoCManager.Resolve<IEntityManager>().TryGetComponent(eventArgs.User, out ActorComponent? actor))
|
||||
return;
|
||||
|
||||
_game ??= new SpaceVillainGame(this);
|
||||
|
||||
if (_entityManager.TryGetComponent<WiresComponent>(Owner, out var wiresComponent) && wiresComponent.IsPanelOpen)
|
||||
{
|
||||
wiresComponent.OpenInterface(actor.PlayerSession);
|
||||
}
|
||||
else
|
||||
{
|
||||
UserInterface?.Toggle(actor.PlayerSession);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
@@ -131,22 +105,22 @@ namespace Content.Server.Arcade.Components
|
||||
switch (msg.PlayerAction)
|
||||
{
|
||||
case PlayerAction.Attack:
|
||||
_game?.ExecutePlayerAction(msg.PlayerAction);
|
||||
Game?.ExecutePlayerAction(msg.PlayerAction);
|
||||
break;
|
||||
case PlayerAction.Heal:
|
||||
_game?.ExecutePlayerAction(msg.PlayerAction);
|
||||
Game?.ExecutePlayerAction(msg.PlayerAction);
|
||||
break;
|
||||
case PlayerAction.Recharge:
|
||||
_game?.ExecutePlayerAction(msg.PlayerAction);
|
||||
Game?.ExecutePlayerAction(msg.PlayerAction);
|
||||
break;
|
||||
case PlayerAction.NewGame:
|
||||
SoundSystem.Play(Filter.Pvs(Owner), _newGameSound.GetSound(), Owner, AudioParams.Default.WithVolume(-4f));
|
||||
|
||||
_game = new SpaceVillainGame(this);
|
||||
UserInterface?.SendMessage(_game.GenerateMetaDataMessage());
|
||||
Game = new SpaceVillainGame(this);
|
||||
UserInterface?.SendMessage(Game.GenerateMetaDataMessage());
|
||||
break;
|
||||
case PlayerAction.RequestData:
|
||||
UserInterface?.SendMessage(_game.GenerateMetaDataMessage());
|
||||
UserInterface?.SendMessage(Game.GenerateMetaDataMessage());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user