public void Start() { resourceManager = FindObjectOfType <ResourceManager>(); eventBar = FindObjectOfType <EventBar>(); minerStatus = Status.Active; StudyIndicator.gameObject.SetActive(false); StrikeIndicator.gameObject.SetActive(false); miningShaft = GetComponentInParent <MiningShaft>(); //gameSystem = FindObjectOfType<GameSystem>(); }
public EventTester() { var popButton = new TextButton(Width / 2, 9.5f * Height / 10, Height / 40, "Pop !"); AddChild(popButton); popButton.Activated += PopButton_Activated; var objectives = new Dictionary <int, int>(); objectives.Add(2, 8); objectives.Add(4, 5); objectives.Add(6, 1); objectives.Add(8, 3); var events = new List <EventType>() { EventType.Empty, EventType.Energy, EventType.Empty, EventType.Energy, EventType.Empty, EventType.Energy, EventType.Empty, EventType.Energy, EventType.Empty, EventType.Energy, }; var levelData = new LevelData() { BoardSetupString = "", Columns = 4, Rows = 4, Id = 1, Objectives = objectives, Events = events }; var json = JsonConvert.SerializeObject(levelData); _eventBar = new EventBar(0, 0, 0.1f * Height, Width); AddChild(_eventBar); _eventBar.Initialize(levelData.Events); var objectivesView = new ObjectivesView(objectives, false, Width / 2, 0.2f * Height, 0.1f * Height); AddChild(objectivesView); }
protected override void OnPaint(PaintEventArgs e) { trackRegions.Clear(); if (!DesignMode) { e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; e.Graphics.FillRectangle(Brushes.White, ClientRectangle); if (!top.Level2) { TextRenderer.DrawText(e.Graphics, "Log does not contain event data.", Font, ClientRectangle, Color.Black); return; } Generate(); if (lines == null) { lines = new int[top.Definitions.Count][]; linesCounts = new int[top.Definitions.Count]; for (int j = 0; j < top.Definitions.Count; j++) { lines[j] = new int[bars[j].Length]; List <int> lineEnds = new List <int>(); for (int i = 0; i < bars[j].Length; i++) { // allocate from existing lines bool done = false; for (int k = 0; k < lineEnds.Count; k++) { if (lineEnds[k] + MinSpace <= bars[j][i].start) { lines[j][i] = k; lineEnds[k] = bars[j][i].end; done = true; break; } } // create new line if (!done) { lines[j][i] = lineEnds.Count; lineEnds.Add(bars[j][i].end); } } linesCounts[j] = lineEnds.Count; } } int leftEpoch = Math.Max((int)Math.Floor((-AutoScrollPosition.X - LeftMargin) / (StandardWidth * scale)), 0); int rightEpoch = Math.Max((int)Math.Ceiling((-AutoScrollPosition.X - LeftMargin + ClientSize.Width + StandardWidth) / (StandardWidth * scale)), 0); int c = 1; int cc = 1; bool f = false; while (c * StandardWidth * scale < 80) { cc = c; c = c * (!f ? 5 : 2); f = !f; } for (int i = leftEpoch / c * c; i < rightEpoch + c - 1; i += cc) { int x = AutoScrollPosition.X + LeftMargin + (int)Math.Floor(i * StandardWidth * scale); e.Graphics.DrawLine( i % c == 0 ? Pens.Gray : Pens.LightGray, new Point(x, 0), new Point(x, ClientSize.Height)); if (i % c == 0) { string label = i.ToString(); int w = TextRenderer.MeasureText(label, Font).Width; TextRenderer.DrawText( e.Graphics, label, Font, new Rectangle(x - w / 2, AutoScrollPosition.Y, w, FontHeight), Color.Black, Color.Transparent, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter | TextFormatFlags.SingleLine); } } int y = 2 * FontHeight; for (int j = 0; j < top.Definitions.Count; j++) { e.Graphics.DrawLine(Pens.Gray, 0, y + AutoScrollPosition.Y, ClientSize.Width, y + AutoScrollPosition.Y); y++; bool colorSync = (j % 2 == 0); Rectangle bounds = new Rectangle( AutoScrollPosition.X, y + AutoScrollPosition.Y, LeftMargin + (int)Math.Ceiling(StandardWidth * scale * top.Epochs.Count), 1 + (FontHeight + 2 * InnerSpacing) * Math.Max(1, linesCounts[j])); e.Graphics.FillRectangle(colorSync ? Brushes.OldLace : Brushes.WhiteSmoke, bounds); trackRegions.Add(new Region(bounds)); TextRenderer.DrawText( e.Graphics, String.Format("{0}: {1}", j, top.Definitions[j].Name), Font, new Rectangle(bounds.Location, new Size(LeftMargin, bounds.Height)), Color.Black, Color.Transparent, TextFormatFlags.Left | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPrefix | TextFormatFlags.EndEllipsis); for (int i = 0; i < bars[j].Length; i++) { EventBar bar = bars[j][i]; if ((bar.end < leftEpoch) || (bar.start > rightEpoch)) { continue; // not visible } Rectangle barBounds; if (bar.start < bar.end) { barBounds = new Rectangle( LeftMargin + (int)Math.Floor(StandardWidth * scale * bar.start) + AutoScrollPosition.X, 1 + y + lines[j][i] * (FontHeight + 2 * InnerSpacing) + AutoScrollPosition.Y, (int)Math.Ceiling(StandardWidth * scale * (bar.end - bar.start)), FontHeight + 2); e.Graphics.FillRectangle(colorSync ? Brushes.NavajoWhite : Brushes.PaleTurquoise, barBounds); e.Graphics.DrawRectangle(Pens.Black, barBounds); } else { barBounds = new Rectangle( LeftMargin + (int)Math.Floor(StandardWidth * scale * bar.start) + AutoScrollPosition.X, 1 + y + lines[j][i] * (FontHeight + 2 * InnerSpacing) + AutoScrollPosition.Y, Int16.MaxValue, FontHeight + 2); Point[] curve = new Point[] { new Point(barBounds.X + FontHeight / 2, barBounds.Y), new Point(barBounds.X - FontHeight / 2, barBounds.Y + FontHeight + 2), new Point(barBounds.X, barBounds.Y + FontHeight + 2), new Point(barBounds.X, barBounds.Y), }; e.Graphics.FillPolygon(colorSync ? Brushes.NavajoWhite : Brushes.PaleTurquoise, curve); e.Graphics.DrawPolygon(Pens.Black, curve); } string l1 = bar.seq.ToString() + (!String.IsNullOrEmpty(bar.tag) ? String.Concat(":", bar.tag) : String.Empty); int l1w = TextRenderer.MeasureText(l1, Font, new Size(Int16.MaxValue, FontHeight), TextFormatFlags.NoPadding | TextFormatFlags.Left).Width; TextRenderer.DrawText( e.Graphics, l1, Font, barBounds, Color.Black, Color.Transparent, TextFormatFlags.Left | TextFormatFlags.VerticalCenter); if (bar.frameIndex.HasValue || bar.noteIndex.HasValue) { TextRenderer.DrawText( e.Graphics, String.Format("{0}.{1}", bar.frameIndex, bar.noteIndex), Font, new Rectangle(barBounds.X + l1w, barBounds.Y, barBounds.Width - l1w, barBounds.Height), Color.Gray, Color.Transparent, TextFormatFlags.Left | TextFormatFlags.VerticalCenter); } for (int t = 0; t < bar.ties.Length; t++) { Rectangle barBounds2 = new Rectangle( LeftMargin + (int)Math.Floor(StandardWidth * scale * bar.ties[t].when) + AutoScrollPosition.X, 1 + y + lines[j][i] * (FontHeight + 2 * InnerSpacing) + AutoScrollPosition.Y, (int)Math.Ceiling(StandardWidth * scale * (bar.end - bar.ties[t].when)), FontHeight + 2); e.Graphics.DrawLine(colorSync ? Pens.DarkSalmon : Pens.MediumSlateBlue, barBounds2.X, barBounds2.Y + 1, barBounds2.X, barBounds2.Y + barBounds2.Height - 1); TextRenderer.DrawText( e.Graphics, String.Format("{0}.{1}", bar.ties[t].frameIndex, bar.ties[t].noteIndex), Font, barBounds2, Color.Gray, Color.Transparent, TextFormatFlags.Left | TextFormatFlags.VerticalCenter); } } y += bounds.Height; } e.Graphics.DrawLine(Pens.Gray, 0, y + AutoScrollPosition.Y, ClientSize.Width, y + AutoScrollPosition.Y); y++; y += FontHeight; AutoScrollMinSize = new Size( LeftMargin + (int)Math.Ceiling(StandardWidth * scale * top.Epochs.Count) + RightMargin, y); HorizontalScroll.SmallChange = ClientSize.Width / 8; } base.OnPaint(e); }
private void Generate() { if (bars != null) { return; } if (!top.Level2) { return; } #if false string acceleratorPath = Accelerators.Events.QueryAcceleratorPath(logPath, top.LogStream, Top.AcceleratorVersion); if (acceleratorPath == null) { evtf = new BitVector(top.Epochs.Count); } else { using (Stream stream = new FileStream(acceleratorPath, FileMode.Open, FileAccess.Read, FileShare.Read, Constants.BufferSize)) { evtf = BitVector.Load(stream); } } #endif List <EventBar>[] bars2 = new List <EventBar> [top.Definitions.Count]; Dictionary <int, EventBar>[] bars3 = new Dictionary <int, EventBar> [top.Definitions.Count]; for (int j = 0; j < top.Definitions.Count; j++) { bars2[j] = new List <EventBar>(); bars3[j] = new Dictionary <int, EventBar>(); } for (int i = 0; i < top.Epochs.Count; i++) { #if false if (acceleratorPath != null) { if (!evtf[i]) { continue; } } bool found = false; #endif Epoch epoch = top.Epochs[i]; if (!epoch.Level2) { continue; } for (int j = 0; j < top.Definitions.Count; j++) { DatumEvent[] events = epoch.Data[j].Events; foreach (DatumEvent e in events) { #if false found = true; #endif switch (e.Tag) { default: Debug.Assert(false); break; case "Start": { EventBar bar = new EventBar(); bar.start = i; bar.seq = e.Seq; bar.frameIndex = ((DatumEvent2)e).frameIndex; bar.noteIndex = ((DatumEvent2)e).noteIndex; bars2[j].Add(bar); bars3[j].Add(e.Seq, bar); } break; case "Stop": { EventBar bar = bars3[j][e.Seq]; bar.end = i; } break; case "Restart": { EventBar bar = bars3[j][e.Seq]; EventBar.Tie tie = new EventBar.Tie(); tie.when = i; tie.frameIndex = ((DatumEvent2)e).frameIndex; tie.noteIndex = ((DatumEvent2)e).noteIndex; int p = bar.ties.Length; Array.Resize(ref bar.ties, p + 1); bar.ties[p] = tie; } break; case "SkipEnter": case "SkipLeave": { EventBar bar = new EventBar(); bar.tag = e.Tag; bar.start = i; bar.end = i; bar.seq = e.Seq; bars2[j].Add(bar); bars3[j].Add(e.Seq, bar); } break; } } } #if false if ((acceleratorPath == null) && found) { evtf[i] = true; } #endif } #if false if (acceleratorPath == null) { acceleratorPath = System.IO.Path.GetTempFileName(); using (Stream stream = new FileStream(acceleratorPath, FileMode.Create, FileAccess.Write, FileShare.None, Constants.BufferSize)) { evtf.Save(stream); } Accelerators.Events.RecordAcceleratorPath(logPath, top.LogStream, acceleratorPath, Top.AcceleratorVersion); } #endif bars = new EventBar[top.Definitions.Count][]; for (int j = 0; j < top.Definitions.Count; j++) { bars[j] = bars2[j].ToArray(); } }