Пример #1
0
 private bool DoAction(TrackWriter track, GameLine beforeact, GameLine afteract)
 {
     if (beforeact == null && afteract == null)
     {
         throw new ArgumentNullException(
                   "undo action with no values");
     }
     // remove line
     if (afteract == null)
     {
         track.RemoveLine(beforeact);
     }
     // add line
     else if (beforeact == null)
     {
         track.AddLine(afteract.Clone());
     }
     // Replace line
     else if (beforeact.Type != afteract.Type)
     {
         track.RemoveLine(beforeact);
         track.AddLine(afteract);
     }
     //move action
     else
     {
         track.ReplaceLine(beforeact, afteract.Clone());
     }
     return(!(beforeact is SceneryLine));
 }
Пример #2
0
        private void SetupRedOptions(PropertyTree tree)
        {
            if (_ownerline is RedLine red)
            {
                var table      = tree.Add("Acceleration", 120);
                var multiplier = new NumberProperty(table)
                {
                    Min              = 1,
                    Max              = 255,
                    NumberValue      = red.Multiplier,
                    OnlyWholeNumbers = true,
                };
                multiplier.ValueChanged += (o, e) =>
                {
                    ChangeMultiplier((int)multiplier.NumberValue);
                };
                table.Add("Multiplier", multiplier);
                var multilines = new NumberProperty(table)
                {
                    Min = 1,
                    Max = 9999,
                    OnlyWholeNumbers = true,
                };
                multilines.NumberValue   = GetMultiLines(true).Count;
                multilines.ValueChanged += (o, e) =>
                {
                    Multiline((int)multilines.NumberValue);
                };
                table.Add("Multilines", multilines);

                var accelinverse = GwenHelper.AddPropertyCheckbox(
                    table,
                    "Inverse",
                    red.inv
                    );
                accelinverse.ValueChanged += (o, e) =>
                {
                    using (var trk = _editor.CreateTrackWriter())
                    {
                        var multi = GetMultiLines(false);
                        foreach (var l in multi)
                        {
                            var cpy = (StandardLine)l.Clone();
                            cpy.Position  = l.Position2;
                            cpy.Position2 = l.Position;
                            cpy.inv       = accelinverse.IsChecked;
                            UpdateLine(trk, l, cpy);
                        }

                        var owner = (StandardLine)_ownerline.Clone();
                        owner.Position  = _ownerline.Position2;
                        owner.Position2 = _ownerline.Position;
                        owner.inv       = accelinverse.IsChecked;
                        UpdateOwnerLine(trk, owner);
                    }
                };
            }
        }
Пример #3
0
        /// <summary>
        /// Moves the line in the track, grid, and renderer.
        /// Updates extensions
        /// Notifies the undo/timeline managers
        /// </summary>
        public void MoveLine(
            GameLine line,
            Vector2d pos1,
            Vector2d pos2)
        {
            if (line.Position != pos1 || line.Position2 != pos2)
            {
                var clone = line.Clone();
                var std   = line as StandardLine;
                if (std != null)
                {
                    SaveCells(line.Position, line.Position2);
                    SaveCells(pos1, pos2);
                    if (_updateextensions)
                    {
                        RemoveExtensions(std);
                    }
                    Track.MoveLine(std, pos1, pos2);
                    if (_updateextensions)
                    {
                        AddExtensions(std);
                    }
                }
                else
                {
                    line.Position  = pos1;
                    line.Position2 = pos2;
                }
                _editorcells.RemoveLine(clone);
                _editorcells.AddLine(line);

                RegisterUndoAction(clone, line);
                _renderer.RedrawLine(line);
            }
        }
 /// <summary>
 /// Initialize a lineselection automatically generating clone and generating joint snap
 /// </summary>
 public LineSelection(GameLine Line, Vector2d snapjoint)
 {
     line    = Line;
     clone   = line.Clone();
     joint1  = line.Position == snapjoint;
     joint2  = line.Position2 == snapjoint;
     snapped = new List <LineSelection>();
 }
 /// <summary>
 /// Initialize a lineselection automatically generating clone and applying bothjoints
 /// </summary>
 public LineSelection(GameLine Line, bool bothjoints, List <LineSelection> Snapped)
 {
     line    = Line;
     clone   = line.Clone();
     joint1  = bothjoints;
     joint2  = bothjoints;
     snapped = Snapped;
 }
 /// <summary>
 /// Initialize a lineselection automatically generating clone and applying bothjoints
 /// </summary>
 public LineSelection(GameLine Line, bool bothjoints)
 {
     line    = Line;
     clone   = line.Clone();
     joint1  = bothjoints;
     joint2  = bothjoints;
     snapped = new List <LineSelection>();
 }
