public bool SetBinding(KeyBindingDef keyDef, KeyPrefs.BindingSlot slot, KeyCode keyCode) { KeyBindingData keyBindingData = default(KeyBindingData); if (this.keyPrefs.TryGetValue(keyDef, out keyBindingData)) { switch (slot) { case KeyPrefs.BindingSlot.A: keyBindingData.keyBindingA = keyCode; break; case KeyPrefs.BindingSlot.B: keyBindingData.keyBindingB = keyCode; break; default: Log.Error("Tried to set a key binding for \"" + keyDef.LabelCap + "\" on a nonexistent slot: " + slot.ToString()); return(false); } return(true); } Log.Error("Key not found in keyprefs: \"" + keyDef.LabelCap + "\""); return(false); }
public void EraseConflictingBindingsForKeyCode(KeyBindingDef keyDef, KeyCode keyCode, Action <KeyBindingDef> callBackOnErase = null) { foreach (KeyBindingDef item in ConflictingBindings(keyDef, keyCode)) { KeyBindingData keyBindingData = keyPrefs[item]; if (keyBindingData.keyBindingA == keyCode) { keyBindingData.keyBindingA = KeyCode.None; } if (keyBindingData.keyBindingB == keyCode) { keyBindingData.keyBindingB = KeyCode.None; } callBackOnErase?.Invoke(item); } }
public void EraseConflictingBindingsForKeyCode(KeyBindingDef keyDef, KeyCode keyCode, Action <KeyBindingDef> callBackOnErase = null) { foreach (KeyBindingDef keyBindingDef in this.ConflictingBindings(keyDef, keyCode)) { KeyBindingData keyBindingData = this.keyPrefs[keyBindingDef]; if (keyBindingData.keyBindingA == keyCode) { keyBindingData.keyBindingA = KeyCode.None; } if (keyBindingData.keyBindingB == keyCode) { keyBindingData.keyBindingB = KeyCode.None; } if (callBackOnErase != null) { callBackOnErase(keyBindingDef); } } }
public KeyCode GetBoundKeyCode(KeyBindingDef keyDef, KeyPrefs.BindingSlot slot) { KeyBindingData keyBindingData = default(KeyBindingData); if (!this.keyPrefs.TryGetValue(keyDef, out keyBindingData)) { Log.Error("Key not found in keyprefs: \"" + keyDef.LabelCap + "\""); return(KeyCode.None); } switch (slot) { case KeyPrefs.BindingSlot.A: return(keyBindingData.keyBindingA); case KeyPrefs.BindingSlot.B: return(keyBindingData.keyBindingB); default: throw new InvalidOperationException(); } }