public override void OnInspectorGUI()
    {
        KeyBehaviour keyBehaviour = target as KeyBehaviour;

        remove = -1;

        EditorGUILayout.LabelField("List", EditorStyles.whiteLargeLabel);

        foreach (KeyBehaviour.Entry i in keyBehaviour.listEntry)
        {
            EditorGUILayout.BeginHorizontal();
            i.key   = EditorGUILayout.TextField(i.key);
            i.value = EditorGUILayout.IntField(i.value);
            if (GUILayout.Button("remove"))
            {
                remove = keyBehaviour.listEntry.IndexOf(i);
            }
            EditorGUILayout.EndHorizontal();
        }

        if (GUILayout.Button("ADD"))
        {
            keyBehaviour.listEntry.Add(new KeyBehaviour.Entry());
        }
        if (remove >= 0)
        {
            keyBehaviour.listEntry.RemoveAt(remove);
        }
    }
示例#2
0
 public void Spawn(Vector3 newposition)
 {
     if (currentBehaviour == KeyBehaviour.NONE || currentBehaviour == KeyBehaviour.HIDING)
     {
         currentBehaviour = KeyBehaviour.RESPAWNING;
         desiredPosition  = newposition;
     }
 }
 protected override void OnKeyReleased(KeyBehaviour key)
 {
     base.OnKeyReleased(key);
     if (pressed)
     {
         pressed = false;
     }
 }
示例#4
0
        public static void SetKeyBehaviour(DependencyObject property, KeyBehaviour value)
        {
            if (property == null)
            {
                throw new System.ArgumentNullException(nameof(property));
            }

            property.SetValue(KeyBehaviourProperty, value);
        }
示例#5
0
        public void GetBehaviour()
        {
            MockInputSimulator inputSimulator = new MockInputSimulator();
            TestabelKeyboard   keyboard       = CreateKeyboard(inputSimulator);

            MockButton btn = keyboard.Children[3] as MockButton;

            KeyBehaviour behaviour = Keyboard.GetKeyBehaviour(btn);

            Assert.AreEqual(KeyBehaviour.VirtualKey, behaviour);
        }
示例#6
0
        private static void RecreateKey(UIElement child)
        {
            if (child == null)
            {
                return;
            }

            if (!(VisualTreeHelper.GetParent(child) is Keyboard parentKeyboard) || parentKeyboard.keys == null)
            {
                return;
            }

            // make sure key exist. If it's behavour is none it will not exist
            if (parentKeyboard.keys.ContainsKey(child))
            {
                LogicalKey oldKey = parentKeyboard.keys[child];

                parentKeyboard.keys.Remove(child);
                parentKeyboard.modifierKeys.Remove(oldKey as ModifierKeyBase);
            }

            VirtualKeyCode       keyCode      = (VirtualKeyCode)child.GetValue(KeyCodeProperty);
            KeyBehaviour         keyBehaviour = (KeyBehaviour)child.GetValue(KeyBehaviourProperty);
            VirtualKeyCollection chordKeys    = (VirtualKeyCollection)child.GetValue(ChordKeysProperty);
            string outputText = (string)child.GetValue(OutputTextProperty);

            if (keyBehaviour == KeyBehaviour.None)
            {
                // do not create a new key
                return;
            }

            LogicalKey key = CreateKey(keyCode, parentKeyboard.inputSimulator, keyBehaviour, chordKeys, outputText);

            if (key == null)
            {
                return;
            }

            parentKeyboard.keys.Add(child, key);
            key.KeyPressed += parentKeyboard.LogicalKeyPressed;

            if (keyBehaviour == KeyBehaviour.InstantaneousModifier || keyBehaviour == KeyBehaviour.TogglingModifier)
            {
                parentKeyboard.modifierKeys.Add(key as ModifierKeyBase);
            }
        }
示例#7
0
    // Update is called once per frame
    void Update()
    {
        if (!isBound)
        {
            isBound = true;
            foreach (GameObject key in GameObject.FindGameObjectsWithTag("Key"))
            {
                KeyBehaviour keyBehavour = key.GetComponent <KeyBehaviour>();
                if (keyBehavour && keyBehavour.keyColor == lockColor)
                {
                    key.GetComponent <PickupBehaviour>().onPickUp.AddListener(KeyCollected);
                }
            }
        }

        if (!raiseBehaviour.isRaised)
        {
            Color c = keyholeRenderer.material.color;
            c.a = Mathf.Lerp(1.0f, 0.2f, raiseBehaviour.raiseDeltaT);
            keyholeRenderer.material.color = c;
        }
    }
