1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 02:07:34 +08:00

Update remaining tooltip implementations to use generics

This commit is contained in:
Salman Ahmed 2021-08-28 19:09:37 +03:00
parent d6a0d2aa44
commit da7ff4b160
6 changed files with 144 additions and 138 deletions

View File

@ -16,7 +16,6 @@ using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osuTK;
@ -24,7 +23,7 @@ using osuTK.Graphics;
namespace osu.Game.Beatmaps.Drawables
{
public class DifficultyIcon : CompositeDrawable, IHasCustomTooltip
public class DifficultyIcon : CompositeDrawable, IHasCustomTooltip<DifficultyIconTooltipContent>
{
private readonly Container iconContainer;
@ -127,9 +126,9 @@ namespace osu.Game.Beatmaps.Drawables
difficultyBindable.BindValueChanged(difficulty => background.Colour = colours.ForStarDifficulty(difficulty.NewValue.Stars));
}
public ITooltip GetCustomTooltip() => new DifficultyIconTooltip();
public ITooltip<DifficultyIconTooltipContent> GetCustomTooltip() => new DifficultyIconTooltip();
public object TooltipContent => shouldShowTooltip ? new DifficultyIconTooltipContent(beatmap, difficultyBindable) : null;
public DifficultyIconTooltipContent TooltipContent => shouldShowTooltip ? new DifficultyIconTooltipContent(beatmap, difficultyBindable) : null;
private class DifficultyRetriever : Component
{
@ -173,113 +172,5 @@ namespace osu.Game.Beatmaps.Drawables
difficultyCancellation?.Cancel();
}
}
private class DifficultyIconTooltipContent
{
public readonly BeatmapInfo Beatmap;
public readonly IBindable<StarDifficulty> Difficulty;
public DifficultyIconTooltipContent(BeatmapInfo beatmap, IBindable<StarDifficulty> difficulty)
{
Beatmap = beatmap;
Difficulty = difficulty;
}
}
private class DifficultyIconTooltip : VisibilityContainer, ITooltip
{
private readonly OsuSpriteText difficultyName, starRating;
private readonly Box background;
private readonly FillFlowContainer difficultyFlow;
public DifficultyIconTooltip()
{
AutoSizeAxes = Axes.Both;
Masking = true;
CornerRadius = 5;
Children = new Drawable[]
{
background = new Box
{
RelativeSizeAxes = Axes.Both
},
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
AutoSizeDuration = 200,
AutoSizeEasing = Easing.OutQuint,
Direction = FillDirection.Vertical,
Padding = new MarginPadding(10),
Children = new Drawable[]
{
difficultyName = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = OsuFont.GetFont(size: 16, weight: FontWeight.Bold),
},
difficultyFlow = new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Direction = FillDirection.Horizontal,
Children = new Drawable[]
{
starRating = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = OsuFont.GetFont(size: 16, weight: FontWeight.Regular),
},
new SpriteIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Margin = new MarginPadding { Left = 4 },
Icon = FontAwesome.Solid.Star,
Size = new Vector2(12),
},
}
}
}
}
};
}
[Resolved]
private OsuColour colours { get; set; }
[BackgroundDependencyLoader]
private void load()
{
background.Colour = colours.Gray3;
}
private readonly IBindable<StarDifficulty> starDifficulty = new Bindable<StarDifficulty>();
public void SetContent(object content)
{
if (!(content is DifficultyIconTooltipContent iconContent))
return;
difficultyName.Text = iconContent.Beatmap.Version;
starDifficulty.UnbindAll();
starDifficulty.BindTo(iconContent.Difficulty);
starDifficulty.BindValueChanged(difficulty =>
{
starRating.Text = $"{difficulty.NewValue.Stars:0.##}";
difficultyFlow.Colour = colours.ForStarDifficulty(difficulty.NewValue.Stars);
}, true);
}
public void Move(Vector2 pos) => Position = pos;
protected override void PopIn() => this.FadeIn(200, Easing.OutQuint);
protected override void PopOut() => this.FadeOut(200, Easing.OutQuint);
}
}
}

View File

@ -0,0 +1,121 @@
// 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.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osuTK;
namespace osu.Game.Beatmaps.Drawables
{
public class DifficultyIconTooltip : VisibilityContainer, ITooltip<DifficultyIconTooltipContent>
{
private readonly OsuSpriteText difficultyName, starRating;
private readonly Box background;
private readonly FillFlowContainer difficultyFlow;
public DifficultyIconTooltip()
{
AutoSizeAxes = Axes.Both;
Masking = true;
CornerRadius = 5;
Children = new Drawable[]
{
background = new Box
{
RelativeSizeAxes = Axes.Both
},
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
AutoSizeDuration = 200,
AutoSizeEasing = Easing.OutQuint,
Direction = FillDirection.Vertical,
Padding = new MarginPadding(10),
Children = new Drawable[]
{
difficultyName = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = OsuFont.GetFont(size: 16, weight: FontWeight.Bold),
},
difficultyFlow = new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Direction = FillDirection.Horizontal,
Children = new Drawable[]
{
starRating = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = OsuFont.GetFont(size: 16, weight: FontWeight.Regular),
},
new SpriteIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Margin = new MarginPadding { Left = 4 },
Icon = FontAwesome.Solid.Star,
Size = new Vector2(12),
},
}
}
}
}
};
}
[Resolved]
private OsuColour colours { get; set; }
[BackgroundDependencyLoader]
private void load()
{
background.Colour = colours.Gray3;
}
private readonly IBindable<StarDifficulty> starDifficulty = new Bindable<StarDifficulty>();
public void SetContent(DifficultyIconTooltipContent content)
{
difficultyName.Text = content.Beatmap.Version;
starDifficulty.UnbindAll();
starDifficulty.BindTo(content.Difficulty);
starDifficulty.BindValueChanged(difficulty =>
{
starRating.Text = $"{difficulty.NewValue.Stars:0.##}";
difficultyFlow.Colour = colours.ForStarDifficulty(difficulty.NewValue.Stars);
}, true);
}
public void Move(Vector2 pos) => Position = pos;
protected override void PopIn() => this.FadeIn(200, Easing.OutQuint);
protected override void PopOut() => this.FadeOut(200, Easing.OutQuint);
}
public class DifficultyIconTooltipContent
{
public readonly BeatmapInfo Beatmap;
public readonly IBindable<StarDifficulty> Difficulty;
public DifficultyIconTooltipContent(BeatmapInfo beatmap, IBindable<StarDifficulty> difficulty)
{
Beatmap = beatmap;
Difficulty = difficulty;
}
}
}

