public Anchor(string NewLabelText, string NewLabelDescription, AnchorType InType, EntityBox <EntityType> InOwner) { LabelText = NewLabelText; LabelDescription = NewLabelDescription; Type = InType; Owner = InOwner; }
public virtual void HandleContextClick() { EntityBox <EntityType> HoveredBox = MouseOverBox(); if (HoveredBox == null) { if (HandleContextMenu()) { Event.current.Use(); } } else if (GroupSelectedBoxes.Count == 0) { GenericMenu GenericContextMenu = new GenericMenu(); if (HoveredBox.HandleContextMenu(GenericContextMenu)) { GenericContextMenu.ShowAsContext(); Event.current.Use(); } } else { if (HandleGroupSelectContextMenu()) { Event.current.Use(); } } }
public virtual void BuildConnectionsFromSourceData() { List <EntityLink <EntityType> > InputEvents = GetInputEvents(); foreach (EntityLink <EntityType> CurrentLink in InputEvents) { Anchor <EntityType> LocalAnchor = GetAnchor("Input" + CurrentLink.Name); if (LocalAnchor != null) { foreach (EntityLink <EntityType> CurrentRemoteLink in CurrentLink.LinkedEntities) { if (CurrentRemoteLink.GetOwner() != null && CurrentRemoteLink.GetOwner().OutputEvents.Contains(CurrentRemoteLink)) { EntityBox <EntityType> RemoteBox = Owner.GetEntityBoxForEntity(CurrentRemoteLink.GetOwner()); if (RemoteBox != null) { Anchor <EntityType> RemoteAnchor = RemoteBox.GetAnchor("Output" + CurrentRemoteLink.Name); if (RemoteAnchor != null) { Owner.ConnectInputToOutput(LocalAnchor, RemoteAnchor); } } } } } } }
public virtual void BreakAllConnectionsForBox(EntityBox <EntityType> BoxToDisconnect) { List <Anchor <EntityType> > FullAnchorList = BoxToDisconnect.GetAllAnchors(); foreach (Anchor <EntityType> CurrentAnchor in FullAnchorList) { BreakAllConnectionsForAnchor(CurrentAnchor); } }
public virtual void RemoveBox(EntityBox <EntityType> BoxToRemove) { BreakAllConnectionsForBox(BoxToRemove); Boxes.Remove(BoxToRemove); if (SelectedBox == BoxToRemove) { SelectedBox = null; Selection.activeObject = null; } }
protected virtual void CheckAndResolveBoxCollision(EntityBox <EntityType> BoxA, EntityBox <EntityType> BoxB) { Rect BoxABounds = BoxA.GetBoxBounds(); Rect BiggerBoxABounds = new Rect(BoxABounds.x - MinimumSafeDistance, BoxABounds.y - MinimumSafeDistance, BoxABounds.width + (2 * MinimumSafeDistance), BoxABounds.height + (2 * MinimumSafeDistance)); Rect BoxBBounds = BoxB.GetBoxBounds(); Rect BiggerBoxBBounds = new Rect(BoxBBounds.x - MinimumSafeDistance, BoxBBounds.y - MinimumSafeDistance, BoxBBounds.width + (2 * MinimumSafeDistance), BoxBBounds.height + (2 * MinimumSafeDistance)); if (VisualScriptingDrawing.RectOverlapsRect(BiggerBoxABounds, BiggerBoxBBounds)) { Rect CurrentRelativeRect = BiggerBoxABounds; bool bNewSpotFound = false; Rect NewBoxBBounds = BiggerBoxBBounds; while (!bNewSpotFound) { bool bFoundConflict = false; NewBoxBBounds = new Rect(CurrentRelativeRect.x + CurrentRelativeRect.width + 1, CurrentRelativeRect.y, BiggerBoxBBounds.width, BiggerBoxBBounds.height); for (int CurrentBox = 0; CurrentBox < Boxes.Count; ++CurrentBox) { if (Boxes[CurrentBox] != BoxB) { if (VisualScriptingDrawing.RectOverlapsRect(NewBoxBBounds, Boxes[CurrentBox].GetBoxBounds())) { bFoundConflict = true; Rect NewBoxBounds = Boxes[CurrentBox].GetBoxBounds(); CurrentRelativeRect = new Rect(NewBoxBounds.x - MinimumSafeDistance, NewBoxBounds.y - MinimumSafeDistance, NewBoxBounds.width + (2 * MinimumSafeDistance), NewBoxBounds.height + (2 * MinimumSafeDistance)); } } } if (!bFoundConflict) { bNewSpotFound = true; } } BoxB.MoveBoxTo(new Vector2(NewBoxBBounds.x + MinimumSafeDistance, NewBoxBBounds.y + MinimumSafeDistance)); } }
public virtual void OnDisconnectedAnchors(Anchor <EntityType> LocalAnchor, Anchor <EntityType> RemoteAnchor) { EntityBox <EntityType> RemoteBox = RemoteAnchor.Owner; string LocalAnchorName = ""; string RemoteAnchorName = ""; if (Inputs.Contains(LocalAnchor)) { LocalAnchorName = "Input"; } else { LocalAnchorName = "Output"; } LocalAnchorName += LocalAnchor.GetLabelText(); if (RemoteBox.Inputs.Contains(RemoteAnchor)) { RemoteAnchorName = "Input"; } else { RemoteAnchorName = "Output"; } RemoteAnchorName += RemoteAnchor.GetLabelText(); EntityLink <EntityType> LocalLink = GetLinkByName(LocalAnchorName); EntityLink <EntityType> RemoteLink = RemoteBox.GetLinkByName(RemoteAnchorName); if (LocalLink != null && RemoteLink != null) { LocalLink.BreakLink(RemoteLink); } }
public virtual void CleanDirtyBox(EntityBox <EntityType> DirtyBox) { DirtyBox.UpdateBoxBounds(); ArrangeBoxes(); DirtyBox.CleanedUp(); }
public virtual void AddBox(EntityBox <EntityType> NewBox) { Boxes.Add(NewBox); }
public virtual void UpdateWindow() { if (Boxes == null) { Close(); return; } InputState.Update(this, ScrollPosition); bInDragSelect = false; bool bUpdateDragArea = false; if (Event.current.type == EventType.ContextClick) { HandleContextClick(); } else if (Event.current.type == EventType.MouseDown) { if (InputState.IsMouseButtonDown(InputState.MouseButton.Mouse_Middle)) { SelectedBox = null; Selection.activeObject = null; bInDragSelect = true; DragSelectStartPosition = InputState.GetLocalMousePosition(this, Vector2.zero); } else { EntityBox <EntityType> NewSelectedBox = MouseOverBox(); if (NewSelectedBox == null) { Selection.activeObject = null; GroupSelectedBoxes.Clear(); } else if (NewSelectedBox != SelectedBox) { if (GroupSelectedBoxes.Count == 0 || !GroupSelectedBoxes.Contains(NewSelectedBox)) { GroupSelectedBoxes.Clear(); NewSelectedBox.GainedFocus(); } } SelectedBox = NewSelectedBox; } } else if (Event.current.type == EventType.MouseDrag) { bool bShouldCheckDrag = true; if (InputState.IsMouseButtonDown(InputState.MouseButton.Mouse_Middle) && !InputState.IsMouseButtonDown(InputState.MouseButton.Mouse_Left)) { bShouldCheckDrag = false; if (InputState.IsModifierDown(InputState.ModifierKeys.Key_Control)) { bShouldCheckDrag = true; bInDragSelect = true; bUpdateDragArea = true; } else { ScrollPosition -= Event.current.delta; } } else { bInDragSelect = false; bShouldCheckDrag = DragLink != null || GroupSelectedBoxes.Count > 0; } if (bShouldCheckDrag) { Vector2 CurrentMousePosition = InputState.GetLocalMousePosition(this, Vector2.zero); CurrentMousePosition -= ScrollPosition; if (CurrentMousePosition.x < position.width * EdgeAreaToStartMovement) { CurrentMoveDirection = MoveDirection.Move_Left; } else if (CurrentMousePosition.x > position.width * (1.0f - EdgeAreaToStartMovement)) { CurrentMoveDirection = MoveDirection.Move_Right; } else if (CurrentMousePosition.y < position.height * EdgeAreaToStartMovement) { CurrentMoveDirection = MoveDirection.Move_Up; } else if (CurrentMousePosition.y > position.height * (1.0f - EdgeAreaToStartMovement)) { CurrentMoveDirection = MoveDirection.Move_Down; } else { CurrentMoveDirection = MoveDirection.Move_Stopped; } } } else if (Event.current.type == EventType.MouseUp) { if (!InputState.IsMouseButtonDown(InputState.MouseButton.Mouse_Middle)) { LastDragArea = new Rect(0.0f, 0.0f, 0.0f, 0.0f); bInDragSelect = false; CurrentMoveDirection = MoveDirection.Move_Stopped; } } else if (!InputState.IsMouseButtonDown(InputState.MouseButton.Mouse_Left) && !InputState.WasLastMouseUpHandled(this, InputState.MouseButton.Mouse_Left)) { EntityBox <EntityType> NewSelectedBox = MouseOverBox(); if (NewSelectedBox != null) { InputState.HandledMouseUp(InputState.MouseButton.Mouse_Left); if (InputState.WasLastClickDoubleClick(InputState.MouseButton.Mouse_Left)) { InputState.HandledDoubleClick(InputState.MouseButton.Mouse_Left); if (GroupSelectedBoxes.Count == 0 || !GroupSelectedBoxes.Contains(NewSelectedBox)) { GroupSelectedBoxes.Clear(); NewSelectedBox.HandleDoubleClick(); } } } } LastScrollDelta = new Vector2(0.0f, 0.0f); switch (CurrentMoveDirection) { case MoveDirection.Move_Left: LastScrollDelta = new Vector2(-EdgeMovementSpeeds * Time.deltaTime, 0.0f); bUpdateDragArea = bInDragSelect; break; case MoveDirection.Move_Right: LastScrollDelta = new Vector2(EdgeMovementSpeeds * Time.deltaTime, 0.0f); bUpdateDragArea = bInDragSelect; break; case MoveDirection.Move_Up: LastScrollDelta = new Vector2(0.0f, -EdgeMovementSpeeds * Time.deltaTime); bUpdateDragArea = bInDragSelect; break; case MoveDirection.Move_Down: LastScrollDelta = new Vector2(0.0f, EdgeMovementSpeeds * Time.deltaTime); bUpdateDragArea = bInDragSelect; break; default: break; } ScrollPosition += LastScrollDelta; if (bUpdateDragArea) { Vector2 CurrentPos = InputState.GetLocalMousePosition(this, Vector2.zero); Rect DragArea = new Rect(0.0f, 0.0f, 0.0f, 0.0f); if (DragSelectStartPosition.x < CurrentPos.x) { DragArea.x = DragSelectStartPosition.x; DragArea.width = CurrentPos.x - DragSelectStartPosition.x; } else { DragArea.x = CurrentPos.x; DragArea.width = DragSelectStartPosition.x - CurrentPos.x; } if (DragSelectStartPosition.y < CurrentPos.y) { DragArea.y = DragSelectStartPosition.y; DragArea.height = CurrentPos.y - DragSelectStartPosition.y; } else { DragArea.y = CurrentPos.y; DragArea.height = DragSelectStartPosition.y - CurrentPos.y; } LastDragArea = new Rect(DragArea.x - ScrollPosition.x, DragArea.y - ScrollPosition.y, DragArea.width, DragArea.height); GroupSelectAllBoxesInArea(DragArea); } CheckForDirtyBoxes(); }
public override void BuildConnectionsFromSourceData() { if (bIsInputBox) { List <EntityLink <EntityType> > OutputEvents = GetStartEntities(); foreach (EntityLink <EntityType> CurrentLink in OutputEvents) { Anchor <EntityType> LocalAnchor = GetAnchor("Output" + CurrentLink.Name); if (LocalAnchor != null) { foreach (EntityLink <EntityType> CurrentRemoteLink in CurrentLink.LinkedEntities) { if (CurrentRemoteLink.GetOwner() != null) { if (CurrentRemoteLink.GetOwner().InputEvents.Contains(CurrentRemoteLink)) { EntityBox <EntityType> RemoteBox = Owner.GetEntityBoxForEntity(CurrentRemoteLink.GetOwner()); if (RemoteBox != null) { Anchor <EntityType> RemoteAnchor = RemoteBox.GetAnchor("Input" + CurrentRemoteLink.Name); if (RemoteAnchor != null) { Owner.ConnectInputToOutput(LocalAnchor, RemoteAnchor); } } } } else { EntityBox <EntityType> EndBox = Owner.GetOutputBox(); if (EndBox != null) { Anchor <EntityType> RemoteAnchor = EndBox.GetAnchor("Input" + CurrentRemoteLink.Name); if (RemoteAnchor != null) { Owner.ConnectInputToOutput(LocalAnchor, RemoteAnchor); } } } } } } } else { List <EntityLink <EntityType> > InputEvents = GetEndEntities(); foreach (EntityLink <EntityType> CurrentLink in InputEvents) { Anchor <EntityType> LocalAnchor = GetAnchor("Input" + CurrentLink.Name); if (LocalAnchor != null) { foreach (EntityLink <EntityType> CurrentRemoteLink in CurrentLink.LinkedEntities) { if (CurrentRemoteLink.GetOwner() != null) { if (CurrentRemoteLink.GetOwner().OutputEvents.Contains(CurrentRemoteLink)) { EntityBox <EntityType> RemoteBox = Owner.GetEntityBoxForEntity(CurrentRemoteLink.GetOwner()); if (RemoteBox != null) { Anchor <EntityType> RemoteAnchor = RemoteBox.GetAnchor("Output" + CurrentRemoteLink.Name); if (RemoteAnchor != null) { Owner.ConnectInputToOutput(LocalAnchor, RemoteAnchor); } } } } else { EntityBox <EntityType> StartBox = Owner.GetInputBox(); if (StartBox != null) { Anchor <EntityType> RemoteAnchor = StartBox.GetAnchor("Input" + CurrentRemoteLink.Name); if (RemoteAnchor != null) { Owner.ConnectInputToOutput(LocalAnchor, RemoteAnchor); } } } } } } } }