Ejemplo n.º 1
0
        public void RemoveLine(StandardLine line)
        {
            var positions = GetGridPositions(line);

            using (_sync.AcquireWrite())
            {
                foreach (var pos in positions)
                {
                    Unregister(line, pos.X, pos.Y);
                }
            }
        }
Ejemplo n.º 2
0
        private void Register(StandardLine l, int x, int y)
        {
            var            key = GetCellKey(x, y);
            SimulationCell cell;

            if (!Cells.TryGetValue(key, out cell))
            {
                cell       = new SimulationCell();
                Cells[key] = cell;
            }
            cell.AddLine(l);
        }
Ejemplo n.º 3
0
 public void AddExtensionChange(StandardLine l1, StandardLine l2, bool add)
 {
     if (!_working)
     {
         if (_actions.Count == 0)
         {
             return;
         }
         var ac  = new ExtensionAction(l1, l2, add);
         var act = (lineaction)_actions[_actions.Count - 1];
         act.extensions.Add(ac);
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Removes the line ID in all old grid cells and adds it back to new
        /// ones
        /// </summary>
        public void MoveLine(Vector2d old1, Vector2d old2, StandardLine line)
        {
            var oldpos = GetGridPositions(old1, old2, GridVersion);
            var newpos = GetGridPositions(line);

            using (_sync.AcquireWrite())
            {
                foreach (var v in oldpos)
                {
                    Unregister(line, v.X, v.Y);
                }
                foreach (var v in newpos)
                {
                    Register(line, v.X, v.Y);
                }
            }
        }
Ejemplo n.º 5
0
        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);
                }
            }
        }
Ejemplo n.º 6
0
 public override void OnMouseUp(Vector2d pos)
 {
     game.Invalidate();
     if (_started)
     {
         _started = false;
         var diff = _end - _start;
         var x    = diff.X;
         var y    = diff.Y;
         if (Math.Abs(x) + Math.Abs(y) < MINIMUM_LINE / game.Track.Zoom && (_end != _start || game.Canvas.ColorControls.Selected != LineType.Scenery))
         {
             return;
         }
         AddLine();
         _last = null;
     }
     base.OnMouseUp(pos);
 }
Ejemplo n.º 7
0
        private void AddLine()
        {
            Line added = null;

            switch (game.Canvas.ColorControls.Selected)
            {
            case LineType.Blue:
                added = new StandardLine(_start, _end, false)
                {
                    inv = inv
                };
                added.CalculateConstants();
                break;

            case LineType.Red:
                added = new RedLine(_start, _end, false)
                {
                    inv = inv
                };
                (added as RedLine).Multiplier = game.Canvas.ColorControls.RedMultiplier;
                added.CalculateConstants();
                break;

            case LineType.Scenery:
                added = new SceneryLine(_start, _end)
                {
                    Width = game.Canvas.ColorControls.GreenMultiplier
                };
                break;
            }
            game.Track.AddLine(added);
            if (added is StandardLine)
            {
                var stl = added as StandardLine;
                game.Track.TryConnectLines(stl, _last);
                _last = stl;
            }
            if (game.Canvas.ColorControls.Selected != LineType.Scenery)
            {
                game.Track.ChangeMade(_start, _end);
                game.Track.TrackUpdated();
            }
            game.Invalidate();
        }
Ejemplo n.º 8
0
        public override void OnMouseDown(Vector2d pos)
        {
            _started = true;
            _last    = null;

            if (game.EnableSnap)
            {
                var gamepos = MouseCoordsToGame(pos);
                var ssnap   = Snap(gamepos);
                var snap    = ssnap as StandardLine;

                if (snap != null)
                {
                    _start = (snap.CompliantPosition - gamepos).Length < (snap.CompliantPosition2 - gamepos).Length ? snap.CompliantPosition : snap.CompliantPosition2;
                    _last  = snap;
                }
                else if (ssnap != null)
                {
                    _start = (ssnap.Position - gamepos).Length < (ssnap.Position2 - gamepos).Length
                        ? ssnap.Position
                        : ssnap.Position2;
                }
                else
                {
                    _start = gamepos;
                }
            }
            else
            {
                _start = MouseCoordsToGame(pos);
            }
            var state = OpenTK.Input.Keyboard.GetState();

            inv  = state[OpenTK.Input.Key.ShiftLeft] || state[OpenTK.Input.Key.ShiftRight];
            _end = _start;
            game.Invalidate();
            base.OnMouseDown(pos);
        }
