Skip to content

Commit

Permalink
Song select improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
flustix committed Sep 22, 2023
1 parent ce0648b commit 51cb326
Show file tree
Hide file tree
Showing 13 changed files with 794 additions and 369 deletions.
4 changes: 3 additions & 1 deletion fluXis.Game/Database/FluXisRealm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ public class FluXisRealm : IDisposable
/// 7 - Make RealmScore.Mods a string
/// 8 - Added PlayerID to RealmScore
/// 9 - Removed RealmJudgements and moved to RealmScore
/// 10 - Changed storage system
/// 11 - Added ColorHex to RealmMapMetadata
/// </summary>
private const int schema_version = 10;
private const int schema_version = 11;

private Realm updateRealm;

Expand Down
6 changes: 6 additions & 0 deletions fluXis.Game/Database/Maps/RealmMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ public virtual Texture GetBackground()
return backgrounds?.Get(MapSet.GetPathForFile(Metadata.Background));
}

public virtual Stream GetBackgroundStream()
{
var backgrounds = MapSet.Resources?.BackgroundStore;
return backgrounds?.GetStream(MapSet.GetPathForFile(Metadata.Background));
}

public virtual Texture GetPanelBackground()
{
var croppedBackgrounds = MapSet.Resources?.CroppedBackgroundStore;
Expand Down
1 change: 1 addition & 0 deletions fluXis.Game/Database/Maps/RealmMapMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class RealmMapMetadata : RealmObject
public string Background { get; set; } = string.Empty;
public string Audio { get; set; } = string.Empty;
public int PreviewTime { get; set; }
public string ColorHex { get; set; }

[UsedImplicitly]
public RealmMapMetadata()
Expand Down
39 changes: 39 additions & 0 deletions fluXis.Game/Graphics/Background/MapBackground.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
using System.Collections.Generic;
using System.Linq;
using fluXis.Game.Database.Maps;
using fluXis.Game.Import;
using fluXis.Game.Skinning;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors.Quantization;

namespace fluXis.Game.Graphics.Background;

Expand All @@ -22,4 +29,36 @@ private void load(SkinManager skinManager)
else
Texture = (Cropped ? Map.GetPanelBackground() : Map.GetBackground()) ?? skinManager.GetDefaultBackground();
}

public Colour4 GetColour()
{
var stream = Map?.GetBackgroundStream();

if (stream == null)
return Colour4.Transparent;

var image = Image.Load<Rgba32>(stream);
image.Mutate(x => x.Quantize(new WuQuantizer(new QuantizerOptions { MaxColors = 10 })));

var dict = new Dictionary<Rgba32, int>();

for (var x = 0; x < image.Width; x++)
{
for (var y = 0; y < image.Height; y++)
{
var pixel = image[x, y];

if (pixel.A == 0)
continue;

if (dict.ContainsKey(pixel))
dict[pixel]++;
else
dict.Add(pixel, 1);
}
}

var orderedByLight = dict.Select(x => x.Key).Select(x => new Colour4(x.R, x.G, x.B, 255)).OrderBy(x => x.ToHSL().Z).ToList();
return orderedByLight.ElementAt(orderedByLight.Count / 2);
}
}
25 changes: 25 additions & 0 deletions fluXis.Game/Graphics/UserInterface/Color/FluXisColors.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osuTK;

namespace fluXis.Game.Graphics.UserInterface.Color;

Expand Down Expand Up @@ -51,6 +52,30 @@ public static bool IsBright(Colour4 color)
return hsl.Z > .5f;
}

public static Colour4 DifficultyZero => Colour4.FromHex("#888888");
public static Colour4 Difficulty0 => Colour4.FromHex("#3355FF");
public static Colour4 Difficulty5 => Colour4.FromHex("#3489FF");
public static Colour4 Difficulty10 => Colour4.FromHex("#35BCFF");
public static Colour4 Difficulty15 => Colour4.FromHex("#33FFDD");
public static Colour4 Difficulty20 => Colour4.FromHex("#55FF33");
public static Colour4 Difficulty25 => Colour4.FromHex("#FEFF33");
public static Colour4 Difficulty30 => Colour4.FromHex("#FF3333");

