2018-01-05 19:21:19 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
2017-02-07 12:59:30 +08:00
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
2016-12-06 17:54:32 +08:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Configuration;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2016-12-07 14:45:17 +08:00
|
|
|
|
using osu.Framework.Graphics.OpenGL.Textures;
|
2017-02-16 18:30:31 +08:00
|
|
|
|
using osu.Framework.Graphics.Lines;
|
2016-12-06 17:54:32 +08:00
|
|
|
|
using osu.Framework.Graphics.Textures;
|
|
|
|
|
using osu.Game.Configuration;
|
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics.ES30;
|
2017-03-23 14:37:16 +08:00
|
|
|
|
using OpenTK.Graphics;
|
2017-12-01 23:26:02 +08:00
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
2016-12-06 17:54:32 +08:00
|
|
|
|
|
2017-04-18 15:05:58 +08:00
|
|
|
|
namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
|
2016-12-06 17:54:32 +08:00
|
|
|
|
{
|
|
|
|
|
public class SliderBody : Container, ISliderProgress
|
|
|
|
|
{
|
2017-03-23 12:41:50 +08:00
|
|
|
|
private readonly Path path;
|
|
|
|
|
private readonly BufferedContainer container;
|
2016-12-06 17:54:32 +08:00
|
|
|
|
|
|
|
|
|
public float PathWidth
|
|
|
|
|
{
|
|
|
|
|
get { return path.PathWidth; }
|
2017-03-23 14:37:16 +08:00
|
|
|
|
set { path.PathWidth = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public double? SnakedStart { get; private set; }
|
|
|
|
|
public double? SnakedEnd { get; private set; }
|
|
|
|
|
|
|
|
|
|
private Color4 accentColour;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Used to colour the path.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Color4 AccentColour
|
|
|
|
|
{
|
|
|
|
|
get { return accentColour; }
|
2016-12-06 17:54:32 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
2017-03-23 14:37:16 +08:00
|
|
|
|
if (accentColour == value)
|
|
|
|
|
return;
|
|
|
|
|
accentColour = value;
|
|
|
|
|
|
2017-08-14 10:03:03 +08:00
|
|
|
|
if (LoadState == LoadState.Ready)
|
2017-03-23 16:11:51 +08:00
|
|
|
|
Schedule(reloadTexture);
|
2016-12-06 17:54:32 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-01 23:26:02 +08:00
|
|
|
|
public Quad PathDrawQuad => container.ScreenSpaceDrawQuad;
|
|
|
|
|
|
2017-03-23 14:37:16 +08:00
|
|
|
|
private int textureWidth => (int)PathWidth * 2;
|
2016-12-06 17:54:32 +08:00
|
|
|
|
|
2017-03-23 12:41:50 +08:00
|
|
|
|
private readonly Slider slider;
|
2016-12-06 17:54:32 +08:00
|
|
|
|
public SliderBody(Slider s)
|
|
|
|
|
{
|
|
|
|
|
slider = s;
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
container = new BufferedContainer
|
|
|
|
|
{
|
|
|
|
|
CacheDrawnFrameBuffer = true,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
path = new Path
|
|
|
|
|
{
|
2017-09-07 21:46:21 +08:00
|
|
|
|
Blending = BlendingMode.None,
|
2016-12-06 17:54:32 +08:00
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
container.Attach(RenderbufferInternalFormat.DepthComponent16);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetRange(double p0, double p1)
|
|
|
|
|
{
|
|
|
|
|
if (p0 > p1)
|
|
|
|
|
MathHelper.Swap(ref p0, ref p1);
|
|
|
|
|
|
|
|
|
|
if (updateSnaking(p0, p1))
|
|
|
|
|
{
|
|
|
|
|
// Autosizing does not give us the desired behaviour here.
|
|
|
|
|
// We want the container to have the same size as the slider,
|
|
|
|
|
// and to be positioned such that the slider head is at (0,0).
|
|
|
|
|
container.Size = path.Size;
|
|
|
|
|
container.Position = -path.PositionInBoundingBox(slider.Curve.PositionAt(0) - currentCurve[0]);
|
|
|
|
|
|
|
|
|
|
container.ForceRedraw();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Bindable<bool> snakingIn;
|
|
|
|
|
private Bindable<bool> snakingOut;
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuConfigManager config)
|
|
|
|
|
{
|
2017-05-15 09:56:27 +08:00
|
|
|
|
snakingIn = config.GetBindable<bool>(OsuSetting.SnakingInSliders);
|
|
|
|
|
snakingOut = config.GetBindable<bool>(OsuSetting.SnakingOutSliders);
|
2016-12-07 14:45:17 +08:00
|
|
|
|
|
2017-03-23 14:37:16 +08:00
|
|
|
|
reloadTexture();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void reloadTexture()
|
|
|
|
|
{
|
2017-03-23 16:11:51 +08:00
|
|
|
|
var texture = new Texture(textureWidth, 1);
|
2016-12-07 14:45:17 +08:00
|
|
|
|
|
|
|
|
|
//initialise background
|
|
|
|
|
var upload = new TextureUpload(textureWidth * 4);
|
|
|
|
|
var bytes = upload.Data;
|
|
|
|
|
|
|
|
|
|
const float aa_portion = 0.02f;
|
2017-02-06 21:17:29 +08:00
|
|
|
|
const float border_portion = 0.128f;
|
2016-12-07 14:45:17 +08:00
|
|
|
|
const float gradient_portion = 1 - border_portion;
|
|
|
|
|
|
|
|
|
|
const float opacity_at_centre = 0.3f;
|
|
|
|
|
const float opacity_at_edge = 0.8f;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < textureWidth; i++)
|
|
|
|
|
{
|
|
|
|
|
float progress = (float)i / (textureWidth - 1);
|
|
|
|
|
|
|
|
|
|
if (progress <= border_portion)
|
|
|
|
|
{
|
|
|
|
|
bytes[i * 4] = 255;
|
|
|
|
|
bytes[i * 4 + 1] = 255;
|
|
|
|
|
bytes[i * 4 + 2] = 255;
|
|
|
|
|
bytes[i * 4 + 3] = (byte)(Math.Min(progress / aa_portion, 1) * 255);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
progress -= border_portion;
|
|
|
|
|
|
2017-03-23 14:37:16 +08:00
|
|
|
|
bytes[i * 4] = (byte)(AccentColour.R * 255);
|
|
|
|
|
bytes[i * 4 + 1] = (byte)(AccentColour.G * 255);
|
|
|
|
|
bytes[i * 4 + 2] = (byte)(AccentColour.B * 255);
|
|
|
|
|
bytes[i * 4 + 3] = (byte)((opacity_at_edge - (opacity_at_edge - opacity_at_centre) * progress / gradient_portion) * (AccentColour.A * 255));
|
2016-12-07 14:45:17 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-23 16:11:51 +08:00
|
|
|
|
texture.SetData(upload);
|
|
|
|
|
path.Texture = texture;
|
2016-12-06 17:54:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-23 12:41:50 +08:00
|
|
|
|
private readonly List<Vector2> currentCurve = new List<Vector2>();
|
2016-12-06 17:54:32 +08:00
|
|
|
|
private bool updateSnaking(double p0, double p1)
|
|
|
|
|
{
|
2016-12-07 15:00:29 +08:00
|
|
|
|
if (SnakedStart == p0 && SnakedEnd == p1) return false;
|
2016-12-06 17:54:32 +08:00
|
|
|
|
|
2016-12-07 15:00:29 +08:00
|
|
|
|
SnakedStart = p0;
|
|
|
|
|
SnakedEnd = p1;
|
2016-12-06 17:54:32 +08:00
|
|
|
|
|
|
|
|
|
slider.Curve.GetPathToProgress(currentCurve, p0, p1);
|
|
|
|
|
|
|
|
|
|
path.ClearVertices();
|
|
|
|
|
foreach (Vector2 p in currentCurve)
|
|
|
|
|
path.AddVertex(p - currentCurve[0]);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateProgress(double progress, int repeat)
|
|
|
|
|
{
|
2016-12-07 15:00:29 +08:00
|
|
|
|
double start = 0;
|
|
|
|
|
double end = snakingIn ? MathHelper.Clamp((Time.Current - (slider.StartTime - DrawableOsuHitObject.TIME_PREEMPT)) / DrawableOsuHitObject.TIME_FADEIN, 0, 1) : 1;
|
2016-12-06 17:54:32 +08:00
|
|
|
|
|
|
|
|
|
if (repeat >= slider.RepeatCount - 1)
|
|
|
|
|
{
|
|
|
|
|
if (Math.Min(repeat, slider.RepeatCount - 1) % 2 == 1)
|
|
|
|
|
{
|
2016-12-07 15:00:29 +08:00
|
|
|
|
start = 0;
|
|
|
|
|
end = snakingOut ? progress : 1;
|
2016-12-06 17:54:32 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-12-07 15:00:29 +08:00
|
|
|
|
start = snakingOut ? progress : 0;
|
2016-12-06 17:54:32 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-07 15:00:29 +08:00
|
|
|
|
SetRange(start, end);
|
2016-12-06 17:54:32 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-12-01 23:26:02 +08:00
|
|
|
|
}
|