Replace usages of ISharedNotifyManager and IServerNotifyManager with extension methods (#1965)

* Replace usages of ISharedNotifyManager and IServerNotifyManager with extension methods

* Remove redundant code
This commit is contained in:
DrSmugleaf
2020-09-01 12:34:53 +02:00
committed by GitHub
parent 14259ed920
commit 8f9ed2f562
53 changed files with 247 additions and 375 deletions

View File

@@ -2,13 +2,12 @@
using System.Collections.Generic;
using Content.Server.GameObjects.Components.GUI;
using Content.Server.GameObjects.Components.Items.Storage;
using Content.Server.Interfaces;
using Content.Shared.GameObjects;
using Content.Shared.GameObjects.Components.Items;
using Content.Shared.Interfaces;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Serialization;
using static Content.Shared.GameObjects.Components.Inventory.EquipmentSlotDefines;
@@ -20,8 +19,6 @@ namespace Content.Server.GameObjects.Components.Items.Clothing
[ComponentReference(typeof(IItemComponent))]
public class ClothingComponent : ItemComponent, IUse
{
[Dependency] private readonly IServerNotifyManager _serverNotifyManager = default!;
public override string Name => "Clothing";
public override uint? NetID => ContentNetIDs.CLOTHING;
@@ -112,7 +109,7 @@ namespace Content.Server.GameObjects.Components.Items.Clothing
if (!inv.Equip(slot, this, true, out var reason))
{
if (reason != null)
_serverNotifyManager.PopupMessage(Owner, user, reason);
Owner.PopupMessage(user, reason);
return false;
}

View File

@@ -1,10 +1,9 @@
using System;
using Content.Server.Interfaces;
using Content.Server.Interfaces.GameObjects.Components.Items;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.Interfaces;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;
@@ -15,8 +14,6 @@ namespace Content.Server.GameObjects.Components.Items.RCD
[RegisterComponent]
public class RCDAmmoComponent : Component, IAfterInteract, IExamine
{
[Dependency] private IServerNotifyManager _serverNotifyManager = default!;
public override string Name => "RCDAmmo";
//How much ammo we refill
@@ -43,17 +40,16 @@ namespace Content.Server.GameObjects.Components.Items.RCD
if (rcdComponent.maxAmmo - rcdComponent._ammo < refillAmmo)
{
_serverNotifyManager.PopupMessage(rcdComponent.Owner, eventArgs.User, "The RCD is full!");
rcdComponent.Owner.PopupMessage(eventArgs.User, Loc.GetString("The RCD is full!"));
return;
}
rcdComponent._ammo = Math.Min(rcdComponent.maxAmmo, rcdComponent._ammo + refillAmmo);
_serverNotifyManager.PopupMessage(rcdComponent.Owner, eventArgs.User, "You refill the RCD.");
rcdComponent.Owner.PopupMessage(eventArgs.User, Loc.GetString("You refill the RCD."));
//Deleting a held item causes a lot of errors
hands.Drop(Owner, false);
Owner.Delete();
}
}
}

View File

