Make more uids nullable (#5794)
This commit is contained in:
@@ -15,7 +15,7 @@ namespace Content.Client.ContextMenu.UI
|
||||
/// <summary>
|
||||
/// The entity that can be accessed by interacting with this element.
|
||||
/// </summary>
|
||||
public EntityUid Entity;
|
||||
public EntityUid? Entity;
|
||||
|
||||
/// <summary>
|
||||
/// How many entities are accessible through this element's sub-menus.
|
||||
@@ -28,7 +28,7 @@ namespace Content.Client.ContextMenu.UI
|
||||
public readonly Label CountLabel;
|
||||
public readonly SpriteView EntityIcon = new() { OverrideDirection = Direction.South};
|
||||
|
||||
public EntityMenuElement(EntityUid entity = default)
|
||||
public EntityMenuElement(EntityUid? entity = null)
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace Content.Client.ContextMenu.UI
|
||||
LayoutContainer.SetGrowVertical(CountLabel, LayoutContainer.GrowDirection.Begin);
|
||||
|
||||
Entity = entity;
|
||||
if (Entity != default)
|
||||
if (Entity != null)
|
||||
{
|
||||
Count = 1;
|
||||
CountLabel.Visible = false;
|
||||
@@ -51,7 +51,7 @@ namespace Content.Client.ContextMenu.UI
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
Entity = default;
|
||||
Entity = null;
|
||||
Count = 0;
|
||||
}
|
||||
|
||||
@@ -59,23 +59,25 @@ namespace Content.Client.ContextMenu.UI
|
||||
/// Update the icon and text of this element based on the given entity or this element's own entity if none
|
||||
/// is provided.
|
||||
/// </summary>
|
||||
public void UpdateEntity(EntityUid entity = default)
|
||||
public void UpdateEntity(EntityUid? entity = null)
|
||||
{
|
||||
if (Entity != default && _entityManager.EntityExists(Entity) && !entity.Valid)
|
||||
entity = Entity;
|
||||
entity ??= Entity;
|
||||
|
||||
if (entity == default)
|
||||
// check whether entity is null, invalid, or has been deleted.
|
||||
// _entityManager.Deleted() implicitly checks all of these.
|
||||
if (_entityManager.Deleted(entity))
|
||||
{
|
||||
Text = string.Empty;
|
||||
EntityIcon.Sprite = null;
|
||||
return;
|
||||
}
|
||||
|
||||
EntityIcon.Sprite = _entityManager.GetComponentOrNull<ISpriteComponent>(entity);
|
||||
|
||||
if (UserInterfaceManager.DebugMonitors.Visible)
|
||||
Text = $"{_entityManager.GetComponent<MetaDataComponent>(entity!).EntityName} ({entity})";
|
||||
Text = _entityManager.ToPrettyString(entity.Value);
|
||||
else
|
||||
Text = _entityManager.GetComponent<MetaDataComponent>(entity!).EntityName;
|
||||
Text = _entityManager.GetComponent<MetaDataComponent>(entity.Value).EntityName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user