private void CreateElementMap() { try { ElementAssignment elementAssignment = new ElementAssignment { actionId = this._foundRewiredAction.id, axisContribution = ((!this._negativeAxis) ? Pole.Positive : Pole.Negative), keyboardKey = this._pollingInfo.keyboardKey, elementIdentifierId = this._pollingInfo.elementIdentifierId, modifierKeyFlags = this._modifierKeyFlags }; if (!this._pollingControllerMap.CreateElementMap(elementAssignment)) { throw new InvalidOperationException("Rewire reported failure"); } this._controllerMap = this._pollingControllerMap; this._controllerType = this._pollingControllerType; Debug.Log(string.Format("Created Map {0} {1} + {2}", this._foundRewiredAction.name, this._pollingInfo.keyboardKey, this._modifierKeyFlags)); } catch (Exception ex) { Debug.Log(string.Format("Create Map failed! {0}", ex.Message)); } }
private void CreateElementMapsFromPollingInfo(ActionElementMap[] sourceActionElementMaps) { if (sourceActionElementMaps.SafeCount <ActionElementMap>() == 0) { return; } foreach (ActionElementMap actionElementMap in sourceActionElementMaps) { if (actionElementMap != null) { ElementAssignment newElementAssignment = new ElementAssignment { actionId = this._foundRewiredAction.id, axisContribution = ((!this._negativeAxis) ? Pole.Positive : Pole.Negative), keyboardKey = this._pollingInfo.keyboardKey, elementIdentifierId = this._pollingInfo.elementIdentifierId, modifierKeyFlags = this._modifierKeyFlags, elementMapId = actionElementMap.id }; bool flag = InputMappingButton.TryCreateElementMap(newElementAssignment, actionElementMap.controllerMap); if (flag) { this._controllerMap = this._pollingControllerMap; this._controllerType = this._pollingControllerType; Debug.Log(string.Format("Created Element Map {0} {1} + {2}", this._foundRewiredAction.name, this._pollingInfo.keyboardKey, this._modifierKeyFlags)); } } } }
private void ProcessVRViveInputMappings(Player player) { Player.ControllerHelper controllers = player.controllers; IEnumerable <ControllerMap> enumerable = controllers.maps.GetAllMaps(ControllerType.Joystick); if (enumerable == null) { enumerable = new List <ControllerMap>(); } foreach (ControllerMap controllerMap in enumerable) { List <ElementAssignment> list = new List <ElementAssignment>(); IList <ActionElementMap> allMaps = controllerMap.AllMaps; foreach (ActionElementMap actionElementMap in allMaps) { if (actionElementMap.elementIdentifierId == 2 && actionElementMap.elementIdentifierName.Equals("Index Trigger")) { ElementAssignment item = new ElementAssignment(ControllerType.Joystick, ControllerElementType.Button, 7, AxisRange.Full, KeyCode.None, ModifierKeyFlags.None, actionElementMap.actionId, Pole.Positive, false, actionElementMap.id); list.Add(item); } } foreach (ElementAssignment elementAssignment in list) { ActionElementMap actionElementMap2; bool flag = controllerMap.ReplaceElementMap(elementAssignment, out actionElementMap2); } } }
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); } } } } } } } } } } }
public void ReplaceOrCreateActionElementMap(bool replaceElementMap) { ElementAssignment elementAssignment = this.ToElementAssignment(); if (replaceElementMap) { this.controllerMap.ReplaceElementMap(elementAssignment); } else { this.controllerMap.ReplaceOrCreateElementMap(elementAssignment); } }
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); }
// Removes an input from an action map public void RemoveInput() { // Current Action Map ActionElementMap map = bAltMap ? aAltElementMaps[currentUIInputRow.PrimaryActionID] : aElementMaps[currentUIInputRow.SecondaryActionID]; // Assignment Data ElementAssignment assignment = new ElementAssignment(controlType, ControllerElementType.Button, -1, map.axisRange, KeyCode.None, ModifierKeyFlags.None, map.actionId, map.axisContribution, false, map.id); // Remove element based on which map is being assigned to if (bAltMap) { altControlMap.ReplaceElementMap(assignment); currentUIInputRow.secondaryButtonText.gameObject.SetActive(true); if (controlType == ControllerType.Joystick) { currentUIInputRow.secondaryButtonIcon.gameObject.SetActive(false); currentUIInputRow.secondaryButtonIcon.sprite = null; } currentUIInputRow.secondaryButtonText.text = "None"; } else { controlMap.ReplaceElementMap(assignment); currentUIInputRow.primaryButtonText.gameObject.SetActive(true); if (controlType == ControllerType.Joystick) { currentUIInputRow.primaryButtonIcon.gameObject.SetActive(false); currentUIInputRow.primaryButtonIcon.sprite = null; } currentUIInputRow.primaryButtonText.text = "None"; } SettingsManager.bOptionChanged = true; CloseAssignmentWindow(); }
private bool CreateConflictCheck( ElementAssignment _elementAssignment, out ElementAssignmentConflictCheck _conflictCheck, ActionElementMap _actionElementMap) { if (this.controllerMap == null || this.player == null) { _conflictCheck = (ElementAssignmentConflictCheck)null; return(false); } _conflictCheck = ((ElementAssignment) ref _elementAssignment).ToElementAssignmentConflictCheck(); ((ElementAssignmentConflictCheck) ref _conflictCheck).set_playerId(this.player.get_id()); ((ElementAssignmentConflictCheck) ref _conflictCheck).set_controllerType(this.controllerMap.get_controllerType()); ((ElementAssignmentConflictCheck) ref _conflictCheck).set_controllerMapId(this.controllerMap.get_id()); ((ElementAssignmentConflictCheck) ref _conflictCheck).set_controllerMapCategoryId(this.controllerMap.get_categoryId()); if (_actionElementMap != null) { ((ElementAssignmentConflictCheck) ref _conflictCheck).set_elementMapId(_actionElementMap.get_id()); } return(true); }
// Token: 0x0600421C RID: 16924 RVA: 0x001661C4 File Offset: 0x001643C4 private void InitMappings() { if (this.m_sectionTemplate) { this.m_sectionTemplate.gameObject.SetActive(true); foreach (InputMapCategory inputMapCategory in ReInput.mapping.UserAssignableMapCategories) { if (this.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. if (inputMapCategory.name == "QuickSlot") { // Loop through our 8 actions we added via ReWired and create the mapping objects for them. for (int i = 0; i < 8; i++) { var aid = ReInput.mapping.GetActionId(string.Format("QS_Instant{0}", i + 12)); ElementAssignment elementAssignment = new ElementAssignment(KeyCode.None, ModifierKeyFlags.None, aid, Pole.Positive); ActionElementMap actionElementMap; keyboardMapInstance.CreateElementMap(elementAssignment, out actionElementMap); mouseMapInstance.CreateElementMap(elementAssignment, out actionElementMap); } } this.InitSections(keyboardMapInstance); this.InitSections(mouseMapInstance); } else if (this.m_lastJoystickController != null) { JoystickMap joystickMapInstance = ReInput.mapping.GetJoystickMapInstance((Joystick)this.m_lastJoystickController, inputMapCategory.id, 0); this.InitSections(joystickMapInstance); } else { this.m_mappingInitialized = false; } } this.m_sectionTemplate.gameObject.SetActive(false); } }
private void UpdateInputCheckMode() { ControllerPollingInfo _pollingInfo = ((ReInput.ControllerHelper.PollingHelper)ReInput.get_controllers().polling).PollControllerForFirstElementDown(this.selectedControllerType, this.selectedControllerId); if (!((ControllerPollingInfo) ref _pollingInfo).get_success() || ((ControllerPollingInfo) ref _pollingInfo).get_elementType() != 1) { return; } InputAction action = this.row.action; ActionElementMap _actionElementMap = !this.controllerMap.ContainsAction(action.get_id()) ? (ActionElementMap)null : this.controllerMap.GetElementMapsWithAction(action.get_id())[0]; ElementAssignment elementAssignment = this.ToElementAssignment(_pollingInfo, (ModifierKeyFlags)0, this.row.actionRange, action.get_id(), _actionElementMap); ElementAssignmentConflictCheck _conflictCheck = (ElementAssignmentConflictCheck)null; if (this.CreateConflictCheck(elementAssignment, out _conflictCheck, _actionElementMap) && !((ReInput.ControllerHelper.ConflictCheckingHelper)ReInput.get_controllers().conflictChecking).DoesElementAssignmentConflict(_conflictCheck)) { this.controllerMap.ReplaceOrCreateElementMap(elementAssignment); } this.row = (Remapping.Row)null; this.updateMode = Remapping.UpdateMode.ButtonSelectMode; ((Selectable)this.controllerSelectDropDown).set_interactable(true); this.RedrawUI(); }
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); } } }
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); }
// Polls for Gamepad Input private void GamepadPoll() { // If no controllers connected if (playerInput.controllers.joystickCount == 0) { return; } // Get current polling info in use ControllerPollingInfo pollingInfo = ReInput.controllers.polling.PollControllerForFirstElementDown(ControllerType.Joystick, playerInput.controllers.GetLastActiveController().id); // If Guide or PS Button if (pollingInfo.elementIdentifierName == "Guide" || pollingInfo.elementIdentifierName == "PS Button") { return; } // If unsuccessful if (!pollingInfo.success) { return; } bPolling = false; // Current Action Map ActionElementMap map = bAltMap ? aAltElementMaps[currentUIInputRow.SecondaryActionID] : aElementMaps[currentUIInputRow.PrimaryActionID]; // Assignment Data ElementAssignment assignment = new ElementAssignment(controlType, pollingInfo.elementType, pollingInfo.elementIdentifierId, map.axisRange, pollingInfo.keyboardKey, ModifierKeyFlags.None, map.actionId, map.axisContribution, false, map.id); // Replace element based on which map is being assigned to if (bAltMap) { altControlMap.ReplaceElementMap(assignment); if (ControllerStatusManager.currentGamepadType != eGamepadButtonType.Generic) { currentUIInputRow.secondaryButtonText.gameObject.SetActive(false); currentUIInputRow.secondaryButtonIcon.gameObject.SetActive(true); currentUIInputRow.secondaryButtonIcon.sprite = buttonImageData.GetImage(controlType, pollingInfo.elementType, pollingInfo.elementIdentifierId, map.axisRange, pollingInfo.axisPole); } else { currentUIInputRow.secondaryButtonText.gameObject.SetActive(true); currentUIInputRow.secondaryButtonIcon.gameObject.SetActive(false); currentUIInputRow.secondaryButtonText.text = pollingInfo.elementIdentifierName + SGetAxisDir(pollingInfo); } } else { controlMap.ReplaceElementMap(assignment); if (ControllerStatusManager.currentGamepadType != eGamepadButtonType.Generic) { currentUIInputRow.primaryButtonText.gameObject.SetActive(false); currentUIInputRow.primaryButtonIcon.gameObject.SetActive(true); currentUIInputRow.primaryButtonIcon.sprite = buttonImageData.GetImage(controlType, pollingInfo.elementType, pollingInfo.elementIdentifierId, map.axisRange, pollingInfo.axisPole); } else { currentUIInputRow.primaryButtonText.gameObject.SetActive(true); currentUIInputRow.primaryButtonIcon.gameObject.SetActive(false); currentUIInputRow.primaryButtonText.text = pollingInfo.elementIdentifierName + SGetAxisDir(pollingInfo); } } SettingsManager.bOptionChanged = true; CloseAssignmentWindow(); }
// Polls for Mouse Input private void MousePoll() { ControllerPollingInfo pollingInfo = new ControllerPollingInfo(); // Loop through each polling info to find which one is in use foreach (ControllerPollingInfo info in ReInput.controllers.polling.PollControllerForAllElementsDown(ControllerType.Mouse, 0)) { if (info.elementType == ControllerElementType.Axis) { // If Mouse Move X or Y, then continue if (info.elementIndex == 0 || info.elementIndex == 1) { continue; } } pollingInfo = info; } // If unsuccessful if (!pollingInfo.success) { return; } // Stop Polling bPolling = false; // Current Action Map ActionElementMap map = bAltMap ? aAltElementMaps[currentUIInputRow.SecondaryActionID] : aElementMaps[currentUIInputRow.PrimaryActionID]; // Assignment Data ElementAssignment assignment = new ElementAssignment(controlType, pollingInfo.elementType, pollingInfo.elementIdentifierId, map.axisRange, pollingInfo.keyboardKey, ModifierKeyFlags.None, map.actionId, map.axisContribution, false, map.id); string elementName = pollingInfo.elementIdentifierName; if (controlType == ControllerType.Mouse) { if (elementName == "Left Mouse Button") { elementName = "Left Click"; } else if (elementName == "Right Mouse Button") { elementName = "Right Click"; } } // Replace element based on which map is being assigned to if (bAltMap) { altControlMap.ReplaceElementMap(assignment); currentUIInputRow.secondaryButtonText.text = elementName + SGetAxisDir(pollingInfo); } else { controlMap.ReplaceElementMap(assignment); currentUIInputRow.primaryButtonText.text = elementName + SGetAxisDir(pollingInfo); } SettingsManager.bOptionChanged = true; CloseAssignmentWindow(); }