From: Milon Date: Fri, 14 Feb 2025 14:35:27 +0000 (+0100) Subject: make chameleon verb predicted (#35156) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=498440d369480bd5c75293813b13cd8414bbb4cd;p=space-station-14.git make chameleon verb predicted (#35156) * ok but what if we just predicted EVERYTHING * cleanup --- diff --git a/Content.Server/Clothing/Systems/ChameleonClothingSystem.cs b/Content.Server/Clothing/Systems/ChameleonClothingSystem.cs index 3700aeb549..5c8954cc69 100644 --- a/Content.Server/Clothing/Systems/ChameleonClothingSystem.cs +++ b/Content.Server/Clothing/Systems/ChameleonClothingSystem.cs @@ -3,18 +3,13 @@ using Content.Shared.Clothing.Components; using Content.Shared.Clothing.EntitySystems; using Content.Shared.IdentityManagement.Components; using Content.Shared.Prototypes; -using Content.Shared.Verbs; -using Robust.Server.GameObjects; -using Robust.Shared.Player; using Robust.Shared.Prototypes; -using Robust.Shared.Utility; namespace Content.Server.Clothing.Systems; public sealed class ChameleonClothingSystem : SharedChameleonClothingSystem { [Dependency] private readonly IPrototypeManager _proto = default!; - [Dependency] private readonly UserInterfaceSystem _uiSystem = default!; [Dependency] private readonly IComponentFactory _factory = default!; [Dependency] private readonly IdentitySystem _identity = default!; @@ -22,7 +17,6 @@ public sealed class ChameleonClothingSystem : SharedChameleonClothingSystem { base.Initialize(); SubscribeLocalEvent(OnMapInit); - SubscribeLocalEvent>(OnVerb); SubscribeLocalEvent(OnSelected); } @@ -31,40 +25,18 @@ public sealed class ChameleonClothingSystem : SharedChameleonClothingSystem SetSelectedPrototype(uid, component.Default, true, component); } - private void OnVerb(EntityUid uid, ChameleonClothingComponent component, GetVerbsEvent args) - { - if (!args.CanAccess || !args.CanInteract || component.User != args.User) - return; - - args.Verbs.Add(new InteractionVerb() - { - Text = Loc.GetString("chameleon-component-verb-text"), - Icon = new SpriteSpecifier.Texture(new("/Textures/Interface/VerbIcons/settings.svg.192dpi.png")), - Act = () => TryOpenUi(uid, args.User, component) - }); - } - private void OnSelected(EntityUid uid, ChameleonClothingComponent component, ChameleonPrototypeSelectedMessage args) { SetSelectedPrototype(uid, args.SelectedId, component: component); } - private void TryOpenUi(EntityUid uid, EntityUid user, ChameleonClothingComponent? component = null) - { - if (!Resolve(uid, ref component)) - return; - if (!TryComp(user, out ActorComponent? actor)) - return; - _uiSystem.TryToggleUi(uid, ChameleonUiKey.Key, actor.PlayerSession); - } - private void UpdateUi(EntityUid uid, ChameleonClothingComponent? component = null) { if (!Resolve(uid, ref component)) return; var state = new ChameleonBoundUserInterfaceState(component.Slot, component.Default, component.RequireTag); - _uiSystem.SetUiState(uid, ChameleonUiKey.Key, state); + UI.SetUiState(uid, ChameleonUiKey.Key, state); } /// diff --git a/Content.Shared/Clothing/EntitySystems/SharedChameleonClothingSystem.cs b/Content.Shared/Clothing/EntitySystems/SharedChameleonClothingSystem.cs index 488b7a5b64..725b034766 100644 --- a/Content.Shared/Clothing/EntitySystems/SharedChameleonClothingSystem.cs +++ b/Content.Shared/Clothing/EntitySystems/SharedChameleonClothingSystem.cs @@ -5,8 +5,9 @@ using Content.Shared.Inventory; using Content.Shared.Inventory.Events; using Content.Shared.Item; using Content.Shared.Tag; +using Content.Shared.Verbs; using Robust.Shared.Prototypes; -using Robust.Shared.Serialization.Manager; +using Robust.Shared.Utility; namespace Content.Shared.Clothing.EntitySystems; @@ -14,19 +15,20 @@ public abstract class SharedChameleonClothingSystem : EntitySystem { [Dependency] private readonly IComponentFactory _factory = default!; [Dependency] private readonly IPrototypeManager _proto = default!; - [Dependency] private readonly ISerializationManager _serialization = default!; [Dependency] private readonly ClothingSystem _clothingSystem = default!; [Dependency] private readonly ContrabandSystem _contraband = default!; [Dependency] private readonly MetaDataSystem _metaData = default!; [Dependency] private readonly SharedItemSystem _itemSystem = default!; [Dependency] private readonly SharedAppearanceSystem _appearance = default!; [Dependency] private readonly TagSystem _tag = default!; + [Dependency] protected readonly SharedUserInterfaceSystem UI = default!; public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnGotEquipped); SubscribeLocalEvent(OnGotUnequipped); + SubscribeLocalEvent>(OnVerb); } private void OnGotEquipped(EntityUid uid, ChameleonClothingComponent component, GotEquippedEvent args) @@ -94,6 +96,22 @@ public abstract class SharedChameleonClothingSystem : EntitySystem } } + private void OnVerb(Entity ent, ref GetVerbsEvent args) + { + if (!args.CanAccess || !args.CanInteract || ent.Comp.User != args.User) + return; + + // Can't pass args from a ref event inside of lambdas + var user = args.User; + + args.Verbs.Add(new InteractionVerb() + { + Text = Loc.GetString("chameleon-component-verb-text"), + Icon = new SpriteSpecifier.Texture(new("/Textures/Interface/VerbIcons/settings.svg.192dpi.png")), + Act = () => UI.TryToggleUi(ent.Owner, ChameleonUiKey.Key, user) + }); + } + protected virtual void UpdateSprite(EntityUid uid, EntityPrototype proto) { } ///