mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 23:24:04 +09:00
Merge branch 'master' into add-missing-long-running
This commit is contained in:
@ -4,7 +4,6 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
@ -43,18 +42,7 @@ namespace osu.Game.Overlays.Changelog
|
||||
};
|
||||
req.Failure += _ => complete = true;
|
||||
|
||||
// This is done on a separate thread to support cancellation below
|
||||
Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
req.Perform(api);
|
||||
}
|
||||
catch
|
||||
{
|
||||
complete = true;
|
||||
}
|
||||
});
|
||||
api.PerformAsync(req);
|
||||
|
||||
while (!complete)
|
||||
{
|
||||
|
@ -191,15 +191,7 @@ namespace osu.Game.Overlays
|
||||
tcs.SetResult(false);
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
req.Perform(API);
|
||||
}
|
||||
catch
|
||||
{
|
||||
initialFetchTask = null;
|
||||
tcs.SetResult(false);
|
||||
}
|
||||
await API.PerformAsync(req);
|
||||
|
||||
await tcs.Task;
|
||||
});
|
||||
|
67
osu.Game/Overlays/Rankings/Tables/CountriesTable.cs
Normal file
67
osu.Game/Overlays/Rankings/Tables/CountriesTable.cs
Normal file
@ -0,0 +1,67 @@
|
||||
// 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.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using System;
|
||||
using osu.Game.Users;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace osu.Game.Overlays.Rankings.Tables
|
||||
{
|
||||
public class CountriesTable : RankingsTable<CountryStatistics>
|
||||
{
|
||||
public CountriesTable(int page, IReadOnlyList<CountryStatistics> rankings)
|
||||
: base(page, rankings)
|
||||
{
|
||||
}
|
||||
|
||||
protected override TableColumn[] CreateAdditionalHeaders() => new[]
|
||||
{
|
||||
new TableColumn("Active Users", Anchor.Centre, new Dimension(GridSizeMode.AutoSize)),
|
||||
new TableColumn("Play Count", Anchor.Centre, new Dimension(GridSizeMode.AutoSize)),
|
||||
new TableColumn("Ranked Score", Anchor.Centre, new Dimension(GridSizeMode.AutoSize)),
|
||||
new TableColumn("Avg. Score", Anchor.Centre, new Dimension(GridSizeMode.AutoSize)),
|
||||
new TableColumn("Performance", Anchor.Centre, new Dimension(GridSizeMode.AutoSize)),
|
||||
new TableColumn("Avg. Perf.", Anchor.Centre, new Dimension(GridSizeMode.AutoSize)),
|
||||
};
|
||||
|
||||
protected override Country GetCountry(CountryStatistics item) => item.Country;
|
||||
|
||||
protected override Drawable CreateFlagContent(CountryStatistics item) => new OsuSpriteText
|
||||
{
|
||||
Font = OsuFont.GetFont(size: TEXT_SIZE),
|
||||
Text = $@"{item.Country.FullName}",
|
||||
};
|
||||
|
||||
protected override Drawable[] CreateAdditionalContent(CountryStatistics item) => new Drawable[]
|
||||
{
|
||||
new ColoredRowText
|
||||
{
|
||||
Text = $@"{item.ActiveUsers:N0}",
|
||||
},
|
||||
new ColoredRowText
|
||||
{
|
||||
Text = $@"{item.PlayCount:N0}",
|
||||
},
|
||||
new ColoredRowText
|
||||
{
|
||||
Text = $@"{item.RankedScore:N0}",
|
||||
},
|
||||
new ColoredRowText
|
||||
{
|
||||
Text = $@"{item.RankedScore / Math.Max(item.ActiveUsers, 1):N0}",
|
||||
},
|
||||
new RowText
|
||||
{
|
||||
Text = $@"{item.Performance:N0}",
|
||||
},
|
||||
new ColoredRowText
|
||||
{
|
||||
Text = $@"{item.Performance / Math.Max(item.ActiveUsers, 1):N0}",
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
28
osu.Game/Overlays/Rankings/Tables/PerformanceTable.cs
Normal file
28
osu.Game/Overlays/Rankings/Tables/PerformanceTable.cs
Normal file
@ -0,0 +1,28 @@
|
||||
// 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 System.Collections.Generic;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Overlays.Rankings.Tables
|
||||
{
|
||||
public class PerformanceTable : UserBasedTable
|
||||
{
|
||||
public PerformanceTable(int page, IReadOnlyList<UserStatistics> rankings)
|
||||
: base(page, rankings)
|
||||
{
|
||||
}
|
||||
|
||||
protected override TableColumn[] CreateUniqueHeaders() => new[]
|
||||
{
|
||||
new TableColumn("Performance", Anchor.Centre, new Dimension(GridSizeMode.AutoSize)),
|
||||
};
|
||||
|
||||
protected override Drawable[] CreateUniqueContent(UserStatistics item) => new Drawable[]
|
||||
{
|
||||
new RowText { Text = $@"{item.PP:N0}", }
|
||||
};
|
||||
}
|
||||
}
|
140
osu.Game/Overlays/Rankings/Tables/RankingsTable.cs
Normal file
140
osu.Game/Overlays/Rankings/Tables/RankingsTable.cs
Normal file
@ -0,0 +1,140 @@
|
||||
// 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.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||
using osu.Game.Users;
|
||||
using osu.Game.Users.Drawables;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Overlays.Rankings.Tables
|
||||
{
|
||||
public abstract class RankingsTable<TModel> : TableContainer
|
||||
{
|
||||
protected const int TEXT_SIZE = 14;
|
||||
private const float horizontal_inset = 20;
|
||||
private const float row_height = 25;
|
||||
private const int items_per_page = 50;
|
||||
|
||||
private readonly int page;
|
||||
private readonly IReadOnlyList<TModel> rankings;
|
||||
|
||||
protected RankingsTable(int page, IReadOnlyList<TModel> rankings)
|
||||
{
|
||||
this.page = page;
|
||||
this.rankings = rankings;
|
||||
|
||||
RelativeSizeAxes = Axes.X;
|
||||
AutoSizeAxes = Axes.Y;
|
||||
|
||||
Padding = new MarginPadding { Horizontal = horizontal_inset };
|
||||
RowSize = new Dimension(GridSizeMode.Absolute, row_height);
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
FillFlowContainer backgroundFlow;
|
||||
|
||||
AddInternal(backgroundFlow = new FillFlowContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Depth = 1f,
|
||||
Margin = new MarginPadding { Top = row_height }
|
||||
});
|
||||
|
||||
rankings.ForEach(_ => backgroundFlow.Add(new TableRowBackground()));
|
||||
|
||||
Columns = mainHeaders.Concat(CreateAdditionalHeaders()).ToArray();
|
||||
Content = rankings.Select((s, i) => createContent((page - 1) * items_per_page + i, s)).ToArray().ToRectangular();
|
||||
}
|
||||
|
||||
private Drawable[] createContent(int index, TModel item) => new Drawable[] { createIndexDrawable(index), createMainContent(item) }.Concat(CreateAdditionalContent(item)).ToArray();
|
||||
|
||||
private static TableColumn[] mainHeaders => new[]
|
||||
{
|
||||
new TableColumn(string.Empty, Anchor.Centre, new Dimension(GridSizeMode.Absolute, 50)), // place
|
||||
new TableColumn(string.Empty, Anchor.CentreLeft, new Dimension(GridSizeMode.Distributed)), // flag and username (country name)
|
||||
};
|
||||
|
||||
protected abstract TableColumn[] CreateAdditionalHeaders();
|
||||
|
||||
protected abstract Drawable[] CreateAdditionalContent(TModel item);
|
||||
|
||||
protected override Drawable CreateHeader(int index, TableColumn column) => new HeaderText(column?.Header ?? string.Empty, HighlightedColumn());
|
||||
|
||||
protected abstract Country GetCountry(TModel item);
|
||||
|
||||
protected abstract Drawable CreateFlagContent(TModel item);
|
||||
|
||||
private OsuSpriteText createIndexDrawable(int index) => new OsuSpriteText
|
||||
{
|
||||
Text = $"#{index + 1}",
|
||||
Font = OsuFont.GetFont(size: TEXT_SIZE, weight: FontWeight.Bold)
|
||||
};
|
||||
|
||||
private FillFlowContainer createMainContent(TModel item) => new FillFlowContainer
|
||||
{
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Direction = FillDirection.Horizontal,
|
||||
Spacing = new Vector2(7, 0),
|
||||
Children = new[]
|
||||
{
|
||||
new UpdateableFlag(GetCountry(item))
|
||||
{
|
||||
Size = new Vector2(20, 13),
|
||||
ShowPlaceholderOnNull = false,
|
||||
},
|
||||
CreateFlagContent(item)
|
||||
}
|
||||
};
|
||||
|
||||
protected virtual string HighlightedColumn() => @"Performance";
|
||||
|
||||
private class HeaderText : OsuSpriteText
|
||||
{
|
||||
private readonly string highlighted;
|
||||
|
||||
public HeaderText(string text, string highlighted)
|
||||
{
|
||||
this.highlighted = highlighted;
|
||||
|
||||
Text = text;
|
||||
Font = OsuFont.GetFont(size: 12);
|
||||
Margin = new MarginPadding { Horizontal = 10 };
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
if (Text != highlighted)
|
||||
Colour = colours.GreySeafoamLighter;
|
||||
}
|
||||
}
|
||||
|
||||
protected class RowText : OsuSpriteText
|
||||
{
|
||||
public RowText()
|
||||
{
|
||||
Font = OsuFont.GetFont(size: TEXT_SIZE);
|
||||
Margin = new MarginPadding { Horizontal = 10 };
|
||||
}
|
||||
}
|
||||
|
||||
protected class ColoredRowText : RowText
|
||||
{
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
Colour = colours.GreySeafoamLighter;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
38
osu.Game/Overlays/Rankings/Tables/ScoresTable.cs
Normal file
38
osu.Game/Overlays/Rankings/Tables/ScoresTable.cs
Normal file
@ -0,0 +1,38 @@
|
||||
// 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 System.Collections.Generic;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Overlays.Rankings.Tables
|
||||
{
|
||||
public class ScoresTable : UserBasedTable
|
||||
{
|
||||
public ScoresTable(int page, IReadOnlyList<UserStatistics> rankings)
|
||||
: base(page, rankings)
|
||||
{
|
||||
}
|
||||
|
||||
protected override TableColumn[] CreateUniqueHeaders() => new[]
|
||||
{
|
||||
new TableColumn("Total Score", Anchor.Centre, new Dimension(GridSizeMode.AutoSize)),
|
||||
new TableColumn("Ranked Score", Anchor.Centre, new Dimension(GridSizeMode.AutoSize))
|
||||
};
|
||||
|
||||
protected override Drawable[] CreateUniqueContent(UserStatistics item) => new Drawable[]
|
||||
{
|
||||
new ColoredRowText
|
||||
{
|
||||
Text = $@"{item.TotalScore:N0}",
|
||||
},
|
||||
new RowText
|
||||
{
|
||||
Text = $@"{item.RankedScore:N0}",
|
||||
}
|
||||
};
|
||||
|
||||
protected override string HighlightedColumn() => @"Ranked Score";
|
||||
}
|
||||
}
|
56
osu.Game/Overlays/Rankings/Tables/TableRowBackground.cs
Normal file
56
osu.Game/Overlays/Rankings/Tables/TableRowBackground.cs
Normal file
@ -0,0 +1,56 @@
|
||||
// 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.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Graphics;
|
||||
using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Overlays.Rankings.Tables
|
||||
{
|
||||
public class TableRowBackground : CompositeDrawable
|
||||
{
|
||||
private const int fade_duration = 100;
|
||||
|
||||
private readonly Box background;
|
||||
|
||||
private Color4 idleColour;
|
||||
private Color4 hoverColour;
|
||||
|
||||
public TableRowBackground()
|
||||
{
|
||||
RelativeSizeAxes = Axes.X;
|
||||
Height = 25;
|
||||
|
||||
CornerRadius = 3;
|
||||
Masking = true;
|
||||
|
||||
InternalChild = background = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
};
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
background.Colour = idleColour = colours.GreySeafoam;
|
||||
hoverColour = colours.GreySeafoamLight;
|
||||
}
|
||||
|
||||
protected override bool OnHover(HoverEvent e)
|
||||
{
|
||||
background.FadeColour(hoverColour, fade_duration, Easing.OutQuint);
|
||||
return base.OnHover(e);
|
||||
}
|
||||
|
||||
protected override void OnHoverLost(HoverLostEvent e)
|
||||
{
|
||||
background.FadeColour(idleColour, fade_duration, Easing.OutQuint);
|
||||
base.OnHoverLost(e);
|
||||
}
|
||||
}
|
||||
}
|
56
osu.Game/Overlays/Rankings/Tables/UserBasedTable.cs
Normal file
56
osu.Game/Overlays/Rankings/Tables/UserBasedTable.cs
Normal file
@ -0,0 +1,56 @@
|
||||
// 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 System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Overlays.Rankings.Tables
|
||||
{
|
||||
public abstract class UserBasedTable : RankingsTable<UserStatistics>
|
||||
{
|
||||
protected UserBasedTable(int page, IReadOnlyList<UserStatistics> rankings)
|
||||
: base(page, rankings)
|
||||
{
|
||||
}
|
||||
|
||||
protected override TableColumn[] CreateAdditionalHeaders() => new[]
|
||||
{
|
||||
new TableColumn("Accuracy", Anchor.Centre, new Dimension(GridSizeMode.AutoSize)),
|
||||
new TableColumn("Play Count", Anchor.Centre, new Dimension(GridSizeMode.AutoSize)),
|
||||
}.Concat(CreateUniqueHeaders()).Concat(new[]
|
||||
{
|
||||
new TableColumn("SS", Anchor.Centre, new Dimension(GridSizeMode.AutoSize)),
|
||||
new TableColumn("S", Anchor.Centre, new Dimension(GridSizeMode.AutoSize)),
|
||||
new TableColumn("A", Anchor.Centre, new Dimension(GridSizeMode.AutoSize)),
|
||||
}).ToArray();
|
||||
|
||||
protected sealed override Country GetCountry(UserStatistics item) => item.User.Country;
|
||||
|
||||
protected sealed override Drawable CreateFlagContent(UserStatistics item)
|
||||
{
|
||||
var username = new LinkFlowContainer(t => t.Font = OsuFont.GetFont(size: TEXT_SIZE)) { AutoSizeAxes = Axes.Both };
|
||||
username.AddUserLink(item.User);
|
||||
return username;
|
||||
}
|
||||
|
||||
protected sealed override Drawable[] CreateAdditionalContent(UserStatistics item) => new[]
|
||||
{
|
||||
new ColoredRowText { Text = $@"{item.Accuracy:F2}%", },
|
||||
new ColoredRowText { Text = $@"{item.PlayCount:N0}", },
|
||||
}.Concat(CreateUniqueContent(item)).Concat(new[]
|
||||
{
|
||||
new ColoredRowText { Text = $@"{item.GradesCount.SS + item.GradesCount.SSPlus:N0}", },
|
||||
new ColoredRowText { Text = $@"{item.GradesCount.S + item.GradesCount.SPlus:N0}", },
|
||||
new ColoredRowText { Text = $@"{item.GradesCount.A:N0}", }
|
||||
}).ToArray();
|
||||
|
||||
protected abstract TableColumn[] CreateUniqueHeaders();
|
||||
|
||||
protected abstract Drawable[] CreateUniqueContent(UserStatistics item);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user