Skip to content

Commit

Permalink
Add tooltips to MapCard
Browse files Browse the repository at this point in the history
  • Loading branch information
flustix committed Sep 23, 2024
1 parent b5b13fd commit 3447c97
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 20 deletions.
23 changes: 16 additions & 7 deletions fluXis.Game.Tests/Graphics/TestMapCard.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using fluXis.Game.Map.Drawables;
using fluXis.Game.Map.Drawables.Card;
using fluXis.Game.Overlay.Mouse;
using fluXis.Shared.Components.Maps;
using fluXis.Shared.Components.Users;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osuTK;
Expand All @@ -15,16 +17,23 @@ public partial class TestMapCard : FluXisTestScene
{
private FillFlowContainer container;

[Resolved]
private GlobalCursorOverlay cursor { get; set; }

[SetUp]
public void Setup() => Schedule(() =>
{
Child = container = new FillFlowContainer()
Child = new GlobalTooltipContainer(cursor.Cursor)
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Spacing = new Vector2(10),
Anchor = Anchor.Centre,
Origin = Anchor.Centre
RelativeSizeAxes = Axes.Both,
Child = container = new FillFlowContainer()
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Spacing = new Vector2(10),
Anchor = Anchor.Centre,
Origin = Anchor.Centre
}
};
});

Expand Down
93 changes: 93 additions & 0 deletions fluXis.Game/Map/Drawables/Card/MapCard-Tooltip.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using System.Collections.Generic;
using System.Linq;
using fluXis.Game.Graphics.Sprites;
using fluXis.Game.Graphics.UserInterface;
using fluXis.Game.Graphics.UserInterface.Color;
using fluXis.Game.Overlay.Mouse;
using fluXis.Shared.Components.Maps;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osuTK;

namespace fluXis.Game.Map.Drawables.Card;

public partial class MapCard
{
private partial class TooltipEntry : GridContainer
{
public TooltipEntry(APIMap map)
{
Size = new Vector2(320, 14);
ColumnDimensions = new Dimension[]
{
new(GridSizeMode.Absolute, 32),
new(),
new(GridSizeMode.Absolute, 48)
};

Content = new[]
{
new Drawable[]
{
new RoundedChip
{
AutoSizeAxes = Axes.None,
Size = new Vector2(32, 14),
WebFontSize = 10,
BackgroundColour = FluXisColors.GetKeyColor(map.Mode),
TextColour = Colour4.Black.Opacity(.75f),
Text = $"{map.Mode}K"
},
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Horizontal = 6 },
Child = new TruncatingText
{
RelativeSizeAxes = Axes.X,
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Text = $"{map.Difficulty}",
WebFontSize = 12
}
},
new DifficultyChip
{
Size = new Vector2(48, 14),
WebFontSize = 10,
Rating = map.NotesPerSecond
}
}
};
}
}

private partial class MapCardTooltip : CustomTooltipContainer<APIMapSet>
{
private FillFlowContainer flow { get; }
private List<APIMap> maps;

public MapCardTooltip()
{
Child = flow = new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Padding = new MarginPadding(12),
Spacing = new Vector2(8)
};
}

public override void SetContent(APIMapSet content)
{
var list = content.Maps;
list.Sort((a, b) => a.NotesPerSecond.CompareTo(b.NotesPerSecond));

if (maps is not null && maps.SequenceEqual(list))
return;

maps = list;
flow.ChildrenEnumerable = list.Select(m => new TooltipEntry(m));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
using osu.Framework.Platform;
using osuTK;

namespace fluXis.Game.Map.Drawables;
namespace fluXis.Game.Map.Drawables.Card;

public partial class MapCard : Container, IHasContextMenu
public partial class MapCard : Container, IHasCustomTooltip<APIMapSet>, IHasContextMenu
{
[Resolved]
private MapStore maps { get; set; }
Expand Down Expand Up @@ -67,6 +67,8 @@ public MenuItem[] ContextMenuItems
}
}

public APIMapSet TooltipContent => MapSet;

public int CardWidth { get; init; } = 430;
public APIMapSet MapSet { get; }
public Action<APIMapSet> OnClickAction { get; set; }
Expand Down Expand Up @@ -348,6 +350,8 @@ protected override bool OnDoubleClick(DoubleClickEvent e)
return true;
}

public ITooltip<APIMapSet> GetCustomTooltip() => new MapCardTooltip();

private void selectAndShow()
{
if (localSet == null)
Expand Down
4 changes: 2 additions & 2 deletions fluXis.Game/Overlay/Mouse/CustomTooltipContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace fluXis.Game.Overlay.Mouse;

public abstract partial class CustomTooltipContainer<T> : CustomTooltipContainer, ITooltip<T>
{
public override void SetContent(object content) => SetContent((T)content);
public sealed override void SetContent(object content) => SetContent((T)content);
public abstract void SetContent(T content);
}

Expand All @@ -24,7 +24,7 @@ public abstract partial class CustomTooltipContainer : VisibilityContainer, IToo
protected CustomTooltipContainer()
{
AutoSizeAxes = Axes.Both;
CornerRadius = 5;
CornerRadius = 8;
Masking = true;
AutoSizeEasing = Easing.OutQuint;
EdgeEffect = FluXisStyles.ShadowSmall;
Expand Down
6 changes: 0 additions & 6 deletions fluXis.Game/Overlay/Mouse/GlobalTooltipContainer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using fluXis.Game.Graphics;
using fluXis.Game.Graphics.UserInterface.Text;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Cursor;
Expand All @@ -24,11 +23,6 @@ public partial class TextTooltip : CustomTooltipContainer<LocalisableString>

public TextTooltip()
{
CornerRadius = 5;
Masking = true;
AutoSizeEasing = Easing.OutQuint;
EdgeEffect = FluXisStyles.ShadowSmall;

Child = text = new FluXisTextFlow()
{
AutoSizeAxes = Axes.Both,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using fluXis.Game.Graphics.Sprites;
using fluXis.Game.Map.Drawables;
using fluXis.Game.Map.Drawables.Card;
using fluXis.Shared.Components.Maps;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
Expand Down
2 changes: 1 addition & 1 deletion fluXis.Game/Screens/Browse/Info/BrowseInfoMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private void load()
},
new DifficultyChip
{
Rating = map.Rating,
Rating = map.NotesPerSecond,
Width = 70,
Height = 20,
Anchor = Anchor.CentreRight,
Expand Down
2 changes: 1 addition & 1 deletion fluXis.Game/Screens/Browse/MapBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using fluXis.Game.Graphics.UserInterface.Panel;
using fluXis.Game.Input;
using fluXis.Game.Localization;
using fluXis.Game.Map.Drawables;
using fluXis.Game.Map.Drawables.Card;
using fluXis.Game.Online.Activity;
using fluXis.Game.Online.API;
using fluXis.Game.Online.API.Requests.MapSets;
Expand Down

0 comments on commit 3447c97

Please sign in to comment.