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.
|
|
|
|
|
|
2022-12-31 01:44:03 +08:00
|
|
|
|
using System.Linq;
|
2022-12-31 02:12:50 +08:00
|
|
|
|
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;
|
2022-12-31 01:44:03 +08:00
|
|
|
|
using osu.Game.Extensions;
|
2019-06-04 21:22:54 +08:00
|
|
|
|
using osu.Game.Rulesets;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Profile.Header.Components
|
|
|
|
|
{
|
2020-01-02 03:55:28 +08:00
|
|
|
|
public partial class ProfileRulesetSelector : OverlayRulesetSelector
|
2019-06-04 21:22:54 +08:00
|
|
|
|
{
|
2022-12-31 02:12:50 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
private UserProfileOverlay? profileOverlay { get; set; }
|
|
|
|
|
|
2023-01-12 02:11:40 +08:00
|
|
|
|
public readonly Bindable<UserProfileData?> User = new Bindable<UserProfileData?>();
|
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();
|
2022-12-31 01:03:44 +08:00
|
|
|
|
|
2023-01-12 02:11:40 +08:00
|
|
|
|
User.BindValueChanged(user => updateState(user.NewValue), true);
|
2022-12-31 02:12:50 +08:00
|
|
|
|
Current.BindValueChanged(ruleset =>
|
|
|
|
|
{
|
2023-01-12 02:11:40 +08:00
|
|
|
|
if (User.Value != null && !ruleset.NewValue.Equals(User.Value.Ruleset))
|
|
|
|
|
profileOverlay?.ShowUser(User.Value.User, ruleset.NewValue);
|
2022-12-31 02:12:50 +08:00
|
|
|
|
});
|
2022-12-31 01:03:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-12 02:11:40 +08:00
|
|
|
|
private void updateState(UserProfileData? user)
|
2022-12-31 01:03:44 +08:00
|
|
|
|
{
|
2023-01-12 02:11:40 +08:00
|
|
|
|
Current.Value = Items.SingleOrDefault(ruleset => user?.Ruleset.MatchesOnlineID(ruleset) == true);
|
|
|
|
|
SetDefaultRuleset(Rulesets.GetRuleset(user?.User.PlayMode ?? @"osu").AsNonNull());
|
2019-08-04 19:15:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetDefaultRuleset(RulesetInfo ruleset)
|
2019-06-04 23:37:31 +08:00
|
|
|
|
{
|
2020-01-02 03:55:28 +08:00
|
|
|
|
foreach (var tabItem in TabContainer)
|
2021-11-24 11:49:57 +08:00
|
|
|
|
((ProfileRulesetTabItem)tabItem).IsDefault = ((ProfileRulesetTabItem)tabItem).Value.Equals(ruleset);
|
2019-06-04 21:22:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-02 03:55:28 +08:00
|
|
|
|
protected override TabItem<RulesetInfo> CreateTabItem(RulesetInfo value) => new ProfileRulesetTabItem(value);
|
2019-06-04 21:22:54 +08:00
|
|
|
|
}
|
|
|
|
|
}
|