public bool SetBinding(KeyBindingDef keyDef, KeyPrefs.BindingSlot slot, KeyCode keyCode) { KeyBindingData keyBindingData; bool result; if (this.keyPrefs.TryGetValue(keyDef, out keyBindingData)) { if (slot != KeyPrefs.BindingSlot.A) { if (slot != KeyPrefs.BindingSlot.B) { Log.Error("Tried to set a key binding for \"" + keyDef.LabelCap + "\" on a nonexistent slot: " + slot.ToString(), false); return(false); } keyBindingData.keyBindingB = keyCode; } else { keyBindingData.keyBindingA = keyCode; } result = true; } else { Log.Error("Key not found in keyprefs: \"" + keyDef.LabelCap + "\"", false); result = false; } return(result); }
private void ErrorCheckOn(KeyBindingDef keyDef, KeyPrefs.BindingSlot slot) { KeyCode boundKeyCode = GetBoundKeyCode(keyDef, slot); if (boundKeyCode != 0) { foreach (KeyBindingDef item in ConflictingBindings(keyDef, boundKeyCode)) { bool flag = boundKeyCode != keyDef.GetDefaultKeyCode(slot); Log.Warning("Key binding conflict: " + item + " and " + keyDef + " are both bound to " + boundKeyCode + "." + (flag ? " Fixed automatically." : "")); if (flag) { if (slot == KeyPrefs.BindingSlot.A) { keyPrefs[keyDef].keyBindingA = keyDef.defaultKeyCodeA; } else { keyPrefs[keyDef].keyBindingB = keyDef.defaultKeyCodeB; } KeyPrefs.Save(); } } } }
private void ErrorCheckOn(KeyBindingDef keyDef, KeyPrefs.BindingSlot slot) { KeyCode boundKeyCode = this.GetBoundKeyCode(keyDef, slot); if (boundKeyCode != KeyCode.None) { foreach (KeyBindingDef keyBindingDef in this.ConflictingBindings(keyDef, boundKeyCode)) { bool flag = boundKeyCode != keyDef.GetDefaultKeyCode(slot); Log.Error(string.Concat(new object[] { "Key binding conflict: ", keyBindingDef, " and ", keyDef, " are both bound to ", boundKeyCode, ".", (!flag) ? "" : " Fixed automatically." }), false); if (flag) { if (slot == KeyPrefs.BindingSlot.A) { this.keyPrefs[keyDef].keyBindingA = keyDef.defaultKeyCodeA; } else { this.keyPrefs[keyDef].keyBindingB = keyDef.defaultKeyCodeB; } KeyPrefs.Save(); } } } }
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 KeyCode GetDefaultKeyCode(KeyPrefs.BindingSlot slot) { return(slot switch { KeyPrefs.BindingSlot.A => defaultKeyCodeA, KeyPrefs.BindingSlot.B => defaultKeyCodeB, _ => throw new InvalidOperationException(), });
public Dialog_DefineBinding(KeyPrefsData keyPrefsData, KeyBindingDef keyDef, KeyPrefs.BindingSlot slot) { this.keyDef = keyDef; this.slot = slot; this.keyPrefsData = keyPrefsData; base.forcePause = true; base.onlyOneOfTypeAllowed = true; base.absorbInputAroundWindow = true; }
public void CheckConflictsFor(KeyBindingDef keyDef, KeyPrefs.BindingSlot slot) { KeyCode boundKeyCode = this.GetBoundKeyCode(keyDef, slot); if (boundKeyCode != KeyCode.None) { this.EraseConflictingBindingsForKeyCode(keyDef, boundKeyCode, null); this.SetBinding(keyDef, slot, boundKeyCode); } }
public void CheckConflictsFor(KeyBindingDef keyDef, KeyPrefs.BindingSlot slot) { KeyCode boundKeyCode = GetBoundKeyCode(keyDef, slot); if (boundKeyCode != 0) { EraseConflictingBindingsForKeyCode(keyDef, boundKeyCode); SetBinding(keyDef, slot, boundKeyCode); } }
public Dialog_DefineBinding(KeyPrefsData keyPrefsData, KeyBindingDef keyDef, KeyPrefs.BindingSlot slot) { this.keyDef = keyDef; this.slot = slot; this.keyPrefsData = keyPrefsData; this.closeOnAccept = false; this.closeOnCancel = false; this.forcePause = true; this.onlyOneOfTypeAllowed = true; this.absorbInputAroundWindow = true; }
public KeyCode GetDefaultKeyCode(KeyPrefs.BindingSlot slot) { if (slot == KeyPrefs.BindingSlot.A) { return(this.defaultKeyCodeA); } if (slot == KeyPrefs.BindingSlot.B) { return(this.defaultKeyCodeB); } throw new InvalidOperationException(); }
public KeyCode GetBoundKeyCode(KeyBindingDef keyDef, KeyPrefs.BindingSlot slot) { if (!keyPrefs.TryGetValue(keyDef, out var value)) { Log.Error("Key not found in keyprefs: \"" + keyDef.LabelCap + "\""); return(KeyCode.None); } return(slot switch { KeyPrefs.BindingSlot.A => value.keyBindingA, KeyPrefs.BindingSlot.B => value.keyBindingB, _ => throw new InvalidOperationException(), });
public KeyCode GetDefaultKeyCode(KeyPrefs.BindingSlot slot) { switch (slot) { case KeyPrefs.BindingSlot.A: return(defaultKeyCodeA); case KeyPrefs.BindingSlot.B: return(defaultKeyCodeB); default: throw new InvalidOperationException(); } }
public KeyCode GetDefaultKeyCode(KeyPrefs.BindingSlot slot) { KeyCode result; if (slot == KeyPrefs.BindingSlot.A) { result = this.defaultKeyCodeA; } else { if (slot != KeyPrefs.BindingSlot.B) { throw new InvalidOperationException(); } result = this.defaultKeyCodeB; } return(result); }
public KeyCode GetBoundKeyCode(KeyBindingDef keyDef, KeyPrefs.BindingSlot slot) { KeyBindingData keyBindingData; if (!this.keyPrefs.TryGetValue(keyDef, out keyBindingData)) { Log.Error("Key not found in keyprefs: \"" + keyDef.LabelCap + "\"", false); return(KeyCode.None); } if (slot == KeyPrefs.BindingSlot.A) { return(keyBindingData.keyBindingA); } if (slot != KeyPrefs.BindingSlot.B) { throw new InvalidOperationException(); } return(keyBindingData.keyBindingB); }
public KeyCode GetBoundKeyCode(KeyBindingDef keyDef, KeyPrefs.BindingSlot slot) { if (!keyPrefs.TryGetValue(keyDef, out KeyBindingData value)) { Log.Error("Key not found in keyprefs: \"" + keyDef.LabelCap + "\""); return(KeyCode.None); } switch (slot) { case KeyPrefs.BindingSlot.A: return(value.keyBindingA); case KeyPrefs.BindingSlot.B: return(value.keyBindingB); default: throw new InvalidOperationException(); } }
private void SettingButtonClicked(KeyBindingDef keyDef, KeyPrefs.BindingSlot slot) { if (Event.current.button == 0) { Find.WindowStack.Add(new Dialog_DefineBinding(keyPrefsData, keyDef, slot)); Event.current.Use(); } else if (Event.current.button == 1) { List <FloatMenuOption> list = new List <FloatMenuOption>(); list.Add(new FloatMenuOption("ResetBinding".Translate(), delegate { KeyCode keyCode = (slot != 0) ? keyDef.defaultKeyCodeB : keyDef.defaultKeyCodeA; keyPrefsData.SetBinding(keyDef, slot, keyCode); })); list.Add(new FloatMenuOption("ClearBinding".Translate(), delegate { keyPrefsData.SetBinding(keyDef, slot, KeyCode.None); })); Find.WindowStack.Add(new FloatMenu(list)); } }