1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-30 06:52:53 +08:00

move shared stuff between MostPlayedBeatmapDrawable and DrawableScore to DrawableBeatmapRow

This commit is contained in:
jorolf 2017-11-26 21:52:35 +01:00
parent 6b3347d6ac
commit 02fa1f9dd6
6 changed files with 213 additions and 219 deletions

View File

@ -0,0 +1,118 @@
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input;
using osu.Game.Graphics;
using OpenTK;
using OpenTK.Graphics;
namespace osu.Game.Overlays.Profile.Sections
{
public abstract class DrawableBeatmapRow : Container
{
private const int fade_duration = 200;
private Box underscoreLine;
private readonly Box coloredBackground;
private readonly Container background;
protected abstract Drawable CreatePicture();
protected FillFlowContainer LeftFlowContainer { get; private set; }
protected FillFlowContainer RightFlowContainer { get; private set; }
protected override Container<Drawable> Content { get; }
protected DrawableBeatmapRow()
{
RelativeSizeAxes = Axes.X;
Height = 60;
InternalChildren = new Drawable[]
{
background = new Container
{
RelativeSizeAxes = Axes.Both,
Masking = true,
CornerRadius = 3,
Alpha = 0,
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Shadow,
Offset = new Vector2(0f, 1f),
Radius = 1f,
Colour = Color4.Black.Opacity(0.2f),
},
Child = coloredBackground = new Box { RelativeSizeAxes = Axes.Both }
},
Content = new Container
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Width = 0.97f,
},
};
}
[BackgroundDependencyLoader(true)]
private void load(OsuColour colour)
{
AddRange(new Drawable[]
{
underscoreLine = new Box
{
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
RelativeSizeAxes = Axes.X,
Height = 1,
},
new FillFlowContainer
{
RelativeSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Children = new[]
{
CreatePicture(),
LeftFlowContainer = new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Margin = new MarginPadding { Left = 10 },
Direction = FillDirection.Vertical,
},
}
},
RightFlowContainer = new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Direction = FillDirection.Vertical,
},
});
coloredBackground.Colour = underscoreLine.Colour = colour.Gray4;
}
protected override bool OnClick(InputState state) => true;
protected override bool OnHover(InputState state)
{
background.FadeIn(fade_duration, Easing.OutQuint);
underscoreLine.FadeOut(fade_duration, Easing.OutQuint);
return true;
}
protected override void OnHoverLost(InputState state)
{
background.FadeOut(fade_duration, Easing.OutQuint);
underscoreLine.FadeIn(fade_duration, Easing.OutQuint);
base.OnHoverLost(state);
}
}
}

View File

