protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(this.State_BackgroundColor); this.spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.NonPremultiplied); for (int b = this.nearbyHitObjects.Count - 1; b >= 0; b--) { BMAPI.v1.HitObjects.CircleObject hitObject = this.nearbyHitObjects[b]; // the song time relative to the hitobject start time float diff = (float)(hitObject.StartTime - this.songPlayer.SongTime); // transparency of hitobject float alpha = 1.0f; // a percentage of how open a slider is, 1.0 is closed, 0.0 is open float approachCircleValue = 0.0f; // length in time of hit object (only applies to sliders and spinners) int hitObjectLength = 0; // Use these types if the hitobject is a slider or spinner BMAPI.v1.HitObjects.SliderObject hitObjectAsSlider = null; BMAPI.v1.HitObjects.SpinnerObject hitObjectAsSpinner = null; if (hitObject.Type.HasFlag(BMAPI.v1.HitObjectType.Spinner)) { hitObjectAsSpinner = (BMAPI.v1.HitObjects.SpinnerObject)hitObject; hitObjectLength = (int)(hitObjectAsSpinner.EndTime - hitObjectAsSpinner.StartTime); } else if (hitObject.Type.HasFlag(BMAPI.v1.HitObjectType.Slider)) { hitObjectAsSlider = (BMAPI.v1.HitObjects.SliderObject)hitObject; hitObjectLength = (int)((hitObjectAsSlider.SegmentEndTime - hitObjectAsSlider.StartTime) * hitObjectAsSlider.RepeatCount); //hitObjectLength = 500; } // for reference: this.approachRate is the time in ms it takes for approach circle to close if (diff < this.approachRate + this.State_FadeTime && diff > -(hitObjectLength + this.State_FadeTime)) { if (diff < -hitObjectLength) { // fade out alpha = 1 - ((diff + hitObjectLength) / -(float)this.State_FadeTime); } else if (!hitObject.Type.HasFlag(BMAPI.v1.HitObjectType.Spinner) && diff >= this.approachRate && diff < this.approachRate + this.State_FadeTime) { // fade in alpha = 1 - (diff - this.approachRate) / (float)this.State_FadeTime; } else if (hitObject.Type.HasFlag(BMAPI.v1.HitObjectType.Spinner)) { // because spinners don't have an approach circle before they appear if (diff >= 0 && diff < this.State_FadeTime) { alpha = 1 - diff / (float)this.State_FadeTime; } else if (diff > 0) { alpha = 0; } } if (diff < this.approachRate + this.State_FadeTime && diff > 0) { // hitcircle percentage from open to closed approachCircleValue = diff / (float)(this.approachRate + this.State_FadeTime); } else if (diff > 0) { approachCircleValue = 1.0f; } if (hitObject.Type.HasFlag(BMAPI.v1.HitObjectType.Circle)) { this.DrawHitcircle(hitObject, alpha, b); this.DrawApproachCircle(hitObject, alpha, approachCircleValue); } else if (hitObject.Type.HasFlag(BMAPI.v1.HitObjectType.Slider)) { this.DrawSlider(hitObjectAsSlider, alpha, b, approachCircleValue); } else if (hitObject.Type.HasFlag(BMAPI.v1.HitObjectType.Spinner)) { this.DrawSpinner(hitObjectAsSpinner, alpha); this.DrawSpinnerApproachCircle(hitObjectAsSpinner, alpha, (float)(this.songPlayer.SongTime - hitObjectAsSpinner.StartTime) / (hitObjectAsSpinner.EndTime - hitObjectAsSpinner.StartTime)); } } } if (this.State_PlaybackMode == 0) { Vector2 currentPos = Vector2.Zero; Vector2 lastPos = new Vector2(-222, 0); for (int i = 0; i < this.nearbyFrames[this.state_ReplaySelected].Count; i++) { ReplayAPI.ReplayFrame currentFrame = this.nearbyFrames[this.state_ReplaySelected][i]; float alpha = i / (float)this.nearbyFrames[this.state_ReplaySelected].Count; currentPos = this.InflateVector(new Vector2(currentFrame.X, currentFrame.Y)); bool selected = false; if (this.selectedFrames != null) { selected = this.selectedFrames.Contains(currentFrame); } if (lastPos.X != -222) { Color linecolor; if (selected) { linecolor = Color.White; } else { linecolor = new Color(1.0f, 0.0f, 0.0f, alpha); } this.DrawLine(lastPos, currentPos, linecolor); } Color nodeColor = Color.Gray; if (currentFrame.Keys.HasFlag(ReplayAPI.Keys.K1)) { nodeColor = Color.Cyan; } else if (currentFrame.Keys.HasFlag(ReplayAPI.Keys.K2)) { nodeColor = Color.Magenta; } else if (currentFrame.Keys.HasFlag(ReplayAPI.Keys.M1)) { nodeColor = Color.Lime; } else if (currentFrame.Keys.HasFlag(ReplayAPI.Keys.M2)) { nodeColor = Color.Yellow; } if (!selected) { nodeColor.A = (byte)(alpha * 255); } this.spriteBatch.Draw(this.nodeTexture, currentPos - new Vector2(5, 5), nodeColor); lastPos = currentPos; } if (this.ToolRect.Width != 0 && this.ToolRect.Height != 0) { this.DrawTool(); } } else if (this.State_PlaybackMode == 1) { for (int i = 0; i < 7; i++) { if (this.nearbyFrames[i] != null && this.nearbyFrames[i].Count >= 1) { this.spriteBatch.Draw(this.cursorTexture, this.InflateVector(this.GetInterpolatedFrame(i)) - new Vector2(this.cursorTexture.Width, this.cursorTexture.Height) / 2f, Canvas.Color_Cursor[i]); } } } if (this.ShowHelp != 0) { this.spriteBatch.Draw(this.helpTexture, Vector2.Zero, Color.White); } this.spriteBatch.End(); base.Draw(gameTime); }
private void Draw(bool isBackground) { if (this.Visual_MapInvert) { GL.MatrixMode(MatrixMode.Projection); GL.PushMatrix(); this.MulFlipMatrix(); } //this.spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.NonPremultiplied); for (int b = this.nearbyHitObjects.Count - 1; b >= 0; b--) { BMAPI.v1.HitObjects.CircleObject hitObject = this.nearbyHitObjects[b]; // the song time relative to the hitobject start time float diff = (float)(hitObject.StartTime - this.songPlayer.SongTime); // transparency of hitobject float alpha = 1.0f; // a percentage of how open a slider is, 1.0 is closed, 0.0 is open float approachCircleValue = 0.0f; // length in time of hit object (only applies to sliders and spinners) int hitObjectLength = 0; // Use these types if the hitobject is a slider or spinner BMAPI.v1.HitObjects.SliderObject hitObjectAsSlider = null; BMAPI.v1.HitObjects.SpinnerObject hitObjectAsSpinner = null; if (hitObject.Type.HasFlag(BMAPI.v1.HitObjectType.Spinner)) { hitObjectAsSpinner = (BMAPI.v1.HitObjects.SpinnerObject)hitObject; hitObjectLength = (int)(hitObjectAsSpinner.EndTime - hitObjectAsSpinner.StartTime); } else if (hitObject.Type.HasFlag(BMAPI.v1.HitObjectType.Slider)) { hitObjectAsSlider = (BMAPI.v1.HitObjects.SliderObject)hitObject; hitObjectLength = (int)((hitObjectAsSlider.SegmentEndTime - hitObjectAsSlider.StartTime) * hitObjectAsSlider.RepeatCount); //hitObjectLength = 500; } // for reference: this.approachRate is the time in ms it takes for approach circle to close if (diff < this.approachRate + this.State_FadeTime && diff > -(hitObjectLength + this.State_FadeTime)) { if (diff < -hitObjectLength) { // fade out alpha = 1 - ((diff + hitObjectLength) / -(float)this.State_FadeTime); } else if (!hitObject.Type.HasFlag(BMAPI.v1.HitObjectType.Spinner) && diff >= this.approachRate && diff < this.approachRate + this.State_FadeTime) { // fade in alpha = 1 - (diff - this.approachRate) / (float)this.State_FadeTime; } else if (hitObject.Type.HasFlag(BMAPI.v1.HitObjectType.Spinner)) { // because spinners don't have an approach circle before they appear if (diff >= 0 && diff < this.State_FadeTime) { alpha = 1 - diff / (float)this.State_FadeTime; } else if (diff > 0) { alpha = 0; } } if (diff < this.approachRate + this.State_FadeTime && diff > 0) { // hitcircle percentage from open to closed approachCircleValue = diff / (float)(this.approachRate + this.State_FadeTime); } else if (diff > 0) { approachCircleValue = 1.0f; } if (hitObject.Type.HasFlag(BMAPI.v1.HitObjectType.Circle)) { if (isBackground) { this.DrawHitcircle(hitObject, alpha); } else { this.DrawApproachCircle(hitObject, alpha, approachCircleValue); } } else if (hitObject.Type.HasFlag(BMAPI.v1.HitObjectType.Slider)) { this.DrawSlider(hitObjectAsSlider, alpha, approachCircleValue, isBackground); } else if (hitObject.Type.HasFlag(BMAPI.v1.HitObjectType.Spinner)) { if (!isBackground) { this.DrawSpinner(hitObjectAsSpinner, alpha); this.DrawSpinnerApproachCircle(hitObjectAsSpinner, alpha, (float)(this.songPlayer.SongTime - hitObjectAsSpinner.StartTime) / (hitObjectAsSpinner.EndTime - hitObjectAsSpinner.StartTime)); } } } } if (this.Visual_MapInvert) { GL.MatrixMode(MatrixMode.Projection); GL.PopMatrix(); } if (!isBackground) { bool forceFlip = false; if (this.State_PlaybackMode == 0) { if (MainForm.self.CurrentReplays[this.State_ReplaySelected] != null) { forceFlip = MainForm.self.CurrentReplays[this.State_ReplaySelected].AxisFlip; } if (forceFlip) { GL.MatrixMode(MatrixMode.Projection); GL.PushMatrix(); this.MulFlipMatrix(); } Vector2 currentPos = Vector2.Zero; Vector2 lastPos = new Vector2(-222, 0); for (int i = 0; i < this.nearbyFrames[this.state_ReplaySelected].Count; i++) { ReplayAPI.ReplayFrame currentFrame = this.nearbyFrames[this.state_ReplaySelected][i]; float alpha = i / (float)this.nearbyFrames[this.state_ReplaySelected].Count; currentPos = new Vector2(currentFrame.X, currentFrame.Y); if (lastPos.X != -222) { this.DrawLine(lastPos, currentPos, new Color(1.0f, 0.0f, 0.0f, alpha)); } Color nodeColor = Color.Gray; if (currentFrame.Keys.HasFlag(ReplayAPI.Keys.K1)) { nodeColor = Color.Cyan; } else if (currentFrame.Keys.HasFlag(ReplayAPI.Keys.K2)) { nodeColor = Color.Magenta; } else if (currentFrame.Keys.HasFlag(ReplayAPI.Keys.M1)) { nodeColor = Color.Lime; } else if (currentFrame.Keys.HasFlag(ReplayAPI.Keys.M2)) { nodeColor = Color.Yellow; } this.nodeTexture.Draw(currentPos - new Vector2(5, 5), Vector2.Zero, nodeColor); lastPos = currentPos; } if (forceFlip) { GL.MatrixMode(MatrixMode.Projection); GL.PopMatrix(); } } else if (this.State_PlaybackMode == 1) { for (int i = 0; i < 7; i++) { if (this.nearbyFrames[i] != null && this.nearbyFrames[i].Count >= 1) { forceFlip = MainForm.self.CurrentReplays[i].AxisFlip; if (forceFlip) { GL.MatrixMode(MatrixMode.Projection); GL.PushMatrix(); this.MulFlipMatrix(); } Vector2 cursorPos = this.GetInterpolatedFrame(i); float diameter = 32.0f; this.cursorTexture.Draw(cursorPos, diameter, diameter, new Vector2(diameter * 0.5f), Canvas.Color_Cursor[i]); if (forceFlip) { GL.MatrixMode(MatrixMode.Projection); GL.PopMatrix(); } } } } if (this.ShowHelp != 0) { GL.MatrixMode(MatrixMode.Projection); GL.PushMatrix(); GL.LoadIdentity(); GL.Ortho(0.0, 1.0, 1.0, 0.0, 0.0, 1.0); this.helpTexture.Draw(Vector2.Zero, 1.0f, 1.0f, Vector2.Zero, Color.White); GL.MatrixMode(MatrixMode.Projection); GL.PopMatrix(); } } }
private void ToolAction() { // a is the point first clicked Vector2 a = new Vector2(this.ToolRect.X, this.ToolRect.Y); // b is the point released Vector2 b = new Vector2(this.ToolRect.X + this.ToolRect.Width, this.ToolRect.Y + this.ToolRect.Height); // this always sets the rectangle so that the top left coords is the x and y, even if dragged from bottom right to top left if (this.ToolRect.Width < 0) { this.ToolRect.X += this.ToolRect.Width; this.ToolRect.Width *= -1; } if (this.ToolRect.Height < 0) { this.ToolRect.Y += this.ToolRect.Height; this.ToolRect.Height *= -1; } if (this.State_ToolSelected == 0) { this.selectedFrames = new List <ReplayAPI.ReplayFrame>(); for (int i = 0; i < this.nearbyFrames[this.state_ReplaySelected].Count; i++) { ReplayAPI.ReplayFrame frame = this.nearbyFrames[this.state_ReplaySelected][i]; Vector2 frameCoor = this.InflateVector(new Vector2(frame.X, frame.Y)); if (frameCoor.X >= this.ToolRect.X && frameCoor.X < this.ToolRect.X + this.ToolRect.Width && frameCoor.Y >= this.ToolRect.Y && frameCoor.Y < this.ToolRect.Y + this.ToolRect.Height) { this.selectedFrames.Add(frame); } } MainForm.self.SetNumberSelectedLabel(this.selectedFrames.Count); } else if (this.State_ToolSelected == 1) { Vector2 displace = this.DeflateVector(b - a); for (int i = 0; i < this.selectedFrames.Count; i++) { ReplayAPI.ReplayFrame item = this.selectedFrames[i]; int k = this.replayFrames[this.State_ReplaySelected].IndexOf(item); if (k >= 0) { ReplayAPI.ReplayFrame dup = new ReplayAPI.ReplayFrame(); dup.X = item.X + displace.X; dup.Y = item.Y + displace.Y; dup.Keys = item.Keys; dup.Time = item.Time; dup.TimeDiff = item.TimeDiff; this.replayFrames[this.State_ReplaySelected][k] = dup; this.selectedFrames[i] = dup; } } } else if (this.State_ToolSelected == 2) { Vector2 from = this.DeflateVector(a); Vector2 to = this.DeflateVector(b); for (int i = 0; i < this.selectedFrames.Count; i++) { ReplayAPI.ReplayFrame item = this.selectedFrames[i]; int k = this.replayFrames[this.State_ReplaySelected].IndexOf(item); if (k >= 0) { ReplayAPI.ReplayFrame dup = new ReplayAPI.ReplayFrame(); float distance = (float)Math.Max(1, Math.Sqrt(Math.Pow(from.X - item.X, 2) + Math.Pow(from.Y - item.Y, 2))); float reduction = (float)Math.Min(1, distance / 50); dup.X = item.X + (to.X - item.X) * (1 - reduction); dup.Y = item.Y + (to.Y - item.Y) * (1 - reduction); dup.Keys = item.Keys; dup.Time = item.Time; dup.TimeDiff = item.TimeDiff; this.replayFrames[this.State_ReplaySelected][k] = dup; this.selectedFrames[i] = dup; } } } }