* it works! kinda * so it works now * minor cleanup * central button now is useful too * more cleanup * minor cleanup * more cleanup * refactor: migrated code from toolbox (as it was rejected as too specific) * feat: moved border drawing for radial menu into RadialMenuTextureButton. Radial menu position setting into was moved to OverrideArrange to not being called on every frame * refactor: major reworks! * renamed DrawBagleSector to DrawAnnulusSector * Remove strange indexing * Regularize math * refactor: re-orienting segment elements to be Y-mirrored * refactor: extracted radial menu radius multiplier property, changed color pallet for radial menu button * refactor: removed icon backgrounds on textures used in current radial menu buttons with sectors, RadialContainer Radius renamed and now actually changed control radius. * refactor: in RadialMenuTextureButtonWithSector all sector colors are converted to and from sRGB in property getter-setters * refactor: renamed srgb to include Srgb suffix so devs gonna see that its srgb clearly * fix: enabled any functional keys pressed when pushing radial menu buttons * fix: radial menu sector now scales with UIScale * fix: accept only one event when clicking on radial menu ContextualButton * fix: now radial menu buttons accepts only click/alt-click, now clicks outside menu closes menu always * feat: simple radial menu prototype for easier creation * refactor: cleanup, restored emote filtering, button models now have class hierarchy * refactor: remove usage of closure from 'outside code' * refactor: remove non existing type from UiControlTest * refactor: remove unused using * refactor: revert ability to declare radial menu layers in xaml, scale 32px sprites using scale in radial menu * refactor: whitespaces * feat: now door remote have some kind of ui to switch mode * refactor: subscribe for dispose on existing radial menus * feat: now simple radial menu button models can have custom color for each sector background (and hover background color). Also added OpenOverMouseScreenPosition inside SimpleRadialMenu * fix: AI door menu now can be closed by verb if it gets unpowered * refactor: simplify code for DoorRemoteBoundUserInterface * fix open/close mode sprite * remove broken merge changes * refactor: changed DoorRemoteSystem to be fully in shared * refactor: localize DoorRemoteBoundUserInterface * refactor: fix multiple invocation for TryToggleDoor inside DoorRemoteSystem on prediction * refactor: extracted sprites and loc strings into prototype for cleaner code. Currently selected mode now have different background. * refactor: changed hover selected color to recommmended * refactor: reuse stylenano colors! * review * refactor: remove StyleNano reference * refactor: revert removal of item status for door remote * refactor: fix status control misprediction * refactor: remove invalid comments, rename client DoorRemoteSystem comp after handle method * refactor: fix DoorRemoteStatusControl not displaying status on entity pickup --------- Co-authored-by: pa.pecherskij <pa.pecherskij@interfax.ru> Co-authored-by: Eoin Mcloughlin <helloworld@eoinrul.es> Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
135 lines
5.6 KiB
C#
135 lines
5.6 KiB
C#
using Content.Shared.Access.Components;
|
|
using Content.Shared.Administration.Logs;
|
|
using Content.Shared.Database;
|
|
using Content.Shared.Doors.Components;
|
|
using Content.Shared.Doors.Systems;
|
|
using Content.Shared.Examine;
|
|
using Content.Shared.Interaction;
|
|
using Content.Shared.Popups;
|
|
using Content.Shared.Power.EntitySystems;
|
|
using Content.Shared.Remotes.Components;
|
|
using Robust.Shared.Serialization;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Content.Shared.Remotes.EntitySystems;
|
|
|
|
public abstract class SharedDoorRemoteSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly SharedAirlockSystem _airlock = default!;
|
|
[Dependency] private readonly SharedDoorSystem _doorSystem = default!;
|
|
[Dependency] private readonly ExamineSystemShared _examine = default!;
|
|
[Dependency] private readonly SharedPowerReceiverSystem _powerReceiver = default!;
|
|
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
|
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
|
|
[Dependency] protected readonly IGameTiming Timing = default!;
|
|
|
|
|
|
public override void Initialize()
|
|
{
|
|
SubscribeLocalEvent<DoorRemoteComponent, DoorRemoteModeChangeMessage>(OnDoorRemoteModeChange);
|
|
SubscribeLocalEvent<DoorRemoteComponent, BeforeRangedInteractEvent>(OnBeforeInteract);
|
|
}
|
|
|
|
private void OnDoorRemoteModeChange(Entity<DoorRemoteComponent> ent, ref DoorRemoteModeChangeMessage args)
|
|
{
|
|
ent.Comp.Mode = args.Mode;
|
|
Dirty(ent);
|
|
}
|
|
|
|
private void OnBeforeInteract(Entity<DoorRemoteComponent> entity, ref BeforeRangedInteractEvent args)
|
|
{
|
|
if (!Timing.IsFirstTimePredicted)
|
|
return;
|
|
|
|
var isAirlock = TryComp<AirlockComponent>(args.Target, out var airlockComp);
|
|
|
|
if (args.Handled
|
|
|| args.Target == null
|
|
|| !TryComp<DoorComponent>(args.Target, out var doorComp) // If it isn't a door we don't use it
|
|
// Only able to control doors if they are within your vision and within your max range.
|
|
// Not affected by mobs or machines anymore.
|
|
|| !_examine.InRangeUnOccluded(args.User,
|
|
args.Target.Value,
|
|
SharedInteractionSystem.MaxRaycastRange,
|
|
null))
|
|
|
|
{
|
|
return;
|
|
}
|
|
|
|
args.Handled = true;
|
|
|
|
if (!_powerReceiver.IsPowered(args.Target.Value))
|
|
{
|
|
_popup.PopupClient(Loc.GetString("door-remote-no-power"), args.User, args.User);
|
|
return;
|
|
}
|
|
|
|
var accessTarget = args.Used;
|
|
// This covers the accesses the REMOTE has, and is not effected by the user's ID card.
|
|
if (entity.Comp.IncludeUserAccess) // Allows some door remotes to inherit the user's access.
|
|
{
|
|
accessTarget = args.User;
|
|
// This covers the accesses the USER has, which always includes the remote's access since holding a remote acts like holding an ID card.
|
|
}
|
|
|
|
if (TryComp<AccessReaderComponent>(args.Target, out var accessComponent)
|
|
&& !_doorSystem.HasAccess(args.Target.Value, accessTarget, doorComp, accessComponent))
|
|
{
|
|
if (isAirlock)
|
|
_doorSystem.Deny(args.Target.Value, doorComp, user: args.User, predicted: true);
|
|
|
|
_popup.PopupClient(Loc.GetString("door-remote-denied"), args.User, args.User);
|
|
return;
|
|
}
|
|
|
|
switch (entity.Comp.Mode)
|
|
{
|
|
case OperatingMode.OpenClose:
|
|
if (_doorSystem.TryToggleDoor(args.Target.Value, doorComp, user: args.User, predicted: true))
|
|
_adminLogger.Add(LogType.Action,
|
|
LogImpact.Medium,
|
|
$"{ToPrettyString(args.User):player} used {ToPrettyString(args.Used)} on {ToPrettyString(args.Target.Value)}: {doorComp.State}");
|
|
break;
|
|
case OperatingMode.ToggleBolts:
|
|
if (TryComp<DoorBoltComponent>(args.Target, out var boltsComp))
|
|
{
|
|
if (!boltsComp.BoltWireCut)
|
|
{
|
|
_doorSystem.SetBoltsDown((args.Target.Value, boltsComp), !boltsComp.BoltsDown, user: args.User, predicted: true);
|
|
_adminLogger.Add(LogType.Action,
|
|
LogImpact.Medium,
|
|
$"{ToPrettyString(args.User):player} used {ToPrettyString(args.Used)} on {ToPrettyString(args.Target.Value)} to {(boltsComp.BoltsDown ? "" : "un")}bolt it");
|
|
}
|
|
}
|
|
|
|
break;
|
|
case OperatingMode.ToggleEmergencyAccess:
|
|
if (airlockComp != null)
|
|
{
|
|
_airlock.SetEmergencyAccess((args.Target.Value, airlockComp), !airlockComp.EmergencyAccess, user: args.User, predicted: true);
|
|
_adminLogger.Add(LogType.Action,
|
|
LogImpact.Medium,
|
|
$"{ToPrettyString(args.User):player} used {ToPrettyString(args.Used)} on {ToPrettyString(args.Target.Value)} to set emergency access {(airlockComp.EmergencyAccess ? "on" : "off")}");
|
|
}
|
|
|
|
break;
|
|
default:
|
|
throw new InvalidOperationException(
|
|
$"{nameof(DoorRemoteComponent)} had invalid mode {entity.Comp.Mode}");
|
|
}
|
|
}
|
|
}
|
|
|
|
[Serializable, NetSerializable]
|
|
public sealed class DoorRemoteModeChangeMessage : BoundUserInterfaceMessage
|
|
{
|
|
public OperatingMode Mode;
|
|
}
|
|
|
|
[Serializable, NetSerializable]
|
|
public enum DoorRemoteUiKey : byte
|
|
{
|
|
Key
|
|
}
|