Make more uids nullable (#5794)
This commit is contained in:
@@ -14,9 +14,6 @@ namespace Content.Client.Body.UI
|
||||
[ViewVariables]
|
||||
private BodyScannerDisplay? _display;
|
||||
|
||||
[ViewVariables]
|
||||
private EntityUid _entity;
|
||||
|
||||
public BodyScannerBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey) { }
|
||||
|
||||
protected override void Open()
|
||||
@@ -43,7 +40,7 @@ namespace Content.Client.Body.UI
|
||||
throw new ArgumentException($"Received an invalid entity with id {scannerState.Uid} for body scanner with id {Owner.Owner} at {entMan.GetComponent<TransformComponent>(Owner.Owner).MapPosition}");
|
||||
}
|
||||
|
||||
_display?.UpdateDisplay(_entity);
|
||||
_display?.UpdateDisplay(scannerState.Uid);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Content.Client.Body.UI
|
||||
{
|
||||
public sealed class BodyScannerDisplay : SS14Window
|
||||
{
|
||||
private EntityUid _currentEntity;
|
||||
private EntityUid? _currentEntity;
|
||||
private SharedBodyPartComponent? _currentBodyPart;
|
||||
|
||||
public BodyScannerDisplay(BodyScannerBoundUserInterface owner)
|
||||
@@ -104,9 +104,6 @@ namespace Content.Client.Body.UI
|
||||
|
||||
public void UpdateDisplay(EntityUid entity)
|
||||
{
|
||||
if(entity == null)
|
||||
return;
|
||||
|
||||
_currentEntity = entity;
|
||||
BodyPartList.Clear();
|
||||
|
||||
@@ -125,12 +122,7 @@ namespace Content.Client.Body.UI
|
||||
|
||||
public void BodyPartOnItemSelected(ItemListSelectedEventArgs args)
|
||||
{
|
||||
if (_currentEntity == null)
|
||||
return;
|
||||
|
||||
var body = IoCManager.Resolve<IEntityManager>().GetComponentOrNull<SharedBodyComponent>(_currentEntity);
|
||||
|
||||
if (body == null)
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<SharedBodyComponent>(_currentEntity, out var body))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,18 +101,16 @@ namespace Content.Client.ContextMenu.UI
|
||||
|
||||
// get an entity associated with this element
|
||||
var entity = entityElement.Entity;
|
||||
if (!entity.Valid)
|
||||
{
|
||||
entity = GetFirstEntityOrNull(element.SubMenu);
|
||||
}
|
||||
entity ??= GetFirstEntityOrNull(element.SubMenu);
|
||||
|
||||
if (!entity.Valid)
|
||||
// Deleted() automatically checks for null & existence.
|
||||
if (_entityManager.Deleted(entity))
|
||||
return;
|
||||
|
||||
// open verb menu?
|
||||
if (args.Function == ContentKeyFunctions.OpenContextMenu)
|
||||
{
|
||||
_verbSystem.VerbMenu.OpenVerbMenu(entity);
|
||||
_verbSystem.VerbMenu.OpenVerbMenu(entity.Value);
|
||||
args.Handle();
|
||||
return;
|
||||
}
|
||||
@@ -120,7 +118,7 @@ namespace Content.Client.ContextMenu.UI
|
||||
// do examination?
|
||||
if (args.Function == ContentKeyFunctions.ExamineEntity)
|
||||
{
|
||||
_systemManager.GetEntitySystem<ExamineSystem>().DoExamine(entity);
|
||||
_systemManager.GetEntitySystem<ExamineSystem>().DoExamine(entity.Value);
|
||||
args.Handle();
|
||||
return;
|
||||
}
|
||||
@@ -139,7 +137,7 @@ namespace Content.Client.ContextMenu.UI
|
||||
var funcId = _inputManager.NetworkBindMap.KeyFunctionID(func);
|
||||
|
||||
var message = new FullInputCmdMessage(_gameTiming.CurTick, _gameTiming.TickFraction, funcId,
|
||||
BoundKeyState.Down, _entityManager.GetComponent<TransformComponent>(entity).Coordinates, args.PointerLocation, entity);
|
||||
BoundKeyState.Down, _entityManager.GetComponent<TransformComponent>(entity.Value).Coordinates, args.PointerLocation, entity.Value);
|
||||
|
||||
var session = _playerManager.LocalPlayer?.Session;
|
||||
if (session != null)
|
||||
@@ -314,7 +312,7 @@ namespace Content.Client.ContextMenu.UI
|
||||
element.SubMenu.Dispose();
|
||||
element.SubMenu = null;
|
||||
element.CountLabel.Visible = false;
|
||||
Elements[entity] = element;
|
||||
Elements[entity.Value] = element;
|
||||
}
|
||||
|
||||
// update the parent element, so that it's count and entity icon gets updated.
|
||||
@@ -326,17 +324,17 @@ namespace Content.Client.ContextMenu.UI
|
||||
/// <summary>
|
||||
/// Recursively look through a sub-menu and return the first entity.
|
||||
/// </summary>
|
||||
private EntityUid GetFirstEntityOrNull(ContextMenuPopup? menu)
|
||||
private EntityUid? GetFirstEntityOrNull(ContextMenuPopup? menu)
|
||||
{
|
||||
if (menu == null)
|
||||
return default;
|
||||
return null;
|
||||
|
||||
foreach (var element in menu.MenuBody.Children)
|
||||
{
|
||||
if (element is not EntityMenuElement entityElement)
|
||||
continue;
|
||||
|
||||
if (entityElement.Entity != default)
|
||||
if (entityElement.Entity != null)
|
||||
{
|
||||
if (!_entityManager.Deleted(entityElement.Entity))
|
||||
return entityElement.Entity;
|
||||
@@ -345,11 +343,11 @@ namespace Content.Client.ContextMenu.UI
|
||||
|
||||
// if the element has no entity, its a group of entities with another attached sub-menu.
|
||||
var entity = GetFirstEntityOrNull(entityElement.SubMenu);
|
||||
if (entity != default)
|
||||
if (entity != null)
|
||||
return entity;
|
||||
}
|
||||
|
||||
return default;
|
||||
return null;
|
||||
}
|
||||
|
||||
public override void OpenSubMenu(ContextMenuElement element)
|
||||
|
||||
@@ -118,8 +118,8 @@ namespace Content.Client.DoAfter
|
||||
|
||||
if (doAfter.BreakOnTargetMove)
|
||||
{
|
||||
if (EntityManager.EntityExists(doAfter.TargetUid) &&
|
||||
!Transform(doAfter.TargetUid).Coordinates.InRange(EntityManager, doAfter.TargetGrid,
|
||||
if (!EntityManager.Deleted(doAfter.Target) &&
|
||||
!Transform(doAfter.Target.Value).Coordinates.InRange(EntityManager, doAfter.TargetGrid,
|
||||
doAfter.MovementThreshold))
|
||||
{
|
||||
comp.Cancel(id, currentTime);
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace Content.Client.Popups
|
||||
PopupMessage(message, _eyeManager.CoordinatesToScreen(transform.Coordinates));
|
||||
}
|
||||
|
||||
public void PopupMessage(string message, ScreenCoordinates coordinates, EntityUid entity = default)
|
||||
public void PopupMessage(string message, ScreenCoordinates coordinates, EntityUid? entity = null)
|
||||
{
|
||||
var label = new PopupLabel(_eyeManager, EntityManager)
|
||||
{
|
||||
@@ -146,7 +146,7 @@ namespace Content.Client.Popups
|
||||
|
||||
public float TimeLeft { get; private set; }
|
||||
public Vector2 InitialPos { get; set; }
|
||||
public EntityUid Entity { get; set; }
|
||||
public EntityUid? Entity { get; set; }
|
||||
|
||||
public PopupLabel(IEyeManager eyeManager, IEntityManager entityManager)
|
||||
{
|
||||
@@ -161,9 +161,9 @@ namespace Content.Client.Popups
|
||||
{
|
||||
TimeLeft += eventArgs.DeltaSeconds;
|
||||
|
||||
var position = Entity == default
|
||||
var position = Entity == null
|
||||
? InitialPos
|
||||
: (_eyeManager.CoordinatesToScreen(_entityManager.GetComponent<TransformComponent>(Entity).Coordinates).Position / UIScale) - DesiredSize / 2;
|
||||
: (_eyeManager.CoordinatesToScreen(_entityManager.GetComponent<TransformComponent>(Entity.Value).Coordinates).Position / UIScale) - DesiredSize / 2;
|
||||
|
||||
LayoutContainer.SetPosition(this, position - (0, 20 * (TimeLeft * TimeLeft + TimeLeft)));
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace Content.Client.Viewport
|
||||
|
||||
private IEventBus _eventBus => _entityManager.EventBus;
|
||||
|
||||
private EntityUid _lastHoveredEntity;
|
||||
private EntityUid? _lastHoveredEntity;
|
||||
|
||||
private bool _outlineEnabled = true;
|
||||
|
||||
@@ -84,7 +84,7 @@ namespace Content.Client.Viewport
|
||||
// lead to extremely thick outlines in the other viewports. Fixing this probably requires changing how the
|
||||
// hover outline works, so that it only highlights the entity in a single viewport.
|
||||
|
||||
EntityUid entityToClick = default;
|
||||
EntityUid? entityToClick = null;
|
||||
var renderScale = 1;
|
||||
if (UserInterfaceManager.CurrentlyHovered is IViewportControl vp)
|
||||
{
|
||||
@@ -107,15 +107,15 @@ namespace Content.Client.Viewport
|
||||
}
|
||||
|
||||
var inRange = false;
|
||||
if (localPlayer.ControlledEntity != default && entityToClick != default)
|
||||
if (localPlayer.ControlledEntity != null && entityToClick != null)
|
||||
{
|
||||
inRange = localPlayer.InRangeUnobstructed(entityToClick, ignoreInsideBlocker: true);
|
||||
inRange = localPlayer.InRangeUnobstructed(entityToClick.Value, ignoreInsideBlocker: true);
|
||||
}
|
||||
|
||||
InteractionOutlineComponent? outline;
|
||||
if(!_outlineEnabled || !ConfigurationManager.GetCVar(CCVars.OutlineEnabled))
|
||||
{
|
||||
if(entityToClick != default && _entityManager.TryGetComponent(entityToClick, out outline))
|
||||
if(entityToClick != null && _entityManager.TryGetComponent(entityToClick, out outline))
|
||||
{
|
||||
outline.OnMouseLeave(); //Prevent outline remains from persisting post command.
|
||||
}
|
||||
@@ -124,7 +124,7 @@ namespace Content.Client.Viewport
|
||||
|
||||
if (entityToClick == _lastHoveredEntity)
|
||||
{
|
||||
if (entityToClick != default && _entityManager.TryGetComponent(entityToClick, out outline))
|
||||
if (entityToClick != null && _entityManager.TryGetComponent(entityToClick, out outline))
|
||||
{
|
||||
outline.UpdateInRange(inRange, renderScale);
|
||||
}
|
||||
@@ -132,7 +132,7 @@ namespace Content.Client.Viewport
|
||||
return;
|
||||
}
|
||||
|
||||
if (_lastHoveredEntity != default && !_entityManager.Deleted(_lastHoveredEntity) &&
|
||||
if (_lastHoveredEntity != null && !_entityManager.Deleted(_lastHoveredEntity) &&
|
||||
_entityManager.TryGetComponent(_lastHoveredEntity, out outline))
|
||||
{
|
||||
outline.OnMouseLeave();
|
||||
@@ -140,16 +140,16 @@ namespace Content.Client.Viewport
|
||||
|
||||
_lastHoveredEntity = entityToClick;
|
||||
|
||||
if (_lastHoveredEntity != default && _entityManager.TryGetComponent(_lastHoveredEntity, out outline))
|
||||
if (_lastHoveredEntity != null && _entityManager.TryGetComponent(_lastHoveredEntity, out outline))
|
||||
{
|
||||
outline.OnMouseEnter(inRange, renderScale);
|
||||
}
|
||||
}
|
||||
|
||||
public EntityUid GetEntityUnderPosition(MapCoordinates coordinates)
|
||||
public EntityUid? GetEntityUnderPosition(MapCoordinates coordinates)
|
||||
{
|
||||
var entitiesUnderPosition = GetEntitiesUnderPosition(coordinates);
|
||||
return entitiesUnderPosition.Count > 0 ? entitiesUnderPosition[0] : default;
|
||||
return entitiesUnderPosition.Count > 0 ? entitiesUnderPosition[0] : null;
|
||||
}
|
||||
|
||||
public IList<EntityUid> GetEntitiesUnderPosition(EntityCoordinates coordinates)
|
||||
@@ -257,7 +257,7 @@ namespace Content.Client.Viewport
|
||||
var funcId = InputManager.NetworkBindMap.KeyFunctionID(func);
|
||||
|
||||
EntityCoordinates coordinates = default;
|
||||
EntityUid entityToClick = default;
|
||||
EntityUid? entityToClick = null;
|
||||
if (args.Viewport is IViewportControl vp)
|
||||
{
|
||||
var mousePosWorld = vp.ScreenToMap(kArgs.PointerLocation.Position);
|
||||
@@ -269,7 +269,7 @@ namespace Content.Client.Viewport
|
||||
|
||||
var message = new FullInputCmdMessage(Timing.CurTick, Timing.TickFraction, funcId, kArgs.State,
|
||||
coordinates , kArgs.PointerLocation,
|
||||
entityToClick);
|
||||
entityToClick ?? default); // TODO make entityUid nullable
|
||||
|
||||
// client side command handlers will always be sent the local player session.
|
||||
var session = PlayerManager.LocalPlayer?.Session;
|
||||
|
||||
@@ -64,10 +64,11 @@ namespace Content.Client.Wall.Components
|
||||
{
|
||||
base.Shutdown();
|
||||
|
||||
EntityUid tempQualifier = _overlayEntity;
|
||||
if (tempQualifier != null)
|
||||
// _overlayEntity is non-nullable as it is set on startup.
|
||||
// Should also never be default but might as well check.
|
||||
if (_overlayEntity.Valid)
|
||||
{
|
||||
_entMan.DeleteEntity(tempQualifier);
|
||||
_entMan.DeleteEntity(_overlayEntity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user