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

Merge branch 'master' into key-binding-fixes

This commit is contained in:
Dean Herbert 2019-06-21 15:12:37 +09:00 committed by GitHub
commit 5ed6c09aa9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 515 additions and 379 deletions

View File

@ -18,9 +18,6 @@ namespace osu.Game.Tests.Visual.UserInterface
[TestFixture] [TestFixture]
public class TestSceneNotificationOverlay : OsuTestScene public class TestSceneNotificationOverlay : OsuTestScene
{ {
private readonly NotificationOverlay manager;
private readonly List<ProgressNotification> progressingNotifications = new List<ProgressNotification>();
public override IReadOnlyList<Type> RequiredTypes => new[] public override IReadOnlyList<Type> RequiredTypes => new[]
{ {
typeof(NotificationSection), typeof(NotificationSection),
@ -31,25 +28,33 @@ namespace osu.Game.Tests.Visual.UserInterface
typeof(Notification) typeof(Notification)
}; };
public TestSceneNotificationOverlay() private NotificationOverlay notificationOverlay;
private readonly List<ProgressNotification> progressingNotifications = new List<ProgressNotification>();
private SpriteText displayedCount;
[SetUp]
public void SetUp() => Schedule(() =>
{ {
progressingNotifications.Clear(); progressingNotifications.Clear();
Content.Add(manager = new NotificationOverlay Content.Children = new Drawable[]
{ {
Anchor = Anchor.TopRight, notificationOverlay = new NotificationOverlay
Origin = Anchor.TopRight {
}); Anchor = Anchor.TopRight,
Origin = Anchor.TopRight
},
displayedCount = new OsuSpriteText()
};
SpriteText displayedCount = new OsuSpriteText(); notificationOverlay.UnreadCount.ValueChanged += count => { displayedCount.Text = $"displayed count: {count.NewValue}"; };
});
Content.Add(displayedCount);
void setState(Visibility state) => AddStep(state.ToString(), () => manager.State.Value = state);
void checkProgressingCount(int expected) => AddAssert($"progressing count is {expected}", () => progressingNotifications.Count == expected);
manager.UnreadCount.ValueChanged += count => { displayedCount.Text = $"displayed count: {count.NewValue}"; };
[Test]
public void TestBasicFlow()
{
setState(Visibility.Visible); setState(Visibility.Visible);
AddStep(@"simple #1", sendHelloNotification); AddStep(@"simple #1", sendHelloNotification);
AddStep(@"simple #2", sendAmazingNotification); AddStep(@"simple #2", sendAmazingNotification);
@ -61,6 +66,7 @@ namespace osu.Game.Tests.Visual.UserInterface
setState(Visibility.Hidden); setState(Visibility.Hidden);
AddRepeatStep(@"add many simple", sendManyNotifications, 3); AddRepeatStep(@"add many simple", sendManyNotifications, 3);
AddWaitStep("wait some", 5); AddWaitStep("wait some", 5);
checkProgressingCount(0); checkProgressingCount(0);
@ -69,18 +75,122 @@ namespace osu.Game.Tests.Visual.UserInterface
checkProgressingCount(1); checkProgressingCount(1);
AddAssert("Displayed count is 33", () => manager.UnreadCount.Value == 33); checkDisplayedCount(33);
AddWaitStep("wait some", 10); AddWaitStep("wait some", 10);
checkProgressingCount(0); checkProgressingCount(0);
setState(Visibility.Visible);
//AddStep(@"barrage", () => sendBarrage());
} }
private void sendBarrage(int remaining = 10) [Test]
public void TestImportantWhileClosed()
{
AddStep(@"simple #1", sendHelloNotification);
AddAssert("Is visible", () => notificationOverlay.State.Value == Visibility.Visible);
checkDisplayedCount(1);
AddStep(@"progress #1", sendUploadProgress);
AddStep(@"progress #2", sendDownloadProgress);
checkProgressingCount(2);
checkDisplayedCount(3);
}
[Test]
public void TestUnimportantWhileClosed()
{
AddStep(@"background #1", sendBackgroundNotification);
AddAssert("Is not visible", () => notificationOverlay.State.Value == Visibility.Hidden);
checkDisplayedCount(1);
AddStep(@"background progress #1", sendBackgroundUploadProgress);
AddWaitStep("wait some", 5);
checkProgressingCount(0);
checkDisplayedCount(2);
AddStep(@"simple #1", sendHelloNotification);
checkDisplayedCount(3);
}
[Test]
public void TestSpam()
{
setState(Visibility.Visible);
AddRepeatStep("send barrage", sendBarrage, 10);
}
protected override void Update()
{
base.Update();
progressingNotifications.RemoveAll(n => n.State == ProgressNotificationState.Completed);
if (progressingNotifications.Count(n => n.State == ProgressNotificationState.Active) < 3)
{
var p = progressingNotifications.Find(n => n.State == ProgressNotificationState.Queued);
if (p != null)
p.State = ProgressNotificationState.Active;
}
foreach (var n in progressingNotifications.FindAll(n => n.State == ProgressNotificationState.Active))
{
if (n.Progress < 1)
n.Progress += (float)(Time.Elapsed / 400) * RNG.NextSingle();
else
n.State = ProgressNotificationState.Completed;
}
}
private void checkDisplayedCount(int expected) =>
AddAssert($"Displayed count is {expected}", () => notificationOverlay.UnreadCount.Value == expected);
private void sendDownloadProgress()
{
var n = new ProgressNotification
{
Text = @"Downloading Haitai...",
CompletionText = "Downloaded Haitai!",
};
notificationOverlay.Post(n);
progressingNotifications.Add(n);
}
private void sendUploadProgress()
{
var n = new ProgressNotification
{
Text = @"Uploading to BSS...",
CompletionText = "Uploaded to BSS!",
};
notificationOverlay.Post(n);
progressingNotifications.Add(n);
}
private void sendBackgroundUploadProgress()
{
var n = new BackgroundProgressNotification
{
Text = @"Uploading to BSS...",
CompletionText = "Uploaded to BSS!",
};
notificationOverlay.Post(n);
progressingNotifications.Add(n);
}
private void setState(Visibility state) => AddStep(state.ToString(), () => notificationOverlay.State.Value = state);
private void checkProgressingCount(int expected) => AddAssert($"progressing count is {expected}", () => progressingNotifications.Count == expected);
private void sendBarrage()
{ {
switch (RNG.Next(0, 4)) switch (RNG.Next(0, 4))
{ {
@ -100,69 +210,37 @@ namespace osu.Game.Tests.Visual.UserInterface
sendDownloadProgress(); sendDownloadProgress();
break; break;
} }
if (remaining > 0)
Scheduler.AddDelayed(() => sendBarrage(remaining - 1), 80);
}
protected override void Update()
{
base.Update();
progressingNotifications.RemoveAll(n => n.State == ProgressNotificationState.Completed);
if (progressingNotifications.Count(n => n.State == ProgressNotificationState.Active) < 3)
{
var p = progressingNotifications.Find(n => n.State == ProgressNotificationState.Queued);
if (p != null)
p.State = ProgressNotificationState.Active;
}
foreach (var n in progressingNotifications.FindAll(n => n.State == ProgressNotificationState.Active))
{
if (n.Progress < 1)
n.Progress += (float)(Time.Elapsed / 400) * RNG.NextSingle();
else
n.State = ProgressNotificationState.Completed;
}
}
private void sendDownloadProgress()
{
var n = new ProgressNotification
{
Text = @"Downloading Haitai...",
CompletionText = "Downloaded Haitai!",
};
manager.Post(n);
progressingNotifications.Add(n);
}
private void sendUploadProgress()
{
var n = new ProgressNotification
{
Text = @"Uploading to BSS...",
CompletionText = "Uploaded to BSS!",
};
manager.Post(n);
progressingNotifications.Add(n);
} }
private void sendAmazingNotification() private void sendAmazingNotification()
{ {
manager.Post(new SimpleNotification { Text = @"You are amazing" }); notificationOverlay.Post(new SimpleNotification { Text = @"You are amazing" });
} }
private void sendHelloNotification() private void sendHelloNotification()
{ {
manager.Post(new SimpleNotification { Text = @"Welcome to osu!. Enjoy your stay!" }); notificationOverlay.Post(new SimpleNotification { Text = @"Welcome to osu!. Enjoy your stay!" });
}
private void sendBackgroundNotification()
{
notificationOverlay.Post(new BackgroundNotification { Text = @"Welcome to osu!. Enjoy your stay!" });
} }
private void sendManyNotifications() private void sendManyNotifications()
{ {
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
manager.Post(new SimpleNotification { Text = @"Spam incoming!!" }); notificationOverlay.Post(new SimpleNotification { Text = @"Spam incoming!!" });
}
private class BackgroundNotification : SimpleNotification
{
public override bool IsImportant => false;
}
private class BackgroundProgressNotification : ProgressNotification
{
public override bool IsImportant => false;
} }
} }
} }

