Rev 1493 | Rev 1588 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1423 | chris | 1 | using System; |
| 2 | using System.Collections.Generic; |
||
| 3 | using System.Linq; |
||
| 4 | using System.Text; |
||
| 5 | using System.Threading.Tasks; |
||
| 6 | using System.ComponentModel; |
||
| 1493 | chris | 7 | using System.IO; |
| 1423 | chris | 8 | |
| 9 | using BauzoidNET.math; |
||
| 10 | using BauzoidNET.parser; |
||
| 11 | |||
| 1448 | chris | 12 | using BurutaruEditor.view; |
| 13 | |||
| 1423 | chris | 14 | namespace BurutaruEditor.file |
| 15 | { |
||
| 16 | public class CheckPoint : LevelObject |
||
| 17 | { |
||
| 1448 | chris | 18 | public const float INTERACTION_SIZE = DocumentView.CHECKPOINT_SIZE; |
| 1423 | chris | 19 | |
| 20 | [TypeConverter(typeof(ExpandableObjectConverter))] |
||
| 1477 | chris | 21 | [Category("Basic Parameters")] |
| 1423 | chris | 22 | public Vector2 Position { get; set; } |
| 23 | |||
| 24 | [TypeConverter(typeof(ExpandableObjectConverter))] |
||
| 1477 | chris | 25 | [Category("Basic Parameters")] |
| 1423 | chris | 26 | public Vector2 FreeScroll { get; set; } |
| 27 | |||
| 1477 | chris | 28 | [Category("Basic Parameters")] |
| 1423 | chris | 29 | public float ScrollSpeed { get; set; } |
| 30 | |||
| 1477 | chris | 31 | [Category("Conditions")] |
| 1423 | chris | 32 | public string ContinueCondition { get; set; } |
| 33 | |||
| 34 | |||
| 35 | public CheckPoint(Document doc, string name) |
||
| 36 | : base(doc, name) |
||
| 37 | { |
||
| 1461 | chris | 38 | Position = new Vector2(); |
| 39 | FreeScroll = new Vector2(); |
||
| 40 | ScrollSpeed = 10; |
||
| 41 | ContinueCondition = ""; |
||
| 1423 | chris | 42 | } |
| 43 | |||
| 1463 | chris | 44 | public override void RenderSelected(int selectedPart, bool forHover = false) |
| 1460 | chris | 45 | { |
| 46 | float posX = Position.x + Document.VIRTUAL_WIDTH / 2 + Doc.View.CurrentPosition.x; |
||
| 47 | float posY = Position.y + Document.VIRTUAL_HEIGHT / 2 + Doc.View.CurrentPosition.y; |
||
| 48 | float halfSize = INTERACTION_SIZE / 2 + DocumentView.SELECTION_FRAME_OFFSET; |
||
| 49 | |||
| 1463 | chris | 50 | if (forHover) |
| 51 | Doc.View.RenderSelectionFrame(posX - halfSize, posY - halfSize, posX + halfSize, posY + halfSize, DocumentView.SELECTION_FRAME_HOVER_ALPHA); |
||
| 52 | else |
||
| 53 | Doc.View.RenderSelectionFrame(posX - halfSize, posY - halfSize, posX + halfSize, posY + halfSize); |
||
| 1460 | chris | 54 | } |
| 55 | |||
| 1459 | chris | 56 | public override bool IsInside(float x, float y, out int selectedPart) |
| 1423 | chris | 57 | { |
| 1459 | chris | 58 | selectedPart = -1; |
| 1441 | chris | 59 | if ((Math.Abs(x - Position.x) <= INTERACTION_SIZE) && (Math.Abs(y - Position.y) <= INTERACTION_SIZE)) |
| 60 | return true; |
||
| 61 | return false; |
||
| 62 | } |
||
| 63 | |||
| 1459 | chris | 64 | public override void MoveBy(float dx, float dy, int selectedPart) |
| 1441 | chris | 65 | { |
| 66 | Position.x += (dx / Doc.View.ZoomFactor); |
||
| 67 | Position.y += (dy / Doc.View.ZoomFactor); |
||
| 68 | } |
||
| 69 | |||
| 1477 | chris | 70 | public override string GetPropertiesType() |
| 71 | { |
||
| 1493 | chris | 72 | return "CheckPoint"; |
| 1477 | chris | 73 | } |
| 74 | |||
| 1493 | chris | 75 | public override void WriteData(TextWriter tw) |
| 76 | { |
||
| 1548 | chris | 77 | tw.WriteLine("\tposition " + Position.x.ToString("F") + ", " + Position.y.ToString("F") + ";"); |
| 1493 | chris | 78 | tw.WriteLine("\tfreeScroll " + FreeScroll.x + ", " + FreeScroll.y + ";"); |
| 79 | tw.WriteLine("\tcontinueCondition \"" + ContinueCondition + "\";"); |
||
| 80 | tw.WriteLine("\tscrollSpeed " + ScrollSpeed + ";"); |
||
| 81 | } |
||
| 82 | |||
| 1441 | chris | 83 | public override bool ReadParameter(Tokenizer t, string id) |
| 84 | { |
||
| 1423 | chris | 85 | if (id.Equals("position", StringComparison.OrdinalIgnoreCase)) |
| 86 | { |
||
| 87 | Position = ParseUtil.readVector2(t); |
||
| 88 | } |
||
| 89 | else if (id.Equals("freeScroll", StringComparison.OrdinalIgnoreCase)) |
||
| 90 | { |
||
| 91 | FreeScroll = ParseUtil.readVector2(t); |
||
| 92 | } |
||
| 93 | else if (id.Equals("continueCondition", StringComparison.OrdinalIgnoreCase)) |
||
| 94 | { |
||
| 95 | ContinueCondition = t.readString(); |
||
| 96 | } |
||
| 97 | else if (id.Equals("scrollSpeed", StringComparison.OrdinalIgnoreCase)) |
||
| 98 | { |
||
| 99 | ScrollSpeed = t.readNumber(); |
||
| 100 | } |
||
| 101 | else |
||
| 102 | { |
||
| 103 | return base.ReadParameter(t, id); |
||
| 104 | } |
||
| 105 | |||
| 106 | t.readToken(";"); |
||
| 107 | return true; |
||
| 108 | } |
||
| 109 | |||
| 110 | |||
| 111 | } |
||
| 112 | } |