Skip to content

Commit

Permalink
Add mapset flags
Browse files Browse the repository at this point in the history
  • Loading branch information
flustix committed Jul 6, 2024
1 parent 8327943 commit 1db4876
Show file tree
Hide file tree
Showing 6 changed files with 221 additions and 85 deletions.
101 changes: 91 additions & 10 deletions fluXis.Game.Tests/Graphics/TestMapCard.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,104 @@
using fluXis.Game.Map.Drawables;
using fluXis.Game.Online.API.Requests.MapSets;
using fluXis.Game.Online.Fluxel;
using osu.Framework.Allocation;
using System;
using System.Collections.Generic;
using System.Linq;
using fluXis.Game.Map.Drawables;
using fluXis.Shared.Components.Maps;
using fluXis.Shared.Components.Users;
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osuTK;

namespace fluXis.Game.Tests.Graphics;

public partial class TestMapCard : FluXisTestScene
{
[BackgroundDependencyLoader]
private void load(IAPIClient api)
{
var req = new MapSetRequest(4);
api.PerformRequest(req);
private FillFlowContainer container;

Add(new MapCard(req.Response.Data)
[SetUp]
public void Setup() => Schedule(() =>
{
Child = container = new FillFlowContainer()
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Spacing = new Vector2(10),
Anchor = Anchor.Centre,
Origin = Anchor.Centre
};
});

private APIMapSet create(Action<APIMapSet> func = null)
{
var set = new APIMapSet()
{
ID = 1,
Creator = APIUser.CreateUnknown(1),
Title = "super cool song with a long name",
Artist = "super cool artist",
Source = "somewhere",
Tags = new[] { "some", "cool", "and fitting", "tags" },
Maps = new List<APIMap>
{
new()
{
ID = 1,
MapSetID = 1,
Mapper = APIUser.CreateUnknown(1),
SHA256Hash = "veryvalidhash",
Difficulty = "hard",
Title = "super cool song",
Artist = "super cool artist",
Source = "somewhere",
Tags = "some, cool, and fitting, tags",
Mode = 4,
Status = 0,
BPM = 120,
Length = 12000,
NoteCount = 456,
LongNoteCount = 32,
MaxCombo = 488,
NotesPerSecond = 14.24,
Rating = 8,
UpVotes = 4,
DownVotes = 6,
FileName = "195769352.fsc"
}
}
};

func?.Invoke(set);
return set;
}

[Test]
public void TestDefault()
{
AddStep("add default", () => container.Child = new MapCard(create()));
}

[Test]
public void TestFlags()
{
AddStep("add normal", () => container.Add(new MapCard(create())));
AddStep("add explicit", () => container.Add(new MapCard(create(s => s.Flags |= MapSetFlag.Explicit))));
AddStep("add featured", () => container.Add(new MapCard(create(s => s.Flags |= MapSetFlag.FeaturedArtist))));
}

[Test]
public void TestRankStatus()
{
var states = Enumerable.Range(0, 4);
AddStep("add all", () =>
{
foreach (var state in states)
container.Add(new MapCard(create(s => s.Status = state)));
});
}

[Test]
public void TestNullData()
{
AddStep("add null", () => container.Child = new MapCard(null));
}
}
48 changes: 48 additions & 0 deletions fluXis.Game/Graphics/UserInterface/RoundedChip.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using fluXis.Game.Graphics.Sprites;
using fluXis.Game.Graphics.UserInterface.Color;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;

namespace fluXis.Game.Graphics.UserInterface;

public partial class RoundedChip : CircularContainer
{
public string Text { get; init; } = "text";
public float FontSize { get; init; } = FluXisSpriteText.GetWebFontSize(12);
public ColourInfo TextColour { get; init; } = FluXisColors.Text.Opacity(.75f);
public ColourInfo BackgroundColour { get; init; } = FluXisColors.Background2;
public float SidePadding { get; init; } = 12;

public RoundedChip()
{
AutoSizeAxes = Axes.X;
Height = 20;
}

[BackgroundDependencyLoader]
private void load()
{
Masking = true;

InternalChildren = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = BackgroundColour
},
new FluXisSpriteText
{
Text = Text,
FontSize = FontSize,
Colour = TextColour,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Margin = new MarginPadding { Horizontal = SidePadding }
}
};
}
}
133 changes: 64 additions & 69 deletions fluXis.Game/Map/Drawables/MapCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using fluXis.Game.Audio;
using fluXis.Game.Database.Maps;
using fluXis.Game.Graphics;
using fluXis.Game.Graphics.Containers;
using fluXis.Game.Graphics.Sprites;
using fluXis.Game.Graphics.UserInterface;
using fluXis.Game.Graphics.UserInterface.Color;
Expand All @@ -14,6 +15,7 @@
using fluXis.Shared.Utils.Extensions;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Extensions.EnumExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
Expand Down Expand Up @@ -72,8 +74,8 @@ public MenuItem[] ContextMenuItems
private Container content;
private SectionedGradient gradient;

private bool downloaded => maps.MapSets.Any(x => x.OnlineID == MapSet.ID);
private bool downloading => maps.DownloadQueue.Any(x => x == MapSet.ID);
private bool downloaded => maps.MapSets.Any(x => x.OnlineID == MapSet?.ID);
private bool downloading => maps.DownloadQueue.Any(x => x == MapSet?.ID);

