retrieve user's default playmode

This commit is contained in:
EVAST9919 2019-06-04 17:51:56 +03:00
parent 0abb48882c
commit a0f7f69f46
2 changed files with 69 additions and 7 deletions

View File

@ -4,6 +4,7 @@
using osu.Framework.Allocation;
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;
@ -46,7 +47,7 @@ public Color4 AccentColour
public GamemodeControl()
{
TabContainer.Masking = false;
TabContainer.Spacing = new Vector2(15, 0);
TabContainer.Spacing = new Vector2(10, 0);
AutoSizeAxes = Axes.Both;
}
@ -54,7 +55,20 @@ public GamemodeControl()
private void load(RulesetStore rulesets)
{
foreach (var r in rulesets.AvailableRulesets)
AddItem(r.Name);
AddItem(r.ShortName);
//AddItem(r.Name);
}
public void SetDefaultGamemode(string gamemode)
{
foreach (GamemodeTabItem i in TabContainer)
{
if (i.Value == gamemode)
{
i.IsDefault = true;
return;
}
}
}
protected override TabFillFlowContainer CreateTabFlow() => new TabFillFlowContainer
@ -66,6 +80,7 @@ private void load(RulesetStore rulesets)
private class GamemodeTabItem : TabItem<string>
{
private readonly OsuSpriteText text;
private readonly SpriteIcon icon;
private Color4 accentColour;
@ -83,6 +98,22 @@ public Color4 AccentColour
}
}
private bool isDefault;
public bool IsDefault
{
get => isDefault;
set
{
if (isDefault == value)
return;
isDefault = value;
icon.FadeTo(isDefault ? 1 : 0, 100, Easing.OutQuint);
}
}
public GamemodeTabItem(string value)
: base(value)
{
@ -90,13 +121,32 @@ public GamemodeTabItem(string value)
Children = new Drawable[]
{
text = new OsuSpriteText
new FillFlowContainer
{
Margin = new MarginPadding { Bottom = 10 },
AutoSizeAxes = Axes.Both,
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
Text = value,
Font = OsuFont.GetFont()
Direction = FillDirection.Horizontal,
Spacing = new Vector2(3, 0),
Children = new Drawable[]
{
text = new OsuSpriteText
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Text = value,
Font = OsuFont.GetFont()
},
icon = new SpriteIcon
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Alpha = 0,
AlwaysPresent = true,
Icon = FontAwesome.Solid.Star,
Size = new Vector2(12),
},
}
},
new HoverClickSounds()
};
@ -127,6 +177,7 @@ private void updateState()
if (Active.Value || IsHovered)
{
text.FadeColour(Color4.White, 120, Easing.InQuad);
icon.FadeColour(Color4.White, 120, Easing.InQuad);
if (Active.Value)
text.Font = text.Font.With(weight: FontWeight.Bold);
@ -134,6 +185,7 @@ private void updateState()
else
{
text.FadeColour(AccentColour, 120, Easing.InQuad);
icon.FadeColour(AccentColour, 120, Easing.InQuad);
text.Font = text.Font.With(weight: FontWeight.Medium);
}
}

View File

@ -37,6 +37,7 @@ public ProfileHeader()
Add(gamemodeControl = new GamemodeControl
{
Alpha = 0,
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Y = 100,
@ -105,7 +106,16 @@ protected override Drawable CreateBackground() =>
protected override ScreenTitle CreateTitle() => new ProfileHeaderTitle();
private void updateDisplay(User user) => coverContainer.User = user;
private void updateDisplay(User user)
{
coverContainer.User = user;
string playMode = user.PlayMode;
gamemodeControl.Current.Value = playMode;
gamemodeControl.SetDefaultGamemode(playMode);
gamemodeControl.FadeInFromZero(100, Easing.OutQuint);
}
private class ProfileHeaderTitle : ScreenTitle
{