mirror of
https://github.com/osukey/osukey.git
synced 2025-08-05 23:53:51 +09:00
Implement GamemodeControl
This commit is contained in:
142
osu.Game/Overlays/Profile/Header/Components/GamemodeControl.cs
Normal file
142
osu.Game/Overlays/Profile/Header/Components/GamemodeControl.cs
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
// 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.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 GamemodeControl : TabControl<string>
|
||||||
|
{
|
||||||
|
protected override Dropdown<string> CreateDropdown() => null;
|
||||||
|
|
||||||
|
protected override TabItem<string> CreateTabItem(string value) => new GamemodeTabItem(value)
|
||||||
|
{
|
||||||
|
AccentColour = AccentColour
|
||||||
|
};
|
||||||
|
|
||||||
|
private Color4 accentColour = Color4.White;
|
||||||
|
|
||||||
|
public Color4 AccentColour
|
||||||
|
{
|
||||||
|
get => accentColour;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (accentColour == value)
|
||||||
|
return;
|
||||||
|
|
||||||
|
accentColour = value;
|
||||||
|
|
||||||
|
foreach (TabItem<string> tabItem in TabContainer)
|
||||||
|
{
|
||||||
|
((GamemodeTabItem)tabItem).AccentColour = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public GamemodeControl()
|
||||||
|
{
|
||||||
|
TabContainer.Masking = false;
|
||||||
|
TabContainer.Spacing = new Vector2(15, 0);
|
||||||
|
AutoSizeAxes = Axes.Both;
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(RulesetStore rulesets)
|
||||||
|
{
|
||||||
|
foreach (var r in rulesets.AvailableRulesets)
|
||||||
|
AddItem(r.Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override TabFillFlowContainer CreateTabFlow() => new TabFillFlowContainer
|
||||||
|
{
|
||||||
|
Direction = FillDirection.Horizontal,
|
||||||
|
AutoSizeAxes = Axes.Both,
|
||||||
|
};
|
||||||
|
|
||||||
|
private class GamemodeTabItem : TabItem<string>
|
||||||
|
{
|
||||||
|
private readonly OsuSpriteText text;
|
||||||
|
|
||||||
|
private Color4 accentColour;
|
||||||
|
|
||||||
|
public Color4 AccentColour
|
||||||
|
{
|
||||||
|
get => accentColour;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (accentColour == value)
|
||||||
|
return;
|
||||||
|
|
||||||
|
accentColour = value;
|
||||||
|
|
||||||
|
updateState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public GamemodeTabItem(string value)
|
||||||
|
: base(value)
|
||||||
|
{
|
||||||
|
AutoSizeAxes = Axes.Both;
|
||||||
|
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
text = new OsuSpriteText
|
||||||
|
{
|
||||||
|
Margin = new MarginPadding { Bottom = 10 },
|
||||||
|
Origin = Anchor.BottomLeft,
|
||||||
|
Anchor = Anchor.BottomLeft,
|
||||||
|
Text = value,
|
||||||
|
Font = OsuFont.GetFont()
|
||||||
|
},
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
if (Active.Value || IsHovered)
|
||||||
|
{
|
||||||
|
text.FadeColour(Color4.White, 120, Easing.InQuad);
|
||||||
|
|
||||||
|
if (Active.Value)
|
||||||
|
text.Font = text.Font.With(weight: FontWeight.Bold);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
text.FadeColour(AccentColour, 120, Easing.InQuad);
|
||||||
|
text.Font = text.Font.With(weight: FontWeight.Medium);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -11,6 +11,7 @@ using osu.Framework.Graphics.Shapes;
|
|||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Overlays.Profile.Header;
|
using osu.Game.Overlays.Profile.Header;
|
||||||
|
using osu.Game.Overlays.Profile.Header.Components;
|
||||||
using osu.Game.Users;
|
using osu.Game.Users;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Profile
|
namespace osu.Game.Overlays.Profile
|
||||||
@ -18,6 +19,7 @@ namespace osu.Game.Overlays.Profile
|
|||||||
public class ProfileHeader : OverlayHeader
|
public class ProfileHeader : OverlayHeader
|
||||||
{
|
{
|
||||||
private UserCoverBackground coverContainer;
|
private UserCoverBackground coverContainer;
|
||||||
|
private readonly GamemodeControl gamemodeControl;
|
||||||
|
|
||||||
public Bindable<User> User = new Bindable<User>();
|
public Bindable<User> User = new Bindable<User>();
|
||||||
|
|
||||||
@ -32,12 +34,20 @@ namespace osu.Game.Overlays.Profile
|
|||||||
TabControl.AddItem("Modding");
|
TabControl.AddItem("Modding");
|
||||||
|
|
||||||
centreHeaderContainer.DetailsVisible.BindValueChanged(visible => detailHeaderContainer.Expanded = visible.NewValue, true);
|
centreHeaderContainer.DetailsVisible.BindValueChanged(visible => detailHeaderContainer.Expanded = visible.NewValue, true);
|
||||||
|
|
||||||
|
Add(gamemodeControl = new GamemodeControl
|
||||||
|
{
|
||||||
|
Anchor = Anchor.TopRight,
|
||||||
|
Origin = Anchor.TopRight,
|
||||||
|
Y = 100,
|
||||||
|
Margin = new MarginPadding { Right = 30 },
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuColour colours)
|
private void load(OsuColour colours)
|
||||||
{
|
{
|
||||||
TabControl.AccentColour = colours.Seafoam;
|
TabControl.AccentColour = gamemodeControl.AccentColour = colours.Seafoam;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override Drawable CreateBackground() =>
|
protected override Drawable CreateBackground() =>
|
||||||
|
Reference in New Issue
Block a user