Example #1
0
            public static bool InitSections(ControllerMap _controllerMap)
            {
                InitLocalization();

                if (_controllerMap.categoryId == CUSTOM_CATEGORY)
                {
                    return(false);
                }

                foreach (var keybindInfo in s_customKeyDict.Values)
                {
                    // If the controller map's control type does not match our action
                    if (!(keybindInfo.controllerType == ControlType.Both ||
                          keybindInfo.controllerType == ControlType.Keyboard && (_controllerMap is KeyboardMap || _controllerMap is MouseMap) ||
                          keybindInfo.controllerType == ControlType.Gamepad && (_controllerMap is JoystickMap)))
                    {
                        // Then skip to next action
                        continue;
                    }

                    // i dont know but this gets the best results
                    if (_controllerMap.categoryId != 5)
                    {
                        // Skip to next action
                        continue;
                    }

                    //SL.LogWarning("Creating element map for '" + keybindInfo.name + "', id: " + _controllerMap.id + ", categoryId: " + _controllerMap.categoryId);

                    _controllerMap.CreateElementMap(keybindInfo.actionID, Pole.Positive, KeyCode.None, ModifierKeyFlags.None);
                }

                // We're done here. Call original implementation
                return(true);
            }
Example #2
0
        public static bool InitSections(ControllerMap _controllerMap)
        {
            //MyLogger.LogDebug("InitSections");
            // Loop through our custom actions we added via Rewired
            foreach (int myActionId in CustomKeybindings.myCustomActionIds.Keys)
            {
                // The info that the user specified for this action
                CustomKeybindings.InputActionDescription myActionDescription = CustomKeybindings.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)
                {
                    MyLogger.LogDebug("_controllerMap is keyboard or mouse: " + (_controllerMap is KeyboardMap || _controllerMap is MouseMap));
                    MyLogger.LogDebug("_controllerMap is joystick: " + (_controllerMap is JoystickMap));
                    MyLogger.LogDebug("_controllerMap.categoryId: " + _controllerMap.categoryId);
                    MyLogger.LogDebug("action is keyboard: " + (myActionDescription.controlType == ControlType.Keyboard));
                    MyLogger.LogDebug("action is gamepad: " + (myActionDescription.controlType == ControlType.Gamepad));
                    MyLogger.LogDebug("action is both: " + (myActionDescription.controlType == ControlType.Both));
                    MyLogger.LogDebug("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...
            }

            // We're done here. Call original implementation
            return(true);
        }
Example #3
0
        private void AddDefaultMappingsForNewActions(Player player, List <UserDataStore_PlayerPrefs.SavedControllerMapData> savedData, ControllerType controllerType, int controllerId)
        {
            if (player == null || savedData == null)
            {
                return;
            }
            List <int> allActionIds = this.GetAllActionIds();

            for (int i = 0; i < savedData.Count; i++)
            {
                UserDataStore_PlayerPrefs.SavedControllerMapData savedControllerMapData = savedData[i];
                if (savedControllerMapData != null)
                {
                    if (savedControllerMapData.knownActionIds != null && savedControllerMapData.knownActionIds.Count != 0)
                    {
                        ControllerMap controllerMap = ControllerMap.CreateFromXml(controllerType, savedData[i].xml);
                        if (controllerMap != null)
                        {
                            ControllerMap map = player.controllers.maps.GetMap(controllerType, controllerId, controllerMap.categoryId, controllerMap.layoutId);
                            if (map != null)
                            {
                                ControllerMap controllerMapInstance = ReInput.mapping.GetControllerMapInstance(ReInput.controllers.GetController(controllerType, controllerId), controllerMap.categoryId, controllerMap.layoutId);
                                if (controllerMapInstance != null)
                                {
                                    List <int> list = new List <int>();
                                    foreach (int item in allActionIds)
                                    {
                                        if (!savedControllerMapData.knownActionIds.Contains(item))
                                        {
                                            list.Add(item);
                                        }
                                    }
                                    if (list.Count != 0)
                                    {
                                        foreach (ActionElementMap actionElementMap in controllerMapInstance.AllMaps)
                                        {
                                            if (list.Contains(actionElementMap.actionId))
                                            {
                                                if (!map.DoesElementAssignmentConflict(actionElementMap))
                                                {
                                                    ElementAssignment elementAssignment = new ElementAssignment(controllerType, actionElementMap.elementType, actionElementMap.elementIdentifierId, actionElementMap.axisRange, actionElementMap.keyCode, actionElementMap.modifierKeyFlags, actionElementMap.actionId, actionElementMap.axisContribution, actionElementMap.invert);
                                                    map.CreateElementMap(elementAssignment);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Example #4
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...
            }
        }
Example #5
0
 private static bool TryCreateElementMap(ElementAssignment newElementAssignment, ControllerMap controllerMap)
 {
     try
     {
         if (!controllerMap.CreateElementMap(newElementAssignment))
         {
             throw new InvalidOperationException("Rewire reported failure");
         }
         return(true);
     }
     catch (Exception ex)
     {
         Debug.Log(string.Format("Create Element Map failed! {0}", ex.Message));
     }
     return(false);
 }
    // 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);
    }
Example #7
0
 private static void UpdateActionElementRelationships(Dictionary <int[], List <ActionElementMap> > elementSourceActionLinks, Dictionary <int, ActionElementMap> storedElementMaps, InputMapCategory sourceCategory, Player player)
 {
     foreach (KeyValuePair <int[], List <ActionElementMap> > keyValuePair in elementSourceActionLinks)
     {
         if (keyValuePair.Value.SafeCount <ActionElementMap>() != 0)
         {
             int key = keyValuePair.Key[2];
             ActionElementMap oldElementMap      = storedElementMaps[key];
             KeyboardMap      firstMapInCategory = player.controllers.maps.GetFirstMapInCategory <KeyboardMap>(0, sourceCategory.id);
             if (firstMapInCategory == null)
             {
                 Debug.LogError("newControllerMap is null!");
             }
             else
             {
                 ActionElementMap firstElementMapMatch = firstMapInCategory.GetFirstElementMapMatch((ActionElementMap searchMap) => searchMap.actionId == oldElementMap.actionId);
                 if (firstElementMapMatch == null)
                 {
                     Debug.LogError("sourceMap is null!");
                 }
                 else
                 {
                     foreach (ActionElementMap actionElementMap in keyValuePair.Value)
                     {
                         ControllerMap     controllerMap     = actionElementMap.controllerMap;
                         ElementAssignment elementAssignment = new ElementAssignment(ControllerType.Keyboard, firstElementMapMatch.elementType, firstElementMapMatch.elementIdentifierId, firstElementMapMatch.axisRange, firstElementMapMatch.keyCode, firstElementMapMatch.modifierKeyFlags, firstElementMapMatch.actionId, firstElementMapMatch.axisContribution, firstElementMapMatch.invert, actionElementMap.id);
                         bool             flag = controllerMap.DeleteElementMap(actionElementMap.id);
                         ActionElementMap actionElementMap2;
                         if (!flag || !controllerMap.CreateElementMap(elementAssignment, out actionElementMap2))
                         {
                             Debug.Log("Failed to remap secondary actions");
                         }
                     }
                 }
             }
         }
     }
 }
        private void AddDefaultMappingsForNewActions(Player player, List <SavedControllerMapData> savedData, ControllerType controllerType, int controllerId)
        {
            if (player == null || savedData == null)
            {
                return;
            }

            // Check for new Actions added to the default mappings that didn't exist when the Controller Map was saved
            List <int> allActionIds = GetAllActionIds();

            for (int i = 0; i < savedData.Count; i++)
            {
                SavedControllerMapData data = savedData[i];
                if (data == null)
                {
                    continue;
                }
                if (data.knownActionIds == null || data.knownActionIds.Count == 0)
                {
                    continue;
                }

                // Create a map from the Xml so we can get information
                ControllerMap mapFromXml = ControllerMap.CreateFromXml(controllerType, savedData[i].xml);
                if (mapFromXml == null)
                {
                    continue;
                }

                // Load the map that was added to the Player
                ControllerMap mapInPlayer = player.controllers.maps.GetMap(controllerType, controllerId, mapFromXml.categoryId, mapFromXml.layoutId);
                if (mapInPlayer == null)
                {
                    continue;
                }

                // Load default map for comparison
                ControllerMap defaultMap = ReInput.mapping.GetControllerMapInstance(ReInput.controllers.GetController(controllerType, controllerId), mapFromXml.categoryId, mapFromXml.layoutId);
                if (defaultMap == null)
                {
                    continue;
                }

                // Find any new Action ids that didn't exist when the Controller Map was saved
                List <int> unknownActionIds = new List <int>();
                foreach (int id in allActionIds)
                {
                    if (data.knownActionIds.Contains(id))
                    {
                        continue;
                    }
                    unknownActionIds.Add(id);
                }

                if (unknownActionIds.Count == 0)
                {
                    continue;                             // no new Action ids
                }
                // Add all mappings in the default map for previously unknown Action ids
                foreach (ActionElementMap aem in defaultMap.AllMaps)
                {
                    if (!unknownActionIds.Contains(aem.actionId))
                    {
                        continue;
                    }

                    // Skip this ActionElementMap if there's a conflict within the loaded map
                    if (mapInPlayer.DoesElementAssignmentConflict(aem))
                    {
                        continue;
                    }

                    // Create an assignment
                    ElementAssignment assignment = new ElementAssignment(
                        controllerType,
                        aem.elementType,
                        aem.elementIdentifierId,
                        aem.axisRange,
                        aem.keyCode,
                        aem.modifierKeyFlags,
                        aem.actionId,
                        aem.axisContribution,
                        aem.invert
                        );

                    // Assign it
                    mapInPlayer.CreateElementMap(assignment);
                }
            }
        }