Ejemplo n.º 1
0
        public void Interaction(object msg)
        {
            // Make sure we get the message type we are expecting.
            InteractionMessage interactionMsg = msg as InteractionMessage;

            if (interactionMsg == null)
            {
                return;
            }

            // Interacting with an item means picking it up. Answer by sending the item to the sender.
            interactionMsg.Sender[AddItemTrigger] |= new AddItemMessage(RepresentedItem);

            // And remove this entity.
            ContainingWorld.RemoveEntity(thisEntity);
        }
Ejemplo n.º 2
0
        public void Interaction(object msg)
        {
            // Make sure we get the message type we are expecting.
            InteractionMessage interactionMsg = msg as InteractionMessage;

            if (interactionMsg == null)
            {
                return;
            }

            // Interacting with an item means picking it up. Answer by sending the item to the sender.
            interactionMsg.Sender[AddItemTrigger] |= new AddItemMessage(new ToolItem(ToolType.DroneChain));

            // Remove drone from drone constraints.
            Owner.RemoveDrone(this);
            // And remove this entity.
            ContainingWorld.RemoveEntity(thisEntity);
        }
Ejemplo n.º 3
0
        void HandlePressInput(object sender, InputPressArgs e)
        {
            if (!Rendering.MainViewport.HasFocus)
            {
                return;
            }

            // Scale the area using + and - keys.
            // Translate it using up down left right (x, z)
            // and PageUp PageDown (y).
            if (e.PressType == InputPressArgs.KeyPressType.Down)
            {
                switch (e.Key)
                {
                case InputKey.Shift:
                    keyModifierShift = true;
                    break;

                case InputKey.Control:
                    keyModifierControl = true;
                    break;

                case InputKey.Alt:
                    keyModifierAlt = true;
                    break;

                case InputKey.F8:
                    Renderer.Opaque.Mesh.DebugWireframe = !Renderer.Opaque.Mesh.DebugWireframe;
                    break;

                case InputKey.Q:
                    if (Inventory.Selection != null)
                    {
                        DropItem(Inventory.Selection);
                    }
                    break;

                // F1 resets the player position
                case InputKey.F1:
                    character.Body.SetTransformation(mat4.Translate(new vec3(0, 10f, 0)));
                    break;

                // Tab and shift-Tab cycle between digging shapes
                case InputKey.Tab:

                    if (!keyModifierControl)
                    {
                        int vals   = Enum.GetValues(typeof(DiggingShape)).Length;
                        int offset = keyModifierShift ? vals - 1 : 1;
                        CurrentDiggingShape = (DiggingShape)(((uint)CurrentDiggingShape + offset) % vals);
                    }
                    else
                    {
                        int vals   = Enum.GetValues(typeof(DiggingAlignment)).Length;
                        int offset = keyModifierShift ? vals - 1 : 1;
                        CurrentDiggingAlignment = (DiggingAlignment)(((uint)CurrentDiggingAlignment + offset) % vals);
                    }

                    // Reselect to refresh shape
                    if (Inventory.Selection != null)
                    {
                        Inventory.Selection.OnDeselect(this);
                        Inventory.Selection.OnSelect(this);
                    }

                    break;

                default:
                    break;
                }

                // Quickaccess items.
                if (InputKey.Key1 <= e.Key && e.Key <= InputKey.Key9)
                {
                    Inventory.Select((int)e.Key - (int)InputKey.Key1);
                }
                if (e.Key == InputKey.Key0)
                {
                    Inventory.Select(9); // Special '0'.
                }
            }
            else if (e.PressType == InputPressArgs.KeyPressType.Up)
            {
                switch (e.Key)
                {
                case InputKey.Shift:
                    keyModifierShift = false;
                    break;

                case InputKey.Control:
                    keyModifierControl = false;
                    break;

                case InputKey.Alt:
                    keyModifierAlt = false;
                    break;
                }
            }

            // Following interactions are only possible if UI is not open.
            if (!Gui.IsInventoryOpen)
            {
                float minRayQueryRange;
                float maxRayQueryRange;
                if (!LocalScript.NoclipEnabled)
                {
                    minRayQueryRange = minRayQueryDistancePlayer;
                    maxRayQueryRange = maxRayQueryDistancePlayer;
                }
                else
                {
                    minRayQueryRange = minRayQueryDistanceNoClip;
                    maxRayQueryRange = maxRayQueryDistanceNoClip;
                }

                // If left mouse click is detected, we want to execute a rayquery and report a "OnUse" to the selected item.
                if (Inventory.Selection != null && e.Key == InputKey.MouseLeft && e.PressType == InputPressArgs.KeyPressType.Down)
                {
                    // Send a ray query to find the position on the terrain we are looking at.
                    ContainingWorld.Physics.RayQuery(camera.Position + camera.ForwardDirection * minRayQueryRange, camera.Position + camera.ForwardDirection * maxRayQueryRange, delegate(bool _hit, vec3 _position, vec3 _normal, RigidBody _body, bool _hasTerrainCollision)
                    {
                        // Receiving the async ray query result here
                        if (_hit)
                        {
                            Entity _hitEntity = null;
                            if (_body != null && _body.RefComponent != null)
                            {
                                _hitEntity = _body.RefComponent.Entity;
                            }

                            /// Subtract a few cm toward camera to increase stability near constraints.
                            _position -= camera.ForwardDirection * .04f;

                            // Use currently selected item.
                            if (e.Key == InputKey.MouseLeft)
                            {
                                Item selection = Inventory.Selection;
                                if (selection != null)
                                {
                                    selection.OnUse(this, _position, _normal, _hitEntity);
                                }
                            }
                        }
                    });
                }

                if (e.Key == InputKey.E && e.PressType == InputPressArgs.KeyPressType.Down)
                {
                    ContainingWorld.Physics.RayQuery(camera.Position + camera.ForwardDirection * minRayQueryRange, camera.Position + camera.ForwardDirection * maxRayQueryRange, delegate(bool _hit, vec3 _position, vec3 _normal, RigidBody _body, bool _hasTerrainCollision)
                    {
                        // Receiving the async ray query result here
                        if (_body != null && _body.RefComponent != null)
                        {
                            Entity entity = _body.RefComponent.Entity;
                            if (entity != null)
                            {
                                TriggerId trigger = TriggerId.getIdByName("Interaction");
                                entity[trigger]  |= new InteractionMessage(thisEntity);
                            }
                        }
                    });
                }
            }
        }