@@ -1,9 +1,8 @@
using System;
using System.Threading;
using Content.Server.GameObjects.EntitySystems.DoAfter;
using Content.Server.Interfaces;
using Content.Server.Utility;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.Interfaces;
using Content.Shared.Interfaces.GameObjects.Components;
using Content.Shared.Maps;
using Content.Shared.Utility;
@@ -30,7 +29,6 @@ namespace Content.Server.GameObjects.Components.Items.RCD
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IServerEntityManager _serverEntityManager = default!;
[Dependency] private readonly IServerNotifyManager _serverNotifyManager = default!;
public override string Name => "RCD";
private RcdMode _mode = 0; //What mode are we on? Can be floors, walls, deconstruct.
@@ -86,12 +84,12 @@ namespace Content.Server.GameObjects.Components.Items.RCD
int mode = (int) _mode; //Firstly, cast our RCDmode mode to an int (enums are backed by ints anyway by default)
mode = (++mode) % _modes.Length; //Then, do a rollover on the value so it doesnt hit an invalid state
_mode = (RcdMode) mode; //Finally, cast the newly acquired int mode to an RCDmode so we can use it.
_serverNotifyManager.PopupMessage(Owner, eventArgs.User, $"The RCD is now set to {this._mode} mode."); //Prints an overhead message above the RCD
Owner.PopupMessage(eventArgs.User, Loc.GetString("The RCD is now set to {0} mode.", _mode)); //Prints an overhead message above the RCD
}
public void Examine(FormattedMessage message, bool inDetailsRange)
{
message.AddMarkup(Loc.GetString("It's currently on {0} mode, and holds {1} charges.",_mode.ToString(), this._ammo));
message.AddMarkup(Loc.GetString("It's currently on {0} mode, and holds {1} charges.",_mode.ToString(), _ammo));
}
public async void AfterInteract(AfterInteractEventArgs eventArgs)
@@ -159,7 +157,7 @@ namespace Content.Server.GameObjects.Components.Items.RCD
//Less expensive checks first. Failing those ones, we need to check that the tile isn't obstructed.
if (_ammo <= 0)
{
_serverNotifyManager.PopupMessage(Owner, eventArgs.User, $"The RCD is out of ammo!");
Owner.PopupMessage(eventArgs.User, Loc.GetString("The RCD is out of ammo!"));
return false;
}
@@ -180,7 +178,7 @@ namespace Content.Server.GameObjects.Components.Items.RCD
case RcdMode.Floors:
if (!tile.Tile.IsEmpty)
{
_serverNotifyManager.PopupMessage(Owner, eventArgs.User, $"You can only build a floor on space!");
Owner.PopupMessage(eventArgs.User, Loc.GetString("You can only build a floor on space!"));
return false;
}
@@ -195,13 +193,13 @@ namespace Content.Server.GameObjects.Components.Items.RCD
//They tried to decon a turf but the turf is blocked
if (eventArgs.Target == null && tile.IsBlockedTurf(true))
{
_serverNotifyManager.PopupMessage(Owner, eventArgs.User, $"That tile is obstructed!");
Owner.PopupMessage(eventArgs.User, Loc.GetString("That tile is obstructed!"));
return false;
}
//They tried to decon a non-turf but it's not in the whitelist
if (eventArgs.Target != null && !eventArgs.Target.TryGetComponent(out RCDDeconstructWhitelist rcd_decon))
{
_serverNotifyManager.PopupMessage(Owner, eventArgs.User, $"You can't deconstruct that!");
Owner.PopupMessage(eventArgs.User, Loc.GetString("You can't deconstruct that!"));
return false;
}
@@ -210,25 +208,25 @@ namespace Content.Server.GameObjects.Components.Items.RCD
case RcdMode.Walls:
if (tile.Tile.IsEmpty)
{
_serverNotifyManager.PopupMessage(Owner, eventArgs.User, $"Cannot build a wall on space!");
Owner.PopupMessage(eventArgs.User, Loc.GetString("You cannot build a wall on space!"));
return false;
}
if (tile.IsBlockedTurf(true))
{
_serverNotifyManager.PopupMessage(Owner, eventArgs.User, $"That tile is obstructed!");
Owner.PopupMessage(eventArgs.User, Loc.GetString("That tile is obstructed!"));
return false;
}
return true;
case RcdMode.Airlock:
if (tile.Tile.IsEmpty)
{
_serverNotifyManager.PopupMessage(Owner, eventArgs.User, $"Cannot build an airlock on space!");
Owner.PopupMessage(eventArgs.User, Loc.GetString("Cannot build an airlock on space!"));
return false;
}
if (tile.IsBlockedTurf(true))
{
_serverNotifyManager.PopupMessage(Owner, eventArgs.User, $"That tile is obstructed!");
Owner.PopupMessage(eventArgs.User, Loc.GetString("That tile is obstructed!"));
return false;
}
return true;

View File

@@ -126,8 +126,7 @@ namespace Content.Server.GameObjects.Components.Items.Storage
{
if (!reader.IsAllowed(user))
{
IoCManager.Resolve<IServerNotifyManager>()
.PopupMessage(Owner, user, Loc.GetString("Access denied"));
Owner.PopupMessage(user, Loc.GetString("Access denied"));
return true;
}
}