Files
tbd-station-14/Content.Server/PowerCell/Components/PowerCellSlotComponent.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

217 lines
8.5 KiB
C#

using System;
using Content.Server.Hands.Components;
using Content.Server.Items;
using Content.Shared.Audio;
using Content.Shared.Examine;
using Content.Shared.Sound;
using Robust.Shared.Audio;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
using Robust.Shared.Player;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
namespace Content.Server.PowerCell.Components
{
/// <summary>
/// Provides a "battery compartment" that can contain a <see cref="PowerCellComponent"/> of the matching
/// <see cref="PowerCellSize"/>. Intended to supplement other components, not very useful by itself.
/// </summary>
[RegisterComponent]
public class PowerCellSlotComponent : Component, IExamine, IMapInit
{
public override string Name => "PowerCellSlot";
/// <summary>
/// What size of cell fits into this component.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("slotSize")]
public PowerCellSize SlotSize { get; set; } = PowerCellSize.Small;
/// <summary>
/// Can the cell be removed ?
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("canRemoveCell")]
public bool CanRemoveCell { get; set; } = true;
/// <summary>
/// Should the "Remove cell" verb be displayed on this component?
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("showVerb")]
public bool ShowVerb { get; set; } = true;
/// <summary>
/// String passed to <see><cref>String.Format</cref></see> when showing the description text for this item.
/// String.Format is given a single parameter which is the size letter (S/M/L) of the cells this component uses.
/// Use null to show no text.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("descFormatString")]
public string? DescFormatString { get; set; } = "It uses size {0} power cells.";
/// <summary>
/// File path to a sound file that should be played when the cell is removed.
/// </summary>
/// <example>"/Audio/Items/pistol_magout.ogg"</example>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("cellRemoveSound")]
public SoundSpecifier CellRemoveSound { get; set; } = new SoundPathSpecifier("/Audio/Items/pistol_magin.ogg");
/// <summary>
/// File path to a sound file that should be played when a cell is inserted.
/// </summary>
/// <example>"/Audio/Items/pistol_magin.ogg"</example>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("cellInsertSound")]
public SoundSpecifier CellInsertSound { get; set; } = new SoundPathSpecifier("/Audio/Items/pistol_magout.ogg");
[ViewVariables] private ContainerSlot _cellContainer = default!;
[ViewVariables]
public PowerCellComponent? Cell
{
get
{
if (_cellContainer.ContainedEntity == null) return null;
return _cellContainer.ContainedEntity.TryGetComponent(out PowerCellComponent? cell) ? cell : null;
}
}
[ViewVariables] public bool HasCell => Cell != null;
/// <summary>
/// True if we don't want a cell inserted during map init.
/// </summary>
[DataField("startEmpty")]
private bool _startEmpty = false;
/// <summary>
/// If not null, this cell type will be inserted at MapInit instead of the default Standard cell.
/// </summary>
[DataField("startingCellType")]
private string? _startingCellType = null;
protected override void Initialize()
{
base.Initialize();
_cellContainer = ContainerHelpers.EnsureContainer<ContainerSlot>(Owner, "cellslot_cell_container", out _);
}
void IExamine.Examine(FormattedMessage message, bool inDetailsRange)
{
if (!inDetailsRange) return;
string sizeLetter = SlotSize switch
{
PowerCellSize.Small => Loc.GetString("power-cell-slot-component-small-size-shorthand"),
PowerCellSize.Medium => Loc.GetString("power-cell-slot-component-medium-size-shorthand"),
PowerCellSize.Large => Loc.GetString("power-cell-slot-component-large-size-shorthand"),
_ => "???"
};
if (DescFormatString != null) message.AddMarkup(string.Format(DescFormatString, sizeLetter));
}
/// <summary>
/// Remove the cell from this component. If a user is specified, the cell will be put in their hands
/// or failing that, at their feet. If no user is specified the cell will be put at the location of
/// the parent of this component.
/// </summary>
/// <param name="user">(optional) the user to give the removed cell to.</param>
/// <param name="playSound">Should <see cref="CellRemoveSound"/> be played upon removal?</param>
/// <returns>The cell component of the entity that was removed, or null if removal failed.</returns>
public PowerCellComponent? EjectCell(IEntity? user, bool playSound = true)
{
var cell = Cell;
if (cell == null || !CanRemoveCell) return null;
if (!_cellContainer.Remove(cell.Owner)) return null;
//Dirty();
if (user != null)
{
if (!user.TryGetComponent(out HandsComponent? hands) || !hands.PutInHand(cell.Owner.GetComponent<ItemComponent>()))
{
cell.Owner.Transform.Coordinates = user.Transform.Coordinates;
}
}
else
{
cell.Owner.Transform.Coordinates = Owner.Transform.Coordinates;
}
if (playSound)
{
SoundSystem.Play(Filter.Pvs(Owner), CellRemoveSound.GetSound(), Owner, AudioHelpers.WithVariation(0.125f));
}
Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, new PowerCellChangedEvent(true), false);
return cell;
}
/// <summary>
/// Tries to insert the given cell into this component. The cell will be put into the container of this component.
/// </summary>
/// <param name="cell">The cell to insert.</param>
/// <param name="playSound">Should <see cref="CellInsertSound"/> be played upon insertion?</param>
/// <returns>True if insertion succeeded; false otherwise.</returns>
public bool InsertCell(IEntity cell, bool playSound = true)
{
if (Cell != null) return false;
if (!cell.TryGetComponent<ItemComponent>(out var _)) return false;
if (!cell.TryGetComponent<PowerCellComponent>(out var cellComponent)) return false;
if (cellComponent.CellSize != SlotSize) return false;
if (!_cellContainer.Insert(cell)) return false;
//Dirty();
if (playSound)
{
SoundSystem.Play(Filter.Pvs(Owner), CellInsertSound.GetSound(), Owner, AudioHelpers.WithVariation(0.125f));
}
Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, new PowerCellChangedEvent(false), false);
return true;
}
void IMapInit.MapInit()
{
if (_startEmpty || _cellContainer.ContainedEntity != null)
{
return;
}
string type;
if (_startingCellType != null)
{
type = _startingCellType;
}
else
{
type = SlotSize switch
{
PowerCellSize.Small => "PowerCellSmallStandard",
PowerCellSize.Medium => "PowerCellMediumStandard",
PowerCellSize.Large => "PowerCellLargeStandard",
_ => throw new ArgumentOutOfRangeException()
};
}
var cell = Owner.EntityManager.SpawnEntity(type, Owner.Transform.Coordinates);
_cellContainer.Insert(cell);
}
}
public class PowerCellChangedEvent : EntityEventArgs
{
/// <summary>
/// If true, the cell was ejected; if false, it was inserted.
/// </summary>
public bool Ejected { get; }
public PowerCellChangedEvent(bool ejected)
{
Ejected = ejected;
}
}
}