mirror of
https://github.com/osukey/osukey.git
synced 2025-06-30 07:38:04 +09:00
Merge pull request #4910 from EVAST9919/user_profile_modes
Implement Ruleset Selector component for profile overlay
This commit is contained in:
commit
7762b67ecb
@ -0,0 +1,40 @@
|
|||||||
|
// 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.Game.Overlays.Profile.Header.Components;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using osu.Game.Rulesets.Catch;
|
||||||
|
using osu.Game.Rulesets.Mania;
|
||||||
|
using osu.Game.Rulesets.Osu;
|
||||||
|
using osu.Game.Rulesets.Taiko;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Visual.Online
|
||||||
|
{
|
||||||
|
public class TestSceneProfileRulesetSelector : OsuTestScene
|
||||||
|
{
|
||||||
|
public override IReadOnlyList<Type> RequiredTypes => new[]
|
||||||
|
{
|
||||||
|
typeof(ProfileRulesetSelector),
|
||||||
|
typeof(ProfileRulesetTabItem),
|
||||||
|
};
|
||||||
|
|
||||||
|
public TestSceneProfileRulesetSelector()
|
||||||
|
{
|
||||||
|
ProfileRulesetSelector selector;
|
||||||
|
|
||||||
|
Child = selector = new ProfileRulesetSelector
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
};
|
||||||
|
|
||||||
|
AddStep("set osu! as default", () => selector.SetDefaultRuleset(new OsuRuleset().RulesetInfo));
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,66 @@
|
|||||||
|
// 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.Allocation;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.UserInterface;
|
||||||
|
using osu.Game.Graphics;
|
||||||
|
using osu.Game.Rulesets;
|
||||||
|
using osuTK;
|
||||||
|
using osuTK.Graphics;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.Profile.Header.Components
|
||||||
|
{
|
||||||
|
public class ProfileRulesetSelector : RulesetSelector
|
||||||
|
{
|
||||||
|
private Color4 accentColour = Color4.White;
|
||||||
|
|
||||||
|
public ProfileRulesetSelector()
|
||||||
|
{
|
||||||
|
TabContainer.Masking = false;
|
||||||
|
TabContainer.Spacing = new Vector2(10, 0);
|
||||||
|
AutoSizeAxes = Axes.Both;
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(OsuColour colours)
|
||||||
|
{
|
||||||
|
accentColour = colours.Seafoam;
|
||||||
|
|
||||||
|
foreach (TabItem<RulesetInfo> tabItem in TabContainer)
|
||||||
|
((ProfileRulesetTabItem)tabItem).AccentColour = accentColour;
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
((ProfileRulesetTabItem)tabItem).IsDefault = ((ProfileRulesetTabItem)tabItem).Value.ID == ruleset.ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SelectDefaultRuleset()
|
||||||
|
{
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override TabItem<RulesetInfo> CreateTabItem(RulesetInfo value) => new ProfileRulesetTabItem(value)
|
||||||
|
{
|
||||||
|
AccentColour = accentColour
|
||||||
|
};
|
||||||
|
|
||||||
|
protected override TabFillFlowContainer CreateTabFlow() => new TabFillFlowContainer
|
||||||
|
{
|
||||||
|
Direction = FillDirection.Horizontal,
|
||||||
|
AutoSizeAxes = Axes.Both,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,125 @@
|
|||||||
|
// 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.Framework.Graphics.Sprites;
|
||||||
|
using osu.Framework.Graphics.UserInterface;
|
||||||
|
using osu.Framework.Input.Events;
|
||||||
|
using osu.Game.Graphics;
|
||||||
|
using osu.Game.Graphics.Sprites;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
using osu.Game.Rulesets;
|
||||||
|
using osuTK;
|
||||||
|
using osuTK.Graphics;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.Profile.Header.Components
|
||||||
|
{
|
||||||
|
public class ProfileRulesetTabItem : TabItem<RulesetInfo>, IHasAccentColour
|
||||||
|
{
|
||||||
|
private readonly OsuSpriteText text;
|
||||||
|
private readonly SpriteIcon icon;
|
||||||
|
|
||||||
|
private Color4 accentColour;
|
||||||
|
|
||||||
|
public Color4 AccentColour
|
||||||
|
{
|
||||||
|
get => accentColour;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (accentColour == value)
|
||||||
|
return;
|
||||||
|
|
||||||
|
accentColour = value;
|
||||||
|
|
||||||
|
updateState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool isDefault;
|
||||||
|
|
||||||
|
public bool IsDefault
|
||||||
|
{
|
||||||
|
get => isDefault;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (isDefault == value)
|
||||||
|
return;
|
||||||
|
|
||||||
|
isDefault = value;
|
||||||
|
|
||||||
|
icon.FadeTo(isDefault ? 1 : 0, 200, Easing.OutQuint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProfileRulesetTabItem(RulesetInfo value)
|
||||||
|
: base(value)
|
||||||
|
{
|
||||||
|
AutoSizeAxes = Axes.Both;
|
||||||
|
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new FillFlowContainer
|
||||||
|
{
|
||||||
|
AutoSizeAxes = Axes.Both,
|
||||||
|
Origin = Anchor.BottomLeft,
|
||||||
|
Anchor = Anchor.BottomLeft,
|
||||||
|
Direction = FillDirection.Horizontal,
|
||||||
|
Spacing = new Vector2(3, 0),
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
text = new OsuSpriteText
|
||||||
|
{
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Text = value.Name,
|
||||||
|
},
|
||||||
|
icon = new SpriteIcon
|
||||||
|
{
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Alpha = 0,
|
||||||
|
AlwaysPresent = true,
|
||||||
|
Icon = FontAwesome.Solid.Star,
|
||||||
|
Size = new Vector2(12),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new HoverClickSounds()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool OnHover(HoverEvent e)
|
||||||
|
{
|
||||||
|
base.OnHover(e);
|
||||||
|
updateState();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnHoverLost(HoverLostEvent e)
|
||||||
|
{
|
||||||
|
base.OnHoverLost(e);
|
||||||
|
updateState();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnActivated() => updateState();
|
||||||
|
|
||||||
|
protected override void OnDeactivated() => updateState();
|
||||||
|
|
||||||
|
private void updateState()
|
||||||
|
{
|
||||||
|
text.Font = text.Font.With(weight: Active.Value ? FontWeight.Bold : FontWeight.Medium);
|
||||||
|
|
||||||
|
if (IsHovered || Active.Value)
|
||||||
|
{
|
||||||
|
text.FadeColour(Color4.White, 120, Easing.InQuad);
|
||||||
|
icon.FadeColour(Color4.White, 120, Easing.InQuad);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
text.FadeColour(AccentColour, 120, Easing.InQuad);
|
||||||
|
icon.FadeColour(AccentColour, 120, Easing.InQuad);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -32,7 +32,8 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
public void ShowUser(User user, bool fetchOnline = true)
|
public void ShowUser(User user, bool fetchOnline = true)
|
||||||
{
|
{
|
||||||
if (user == User.SYSTEM_USER) return;
|
if (user == User.SYSTEM_USER)
|
||||||
|
return;
|
||||||
|
|
||||||
Show();
|
Show();
|
||||||
|
|
||||||
@ -76,7 +77,7 @@ namespace osu.Game.Overlays
|
|||||||
{
|
{
|
||||||
Colour = OsuColour.Gray(34),
|
Colour = OsuColour.Gray(34),
|
||||||
RelativeSizeAxes = Axes.Both
|
RelativeSizeAxes = Axes.Both
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
sectionsContainer.SelectedSection.ValueChanged += section =>
|
sectionsContainer.SelectedSection.ValueChanged += section =>
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user