Esempio n. 1
0
        /// <summary>
        /// Called by the UIView when modal was popped without us knowing
        /// </summary>
        /// <param name="component">The button which temporarily was modal</param>
        private void OnKeybindModalPopped(UIComponent component)
        {
            var keybindButton = component as UIButton;

            if (keybindButton != null && currentlyEditedBinding_ != null)
            {
                keybindButton.text      = Keybind.ToLocalizedString(currentlyEditedBinding_.Value.TargetKey);
                currentlyEditedBinding_ = null;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Set the button text to welcoming message. Push the button as modal blocking
        /// everything else on screen and capturing the input.
        /// </summary>
        /// <param name="editable">The keysetting and inputkey inside it, to edit</param>
        /// <param name="keybindButton">The button to become modal</param>
        private void StartKeybindEditMode(KeybindSetting.Editable editable, UIButton keybindButton)
        {
            currentlyEditedBinding_ = editable;

            keybindButton.buttonsMask =
                UIMouseButton.Left | UIMouseButton.Right | UIMouseButton.Middle |
                UIMouseButton.Special0 | UIMouseButton.Special1 | UIMouseButton.Special2 |
                UIMouseButton.Special3;
            keybindButton.text = "Press key (or Esc)";
            keybindButton.Focus();
            UIView.PushModal(keybindButton, OnKeybindModalPopped);
        }
Esempio n. 3
0
        private void OnBindingMouseDown(UIComponent comp, UIMouseEventParameter evParam)
        {
            var editable      = (KeybindSetting.Editable)evParam.source.objectUserData;
            var keybindButton = evParam.source as UIButton;

            // This will only work if the user is not in the process of changing the shortcut
            if (currentlyEditedBinding_ == null)
            {
                evParam.Use();
                StartKeybindEditMode(editable, keybindButton);
            }
            else if (!Keybind.IsUnbindableMouseButton(evParam.buttons))
            {
                // This will work if the user clicks while the shortcut change is in progress
                evParam.Use();
                var editedBinding = currentlyEditedBinding_; // will be nulled by closing modal
                UIView.PopModal();

                var inputKey = SavedInputKey.Encode(Keybind.ButtonToKeycode(evParam.buttons),
                                                    Keybind.IsControlDown(),
                                                    Keybind.IsShiftDown(),
                                                    Keybind.IsAltDown());
                var category      = editable.Target.Category;
                var maybeConflict = FindConflict(editedBinding.Value, inputKey, category);
                if (maybeConflict != string.Empty)
                {
                    var message = Translation.Options.Get("Keybinds.Dialog.Text:Keybind conflict")
                                  + "\n\n" + maybeConflict;
                    Log.Info($"Keybind conflict: {message}");
                    UIView.library
                    .ShowModal <ExceptionPanel>("ExceptionPanel")
                    .SetMessage("Key Conflict", message, false);
                }
                else
                {
                    editedBinding.Value.TargetKey.value = inputKey;
                    editedBinding.Value.Target.NotifyKeyChanged();
                }

                keybindButton.buttonsMask = UIMouseButton.Left;
                keybindButton.text        = Keybind.ToLocalizedString(editedBinding.Value.TargetKey);
                currentlyEditedBinding_   = null;
            }
        }
Esempio n. 4
0
        private void OnBindingKeyDown(UIComponent comp, UIKeyEventParameter evParam)
        {
            try {
                // This will only work if the user clicked the modify button
                // otherwise no effect
                if (!currentlyEditedBinding_.HasValue || Keybind.IsModifierKey(evParam.keycode))
                {
                    return;
                }

                evParam.Use();                               // Consume the event
                var editedBinding = currentlyEditedBinding_; // will be nulled by closing modal
                UIView.PopModal();

                var keybindButton = evParam.source as UIButton;
                var inputKey      = SavedInputKey.Encode(evParam.keycode, evParam.control, evParam.shift, evParam.alt);
                var editable      = (KeybindSetting.Editable)evParam.source.objectUserData;
                var category      = editable.Target.Category;

                if (evParam.keycode != KeyCode.Escape)
                {
                    // Check the key conflict
                    var maybeConflict = FindConflict(editedBinding.Value, inputKey, category);
                    if (maybeConflict != string.Empty)
                    {
                        var message = Translation.Options.Get("Keybinds.Dialog.Text:Keybind conflict")
                                      + "\n\n" + maybeConflict;
                        Log.Info($"Keybind conflict: {message}");
                        UIView.library
                        .ShowModal <ExceptionPanel>("ExceptionPanel")
                        .SetMessage("Key Conflict", message, false);
                    }
                    else
                    {
                        editedBinding.Value.TargetKey.value = inputKey;
                        editedBinding.Value.Target.NotifyKeyChanged();
                    }
                }

                keybindButton.text      = Keybind.ToLocalizedString(editedBinding.Value.TargetKey);
                currentlyEditedBinding_ = null;
            } catch (Exception e) { Log.Error($"{e}"); }
        }