ProfileRulesetSelector improvements

This commit is contained in:
Andrei Zavatski 2019-08-04 14:15:16 +03:00
parent 8fde92c595
commit 3ae5428dad
2 changed files with 22 additions and 14 deletions

View File

@ -9,6 +9,7 @@
using osu.Game.Rulesets.Mania;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Taiko;
using osu.Game.Users;
namespace osu.Game.Tests.Visual.Online
{
@ -34,7 +35,12 @@ public TestSceneProfileRulesetSelector()
AddStep("set mania as default", () => selector.SetDefaultRuleset(new ManiaRuleset().RulesetInfo));
AddStep("set taiko as default", () => selector.SetDefaultRuleset(new TaikoRuleset().RulesetInfo));
AddStep("set catch as default", () => selector.SetDefaultRuleset(new CatchRuleset().RulesetInfo));
AddStep("select default ruleset", selector.SelectDefaultRuleset);
AddStep("User with osu as default", () => selector.User.Value = new User { PlayMode = "osu" });
AddStep("User with mania as default", () => selector.User.Value = new User { PlayMode = "mania" });
AddStep("User with taiko as default", () => selector.User.Value = new User { PlayMode = "taiko" });
AddStep("User with catch as default", () => selector.User.Value = new User { PlayMode = "fruits" });
AddStep("null user", () => selector.User.Value = null);
}
}
}

View File

@ -2,11 +2,13 @@
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics;
using osu.Game.Rulesets;
using osu.Game.Users;
using osuTK;
using osuTK.Graphics;
@ -16,6 +18,8 @@ public class ProfileRulesetSelector : RulesetSelector
{
private Color4 accentColour = Color4.White;
public readonly Bindable<User> User = new Bindable<User>();
public ProfileRulesetSelector()
{
TabContainer.Masking = false;
@ -32,24 +36,22 @@ private void load(OsuColour colours)
((ProfileRulesetTabItem)tabItem).AccentColour = accentColour;
}
public void SetDefaultRuleset(RulesetInfo ruleset)
protected override void LoadComplete()
{
// Todo: This method shouldn't exist, but bindables don't provide the concept of observing a change to the default value
foreach (TabItem<RulesetInfo> tabItem in TabContainer)
((ProfileRulesetTabItem)tabItem).IsDefault = ((ProfileRulesetTabItem)tabItem).Value.ID == ruleset.ID;
base.LoadComplete();
User.BindValueChanged(onUserChanged, true);
}
public void SelectDefaultRuleset()
private void onUserChanged(ValueChangedEvent<User> user)
{
SetDefaultRuleset(Rulesets.GetRuleset(user.NewValue?.PlayMode ?? "osu"));
}
public void SetDefaultRuleset(RulesetInfo ruleset)
{
// Todo: This method shouldn't exist, but bindables don't provide the concept of observing a change to the default value
foreach (TabItem<RulesetInfo> tabItem in TabContainer)
{
if (((ProfileRulesetTabItem)tabItem).IsDefault)
{
Current.Value = ((ProfileRulesetTabItem)tabItem).Value;
return;
}
}
((ProfileRulesetTabItem)tabItem).IsDefault = ((ProfileRulesetTabItem)tabItem).Value.ID == ruleset.ID;
}
protected override TabItem<RulesetInfo> CreateTabItem(RulesetInfo value) => new ProfileRulesetTabItem(value)