Ejemplo n.º 9
0
        private SimulationCell GetPairs(StandardLine input)
        {
            var list  = new SimulationCell();
            var c1    = _editorcells.GetCellFromPoint(input.Position);
            var c2    = _editorcells.GetCellFromPoint(input.Position2);
            var cells = new LineContainer <GameLine>[]
            {
                c1,
                c1 == c2 ? null : c2
            };

            foreach (var cell in cells)
            {
                if (cell == null)
                {
                    continue;
                }
                foreach (var line in cell)
                {
                    if (line.Type == LineType.Scenery)
                    {
                        continue;
                    }
                    if (line.ID != input.ID)
                    {
                        if (
                            line.End == input.Start ||
                            line.Start == input.End)
                        {
                            list.AddLine((StandardLine)line);
                        }
                    }
                }
            }
            return(list);
        }
Ejemplo n.º 10
0
 public List <CellLocation> GetGridPositions(StandardLine line)
 {
     return(GetGridPositions(line, GridVersion));
 }
Ejemplo n.º 11
0
        public List <Line> Erase(Vector2d pos, LineType t, float zoom)
        {
            List <Line> ret        = new List <Line>();
            var         eraser     = new Vector2d(5 / zoom, 5 / zoom);
            var         searchrect = new FloatRect((Vector2)(pos - eraser), (Vector2)(eraser * 2));

            searchrect = searchrect.Inflate(24, 24);
            var fr    = new FloatRect((Vector2)(pos - eraser), (Vector2)(eraser * 2));
            var lines = FastChunks.LinesInChunks(FastChunks.UsedChunksInRect(fr));

            foreach (var line in lines)
            {
                var scenery = line as SceneryLine;
                if (scenery != null)
                {
                    var sceneryeraser = new Vector2d((5 / zoom) * scenery.Width, (5 / zoom) * scenery.Width);
                    var sceneryfr     = new FloatRect((Vector2)(pos - sceneryeraser), (Vector2)(sceneryeraser * 2));
                    if (!Line.DoesLineIntersectRect(line, sceneryfr))
                    {
                        continue;
                    }
                }
                else
                {
                    if (!Line.DoesLineIntersectRect(line, fr))
                    {
                        continue;
                    }
                }
                if (!(t == LineType.All || ((t == LineType.Red && line.GetLineType() == LineType.Red) ||
                                            (t == LineType.Blue && line.GetLineType() == LineType.Blue) ||
                                            (t == LineType.Scenery && line.GetLineType() == LineType.Scenery))))
                {
                    continue;
                }
                var          sl  = line as StandardLine;
                StandardLine pl1 = null;
                StandardLine pl2 = null;
                StandardLine nl1 = null;
                StandardLine nl2 = null;
                if (sl != null)
                {
                    if (sl.Prev != null)
                    {
                        pl1          = sl.Prev;
                        pl2          = sl;
                        sl.Prev.Next = null;
                        sl.Prev.RemoveExtension(StandardLine.ExtensionDirection.Right);
                        sl.RemoveExtension(StandardLine.ExtensionDirection.Left);
                        sl.Prev = null;
                    }
                    if (sl.Next != null)
                    {
                        nl1          = sl;
                        nl2          = sl.Next;
                        sl.Next.Prev = null;
                        sl.Next.RemoveExtension(StandardLine.ExtensionDirection.Left);
                        sl.RemoveExtension(StandardLine.ExtensionDirection.Right);
                        sl.Next = null;
                    }
                }
                RemoveLine(line);
                ret.Add(line);
                if (pl1 != null)
                {
                    UndoManager.AddExtensionChange(pl1, pl2, false);
                }
                if (nl1 != null)
                {
                    UndoManager.AddExtensionChange(nl1, nl2, false);
                }
            }
            return(ret);
        }