View File

@ -130,6 +130,11 @@ namespace osu.Game.Online.Chat
public StandAloneDrawableChannel(Channel channel) public StandAloneDrawableChannel(Channel channel)
: base(channel) : base(channel)
{
}
[BackgroundDependencyLoader]
private void load()
{ {
ChatLineFlow.Padding = new MarginPadding { Horizontal = 0 }; ChatLineFlow.Padding = new MarginPadding { Horizontal = 0 };
} }

View File

@ -3,72 +3,44 @@
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Extensions; using osu.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Textures;
using osu.Game.Scoring; using osu.Game.Scoring;
using System;
namespace osu.Game.Online.Leaderboards namespace osu.Game.Online.Leaderboards
{ {
public class DrawableRank : Container public class DrawableRank : Sprite
{ {
private readonly Sprite rankSprite; private readonly ScoreRank rank;
private TextureStore textures;
public ScoreRank Rank { get; private set; }
public DrawableRank(ScoreRank rank) public DrawableRank(ScoreRank rank)
{ {
Rank = rank; this.rank = rank;
Children = new Drawable[]
{
rankSprite = new Sprite
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
FillMode = FillMode.Fit
},
};
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader(true)]
private void load(TextureStore textures) private void load(TextureStore ts)
{ {
this.textures = textures; if (ts == null)
updateTexture(); throw new ArgumentNullException(nameof(ts));
Texture = ts.Get($@"Grades/{getTextureName()}");
} }
private void updateTexture() private string getTextureName()
{ {
string textureName; switch (rank)
switch (Rank)
{ {
default: default:
textureName = Rank.GetDescription(); return rank.GetDescription();
break;
case ScoreRank.SH: case ScoreRank.SH:
textureName = "SPlus"; return "SPlus";
break;
case ScoreRank.XH: case ScoreRank.XH:
textureName = "SSPlus"; return "SSPlus";
break;
} }
rankSprite.Texture = textures.Get($@"Grades/{textureName}");
}
public void UpdateRank(ScoreRank newRank)
{
Rank = newRank;
if (LoadState >= LoadState.Ready)
updateTexture();
} }
} }
} }

View File

