1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-16 07:03:21 +08:00

Make ProfileRulesetSelector inherit from OverlayRulesetSelector

This commit is contained in:
Andrei Zavatski 2020-01-01 22:55:28 +03:00
parent af248457b0
commit b016238c16
3 changed files with 20 additions and 112 deletions

View File

@ -25,7 +25,7 @@ namespace osu.Game.Tests.Visual.Online
public TestSceneProfileRulesetSelector() public TestSceneProfileRulesetSelector()
{ {
ProfileRulesetSelector selector; ProfileRulesetSelector selector;
Bindable<User> user = new Bindable<User>(); var user = new Bindable<User>();
Child = selector = new ProfileRulesetSelector Child = selector = new ProfileRulesetSelector
{ {

View File

@ -3,37 +3,21 @@
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Users; using osu.Game.Users;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Overlays.Profile.Header.Components namespace osu.Game.Overlays.Profile.Header.Components
{ {
public class ProfileRulesetSelector : RulesetSelector public class ProfileRulesetSelector : OverlayRulesetSelector
{ {
private Color4 accentColour = Color4.White;
public readonly Bindable<User> User = new Bindable<User>(); public readonly Bindable<User> User = new Bindable<User>();
public ProfileRulesetSelector()
{
TabContainer.Masking = false;
TabContainer.Spacing = new Vector2(10, 0);
AutoSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OsuColour colours)
{ {
accentColour = colours.Seafoam; AccentColour = colours.Seafoam;
foreach (TabItem<RulesetInfo> tabItem in TabContainer)
((ProfileRulesetTabItem)tabItem).AccentColour = accentColour;
} }
protected override void LoadComplete() protected override void LoadComplete()
@ -45,19 +29,10 @@ namespace osu.Game.Overlays.Profile.Header.Components
public void SetDefaultRuleset(RulesetInfo ruleset) public void SetDefaultRuleset(RulesetInfo ruleset)
{ {
foreach (TabItem<RulesetInfo> tabItem in TabContainer) foreach (var tabItem in TabContainer)
((ProfileRulesetTabItem)tabItem).IsDefault = ((ProfileRulesetTabItem)tabItem).Value.ID == ruleset.ID; ((ProfileRulesetTabItem)tabItem).IsDefault = ((ProfileRulesetTabItem)tabItem).Value.ID == ruleset.ID;
} }
protected override TabItem<RulesetInfo> CreateTabItem(RulesetInfo value) => new ProfileRulesetTabItem(value) protected override TabItem<RulesetInfo> CreateTabItem(RulesetInfo value) => new ProfileRulesetTabItem(value);
{
AccentColour = accentColour
};
protected override TabFillFlowContainer CreateTabFlow() => new TabFillFlowContainer
{
Direction = FillDirection.Horizontal,
AutoSizeAxes = Axes.Both,
};
} }
} }

View File

@ -2,38 +2,21 @@
// 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 osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites; 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 osu.Game.Rulesets;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
namespace osu.Game.Overlays.Profile.Header.Components namespace osu.Game.Overlays.Profile.Header.Components
{ {
public class ProfileRulesetTabItem : TabItem<RulesetInfo>, IHasAccentColour public class ProfileRulesetTabItem : OverlayRulesetTabItem
{ {
private readonly OsuSpriteText text;
private readonly SpriteIcon icon; private readonly SpriteIcon icon;
private Color4 accentColour; public new Color4 AccentColour
public Color4 AccentColour
{ {
get => accentColour; get => base.AccentColour;
set set => base.AccentColour = icon.Colour = value;
{
if (accentColour == value)
return;
accentColour = value;
updateState();
}
} }
private bool isDefault; private bool isDefault;
@ -55,26 +38,7 @@ namespace osu.Game.Overlays.Profile.Header.Components
public ProfileRulesetTabItem(RulesetInfo value) public ProfileRulesetTabItem(RulesetInfo value)
: base(value) : base(value)
{ {
AutoSizeAxes = Axes.Both; Add(icon = new SpriteIcon
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, Origin = Anchor.Centre,
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
@ -82,44 +46,13 @@ namespace osu.Game.Overlays.Profile.Header.Components
AlwaysPresent = true, AlwaysPresent = true,
Icon = FontAwesome.Solid.Star, Icon = FontAwesome.Solid.Star,
Size = new Vector2(12), Size = new Vector2(12),
}, });
}
},
new HoverClickSounds()
};
} }
protected override bool OnHover(HoverEvent e) protected override void UpdateState()
{ {
base.OnHover(e); base.UpdateState();
updateState(); icon.FadeColour(GetColour(), 120, Easing.OutQuint);
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);
}
} }
} }
} }