示例#8
0
        public override void EndInit()
        {
            inputSimulator = CreateInputSimulator();
            keys           = new Dictionary <UIElement, LogicalKey>();
            modifierKeys   = new List <ModifierKeyBase>();

            foreach (UIElement child in Children)
            {
                VirtualKeyCode       keyCode      = (VirtualKeyCode)child.GetValue(KeyCodeProperty);
                KeyBehaviour         keyBehaviour = (KeyBehaviour)child.GetValue(KeyBehaviourProperty);
                VirtualKeyCollection chordKeys    = (VirtualKeyCollection)child.GetValue(ChordKeysProperty);
                string outputText = (string)child.GetValue(OutputTextProperty);

                if (keyBehaviour == KeyBehaviour.None)
                {
                    // skip to the next child element
                    continue;
                }

                LogicalKey key = CreateKey(keyCode, inputSimulator, keyBehaviour, chordKeys, outputText);
                if (key == null)
                {
                    // skip to the next child element
                    continue;
                }

                ConnectToChildControl(child);
                keys.Add(child, key);
                key.KeyPressed += LogicalKeyPressed;

                if (keyBehaviour == KeyBehaviour.InstantaneousModifier || keyBehaviour == KeyBehaviour.TogglingModifier)
                {
                    modifierKeys.Add(key as ModifierKeyBase);
                }
            }

            SynchroniseModifierKeyState();
            base.EndInit();
        }
示例#9
0
 protected override void OnKeyPressed(KeyBehaviour field)
 {
     base.OnKeyPressed(field);
     StimulateCenter();
 }
示例#10
0
 protected virtual void OnKeyPressed(KeyBehaviour field)
 {
 }
 protected override void OnKeyPressed(KeyBehaviour field)
 {
     base.OnKeyPressed(field);
     TurnManager.Instance.FieldPressed(this);
 }
示例#12
0
 public void TurnKey()
 {
     desiredRotation.X = 0;
     currentBehaviour  = KeyBehaviour.TURNINGIN;
 }
示例#13
0
 public void Hide()
 {
     currentBehaviour  = KeyBehaviour.DISAPPEARING;
     desiredRotation.X = -MathHelper.PiOver2;
 }
示例#14
0
 protected virtual void OnKeyReleased(KeyBehaviour field)
 {
 }
示例#15
0
        public override void Update(GameTime gameTime)
        {
            switch (currentBehaviour)
            {
            case KeyBehaviour.HIDING:
                this.transparency = 0;
                break;

            case KeyBehaviour.RESPAWNING:
                if (this.transparency == 0)
                {
                    position         = desiredPosition;
                    xrotation        = desiredRotation.X;
                    yrotation        = desiredRotation.Y;
                    zrotation        = desiredRotation.Z;
                    currentBehaviour = KeyBehaviour.APPEARING;
                }
                else
                {
                    this.transparency = MathHelper.Clamp(this.transparency - (float)gameTime.ElapsedGameTime.TotalSeconds, 0, 1);
                }
                break;

            case KeyBehaviour.APPEARING:
                if (this.transparency == 1)
                {
                    currentBehaviour = KeyBehaviour.NONE;
                }
                else
                {
                    this.transparency = MathHelper.Clamp(this.transparency + (float)gameTime.ElapsedGameTime.TotalSeconds, 0, 1);
                }
                break;

            case KeyBehaviour.DISAPPEARING:
                if (this.transparency == 0)
                {
                    currentBehaviour = KeyBehaviour.HIDING;
                }
                else
                {
                    this.transparency = MathHelper.Clamp(this.transparency - (float)gameTime.ElapsedGameTime.TotalSeconds, 0, 1);
                }
                break;

            case KeyBehaviour.TURNINGIN:
                xrotation = MathHelper.Lerp(xrotation, desiredRotation.X, (float)gameTime.ElapsedGameTime.TotalSeconds * 5);
                if (Math.Abs(xrotation - desiredRotation.X) < 0.01f)
                {
                    desiredRotation.X = -MathHelper.PiOver2;
                    currentBehaviour  = KeyBehaviour.NONE;
                }
                break;

            default:
                position.X = MathHelper.Lerp(position.X, desiredPosition.X, (float)gameTime.ElapsedGameTime.TotalSeconds * 5);
                position.Y = MathHelper.Lerp(position.Y, desiredPosition.Y, (float)gameTime.ElapsedGameTime.TotalSeconds * 5);
                position.Z = MathHelper.Lerp(position.Z, desiredPosition.Z, (float)gameTime.ElapsedGameTime.TotalSeconds * 5);
                xrotation  = MathHelper.Lerp(xrotation, desiredRotation.X, (float)gameTime.ElapsedGameTime.TotalSeconds * 5);
                yrotation  = MathHelper.Lerp(yrotation, desiredRotation.Y, (float)gameTime.ElapsedGameTime.TotalSeconds * 5);
                zrotation  = MathHelper.Lerp(zrotation, desiredRotation.Z, (float)gameTime.ElapsedGameTime.TotalSeconds * 5);
                break;
            }

            /*sphere.Center = position;
             * if (selected && yrotation > -MathHelper.PiOver2)
             * {
             *  yrotation -= (float)gameTime.ElapsedGameTime.TotalSeconds * 1.5f;
             * }*/
        }
 protected override void OnKeyPressed(KeyBehaviour key)
 {
     base.OnKeyPressed(key);
     Press(transform.up);
 }
