diff --git a/Content.Client/ClientNotifyManager.cs b/Content.Client/ClientNotifyManager.cs new file mode 100644 index 0000000000..125dddf230 --- /dev/null +++ b/Content.Client/ClientNotifyManager.cs @@ -0,0 +1,127 @@ +using System; +using System.Collections.Generic; +using Content.Client.Interfaces; +using Content.Shared; +using SS14.Client; +using SS14.Client.Interfaces.Console; +using SS14.Client.Interfaces.Graphics.ClientEye; +using SS14.Client.Interfaces.Input; +using SS14.Client.Interfaces.UserInterface; +using SS14.Client.Player; +using SS14.Client.UserInterface.Controls; +using SS14.Shared.Interfaces.GameObjects; +using SS14.Shared.Interfaces.Network; +using SS14.Shared.IoC; +using SS14.Shared.Map; +using SS14.Shared.Maths; +using SS14.Shared.Utility; + +namespace Content.Client +{ + public class ClientNotifyManager : SharedNotifyManager, IClientNotifyManager + { +#pragma warning disable 649 + [Dependency] private IPlayerManager _playerManager; + [Dependency] private IUserInterfaceManager _userInterfaceManager; + [Dependency] private IInputManager _inputManager; + [Dependency] private IEyeManager _eyeManager; + [Dependency] private IClientNetManager _netManager; +#pragma warning restore 649 + + private readonly List _aliveLabels = new List(); + private bool _initialized; + + public void Initialize() + { + DebugTools.Assert(!_initialized); + + _netManager.RegisterNetMessage(nameof(MsgDoNotify), DoNotifyMessage); + + _initialized = true; + } + + private void DoNotifyMessage(MsgDoNotify message) + { + PopupMessage(_eyeManager.WorldToScreen(message.Coordinates), message.Message); + } + + public override void PopupMessage(GridLocalCoordinates coordinates, IEntity viewer, string message) + { + if (viewer != _playerManager.LocalPlayer.ControlledEntity) + { + return; + } + + PopupMessage(_eyeManager.WorldToScreen(coordinates), message); + } + + public void PopupMessage(ScreenCoordinates coordinates, string message) + { + var label = new PopupLabel {Text = message}; + var minimumSize = label.CombinedMinimumSize; + label.InitialPos = label.Position = coordinates.AsVector - minimumSize / 2; + _userInterfaceManager.StateRoot.AddChild(label); + _aliveLabels.Add(label); + } + + public void PopupMessage(string message) + { + PopupMessage(new ScreenCoordinates(_inputManager.MouseScreenPosition), message); + } + + public void FrameUpdate(RenderFrameEventArgs eventArgs) + { + foreach (var label in _aliveLabels) + { + label.Update(eventArgs); + } + + _aliveLabels.RemoveAll(l => l.Disposed); + } + + private class PopupLabel : Label + { + private float _timeLeft; + public Vector2 InitialPos { get; set; } + + protected override void Initialize() + { + base.Initialize(); + + ShadowOffsetXOverride = 1; + ShadowOffsetYOverride = 1; + FontColorShadowOverride = Color.Black; + + } + + public void Update(RenderFrameEventArgs eventArgs) + { + _timeLeft += eventArgs.Elapsed; + Position = InitialPos - new Vector2(0, 20 * (_timeLeft * _timeLeft + _timeLeft)); + if (_timeLeft > 0.5f) + { + Modulate = Color.White.WithAlpha(1f - 0.2f * (float)Math.Pow(_timeLeft - 0.5f, 3f)); + if (_timeLeft > 3f) + { + Dispose(); + } + } + } + } + } + + public class PopupMessageCommand : IConsoleCommand + { + public string Command => "popupmsg"; + public string Description => ""; + public string Help => ""; + + public bool Execute(IDebugConsole console, params string[] args) + { + var arg = args[0]; + var mgr = IoCManager.Resolve(); + mgr.PopupMessage(arg); + return false; + } + } +} diff --git a/Content.Client/Content.Client.csproj b/Content.Client/Content.Client.csproj index 4fe9afb6a1..d7a601bd7c 100644 --- a/Content.Client/Content.Client.csproj +++ b/Content.Client/Content.Client.csproj @@ -74,8 +74,11 @@ + + + diff --git a/Content.Client/EntryPoint.cs b/Content.Client/EntryPoint.cs index 2a2f4ee15d..add7469e56 100644 --- a/Content.Client/EntryPoint.cs +++ b/Content.Client/EntryPoint.cs @@ -5,7 +5,10 @@ using Content.Client.GameObjects.Components.Power; using Content.Client.GameObjects.Components.SmoothWalling; using Content.Client.GameObjects.Components.Storage; using Content.Client.Input; +using Content.Client.Interfaces; using Content.Client.Interfaces.GameObjects; +using Content.Shared.Interfaces; +using SS14.Client; using SS14.Client.Interfaces.Input; using SS14.Client.Utility; using SS14.Shared.ContentPack; @@ -72,6 +75,9 @@ namespace Content.Client prototypes.RegisterIgnore("material"); + IoCManager.Register(); + IoCManager.Register(); + IoCManager.BuildGraph(); } public override void PostInit() @@ -81,6 +87,20 @@ namespace Content.Client // Setup key contexts var inputMan = IoCManager.Resolve(); ContentContexts.SetupContexts(inputMan.Contexts); + + IoCManager.Resolve().Initialize(); + } + + public override void Update(AssemblyLoader.UpdateLevel level, float frameTime) + { + base.Update(level, frameTime); + + switch (level) + { + case AssemblyLoader.UpdateLevel.FramePreEngine: + IoCManager.Resolve().FrameUpdate(new RenderFrameEventArgs(frameTime)); + break; + } } } } diff --git a/Content.Client/GameObjects/EntitySystems/ClientNotifySystem.cs b/Content.Client/GameObjects/EntitySystems/ClientNotifySystem.cs new file mode 100644 index 0000000000..930fda53a6 --- /dev/null +++ b/Content.Client/GameObjects/EntitySystems/ClientNotifySystem.cs @@ -0,0 +1,7 @@ +namespace Content.Client.GameObjects.EntitySystems +{ + public class ClientNotifySystem + { + + } +} diff --git a/Content.Client/Interfaces/IClientNotifyManager.cs b/Content.Client/Interfaces/IClientNotifyManager.cs new file mode 100644 index 0000000000..479f070b17 --- /dev/null +++ b/Content.Client/Interfaces/IClientNotifyManager.cs @@ -0,0 +1,14 @@ +using Content.Shared.Interfaces; +using SS14.Client; +using SS14.Shared.Map; + +namespace Content.Client.Interfaces +{ + public interface IClientNotifyManager : ISharedNotifyManager + { + void Initialize(); + void PopupMessage(ScreenCoordinates coordinates, string message); + void PopupMessage(string message); + void FrameUpdate(RenderFrameEventArgs eventArgs); + } +} diff --git a/Content.Server/Content.Server.csproj b/Content.Server/Content.Server.csproj index f09d19e118..1e57e86ca7 100644 --- a/Content.Server/Content.Server.csproj +++ b/Content.Server/Content.Server.csproj @@ -116,6 +116,7 @@ + @@ -127,6 +128,7 @@ + diff --git a/Content.Server/EntryPoint.cs b/Content.Server/EntryPoint.cs index 5e4ca02e48..8ede28cbf9 100644 --- a/Content.Server/EntryPoint.cs +++ b/Content.Server/EntryPoint.cs @@ -34,7 +34,9 @@ using Content.Server.GameObjects.EntitySystems; using Content.Server.Mobs; using Content.Server.Players; using Content.Server.GameObjects.Components.Interactable; +using Content.Server.Interfaces; using Content.Shared.GameObjects.Components.Inventory; +using Content.Shared.Interfaces; namespace Content.Server { @@ -125,6 +127,12 @@ namespace Content.Server factory.RegisterIgnore("ConstructionGhost"); factory.Register(); + + IoCManager.Register(); + IoCManager.Register(); + IoCManager.BuildGraph(); + + IoCManager.Resolve().Initialize(); } /// diff --git a/Content.Server/Interfaces/IServerNotifyManager.cs b/Content.Server/Interfaces/IServerNotifyManager.cs new file mode 100644 index 0000000000..09afa47581 --- /dev/null +++ b/Content.Server/Interfaces/IServerNotifyManager.cs @@ -0,0 +1,9 @@ +using Content.Shared.Interfaces; + +namespace Content.Server.Interfaces +{ + public interface IServerNotifyManager : ISharedNotifyManager + { + void Initialize(); + } +} diff --git a/Content.Server/ServerNotifyManager.cs b/Content.Server/ServerNotifyManager.cs new file mode 100644 index 0000000000..9357e15685 --- /dev/null +++ b/Content.Server/ServerNotifyManager.cs @@ -0,0 +1,63 @@ +using Content.Server.Interfaces; +using Content.Shared; +using Content.Shared.Interfaces; +using SS14.Server.Interfaces.Console; +using SS14.Server.Interfaces.GameObjects; +using SS14.Server.Interfaces.Player; +using SS14.Shared.GameObjects; +using SS14.Shared.Interfaces.GameObjects; +using SS14.Shared.Interfaces.Network; +using SS14.Shared.IoC; +using SS14.Shared.Map; +using SS14.Shared.Utility; + +namespace Content.Server +{ + public class ServerNotifyManager : SharedNotifyManager, IServerNotifyManager + { +#pragma warning disable 649 + [Dependency] private IServerNetManager _netManager; +#pragma warning restore 649 + + private bool _initialized; + + public void Initialize() + { + DebugTools.Assert(!_initialized); + + _netManager.RegisterNetMessage(nameof(MsgDoNotify)); + _initialized = true; + } + + public override void PopupMessage(GridLocalCoordinates coordinates, IEntity viewer, string message) + { + if (!viewer.TryGetComponent(out IActorComponent actor)) + { + return; + } + + var netMessage = _netManager.CreateNetMessage(); + netMessage.Coordinates = coordinates; + netMessage.Message = message; + _netManager.ServerSendMessage(netMessage, actor.playerSession.ConnectedClient); + } + + public class PopupMsgCommand : IClientCommand + { + public string Command => "srvpopupmsg"; + public string Description => ""; + public string Help => ""; + + public void Execute(IConsoleShell shell, IPlayerSession player, string[] args) + { + var entityMgr = IoCManager.Resolve(); + + var source = EntityUid.Parse(args[0]); + var viewer = EntityUid.Parse(args[1]); + var msg = args[2]; + + entityMgr.GetEntity(source).PopupMessage(entityMgr.GetEntity(viewer), msg); + } + } + } +} diff --git a/Content.Shared/Content.Shared.csproj b/Content.Shared/Content.Shared.csproj index dd75ee68c1..d4b37d5a9c 100644 --- a/Content.Shared/Content.Shared.csproj +++ b/Content.Shared/Content.Shared.csproj @@ -72,6 +72,7 @@ + @@ -107,6 +108,7 @@ + diff --git a/Content.Shared/Interfaces/ISharedNotifyManager.cs b/Content.Shared/Interfaces/ISharedNotifyManager.cs new file mode 100644 index 0000000000..49f0ed5c14 --- /dev/null +++ b/Content.Shared/Interfaces/ISharedNotifyManager.cs @@ -0,0 +1,20 @@ +using SS14.Shared.Interfaces.GameObjects; +using SS14.Shared.IoC; +using SS14.Shared.Map; + +namespace Content.Shared.Interfaces +{ + public interface ISharedNotifyManager + { + void PopupMessage(IEntity source, IEntity viewer, string message); + void PopupMessage(GridLocalCoordinates coordinates, IEntity viewer, string message); + } + + public static class NotifyManagerExt + { + public static void PopupMessage(this IEntity source, IEntity viewer, string message) + { + IoCManager.Resolve().PopupMessage(source, viewer, message); + } + } +} diff --git a/Content.Shared/SharedNotifyManager.cs b/Content.Shared/SharedNotifyManager.cs new file mode 100644 index 0000000000..c588ed52cd --- /dev/null +++ b/Content.Shared/SharedNotifyManager.cs @@ -0,0 +1,48 @@ +using Content.Shared.Interfaces; +using Lidgren.Network; +using SS14.Shared.Interfaces.GameObjects; +using SS14.Shared.Interfaces.Network; +using SS14.Shared.Map; +using SS14.Shared.Network; +using SS14.Shared.Network.Messages; + +namespace Content.Shared +{ + public abstract class SharedNotifyManager : ISharedNotifyManager + { + public void PopupMessage(IEntity source, IEntity viewer, string message) + { + // TODO: we might eventually want for this to pass the actual entity, + // so the notify could track the entity movement visually. + PopupMessage(source.Transform.LocalPosition, viewer, message); + } + + public abstract void PopupMessage(GridLocalCoordinates coordinates, IEntity viewer, string message); + + protected class MsgDoNotify : NetMessage + { + #region REQUIRED + + public const MsgGroups GROUP = MsgGroups.Command; + public const string NAME = nameof(MsgDoNotify); + public MsgDoNotify(INetChannel channel) : base(NAME, GROUP) { } + + #endregion + + public string Message { get; set; } + public GridLocalCoordinates Coordinates; + + public override void ReadFromBuffer(NetIncomingMessage buffer) + { + Message = buffer.ReadString(); + Coordinates = buffer.ReadGridLocalCoordinates(); + } + + public override void WriteToBuffer(NetOutgoingMessage buffer) + { + buffer.Write(Message); + buffer.Write(Coordinates); + } + } + } +} diff --git a/engine b/engine index 69c0d409c8..153b57ed56 160000 --- a/engine +++ b/engine @@ -1 +1 @@ -Subproject commit 69c0d409c886b0a5c9824c5a7d3843ed8c5c5d0c +Subproject commit 153b57ed562cb43f85993a1adf57cafc68fcee36