public void TryDisconnectLines(StandardLine l1, StandardLine l2, bool undo = true) { if (l1 == null || l2 == null) { return; } Vector2d joint; if (l1.Position == l2.Position || l1.Position == l2.Position2) { joint = l1.Position; } else if (l1.Position2 == l2.Position || l1.Position2 == l2.Position2) { joint = l1.Position2; } else { return; } //var leftlink = (l1.CompliantPosition == joint && l2.CompliantPosition2 == joint); var rightlink = (l1.CompliantPosition2 == joint && l2.CompliantPosition == joint); if (rightlink) { l1.Next = null; l1.RemoveExtension(StandardLine.ExtensionDirection.Right); l2.Prev = null; l2.RemoveExtension(StandardLine.ExtensionDirection.Left); if (undo) { UndoManager.AddExtensionChange(l1, l2, false); } } else { l1.Prev = null; l1.RemoveExtension(StandardLine.ExtensionDirection.Left); l2.Next = null; l2.RemoveExtension(StandardLine.ExtensionDirection.Right); if (undo) { UndoManager.AddExtensionChange(l2, l1, false); } } }
public void SelectLine(Vector2d pos) { _started = true; var gamepos = MouseCoordsToGame(pos); var ssnap = Snap(gamepos); var snap = ssnap as StandardLine; var keyboard = Keyboard.GetState(); if (snap == null) { if (ssnap == null) { _started = false; return; } else//scenery { if ((ssnap.Position - gamepos).Length < (ssnap.Position2 - gamepos).Length) { _joint = Joint.Left; _startPos = ssnap.Position; } else { _joint = Joint.Right; _startPos = ssnap.Position2; } _snappedline = Snap(_startPos, ssnap); if (_snappedline is StandardLine) { _snappedline = null; } _nonphysicalline = ssnap; _originalPos1 = _nonphysicalline.Position; _originalPos2 = _nonphysicalline.Position2; UpdateTooltip(); game.Invalidate(); if (keyboard[Key.ControlLeft] || keyboard[Key.ControlRight]) { _joint = Joint.Both; _snappedline = null; } return; } } if (keyboard[Key.AltLeft] || keyboard[Key.AltRight]) { if (game.Track.Animating) { game.Track.EnterPlayback(); { if (!DoLifelock()) { LifeLock = true; } else { _started = false; game.Track.ExitPlayback(); return; } game.Track.ExitPlayback(); } } } if ((snap.Position - gamepos).Length < (snap.Position2 - gamepos).Length) { _joint = Joint.Left; _startPos = snap.Position; } else { _joint = Joint.Right; _startPos = snap.Position2; } _snappedline = Snap(_startPos, ssnap); if (!(_snappedline is StandardLine)) { _snappedline = null; } else { if ((_snappedline.Position - _startPos).Length < (_snappedline.Position2 - _startPos).Length) { _snapjoint = Joint.Left; } else { _snapjoint = Joint.Right; } _snaporiginalpos1 = _snappedline.Position; _snaporiginalpos2 = _snappedline.Position2; } if (keyboard[Key.ControlLeft] || keyboard[Key.ControlRight]) { _joint = Joint.Both; _snappedline = null; } _line = snap; UpdateTooltip(); _originalPos1 = _line.CompliantPosition; _originalPos2 = _line.CompliantPosition2; if (_line.Prev != null) { _prev = _line.Prev; _line.Prev.Next = null; _line.Prev.RemoveExtension(StandardLine.ExtensionDirection.Right); _line.RemoveExtension(StandardLine.ExtensionDirection.Left); _line.Prev = null; } else { _prev = null; } if (_line.Next != null) { _next = _line.Next; _line.Next.Prev = null; _line.Next.RemoveExtension(StandardLine.ExtensionDirection.Left); _line.RemoveExtension(StandardLine.ExtensionDirection.Right); _line.Next = null; } else { _next = null; } _snext = null; _sprev = null; if (_snappedline is StandardLine) { var snl = _snappedline as StandardLine; if (snl.Next != null) { _snext = snl.Next; snl.Next.Prev = null; snl.Next.RemoveExtension(StandardLine.ExtensionDirection.Left); snl.RemoveExtension(StandardLine.ExtensionDirection.Right); snl.Next = null; } if (snl.Prev != null) { _sprev = snl.Prev; snl.Prev.Next = null; snl.Prev.RemoveExtension(StandardLine.ExtensionDirection.Right); snl.RemoveExtension(StandardLine.ExtensionDirection.Left); snl.Prev = null; } } game.Track.ChangeMade(_originalPos1, _originalPos2); game.Invalidate(); }