private bool ToggleSelection(Vector2d gamepos) { using (var trk = game.Track.CreateTrackWriter()) { var line = SelectLine(trk, gamepos, out bool knob); if (line != null) { if (_selectedlines.Contains(line.ID)) { _selectedlines.Remove(line.ID); _selection.RemoveAt( _selection.FindIndex( x => x.line.ID == line.ID)); line.SelectionState = SelectionState.None; } else { _selectedlines.Add(line.ID); var selection = new LineSelection(line, true, null); _selection.Add(selection); line.SelectionState = SelectionState.Selected; } _selectionbox = GetBoxFromSelected(_selection); game.Track.RedrawLine(line); return(true); } } return(false); }
public override void OnUndoRedo(bool isundo, object undohint) { if (Active && (_selection.Count != 0 || _boxselection.Count != 0) && (undohint is int[] lineids)) { if (lineids.Length != 0) { Stop(false); _hoverline = null; Active = true; using (var trk = game.Track.CreateTrackWriter()) { foreach (var lineid in lineids) { var line = trk.Track.LineLookup[lineid]; _selectedlines.Add(line.ID); var selection = new LineSelection(line, true, null); _selection.Add(selection); line.SelectionState = SelectionState.Selected; game.Track.RedrawLine(line); } } _selectionbox = GetBoxFromSelected(_selection); return; } } Stop(true); }
private void DropLine() { if (_active) { _hoverline = _selection.line; _hoverknob = !_selection.BothJoints; _hoverknobjoint1 = _selection.joint1; } _lifelocking = false; if (_active) { if (_selection != null) { game.Track.UndoManager.BeginAction(); game.Track.UndoManager.AddChange(_selection.clone, _selection.line); foreach (var s in _selection.snapped) { game.Track.UndoManager.AddChange(s.clone, s.line); } game.Track.UndoManager.EndAction(); } game.Invalidate(); } _active = false; _selection = null; }
private bool SelectLine(Vector2d gamepos) { using (var trk = game.Track.CreateTrackReader()) { var line = SelectLine(trk, gamepos, out bool knob); if (line != null) { _clickstart = gamepos; _active = true; //is it a knob? if (knob) { if (InputUtils.Check(Hotkey.ToolSelectBothJoints)) { _selection = new LineSelection(line, bothjoints: true); } else { var knobpos = Utility.CloserPoint( gamepos, line.Position, line.Position2); _selection = new LineSelection(line, knobpos); _hoverclick = true; _hovertime.Restart(); foreach (var snap in LineEndsInRadius(trk, knobpos, 1)) { if ((snap.Position == knobpos || snap.Position2 == knobpos) && snap != line) { _selection.snapped.Add(new LineSelection(snap, knobpos)); } } } return(true); } else { _selection = new LineSelection(line, true); return(true); } } } return(false); }
private void UpdateDrawingBox(Vector2d gamepos) { var size = gamepos - _drawbox.Vector; _drawbox.Size = size; UnselectBox(); using (var trk = game.Track.CreateTrackWriter()) { var lines = trk.GetLinesInRect(_drawbox.MakeLRTB(), true); foreach (var line in lines) { if (!_selectedlines.Contains(line.ID)) { var selection = new LineSelection(line, true, null); line.SelectionState = SelectionState.Selected; _boxselection.Add(selection); game.Track.RedrawLine(line); } } } }
public List <LineSelection> SelectLines(List <GameLine> lines, bool additive = false) { if (!additive) { Unselect(); UnselectBox(); } foreach (GameLine line in lines) { LineSelection selection = new LineSelection(line, true, null); _selectedlines.Add(line.ID); _selection.Add(selection); _boxselection.Add(selection); line.SelectionState = SelectionState.Selected; game.Track.RedrawLine(line); } _selectionbox = GetBoxFromSelected(_selection); Render(); return(_selection); }
public void Paste() { if (_copybuffer.Count != 0) { Stop(false); var pasteorigin = GetCopyOrigin(); var diff = pasteorigin - _copyorigin; Unselect(); Active = true; if (CurrentTools.SelectedTool != this) { CurrentTools.SetTool(this); } using (var trk = game.Track.CreateTrackWriter()) { game.Track.UndoManager.BeginAction(); foreach (var line in _copybuffer) { var add = line.Clone(); add.ID = GameLine.UninitializedID; add.Position += diff; add.Position2 += diff; if (add is StandardLine stl) { stl.CalculateConstants(); } add.SelectionState = SelectionState.Selected; trk.AddLine(add); var selectinfo = new LineSelection(add, true, null); _selection.Add(selectinfo); _selectedlines.Add(add.ID); } game.Track.UndoManager.EndAction(); } _selectionbox = GetBoxFromSelected(_selection); game.Track.NotifyTrackChanged(); } }