1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 08:52:55 +08:00

Remove custom link container implementation

This commit is contained in:
Andrei Zavatski 2019-07-15 13:09:21 +03:00
parent cfb1e0683c
commit d62e42ba14
6 changed files with 67 additions and 204 deletions

View File

@ -4,22 +4,19 @@
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Localisation;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
namespace osu.Game.Overlays.Profile.Sections
{
/// <summary>
/// Display artist/title/mapper information, commonly used as the left portion of a profile or score display row (see <see cref="DrawableProfileRow"/>).
/// </summary>
public class BeatmapMetadataContainer : OsuHoverContainer
public abstract class BeatmapMetadataContainer : OsuHoverContainer
{
private readonly BeatmapInfo beatmap;
public BeatmapMetadataContainer(BeatmapInfo beatmap)
protected BeatmapMetadataContainer(BeatmapInfo beatmap)
{
this.beatmap = beatmap;
AutoSizeAxes = Axes.Both;
@ -40,23 +37,10 @@ namespace osu.Game.Overlays.Profile.Sections
Child = new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
new OsuSpriteText
{
Text = new LocalisedString((
$"{beatmap.Metadata.TitleUnicode ?? beatmap.Metadata.Title} [{beatmap.Version}] ",
$"{beatmap.Metadata.Title ?? beatmap.Metadata.TitleUnicode} [{beatmap.Version}] ")),
Font = OsuFont.GetFont(size: 15, weight: FontWeight.SemiBold, italics: true)
},
new OsuSpriteText
{
Text = new LocalisedString((beatmap.Metadata.ArtistUnicode, beatmap.Metadata.Artist)),
Padding = new MarginPadding { Top = 3 },
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Regular, italics: true)
},
},
Children = CreateText(beatmap),
};
}
protected abstract Drawable[] CreateText(BeatmapInfo beatmap);
}
}

View File

@ -19,13 +19,12 @@ namespace osu.Game.Overlays.Profile.Sections.Historical
{
public class DrawableMostPlayedBeatmap : OsuHoverContainer
{
private readonly OsuSpriteText mapperText;
private readonly Box background;
private const int cover_width = 100;
private const int corner_radius = 10;
private readonly SpriteIcon icon;
private readonly OsuSpriteText playCountText;
private readonly UnderscoredUserLink mapper;
private readonly LinkFlowContainer mapper;
protected override IEnumerable<Drawable> EffectTargets => new[] { background };
@ -71,54 +70,24 @@ namespace osu.Game.Overlays.Profile.Sections.Historical
Padding = new MarginPadding { Left = 15, Right = 20 },
Children = new Drawable[]
{
new UnderscoredBeatmapLink(beatmap)
new MostPlayedBeatmapMetadataContainer(beatmap)
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.BottomLeft,
Margin = new MarginPadding { Bottom = 2 },
Text = new[]
{
new OsuSpriteText
{
Text = new LocalisedString((
$"{beatmap.Metadata.TitleUnicode ?? beatmap.Metadata.Title} [{beatmap.Version}] ",
$"{beatmap.Metadata.Title ?? beatmap.Metadata.TitleUnicode} [{beatmap.Version}] ")),
Font = OsuFont.GetFont(size: 20, weight: FontWeight.Bold)
},
new OsuSpriteText
mapper = new LinkFlowContainer(t => t.Font = OsuFont.GetFont(size: 15, weight: FontWeight.Regular))
{
Text = "by " + new LocalisedString((beatmap.Metadata.ArtistUnicode, beatmap.Metadata.Artist)),
Font = OsuFont.GetFont(size: 20, weight: FontWeight.Regular)
},
}
},
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Anchor = Anchor.CentreLeft,
Origin = Anchor.TopLeft,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Margin = new MarginPadding { Top = 2 },
Children = new Drawable[]
}.With(d =>
{
mapperText = new OsuSpriteText
{
Text = "mapped by ",
Font = OsuFont.GetFont(size: 15, weight: FontWeight.Regular),
},
mapper = new UnderscoredUserLink(beatmap.Metadata.Author.Id)
{
Text = new[]
{
new OsuSpriteText
{
Text = beatmap.Metadata.Author.Username,
Font = OsuFont.GetFont(size: 15, weight: FontWeight.Bold),
}
}
},
}
},
d.AddText("mapped by ");
d.AddUserLink(beatmap.Metadata.Author);
}),
new FillFlowContainer
{
Anchor = Anchor.CentreRight,
@ -157,8 +126,32 @@ namespace osu.Game.Overlays.Profile.Sections.Historical
{
IdleColour = colors.GreySeafoam;
HoverColour = colors.GreySeafoamLight;
mapperText.Colour = mapper.Colour = colors.GreySeafoamLighter;
mapper.Colour = colors.GreySeafoamLighter;
icon.Colour = playCountText.Colour = colors.Yellow;
}
private class MostPlayedBeatmapMetadataContainer : BeatmapMetadataContainer
{
public MostPlayedBeatmapMetadataContainer(BeatmapInfo beatmap)
: base(beatmap)
{
}
protected override Drawable[] CreateText(BeatmapInfo beatmap) => new Drawable[]
{
new OsuSpriteText
{
Text = new LocalisedString((
$"{beatmap.Metadata.TitleUnicode ?? beatmap.Metadata.Title} [{beatmap.Version}] ",
$"{beatmap.Metadata.Title ?? beatmap.Metadata.TitleUnicode} [{beatmap.Version}] ")),
Font = OsuFont.GetFont(size: 20, weight: FontWeight.Bold)
},
new OsuSpriteText
{
Text = "by " + new LocalisedString((beatmap.Metadata.ArtistUnicode, beatmap.Metadata.Artist)),
Font = OsuFont.GetFont(size: 20, weight: FontWeight.Regular)
},
};
}
}
}

