1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 13:37:25 +08:00

Add click to avatar

This commit is contained in:
smoogipoo 2018-12-20 20:08:22 +09:00 committed by Dean Herbert
parent c1d316d06e
commit f47ac35522
6 changed files with 67 additions and 22 deletions

View File

@ -9,7 +9,6 @@ using osu.Game.Graphics.Sprites;
using osu.Game.Users;
using osuTK;
using osuTK.Graphics;
using osu.Framework.Allocation;
using osu.Game.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
@ -20,7 +19,6 @@ namespace osu.Game.Overlays.BeatmapSet
private const float height = 50;
private readonly UpdateableAvatar avatar;
private readonly ClickableArea clickableArea;
private readonly FillFlowContainer fields;
private BeatmapSetInfo beatmapSet;
@ -73,7 +71,7 @@ namespace osu.Game.Overlays.BeatmapSet
Children = new Drawable[]
{
clickableArea = new ClickableArea
new Container
{
AutoSizeAxes = Axes.Both,
CornerRadius = 3,
@ -100,14 +98,8 @@ namespace osu.Game.Overlays.BeatmapSet
};
}
[BackgroundDependencyLoader(true)]
private void load(UserProfileOverlay profile)
private void load()
{
clickableArea.Action = () =>
{
if (avatar.User != null) profile?.ShowUser(avatar.User);
};
updateDisplay();
}

View File

@ -82,6 +82,7 @@ namespace osu.Game.Overlays.Profile
Origin = Anchor.BottomLeft,
Masking = true,
CornerRadius = 5,
OpenOnClick = { Value = false },
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Shadow,

View File

@ -31,6 +31,7 @@ namespace osu.Game.Overlays.Toolbar
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
CornerRadius = 4,
OpenOnClick = { Value = false },
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Shadow,

View File

@ -3,17 +3,29 @@
using System;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Framework.Input.Events;
using osu.Game.Graphics.Containers;
namespace osu.Game.Users
{
public class Avatar : Container
{
/// <summary>
/// Whether to open the user's profile when clicked.
/// </summary>
public readonly BindableBool OpenOnClick = new BindableBool(true);
private readonly User user;
[Resolved(CanBeNull = true)]
private OsuGame game { get; set; }
/// <summary>
/// An avatar for specified user.
/// </summary>
@ -33,14 +45,43 @@ namespace osu.Game.Users
if (user != null && user.Id > 1) texture = textures.Get($@"https://a.ppy.sh/{user.Id}");
if (texture == null) texture = textures.Get(@"Online/avatar-guest");
Add(new Sprite
ClickableArea clickableArea;
Add(clickableArea = new ClickableArea
{
RelativeSizeAxes = Axes.Both,
Child = new Sprite
{
RelativeSizeAxes = Axes.Both,
Texture = texture,
FillMode = FillMode.Fit,
Anchor = Anchor.Centre,
Origin = Anchor.Centre
},
Action = openProfile
});
clickableArea.Enabled.BindTo(OpenOnClick);
}
private void openProfile()
{
if (!OpenOnClick)
return;
if (user != null)
game?.ShowUser(user.Id);
}
private class ClickableArea : OsuClickableContainer, IHasTooltip
{
public string TooltipText => Enabled.Value ? @"View Profile" : null;
protected override bool OnClick(ClickEvent e)
{
if (!Enabled)
return false;
return base.OnClick(e);
}
}
}
}

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -35,6 +36,11 @@ namespace osu.Game.Users
}
}
/// <summary>
/// Whether to open the user's profile when clicked.
/// </summary>
public readonly BindableBool OpenOnClick = new BindableBool(true);
protected override void LoadComplete()
{
base.LoadComplete();
@ -45,15 +51,18 @@ namespace osu.Game.Users
{
displayedAvatar?.FadeOut(300);
displayedAvatar?.Expire();
if (user != null || ShowGuestOnNull)
{
Add(displayedAvatar = new DelayedLoadWrapper(
new Avatar(user)
var avatar = new Avatar(user)
{
RelativeSizeAxes = Axes.Both,
OnLoadComplete = d => d.FadeInFromZero(300, Easing.OutQuint),
})
);
};
avatar.OpenOnClick.BindTo(OpenOnClick);
Add(displayedAvatar = new DelayedLoadWrapper(avatar));
}
}
}

View File

@ -99,6 +99,7 @@ namespace osu.Game.Users
User = user,
Masking = true,
CornerRadius = 5,
OpenOnClick = { Value = false },
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Shadow,