Ejemplo n.º 12
0
        public static Track LoadTrack(sol_track trackdata)
        {
            var ret = new Track {
                Name = trackdata.name
            };
            var buffer     = (List <Amf0Object>)trackdata.get_property("data");
            var addedlines = new Dictionary <int, StandardLine>();
            var version    = trackdata.data.First(x => x.name == "version").data as string;

            if (version == "6.1")
            {
                ret.SetVersion(6.1m);
            }
            else
            {
                ret.SetVersion(6.2m);
            }
            try
            {
                var options = (List <Amf0Object>)trackdata.get_property("trackData");
                if (options.Count >= 2)
                {
                    try
                    {
                        ret.ZeroStart = (bool)options.Find(x => x.name == "2").get_property("5");
                    }
                    catch
                    {
                        //ignored
                    }
                }
            }
            catch
            {
                //ignored
            }
            var extensions = new List <Extensionentry>();

            for (var i = buffer.Count - 1; i >= 0; --i)
            {
                var line = (List <Amf0Object>)buffer[i].data;
                var type = Convert.ToInt32(line[9].data, CultureInfo.InvariantCulture);
                switch (type)
                {
                case 0:
                {
                    var l =
                        new StandardLine(
                            new Vector2d(Convert.ToDouble(line[0].data, CultureInfo.InvariantCulture),
                                         Convert.ToDouble(line[1].data, CultureInfo.InvariantCulture)),
                            new Vector2d(Convert.ToDouble(line[2].data, CultureInfo.InvariantCulture),
                                         Convert.ToDouble(line[3].data, CultureInfo.InvariantCulture)),
                            Convert.ToBoolean(line[5].data, CultureInfo.InvariantCulture))
                    {
                        ID = Convert.ToInt32(line[8].data, CultureInfo.InvariantCulture)
                    };
                    l.SetExtension(Convert.ToInt32(line[4].data, CultureInfo.InvariantCulture));
                    if (line[6].data != null)
                    {
                        var prev = Convert.ToInt32(line[6].data, CultureInfo.InvariantCulture);
                        extensions.Add(new Extensionentry {
                                Line = l, Linkid = prev, Next = false
                            });
                    }
                    if (line[7].data != null)
                    {
                        var next = Convert.ToInt32(line[7].data, CultureInfo.InvariantCulture);
                        extensions.Add(new Extensionentry {
                                Line = l, Linkid = next, Next = true
                            });
                    }
                    if (!addedlines.ContainsKey(l.ID))
                    {
                        ret.AddLines(l);
                        addedlines[l.ID] = l;
                    }
                }
                break;

                case 1:
                {
                    var l =
                        new RedLine(
                            new Vector2d(Convert.ToDouble(line[0].data, CultureInfo.InvariantCulture),
                                         Convert.ToDouble(line[1].data, CultureInfo.InvariantCulture)),
                            new Vector2d(Convert.ToDouble(line[2].data, CultureInfo.InvariantCulture),
                                         Convert.ToDouble(line[3].data, CultureInfo.InvariantCulture)),
                            Convert.ToBoolean(line[5].data, CultureInfo.InvariantCulture))
                    {
                        ID = Convert.ToInt32(line[8].data, CultureInfo.InvariantCulture)
                    };
                    l.SetExtension(Convert.ToInt32(line[4].data, CultureInfo.InvariantCulture));
                    if (line[6].data != null)
                    {
                        var prev = Convert.ToInt32(line[6].data, CultureInfo.InvariantCulture);
                        extensions.Add(new Extensionentry {
                                Line = l, Linkid = prev, Next = false
                            });
                    }
                    if (line[7].data != null)
                    {
                        var next = Convert.ToInt32(line[7].data, CultureInfo.InvariantCulture);
                        extensions.Add(new Extensionentry {
                                Line = l, Linkid = next, Next = true
                            });
                    }
                    if (!addedlines.ContainsKey(l.ID))
                    {
                        ret.AddLines(l);
                        addedlines[l.ID] = l;
                    }
                }
                break;

                case 2:
                    ret.AddLines(
                        new SceneryLine(
                            new Vector2d(Convert.ToDouble(line[0].data, CultureInfo.InvariantCulture),
                                         Convert.ToDouble(line[1].data, CultureInfo.InvariantCulture)),
                            new Vector2d(Convert.ToDouble(line[2].data, CultureInfo.InvariantCulture),
                                         Convert.ToDouble(line[3].data, CultureInfo.InvariantCulture))));
                    break;

                default:
                    throw new Exception("Unknown line type");
                }
            }
            foreach (var v in extensions)
            {
                if (v.Next)
                {
                    StandardLine sl;
                    if (addedlines.TryGetValue(v.Linkid, out sl))
                    {
                        v.Line.Next = sl;
                        sl.Prev     = v.Line;
                    }
                }
                else //prev
                {
                    StandardLine sl;
                    if (addedlines.TryGetValue(v.Linkid, out sl))
                    {
                        v.Line.Prev = sl;
                        sl.Next     = v.Line;
                    }
                }
            }
            var startlineprop = trackdata.get_property("startLine");
            var startline     = startlineprop as List <Amf0Object>;

            if (startline == null && startlineprop is double)
            {
                var conv = Convert.ToInt32(startlineprop, CultureInfo.InvariantCulture);
                if (conv >= ret.Lines.Count || conv < 0)
                {
                    startline = new List <Amf0Object>();
                    startline.Add(new Amf0Object {
                        data = 100
                    });
                    startline.Add(new Amf0Object {
                        data = 100
                    });
                }
            }
            else if (startlineprop is double)
            {
                var conv = Convert.ToInt32(startlineprop, CultureInfo.InvariantCulture);
                startline = new List <Amf0Object>();
                startline.Add(new Amf0Object {
                    data = ret.Lines[conv].Position.X
                });
                startline.Add(new Amf0Object {
                    data = ret.Lines[conv].Position.Y - 50 * 0.5
                });
            }
            ret.Start.X = Convert.ToDouble(startline[0].data, CultureInfo.InvariantCulture);
            ret.Start.Y = Convert.ToDouble(startline[1].data, CultureInfo.InvariantCulture);
            ret.ResetUndo();
            ret.ResetChanges();
            return(ret);
        }
