示例#1
0
        public void VoxelsSelected(List <VoxelHandle> refs, InputManager.MouseButton button)
        {
            if (!IsEnabled)
            {
                return;
            }
            switch (button)
            {
            case (InputManager.MouseButton.Left):
            {
                List <Task> assignments = new List <Task>();
                // Creating multiples doesn't work anyway - kill it.
                foreach (var r in refs)
                {
                    if (IsDesignation(r) || !r.IsValid || !r.IsEmpty)
                    {
                        continue;
                    }
                    else
                    {
                        Vector3 pos = r.WorldPosition + new Vector3(0.5f, 0.0f, 0.5f) + CurrentCraftType.SpawnOffset;

                        Vector3 startPos = pos + new Vector3(0.0f, -0.1f, 0.0f);
                        Vector3 endPos   = pos;
                        // TODO: Why are we creating a new designation?
                        CraftDesignation newDesignation = new CraftDesignation()
                        {
                            ItemType            = CurrentCraftType,
                            Location            = r,
                            Orientation         = CurrentDesignation.Orientation,
                            OverrideOrientation = CurrentDesignation.OverrideOrientation,
                            Valid             = true,
                            Entity            = CurrentCraftBody,
                            SelectedResources = SelectedResources
                        };

                        if (IsValid(newDesignation))
                        {
                            AddDesignation(newDesignation, CurrentCraftType.SpawnOffset);
                            assignments.Add(new CraftItemTask(newDesignation));

                            // Todo: Maybe don't support create huge numbers of entities at once?
                            CurrentCraftBody = EntityFactory.CreateEntity <Body>(CurrentCraftType.Name, r.WorldPosition,
                                                                                 Blackboard.Create <List <ResourceAmount> >("Resources", SelectedResources));
                            EntityFactory.GhostEntity(CurrentCraftBody, Color.White);

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

                if (assignments.Count > 0)
                {
                    World.Master.TaskManager.AddTasks(assignments);
                }

                break;
            }

            case (InputManager.MouseButton.Right):
            {
                foreach (var r in refs)
                {
                    if (!IsDesignation(r))
                    {
                        continue;
                    }
                    RemoveDesignation(r);
                }
                break;
            }
            }
        }
示例#2
0
        public void Update(DwarfTime gameTime, GameMaster player)
        {
            if (!IsEnabled)
            {
                if (CurrentCraftBody != null)
                {
                    CurrentCraftBody.Delete();
                    CurrentCraftBody = null;
                }

                return;
            }

            if (Faction == null)
            {
                Faction = player.Faction;
            }

            if (CurrentCraftType != null && CurrentCraftBody == null)
            {
                CurrentCraftBody = EntityFactory.CreateEntity <Body>(CurrentCraftType.Name,
                                                                     player.VoxSelector.VoxelUnderMouse.WorldPosition,
                                                                     Blackboard.Create <List <ResourceAmount> >("Resources", SelectedResources));
                EntityFactory.GhostEntity(CurrentCraftBody, Color.White);

                CurrentDesignation = new CraftDesignation()
                {
                    ItemType = CurrentCraftType,
                    Location = VoxelHandle.InvalidHandle,
                    Valid    = true
                };

                OverrideOrientation = false;
                CurrentCraftBody.SetTintRecursive(Color.Green);
            }

            if (CurrentCraftBody == null || !player.VoxSelector.VoxelUnderMouse.IsValid)
            {
                return;
            }

            CurrentCraftBody.LocalPosition = player.VoxSelector.VoxelUnderMouse.WorldPosition + new Vector3(0.5f, 0.0f, 0.5f) + CurrentCraftType.SpawnOffset;

            CurrentCraftBody.GlobalTransform = CurrentCraftBody.LocalTransform;
            CurrentCraftBody.UpdateTransform();
            CurrentCraftBody.PropogateTransforms();
            if (OverrideOrientation)
            {
                CurrentCraftBody.Orient(CurrentOrientation);
            }
            else
            {
                CurrentCraftBody.OrientToWalls();
            }

            HandleOrientation();

            if (CurrentDesignation != null)
            {
                if (CurrentDesignation.Location.Equals(player.VoxSelector.VoxelUnderMouse))
                {
                    return;
                }

                CurrentDesignation.Location = player.VoxSelector.VoxelUnderMouse;

                World.ShowTooltip("Click to build. Press R/T to rotate.");
                CurrentCraftBody.SetTintRecursive(IsValid(CurrentDesignation) ? Color.Green : Color.Red);
            }
        }