Ejemplo n.º 1
0
        public void Update()
        {
            MouseState    mouse    = Mouse.GetState();
            KeyboardState keyboard = Keyboard.GetState();

            var currentHoverVoxel = GetVoxelUnderMouse();

            if (!currentHoverVoxel.IsValid)
            {
                return;
            }

            bool isNewVoxelUnderMouse = currentHoverVoxel.IsValid && currentHoverVoxel != VoxelUnderMouse;

            // Prevent selection of top layer because building here causes graphical glitches.
            if (SelectionType == VoxelSelectionType.SelectEmpty && currentHoverVoxel.Coordinate.Y == World.WorldSizeInVoxels.Y - 1)
            {
                return;
            }

            VoxelUnderMouse = currentHoverVoxel;
            World.Renderer.CursorLightPos = currentHoverVoxel.WorldPosition + new Vector3(0.5f, 0.5f, 0.5f);

            if (!Enabled)
            {
                return;
            }

            // Get the type of the voxel and display it to the player.
            if (Enabled && !currentHoverVoxel.IsEmpty && currentHoverVoxel.IsExplored)
            {
                string info = currentHoverVoxel.Type.Name;

                // If it belongs to a room, display that information.
                if (World.IsInZone(currentHoverVoxel))
                {
                    var room = World.GetMostLikelyZone(currentHoverVoxel);

                    if (room != null)
                    {
                        info += " (" + room.ID + ")";
                    }
                }

                World.UserInterface.ShowInfo(info);
            }


            bool altPressed = HandleAltPressed(mouse, keyboard, ref isNewVoxelUnderMouse);

            // Draw a box around the current voxel under the mouse.
            if (currentHoverVoxel.IsValid && DrawVoxel)
            {
                BoundingBox box = currentHoverVoxel.GetBoundingBox().Expand(0.05f);
                Drawer3D.DrawBox(box, CurrentColor, CurrentWidth, true);
            }

            HandleMouseButton(mouse.LeftButton, currentHoverVoxel, isNewVoxelUnderMouse, altPressed, ref isLeftPressed, InputManager.MouseButton.Left);
            HandleMouseButton(mouse.RightButton, currentHoverVoxel, isNewVoxelUnderMouse, altPressed, ref isRightPressed, InputManager.MouseButton.Right);
        }
Ejemplo n.º 2
0
        public bool CanBuildHere(List <VoxelHandle> Voxels, WorldManager World)
        {
            if (Voxels.Count == 0)
            {
                return(false);
            }

            if (World.EnumerateZones().Where(room => room.Type.Name == this.Name).Count() + 1 > MaxNumRooms)
            {
                World.UserInterface.ShowTooltip(String.Format("We can only build {0} {1}. Destroy the existing to build a new one.", MaxNumRooms, Name));
                return(false);
            }

            if (Voxels.Any(v => World.PersistentData.Designations.GetVoxelDesignation(v, DesignationType._All).HasValue(out var _)))
            {
                World.UserInterface.ShowTooltip("Something else is designated for this area.");
                return(false);
            }

            List <BoundingBox> boxes = Voxels.Select(voxel => voxel.GetBoundingBox()).ToList();
            BoundingBox        box   = MathFunctions.GetBoundingBox(boxes);

            Vector3 extents = box.Max - box.Min;

            float maxExtents = Math.Max(extents.X, extents.Z);
            float minExtents = Math.Min(extents.X, extents.Z);

            if (maxExtents < MinimumSideLength || minExtents < MinimumSideWidth)
            {
                World.UserInterface.ShowTooltip("Room is too small (minimum is " + MinimumSideLength + " x " + MinimumSideWidth + ")!");
                return(false);
            }

            int height = Voxels[0].Coordinate.Y;

            foreach (var voxel in Voxels)
            {
                if (voxel.IsEmpty)
                {
                    World.UserInterface.ShowTooltip("Room must be built on solid ground.");
                    return(false);
                }

                var above = VoxelHelpers.GetVoxelAbove(voxel);

                if (above.IsValid && !above.IsEmpty)
                {
                    World.UserInterface.ShowTooltip("Room must be built in free space.");
                    return(false);
                }

                if (voxel.Type.IsInvincible)
                {
                    continue;
                }

                if (height != (int)voxel.Coordinate.Y)
                {
                    World.UserInterface.ShowTooltip("Room must be on flat ground!");
                    return(false);
                }

                if (!CanBuildAboveGround && voxel.Sunlight)
                {
                    World.UserInterface.ShowTooltip("Room can't be built aboveground!");
                    return(false);
                }

                if (!CanBuildBelowGround && !voxel.Sunlight)
                {
                    World.UserInterface.ShowTooltip("Room can't be built belowground!");
                    return(false);
                }

                if (World.IsInZone(voxel) || World.IsBuildDesignation(voxel))
                {
                    World.UserInterface.ShowTooltip("Room's can't overlap!");
                    return(false);
                }
            }

            return(true);
        }