From 8a1607bedee732a8ebacdb1fc0d48e8487cc02b4 Mon Sep 17 00:00:00 2001 From: "pa.pecherskij" Date: Sun, 13 Oct 2024 13:09:17 +0300 Subject: [PATCH 1/2] fix: EntityPrototypeView now only creates entity when in opened ui (after EnteredTree and not after ExitedTree) --- .../Controls/EntityPrototypeView.cs | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/Robust.Client/UserInterface/Controls/EntityPrototypeView.cs b/Robust.Client/UserInterface/Controls/EntityPrototypeView.cs index 5aa23f3dc33..8327d972f6b 100644 --- a/Robust.Client/UserInterface/Controls/EntityPrototypeView.cs +++ b/Robust.Client/UserInterface/Controls/EntityPrototypeView.cs @@ -22,8 +22,6 @@ public EntityPrototypeView(EntProtoId? entProto, IEntityManager entMan) : base(e public void SetPrototype(EntProtoId? entProto) { - SpriteSystem ??= EntMan.System(); - if (entProto == _currentPrototype && EntMan.TryGetComponent(Entity?.Owner, out MetaDataComponent? meta) && meta.EntityPrototype?.ID == _currentPrototype) @@ -32,14 +30,10 @@ public void SetPrototype(EntProtoId? entProto) } _currentPrototype = entProto; - SetEntity(null); - EntMan.DeleteEntity(_ourEntity); - if (_currentPrototype != null) + if (_ourEntity != default) { - _ourEntity = EntMan.Spawn(_currentPrototype); - SpriteSystem.ForceUpdate(_ourEntity.Value); - SetEntity(_ourEntity); + UpdateEntity(); } } @@ -48,7 +42,9 @@ protected override void EnteredTree() base.EnteredTree(); if (_currentPrototype != null) - SetPrototype(_currentPrototype); + { + UpdateEntity(); + } } protected override void ExitedTree() @@ -56,4 +52,19 @@ protected override void ExitedTree() base.ExitedTree(); EntMan.TryQueueDeleteEntity(_ourEntity); } + + private void UpdateEntity() + { + SetEntity(null); + EntMan.DeleteEntity(_ourEntity); + + if (_currentPrototype != null) + { + SpriteSystem ??= EntMan.System(); + + _ourEntity = EntMan.Spawn(_currentPrototype); + SpriteSystem.ForceUpdate(_ourEntity.Value); + SetEntity(_ourEntity); + } + } } From 587738cccf85c922f0a3d8842b770ace7ed5e0ac Mon Sep 17 00:00:00 2001 From: "pa.pecherskij" Date: Sun, 13 Oct 2024 13:27:04 +0300 Subject: [PATCH 2/2] refactor: release notes update --- RELEASE-NOTES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 3ca1a90e8ed..857133106df 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -45,7 +45,7 @@ END TEMPLATE--> ### Bugfixes -*None yet* +* EntityPrototypeView control now is creating entity and keeping it alive only when opened (between EnteredTree and ExitedTree). ### Other