committed by
GitHub
parent
e4676395c0
commit
c283634efb
@@ -92,6 +92,7 @@
|
||||
<Compile Include="GameObjects\Components\Weapons\Ranged\ClientRangedWeaponComponent.cs" />
|
||||
<Compile Include="GameObjects\EntitySystems\CameraRecoilSystem.cs" />
|
||||
<Compile Include="GameObjects\EntitySystems\ClientNotifySystem.cs" />
|
||||
<Compile Include="GameObjects\EntitySystems\ExamineSystem.cs" />
|
||||
<Compile Include="GameObjects\EntitySystems\IconSmoothSystem.cs" />
|
||||
<Compile Include="GameObjects\EntitySystems\RangedWeaponSystem.cs" />
|
||||
<Compile Include="GameObjects\EntitySystems\SubFloorHideSystem.cs" />
|
||||
|
||||
139
Content.Client/GameObjects/EntitySystems/ExamineSystem.cs
Normal file
139
Content.Client/GameObjects/EntitySystems/ExamineSystem.cs
Normal file
@@ -0,0 +1,139 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Shared.GameObjects.EntitySystemMessages;
|
||||
using Content.Shared.Input;
|
||||
using JetBrains.Annotations;
|
||||
using SS14.Client.GameObjects.EntitySystems;
|
||||
using SS14.Client.Interfaces.GameObjects.Components;
|
||||
using SS14.Client.Interfaces.Input;
|
||||
using SS14.Client.Interfaces.UserInterface;
|
||||
using SS14.Client.UserInterface;
|
||||
using SS14.Client.UserInterface.Controls;
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.GameObjects.Systems;
|
||||
using SS14.Shared.Input;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
using SS14.Shared.IoC;
|
||||
using SS14.Shared.Map;
|
||||
using SS14.Shared.Maths;
|
||||
using SS14.Shared.Players;
|
||||
|
||||
namespace Content.Client.GameObjects.EntitySystems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
internal sealed class ExamineSystem : EntitySystem
|
||||
{
|
||||
public const string StyleClassEntityTooltip = "entity-tooltip";
|
||||
|
||||
#pragma warning disable 649
|
||||
[Dependency] private IInputManager _inputManager;
|
||||
[Dependency] private IUserInterfaceManager _userInterfaceManager;
|
||||
[Dependency] private IEntityManager _entityManager;
|
||||
#pragma warning restore 649
|
||||
|
||||
private Popup _examineTooltipOpen;
|
||||
private CancellationTokenSource _requestCancelTokenSource;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
var inputSys = EntitySystemManager.GetEntitySystem<InputSystem>();
|
||||
inputSys.BindMap.BindFunction(ContentKeyFunctions.ExamineEntity, new PointerInputCmdHandler(HandleExamine));
|
||||
}
|
||||
|
||||
public override void RegisterMessageTypes()
|
||||
{
|
||||
base.RegisterMessageTypes();
|
||||
|
||||
RegisterMessageType<ExamineSystemMessages.ExamineInfoResponseMessage>();
|
||||
}
|
||||
|
||||
private void HandleExamine(ICommonSession session, GridCoordinates coords, EntityUid uid)
|
||||
{
|
||||
if (!uid.IsValid() || !_entityManager.TryGetEntity(uid, out var entity))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DoExamine(entity);
|
||||
}
|
||||
|
||||
public async void DoExamine(IEntity entity)
|
||||
{
|
||||
CloseTooltip();
|
||||
|
||||
var mousePos = _inputManager.MouseScreenPosition;
|
||||
|
||||
// Actually open the tooltip.
|
||||
_examineTooltipOpen = new Popup();
|
||||
_userInterfaceManager.StateRoot.AddChild(_examineTooltipOpen);
|
||||
var panel = new PanelContainer();
|
||||
panel.AddStyleClass(StyleClassEntityTooltip);
|
||||
_examineTooltipOpen.AddChild(panel);
|
||||
panel.SetAnchorAndMarginPreset(Control.LayoutPreset.Wide);
|
||||
var vBox = new VBoxContainer();
|
||||
panel.AddChild(vBox);
|
||||
var hBox = new HBoxContainer { SeparationOverride = 5};
|
||||
vBox.AddChild(hBox);
|
||||
if (entity.TryGetComponent(out ISpriteComponent sprite))
|
||||
{
|
||||
hBox.AddChild(new SpriteView {Sprite = sprite});
|
||||
}
|
||||
|
||||
hBox.AddChild(new Label
|
||||
{
|
||||
Text = entity.Name,
|
||||
SizeFlagsHorizontal = Control.SizeFlags.FillExpand,
|
||||
});
|
||||
|
||||
const float minWidth = 300;
|
||||
var size = Vector2.ComponentMax((minWidth, 0), panel.CombinedMinimumSize);
|
||||
_examineTooltipOpen.Open(UIBox2.FromDimensions(mousePos, size));
|
||||
|
||||
if (entity.Uid.IsClientSide())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Ask server for extra examine info.
|
||||
RaiseNetworkEvent(new ExamineSystemMessages.RequestExamineInfoMessage(entity.Uid));
|
||||
|
||||
ExamineSystemMessages.ExamineInfoResponseMessage response;
|
||||
try
|
||||
{
|
||||
_requestCancelTokenSource = new CancellationTokenSource();
|
||||
response =
|
||||
await AwaitNetMessage<ExamineSystemMessages.ExamineInfoResponseMessage>(_requestCancelTokenSource
|
||||
.Token);
|
||||
}
|
||||
catch (TaskCanceledException)
|
||||
{
|
||||
return;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_requestCancelTokenSource = null;
|
||||
}
|
||||
|
||||
var richLabel = new RichTextLabel();
|
||||
richLabel.SetMessage(response.Message);
|
||||
vBox.AddChild(richLabel);
|
||||
}
|
||||
|
||||
public void CloseTooltip()
|
||||
{
|
||||
if (_examineTooltipOpen != null)
|
||||
{
|
||||
_examineTooltipOpen.Dispose();
|
||||
_examineTooltipOpen = null;
|
||||
}
|
||||
|
||||
if (_requestCancelTokenSource != null)
|
||||
{
|
||||
_requestCancelTokenSource.Cancel();
|
||||
_requestCancelTokenSource = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using Content.Client.GameObjects.EntitySystems;
|
||||
using Content.Client.Utility;
|
||||
using SS14.Client.Graphics.Drawing;
|
||||
using SS14.Client.Interfaces.ResourceManagement;
|
||||
@@ -131,6 +132,15 @@ namespace Content.Client.UserInterface
|
||||
var checkBoxTextureChecked = resCache.GetTexture("/Nano/checkbox_checked.svg.96dpi.png");
|
||||
var checkBoxTextureUnchecked = resCache.GetTexture("/Nano/checkbox_unchecked.svg.96dpi.png");
|
||||
|
||||
// Tooltip box
|
||||
var tooltipTexture = resCache.GetTexture("/Nano/tooltip.png");
|
||||
var tooltipBox = new StyleBoxTexture
|
||||
{
|
||||
Texture = tooltipTexture,
|
||||
};
|
||||
tooltipBox.SetPatchMargin(StyleBox.Margin.All, 2);
|
||||
tooltipBox.SetContentMarginOverride(StyleBox.Margin.Horizontal, 5);
|
||||
|
||||
Stylesheet = new Stylesheet(new[]
|
||||
{
|
||||
// Default font.
|
||||
@@ -337,7 +347,13 @@ namespace Content.Client.UserInterface
|
||||
// Tooltip
|
||||
new StyleRule(new SelectorElement(typeof(Tooltip), null, null, null), new []
|
||||
{
|
||||
new StyleProperty(PanelContainer.StylePropertyPanel, new StyleBoxFlat { BackgroundColor = new Color(21, 21, 26)})
|
||||
new StyleProperty(PanelContainer.StylePropertyPanel, tooltipBox)
|
||||
}),
|
||||
|
||||
// Entity tooltip
|
||||
new StyleRule(new SelectorElement(typeof(PanelContainer), new []{ExamineSystem.StyleClassEntityTooltip}, null, null), new []
|
||||
{
|
||||
new StyleProperty(PanelContainer.StylePropertyPanel, tooltipBox)
|
||||
}),
|
||||
|
||||
// ItemList
|
||||
|
||||
Reference in New Issue
Block a user