1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-06 08:22:56 +08:00

initial commit to allow filtering / selecting different tabs / etc

still wip tho
bleh


bleh
This commit is contained in:
Aergwyn 2017-12-24 20:25:23 +01:00
parent 45e4c09cb8
commit f00676e6ee
3 changed files with 119 additions and 54 deletions

View File

@ -22,7 +22,7 @@ namespace osu.Game.Overlays.Social
public enum SocialSortCriteria public enum SocialSortCriteria
{ {
Rank, Rank,
//Location, Location,
//[Description("Time Zone")] //[Description("Time Zone")]
//TimeZone, //TimeZone,
//[Description("World Map")] //[Description("World Map")]

View File

@ -55,8 +55,8 @@ namespace osu.Game.Overlays.Social
{ {
[Description("Online Players")] [Description("Online Players")]
OnlinePlayers, OnlinePlayers,
//[Description("Online Friends")] [Description("Online Friends")]
//OnlineFriends, OnlineFriends,
//[Description("Online Team Members")] //[Description("Online Team Members")]
//OnlineTeamMembers, //OnlineTeamMembers,
//[Description("Chat Channels")] //[Description("Chat Channels")]

View File

@ -9,19 +9,23 @@ using OpenTK.Graphics;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Cursor;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Online.API.Requests; using osu.Game.Online.API.Requests;
using osu.Game.Overlays.SearchableList; using osu.Game.Overlays.SearchableList;
using osu.Game.Overlays.Social; using osu.Game.Overlays.Social;
using osu.Game.Users; using osu.Game.Users;
using osu.Framework.Configuration;
using osu.Framework.Threading;
using System.Threading.Tasks;
namespace osu.Game.Overlays namespace osu.Game.Overlays
{ {
public class SocialOverlay : SearchableListOverlay<SocialTab, SocialSortCriteria, SortDirection>, IOnlineComponent public class SocialOverlay : SearchableListOverlay<SocialTab, SocialSortCriteria, SortDirection>
{ {
private readonly FillFlowContainer<UserPanel> panelFlow; private APIAccess api;
private FillFlowContainer<UserPanel> panels;
protected override Color4 BackgroundColour => OsuColour.FromHex(@"60284b"); protected override Color4 BackgroundColour => OsuColour.FromHex(@"60284b");
protected override Color4 TrianglesColourLight => OsuColour.FromHex(@"672b51"); protected override Color4 TrianglesColourLight => OsuColour.FromHex(@"672b51");
@ -30,28 +34,19 @@ namespace osu.Game.Overlays
protected override SearchableListHeader<SocialTab> CreateHeader() => new Header(); protected override SearchableListHeader<SocialTab> CreateHeader() => new Header();
protected override SearchableListFilterControl<SocialSortCriteria, SortDirection> CreateFilterControl() => new FilterControl(); protected override SearchableListFilterControl<SocialSortCriteria, SortDirection> CreateFilterControl() => new FilterControl();
private IEnumerable<User> users;
private readonly LoadingAnimation loading; private readonly LoadingAnimation loading;
private IEnumerable<User> users;
public IEnumerable<User> Users public IEnumerable<User> Users
{ {
get { return users; } get { return users; }
set set
{ {
if (users?.Equals(value) ?? false) return; if (users?.Equals(value) ?? false)
users = value; return;
if (users == null) users = value?.ToList();
panelFlow.Clear();
else
{
panelFlow.ChildrenEnumerable = users.Select(u =>
{
var p = new UserPanel(u) { Width = 300 };
p.Status.BindTo(u.Status);
return p;
});
}
} }
} }
@ -62,59 +57,129 @@ namespace osu.Game.Overlays
ThirdWaveColour = OsuColour.FromHex(@"9b2b6e"); ThirdWaveColour = OsuColour.FromHex(@"9b2b6e");
FourthWaveColour = OsuColour.FromHex(@"6d214d"); FourthWaveColour = OsuColour.FromHex(@"6d214d");
ScrollFlow.Children = new[] Add(loading = new LoadingAnimation());
Filter.DisplayStyleControl.DisplayStyle.ValueChanged += recreatePanels;
// TODO sort our list in some way (either locally or with API call)
//Filter.DisplayStyleControl.Dropdown.Current.ValueChanged += rankStatus => Scheduler.AddOnce(updateSearch);
Header.Tabs.Current.ValueChanged += tab =>
{ {
new OsuContextMenuContainer currentQuery.Value = string.Empty;
{ Filter.Tabs.Current.Value = (SocialSortCriteria)Header.Tabs.Current.Value;
RelativeSizeAxes = Axes.X, Scheduler.AddOnce(updateSearch);
AutoSizeAxes = Axes.Y,
Child = panelFlow = new FillFlowContainer<UserPanel>
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Margin = new MarginPadding { Top = 20 },
Spacing = new Vector2(10f),
}
},
}; };
Add(loading = new LoadingAnimation()); currentQuery.ValueChanged += v =>
{
queryChangedDebounce?.Cancel();
if (string.IsNullOrEmpty(v))
Scheduler.AddOnce(updateSearch);
else
{
Users = null;
queryChangedDebounce = Scheduler.AddDelayed(updateSearch, 500);
}
};
currentQuery.BindTo(Filter.Search.Current);
Filter.Tabs.Current.ValueChanged += sortCriteria => Scheduler.AddOnce(updateSearch);
Scheduler.AddOnce(updateSearch); // so it displays something once it's first opened
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(APIAccess api) private void load(APIAccess api)
{ {
if (Users == null) this.api = api;
reloadUsers(api);
} }
private void reloadUsers(APIAccess api) private void recreatePanels(PanelDisplayStyle displayStyle)
{ {
Users = null; if (Users == null)
return;
// no this is not the correct data source, but it's something. if (panels != null)
var request = new GetUsersRequest();
request.Success += res =>
{ {
Users = res.Select(e => e.User); panels.FadeOut(200);
loading.Hide(); panels.Expire();
panels = null;
}
var newPanels = new FillFlowContainer<UserPanel>
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Spacing = new Vector2(10f),
Margin = new MarginPadding { Top = 10 },
ChildrenEnumerable = Users.Select(u =>
{
UserPanel panel = new UserPanel(u);
switch (displayStyle)
{
case PanelDisplayStyle.Grid:
panel.Width = 300;
break;
default:
panel.RelativeSizeAxes = Axes.X;
break;
}
panel.Status.BindTo(u.Status);
return panel;
})
}; };
api.Queue(request); LoadComponentAsync(newPanels, p =>
loading.Show(); {
if (panels != null)
ScrollFlow.Remove(panels);
ScrollFlow.Add(panels = newPanels);
});
} }
public void APIStateChanged(APIAccess api, APIState state) private GetUsersRequest getUsersRequest;
private readonly Bindable<string> currentQuery = new Bindable<string>();
private ScheduledDelegate queryChangedDebounce;
private void updateSearch()
{ {
switch (state) queryChangedDebounce?.Cancel();
if (!IsLoaded)
return;
Users = null;
loading.Hide();
getUsersRequest?.Cancel();
if (api == null || api.State == APIState.Offline)
return;
getUsersRequest = new GetUsersRequest(); // TODO filter/sort values?!?
getUsersRequest.Success += response =>
{ {
case APIState.Online: Task.Run(() =>
reloadUsers(api); {
break; var newUsers = response.Select(r => r.User);
default:
Users = null; Schedule(() =>
break; {
} Users = newUsers;
recreatePanels(Filter.DisplayStyleControl.DisplayStyle.Value);
loading.Hide();
});
});
};
loading.Show();
api.Queue(getUsersRequest);
} }
} }