示例#1
0
        protected override void OnShow()
        {
            base.OnShow();

            var inputManager = base.Alex.InputManager.GetOrAddPlayerManager(PlayerIndex.One);

            if (inputManager.TryGetListener(out KeyboardInputListener inputListener))
            {
                InputListener = inputListener;
                var inputs = InputListener.ToDictionary(x => x.Key, x => x.Value);

                foreach (InputCommand ic in Enum.GetValues(typeof(InputCommand)))
                {
                    InputCommand inputCommand = ic;

                    Keys value = KeybindElement.Unbound;
                    if (inputs.TryGetValue(ic, out Keys key))
                    {
                        value = key;
                    }

                    KeybindElement textInput = new KeybindElement(value);

                    var row = AddGuiRow(new GuiTextElement()
                    {
                        Text = ic.ToString().SplitPascalCase()
                    }, textInput);
                    row.Margin = new Thickness(5, 5);

                    textInput.ValueChanged += (sender, newValue) =>
                    {
                        if (newValue == KeybindElement.Unbound)
                        {
                            inputListener.RemoveMap(inputCommand);
                        }
                        else
                        {
                            foreach (var input in Inputs.Where(x => x.Key != inputCommand && x.Value.Value == newValue))
                            {
                                input.Value.Value = KeybindElement.Unbound;
                            }

                            InputListener.RegisterMap(inputCommand, newValue);
                        }

                        base.Alex.GuiManager.FocusManager.FocusedElement = null;

                        textInput.ClearFocus();
                        value = newValue;
                    };

                    Inputs.TryAdd(ic, textInput);
                }
            }
        }
示例#2
0
    private void AddKeybindElement(InputAction action, InputBinding binding)
    {
        if (last_label != action.actionMap.name)
        {
            var text = Instantiate(label_template, container);
            text.text = action.actionMap.name;
            text.gameObject.SetActive(true);

            last_label = action.actionMap.name;
        }

        KeybindElement element = Instantiate(template, container);

        element.input_action         = action;
        element.binding              = binding;
        element.rebind_dialog_script = rebind_dialog_script;
        element.gameObject.SetActive(true);
    }