示例#1
0
        public override void OnVoxelsSelected(List <VoxelHandle> voxels, InputManager.MouseButton button)
        {
            switch (button)
            {
            case (InputManager.MouseButton.Left):
            {
                if (ObjectHelper.IsValidPlacement(World.UserInterface.VoxSelector.VoxelUnderMouse, CraftType, World, PreviewBody, "build", "built"))
                {
                    PreviewBody.SetFlag(GameComponent.Flag.ShouldSerialize, true);

                    Vector3 pos      = World.UserInterface.VoxSelector.VoxelUnderMouse.WorldPosition + new Vector3(0.5f, 0.0f, 0.5f) + CraftType.SpawnOffset;
                    Vector3 startPos = pos + new Vector3(0.0f, -0.1f, 0.0f);

                    CraftDesignation newDesignation = new CraftDesignation()
                    {
                        ItemType            = CraftType,
                        Location            = World.UserInterface.VoxSelector.VoxelUnderMouse,
                        Orientation         = Orientation,
                        OverrideOrientation = OverrideOrientation,
                        Valid             = true,
                        Entity            = PreviewBody,
                        SelectedResources = SelectedResources,
                        WorkPile          = new WorkPile(World.ComponentManager, startPos)
                    };

                    if (Mode == PlacementMode.PlaceExisting)
                    {
                        newDesignation.ExistingResource = ExistingPlacement;
                    }

                    World.ComponentManager.RootComponent.AddChild(newDesignation.WorkPile);
                    newDesignation.WorkPile.AnimationQueue.Add(new EaseMotion(1.1f, Matrix.CreateTranslation(startPos), pos));
                    World.ParticleManager.Trigger("puff", pos, Color.White, 10);

                    World.TaskManager.AddTask(new CraftItemTask(newDesignation));


                    if (Mode == PlacementMode.PlaceExisting && !HandlePlaceExistingUpdate())
                    {
                        World.UserInterface.ShowToolPopup("Unable to place any more.");
                        Mode = PlacementMode.BuildNew;
                    }

                    PreviewBody = CreatePreviewBody();
                }

                break;
            }

            case (InputManager.MouseButton.Right):
            {
                var designation = World.PersistentData.Designations.EnumerateEntityDesignations(DesignationType.Craft).Select(d => d.Tag as CraftDesignation).FirstOrDefault(d => d.Location == World.UserInterface.VoxSelector.VoxelUnderMouse);
                if (designation != null)
                {
                    var realDesignation = World.PersistentData.Designations.GetEntityDesignation(designation.Entity, DesignationType.Craft);
                    if (realDesignation != null)
                    {
                        World.TaskManager.CancelTask(realDesignation.Task);
                    }
                }
                break;
            }
            }
        }