mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 02:22:56 +08:00
Add scores container
This commit is contained in:
parent
6def49d6a4
commit
3261af5200
157
osu.Game/Overlays/BeatmapSet/Scores/DrawableScore.cs
Normal file
157
osu.Game/Overlays/BeatmapSet/Scores/DrawableScore.cs
Normal file
@ -0,0 +1,157 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using OpenTK;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Input;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Online.API.Requests;
|
||||
using osu.Game.Overlays.Profile.Sections.Ranks;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.UI;
|
||||
using osu.Game.Screens.Select.Leaderboards;
|
||||
using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Overlays.BeatmapSet.Scores
|
||||
{
|
||||
public class DrawableScore : Container
|
||||
{
|
||||
private const int fade_duration = 100;
|
||||
private const int height = 30;
|
||||
|
||||
private readonly Box background;
|
||||
private readonly ScoreModsContainer modsContainer;
|
||||
|
||||
public DrawableScore(int index, OnlineScore score)
|
||||
{
|
||||
RelativeSizeAxes = Axes.X;
|
||||
Height = height;
|
||||
CornerRadius = 3;
|
||||
Masking = true;
|
||||
Children = new Drawable[]
|
||||
{
|
||||
background = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Alpha = 0,
|
||||
},
|
||||
new OsuSpriteText
|
||||
{
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
Text = $"#{index + 1}",
|
||||
Font = @"Exo2.0-RegularItalic",
|
||||
RelativePositionAxes = Axes.X,
|
||||
X = 0.02f
|
||||
},
|
||||
new DrawableFlag(score.User.Country?.FlagName)
|
||||
{
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
Width = 30,
|
||||
Height = 20,
|
||||
RelativePositionAxes = Axes.X,
|
||||
X = 0.06f
|
||||
},
|
||||
new ClickableUsername(score.User.Username)
|
||||
{
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
RelativePositionAxes = Axes.X,
|
||||
X = 0.1f
|
||||
},
|
||||
modsContainer = new ScoreModsContainer
|
||||
{
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Width = 60,
|
||||
RelativePositionAxes = Axes.X,
|
||||
X = 0.45f
|
||||
},
|
||||
new DrawableRank(score.Rank)
|
||||
{
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
Width = 30,
|
||||
Height = 20,
|
||||
FillMode = FillMode.Fit,
|
||||
RelativePositionAxes = Axes.X,
|
||||
X = 0.55f
|
||||
},
|
||||
new OsuSpriteText
|
||||
{
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreRight,
|
||||
Text = score.TotalScore.ToString(),
|
||||
Font = @"Exo2.0-MediumItalic",
|
||||
RelativePositionAxes = Axes.X,
|
||||
X = 0.7f
|
||||
},
|
||||
new OsuSpriteText
|
||||
{
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreRight,
|
||||
Text = $@"{score.Accuracy:P2}",
|
||||
Font = @"Exo2.0-RegularItalic",
|
||||
RelativePositionAxes = Axes.X,
|
||||
X = 0.8f
|
||||
},
|
||||
new OsuSpriteText
|
||||
{
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreRight,
|
||||
Text = $"{score.Statistics["300"]}/{score.Statistics["100"]}/{score.Statistics["50"]}",
|
||||
Font = @"Exo2.0-RegularItalic",
|
||||
RelativePositionAxes = Axes.X,
|
||||
X = 0.98f
|
||||
},
|
||||
};
|
||||
|
||||
foreach (Mod mod in score.Mods)
|
||||
modsContainer.Add(new ModIcon(mod)
|
||||
{
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Scale = new Vector2(0.35f),
|
||||
});
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
background.Colour = colours.Gray4;
|
||||
}
|
||||
|
||||
protected override bool OnHover(InputState state)
|
||||
{
|
||||
background.FadeIn(fade_duration, Easing.OutQuint);
|
||||
return base.OnHover(state);
|
||||
}
|
||||
|
||||
protected override void OnHoverLost(InputState state)
|
||||
{
|
||||
background.FadeOut(fade_duration, Easing.OutQuint);
|
||||
base.OnHoverLost(state);
|
||||
}
|
||||
|
||||
protected override bool OnClick(InputState state) => true;
|
||||
|
||||
private class ClickableUsername : OsuHoverContainer
|
||||
{
|
||||
public ClickableUsername(string username)
|
||||
{
|
||||
AutoSizeAxes = Axes.Both;
|
||||
Child = new OsuSpriteText
|
||||
{
|
||||
Text = username,
|
||||
Font = @"Exo2.0-BoldItalic",
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
73
osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs
Normal file
73
osu.Game/Overlays/BeatmapSet/Scores/ScoresContainer.cs
Normal file
@ -0,0 +1,73 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using OpenTK;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.API.Requests;
|
||||
using System.Linq;
|
||||
|
||||
namespace osu.Game.Overlays.BeatmapSet.Scores
|
||||
{
|
||||
public class ScoresContainer : Container
|
||||
{
|
||||
private readonly FillFlowContainer flow;
|
||||
private APIAccess api;
|
||||
|
||||
private BeatmapInfo beatmap;
|
||||
public BeatmapInfo Beatmap
|
||||
{
|
||||
set
|
||||
{
|
||||
if (beatmap == value) return;
|
||||
beatmap = value;
|
||||
|
||||
getScores();
|
||||
}
|
||||
get { return beatmap; }
|
||||
}
|
||||
|
||||
public ScoresContainer()
|
||||
{
|
||||
RelativeSizeAxes = Axes.X;
|
||||
AutoSizeAxes = Axes.Y;
|
||||
Child = flow = new FillFlowContainer
|
||||
{
|
||||
Anchor = Anchor.TopCentre,
|
||||
Origin = Anchor.TopCentre,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Width = 0.95f,
|
||||
Direction = FillDirection.Vertical,
|
||||
Spacing = new Vector2(0, 1),
|
||||
};
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(APIAccess api)
|
||||
{
|
||||
this.api = api;
|
||||
}
|
||||
|
||||
private void getScores()
|
||||
{
|
||||
flow.Clear();
|
||||
|
||||
var req = new GetScoresRequest(beatmap);
|
||||
req.Success += scores =>
|
||||
{
|
||||
int i = 0;
|
||||
foreach(var s in scores.Scores)
|
||||
{
|
||||
flow.Add(new DrawableScore(i, s));
|
||||
i++;
|
||||
}
|
||||
};
|
||||
api.Queue(req);
|
||||
}
|
||||
}
|
||||
}
|
@ -16,6 +16,7 @@ using osu.Game.Online.API;
|
||||
using osu.Game.Online.API.Requests;
|
||||
using osu.Game.Overlays.BeatmapSet;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Overlays.BeatmapSet.Scores;
|
||||
|
||||
namespace osu.Game.Overlays
|
||||
{
|
||||
@ -26,6 +27,7 @@ namespace osu.Game.Overlays
|
||||
|
||||
private readonly Header header;
|
||||
private readonly Info info;
|
||||
private readonly ScoresContainer scores;
|
||||
|
||||
private APIAccess api;
|
||||
private RulesetStore rulesets;
|
||||
@ -74,12 +76,13 @@ namespace osu.Game.Overlays
|
||||
{
|
||||
header = new Header(),
|
||||
info = new Info(),
|
||||
scores = new ScoresContainer(),
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
header.Picker.Beatmap.ValueChanged += b => info.Beatmap = b;
|
||||
header.Picker.Beatmap.ValueChanged += b => info.Beatmap = scores.Beatmap = b;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
|
@ -22,7 +22,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
|
||||
{
|
||||
protected readonly FillFlowContainer<OsuSpriteText> Stats;
|
||||
private readonly FillFlowContainer metadata;
|
||||
private readonly ModContainer modContainer;
|
||||
private readonly ScoreModsContainer modsContainer;
|
||||
protected readonly Score Score;
|
||||
|
||||
protected DrawableScore(Score score)
|
||||
@ -61,7 +61,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
|
||||
Depth = -1,
|
||||
},
|
||||
},
|
||||
modContainer = new ModContainer
|
||||
modsContainer = new ScoreModsContainer
|
||||
{
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Anchor = Anchor.CentreRight,
|
||||
@ -119,21 +119,11 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
|
||||
});
|
||||
|
||||
foreach (Mod mod in Score.Mods)
|
||||
modContainer.Add(new ModIcon(mod)
|
||||
modsContainer.Add(new ModIcon(mod)
|
||||
{
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Scale = new Vector2(0.5f),
|
||||
});
|
||||
}
|
||||
|
||||
private class ModContainer : FlowContainer<ModIcon>
|
||||
{
|
||||
protected override IEnumerable<Vector2> ComputeLayoutPositions()
|
||||
{
|
||||
int count = FlowingChildren.Count();
|
||||
for (int i = 0; i < count; i++)
|
||||
yield return new Vector2(DrawWidth * i * (count == 1 ? 0 : 1f / (count - 1)), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,21 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using OpenTK;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Rulesets.UI;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace osu.Game.Overlays.Profile.Sections.Ranks
|
||||
{
|
||||
public class ScoreModsContainer : FlowContainer<ModIcon>
|
||||
{
|
||||
protected override IEnumerable<Vector2> ComputeLayoutPositions()
|
||||
{
|
||||
int count = FlowingChildren.Count();
|
||||
for (int i = 0; i < count; i++)
|
||||
yield return new Vector2(DrawWidth * i * (count == 1 ? 0 : 1f / (count - 1)), 0);
|
||||
}
|
||||
}
|
||||
}
|
@ -279,9 +279,12 @@
|
||||
<Compile Include="Migrations\OsuDbContextModelSnapshot.cs" />
|
||||
<Compile Include="Online\API\Requests\GetBeatmapSetRequest.cs" />
|
||||
<Compile Include="Online\API\Requests\GetBeatmapSetsResponse.cs" />
|
||||
<Compile Include="Overlays\BeatmapSet\Scores\DrawableScore.cs" />
|
||||
<Compile Include="Overlays\BeatmapSet\Scores\ScoresContainer.cs" />
|
||||
<Compile Include="Overlays\Profile\Sections\Ranks\DrawablePerformanceScore.cs" />
|
||||
<Compile Include="Overlays\Profile\Sections\Ranks\PaginatedScoreContainer.cs" />
|
||||
<Compile Include="Overlays\Profile\Sections\Ranks\DrawableTotalScore.cs" />
|
||||
<Compile Include="Overlays\Profile\Sections\Ranks\ScoreModsContainer.cs" />
|
||||
<Compile Include="Overlays\Settings\SettingsButton.cs" />
|
||||
<Compile Include="Screens\Edit\Screens\Compose\Timeline\BeatmapWaveformGraph.cs" />
|
||||
<Compile Include="Beatmaps\Drawables\DifficultyColouredContainer.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user