@ -2,14 +2,11 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation; using osu.Framework.Allocation;
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.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Input;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables; using osu.Game.Beatmaps.Drawables;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using OpenTK; using OpenTK;
@ -17,144 +14,99 @@ using OpenTK.Graphics;
namespace osu.Game.Overlays.Profile.Sections.Historical namespace osu.Game.Overlays.Profile.Sections.Historical
{ {
public class MostPlayedBeatmapDrawable : Container public class MostPlayedBeatmapDrawable : DrawableBeatmapRow
{ {
private readonly BeatmapInfo beatmap; private readonly BeatmapInfo beatmap;
private readonly OsuHoverContainer mapperContainer; private readonly int playCount;
private OsuHoverContainer mapperContainer;
private readonly EdgeEffectParameters edgeEffectNormal = new EdgeEffectParameters
{
Type = EdgeEffectType.Shadow,
Offset = new Vector2(0, 1f),
Radius = 2f,
Colour = Color4.Black.Opacity(0.25f),
};
private readonly EdgeEffectParameters edgeEffectHovered = new EdgeEffectParameters
{
Type = EdgeEffectType.Shadow,
Offset = new Vector2(0, 5f),
Radius = 10f,
Colour = Color4.Black.Opacity(0.25f),
};
public MostPlayedBeatmapDrawable(BeatmapInfo beatmap, int playCount) public MostPlayedBeatmapDrawable(BeatmapInfo beatmap, int playCount)
{ {
this.beatmap = beatmap; this.beatmap = beatmap;
RelativeSizeAxes = Axes.X; this.playCount = playCount;
Height = 50; }
Margin = new MarginPadding { Bottom = 10 };
Masking = true;
EdgeEffect = edgeEffectNormal;
protected override Drawable CreatePicture() => new Container
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
AutoSizeAxes = Axes.Both,
Children = new Drawable[] Children = new Drawable[]
{ {
new Box //Background for this container, otherwise the shadow would be visible
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.Gray(0.2f),
},
new Box //Image Background while loading new Box //Image Background while loading
{ {
Size = new Vector2(80, 50), Size = new Vector2(80, 50),
Colour = Color4.Black, Colour = Color4.Black,
}, },
new DelayedLoadWrapper(new BeatmapSetCover(beatmap.BeatmapSet, BeatmapSetCoverType.List) new DelayedLoadWrapper(new BeatmapSetCover(beatmap.BeatmapSet, BeatmapSetCoverType.List)
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
FillMode = FillMode.Fit, FillMode = FillMode.Fit,
}), }),
new FillFlowContainer },
{ };
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding(10) { Left = 90 },
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Children = new Drawable[]
{
new BeatmapMetadataContainer(beatmap),
new FillFlowContainer
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Children = new []
{
new OsuSpriteText
{
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
Text = playCount.ToString(),
TextSize = 18,
Font = @"Exo2.0-SemiBoldItalic"
},
new OsuSpriteText
{
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
Text = @"times played ",
TextSize = 12,
Font = @"Exo2.0-RegularItalic"
},
}
}
},
},
new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Horizontal,
Children = new Drawable[]
{
new OsuSpriteText
{
Text = @"mapped by ",
TextSize = 12,
},
mapperContainer = new OsuHoverContainer
{
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
new OsuSpriteText
{
Text = beatmap.Metadata.AuthorString,
TextSize = 12,
Font = @"Exo2.0-MediumItalic"
}
}
},
}
},
},
}
};
}
[BackgroundDependencyLoader(true)] [BackgroundDependencyLoader(true)]
private void load(UserProfileOverlay profileOverlay) private void load(UserProfileOverlay profileOverlay)
{ {
LeftFlowContainer.Add(new BeatmapMetadataContainer(beatmap));
LeftFlowContainer.Add(new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Horizontal,
Children = new Drawable[]
{
new OsuSpriteText
{
Text = @"mapped by ",
TextSize = 12,
},
mapperContainer = new OsuHoverContainer
{
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
new OsuSpriteText
{
Text = beatmap.Metadata.AuthorString,
TextSize = 12,
Font = @"Exo2.0-MediumItalic"
}
}
},
}
});
RightFlowContainer.Add(new FillFlowContainer
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Children = new[]
{
new OsuSpriteText
{
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
Text = playCount.ToString(),
TextSize = 18,
Font = @"Exo2.0-SemiBoldItalic"
},
new OsuSpriteText
{
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
Text = @"times played ",
TextSize = 12,
Font = @"Exo2.0-RegularItalic"
},
}
});
if(profileOverlay != null) if(profileOverlay != null)
mapperContainer.Action = () => profileOverlay.ShowUser(beatmap.BeatmapSet.Metadata.Author); mapperContainer.Action = () => profileOverlay.ShowUser(beatmap.BeatmapSet.Metadata.Author);
} }
protected override bool OnHover(InputState state)
{
TweenEdgeEffectTo(edgeEffectHovered, 120, Easing.OutQuint);
return base.OnHover(state);
}
protected override void OnHoverLost(InputState state)
{
TweenEdgeEffectTo(edgeEffectNormal, 120, Easing.OutQuint);
base.OnHoverLost(state);
}
} }
} }

View File