public static Colour4 GetDifficultyColor(float difficulty)
{
return difficulty switch
{
<= 0 => DifficultyZero,
<= 5 => ColourInfo.GradientHorizontal(Difficulty0, Difficulty5).Interpolate(new Vector2(difficulty / 5, 0)),
<= 10 => ColourInfo.GradientHorizontal(Difficulty5, Difficulty10).Interpolate(new Vector2((difficulty - 5) / 5, 0)),
<= 15 => ColourInfo.GradientHorizontal(Difficulty10, Difficulty15).Interpolate(new Vector2((difficulty - 10) / 5, 0)),
<= 20 => ColourInfo.GradientHorizontal(Difficulty15, Difficulty20).Interpolate(new Vector2((difficulty - 15) / 5, 0)),
<= 25 => ColourInfo.GradientHorizontal(Difficulty20, Difficulty25).Interpolate(new Vector2((difficulty - 20) / 5, 0)),
<= 30 => ColourInfo.GradientHorizontal(Difficulty25, Difficulty30).Interpolate(new Vector2((difficulty - 25) / 5, 0)),
_ => Difficulty30
};
}

public static Colour4 GetStatusColor(int status)
{
return status switch
Expand Down
119 changes: 83 additions & 36 deletions fluXis.Game/Screens/Select/Info/Scores/ScoreList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
using fluXis.Game.Online.Fluxel;
using Newtonsoft.Json;
using osu.Framework.Allocation;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Shapes;
using osuTK;

namespace fluXis.Game.Screens.Select.Info.Scores;
Expand All @@ -43,7 +44,7 @@ public partial class ScoreList : GridContainer

private FluXisSpriteText noScoresText;
private FluXisScrollContainer scrollContainer;
private FillFlowContainer<ClickableText> typeSwitcher;
private FillFlowContainer<LeaderboardTypeButton> typeSwitcher;
private LoadingIcon loadingIcon;

[BackgroundDependencyLoader]
Expand All @@ -60,25 +61,49 @@ private void load()
{
new Drawable[]
{
typeSwitcher = new FillFlowContainer<ClickableText>
new Container
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(40),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.X,
Height = 50,
CornerRadius = 10,
Masking = true,
Shear = new Vector2(-.1f, 0),
Margin = new MarginPadding { Bottom = 10 },
Children = new ClickableText[]
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Shadow,
Colour = Colour4.Black.Opacity(.25f),
Radius = 5,
Offset = new Vector2(0, 1)
},
Children = new Drawable[]
{
new()
new Box
{
ScoreList = this,
Type = ScoreListType.Global
RelativeSizeAxes = Axes.Both,
Colour = FluXisColors.Background2
},
new()
new FluXisSpriteText
{
ScoreList = this,
Type = ScoreListType.Local
Text = "Scores",
FontSize = 32,
Shear = new Vector2(.1f, 0),
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
X = 20
},
typeSwitcher = new FillFlowContainer<LeaderboardTypeButton>
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
X = -40,
Children = Enum.GetValues<ScoreListType>().Select(t => new LeaderboardTypeButton
{
Type = t,
ScoreList = this
}).ToList()
}
}
}
Expand All @@ -88,6 +113,7 @@ private void load()
new FluXisContextMenuContainer
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Right = 20 },
Children = new Drawable[]
{
noScoresText = new FluXisSpriteText
Expand All @@ -114,8 +140,6 @@ private void load()
}
}
};

updateTabs();
}

public void Refresh()
Expand All @@ -124,11 +148,8 @@ public void Refresh()
return;

SetMap(map);
updateTabs();
}

