Skip to content

Commit

Permalink
Removes all dependencies on engine component events. (#4199)
Browse files Browse the repository at this point in the history
  • Loading branch information
Acruid authored Jun 18, 2021
1 parent 9fea687 commit e1e54e9
Show file tree
Hide file tree
Showing 27 changed files with 236 additions and 185 deletions.
6 changes: 5 additions & 1 deletion Content.Client/Actions/ActionsSystem.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Content.Client.Construction;
using Content.Client.Construction;
using Content.Client.DragDrop;
using Content.Shared.Input;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Client.Player;
using Robust.Shared.GameObjects;
using Robust.Shared.Input;
Expand Down Expand Up @@ -66,6 +67,9 @@ public override void Initialize()
.BindBefore(EngineKeyFunctions.Use, new PointerInputCmdHandler(TargetingOnUse),
typeof(ConstructionSystem), typeof(DragDropSystem))
.Register<ActionsSystem>();

SubscribeLocalEvent<ClientActionsComponent, PlayerAttachedEvent>((_, component, _) => component.PlayerAttached());
SubscribeLocalEvent<ClientActionsComponent, PlayerDetachedEvent>((_, component, _) => component.PlayerDetached());
}

public override void Shutdown()
Expand Down
20 changes: 3 additions & 17 deletions Content.Client/Actions/ClientActionsComponent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using Content.Client.Actions.Assignments;
using Content.Client.Actions.UI;
using Content.Client.Hands;
Expand Down Expand Up @@ -51,20 +51,6 @@ protected override void Shutdown()
PlayerDetached();
}

public override void HandleMessage(ComponentMessage message, IComponent? component)
{
base.HandleMessage(message, component);
switch (message)
{
case PlayerAttachedMsg _:
PlayerAttached();
break;
case PlayerDetachedMsg _:
PlayerDetached();
break;
}
}

public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
{
base.HandleComponentState(curState, nextState);
Expand All @@ -77,7 +63,7 @@ public override void HandleComponentState(ComponentState? curState, ComponentSta
UpdateUI();
}

private void PlayerAttached()
public void PlayerAttached()
{
if (!CurrentlyControlled || _ui != null)
{
Expand All @@ -89,7 +75,7 @@ private void PlayerAttached()
UpdateUI();
}

private void PlayerDetached()
public void PlayerDetached()
{
if (_ui == null) return;
IoCManager.Resolve<IUserInterfaceManager>().StateRoot.RemoveChild(_ui);
Expand Down
20 changes: 3 additions & 17 deletions Content.Client/Alerts/ClientAlertsComponent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using Content.Client.Alerts.UI;
using Content.Shared.Alert;
Expand Down Expand Up @@ -41,20 +41,6 @@ protected override void Shutdown()
PlayerDetached();
}

public override void HandleMessage(ComponentMessage message, IComponent? component)
{
base.HandleMessage(message, component);
switch (message)
{
case PlayerAttachedMsg _:
PlayerAttached();
break;
case PlayerDetachedMsg _:
PlayerDetached();
break;
}
}

public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
{
base.HandleComponentState(curState, nextState);
Expand All @@ -67,7 +53,7 @@ public override void HandleComponentState(ComponentState? curState, ComponentSta
UpdateAlertsControls();
}

private void PlayerAttached()
public void PlayerAttached()
{
if (!CurrentlyControlled || _ui != null)
{
Expand All @@ -86,7 +72,7 @@ private void PlayerAttached()
UpdateAlertsControls();
}

private void PlayerDetached()
public void PlayerDetached()
{
foreach (var alertControl in _alertControls.Values)
{
Expand Down
16 changes: 16 additions & 0 deletions Content.Client/Alerts/ClientAlertsSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Robust.Client.GameObjects;
using Robust.Shared.GameObjects;

namespace Content.Client.Alerts
{
internal class ClientAlertsSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<ClientAlertsComponent, PlayerAttachedEvent>((_, component, _) => component.PlayerAttached());
SubscribeLocalEvent<ClientAlertsComponent, PlayerDetachedEvent>((_, component, _) => component.PlayerDetached());
}
}
}
43 changes: 18 additions & 25 deletions Content.Client/CharacterInterface/CharacterInterfaceComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,39 +76,32 @@ public override void OnRemove()
inputMgr.SetInputCommand(ContentKeyFunctions.OpenCharacterMenu, null);
}

public override void HandleMessage(ComponentMessage message, IComponent? component)
public void PlayerDetached()
{
base.HandleMessage(message, component);
if (Window != null)
{
_gameHud.CharacterButtonVisible = false;
Window.Close();
}
}

switch (message)
public void PlayerAttached()
{
if (Window != null)
{
case PlayerAttachedMsg _:
if (Window != null)
_gameHud.CharacterButtonVisible = true;

_gameHud.CharacterButtonToggled = b =>
{
if (b)
{
_gameHud.CharacterButtonVisible = true;
_gameHud.CharacterButtonToggled = b =>
{
if (b)
{
Window.OpenCentered();
}
else
{
Window.Close();
}
};
Window.OpenCentered();
}

break;

case PlayerDetachedMsg _:
if (Window != null)
else
{
_gameHud.CharacterButtonVisible = false;
Window.Close();
}

break;
};
}
}

Expand Down
4 changes: 4 additions & 0 deletions Content.Client/CharacterInterface/CharacterInterfaceSystem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Content.Client.HUD;
using Content.Shared.Input;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Client.Player;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.GameObjects;
Expand All @@ -23,6 +24,9 @@ public override void Initialize()
.Bind(ContentKeyFunctions.OpenCharacterMenu,
InputCmdHandler.FromDelegate(s => HandleOpenCharacterMenu()))
.Register<CharacterInterfaceSystem>();

SubscribeLocalEvent<CharacterInterfaceComponent, PlayerAttachedEvent>((_, component, _) => component.PlayerAttached());
SubscribeLocalEvent<CharacterInterfaceComponent, PlayerDetachedEvent>((_, component, _) => component.PlayerDetached());
}

public override void Shutdown()
Expand Down
21 changes: 6 additions & 15 deletions Content.Client/CombatMode/CombatModeComponent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Content.Client.HUD;
using Content.Client.HUD;
using Content.Shared.CombatMode;
using Content.Shared.Targeting;
using Robust.Client.GameObjects;
Expand Down Expand Up @@ -35,21 +35,12 @@ public override TargetingZone ActiveZone
}
}

