mirror of
https://github.com/osukey/osukey.git
synced 2025-05-09 23:57:18 +09:00
Rework BarsInfo struct
This commit is contained in:
parent
6c62cfb830
commit
2cb966b47c
@ -42,7 +42,8 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly List<BarInfo> bars = new List<BarInfo>();
|
private readonly BarsInfo bars = new BarsInfo(0);
|
||||||
|
|
||||||
private float barBreadth;
|
private float barBreadth;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -71,16 +72,11 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
|
|
||||||
if (bar.Index < bars.Count)
|
if (bar.Index < bars.Count)
|
||||||
{
|
{
|
||||||
BarInfo b = bars[bar.Index];
|
bars.UpdateLength(bar.Index, length);
|
||||||
|
|
||||||
b.InitialLength = b.FinalLength;
|
|
||||||
b.FinalLength = length;
|
|
||||||
|
|
||||||
bars[bar.Index] = b;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
bars.Add(new BarInfo { FinalLength = length });
|
bars.AddBar(length);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bars.Count > newCount)
|
if (bars.Count > newCount)
|
||||||
@ -108,31 +104,19 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
{
|
{
|
||||||
base.Update();
|
base.Update();
|
||||||
|
|
||||||
if (!bars.Any())
|
if (!bars.Any)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
double currentTime = Clock.CurrentTime;
|
double currentTime = Clock.CurrentTime;
|
||||||
|
|
||||||
if (currentTime < animationStartTime + resize_duration)
|
if (currentTime < animationStartTime + resize_duration)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < bars.Count; i++)
|
bars.Animate(animationStartTime, currentTime);
|
||||||
{
|
|
||||||
BarInfo bar = bars[i];
|
|
||||||
bar.InstantaneousLength = Interpolation.ValueAt(currentTime, bar.InitialLength, bar.FinalLength, animationStartTime, animationStartTime + resize_duration, easing);
|
|
||||||
bars[i] = bar;
|
|
||||||
}
|
|
||||||
|
|
||||||
Invalidate(Invalidation.DrawNode);
|
Invalidate(Invalidation.DrawNode);
|
||||||
}
|
}
|
||||||
else if (!animationComplete)
|
else if (!animationComplete)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < bars.Count; i++)
|
bars.FinishAnimation();
|
||||||
{
|
|
||||||
BarInfo bar = bars[i];
|
|
||||||
bar.InstantaneousLength = bar.FinalLength;
|
|
||||||
bars[i] = bar;
|
|
||||||
}
|
|
||||||
|
|
||||||
Invalidate(Invalidation.DrawNode);
|
Invalidate(Invalidation.DrawNode);
|
||||||
|
|
||||||
animationComplete = true;
|
animationComplete = true;
|
||||||
@ -155,8 +139,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
private Vector2 drawSize;
|
private Vector2 drawSize;
|
||||||
private BarDirection direction;
|
private BarDirection direction;
|
||||||
private float barBreadth;
|
private float barBreadth;
|
||||||
|
private BarsInfo bars;
|
||||||
private readonly List<BarInfo> bars = new List<BarInfo>();
|
|
||||||
|
|
||||||
public override void ApplyState()
|
public override void ApplyState()
|
||||||
{
|
{
|
||||||
@ -167,26 +150,19 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
drawSize = Source.DrawSize;
|
drawSize = Source.DrawSize;
|
||||||
direction = Source.direction;
|
direction = Source.direction;
|
||||||
barBreadth = Source.barBreadth;
|
barBreadth = Source.barBreadth;
|
||||||
|
bars = Source.bars;
|
||||||
bars.Clear();
|
|
||||||
bars.AddRange(Source.bars);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Draw(IRenderer renderer)
|
public override void Draw(IRenderer renderer)
|
||||||
{
|
{
|
||||||
base.Draw(renderer);
|
base.Draw(renderer);
|
||||||
|
|
||||||
if (!bars.Any())
|
|
||||||
return;
|
|
||||||
|
|
||||||
shader.Bind();
|
shader.Bind();
|
||||||
|
|
||||||
for (int i = 0; i < bars.Count; i++)
|
for (int i = 0; i < bars.Count; i++)
|
||||||
{
|
{
|
||||||
var bar = bars[i];
|
float barHeight = drawSize.Y * ((direction == BarDirection.TopToBottom || direction == BarDirection.BottomToTop) ? bars.InstantaneousLength(i) : barBreadth);
|
||||||
|
float barWidth = drawSize.X * ((direction == BarDirection.LeftToRight || direction == BarDirection.RightToLeft) ? bars.InstantaneousLength(i) : barBreadth);
|
||||||
float barHeight = drawSize.Y * ((direction == BarDirection.TopToBottom || direction == BarDirection.BottomToTop) ? bar.InstantaneousLength : barBreadth);
|
|
||||||
float barWidth = drawSize.X * ((direction == BarDirection.LeftToRight || direction == BarDirection.RightToLeft) ? bar.InstantaneousLength : barBreadth);
|
|
||||||
|
|
||||||
Vector2 topLeft;
|
Vector2 topLeft;
|
||||||
|
|
||||||
@ -210,29 +186,85 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 topRight = topLeft + new Vector2(barWidth, 0);
|
renderer.DrawQuad(
|
||||||
Vector2 bottomLeft = topLeft + new Vector2(0, barHeight);
|
texture,
|
||||||
Vector2 bottomRight = bottomLeft + new Vector2(barWidth, 0);
|
new Quad(
|
||||||
|
Vector2Extensions.Transform(topLeft, DrawInfo.Matrix),
|
||||||
var drawQuad = new Quad(
|
Vector2Extensions.Transform(topLeft + new Vector2(barWidth, 0), DrawInfo.Matrix),
|
||||||
Vector2Extensions.Transform(topLeft, DrawInfo.Matrix),
|
Vector2Extensions.Transform(topLeft + new Vector2(0, barHeight), DrawInfo.Matrix),
|
||||||
Vector2Extensions.Transform(topRight, DrawInfo.Matrix),
|
Vector2Extensions.Transform(topLeft + new Vector2(barWidth, barHeight), DrawInfo.Matrix)
|
||||||
Vector2Extensions.Transform(bottomLeft, DrawInfo.Matrix),
|
),
|
||||||
Vector2Extensions.Transform(bottomRight, DrawInfo.Matrix)
|
DrawColourInfo.Colour);
|
||||||
);
|
|
||||||
|
|
||||||
renderer.DrawQuad(texture, drawQuad, DrawColourInfo.Colour);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
shader.Unbind();
|
shader.Unbind();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private struct BarInfo
|
private struct BarsInfo
|
||||||
{
|
{
|
||||||
public float InitialLength { get; set; }
|
private readonly List<float> initialLengths;
|
||||||
public float FinalLength { get; set; }
|
private readonly List<float> finalLengths;
|
||||||
public float InstantaneousLength { get; set; }
|
private readonly List<float> instantaneousLengths;
|
||||||
|
|
||||||
|
public bool Any => initialLengths.Any();
|
||||||
|
|
||||||
|
public int Count => initialLengths.Count;
|
||||||
|
|
||||||
|
public BarsInfo(int initialCount)
|
||||||
|
{
|
||||||
|
initialLengths = new List<float>();
|
||||||
|
finalLengths = new List<float>();
|
||||||
|
instantaneousLengths = new List<float>();
|
||||||
|
|
||||||
|
for (int i = 0; i < initialCount; i++)
|
||||||
|
{
|
||||||
|
initialLengths.Add(0);
|
||||||
|
finalLengths.Add(0);
|
||||||
|
instantaneousLengths.Add(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public float InstantaneousLength(int index) => instantaneousLengths[index];
|
||||||
|
|
||||||
|
public void UpdateLength(int index, float newLength)
|
||||||
|
{
|
||||||
|
initialLengths[index] = finalLengths[index];
|
||||||
|
finalLengths[index] = newLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddBar(float finalLength)
|
||||||
|
{
|
||||||
|
initialLengths.Add(0);
|
||||||
|
finalLengths.Add(finalLength);
|
||||||
|
instantaneousLengths.Add(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Clear()
|
||||||
|
{
|
||||||
|
initialLengths.Clear();
|
||||||
|
finalLengths.Clear();
|
||||||
|
instantaneousLengths.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveRange(int index, int count)
|
||||||
|
{
|
||||||
|
initialLengths.RemoveRange(index, count);
|
||||||
|
finalLengths.RemoveRange(index, count);
|
||||||
|
instantaneousLengths.RemoveRange(index, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Animate(double animationStartTime, double currentTime)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < Count; i++)
|
||||||
|
instantaneousLengths[i] = Interpolation.ValueAt(currentTime, initialLengths[i], finalLengths[i], animationStartTime, animationStartTime + resize_duration, easing);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void FinishAnimation()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < Count; i++)
|
||||||
|
instantaneousLengths[i] = finalLengths[i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user