示例#17
0
        private static LogicalKey CreateKey(VirtualKeyCode keyCode, IInputSimulator inputSimulator, KeyBehaviour keyType, VirtualKeyCollection chordKeys, string outputText)
        {
            LogicalKey result = null;

            switch (keyType)
            {
            case KeyBehaviour.VirtualKey:
                result = CreateVirtualKey(keyCode, inputSimulator);
                break;

            case KeyBehaviour.Chord:
                result = CreateChordKey(keyCode, inputSimulator, chordKeys);
                break;

            case KeyBehaviour.Text:
                result = CreateTextKey(keyCode, inputSimulator, outputText);
                break;

            case KeyBehaviour.InstantaneousModifier:
                result = CreateInstantaneousModifierKey(keyCode, inputSimulator);
                break;

            case KeyBehaviour.TogglingModifier:
                result = CreateTogglingModifierKey(keyCode, inputSimulator);
                break;

            default:
                break;
            }

            return(result);
        }
示例#18
0
 protected virtual void Start()
 {
     keyBehaviour = GetComponent <KeyBehaviour>();
     keyBehaviour.onKeyPressed  += OnKeyPressed;
     keyBehaviour.onKeyReleased += OnKeyReleased;
 }
示例#19
0
 public void Disappear()
 {
     currentBehaviour = KeyBehaviour.DISAPPEARING;
 }
示例#20
0
    private void Populate(GameObject parent, KeyboardRow row, KeyboardSkin skin)
    {
        foreach (KeyboardObject keyboardObject in row.Keys)
        {
            GameObject keyObj = new GameObject(keyboardObject.Name);
            keyObj.transform.parent   = parent.transform;
            keyObj.transform.position = Vector3.zero;

            // Set key background image (rounded rectangle)
            Image backgroundImage = keyObj.AddComponent <Image>();
            backgroundImage.sprite = skin.GetKeyBackgroundImage();
            backgroundImage.type   = Image.Type.Sliced;
            backgroundImage.color  = skin.GetKeyBackgroundColor();

            if (keyboardObject is Spacer)
            {
                backgroundImage.color = Color.clear;
            }

            // Add the button
            Button button = keyObj.AddComponent <Button>();

            // Adds the shadow
            Shadow shadow = keyObj.AddComponent <Shadow>();
            shadow.effectColor    = new Color(0, 0, 0, 80);
            shadow.effectDistance = new Vector2(0, -0.5f);

            // Adjust width and height
            RectTransform rectTransform = keyObj.GetComponent <RectTransform>();
            rectTransform.sizeDelta     = new Vector2(keyboardObject.Width, keyboardObject.Height);
            rectTransform.localPosition = Vector3.zero;

            GameObject image = null;

            // Add image
            if (keyboardObject is ImageObjectButton imageObjectButton)
            {
                image = new GameObject("Image");
                image.transform.parent = keyObj.transform;

                Image img = image.AddComponent <Image>();
                img.sprite = skin.Load <Sprite>(imageObjectButton.ImageKey);

                RectTransform imgRectTransform = image.GetComponent <RectTransform>();
                imgRectTransform.sizeDelta     = new Vector2(10, 10);
                imgRectTransform.localPosition = new Vector3(0, 0, 0);
            }

            // Add text
            if (keyboardObject is TextButton TextButton)
            {
                var color = backgroundImage.color;

                backgroundImage.color = new Color(
                    color.r,
                    color.g,
                    color.b,
                    0.8f);

                TextButtonBehaviour textButtonBehaviour = keyObj.AddComponent <TextButtonBehaviour>();
                textButtonBehaviour.Init(TextButton, skin);

                if (keyboardObject is Key key)
                {
                    KeyBehaviour keyBehaviour = keyObj.AddComponent <KeyBehaviour>();
                    keyBehaviour.Init(textButtonBehaviour.Text);
                    _keys.Add(keyBehaviour);

                    button.onClick.AddListener(() => { Write(key.Name); });
                }
                else
                {
                    textButtonBehaviour.SlightlyDarker();
                }
            }

            if (keyboardObject is UppercaseToggle uppercaseToggle)
            {
                _uppercaseBehaviour = image.AddComponent <UppercaseToggleBehaviour>();
                _uppercaseBehaviour.Init(uppercaseToggle, skin);

                button.onClick.AddListener(ToggleUppercase);
            }

            if (keyboardObject is BackspaceButton)
            {
                button.onClick.AddListener(Backspace);
            }

            if (keyboardObject is SymbolsToggle toggle)
            {
                _toggleableTextButton = keyObj.AddComponent <ToggleableTextButtonBehaviour>();
                _toggleableTextButton.Init(toggle);

                button.onClick.AddListener(ToggleSymbols);
            }

            if (keyboardObject is SpaceBarButton)
            {
                button.onClick.AddListener(() => { Write(" "); });
            }
        }

        UpdateUppercase();
    }