Пример #7
0
 /// <summary>
 /// After calling beginaction the current state will be added tothe action
 /// </summary>
 public void AddChange(GameLine before, GameLine after)
 {
     if (_currentaction == null)
     {
         throw new Exception("UndoManager current action null");
     }
     _currentaction.States.Add(before?.Clone());
     _currentaction.States.Add(after?.Clone());
 }
Пример #8
0
 public LineWindow(GameCanvas parent, Editor editor, GameLine line) : base(parent, editor)
 {
     _ownerline         = line;
     _linecopy          = _ownerline.Clone();
     Title              = "Line Properties";
     Padding            = new Padding(0, 0, 0, 0);
     AutoSizeToContents = true;
     _proptree          = new PropertyTree(this)
     {
         Width  = 220,
         Height = 200
     };
     _proptree.Dock = Dock.Top;
     MakeModal(true);
     Setup();
     _proptree.ExpandAll();
 }
Пример #9
0
        private void SetupRedOptions(PropertyTree tree)
        {
            var vec   = _ownerline.GetVector();
            var len   = vec.Length;
            var angle = Angle.FromVector(vec);

            angle.Degrees += 90;
            var lineProp = tree.Add("Line Properties", 120);

            Console.WriteLine(_ownerline.GetType().ToString());

            if (!(_ownerline is SceneryLine scenery))
            {
                var id = new NumberProperty(lineProp)
                {
                    Min              = 0,
                    Max              = int.MaxValue - 1,
                    NumberValue      = _ownerline.ID,
                    OnlyWholeNumbers = true,
                };
                id.ValueChanged += (o, e) =>
                {
                    ChangeID((int)id.NumberValue);
                };
                lineProp.Add("ID", id);
            }

            _length = new NumberProperty(lineProp)
            {
                Min         = 0.0000001,
                Max         = double.MaxValue - 1,
                NumberValue = len,
            };
            _length.ValueChanged += (o, e) =>
            {
                ChangeLength(_length.NumberValue);
            };
            lineProp.Add("Length", _length);

            _angleProp = new NumberProperty(lineProp)
            {
                Min         = 0,
                Max         = 360,
                NumberValue = angle.Degrees,
            };
            _angleProp.ValueChanged += (o, e) =>
            {
                ChangeAngle(_angleProp.NumberValue);
            };
            lineProp.Add("Angle", _angleProp);

            if (!(_ownerline is SceneryLine))
            {
                var multilines = new NumberProperty(lineProp)
                {
                    Min = 1,
                    Max = int.MaxValue - 1,
                    OnlyWholeNumbers = true,
                };
                multilines.NumberValue   = GetMultiLines(true).Count;
                multilines.ValueChanged += (o, e) =>
                {
                    Multiline((int)multilines.NumberValue);
                };
                lineProp.Add("Multilines", multilines);
            }

            if (_ownerline is SceneryLine sceneryLine)
            {
                _width = new NumberProperty(lineProp)
                {
                    Min         = 0.1,
                    Max         = 25.5,
                    NumberValue = _ownerline.Width,
                };
                _width.ValueChanged += (o, e) =>
                {
                    ChangeWidth(_width.NumberValue);
                };
                lineProp.Add("Width", _width);
            }

            if (_ownerline is RedLine red)
            {
                var acceleration = tree.Add("Acceleration", 120);
                var multiplier   = new NumberProperty(acceleration)
                {
                    Min              = 1,
                    Max              = 255,
                    NumberValue      = red.Multiplier,
                    OnlyWholeNumbers = true,
                };
                multiplier.ValueChanged += (o, e) =>
                {
                    ChangeMultiplier((int)multiplier.NumberValue);
                };
                acceleration.Add("Multiplier", multiplier);

                var accelinverse = GwenHelper.AddPropertyCheckbox(
                    acceleration,
                    "Inverse",
                    red.inv
                    );
                accelinverse.ValueChanged += (o, e) =>
                {
                    using (var trk = _editor.CreateTrackWriter())
                    {
                        var multi = GetMultiLines(false);
                        foreach (var l in multi)
                        {
                            var cpy = (StandardLine)l.Clone();
                            cpy.Position  = l.Position2;
                            cpy.Position2 = l.Position;
                            cpy.inv       = accelinverse.IsChecked;
                            UpdateLine(trk, l, cpy);
                        }

                        var owner = (StandardLine)_ownerline.Clone();
                        owner.Position  = _ownerline.Position2;
                        owner.Position2 = _ownerline.Position;
                        owner.inv       = accelinverse.IsChecked;
                        UpdateOwnerLine(trk, owner);
                    }
                };
            }
        }
