1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-08 17:37:46 +08:00
osu-lazer/osu.Game/Overlays/Profile/Header/Components/ProfileRulesetSelector.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

48 lines
1.8 KiB
C#
Raw Normal View History

2019-06-04 21:22:54 +08:00
// 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.Linq;
using osu.Framework.Allocation;
2019-08-04 19:15:16 +08:00
using osu.Framework.Bindables;
2022-12-30 20:17:59 +08:00
using osu.Framework.Extensions.ObjectExtensions;
2019-06-04 21:22:54 +08:00
using osu.Framework.Graphics.UserInterface;
using osu.Game.Extensions;
2019-06-04 21:22:54 +08:00
using osu.Game.Rulesets;
namespace osu.Game.Overlays.Profile.Header.Components
{
public partial class ProfileRulesetSelector : OverlayRulesetSelector
2019-06-04 21:22:54 +08:00
{
[Resolved]
private UserProfileOverlay? profileOverlay { get; set; }
public readonly Bindable<UserProfile?> UserProfile = new Bindable<UserProfile?>();
2019-08-04 19:15:16 +08:00
protected override void LoadComplete()
2019-06-04 22:51:56 +08:00
{
2019-08-04 19:15:16 +08:00
base.LoadComplete();
UserProfile.BindValueChanged(userProfile => updateState(userProfile.NewValue), true);
Current.BindValueChanged(ruleset =>
{
if (UserProfile.Value != null && !ruleset.NewValue.Equals(UserProfile.Value.Ruleset))
profileOverlay?.ShowUser(UserProfile.Value.User, ruleset.NewValue);
});
}
private void updateState(UserProfile? userProfile)
{
Current.Value = Items.SingleOrDefault(ruleset => userProfile?.Ruleset.MatchesOnlineID(ruleset) == true);
SetDefaultRuleset(Rulesets.GetRuleset(userProfile?.User.PlayMode ?? @"osu").AsNonNull());
2019-08-04 19:15:16 +08:00
}
public void SetDefaultRuleset(RulesetInfo ruleset)
{
foreach (var tabItem in TabContainer)
((ProfileRulesetTabItem)tabItem).IsDefault = ((ProfileRulesetTabItem)tabItem).Value.Equals(ruleset);
2019-06-04 21:22:54 +08:00
}
protected override TabItem<RulesetInfo> CreateTabItem(RulesetInfo value) => new ProfileRulesetTabItem(value);
2019-06-04 21:22:54 +08:00
}
}