@ -17,7 +17,7 @@ using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI;
using osu.Game.Scoring; using osu.Game.Scoring;
using osu.Game.Users; using osu.Game.Users.Drawables;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
@ -65,7 +65,7 @@ namespace osu.Game.Online.Leaderboards
statisticsLabels = GetStatistics(score).Select(s => new ScoreComponentLabel(s)).ToList(); statisticsLabels = GetStatistics(score).Select(s => new ScoreComponentLabel(s)).ToList();
Avatar innerAvatar; DrawableAvatar innerAvatar;
Children = new Drawable[] Children = new Drawable[]
{ {
@ -112,7 +112,7 @@ namespace osu.Game.Online.Leaderboards
Children = new[] Children = new[]
{ {
avatar = new DelayedLoadWrapper( avatar = new DelayedLoadWrapper(
innerAvatar = new Avatar(user) innerAvatar = new DrawableAvatar(user)
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
CornerRadius = corner_radius, CornerRadius = corner_radius,
@ -157,7 +157,7 @@ namespace osu.Game.Online.Leaderboards
Masking = true, Masking = true,
Children = new Drawable[] Children = new Drawable[]
{ {
new DrawableFlag(user.Country) new UpdateableFlag(user.Country)
{ {
Width = 30, Width = 30,
RelativeSizeAxes = Axes.Y, RelativeSizeAxes = Axes.Y,
@ -193,7 +193,7 @@ namespace osu.Game.Online.Leaderboards
Size = new Vector2(40f, 20f), Size = new Vector2(40f, 20f),
Children = new[] Children = new[]
{ {
scoreRank = new DrawableRank(score.Rank) scoreRank = new UpdateableRank(score.Rank)
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,

View File

@ -0,0 +1,31 @@
// 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.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Scoring;
namespace osu.Game.Online.Leaderboards
{
public class UpdateableRank : ModelBackedDrawable<ScoreRank>
{
public ScoreRank Rank
{
get => Model;
set => Model = value;
}
public UpdateableRank(ScoreRank rank)
{
Rank = rank;
}
protected override Drawable CreateDrawable(ScoreRank rank) => new DrawableRank(rank)
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
FillMode = FillMode.Fit,
};
}
}

View File

@ -6,7 +6,7 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Users; using osu.Game.Users.Drawables;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
using osu.Framework.Graphics.Effects; using osu.Framework.Graphics.Effects;

View File

@ -13,7 +13,7 @@ using osu.Game.Graphics.Sprites;
using osu.Game.Online.Leaderboards; using osu.Game.Online.Leaderboards;
using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI;
using osu.Game.Scoring; using osu.Game.Scoring;
using osu.Game.Users; using osu.Game.Users.Drawables;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
@ -103,7 +103,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
Text = $"#{index + 1}", Text = $"#{index + 1}",
Font = OsuFont.GetFont(size: text_size, weight: FontWeight.Bold) Font = OsuFont.GetFont(size: text_size, weight: FontWeight.Bold)
}, },
new DrawableRank(score.Rank) new UpdateableRank(score.Rank)
{ {
Size = new Vector2(30, 20) Size = new Vector2(30, 20)
}, },
@ -135,7 +135,11 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
Spacing = new Vector2(5, 0), Spacing = new Vector2(5, 0),
Children = new Drawable[] Children = new Drawable[]
{ {
new DrawableFlag(score.User.Country) { Size = new Vector2(20, 13) }, new UpdateableFlag(score.User.Country)
{
Size = new Vector2(20, 13),
ShowPlaceholderOnNull = false,
},
username username
} }
}, },

View File

@ -13,7 +13,7 @@ using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Online.Leaderboards; using osu.Game.Online.Leaderboards;
using osu.Game.Scoring; using osu.Game.Scoring;
using osu.Game.Users; using osu.Game.Users.Drawables;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
@ -22,11 +22,11 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
public class TopScoreUserSection : CompositeDrawable public class TopScoreUserSection : CompositeDrawable
{ {
private readonly SpriteText rankText; private readonly SpriteText rankText;
private readonly DrawableRank rank; private readonly UpdateableRank rank;
private readonly UpdateableAvatar avatar; private readonly UpdateableAvatar avatar;
private readonly LinkFlowContainer usernameText; private readonly LinkFlowContainer usernameText;
private readonly SpriteText date; private readonly SpriteText date;
private readonly DrawableFlag flag; private readonly UpdateableFlag flag;
public TopScoreUserSection() public TopScoreUserSection()
{ {
@ -46,7 +46,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
Text = "#1", Text = "#1",
Font = OsuFont.GetFont(size: 30, weight: FontWeight.Bold, italics: true) Font = OsuFont.GetFont(size: 30, weight: FontWeight.Bold, italics: true)
}, },
rank = new DrawableRank(ScoreRank.D) rank = new UpdateableRank(ScoreRank.D)
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
@ -67,6 +67,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
Offset = new Vector2(0, 2), Offset = new Vector2(0, 2),
Radius = 1, Radius = 1,
}, },
ShowGuestOnNull = false,
}, },
new FillFlowContainer new FillFlowContainer
{ {
@ -89,11 +90,12 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
Font = OsuFont.GetFont(size: 15, weight: FontWeight.Bold) Font = OsuFont.GetFont(size: 15, weight: FontWeight.Bold)
}, },
flag = new DrawableFlag flag = new UpdateableFlag
{ {
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
Size = new Vector2(20, 13), Size = new Vector2(20, 13),
ShowPlaceholderOnNull = false,
}, },
} }
} }
@ -121,7 +123,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
usernameText.Clear(); usernameText.Clear();
usernameText.AddUserLink(value.User); usernameText.AddUserLink(value.User);
rank.UpdateRank(value.Rank); rank.Rank = value.Rank;
} }
} }
} }

View File