Пример #10
0
        private void SetupBlueAndRedOptions(PropertyTree tree)
        {
            int  currentMultiplier = 0;
            bool inv = false;

            StandardLine.Ext lineEXT  = ((StandardLine)_ownerline).Extension;
            bool             leftEXT  = ((StandardLine)_ownerline).Extension == StandardLine.Ext.Both || ((StandardLine)_ownerline).Extension == StandardLine.Ext.Left;
            bool             rightEXT = ((StandardLine)_ownerline).Extension == StandardLine.Ext.Both || ((StandardLine)_ownerline).Extension == StandardLine.Ext.Right;


            if (_ownerline is RedLine red)
            {
                currentMultiplier = red.Multiplier;
                inv = red.inv;
            }

            var table = tree.Add("Acceleration", 120);

            multiplier = new NumberProperty(table)
            {
                Min              = -255,
                Max              = 255,
                NumberValue      = (inv ? -currentMultiplier : currentMultiplier),
                OnlyWholeNumbers = true,
            };
            multiplier.ValueChanged += (o, e) =>
            {
                if (multiplier.NumberValue < 0)
                {
                    accelinverse.IsChecked = true;
                }
                else
                {
                    accelinverse.IsChecked = false;
                }
                ChangeMultiplier((int)Math.Abs(multiplier.NumberValue));
            };
            table.Add("Multiplier", multiplier);
            multilines = new NumberProperty(table)
            {
                Min = 1,
                Max = 9999,
                OnlyWholeNumbers = true,
            };
            multilines.NumberValue   = GetMultiLines(true).Count;
            multilines.ValueChanged += (o, e) =>
            {
                Multiline((int)multilines.NumberValue);
            };
            table.Add("Multilines", multilines);

            accelinverse = GwenHelper.AddPropertyCheckbox(
                table,
                "Inverse",
                inv
                );
            accelinverse.ValueChanged += (o, e) =>
            {
                if (accelinverse.IsChecked)
                {
                    if (multiplier.NumberValue > 0)
                    {
                        multiplier.NumberValue = -multiplier.NumberValue;
                    }
                }
                else
                {
                    multiplier.NumberValue = Math.Abs(multiplier.NumberValue);
                }

                using (var trk = _editor.CreateTrackWriter())
                {
                    var multi = GetMultiLines(false);
                    foreach (var l in multi)
                    {
                        var cpy = (StandardLine)l.Clone();
                        cpy.Position  = l.Position2;
                        cpy.Position2 = l.Position;
                        cpy.inv       = accelinverse.IsChecked;
                        UpdateLine(trk, l, cpy);
                    }

                    var owner = (StandardLine)_ownerline.Clone();
                    owner.Position  = _ownerline.Position2;
                    owner.Position2 = _ownerline.Position;
                    owner.inv       = accelinverse.IsChecked;
                    UpdateOwnerLine(trk, owner);
                }

                var vec   = _ownerline.GetVector();
                var angle = Angle.FromVector(vec);
                angle.Degrees        += 90;
                angleProp.NumberValue = angle.Degrees;
            };

            multiplier.ValueChanged += (o, e) =>
            {
                int val = (int)multiplier.NumberValue;
                if (val == 0)
                {
                    accelinverse.Disable();
                }
                else
                {
                    accelinverse.Enable();
                }
            };

            if ((int)multiplier.NumberValue == 0)
            {
                accelinverse.Disable();
            }

            table   = tree.Add("Line Extensions (AGWs)", 120);
            leftAGW = GwenHelper.AddPropertyCheckbox(table, "Starting Extension", leftEXT);
            leftAGW.ValueChanged += (o, e) =>
            {
                UpdateAGWs(leftAGW.IsChecked, rightAGW.IsChecked);
            };
            rightAGW = GwenHelper.AddPropertyCheckbox(table, "Ending Extension", rightEXT);
            rightAGW.ValueChanged += (o, e) =>
            {
                UpdateAGWs(leftAGW.IsChecked, rightAGW.IsChecked);
            };
        }