View File

@ -10,6 +10,8 @@ using osu.Game.Online.Leaderboards;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.UI;
using osu.Game.Scoring;
using osu.Game.Beatmaps;
using osu.Framework.Localisation;
namespace osu.Game.Overlays.Profile.Sections.Ranks
{
@ -51,7 +53,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
RightFlowContainer.Insert(1, text);
LeftFlowContainer.Add(new BeatmapMetadataContainer(Score.Beatmap));
LeftFlowContainer.Add(new ProfileScoreBeatmapMetadataContainer(Score.Beatmap));
LeftFlowContainer.Add(new DrawableDate(Score.Date));
foreach (Mod mod in Score.Mods)
@ -64,5 +66,30 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
Width = 60,
FillMode = FillMode.Fit,
};
private class ProfileScoreBeatmapMetadataContainer : BeatmapMetadataContainer
{
public ProfileScoreBeatmapMetadataContainer(BeatmapInfo beatmap)
: base(beatmap)
{
}
protected override Drawable[] CreateText(BeatmapInfo beatmap) => new Drawable[]
{
new OsuSpriteText
{
Text = new LocalisedString((
$"{beatmap.Metadata.TitleUnicode ?? beatmap.Metadata.Title} [{beatmap.Version}] ",
$"{beatmap.Metadata.Title ?? beatmap.Metadata.TitleUnicode} [{beatmap.Version}] ")),
Font = OsuFont.GetFont(size: 15, weight: FontWeight.SemiBold, italics: true)
},
new OsuSpriteText
{
Text = new LocalisedString((beatmap.Metadata.ArtistUnicode, beatmap.Metadata.Artist)),
Padding = new MarginPadding { Top = 3 },
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Regular, italics: true)
},
};
}
}
}

View File

@ -1,30 +0,0 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Game.Beatmaps;
namespace osu.Game.Overlays.Profile.Sections
{
public class UnderscoredBeatmapLink : UnderscoredLinkContainer
{
private readonly BeatmapInfo beatmap;
public UnderscoredBeatmapLink(BeatmapInfo beatmap)
{
this.beatmap = beatmap;
}
protected override void LoadComplete()
{
base.LoadComplete();
ClickAction = () =>
{
var beatmapId = beatmap.OnlineBeatmapID;
if (beatmapId.HasValue)
Game?.ShowBeatmap(beatmapId.Value);
};
}
}
}

View File

@ -1,89 +0,0 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events;
using osu.Game.Graphics.Sprites;
using System;
using System.Collections.Generic;
namespace osu.Game.Overlays.Profile.Sections
{
public abstract class UnderscoredLinkContainer : Container
{
private const int duration = 200;
private readonly Container underscore;
private readonly FillFlowContainer<OsuSpriteText> textContent;
protected OsuGame Game;
protected Action ClickAction;
public IReadOnlyList<OsuSpriteText> Text
{
get => textContent.Children;
set
{
textContent.Clear();
textContent.AddRange(value);
}
}
protected UnderscoredLinkContainer()
{
AutoSizeAxes = Axes.Both;
Child = new Container
{
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
underscore = new Container
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
RelativeSizeAxes = Axes.X,
Height = 1,
Alpha = 0,
AlwaysPresent = true,
Child = new Box
{
RelativeSizeAxes = Axes.Both,
}
},
textContent = new FillFlowContainer<OsuSpriteText>
{
Direction = FillDirection.Horizontal,
AutoSizeAxes = Axes.Both,
},
},
};
}
[BackgroundDependencyLoader(true)]
private void load(OsuGame game)
{
Game = game;
}
protected override bool OnHover(HoverEvent e)
{
underscore.FadeIn(duration, Easing.OutQuint);
return base.OnHover(e);
}
protected override void OnHoverLost(HoverLostEvent e)
{
underscore.FadeOut(duration, Easing.OutQuint);
base.OnHoverLost(e);
}
protected override bool OnClick(ClickEvent e)
{
ClickAction?.Invoke();
return base.OnClick(e);
}
}
}

View File

@ -1,22 +0,0 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
namespace osu.Game.Overlays.Profile.Sections
{
public class UnderscoredUserLink : UnderscoredLinkContainer
{
private readonly long userId;
public UnderscoredUserLink(long userId)
{
this.userId = userId;
}
protected override void LoadComplete()
{
base.LoadComplete();
ClickAction = () => Game?.ShowUser(userId);
}
}
}