private static void ReleaseAbstractButtonMapping( IWrappedButton buttonToReset, InputKey keyToRemove) { if (!RegisteredButtons.TryGetValue(buttonToReset, out _)) { throw new Exception("Unknown button: " + buttonToReset); } var mapping = MappingButtonToKeys[buttonToReset]; if (mapping.PrimaryKey == keyToRemove) { mapping = new ButtonMapping(InputKey.None, mapping.SecondaryKey); } if (mapping.SecondaryKey == keyToRemove) { mapping = new ButtonMapping(mapping.PrimaryKey, InputKey.None); } Api.Logger.Important( $"Releasing button mapping: {buttonToReset}; key to remove: {keyToRemove}; mapping: {mapping}"); MappingButtonToKeys[buttonToReset] = mapping; ButtonKeyMappingUpdated?.Invoke(buttonToReset); }
private static FrameworkElement GetInputMappingControl(IWrappedButton button, ButtonInfoAttribute buttonInfo) { var control = new ButtonMappingControl(); control.Setup(button, buttonInfo); return(control); }
private void ButtonKeyMappingUpdatedHandler(IWrappedButton obj) { if (this.Button.Equals(obj)) { this.UpdateMapping(); } }
public static InputKey GetKeyForAbstractButton(IWrappedButton button) { var mapping = GetMappingForAbstractButton(button); return(mapping.PrimaryKey != InputKey.None ? mapping.PrimaryKey : mapping.SecondaryKey); }
public static void SetAbstractButtonMapping( IWrappedButton buttonToRebind, ButtonMapping mapping, bool writeToLog = true) { if (!RegisteredButtons.TryGetValue(buttonToRebind, out var buttonToRebindInfo)) { throw new Exception("Unknown button: " + buttonToRebind); } var buttonCategory = buttonToRebindInfo.Category; foreach (var pair in MappingButtonToKeys.ToList()) { var existingButton = pair.Key; if (existingButton.Equals(buttonToRebind)) { continue; } var existingMapping = pair.Value; if (existingMapping.PrimaryKey != InputKey.None && (existingMapping.PrimaryKey == mapping.PrimaryKey || existingMapping.PrimaryKey == mapping.SecondaryKey)) { if (IsSameCategory(existingButton, buttonCategory)) { // the key is already used - release this mapping ReleaseAbstractButtonMapping(existingButton, existingMapping.PrimaryKey); } } if (existingMapping.SecondaryKey != InputKey.None && (existingMapping.SecondaryKey == mapping.PrimaryKey || existingMapping.SecondaryKey == mapping.SecondaryKey)) { if (IsSameCategory(existingButton, buttonCategory)) { // the key is already used - release this mapping ReleaseAbstractButtonMapping(existingButton, existingMapping.SecondaryKey); } } } if (writeToLog) { Api.Logger.Important($"Setting button mapping: {buttonToRebind}; mapping: {mapping}"); } MappingButtonToKeys[buttonToRebind] = mapping; ButtonKeyMappingUpdated?.Invoke(buttonToRebind); }
public ViewModelButtonMappingControl(IWrappedButton button, ButtonInfoAttribute buttonInfo) { // ReSharper disable once CanExtractXamlLocalizableStringCSharp this.CommandBindKey = new ActionCommandWithParameter( param => this.ExecuteCommandBindKey("Secondary".Equals(param))); this.Button = button; this.ButtonInfo = buttonInfo; this.UpdateMapping(); ClientInputManager.ButtonKeyMappingUpdated += this.ButtonKeyMappingUpdatedHandler; }
public static void ConsumeButton(IWrappedButton button) { if (!MappingButtonToKeys.TryGetValue(button, out var mapping)) { return; //throw new Exception("The button is not mapped, it cannot be consumed"); } RawInput.ConsumeKey(mapping.PrimaryKey); RawInput.ConsumeKey(mapping.SecondaryKey); }
public ViewModelRebindKeyWindow( ViewModelButtonMappingControl viewModelMapping, bool isSecondaryKey, Action onClose) { this.viewModelMapping = viewModelMapping; this.buttonToRebind = viewModelMapping.Button; this.onClose = onClose; this.isSecondaryKey = isSecondaryKey; // ReSharper disable once CanExtractXamlLocalizableStringCSharp this.clientInputContext = ClientInputContext.Start("Key binding") .HandleAll(this.InputCallback); Instance = this; }
private static bool Check( IWrappedButton wrappedButton, Func <InputKey, bool, bool> checkFunc, bool evenIfHandled) { if (!isFrozen) { LoadButtonsMapping(); } if (!MappingButtonToKeys.TryGetValue( wrappedButton, out var mapping)) { // the key is not mapped var buttonType = wrappedButton.WrappedButtonType; ValidateButtonType(buttonType); if (!RegisteredButtonEnums.Contains(buttonType)) { throw new Exception( $"The button enum type is not registered: {buttonType.FullName}. Please register it in your mod initialization code by calling {nameof(ClientInputManager)}.{nameof(RegisterButtonsEnum)}<{buttonType.Name}>()"); } return(false); } if (mapping.PrimaryKey != InputKey.None && checkFunc(mapping.PrimaryKey, evenIfHandled)) { // check successful return(true); } if (mapping.SecondaryKey != InputKey.None && checkFunc(mapping.SecondaryKey, evenIfHandled)) { // check successful return(true); } return(false); }
public void Setup(IWrappedButton button, ButtonInfoAttribute buttonInfo) { this.button = button; this.buttonInfo = buttonInfo; }
public ButtonCallback(IWrappedButton wrappedButton, Action callback, bool evenIfHandled) { this.WrappedButton = wrappedButton; this.Callback = callback; this.EvenIfHandled = evenIfHandled; }
public static ButtonInfoAttribute GetButtonInfo(IWrappedButton button) { return(RegisteredButtons.Find(button)); }
public static ButtonMapping GetMappingForAbstractButton(IWrappedButton button) { return(MappingButtonToKeys.Find(button)); }
private static string GetButtonId(IWrappedButton wrappedButton) { return(wrappedButton.WrappedButtonType.FullName + "." + wrappedButton.WrappedButtonName); }
internal static bool IsButtonUp(IWrappedButton wrappedButton, bool evenIfHandled = false) { return(Check(wrappedButton, DelegateRawInputIsKeyUp, evenIfHandled)); }
private static void ApplyDefaultMapping(IWrappedButton button, ButtonInfoAttribute info) { MappingButtonToKeys.Add(button, info.DefaultButtonMapping); }
private static bool IsSameCategory( IWrappedButton foundButton, string buttonCategory) { return(RegisteredButtons[foundButton].Category == buttonCategory); }