Exemplo n.º 1
0
        //Set up a control mapping UI section and bind references

        internal static void InitCustomSection(ControlMappingSection mapSection, ControllerMap _controllerMap, IEnumerable <KeybindInfo> keysToAdd)
        {
            if (_controllerMap == null)
            {
                return;
            }

            // Loop through the custom actions we defined
            foreach (var customKey in keysToAdd)
            {
                // add the actual keybind mapping to this controller in Rewired
                _controllerMap.CreateElementMap(customKey.actionID, Pole.Positive, KeyCode.None, ModifierKeyFlags.None);

                var alreadyKnown = At.GetField(mapSection, "m_actionAlreadyKnown") as List <int>;

                // see if the UI has already been set up for this keybind
                if (alreadyKnown.Contains(customKey.actionID))
                {
                    continue;
                }

                // set up the UI for this keybind (same as how game does it)
                alreadyKnown.Add(customKey.actionID);

                var action = ReInput.mapping.GetAction(customKey.actionID);

                var actTemplate = At.GetField(mapSection, "m_actionTemplate") as ControlMappingAction;

                actTemplate.gameObject.SetActive(true);
                if (action.type == InputActionType.Button)
                {
                    At.Invoke(mapSection, "CreateActionRow", CUSTOM_CATEGORY, action, AxisRange.Positive);
                }
                else
                {
                    if (mapSection.ControllerType == ControlMappingPanel.ControlType.Keyboard)
                    {
                        At.Invoke(mapSection, "CreateActionRow", CUSTOM_CATEGORY, action, AxisRange.Positive);
                        At.Invoke(mapSection, "CreateActionRow", CUSTOM_CATEGORY, action, AxisRange.Negative);
                    }
                    else
                    {
                        At.Invoke(mapSection, "CreateActionRow", CUSTOM_CATEGORY, action, AxisRange.Full);
                    }
                }
                actTemplate.gameObject.SetActive(false);

                // Continue the loop of custom keys...
            }
        }
Exemplo n.º 2
0
            public static void InitMappings(ControlMappingPanel __instance, ControlMappingSection ___m_sectionTemplate,
                                            DictionaryExt <int, ControlMappingSection> ___m_sectionList, Controller ___m_lastJoystickController)
            {
                // filter our custom keybindings for this context
                var filter = s_customKeyDict.Values
                             .Where(it => it.category == CUSTOM_CATEGORY &&
                                    (it.controllerType == ControlType.Both || (int)it.controllerType == (int)__instance.ControllerType));

                // check if any keybindings in "custom" category were defined
                if (!filter.Any())
                {
                    return;
                }

                // set up our custom localization (if not already)
                InitLocalization();

                // set the template active while we clone from it
                ___m_sectionTemplate.gameObject.SetActive(true);
                // Create the UI (copied from how game does it)
                var mapSection = UnityEngine.Object.Instantiate(___m_sectionTemplate, ___m_sectionTemplate.transform.parent);

                // set the template inactive again
                ___m_sectionTemplate.gameObject.SetActive(false);

                // move our custom section to the top
                mapSection.transform.SetAsFirstSibling();

                // Setup our custom map section
                ___m_sectionList.Add(CUSTOM_CATEGORY, mapSection);
                mapSection.ControllerType = __instance.ControllerType;
                mapSection.SetCategory(CUSTOM_CATEGORY);

                // Init the custom keys
                if (__instance.ControllerType == ControlMappingPanel.ControlType.Keyboard)
                {
                    var kbMap = ReInput.mapping.GetKeyboardMapInstance(CUSTOM_CATEGORY, 0);
                    InitCustomSection(mapSection, kbMap, filter);

                    var mouseMap = ReInput.mapping.GetMouseMapInstance(CUSTOM_CATEGORY, 0);
                    InitCustomSection(mapSection, mouseMap, filter);
                }
                else
                {
                    var joyMap = ReInput.mapping.GetJoystickMapInstance(___m_lastJoystickController as Joystick, CUSTOM_CATEGORY, 0);
                    InitCustomSection(mapSection, joyMap, filter);
                }
            }
        public static bool InitMappingsPrefix(ControlMappingPanel __instance, ref ControlMappingSection ___m_sectionTemplate, ref bool ___m_mappingInitialized, ref Controller ___m_lastJoystickController)
        {
            if (___m_sectionTemplate)
            {
                ___m_sectionTemplate.gameObject.SetActive(true);
                foreach (InputMapCategory inputMapCategory in ReInput.mapping.UserAssignableMapCategories)
                {
                    if (__instance.ControllerType == ControlMappingPanel.ControlType.Keyboard)
                    {
                        KeyboardMap keyboardMapInstance = ReInput.mapping.GetKeyboardMapInstance(inputMapCategory.id, 0);
                        MouseMap    mouseMapInstance    = ReInput.mapping.GetMouseMapInstance(inputMapCategory.id, 0);
                        // We know this name from debugging, or we can dump it.
                        Debug.Log("Extended Quickslots - InitMappingsPrefix() inputMapCategory = " + inputMapCategory.name);
                        if (inputMapCategory.name == "QuickSlot")
                        {
                            Debug.Log("ExtendedQuickslots - Mapping Quickslots ...");
                            // Loop through our 8 actions we added via ReWired and create the mapping objects for them.
                            for (int i = 0; i < ExtendedQuickslots.numSlots; i++)
                            {
                                Debug.Log("\tMapping " + string.Format("QS_Instant{0}", i + 12));
                                var aid = ReInput.mapping.GetActionId(string.Format("QS_Instant{0}", i + 12));
                                ElementAssignment elementAssignment = new ElementAssignment(KeyCode.None, ModifierKeyFlags.None, aid, Pole.Positive);
                                keyboardMapInstance.CreateElementMap(elementAssignment, out ActionElementMap actionElementMap);
                                mouseMapInstance.CreateElementMap(elementAssignment, out actionElementMap);
                            }
                        }
                        if (inputMapCategory.name == "Actions")
                        {
                            ElementAssignment elementAssignment;
                            int aid;

                            Debug.Log("\tMapping Sit emote");
                            aid = ReInput.mapping.GetActionId("Sit_Emote");
                            elementAssignment = new ElementAssignment(KeyCode.None, ModifierKeyFlags.None, aid, Pole.Positive);
                            keyboardMapInstance.CreateElementMap(elementAssignment, out ActionElementMap actionElementMap);
                            mouseMapInstance.CreateElementMap(elementAssignment, out actionElementMap);

                            Debug.Log("\tMapping Alternate Idle Emote");
                            aid = ReInput.mapping.GetActionId("Alternate_Idle_Emote");
                            elementAssignment = new ElementAssignment(KeyCode.None, ModifierKeyFlags.None, aid, Pole.Positive);
                            keyboardMapInstance.CreateElementMap(elementAssignment, out actionElementMap);
                            mouseMapInstance.CreateElementMap(elementAssignment, out actionElementMap);
                        }

                        ControlMappingPanel_InitSections(__instance, new object[] { keyboardMapInstance });
                        ControlMappingPanel_InitSections(__instance, new object[] { mouseMapInstance });
                    }
                    else if (___m_lastJoystickController != null)
                    {
                        JoystickMap joystickMapInstance = ReInput.mapping.GetJoystickMapInstance((Joystick)___m_lastJoystickController, inputMapCategory.id, 0);
                        ControlMappingPanel_InitSections(__instance, new object[] { joystickMapInstance });
                    }
                    else
                    {
                        ___m_mappingInitialized = false;
                    }
                }
                ___m_sectionTemplate.gameObject.SetActive(false);
            }
            return(false);
        }