public override void HandleMessage(ComponentMessage message, IComponent? component)
{
base.HandleMessage(message, component);

switch (message)
{
case PlayerAttachedMsg _:
_gameHud.CombatPanelVisible = true;
UpdateHud();
break;
public void PlayerDetached() { _gameHud.CombatPanelVisible = false; }

case PlayerDetachedMsg _:
_gameHud.CombatPanelVisible = false;
break;
}
public void PlayerAttached()
{
_gameHud.CombatPanelVisible = true;
UpdateHud();
}

private void UpdateHud()
Expand Down
3 changes: 3 additions & 0 deletions Content.Client/CombatMode/CombatModeSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public override void Initialize()
base.Initialize();

_gameHud.OnTargetingZoneChanged = OnTargetingZoneChanged;

SubscribeLocalEvent<CombatModeComponent, PlayerAttachedEvent>((_, component, _) => component.PlayerAttached());
SubscribeLocalEvent<CombatModeComponent, PlayerDetachedEvent>((_, component, _) => component.PlayerDetached());
}

public override void Shutdown()
Expand Down
33 changes: 17 additions & 16 deletions Content.Client/Hands/HandsComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,22 +210,6 @@ public override void HandleMessage(ComponentMessage message, IComponent? compone

switch (message)
{
case PlayerAttachedMsg _:
if (_gui == null)
{
_gui = new HandsGui();
}
else
{
_gui.Parent?.RemoveChild(_gui);
}

_gameHud.HandsContainer.AddChild(_gui);
_gui.UpdateHandIcons();
break;
case PlayerDetachedMsg _:
_gui?.Parent?.RemoveChild(_gui);
break;
case HandEnabledMsg msg:
{
var hand = GetHand(msg.Name);
Expand Down Expand Up @@ -255,6 +239,23 @@ public override void HandleMessage(ComponentMessage message, IComponent? compone
}
}

public void PlayerDetached() { _gui?.Parent?.RemoveChild(_gui); }

public void PlayerAttached()
{
if (_gui == null)
{
_gui = new HandsGui();
}
else
{
_gui.Parent?.RemoveChild(_gui);
}

_gameHud.HandsContainer.AddChild(_gui);
_gui.UpdateHandIcons();
}

public override void HandleNetworkMessage(ComponentMessage message, INetChannel netChannel, ICommonSession? session = null)
{
base.HandleNetworkMessage(message, netChannel, session);
Expand Down
16 changes: 16 additions & 0 deletions Content.Client/Hands/HandsSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Robust.Client.GameObjects;
using Robust.Shared.GameObjects;

namespace Content.Client.Hands
{
internal class HandsSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<HandsComponent, PlayerAttachedEvent>((_, component, _) => component.PlayerAttached());
SubscribeLocalEvent<HandsComponent, PlayerDetachedEvent>((_, component, _) => component.PlayerDetached());
}
}
}
24 changes: 9 additions & 15 deletions Content.Client/Inventory/ClientInventoryComponent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Content.Client.Clothing;
Expand Down Expand Up @@ -252,22 +252,16 @@ public void SendOpenStorageUIMessage(Slots slot)
SendNetworkMessage(new OpenSlotStorageUIMessage(slot));
}

public override void HandleMessage(ComponentMessage message, IComponent? component)
public void PlayerDetached()
{
base.HandleMessage(message, component);
InterfaceController.PlayerDetached();
_playerAttached = false;
}

switch (message)
{
case PlayerAttachedMsg _:
InterfaceController.PlayerAttached();
_playerAttached = true;
break;

case PlayerDetachedMsg _:
InterfaceController.PlayerDetached();
_playerAttached = false;
break;
}
public void PlayerAttached()
{
InterfaceController.PlayerAttached();
_playerAttached = true;
}

public bool TryGetSlot(Slots slot, [NotNullWhen(true)] out IEntity? item)
Expand Down
6 changes: 4 additions & 2 deletions Content.Client/Inventory/ClientInventorySystem.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Content.Client.HUD;
using Content.Shared.Input;
using JetBrains.Annotations;
using Robust.Client.Player;
using Robust.Client.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Input.Binding;
using Robust.Shared.IoC;
Expand All @@ -12,7 +12,6 @@ namespace Content.Client.Inventory
public sealed class ClientInventorySystem : EntitySystem
{
[Dependency] private readonly IGameHud _gameHud = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;

public override void Initialize()
{
Expand All @@ -22,6 +21,9 @@ public override void Initialize()
.Bind(ContentKeyFunctions.OpenInventoryMenu,
InputCmdHandler.FromDelegate(_ => HandleOpenInventoryMenu()))
.Register<ClientInventorySystem>();

SubscribeLocalEvent<ClientInventoryComponent, PlayerAttachedEvent>((_, component, _) => component.PlayerAttached());
SubscribeLocalEvent<ClientInventoryComponent, PlayerDetachedEvent>((_, component, _) => component.PlayerDetached());
}

public override void Shutdown()
Expand Down
Loading

0 comments on commit e1e54e9

Please sign in to comment.