public override void Input() { if (!ModalActive) { return; } IInputMap inputMap = Woofer.Controller.InputManager.ActiveInputMap; if (inputMap.Pulse.Consume()) { Mode++; if ((MultipleAllowed && Mode > 3) || (!MultipleAllowed && Mode > 1)) { Mode = 0; } SelectionLocked = false; } if (Mode == Edit) { if (!SelectionLocked) { UpdateSelected(); if (SelectedBox != null && inputMap.Jump.Consume()) { SelectionLocked = true; } } if (SelectionLocked) { if (!CursorSystem.Dragging) { DraggingSide = -1; } FaceOutline.Bounds = new Rectangle(FaceOutline.Bounds?.X ?? 0, FaceOutline.Bounds?.Y ?? 0, 0, 0); Rectangle selectedBounds = SelectedBox.ToRectangle() + Pivot; if (CursorSystem.StartedDragging) { PreResizeBounds = selectedBounds; } int highlightedSide = UpdateSelectedFace(); if (highlightedSide != -1 && DraggingSide == -1 && CursorSystem.Dragging) { DraggingSide = highlightedSide; } if (CursorSystem.Dragging && DraggingSide == -1 && selectedBounds.Contains(CursorSystem.CursorPos)) { DraggingSide = 4; } if (CursorSystem.Dragging && DraggingSide != -1 && PreResizeBounds != Rectangle.Empty) { if (DraggingSide == 3) //Left { double prevRight = SelectedBox.Right; SelectedBox.X = (CursorSystem.CursorPos.X - Pivot.X); SelectedBox.Width = prevRight - SelectedBox.X; if (SelectedBox.Width < 0) { double min = Math.Min(SelectedBox.Left, SelectedBox.Right); double max = Math.Max(SelectedBox.Left, SelectedBox.Right); SelectedBox.X = min; SelectedBox.Width = max - min; DraggingSide = 1; } } else if (DraggingSide == 1) //Right { SelectedBox.Width = (CursorSystem.CursorPos.X - SelectedBox.X) - Pivot.X; if (SelectedBox.Width < 0) { double min = Math.Min(SelectedBox.Left, SelectedBox.Right); double max = Math.Max(SelectedBox.Left, SelectedBox.Right); SelectedBox.X = min; SelectedBox.Width = max - min; DraggingSide = 3; } } else if (DraggingSide == 2) //Bottom { double prevTop = SelectedBox.Top; SelectedBox.Y = (CursorSystem.CursorPos.Y - Pivot.Y); SelectedBox.Height = prevTop - SelectedBox.Y; if (SelectedBox.Height < 0) { double min = Math.Min(SelectedBox.Bottom, SelectedBox.Top); double max = Math.Max(SelectedBox.Bottom, SelectedBox.Top); SelectedBox.Y = min; SelectedBox.Height = max - min; DraggingSide = 0; } } else if (DraggingSide == 0) //Top { SelectedBox.Height = (CursorSystem.CursorPos.Y - SelectedBox.Y) - Pivot.Y; if (SelectedBox.Height < 0) { double min = Math.Min(SelectedBox.Bottom, SelectedBox.Top); double max = Math.Max(SelectedBox.Bottom, SelectedBox.Top); SelectedBox.Y = min; SelectedBox.Height = max - min; DraggingSide = 2; } } else if (DraggingSide == 4) //Middle { SelectedBox.X = PreResizeBounds.X + (CursorSystem.CursorPos.X - CursorSystem.SelectionStart.X) - Pivot.X; SelectedBox.Y = PreResizeBounds.Y + (CursorSystem.CursorPos.Y - CursorSystem.SelectionStart.Y) - Pivot.Y; } } } } else if (Mode == Create) { if (CursorSystem.StartedDragging) { CollisionBox newBox = new CollisionBox(CursorSystem.SelectionRectangle - Pivot); Boxes.Add(newBox); IOutline newOutline = new CollisionBoxOutline(Pivot, newBox, Color.Orange); Outlines.Add(newOutline); Owner.Events.InvokeEvent(new BeginOverlay(newOutline)); Creating = true; } if (CursorSystem.Dragging && Creating) { CollisionBox newBox = Boxes.Last(); newBox.X = CursorSystem.SelectionRectangle.X - Pivot.X; newBox.Y = CursorSystem.SelectionRectangle.Y - Pivot.Y; newBox.Width = CursorSystem.SelectionRectangle.Width; newBox.Height = CursorSystem.SelectionRectangle.Height; } if (CursorSystem.StoppedDragging && Creating) { CollisionBox newBox = Boxes.Last(); if (newBox.Area == 0) { RemoveBox(newBox); } Creating = false; } } else if (Mode == Delete) { UpdateSelected(); if (SelectedBox != null) { IOutline associatedOutline = null; foreach (IOutline outline in Outlines) { if (outline is CollisionBoxOutline boxOutline) { if (boxOutline.Box == SelectedBox) { boxOutline.Color = Color.Red; boxOutline.Thickness = 4; associatedOutline = outline; } } } if (inputMap.Jump.Consume()) { RemoveBox(SelectedBox); } } } else if (Mode == TweakFaces) { if (!SelectionLocked) { UpdateSelected(); if (SelectedBox != null && inputMap.Jump.Consume()) { SelectionLocked = true; } } if (SelectionLocked) { FaceOutline.Bounds = new Rectangle(FaceOutline.Bounds?.X ?? 0, FaceOutline.Bounds?.Y ?? 0, 0, 0); int highlightedFace = UpdateSelectedFace(); if (highlightedFace != -1 && inputMap.Jump.Consume()) { Owner.Events.InvokeEvent(new CollisionFaceSelectEvent(SelectedBox, highlightedFace)); Owner.Events.InvokeEvent(new ForceModalChangeEvent("collision_face_view", null)); CursorSystem.ModalActive = false; ModalActive = false; } } } }
public override void EventFired(object sender, Event e) { if (e is StartCollisionModeEvent start) { Pivot = start.Pivot; Callback = start.Callback; MultipleAllowed = start.MultipleBoxes; Boxes = start.Boxes.ToList(); Mode = Edit; foreach (CollisionBox box in Boxes) { IOutline outline = new CollisionBoxOutline(Pivot, box, Color.Purple); Outlines.Add(outline); Owner.Events.InvokeEvent(new BeginOverlay(outline)); } IOutline pivotOutline = new RectangleOutline(new Rectangle(Pivot - new Vector2D(1, 1), new Size(2, 2)), Color.White, 4); Outlines.Add(pivotOutline); Owner.Events.InvokeEvent(new BeginOverlay(pivotOutline)); FaceOutline = new RectangleOutline(new Rectangle(0, 0, 0, 0), Color.White, 4); Outlines.Add(FaceOutline); Owner.Events.InvokeEvent(new BeginOverlay(FaceOutline)); } else if (e is ModalChangeEvent changed) { //changed.Valid = false; //Owner.Events.InvokeEvent(new ForceModalChangeEvent("editor_cursor", null)); ModalActive = true; ModalVisible = true; CursorSystem.ModalActive = true; CursorSystem.DraggingEnabled = true; if (changed.From != "collision_face_view") { CursorSystem.SwitchToModal = changed.From; } //CursorSystem.OutlinesEnabled = true; } else if (e is BeginModalChangeEvent bmce) { if (SelectionLocked) { SelectionLocked = false; return; } bmce.SystemName = CursorSystem.SwitchToModal; ModalActive = false; ModalVisible = false; CursorSystem.ModalActive = false; CursorSystem.DraggingEnabled = false; Callback(Boxes); Callback = null; foreach (IOutline outline in Outlines) { Owner.Events.InvokeEvent(new RemoveOverlay(outline)); } Outlines.Clear(); Boxes.Clear(); } }