public override bool Update(ScreenCoordinates mouseS) { if (mouseS.MapID == MapManager.NULLSPACE) { return(false); } mouseScreen = mouseS; mouseCoords = CluwneLib.ScreenToCoordinates(mouseScreen); if (pManager.CurrentPermission.IsTile) { return(false); } currentTile = mouseCoords.Grid.GetTile(mouseCoords); if (!RangeCheck()) { return(false); } var manager = IoCManager.Resolve <IClientEntityManager>(); IOrderedEnumerable <IEntity> snapToEntities = from IEntity entity in manager.GetEntitiesInRange(mouseCoords, snapToRange) where entity.Prototype == pManager.CurrentPrototype && entity.GetComponent <ITransformComponent>().MapID == mouseCoords.MapID orderby (entity.GetComponent <ITransformComponent>( ).WorldPosition - mouseCoords.ToWorld().Position).LengthSquared ascending select entity; if (snapToEntities.Any()) { IEntity closestEntity = snapToEntities.First(); if (closestEntity.TryGetComponent <ISpriteRenderableComponent>(out var component)) { var closestSprite = component.GetCurrentSprite(); var closestBounds = closestSprite.LocalBounds; var closestRect = Box2.FromDimensions( closestEntity.GetComponent <ITransformComponent>().WorldPosition.X - closestBounds.Width / 2f, closestEntity.GetComponent <ITransformComponent>().WorldPosition.Y - closestBounds.Height / 2f, closestBounds.Width, closestBounds.Height); var sides = new Vector2[] { new Vector2(closestRect.Left + (closestRect.Width / 2f), closestRect.Top - closestBounds.Height / 2f), new Vector2(closestRect.Left + (closestRect.Width / 2f), closestRect.Bottom + closestBounds.Height / 2f), new Vector2(closestRect.Left - closestBounds.Width / 2f, closestRect.Top + (closestRect.Height / 2f)), new Vector2(closestRect.Right + closestBounds.Width / 2f, closestRect.Top + (closestRect.Height / 2f)) }; Vector2 closestSide = (from Vector2 side in sides orderby(side - mouseCoords.Position).LengthSquared ascending select side).First(); mouseCoords = new LocalCoordinates(closestSide, mouseCoords.Grid); mouseScreen = CluwneLib.WorldToScreen(mouseCoords); } } if (CheckCollision()) { return(false); } return(true); }
public override void AlignPlacementMode(ScreenCoordinates mouseScreen) { MouseCoords = ScreenToCursorGrid(mouseScreen); CurrentTile = pManager.MapManager.GetGrid(MouseCoords.GridID).GetTileRef(MouseCoords); }
protected override void FrameUpdate(RenderFrameEventArgs args) { if (!VisibleInTree) { return; } var stringBuilder = new StringBuilder(); var mouseScreenPos = inputManager.MouseScreenPosition; var screenSize = _displayManager.ScreenSize; int mouseWorldMap; int mouseWorldGrid; GridCoordinates mouseWorldPos; ScreenCoordinates worldToScreen; IEntity mouseEntity = null; TileRef tile; try { var coords = eyeManager.ScreenToWorld(new ScreenCoordinates(mouseScreenPos)); mouseWorldMap = (int)_mapManager.GetGrid(coords.GridID).ParentMapId; mouseWorldGrid = (int)coords.GridID; mouseWorldPos = coords; worldToScreen = eyeManager.WorldToScreen(coords); if (stateManager.CurrentState is GameScreen gameScreen) { mouseEntity = gameScreen.GetEntityUnderPosition(coords); } tile = _mapManager.GetGrid(coords.GridID).GetTileRef(coords); } catch { mouseWorldPos = eyeManager.ScreenToWorld(mouseScreenPos); mouseWorldGrid = 0; mouseWorldMap = 0; worldToScreen = new ScreenCoordinates(); tile = new TileRef(); } stringBuilder.AppendFormat(@"Positioning Debug: Screen Size: {0} Mouse Pos: Screen: {1} World: {2} W2S: {3} Grid: {4} Tile: {8} Map: {5} Entity: {6} GUI: {7} ", screenSize, mouseScreenPos, mouseWorldPos, worldToScreen, mouseWorldGrid, mouseWorldMap, mouseEntity, UserInterfaceManager.CurrentlyHovered, tile); stringBuilder.AppendLine("\nAttached Entity:"); if (playerManager.LocalPlayer?.ControlledEntity == null) { stringBuilder.AppendLine("No attached entity."); } else { var entityTransform = playerManager.LocalPlayer.ControlledEntity.Transform; var playerWorldOffset = entityTransform.WorldPosition; var playerScreen = eyeManager.WorldToScreen(playerWorldOffset); stringBuilder.AppendFormat(@" World: {0} Screen: {1} Grid: {2} Map: {3}", playerWorldOffset, playerScreen, entityTransform.GridID, entityTransform.MapID); } contents.Text = stringBuilder.ToString(); MinimumSizeChanged(); }
public virtual bool Update(ScreenCoordinates mouseScreen) { return(false); }
public override void AlignPlacementMode(ScreenCoordinates mouseScreen) { MouseCoords = ScreenToCursorGrid(mouseScreen); CurrentTile = GetTileRef(MouseCoords); }
/// <summary> /// Creates an instance of <see cref="FullInputCmdMessage"/>. /// </summary> /// <param name="tick">Client tick this was created.</param> /// <param name="inputSequence"></param> /// <param name="inputFunctionId">Function this command is changing.</param> /// <param name="state">New state of the Input Function.</param> /// <param name="coordinates">Local Coordinates of the pointer when the command was created.</param> /// <param name="screenCoordinates"></param> public FullInputCmdMessage(GameTick tick, ushort subTick, int inputSequence, KeyFunctionId inputFunctionId, BoundKeyState state, GridCoordinates coordinates, ScreenCoordinates screenCoordinates) : this(tick, subTick, inputFunctionId, state, coordinates, screenCoordinates, EntityUid.Invalid) { }
public CursorPopupLabel(ScreenCoordinates screenCoords) : base() { InitialPos = screenCoords.Position / UIScale - DesiredSize / 2; }
protected MouseEventArgs(ScreenCoordinates position) { Position = position; }
// ALL the parameters! public MouseButtonEventArgs(Mouse.Button button, ScreenCoordinates position) : base(position) { Button = button; }
public void PopupMessage(ScreenCoordinates coordinates, string message) { PopupMessage(coordinates, message, null); }
public virtual bool FrameUpdate(RenderFrameEventArgs e, ScreenCoordinates mouseScreen) { return(false); }
public virtual void Render(Vector2 topLeft, Vector2 bottomRight) { //Render slaves beneath IEnumerable <SpriteComponent> renderablesBeneath = from SpriteComponent c in slaves //FIXTHIS orderby c.DrawDepth ascending where c.DrawDepth < DrawDepth select c; foreach (SpriteComponent component in renderablesBeneath.ToList()) { component.Render(topLeft, bottomRight); } //Render this sprite if (!visible) { return; } if (currentBaseSprite == null) { return; } Sprite spriteToRender = GetActiveDirectionalSprite(); ScreenCoordinates renderPos = CluwneLib.WorldToScreen(Owner.GetComponent <ITransformComponent>().LocalPosition); var bounds = spriteToRender.GetLocalBounds(); SetSpriteCenter(spriteToRender, renderPos.Position); if (Owner.GetComponent <ITransformComponent>().WorldPosition.X + bounds.Left + bounds.Width < topLeft.X || Owner.GetComponent <ITransformComponent>().WorldPosition.X > bottomRight.X || Owner.GetComponent <ITransformComponent>().WorldPosition.Y + bounds.Top + bounds.Height < topLeft.Y || Owner.GetComponent <ITransformComponent>().WorldPosition.Y > bottomRight.Y) { return; } spriteToRender.Scale = new Vector2f(HorizontalFlip ? -1 : 1, 1); spriteToRender.Color = this.Color.Convert(); spriteToRender.Draw(); spriteToRender.Color = Color4.White.Convert(); //Render slaves above IEnumerable <SpriteComponent> renderablesAbove = from SpriteComponent c in slaves //FIXTHIS orderby c.DrawDepth ascending where c.DrawDepth >= DrawDepth select c; foreach (SpriteComponent component in renderablesAbove.ToList()) { component.Render(topLeft, bottomRight); } //Draw AABB var aabb = LocalAABB; if (CluwneLib.Debug.DebugColliders) { CluwneLib.drawRectangle((int)(renderPos.X - aabb.Width / 2), (int)(renderPos.Y - aabb.Height / 2), aabb.Width, aabb.Height, Color4.Blue); } }
public override bool Update(ScreenCoordinates mouseS) { if (mouseS.MapID == MapId.Nullspace) { return(false); } MouseScreen = mouseS; MouseCoords = CluwneLib.ScreenToCoordinates(MouseScreen); if (pManager.CurrentPermission.IsTile) { return(false); } CurrentTile = MouseCoords.Grid.GetTile(MouseCoords); if (!RangeCheck()) { return(false); } var manager = IoCManager.Resolve <IClientEntityManager>(); var snapToEntities = manager.GetEntitiesInRange(MouseCoords, SnapToRange) .Where(entity => entity.Prototype == pManager.CurrentPrototype && entity.GetComponent <ITransformComponent>().MapID == MouseCoords.MapID) .OrderBy(entity => (entity.GetComponent <ITransformComponent>().WorldPosition - MouseCoords.ToWorld().Position).LengthSquared) .ToList(); if (snapToEntities.Any()) { var closestEntity = snapToEntities.First(); if (closestEntity.TryGetComponent <ISpriteRenderableComponent>(out var component)) { var closestSprite = component.GetCurrentSprite(); var closestBounds = closestSprite.LocalBounds; var closestRect = Box2.FromDimensions( closestEntity.GetComponent <ITransformComponent>().WorldPosition.X - closestBounds.Width / 2f, closestEntity.GetComponent <ITransformComponent>().WorldPosition.Y - closestBounds.Height / 2f, closestBounds.Width, closestBounds.Height); var sides = new[] { new Vector2(closestRect.Left + closestRect.Width / 2f, closestRect.Top - closestBounds.Height / 2f), new Vector2(closestRect.Left + closestRect.Width / 2f, closestRect.Bottom + closestBounds.Height / 2f), new Vector2(closestRect.Left - closestBounds.Width / 2f, closestRect.Top + closestRect.Height / 2f), new Vector2(closestRect.Right + closestBounds.Width / 2f, closestRect.Top + closestRect.Height / 2f) }; var closestSide = (from Vector2 side in sides orderby(side - MouseCoords.Position).LengthSquared select side).First(); MouseCoords = new LocalCoordinates(closestSide, MouseCoords.Grid); MouseScreen = CluwneLib.WorldToScreen(MouseCoords); } } if (CheckCollision()) { return(false); } return(true); }
/// <summary> /// Constructs a new instance of <see cref="BoundKeyEventArgs"/>. /// </summary> /// <param name="function">Bound key that that is changing.</param> /// <param name="state">New state of the function.</param> /// <param name="pointerLocation">Current Pointer location in screen coordinates.</param> public BoundKeyEventArgs(BoundKeyFunction function, BoundKeyState state, ScreenCoordinates pointerLocation) { Function = function; State = state; PointerLocation = pointerLocation; }
/// <summary> /// Creates an instance of <see cref="FullInputCmdMessage"/>. /// </summary> /// <param name="tick">Client tick this was created.</param> /// <param name="inputFunctionId">Function this command is changing.</param> /// <param name="state">New state of the Input Function.</param> /// <param name="coordinates">Local Coordinates of the pointer when the command was created.</param> public FullInputCmdMessage(uint tick, KeyFunctionId inputFunctionId, BoundKeyState state, GridLocalCoordinates coordinates, ScreenCoordinates screenCoordinates) : this(tick, inputFunctionId, state, coordinates, screenCoordinates, EntityUid.Invalid) { }
// ALL the parameters! public MouseWheelEventArgs(Vector2 delta, ScreenCoordinates position) : base(position) { Delta = delta; }
/// <summary> /// Creates an instance of <see cref="FullInputCmdMessage"/> with an optional Entity reference. /// </summary> /// <param name="tick">Client tick this was created.</param> /// <param name="inputFunctionId">Function this command is changing.</param> /// <param name="state">New state of the Input Function.</param> /// <param name="coordinates">Local Coordinates of the pointer when the command was created.</param> /// <param name="uid">Entity that was under the pointer when the command was created.</param> public FullInputCmdMessage(uint tick, KeyFunctionId inputFunctionId, BoundKeyState state, GridLocalCoordinates coordinates, ScreenCoordinates screenCoordinates, EntityUid uid) : base(tick, inputFunctionId) { State = state; Coordinates = coordinates; ScreenCoordinates = screenCoordinates; Uid = uid; }
// ALL the parameters! public MouseMoveEventArgs(Vector2 relative, ScreenCoordinates position) : base(position) { Relative = relative; }
/// <summary> /// Creates an instance of <see cref="FullInputCmdMessage"/> with an optional Entity reference. /// </summary> /// <param name="tick">Client tick this was created.</param> /// <param name="inputFunctionId">Function this command is changing.</param> /// <param name="state">New state of the Input Function.</param> /// <param name="coordinates">Local Coordinates of the pointer when the command was created.</param> /// <param name="screenCoordinates"></param> /// <param name="uid">Entity that was under the pointer when the command was created.</param> public FullInputCmdMessage(GameTick tick, ushort subTick, KeyFunctionId inputFunctionId, BoundKeyState state, GridCoordinates coordinates, ScreenCoordinates screenCoordinates, EntityUid uid) : base(tick, subTick, inputFunctionId) { State = state; Coordinates = coordinates; ScreenCoordinates = screenCoordinates; Uid = uid; }
public override void AlignPlacementMode(ScreenCoordinates mouseScreen) { const float SearchBoxSize = 1.5f; // size of search box in meters MouseCoords = ScreenToCursorGrid(mouseScreen); var mapGrid = pManager.MapManager.GetGrid(MouseCoords.GridID); if (mapGrid.IsDefaultGrid) { // check if we are on an edge of a grid // create a box around the cursor DebugTools.Assert(mapGrid.WorldPosition == Vector2.Zero); // assert that LocalPos == WorldPos var gridSearchBox = Box2.UnitCentered.Scale(SearchBoxSize).Translated(MouseCoords.Position); // find grids in search box var gridsInArea = mapGrid.ParentMap.FindGridsIntersecting(gridSearchBox); // find closest grid intersecting our search box. IMapGrid closest = null; var distance = float.PositiveInfinity; var intersect = new Box2(); foreach (var grid in gridsInArea) { // figure out closest intersect var gridIntersect = gridSearchBox.Intersect(grid.WorldBounds); var gridDist = (gridIntersect.Center - MouseCoords.Position).LengthSquared; if (gridDist >= distance) { continue; } distance = gridDist; closest = grid; intersect = gridIntersect; } if (closest != null) // stick to existing grid { // round to nearest cardinal dir var normal = new Angle(MouseCoords.Position - intersect.Center).GetCardinalDir().ToVec(); // round coords to center of tile var tileIndices = closest.WorldToTile(intersect.Center); var tileCenterLocal = closest.GridTileToLocal(tileIndices); var tileCenterWorld = tileCenterLocal.ToWorld(pManager.MapManager).Position; // move mouse one tile out along normal var newTilePos = tileCenterWorld + normal * closest.TileSize; MouseCoords = new GridCoordinates(closest.WorldToLocal(newTilePos), closest.Index); } //else free place } CurrentTile = mapGrid.GetTileRef(MouseCoords); float tileSize = mapGrid.TileSize; //convert from ushort to float GridDistancing = tileSize; if (pManager.CurrentPermission.IsTile) { if (!mapGrid.IsDefaultGrid) { MouseCoords = new GridCoordinates(CurrentTile.X + tileSize / 2, CurrentTile.Y + tileSize / 2, MouseCoords.GridID); } // else we don't modify coords } else { MouseCoords = new GridCoordinates(CurrentTile.X + tileSize / 2 + pManager.PlacementOffset.X, CurrentTile.Y + tileSize / 2 + pManager.PlacementOffset.Y, MouseCoords.GridID); } }
/// <summary> /// Aligns the location of placement based on cursor location /// </summary> /// <param name="mouseScreen"></param> /// <returns>Returns whether the current position is a valid placement position</returns> public abstract void AlignPlacementMode(ScreenCoordinates mouseScreen);
protected GridCoordinates ScreenToCursorGrid(ScreenCoordinates coords) { return pManager.eyeManager.ScreenToWorld(coords.Position); }
public override void AlignPlacementMode(ScreenCoordinates mouseScreen) { MouseCoords = ScreenToPlayerGrid(mouseScreen); CurrentTile = MouseCoords.Grid.GetTile(MouseCoords); }
public override void Render(Vector2 topLeft, Vector2 bottomRight) { if (IsCurrentlyWorn && currentSprite == baseSprite) { base.Render(topLeft, bottomRight); return; } else if (IsCurrentlyCarried && currentSprite != CarriedSprite) { SetSprite(CarriedSprite); base.Render(topLeft, bottomRight); return; } //Render slaves beneath IEnumerable <SpriteComponent> renderablesBeneath = from SpriteComponent c in slaves //FIXTHIS orderby c.DrawDepth ascending where c.DrawDepth < DrawDepth select c; foreach (SpriteComponent component in renderablesBeneath.ToList()) { component.Render(topLeft, bottomRight); } //Render this sprite if (!visible) { return; } if (NotWornSprite == null) { return; } Sprite spriteToRender = NotWornSprite; var bounds = spriteToRender.GetLocalBounds(); ScreenCoordinates renderPos = CluwneLib.WorldToScreen(Owner.GetComponent <ITransformComponent>().LocalPosition); spriteToRender.Position = new Vector2f(renderPos.X - (bounds.Width / 2), renderPos.Y - (bounds.Height / 2)); if (Owner.GetComponent <ITransformComponent>().WorldPosition.X + bounds.Left + bounds.Width < topLeft.X || Owner.GetComponent <ITransformComponent>().WorldPosition.X > bottomRight.X || Owner.GetComponent <ITransformComponent>().WorldPosition.Y + bounds.Top + bounds.Height < topLeft.Y || Owner.GetComponent <ITransformComponent>().WorldPosition.Y > bottomRight.Y) { return; } spriteToRender.Scale = new Vector2f(HorizontalFlip ? -1 : 1, 1); spriteToRender.Draw(); //Render slaves above IEnumerable <SpriteComponent> renderablesAbove = from SpriteComponent c in slaves //FIXTHIS orderby c.DrawDepth ascending where c.DrawDepth >= DrawDepth select c; foreach (SpriteComponent component in renderablesAbove.ToList()) { component.Render(topLeft, bottomRight); } //Draw AABB var aabb = LocalAABB; if (CluwneLib.Debug.DebugColliders) { CluwneLib.drawRectangle((int)(renderPos.X - aabb.Width / 2), (int)(renderPos.Y - aabb.Height / 2), aabb.Width, aabb.Height, Color4.Blue); } }