Replace SocialOverlay with DashboardOverlay

This commit is contained in:
Andrei Zavatski 2020-04-16 12:05:51 +03:00
parent 29bea4e11c
commit 894598eb22
5 changed files with 100 additions and 12 deletions

View File

@ -48,7 +48,7 @@ public class TestSceneOsuGame : OsuTestScene
typeof(OnScreenDisplay),
typeof(NotificationOverlay),
typeof(DirectOverlay),
typeof(SocialOverlay),
typeof(DashboardOverlay),
typeof(ChannelManager),
typeof(ChatOverlay),
typeof(SettingsOverlay),

View File

@ -67,7 +67,7 @@ public class OsuGame : OsuGameBase, IKeyBindingHandler<GlobalAction>
private DirectOverlay direct;
private SocialOverlay social;
private DashboardOverlay dashboard;
private UserProfileOverlay userProfile;
@ -611,7 +611,7 @@ protected override void LoadComplete()
//overlay elements
loadComponentSingleFile(direct = new DirectOverlay(), overlayContent.Add, true);
loadComponentSingleFile(social = new SocialOverlay(), overlayContent.Add, true);
loadComponentSingleFile(dashboard = new DashboardOverlay(), overlayContent.Add, true);
var rankingsOverlay = loadComponentSingleFile(new RankingsOverlay(), overlayContent.Add, true);
loadComponentSingleFile(channelManager = new ChannelManager(), AddInternal, true);
loadComponentSingleFile(chatOverlay = new ChatOverlay(), overlayContent.Add, true);
@ -670,7 +670,7 @@ protected override void LoadComplete()
}
// ensure only one of these overlays are open at once.
var singleDisplayOverlays = new OverlayContainer[] { chatOverlay, social, direct, changelogOverlay, rankingsOverlay };
var singleDisplayOverlays = new OverlayContainer[] { chatOverlay, dashboard, direct, changelogOverlay, rankingsOverlay };
foreach (var overlay in singleDisplayOverlays)
{
@ -842,7 +842,7 @@ public bool OnPressed(GlobalAction action)
return true;
case GlobalAction.ToggleSocial:
social.ToggleVisibility();
dashboard.ToggleVisibility();
return true;
case GlobalAction.ResetInputSettings:

View File

@ -3,7 +3,7 @@
namespace osu.Game.Overlays.Dashboard
{
public class DashboardOverlayHeader : TabControlOverlayHeader<HomeOverlayTabs>
public class DashboardOverlayHeader : TabControlOverlayHeader<DashboardOverlayTabs>
{
protected override OverlayTitle CreateTitle() => new DashboardTitle();
@ -17,7 +17,7 @@ public DashboardTitle()
}
}
public enum HomeOverlayTabs
public enum DashboardOverlayTabs
{
Friends
}

View File

@ -1,19 +1,29 @@
// 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;
using System.Threading;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API;
using osu.Game.Overlays.Dashboard;
using osu.Game.Overlays.Dashboard.Friends;
namespace osu.Game.Overlays
{
public class DashboardOverlay : FullscreenOverlay
{
private CancellationTokenSource cancellationToken;
private readonly Box background;
private readonly Container content;
private readonly DashboardOverlayHeader header;
private readonly LoadingLayer loading;
private readonly OverlayScrollContainer scrollFlow;
public DashboardOverlay()
: base(OverlayColourScheme.Purple)
@ -24,7 +34,7 @@ public DashboardOverlay()
{
RelativeSizeAxes = Axes.Both
},
new OverlayScrollContainer
scrollFlow = new OverlayScrollContainer
{
RelativeSizeAxes = Axes.Both,
ScrollbarVisible = false,
@ -35,7 +45,7 @@ public DashboardOverlay()
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
new DashboardOverlayHeader
header = new DashboardOverlayHeader
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
@ -49,7 +59,7 @@ public DashboardOverlay()
}
}
},
new LoadingLayer(content),
loading = new LoadingLayer(content),
};
}
@ -58,5 +68,83 @@ private void load()
{
background.Colour = ColourProvider.Background5;
}
protected override void LoadComplete()
{
base.LoadComplete();
header.Current.BindValueChanged(onTabChanged);
}
private bool displayUpdateRequired = true;
protected override void PopIn()
{
base.PopIn();
// We don't want to create new display on every call, only when exiting from fully closed state.
if (displayUpdateRequired)
{
header.Current.TriggerChange();
displayUpdateRequired = false;
}
}
protected override void PopOutComplete()
{
base.PopOutComplete();
loadDisplay(Empty());
displayUpdateRequired = true;
}
private void loadDisplay(Drawable display)
{
scrollFlow.ScrollToStart();
LoadComponentAsync(display, loaded =>
{
loading.Hide();
content.Child = loaded;
}, (cancellationToken = new CancellationTokenSource()).Token);
}
private void onTabChanged(ValueChangedEvent<DashboardOverlayTabs> tab)
{
cancellationToken?.Cancel();
loading.Show();
switch (tab.NewValue)
{
case DashboardOverlayTabs.Friends:
loadDisplay(new FriendDisplay());
break;
default:
throw new NotImplementedException($"Display for {tab.NewValue} tab is not implemented");
}
}
public override void APIStateChanged(IAPIProvider api, APIState state)
{
switch (state)
{
case APIState.Online:
// Will force to create a display based on visibility state
displayUpdateRequired = true;
State.TriggerChange();
return;
default:
content.Clear();
loading.Show();
return;
}
}
protected override void Dispose(bool isDisposing)
{
cancellationToken?.Cancel();
base.Dispose(isDisposing);
}
}
}

View File

@ -14,9 +14,9 @@ public ToolbarSocialButton()
}
[BackgroundDependencyLoader(true)]
private void load(SocialOverlay chat)
private void load(DashboardOverlay dashboard)
{
StateContainer = chat;
StateContainer = dashboard;
}
}
}