private void updateTabs() => typeSwitcher.Children.ForEach(c => c.Selected = c.Type == type);

public void SetMap(RealmMap map)
{
if (!IsLoaded)
Expand Down Expand Up @@ -176,7 +197,7 @@ private void loadScores(CancellationToken cancellationToken)
case ScoreListType.Global:
if (map.OnlineID == -1)
{
noScoresText.Text = "Scores are not available for this map!";
noScoresText.Text = "This map is not submitted online!";
Schedule(() =>
{
noScoresText.FadeIn(200);
Expand Down Expand Up @@ -220,6 +241,15 @@ private void loadScores(CancellationToken cancellationToken)
}

break;

default:
noScoresText.Text = $"{type} leaderboards are not available yet!";
Schedule(() =>
{
noScoresText.FadeIn(200);
loadingIcon.FadeOut(200);
});
return;
}

Schedule(() =>
Expand All @@ -246,30 +276,45 @@ private void addScore(ScoreListEntry entry, int index = -1)
scrollContainer.ScrollContent.Add(entry);
}

private partial class ClickableText : ClickableContainer
private partial class LeaderboardTypeButton : ClickableContainer
{
public ScoreListType Type { get; init; }
public ScoreList ScoreList { get; init; }

public bool Selected
{
set => Schedule(() => text.FadeColour(value ? FluXisColors.Text : FluXisColors.Text2, 200));
}

private FluXisSpriteText text;

[BackgroundDependencyLoader]
private void load()
{
AutoSizeAxes = Axes.Both;
Child = text = new FluXisSpriteText
Width = 100;
Height = 30;
Shear = new Vector2(.2f, 0);
CornerRadius = 5;
Masking = true;

InternalChildren = new Drawable[]
{
Text = Type.ToString(),
FontSize = 32,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Colour = FluXisColors.Text2,
Shadow = true
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Type switch
{
ScoreListType.Local => Colour4.FromHSV(120f / 360f, .6f, 1f),
ScoreListType.Global => Colour4.FromHSV(30f / 360f, .6f, 1f),
ScoreListType.Country => Colour4.FromHSV(0f, .6f, 1f),
ScoreListType.Friends => Colour4.FromHSV(210f / 360f, .6f, 1f),
_ => FluXisColors.Background4
}
},
text = new FluXisSpriteText
{
Text = Type.ToString(),
FontSize = 18,
Shear = new Vector2(-.1f, 0),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Colour = FluXisColors.TextDark
}
};

Action = () =>
Expand All @@ -284,5 +329,7 @@ private void load()
public enum ScoreListType
{
Local,
Global
Global,
Country,
Friends
}
17 changes: 11 additions & 6 deletions fluXis.Game/Screens/Select/Info/SelectMapInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,26 +92,31 @@ private void load()
},
new Container
{
RelativeSizeAxes = Axes.Both,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = new MarginPadding(20),
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Children = new Drawable[]
{
titleText = new FluXisSpriteText
{
Text = "No Map Selected",
FontSize = 60,
RelativeSizeAxes = Axes.X,
FontSize = 60,
Text = "No Map Selected",
Truncate = true,
Shadow = true,
Anchor = Anchor.CentreLeft,
Origin = Anchor.BottomLeft,
Y = 10
},
artistText = new FluXisSpriteText
{
Text = "Please select a map to view info",
FontSize = 32,
RelativeSizeAxes = Axes.X,
FontSize = 32,
Text = "Please select a map to view info",
Truncate = true,
Shadow = true,
Anchor = Anchor.CentreLeft,
Origin = Anchor.TopLeft
}
Expand Down Expand Up @@ -246,7 +251,7 @@ private void load()
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Bottom = 20, Right = 20 },
Padding = new MarginPadding { Bottom = 20 },
Child = ScoreList = new ScoreList
{
MapInfo = this
Expand Down
Loading

0 comments on commit 51cb326

Please sign in to comment.