osu/osu.Game/Graphics/UserInterface/ShowMoreButton.cs

152 lines
4.6 KiB
C#
Raw Normal View History

2019-10-13 11:43:30 +00:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
2019-05-30 19:55:59 +00:00
// 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.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Events;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osuTK;
2019-10-13 11:43:30 +00:00
using osuTK.Graphics;
2019-05-30 19:55:59 +00:00
using System.Collections.Generic;
2019-10-13 11:43:30 +00:00
namespace osu.Game.Graphics.UserInterface
2019-05-30 19:55:59 +00:00
{
public class ShowMoreButton : OsuHoverContainer
{
2019-06-03 08:06:07 +00:00
private const float fade_duration = 200;
2019-10-13 11:43:30 +00:00
private Color4 chevronIconColour;
2019-05-30 19:55:59 +00:00
2019-10-13 11:43:30 +00:00
public Color4 ChevronIconColour
{
get => chevronIconColour;
set { chevronIconColour = leftChevron.AccentColour = rightChevron.AccentColour = value; }
}
public string Text
{
get => text.Text;
set { text.Text = value; }
}
2019-05-30 19:55:59 +00:00
private bool isLoading;
public bool IsLoading
{
get => isLoading;
set
{
isLoading = value;
2019-06-04 01:04:33 +00:00
Enabled.Value = !isLoading;
2019-05-30 19:55:59 +00:00
if (value)
{
2019-10-13 11:43:30 +00:00
loading.Show();
2019-06-03 08:06:07 +00:00
content.FadeOut(fade_duration, Easing.OutQuint);
2019-05-30 19:55:59 +00:00
}
else
{
2019-10-13 11:43:30 +00:00
loading.Hide();
2019-06-03 08:06:07 +00:00
content.FadeIn(fade_duration, Easing.OutQuint);
2019-05-30 19:55:59 +00:00
}
}
}
2019-10-13 11:43:30 +00:00
private readonly Box background;
private readonly LoadingAnimation loading;
private readonly FillFlowContainer content;
private readonly ChevronIcon leftChevron;
private readonly ChevronIcon rightChevron;
private readonly SpriteText text;
protected override IEnumerable<Drawable> EffectTargets => new[] { background };
2019-05-30 19:55:59 +00:00
public ShowMoreButton()
{
AutoSizeAxes = Axes.Both;
Children = new Drawable[]
{
2019-05-30 20:07:04 +00:00
new CircularContainer
{
Masking = true,
Size = new Vector2(140, 30),
Children = new Drawable[]
2019-05-30 19:55:59 +00:00
{
2019-05-30 20:07:04 +00:00
background = new Box
2019-05-30 19:55:59 +00:00
{
2019-05-30 20:07:04 +00:00
RelativeSizeAxes = Axes.Both,
},
content = new FillFlowContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(7),
Children = new Drawable[]
2019-05-30 19:55:59 +00:00
{
2019-10-13 11:43:30 +00:00
leftChevron = new ChevronIcon(),
text = new OsuSpriteText
2019-05-30 19:55:59 +00:00
{
2019-05-30 20:07:04 +00:00
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold),
Text = "show more".ToUpper(),
},
2019-10-13 11:43:30 +00:00
rightChevron = new ChevronIcon(),
2019-05-30 20:07:04 +00:00
}
},
loading = new LoadingAnimation
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(12)
},
2019-05-30 19:55:59 +00:00
}
2019-05-30 20:07:04 +00:00
}
2019-05-30 19:55:59 +00:00
};
}
protected override bool OnClick(ClickEvent e)
{
2019-06-04 01:26:21 +00:00
if (!Enabled.Value)
return false;
2019-06-04 01:04:33 +00:00
2019-06-04 01:26:21 +00:00
try
{
return base.OnClick(e);
}
finally
{
// run afterwards as this will disable this button.
IsLoading = true;
}
2019-05-30 19:55:59 +00:00
}
private class ChevronIcon : SpriteIcon
{
private const int icon_size = 8;
2019-10-13 11:43:30 +00:00
private Color4 accentColour;
public Color4 AccentColour
{
get => accentColour;
set { accentColour = Colour = value; }
}
2019-05-30 19:55:59 +00:00
public ChevronIcon()
{
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
Size = new Vector2(icon_size);
Icon = FontAwesome.Solid.ChevronDown;
}
}
}
}