public static void Prefix(ControlMappingPanel __instance, ControllerMap _controllerMap) { // Loop through our custom actions we added via Rewired foreach (int myActionId in myCustomActionIds.Keys) { FileLog.Log(myActionId.ToString()); // The info that the user specified for this action InputActionDescription myActionDescription = myCustomActionIds[myActionId]; // There are separate keybinding maps for keyboard, mouse, & controllers // We only add our action-to-element mappings to the keybind maps that make sense // For example, if you are adding a key that doesn't make sense to have on a controller, // then skip when _controllerMap is JoystickMap // // (Optional) // You can check if this method is being called for the Keyboard/Mouse bindings panel or // the Controller bindings panel, but I prefer to check the class of the _controllerMap // if (self.ControllerType == ControlMappingPanel.ControlType.Keyboard) { // bool shouldLog = false; if (shouldLog) { Debug.Log("_controllerMap is keyboard or mouse: " + (_controllerMap is KeyboardMap || _controllerMap is MouseMap)); Debug.Log("_controllerMap is joystick: " + (_controllerMap is JoystickMap)); Debug.Log("_controllerMap.categoryId: " + _controllerMap.categoryId); Debug.Log("action is keyboard: " + (myActionDescription.controlType == ControlType.Keyboard)); Debug.Log("action is gamepad: " + (myActionDescription.controlType == ControlType.Gamepad)); Debug.Log("action is both: " + (myActionDescription.controlType == ControlType.Both)); Debug.Log("action.sectionId: " + myActionDescription.sectionId); } // If the controller map's control type does not match our action if (!(myActionDescription.controlType == ControlType.Keyboard && (_controllerMap is KeyboardMap || _controllerMap is MouseMap) || myActionDescription.controlType == ControlType.Gamepad && (_controllerMap is JoystickMap) || myActionDescription.controlType == ControlType.Both)) { // Then skip to next action continue; } // If the categoryId of this controller map does not match our action's if (_controllerMap.categoryId != myActionDescription.sectionId) { // Skip to next action continue; } // If we pass the tests, create & add the action-to-element map for this particular action _controllerMap.CreateElementMap(myActionId, Pole.Positive, KeyCode.None, ModifierKeyFlags.None); // Continue the loop... } }
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); } }
// Create Action-to-Element mapping objects, which are what is shown in the keybindings menu // This could have been implemented elsewhere than the ControlMappingPanel, but the InitSections // method is conveniently passed the actual ControllerMap that we need to add our ActionElementMap to private static void ControlMappingPanel_InitSections(On.ControlMappingPanel.orig_InitSections orig, ControlMappingPanel self, ControllerMap _controllerMap) { // Loop through our custom actions we added via Rewired foreach (int myActionId in myCustomActionIds.Keys) { // The info that the user specified for this action InputActionDescription myActionDescription = myCustomActionIds[myActionId]; // There are separate keybinding maps for keyboard, mouse, & controllers // We only add our action-to-element mappings to the keybind maps that make sense // For example, if you are adding a key that doesn't make sense to have on a controller, // then skip when _controllerMap is JoystickMap // // (Optional) // You can check if this method is being called for the Keyboard/Mouse bindings panel or // the Controller bindings panel, but I prefer to check the class of the _controllerMap // if (self.ControllerType == ControlMappingPanel.ControlType.Keyboard) { // // If the controller map is not for keyboard or mouse; or if it's for joystick, but our action isn't for joystick if (!(_controllerMap is KeyboardMap || _controllerMap is MouseMap) && (_controllerMap is JoystickMap && !myActionDescription.showForController)) { // Then skip to next action continue; } // If the categoryId of this controller map does not match our action's if (_controllerMap.categoryId != myActionDescription.sectionId) { // Skip to next action continue; } // If we pass the tests, create & add the action-to-element map for this particular action _controllerMap.CreateElementMap(myActionId, Pole.Positive, KeyCode.None, ModifierKeyFlags.None); // Continue the loop... } // We're done here. Call original implementation orig(self, _controllerMap); }
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); }