예제 #1
0
파일: InputManager.cs 프로젝트: mrvux/xenko
        private void UpdateKeyboard()
        {
            pressedKeysSet.Clear();
            releasedKeysSet.Clear();
            KeyEvents.Clear();

            lock (KeyboardInputEvents)
            {
                foreach (KeyboardInputEvent keyboardInputEvent in KeyboardInputEvents)
                {
                    var key = keyboardInputEvent.Key;

                    if (key == Keys.None)
                    {
                        continue;
                    }

                    switch (keyboardInputEvent.Type)
                    {
                    case InputEventType.Down:
                        if (!IsKeyDown(key))     // prevent from several inconsistent pressed key due to OS repeat key
                        {
                            activeKeys[key] = true;
                            if (!keyboardInputEvent.OutOfFocus)
                            {
                                pressedKeysSet.Add(key);
                                KeyEvents.Add(new KeyEvent(key, KeyEventType.Pressed));
                            }
                            downKeysList.Add(key);
                        }
                        break;

                    case InputEventType.Up:
                        activeKeys[key] = false;
                        releasedKeysSet.Add(key);
                        KeyEvents.Add(new KeyEvent(key, KeyEventType.Released));
                        downKeysList.Remove(key);
                        break;

                    default:
                        throw new NotSupportedException();
                    }
                }

                KeyboardInputEvents.Clear();
            }

            if (LostFocus)
            {
                // Release keys/buttons when control focus is lost (this prevents some keys getting stuck when a focus loss happens)
                foreach (var key in downKeysList)
                {
                    releasedKeysSet.Add(key);
                    KeyEvents.Add(new KeyEvent(key, KeyEventType.Released));
                }
                activeKeys.Clear();
                downKeysList.Clear();
            }
        }
예제 #2
0
        private void UpdateKeyboard()
        {
            pressedKeysSet.Clear();
            releasedKeysSet.Clear();
            KeyEvents.Clear();

            lock (KeyboardInputEvents)
            {
                foreach (KeyboardInputEvent keyboardInputEvent in KeyboardInputEvents)
                {
                    var key = keyboardInputEvent.Key;

                    if (key == Keys.None)
                    {
                        continue;
                    }

                    switch (keyboardInputEvent.Type)
                    {
                    case InputEventType.Down:
                        if (!IsKeyDown(key))     // prevent from several inconsistent pressed key due to OS repeat key
                        {
                            activeKeys[key] = true;
                            pressedKeysSet.Add(key);

                            KeyEvents.Add(new KeyEvent(key, KeyEventType.Pressed));
                            downKeysList.Add(key);
                        }
                        break;

                    case InputEventType.Up:
                        activeKeys[key] = false;
                        releasedKeysSet.Add(key);
                        KeyEvents.Add(new KeyEvent(key, KeyEventType.Released));
                        downKeysList.Remove(key);
                        break;

                    default:
                        throw new NotSupportedException();
                    }
                }

                KeyboardInputEvents.Clear();
            }

            if (LostFocus)
            {
                activeKeys.Clear();
                downKeysList.Clear();
            }
        }
예제 #3
0
        public OtherCube(Level parent, BinaryReader reader)
        {
            PositionTrigger = new Point3D16(reader);
            MovingBlockSync = new IDReference <MovingPlatform>(parent.MovingPlatforms, reader.ReadInt16());
            if (MovingBlockSync.Index == -2)
            {
                DarkCubeRadius          = new Point2D8(reader);
                DarkCubeMovingBlockSync = new IDReference <MovingPlatform>(parent.MovingPlatforms, reader.ReadInt16());
            }
            var count = reader.ReadUInt16();

            PositionCube = new Point3D16(reader);
            for (var i = 0; i < count; i++)
            {
                KeyEvents.Add(new KeyEvent(reader));
            }
        }
예제 #4
0
 protected override void OnKeyDown(KeyEventArgs e)
 {
     KeyEvents.Add(e);
     base.OnKeyDown(e);
 }
예제 #5
0
        public OtherCube(Level parent, XElement element)
        {
            element.GetAttributeValue(out PositionTrigger, "PositionTrigger");
            var id   = element.GetAttributeValue("MovingBlockSync");
            var sync = id == null ? new IDReference <MovingPlatform>(parent.MovingPlatforms, -1)
                                  : new IDReference <MovingPlatform>(parent.MovingPlatforms, id);

            element.GetAttributeValueWithDefault(out DarkCubeRadius, "Radius");
            element.GetAttributeValue(out PositionCube, "PositionCube");
            foreach (var e in element.Elements())
            {
                try
                {
                    KeyEvents.Add(new KeyEvent(e));
                }
                catch
                {
                    if (!e.Name.LocalName.Equals("MovingPlatform", StringComparison.InvariantCultureIgnoreCase) &&
                        !e.Name.LocalName.Equals("Button", StringComparison.InvariantCultureIgnoreCase))
                    {
                        Warning.WriteLine(string.Format(Localization.UnrecognizedChildElement, e.Name, element.Name));
                    }
                }
            }
            if (element.Name == "OtherCube")
            {
                MovingBlockSync = sync;
                var mode          = element.GetAttributeValueWithDefault("Mode", OtherCubeMode.AutoHide);
                var moveDirection = element.GetAttributeValueWithDefault("MoveDirection", GetDefaultDirection(mode));
                if (mode == OtherCubeMode.Hole)
                {
                    PositionTrigger -= moveDirection;
                }
                AddHelper(parent, mode, PositionTrigger, moveDirection, element);
                if (DarkCubeRadius.Equals(default(Point2D8)))
                {
                    return;
                }
                var radius = DarkCubeRadius;
                DarkCubeRadius = default(Point2D8);
                for (var x = -radius.X; x <= radius.X; x++)
                {
                    for (var y = -radius.Y; y <= radius.Y; y++)
                    {
                        if (x != 0 || y != 0)
                        {
                            var position = PositionTrigger + new Point3D16((short)x, (short)y, 0);
                            parent.OtherCubes.Add(new OtherCube
                            {
                                PositionTrigger = position,
                                MovingBlockSync = MovingBlockSync,
                                PositionCube    = PositionCube,
                                KeyEvents       = KeyEvents
                            });
                            AddHelper(parent, mode, position, moveDirection, element);
                        }
                    }
                }
            }
            else
            {
                MovingBlockSync         = new IDReference <MovingPlatform>(parent.MovingPlatforms, -2);
                DarkCubeMovingBlockSync = sync;
            }
        }