@ -74,17 +74,12 @@ namespace osu.Game.Overlays.Chat
} }
} }
private bool senderHasBackground => !string.IsNullOrEmpty(message.Sender.Colour);
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OsuColour colours)
{ {
customUsernameColour = colours.ChatBlue; customUsernameColour = colours.ChatBlue;
}
private bool senderHasBackground => !string.IsNullOrEmpty(message.Sender.Colour);
protected override void LoadComplete()
{
base.LoadComplete();
bool hasBackground = senderHasBackground; bool hasBackground = senderHasBackground;
@ -179,6 +174,11 @@ namespace osu.Game.Overlays.Chat
}; };
updateMessageContent(); updateMessageContent();
}
protected override void LoadComplete()
{
base.LoadComplete();
FinishTransforms(true); FinishTransforms(true);
} }

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using osu.Framework.Allocation;
using osuTK.Graphics; using osuTK.Graphics;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -17,15 +18,18 @@ namespace osu.Game.Overlays.Chat
public class DrawableChannel : Container public class DrawableChannel : Container
{ {
public readonly Channel Channel; public readonly Channel Channel;
protected readonly ChatLineContainer ChatLineFlow; protected ChatLineContainer ChatLineFlow;
private readonly OsuScrollContainer scroll; private OsuScrollContainer scroll;
public DrawableChannel(Channel channel) public DrawableChannel(Channel channel)
{ {
Channel = channel; Channel = channel;
RelativeSizeAxes = Axes.Both; RelativeSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader]
private void load()
{
Children = new Drawable[] Children = new Drawable[]
{ {
scroll = new OsuScrollContainer scroll = new OsuScrollContainer
@ -48,18 +52,17 @@ namespace osu.Game.Overlays.Chat
}, },
} }
}; };
}
protected override void LoadComplete()
{
base.LoadComplete();
newMessagesArrived(Channel.Messages); newMessagesArrived(Channel.Messages);
Channel.NewMessagesArrived += newMessagesArrived; Channel.NewMessagesArrived += newMessagesArrived;
Channel.MessageRemoved += messageRemoved; Channel.MessageRemoved += messageRemoved;
Channel.PendingMessageResolved += pendingMessageResolved; Channel.PendingMessageResolved += pendingMessageResolved;
}
protected override void LoadComplete()
{
base.LoadComplete();
scrollToEnd(); scrollToEnd();
} }

View File

