Files
tbd-station-14/Content.Client/Examine/ExamineSystem.cs
Leon Friedrich 6cb58e608b ECS verbs and update context menu (#4594)
* Functioning ECS verbs

Currently only ID card console works.

* Changed verb types and allow ID card insertions

* Verb GUI sorting and verb networking

* More networking, and shared components

* Clientside verbs work now.

* Verb enums changed to bitmask flags

* Verb Categories redo

* Fix range check

* GasTank Verb

* Remove unnecessary bodypart verb

* Buckle Verb

* buckle & unbuckle verbs

* Updated range checks

* Item cabinet verbs

* Add range user override

* construction verb

* Chemistry machine verbs

* Climb Verb

* Generalise pulled entity verbs

* ViewVariables Verb

* rejuvenate, delete, sentient, control verbs

* Outfit verb

* inrangeunoccluded and tubedirection verbs

* attach-to verbs

* remove unused verbs and move VV

* Rename DebugVerbSystem

* Ghost role and pointing verbs

* Remove global verbs

* Allow verbs to raise events

* Changing categories and simplifying debug verbs

* Add rotate and flip verbs

* fix rejuvenate test

* redo context menu

* new Add Gas debug verb

* Add Set Temperature debug verb

* Uncuff verb

* Disposal unit verbs

* Add pickup verb

* lock/unlock verb

* Remove verb type, add specific verb events

* rename verb messages -> events

* Context menu displays verbs by interaction type

* Updated context menu HandleMove

previously, checked if entities moved 1 tile from click location.

Now checks if entities moved out of view.

Now you can actually right-click interact with yourself while walking!

* Misc Verb menu GUI changes

* Fix non-human/ghost verbs

* Update types and categories

* Allow non-ghost/human to open context menu

* configuration verb

* tagger verb

* Morgue Verbs

* Medical Scanner Verbs

* Fix solution refactor merge issues

* Fix context menu in-view check

* Remove prepare GUI

* Redo verb restrictions

* Fix context menu UI

* Disposal Verbs

* Spill verb

* Light verb

* Hand Held light verb

* power cell verbs

* storage verbs

and adding names to insert/eject

* Pulling verb

* Close context menu on verb execution

* Strip verb

* AmmoBox verb

* fix pull verb

* gun barrel verbs

revolver verb
energy weapon verbs
Bolt action verb

* Magazine gun barrel  verbs

* Add charger verbs

* PDA verbs

* Transfer amount verb

* Add reagent verb

* make alt-click use ECS verbs

* Delete old verb files

* Magboot verb

* finalising tweaks

* context menu visibility changes

* code cleanup

* Update AdminAddReagentUI.cs

* Remove HasFlag

* Consistent verb keys

* Remove Linq, add comment

* Fix in-inventory check

* Update GUI text alignment and padding

* Added close-menu option

* Changed some "interaction" verbs to "activation"

* Remove verb keys, use sorted sets

* fix master merge

* update some verb text

* Undo Changes

Remove some new verbs that can be added later

undid some .ftl bugfixes, can and should be done separately

* fix merge

* Undo file rename

* fix merge

* Misc Cleanup

* remove contraction

* Fix keybinding issue

* fix comment

* merge fix

* fix merge

* fix merge

* fix merge

* fix merge

* fix open-close verbs

* adjust uncuff verb

* fix merge

and undo the renaming of SharedPullableComponent to PullableComponent. I'm tired of all of those merge conflicts
2021-10-04 20:29:03 -07:00

206 lines
6.7 KiB
C#

using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Content.Shared.Examine;
using Content.Shared.Input;
using Content.Shared.Verbs;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Client.Player;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.Input.Binding;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Players;
using Robust.Shared.Utility;
using static Content.Shared.Interaction.SharedInteractionSystem;
using static Robust.Client.UserInterface.Controls.BoxContainer;
namespace Content.Client.Examine
{
[UsedImplicitly]
internal sealed class ExamineSystem : ExamineSystemShared
{
[Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
public const string StyleClassEntityTooltip = "entity-tooltip";
private IEntity? _examinedEntity;
private IEntity? _playerEntity;
private Popup? _examineTooltipOpen;
private CancellationTokenSource? _requestCancelTokenSource;
public override void Initialize()
{
IoCManager.InjectDependencies(this);
SubscribeLocalEvent<GetOtherVerbsEvent>(AddExamineVerb);
CommandBinds.Builder
.Bind(ContentKeyFunctions.ExamineEntity, new PointerInputCmdHandler(HandleExamine))
.Register<ExamineSystem>();
}
public override void Update(float frameTime)
{
if (_examineTooltipOpen == null || !_examineTooltipOpen.Visible) return;
if (_examinedEntity == null || _playerEntity == null) return;
Ignored predicate = entity => entity == _playerEntity || entity == _examinedEntity;
if (_playerEntity.TryGetContainer(out var container))
{
predicate += entity => entity == container.Owner;
}
if (!InRangeUnOccluded(_playerEntity, _examinedEntity, ExamineRange, predicate))
{
CloseTooltip();
}
}
public override void Shutdown()
{
CommandBinds.Unregister<ExamineSystem>();
base.Shutdown();
}
private bool HandleExamine(ICommonSession? session, EntityCoordinates coords, EntityUid uid)
{
if (!uid.IsValid() || !EntityManager.TryGetEntity(uid, out _examinedEntity))
{
return false;
}
_playerEntity = _playerManager.LocalPlayer?.ControlledEntity;
if (_playerEntity == null || !CanExamine(_playerEntity, _examinedEntity))
{
return false;
}
DoExamine(_examinedEntity);
return true;
}
private void AddExamineVerb(GetOtherVerbsEvent args)
{
if (!CanExamine(args.User, args.Target))
return;
Verb verb = new();
verb.Act = () => DoExamine(args.Target) ;
verb.Text = Loc.GetString("examine-verb-name");
verb.IconTexture = "/Textures/Interface/VerbIcons/examine.svg.192dpi.png";
args.Verbs.Add(verb);
}
public async void DoExamine(IEntity entity)
{
// Close any examine tooltip that might already be opened
CloseTooltip();
const float minWidth = 300;
var popupPos = _userInterfaceManager.MousePositionScaled;
// Actually open the tooltip.
_examineTooltipOpen = new Popup { MaxWidth = 400 };
_userInterfaceManager.ModalRoot.AddChild(_examineTooltipOpen);
var panel = new PanelContainer();
panel.AddStyleClass(StyleClassEntityTooltip);
panel.ModulateSelfOverride = Color.LightGray.WithAlpha(0.90f);
_examineTooltipOpen.AddChild(panel);
var vBox = new BoxContainer
{
Orientation = LayoutOrientation.Vertical
};
panel.AddChild(vBox);
var hBox = new BoxContainer
{
Orientation = LayoutOrientation.Horizontal,
SeparationOverride = 5
};
vBox.AddChild(hBox);
if (entity.TryGetComponent(out ISpriteComponent? sprite))
{
hBox.AddChild(new SpriteView { Sprite = sprite, OverrideDirection = Direction.South });
}
hBox.AddChild(new Label
{
Text = entity.Name,
HorizontalExpand = true,
});
panel.Measure(Vector2.Infinity);
var size = Vector2.ComponentMax((minWidth, 0), panel.DesiredSize);
_examineTooltipOpen.Open(UIBox2.FromDimensions(popupPos.Position, size));
FormattedMessage message;
if (entity.Uid.IsClientSide())
{
message = GetExamineText(entity, _playerManager.LocalPlayer?.ControlledEntity);
}
else
{
// Ask server for extra examine info.
RaiseNetworkEvent(new ExamineSystemMessages.RequestExamineInfoMessage(entity.Uid));
ExamineSystemMessages.ExamineInfoResponseMessage response;
try
{
_requestCancelTokenSource = new CancellationTokenSource();
response =
await AwaitNetworkEvent<ExamineSystemMessages.ExamineInfoResponseMessage>(_requestCancelTokenSource
.Token);
}
catch (TaskCanceledException)
{
return;
}
finally
{
_requestCancelTokenSource = null;
}
message = response.Message;
}
foreach (var msg in message.Tags.OfType<FormattedMessage.TagText>())
{
if (string.IsNullOrWhiteSpace(msg.Text)) continue;
var richLabel = new RichTextLabel();
richLabel.SetMessage(message);
vBox.AddChild(richLabel);
break;
}
}
private void CloseTooltip()
{
if (_examineTooltipOpen != null)
{
_examineTooltipOpen.Dispose();
_examineTooltipOpen = null;
}
if (_requestCancelTokenSource != null)
{
_requestCancelTokenSource.Cancel();
_requestCancelTokenSource = null;
}
}
}
}