mirror of
https://github.com/ppy/osu
synced 2025-03-22 19:06:58 +00:00
Add capability to toggle visibility of graph
This commit is contained in:
parent
95d15a703e
commit
3cf8082aa7
@ -7,6 +7,7 @@ using System.Linq;
|
|||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Cursor;
|
using osu.Framework.Graphics.Cursor;
|
||||||
@ -75,7 +76,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
legend = new FillFlowContainer
|
legend = new FillFlowContainer
|
||||||
{
|
{
|
||||||
Padding = new MarginPadding(20),
|
Padding = new MarginPadding(20),
|
||||||
Direction = FillDirection.Full,
|
Direction = FillDirection.Vertical,
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
AutoSizeAxes = Axes.Y,
|
AutoSizeAxes = Axes.Y,
|
||||||
},
|
},
|
||||||
@ -263,7 +264,8 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
results.Add(getTotalScore());
|
results.Add(getTotalScore());
|
||||||
}
|
}
|
||||||
|
|
||||||
graphs.Add(new LineGraph
|
LineGraph graph;
|
||||||
|
graphs.Add(graph = new LineGraph
|
||||||
{
|
{
|
||||||
Name = name,
|
Name = name,
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
@ -271,20 +273,9 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
Values = results
|
Values = results
|
||||||
});
|
});
|
||||||
|
|
||||||
legend.Add(new OsuSpriteText
|
legend.Add(new LegendEntry(name, getTotalScore(), graph)
|
||||||
{
|
{
|
||||||
Colour = colour,
|
AccentColour = colour
|
||||||
RelativeSizeAxes = Axes.X,
|
|
||||||
Width = 0.5f,
|
|
||||||
Text = $"{FontAwesome.Solid.Circle.Icon} {name}"
|
|
||||||
});
|
|
||||||
|
|
||||||
legend.Add(new OsuSpriteText
|
|
||||||
{
|
|
||||||
Colour = colour,
|
|
||||||
RelativeSizeAxes = Axes.X,
|
|
||||||
Width = 0.5f,
|
|
||||||
Text = $"final score {getTotalScore():#,0}"
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -505,4 +496,75 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
public void Move(Vector2 pos) => this.MoveTo(pos);
|
public void Move(Vector2 pos) => this.MoveTo(pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public partial class LegendEntry : OsuClickableContainer, IHasAccentColour
|
||||||
|
{
|
||||||
|
public Color4 AccentColour { get; set; }
|
||||||
|
|
||||||
|
public BindableBool Visible { get; } = new BindableBool(true);
|
||||||
|
|
||||||
|
private readonly string description;
|
||||||
|
private readonly long finalScore;
|
||||||
|
private readonly LineGraph lineGraph;
|
||||||
|
|
||||||
|
private OsuSpriteText descriptionText = null!;
|
||||||
|
private OsuSpriteText finalScoreText = null!;
|
||||||
|
|
||||||
|
public LegendEntry(string description, long finalScore, LineGraph lineGraph)
|
||||||
|
{
|
||||||
|
this.description = description;
|
||||||
|
this.finalScore = finalScore;
|
||||||
|
this.lineGraph = lineGraph;
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Content.RelativeSizeAxes = Axes.X;
|
||||||
|
AutoSizeAxes = Content.AutoSizeAxes = Axes.Y;
|
||||||
|
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
descriptionText = new OsuSpriteText
|
||||||
|
{
|
||||||
|
Anchor = Anchor.CentreLeft,
|
||||||
|
Origin = Anchor.CentreLeft,
|
||||||
|
},
|
||||||
|
finalScoreText = new OsuSpriteText
|
||||||
|
{
|
||||||
|
Anchor = Anchor.CentreRight,
|
||||||
|
Origin = Anchor.CentreRight,
|
||||||
|
Font = OsuFont.Default.With(fixedWidth: true)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
Visible.BindValueChanged(_ => updateState(), true);
|
||||||
|
Action = Visible.Toggle;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool OnHover(HoverEvent e)
|
||||||
|
{
|
||||||
|
updateState();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnHoverLost(HoverLostEvent e)
|
||||||
|
{
|
||||||
|
updateState();
|
||||||
|
base.OnHoverLost(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateState()
|
||||||
|
{
|
||||||
|
Colour = IsHovered ? AccentColour.Lighten(0.2f) : AccentColour;
|
||||||
|
|
||||||
|
descriptionText.Text = $"{(Visible.Value ? FontAwesome.Solid.CheckCircle.Icon : FontAwesome.Solid.Circle.Icon)} {description}";
|
||||||
|
finalScoreText.Text = finalScore.ToString("#,0");
|
||||||
|
lineGraph.Alpha = Visible.Value ? 1 : 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user