private void RegisterKeyBindings() { int n = actions.Count; LogKeyBind("Registering {0:D} key bind(s) for mod {1}".F(n, Assembly. GetExecutingAssembly().GetNameSafe() ?? "?")); var currentBindings = new List <BindingEntry>(GameInputMapping.DefaultBindings); foreach (var action in actions) { var kAction = action.GetKAction(); var binding = action.DefaultBinding; if (!FindKeyBinding(currentBindings, kAction)) { if (binding == null) { binding = new PKeyBinding(); } // This constructor changes often enough to be worth detouring currentBindings.Add(NEW_BINDING_ENTRY.Invoke(CATEGORY, binding. GamePadButton, binding.Key, binding.Modifiers, kAction)); } } GameInputMapping.SetDefaultKeyBindings(currentBindings.ToArray()); UpdateMaxAction(); }
public KInputController AddKeyboardMouseController() { KInputController kInputController = new KInputController(false); BindingEntry[] bindingEntries = GameInputMapping.GetBindingEntries(); for (int i = 0; i < bindingEntries.Length; i++) { BindingEntry bindingEntry = bindingEntries[i]; kInputController.Bind(bindingEntry.mKeyCode, bindingEntry.mModifier, bindingEntry.mAction); } AddController(kInputController); return(kInputController); }
public KInputController AddGamepadController(int gamepad_index) { KInputController kInputController = new KInputController(true); BindingEntry[] bindingEntries = GameInputMapping.GetBindingEntries(); for (int i = 0; i < bindingEntries.Length; i++) { BindingEntry bindingEntry = bindingEntries[i]; kInputController.Bind(BindingEntry.GetGamepadKeyCode(gamepad_index, bindingEntry.mButton), Modifier.None, bindingEntry.mAction); } AddController(kInputController); return(kInputController); }
public void RebindControls() { foreach (KInputController mController in mControllers) { mController.ClearBindings(); BindingEntry[] bindingEntries = GameInputMapping.GetBindingEntries(); for (int i = 0; i < bindingEntries.Length; i++) { BindingEntry bindingEntry = bindingEntries[i]; mController.Bind(bindingEntry.mKeyCode, bindingEntry.mModifier, bindingEntry.mAction); } mController.HandleCancelInput(); } }
public static bool GameInputMapping_CompareActionKeyCodes_Prefix(Action a, Action b, ref bool __result) { BindingEntry entry1 = GameInputMapping.FindEntry(a); BindingEntry entry2 = GameInputMapping.FindEntry(b); if (!(entry1.mAction == Action.NumActions || entry2.mAction == Action.NumActions) && entry1.mKeyCode == entry2.mKeyCode) { __result = entry1.mModifier == entry2.mModifier; return(false); } __result = false; return(false); }
protected override void OnPrefabInit() { BindingEntry[] bindingEntries = GameInputMapping.GetBindingEntries(); string text = string.Empty; BindingEntry[] array = bindingEntries; for (int i = 0; i < array.Length; i++) { BindingEntry bindingEntry = array[i]; text += bindingEntry.mAction.ToString(); text += ": "; text += bindingEntry.mKeyCode.ToString(); text += "\n"; } controlLabel.text = text; }
/// <summary> /// Adds a key binding to the game for this custom Action. It must be done after mods /// are loaded. /// </summary> /// <param name="binding">The default key binding for this action.</param> internal void AddKeyBinding(PKeyBinding binding) { var currentBindings = GameInputMapping.DefaultBindings; if (binding == null) { throw new ArgumentNullException("binding"); } if (currentBindings != null) { // Only if GameInputMapping is initialized Action action = GetKAction(); bool inBindings = false; int n = currentBindings.Length; for (int i = 0; i < n && !inBindings; i++) { var cb = currentBindings[i]; if (cb.mAction == action) { // Already exists, but it really should not PActionManager.LogKeyBindWarning(("Action {0} already exists; " + "assigned to KeyCode {1}").F(action, cb.mKeyCode)); inBindings = true; break; } } if (!inBindings) { var newBindings = new BindingEntry[n + 1]; Array.Copy(currentBindings, newBindings, n); newBindings[n] = new BindingEntry(PActionManager.CATEGORY, binding. GamePadButton, binding.Key, binding.Modifiers, action, true, false); GameInputMapping.SetDefaultKeyBindings(newBindings); } } else { // Queue into PActionManager PActionManager.Instance.QueueKeyBind(this, binding); } }
/// <summary> /// Adds a key binding to the game for this custom Action. It must be done after mods /// are loaded. /// </summary> /// <param name="binding">The default key binding for this action.</param> internal void AddKeyBinding(PKeyBinding binding) { var currentBindings = GameInputMapping.DefaultBindings; if (binding == null) { throw new ArgumentNullException("binding"); } if (currentBindings != null) { Action action = GetKAction(); bool inBindings = false; // Only if GameInputMapping is initialized int n = currentBindings.Length; for (int i = 0; i < n && !inBindings; i++) { if (currentBindings[i].mAction == action) { inBindings = true; break; } } if (!inBindings) { var newBindings = new BindingEntry[n + 1]; Array.Copy(currentBindings, newBindings, n); newBindings[n] = new BindingEntry(PActionManager.CATEGORY, binding. GamePadButton, binding.Key, binding.Modifiers, action, true, false); GameInputMapping.SetDefaultKeyBindings(newBindings); } } else { // Queue into PActionManager PActionManager.Instance.QueueKeyBind(this, binding); } }
public GameInputManager(BindingEntry[] default_keybindings) { GameInputMapping.SetDefaultKeyBindings(default_keybindings); GameInputMapping.LoadBindings(); AddKeyboardMouseController(); }
protected override void OnDeactivate() { GameInputMapping.SaveBindings(); DestroyDisplay(); }