示例#1
0
    public IEnumerator ChangeKeybind(KeyAction selectedAction, bool isPrimary)
    {
        KeyValuePair <KeyAction, KeybindObject> conflictingKVP;
        KeyCombo capturedKeyCombo  = KeyCombo.None;
        bool     isConflictPrimary = true;

        // Wait for the keycombo to be captured
        KeyCapturePanel.SetActive(true);
        UIManager.IsInputFocus = true;
        while (capturedKeyCombo == KeyCombo.None)
        {
            capturedKeyCombo = keybindManager.CaptureKeyCombo();
            yield return(null);
        }
        KeyCapturePanel.SetActive(false);

        // If null stop the function (null is returned if Escape was captured)
        if (capturedKeyCombo == null)
        {
            Logger.Log("Captured Escape key, cancelling change", Category.Keybindings);
            UIManager.IsInputFocus = false;
            yield break;
        }

        Logger.Log("Captured key combo: " + capturedKeyCombo.ToString(), Category.Keybindings);

        conflictingKVP = tempKeybinds.CheckConflict(capturedKeyCombo, ref isConflictPrimary);
        KeyAction     conflictingAction        = conflictingKVP.Key;
        KeybindObject conflictingKeybindObject = conflictingKVP.Value;

        if (conflictingAction == KeyAction.None)
        {
            // No conflicts found so set the new keybind and refresh the view
            tempKeybinds.Set(selectedAction, capturedKeyCombo, isPrimary);
            // Make sure the player can move around again
            UIManager.IsInputFocus = false;
            PopulateKeybindScrollView();
        }
        // Check that the conflict isn't with itself, if it is just ignore it
        else if (conflictingAction != selectedAction)
        {
            // Check if the user wants to change the keybind
            modalPanelManager.Confirm(
                "Warning!\n\nThis combination is already being used by:\n" + conflictingKeybindObject.Name + "\nAre you sure you want to override it?",
                () =>
            {
                // User confirms they want to change the keybind
                tempKeybinds.Set(selectedAction, capturedKeyCombo, isPrimary);
                tempKeybinds.Remove(conflictingAction, isConflictPrimary);
                UIManager.IsInputFocus = false;
                PopulateKeybindScrollView();
            },
                "Yes",
                () =>
            {
                UIManager.IsInputFocus = false;
            }
                );
        }
    }
示例#2
0
    /// <summary>
    /// Check if either of the key combos for the selected action have been pressed
    /// </summary>
    /// <param name="keyAction">The action to check</param>
    /// <param name="keyEventType">The type of key event to check for</param>
    private bool CheckKeyAction(KeyAction keyAction, KeyEventType keyEventType = KeyEventType.Down)
    {
        KeybindObject action = keybindManager.userKeybinds[keyAction];

        if (CheckComboEvent(action.PrimaryCombo, keyEventType) || CheckComboEvent(action.SecondaryCombo, keyEventType))
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
示例#3
0
    // Keybind list functions
    // ==================================================

    /// <summary>
    /// Populates the list of keybinds, will destroy old ones if they already exist
    /// </summary>
    public void PopulateKeybindScrollView()
    {
        Logger.Log("Populating keybind scroll view", Category.Keybindings);
        if (KeybindItemList.Count > 0)
        {
            Logger.Log("Removing old keybind objects", Category.Keybindings);
            // Destroy all items in list if it already exists
            foreach (GameObject item in KeybindItemList)
            {
                Destroy(item.gameObject);
            }
            KeybindItemList.Clear();
        }

        // Reverse loop direction so items are in intended order under the headings
        for (int i = KeybindCount; i > 0; i--)
        {
            // Convert i to a KeyAction enum and get the corresponding keybind
            KeyAction action = (KeyAction)i;

            // Check if there is an entry for the action
            if (tempKeybinds.ContainsKey(action))
            {
                KeybindObject keybind = tempKeybinds[action];

                // Only add the action if it can be rebound
                if (keybind.Rebindable)
                {
                    GameObject newKeybindItem = Instantiate(KeybindItemTemplate) as GameObject;
                    // Add item to the list so we can destroy it again later
                    KeybindItemList.Add(newKeybindItem);

                    // Set the correct labels and onClick functions
                    newKeybindItem.GetComponent <KeybindItemTemplate>().SetupKeybindItem(action, keybind);

                    // Give the object the same parent as the template (the scroll view content)
                    newKeybindItem.transform.SetParent(KeybindItemTemplate.transform.parent, false);

                    // Grab the index of the appropriate heading and put the keybind under it
                    int headingIndex = KeybindHeadingDict[keybind.Type].transform.GetSiblingIndex();
                    newKeybindItem.transform.SetSiblingIndex(headingIndex + 1);
                    newKeybindItem.SetActive(true);
                }
            }
        }
    }
示例#4
0
    public void SetupKeybindItem(KeyAction action, KeybindObject keybind)
    {
        // Setup the action text and store it
        ActionText.text = keybind.Name;
        ItemAction      = action;

        // Only activate the remove button if a KeyCombo is present
        PrimaryRemoveButton.gameObject.SetActive(keybind.PrimaryCombo != KeyCombo.None);
        PrimaryButton.GetComponentInChildren <Text>().text = keybind.PrimaryCombo.ToString();
        PrimaryButton.onClick.AddListener(primary_onClick);
        PrimaryRemoveButton.onClick.AddListener(primaryRemove_onClick);

        // Setup the secondary buttons too
        SecondaryRemoveButton.gameObject.SetActive(keybind.SecondaryCombo != KeyCombo.None);
        SecondaryButton.GetComponentInChildren <Text>().text = keybind.SecondaryCombo.ToString();
        SecondaryButton.onClick.AddListener(secondary_onClick);
        SecondaryRemoveButton.onClick.AddListener(secondaryRemove_onClick);
    }