Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: EntityPrototypeView now only creates entities when the UI is open #5491

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ END TEMPLATE-->

### Bugfixes

*None yet*
* EntityPrototypeView control now avoids creating entities if the prototype is set while the control is not on the UI tree.

### Other

Expand Down
34 changes: 25 additions & 9 deletions Robust.Client/UserInterface/Controls/EntityPrototypeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ public EntityPrototypeView(EntProtoId? entProto, IEntityManager entMan) : base(e

public void SetPrototype(EntProtoId? entProto)
{
SpriteSystem ??= EntMan.System<SpriteSystem>();

if (entProto == _currentPrototype
&& EntMan.TryGetComponent(Entity?.Owner, out MetaDataComponent? meta)
&& meta.EntityPrototype?.ID == _currentPrototype)
Expand All @@ -32,14 +30,10 @@ public void SetPrototype(EntProtoId? entProto)
}

_currentPrototype = entProto;
SetEntity(null);
EntMan.DeleteEntity(_ourEntity);

if (_currentPrototype != null)
if (_ourEntity != null)
{
_ourEntity = EntMan.Spawn(_currentPrototype);
SpriteSystem.ForceUpdate(_ourEntity.Value);
SetEntity(_ourEntity);
UpdateEntity();
}
}

Expand All @@ -48,12 +42,34 @@ protected override void EnteredTree()
base.EnteredTree();

if (_currentPrototype != null)
SetPrototype(_currentPrototype);
{
UpdateEntity();
}
}

protected override void ExitedTree()
{
base.ExitedTree();
EntMan.TryQueueDeleteEntity(_ourEntity);
_ourEntity = null;
}

private void UpdateEntity()
{
SetEntity(null);
EntMan.DeleteEntity(_ourEntity);

if (_currentPrototype != null)
{
SpriteSystem ??= EntMan.System<SpriteSystem>();

_ourEntity = EntMan.Spawn(_currentPrototype);
SpriteSystem.ForceUpdate(_ourEntity.Value);
SetEntity(_ourEntity);
}
else
{
_ourEntity = null;
}
}
}
Loading