mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 00:40:09 +09:00
Refactor LoadRepliesButton to inherit LoadingButton
This commit is contained in:
@ -33,7 +33,10 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
button = new TestButton(),
|
button = new TestButton(),
|
||||||
new LoadRepliesButton(),
|
new LoadRepliesButton
|
||||||
|
{
|
||||||
|
Action = () => { }
|
||||||
|
},
|
||||||
new ShowRepliesButton(1),
|
new ShowRepliesButton(1),
|
||||||
new ShowRepliesButton(2)
|
new ShowRepliesButton(2)
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
@ -17,8 +16,6 @@ namespace osu.Game.Overlays.Comments.Buttons
|
|||||||
{
|
{
|
||||||
public abstract class CommentRepliesButton : CompositeDrawable
|
public abstract class CommentRepliesButton : CompositeDrawable
|
||||||
{
|
{
|
||||||
public Action Action { get; set; }
|
|
||||||
|
|
||||||
protected string Text
|
protected string Text
|
||||||
{
|
{
|
||||||
get => text.Text;
|
get => text.Text;
|
||||||
@ -72,6 +69,7 @@ namespace osu.Game.Overlays.Comments.Buttons
|
|||||||
{
|
{
|
||||||
Anchor = Anchor.CentreLeft,
|
Anchor = Anchor.CentreLeft,
|
||||||
Origin = Anchor.CentreLeft,
|
Origin = Anchor.CentreLeft,
|
||||||
|
AlwaysPresent = true,
|
||||||
Font = OsuFont.GetFont(size: 12, weight: FontWeight.SemiBold)
|
Font = OsuFont.GetFont(size: 12, weight: FontWeight.SemiBold)
|
||||||
},
|
},
|
||||||
icon = new SpriteIcon
|
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));
|
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)
|
protected override bool OnHover(HoverEvent e)
|
||||||
{
|
{
|
||||||
base.OnHover(e);
|
base.OnHover(e);
|
||||||
@ -113,11 +113,5 @@ namespace osu.Game.Overlays.Comments.Buttons
|
|||||||
background.FadeColour(colourProvider.Background2, 200, Easing.OutQuint);
|
background.FadeColour(colourProvider.Background2, 200, Easing.OutQuint);
|
||||||
icon.FadeColour(colourProvider.Foreground1, 200, Easing.OutQuint);
|
icon.FadeColour(colourProvider.Foreground1, 200, Easing.OutQuint);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnClick(ClickEvent e)
|
|
||||||
{
|
|
||||||
Action?.Invoke();
|
|
||||||
return base.OnClick(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,32 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// 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
|
namespace osu.Game.Overlays.Comments.Buttons
|
||||||
{
|
{
|
||||||
public class LoadRepliesButton : CommentRepliesButton
|
public class LoadRepliesButton : LoadingButton
|
||||||
{
|
{
|
||||||
|
private ButtonContent content;
|
||||||
|
|
||||||
public LoadRepliesButton()
|
public LoadRepliesButton()
|
||||||
|
{
|
||||||
|
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";
|
Text = "load replies";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
using Humanizer;
|
using Humanizer;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
@ -9,6 +10,8 @@ namespace osu.Game.Overlays.Comments.Buttons
|
|||||||
{
|
{
|
||||||
public class ShowRepliesButton : CommentRepliesButton
|
public class ShowRepliesButton : CommentRepliesButton
|
||||||
{
|
{
|
||||||
|
public Action Action;
|
||||||
|
|
||||||
public readonly BindableBool Expanded = new BindableBool(true);
|
public readonly BindableBool Expanded = new BindableBool(true);
|
||||||
|
|
||||||
public ShowRepliesButton(int count)
|
public ShowRepliesButton(int count)
|
||||||
@ -25,6 +28,7 @@ namespace osu.Game.Overlays.Comments.Buttons
|
|||||||
protected override bool OnClick(ClickEvent e)
|
protected override bool OnClick(ClickEvent e)
|
||||||
{
|
{
|
||||||
Expanded.Toggle();
|
Expanded.Toggle();
|
||||||
|
Action?.Invoke();
|
||||||
return base.OnClick(e);
|
return base.OnClick(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@ using osu.Framework.Graphics.Shapes;
|
|||||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||||
using System.Collections.Specialized;
|
using System.Collections.Specialized;
|
||||||
using osu.Game.Overlays.Comments.Buttons;
|
using osu.Game.Overlays.Comments.Buttons;
|
||||||
using osu.Game.Graphics.UserInterface;
|
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Comments
|
namespace osu.Game.Overlays.Comments
|
||||||
{
|
{
|
||||||
@ -52,7 +51,6 @@ namespace osu.Game.Overlays.Comments
|
|||||||
private ShowRepliesButton showRepliesButton;
|
private ShowRepliesButton showRepliesButton;
|
||||||
private ChevronButton chevronButton;
|
private ChevronButton chevronButton;
|
||||||
private DeletedCommentsCounter deletedCommentsCounter;
|
private DeletedCommentsCounter deletedCommentsCounter;
|
||||||
private LoadingSpinner loading;
|
|
||||||
|
|
||||||
public DrawableComment(Comment comment)
|
public DrawableComment(Comment comment)
|
||||||
{
|
{
|
||||||
@ -194,11 +192,7 @@ namespace osu.Game.Overlays.Comments
|
|||||||
},
|
},
|
||||||
loadRepliesButton = new LoadRepliesButton
|
loadRepliesButton = new LoadRepliesButton
|
||||||
{
|
{
|
||||||
Action = () =>
|
Action = () => RepliesRequested(this, ++currentPage)
|
||||||
{
|
|
||||||
RepliesRequested(this, ++currentPage);
|
|
||||||
loadRepliesButton.Hide();
|
|
||||||
loading.Show();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -207,18 +201,6 @@ namespace osu.Game.Overlays.Comments
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
|
||||||
loading = new LoadingSpinner
|
|
||||||
{
|
|
||||||
Anchor = Anchor.TopLeft,
|
|
||||||
Origin = Anchor.TopLeft,
|
|
||||||
Size = new Vector2(15),
|
|
||||||
Margin = new MarginPadding
|
|
||||||
{
|
|
||||||
Vertical = 5,
|
|
||||||
Left = 80
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
childCommentsVisibilityContainer = new FillFlowContainer
|
childCommentsVisibilityContainer = new FillFlowContainer
|
||||||
{
|
{
|
||||||
@ -372,9 +354,7 @@ namespace osu.Game.Overlays.Comments
|
|||||||
if (Comment.IsTopLevel)
|
if (Comment.IsTopLevel)
|
||||||
chevronButton.FadeTo(loadedReplesCount != 0 ? 1 : 0);
|
chevronButton.FadeTo(loadedReplesCount != 0 ? 1 : 0);
|
||||||
|
|
||||||
showMoreButton.IsLoading = false;
|
showMoreButton.IsLoading = loadRepliesButton.IsLoading = false;
|
||||||
loading.Hide();
|
|
||||||
loading.FinishTransforms();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ChevronButton : ShowChildrenButton
|
private class ChevronButton : ShowChildrenButton
|
||||||
|
Reference in New Issue
Block a user