Refactor LoadRepliesButton to inherit LoadingButton

This commit is contained in:
Andrei Zavatski
2020-07-14 15:02:29 +03:00
parent 4b22832cc8
commit 4c2294f0cd
5 changed files with 34 additions and 34 deletions

View File

@ -1,7 +1,6 @@
// 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 System;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -17,8 +16,6 @@ namespace osu.Game.Overlays.Comments.Buttons
{
public abstract class CommentRepliesButton : CompositeDrawable
{
public Action Action { get; set; }
protected string Text
{
get => text.Text;
@ -72,6 +69,7 @@ namespace osu.Game.Overlays.Comments.Buttons
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
AlwaysPresent = true,
Font = OsuFont.GetFont(size: 12, weight: FontWeight.SemiBold)
},
icon = new SpriteIcon
@ -99,6 +97,8 @@ namespace osu.Game.Overlays.Comments.Buttons
protected void SetIconDirection(bool upwards) => icon.ScaleTo(new Vector2(1, upwards ? -1 : 1));
public void ToggleTextVisibility(bool visible) => text.FadeTo(visible ? 1 : 0, 200, Easing.OutQuint);
protected override bool OnHover(HoverEvent e)
{
base.OnHover(e);
@ -113,11 +113,5 @@ namespace osu.Game.Overlays.Comments.Buttons
background.FadeColour(colourProvider.Background2, 200, Easing.OutQuint);
icon.FadeColour(colourProvider.Foreground1, 200, Easing.OutQuint);
}
protected override bool OnClick(ClickEvent e)
{
Action?.Invoke();
return base.OnClick(e);
}
}
}

View File

@ -1,13 +1,32 @@
// 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.Graphics;
using osu.Game.Graphics.UserInterface;
namespace osu.Game.Overlays.Comments.Buttons
{
public class LoadRepliesButton : CommentRepliesButton
public class LoadRepliesButton : LoadingButton
{
private ButtonContent content;
public LoadRepliesButton()
{
Text = "load replies";
AutoSizeAxes = Axes.Both;
}
protected override Drawable CreateContent() => content = new ButtonContent();
protected override void OnLoadStarted() => content.ToggleTextVisibility(false);
protected override void OnLoadFinished() => content.ToggleTextVisibility(true);
private class ButtonContent : CommentRepliesButton
{
public ButtonContent()
{
Text = "load replies";
}
}
}
}

View File

@ -1,6 +1,7 @@
// 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 System;
using Humanizer;
using osu.Framework.Bindables;
using osu.Framework.Input.Events;
@ -9,6 +10,8 @@ namespace osu.Game.Overlays.Comments.Buttons
{
public class ShowRepliesButton : CommentRepliesButton
{
public Action Action;
public readonly BindableBool Expanded = new BindableBool(true);
public ShowRepliesButton(int count)
@ -25,6 +28,7 @@ namespace osu.Game.Overlays.Comments.Buttons
protected override bool OnClick(ClickEvent e)
{
Expanded.Toggle();
Action?.Invoke();
return base.OnClick(e);
}
}