@ -23,7 +23,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
private void load(OsuColour colour) private void load(OsuColour colour)
{ {
double pp = Score.PP ?? 0; double pp = Score.PP ?? 0;
Stats.Add(new OsuSpriteText RightFlowContainer.Add(new OsuSpriteText
{ {
Text = $"{pp:0}pp", Text = $"{pp:0}pp",
Anchor = Anchor.TopRight, Anchor = Anchor.TopRight,
@ -34,7 +34,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
if (weight.HasValue) if (weight.HasValue)
{ {
Stats.Add(new OsuSpriteText RightFlowContainer.Add(new OsuSpriteText
{ {
Text = $"weighted: {pp * weight:0}pp ({weight:P0})", Text = $"weighted: {pp * weight:0}pp ({weight:P0})",
Anchor = Anchor.TopRight, Anchor = Anchor.TopRight,

View File

@ -11,24 +11,14 @@ using osu.Game.Rulesets.Mods;
using osu.Game.Screens.Select.Leaderboards; using osu.Game.Screens.Select.Leaderboards;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI;
using OpenTK.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input;
using osu.Framework.Extensions.Color4Extensions;
namespace osu.Game.Overlays.Profile.Sections.Ranks namespace osu.Game.Overlays.Profile.Sections.Ranks
{ {
public abstract class DrawableScore : Container public abstract class DrawableScore : DrawableBeatmapRow
{ {
private const int fade_duration = 200;
protected readonly FillFlowContainer<OsuSpriteText> Stats;
private readonly FillFlowContainer metadata; private readonly FillFlowContainer metadata;
private readonly ScoreModsContainer modsContainer; private readonly ScoreModsContainer modsContainer;
protected readonly Score Score; protected readonly Score Score;
private readonly Box underscoreLine;
private readonly Box coloredBackground;
private readonly Container background;
protected DrawableScore(Score score) protected DrawableScore(Score score)
{ {
@ -38,85 +28,21 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
Height = 60; Height = 60;
Children = new Drawable[] Children = new Drawable[]
{ {
background = new Container modsContainer = new ScoreModsContainer
{ {
RelativeSizeAxes = Axes.Both, AutoSizeAxes = Axes.Y,
Masking = true, Anchor = Anchor.CentreRight,
CornerRadius = 3, Origin = Anchor.CentreRight,
Alpha = 0, Width = 60,
EdgeEffect = new EdgeEffectParameters Margin = new MarginPadding { Right = 160 }
{ }
Type = EdgeEffectType.Shadow,
Offset = new Vector2(0f, 1f),
Radius = 1f,
Colour = Color4.Black.Opacity(0.2f),
},
Child = coloredBackground = new Box { RelativeSizeAxes = Axes.Both }
},
new Container
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Width = 0.97f,
Children = new Drawable[]
{
underscoreLine = new Box
{
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
RelativeSizeAxes = Axes.X,
Height = 1,
},
new DrawableRank(score.Rank)
{
RelativeSizeAxes = Axes.Y,
Width = 60,
FillMode = FillMode.Fit,
},
Stats = new FillFlowContainer<OsuSpriteText>
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Direction = FillDirection.Vertical,
},
metadata = new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Margin = new MarginPadding { Left = 70 },
Direction = FillDirection.Vertical,
Child = new OsuSpriteText
{
Text = score.Date.LocalDateTime.ToShortDateString(),
TextSize = 11,
Colour = OsuColour.Gray(0xAA),
Depth = -1,
},
},
modsContainer = new ScoreModsContainer
{
AutoSizeAxes = Axes.Y,
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Width = 60,
Margin = new MarginPadding { Right = 160 }
}
}
},
}; };
} }
[BackgroundDependencyLoader(true)] [BackgroundDependencyLoader(true)]
private void load(OsuColour colour) private void load(OsuColour colour)
{ {
coloredBackground.Colour = underscoreLine.Colour = colour.Gray4; RightFlowContainer.Add(new OsuSpriteText
Stats.Add(new OsuSpriteText
{ {
Text = $"accuracy: {Score.Accuracy:P2}", Text = $"accuracy: {Score.Accuracy:P2}",
Anchor = Anchor.TopRight, Anchor = Anchor.TopRight,
@ -127,26 +53,23 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
Depth = -1, Depth = -1,
}); });
metadata.Add(new BeatmapMetadataContainer(Score.Beatmap)); LeftFlowContainer.Add(new BeatmapMetadataContainer(Score.Beatmap));
LeftFlowContainer.Add(new OsuSpriteText
{
Text = Score.Date.LocalDateTime.ToShortDateString(),
TextSize = 11,
Colour = OsuColour.Gray(0xAA),
});
foreach (Mod mod in Score.Mods) foreach (Mod mod in Score.Mods)
modsContainer.Add(new ModIcon(mod) { Scale = new Vector2(0.5f) }); modsContainer.Add(new ModIcon(mod) { Scale = new Vector2(0.5f) });
} }
protected override bool OnClick(InputState state) => true; protected override Drawable CreatePicture() => new DrawableRank(Score.Rank)
protected override bool OnHover(InputState state)
{ {
background.FadeIn(fade_duration, Easing.OutQuint); RelativeSizeAxes = Axes.Y,
underscoreLine.FadeOut(fade_duration, Easing.OutQuint); Width = 60,
return true; FillMode = FillMode.Fit,
} };
protected override void OnHoverLost(InputState state)
{
background.FadeOut(fade_duration, Easing.OutQuint);
underscoreLine.FadeIn(fade_duration, Easing.OutQuint);
base.OnHoverLost(state);
}
} }
} }

View File

@ -18,7 +18,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
Stats.Add(new OsuSpriteText RightFlowContainer.Add(new OsuSpriteText
{ {
Text = Score.TotalScore.ToString("#,###"), Text = Score.TotalScore.ToString("#,###"),
Anchor = Anchor.TopRight, Anchor = Anchor.TopRight,

View File

@ -294,6 +294,7 @@
<Compile Include="Online\API\Requests\GetUserBeatmapsRequest.cs" /> <Compile Include="Online\API\Requests\GetUserBeatmapsRequest.cs" />
<Compile Include="Overlays\Profile\Sections\BeatmapMetadataContainer.cs" /> <Compile Include="Overlays\Profile\Sections\BeatmapMetadataContainer.cs" />
<Compile Include="Overlays\Profile\Sections\Beatmaps\PaginatedBeatmapContainer.cs" /> <Compile Include="Overlays\Profile\Sections\Beatmaps\PaginatedBeatmapContainer.cs" />
<Compile Include="Overlays\Profile\Sections\DrawableBeatmapRow.cs" />
<Compile Include="Overlays\Profile\Sections\Historical\MostPlayedBeatmapDrawable.cs" /> <Compile Include="Overlays\Profile\Sections\Historical\MostPlayedBeatmapDrawable.cs" />
<Compile Include="Overlays\Profile\Sections\Historical\PaginatedMostPlayedBeatmapContainer.cs" /> <Compile Include="Overlays\Profile\Sections\Historical\PaginatedMostPlayedBeatmapContainer.cs" />
<Compile Include="Overlays\Profile\Sections\Kudosu\KudosuInfo.cs" /> <Compile Include="Overlays\Profile\Sections\Kudosu\KudosuInfo.cs" />