public override void Render() { base.Render(); if (_started) { var diff = _end - _start; var x = diff.X; var y = diff.Y; Color c = Color.FromArgb(150, 150, 150); if (Math.Abs(x) + Math.Abs(y) < MINIMUM_LINE) { c = Color.Red; } switch (game.Canvas.ColorControls.Selected) { case LineType.Blue: StandardLine sl = new StandardLine(_start, _end, _addflip); sl.CalculateConstants(); GameRenderer.DrawTrackLine(sl, c, game.SettingRenderGravityWells, true, false, false); break; case LineType.Red: RedLine rl = new RedLine(_start, _end, _addflip); rl.Multiplier = game.Canvas.ColorControls.RedMultiplier; rl.CalculateConstants(); GameRenderer.DrawTrackLine(rl, c, game.SettingRenderGravityWells, true, false, false); break; case LineType.Scenery: GameRenderer.RenderRoundedLine(_start, _end, c, 1); break; } } }
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(); }
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); }
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); }
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; } }
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); }