Ejemplo n.º 1
0
        public override void Update(DwarfGame game, DwarfTime time)
        {
            if (World.UserInterface.IsCameraRotationModeActive())
            {
                World.UserInterface.VoxSelector.Enabled = false;
                World.UserInterface.SetMouse(null);
                World.UserInterface.BodySelector.Enabled = false;
                return;
            }

            World.UserInterface.VoxSelector.SelectionType = VoxelSelectionType.SelectEmpty;
            World.UserInterface.VoxSelector.Enabled       = true;
            World.UserInterface.BodySelector.Enabled      = false;

            if (World.UserInterface.IsMouseOverGui)
            {
                World.UserInterface.SetMouse(World.UserInterface.MousePointer);
            }
            else
            {
                World.UserInterface.SetMouse(new Gui.MousePointer("mouse", 1, 4));
            }

            if (PreviewBody == null || !World.UserInterface.VoxSelector.VoxelUnderMouse.IsValid)
            {
                return;
            }

            HandleOrientation();

            PreviewBody.LocalPosition = World.UserInterface.VoxSelector.VoxelUnderMouse.WorldPosition + new Vector3(0.5f, 0.0f, 0.5f) + CraftType.Placement_SpawnOffset;
            PreviewBody.UpdateTransform();
            PreviewBody.PropogateTransforms();

            foreach (var tinter in PreviewBody.EnumerateAll().OfType <Tinter>())
            {
                tinter.Stipple = true;
            }

            if (OverrideOrientation)
            {
                PreviewBody.Orient(Orientation);
            }
            else
            {
                PreviewBody.OrientToWalls();
            }

            var valid = ObjectHelper.IsValidPlacement(World.UserInterface.VoxSelector.VoxelUnderMouse, CraftType, World, PreviewBody, "build", "built");

            PreviewBody.SetVertexColorRecursive(valid ? GameSettings.Current.Colors.GetColor("Positive", Color.Green) : GameSettings.Current.Colors.GetColor("Negative", Color.Red));

            if (valid && CraftType.Placement_AllowRotation)
            {
                World.UserInterface.ShowTooltip("Click to build. Press R/T to rotate.");
            }
        }
Ejemplo n.º 2
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.Placement_SpawnOffset;
                    Vector3 startPos = pos + new Vector3(0.0f, -0.1f, 0.0f);

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

                    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 PlaceObjectTask(newDesignation));

                    if (!HandlePlaceExistingUpdate())
                    {
                        PreviewBody = null;
                        World.UserInterface.ShowToolPopup("Unable to place any more.");
                        World.UserInterface.ChangeTool("SelectUnits");
                    }
                    else
                    {
                        PreviewBody = CreatePreviewBody();
                    }
                }

                break;
            }

            case (InputManager.MouseButton.Right):
            {
                var designation = World.PersistentData.Designations.EnumerateEntityDesignations(DesignationType.PlaceObject).Select(d => d.Tag as PlacementDesignation).FirstOrDefault(d => d.Location == World.UserInterface.VoxSelector.VoxelUnderMouse);
                if (designation != null && World.PersistentData.Designations.GetEntityDesignation(designation.Entity, DesignationType.PlaceObject).HasValue(out var realDesignation))
                {
                    World.TaskManager.CancelTask(realDesignation.Task);
                }
                break;
            }
            }
        }
