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

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

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

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

            HandleOrientation();

            PreviewBody.LocalPosition = Player.VoxSelector.VoxelUnderMouse.WorldPosition + new Vector3(0.5f, 0.0f, 0.5f) + CraftType.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(Player.VoxSelector.VoxelUnderMouse, CraftType, Player, PreviewBody, "build", "built");

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

            if (valid && CraftType.AllowRotation)
            {
                World.ShowTooltip("Click to build. Press R/T to rotate.");
            }
        }
Exemplo n.º 2
0
        public override void OnEnd()
        {
            Player.VoxSelector.DrawBox   = true;
            Player.VoxSelector.DrawVoxel = true;

            if (PreviewBody != null)
            {
                PreviewBody.GetRoot().Delete();
                PreviewBody = null;
            }

            CraftType = null;
        }
Exemplo n.º 3
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;
            }
            }
        }