private bool canDelete
{
Expand All @@ -84,15 +86,15 @@ private bool canDelete
if (user == null)
return false;

if (user.IsDeveloper() || user.CanModerate() || MapSet.Creator.ID == user.ID)
if (user.IsDeveloper() || user.CanModerate() || MapSet?.Creator.ID == user.ID)
return true;

return false;
}
}

[CanBeNull]
private RealmMapSet localSet => maps.MapSets.FirstOrDefault(x => x.OnlineID == MapSet.ID);
private RealmMapSet localSet => maps.MapSets.FirstOrDefault(x => x.OnlineID == MapSet?.ID);

public MapCard(APIMapSet mapSet)
{
Expand All @@ -118,7 +120,7 @@ private void load()
},
new FluXisSpriteText
{
Text = "Missing mapset data.",
Text = "MapSet was not found.",
Anchor = Anchor.Centre,
Origin = Anchor.Centre
}
Expand Down Expand Up @@ -146,9 +148,11 @@ private void load()
RelativeSizeAxes = Axes.Both,
Colour = FluXisColors.Background3
},
new DelayedLoadUnloadWrapper(() => new DrawableOnlineBackground(MapSet))
new LoadWrapper<DrawableOnlineBackground>
{
RelativeSizeAxes = Axes.Both
RelativeSizeAxes = Axes.Both,
LoadContent = () => new DrawableOnlineBackground(MapSet),
OnComplete = d => d.FadeInFromZero(400)
},
gradient = new SectionedGradient
{
Expand All @@ -170,15 +174,13 @@ private void load()
{
new Drawable[]
{
new Container
new LoadWrapper<DrawableOnlineCover>
{
Size = new Vector2(112),
CornerRadius = 16,
Masking = true,
Child = new DelayedLoadUnloadWrapper(() => new DrawableOnlineCover(MapSet))
{
RelativeSizeAxes = Axes.Both
}
LoadContent = () => new DrawableOnlineCover(MapSet),
OnComplete = d => d.FadeInFromZero(400)
},
new Container
{
Expand All @@ -194,12 +196,39 @@ private void load()
Spacing = new Vector2(-3),
Children = new Drawable[]
{
new TruncatingText
new GridContainer
{
RelativeSizeAxes = Axes.X,
Text = MapSet.Title,
WebFontSize = 18,
Shadow = true
AutoSizeAxes = Axes.Y,
RowDimensions = new Dimension[] { new(GridSizeMode.AutoSize) },
ColumnDimensions = new Dimension[]
{
new(),
new(GridSizeMode.AutoSize)
},
Content = new[]
{
new Drawable[]
{
new TruncatingText
{
RelativeSizeAxes = Axes.X,
Text = MapSet.Title,
WebFontSize = 18,
Shadow = true
},
new RoundedChip
{
Alpha = MapSet.Flags.HasFlagFast(MapSetFlag.Explicit) ? 1f : 0f,
Text = "EXPLICIT",
BackgroundColour = Colour4.Black.Opacity(.5f),
TextColour = Colour4.White,
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Margin = new MarginPadding { Left = 8 }
}
}
}
},
new TruncatingText
{
Expand All @@ -222,69 +251,32 @@ private void load()
{
RelativeSizeAxes = Axes.X,
Height = 20,
Margin = new MarginPadding { Top = 5 },
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Children = new Drawable[]
{
new CircularContainer
new RoundedChip
{
AutoSizeAxes = Axes.X,
RelativeSizeAxes = Axes.Y,
Masking = true,
EdgeEffect = FluXisStyles.ShadowSmallNoOffset,
Children = new Drawable[]
Text = MapSet.Status switch
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = FluXisColors.GetStatusColor(MapSet.Status)
},
new FluXisSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = MapSet.Status switch
{
0 => "UNSUBMITTED",
1 => "PENDING",
2 => "IMPURE",
3 => "PURE",
_ => "UNKNOWN"
},
Colour = Colour4.Black,
WebFontSize = 12,
Alpha = .75f,
Margin = new MarginPadding { Horizontal = 8 }
}
}
0 => "UNSUBMITTED",
1 => "PENDING",
2 => "IMPURE",
3 => "PURE",
_ => "UNKNOWN"
},
TextColour = Colour4.Black.Opacity(.75f),
BackgroundColour = FluXisColors.GetStatusColor(MapSet.Status),
EdgeEffect = FluXisStyles.ShadowSmallNoOffset,
},
new CircularContainer
new RoundedChip
{
AutoSizeAxes = Axes.X,
RelativeSizeAxes = Axes.Y,
Masking = true,
Text = getKeymodeString(),
TextColour = Colour4.Black.Opacity(.75f),
BackgroundColour = getKeymodeColor(),
EdgeEffect = FluXisStyles.ShadowSmallNoOffset,
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = getKeymodeColor()
},
new FluXisSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
WebFontSize = 12,
Alpha = .75f,
Colour = Colour4.Black,
Text = getKeymodeString(),
Margin = new MarginPadding { Horizontal = 8 }
}
}
Origin = Anchor.CentreRight
}
}
}
Expand Down Expand Up @@ -380,6 +372,9 @@ private ColourInfo getKeymodeColor()

private void updateState()
{
if (content == null || background == null)
return;

bool shouldShow = downloading || downloaded;

content.ResizeWidthTo(shouldShow ? CardWidth - 10 : CardWidth, 400, Easing.OutQuint);
Expand Down
Loading

0 comments on commit 1db4876

Please sign in to comment.