Esempio n. 1
0
        public override bool Update(ScreenCoordinates mouseS)
        {
            if (mouseS.MapID == MapManager.NULLSPACE)
            {
                return(false);
            }

            mouseScreen = mouseS;
            mouseCoords = CluwneLib.ScreenToCoordinates(mouseScreen);

            currentTile = mouseCoords.Grid.GetTile(mouseCoords);
            var tilesize = mouseCoords.Grid.TileSize;

            if (!RangeCheck())
            {
                return(false);
            }

            if (pManager.CurrentPermission.IsTile)
            {
                mouseCoords = new LocalCoordinates(currentTile.X + tilesize / 2,
                                                   currentTile.Y + tilesize / 2,
                                                   mouseCoords.Grid);
                mouseScreen = CluwneLib.WorldToScreen(mouseCoords);
            }
            else
            {
                mouseCoords = new LocalCoordinates(currentTile.X + tilesize / 2 + pManager.CurrentPrototype.PlacementOffset.X,
                                                   currentTile.Y + tilesize / 2 + pManager.CurrentPrototype.PlacementOffset.Y,
                                                   mouseCoords.Grid);
                mouseScreen = CluwneLib.WorldToScreen(mouseCoords);
            }

            return(true);
        }
        public override bool Update(ScreenCoordinates mouseS)
        {
            if (mouseS.MapID == MapManager.NULLSPACE)
            {
                return(false);
            }

            mouseScreen = mouseS;
            mouseCoords = CluwneLib.ScreenToCoordinates(mouseScreen);

            var snapsize = mouseCoords.Grid.SnapSize; //Find snap size.

            var mouselocal = new Vector2(             //Round local coordinates onto the snap grid
                (float)(Math.Round((mouseCoords.Position.X / (double)snapsize - 0.5), MidpointRounding.AwayFromZero) + 0.5) * snapsize,
                (float)(Math.Round((mouseCoords.Position.Y / (double)snapsize - 0.5), MidpointRounding.AwayFromZero) + 0.5) * snapsize);

            //Adjust mouseCoords to new calculated position
            mouseCoords = new LocalCoordinates(mouselocal + new Vector2(pManager.CurrentPrototype.PlacementOffset.X, pManager.CurrentPrototype.PlacementOffset.Y), mouseCoords.Grid);
            mouseScreen = CluwneLib.WorldToScreen(mouseCoords);

            if (!RangeCheck())
            {
                return(false);
            }

            return(true);
        }
Esempio n. 3
0
        public override bool Update(ScreenCoordinates mouseS)
        {
            if (mouseS.MapID == MapId.Nullspace)
            {
                return(false);
            }

            MouseScreen = mouseS;
            MouseCoords = CluwneLib.ScreenToCoordinates(MouseScreen);

            CurrentTile = MouseCoords.Grid.GetTile(MouseCoords);
            var tileSize = MouseCoords.Grid.TileSize;

            if (!RangeCheck())
            {
                return(false);
            }

            if (pManager.CurrentPermission.IsTile)
            {
                MouseCoords = new LocalCoordinates(CurrentTile.X + tileSize / 2,
                                                   CurrentTile.Y + tileSize / 2,
                                                   MouseCoords.Grid);
                MouseScreen = CluwneLib.WorldToScreen(MouseCoords);
            }
            else
            {
                MouseCoords = new LocalCoordinates(CurrentTile.X + tileSize / 2 + pManager.CurrentPrototype.PlacementOffset.X,
                                                   CurrentTile.Y + tileSize / 2 + pManager.CurrentPrototype.PlacementOffset.Y,
                                                   MouseCoords.Grid);
                MouseScreen = CluwneLib.WorldToScreen(MouseCoords);
            }

            return(true);
        }
        public override bool Update(ScreenCoordinates mouseS)
        {
            if (mouseS.MapID == MapManager.NULLSPACE)
            {
                return(false);
            }

            mouseScreen = mouseS;
            mouseCoords = CluwneLib.ScreenToCoordinates(mouseScreen);

            var snapsize = mouseCoords.Grid.SnapSize; //Find snap size.

            var mouselocal = new Vector2(             //Round local coordinates onto the snap grid
                (float)Math.Round((mouseCoords.X / (double)snapsize), MidpointRounding.AwayFromZero) * snapsize,
                (float)Math.Round((mouseCoords.Y / (double)snapsize), MidpointRounding.AwayFromZero) * snapsize);

            //Convert back to original world and screen coordinates after applying offset
            mouseCoords = new LocalCoordinates(mouselocal + new Vector2(pManager.CurrentPrototype.PlacementOffset.X, pManager.CurrentPrototype.PlacementOffset.Y), mouseCoords.Grid);
            mouseScreen = CluwneLib.WorldToScreen(mouseCoords);

            if (!RangeCheck())
            {
                return(false);
            }

            return(true);
        }
Esempio n. 5
0
        public override bool Update(ScreenCoordinates mouseS)
        {
            if (mouseS.MapID == MapId.Nullspace)
            {
                return(false);
            }

            MouseScreen = mouseS;
            MouseCoords = CluwneLib.ScreenToCoordinates(MouseScreen);
            CurrentTile = MouseCoords.Grid.GetTile(MouseCoords);

            return(true);
        }
