1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 12:23:22 +08:00

Refactor LoadingButton

This commit is contained in:
Andrei Zavatski 2019-10-24 17:49:34 +03:00
parent 4f79ac8095
commit 85769982a0
3 changed files with 54 additions and 50 deletions

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Events;
using osu.Game.Graphics.Containers;
using osuTK;
@ -11,8 +10,6 @@ namespace osu.Game.Graphics.UserInterface
{
public abstract class LoadingButton : OsuHoverContainer
{
private const float fade_duration = 200;
private bool isLoading;
public bool IsLoading
@ -27,14 +24,12 @@ namespace osu.Game.Graphics.UserInterface
if (value)
{
loading.Show();
text.FadeOut(fade_duration, Easing.OutQuint);
OnLoadingStart();
OnLoadStarted();
}
else
{
loading.Hide();
text.FadeIn(fade_duration, Easing.OutQuint);
OnLoadingFinished();
OnLoadFinished();
}
}
}
@ -46,17 +41,12 @@ namespace osu.Game.Graphics.UserInterface
}
private readonly LoadingAnimation loading;
private readonly Drawable text;
protected LoadingButton()
{
Container content;
Child = content = CreateContent();
content.AddRange(new[]
AddRange(new[]
{
text = CreateText(),
CreateContent(),
loading = new LoadingAnimation
{
Anchor = Anchor.Centre,
@ -82,16 +72,14 @@ namespace osu.Game.Graphics.UserInterface
}
}
protected virtual void OnLoadingStart()
protected virtual void OnLoadStarted()
{
}
protected virtual void OnLoadingFinished()
protected virtual void OnLoadFinished()
{
}
protected abstract Container CreateContent();
protected abstract Drawable CreateText();
protected abstract Drawable CreateContent();
}
}

View File

@ -14,6 +14,8 @@ namespace osu.Game.Graphics.UserInterface
{
public class ShowMoreButton : LoadingButton
{
private const int duration = 200;
private Color4 chevronIconColour;
protected Color4 ChevronIconColour
@ -34,43 +36,50 @@ namespace osu.Game.Graphics.UserInterface
private ChevronIcon rightChevron;
private SpriteText text;
private Box background;
private FillFlowContainer textContainer;
public ShowMoreButton()
{
AutoSizeAxes = Axes.Both;
}
protected override Container CreateContent() => new CircularContainer
protected override Drawable CreateContent() => new CircularContainer
{
Masking = true,
Size = new Vector2(140, 30),
Child = background = new Box
{
RelativeSizeAxes = Axes.Both,
}
};
protected override Drawable CreateText() => new FillFlowContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(7),
Children = new Drawable[]
{
leftChevron = new ChevronIcon(),
text = new OsuSpriteText
background = new Box
{
RelativeSizeAxes = Axes.Both,
},
textContainer = new FillFlowContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold),
Text = "show more".ToUpper(),
},
rightChevron = new ChevronIcon(),
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(7),
Children = new Drawable[]
{
leftChevron = new ChevronIcon(),
text = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold),
Text = "show more".ToUpper(),
},
rightChevron = new ChevronIcon(),
}
}
}
};
protected override void OnLoadStarted() => textContainer.FadeOut(duration, Easing.OutQuint);
protected override void OnLoadFinished() => textContainer.FadeIn(duration, Easing.OutQuint);
private class ChevronIcon : SpriteIcon
{
private const int icon_size = 8;

View File

@ -24,6 +24,8 @@ namespace osu.Game.Overlays.Comments
{
public class VotePill : LoadingButton, IHasAccentColour
{
private const int duration = 200;
public Color4 AccentColour { get; set; }
protected override IEnumerable<Drawable> EffectTargets => null;
@ -84,7 +86,7 @@ namespace osu.Game.Overlays.Comments
IsLoading = false;
}
protected override Container CreateContent() => new Container
protected override Drawable CreateContent() => new Container
{
RelativeSizeAxes = Axes.Y,
AutoSizeAxes = Axes.X,
@ -116,22 +118,27 @@ namespace osu.Game.Overlays.Comments
Margin = new MarginPadding { Right = 3 },
Alpha = 0,
},
votesCounter = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Margin = new MarginPadding { Horizontal = 10 },
Font = OsuFont.GetFont(size: 14),
AlwaysPresent = true,
}
},
};
protected override Drawable CreateText() => votesCounter = new OsuSpriteText
protected override void OnLoadStarted()
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Margin = new MarginPadding { Horizontal = 10 },
Font = OsuFont.GetFont(size: 14),
AlwaysPresent = true,
};
votesCounter.FadeOut(duration, Easing.OutQuint);
updateDisplay();
}
protected override void OnLoadingStart() => updateDisplay();
protected override void OnLoadingFinished()
protected override void OnLoadFinished()
{
votesCounter.FadeIn(duration, Easing.OutQuint);
if (IsHovered)
onHoverAction();
}