Ejemplo n.º 13
0
        public static Track LoadTrackTRK(string track, string savename)
        {
            var ret = new Track();

            ret.Name = track;
            var addedlines = new Dictionary <int, StandardLine>();
            var extensions = new List <Extensionentry>();
            var location   = Program.CurrentDirectory + "Tracks" + Path.DirectorySeparatorChar + track;

            if (savename != null)
            {
                location += Path.DirectorySeparatorChar + savename + ".trk";
            }
            else
            {
                location += ".trk";
            }
            using (var file =
                       File.Open(location, FileMode.Open))
            {
                var br    = new BinaryReader(file);
                int magic = br.ReadInt32();
                if (magic == ('T' | 'R' << 8 | 'K' << 16 | 0xF2 << 24))
                {
                    byte     version  = br.ReadByte();
                    string[] features = Encoding.ASCII.GetString(br.ReadBytes(br.ReadInt16())).Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                    if (version != 1)
                    {
                        throw new Exception("Unsupported version");
                    }
                    bool redmultipier     = false;
                    bool scenerywidth     = false;
                    bool supports61       = false;
                    bool songinfo         = false;
                    bool ignorabletrigger = false;
                    for (int i = 0; i < features.Length; i++)
                    {
                        switch (features[i])
                        {
                        case "REDMULTIPLIER":
                            redmultipier = true;
                            break;

                        case "SCENERYWIDTH":
                            scenerywidth = true;
                            break;

                        case "6.1":
                            supports61 = true;
                            break;

                        case "SONGINFO":
                            songinfo = true;
                            break;

                        case "IGNORABLE_TRIGGER":
                            ignorabletrigger = true;
                            break;

                        case "ZEROSTART":
                            ret.ZeroStart = true;
                            break;

                        default:
                            throw new Exception("Unsupported feature");
                        }
                    }
                    if (supports61)
                    {
                        ret.SetVersion(6.1m);
                    }
                    else
                    {
                        ret.SetVersion(6.2m);
                    }
                    if (songinfo)
                    {
                        var song = br.ReadString();
                        try
                        {
                            var strings = song.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                            var fn      = Program.CurrentDirectory + "Songs" +
                                          Path.DirectorySeparatorChar +
                                          strings[0];
                            if (File.Exists(fn))
                            {
                                if (AudioPlayback.LoadFile(ref fn))
                                {
                                    game.CurrentSong = new Song(Path.GetFileName(fn), float.Parse(strings[1]));
                                    game.EnableSong  = true;
                                }
                                else
                                {
                                    Program.NonFatalError("An unknown error occured trying to load the song file");
                                }
                            }
                        }
                        catch
                        {
                            // ignored
                        }
                    }
                    ret.Start = new Vector2d(br.ReadDouble(), br.ReadDouble());
                    var lines = br.ReadInt32();
                    for (var i = 0; i < lines; i++)
                    {
                        Line        l;
                        byte        ltype      = br.ReadByte();
                        var         lt         = (LineType)(ltype & 0x1F);//we get 5 bits
                        var         inv        = (ltype >> 7) != 0;
                        var         lim        = (ltype >> 5) & 0x3;
                        var         ID         = -1;
                        var         prvID      = -1;
                        var         nxtID      = -1;
                        var         multiplier = 1;
                        var         linewidth  = 1f;
                        LineTrigger tr         = ignorabletrigger ? new LineTrigger() : null;
                        if (redmultipier)
                        {
                            if (lt == LineType.Red)
                            {
                                multiplier = br.ReadByte();
                            }
                        }
                        if (lt == LineType.Blue || lt == LineType.Red)
                        {
                            if (ignorabletrigger)
                            {
                                bool zoomtrigger = br.ReadBoolean();
                                if (zoomtrigger)
                                {
                                    tr.Zoomtrigger = true;
                                    var target = br.ReadSingle();
                                    var frames = br.ReadInt16();
                                    tr.ZoomFrames = frames;
                                    tr.ZoomTarget = target;
                                }
                                else
                                {
                                    tr = null;
                                }
                            }
                            ID = br.ReadInt32();
                            if (lim != 0)
                            {
                                prvID = br.ReadInt32();
                                nxtID = br.ReadInt32();
                            }
                        }
                        if (lt == LineType.Scenery)
                        {
                            if (scenerywidth)
                            {
                                float b = br.ReadByte();
                                linewidth = b / 10f;
                            }
                        }
                        var x1 = br.ReadDouble();
                        var y1 = br.ReadDouble();
                        var x2 = br.ReadDouble();
                        var y2 = br.ReadDouble();
                        switch (lt)
                        {
                        case LineType.Blue:
                            var bl = new StandardLine(new Vector2d(x1, y1), new Vector2d(x2, y2), inv);
                            bl.ID = ID;
                            bl.SetExtension(lim);
                            l = bl;
                            if (prvID != -1)
                            {
                                extensions.Add(new Extensionentry {
                                    Line = bl, Linkid = prvID, Next = false
                                });
                            }
                            if (nxtID != -1)
                            {
                                extensions.Add(new Extensionentry {
                                    Line = bl, Linkid = nxtID, Next = true
                                });
                            }
                            bl.Trigger = tr;
                            break;

                        case LineType.Red:
                            var rl = new RedLine(new Vector2d(x1, y1), new Vector2d(x2, y2), inv);
                            rl.ID = ID;
                            rl.SetExtension(lim);
                            if (redmultipier)
                            {
                                rl.Multiplier = multiplier;
                            }
                            l = rl;
                            if (prvID != -1)
                            {
                                extensions.Add(new Extensionentry {
                                    Line = rl, Linkid = prvID, Next = false
                                });
                            }
                            if (nxtID != -1)
                            {
                                extensions.Add(new Extensionentry {
                                    Line = rl, Linkid = nxtID, Next = true
                                });
                            }
                            rl.Trigger = tr;
                            break;

                        case LineType.Scenery:
                            l = new SceneryLine(new Vector2d(x1, y1), new Vector2d(x2, y2))
                            {
                                Width = linewidth
                            };

                            break;

                        default:
                            throw new Exception("Invalid line type");
                        }
                        if (l is StandardLine)
                        {
                            if (!addedlines.ContainsKey(l.ID))
                            {
                                addedlines[ID] = (StandardLine)l;
                                ret.AddLines(l);
                            }
                        }
                        else
                        {
                            ret.AddLines(l);
                        }
                    }
                }
            }
            foreach (var v in extensions)
            {
                if (v.Next)
                {
                    StandardLine sl;
                    if (addedlines.TryGetValue(v.Linkid, out sl))
                    {
                        //if (sl.Extension == StandardLine.ExtensionDirection.Right || sl.Extension == StandardLine.ExtensionDirection.Both)
                        {
                            v.Line.Next = sl;
                            sl.Prev     = v.Line;
                        }
                    }
                }
                else //prev
                {
                    StandardLine sl;
                    if (addedlines.TryGetValue(v.Linkid, out sl))
                    {
                        //if (sl.Extension == StandardLine.ExtensionDirection.Left || sl.Extension == StandardLine.ExtensionDirection.Both)
                        {
                            v.Line.Prev = sl;
                            sl.Next     = v.Line;
                        }
                    }
                }
            }
            ret.ResetUndo();
            ret.ResetChanges();
            return(ret);
        }
