1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-31 19:32:58 +08:00

Inherit GrayButton instead

Also fixes hover highlight.
This commit is contained in:
Joseph Madamba 2024-07-27 17:20:22 -07:00
parent 6a4872faa8
commit aed2b3c7c6
2 changed files with 12 additions and 50 deletions

View File

@ -3,9 +3,7 @@
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Extensions; using osu.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
@ -15,41 +13,24 @@ using osuTK;
namespace osu.Game.Screens.Ranking namespace osu.Game.Screens.Ranking
{ {
public partial class CollectionButton : OsuAnimatedButton, IHasPopover public partial class CollectionButton : GrayButton, IHasPopover
{ {
private readonly Box background;
private readonly BeatmapInfo beatmapInfo; private readonly BeatmapInfo beatmapInfo;
public CollectionButton(BeatmapInfo beatmapInfo) public CollectionButton(BeatmapInfo beatmapInfo)
: base(FontAwesome.Solid.Book)
{ {
this.beatmapInfo = beatmapInfo; this.beatmapInfo = beatmapInfo;
Size = new Vector2(50, 30); Size = new Vector2(50, 30);
Children = new Drawable[]
{
background = new Box
{
RelativeSizeAxes = Axes.Both,
Depth = float.MaxValue
},
new SpriteIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(13),
Icon = FontAwesome.Solid.Book,
},
};
TooltipText = "collections"; TooltipText = "collections";
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OsuColour colours)
{ {
background.Colour = colours.Green; Background.Colour = colours.Green;
Action = this.ShowPopover; Action = this.ShowPopover;
} }

View File

@ -3,8 +3,6 @@
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Logging; using osu.Framework.Logging;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
@ -19,17 +17,14 @@ using osuTK;
namespace osu.Game.Screens.Ranking namespace osu.Game.Screens.Ranking
{ {
public partial class FavouriteButton : OsuAnimatedButton public partial class FavouriteButton : GrayButton
{ {
private readonly Box background;
private readonly SpriteIcon icon;
public readonly BeatmapSetInfo BeatmapSetInfo; public readonly BeatmapSetInfo BeatmapSetInfo;
private APIBeatmapSet? beatmapSet; private APIBeatmapSet? beatmapSet;
private readonly Bindable<BeatmapSetFavouriteState> current; private readonly Bindable<BeatmapSetFavouriteState> current;
private PostBeatmapFavouriteRequest? favouriteRequest; private PostBeatmapFavouriteRequest? favouriteRequest;
private readonly LoadingLayer loading; private LoadingLayer loading = null!;
private readonly IBindable<APIUser> localUser = new Bindable<APIUser>(); private readonly IBindable<APIUser> localUser = new Bindable<APIUser>();
@ -40,35 +35,21 @@ namespace osu.Game.Screens.Ranking
private OsuColour colours { get; set; } = null!; private OsuColour colours { get; set; } = null!;
public FavouriteButton(BeatmapSetInfo beatmapSetInfo) public FavouriteButton(BeatmapSetInfo beatmapSetInfo)
: base(FontAwesome.Regular.Heart)
{ {
BeatmapSetInfo = beatmapSetInfo; BeatmapSetInfo = beatmapSetInfo;
current = new BindableWithCurrent<BeatmapSetFavouriteState>(new BeatmapSetFavouriteState(false, 0)); current = new BindableWithCurrent<BeatmapSetFavouriteState>(new BeatmapSetFavouriteState(false, 0));
Size = new Vector2(50, 30); Size = new Vector2(50, 30);
Children = new Drawable[]
{
background = new Box
{
RelativeSizeAxes = Axes.Both,
Depth = float.MaxValue
},
icon = new SpriteIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(13),
Icon = FontAwesome.Regular.Heart,
},
loading = new LoadingLayer(true, false),
};
Action = toggleFavouriteStatus; Action = toggleFavouriteStatus;
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
Add(loading = new LoadingLayer(true, false));
current.BindValueChanged(_ => updateState(), true); current.BindValueChanged(_ => updateState(), true);
localUser.BindTo(api.LocalUser); localUser.BindTo(api.LocalUser);
@ -147,14 +128,14 @@ namespace osu.Game.Screens.Ranking
{ {
if (current.Value.Favourited) if (current.Value.Favourited)
{ {
background.Colour = colours.Green; Background.Colour = colours.Green;
icon.Icon = FontAwesome.Solid.Heart; Icon.Icon = FontAwesome.Solid.Heart;
TooltipText = BeatmapsetsStrings.ShowDetailsUnfavourite; TooltipText = BeatmapsetsStrings.ShowDetailsUnfavourite;
} }
else else
{ {
background.Colour = colours.Gray4; Background.Colour = colours.Gray4;
icon.Icon = FontAwesome.Regular.Heart; Icon.Icon = FontAwesome.Regular.Heart;
TooltipText = BeatmapsetsStrings.ShowDetailsFavourite; TooltipText = BeatmapsetsStrings.ShowDetailsFavourite;
} }
} }