Esempio n. 1
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, not all of them will have entries
            if (!tempKeybinds.ContainsKey(action))
            {
                continue;
            }

            DualKeyCombo    actionKeybind  = tempKeybinds[action];
            KeybindMetadata actionMetadata = keybindManager.keyActionMetadata[action];

            // Only add the action if it can be rebound
            if (!actionMetadata.Rebindable)
            {
                continue;
            }

            // Create the item and give it the same parent as the template (the scroll view content)
            GameObject newKeybindItem = Instantiate(KeybindItemTemplate, KeybindItemTemplate.transform.parent, false);

            // 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, actionKeybind, actionMetadata);

            // Grab the index of the appropriate heading and put the keybind under it
            int headingIndex = KeybindHeadingDict[actionMetadata.Type].transform.GetSiblingIndex();
            newKeybindItem.transform.SetSiblingIndex(headingIndex + 1);

            newKeybindItem.SetActive(true);
        }
    }
    public void SetupKeybindItem(KeyAction action, DualKeyCombo keybind, KeybindMetadata metadata)
    {
        // Setup the action text and store it
        ActionText.text = metadata.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);
    }
    /// <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)
    {
        DualKeyCombo action = keybindManager.userKeybinds[keyAction];

        return(CheckComboEvent(action.PrimaryCombo, keyEventType) || CheckComboEvent(action.SecondaryCombo, keyEventType));
    }