@ -10,7 +10,7 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Online.Chat; using osu.Game.Online.Chat;
using osu.Game.Users; using osu.Game.Users.Drawables;
using osuTK; using osuTK;
namespace osu.Game.Overlays.Chat.Tabs namespace osu.Game.Overlays.Chat.Tabs
@ -25,7 +25,7 @@ namespace osu.Game.Overlays.Chat.Tabs
if (value.Type != ChannelType.PM) if (value.Type != ChannelType.PM)
throw new ArgumentException("Argument value needs to have the targettype user!"); throw new ArgumentException("Argument value needs to have the targettype user!");
Avatar avatar; DrawableAvatar avatar;
AddRange(new Drawable[] AddRange(new Drawable[]
{ {
@ -48,7 +48,7 @@ namespace osu.Game.Overlays.Chat.Tabs
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
Masking = true, Masking = true,
Child = new DelayedLoadWrapper(avatar = new Avatar(value.Users.First()) Child = new DelayedLoadWrapper(avatar = new DrawableAvatar(value.Users.First())
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
OpenOnClick = { Value = false }, OpenOnClick = { Value = false },

View File

@ -31,12 +31,13 @@ namespace osu.Game.Overlays
private ChannelManager channelManager; private ChannelManager channelManager;
private readonly Container<DrawableChannel> currentChannelContainer; private Container<DrawableChannel> currentChannelContainer;
private readonly List<DrawableChannel> loadedChannels = new List<DrawableChannel>(); private readonly List<DrawableChannel> loadedChannels = new List<DrawableChannel>();
private readonly LoadingAnimation loading; private LoadingAnimation loading;
private readonly FocusedTextBox textbox; private FocusedTextBox textbox;
private const int transition_length = 500; private const int transition_length = 500;
@ -44,17 +45,17 @@ namespace osu.Game.Overlays
public const float TAB_AREA_HEIGHT = 50; public const float TAB_AREA_HEIGHT = 50;
private readonly ChannelTabControl channelTabControl; private ChannelTabControl channelTabControl;
private readonly Container chatContainer; private Container chatContainer;
private readonly TabsArea tabsArea; private TabsArea tabsArea;
private readonly Box chatBackground; private Box chatBackground;
private readonly Box tabBackground; private Box tabBackground;
public Bindable<double> ChatHeight { get; set; } public Bindable<double> ChatHeight { get; set; }
private readonly Container channelSelectionContainer; private Container channelSelectionContainer;
private readonly ChannelSelectionOverlay channelSelectionOverlay; private ChannelSelectionOverlay channelSelectionOverlay;
public override bool Contains(Vector2 screenSpacePos) => chatContainer.ReceivePositionalInputAt(screenSpacePos) || (channelSelectionOverlay.State.Value == Visibility.Visible && channelSelectionOverlay.ReceivePositionalInputAt(screenSpacePos)); public override bool Contains(Vector2 screenSpacePos) => chatContainer.ReceivePositionalInputAt(screenSpacePos) || (channelSelectionOverlay.State.Value == Visibility.Visible && channelSelectionOverlay.ReceivePositionalInputAt(screenSpacePos));
@ -64,7 +65,11 @@ namespace osu.Game.Overlays
RelativePositionAxes = Axes.Both; RelativePositionAxes = Axes.Both;
Anchor = Anchor.BottomLeft; Anchor = Anchor.BottomLeft;
Origin = Anchor.BottomLeft; Origin = Anchor.BottomLeft;
}
[BackgroundDependencyLoader]
private void load(OsuConfigManager config, OsuColour colours, ChannelManager channelManager)
{
const float padding = 5; const float padding = 5;
Children = new Drawable[] Children = new Drawable[]
@ -154,7 +159,7 @@ namespace osu.Game.Overlays
Anchor = Anchor.BottomLeft, Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft, Origin = Anchor.BottomLeft,
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
OnRequestLeave = channel => channelManager.LeaveChannel(channel) OnRequestLeave = channelManager.LeaveChannel
}, },
} }
}, },
@ -186,9 +191,45 @@ namespace osu.Game.Overlays
}; };
channelSelectionOverlay.OnRequestJoin = channel => channelManager.JoinChannel(channel); channelSelectionOverlay.OnRequestJoin = channel => channelManager.JoinChannel(channel);
channelSelectionOverlay.OnRequestLeave = channel => channelManager.LeaveChannel(channel); channelSelectionOverlay.OnRequestLeave = channelManager.LeaveChannel;
ChatHeight = config.GetBindable<double>(OsuSetting.ChatDisplayHeight);
ChatHeight.ValueChanged += height =>
{
chatContainer.Height = (float)height.NewValue;
channelSelectionContainer.Height = 1f - (float)height.NewValue;
tabBackground.FadeTo(height.NewValue == 1 ? 1 : 0.8f, 200);
};
ChatHeight.TriggerChange();
chatBackground.Colour = colours.ChatBlue;
this.channelManager = channelManager;
loading.Show();
// This is a relatively expensive (and blocking) operation.
// Scheduling it ensures that it won't be performed unless the user decides to open chat.
// TODO: Refactor OsuFocusedOverlayContainer / OverlayContainer to support delayed content loading.
Schedule(() =>
{
// TODO: consider scheduling bindable callbacks to not perform when overlay is not present.
channelManager.JoinedChannels.ItemsAdded += onChannelAddedToJoinedChannels;
channelManager.JoinedChannels.ItemsRemoved += onChannelRemovedFromJoinedChannels;
foreach (Channel channel in channelManager.JoinedChannels)
channelTabControl.AddChannel(channel);
channelManager.AvailableChannels.ItemsAdded += availableChannelsChanged;
channelManager.AvailableChannels.ItemsRemoved += availableChannelsChanged;
channelSelectionOverlay.UpdateAvailableChannels(channelManager.AvailableChannels);
currentChannel = channelManager.CurrentChannel.GetBoundCopy();
currentChannel.BindValueChanged(currentChannelChanged, true);
});
} }
private Bindable<Channel> currentChannel;
private void currentChannelChanged(ValueChangedEvent<Channel> e) private void currentChannelChanged(ValueChangedEvent<Channel> e)
{ {
if (e.NewValue == null) if (e.NewValue == null)
@ -331,35 +372,6 @@ namespace osu.Game.Overlays
base.PopOut(); base.PopOut();
} }
[BackgroundDependencyLoader]
private void load(OsuConfigManager config, OsuColour colours, ChannelManager channelManager)
{
ChatHeight = config.GetBindable<double>(OsuSetting.ChatDisplayHeight);
ChatHeight.ValueChanged += height =>
{
chatContainer.Height = (float)height.NewValue;
channelSelectionContainer.Height = 1f - (float)height.NewValue;
tabBackground.FadeTo(height.NewValue == 1 ? 1 : 0.8f, 200);
};
ChatHeight.TriggerChange();
chatBackground.Colour = colours.ChatBlue;
loading.Show();
this.channelManager = channelManager;
channelManager.CurrentChannel.ValueChanged += currentChannelChanged;
channelManager.JoinedChannels.ItemsAdded += onChannelAddedToJoinedChannels;
channelManager.JoinedChannels.ItemsRemoved += onChannelRemovedFromJoinedChannels;
channelManager.AvailableChannels.ItemsAdded += availableChannelsChanged;
channelManager.AvailableChannels.ItemsRemoved += availableChannelsChanged;
//for the case that channelmanager was faster at fetching the channels than our attachment to CollectionChanged.
channelSelectionOverlay.UpdateAvailableChannels(channelManager.AvailableChannels);
foreach (Channel channel in channelManager.JoinedChannels)
channelTabControl.AddChannel(channel);
}
private void onChannelAddedToJoinedChannels(IEnumerable<Channel> channels) private void onChannelAddedToJoinedChannels(IEnumerable<Channel> channels)
{ {
foreach (Channel channel in channels) foreach (Channel channel in channels)

View File

@ -35,8 +35,6 @@ namespace osu.Game.Overlays
Width = width; Width = width;
RelativeSizeAxes = Axes.Y; RelativeSizeAxes = Axes.Y;
AlwaysPresent = true;
Children = new Drawable[] Children = new Drawable[]
{ {
new Box new Box
@ -100,9 +98,6 @@ namespace osu.Game.Overlays
OverlayActivationMode.BindValueChanged(_ => updateProcessingMode(), true); OverlayActivationMode.BindValueChanged(_ => updateProcessingMode(), true);
} }
private int totalCount => sections.Select(c => c.DisplayedCount).Sum();
private int unreadCount => sections.Select(c => c.UnreadCount).Sum();
public readonly BindableInt UnreadCount = new BindableInt(); public readonly BindableInt UnreadCount = new BindableInt();
private int runningDepth; private int runningDepth;
@ -111,6 +106,8 @@ namespace osu.Game.Overlays
private readonly Scheduler postScheduler = new Scheduler(); private readonly Scheduler postScheduler = new Scheduler();
public override bool IsPresent => base.IsPresent || postScheduler.HasPendingTasks;
private bool processingPosts = true; private bool processingPosts = true;
public void Post(Notification notification) => postScheduler.Add(() => public void Post(Notification notification) => postScheduler.Add(() =>
@ -160,7 +157,7 @@ namespace osu.Game.Overlays
private void updateCounts() private void updateCounts()
{ {
UnreadCount.Value = unreadCount; UnreadCount.Value = sections.Select(c => c.UnreadCount).Sum();
} }
private void markAllRead() private void markAllRead()

View File

@ -23,10 +23,16 @@ namespace osu.Game.Overlays.Notifications
public string CompletionText { get; set; } = "Task has completed!"; public string CompletionText { get; set; } = "Task has completed!";
private float progress;
public float Progress public float Progress
{ {
get => progressBar.Progress; get => progress;
set => Schedule(() => progressBar.Progress = value); set
{
progress = value;
Scheduler.AddOnce(() => progressBar.Progress = progress);
}
} }
protected override void LoadComplete() protected override void LoadComplete()
@ -34,59 +40,56 @@ namespace osu.Game.Overlays.Notifications
base.LoadComplete(); base.LoadComplete();
//we may have received changes before we were displayed. //we may have received changes before we were displayed.
State = state; updateState();
} }
private readonly CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); private readonly CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
public CancellationToken CancellationToken => cancellationTokenSource.Token; public CancellationToken CancellationToken => cancellationTokenSource.Token;
public virtual ProgressNotificationState State public ProgressNotificationState State
{ {
get => state; get => state;
set => set
Schedule(() => {
{ if (state == value) return;
bool stateChanged = state != value;
state = value;
if (IsLoaded) state = value;
{
switch (state)
{
case ProgressNotificationState.Queued:
Light.Colour = colourQueued;
Light.Pulsate = false;
progressBar.Active = false;
break;
case ProgressNotificationState.Active: if (IsLoaded)
Light.Colour = colourActive; Schedule(updateState);
Light.Pulsate = true; }
progressBar.Active = true; }
break;
case ProgressNotificationState.Cancelled: private void updateState()
cancellationTokenSource.Cancel(); {
switch (state)
{
case ProgressNotificationState.Queued:
Light.Colour = colourQueued;
Light.Pulsate = false;
progressBar.Active = false;
break;
Light.Colour = colourCancelled; case ProgressNotificationState.Active:
Light.Pulsate = false; Light.Colour = colourActive;
progressBar.Active = false; Light.Pulsate = true;
break; progressBar.Active = true;
} break;
}
if (stateChanged) case ProgressNotificationState.Cancelled:
{ cancellationTokenSource.Cancel();
switch (state)
{ Light.Colour = colourCancelled;
case ProgressNotificationState.Completed: Light.Pulsate = false;
NotificationContent.MoveToY(-DrawSize.Y / 2, 200, Easing.OutQuint); progressBar.Active = false;
this.FadeOut(200).Finally(d => Completed()); break;
break;
} case ProgressNotificationState.Completed:
} NotificationContent.MoveToY(-DrawSize.Y / 2, 200, Easing.OutQuint);
}); this.FadeOut(200).Finally(d => Completed());
break;
}
} }
private ProgressNotificationState state; private ProgressNotificationState state;

View File

@ -200,7 +200,7 @@ namespace osu.Game.Overlays.Profile.Header
Direction = FillDirection.Vertical, Direction = FillDirection.Vertical,
Children = new Drawable[] Children = new Drawable[]
{ {
new DrawableRank(rank) new UpdateableRank(rank)
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Height = 30, Height = 30,

View File

@ -12,6 +12,7 @@ using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays.Profile.Header.Components; using osu.Game.Overlays.Profile.Header.Components;
using osu.Game.Users; using osu.Game.Users;
using osu.Game.Users.Drawables;
using osuTK; using osuTK;
namespace osu.Game.Overlays.Profile.Header namespace osu.Game.Overlays.Profile.Header
@ -27,7 +28,7 @@ namespace osu.Game.Overlays.Profile.Header
private OsuSpriteText usernameText; private OsuSpriteText usernameText;
private ExternalLinkButton openUserExternally; private ExternalLinkButton openUserExternally;
private OsuSpriteText titleText; private OsuSpriteText titleText;
private DrawableFlag userFlag; private UpdateableFlag userFlag;
private OsuSpriteText userCountryText; private OsuSpriteText userCountryText;
private FillFlowContainer userStats; private FillFlowContainer userStats;
@ -51,7 +52,7 @@ namespace osu.Game.Overlays.Profile.Header
AutoSizeAxes = Axes.X, AutoSizeAxes = Axes.X,
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
Children = new[] Children = new Drawable[]
{ {
avatar = new UpdateableAvatar avatar = new UpdateableAvatar
{ {
@ -59,6 +60,7 @@ namespace osu.Game.Overlays.Profile.Header
Masking = true, Masking = true,
CornerRadius = avatar_size * 0.25f, CornerRadius = avatar_size * 0.25f,
OpenOnClick = { Value = false }, OpenOnClick = { Value = false },
ShowGuestOnNull = false,
}, },
new Container new Container
{ {
@ -115,9 +117,10 @@ namespace osu.Game.Overlays.Profile.Header
Margin = new MarginPadding { Top = 5 }, Margin = new MarginPadding { Top = 5 },
Children = new Drawable[] Children = new Drawable[]
{ {
userFlag = new DrawableFlag userFlag = new UpdateableFlag
{ {
Size = new Vector2(30, 20) Size = new Vector2(30, 20),
ShowPlaceholderOnNull = false,
}, },
userCountryText = new OsuSpriteText userCountryText = new OsuSpriteText
{ {

View File

@ -59,7 +59,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
modsContainer.Add(new ModIcon(mod) { Scale = new Vector2(0.5f) }); modsContainer.Add(new ModIcon(mod) { Scale = new Vector2(0.5f) });
} }
protected override Drawable CreateLeftVisual() => new DrawableRank(Score.Rank) protected override Drawable CreateLeftVisual() => new UpdateableRank(Score.Rank)
{ {
RelativeSizeAxes = Axes.Y, RelativeSizeAxes = Axes.Y,
Width = 60, Width = 60,

View File

@ -58,7 +58,7 @@ namespace osu.Game.Overlays.Profile.Sections.Recent
switch (activity.Type) switch (activity.Type)
{ {
case RecentActivityType.Rank: case RecentActivityType.Rank:
return new DrawableRank(activity.ScoreRank) return new UpdateableRank(activity.ScoreRank)
{ {
RelativeSizeAxes = Axes.Y, RelativeSizeAxes = Axes.Y,
Width = 60, Width = 60,

View File

@ -8,6 +8,7 @@ using osu.Framework.Graphics.Effects;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Users; using osu.Game.Users;
using osu.Game.Users.Drawables;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;

View File

@ -8,7 +8,7 @@ using osu.Framework.Graphics.Containers;
using osu.Game.Graphics; 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 osu.Game.Users; using osu.Game.Users.Drawables;
using osuTK; using osuTK;
namespace osu.Game.Screens.Multi.Lounge.Components namespace osu.Game.Screens.Multi.Lounge.Components
@ -79,7 +79,7 @@ namespace osu.Game.Screens.Multi.Lounge.Components
hostText.AddText("hosted by "); hostText.AddText("hosted by ");
hostText.AddUserLink(host.NewValue, s => s.Font = s.Font.With(Typeface.Exo, weight: FontWeight.Bold, italics: true)); hostText.AddUserLink(host.NewValue, s => s.Font = s.Font.With(Typeface.Exo, weight: FontWeight.Bold, italics: true));
flagContainer.Child = new DrawableFlag(host.NewValue.Country) { RelativeSizeAxes = Axes.Both }; flagContainer.Child = new UpdateableFlag(host.NewValue.Country) { RelativeSizeAxes = Axes.Both };
} }
}, true); }, true);

View File

@ -19,6 +19,7 @@ using osu.Game.Online.API.Requests;
using osu.Game.Online.Multiplayer; using osu.Game.Online.Multiplayer;
using osu.Game.Screens.Multi.Components; using osu.Game.Screens.Multi.Components;
using osu.Game.Users; using osu.Game.Users;
using osu.Game.Users.Drawables;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;

View File

@ -7,6 +7,7 @@ using osu.Framework.Graphics.Containers;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Users; using osu.Game.Users;
using osu.Game.Users.Drawables;
using osuTK; using osuTK;
namespace osu.Game.Screens.Multi.Match.Components namespace osu.Game.Screens.Multi.Match.Components

View File

@ -74,7 +74,7 @@ namespace osu.Game.Screens.Ranking.Pages
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Height = user_header_height, Height = user_header_height,
}, },
new DrawableRank(Score.Rank) new UpdateableRank(Score.Rank)
{ {
Anchor = Anchor.TopCentre, Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre, Origin = Anchor.TopCentre,

View File

@ -143,10 +143,10 @@ namespace osu.Game.Screens.Select.Carousel
Origin = Anchor.Centre, Origin = Anchor.Centre,
FillMode = FillMode.Fill, FillMode = FillMode.Fill,
}, },
new FillFlowContainer // Todo: This should be a fill flow, but has invalidation issues (see https://github.com/ppy/osu-framework/issues/223)
new Container
{ {
Depth = -1, Depth = -1,
Direction = FillDirection.Horizontal,
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
// This makes the gradient not be perfectly horizontal, but diagonal at a ~40° angle // This makes the gradient not be perfectly horizontal, but diagonal at a ~40° angle
Shear = new Vector2(0.8f, 0), Shear = new Vector2(0.8f, 0),
@ -157,6 +157,7 @@ namespace osu.Game.Screens.Select.Carousel
new Box new Box
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
RelativePositionAxes = Axes.Both,
Colour = Color4.Black, Colour = Color4.Black,
Width = 0.4f, Width = 0.4f,
}, },
@ -164,20 +165,26 @@ namespace osu.Game.Screens.Select.Carousel
new Box new Box
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
RelativePositionAxes = Axes.Both,
Colour = ColourInfo.GradientHorizontal(Color4.Black, new Color4(0f, 0f, 0f, 0.9f)), Colour = ColourInfo.GradientHorizontal(Color4.Black, new Color4(0f, 0f, 0f, 0.9f)),
Width = 0.05f, Width = 0.05f,
X = 0.4f,
}, },
new Box new Box
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
RelativePositionAxes = Axes.Both,
Colour = ColourInfo.GradientHorizontal(new Color4(0f, 0f, 0f, 0.9f), new Color4(0f, 0f, 0f, 0.1f)), Colour = ColourInfo.GradientHorizontal(new Color4(0f, 0f, 0f, 0.9f), new Color4(0f, 0f, 0f, 0.1f)),
Width = 0.2f, Width = 0.2f,
X = 0.45f,
}, },
new Box new Box
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
RelativePositionAxes = Axes.Both,
Colour = ColourInfo.GradientHorizontal(new Color4(0f, 0f, 0f, 0.1f), new Color4(0, 0, 0, 0)), Colour = ColourInfo.GradientHorizontal(new Color4(0f, 0f, 0f, 0.1f), new Color4(0, 0, 0, 0)),
Width = 0.05f, Width = 0.05f,
X = 0.65f,
}, },
} }
}, },

