Popup message notifications. (#125)
* Popup message system v1 * Networking for the popup notifications. Ship it.
This commit is contained in:
committed by
GitHub
parent
b0f212bad5
commit
f91488fa27
127
Content.Client/ClientNotifyManager.cs
Normal file
127
Content.Client/ClientNotifyManager.cs
Normal file
@@ -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<PopupLabel> _aliveLabels = new List<PopupLabel>();
|
||||
private bool _initialized;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
DebugTools.Assert(!_initialized);
|
||||
|
||||
_netManager.RegisterNetMessage<MsgDoNotify>(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<IClientNotifyManager>();
|
||||
mgr.PopupMessage(arg);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -74,8 +74,11 @@
|
||||
<Compile Include="GameObjects\Components\Power\ApcBoundUserInterface.cs" />
|
||||
<Compile Include="GameObjects\Components\Power\PowerCellVisualizer2D.cs" />
|
||||
<Compile Include="GameObjects\Components\Storage\ClientStorageComponent.cs" />
|
||||
<Compile Include="GameObjects\EntitySystems\ClientNotifySystem.cs" />
|
||||
<Compile Include="GameObjects\EntitySystems\VerbSystem.cs" />
|
||||
<Compile Include="Input\ContentContexts.cs" />
|
||||
<Compile Include="Interfaces\IClientNotifyManager.cs" />
|
||||
<Compile Include="ClientNotifyManager.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="GameObjects\Components\Items\ClientHandsComponent.cs" />
|
||||
<Compile Include="Interfaces\GameObjects\Components\Items\IHandsComponent.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<IClientNotifyManager, ClientNotifyManager>();
|
||||
IoCManager.Register<ISharedNotifyManager, ClientNotifyManager>();
|
||||
IoCManager.BuildGraph();
|
||||
}
|
||||
|
||||
public override void PostInit()
|
||||
@@ -81,6 +87,20 @@ namespace Content.Client
|
||||
// Setup key contexts
|
||||
var inputMan = IoCManager.Resolve<IInputManager>();
|
||||
ContentContexts.SetupContexts(inputMan.Contexts);
|
||||
|
||||
IoCManager.Resolve<IClientNotifyManager>().Initialize();
|
||||
}
|
||||
|
||||
public override void Update(AssemblyLoader.UpdateLevel level, float frameTime)
|
||||
{
|
||||
base.Update(level, frameTime);
|
||||
|
||||
switch (level)
|
||||
{
|
||||
case AssemblyLoader.UpdateLevel.FramePreEngine:
|
||||
IoCManager.Resolve<IClientNotifyManager>().FrameUpdate(new RenderFrameEventArgs(frameTime));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Content.Client.GameObjects.EntitySystems
|
||||
{
|
||||
public class ClientNotifySystem
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
14
Content.Client/Interfaces/IClientNotifyManager.cs
Normal file
14
Content.Client/Interfaces/IClientNotifyManager.cs
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user