Ejemplo n.º 3
0
        public override void Update(DwarfGame game, DwarfTime time)
        {
            if (Player.IsCameraRotationModeActive())
            {
                return;
            }

            Player.VoxSelector.Enabled  = false;
            Player.BodySelector.Enabled = false;

            if (Player.World.IsMouseOverGui)
            {
                Player.World.SetMouse(Player.World.MousePointer);
            }
            else
            {
                Player.World.SetMouse(new Gui.MousePointer("mouse", 1, 9));
            }

            MouseState mouse = Mouse.GetState();


            if (State == ToolState.Selecting)
            {
                if (SelectedBody != null)
                {
                    foreach (var tinter in SelectedBody.GetRoot().EnumerateAll().OfType <Tinter>())
                    {
                        tinter.VertexColorTint = Color.White;
                        tinter.Stipple         = false;
                    }
                }

                SelectedBody = Player.World.ComponentManager.SelectRootBodiesOnScreen(new Rectangle(mouse.X, mouse.Y, 1, 1), Player.World.Camera)
                               .Where(body => body.Tags.Contains("Moveable"))
                               .FirstOrDefault();

                if (SelectedBody != null)
                {
                    if (SelectedBody.IsReserved)
                    {
                        Player.World.ShowTooltip("Can't move this " + SelectedBody.Name + "\nIt is being used.");
                    }
                    else
                    {
                        Player.World.ShowTooltip("Left click and drag to move this " + SelectedBody.Name);
                        foreach (var tinter in SelectedBody.GetRoot().EnumerateAll().OfType <Tinter>())
                        {
                            tinter.VertexColorTint = Color.Blue;
                            tinter.Stipple         = false;
                        }
                    }

                    if (mouse.LeftButton == ButtonState.Pressed)
                    {
                        StartDragging(SelectedBody);
                    }
                }
            }
            else if (State == ToolState.Dragging)
            {
                if (SelectedBody == null)
                {
                    throw new InvalidProgramException();
                }

                var craftDetails = SelectedBody.GetRoot().GetComponent <CraftDetails>();
                if (craftDetails != null && CraftLibrary.GetCraftable(craftDetails.CraftType).AllowRotation)
                {
                    HandleOrientation();
                    Player.World.ShowToolPopup(String.Format("Press {0}/{1} to rotate.", ControlSettings.Mappings.RotateObjectLeft, ControlSettings.Mappings.RotateObjectRight));
                }

                var voxelUnderMouse = Player.VoxSelector.VoxelUnderMouse;
                if (voxelUnderMouse.IsValid && voxelUnderMouse.IsEmpty)
                {
                    var       spawnOffset = Vector3.Zero;
                    CraftItem craftItem   = null;

                    if (craftDetails != null)
                    {
                        craftItem = CraftLibrary.GetCraftable(craftDetails.CraftType);
                        if (craftItem != null)
                        {
                            spawnOffset = craftItem.SpawnOffset;
                        }
                        else
                        {
                            Console.Error.WriteLine("{0} had no craft item.", craftDetails.CraftType);
                        }
                    }


                    if (craftItem == null)
                    {
                        return;
                    }

                    SelectedBody.LocalPosition = voxelUnderMouse.WorldPosition + new Vector3(0.5f, 0.0f, 0.5f) + spawnOffset;
                    SelectedBody.UpdateTransform();

                    if (OverrideOrientation)
                    {
                        SelectedBody.Orient(CurrentOrientation);
                    }
                    else
                    {
                        SelectedBody.OrientToWalls();
                    }

                    SelectedBody.PropogateTransforms();

                    var validPlacement = ObjectHelper.IsValidPlacement(voxelUnderMouse, craftItem, Player, SelectedBody, "move", "moved");

                    foreach (var tinter in SelectedBody.GetRoot().EnumerateAll().OfType <Tinter>())
                    {
                        tinter.VertexColorTint = validPlacement ? Color.Green : Color.Red;
                        tinter.Stipple         = true;
                    }

                    if (mouse.LeftButton == ButtonState.Released)
                    {
                        if (validPlacement)
                        {
                        }
                        else
                        {
                            SelectedBody.LocalTransform = OrigTransform;
                            SelectedBody.PropogateTransforms();
                        }

                        foreach (var tinter in SelectedBody.GetRoot().EnumerateAll().OfType <Tinter>())
                        {
                            tinter.VertexColorTint = Color.White;
                            tinter.Stipple         = false;
                        }

                        State = ToolState.Selecting;
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public override void OnVoxelsSelected(List <VoxelHandle> voxels, InputManager.MouseButton button)
        {
            switch (button)
            {
            case (InputManager.MouseButton.Left):
            {
                if (ObjectHelper.IsValidPlacement(Player.VoxSelector.VoxelUnderMouse, CraftType, Player, PreviewBody, "build", "built"))
                {
                    PreviewBody.SetFlag(GameComponent.Flag.ShouldSerialize, true);

                    Vector3 pos      = Player.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            = Player.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.Master.TaskManager.AddTask(new CraftItemTask(newDesignation));


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

                    PreviewBody = CreatePreviewBody();
                }

                break;
            }

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