internal static InputEventItem BuildGUI(InputActionItem associatedAction, SpecifiedInputKey @event) { var result = (InputEventItem)associatedAction.GroupList.InputEventItemScene.Instance(); result.AssociatedAction = new WeakReference <InputActionItem>(associatedAction); result.AssociatedEvent = @event; return(result); }
internal static InputEventItem BuildGUI(InputActionItem associatedAction, SpecifiedInputKey @event) { if (associatedAction.GroupList == null) { throw new ArgumentException("Action doesn't have group list", nameof(associatedAction)); } var result = (InputEventItem)associatedAction.GroupList.InputEventItemScene.Instance(); result.AssociatedAction = new WeakReference <InputActionItem>(associatedAction); result.AssociatedEvent = @event; return(result); }
private bool CheckNewKeyConflicts(InputEvent @event, InputGroupList groupList, SpecifiedInputKey old) { // Get the conflicts with the new input. var conflict = groupList.Conflicts(this); if (conflict != null) { AssociatedEvent = old; // If there are conflicts detected reset the changes and ask the user. groupList.ShowInputConflictDialog(this, conflict, (InputEventWithModifiers)@event); return(true); } var associatedAction = Action; // Check if the input is already defined for this action // This code works by finding a pair for (var i = 0; i < associatedAction.Inputs.Count; i++) { for (var x = i + 1; x < associatedAction.Inputs.Count; x++) { // Pair found (input already defined) if (!associatedAction.Inputs[i].Equals(associatedAction.Inputs[x])) { continue; } // Set AssociatedEvent to null to not delete the wrong InputEventItem, // because Equals treats it the same with the same AssociatedEvent. AssociatedEvent = null; Delete(); return(true); } } return(false); }
/// <summary> /// Performs the key reassigning. /// Checks if it is waiting for a user input and if there are any conflicts (opens a warning dialog /// if there is any). /// Overrides the old input with the new one and update the godot InputMap. /// </summary> public override void _Input(InputEvent @event) { var groupList = GroupList; if (groupList == null) { GD.PrintErr("InputEventItem has no group list"); return; } if (groupList.IsConflictDialogOpen()) { return; } // Only InputEventMouseButton and InputEventKey are supported now if (!(@event is InputEventMouseButton) && !(@event is InputEventKey)) { return; } // Hacky custom button press detection if (@event is InputEventMouseButton mouseEvent) { if (xButton.IsHovered() && !xButton.Disabled) { GetTree().SetInputAsHandled(); Delete(); // Rebind canceled, alert the InputManager so it can resume getting input InputManager.PerformingRebind = false; return; } if (button.IsHovered() && !WaitingForInput && mouseEvent.Pressed && !button.Disabled) { GetTree().SetInputAsHandled(); OnButtonPressed(mouseEvent); return; } } if (!WaitingForInput) { return; } if (wasPressingButton) { wasPressingButton = false; return; } if (@event is InputEventKey key) { switch (key.Scancode) { case (uint)KeyList.Escape: { GetTree().SetInputAsHandled(); WaitingForInput = false; // Rebind canceled, alert the InputManager so it can resume getting input InputManager.PerformingRebind = false; if (AssociatedEvent == null) { Delete(); } else { UpdateButtonText(); } return; } case (uint)KeyList.Alt: case (uint)KeyList.Shift: case (uint)KeyList.Control: return; } } else if (@event is InputEventMouseButton mouse) { if (!mouse.Pressed) { return; } } // The old key input event. Null if this event is assigned a value the first time. var old = AssociatedEvent; AssociatedEvent = new SpecifiedInputKey((InputEventWithModifiers)@event); GetTree().SetInputAsHandled(); // Check conflicts, and don't proceed if there is a conflict if (CheckNewKeyConflicts(@event, groupList, old)) { return; } OnKeybindingSuccessfullyChanged(); }