Skip to content

Commit

Permalink
Merge pull request #195 from andy840119/rabbit/singer-tooltip
Browse files Browse the repository at this point in the history
Implement singer tooltip.
  • Loading branch information
andy840119 authored Oct 4, 2020
2 parents 0eff0e3 + 46a643c commit db532a3
Show file tree
Hide file tree
Showing 4 changed files with 211 additions and 37 deletions.
72 changes: 72 additions & 0 deletions osu.Game.Rulesets.Karaoke.Tests/Graphics/TestSceneSingerToolTip.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using NUnit.Framework;
using osu.Game.Rulesets.Karaoke.Graphics.Cursor;
using osu.Game.Tests.Visual;
using osu.Framework.Graphics;
using osu.Game.Rulesets.Karaoke.Beatmaps.Metadatas;
using System;

namespace osu.Game.Rulesets.Karaoke.Tests.Graphics
{
[TestFixture]
public class TestSceneSingerToolTip : OsuTestScene
{
private SingerToolTip toolTip;

[SetUp]
public void SetUp() => Schedule(() =>
{
Child = toolTip = new SingerToolTip
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre
};
toolTip.Show();
});

[Test]
public void TestDisplayToolTip()
{
setTooltip("Test normal singer", singer =>
{
singer.Name = "Normal singer";
});

setTooltip("Test singer with description", singer =>
{
singer.Name = "Singer with description";
singer.Description = "International superstar vocaloid Hatsune Miku.";
});

setTooltip("Test singer with large description", singer =>
{
singer.Name = "Singer with large description";
singer.Description = "International superstar vocaloid Hatsune Miku on Sept 9 assumed her new position as Coronavirus Countermeasure Supporter in the Office for Novel Coronavirus Disease Control of the Japanese government’s Cabinet Secretariat.";
});

setTooltip("Test singer with english name", singer =>
{
singer.Name = "Singer with English name";
singer.EnglishName = "Hatsune Miku";
});

setTooltip("Test singer with romaji name", singer =>
{
singer.Name = "Singer with Romaji name";
singer.EnglishName = "Hatsune Miku";
});
}

private void setTooltip(string testName, Action<Singer> callBack)
{
AddStep(testName, () =>
{
var singer = new Singer(1);
callBack?.Invoke(singer);
toolTip.SetContent(singer);
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ private SingerMetadata createDefaultSinger()
{
metadata.CreateSinger(x =>
{
x.Name = $"Singer{x}";
x.RomajiName = $"[Romaji]Singer{x}";
x.EnglishName = $"[English]Singer{x}";
x.Name = $"Singer{i}";
x.RomajiName = $"[Romaji]Singer{i}";
x.EnglishName = $"[English]Singer{i}";
});
}

Expand Down
57 changes: 57 additions & 0 deletions osu.Game.Rulesets.Karaoke/Graphics/Cursor/BackgroundToolTip.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using osuTK;

namespace osu.Game.Rulesets.Karaoke.Graphics.Cursor
{
public abstract class BackgroundToolTip : VisibilityContainer, ITooltip
{
private readonly Box background;
private readonly Container content;

protected override Container<Drawable> Content => content;

public BackgroundToolTip()
{
AutoSizeAxes = Axes.Both;
Masking = true;
CornerRadius = 5;

InternalChildren = new Drawable[]
{
background = new Box
{
RelativeSizeAxes = Axes.Both
},
content = new Container
{
AutoSizeAxes = Axes.Both,
AutoSizeDuration = 200,
AutoSizeEasing = Easing.OutQuint,
Padding = new MarginPadding(10)
}
};
}

[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
background.Colour = colours.Gray3;
}

public abstract bool SetContent(object content);

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);
}
}
113 changes: 79 additions & 34 deletions osu.Game.Rulesets.Karaoke/Graphics/Cursor/SingerToolTip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,116 @@
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
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.Framework.Graphics.Textures;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Rulesets.Karaoke.Beatmaps.Metadatas;
using osuTK;
using osuTK.Graphics;
using System;

namespace osu.Game.Rulesets.Karaoke.Graphics.Cursor
{
public class SingerToolTip : VisibilityContainer, ITooltip
public class SingerToolTip : BackgroundToolTip
{
private readonly Box background;

public void Move(Vector2 pos) => Position = pos;
private readonly OsuSpriteText singerName;
private readonly OsuSpriteText singerEnglishName;
private readonly OsuSpriteText singerRomajiName;
private readonly OsuTextFlowContainer singerDescription;

public SingerToolTip()
{
AutoSizeAxes = Axes.Both;
Masking = true;
CornerRadius = 5;

Children = new Drawable[]
Child = new FillFlowContainer
{
background = new Box
AutoSizeAxes = Axes.Y,
Width = 300,
Direction = FillDirection.Vertical,
Spacing = new Vector2(15),
Children = new Drawable[]
{
RelativeSizeAxes = Axes.Both
},
new Container
{
AutoSizeAxes = Axes.Both,
AutoSizeDuration = 200,
AutoSizeEasing = Easing.OutQuint,

Padding = new MarginPadding(10),
Children = new Drawable[]
new DrawableSingerAvatar
{
new Box
Name = "Avatar",
Size = new Vector2(64)
},
new FillFlowContainer
{
Name = "Singer name",
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(5),
Children = new []
{
Size = new Vector2(100),
Colour = Color4.Red,
singerName = new OsuSpriteText
{
Name = "Singer name",
Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 20),
},
singerEnglishName = new OsuSpriteText
{
Name = "English name",
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 13),
Margin = new MarginPadding{ Bottom = 1}
}
}
},
singerRomajiName = new OsuSpriteText
{
Name = "Romaji name"
},
singerDescription = new OsuTextFlowContainer(s => s.Font = s.Font.With(size: 14))
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Colour = Color4.White.Opacity(0.75f),
Name = "Description",
}
}
};
}

[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
background.Colour = colours.Gray3;
}

public bool SetContent(object content)
public override bool SetContent(object content)
{
if(!(content is Singer singer))
return false;

// todo : implement
singerName.Text = singer.Name;
singerEnglishName.Text = singer.EnglishName != null ? $"({singer.EnglishName})" : "";
singerRomajiName.Text = singer.RomajiName;
singerDescription.Text = singer.Description ?? "<No description>";

return true;
}

protected override void PopIn() => this.FadeIn(200, Easing.OutQuint);
public class DrawableSingerAvatar : Container
{
[BackgroundDependencyLoader]
private void load(LargeTextureStore textures)
{
if (textures == null)
throw new ArgumentNullException(nameof(textures));

// todo : get real texture from beatmap
Texture texture = textures.Get(@"Online/avatar-guest");

protected override void PopOut() => this.FadeOut(200, Easing.OutQuint);
Add(new Sprite
{
RelativeSizeAxes = Axes.Both,
Texture = texture,
FillMode = FillMode.Fit,
Anchor = Anchor.Centre,
Origin = Anchor.Centre
});
}
}
}
}

0 comments on commit db532a3

Please sign in to comment.