diff --git a/Content.Client/_Sunrise/UserInterface/Controls/SunriseSpriteView.cs b/Content.Client/_Sunrise/UserInterface/Controls/SunriseSpriteView.cs index 6eac8ecb1f..5442606557 100644 --- a/Content.Client/_Sunrise/UserInterface/Controls/SunriseSpriteView.cs +++ b/Content.Client/_Sunrise/UserInterface/Controls/SunriseSpriteView.cs @@ -10,21 +10,14 @@ namespace Content.Client._Sunrise.UserInterface.Controls; [Virtual] public class SunriseStaticSpriteView : Control { - protected SpriteSystem? SpriteSystem; - private SharedTransformSystem? _transform; - protected readonly IEntityManager EntMan; + private readonly SpriteSystem _sprite; + private readonly IEntityManager _entityMan; private SpriteComponent? _cachedSprite; - private readonly Angle _cachedWorldRotation = Angle.Zero; + private Angle _rotation; [ViewVariables] - public SpriteComponent? Sprite => Entity?.Comp1; - - [ViewVariables] - public Entity? Entity { get; private set; } - - [ViewVariables] - public NetEntity? NetEnt { get; private set; } + private Entity Entity { get; set; } /// /// This field configures automatic scaling of the sprite. This automatic scaling is done before @@ -64,32 +57,6 @@ public class SunriseStaticSpriteView : Control #region Transform private Vector2 _scale = Vector2.One; - private Angle _eyeRotation = Angle.Zero; - private Angle? _worldRotation = Angle.Zero; - - public Angle EyeRotation - { - get => _eyeRotation; - set - { - _eyeRotation = value; - InvalidateMeasure(); - } - } - - /// - /// Used to override the entity's world rotation. Note that the desired size of the control will not - /// automatically get updated as the entity's world rotation changes. - /// - public Angle? WorldRotation - { - get => _worldRotation; - set - { - _worldRotation = value; - InvalidateMeasure(); - } - } /// /// Scale to apply when rendering the sprite. This is separate from the sprite's scale. @@ -117,68 +84,32 @@ public class SunriseStaticSpriteView : Control #endregion - public SunriseStaticSpriteView() + public SunriseStaticSpriteView(EntityUid uid) { - IoCManager.Resolve(ref EntMan); - RectClipContent = true; - } + IoCManager.Resolve(ref _entityMan); - public SunriseStaticSpriteView(IEntityManager entMan) - { - EntMan = entMan; RectClipContent = true; - } - public SunriseStaticSpriteView(EntityUid? uid, IEntityManager entMan) - { - EntMan = entMan; - RectClipContent = true; + _sprite = _entityMan.System(); + SetEntity(uid); } - public SunriseStaticSpriteView(NetEntity uid, IEntityManager entMan) + public void SetEntity(EntityUid uid) { - EntMan = entMan; - RectClipContent = true; - SetEntity(uid); - } - - public void SetEntity(NetEntity netEnt) - { - if (netEnt == NetEnt) + if (Entity.Owner == uid) return; - if (EntMan.TryGetEntity(netEnt, out var uid)) - { - SetEntity(uid); - } - else - { - // Подписаться на событие появления сущности - Entity = null; - NetEnt = netEnt; - } - } - - public void SetEntity(EntityUid? uid) - { - if (Entity?.Owner == uid) + if (!_entityMan.TryGetComponent(uid, out SpriteComponent? sprite)) return; - if (!EntMan.TryGetComponent(uid, out SpriteComponent? sprite) - || !EntMan.TryGetComponent(uid, out TransformComponent? xform)) - { - Entity = null; - NetEnt = null; - return; - } - // Создаем глубокую копию спрайта - _cachedSprite = new SpriteComponent(); - _cachedSprite.CopyFrom(sprite); // Используем встроенный метод копирования + _cachedSprite = _entityMan.ComponentFactory.GetComponent(); + _sprite.CopySprite((uid, sprite), (uid, _cachedSprite)); - Entity = new(uid.Value, sprite, xform); - NetEnt = EntMan.GetNetEntity(uid); + _rotation = sprite.Rotation; + + Entity = (uid, sprite); } protected override Vector2 MeasureOverride(Vector2 availableSize) { @@ -189,10 +120,10 @@ public class SunriseStaticSpriteView : Control private void UpdateSize() { - if (!ResolveEntity(out _, out var sprite, out _)) + if (!ResolveEntity(out var uid, out var sprite)) return; - var spriteBox = sprite.CalculateRotatedBoundingBox(default, _worldRotation ?? Angle.Zero, _eyeRotation) + var spriteBox = _sprite.CalculateBounds((uid, sprite), default, _rotation, _rotation) .CalcBoundingBox(); if (!SpriteOffset) @@ -217,8 +148,7 @@ public class SunriseStaticSpriteView : Control DebugTools.Assert(box.Contains(Vector2.Zero)); DebugTools.Assert(box.TopLeft.EqualsApprox(-box.BottomRight)); - if (_worldRotation != null - && _eyeRotation == Angle.Zero) // TODO This shouldn't need to be here, but I just give up at this point I am going fucking insane looking at rotating blobs of pixels. I doubt anyone will ever even use rotated sprite views.? + if (_rotation == Angle.Zero) // TODO This shouldn't need to be here, but I just give up at this point I am going fucking insane looking at rotating blobs of pixels. I doubt anyone will ever even use rotated sprite views.? { _spriteSize = box.Size; return; @@ -234,12 +164,9 @@ public class SunriseStaticSpriteView : Control protected override void Draw(IRenderHandle renderHandle) { - if (!ResolveEntity(out var uid, out _, out var xform) || _cachedSprite == null) + if (!ResolveEntity(out var uid, out _) || _cachedSprite == null) return; - SpriteSystem ??= EntMan.System(); - _transform ??= EntMan.System(); - var stretchVec = Stretch switch { StretchMode.Fit => Vector2.Min(Size / _spriteSize, Vector2.One), @@ -250,7 +177,7 @@ public class SunriseStaticSpriteView : Control var offset = SpriteOffset ? Vector2.Zero - : - (-_eyeRotation).RotateVec(_cachedSprite.Offset * _scale) * new Vector2(1, -1) * EyeManager.PixelsPerMeter; + : - (-_rotation).RotateVec(_cachedSprite.Offset * _scale) * new Vector2(1, -1) * EyeManager.PixelsPerMeter; var position = PixelSize / 2 + offset * stretch * UIScale; var scale = Scale * UIScale * stretch; @@ -263,34 +190,26 @@ public class SunriseStaticSpriteView : Control uid, position, scale, - _cachedWorldRotation, // Используем сохраненный поворот - _eyeRotation, + _rotation, + _rotation, OverrideDirection, - _cachedSprite, // Кэшированный спрайт - xform + _cachedSprite ); world.Modulate = oldModulate; } - private bool ResolveEntity( - out EntityUid uid, - [NotNullWhen(true)] out SpriteComponent? sprite, - [NotNullWhen(true)] out TransformComponent? xform) + private bool ResolveEntity(out EntityUid uid, [NotNullWhen(true)] out SpriteComponent? sprite) { - sprite = _cachedSprite; // Возвращаем кэшированный спрайт - xform = null; // Не используем текущий transform + sprite = null; + uid = EntityUid.Invalid; - if (NetEnt != null && Entity == null && EntMan.TryGetEntity(NetEnt, out var ent)) - SetEntity(ent); + if (!_entityMan.EntityExists(Entity.Owner) || _cachedSprite == null) + return false; - if (Entity != null) - { - uid = Entity.Value.Owner; - return !EntMan.Deleted(uid); - } + uid = Entity.Owner; + sprite = _cachedSprite; - uid = default; - return false; + return true; } } diff --git a/Content.Client/_Sunrise/UserInterface/RichText/BaseTextureTag.cs b/Content.Client/_Sunrise/UserInterface/RichText/BaseTextureTag.cs index ec00067021..4cd9102e94 100644 --- a/Content.Client/_Sunrise/UserInterface/RichText/BaseTextureTag.cs +++ b/Content.Client/_Sunrise/UserInterface/RichText/BaseTextureTag.cs @@ -53,19 +53,17 @@ public abstract class BaseTextureTag : IMarkupTag protected static bool TryDrawIconEntity(string stringUid, long scaleValue, [NotNullWhen(true)] out Control? control) { control = null; - var spriteView = new SunriseStaticSpriteView() - { - OverrideDirection = Direction.South, - SetSize = new Vector2(48f, 32f), - }; stringUid = ClearString(stringUid); if (!EntityUid.TryParse(stringUid, out var entityUid)) return false; - spriteView.SetEntity(entityUid); - spriteView.Scale = new Vector2(scaleValue, scaleValue); + var spriteView = new SunriseStaticSpriteView(entityUid) + { + SetSize = new Vector2(48f, 32f), + Scale = new Vector2(scaleValue, scaleValue), + }; control = spriteView; return true;