View File

@ -10,7 +10,7 @@ using osu.Game.Utils;
namespace osu.Game.Graphics
{
public class DrawableDate : OsuSpriteText, IHasCustomTooltip
public class DrawableDate : OsuSpriteText, IHasCustomTooltip<DateTimeOffset>
{
private DateTimeOffset date;
@ -75,8 +75,8 @@ namespace osu.Game.Graphics
private void updateTime() => Text = Format();
public ITooltip GetCustomTooltip() => new DateTooltip();
public ITooltip<DateTimeOffset> GetCustomTooltip() => new DateTooltip();
public object TooltipContent => Date;
public DateTimeOffset TooltipContent => Date;
}
}

View File

@ -140,17 +140,15 @@ namespace osu.Game.Overlays.Dashboard.Home.News
}
}
private class Date : CompositeDrawable, IHasCustomTooltip
private class Date : CompositeDrawable, IHasCustomTooltip<DateTimeOffset>
{
public ITooltip GetCustomTooltip() => new DateTooltip();
public ITooltip<DateTimeOffset> GetCustomTooltip() => new DateTooltip();
public object TooltipContent => date;
private readonly DateTimeOffset date;
public DateTimeOffset TooltipContent { get; }
public Date(DateTimeOffset date)
{
this.date = date;
TooltipContent = date;
}
[BackgroundDependencyLoader]
@ -174,7 +172,7 @@ namespace osu.Game.Overlays.Dashboard.Home.News
Origin = Anchor.TopRight,
Font = OsuFont.GetFont(weight: FontWeight.Bold), // using Bold since there is no 800 weight alternative
Colour = colourProvider.Light1,
Text = $"{date:dd}"
Text = $"{TooltipContent:dd}"
},
new TextFlowContainer(f =>
{
@ -185,7 +183,7 @@ namespace osu.Game.Overlays.Dashboard.Home.News
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
AutoSizeAxes = Axes.Both,
Text = $"{date:MMM yyyy}"
Text = $"{TooltipContent:MMM yyyy}"
}
}
};

View File

@ -67,17 +67,15 @@ namespace osu.Game.Overlays.Dashboard.Home.News
};
}
private class Date : CompositeDrawable, IHasCustomTooltip
private class Date : CompositeDrawable, IHasCustomTooltip<DateTimeOffset>
{
public ITooltip GetCustomTooltip() => new DateTooltip();
public ITooltip<DateTimeOffset> GetCustomTooltip() => new DateTooltip();
public object TooltipContent => date;
private readonly DateTimeOffset date;
public DateTimeOffset TooltipContent { get; }
public Date(DateTimeOffset date)
{
this.date = date;
TooltipContent = date;
}
[BackgroundDependencyLoader]
@ -100,12 +98,12 @@ namespace osu.Game.Overlays.Dashboard.Home.News
Margin = new MarginPadding { Vertical = 5 }
};
textFlow.AddText($"{date:dd}", t =>
textFlow.AddText($"{TooltipContent:dd}", t =>
{
t.Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold);
});
textFlow.AddText($"{date: MMM}", t =>
textFlow.AddText($"{TooltipContent: MMM}", t =>
{
t.Font = OsuFont.GetFont(size: 14, weight: FontWeight.Regular);
});

View File

@ -123,17 +123,15 @@ namespace osu.Game.Overlays.News
main.AddText(post.Author, t => t.Font = OsuFont.GetFont(size: 12, weight: FontWeight.SemiBold));
}
private class DateContainer : CircularContainer, IHasCustomTooltip
private class DateContainer : CircularContainer, IHasCustomTooltip<DateTimeOffset>
{
public ITooltip GetCustomTooltip() => new DateTooltip();
public ITooltip<DateTimeOffset> GetCustomTooltip() => new DateTooltip();
public object TooltipContent => date;
private readonly DateTimeOffset date;
public DateTimeOffset TooltipContent { get; }
public DateContainer(DateTimeOffset date)
{
this.date = date;
TooltipContent = date;
}
[BackgroundDependencyLoader]
@ -150,7 +148,7 @@ namespace osu.Game.Overlays.News
},
new OsuSpriteText
{
Text = date.ToString("d MMM yyyy").ToUpper(),
Text = TooltipContent.ToString("d MMM yyyy").ToUpper(),
Font = OsuFont.GetFont(size: 10, weight: FontWeight.SemiBold),
Margin = new MarginPadding
{