Ejemplo n.º 14
0
 public static List <CellLocation> GetGridPositions(StandardLine line, int gridversion)
 {
     return(GetGridPositions(line.Position, line.Position2, gridversion));
 }
Ejemplo n.º 15
0
        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();
        }
Ejemplo n.º 16
0
        public void Select(StandardLine line, Vector2d position)
        {
            if (selectionwindow != null)
            {
                if (selectionwindow.UserData != line)
                {
                    selectionwindow.Close();
                    selectionwindow = null;
                }
            }
            if (selectionwindow == null)
            {
                selectionwindow = new WindowControl(game.Canvas, "Line Settings", false);
                selectionwindow.MakeModal(true);
                selectionwindow.UserData      = line;
                selectionwindow.DeleteOnClose = true;
                selectionwindow.DisableResizing();
                selectionwindow.Height = 170;
                selectionwindow.Width  = 150;

                ControlBase container1 = new ControlBase(selectionwindow);
                container1.Dock = Gwen.Pos.Fill;
                if (line.GetLineType() != LineType.Scenery)
                {
                    LabeledCheckBox btn = new LabeledCheckBox(container1);
                    btn.Dock          = Gwen.Pos.Top;
                    btn.Text          = "Inverse";
                    btn.IsChecked     = line.inv;
                    btn.CheckChanged += (o, e) =>
                    {
                        var caller = (LabeledCheckBox)o;
                        line.inv = caller.IsChecked;
                        line.CalculateConstants();
                        game.Track.TrackUpdated();
                        game.Invalidate();
                    };
                    LineTrigger tr = (LineTrigger)line.Trigger ?? new LineTrigger();

                    var gb = new PropertyTree(container1);
                    gb.Height = 110;
                    gb.Dock   = Gwen.Pos.Top;

                    PropertyTree table = new PropertyTree(gb);

                    table.Name   = "triggers";
                    table.Dock   = Gwen.Pos.Fill;
                    table.Height = 100;

                    var row     = table.Add("Zoom Trigger");
                    var enabled = row.Add("Enabled", new Gwen.Controls.Property.Check(table));
                    enabled.Value         = tr.Zoomtrigger ? "1" : "0";
                    enabled.ValueChanged += (o, e) =>
                    {
                        if (enabled.Value == "1")
                        {
                            tr.Zoomtrigger = true;
                            tr.ZoomTarget  = float.Parse(((PropertyRow)container1.FindChildByName("Zoom", true)).Value);
                            tr.ZoomFrames  = int.Parse(((PropertyRow)container1.FindChildByName("ZoomFrames", true)).Value);
                            line.Trigger   = tr;
                        }
                        else
                        {
                            tr.Zoomtrigger = false;
                            if (!tr.Enabled)
                            {
                                line.Trigger = null;
                            }
                        }
                        game.Track.LineChanged(line);
                    };
                    var prop = row.Add("Zoom");
                    prop.Name          = "Zoom";
                    prop.Value         = (enabled.Value == "1" ? tr.ZoomTarget : 1).ToString();
                    prop.ValueChanged += (o, e) =>
                    {
                        var   caller = (PropertyRow)o;
                        float val    = 0;
                        if (float.TryParse(caller.Value, out val) && val >= 0.1 && val <= 24)
                        {
                            caller.LabelColor = System.Drawing.Color.Black;
                            tr.ZoomTarget     = val;
                        }
                        else
                        {
                            caller.LabelColor = System.Drawing.Color.Red;
                        }
                    };
                    prop               = row.Add("Frames");
                    prop.Name          = "ZoomFrames";
                    prop.Value         = (enabled.Value == "1" ? tr.ZoomFrames : 40).ToString();
                    prop.ValueChanged += (o, e) =>
                    {
                        var caller = (PropertyRow)o;
                        int val    = 0;
                        if (int.TryParse(caller.Value, out val) && val >= 1 && val < 10000)
                        {
                            caller.LabelColor = System.Drawing.Color.Black;
                            tr.ZoomFrames     = val;
                        }
                        else
                        {
                            caller.LabelColor = System.Drawing.Color.Red;
                        }
                    };
                }

                if (line.GetLineType() == LineType.Red)
                {
                    selectionwindow.Height += 30;
                    NoDecimalNUD nud  = new NoDecimalNUD(container1);
                    var          marg = nud.Margin;
                    marg.Top          = 5;
                    marg.Left         = marg.Right = 1;
                    marg.Left         = 70;
                    marg.Bottom       = 10;
                    nud.Margin        = marg;
                    nud.Dock          = Gwen.Pos.Top;
                    nud.Min           = 1;
                    nud.Max           = 3;
                    nud.Value         = (line as RedLine).Multiplier;
                    nud.ValueChanged += nud_redlinemultiplier_ValueChanged;
                    nud.UserData      = line;
                    Label l = new Label(container1);
                    l.Y    = 137;
                    l.Text = "Multiplier";
                    selectionwindow.Height += 25;


                    nud         = new NoDecimalNUD(container1);
                    marg        = nud.Margin;
                    marg.Top    = 5;
                    marg.Left   = marg.Right = 1;
                    marg.Left   = 70;
                    marg.Bottom = 10;
                    nud.Margin  = marg;
                    nud.Dock    = Gwen.Pos.Top;
                    var         lines    = game.Track.GetLinesInRect(new FloatRect((Vector2)line.Position, new Vector2(1, 1)), false);
                    List <Line> redlines = new List <Line>();
                    foreach (var red in lines)
                    {
                        if (red.Position == line.Position && red.Position2 == line.Position2)
                        {
                            redlines.Add(red);
                        }
                    }
                    nud.Min = 1;
                    nud.Max = 50;
                    redlines.Sort(new Track.Linecomparer());
                    nud.Value         = redlines.Count;
                    nud.ValueChanged += (o, e) =>
                    {
                        var diff = nud.Value - redlines.Count;
                        if (diff < 0)
                        {
                            for (int i = 0; i > diff; i--)
                            {
                                game.Track.RemoveLine(redlines[(int)((redlines.Count - 1))]);
                                redlines.RemoveAt(redlines.Count - 1);
                            }
                        }
                        else
                        {
                            for (int i = 0; i < diff; i++)
                            {
                                var red = new RedLine(line.Position, line.Position2, line.inv)
                                {
                                    Multiplier = ((RedLine)line).Multiplier
                                };
                                game.Track.AddLine(red);
                                redlines.Add(red);
                            }
                        }
                        game.Track.TrackUpdated();
                    };
                    nud.UserData = line;
                    l            = new Label(container1);
                    l.Y          = 137 + 35;
                    l.Text       = "Multilines";
                }
                selectionwindow.IsHiddenChanged += Selectionwindow_IsHiddenChanged;
                selectionwindow.Show();
                selectionwindow.X = (int)position.X;
                selectionwindow.Y = (int)position.Y;
                game.Cursor       = MouseCursor.Default;
            }
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Removes the line from the physics
 /// </summary>
 public void RemoveLineFromGrid(StandardLine line)
 {
     Grid.RemoveLine(line);
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Adds the line to the physics grid.
 /// </summary>
 public void AddLineToGrid(StandardLine line)
 {
     Grid.AddLine(line);
 }
Ejemplo n.º 19
0
 public ExtensionAction(StandardLine l, StandardLine l2, bool set)
 {
     L   = l;
     L2  = l2;
     Add = set;
 }
Ejemplo n.º 20
0
        public void TryConnectLines(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 (!leftlink && !rightlink)
            {
                return;
            }

            var diff1 = l2.CompliantPosition2 - l2.CompliantPosition;
            var diff2 = l1.CompliantPosition2 - l1.CompliantPosition;

            var angle1 = Angle.FromVector(diff1).Degrees;            // (Math.Atan2(diff1.Y, diff1.X) * (180.0 / Math.PI));
            var angle2 = Angle.FromVector(diff2).Degrees;

            var anglediff1 = new Angle(angle1 - angle2).Degrees;
            var anglediff2 = new Angle(angle2 - angle1).Degrees;

            bool cmp1 = anglediff1 > 0 && anglediff1 <= 180;
            bool cmp2 = anglediff2 > 0 && anglediff2 <= 180;

            if ((rightlink) ? cmp2 : cmp1)
            {
                if (rightlink)
                {
                    l1.Next = l2;
                    l1.AddExtension(StandardLine.ExtensionDirection.Right);
                    l2.Prev = l1;
                    l2.AddExtension(StandardLine.ExtensionDirection.Left);
                    if (undo)
                    {
                        UndoManager.AddExtensionChange(l1, l2, true);
                    }
                }
                else
                {
                    l1.Prev = l2;
                    l1.AddExtension(StandardLine.ExtensionDirection.Left);
                    l2.Next = l1;
                    l2.AddExtension(StandardLine.ExtensionDirection.Right);
                    if (undo)
                    {
                        UndoManager.AddExtensionChange(l2, l1, true);
                    }
                }
            }
        }
Ejemplo n.º 21
0
        public override void OnMouseUp(Vector2d pos)
        {
            game.Invalidate();
            if (_started)
            {
                _started = false;
                var diff = _end - _start;
                var x    = diff.X;
                var y    = diff.Y;
                if (Math.Abs(x) + Math.Abs(y) < MINIMUM_LINE)
                {
                    return;
                }
                StandardLine next = null;
                if (game.ShouldXySnap())
                {
                    _end = SnapXY(_start, _end);
                }
                else if (game.EnableSnap)
                {
                    var ssnap = Snap(_end);
                    var snap  = ssnap as StandardLine;
                    if (snap != null)
                    {
                        var old = _end;

                        _end = (snap.CompliantPosition - _end).Length < (snap.CompliantPosition2 - _end).Length ? snap.CompliantPosition : snap.CompliantPosition2;
                        if (_end == _start)
                        {
                            _end = old;
                        }
                        else
                        {
                            next = snap;
                        }
                    }
                    else if (ssnap != null)
                    {
                        var old = _end;
                        _end = (ssnap.Position - _end).Length < (ssnap.Position2 - _end).Length
    ? ssnap.Position
    : ssnap.Position2;
                        if (_end == _start)
                        {
                            _end = old;
                        }
                    }
                }
                if ((_end - _start).Length >= MINIMUM_LINE)
                {
                    Line added = null;
                    switch (game.Canvas.ColorControls.Selected)
                    {
                    case LineType.Blue:
                        added = new StandardLine(_start, _end, _addflip);
                        break;

                    case LineType.Red:
                        added = new RedLine(_start, _end, _addflip);
                        (added as RedLine).Multiplier = game.Canvas.ColorControls.RedMultiplier;
                        break;

                    case LineType.Scenery:
                        added = new SceneryLine(_start, _end)
                        {
                            Width = game.Canvas.ColorControls.GreenMultiplier
                        };
                        break;
                    }
                    game.Track.AddLine(added);
                    if (added is StandardLine)
                    {
                        var stl = added as StandardLine;
                        game.Track.TryConnectLines(stl, _last);
                        game.Track.TryConnectLines(stl, next);
                    }
                    if (game.Canvas.ColorControls.Selected != LineType.Scenery)
                    {
                        game.Track.TrackUpdated();
                    }
                    game.Invalidate();
                }
            }
            base.OnMouseUp(pos);
        }
Ejemplo n.º 22
0
 private void RemoveExtensions(StandardLine input)
 {
     UpdateExtensions(input, false);
 }
Ejemplo n.º 23
0
 private void AddExtensions(StandardLine input)
 {
     UpdateExtensions(input, true);
 }