Esempio n. 6
0
        public override bool Update(ScreenCoordinates mouseS)
        {
            if (mouseS.MapID == MapManager.NULLSPACE)
            {
                return(false);
            }

            mouseScreen = mouseS;
            mouseCoords = CluwneLib.ScreenToCoordinates(mouseScreen);
            currentTile = mouseCoords.Grid.GetTile(mouseCoords);

            return(true);
        }
Esempio n. 7
0
        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 nodes = new List <Vector2>();

            if (pManager.CurrentPrototype.MountingPoints != null)
            {
                nodes.AddRange(
                    pManager.CurrentPrototype.MountingPoints.Select(
                        current => new Vector2(mouseCoords.X, currentTile.Y + current)));
            }
            else
            {
                nodes.Add(new Vector2(mouseCoords.X, currentTile.Y + 0.5f));
                nodes.Add(new Vector2(mouseCoords.X, currentTile.Y + 1.0f));
                nodes.Add(new Vector2(mouseCoords.X, currentTile.Y + 1.5f));
            }

            Vector2 closestNode = (from Vector2 node in nodes
                                   orderby(node - mouseCoords.Position).LengthSquared ascending
                                   select node).First();

            mouseCoords = new LocalCoordinates(closestNode + new Vector2(pManager.CurrentPrototype.PlacementOffset.X,
                                                                         pManager.CurrentPrototype.PlacementOffset.Y),
                                               mouseCoords.Grid);
            mouseScreen = CluwneLib.WorldToScreen(mouseCoords);

            return(true);
        }
Esempio n. 8
0
 public override void Render()
 {
     base.Render();
     if (_onGrid)
     {
         var position  = CluwneLib.ScreenToCoordinates(new ScreenCoordinates(0, 0, MouseCoords.MapID)); //Find world coordinates closest to screen origin
         var gridstart = CluwneLib.WorldToScreen(new Vector2(                                           //Find snap grid closest to screen origin and convert back to screen coords
                                                     (float)Math.Round(position.X / _snapSize, MidpointRounding.AwayFromZero) * _snapSize,
                                                     (float)Math.Round(position.Y / _snapSize, MidpointRounding.AwayFromZero) * _snapSize));
         for (var a = gridstart.X; a < CluwneLib.Window.Viewport.Size.X; a += _snapSize * 32) //Iterate through screen creating gridlines
         {
             CluwneLib.drawLine(a, 0, CluwneLib.Window.Viewport.Size.Y, 90, 0.5f, Color.Blue);
         }
         for (var a = gridstart.Y; a < CluwneLib.Window.Viewport.Size.Y; a += _snapSize * 32)
         {
             CluwneLib.drawLine(0, a, CluwneLib.Window.Viewport.Size.X, 0, 0.5f, Color.Blue);
         }
     }
 }
Esempio n. 9
0
        public override bool Update(ScreenCoordinates mouseS)
        {
            if (mouseS.MapID == MapManager.NULLSPACE)
            {
                return(false);
            }

            mouseScreen = mouseS;
            mouseCoords = CluwneLib.ScreenToCoordinates(mouseScreen);
            currentTile = mouseCoords.Grid.GetTile(mouseCoords);

            if (pManager.CurrentPermission.IsTile)
            {
                return(false);
            }

            if (!RangeCheck())
            {
                return(false);
            }

            return(true);
        }
Esempio n. 10
0
        public override bool Update(ScreenCoordinates mouseS)
        {
            if (mouseS.MapID == MapId.Nullspace)
            {
                return(false);
            }

            MouseScreen = mouseS;
            MouseCoords = CluwneLib.ScreenToCoordinates(MouseScreen);
            CurrentTile = MouseCoords.Grid.GetTile(MouseCoords);

            if (pManager.CurrentPermission.IsTile)
            {
                return(false);
            }

            if (!RangeCheck())
            {
                return(false);
            }

            return(true);
        }
Esempio n. 11
0
        public override bool Update(ScreenCoordinates mouseS)
        {
            if (mouseS.MapID == MapManager.NULLSPACE)
            {
                return(false);
            }

            mouseScreen = mouseS;
            mouseCoords = CluwneLib.ScreenToCoordinates(mouseScreen);

            currentTile = mouseCoords.Grid.GetTile(mouseCoords);
            var tilesize = mouseCoords.Grid.TileSize;

            if (!RangeCheck())
            {
                return(false);
            }

            var entitymanager = IoCManager.Resolve <IClientEntityManager>();
            var failtoplace   = !entitymanager.AnyEntitiesIntersecting(new Box2(new Vector2(currentTile.X, currentTile.Y), new Vector2(currentTile.X + 0.99f, currentTile.Y + 0.99f)));

            if (pManager.CurrentPermission.IsTile)
            {
                mouseCoords = new LocalCoordinates(currentTile.X + tilesize / 2,
                                                   currentTile.Y + tilesize / 2,
                                                   mouseCoords.Grid);
                mouseScreen = CluwneLib.WorldToScreen(mouseCoords);
            }
            else
            {
                mouseCoords = new LocalCoordinates(currentTile.X + tilesize / 2 + pManager.CurrentPrototype.PlacementOffset.X,
                                                   currentTile.Y + tilesize / 2 + pManager.CurrentPrototype.PlacementOffset.Y,
                                                   mouseCoords.Grid);
                mouseScreen = CluwneLib.WorldToScreen(mouseCoords);
            }
            return(failtoplace);
        }
Esempio n. 12
0
        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);
        }
Esempio n. 13
0
        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);
        }