Files
tbd-station-14/Content.Server/PDA/PDAComponent.cs
Alex Evgrashin e5df8dbee3 Moving PDA to ECS (#4538)
* Moved pen slot to separate component

* Moved it all to more generic item slot class

* Add sounds

* Item slots now supports many slots

* Some clean-up

* Refactored slots a bit

* Moving ID card out

* Moving pda to system

* Moving PDA owner to ECS

* Moved PDA flashlight to separate component

* Toggle lights work through events

* Fixing UI

* Moving uplink to separate component

* Continue moving uplink to separate component

* More cleaning

* Removing pda shared

* Nuked shared pda component

* Fixed flashlight

* Pen slot now showed in UI

* Light toggle now shows correctly in UI

* Small refactoring of item slots

* Added contained entity

* Fixed tests

* Finished with PDA

* Moving PDA uplink to separate window

* Adding-removing uplink should show new button

* Working on a better debug

* Debug command to add uplink

* Uplink send state to UI

* Almost working UI

* Uplink correcty updates when you buy-sell items

* Ups

* Moved localization to separate file

* Minor fixes

* Removed item slots methods events

* Removed PDA owner name

* Removed one uplink event

* Deleted all uplink events

* Removed flashlight events

* Update Content.Shared/Traitor/Uplink/UplinkVisuals.cs

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>

* Update Content.Server/Containers/ItemSlot/ItemSlotsSystem.cs

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>

* Update Content.Server/Containers/ItemSlot/ItemSlotsSystem.cs

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>

* Update Content.Server/GameTicking/Presets/PresetTraitorDeathMatch.cs

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>

* Item slots system review

* Flashlight review

* PDA to XAML

* Move UplinkMenu to seperate class, fix WeightedColors methods

* Move UI to XAML

* Moved events to entity id

* Address review

* Removed uplink extensions

* Minor fix

* Moved item slots to shared

* My bad Robust...

* Fixed pda sound

* Fixed pda tests

* Fixed pda test again

Co-authored-by: Alexander Evgrashin <evgrashin.adl@gmail.com>
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Co-authored-by: Visne <vincefvanwijk@gmail.com>
2021-10-03 15:05:52 +11:00

128 lines
4.5 KiB
C#

using System;
using System.Collections.Generic;
using Content.Server.Access.Components;
using Content.Shared.Containers.ItemSlots;
using Content.Shared.ActionBlocker;
using Content.Shared.PDA;
using Content.Shared.Verbs;
using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
namespace Content.Server.PDA
{
[RegisterComponent]
[ComponentReference(typeof(IAccess))]
public class PDAComponent : Component, IAccess
{
public override string Name => "PDA";
public const string IDSlotName = "pda_id_slot";
public const string PenSlotName = "pda_pen_slot";
[ViewVariables] [DataField("idCard")] public string? StartingIdCard;
[ViewVariables] public IdCardComponent? ContainedID;
[ViewVariables] public bool PenInserted;
[ViewVariables] public bool FlashlightOn;
[ViewVariables] public string? OwnerName;
// TODO: Move me to ECS after Access refactoring
#region Acces Logic
[ViewVariables] private readonly PDAAccessSet _accessSet;
public PDAComponent()
{
_accessSet = new PDAAccessSet(this);
}
public ISet<string>? GetContainedAccess()
{
return ContainedID?.Owner?.GetComponent<AccessComponent>()?.Tags;
}
ISet<string> IAccess.Tags => _accessSet;
bool IAccess.IsReadOnly => true;
void IAccess.SetTags(IEnumerable<string> newTags)
{
throw new NotSupportedException("PDA access list is read-only.");
}
#endregion
// TODO: replace me with dynamic verbs for ItemSlotsSystem
#region Verbs
[Verb]
public sealed class EjectPenVerb : Verb<PDAComponent>
{
protected override void GetData(IEntity user, PDAComponent component, VerbData data)
{
data.Visibility = VerbVisibility.Invisible;
if (!component.Owner.TryGetComponent(out SharedItemSlotsComponent? slots))
return;
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(user))
return;
var item = EntitySystem.Get<SharedItemSlotsSystem>().PeekItemInSlot(slots, PenSlotName);
if (item == null)
return;
data.Visibility = VerbVisibility.Visible;
data.Text = Loc.GetString("eject-item-verb-text-default", ("item", item.Name));
data.IconTexture = "/Textures/Interface/VerbIcons/eject.svg.192dpi.png";
}
protected override void Activate(IEntity user, PDAComponent pda)
{
var entityManager = pda.Owner.EntityManager;
if (pda.Owner.TryGetComponent(out SharedItemSlotsComponent? itemSlots))
{
entityManager.EntitySysManager.GetEntitySystem<SharedItemSlotsSystem>().
TryEjectContent(itemSlots, PenSlotName, user);
}
}
}
[Verb]
public sealed class EjectIDVerb : Verb<PDAComponent>
{
public override bool AlternativeInteraction => true;
protected override void GetData(IEntity user, PDAComponent component, VerbData data)
{
data.Visibility = VerbVisibility.Invisible;
if (!component.Owner.TryGetComponent(out SharedItemSlotsComponent? slots))
return;
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(user))
return;
var item = EntitySystem.Get<SharedItemSlotsSystem>().PeekItemInSlot(slots, IDSlotName);
if (item == null)
return;
data.Visibility = VerbVisibility.Visible;
data.Text = Loc.GetString("eject-item-verb-text-default", ("item", item.Name));
data.IconTexture = "/Textures/Interface/VerbIcons/eject.svg.192dpi.png";
}
protected override void Activate(IEntity user, PDAComponent pda)
{
var entityManager = pda.Owner.EntityManager;
if (pda.Owner.TryGetComponent(out SharedItemSlotsComponent? itemSlots))
{
entityManager.EntitySysManager.GetEntitySystem<SharedItemSlotsSystem>().
TryEjectContent(itemSlots, IDSlotName, user);
}
}
}
#endregion
}
}