public override void MouseDown(MouseButtonEventArgs eventargs) { if (playerManager.LocalPlayer == null || placementManager.MouseDown(eventargs)) { return; } var map = playerManager.LocalPlayer.ControlledEntity.GetComponent <ITransformComponent>().MapID; var mousePosWorld = eyeManager.ScreenToWorld(new ScreenCoordinates(eventargs.Position, map)); IEntity entityToClick = GetEntityUnderPosition(mousePosWorld); //First possible exit point for click, acceptable due to being clientside if (entityToClick != null && placementManager.Eraser && placementManager.IsActive) { placementManager.HandleDeletion(entityToClick); return; } ClickType clicktype = eventargs.ClickType; //Dispatches clicks to relevant clickable components, another single exit point for UI if (entityToClick != null) { var clickable = entityToClick.GetComponent <IClientClickableComponent>(); switch (eventargs.ClickType) { case ClickType.Left: clickable.DispatchClick(playerManager.LocalPlayer.ControlledEntity, ClickType.Left); break; case ClickType.Right: clickable.DispatchClick(playerManager.LocalPlayer.ControlledEntity, ClickType.Right); break; /* * //Acceptable click exit due to being a UI behavior * case Mouse.Button.Middle: * OpenEntityEditWindow(entToClick); * return; */ } } //Assemble information to send to server about click if (clicktype != ClickType.None) { var UID = EntityUid.Invalid; if (entityToClick != null) { UID = entityToClick.Uid; } ClickEventMessage message = new ClickEventMessage(UID, clicktype, mousePosWorld); IoCManager.Resolve <IEntityNetworkManager>().SendSystemNetworkMessage(message); } }
public override void MouseDown(MouseButtonEventArgs eventargs) { if (playerManager.LocalPlayer == null || placementManager.MouseDown(eventargs)) { return; } var map = playerManager.LocalPlayer.ControlledEntity.GetComponent <ITransformComponent>().MapID; var mousePosWorld = eyeManager.ScreenToWorld(new ScreenCoordinates(eventargs.Position, map)); // Find all the entities intersecting our click var entities = _entityManager.GetEntitiesIntersecting(mousePosWorld.MapID, mousePosWorld.Position); // Check the entities against whether or not we can click them var clickedEntities = new List <(IEntity clicked, int drawDepth)>(); foreach (IEntity entity in entities) { if (entity.TryGetComponent <IClientClickableComponent>(out var component) && entity.GetComponent <ITransformComponent>().IsMapTransform && component.CheckClick(mousePosWorld, out int drawdepthofclicked)) { clickedEntities.Add((entity, drawdepthofclicked)); } } IEntity entityToClick; if (clickedEntities.Any()) { entityToClick = (from cd in clickedEntities orderby cd.drawDepth ascending, cd.clicked.GetComponent <ITransformComponent>().LocalPosition .Y ascending select cd.clicked).Last(); } else { entityToClick = null; } //First possible exit point for click, acceptable due to being clientside if (entityToClick != null && placementManager.Eraser && placementManager.IsActive) { placementManager.HandleDeletion(entityToClick); return; } ClickType clicktype = eventargs.ClickType; //Dispatches clicks to relevant clickable components, another single exit point for UI if (entityToClick != null) { var clickable = entityToClick.GetComponent <IClientClickableComponent>(); switch (eventargs.ClickType) { case ClickType.Left: clickable.DispatchClick(playerManager.LocalPlayer.ControlledEntity, ClickType.Left); break; case ClickType.Right: clickable.DispatchClick(playerManager.LocalPlayer.ControlledEntity, ClickType.Right); break; /* * //Acceptable click exit due to being a UI behavior * case Mouse.Button.Middle: * OpenEntityEditWindow(entToClick); * return; */ } } //Assemble information to send to server about click if (clicktype != ClickType.None) { var UID = EntityUid.Invalid; if (entityToClick != null) { UID = entityToClick.Uid; } ClickEventMessage message = new ClickEventMessage(UID, clicktype, mousePosWorld); IoCManager.Resolve <IEntityNetworkManager>().SendSystemNetworkMessage(message); } }