View File

@ -1,14 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using Newtonsoft.Json; using Newtonsoft.Json;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
namespace osu.Game.Users namespace osu.Game.Users
{ {
@ -26,54 +19,4 @@ namespace osu.Game.Users
[JsonProperty(@"code")] [JsonProperty(@"code")]
public string FlagName; public string FlagName;
} }
public class DrawableFlag : Container, IHasTooltip
{
private readonly Sprite sprite;
private TextureStore textures;
private Country country;
public Country Country
{
get => country;
set
{
if (value == country)
return;
country = value;
if (LoadState >= LoadState.Ready)
sprite.Texture = getFlagTexture();
}
}
public string TooltipText => country?.FullName;
public DrawableFlag(Country country = null)
{
this.country = country;
Children = new Drawable[]
{
sprite = new Sprite
{
RelativeSizeAxes = Axes.Both,
},
};
}
[BackgroundDependencyLoader]
private void load(TextureStore ts)
{
if (ts == null)
throw new ArgumentNullException(nameof(ts));
textures = ts;
sprite.Texture = getFlagTexture();
}
private Texture getFlagTexture() => textures.Get($@"Flags/{country?.FlagName ?? @"__"}");
}
} }

View File

@ -11,9 +11,9 @@ using osu.Framework.Graphics.Textures;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
namespace osu.Game.Users namespace osu.Game.Users.Drawables
{ {
public class Avatar : Container public class DrawableAvatar : Container
{ {
/// <summary> /// <summary>
/// Whether to open the user's profile when clicked. /// Whether to open the user's profile when clicked.
@ -29,7 +29,7 @@ namespace osu.Game.Users
/// An avatar for specified user. /// An avatar for specified user.
/// </summary> /// </summary>
/// <param name="user">The user. A null value will get a placeholder avatar.</param> /// <param name="user">The user. A null value will get a placeholder avatar.</param>
public Avatar(User user = null) public DrawableAvatar(User user = null)
{ {
this.user = user; this.user = user;
} }

View File

@ -0,0 +1,32 @@
// 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 System;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
namespace osu.Game.Users.Drawables
{
public class DrawableFlag : Sprite, IHasTooltip
{
private readonly Country country;
public string TooltipText => country?.FullName;
public DrawableFlag(Country country)
{
this.country = country;
}
[BackgroundDependencyLoader]
private void load(TextureStore ts)
{
if (ts == null)
throw new ArgumentNullException(nameof(ts));
Texture = ts.Get($@"Flags/{country?.FlagName ?? @"__"}");
}
}
}

View File

@ -0,0 +1,71 @@
// 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.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Effects;
namespace osu.Game.Users.Drawables
{
/// <summary>
/// An avatar which can update to a new user when needed.
/// </summary>
public class UpdateableAvatar : ModelBackedDrawable<User>
{
public User User
{
get => Model;
set => Model = value;
}
public new bool Masking
{
get => base.Masking;
set => base.Masking = value;
}
public new float CornerRadius
{
get => base.CornerRadius;
set => base.CornerRadius = value;
}
public new EdgeEffectParameters EdgeEffect
{
get => base.EdgeEffect;
set => base.EdgeEffect = value;
}
/// <summary>
/// Whether to show a default guest representation on null user (as opposed to nothing).
/// </summary>
public bool ShowGuestOnNull = true;
/// <summary>
/// Whether to open the user's profile when clicked.
/// </summary>
public readonly BindableBool OpenOnClick = new BindableBool(true);
public UpdateableAvatar(User user = null)
{
User = user;
}
protected override Drawable CreateDrawable(User user)
{
if (user == null && !ShowGuestOnNull)
return null;
var avatar = new DrawableAvatar(user)
{
RelativeSizeAxes = Axes.Both,
};
avatar.OnLoadComplete += d => d.FadeInFromZero(300, Easing.OutQuint);
avatar.OpenOnClick.BindTo(OpenOnClick);
return avatar;
}
}
}

View File

@ -0,0 +1,38 @@
// 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.Graphics;
using osu.Framework.Graphics.Containers;
namespace osu.Game.Users.Drawables
{
public class UpdateableFlag : ModelBackedDrawable<Country>
{
public Country Country
{
get => Model;
set => Model = value;
}
/// <summary>
/// Whether to show a place holder on null country.
/// </summary>
public bool ShowPlaceholderOnNull = true;
public UpdateableFlag(Country country = null)
{
Country = country;
}
protected override Drawable CreateDrawable(Country country)
{
if (country == null && !ShowPlaceholderOnNull)
return null;
return new DrawableFlag(country)
{
RelativeSizeAxes = Axes.Both,
};
}
}
}

View File

@ -1,69 +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.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
namespace osu.Game.Users
{
/// <summary>
/// An avatar which can update to a new user when needed.
/// </summary>
public class UpdateableAvatar : Container
{
private Drawable displayedAvatar;
private User user;
/// <summary>
/// Whether to show a default guest representation on null user (as opposed to nothing).
/// </summary>
public bool ShowGuestOnNull = true;
public User User
{
get => user;
set
{
if (user?.Id == value?.Id)
return;
user = value;
if (IsLoaded)
updateAvatar();
}
}
/// <summary>
/// Whether to open the user's profile when clicked.
/// </summary>
public readonly BindableBool OpenOnClick = new BindableBool(true);
protected override void LoadComplete()
{
base.LoadComplete();
updateAvatar();
}
private void updateAvatar()
{
displayedAvatar?.FadeOut(300);
displayedAvatar?.Expire();
if (user != null || ShowGuestOnNull)
{
var avatar = new Avatar(user)
{
RelativeSizeAxes = Axes.Both,
};
avatar.OnLoadComplete += d => d.FadeInFromZero(300, Easing.OutQuint);
avatar.OpenOnClick.BindTo(OpenOnClick);
Add(displayedAvatar = new DelayedLoadWrapper(avatar));
}
}
}
}

View File

@ -20,6 +20,7 @@ using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Overlays.Profile.Header.Components; using osu.Game.Overlays.Profile.Header.Components;
using osu.Game.Users.Drawables;
namespace osu.Game.Users namespace osu.Game.Users
{ {
@ -137,7 +138,7 @@ namespace osu.Game.Users
Spacing = new Vector2(5f, 0f), Spacing = new Vector2(5f, 0f),
Children = new Drawable[] Children = new Drawable[]
{ {
new DrawableFlag(user.Country) new UpdateableFlag(user.Country)
{ {
Width = 30f, Width = 30f,
RelativeSizeAxes = Axes.Y, RelativeSizeAxes = Axes.Y,