Add cover toggle button

This commit is contained in:
Bartłomiej Dach 2022-12-31 20:09:49 +01:00
parent ef7812412b
commit e74176e5bd
No known key found for this signature in database
2 changed files with 117 additions and 102 deletions

View File

@ -5,7 +5,6 @@ using osu.Framework.Allocation;
using osu.Framework.Audio; using osu.Framework.Audio;
using osu.Framework.Audio.Sample; using osu.Framework.Audio.Sample;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Localisation; using osu.Framework.Localisation;
@ -15,11 +14,11 @@ using osuTK;
namespace osu.Game.Overlays.Profile.Header.Components namespace osu.Game.Overlays.Profile.Header.Components
{ {
public partial class ExpandDetailsButton : ProfileHeaderButton public partial class ToggleCoverButton : ProfileHeaderButton
{ {
public readonly BindableBool DetailsVisible = new BindableBool(); public readonly BindableBool CoverVisible = new BindableBool();
public override LocalisableString TooltipText => DetailsVisible.Value ? CommonStrings.ButtonsCollapse : CommonStrings.ButtonsExpand; public override LocalisableString TooltipText => CoverVisible.Value ? UsersStrings.ShowCoverTo0 : UsersStrings.ShowCoverTo1;
private SpriteIcon icon = null!; private SpriteIcon icon = null!;
private Sample? sampleOpen; private Sample? sampleOpen;
@ -27,12 +26,12 @@ namespace osu.Game.Overlays.Profile.Header.Components
protected override HoverSounds CreateHoverSounds(HoverSampleSet sampleSet) => new HoverClickSounds(); protected override HoverSounds CreateHoverSounds(HoverSampleSet sampleSet) => new HoverClickSounds();
public ExpandDetailsButton() public ToggleCoverButton()
{ {
Action = () => Action = () =>
{ {
DetailsVisible.Toggle(); CoverVisible.Toggle();
(DetailsVisible.Value ? sampleOpen : sampleClose)?.Play(); (CoverVisible.Value ? sampleOpen : sampleClose)?.Play();
}; };
} }
@ -40,19 +39,21 @@ namespace osu.Game.Overlays.Profile.Header.Components
private void load(OverlayColourProvider colourProvider, AudioManager audio) private void load(OverlayColourProvider colourProvider, AudioManager audio)
{ {
IdleColour = colourProvider.Background2; IdleColour = colourProvider.Background2;
HoverColour = colourProvider.Background2.Lighten(0.2f); HoverColour = colourProvider.Background1;
sampleOpen = audio.Samples.Get(@"UI/dropdown-open"); sampleOpen = audio.Samples.Get(@"UI/dropdown-open");
sampleClose = audio.Samples.Get(@"UI/dropdown-close"); sampleClose = audio.Samples.Get(@"UI/dropdown-close");
AutoSizeAxes = Axes.None;
Size = new Vector2(30);
Child = icon = new SpriteIcon Child = icon = new SpriteIcon
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
Size = new Vector2(20, 12) Size = new Vector2(10.5f, 12)
}; };
DetailsVisible.BindValueChanged(visible => updateState(visible.NewValue), true); CoverVisible.BindValueChanged(visible => updateState(visible.NewValue), true);
} }
private void updateState(bool detailsVisible) => icon.Icon = detailsVisible ? FontAwesome.Solid.ChevronUp : FontAwesome.Solid.ChevronDown; private void updateState(bool detailsVisible) => icon.Icon = detailsVisible ? FontAwesome.Solid.ChevronUp : FontAwesome.Solid.ChevronDown;

View File

@ -65,6 +65,12 @@ namespace osu.Game.Overlays.Profile.Header
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Height = 250, Height = 250,
}, },
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Children = new Drawable[]
{
new FillFlowContainer new FillFlowContainer
{ {
Direction = FillDirection.Horizontal, Direction = FillDirection.Horizontal,
@ -133,7 +139,7 @@ namespace osu.Game.Overlays.Profile.Header
{ {
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
} },
} }
}, },
titleText = new OsuSpriteText titleText = new OsuSpriteText
@ -163,10 +169,18 @@ namespace osu.Game.Overlays.Profile.Header
}, },
} }
}, },
},
} }
},
new ToggleCoverButton
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Margin = new MarginPadding { Right = 10 }
} }
} },
} },
},
}, },
}; };