private void HandleDropAt(Vector2 mousePosition) { if (this.activeDragNode is Grapheme dragNode) { Physics2DDirectSpaceState spaceState = GetWorld2d().DirectSpaceState; Godot.Collections.Array phonemeCheck = spaceState.IntersectPoint(mousePosition, maxResults: 1, collideWithAreas: true, collisionLayer: 1); if (phonemeCheck.Count > 0) { Area2D phonemeCollider = (Area2D)((Godot.Collections.Dictionary)phonemeCheck[0])["collider"]; Phoneme phoneme = phonemeCollider.GetParent <Phoneme>(); phoneme.AcceptDrop(dragNode); } } }
public static Array <Physics2DSpaceQueryResult> IntersectPointStructured( this Physics2DDirectSpaceState state, Vector2 point, int maxResults = 32, Godot.Collections.Array exclude = null, uint collisionLayer = 2147483647, bool bodyCollide = true, bool areaCollide = false ) { var intersect = state.IntersectPoint(point, maxResults, exclude, collisionLayer, bodyCollide, areaCollide); var result = new Array <Physics2DSpaceQueryResult>(); result.Resize(intersect.Count); for (int i = 0; i < intersect.Count; i++) { result[i] = new Physics2DSpaceQueryResult((Dictionary)intersect[i]); } return(result); }
public override void _Input(InputEvent @event) { if (@event is InputEventMouseMotion eventMouseMotion && this.activeDragNode != this && this.activeDragNode is Grapheme dragNode) { dragNode.Translate(eventMouseMotion.Relative); } if (@event is InputEventMouseButton eventMouseButton && this.activeDragNode == this && eventMouseButton.Pressed == true && eventMouseButton.ButtonIndex == 1) { Physics2DDirectSpaceState spaceState = GetWorld2d().DirectSpaceState; Godot.Collections.Array graphemeCheck = spaceState.IntersectPoint(eventMouseButton.Position, maxResults: 1, collideWithAreas: true, collisionLayer: 2); if (graphemeCheck.Count > 0) { Area2D graphemeCollider = (Area2D)((Godot.Collections.Dictionary)graphemeCheck[0])["collider"]; Grapheme grapheme = graphemeCollider.GetParent <Grapheme>(); this.Drag(grapheme); } } if (@event is InputEventMouseButton eventMouseButtonRelease && this.activeDragNode != this && eventMouseButtonRelease.Pressed == false && eventMouseButtonRelease.ButtonIndex == 1) { this.Drop(eventMouseButtonRelease.Position); } }
public IMapClickable GetMostClickableAt(Vector2 position) { var collisions = worldSpace.IntersectPoint(position, 32, null, 2147483647, true, true); return(GetMostClickable(collisions)); }
public override void _PhysicsProcess(float delta) { if ((Input.IsActionJustPressed("ui_mouse_click") || Input.IsActionJustPressed("ui_right_click")) && !Input.IsActionPressed("ui_shift")) { Physics2DDirectSpaceState spaceState = GetWorld2d().DirectSpaceState; Godot.Collections.Array result = spaceState.IntersectPoint(GetGlobalMousePosition(), 32, null, 1, false, true); if (result.Count == 0) { ClientVariables.SelectedTokens.Clear(); } else { Dictionary <int, Node> tokenDictionary = new Dictionary <int, Node>(); int topIndex = 0; foreach (Godot.Collections.Dictionary hit in result) { if (hit.Contains("collider")) { if (hit["collider"].GetType().Name == "Area2D") { Area2D collider = (Area2D)hit["collider"]; Node token = collider.GetParent().GetParent(); tokenDictionary.Add(token.GetIndex(), token); if (topIndex < token.GetIndex()) { topIndex = token.GetIndex(); } } } } if (tokenDictionary.Count > 0) { Node pressedToken = tokenDictionary[topIndex]; if (Input.IsActionPressed("ui_control")) { if (ClientVariables.SelectedTokens.Contains(pressedToken)) { ClientVariables.SelectedTokens.Remove(pressedToken); } else { ClientVariables.SelectedTokens.Add(pressedToken); } } else { bool found = false; foreach (Node selectedToken in ClientVariables.SelectedTokens) { if (tokenDictionary.ContainsValue(selectedToken)) { found = true; } } if (!found) { ClientVariables.SelectedTokens.Clear(); ClientVariables.SelectedTokens.Add(pressedToken); } } if (Input.IsActionJustPressed("ui_right_click")) { Token token = (Token)pressedToken; token.PopupMenu.Visible = true; } if (Input.IsActionJustPressed("ui_mouse_click")) { Token token = (Token)pressedToken; token.PopupMenu.Visible = false; } } } } }