Esempio n. 1
0
        private void UpdateMapping()
        {
            var mapping = ClientInputManager.GetMappingForAbstractButton(this.Button);

            this.PrimaryKeyText = InputKeyNameHelper.GetKeyText(mapping.PrimaryKey,
                                                                returnPlaceholderIfNone: false);
            this.SecondaryKeyText = InputKeyNameHelper.GetKeyText(mapping.SecondaryKey,
                                                                  returnPlaceholderIfNone: false);
        }
Esempio n. 2
0
        private void HandleKeyDown(InputKey key)
        {
            switch (key)
            {
            case InputKey.Escape:
                // binding cancelled
                this.onClose();
                return;

            //case InputKey.OemTilde:
            case InputKey.Control:
            case InputKey.Alt:
                this.Message = string.Format(MessageCannotBindToKey,
                                             InputKeyNameHelper.GetKeyText(key,
                                                                           returnPlaceholderIfNone: false));
                return;
            }

            if (this.lastPressedKey != key)
            {
                // player pressed another key - verify if there are collisions with other mapped buttons
                this.lastPressedKey = key;

                var buttons = ClientInputManager.GetButtonForKey(
                    key,
                    this.viewModelMapping.ButtonInfo.Category);

                foreach (var button in buttons)
                {
                    if (button.Equals(this.buttonToRebind))
                    {
                        // pressed a key already bound to this button - allow rebinding
                        break;
                    }

                    // pressed a different key
                    this.Message = string.Format(MessageFormatKeyAlreadyBound,
                                                 ClientInputManager.GetButtonInfo(button).Title);
                    return;
                }
            }

            // do remapping
            var mapping = ClientInputManager.GetMappingForAbstractButton(this.buttonToRebind);

            if (this.isSecondaryKey)
            {
                var secondaryKey = key;
                var primaryKey   = mapping.PrimaryKey != secondaryKey ? mapping.PrimaryKey : InputKey.None;
                mapping = new ButtonMapping(primaryKey, secondaryKey);
            }
            else
            {
                var primaryKey   = key;
                var secondaryKey = mapping.SecondaryKey != primaryKey ? mapping.SecondaryKey : InputKey.None;
                mapping = new ButtonMapping(primaryKey, secondaryKey);
            }

            ClientInputManager.SetAbstractButtonMapping(this.buttonToRebind, mapping);

            Api.GetProtoEntity <ControlsOptionsCategory>().NotifyModified();

            this.onClose();
        }